torchoutil.extras.numpy.scan_info module

class 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 ShapeDTypeInfo(
*args,
**kwds,
)[source]

Bases: Generic[T_Invalid, T_EmptyTorch, T_EmptyNp]

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

Returns the shape and the hdf_dtype for an input.

scan_torch_dtype(
x: Any,
*,
invalid: T_Invalid = InvalidTorchDType(),
empty: T_EmptyTorch | None = 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.

torch_dtype_to_numpy_dtype(
dtype: dtype,
) dtype[source]