Tensorο
- class nuTens.tensor.Tensorο
Bases:
pybind11_objectTensor defines a basic interface for creating and manipulating tensors.To create tensors you should use the static constructor methods. Alternatively you can chain together multiple property setters.
For example
from nuTens.tensor import Tensor, dtype tensor = Tensor.ones([3,3], dtype.scalar_type.float, dtype.device_type.cpu)
will get you a 3x3 tensor of floats that lives on the CPU.
This is equivalent to
- add_batch_dim(self: Tensor) Tensorο
Add a batch dimension to the start of this tensor if it doesnβt have one already
- device(self: Tensor, new_device: device_type) Tensorο
Set the device that the tensor lives on
- dtype(self: Tensor, new_dtype: scalar_type) Tensorο
Set the data type of the tensor
- static eye(n: SupportsInt | SupportsIndex, dtype: scalar_type = <scalar_type.float: 0>, device: device_type = <device_type.cpu: 0>, requires_grad: bool = True) Tensorο
Create a tensor initialised with an identity matrix
- static from_torch_tensor(arg0: torch.Tensor) Tensorο
construct a nuTens Tensor from a pytorch tensor
- get_device(self: Tensor) device_typeο
Get the device that this tensor lives on
- get_dtype(self: Tensor) scalar_typeο
Get the type of the data contained within this tensor
- get_value(self: Tensor, indices: collections.abc.Sequence[SupportsInt | SupportsIndex]) int | float | float | complex | complexο
Get the data stored at a particular index of the tensor
- get_values(self: Tensor, indices: collections.abc.Sequence[SupportsInt | SupportsIndex | str]) Tensorο
Get the subset of values in this tensor at a specified location
- grad(self: Tensor) Tensorο
Get the accumulated gradient stored in this tensor after calling backward()
- has_batch_dim(*args, **kwargs)ο
Overloaded function.
has_batch_dim(self: nuTens._pyNuTens.tensor.Tensor) -> bool
Check Whether or not the first dimension should be interpreted as a batch dim for this tensor
has_batch_dim(self: nuTens._pyNuTens.tensor.Tensor, new_value: bool) -> nuTens._pyNuTens.tensor.Tensor
Set Whether or not the first dimension should be interpreted as a batch dim for this tensor
- static ones(shape: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex], dtype: nuTens._pyNuTens.dtype.scalar_type = <scalar_type.float: 0>, device: nuTens._pyNuTens.dtype.device_type = <device_type.cpu: 0>, requires_grad: bool = True) Tensorο
Create a tensor initialised with ones
- static rand(shape: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex], dtype: nuTens._pyNuTens.dtype.scalar_type = <scalar_type.float: 0>, device: nuTens._pyNuTens.dtype.device_type = <device_type.cpu: 0>, requires_grad: bool = True) Tensorο
Create a tensor initialised with random values
- requires_grad(self: Tensor, new_value: bool) Tensorο
Set Whether or not this tensor requires gradient to be calculated
- set_value(*args, **kwargs)ο
Overloaded function.
set_value(self: nuTens._pyNuTens.tensor.Tensor, indices: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex | str], value: nuTens._pyNuTens.tensor.Tensor) -> None
Set a value at a specific index of this tensor
set_value(self: nuTens._pyNuTens.tensor.Tensor, indices: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex], value: typing.SupportsFloat | typing.SupportsIndex) -> None
Set a value at a specific index of this tensor
set_value(self: nuTens._pyNuTens.tensor.Tensor, indices: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex], value: typing.SupportsFloat | typing.SupportsIndex) -> None
Set a value at a specific index of this tensor
set_value(self: nuTens._pyNuTens.tensor.Tensor, indices: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex], value: typing.SupportsComplex | typing.SupportsFloat | typing.SupportsIndex) -> None
Set a value at a specific index of this tensor
set_value(self: nuTens._pyNuTens.tensor.Tensor, indices: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex], value: typing.SupportsComplex | typing.SupportsFloat | typing.SupportsIndex) -> None
Set a value at a specific index of this tensor
- torch_tensor(self: Tensor) torch.Tensorο
Get the pytorch tensor that lives inside this tensor. Only available if using the pytorch backendβ¦
- unsqueeze(self: Tensor, dim: SupportsInt | SupportsIndex) Tensorο
add an extra dimension to this tensor at the specified location
- static zeros(shape: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex], dtype: nuTens._pyNuTens.dtype.scalar_type = <scalar_type.float: 0>, device: nuTens._pyNuTens.dtype.device_type = <device_type.cpu: 0>, requires_grad: bool = True) Tensorο
Create a tensor initialised with zeros
- nuTens.tensor.cumsum(tensor_1: Tensor, dimensions: SupportsInt | SupportsIndex) Tensorο
Get the cumulative sum over particular dimensions
- nuTens.tensor.gpu_available() boolο
Returns true if there is an available GPU, False if not
- nuTens.tensor.pow(*args, **kwargs)ο
Overloaded function.
pow(tensor_1: nuTens._pyNuTens.tensor.Tensor, power: typing.SupportsFloat | typing.SupportsIndex) -> nuTens._pyNuTens.tensor.Tensor
Raise to scalar power
pow(tensor_1: nuTens._pyNuTens.tensor.Tensor, power: typing.SupportsComplex | typing.SupportsFloat | typing.SupportsIndex) -> nuTens._pyNuTens.tensor.Tensor
Raise to scalar power
- nuTens.tensor.scale(*args, **kwargs)ο
Overloaded function.
scale(tensor_1: nuTens._pyNuTens.tensor.Tensor, scalar: typing.SupportsFloat | typing.SupportsIndex) -> nuTens._pyNuTens.tensor.Tensor
Scalar multiplication
scale(tensor_1: nuTens._pyNuTens.tensor.Tensor, scalar: typing.SupportsComplex | typing.SupportsFloat | typing.SupportsIndex) -> nuTens._pyNuTens.tensor.Tensor
Scalar multiplication
- nuTens.tensor.sum(*args, **kwargs)ο
Overloaded function.
sum(tensor_1: nuTens._pyNuTens.tensor.Tensor) -> nuTens._pyNuTens.tensor.Tensor
Get the sum of all values in a tensor
sum(tensor_1: nuTens._pyNuTens.tensor.Tensor, dimensions: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> nuTens._pyNuTens.tensor.Tensor
Get the sum over particular dimensions