-
Notifications
You must be signed in to change notification settings - Fork 189
[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 2 commits
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(:, :) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you avoid the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (see #478 (comment), #477 (comment), and https://community.intel.com/t5/Intel-Fortran-Compiler/how-to-set-the-stack-size/td-p/933530) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My comment was based on @certik and @milancurcic 's comments (this comment and following ones). Furthermore, the rules for stack vs heap can be different between compilers/OS, and can be also changed within a compiler through a compiler option (e.g., using Gfortran with Therefore, I am in favor to always use automatic arrays when possible. @certik @milancurcic @awvwgk @ivan-pi Any comments on that topic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may indeed be a big controversy, it seems to be: @awvwgk agrees with allocation array, @jvdp1 agrees with automatic array. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I suggest using automatic array wherever possible, and However, if you re-write this to be two specific procedures under one generic name, instead of using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'm not a fan of automatic arrays, since usage with So far automatic array usage has resulted in a significant amount of support request from users for me. Setting the system stack with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @awvwgk I don't think that's a good reason to avoid a language feature. If a feature (and a very old one) doesn't work with a compiler, let's report it. Avoiding it only helps permeate the bug with the compiler. I've been using this with ifort since 2010 and haven't seen an issue. It's possible that I didn't notice it. The downside to the @zoziha When resolving conversations as a GitHub feature, I suggest to leave a comment about what you decided, otherwise discussions get hidden but aren't really resolved. Maybe we should document this in the Code Review guide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @milancurcic: issues with some compilers/options/OS/... are not good reasons to avoid a feature of the language. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jvdp1 okay if we do it in a separate PR and merge this one first? We could evaluate the performance difference too. |
||
|
||
integer :: dim2_ | ||
integer :: i | ||
|
||
dim2_ = merge(dim2, dim1, present(dim2)) | ||
zoziha marked this conversation as resolved.
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.