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
`dim1`: Shall be a scalar of default type `integer`.
251
-
This is an `intent(in)` argument.
252
-
253
-
`dim2`: Shall be a scalar of default type `integer`.
254
-
This is an `intent(in)` and `optional` argument.
250
+
-`dim1`: A scalar of type `integer`. This is an `intent(in)` argument and specifies the number of rows.
251
+
-`dim2`: A scalar of type `integer`. This is an optional `intent(in)` argument specifying the number of columns. If not provided, the matrix is square (`dim1 = dim2`).
252
+
-`mold`: A scalar of any supported `integer`, `real`, or `complex` type. This is an optional `intent(in)` argument. If provided, the returned identity matrix will have the same type and kind as `mold`. If not provided, the matrix will be of type `integer(int8)` by default.
255
253
256
254
### Return value
257
255
258
-
Return the identity matrix, i.e. a matrix with ones on the main diagonal and zeros elsewhere. The return value is of type `integer(int8)`.
259
-
The use of `int8` was suggested to save storage.
256
+
Returns the identity matrix, with ones on the main diagonal and zeros elsewhere.
257
+
258
+
- By default, the return value is of type `integer(int8)`, which is recommended for storage efficiency.
259
+
- If the `mold` argument is provided, the return value will match the type and kind of `mold`, allowing for arbitrary `integer`, `real`, or `complex` return types.
260
260
261
261
#### Warning
262
262
263
-
Since the result of `eye` is of `integer(int8)` type, one should be careful about using it in arithmetic expressions. For example:
263
+
When using the default `integer(int8)` type, be cautious when performing arithmetic operations, as integer division may occur. For example:
264
+
264
265
```fortran
265
-
!> Be careful
266
-
A = eye(2,2)/2 !! A == 0.0
267
-
!> Recommend
268
-
A = eye(2,2)/2.0 !! A == diag([0.5, 0.5])
266
+
!> Caution: default type is `integer`
267
+
A = eye(2,2)/2 !! A == 0.0 due to integer division
268
+
!> Recommend using a non-integer type for division
0 commit comments