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 marix 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

Function Documentation

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
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
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.