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

Commit06d7bdf

Browse files
authored
Merge pull request#25167 from mtsokol/array-api-test-ci
MAINT: Add ``array-api-tests`` CI stage, add ``ndarray.__array_namespace__``
2 parentsa5b0831 +724d86e commit06d7bdf

File tree

6 files changed

+253
-0
lines changed

6 files changed

+253
-0
lines changed

‎.github/workflows/linux.yml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,45 @@ 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:'9afe8c709d81f005c98d383c82ad5e1c2cd8166c'# Latest commit as of 2023-11-24
226+
submodules:'true'
227+
path:'array-api-tests'
228+
-name:Set up Python
229+
uses:actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236# v4.7.1
230+
with:
231+
python-version:'3.11'
232+
-name:Install build and test dependencies from PyPI
233+
run:|
234+
python -m pip install -r build_requirements.txt
235+
python -m pip install -r test_requirements.txt
236+
python -m pip install -r array-api-tests/requirements.txt
237+
-name:Build and install NumPy
238+
run:|
239+
python -m pip install . -v -Csetup-args=-Dallow-noblas=true -Csetup-args=-Dcpu-baseline=none -Csetup-args=-Dcpu-dispatch=none
240+
-name:Run the test suite
241+
env:
242+
ARRAY_API_TESTS_MODULE:numpy
243+
PYTHONWARNINGS:'ignore::UserWarning::,ignore::DeprecationWarning::,ignore::RuntimeWarning::'
244+
run:|
245+
cd ${GITHUB_WORKSPACE}/array-api-tests
246+
# remove once https://github.com/data-apis/array-api-tests/pull/217 is merged
247+
touch pytest.ini
248+
pytest array_api_tests -v -c pytest.ini --ci --max-examples=2 --derandomize --disable-deadline --skips-file ${GITHUB_WORKSPACE}/tools/ci/array-api-skips.txt
249+
211250
custom_checks:
212251
needs:[smoke_test]
213252
runs-on:ubuntu-latest

‎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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,6 +2756,33 @@ 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,"2021.12")!=0&&
2771+
strcmp(array_api_version,"2022.12")!=0) {
2772+
PyErr_Format(PyExc_ValueError,
2773+
"Version \"%s\" of the Array API Standard is not supported.",
2774+
array_api_version);
2775+
returnNULL;
2776+
}
2777+
2778+
PyObject*numpy_module=PyImport_ImportModule("numpy");
2779+
if (numpy_module==NULL){
2780+
returnNULL;
2781+
}
2782+
2783+
returnnumpy_module;
2784+
}
2785+
27592786
NPY_NO_EXPORTPyMethodDefarray_methods[]= {
27602787

27612788
/* for subtypes */
@@ -2980,5 +3007,11 @@ NPY_NO_EXPORT PyMethodDef array_methods[] = {
29803007
{"__dlpack_device__",
29813008
(PyCFunction)array_dlpack_device,
29823009
METH_NOARGS,NULL},
3010+
3011+
// For Array API compatibility
3012+
{"__array_namespace__",
3013+
(PyCFunction)array_array_namespace,
3014+
METH_VARARGS |METH_KEYWORDS,NULL},
3015+
29833016
{NULL,NULL,0,NULL}/* sentinel */
29843017
};

‎numpy/_core/tests/test_regression.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,3 +2556,20 @@ def test_load_ufunc_pickle(self):
25562556
test_data=b'\x80\x04\x95(\x00\x00\x00\x00\x00\x00\x00\x8c\x1cnumpy.core._multiarray_umath\x94\x8c\x03add\x94\x93\x94.'# noqa
25572557
result=pickle.loads(test_data,encoding='bytes')
25582558
assertresultisnp.add
2559+
2560+
deftest__array_namespace__(self):
2561+
arr=np.arange(2)
2562+
2563+
xp=arr.__array_namespace__()
2564+
assertxpisnp
2565+
xp=arr.__array_namespace__(api_version="2021.12")
2566+
assertxpisnp
2567+
xp=arr.__array_namespace__(api_version="2022.12")
2568+
assertxpisnp
2569+
2570+
withpytest.raises(
2571+
ValueError,
2572+
match="Version\"2023.12\" of the Array API Standard "
2573+
"is not supported."
2574+
):
2575+
arr.__array_namespace__(api_version="2023.12")

‎tools/ci/array-api-skips.txt‎

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# copy not implemented
2+
array_api_tests/test_creation_functions.py::test_asarray_arrays
3+
4+
# waiting on NumPy to allow/revert distinct NaNs for np.unique
5+
# https://github.com/numpy/numpy/issues/20326#issuecomment-1012380448
6+
array_api_tests/test_set_functions.py
7+
8+
# https://github.com/numpy/numpy/issues/21213
9+
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]
10+
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]
11+
# noted diversions from spec
12+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
13+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
14+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
15+
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
16+
array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
17+
array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
18+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
19+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
20+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
21+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
22+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
23+
array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
24+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
25+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
26+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
27+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
28+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
29+
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
30+
31+
# asarray() got an unexpected keyword argument 'copy'
32+
array_api_tests/test_array_object.py::test_setitem
33+
# array_api_tests/test_array_object.py::test_setitem_masking
34+
array_api_tests/test_creation_functions.py::test_asarray_scalars
35+
36+
# fft test suite is buggy as of 83f0bcdc
37+
array_api_tests/test_fft.py
38+
39+
# missing isdtype, astype and finfo return type misalignment
40+
array_api_tests/test_data_type_functions.py::test_finfo[float32]
41+
array_api_tests/test_data_type_functions.py::test_isdtype
42+
array_api_tests/test_data_type_functions.py::test_astype
43+
44+
# missing names
45+
array_api_tests/test_has_names.py::test_has_names[linalg-cross]
46+
array_api_tests/test_has_names.py::test_has_names[linalg-matmul]
47+
array_api_tests/test_has_names.py::test_has_names[linalg-matrix_norm]
48+
array_api_tests/test_has_names.py::test_has_names[linalg-matrix_transpose]
49+
array_api_tests/test_has_names.py::test_has_names[linalg-outer]
50+
array_api_tests/test_has_names.py::test_has_names[linalg-svdvals]
51+
array_api_tests/test_has_names.py::test_has_names[linalg-tensordot]
52+
array_api_tests/test_has_names.py::test_has_names[linalg-vecdot]
53+
array_api_tests/test_has_names.py::test_has_names[linalg-vector_norm]
54+
array_api_tests/test_has_names.py::test_has_names[set-unique_all]
55+
array_api_tests/test_has_names.py::test_has_names[set-unique_counts]
56+
array_api_tests/test_has_names.py::test_has_names[set-unique_inverse]
57+
array_api_tests/test_has_names.py::test_has_names[set-unique_values]
58+
array_api_tests/test_has_names.py::test_has_names[manipulation-concat]
59+
array_api_tests/test_has_names.py::test_has_names[manipulation-permute_dims]
60+
array_api_tests/test_has_names.py::test_has_names[data_type-astype]
61+
array_api_tests/test_has_names.py::test_has_names[data_type-isdtype]
62+
array_api_tests/test_has_names.py::test_has_names[elementwise-acos]
63+
array_api_tests/test_has_names.py::test_has_names[elementwise-acosh]
64+
array_api_tests/test_has_names.py::test_has_names[elementwise-asin]
65+
array_api_tests/test_has_names.py::test_has_names[elementwise-asinh]
66+
array_api_tests/test_has_names.py::test_has_names[elementwise-atan]
67+
array_api_tests/test_has_names.py::test_has_names[elementwise-atan2]
68+
array_api_tests/test_has_names.py::test_has_names[elementwise-atanh]
69+
array_api_tests/test_has_names.py::test_has_names[elementwise-bitwise_left_shift]
70+
array_api_tests/test_has_names.py::test_has_names[elementwise-bitwise_invert]
71+
array_api_tests/test_has_names.py::test_has_names[elementwise-bitwise_right_shift]
72+
array_api_tests/test_has_names.py::test_has_names[elementwise-pow]
73+
array_api_tests/test_has_names.py::test_has_names[linear_algebra-matrix_transpose]
74+
array_api_tests/test_has_names.py::test_has_names[linear_algebra-vecdot]
75+
array_api_tests/test_has_names.py::test_has_names[array_method-to_device]
76+
array_api_tests/test_has_names.py::test_has_names[array_attribute-device]
77+
78+
# missing linalg names
79+
array_api_tests/test_linalg.py::test_cross
80+
array_api_tests/test_linalg.py::test_matrix_norm
81+
array_api_tests/test_linalg.py::test_matrix_transpose
82+
array_api_tests/test_linalg.py::test_outer
83+
array_api_tests/test_linalg.py::test_pinv
84+
array_api_tests/test_linalg.py::test_svdvals
85+
array_api_tests/test_linalg.py::test_vecdot
86+
87+
# missing names
88+
array_api_tests/test_manipulation_functions.py::test_concat
89+
array_api_tests/test_manipulation_functions.py::test_permute_dims
90+
91+
# a few misalignments
92+
array_api_tests/test_operators_and_elementwise_functions.py
93+
array_api_tests/test_signatures.py::test_func_signature[std]
94+
array_api_tests/test_signatures.py::test_func_signature[var]
95+
array_api_tests/test_signatures.py::test_func_signature[unique_all]
96+
array_api_tests/test_signatures.py::test_func_signature[unique_counts]
97+
array_api_tests/test_signatures.py::test_func_signature[unique_inverse]
98+
array_api_tests/test_signatures.py::test_func_signature[unique_values]
99+
array_api_tests/test_signatures.py::test_func_signature[asarray]
100+
array_api_tests/test_signatures.py::test_func_signature[empty_like]
101+
array_api_tests/test_signatures.py::test_func_signature[eye]
102+
array_api_tests/test_signatures.py::test_func_signature[full]
103+
array_api_tests/test_signatures.py::test_func_signature[full_like]
104+
array_api_tests/test_signatures.py::test_func_signature[linspace]
105+
array_api_tests/test_signatures.py::test_func_signature[ones]
106+
array_api_tests/test_signatures.py::test_func_signature[ones_like]
107+
array_api_tests/test_signatures.py::test_func_signature[zeros_like]
108+
array_api_tests/test_signatures.py::test_func_signature[concat]
109+
array_api_tests/test_signatures.py::test_func_signature[permute_dims]
110+
array_api_tests/test_signatures.py::test_func_signature[reshape]
111+
array_api_tests/test_signatures.py::test_func_signature[argsort]
112+
array_api_tests/test_signatures.py::test_func_signature[sort]
113+
array_api_tests/test_signatures.py::test_func_signature[astype]
114+
array_api_tests/test_signatures.py::test_func_signature[isdtype]
115+
array_api_tests/test_signatures.py::test_func_signature[acos]
116+
array_api_tests/test_signatures.py::test_func_signature[acosh]
117+
array_api_tests/test_signatures.py::test_func_signature[asin]
118+
array_api_tests/test_signatures.py::test_func_signature[asinh]
119+
array_api_tests/test_signatures.py::test_func_signature[atan]
120+
array_api_tests/test_signatures.py::test_func_signature[atan2]
121+
array_api_tests/test_signatures.py::test_func_signature[atanh]
122+
array_api_tests/test_signatures.py::test_func_signature[bitwise_left_shift]
123+
array_api_tests/test_signatures.py::test_func_signature[bitwise_invert]
124+
array_api_tests/test_signatures.py::test_func_signature[bitwise_right_shift]
125+
array_api_tests/test_signatures.py::test_func_signature[pow]
126+
array_api_tests/test_signatures.py::test_func_signature[matrix_transpose]
127+
array_api_tests/test_signatures.py::test_func_signature[vecdot]
128+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.cross]
129+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.matmul]
130+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.cholesky]
131+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.matrix_norm]
132+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.matrix_rank]
133+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.matrix_transpose]
134+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.outer]
135+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.pinv]
136+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.svdvals]
137+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.tensordot]
138+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.vecdot]
139+
array_api_tests/test_signatures.py::test_extension_func_signature[linalg.vector_norm]
140+
array_api_tests/test_signatures.py::test_array_method_signature[__array_namespace__]
141+
array_api_tests/test_signatures.py::test_array_method_signature[to_device]
142+
143+
# unexpected argument 'stable'
144+
array_api_tests/test_sorting_functions.py::test_argsort
145+
array_api_tests/test_sorting_functions.py::test_sort
146+
147+
# missing aliases
148+
array_api_tests/test_special_cases.py::test_unary
149+
array_api_tests/test_special_cases.py::test_binary
150+
151+
# asarray() got an unexpected keyword argument 'copy'
152+
array_api_tests/test_special_cases.py::test_iop
153+
154+
# got an unexpected keyword argument 'correction'
155+
array_api_tests/test_statistical_functions.py::test_std
156+
array_api_tests/test_statistical_functions.py::test_var
157+
158+
# assertionError: out.dtype=float32, but should be float64 [sum(float32)]
159+
array_api_tests/test_statistical_functions.py::test_sum

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp