You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/specs/stdlib_linalg.md
+27-5Lines changed: 27 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -121,21 +121,43 @@ This is an `intent(in)` argument.
121
121
`dim2`: Shall be a scalar of default type `integer`.
122
122
This is an `intent(in)` and `optional` argument.
123
123
124
+
#### Note
125
+
126
+
Because of `huge(integer :: i) = 2147483647`, the dimensional maximum length of array created by the `eye` function is `2147483647`.
127
+
124
128
### Return value
125
129
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
+
```
127
144
128
145
### Example
129
146
130
147
```fortran
131
148
program demo_eye1
132
149
use stdlib_linalg, only: eye
133
150
implicit none
151
+
integer :: i(2,2)
134
152
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)]
0 commit comments