TriuIndx
Returns the indices of upper triangle part of a matrix.
Interface 1
- ܀ Interface
- ️܀ See example
- ↢
INTERFACE
MODULE PURE FUNCTION TriuIndx(m, n, diagNo) RESULT(ans)
INTEGER(I4B), INTENT(IN) :: m
!! number of rows
INTEGER(I4B), OPTIONAL, INTENT(IN) :: n
!! number of columns, default = m
INTEGER(I4B), OPTIONAL, INTENT(IN) :: diagNo
!! diagonal number, default = 0
!! diagNo>0 means super diagonal
!! diagNo<0 means subdiagonal
INTEGER(I4B), ALLOCATABLE :: ans(:, :)
!! ans(:,1) contains the row indices
!! ans(:,2) contains the col indices
END FUNCTION TriuIndx
END INTERFACE
program main
use easifemBase
implicit none
BLOCK
INTEGER(I4B), ALLOCATABLE :: indx(:,:)
CALL Display(TriuIndx(m=3,n=3,diagNo=0), "(3,3) diagNo=0, = " )
CALL Display(TriuIndx(m=3,n=3,diagNo=1), "(3,3) diagNo=1, = " )
CALL Display(TriuIndx(m=3,n=3,diagNo=2), "(3,3) diagNo=2, = " )
END BLOCK
See results
(3,3) diagNo=0, =
------------------
1 1
2 2
3 3
1 2
2 3
1 3
(3,3) diagNo=1, =
------------------
1 2
2 3
1 3
(3,3) diagNo=2, =
------------------
1 3
BLOCK
CALL Display(TriuIndx(m=3,n=3,diagNo=-1), "(3,3) diagNo=-1, = " )
CALL Display(TriuIndx(m=3,n=3,diagNo=-2), "(3,3) diagNo=-2, = " )
END BLOCK
See results
(3,3) diagNo=-1, =
-------------------
2 1
3 2
1 1
2 2
3 3
1 2
2 3
1 3
(3,3) diagNo=-2, =
-------------------
3 1
2 1
3 2
1 1
2 2
3 3
1 2
2 3
1 3
end program main
Interface 2
- ܀ Interface
- ️܀ See example
- ↢
INTERFACE
MODULE PURE FUNCTION TriuIndx(A, diagNo) RESULT(ans)
CLASS(*), INTENT(IN) :: A(:, :)
INTEGER(I4B), OPTIONAL, INTENT(IN) :: diagNo
!! diagonal number, default = 0
!! diagNo>0 means super diagonal
!! diagNo<0 means subdiagonal
INTEGER(I4B), ALLOCATABLE :: ans(:, :)
!! ans(:,1) contains the row indices
!! ans(:,2) contains the col indices
END FUNCTION TriuIndx
END INTERFACE
program main
use easifemBase
implicit none
INTEGER(I4B), ALLOCATABLE :: indx(:,:)
REAL( DFP ) :: amat(3,3)
CALL Display(TriuIndx(amat,diagNo=0), "(3,3) diagNo=0, = " )
CALL Display(TriuIndx(amat,diagNo=1), "(3,3) diagNo=1, = " )
CALL Display(TriuIndx(amat,diagNo=2), "(3,3) diagNo=2, = " )
CALL Display(TriuIndx(amat,diagNo=-1), "(3,3) diagNo=-1, = " )
CALL Display(TriuIndx(amat,diagNo=-2), "(3,3) diagNo=-2, = " )
See results
(3,3) diagNo=0, =
------------------
1 1
2 2
3 3
1 2
2 3
1 3
(3,3) diagNo=1, =
------------------
1 2
2 3
1 3
(3,3) diagNo=2, =
------------------
1 3
(3,3) diagNo=-1, =
-------------------
2 1
3 2
1 1
2 2
3 3
1 2
2 3
1 3
(3,3) diagNo=-2, =
-------------------
3 1
2 1
3 2
1 1
2 2
3 3
1 2
2 3
1 3
end program main