Array API coverage#
Many SciPy functions supports multiple array types via the Python array API standard.
This standard allows users to use any array API compatible array library with parts of SciPy out of the box, with with the main principle being “array type in equals array type out”. Currently, SciPy supports NumPy, PyTorch, JAX, Dask and CuPy arrays.
This clustering example shows usage with PyTorch tensors as inputs and return values:
>>> import torch
>>> from scipy.cluster.vq import vq
>>> code_book = torch.tensor([[1., 1., 1.],
... [2., 2., 2.]])
>>> features = torch.tensor([[1.9, 2.3, 1.7],
... [1.5, 2.5, 2.2],
... [0.8, 0.6, 1.7]])
>>> code, dist = vq(features, code_book)
>>> code
tensor([1, 1, 0], dtype=torch.int32)
>>> dist
tensor([0.4359, 0.7348, 0.8307])
The below tables show the current state of alternative backend support across
SciPy’s modules. Public functions, function-like callables, and classes are
included in the tables. Parts of the public API which are deemed out-of-scope
are excluded from consideration when calculating coverage percentages. If a
module or submodule contains no in-scope functions, it is excluded from the
tables. For example, scipy.datasets is excluded because its contents are
considered out-of-scope.
Support on CPU#
module |
torch |
jax |
dask |
|---|---|---|---|
cluster.vq (4) |
100% |
100% |
100% |
cluster.hierarchy (29) |
97% |
97% |
97% |
constants (3) |
100% |
100% |
100% |
differentiate (3) |
100% |
100% |
0% |
fft (32) |
100% |
94% |
100% |
integrate (28) |
32% |
29% |
25% |
interpolate (30) |
53% |
53% |
20% |
linalg (95) |
6% |
6% |
5% |
0% |
0% |
0% |
|
ndimage (73) |
99% |
99% |
99% |
optimize (70) |
7% |
6% |
6% |
75% |
0% |
0% |
|
signal (149) |
62% |
62% |
60% |
signal.windows (26) |
96% |
96% |
92% |
sparse (52) |
0% |
0% |
0% |
sparse.linalg (35) |
6% |
6% |
6% |
sparse.csgraph (25) |
0% |
0% |
0% |
spatial (9) |
11% |
11% |
0% |
spatial.distance (27) |
56% |
56% |
56% |
75% |
75% |
0% |
|
special (313) |
89% |
89% |
73% |
stats (149) |
70% |
59% |
34% |
0% |
0% |
0% |
|
stats.qmc (11) |
0% |
0% |
0% |
Support on GPU#
module |
cupy |
torch |
jax |
|---|---|---|---|
cluster.vq (4) |
25% |
25% |
25% |
cluster.hierarchy (29) |
28% |
28% |
28% |
constants (3) |
100% |
100% |
100% |
differentiate (3) |
100% |
100% |
100% |
fft (32) |
75% |
75% |
75% |
integrate (28) |
36% |
32% |
29% |
interpolate (30) |
30% |
3% |
3% |
linalg (95) |
6% |
6% |
6% |
0% |
0% |
0% |
|
ndimage (73) |
93% |
0% |
1% |
optimize (70) |
7% |
7% |
6% |
100% |
75% |
0% |
|
signal (149) |
65% |
33% |
21% |
signal.windows (26) |
96% |
96% |
96% |
sparse (52) |
0% |
0% |
0% |
sparse.linalg (35) |
6% |
6% |
6% |
sparse.csgraph (25) |
0% |
0% |
0% |
spatial (9) |
11% |
11% |
11% |
spatial.distance (27) |
56% |
56% |
56% |
75% |
75% |
75% |
|
special (313) |
35% |
17% |
16% |
stats (149) |
60% |
46% |
50% |
0% |
0% |
0% |
|
stats.qmc (11) |
0% |
0% |
0% |
Support with JIT#
module |
jax |
|---|---|
cluster.vq (4) |
25% |
cluster.hierarchy (29) |
79% |
constants (3) |
100% |
differentiate (3) |
0% |
fft (32) |
94% |
integrate (28) |
18% |
interpolate (30) |
3% |
linalg (95) |
5% |
0% |
|
ndimage (73) |
1% |
optimize (70) |
6% |
0% |
|
signal (149) |
21% |
signal.windows (26) |
96% |
sparse (52) |
0% |
sparse.linalg (35) |
6% |
sparse.csgraph (25) |
0% |
spatial (9) |
0% |
spatial.distance (27) |
56% |
75% |
|
special (313) |
84% |
stats (149) |
52% |
0% |
|
stats.qmc (11) |
0% |