NMSIS-DSP  Version 1.2.0
NMSIS DSP Software Library
Matrix Inverse

Computes the inverse of a matrix. More...

Functions

riscv_status riscv_mat_inverse_f16 (const riscv_matrix_instance_f16 *pSrc, riscv_matrix_instance_f16 *pDst)
 Floating-point matrix inverse. More...
 
riscv_status riscv_mat_inverse_f32 (const riscv_matrix_instance_f32 *pSrc, riscv_matrix_instance_f32 *pDst)
 Floating-point matrix inverse. More...
 
riscv_status riscv_mat_inverse_f64 (const riscv_matrix_instance_f64 *pSrc, riscv_matrix_instance_f64 *pDst)
 Floating-point (64 bit) matrix inverse. More...
 
riscv_status riscv_mat_solve_lower_triangular_f16 (const riscv_matrix_instance_f16 *lt, const riscv_matrix_instance_f16 *a, riscv_matrix_instance_f16 *dst)
 Solve LT . X = A where LT is a lower triangular matrix. More...
 
riscv_status riscv_mat_solve_lower_triangular_f32 (const riscv_matrix_instance_f32 *lt, const riscv_matrix_instance_f32 *a, riscv_matrix_instance_f32 *dst)
 Solve LT . X = A where LT is a lower triangular matrix. More...
 
riscv_status riscv_mat_solve_lower_triangular_f64 (const riscv_matrix_instance_f64 *lt, const riscv_matrix_instance_f64 *a, riscv_matrix_instance_f64 *dst)
 Solve LT . X = A where LT is a lower triangular matrix. More...
 
riscv_status riscv_mat_solve_upper_triangular_f16 (const riscv_matrix_instance_f16 *ut, const riscv_matrix_instance_f16 *a, riscv_matrix_instance_f16 *dst)
 Solve UT . X = A where UT is an upper triangular matrix. More...
 
riscv_status riscv_mat_solve_upper_triangular_f32 (const riscv_matrix_instance_f32 *ut, const riscv_matrix_instance_f32 *a, riscv_matrix_instance_f32 *dst)
 Solve UT . X = A where UT is an upper triangular matrix. More...
 
riscv_status riscv_mat_solve_upper_triangular_f64 (const riscv_matrix_instance_f64 *ut, const riscv_matrix_instance_f64 *a, riscv_matrix_instance_f64 *dst)
 Solve UT . X = A where UT is an upper triangular matrix. More...
 

Detailed Description

Computes the inverse of a matrix.

The inverse is defined only if the input matrix is square and non-singular (the determinant is non-zero). The function checks that the input and output matrices are square and of the same size.

Matrix inversion is numerically sensitive and the NMSIS DSP library only supports matrix inversion of floating-point matrices.

Algorithm
The Gauss-Jordan method is used to find the inverse. The algorithm performs a sequence of elementary row-operations until it reduces the input matrix to an identity matrix. Applying the same sequence of elementary row-operations to an identity matrix yields the inverse matrix. If the input matrix is singular, then the algorithm terminates and returns error status RISCV_MATH_SINGULAR.
Matrix Inverse of a 3 x 3 matrix using Gauss-Jordan Method

\[ \begin{pmatrix} a_{1,1} & a_{1,2} & a_{1,3} & | & 1 & 0 & 0\\ a_{2,1} & a_{2,2} & a_{2,3} & | & 0 & 1 & 0\\ a_{3,1} & a_{3,2} & a_{3,3} & | & 0 & 0 & 1\\ \end{pmatrix} \rightarrow \begin{pmatrix} 1 & 0 & 0 & | & x_{1,1} & x_{2,1} & x_{3,1} \\ 0 & 1 & 0 & | & x_{1,2} & x_{2,2} & x_{3,2} \\ 0 & 0 & 1 & | & x_{1,3} & x_{2,3} & x_{3,3} \\ \end{pmatrix} \]

Function Documentation

◆ riscv_mat_inverse_f16()

riscv_status riscv_mat_inverse_f16 ( const riscv_matrix_instance_f16 pSrc,
riscv_matrix_instance_f16 pDst 
)

Floating-point matrix inverse.

Parameters
[in]pSrcpoints to input matrix structure. The source matrix is modified by the function.
[out]pDstpoints to output matrix structure
Returns
execution status
  • RISCV_MATH_SUCCESS : Operation successful
  • RISCV_MATH_SIZE_MISMATCH : Matrix size check failed
  • RISCV_MATH_SINGULAR : Input matrix is found to be singular (non-invertible)

◆ riscv_mat_inverse_f32()

riscv_status riscv_mat_inverse_f32 ( const riscv_matrix_instance_f32 pSrc,
riscv_matrix_instance_f32 pDst 
)

Floating-point matrix inverse.

Parameters
[in]pSrcpoints to input matrix structure. The source matrix is modified by the function.
[out]pDstpoints to output matrix structure
Returns
execution status
  • RISCV_MATH_SUCCESS : Operation successful
  • RISCV_MATH_SIZE_MISMATCH : Matrix size check failed
  • RISCV_MATH_SINGULAR : Input matrix is found to be singular (non-invertible)

◆ riscv_mat_inverse_f64()

riscv_status riscv_mat_inverse_f64 ( const riscv_matrix_instance_f64 pSrc,
riscv_matrix_instance_f64 pDst 
)

Floating-point (64 bit) matrix inverse.

Floating-point matrix inverse.

Parameters
[in]pSrcpoints to input matrix structure. The source matrix is modified by the function.
[out]pDstpoints to output matrix structure
Returns
execution status
  • RISCV_MATH_SUCCESS : Operation successful
  • RISCV_MATH_SIZE_MISMATCH : Matrix size check failed
  • RISCV_MATH_SINGULAR : Input matrix is found to be singular (non-invertible)

◆ riscv_mat_solve_lower_triangular_f16()

riscv_status riscv_mat_solve_lower_triangular_f16 ( const riscv_matrix_instance_f16 lt,
const riscv_matrix_instance_f16 a,
riscv_matrix_instance_f16 dst 
)

Solve LT . X = A where LT is a lower triangular matrix.

Parameters
[in]ltThe lower triangular matrix
[in]aThe matrix a
[out]dstThe solution X of LT . X = A
Returns
The function returns RISCV_MATH_SINGULAR, if the system can't be solved.

◆ riscv_mat_solve_lower_triangular_f32()

riscv_status riscv_mat_solve_lower_triangular_f32 ( const riscv_matrix_instance_f32 lt,
const riscv_matrix_instance_f32 a,
riscv_matrix_instance_f32 dst 
)

Solve LT . X = A where LT is a lower triangular matrix.

Parameters
[in]ltThe lower triangular matrix
[in]aThe matrix a
[out]dstThe solution X of LT . X = A
Returns
The function returns RISCV_MATH_SINGULAR, if the system can't be solved. Notice: The instruction vfredusum may introduce errors. So, if we use the V-extension implementation, we have to accept the errors that may happen in this function.

◆ riscv_mat_solve_lower_triangular_f64()

riscv_status riscv_mat_solve_lower_triangular_f64 ( const riscv_matrix_instance_f64 lt,
const riscv_matrix_instance_f64 a,
riscv_matrix_instance_f64 dst 
)

Solve LT . X = A where LT is a lower triangular matrix.

Parameters
[in]ltThe lower triangular matrix
[in]aThe matrix a
[out]dstThe solution X of LT . X = A
Returns
The function returns RISCV_MATH_SINGULAR, if the system can't be solved. Notice: The instruction vfredusum may introduce errors. So, if we use the V-extension implementation, we have to accept the errors that may happen in this function.

◆ riscv_mat_solve_upper_triangular_f16()

riscv_status riscv_mat_solve_upper_triangular_f16 ( const riscv_matrix_instance_f16 ut,
const riscv_matrix_instance_f16 a,
riscv_matrix_instance_f16 dst 
)

Solve UT . X = A where UT is an upper triangular matrix.

Parameters
[in]utThe upper triangular matrix
[in]aThe matrix a
[out]dstThe solution X of UT . X = A
Returns
The function returns RISCV_MATH_SINGULAR, if the system can't be solved.

◆ riscv_mat_solve_upper_triangular_f32()

riscv_status riscv_mat_solve_upper_triangular_f32 ( const riscv_matrix_instance_f32 ut,
const riscv_matrix_instance_f32 a,
riscv_matrix_instance_f32 dst 
)

Solve UT . X = A where UT is an upper triangular matrix.

Parameters
[in]utThe upper triangular matrix
[in]aThe matrix a
[out]dstThe solution X of UT . X = A
Returns
The function returns RISCV_MATH_SINGULAR, if the system can't be solved. Notice: The instruction vfredusum may introduce errors. So, if we use the V-extension implementation, we have to accept the errors that may happen in this function.

◆ riscv_mat_solve_upper_triangular_f64()

riscv_status riscv_mat_solve_upper_triangular_f64 ( const riscv_matrix_instance_f64 ut,
const riscv_matrix_instance_f64 a,
riscv_matrix_instance_f64 dst 
)

Solve UT . X = A where UT is an upper triangular matrix.

Parameters
[in]utThe upper triangular matrix
[in]aThe matrix a
[out]dstThe solution X of UT . X = A
Returns
The function returns RISCV_MATH_SINGULAR, if the system can't be solved. Notice: The instruction vfredusum may introduce errors. So, if we use the V-extension implementation, we have to accept the errors that may happen in this function.