# Matrix Decomposition

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasSVD\_Init(const char \*licenseKey)

    - Initialize SVD module. **WARNING:** Must be called once before other FastADAS functions except [FadasVersion()](https://docs.qualcomm.com/doc/80-63309-1/topic/misc.html#group__misc_1ga55cbdff48d751f2a0227ae4ac106d746).

- Parameters:

    - **licenseKey** – License key string.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasSVD\_DeInit(void)

    - Deinitialize SVD module. **WARNING:** Must be called once after all other FastADAS functions except [FadasVersion()](https://docs.qualcomm.com/doc/80-63309-1/topic/misc.html#group__misc_1ga55cbdff48d751f2a0227ae4ac106d746).

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasSVD\_SVDf32(const [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict A, uint32\_t m, uint32\_t n, [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict w, [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict U, [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict Vt, [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*tmpU, [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*tmpV)

    - Compute a singular value decomposition (SVD) of a matrix of a float type A = U\*diag[w]\*Vt; for solving problems such as least-squares, underdetermined linear systems, and matrix inversion. The algorithm does not compute the full U and V matrices, it computes a condensed version of U and V that is sufficient to solve most problems that use SVD.

- Parameters:

    - - **A** – Pointer to the input matrix of dimension m x n. **WARNING:** Must be 128-byte aligned.
- **m** – Number of rows of matrix A
- **n** – Number of columns of matrix A
- **w** – Pointer to the buffer that holds n singular values. When m &gt; n, the buffer contains n singular values while when m &lt; n, only the first m singular values are significant. However, during allocation, it should be allocated as a buffer to hold n floats. **WARNING:** Must be 128-byte aligned.
- **U** – Pointer to the U matrix whose dimension is m x min(m,n). This is not the full size U matrix obtained from the conventional SVD algorithm, but is sufficient for solving problems like least-squares, under-determined linear systems, matrix inversion and so forth. While allocating, allocate as a matrix of m x n floats. **WARNING:** Must be 128-byte aligned.
- **Vt** – Pointer to the V matrix whose dimension is n x min(m,n). Not the full size V matrix obtained from the conventional SVD algorithm, but is sufficient for solving problems like least-squares, under-determined linear systems, matrix inversion and so forth. While allocating, allocate as a matrix of n x n floats. **WARNING:** Must be 128-byte aligned.
- **tmpU** – Pointer to the temporary buffer used in processing. It must be allocated as an array of size m x n. **WARNING:** Must be 128-byte aligned.
- **tmpV** – Pointer to the temporary buffer used in processing. It must be allocated as an array of size m x n. **WARNING:** Must be 128-byte aligned.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasSVD\_SolveCholeskyf32([float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict A, const [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict b, [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict diag, uint32\_t N, [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict x)

    - Executes Cholesky decomposition algorithm on a symmetric and positive definite matrix to solve the linear system A\*x = b, where A is an N x N matrix and x and b are vectors of size N.

- Parameters:

    - - **A** – Pointer to the matrix A or size N x N. **WARNING:**

    - This matrix is modified during computation. Save the original matrix if necessary
    - Must be 128-byte aligned
- **b** – Pointer to the vector b of size N. **WARNING:** Must be 128-byte aligned.
- **diag** – Pointer to the buffer for the diagonal of matrix A. This buffer is for computation. **WARNING:** Must be 128-byte aligned.
- **N** – Size of matrix and vectors.
- **x** – Pointer to the output vector x of size N. **WARNING:** Must be 128-byte aligned.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasSVD\_SolveLUf32([float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict A, [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict b, uint32\_t N, uint8\_t \*\_\_restrict pivot, [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict x)

    - Solves a linear system of equations using LU decomposition. Given a system defined by A x = b, the function decomposes A into a lower triangular matrix L and an upper triangular matrix U. It then computes x by solving L y = B by forward substitution for y, and then solving the system of linear equations U x = y by backward substitution for x. **NOTE:** Because not all matrices have a LU decomposition, pivoting ensures that a nonsingular matrix can be solved.

- Parameters:

    - - **A** – Input coefficient matrix of the linear system of dimension N x N **WARNING:**

    - Must be square
    - Must be 128-byte aligned
- **b** – Component vector of the linear system of dimension N x 1.
- **N** – Dimension of the input matrix A and component vector b.
- **pivot** – N x 1 pivot array that is populated as follows: for each k = 0, 1, …. , N-1, the i-th element of pivot contains the row interchanged with row i when k = i. Pivoting ensures numerical stability and LU factorization for the input matrix A.
- **x** – The solution of the linear system, an N x 1 vector.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasSVD\_SolveLDLf32([float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict A, const [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict b, [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict diag, uint32\_t N, [float32\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1a4611b605e45ab401f02cab15c5e38715.html#_CPPv49float32_t) \*\_\_restrict x)

    - Executes LDL decomposition algorithm on a symmetric and positive definite matrix to solve the linear system A\*x = b, where A is an NxN matrix and x and b are vectors of size N.

- Parameters:

    - - **A** – Pointer to the matrix A or size N x N. **WARNING:**

    - This matrix is modified during computation. Save the original matrix if necessary
    - Must be 128-byte aligned
- **b** – Pointer to the vector b of size N. **WARNING:** Must be 128-byte aligned.
- **diag** – Pointer to the buffer for the diagonal of matrix A. This buffer is for computation. **WARNING:** Must be 128-byte aligned.
- **N** – Size of matrix and vectors.
- **x** – Pointer to the output vector x of size N. **WARNING:** Must be 128-byte aligned.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

## Related examples

- [svd/app.cpp](https://docs.qualcomm.com/doc/80-63309-1/topic/svd.html)
- [one/one.cpp](https://docs.qualcomm.com/doc/80-63309-1/topic/one.html)

Last Published: Sep 30, 2024

[Previous Topic
Remap](https://docs.qualcomm.com/bundle/publicresource/80-63309-1/topics/remap.md) [Next Topic
Tensor](https://docs.qualcomm.com/bundle/publicresource/80-63309-1/topics/tensor.md)