Skip to content

gh-519: test array API compliance of legacy mode functions #595

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 3 commits into from
May 30, 2025

Conversation

Saransh-cpp
Copy link
Member

@Saransh-cpp Saransh-cpp commented Apr 3, 2025

Description

Add array API tests for legacy mode functions added in glass.algorithm. The functions added in other modules do not fully support the array API standard; therefore, those functions can be dealt with once we add full support.

Closes: #519

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 marked this pull request as ready for review April 3, 2025 12:58
@Saransh-cpp Saransh-cpp marked this pull request as draft April 3, 2025 15:14
@Saransh-cpp Saransh-cpp self-assigned this Apr 3, 2025
@Saransh-cpp Saransh-cpp added array-api Work is related to the Array API testing Work is related to testing labels Apr 3, 2025
@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch from 467441d to 7ab2fd8 Compare April 4, 2025 12:29
@Saransh-cpp Saransh-cpp marked this pull request as ready for review April 4, 2025 12:29
@Saransh-cpp
Copy link
Member Author

The typing and rng issues need to be worked out ideally before merging this. Hence, marking as draft.

@Saransh-cpp Saransh-cpp marked this pull request as draft April 4, 2025 12:31
@Saransh-cpp Saransh-cpp added the blocked The issue or pull request is blocked by something label Apr 4, 2025
@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch from 7ab2fd8 to e377ecf Compare April 11, 2025 13:22
@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch 2 times, most recently from 49dac65 to a084534 Compare April 30, 2025 10:46
@Saransh-cpp Saransh-cpp changed the base branch from main to saransh/rngs April 30, 2025 10:46
@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch from a084534 to 448e511 Compare April 30, 2025 10:46
@Saransh-cpp Saransh-cpp marked this pull request as ready for review April 30, 2025 10:47
@Saransh-cpp Saransh-cpp marked this pull request as draft April 30, 2025 10:47
@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch from 448e511 to b41eb0f Compare April 30, 2025 14:18
@Saransh-cpp Saransh-cpp marked this pull request as ready for review April 30, 2025 14:18
@ntessore
Copy link
Collaborator

Thanks @Saransh-cpp! What is the issue with array.reshape() here?

@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch 4 times, most recently from 3108e3b to e2265be Compare April 30, 2025 20:12
@Saransh-cpp Saransh-cpp marked this pull request as draft April 30, 2025 20:15
@Saransh-cpp
Copy link
Member Author

Thanks, @ntessore! array.reshape() exists in JAX and NumPy but it is not a part of the array API (array_api_strict tests fail).

@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch from e2265be to 614b317 Compare May 1, 2025 15:57
@Saransh-cpp Saransh-cpp marked this pull request as ready for review May 1, 2025 17:51
@Saransh-cpp Saransh-cpp marked this pull request as ready for review May 2, 2025 09:30
@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch from 42746f1 to 2e05701 Compare May 2, 2025 09:30
@Saransh-cpp Saransh-cpp marked this pull request as draft May 2, 2025 09:32
@Saransh-cpp Saransh-cpp marked this pull request as ready for review May 8, 2025 11:31
@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch from 42904fe to c669fee Compare May 8, 2025 11:31
@Saransh-cpp Saransh-cpp marked this pull request as draft May 8, 2025 11:33
Base automatically changed from saransh/rngs to main May 14, 2025 10:54
@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch from acc7d03 to b3fa300 Compare May 14, 2025 21:22
@Saransh-cpp Saransh-cpp changed the base branch from main to saransh/array_api_strict-rng May 14, 2025 21:37
@Saransh-cpp Saransh-cpp marked this pull request as ready for review May 14, 2025 21:37
@Saransh-cpp Saransh-cpp marked this pull request as draft May 14, 2025 22:05
Comment on lines -114 to +127
np.divide(a, norm, where=(norm > 0), out=np.zeros_like(a)),
xp.divide(a, norm),
Copy link
Member

Choose a reason for hiding this comment

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

Just checking why dropping where/out?

Copy link
Member Author

Choose a reason for hiding this comment

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

array_api_strict.divide does not support those arguments. out is not testing anything here and the where argument is probably just reducing the number of computations (which is not very large in this case).

Copy link
Collaborator

Choose a reason for hiding this comment

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

norm > 0 is necessary if dealing with rank-deficient matrices, e.g. to get the correlation matrix of this covariance matrix:

$$\begin{pmatrix}2 & 0 & 1 \\ 0 & 0 & 0 \\ 1 & 0 & 3\end{pmatrix}$$

To be fair, I don't we are testing that case currently

Base automatically changed from saransh/array_api_strict-rng to main May 30, 2025 11:21
@Saransh-cpp Saransh-cpp removed the blocked The issue or pull request is blocked by something label May 30, 2025
@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch from 4174e4a to 56a8d44 Compare May 30, 2025 14:29
@Saransh-cpp Saransh-cpp marked this pull request as ready for review May 30, 2025 14:29
)

# cannot deal with negative variances
with pytest.raises(ValueError, match="negative values"):
glass.algorithm.cov_nearest(np.diag([1, 1, -1]))
glass.algorithm.cov_nearest(xp.asarray([[1, 0, 0], [0, 1, 0], [0, 0, -1]]))
Copy link
Member Author

Choose a reason for hiding this comment

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

There is no diag function or alternative in array API standard.

Copy link
Member

Choose a reason for hiding this comment

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

Given the size of this, that doesn't seem like a problem really

Comment on lines -114 to +127
np.divide(a, norm, where=(norm > 0), out=np.zeros_like(a)),
xp.divide(a, norm),
Copy link
Member Author

Choose a reason for hiding this comment

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

array_api_strict.divide does not support those arguments. out is not testing anything here and the where argument is probably just reducing the number of computations (which is not very large in this case).

@Saransh-cpp Saransh-cpp force-pushed the saransh/array-api-tests-legacy branch from 28fad94 to 5480683 Compare May 30, 2025 14:33
@Saransh-cpp
Copy link
Member Author

This should finally be ready now, @paddyroddy @ntessore!

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.

This looks really clean 👌

@Saransh-cpp
Copy link
Member Author

Merging this so that it does not go stale again!

@Saransh-cpp Saransh-cpp merged commit 0935cc6 into main May 30, 2025
17 checks passed
@Saransh-cpp Saransh-cpp deleted the saransh/array-api-tests-legacy branch May 30, 2025 15:03
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Array API: test functions for legacy mode
3 participants