torchwrench.extras.numpy.functional module

torchwrench.extras.numpy.functional.is_numpy_bool_array(x: Any) TypeGuard[bool | ndarray][source]
torchwrench.extras.numpy.functional.is_numpy_integral_array(x: Any) TypeGuard[ndarray | generic][source]
torchwrench.extras.numpy.functional.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.functional.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.functional.is_numpy_str_array(x: Any) TypeGuard[str_ | ndarray][source]
torchwrench.extras.numpy.functional.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.functional.numpy_all_eq(x: generic | ndarray, dim: None = None) bool[source]
torchwrench.extras.numpy.functional.numpy_all_eq(x: generic | ndarray, dim: int) ndarray
torchwrench.extras.numpy.functional.numpy_all_ne(x: generic | ndarray) bool[source]
torchwrench.extras.numpy.functional.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.functional.numpy_is_complex(x: ndarray | generic) bool[source]
torchwrench.extras.numpy.functional.numpy_is_complex_dtype(dtype: dtype) bool[source]
torchwrench.extras.numpy.functional.numpy_is_floating_point(x: ndarray | generic) bool[source]
torchwrench.extras.numpy.functional.numpy_item(x: ndarray | generic | bool | int | float | complex | None | str | bytes) generic[source]
torchwrench.extras.numpy.functional.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.functional.numpy_topk(x: ndarray, k: int, dim: int = -1, largest: bool = True, sorted: bool = True) tuple[ndarray, ndarray][source]
torchwrench.extras.numpy.functional.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.functional.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.functional.tensor_to_ndarray(x: Tensor, *, dtype: str | dtype | None = None, force: bool = False) ndarray[source]

Convert PyTorch tensor to numpy array.

torchwrench.extras.numpy.functional.tensor_to_numpy(x: Tensor, *, dtype: str | dtype | None = None, force: bool = False) ndarray[source]

Convert PyTorch tensor to numpy array.

torchwrench.extras.numpy.functional.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.functional.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.