@@ -188,6 +188,16 @@ module stdlib_linalg
188188 #:endfor
189189 end interface
190190
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
191201
192202 ! Outer product (of two vectors)
193203 interface outer_product
@@ -1327,24 +1337,27 @@ contains
13271337 !>
13281338 !> Constructs the identity matrix.
13291339 !> ([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)
13311342
13321343 integer, intent(in) :: dim1
13331344 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(:, :)
13351347
13361348 integer :: dim2_
13371349 integer :: i
13381350
13391351 dim2_ = optval(dim2, dim1)
13401352 allocate(result(dim1, dim2_))
13411353
1342- result = 0_int8
1354+ result = 0
13431355 do i = 1, min(dim1, dim2_)
1344- result(i, i) = 1_int8
1356+ result(i, i) = 1
13451357 end do
13461358
1347- end function eye
1359+ end function eye_${t1[0]}$${k1}$
1360+ #:endfor
13481361
13491362 #:for k1, t1 in RCI_KINDS_TYPES
13501363 function trace_${t1[0]}$${k1}$(A) result(res)
0 commit comments