|
1 | 1 | import numpy as np |
| 2 | +import healpy as hp |
2 | 3 | import pytest |
3 | 4 | from jax import config |
| 5 | +from s2fft.sampling import s2_samples as samples |
4 | 6 | from s2fft.utils.healpix_ffts import ( |
5 | 7 | healpix_fft_jax, |
6 | 8 | healpix_fft_numpy, |
|
12 | 14 | config.update("jax_enable_x64", True) |
13 | 15 |
|
14 | 16 |
|
15 | | -@pytest.mark.parametrize("L", (32, 64)) |
16 | | -@pytest.mark.parametrize("nside", (4, 8, 16)) |
17 | | -@pytest.mark.parametrize("reality", (True, False)) |
18 | | -def test_healpix_fft_jax_numpy_consistency(rng, L, nside, reality): |
19 | | - f = rng.standard_normal(size=12 * nside**2) |
| 17 | +nside_to_test = [4, 5] |
| 18 | +reality_to_test = [False, True] |
| 19 | + |
| 20 | + |
| 21 | +@pytest.mark.parametrize("nside", nside_to_test) |
| 22 | +@pytest.mark.parametrize("reality", reality_to_test) |
| 23 | +def test_healpix_fft_jax_numpy_consistency(flm_generator, nside, reality): |
| 24 | + L = 2 * nside |
| 25 | + # Generate a random bandlimited signal |
| 26 | + flm = flm_generator(L=L, reality=reality) |
| 27 | + flm_hp = samples.flm_2d_to_hp(flm, L) |
| 28 | + f = hp.sphtfunc.alm2map(flm_hp, nside, lmax=L - 1) |
| 29 | + # Test consistency |
20 | 30 | assert np.allclose( |
21 | 31 | healpix_fft_numpy(f, L, nside, reality), healpix_fft_jax(f, L, nside, reality) |
22 | 32 | ) |
23 | 33 |
|
24 | 34 |
|
25 | | -@pytest.mark.parametrize("L", (32, 64)) |
26 | | -@pytest.mark.parametrize("nside", (4, 8, 16)) |
27 | | -@pytest.mark.parametrize("reality", (True, False)) |
28 | | -def test_healpix_ifft_jax_numpy_consistency(rng, L, nside, reality): |
29 | | - ftm = healpix_fft_numpy( |
30 | | - rng.standard_normal(size=12 * nside**2), L, nside, reality |
31 | | - ) |
| 35 | +@pytest.mark.parametrize("nside", nside_to_test) |
| 36 | +@pytest.mark.parametrize("reality", reality_to_test) |
| 37 | +def test_healpix_ifft_jax_numpy_consistency(flm_generator, nside, reality): |
| 38 | + L = 2 * nside |
| 39 | + # Generate a random bandlimited signal |
| 40 | + flm = flm_generator(L=L, reality=reality) |
| 41 | + flm_hp = samples.flm_2d_to_hp(flm, L) |
| 42 | + f = hp.sphtfunc.alm2map(flm_hp, nside, lmax=L - 1) |
| 43 | + ftm = healpix_fft_numpy(f, L, nside, reality) |
| 44 | + ftm_copy = np.copy(ftm) |
| 45 | + # Test consistency |
32 | 46 | assert np.allclose( |
33 | 47 | healpix_ifft_numpy(ftm, L, nside, reality), |
34 | | - healpix_ifft_jax(ftm, L, nside, reality), |
| 48 | + healpix_ifft_jax(ftm_copy, L, nside, reality), |
35 | 49 | ) |
0 commit comments