Skip to content

Commit 58392f1

Browse files
committed
add test
1 parent 0c30db1 commit 58392f1

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

example/linalg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ADD_EXAMPLE(diag5)
66
ADD_EXAMPLE(eye1)
77
ADD_EXAMPLE(eye2)
88
ADD_EXAMPLE(is_diagonal)
9+
ADD_EXAMPLE(hermitian)
910
ADD_EXAMPLE(is_hermitian)
1011
ADD_EXAMPLE(is_hessenberg)
1112
ADD_EXAMPLE(is_skew_symmetric)

src/stdlib_linalg.fypp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ module stdlib_linalg
316316
!!
317317

318318
#:for k1, t1 in RCI_KINDS_TYPES
319-
module function hermitian_${t1[0]}$${k1}$(a) result(ah)
319+
pure module function hermitian_${t1[0]}$${k1}$(a) result(ah)
320320
${t1}$, intent(in) :: a(:,:)
321321
${t1}$ :: ah(size(a, 2), size(a, 1))
322322
end function hermitian_${t1[0]}$${k1}$

test/linalg/test_linalg.fypp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module test_linalg
55
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
66
use stdlib_kinds, only: sp, dp, xdp, qp, int8, int16, int32, int64
7-
use stdlib_linalg, only: diag, eye, trace, outer_product, cross_product, kronecker_product
7+
use stdlib_linalg, only: diag, eye, trace, outer_product, cross_product, kronecker_product, hermitian
88
use stdlib_linalg_state, only: linalg_state_type, LINALG_SUCCESS, linalg_error_handling
99

1010
implicit none
@@ -52,6 +52,9 @@ contains
5252
new_unittest("trace_int64", test_trace_int64), &
5353
#:for k1, t1 in RCI_KINDS_TYPES
5454
new_unittest("kronecker_product_${t1[0]}$${k1}$", test_kronecker_product_${t1[0]}$${k1}$), &
55+
#:endfor
56+
#:for k1, t1 in CMPLX_KINDS_TYPES
57+
new_unittest("hermitian_${t1[0]}$${k1}$", test_hermitian_${t1[0]}$${k1}$), &
5558
#:endfor
5659
new_unittest("outer_product_rsp", test_outer_product_rsp), &
5760
new_unittest("outer_product_rdp", test_outer_product_rdp), &
@@ -597,6 +600,32 @@ contains
597600
end subroutine test_kronecker_product_${t1[0]}$${k1}$
598601
#:endfor
599602

603+
#:for k1, t1 in CMPLX_KINDS_TYPES
604+
subroutine test_hermitian_${t1[0]}$${k1}$(error)
605+
!> Error handling
606+
type(error_type), allocatable, intent(out) :: error
607+
integer, parameter :: m = 2, n = 3
608+
${t1}$, dimension(m,n) :: A
609+
${t1}$, dimension(n,m) :: AT, expected, diff
610+
real(${k1}$), parameter :: tol = 1.e-6_${k1}$
611+
612+
integer :: i,j
613+
614+
do concurrent (i=1:m,j=1:n)
615+
A (i,j) = cmplx(i,-j,kind=${k1}$)
616+
expected(j,i) = cmplx(i,+j,kind=${k1}$)
617+
end do
618+
619+
620+
AT = hermitian(A)
621+
622+
diff = AT - expected
623+
624+
call check(error, all(abs(diff) < abs(tol)), "hermitian: all(abs(diff) < abs(tol)) failed")
625+
626+
end subroutine test_hermitian_${t1[0]}$${k1}$
627+
#:endfor
628+
600629
subroutine test_outer_product_rsp(error)
601630
!> Error handling
602631
type(error_type), allocatable, intent(out) :: error

0 commit comments

Comments
 (0)