Skip to content

Commit f026097

Browse files
committed
eye: update documentation
1 parent 54c9ca1 commit f026097

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -239,33 +239,34 @@ Pure function.
239239

240240
### Description
241241

242-
Construct the identity matrix.
242+
Constructs the identity matrix.
243243

244244
### Syntax
245245

246-
`I = ` [[stdlib_linalg(module):eye(function)]] `(dim1 [, dim2])`
246+
`I = ` [[stdlib_linalg(module):eye(function)]] `(dim1 [, dim2] [, mold])`
247247

248248
### Arguments
249249

250-
`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.
255253

256254
### Return value
257255

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.
260260

261261
#### Warning
262262

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+
264265
```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
269+
A = eye(2,2, mold=1.0)/2 !! A == diag([0.5, 0.5])
269270
```
270271

271272
### Example

0 commit comments

Comments
 (0)