Extract diagonal from a matrix when extract is set to true. More...

Functions

AFAPI array diag (const array &in, const int num=0, const bool extract=true)
 
AFAPI af_err af_diag_create (af_array *out, const af_array in, const int num)
 
AFAPI af_err af_diag_extract (af_array *out, const af_array in, const int num)
 

Detailed Description

Extract diagonal from a matrix when extract is set to true.

Create a diagonal matrix from input array when extract is set to false

// Extraction
array a = randu(dim4(4, 3));
// a [4 3 1 1]
// 0.0000 0.5328 0.6793
// 0.1315 0.2190 0.9347
// 0.7556 0.0470 0.3835
// 0.4587 0.6789 0.5194
array b = diag(a);
// b [3 1 1 1]
// 0.0000
// 0.2190
// 0.3835
array c = diag(a, 1);
// c [2 1 1 1]
// 0.5328
// 0.9347
// Creation
array a = randu(4);
// a [4 1 1 1]
// 0.0000
// 0.1315
// 0.7556
// 0.4587
array b = diag(a, 0, false);
// b [4 4 1 1]
// 0.0000 0.0000 0.0000 0.0000
// 0.0000 0.1315 0.0000 0.0000
// 0.0000 0.0000 0.7556 0.0000
// 0.0000 0.0000 0.0000 0.4587
array b = diag(a, -1, false);
// c [5 5 1 1]
// 0.0000 0.0000 0.0000 0.0000 0.0000
// 0.0000 0.0000 0.0000 0.0000 0.0000
// 0.0000 0.1315 0.0000 0.0000 0.0000
// 0.0000 0.0000 0.7556 0.0000 0.0000
// 0.0000 0.0000 0.0000 0.4587 0.0000
AFAPI array diag(const array &in, const int num=0, const bool extract=true)
static af::array array(af::dim4 idims, cl_mem buf, af::dtype type, bool retain=false)
Create an af::array object from an OpenCL cl_mem buffer.
Definition: opencl.h:327
AFAPI array randu(const dim4 &dims, const dtype ty, randomEngine &r)

Function Documentation

◆ af_diag_create()

AFAPI af_err af_diag_create ( af_array out,
const af_array  in,
const int  num 
)
Parameters
[out]outis the array created from the input array in
[in]inis the input array which is the diagonal
[in]numis the diagonal index

◆ af_diag_extract()

AFAPI af_err af_diag_extract ( af_array out,
const af_array  in,
const int  num 
)
Parameters
[out]outis the num -th diagonal of in
[in]inis the input matrix
[in]numis the diagonal index

◆ diag()

AFAPI array af::diag ( const array in,
const int  num = 0,
const bool  extract = true 
)
Parameters
[in]inis the input array
[in]numis the diagonal index
[in]extractwhen true returns an array containing diagonal of tha matrix and when false returns a matrix with in as diagonal
Returns
an array with either the diagonal or the matrix based on extract
Examples
lin_algebra/svd.cpp.