ezmsg.sigproc.util.array
Portable helpers for Array API interoperability.
These utilities smooth over differences between Array API libraries
(NumPy, PyTorch, MLX, CuPy, etc.) — in particular around device
placement and dtype introspection, which are not uniformly supported.
Functions
-
array_device(x)[source]
Return the device of an array, or None for device-less libraries.
-
is_complex_dtype(dtype)[source]
Check whether dtype is a complex type, portably across backends.
- Return type:
bool
-
is_float_dtype(xp, dtype)[source]
Check whether dtype is a real floating-point type, portably.
- Return type:
bool
-
xp_asarray(xp, obj, *, dtype=None, device=None)[source]
Portable xp.asarray that omits unsupported kwargs.
Some Array API libraries (e.g. MLX) don’t accept a device keyword.
This helper builds the kwargs dict dynamically so that only supported
arguments are forwarded.
-
xp_create(fn, *args, dtype=None, device=None, **extra)[source]
Call a creation function (zeros, ones, eye) portably.
Omits device if it is None (for libraries that don’t support it).