torchwrench.extras.numpy.scan_info module

class torchwrench.extras.numpy.scan_info.InvalidTorchDType(*args, **kwargs)[source]

Bases: object

Default return type for torch_dtype when an invalid data is passed as argument of scan_torch_dtype function. (like str for example)

class torchwrench.extras.numpy.scan_info.ShapeDTypeInfo(shape: tuple[int, ...], torch_dtype: torch.dtype | +T_Invalid | +T_EmptyTorch, numpy_dtype: numpy.dtype | +T_EmptyNp, valid_shape: bool)[source]

Bases: Generic[T_Invalid, T_EmptyTorch, T_EmptyNp]

property fill_value : bool | int | float | complex | None | str | bytes
property get_ndim : int
property kind : str
numpy_dtype : dtype | T_EmptyNp
shape : Tuple[int, ...]
torch_dtype : dtype | T_Invalid | T_EmptyTorch
valid_shape : bool
torchwrench.extras.numpy.scan_info.get_default_numpy_dtype() dtype[source]
torchwrench.extras.numpy.scan_info.merge_numpy_dtypes(dtypes: Iterable[dtype | T_EmptyNp], *, empty: T_EmptyNp = dtype('V')) dtype | T_EmptyNp[source]
torchwrench.extras.numpy.scan_info.merge_torch_dtypes(dtypes: Iterable[dtype | T_Invalid | T_EmptyNp], *, invalid: T_Invalid = InvalidTorchDType(), empty: T_EmptyNp = None) dtype | T_Invalid | T_EmptyNp[source]
torchwrench.extras.numpy.scan_info.numpy_dtype_to_fill_value(dtype: Any) bool | int | float | complex | None | str | bytes[source]
torchwrench.extras.numpy.scan_info.numpy_dtype_to_torch_dtype(dtype: dtype, *, invalid: T_Invalid = InvalidTorchDType()) dtype | T_Invalid[source]
torchwrench.extras.numpy.scan_info.scan_numpy_dtype(x: Any, *, empty: T_EmptyNp = dtype('V')) dtype | T_EmptyNp[source]
torchwrench.extras.numpy.scan_info.scan_shape_dtypes(x: Any, *, accept_heterogeneous_shape: bool = False, empty_torch: T_EmptyTorch = None, empty_np: T_EmptyNp = dtype('V')) ShapeDTypeInfo[InvalidTorchDType, T_EmptyTorch, T_EmptyNp][source]

Returns the shape and the hdf_dtype for an input.

torchwrench.extras.numpy.scan_info.scan_torch_dtype(x: Any, *, invalid: T_Invalid = InvalidTorchDType(), empty: T_EmptyTorch = None) dtype | T_Invalid | T_EmptyTorch[source]

Returns torch dtype of an arbitrary object. Works recursively on tuples and lists. An instance of InvalidTorchDType can be returned if a str is passed.

torchwrench.extras.numpy.scan_info.torch_dtype_to_numpy_dtype(dtype: dtype) dtype[source]