numpy.dtypes.register_dlpack_dtype#
- dtypes.register_dlpack_dtype(dlpack_key, dtype, /)[source]#
Register a NumPy dtype for a DLPack
(code, bits)pair so thatnumpy.from_dlpackcan import it andndarray.__dlpack__can export it. Built-in dtype mappings take priority on import.If you think a conflict is possible but unproblematic you may wrap this into a try/except block as NumPy will raise an error if another DType is already registered for the same (code, bits) pair. While an error is raised, the export is registered even on error.
Registering an identical (not equal) dtype multiple times is allowed but normally registration should happen at import time.
Warning
It is the responsibility of the registering user to ensure that the mapping is valid.
Note
This function was added primarily for
ml_dtypesand may be replaced with a different mechanism in the future. It is intended to be used by authors of user-defined dtypes and not end-users.- Parameters:
- dlpack_keytuple of int
(dl_dtype_code, dl_bits)matching the DLPackDLDataType, lanes is assumed to be always 1, currently.- dtypedtype
A NumPy dtype instance.
- Raises:
- ValueErrorIf a conflicting registration was already done.
See also