 A high-performance general-purpose compute library

Pseudo-invert a matrix. More...

## Functions

AFAPI array pinverse (const array &in, const double tol=1E-6, const matProp options=AF_MAT_NONE)
C++ Interface for pseudo-inverting (Moore-Penrose) a matrix.

AFAPI af_err af_pinverse (af_array *out, const af_array in, const double tol, const af_mat_prop options)
C Interface for pseudo-inverting (Moore-Penrose) a matrix.

## Detailed Description

Pseudo-invert a matrix.

This function calculates the Moore-Penrose pseudoinverse of a matrix $$A$$, using af::svd at its core. If $$A$$ is of size $$M \times N$$, then its pseudoinverse $$A^+$$ will be of size $$N \times M$$.

This calculation can be batched if the input array is three or four-dimensional $$(M \times N \times P \times Q$$, with $$Q=1$$ for only three dimensions $$)$$. Each $$M \times N$$ slice along the third dimension will have its own pseudoinverse, for a total of $$P \times Q$$ pseudoinverses in the output array $$(N \times M \times P \times Q)$$.

Here's an example snippet of its usage. In this example, we have a matrix $$A$$ and we compute its pseudoinverse $$A^+$$. This condition must hold: $$AA^+A=A$$, given that the two matrices are pseudoinverses of each other (in fact, this is one of the Moore-Penrose conditions):

float hA[] = {0, 1, 2, 3, 4, 5};
array A(3, 2, hA);
// 0.0000 3.0000
// 1.0000 4.0000
// 2.0000 5.0000
array Apinv = pinverse(A);
// -0.7778 -0.1111 0.5556
// 0.2778 0.1111 -0.0556
array MustBeA = matmul(A, Apinv, A);
// 0.0000 3.0000
// 1.0000 4.0000
// 2.0000 5.0000

## ◆ af_pinverse()

 AFAPI af_err af_pinverse ( af_array * out, const af_array in, const double tol, const af_mat_prop options )

C Interface for pseudo-inverting (Moore-Penrose) a matrix.

Currently uses the SVD-based approach.

Parameters
 [out] out will contain the pseudo-inverse of matrix in [in] in is the input matrix [in] tol defines the lower threshold for singular values from SVD [in] options must be AF_MAT_NONE (more options might be supported in the future)
Note
tol is not the actual lower threshold, but it is passed in as a parameter to the calculation of the actual threshold relative to the shape and contents of in.
At first, try setting tol to 1e-6 for single precision and 1e-12 for double.
This function is not supported in GFOR

## ◆ pinverse()

 AFAPI array pinverse ( const array & in, const double tol = 1E-6, const matProp options = AF_MAT_NONE )

C++ Interface for pseudo-inverting (Moore-Penrose) a matrix.

Currently uses the SVD-based approach.

Parameters
 [in] in is the input matrix [in] tol defines the lower threshold for singular values from SVD [in] options must be AF_MAT_NONE (more options might be supported in the future)
Returns
the pseudo-inverse of the input matrix
Note
tol is not the actual lower threshold, but it is passed in as a parameter to the calculation of the actual threshold relative to the shape and contents of in.
This function is not supported in GFOR