brainevent.jaxtype_to_warptype#
- brainevent.jaxtype_to_warptype(dtype)[source]#
Convert a JAX / NumPy dtype to the corresponding Warp scalar type.
Maps standard NumPy data types (which are also used by JAX) to their Warp equivalents. This is needed when constructing Warp kernel signatures or Warp array types from JAX metadata.
- Parameters:
dtype (
dtype|type) – The data type to convert. Accepts anythingnumpy.dtypecan normalize, including NumPy scalar types (np.float32), JAX dtypes (jnp.float32),np.dtypeinstances (np.dtype('float32')), and Python builtins (float,int,bool). Builtins are normalized vianumpy.dtypefirst (e.g.float->float64,int-> the platform default integer,bool->bool_).- Returns:
The corresponding Warp scalar type (e.g.,
warp.float32,warp.int32,warp.bool).- Return type:
- Raises:
ImportError – If the
warppackage is not installed.ValueError – If dtype cannot be normalized by
numpy.dtypeor does not correspond to any supported Warp type. Supported types are:float16,float32,float64,int8,int16,int32,int64,uint8,uint16,uint32,uint64, andbool_.bfloat16and complex dtypes are not supported by Warp and raise a clearValueError.
See also
jaxinfo_to_warpinfoConvert a full
jax.ShapeDtypeStructto a Warp array type.check_warp_installedVerify that Warp is available.
Notes
The dtype is first normalized with
numpy.dtype(dtype)so that Python builtins and dtype-like objects all resolve to a canonicalnumpy.dtypebefore mapping. This avoids the pitfall thatfloat == np.float64isFalseeven thoughnp.dtype(float)isfloat64. The mapping covers all scalar types supported by both NumPy and Warp.bfloat16(which Warp has no scalar for) and complex types are unsupported and raiseValueError.Examples
>>> import numpy as np >>> warp_type = jaxtype_to_warptype(np.float32) >>> warp_type # warp.float32 >>> jaxtype_to_warptype(float) is jaxtype_to_warptype(np.float64) True