Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4373469

Browse files
committed
MAINT: Add array-api-tests CI stage, add numpy.ndarray.__array_namespace__
1 parent94bc564 commit4373469

File tree

5 files changed

+211
-0
lines changed

5 files changed

+211
-0
lines changed

‎.github/workflows/linux.yml‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,47 @@ jobs:
208208
cd tools
209209
pytest --pyargs numpy -m "not slow"
210210
211+
array_api_tests:
212+
needs:[smoke_test]
213+
runs-on:ubuntu-latest
214+
if:github.event_name != 'push'
215+
steps:
216+
-name:Checkout NumPy
217+
uses:actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11# v4.1.1
218+
with:
219+
submodules:recursive
220+
fetch-depth:0
221+
-name:Checkout array-api-tests
222+
uses:actions/checkout@v3
223+
with:
224+
repository:data-apis/array-api-tests
225+
ref:'83f0bcdcc5286250dbb26be5d37511702970b4dc'# Latest commit as of 2023-11-15
226+
submodules:'true'
227+
path:'array-api-tests'
228+
-name:Fix array-apis bug
229+
# Temporary workaround for https://github.com/data-apis/array-api/issues/631
230+
run:|
231+
sed -i -e 's/\\/\\\\/g' array-api-tests/array-api/spec/API_specification/signatures/*.py
232+
-name:Set up Python
233+
uses:actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236# v4.7.1
234+
with:
235+
python-version:'3.11'
236+
-name:Install build and test dependencies from PyPI
237+
run:|
238+
python -m pip install -r build_requirements.txt
239+
python -m pip install -r test_requirements.txt
240+
python -m pip install hypothesis!=6.88.4 # 6.88.4 leads to a strange error
241+
python -m pip install -r array-api-tests/requirements.txt
242+
-name:Build and install NumPy
243+
run:|
244+
python -m pip install . -v -Csetup-args=-Dallow-noblas=true -Csetup-args=-Dcpu-baseline=none -Csetup-args=-Dcpu-dispatch=none
245+
-name:Run the test suite
246+
env:
247+
ARRAY_API_TESTS_MODULE:numpy
248+
run:|
249+
cd ${GITHUB_WORKSPACE}/array-api-tests
250+
pytest array_api_tests -v -W ignore::pytest.PytestDeprecationWarning -W ignore::RuntimeWarning -W ignore::DeprecationWarning --ci --max-examples=2 --derandomize --disable-deadline --skips-file ${GITHUB_WORKSPACE}/array-api-skips.txt
251+
211252
custom_checks:
212253
needs:[smoke_test]
213254
runs-on:ubuntu-latest

‎array-api-skips.txt‎

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# copy not implemented
2+
array_api_tests/test_creation_functions.py::test_asarray_arrays
3+
4+
# https://github.com/numpy/numpy/issues/20870
5+
array_api_tests/test_data_type_functions.py::test_can_cast
6+
7+
# The return dtype for trace is not consistent in the spec
8+
# https://github.com/data-apis/array-api/issues/202#issuecomment-952529197
9+
array_api_tests/test_linalg.py::test_trace
10+
11+
# waiting on NumPy to allow/revert distinct NaNs for np.unique
12+
# https://github.com/numpy/numpy/issues/20326#issuecomment-1012380448
13+
array_api_tests/test_set_functions.py
14+
15+
# newaxis not included in numpy namespace as of v1.26.2
16+
array_api_tests/test_constants.py::test_newaxis
17+
18+
# linalg.solve issue in numpy.array_api as of v1.26.2 (see numpy#25146)
19+
array_api_tests/test_linalg.py::test_solve
20+
21+
# https://github.com/numpy/numpy/issues/21373
22+
array_api_tests/test_array_object.py::test_getitem
23+
24+
# missing copy arg
25+
array_api_tests/test_signatures.py::test_func_signature[reshape]
26+
27+
# https://github.com/numpy/numpy/issues/21211
28+
array_api_tests/test_special_cases.py::test_iop[__iadd__(x1_i is -0 and x2_i is -0) -> -0]
29+
# https://github.com/numpy/numpy/issues/21213
30+
array_api_tests/test_special_cases.py::test_iop[__ipow__(x1_i is -infinity and x2_i > 0 and not (x2_i.is_integer() and x2_i % 2 == 1)) -> +infinity]
31+
array_api_tests/test_special_cases.py::test_iop[__ipow__(x1_i is -0 and x2_i > 0 and not (x2_i.is_integer() and x2_i % 2 == 1)) -> +0]
32+
# noted diversions from spec
33+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
34+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
35+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
36+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
37+
array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
38+
array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
39+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
40+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
41+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
42+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
43+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
44+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
45+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
46+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
47+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
48+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
49+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
50+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
51+
52+
# asarray() got an unexpected keyword argument 'copy'
53+
array_api_tests/test_array_object.py::test_setitem
54+
# array_api_tests/test_array_object.py::test_setitem_masking
55+
array_api_tests/test_creation_functions.py::test_asarray_scalars
56+
57+
# astype is not defined in numpy
58+
array_api_tests/test_data_type_functions.py::test_astype
59+
60+
# fft test suite is buggy as of 83f0bcdc
61+
array_api_tests/test_fft.py
62+
63+
# missing isdtype and finfo return type misalignment
64+
array_api_tests/test_data_type_functions.py::test_finfo[float32]
65+
array_api_tests/test_data_type_functions.py::test_isdtype
66+
67+
# missing names
68+
array_api_tests/test_has_names.py::test_has_names[linalg-cross]
69+
array_api_tests/test_has_names.py::test_has_names[linalg-matmul]
70+
array_api_tests/test_has_names.py::test_has_names[linalg-matrix_norm]
71+
array_api_tests/test_has_names.py::test_has_names[linalg-matrix_transpose]
72+
array_api_tests/test_has_names.py::test_has_names[linalg-outer]
73+
array_api_tests/test_has_names.py::test_has_names[linalg-svdvals]
74+
array_api_tests/test_has_names.py::test_has_names[linalg-tensordot]
75+
array_api_tests/test_has_names.py::test_has_names[linalg-vecdot]
76+
array_api_tests/test_has_names.py::test_has_names[linalg-vector_norm]
77+
array_api_tests/test_has_names.py::test_has_names[set-unique_all]
78+
array_api_tests/test_has_names.py::test_has_names[set-unique_counts]
79+
array_api_tests/test_has_names.py::test_has_names[set-unique_inverse]
80+
array_api_tests/test_has_names.py::test_has_names[set-unique_values]
81+
array_api_tests/test_has_names.py::test_has_names[manipulation-concat]
82+
array_api_tests/test_has_names.py::test_has_names[manipulation-permute_dims]
83+
array_api_tests/test_has_names.py::test_has_names[data_type-astype]
84+
array_api_tests/test_has_names.py::test_has_names[elementwise-acos]
85+
array_api_tests/test_has_names.py::test_has_names[elementwise-acosh]
86+
array_api_tests/test_has_names.py::test_has_names[elementwise-asin]
87+
array_api_tests/test_has_names.py::test_has_names[elementwise-asinh]
88+
array_api_tests/test_has_names.py::test_has_names[elementwise-atan]
89+
array_api_tests/test_has_names.py::test_has_names[elementwise-atan2]
90+
array_api_tests/test_has_names.py::test_has_names[elementwise-atanh]
91+
array_api_tests/test_has_names.py::test_has_names[elementwise-bitwise_left_shift]
92+
array_api_tests/test_has_names.py::test_has_names[elementwise-bitwise_invert]
93+
array_api_tests/test_has_names.py::test_has_names[elementwise-bitwise_right_shift]
94+
array_api_tests/test_has_names.py::test_has_names[elementwise-pow]
95+
array_api_tests/test_has_names.py::test_has_names[linear_algebra-matrix_transpose]
96+
array_api_tests/test_has_names.py::test_has_names[linear_algebra-vecdot]
97+
array_api_tests/test_has_names.py::test_has_names[array_method-to_device]
98+
array_api_tests/test_has_names.py::test_has_names[array_attribute-device]
99+
100+
# missing linalg names
101+
array_api_tests/test_linalg.py::test_cross
102+
array_api_tests/test_linalg.py::test_matrix_norm
103+
array_api_tests/test_linalg.py::test_matrix_transpose
104+
array_api_tests/test_linalg.py::test_outer
105+
array_api_tests/test_linalg.py::test_pinv
106+
array_api_tests/test_linalg.py::test_svdvals
107+
array_api_tests/test_linalg.py::test_vecdot
108+
109+
# missing names
110+
array_api_tests/test_manipulation_functions.py::test_concat
111+
array_api_tests/test_manipulation_functions.py::test_permute_dims
112+
113+
# a few misalignments
114+
array_api_tests/test_operators_and_elementwise_functions.py
115+
array_api_tests/test_signatures.py
116+
117+
# unexpected argument 'stable'
118+
array_api_tests/test_sorting_functions.py::test_argsort
119+
array_api_tests/test_sorting_functions.py::test_sort
120+
121+
# missing aliases
122+
array_api_tests/test_special_cases.py::test_unary
123+
array_api_tests/test_special_cases.py::test_binary
124+
125+
# asarray() got an unexpected keyword argument 'copy'
126+
array_api_tests/test_special_cases.py::test_iop
127+
128+
# got an unexpected keyword argument 'correction'
129+
array_api_tests/test_statistical_functions.py::test_std
130+
array_api_tests/test_statistical_functions.py::test_var
131+
132+
# assertionError: out.dtype=float32, but should be float64 [sum(float32)]
133+
array_api_tests/test_statistical_functions.py::test_sum

‎numpy/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@
285285
# import with `from numpy import *`.
286286
__future_scalars__= {"str","bytes","object"}
287287

288+
__array_api_version__="2022.12"
289+
288290
# now that numpy core module is imported, can initialize limits
289291
_core.getlimits._register_known_types()
290292

‎numpy/__init__.pyi‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ __all__: list[str]
622622
__dir__:list[str]
623623
__version__:str
624624
__git_version__:str
625+
__array_api_version__:str
625626
test:PytestTester
626627

627628
# TODO: Move placeholders to their respective module once
@@ -2462,6 +2463,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
24622463
def__dlpack__(self:NDArray[number[Any]],*,stream:None= ...)->_PyCapsule: ...
24632464
def__dlpack_device__(self)->tuple[int,L[0]]: ...
24642465

2466+
def__array_namespace__(self,*,api_version:str= ...)->Any: ...
2467+
24652468
defbitwise_count(
24662469
self,
24672470
out:None|NDArray[Any]= ...,

‎numpy/_core/src/multiarray/methods.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,6 +2756,32 @@ array_class_getitem(PyObject *cls, PyObject *args)
27562756
returnPy_GenericAlias(cls,args);
27572757
}
27582758

2759+
staticPyObject*
2760+
array_array_namespace(PyArrayObject*self,PyObject*args,PyObject*kwds)
2761+
{
2762+
staticchar*kwlist[]= {"api_version",NULL};
2763+
char*array_api_version="2022.12";
2764+
2765+
if (!PyArg_ParseTupleAndKeywords(args,kwds,"|$s:__array_namespace__",kwlist,
2766+
&array_api_version)) {
2767+
returnNULL;
2768+
}
2769+
2770+
if (strcmp(array_api_version,"2022.12")!=0) {
2771+
PyErr_Format(PyExc_ValueError,
2772+
"Version \"%s\" of Array API is not supported.",
2773+
array_api_version);
2774+
returnNULL;
2775+
}
2776+
2777+
PyObject*numpy_module=PyImport_ImportModule("numpy");
2778+
if (numpy_module==NULL){
2779+
returnNULL;
2780+
}
2781+
2782+
returnnumpy_module;
2783+
}
2784+
27592785
NPY_NO_EXPORTPyMethodDefarray_methods[]= {
27602786

27612787
/* for subtypes */
@@ -2980,5 +3006,11 @@ NPY_NO_EXPORT PyMethodDef array_methods[] = {
29803006
{"__dlpack_device__",
29813007
(PyCFunction)array_dlpack_device,
29823008
METH_NOARGS,NULL},
3009+
3010+
// For Array API compatibility
3011+
{"__array_namespace__",
3012+
(PyCFunction)array_array_namespace,
3013+
METH_VARARGS |METH_KEYWORDS,NULL},
3014+
29833015
{NULL,NULL,0,NULL}/* sentinel */
29843016
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp