Skip to content
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

Identity matrix intrinsic #103

Open
jacobwilliams opened this issue Nov 28, 2019 · 2 comments
Open

Identity matrix intrinsic #103

jacobwilliams opened this issue Nov 28, 2019 · 2 comments
Labels
Clause 16 Standard Clause 16: Intrinsic procedures and modules

Comments

@jacobwilliams
Copy link

An intrinsic to define an identity matrix would be nice. For example, Matlab has this.

Say:

real(wp),dimension(4,4),parameter :: I = eye(4)

For example, currently, to do this we have to have to do something like this:

real(wp),dimension(4,4),parameter :: I = reshape([1.0_wp,0.0_wp,0.0_wp,0.0_wp,&
                                                  0.0_wp,1.0_wp,0.0_wp,0.0_wp,&
                                                  0.0_wp,0.0_wp,1.0_wp,0.0_wp,&
                                                  0.0_wp,0.0_wp,0.0_wp,1.0_wp],[4,4])

Related maybe to #102.

@FortranFan
Copy link
Member

See also #14.

@Leonard-Reuter
Copy link
Contributor

Leonard-Reuter commented Dec 16, 2019

I agree. But well, then there is this solution: =)

integer :: i
integer, parameter :: n = 4  ! dimension of the identity matrix
real(wp), parameter :: I(n,n) = RESHAPE([ (MERGE(1._wp, 0._wp, i/n==MOD(i,n)), i=0, n**2-1) ], [n,n])

@certik certik added the Clause 16 Standard Clause 16: Intrinsic procedures and modules label Apr 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clause 16 Standard Clause 16: Intrinsic procedures and modules
Projects
None yet
Development

No branches or pull requests

4 participants