diff --git a/glass/fields.py b/glass/fields.py index 5846c3e1..7cb8fc6d 100644 --- a/glass/fields.py +++ b/glass/fields.py @@ -417,7 +417,7 @@ def _generate_grf( alm = _glass_to_healpix_alm(alm) # modes with m = 0 are real-valued and come first in array - alm = xpx.at(alm)[:n].set(xp.real(alm[:n])[:] + xp.imag(alm[:n]) + 0j) + alm = xpx.at(alm)[:n].set(xp.real(alm[:n]) + xp.imag(alm[:n]) + 0j) # transform alm to maps # can be performed in place on the temporary alm array diff --git a/tests/benchmarks/test_fields.py b/tests/benchmarks/test_fields.py index e1d4eecf..0f8d9b3c 100644 --- a/tests/benchmarks/test_fields.py +++ b/tests/benchmarks/test_fields.py @@ -13,10 +13,10 @@ from types import ModuleType from typing import Any - from conftest import Compare, GeneratorConsumer from pytest_benchmark.fixture import BenchmarkFixture from glass._types import AngularPowerSpectra, UnifiedGenerator + from tests.fixtures.helper_classes import Compare, GeneratorConsumer @pytest.mark.stable @@ -31,7 +31,7 @@ def test_iternorm_no_size( def function_to_benchmark() -> list[Any]: generator = glass.iternorm(k, iter(array_in)) - return generator_consumer.consume( # type: ignore[no-any-return] + return generator_consumer.consume( generator, valid_exception="covariance matrix is not positive definite", ) @@ -77,7 +77,7 @@ def test_iternorm_specify_size( def function_to_benchmark() -> list[Any]: generator = glass.iternorm(k, iter(array_in), size) - return generator_consumer.consume( # type: ignore[no-any-return] + return generator_consumer.consume( generator, valid_exception="covariance matrix is not positive definite", ) @@ -112,7 +112,7 @@ def test_iternorm_k_0( def function_to_benchmark() -> list[Any]: generator = glass.iternorm(k, iter(array_in)) - return generator_consumer.consume(generator) # type: ignore[no-any-return] + return generator_consumer.consume(generator) results = benchmark(function_to_benchmark) @@ -140,7 +140,7 @@ def function_to_benchmark() -> list[Any]: nf, nc, ) - return generator_consumer.consume(generator) # type: ignore[no-any-return] + return generator_consumer.consume(generator) covs = benchmark(function_to_benchmark) cov = covs[0] @@ -156,18 +156,14 @@ def function_to_benchmark() -> list[Any]: @pytest.mark.stable @pytest.mark.parametrize("use_rng", [False, True]) @pytest.mark.parametrize("ncorr", [None, 1]) -def test_generate_grf( # noqa: PLR0913 - xpb: ModuleType, +def test_generate_grf( benchmark: BenchmarkFixture, generator_consumer: GeneratorConsumer, + ncorr: int | None, urngb: UnifiedGenerator, use_rng: bool, # noqa: FBT001 - ncorr: int | None, ) -> None: """Benchmarks for glass.fields._generate_grf with positional arguments only.""" - if xpb.__name__ == "array_api_strict": - pytest.skip(f"glass.fields._generate_grf not yet ported for {xpb.__name__}") - gls: AngularPowerSpectra = [urngb.random(1_000)] nside = 4 @@ -178,7 +174,7 @@ def function_to_benchmark() -> list[Any]: rng=urngb if use_rng else None, ncorr=ncorr, ) - return generator_consumer.consume(generator) # type: ignore[no-any-return] + return generator_consumer.consume(generator) gaussian_fields = benchmark(function_to_benchmark) @@ -195,9 +191,6 @@ def test_generate( ncorr: int | None, ) -> None: """Benchmarks for glass.generate.""" - if xpb.__name__ == "array_api_strict": - pytest.skip(f"glass.generate not yet ported for {xpb.__name__}") - n = 100 fields = [lambda x, var: x for _ in range(n)] # noqa: ARG005 fields[1] = lambda x, var: x**2 # noqa: ARG005 @@ -212,8 +205,8 @@ def function_to_benchmark() -> list[Any]: nside=nside, ncorr=ncorr, ) - return generator_consumer.consume( # type: ignore[no-any-return] - generator, + return generator_consumer.consume( + generator, # type: ignore[arg-type] valid_exception="covariance matrix is not positive definite", ) diff --git a/tests/benchmarks/test_galaxies.py b/tests/benchmarks/test_galaxies.py index ef906b5c..26058efc 100644 --- a/tests/benchmarks/test_galaxies.py +++ b/tests/benchmarks/test_galaxies.py @@ -66,13 +66,9 @@ def test_redshifts_from_nz( def test_galaxy_shear( benchmark: BenchmarkFixture, urngb: UnifiedGenerator, - xpb: ModuleType, reduced_shear: bool, # noqa: FBT001 ) -> None: """Benchmark for galaxies.galaxy_shear.""" - if xpb.__name__ == "array_api_strict": - pytest.skip(f"glass.galaxy_shear not yet ported for {xpb.__name__}") - scale_factor = 100 size = (12 * scale_factor,) kappa = urngb.normal(size=size) diff --git a/tests/benchmarks/test_harmonics.py b/tests/benchmarks/test_harmonics.py index 5021ad99..c004c36c 100644 --- a/tests/benchmarks/test_harmonics.py +++ b/tests/benchmarks/test_harmonics.py @@ -13,9 +13,10 @@ if TYPE_CHECKING: from types import ModuleType - from conftest import Compare from pytest_benchmark.fixture import BenchmarkFixture + from tests.fixtures.helper_classes import Compare + @pytest.mark.unstable def test_multalm( diff --git a/tests/benchmarks/test_lensing.py b/tests/benchmarks/test_lensing.py index a60a53c3..7fc56f3b 100644 --- a/tests/benchmarks/test_lensing.py +++ b/tests/benchmarks/test_lensing.py @@ -9,12 +9,12 @@ if TYPE_CHECKING: from types import ModuleType - from conftest import Compare from pytest_benchmark.fixture import BenchmarkFixture from typing_extensions import Never from glass._types import FloatArray, UnifiedGenerator from glass.cosmology import Cosmology + from tests.fixtures.helper_classes import Compare @pytest.mark.stable @@ -85,9 +85,6 @@ def test_multi_plane_weights( xpb: ModuleType, ) -> None: """Benchmarks for add_window and add_plane with a multi_plane_weights.""" - if xpb.__name__ == "array_api_strict": - pytest.skip(f"glass.multi_plane_weights not yet ported for {xpb.__name__}") - # Use this over the fixture to allow us to add many more windows shells = [ glass.RadialWindow( diff --git a/tests/benchmarks/test_points.py b/tests/benchmarks/test_points.py index 51199ae5..396b5aa5 100644 --- a/tests/benchmarks/test_points.py +++ b/tests/benchmarks/test_points.py @@ -40,10 +40,6 @@ def test_positions_from_delta( # noqa: PLR0913 remove_monopole: bool, # noqa: FBT001 ) -> None: """Benchmarks for glass.positions_from_delta.""" - if xpb.__name__ == "array_api_strict": - pytest.skip( - f"glass.lensing.multi_plane_matrix not yet ported for {xpb.__name__}", - ) nside = 48 npix = 12 * nside * nside diff --git a/tests/benchmarks/test_shells.py b/tests/benchmarks/test_shells.py index 66334f90..552d2efd 100644 --- a/tests/benchmarks/test_shells.py +++ b/tests/benchmarks/test_shells.py @@ -9,9 +9,10 @@ if TYPE_CHECKING: from types import ModuleType - from conftest import Compare from pytest_benchmark.fixture import BenchmarkFixture + from tests.fixtures.helper_classes import Compare + @pytest.mark.unstable def test_radialwindow( diff --git a/tests/core/test_fields.py b/tests/core/test_fields.py index 0cc755cb..d1f9fafe 100644 --- a/tests/core/test_fields.py +++ b/tests/core/test_fields.py @@ -380,7 +380,7 @@ def test_effective_cls(compare: type[Compare], xp: ModuleType) -> None: def test_generate_grf(compare: type[Compare], xp: ModuleType) -> None: - gls = [xp.asarray([1.0, 0.5, 0.1])] + gls: AngularPowerSpectra = [xp.asarray([1.0, 0.5, 0.1])] nside = 4 ncorr = 1 diff --git a/tests/core/test_galaxies.py b/tests/core/test_galaxies.py index 4ab0504b..341f7f65 100644 --- a/tests/core/test_galaxies.py +++ b/tests/core/test_galaxies.py @@ -18,7 +18,8 @@ def test_redshifts(mocker: MockerFixture, xp: ModuleType) -> None: if xp.__name__ == "jax.numpy": - pytest.skip("Arrays in redshifts are not immutable, so do not support jax") + pytest.skip(f"glass.redshifts not yet ported for {xp.__name__}") + # create a mock radial window function w = mocker.Mock() w.za = xp.linspace(0.0, 1.0, 20) @@ -37,9 +38,7 @@ def test_redshifts(mocker: MockerFixture, xp: ModuleType) -> None: def test_redshifts_from_nz(urng: UnifiedGenerator, xp: ModuleType) -> None: if xp.__name__ == "jax.numpy": - pytest.skip( - "Arrays in redshifts_from_nz are not immutable, so do not support jax", - ) + pytest.skip(f"glass.redshifts_from_nz not yet ported for {xp.__name__}") # test sampling