Skip to content

Commit 02ec1d9

Browse files
author
Thomas Baumann
committed
Added tests for serial GPU transforms
1 parent e23e07a commit 02ec1d9

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

pySDC/helpers/spectral_helper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ def transform(self, u, *args, axes=None, shape=None, **kwargs):
416416
Returns:
417417
Data in spectral space
418418
"""
419-
assert self.fft_lib == scipy.fft
420419
axes = axes if axes else tuple(i for i in range(u.ndim))
421420

422421
trf = self.fft_lib.dctn(u, *args, axes=axes, type=2, norm='backward', s=shape, **kwargs)
@@ -459,7 +458,7 @@ def transform(self, u, *args, axes=None, shape=None, **kwargs):
459458
trf *= norm[(*expansion,)]
460459
return trf
461460

462-
def itransform(self, u, axes, *args, shape=None, **kwargs):
461+
def itransform(self, u, *args, axes=None, shape=None, **kwargs):
463462
"""
464463
Inverse DCT along axis.
465464
@@ -470,7 +469,7 @@ def itransform(self, u, axes, *args, shape=None, **kwargs):
470469
Returns:
471470
Data in physical space
472471
"""
473-
assert self.fft_lib == scipy.fft
472+
axes = axes if axes else tuple(i for i in range(u.ndim))
474473
for axis in axes:
475474

476475
if self.N == u.shape[axis]:

pySDC/tests/test_helpers/test_spectral_helper_1d_chebychev.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,24 @@ def test_transform(N, d):
163163
assert np.allclose(cheby.itransform(cheby.transform(u, axes=(-1,)), axes=(-1,)), u)
164164

165165

166+
@pytest.mark.cupy
167+
def test_transform_cupy(N=8):
168+
import numpy as np
169+
import cupy as cp
170+
from pySDC.helpers.spectral_helper import ChebychevHelper
171+
172+
u = cp.random.random(N).astype('D')
173+
174+
helper_CPU = ChebychevHelper(N=N, useGPU=False)
175+
u_hat_CPU = helper_CPU.transform(u.get())
176+
177+
helper = ChebychevHelper(N=N, useGPU=True)
178+
u_hat = helper.transform(u)
179+
180+
assert cp.allclose(u, helper.itransform(u_hat))
181+
assert np.allclose(u_hat.get(), u_hat_CPU)
182+
183+
166184
@pytest.mark.base
167185
@pytest.mark.parametrize('N', [8, 32])
168186
def test_integration_BC(N):
@@ -402,4 +420,4 @@ def test_tau_method2D_diffusion(nz, nx, bc_val, plotting=False):
402420

403421

404422
if __name__ == '__main__':
405-
test_transform(4, 1, 'dct')
423+
test_transform_cupy()

pySDC/tests/test_helpers/test_spectral_helper_1d_fft.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ def test_transform(useFFTW, N=8):
5656
assert np.allclose(u, helper.itransform(u_hat))
5757

5858

59+
@pytest.mark.cupy
60+
def test_transform_cupy(N=8):
61+
import numpy as np
62+
import cupy as cp
63+
from pySDC.helpers.spectral_helper import FFTHelper
64+
65+
u = cp.random.random(N).astype('D')
66+
67+
helper_CPU = FFTHelper(N=N, useGPU=False)
68+
u_hat_CPU = helper_CPU.transform(u.get())
69+
70+
helper = FFTHelper(N=N, useGPU=True)
71+
u_hat = helper.transform(u)
72+
73+
assert np.allclose(u_hat.get(), u_hat_CPU)
74+
assert cp.allclose(u, helper.itransform(u_hat))
75+
76+
5977
@pytest.mark.base
6078
@pytest.mark.parametrize('N', [8, 64])
6179
def test_integration_matrix(N, plot=False):
@@ -120,5 +138,6 @@ def test_tau_method(N, v):
120138
# test_differentiation_matrix(64, 4, 8, True, True)
121139
# test_integration_matrix(8, True)
122140
# test_tau_method(6, 1)
123-
test_transform(True)
124-
test_transform(False)
141+
# test_transform(True)
142+
# test_transform(False)
143+
test_transform_cupy()

0 commit comments

Comments
 (0)