torchwrench.extras.numpy package¶
- class torchwrench.extras.numpy.InvalidTorchDType(*args, **kwargs)[source]¶
Bases:
objectDefault 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.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]
- torchwrench.extras.numpy.is_numpy_number_like(x: Any) TypeGuard[ndarray | number][source]¶
Returns True if x is an instance of a numpy number type, a np.bool_ or a zero-dimensional numpy array. If numpy is not installed, this function always returns False.
- torchwrench.extras.numpy.is_numpy_scalar_like(x: Any) TypeGuard[ndarray | generic][source]¶
Returns True if x is an instance of a numpy number type or a zero-dimensional numpy array. If numpy is not installed, this function always returns False.
-
torchwrench.extras.numpy.logical_and_lst(*args, start=
None)¶ Reduce elements using “and” operator (&).
-
torchwrench.extras.numpy.logical_or_lst(*args, start=
None)¶ Reduce elements using “or” operator (|).
-
torchwrench.extras.numpy.merge_numpy_dtypes(dtypes: Iterable[dtype | T_EmptyNp], *, empty: T_EmptyNp =
dtype('V')) dtype | T_EmptyNp[source]¶
-
torchwrench.extras.numpy.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.ndarray_to_tensor(x: ndarray | number, *, device: device | None | 'default' | 'cuda_if_available' | str | int =
None, dtype: dtype | None | 'default' | str | DTypeEnum =None) Tensor[source]¶ Convert numpy array to PyTorch tensor.
-
torchwrench.extras.numpy.numpy_all_eq(x: generic | ndarray, dim: None =
None) bool[source]¶ - torchwrench.extras.numpy.numpy_all_eq(x: generic | ndarray, dim: int) ndarray
- torchwrench.extras.numpy.numpy_complex_dtype_to_float_dtype(dtype: dtype) dtype[source]¶
Returns the associated float dtype from complex dtype. If input dtype is not complex, it just returns the same dtype.
- torchwrench.extras.numpy.numpy_dtype_to_fill_value(dtype: Any) bool | int | float | complex | None | str | bytes[source]¶
-
torchwrench.extras.numpy.numpy_dtype_to_torch_dtype(dtype: dtype, *, invalid: T_Invalid =
InvalidTorchDType()) dtype | T_Invalid[source]¶
- torchwrench.extras.numpy.numpy_item(x: ndarray | generic | bool | int | float | complex | None | str | bytes) generic[source]¶
-
torchwrench.extras.numpy.numpy_to_tensor(x: ndarray | number, *, device: device | None | 'default' | 'cuda_if_available' | str | int =
None, dtype: dtype | None | 'default' | str | DTypeEnum =None) Tensor[source]¶ Convert numpy array to PyTorch tensor.
-
torchwrench.extras.numpy.numpy_topk(x: ndarray, k: int, dim: int =
-1, largest: bool =True, sorted: bool =True) tuple[ndarray, ndarray][source]¶
- torchwrench.extras.numpy.numpy_view_as_complex(x: ndarray) ndarray[source]¶
Convert complex array to float array.
- Args:
x: The input float array of any shape (…, 2)
- Returns:
x_real: The same data in a complex array of shape (…,)
- torchwrench.extras.numpy.numpy_view_as_real(x: ndarray) ndarray[source]¶
Convert complex array to float array.
- Args:
x: The input complex array of any shape (…,)
- Returns:
x_real: The same data in a float array of shape (…, 2)
-
torchwrench.extras.numpy.scan_numpy_dtype(x: Any, *, empty: T_EmptyNp =
dtype('V')) dtype | T_EmptyNp[source]¶
-
torchwrench.extras.numpy.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_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.tensor_to_ndarray(x: Tensor, *, dtype: str | dtype | None =
None, force: bool =False) ndarray[source]¶ Convert PyTorch tensor to numpy array.
-
torchwrench.extras.numpy.tensor_to_numpy(x: Tensor, *, dtype: str | dtype | None =
None, force: bool =False) ndarray[source]¶ Convert PyTorch tensor to numpy array.
-
torchwrench.extras.numpy.to_ndarray(x: Tensor | ndarray | Iterable | bool | int | float | complex | None | str | bytes, *, dtype: str | dtype | None =
None, force: bool =False) ndarray[source]¶ Convert input to numpy array. Works with any arbitrary object.
-
torchwrench.extras.numpy.to_numpy(x: Tensor | ndarray | Iterable | bool | int | float | complex | None | str | bytes, *, dtype: str | dtype | None =
None, force: bool =False) ndarray[source]¶ Convert input to numpy array. Works with any arbitrary object.
Submodules¶
- torchwrench.extras.numpy.definitions module
- torchwrench.extras.numpy.functional module
- torchwrench.extras.numpy.functional.is_numpy_bool_array
- torchwrench.extras.numpy.functional.is_numpy_integral_array
- torchwrench.extras.numpy.functional.is_numpy_number_like
- torchwrench.extras.numpy.functional.is_numpy_scalar_like
- torchwrench.extras.numpy.functional.is_numpy_str_array
- torchwrench.extras.numpy.functional.ndarray_to_tensor
- torchwrench.extras.numpy.functional.numpy_all_eq
- torchwrench.extras.numpy.functional.numpy_all_ne
- torchwrench.extras.numpy.functional.numpy_complex_dtype_to_float_dtype
- torchwrench.extras.numpy.functional.numpy_is_complex
- torchwrench.extras.numpy.functional.numpy_is_complex_dtype
- torchwrench.extras.numpy.functional.numpy_is_floating_point
- torchwrench.extras.numpy.functional.numpy_item
- torchwrench.extras.numpy.functional.numpy_to_tensor
- torchwrench.extras.numpy.functional.numpy_topk
- torchwrench.extras.numpy.functional.numpy_view_as_complex
- torchwrench.extras.numpy.functional.numpy_view_as_real
- torchwrench.extras.numpy.functional.tensor_to_ndarray
- torchwrench.extras.numpy.functional.tensor_to_numpy
- torchwrench.extras.numpy.functional.to_ndarray
- torchwrench.extras.numpy.functional.to_numpy
- torchwrench.extras.numpy.saving module
- torchwrench.extras.numpy.saving.dump_ndarray
- torchwrench.extras.numpy.saving.dump_numpy
- torchwrench.extras.numpy.saving.dumps_ndarray
- torchwrench.extras.numpy.saving.load_ndarray
- torchwrench.extras.numpy.saving.load_numpy
- torchwrench.extras.numpy.saving.loads_ndarray
- torchwrench.extras.numpy.saving.read_ndarray
- torchwrench.extras.numpy.saving.save_ndarray
- torchwrench.extras.numpy.scan_info module
- torchwrench.extras.numpy.scan_info.InvalidTorchDType
- torchwrench.extras.numpy.scan_info.ShapeDTypeInfo
- torchwrench.extras.numpy.scan_info.get_default_numpy_dtype
- torchwrench.extras.numpy.scan_info.merge_numpy_dtypes
- torchwrench.extras.numpy.scan_info.merge_torch_dtypes
- torchwrench.extras.numpy.scan_info.numpy_dtype_to_fill_value
- torchwrench.extras.numpy.scan_info.numpy_dtype_to_torch_dtype
- torchwrench.extras.numpy.scan_info.scan_numpy_dtype
- torchwrench.extras.numpy.scan_info.scan_shape_dtypes
- torchwrench.extras.numpy.scan_info.scan_torch_dtype
- torchwrench.extras.numpy.scan_info.torch_dtype_to_numpy_dtype