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
+7-11Lines changed: 7 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -249,28 +249,24 @@ Constructs the identity matrix.
249
249
250
250
-`dim1`: A scalar of type `integer`. This is an `intent(in)` argument and specifies the number of rows.
251
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.
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 `real(real64)` by default.
253
253
254
254
### Return value
255
255
256
256
Returns the identity matrix, with ones on the main diagonal and zeros elsewhere.
257
257
258
-
- By default, the return value is of type `integer(int8)`, which is recommended for storage efficiency.
258
+
- By default, the return value is of type `real(real64)`, which is recommended for arithmetic safety.
259
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
-
#### Warning
262
-
263
-
When using the default `integer(int8)` type, be cautious when performing arithmetic operations, as integer division may occur. For example:
261
+
### Example
264
262
265
263
```fortran
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
269
-
A = eye(2,2, mold=1.0)/2 !! A == diag([0.5,0.5])
264
+
!> Return default type (real64)
265
+
A = eye(2,2)/2 !! A == diag([0.5_dp, 0.5_dp])
266
+
!> Return 32-bit complex
267
+
A = eye(2,2, mold=(0.0,0.0))/2 !! A == diag([(0.5,0.5), (0.5,0.5)])
0 commit comments