Skip to content
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

ENH: generate numpy scalars or 0D arrays #310

Merged
merged 3 commits into from
Nov 20, 2024
Merged

Conversation

ev-br
Copy link
Member

@ev-br ev-br commented Nov 18, 2024

closes #289

@asmeurer
Copy link
Member

Looks good. Can you check the tests with numpy itself, or at least array_api_compat.numpy, and then merge this? It's possible this could uncover some test failures, and we'd want to at least be aware of them if not fix them before merging here.

This is an example of where having numpy tests run on CI could be useful (#298). array-api-strict does not use scalars (it internally converts any numpy scalar into a 0-D array), so the CI tests for it won't really say much here.

Otherwise, on numpy we can generate a numpy scalar and copy=False,
which fails with

(Pdb) p np.asarray(np.False_, copy=False)
*** ValueError: Unable to avoid copy while creating an array as requested.
@ev-br
Copy link
Member Author

ev-br commented Nov 20, 2024

It's interesting, actually.

With numpy, $ ARRAY_API_TESTS_MODULE=numpy pytest array_api_tests -v shows exactly the same failures locally on main and on the PR:

======================================================================================== short test summary info =========================================================================================
FAILED array_api_tests/test_creation_functions.py::test_asarray_arrays - ValueError: Unable to avoid copy while creating an array as requested.
FAILED array_api_tests/test_data_type_functions.py::test_finfo[float32] - AssertionError: type(out.eps)=<class 'numpy.float32'>, but should be float [finfo(float32)]
FAILED array_api_tests/test_manipulation_functions.py::test_repeat - TypeError: Cannot cast array data from dtype('uint64') to dtype('int64') according to the rule 'safe'
FAILED array_api_tests/test_operators_and_elementwise_functions.py::test_clip - AssertionError: out.dtype=uint16, but should be uint8 [clip(uint8)]
FAILED array_api_tests/test_signatures.py::test_func_signature[argsort] - AssertionError: Argument 'descending' missing from signature
FAILED array_api_tests/test_signatures.py::test_func_signature[sort] - AssertionError: Argument 'descending' missing from signature
FAILED array_api_tests/test_signatures.py::test_func_signature[clip] - AssertionError: Expected argument 'a_min' to be named 'min'
FAILED array_api_tests/test_sorting_functions.py::test_argsort - TypeError: argsort() got an unexpected keyword argument 'descending'
FAILED array_api_tests/test_sorting_functions.py::test_sort - TypeError: sort() got an unexpected keyword argument 'descending'
======================================================================== 9 failed, 989 passed, 16 skipped, 457 warnings in 50.98s 

with array_api_compat.numpy though, a small additional fix is needed to avoid

(Pdb) import numpy as np
(Pdb) p np.__version__
'2.1.3'
(Pdb) p np.asarray(np.False_, copy=False)
*** ValueError: Unable to avoid copy while creating an array as requested.
If using `np.array(obj, copy=False)` replace it with `np.asarray(obj)` to allow a copy when needed (no behavior change in NumPy 1.x).
For more details, see https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword.

So, two things to discuss:

  • could you take a look that 0f59c21 makes sense?
  • how come it's not caught by testing with just numpy, neither locally nor on CI. Just too few examples? testing with $ ARRAY_API_TESTS_MODULE=array_api_compat.numpy pytest array_api_tests -v catches it consistently from the first try.

@ev-br ev-br merged commit 298ba5b into data-apis:master Nov 20, 2024
4 checks passed
@ev-br
Copy link
Member Author

ev-br commented Nov 20, 2024

Merging after an offline discussion with Aaron.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate NumPy scalars for test inputs
2 participants