-
Notifications
You must be signed in to change notification settings - Fork 209
[stdlib_linalg] Update eye function. #481
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
Changes from 1 commit
ebc61cd
8745725
c2f0abf
c20f69f
c326353
2e4d681
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,20 +82,28 @@ module stdlib_linalg | |
|
|
||
| contains | ||
|
|
||
| function eye(n) result(res) | ||
| !! version: experimental | ||
| !! | ||
| !! Constructs the identity matrix | ||
| !! ([Specification](../page/specs/stdlib_linalg.html#description_1)) | ||
| integer, intent(in) :: n | ||
| integer(int8) :: res(n, n) | ||
| integer :: i | ||
| res = 0 | ||
| do i = 1, n | ||
| res(i, i) = 1 | ||
| end do | ||
| end function eye | ||
| !> Version: experimental | ||
| !> | ||
| !> Constructs the identity matrix. | ||
| !> ([Specification](../page/specs/stdlib_linalg.html#eye-construct-the-identity-matrix)) | ||
| pure function eye(dim1, dim2) result(result) | ||
|
|
||
| integer, intent(in) :: dim1 | ||
| integer, intent(in), optional :: dim2 | ||
| integer, allocatable :: result(:, :) | ||
|
||
|
|
||
| integer :: dim2_ | ||
| integer :: i | ||
|
|
||
| dim2_ = merge(dim2, dim1, present(dim2)) | ||
zoziha marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| allocate(result(dim1, dim2_)) | ||
|
|
||
| result = 0 | ||
| do i = 1, min(dim1, dim2_) | ||
| result(i, i) = 1 | ||
| end do | ||
|
|
||
| end function eye | ||
|
|
||
| #:for k1, t1 in RCI_KINDS_TYPES | ||
| function trace_${t1[0]}$${k1}$(A) result(res) | ||
|
|
@@ -108,4 +116,5 @@ contains | |
| end do | ||
| end function trace_${t1[0]}$${k1}$ | ||
| #:endfor | ||
| end module | ||
|
|
||
| end module stdlib_linalg | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| PROGS_SRC = test_linalg.f90 | ||
|
|
||
|
|
||
| include ../Makefile.manual.test.mk |
Uh oh!
There was an error while loading. Please reload this page.