You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There, each function, constant, and object is described with details
100
101
on parameters, return values, and special cases.
101
102
102
103
### Testing against Array API
103
104
104
-
There are two main ways to test your API for compliance: Either using
105
-
`array-api-tests` suite or testing your API manually against `array-api-strict`
106
-
reference implementation.
105
+
There are two main ways to test your API for compliance: either using
106
+
`array-api-tests` suite or testing your API manually against the
107
+
`array-api-strict`reference implementation.
107
108
108
109
#### Array API Test suite (Recommended)
109
110
110
111
{ref}`array-api-tests` is a test suite which verifies that your API
111
-
for adhering to the standard. For each function or method it confirms
112
-
it's importable, verifies the signature, and generates multiple test
112
+
adheres to the standard. For each function or method, it confirms
113
+
it's importable, verifies the signature, generates multiple test
113
114
cases with [hypothesis](https://hypothesis.readthedocs.io/en/latest/)
114
-
package and runs asserts for the outputs.
115
+
package, and runs assertions on the outputs.
115
116
116
117
The setup details are enclosed in the GitHub repository, so here we
117
118
cover only the minimal workflow:
@@ -120,44 +121,45 @@ cover only the minimal workflow:
120
121
2. Clone `array-api-tests`, and set `ARRAY_API_TESTS_MODULE` environment
121
122
variable to your package import name.
122
123
3. Inside the `array-api-tests` directory run `pytest` command. There are
123
-
multiple useful options delivered by the test suite, a few worth mentioning:
124
+
multiple useful options delivered by the test suite. A few worth mentioning:
124
125
-`--max-examples=1000` - maximal number of test cases to generate by the
125
126
hypothesis. This allows you to balance between execution time of the test
126
127
suite and thoroughness of the testing. It's advised to use as many examples
127
128
as the time buget can fit. Each test case is a random combination of
128
-
possible inputs: the more cases, the higher chance of finding an unsupported
129
-
edge case.
130
-
- With `--xfails-file` option you can describe which tests are expected to
131
-
fail - it's impossible to get the whole API perfectly implemented on a
129
+
possible inputs: the more cases, the higher chance of finding an
130
+
unsupported edge case.
131
+
- With the `--xfails-file` option, you can describe which tests are expected
132
+
to fail. It's impossible to get the whole API perfectly implemented on a
132
133
first try, so tracking what still fails gives you more control over the
133
134
state of your API.
134
135
-`-o xfail_strict=<bool>` is often used with the previous one. If a test
135
-
expected to fail actually passes (`XPASS`) then you can decide whether
136
+
expected to fail actually passes (`XPASS`), then you can decide whether
136
137
to ignore that fact or raise it as an error.
137
-
-`--skips-file` for skipping tests. At times some failing tests might stall
138
-
the execution time of the test suite - in that case the most convenient
138
+
-`--skips-file` for skipping tests. At times, some failing tests might stall
139
+
the execution time of the test suite. In that case, the most convenient
139
140
option is to skip these for the time being.
140
141
141
142
We strongly advise you to embed this setup in your CI as well. This will allow
142
143
you to monitor the coverage live, and make sure new changes don't break existing
143
-
API. For a reference here's a [NumPy Array API Tests CI setup](https://github.com/numpy/numpy/blob/581d10f43b539a189a2d37856e5130464de9e5f6/.github/workflows/linux.yml#L296).
144
+
APIs. For a reference, here's a [NumPy Array API Tests CI setup](https://github.com/numpy/numpy/blob/581d10f43b539a189a2d37856e5130464de9e5f6/.github/workflows/linux.yml#L296).
144
145
145
146
146
147
#### Array API Strict
147
148
148
149
A simpler, and more manual, way of testing the Array API coverage is to
149
-
run your API calls along with {ref}`array-api-strict` Python implementation.
150
+
run your API calls along with the {ref}`array-api-strict` Python implementation.
150
151
151
152
This way you can ensure the outputs coming from your API match the minimal
152
-
reference implementation, but bear in mind you need to write the tests cases
153
-
yourself, so you need to also take into account the edge cases as well.
153
+
reference implementation. Bear in mind, however, that you need to write
154
+
the tests cases yourself, so you need to also take into account the edge
155
+
cases as well.
154
156
155
157
156
158
(array-consumers)=
157
159
158
160
## Array Consumers
159
161
160
-
For array consumers the main premise is to keep in mind that your **array
162
+
For array consumers, the main premise is to keep in mind that your **array
161
163
manipulation operations should not lock in for a particular array producing
162
164
library**. For instance, if you use NumPy for arrays, then your code could
163
165
contain:
@@ -172,7 +174,7 @@ return np.dot(c, b)
172
174
```
173
175
174
176
The first step should be as simple as assigning `np` namespace to a dedicated
175
-
namespace variable - the convention in the ecosystem is to name it `xp`. Then
177
+
namespace variable. The convention in the ecosystem is to name it `xp`. Then
176
178
making sure that each method and function call is something that Array API
177
179
supports is vital. `dot` is present in the NumPy's API but the standard doesn't
178
180
support it. Let's use `tensordot` instead - both NumPy and the standard define it:
@@ -223,6 +225,6 @@ offers a set of useful utility functions, such as:
0 commit comments