@@ -39,12 +39,20 @@ should be taken into account:
3939 array-api-compat. The addition of functions that are not part of the array
4040 API standard is currently out-of-scope for this package.
4141
42- - * No Monkey Patching.* ` array-api-compat ` should not attempt to modify anything
43- about the underlying library. It is a * wrapper* library only.
42+ - * No side-effects* . array_api_compat behavior should be localized to only the
43+ specific code that imports and uses it. It should be invisible to end-users
44+ or users of dependent codes. This specifically applies to the next two
45+ points.
4446
45- - * No modifying the array object.* Due to the above restrictions, the array
46- (or tensor) object of the array library cannot be modified. Any behavior
47- that is built-in to the array object, such as the behavior of [ array
47+ - * No Monkey Patching.* ` array-api-compat ` should not attempt to modify
48+ anything about the underlying library. It is a * wrapper* library only.
49+
50+ - * No modifying the array object.* The array (or tensor) object of the array
51+ library cannot be modified. Attempting to wrap or subclass a library's array
52+ object would break the localized wrapping goal.
53+
54+ Any behavior that is built-in to the array object, such as the behavior of
55+ [ array
4856 methods] ( https://data-apis.org/array-api/latest/API_specification/array_object.html )
4957 is therefore left unwrapped. Users can workaround issues by using
5058 corresponding [ elementwise
@@ -53,10 +61,10 @@ should be taken into account:
5361 functions] ( ../helper-functions.md ) provided by array-api-compat instead of
5462 methods like ` to_device ` .
5563
56- - * Avoid Restricting Non-Standard Behavior.* All array libraries have
57- functions and behaviors that are outside of the scope of what is specified
58- by the standard. These behaviors should be left intact whenever possible,
59- unless the standard explicitly disallows something. This means
64+ - * Avoid Restricting Behavior Outside the Scope of the Standard .* All array
65+ libraries have functions and behaviors that are outside of the scope of what
66+ is specified by the standard. These behaviors should be left intact whenever
67+ possible, unless the standard explicitly disallows something. This means
6068
6169 - All namespaces are * extended* with wrapper functions. You may notice the
6270 extensive use of ` import * ` in various files in ` array_api_compat ` . While
@@ -72,18 +80,9 @@ should be taken into account:
7280
7381## Avoiding Code Duplication
7482
75- As noted before, the goal of this library is to reuse the NumPy and CuPy array
76- objects, rather than wrapping or extending them. This means that the functions
77- need to accept and return ` np.ndarray ` for NumPy and ` cp.ndarray ` for CuPy.
78-
79- Each namespace (` array_api_compat.numpy ` , ` array_api_compat.cupy ` , and
80- ` array_api_compat.torch ` ) is populated with the normal library namespace (like
81- ` from numpy import * ` ). Then specific functions are replaced with wrapped
82- variants.
83-
84- Since NumPy and CuPy are nearly identical in behavior, most wrapping logic can
85- be shared between them. Wrapped functions that have the same logic between
86- NumPy and CuPy are in ` array_api_compat/common/ ` .
83+ Since NumPy, CuPy, and to a degree, Dask, are nearly identical in behavior,
84+ most wrapping logic can be shared between them. Wrapped functions that have
85+ the same logic between multiple libraries are in ` array_api_compat/common/ ` .
8786These functions are defined like
8887
8988``` py
@@ -93,7 +92,7 @@ def acos(x, /, xp):
9392 return xp.arccos(x)
9493```
9594
96- The ` xp ` argument refers to the original array namespace (either ` numpy ` or
95+ The ` xp ` argument refers to the original array namespace (e.g., ` numpy ` or
9796` cupy ` ). Then in the specific ` array_api_compat/numpy/ ` and
9897` array_api_compat/cupy/ ` namespaces, the ` @get_xp ` decorator is applied to
9998these functions, which automatically removes the ` xp ` argument from the
@@ -123,38 +122,38 @@ import cupy as cp
123122acos = get_xp(cp)(_aliases.acos)
124123```
125124
126- Since NumPy and CuPy are nearly identical in their behaviors, this allows
127- writing the wrapping logic for both libraries only once.
128-
129- PyTorch uses a similar layout in ` array_api_compat/torch/ ` , but it differs
130- enough from NumPy/CuPy that very few common wrappers for those libraries are
131- reused.
132-
133- See https://numpy.org/doc/stable/reference/array_api.html for a full list of
134- changes from the base NumPy (the differences for CuPy are nearly identical). A
135- corresponding document does not yet exist for PyTorch, but you can examine the
136- various comments in the
137- [ implementation] ( https://github.com/data-apis/array-api-compat/blob/main/array_api_compat/torch/_aliases.py )
138- to see what functions and behaviors have been wrapped.
125+ Most NumPy and CuPy are defined in this way, since their behaviors are nearly
126+ identical PyTorch uses a similar layout in ` array_api_compat/torch/ ` , but it
127+ differs enough from NumPy/CuPy that very few common wrappers for those
128+ libraries are reused. Dask is close to NumPy in behavior and so most Dask
129+ functions also reuse the NumPy/CuPy common wrappers.
139130
140131## Tests
141132
142133The majority of the behavior for array-api-compat is tested by the
143134[ array-api-tests] ( https://github.com/data-apis/array-api-tests ) test suite for
144- the array API standard. There are also specific tests in
135+ the array API standard. There are also array-api-compat specific tests in
145136[ ` tests/ ` ] ( https://github.com/data-apis/array-api-compat/tree/main/tests ) .
146137These tests should be limited to things that are not tested by the test suite,
147- e.g., tests for [ helper functions] ( ../helper-functions.md ) or for behavior that is
148- not strictly required by the standard.
138+ e.g., tests for [ helper functions] ( ../helper-functions.md ) or for behavior
139+ that is not strictly required by the standard.
149140
150141array-api-tests is run against all supported libraries are tested on CI
151- (except for JAX,
152- [ wrapping] ( jax-support ) ). This is achieved by a [ reusable GitHub Actions
142+ ([ except for JAX] ( jax-support ) ). This is achieved by a [ reusable GitHub Actions
153143Workflow] ( https://github.com/data-apis/array-api-compat/blob/main/.github/workflows/array-api-tests.yml ) .
154144Most libraries have tests that must be xfailed or skipped for various reasons.
155145These are defined in specific ` <library>-xfails.txt ` files and are
156146automatically forwarded to array-api-tests.
157147
148+ You may often need to update these xfail files, either to add new xfails
149+ (e.g., because of new test suite features, or because a test that was
150+ previously thought to be passing actually flaky fails). Try to keep the xfails
151+ files organized, with comments pointing to upstream issues whenever possible.
152+
153+ From time to time, xpass tests should be removed from the xfail files, but be
154+ aware that many xfail tests are flaky, so an xpass should only be removed if
155+ you know that the underlying issue has been fixed.
156+
158157Array libraries that require a GPU to run (currently only CuPy) cannot be
159158tested on CI. There is a helper script ` test_cupy.sh ` that can be used to
160159manually test CuPy on a machine with a CUDA GPU.
0 commit comments