Backend deviations#
These are the places where a backend passes Backend conformance but behaves differently from NumPy in a way your code can notice; each row gives the workaround. Differences inside the per-op tolerance (eigenvector sign, float32 round-off) are not listed.
Op |
Backend |
Behavior (NumPy: |
Workaround |
|---|---|---|---|
|
JAX |
With |
Set |
|
Torch |
Python floats become |
Pass |
|
Torch |
|
Cast first: |
|
Torch |
Raises |
Check |
|
NumPy, CuPy |
Python-loop fallback ( |
Return tuples from the mapped function, or use JAX/Torch native
|
|
NumPy, Torch, CuPy |
Tracing a function built on these backends fails (NumPy:
|
JIT only |
The Torch workarounds together:
import numpy as np
from spacecore import TorchOps
ops = TorchOps()
a = ops.asarray([[1.0, 2.0], [3.0, 4.0]], dtype=np.float64) # not float32
z = ops.asarray(np.eye(2), dtype=np.complex128)
out = ops.matmul(ops.astype(a, ops.get_dtype(z)), z) # promote before mixing
im = ops.imag(a) if ops.is_complex_dtype(ops.get_dtype(a)) else ops.zeros_like(a)
assert ops.get_dtype(out) == ops.get_dtype(z) and float(ops.sum(im)) == 0.0
See Context, dtype and conversion for dtype promotion and cross-backend conversion.