Skip to content

Commit 9a37e13

Browse files
committed
Turned-on complex-valued tests.
1 parent f6a2c88 commit 9a37e13

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

test/linalg/test_linalg_specialmatrices.fypp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#:include "common.fypp"
22
#:set R_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES, REAL_SUFFIX))
3-
#:set KINDS_TYPES = R_KINDS_TYPES
3+
#:set C_KINDS_TYPES = list(zip(CMPLX_KINDS, CMPLX_TYPES, CMPLX_SUFFIX))
4+
#:set KINDS_TYPES = R_KINDS_TYPES+C_KINDS_TYPES
45
module test_specialmatrices
56
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
67
use stdlib_kinds
8+
use stdlib_constants
79
use stdlib_linalg, only: hermitian
810
use stdlib_linalg_state, only: linalg_state_type
911
use stdlib_math, only: all_close
@@ -41,17 +43,33 @@ contains
4143
integer, parameter :: n = 5
4244
type(tridiagonal_${s1}$_type) :: A
4345
${t1}$, allocatable :: Amat(:,:), dl(:), dv(:), du(:)
46+
#: if t1.startswith('complex')
47+
real(wp), allocatable :: data(:, :)
48+
#:endif
4449
${t1}$, allocatable :: x(:)
4550
${t1}$, allocatable :: y1(:), y2(:)
4651

4752
! Initialize matrix.
4853
allocate(dl(n-1), dv(n), du(n-1))
54+
#:if t1.startswith('real')
4955
call random_number(dl) ; call random_number(dv) ; call random_number(du)
56+
#:else
57+
allocate(data(n, 2))
58+
call random_number(data) ; dl%re = data(:n-1, 1) ; dl%im = data(:n-1, 2)
59+
call random_number(data) ; dv%re = data(:n, 1) ; dv%im = data(:n, 2)
60+
call random_number(data) ; du%re = data(:n-1, 1) ; du%im = data(:n-1, 2)
61+
#:endif
5062
A = tridiagonal(dl, dv, du) ; Amat = dense(A)
5163

5264
! Random vectors.
65+
#:if t1.startswith('real')
5366
allocate(x(n), source = 0.0_wp) ; call random_number(x)
5467
allocate(y1(n), source = 0.0_wp) ; allocate(y2(n), source=0.0_wp)
68+
#:else
69+
allocate(x(n), source=zero_c${k1}$)
70+
call random_number(data) ; x%re = data(:, 1) ; x%im = data(:, 2)
71+
allocate(y1(n), source = zero_c${k1}$) ; allocate(y2(n), source=zero_c${k1}$)
72+
#:endif
5573

5674
! Test y = A @ x
5775
y1 = matmul(Amat, x) ; call spmv(A, x, y2)
@@ -117,33 +135,51 @@ contains
117135
integer, parameter :: n = 5
118136
type(symtridiagonal_${s1}$_type) :: A
119137
${t1}$, allocatable :: Amat(:,:), dv(:), ev(:)
138+
#:if t1.startswith('complex')
139+
real(wp), allocatable :: data(:, :)
140+
#:endif
120141
${t1}$, allocatable :: x(:)
121142
${t1}$, allocatable :: y1(:), y2(:)
122143

123144
! Initialize matrix.
124145
allocate(ev(n-1), dv(n))
146+
#:if t1.startswith('real')
125147
call random_number(dv) ; call random_number(ev)
148+
#:else
149+
allocate(data(n, 2), source=0.0_wp)
150+
call random_number(data) ; dv%re = data(:, 1) ; dv%im = data(:, 2)
151+
call random_number(data) ; ev%re = data(:n-1, 1) ; ev%im = data(:n-1, 2)
152+
#:endif
126153
A = symtridiagonal(dv, ev) ; Amat = dense(A)
127154

128155
! Random vectors.
156+
#:if t1.startswith('real')
129157
allocate(x(n), source = 0.0_wp) ; call random_number(x)
130158
allocate(y1(n), source = 0.0_wp) ; allocate(y2(n), source=0.0_wp)
159+
#:else
160+
allocate(x(n), source=zero_c${k1}$)
161+
call random_number(data) ; x%re = data(:, 1) ; x%im = data(:, 2)
162+
allocate(y1(n), source = zero_c${k1}$) ; allocate(y2(n), source=zero_c${k1}$)
163+
#:endif
131164

132165
! Test y = A @ x
133166
y1 = matmul(Amat, x) ; call spmv(A, x, y2)
167+
print *, "matvec :", all_close(y1, y2)
134168
call check(error, all_close(y1, y2), .true.)
135169
if (allocated(error)) return
136170

137171
! Test y = A.T @ x
138172
y1 = 0.0_wp ; y2 = 0.0_wp
139173
y1 = matmul(transpose(Amat), x) ; call spmv(A, x, y2, op="T")
174+
print *, "tranposed matvec :", all_close(y1, y2)
140175
call check(error, all_close(y1, y2), .true.)
141176
if (allocated(error)) return
142177

143178
#:if t1.startswith('complex')
144179
! Test y = A.H @ x
145180
y1 = 0.0_wp ; y2 = 0.0_wp
146181
y1 = matmul(hermitian(Amat), x) ; call spmv(A, x, y2, op="H")
182+
print *, "hermitian matvec :", all_close(y1, y2)
147183
call check(error, all_close(y1, y2), .true.)
148184
if (allocated(error)) return
149185
#:endif

0 commit comments

Comments
 (0)