svd

Functions
svd
Complete List of ArrayFire Functions ArrayFire Functions by Category » Linear Algebra » | Matrix factorizations and decompositions

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

## § af_svd()

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] | u | is the output array containing U
  [out] | s | is the output array containing the diagonal values of sigma, (singular values of the input matrix))
  [out] | vt | is the output array containing V^H
  [in] | in | is the input matrix

## § af_svd_inplace()

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] | u | is the output array containing U
  [out] | s | is the output array containing the diagonal values of sigma, (singular values of the input matrix))
  [out] | vt | is the output array containing V^H
  [in,out] | in | is the input matrix that will contain random data after this operation

## § svd()

AFAPI void af::svd | ( | array & | u,
|  | array & | s,
|  | array & | vt,
|  | const array & | in
| ) |  |

C++ Interface for SVD decomposition.

Parameters

  [out] | u | is the output array containing U
  [out] | s | is the output array containing the diagonal values of sigma, (singular values of the input matrix))
  [out] | vt | is the output array containing V^H
  [in] | in | is the input matrix

Examples:
  lin_algebra/svd.cpp.

## § svdInPlace()

AFAPI void af::svdInPlace | ( | array & | u,
|  | array & | s,
|  | array & | vt,
|  | array & | in
| ) |  |

C++ Interface for SVD decomposition.

Parameters

  [out] | u | is the output array containing U
  [out] | s | is the output array containing the diagonal values of sigma, (singular values of the input matrix))
  [out] | vt | is the output array containing V^H
  [in,out] | in | is the input matrix and will contain random data after this operation