fortran-lang / stdlib

Fortran Standard Library
https://stdlib.fortran-lang.org
MIT License
1.02k stars 161 forks source link

linalg: determinant #798

Closed perazz closed 2 months ago

perazz commented 2 months ago

Introduce determinant operator, based on LAPACK *GETRF functions.

Prior art:

Proposed implementation: generic interface

1) d = det(a) -> pure function, no additional inputs, a is unchanged 2) d = det(a,overwrite_a=.false.,err=state) -> not pure, option to overwrite_a (do not allocate a temporary), return error state handler 3) .det.a Fortran operator interface, similar to 1), pure, but with the operator method

Error handling returns:

cc @jvdp1 @jalvesz @fortran-lang/stdlib

perazz commented 2 months ago

Thanks @jvdp1 @jalvesz, great to iterate on the format, the more time we spend on this first LAPACK-backed function, the easier will be later. The submodule one is a great idea and here is an implementation.

gfortran returns an error though:

Fixed thanks to Fortran Discourse

perazz commented 2 months ago

Thanks a lot @jvdp1 - your edits look good! I've just added that it works for either real or complex matrices (it would seem it was for real only).

perazz commented 2 months ago

Thank you @jvdp1 @jalvesz for the reviews, let's wait a bit more, and if there are no further comments, I believe we could merge this before the end of the week.

jvdp1 commented 2 months ago

I'll merge this PR. Thank you @perazz for this nice feature.