Skip to content

Commit 654e930

Browse files
committed
implement hermitian
1 parent 7511064 commit 654e930

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/stdlib_linalg.fypp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module stdlib_linalg
4848
public :: is_diagonal
4949
public :: is_symmetric
5050
public :: is_skew_symmetric
51+
public :: hermitian
5152
public :: is_hermitian
5253
public :: is_triangular
5354
public :: is_hessenberg
@@ -298,6 +299,31 @@ module stdlib_linalg
298299
#:endfor
299300
end interface is_hermitian
300301

302+
interface hermitian
303+
!! version: experimental
304+
!!
305+
!! Computes the Hermitian version of a rank-2 matrix.
306+
!! For complex matrices, this returns `conjg(transpose(a))`.
307+
!! For real or integer matrices, this returns `transpose(a)`.
308+
!!
309+
!! Usage:
310+
!! ```
311+
!! A = reshape([(1, 2), (3, 4), (5, 6), (7, 8)], [2, 2])
312+
!! AH = hermitian(A)
313+
!! ```
314+
!!
315+
!! [Specification](../page/specs/stdlib_linalg.html#hermitian)
316+
!!
317+
318+
#:for k1, t1 in RCI_KINDS_TYPES
319+
module function hermitian_${t1[0]}$${k1}$(a) result(ah)
320+
${t1}$, intent(in) :: a(:,:)
321+
${t1}$ :: ah(size(a, 2), size(a, 1))
322+
end function hermitian_${t1[0]}$${k1}$
323+
#:endfor
324+
325+
end interface hermitian
326+
301327

302328
! Check for triangularity
303329
interface is_triangular
@@ -1471,6 +1497,17 @@ contains
14711497
end function is_hermitian_${t1[0]}$${k1}$
14721498
#:endfor
14731499

1500+
#:for k1, t1 in RCI_KINDS_TYPES
1501+
pure module function hermitian_${t1[0]}$${k1}$(a) result(ah)
1502+
${t1}$, intent(in) :: a(:,:)
1503+
${t1}$ :: ah(size(a, 2), size(a, 1))
1504+
#:if t1.startswith('complex')
1505+
ah = conjg(transpose(a))
1506+
#:else
1507+
ah = transpose(a)
1508+
#:endif
1509+
end function hermitian_${t1[0]}$${k1}$
1510+
#:endfor
14741511

14751512
#:for k1, t1 in RCI_KINDS_TYPES
14761513
function is_triangular_${t1[0]}$${k1}$(A,uplo) result(res)
@@ -1546,4 +1583,5 @@ contains
15461583
end function is_hessenberg_${t1[0]}$${k1}$
15471584
#:endfor
15481585

1586+
15491587
end module stdlib_linalg

0 commit comments

Comments
 (0)