Skip to content

Commit dfe4465

Browse files
committed
python: improve testing of modeord option
Integrate it into the matrix of tests for type 1 and add it for the type 2 tests as well.
1 parent 180029d commit dfe4465

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

python/finufft/test/test_finufft_plan.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
N_PTS = [10, 11]
1313
DTYPES = [np.complex64, np.complex128]
1414
OUTPUT_ARGS = [False, True]
15+
MODEORDS = [0, 1]
1516

1617

1718
@pytest.mark.parametrize("dtype", DTYPES)
1819
@pytest.mark.parametrize("shape", SHAPES)
1920
@pytest.mark.parametrize("n_pts", N_PTS)
2021
@pytest.mark.parametrize("output_arg", OUTPUT_ARGS)
21-
def test_finufft1_plan(dtype, shape, n_pts, output_arg):
22+
@pytest.mark.parametrize("modeord", MODEORDS)
23+
def test_finufft1_plan(dtype, shape, n_pts, output_arg, modeord):
2224
pts, coefs = utils.type1_problem(dtype, shape, n_pts)
2325

24-
plan = Plan(1, shape, dtype=dtype)
26+
plan = Plan(1, shape, dtype=dtype, modeord=modeord)
2527

2628
plan.setpts(*pts)
2729

@@ -31,25 +33,34 @@ def test_finufft1_plan(dtype, shape, n_pts, output_arg):
3133
sig = np.empty(shape, dtype=dtype)
3234
plan.execute(coefs, out=sig)
3335

36+
if modeord == 1:
37+
sig = np.fft.fftshift(sig)
38+
3439
utils.verify_type1(pts, coefs, shape, sig, 1e-6)
3540

3641

3742
@pytest.mark.parametrize("dtype", DTYPES)
3843
@pytest.mark.parametrize("shape", SHAPES)
3944
@pytest.mark.parametrize("n_pts", N_PTS)
4045
@pytest.mark.parametrize("output_arg", OUTPUT_ARGS)
41-
def test_finufft2_plan(dtype, shape, n_pts, output_arg):
46+
@pytest.mark.parametrize("modeord", MODEORDS)
47+
def test_finufft2_plan(dtype, shape, n_pts, output_arg, modeord):
4248
pts, sig = utils.type2_problem(dtype, shape, n_pts)
4349

44-
plan = Plan(2, shape, dtype=dtype)
50+
plan = Plan(2, shape, dtype=dtype, modeord=modeord)
4551

4652
plan.setpts(*pts)
4753

54+
if modeord == 1:
55+
_sig = np.fft.ifftshift(sig)
56+
else:
57+
_sig = sig
58+
4859
if not output_arg:
49-
coefs = plan.execute(sig)
60+
coefs = plan.execute(_sig)
5061
else:
5162
coefs = np.empty(n_pts, dtype=dtype)
52-
plan.execute(sig, out=coefs)
63+
plan.execute(_sig, out=coefs)
5364

5465
utils.verify_type2(pts, sig, coefs, 1e-6)
5566

@@ -76,24 +87,6 @@ def test_finufft3_plan(dtype, dim, n_source_pts, n_target_pts, output_arg):
7687
utils.verify_type3(source_pts, source_coefs, target_pts, target_coefs, 1e-6)
7788

7889

79-
def test_finufft_plan_modeord():
80-
dtype = "complex64"
81-
shape = (8, 8)
82-
n_pts = 17
83-
84-
plan = Plan(1, shape, dtype=dtype, modeord=1)
85-
86-
pts, coefs = utils.type1_problem(dtype, shape, n_pts)
87-
88-
plan.setpts(*pts)
89-
90-
sig = plan.execute(coefs)
91-
92-
sig = np.fft.fftshift(sig)
93-
94-
utils.verify_type1(pts, coefs, shape, sig, 1e-6)
95-
96-
9790
def test_finufft_plan_errors():
9891
with pytest.raises(RuntimeError, match="must be single or double"):
9992
Plan(1, (8, 8), dtype="uint32")

0 commit comments

Comments
 (0)