Skip to content

Commit c326353

Browse files
committed
Update eye func: integer(int8)
1 parent c20f69f commit c326353

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,12 @@ This is an `intent(in)` and `optional` argument.
123123

124124
### Return value
125125

126-
Return the identity matrix, i.e. a matrix with ones on the main diagonal and zeros elsewhere. The return value is of type `integer`.
126+
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)`.
127+
The use of `int8` was suggested to save storage.
127128

128129
#### Warning
129130

130-
Since the result of `eye` is of `integer` type, one should be careful about using it in arithmetic expressions. For example:
131+
Since the result of `eye` is of `integer(int8)` type, one should be careful about using it in arithmetic expressions. For example:
131132
```fortran
132133
real :: A(:,:)
133134
!> Be careful

src/stdlib_linalg.fypp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ contains
9191

9292
integer, intent(in) :: dim1
9393
integer, intent(in), optional :: dim2
94-
integer, allocatable :: result(:, :)
94+
integer(int8), allocatable :: result(:, :)
9595

9696
integer :: dim2_
9797
integer :: i
9898

9999
dim2_ = optval(dim2, dim1)
100100
allocate(result(dim1, dim2_))
101101

102-
result = 0
102+
result = 0_int8
103103
do i = 1, min(dim1, dim2_)
104-
result(i, i) = 1
104+
result(i, i) = 1_int8
105105
end do
106106

107107
end function eye

0 commit comments

Comments
 (0)