-
Notifications
You must be signed in to change notification settings - Fork 173
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
linalg: determinant #798
linalg: determinant #798
Conversation
Documentation
src/stdlib_linalg_determinant.fypp
Outdated
@@ -0,0 +1,302 @@ | |||
#:include "common.fypp" | |||
#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES | |||
module stdlib_linalg_determinant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be a submdodule of stdblib_linalg
, such that users can use it as:
use stdlib_linalg, only: det
instead of:
use stdlib_linalg_determinant, only: det
This will avoid an enormous amount of stdlib_linalg
modules.
Inconvenient: this approach will require the compilation of the a large module.
What do you think? What would be the best strategy for the users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good approach, everything would fit together smoothly. This might require indeed a large header module but for the end user and even a developer who would like to pick just one method and work on it, it would be easier... I think.
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.
Fixed thanks to Fortran Discourse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @perazz . Here are some suggestions. Overall, I like the API.
|
||
! Export linalg error handling | ||
public :: linalg_state_type, linalg_error_handling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This let me think that we should review the structure of the specs. Currently we have 1 page per module. However, if these become available through stdlib_linalg
, the specs should be modified accordingly (probably in another PR; I can start to work on a proposition when this is ready).
src/stdlib_linalg.fypp
Outdated
!!``` | ||
!! | ||
#:for rk,rt in RC_KINDS_TYPES | ||
#:if rk!="xdp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future developers, it might be good to add a comment to explain why xdp
is excluded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though it is not automated generation, should we manually implement blas and lapack backends for xdp
? They would be the same as for quad-precision, because all constants are generalized, and 64-bit double precision is still the "lower precision" datatype for mixed-precision algorithms. We should just decide about real/complex prefixes, like s/c
vs. d/z
vs. q/w
, for xdp they may be x/y
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supporting xdp
would be a nice feature IMO (even if I never use xdp
). x/y
prefixes make sense to me. If you think it is easy to implement it, I would support it. However, I don't think it is a priority right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it serves for the discussion, I'm using the following:
in the common.fypp
I added the notion of SUFFIX like
...
#! Collected (kind, type, suffix) tuples for real types
#:set REAL_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES, REAL_KINDS))
#! Complex types to be considered during templating
#:set CMPLX_SUFFIX = ["c{}".format(k) for k in CMPLX_KINDS]
#! Collected (kind, type, suffix) tuples for complex types
#:set CMPLX_KINDS_TYPES = list(zip(CMPLX_KINDS, CMPLX_TYPES, CMPLX_SUFFIX))
Which then allows me to do this in the .fypp
#:for k1, t1, s1 in (KINDS_TYPES)
type, public, extends(COO_t) :: COO_${s1}$
${t1}$, allocatable :: data(:)
contains
procedure :: get => get_value_coo_${s1}$
procedure :: set => set_value_coo_${s1}$
end type
#:endfor
and obtaining this in the fortran file:
type, public, extends(COO_t) :: COO_sp
real(sp), allocatable :: data(:)
contains
procedure :: get => get_value_coo_sp
procedure :: set => set_value_coo_sp
end type
type, public, extends(COO_t) :: COO_dp
real(dp), allocatable :: data(:)
contains
procedure :: get => get_value_coo_dp
procedure :: set => set_value_coo_dp
end type
type, public, extends(COO_t) :: COO_csp
complex(sp), allocatable :: data(:)
contains
procedure :: get => get_value_coo_csp
procedure :: set => set_value_coo_csp
end type
type, public, extends(COO_t) :: COO_cdp
complex(dp), allocatable :: data(:)
contains
procedure :: get => get_value_coo_cdp
procedure :: set => set_value_coo_cdp
end type
So basically considering the real types as reference, and the complex types as extensions adding the c
in front of the suffix.
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @perazz . This PR is almost ready to be merged IMO. Specs should be still added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @perazz. The specs LGTM. I proposed some minor suggestions.
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
Thanks a lot @jvdp1 - your edits look good! I've just added that it works for either |
I'll merge this PR. Thank you @perazz for this nice feature. |
Introduce determinant operator, based on LAPACK
*GETRF
functions.xdp
Prior art:
det(a)
det(a, overwrite_a=False, check_finite=True)
DET(a)
Proposed implementation: generic interface
d = det(a)
->pure
function, no additional inputs,a
is unchangedd = det(a,overwrite_a=.false.,err=state)
-> not pure, option tooverwrite_a
(do not allocate a temporary), return error state handler.det.a
Fortran operator interface, similar to 1), pure, but with the operator methodError handling returns:
LINALG_ERROR
on singular matrixLINALG_VALUE_ERROR
on invalid matrix sizecc @jvdp1 @jalvesz @fortran-lang/stdlib