Skip to content

gh-502: add array API tests and typing for grf._transformations #614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 30, 2025

Conversation

Saransh-cpp
Copy link
Member

Description

Add array API tests and typing for grf._transformations. Should be okay to merge after #610.

Fixes: #502

Checks

  • Is your code passing linting?
  • Is your code passing tests?
  • Have you added additional tests (if required)?
  • Have you modified/extended the documentation (if required)?
  • Have you added a one-liner changelog entry above (if required)?

@Saransh-cpp Saransh-cpp self-assigned this May 5, 2025
@Saransh-cpp Saransh-cpp added typing Static typing array-api Work is related to the Array API testing Work is related to testing labels May 5, 2025
@Saransh-cpp Saransh-cpp linked an issue May 5, 2025 that may be closed by this pull request
Base automatically changed from saransh/rngs to main May 14, 2025 10:54
@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-grf branch from 066c47f to cdda0e6 Compare May 30, 2025 13:04
@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-grf branch from cdda0e6 to 9d88886 Compare May 30, 2025 13:06
@Saransh-cpp Saransh-cpp marked this pull request as ready for review May 30, 2025 13:09
Copy link
Member

@paddyroddy paddyroddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. A couple of small comments.

Comment on lines -86 to +95
np.testing.assert_array_almost_equal_nulp(glass.grf.icorr(t1, t2, y), x, nulp=5)
np.testing.assert_array_almost_equal_nulp(glass.grf.icorr(t1, t2, y), x, nulp=8)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why this has changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get this with JAX with anything less than 8 -

============================================================================== FAILURES ===============================================================================
__________________________________________________________________ test_sqnormal_sqnormal[jax.numpy] __________________________________________________________________

xp = <module 'jax.numpy' from '/Users/saransh/Code/UCL/glass/.env/lib/python3.13/site-packages/jax/numpy/__init__.py'>
urng = <glass.jax.Generator object at 0x111a3ffd0>

    def test_sqnormal_sqnormal(xp: types.ModuleType, urng: UnifiedGenerator) -> None:
        lam1, var1 = urng.uniform(size=2)
        a1 = xp.sqrt(1 - var1)
        t1 = glass.grf.SquaredNormal(a1, lam1)
    
        lam2, var2 = urng.uniform(size=2)
        a2 = xp.sqrt(1 - var2)
        t2 = glass.grf.SquaredNormal(a2, lam2)
    
        # https://arxiv.org/pdf/2408.16903, (E.7)
        x = urng.random(10)
        y = 2 * lam1 * lam2 * x * (x + 2 * a1 * a2)
        dy = 4 * lam1 * lam2 * (x + a1 * a2)
    
        np.testing.assert_array_equal(glass.grf.corr(t1, t2, x), y)
>       np.testing.assert_array_almost_equal_nulp(glass.grf.icorr(t1, t2, y), x, nulp=5)
E       AssertionError: Arrays are not equal to 5 ULP (max is 8)

tests/grf/test_transformations.py:95: AssertionError

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay makes sense. Bit annoying.

Co-authored-by: Patrick J. Roddy <[email protected]>
@paddyroddy
Copy link
Member

I'm going to merge this just so we have fewer stale PRs when we resume work in September

@paddyroddy paddyroddy merged commit 919086b into main May 30, 2025
17 checks passed
@paddyroddy paddyroddy deleted the saransh/array-api-tests-grf branch May 30, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array-api Work is related to the Array API testing Work is related to testing typing Static typing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Array API: test compliance of glass.grf
2 participants