zetta_utils.tensor_ops¶
Handling tensor operations. Each opperation must support both np.ndarray and torch.Tensor input types.
zetta_utils.tensor_ops.convert¶
- zetta_utils.tensor_ops.convert.to_np(data)[source]¶
Convert the given tensor to
numpy.ndarray.- Parameters:
data (
Union[Tensor,TypeAliasType]) – Input tensor_ops.- Return type:
TypeAliasType- Returns:
Input tensor in
numpy.ndarrayformat.
- zetta_utils.tensor_ops.convert.to_torch(data, device=None)[source]¶
Convert the given tensor to
torch.Tensor.
- zetta_utils.tensor_ops.convert.astype(data, reference, cast=False)[source]¶
Convert the given tensor to
np.ndarrayortorch.Tensordepending on the type of reference tensor_ops.- Parameters:
data (
Union[Tensor,TypeAliasType]) – Input tensor_ops.reference (
TypeVar(TensorTypeVar,Tensor,TypeAliasType,Union[Tensor,TypeAliasType])) – Reference type tensor_ops.cast (
bool) – IfTrue, castdatato the type ofreference. RaisesValueErrorif that would round integers: magnitude above 2**24 for float32/complex64, above 2**53 for float64/complex128.
- Return type:
TypeVar(TensorTypeVar,Tensor,TypeAliasType,Union[Tensor,TypeAliasType])- Returns:
Input tensor converted to the reference type.