Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Singular Matrix Inversion #172

Open
thseiler opened this issue Apr 24, 2024 · 1 comment
Open

Singular Matrix Inversion #172

thseiler opened this issue Apr 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@thseiler
Copy link

The current version of CMSIS-DSP arm_mat_inverse_f32() seems to have problems detecting the singularity of certain input matrices:
test_matrix:
{ 1.0, 2.0,
2.0, 4.0 }

The "flag" that tracks whether a row exchange has happened is not reset at the beginning of the next loop iteration. As soon as a row exchange has happened, the singularity detection logic is short-circuited for the remainder of the processing. A singular matrix that happens to trigger any row exchange, therefore, passes as regular and the status returned by arm_mat_inverse_f32 indicates ARM_MATH_SUCCESS.

Proposed fix:

  1. reset the flag at the beginning of each loop:
in arm_mat_inverse_f32.c:191
[...]
        /* Loop over the number of columns of the input matrix.
           All the elements in each column are processed by the row operations */
     
        /* Index modifier to navigate through the columns */
        for(column = 0U; column < numCols; column++)
        {
+             /* reset flag */
+             flag = 0; 

              /* Check if the pivot element is zero..
               * If it is zero then interchange the row with non zero row below.
               * If there is no non zero element to replace in the rows below,
               * then the matrix is Singular. */
  1. Add a singular matrix to the unit tests.

  2. Similar situation for _f16, _f32, and _f64

@christophe0606 christophe0606 added the bug Something isn't working label Apr 25, 2024
@christophe0606
Copy link
Contributor

@thseiler Thanks for reporting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants