|
4 | 4 | module test_linalg
|
5 | 5 | use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
|
6 | 6 | 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 |
8 | 8 | use stdlib_linalg_state, only: linalg_state_type, LINALG_SUCCESS, linalg_error_handling
|
9 | 9 |
|
10 | 10 | implicit none
|
@@ -52,6 +52,9 @@ contains
|
52 | 52 | new_unittest("trace_int64", test_trace_int64), &
|
53 | 53 | #:for k1, t1 in RCI_KINDS_TYPES
|
54 | 54 | 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}$), & |
55 | 58 | #:endfor
|
56 | 59 | new_unittest("outer_product_rsp", test_outer_product_rsp), &
|
57 | 60 | new_unittest("outer_product_rdp", test_outer_product_rdp), &
|
@@ -597,6 +600,32 @@ contains
|
597 | 600 | end subroutine test_kronecker_product_${t1[0]}$${k1}$
|
598 | 601 | #:endfor
|
599 | 602 |
|
| 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 | + |
600 | 629 | subroutine test_outer_product_rsp(error)
|
601 | 630 | !> Error handling
|
602 | 631 | type(error_type), allocatable, intent(out) :: error
|
|
0 commit comments