merlin.utils.dtypes module
Utilities for converting between various dtype representations and torch dtypes.
- merlin.utils.dtypes.to_torch_dtype(dtype_like, *, default=None)
Convert common dtype representations (strings, numpy dtypes, torch dtypes) into torch dtypes.
- Parameters:
dtype_like (object) – Input representation to convert.
default (torch.dtype | None) – Fallback dtype if the representation is unknown. Defaults to
torch.float32whendtype_likeisNone.
- Returns:
Torch dtype corresponding to the requested representation.
- Return type:
- Raises:
TypeError – If the value cannot be mapped and no default is provided.
- merlin.utils.dtypes.complex_dtype_for(dtype_like)
Return the matching complex dtype for the provided float or complex dtype.
- merlin.utils.dtypes.float_dtype_for(dtype_like)
Return the matching float dtype for the provided float or complex dtype.
- merlin.utils.dtypes.resolve_float_complex(dtype)
Given a torch dtype representing either the float or complex side, return the matching pair.
- Parameters:
dtype (torch.dtype) – Torch float or complex dtype.
- Returns:
Matching
(float_dtype, complex_dtype)pair.- Return type:
- Raises:
TypeError – If the dtype is not one of the supported float-complex types.