-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Description
Proposed new feature or change:
Today:
When using numpy.linalg.inv on a stack of matrix (shape=(m,n,n)), if one in the stack is singular, a LinAlgError is raised and all inverse matrices are discarded (even if they are all computed).
If you want to get the inverse matrix of invertible ones, you have to detect the good one first, then execute inv on them. As the algorithm used to determine the singular matrices is not clear, I don't know how to be 100% accurate.
Expected:
numpy.linalg.inv uses the _umath_linalg.inv C function that compute every inverse, with nan matrix for the singular ones. An error flag is raised, catch by a with errstate... block. This errstate cannot be override.
To correct this, there could be an additional argument (ie noerr) that doesn't "activate" the errstate.
The user will have to check after which matrices was not invertible, by checking the presence of nan:
np.isnan(ainv).any((1,2))
One example of a calling to _umath_linalg.inv whithout errors can be found in the cond function.