Closed perazz closed 2 months ago
As far as this is my first review for stdlib
, it looks pretty good to me. I was jut wondering about the tests. Wouldn't including a test with a known singular matrix be useful to make sure the whole error handling is working correctly?
Great idea @loiseaujc, thanks!
LINALG_ERROR
complex
tests were not running -> add them From Fortran Monthly call:
subroutine invert
, add interface to not operate in-place but return inverse to another variable (i.e., call invert(a, am1, [, pivot] [, err])
.inv.A
operator, with singular matrix, do not return all zeros, but stop the programThanks a lot @loiseaujc @jvdp1 @jalvesz for the reviews - I believe I've addressed all your comments (see linked commits in each comment). In d0af9be I've introduced a tiny behavior change:
On exceptions raised when the operator interface (.inv.A
) is used, instead of error stop
ping the program, I think it is more reasonable to instead return an array of NaN
s (which are initialized from ieee_value(0.0,ieee_quiet_nan)
. The reason I think this is better is:
+
, -
, but also matmul
etc. ) would behave exactly in the same way: when something goes wrong, they typically return NaNs. So please do let me know if you also like this update.
Given your idea to enable the operator interface to run through the computation without stopping in case of singular matrices I just suggested a small addition to the documentation. This change seems reasonable to me as even a scalar division would not stop the program but also simply return a NaN. Otherwise LGTM!!
Ok @jvdp1 @jalvesz I've restored the xdp
precision. Please let me know if you have further comments. This is probably ready to be merged sometime next week.
Thank you all, I will merge this now.
Compute the multiplicative inverse of a
real
orcomplex
square matrix: $A \cdot A^{-1} = A^{-1} \cdot A = I_n$ . Based on LAPACK General factorization (*GETRF
) and inversion (*GETRI
).exclude unsupportedxdp
subroutine
interfacePrior art
B = inv(A)
inv(A, overwrite_a=False, check_finite=True)
.i.A
Proposed implementation
B = inv(A [, err])
function interfacecall invert(A [, pivot] [, err])
in-place (no-allocation) subroutine interface (optionalpivot
array).inv.A
operator interfacecc: @jalvesz @jvdp1 @loiseaujc @fortran-lang/stdlib