@@ -188,6 +188,16 @@ module stdlib_linalg
188
188
#:endfor
189
189
end interface
190
190
191
+ ! Identity matrix
192
+ interface eye
193
+ !! version: experimental
194
+ !!
195
+ !! Constructs the identity matrix
196
+ !! ([Specification](../page/specs/stdlib_linalg.html#eye-construct-the-identity-matrix))
197
+ #:for k1, t1 in RCI_KINDS_TYPES
198
+ module procedure eye_${t1[0]}$${k1}$
199
+ #:endfor
200
+ end interface eye
191
201
192
202
! Outer product (of two vectors)
193
203
interface outer_product
@@ -1327,24 +1337,27 @@ contains
1327
1337
!>
1328
1338
!> Constructs the identity matrix.
1329
1339
!> ([Specification](../page/specs/stdlib_linalg.html#eye-construct-the-identity-matrix))
1330
- pure function eye(dim1, dim2) result(result)
1340
+ #:for k1, t1 in RCI_KINDS_TYPES
1341
+ pure function eye_${t1[0]}$${k1}$(dim1, dim2, mold) result(result)
1331
1342
1332
1343
integer, intent(in) :: dim1
1333
1344
integer, intent(in), optional :: dim2
1334
- integer(int8), allocatable :: result(:, :)
1345
+ ${t1}$, intent(in) #{if not 'int8' in t1}#, optional #{endif}#:: mold
1346
+ ${t1}$, allocatable :: result(:, :)
1335
1347
1336
1348
integer :: dim2_
1337
1349
integer :: i
1338
1350
1339
1351
dim2_ = optval(dim2, dim1)
1340
1352
allocate(result(dim1, dim2_))
1341
1353
1342
- result = 0_int8
1354
+ result = 0
1343
1355
do i = 1, min(dim1, dim2_)
1344
- result(i, i) = 1_int8
1356
+ result(i, i) = 1
1345
1357
end do
1346
1358
1347
- end function eye
1359
+ end function eye_${t1[0]}$${k1}$
1360
+ #:endfor
1348
1361
1349
1362
#:for k1, t1 in RCI_KINDS_TYPES
1350
1363
function trace_${t1[0]}$${k1}$(A) result(res)
0 commit comments