Perform Singular Value Decomposition. More...

Functions

AFAPI void svd (array &u, array &s, array &vt, const array &in)
 C++ Interface for SVD decomposition. More...
 
AFAPI void svdInPlace (array &u, array &s, array &vt, array &in)
 C++ Interface for SVD decomposition. More...
 
AFAPI af_err af_svd (af_array *u, af_array *s, af_array *vt, const af_array in)
 C Interface for SVD decomposition. More...
 
AFAPI af_err af_svd_inplace (af_array *u, af_array *s, af_array *vt, af_array in)
 C Interface for SVD decomposition. More...
 

Detailed Description

Perform Singular Value Decomposition.

This function factorizes a matrix A into two unitary matrices U and Vt, and a diagonal matrix S such that

\(A = U * S * Vt\)

If A has M rows and N columns, U is of the size M x M , V is of size N x N, and S is of size M x N

The arrayfire function only returns the non zero diagonal elements of S. To reconstruct the original matrix A from the individual factors, the following code snuppet can be used:

af::array U, S, Vt;
af::svd(U, S, Vt, A);
const int MN = std::min(M, N);
af::array UU = U(af::span, af::seq(MN));
af::array SS = af::diag(S, 0, false).as(ty);
af::array VV = Vt(af::seq(MN), af::span);
af::array AA = matmul(UU, SS, VV);

When memory is a concern, and A is dispensible, svdInPlace() can be used


Function Documentation

AFAPI af_err af_svd ( af_array u,
af_array s,
af_array vt,
const af_array  in 
)

C Interface for SVD decomposition.

Parameters
[out]uis the output array containing U
[out]sis the output array containing the diagonal values of sigma, (singular values of the input matrix))
[out]vtis the output array containing V^H
[in]inis the input matrix
AFAPI af_err af_svd_inplace ( af_array u,
af_array s,
af_array vt,
af_array  in 
)

C Interface for SVD decomposition.

Parameters
[out]uis the output array containing U
[out]sis the output array containing the diagonal values of sigma, (singular values of the input matrix))
[out]vtis the output array containing V^H
[in,out]inis the input matrix that will contain random data after this operation
AFAPI void af::svd ( array u,
array s,
array vt,
const array in 
)

C++ Interface for SVD decomposition.

Parameters
[out]uis the output array containing U
[out]sis the output array containing the diagonal values of sigma, (singular values of the input matrix))
[out]vtis the output array containing V^H
[in]inis the input matrix
Examples:
lin_algebra/svd.cpp.
AFAPI void af::svdInPlace ( array u,
array s,
array vt,
array in 
)

C++ Interface for SVD decomposition.

Parameters
[out]uis the output array containing U
[out]sis the output array containing the diagonal values of sigma, (singular values of the input matrix))
[out]vtis the output array containing V^H
[in,out]inis the input matrix and will contain random data after this operation