Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1db9312
Add `jupyter` as `dev` dep
paddyroddy May 19, 2026
eeb69fd
Use `xp_assert` methods from `xpx`
paddyroddy May 19, 2026
a8c81ab
Missing comma
paddyroddy May 19, 2026
fdd7cc0
Remove redundant assert statements from `Compare`
paddyroddy May 19, 2026
3b8c8c2
Remove `compare` calls
paddyroddy May 19, 2026
d53c07e
Fix some tests
paddyroddy May 20, 2026
165701b
Merge branch 'main' into paddy/issue-1076
paddyroddy May 20, 2026
0bb932a
Port more test
paddyroddy May 20, 2026
732618f
More fixing
paddyroddy May 20, 2026
c4e1ff8
Fix points
paddyroddy May 20, 2026
c0c8cf6
Fix fields
paddyroddy May 20, 2026
dd61128
Fix more tests
paddyroddy May 20, 2026
7bb239f
Fix some more tests
paddyroddy May 21, 2026
107ffbc
Fix NumPy tests
paddyroddy May 21, 2026
cf1b439
Revert back to NumPy
paddyroddy May 21, 2026
cb7e87f
Change `asarray` to `stack`
paddyroddy May 21, 2026
e652991
Fix `healpix` tests
paddyroddy May 21, 2026
4ceb12b
Fix all core tests
paddyroddy May 21, 2026
2ab6cf3
Comma
paddyroddy May 21, 2026
097af7e
Swap order
paddyroddy May 21, 2026
8d7eafc
Fix NumPy test
paddyroddy May 21, 2026
5493d4f
Remove new line
paddyroddy May 21, 2026
b6e1cc2
Change to `xp_` test
paddyroddy May 21, 2026
875a21f
Merge branch 'main' into paddy/issue-1076
paddyroddy May 21, 2026
1c6a64c
Change to new assert names
paddyroddy May 26, 2026
fa3900d
Use `assert_close_nulp`
paddyroddy May 28, 2026
6e7a975
Import `array_api_extra.testing`
paddyroddy May 28, 2026
ac38c9a
Drop Python 3.10 support
paddyroddy May 29, 2026
f320389
Point to main hash
paddyroddy May 29, 2026
4145758
Move hash to dependency groups
paddyroddy May 29, 2026
0b21711
`check_shape=False`
paddyroddy May 29, 2026
9f0a09e
Testing improvements
paddyroddy May 29, 2026
b06b164
Convert back to `xpx.testing`
paddyroddy May 29, 2026
e61583e
More refining
paddyroddy May 29, 2026
2e742f9
More shape ignoring
paddyroddy May 29, 2026
85a3a43
Format
paddyroddy May 29, 2026
860b8d7
Check shape False
paddyroddy May 29, 2026
c022431
Explicitly broadcast
paddyroddy May 29, 2026
0f3f386
Remove `3.10` from metadata
paddyroddy May 29, 2026
f8dd9c4
Remove `3.10` from CI
paddyroddy May 29, 2026
964e8fc
Remove `3.10` from `nox`
paddyroddy May 29, 2026
49c0d61
Update typing from `3.10` to `3.11` changes
paddyroddy May 29, 2026
1a210b9
Merge branch 'paddy/issue-690' into paddy/issue-1076
paddyroddy May 29, 2026
9f33d22
Fix tests
paddyroddy May 29, 2026
872bb36
Suppress linting errors
paddyroddy May 29, 2026
7064641
Remove `array-api-extra` hash
paddyroddy May 29, 2026
dd6f963
Merge branch 'main' into paddy/issue-1076
paddyroddy Jun 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dev = [
"coverage[toml]",
"hatch-vcs",
"hatchling",
"jupyter",
Comment thread
paddyroddy marked this conversation as resolved.
"nox",
"nox-uv",
{include-group = "build"},
Expand Down
16 changes: 7 additions & 9 deletions tests/benchmarks/test_arraytools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import pytest

import array_api_extra as xpx

import glass.arraytools

if TYPE_CHECKING:
from types import ModuleType

from pytest_benchmark.fixture import BenchmarkFixture

from tests.fixtures.helper_classes import Compare


@pytest.mark.unstable
def test_broadcast_leading_axes(
Expand Down Expand Up @@ -44,7 +44,6 @@ def test_broadcast_leading_axes(
@pytest.mark.unstable
def test_cumulative_trapezoid_1d(
benchmark: BenchmarkFixture,
compare: type[Compare],
xpb: ModuleType,
) -> None:
"""Benchmark test for glass.arraytools.cumulative_trapezoid."""
Expand All @@ -56,7 +55,7 @@ def test_cumulative_trapezoid_1d(
ct = benchmark(glass.arraytools.cumulative_trapezoid, f, x)

# Compare to int64 as old versions of glass round to int64 if `dtype` is not passed.
compare.assert_allclose(
xpx.testing.assert_close(
xpb.asarray(ct[:4], dtype=xpb.int64),
xpb.asarray([0, 1, 4, 7]),
)
Expand All @@ -66,7 +65,6 @@ def test_cumulative_trapezoid_1d(
@pytest.mark.unstable
def test_cumulative_trapezoid_2d(
benchmark: BenchmarkFixture,
compare: type[Compare],
xpb: ModuleType,
) -> None:
"""Benchmark test for glass.arraytools.cumulative_trapezoid."""
Expand All @@ -80,16 +78,16 @@ def test_cumulative_trapezoid_2d(
)
x = xpb.arange(scaled_length) # [0, 1, 2, 3,...]

expected_first_4_out = [0, 1, 4, 7]

ct = benchmark(glass.arraytools.cumulative_trapezoid, f, x)

expected_first_4_out = xpb.asarray([0, 1, 4, 7])

# Compare to int64 as old versions of glass round to int64 if `dtype` is not passed.
compare.assert_allclose(
xpx.testing.assert_close(
xpb.asarray(ct[0, :4], dtype=xpb.int64),
expected_first_4_out,
)
compare.assert_allclose(
xpx.testing.assert_close(
xpb.asarray(ct[1, :4], dtype=xpb.int64),
expected_first_4_out,
)
Expand Down
23 changes: 10 additions & 13 deletions tests/benchmarks/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import pytest

import array_api_extra as xpx

import glass
import glass.fields
import glass.healpix as hp
Expand All @@ -16,7 +18,7 @@
from pytest_benchmark.fixture import BenchmarkFixture

from glass._types import AngularPowerSpectra, UnifiedGenerator
from tests.fixtures.helper_classes import Compare, GeneratorConsumer
from tests.fixtures.helper_classes import GeneratorConsumer


@pytest.mark.stable
Expand Down Expand Up @@ -102,7 +104,6 @@ def function_to_benchmark() -> list[Any]:
@pytest.mark.stable
def test_iternorm_k_0(
benchmark: BenchmarkFixture,
compare: type[Compare],
generator_consumer: type[GeneratorConsumer],
xpb: ModuleType,
) -> None:
Expand All @@ -119,13 +120,12 @@ def function_to_benchmark() -> list[Any]:
j, a, s = results[0]
assert j is None
assert a.shape == (0,)
compare.assert_allclose(xpb.asarray(s), 1.0)
xpx.testing.assert_close(s, xpb.asarray(1.0))


@pytest.mark.stable
def test_cls2cov(
benchmark: BenchmarkFixture,
compare: type[Compare],
generator_consumer: type[GeneratorConsumer],
xpb: ModuleType,
) -> None:
Expand All @@ -148,9 +148,9 @@ def function_to_benchmark() -> list[Any]:
assert cov.shape == (nl, nc + 1)
assert cov.dtype == xpb.float64

compare.assert_allclose(cov[:, 0], xpb.asarray([1.0, 1.5, 2.0]))
compare.assert_allclose(cov[:, 1], xpb.asarray([1.5, 2.0, 2.5]))
compare.assert_allclose(cov[:, 2], 0)
xpx.testing.assert_close(cov[:, 0], xpb.asarray([1.0, 1.5, 2.0]))
xpx.testing.assert_close(cov[:, 1], xpb.asarray([1.5, 2.0, 2.5]))
xpx.testing.assert_close(cov[:, 2], xpb.asarray(0.0), check_shape=False)


@pytest.mark.stable
Expand Down Expand Up @@ -185,7 +185,6 @@ def function_to_benchmark() -> list[Any]:
@pytest.mark.parametrize("ncorr", [None, 1])
def test_generate(
benchmark: BenchmarkFixture,
compare: type[Compare],
generator_consumer: type[GeneratorConsumer],
xpb: ModuleType,
ncorr: int | None,
Expand Down Expand Up @@ -214,13 +213,12 @@ def function_to_benchmark() -> list[Any]:

for field in result:
assert field.shape == (hp.nside2npix(nside),)
compare.assert_allclose(result[1], result[0] ** 2, atol=1e-05)
xpx.testing.assert_close(result[1], result[0] ** 2, atol=1e-05)


@pytest.mark.unstable
def test_getcl_lmax_0(
benchmark: BenchmarkFixture,
compare: type[Compare],
xpb: ModuleType,
) -> None:
"""Benchmarks for glass.getcl with lmax of 0."""
Expand All @@ -245,13 +243,12 @@ def test_getcl_lmax_0(
)
expected = xpb.asarray([max(random_i, random_j)], dtype=xpb.float64)
assert result.shape[0] == 1
compare.assert_allclose(result, expected)
xpx.testing.assert_close(result, expected)


@pytest.mark.unstable
def test_getcl_lmax_larger_than_cls(
benchmark: BenchmarkFixture,
compare: type[Compare],
xpb: ModuleType,
) -> None:
"""Benchmarks for glass.getcl with lmax larger than the length of cl."""
Expand All @@ -277,4 +274,4 @@ def test_getcl_lmax_larger_than_cls(
)
expected = xpb.zeros((lmax - 1,), dtype=xpb.float64)
assert result.shape[0] == lmax + 1
compare.assert_allclose(result[2:], expected)
xpx.testing.assert_close(result[2:], expected)
7 changes: 3 additions & 4 deletions tests/benchmarks/test_harmonics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pytest

import array_api_extra as xpx

glass_harmonics = pytest.importorskip(
"glass.harmonics",
reason="tests require glass.harmonics",
Expand All @@ -15,13 +17,10 @@

from pytest_benchmark.fixture import BenchmarkFixture

from tests.fixtures.helper_classes import Compare


@pytest.mark.unstable
def test_multalm(
benchmark: BenchmarkFixture,
compare: type[Compare],
xpb: ModuleType,
) -> None:
"""Benchmarks for glass.harmonics.multalm."""
Expand All @@ -32,7 +31,7 @@ def test_multalm(

result = benchmark(glass_harmonics.multalm, alm, bl)

compare.assert_allclose(
xpx.testing.assert_close(
result[:5],
xpb.asarray([scale_factor * x for x in [0.0, 3.0, 6.0, 9.0, 12.0]]),
)
13 changes: 6 additions & 7 deletions tests/benchmarks/test_lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pytest

import array_api_extra as xpx

import glass

if TYPE_CHECKING:
Expand All @@ -14,13 +16,11 @@

from glass._types import FloatArray, UnifiedGenerator
from glass.cosmology import Cosmology
from tests.fixtures.helper_classes import Compare


@pytest.mark.stable
def test_multi_plane_matrix(
benchmark: BenchmarkFixture,
compare: type[Compare],
cosmo: Cosmology,
urngb: UnifiedGenerator,
xpb: ModuleType,
Expand All @@ -38,8 +38,8 @@ def test_multi_plane_matrix(
mat = glass.multi_plane_matrix(shells, cosmo)
deltas = urngb.random((len(shells), 10))

compare.assert_array_equal(mat, xpb.tril(mat))
compare.assert_array_equal(xpb.triu(mat, k=1), 0)
xpx.testing.assert_equal(mat, xpb.tril(mat))
xpx.testing.assert_equal(xpb.triu(mat, k=1), xpb.asarray(0.0), check_shape=False)

def setup_shells_and_deltas() -> tuple[
tuple[
Expand Down Expand Up @@ -79,7 +79,6 @@ def multi_plane_matrix_add_window(
@pytest.mark.stable
def test_multi_plane_weights(
benchmark: BenchmarkFixture,
compare: type[Compare],
cosmo: Cosmology,
urngb: UnifiedGenerator,
xpb: ModuleType,
Expand All @@ -100,8 +99,8 @@ def test_multi_plane_weights(

w_out = glass.multi_plane_weights(w_in, shells, cosmo)

compare.assert_array_equal(w_out, xpb.triu(w_out, 1))
compare.assert_array_equal(xpb.tril(w_out), 0)
xpx.testing.assert_equal(w_out, xpb.triu(w_out, 1))
xpx.testing.assert_equal(xpb.tril(w_out), xpb.asarray(0.0), check_shape=False)

def setup_shells_deltas_and_weights() -> tuple[
tuple[
Expand Down
8 changes: 4 additions & 4 deletions tests/benchmarks/test_shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import pytest

import array_api_extra as xpx

import glass

if TYPE_CHECKING:
from types import ModuleType

from pytest_benchmark.fixture import BenchmarkFixture

from tests.fixtures.helper_classes import Compare


@pytest.mark.unstable
def test_radialwindow(
Expand All @@ -23,11 +23,11 @@ def test_radialwindow(
"""Benchmark for shells.RadialWindow."""
# check zeff is computed when not provided
arr_length = 100_000
expected_zeff = 66_666.0
expected_zeff = xpb.asarray(66_666.0)

wa = xpb.arange(arr_length)
za = xpb.arange(arr_length)

w = benchmark(glass.RadialWindow, za, wa)

compare.assert_allclose(w.zeff, expected_zeff)
xpx.testing.assert_close(w.zeff, expected_zeff)
26 changes: 10 additions & 16 deletions tests/core/grf/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import numpy as np
import pytest

import array_api_extra as xpx

import glass.grf

if TYPE_CHECKING:
from glass._types import FloatArray
from tests.fixtures.helper_classes import Compare


@pytest.fixture(scope="session")
Expand All @@ -21,7 +22,6 @@ def cl() -> FloatArray:

def test_one_transformation(
cl: FloatArray,
compare: type[Compare],
rng: np.random.Generator,
) -> None:
lam = rng.random()
Expand All @@ -30,7 +30,7 @@ def test_one_transformation(
gl1, _, _ = glass.grf.solve(cl, t)
gl2, _, _ = glass.grf.solve(cl, t, t)

compare.assert_array_equal(gl1, gl2)
xpx.testing.assert_equal(gl1, gl2)


def test_pad(
Expand All @@ -51,7 +51,6 @@ def test_pad(

def test_initial(
cl: FloatArray,
compare: type[Compare],
rng: np.random.Generator,
) -> None:
lam = rng.random()
Expand All @@ -62,24 +61,20 @@ def test_initial(
gl1, _, _ = glass.grf.solve(cl, t)
gl2, _, _ = glass.grf.solve(cl, t, initial=gl)

compare.assert_array_equal(gl1, gl2)
xpx.testing.assert_equal(gl1, gl2)


def test_no_iterations(
cl: FloatArray,
compare: type[Compare],
) -> None:
def test_no_iterations(cl: FloatArray) -> None:
t = glass.grf.Lognormal()

gl1 = glass.grf.compute(cl, t)
gl2, _, _ = glass.grf.solve(cl, t, maxiter=0)

compare.assert_array_equal(gl1, gl2)
xpx.testing.assert_equal(gl1, gl2)


def test_lognormal(
cl: FloatArray,
compare: type[Compare],
rng: np.random.Generator,
) -> None:
t1 = glass.grf.Lognormal()
Expand All @@ -93,17 +88,16 @@ def test_lognormal(

assert info > 0

compare.assert_allclose(cl_[1 : cl.shape[0]], cl[1:], atol=0.0, rtol=cltol)
xpx.testing.assert_close(cl_[1 : cl.shape[0]], cl[1:], atol=0.0, rtol=cltol)

gl_ = glass.grf.compute(cl_, t1, t2)

assert gl[0] == gl0
compare.assert_allclose(gl_[1 : gl.shape[0]], gl[1:])
xpx.testing.assert_close(gl_[1 : gl.shape[0]], gl[1:])


def test_monopole(
cl: FloatArray,
compare: type[Compare],
rng: np.random.Generator,
) -> None:
t = glass.grf.Lognormal()
Expand All @@ -114,10 +108,10 @@ def test_monopole(
gl, cl_out, _ = glass.grf.solve(cl, t, monopole=None, gltol=1e-8)

assert gl[0] != 0.0
compare.assert_allclose(cl_out[0], cl[0])
xpx.testing.assert_close(cl_out[0], cl[0])

gl, cl_out, _ = glass.grf.solve(cl, t, monopole=gl0, gltol=1e-8)

assert gl[0] == gl0
with pytest.raises(AssertionError, match="Not equal to tolerance"):
compare.assert_allclose(cl_out[0], cl[0])
xpx.testing.assert_close(cl_out[0], cl[0])
Loading
Loading