Skip to content

Commit c20f69f

Browse files
committed
Improve eye func test and doc.
1 parent c2f0abf commit c20f69f

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,13 @@ This is an `intent(in)` argument.
121121
`dim2`: Shall be a scalar of default type `integer`.
122122
This is an `intent(in)` and `optional` argument.
123123

124-
#### Note
125-
126-
Because of `huge(integer :: i) = 2147483647`, the dimensional maximum length of array created by the `eye` function is `2147483647`.
127-
128124
### Return value
129125

130-
Return the identity matrix, i.e. a square matrix with ones on the main diagonal and zeros elsewhere. The return value is of type `integer`.
126+
Return the identity matrix, i.e. a matrix with ones on the main diagonal and zeros elsewhere. The return value is of type `integer`.
131127

132128
#### Warning
133129

134-
If the array that receives the return value of the `eye` function is of `real/complex` type, conversion from `integer` type to `real/complex` type will occur.
135-
136-
Just as `Fortran` is a strongly typed statically compiled language, be careful with the following statements:
130+
Since the result of `eye` is of `integer` type, one should be careful about using it in arithmetic expressions. For example:
137131
```fortran
138132
real :: A(:,:)
139133
!> Be careful

src/tests/linalg/test_linalg.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ subroutine test_eye
8585
msg="all(eye(3,3) == diag([(1,i=1,3)])) failed.",warn=warn)
8686

8787
rye = eye(3,4)
88-
call check(sum(rye(:,1:3) - diag([(1.0_sp,i=1,3)])) < sptol, &
89-
msg="sum(rye(:,1:3) - diag([(1.0_sp,i=1,3)])) < sptol", warn=warn)
88+
call check(sum(abs(rye(:,1:3) - diag([(1.0_sp,i=1,3)]))) < sptol, &
89+
msg="sum(abs(rye(:,1:3) - diag([(1.0_sp,i=1,3)]))) < sptol failed", warn=warn)
9090

9191
call check(all(eye(5) == diag([(1,i=1,5)])), &
9292
msg="all(eye(5) == diag([(1,i=1,5)] failed.",warn=warn)
9393

9494
rye = eye(6)
95-
call check(sum(rye - diag([(1.0_sp,i=1,6)])) < sptol, &
96-
msg="sum(rye - diag([(1.0_sp,i=1,6)])) < sptol failed.",warn=warn)
95+
call check(sum(abs(rye - diag([(1.0_sp,i=1,6)]))) < sptol, &
96+
msg="sum(abs(rye - diag([(1.0_sp,i=1,6)]))) < sptol failed.",warn=warn)
9797

9898
cye = eye(7)
9999
call check(abs(trace(cye) - cmplx(7.0_sp,0.0_sp,kind=sp)) < sptol, &

0 commit comments

Comments
 (0)