Skip to content

Commit 7d39a38

Browse files
committed
Original test suite for dcost.
1 parent 6098a60 commit 7d39a38

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/test_fftpack_original.f90

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ subroutine collect_original(testsuite)
1818
testsuite = [new_unittest("dfft", test_dfft)]
1919
testsuite = [testsuite, new_unittest("zfft", test_zfft)]
2020
testsuite = [testsuite, new_unittest("sint", test_sint)]
21+
testsuite = [testsuite, new_unittest("cost", test_cost)]
2122
end subroutine collect_original
2223

2324
subroutine test_dfft(error)
@@ -229,6 +230,61 @@ subroutine test_sint(error)
229230
if (allocated(error)) return
230231
end do
231232
end subroutine test_sint
233+
234+
subroutine test_cost(error)
235+
type(error_type), allocatable, intent(out) :: error
236+
real(rk) :: x(200), y(200), xh(200), w(2000)
237+
integer :: i, j, k, n, np1, nm1, ns2, nz, modn
238+
real(rk) :: dt, sum1, sum2, arg, arg1
239+
real(rk) :: mismatch, cf
240+
241+
do nz = 1, size(nd)
242+
!> Create multisine signal.
243+
n = nd(nz)
244+
modn = mod(n, 2)
245+
np1 = n + 1; nm1 = n - 1
246+
do j = 1, np1
247+
x(j) = sin(j*sqrt(2.0_rk))
248+
y(j) = x(j)
249+
xh(j) = x(j)
250+
end do
251+
252+
!> Discrete sine transform.
253+
dt = pi/n
254+
do i = 1, np1
255+
x(i) = xh(i)
256+
end do
257+
258+
do i = 1, np1
259+
y(i) = 0.5_rk*(x(1) + (-1)**(i + 1)*x(n + 1))
260+
arg = (i - 1)*dt
261+
do k = 2, n
262+
y(i) = y(i) + cos((k - 1)*arg)*x(k)
263+
end do
264+
y(i) = 2*y(i)
265+
end do
266+
267+
!> Fast Sine Transform.
268+
call dcosti(np1, w)
269+
call dcost(np1, x, w)
270+
271+
!> Check error.
272+
cf = 0.5_rk/n
273+
mismatch = maxval(abs(x(:np1) - y(:np1)))*cf
274+
call check(error, mismatch < rtol)
275+
if (allocated(error)) return
276+
277+
!> Chain direct and inverse sine transform.
278+
x(:np1) = xh(:np1); y(:np1) = x(:np1) ! Restore signals.
279+
call dcost(np1, x, w)
280+
call dcost(np1, x, w)
281+
282+
!> Check error.
283+
mismatch = maxval(abs(cf*x(:nm1) - y(:nm1)))
284+
call check(error, mismatch < rtol)
285+
if (allocated(error)) return
286+
end do
287+
end subroutine test_cost
232288
end module test_fftpack_original
233289

234290
program test_original

0 commit comments

Comments
 (0)