Skip to content

Commit 8745725

Browse files
committed
Improve eye function help docs.
1 parent ebc61cd commit 8745725

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,43 @@ 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+
124128
### Return value
125129

126-
Returns the identity matrix, i.e. a square matrix with ones on the main diagonal and zeros elsewhere. The return value is of type `integer`.
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`.
131+
132+
#### Warning
133+
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:
137+
```fortran
138+
real :: A(:,:)
139+
!> Be careful
140+
A = eye(2,2)/2 !! A == 0.0
141+
!> Recommend
142+
A = eye(2,2)/2.0 !! A == diag([0.5, 0.5])
143+
```
127144

128145
### Example
129146

130147
```fortran
131148
program demo_eye1
132149
use stdlib_linalg, only: eye
133150
implicit none
151+
integer :: i(2,2)
134152
real :: a(3,3)
135-
real :: b(3,4)
136-
A = eye(3)
137-
A = eye(3,3)
138-
B = eye(3,4)
153+
real :: b(2,3) !! Matrix is non-square.
154+
complex :: c(2,2)
155+
I = eye(2) !! [1,0; 0,1]
156+
A = eye(3) !! [1.0,0.0,0.0; 0.0,1.0,0.0; 0.0,0.0,1.0]
157+
A = eye(3,3) !! [1.0,0.0,0.0; 0.0,1.0,0.0; 0.0,0.0,1.0]
158+
B = eye(2,3) !! [1.0,0.0,0.0; 0.0,1.0,0.0]
159+
C = eye(2,2) !! [(1.0,0.0),(0.0,0.0); (0.0,0.0),(1.0,0.0)]
160+
C = (1.0,1.0)*eye(2,2) !! [(1.0,1.0),(0.0,0.0); (0.0,0.0),(1.0,1.0)]
139161
end program demo_eye1
140162
```
141163

0 commit comments

Comments
 (0)