Constructs the identity matrix. (Specification)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | dim1 | |||
integer, | intent(in), | optional | :: | dim2 |
pure function eye(dim1, dim2) result(result) integer, intent(in) :: dim1 integer, intent(in), optional :: dim2 integer(int8), allocatable :: result(:, :) integer :: dim2_ integer :: i dim2_ = optval(dim2, dim1) allocate(result(dim1, dim2_)) result = 0_int8 do i = 1, min(dim1, dim2_) result(i, i) = 1_int8 end do end function eye