fortran-lang/stdlib

linalg: generalize return type for `eye`

Closed this issue · 0 comments

Motivation

It was recently suggested that the eye (#481) function is misleading. I would like to suggest that the eye function is extended by allowing a general return type. This could be accomplished by introducing an optional mold keyword:

A = eye(m, n [, mold])

that would tell the eye interface which return type should have A:

pure function eye_${rk}$(m, n, mold)
   integer, intent(in) :: m
   integer, intent(in), optional :: n
   ${rt}$, optional, intent(in) :: mold
   ${rt}$, dimension(:,:), allocatable :: eye
end function eye_${rk}$

Prior Art

mold is a Fortran Standard keyword that specifies that the return type of a polymorphic allocation should be taken from another variable:

allocate(a, mold=b)

Similarly, here we may want to specify that the return type of the eye matrix should be taken from the mold variable.

Additional Information

No response