Tensor

class nuTens.tensor.Tensor

Bases: pybind11_object

Tensor 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

abs(self: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Get element-wise magnitudes of a complex tensor

add_batch_dim(self: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Add a batch dimension to the start of this tensor if it doesn’t have one already

angle(self: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Get element-wise phases of a complex tensor

backward(self: nuTens._pyNuTens.tensor.Tensor) None

Do the backward propagation from this tensor

conj(self: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Get complex conjugate of a complex tensor

device(self: nuTens._pyNuTens.tensor.Tensor, new_device: nuTens._pyNuTens.dtype.device_type) nuTens._pyNuTens.tensor.Tensor

Set the device that the tensor lives on

static diag(diagonal: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Create a tensor with specified values along the diagonal

dtype(self: nuTens._pyNuTens.tensor.Tensor, new_dtype: nuTens._pyNuTens.dtype.scalar_type) nuTens._pyNuTens.tensor.Tensor

Set the data type of the tensor

static eye(n: int, dtype: nuTens._pyNuTens.dtype.scalar_type = <scalar_type.float: 1>, device: nuTens._pyNuTens.dtype.device_type = <device_type.cpu: 0>, requires_grad: bool = True) nuTens._pyNuTens.tensor.Tensor

Create a tensor initialised with an identity matrix

static from_torch_tensor(arg0: torch.Tensor) nuTens._pyNuTens.tensor.Tensor

construct a nuTens Tensor from a pytorch tensor

get_shape(self: nuTens._pyNuTens.tensor.Tensor) list[int]

Get the shape of this tensor

get_value(self: nuTens._pyNuTens.tensor.Tensor, arg0: list[int]) int | float | float | complex | complex

Get the data stored at a particular index of the tensor

get_values(self: nuTens._pyNuTens.tensor.Tensor, arg0: list[int | str]) nuTens._pyNuTens.tensor.Tensor

Get the subset of values in this tensor at a specified location

grad(self: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Get the accumulated gradient stored in this tensor after calling backward()

has_batch_dim(*args, **kwargs)

Overloaded function.

  1. 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

  1. 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

imag(self: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Get imaginary part of a complex tensor

static ones(shape: list[int], dtype: nuTens._pyNuTens.dtype.scalar_type = <scalar_type.float: 1>, device: nuTens._pyNuTens.dtype.device_type = <device_type.cpu: 0>, requires_grad: bool = True) nuTens._pyNuTens.tensor.Tensor

Create a tensor initialised with ones

static rand(shape: list[int], dtype: nuTens._pyNuTens.dtype.scalar_type = <scalar_type.float: 1>, device: nuTens._pyNuTens.dtype.device_type = <device_type.cpu: 0>, requires_grad: bool = True) nuTens._pyNuTens.tensor.Tensor

Create a tensor initialised with random values

real(self: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Get real part of a complex tensor

requires_grad(self: nuTens._pyNuTens.tensor.Tensor, new_value: bool) nuTens._pyNuTens.tensor.Tensor

Set Whether or not this tensor requires gradient to be calculated

set_value(*args, **kwargs)

Overloaded function.

  1. set_value(self: nuTens._pyNuTens.tensor.Tensor, indices: nuTens._pyNuTens.tensor.Tensor, value: nuTens._pyNuTens.tensor.Tensor) -> None

Set a value at a specific index of this tensor

  1. set_value(self: nuTens._pyNuTens.tensor.Tensor, indices: list[Union[int, str]], value: nuTens._pyNuTens.tensor.Tensor) -> None

Set a value at a specific index of this tensor

  1. set_value(self: nuTens._pyNuTens.tensor.Tensor, indices: list[int], value: float) -> None

Set a value at a specific index of this tensor

  1. set_value(self: nuTens._pyNuTens.tensor.Tensor, indices: list[int], value: float) -> None

Set a value at a specific index of this tensor

  1. set_value(self: nuTens._pyNuTens.tensor.Tensor, indices: list[int], value: complex) -> None

Set a value at a specific index of this tensor

  1. set_value(self: nuTens._pyNuTens.tensor.Tensor, indices: list[int], value: complex) -> None

Set a value at a specific index of this tensor

to_string(self: nuTens._pyNuTens.tensor.Tensor) str

get a summary of this tensor as a string

torch_tensor(self: nuTens._pyNuTens.tensor.Tensor) torch.Tensor

Get the pytorch tensor that lives inside this tensor. Only available if using the pytorch backend…

static zeros(shape: list[int], dtype: nuTens._pyNuTens.dtype.scalar_type = <scalar_type.float: 1>, device: nuTens._pyNuTens.dtype.device_type = <device_type.cpu: 0>, requires_grad: bool = True) nuTens._pyNuTens.tensor.Tensor

Create a tensor initialised with zeros

nuTens.tensor.cos(t1: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Element-wise trigonometric cosine function

nuTens.tensor.cumsum(t1: nuTens._pyNuTens.tensor.Tensor, dimensions: int) nuTens._pyNuTens.tensor.Tensor

Get the cumulative sum over particular dimensions

nuTens.tensor.div(t1: nuTens._pyNuTens.tensor.Tensor, t2: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Element-wise division

nuTens.tensor.exp(t1: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Take element-wise exponential of a tensor

nuTens.tensor.matmul(t1: nuTens._pyNuTens.tensor.Tensor, t2: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Matrix multiplication

nuTens.tensor.mul(t1: nuTens._pyNuTens.tensor.Tensor, t2: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Element-wise multiplication

nuTens.tensor.outer(t1: nuTens._pyNuTens.tensor.Tensor, t2: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Tensor outer product

nuTens.tensor.pow(*args, **kwargs)

Overloaded function.

  1. pow(t1: nuTens._pyNuTens.tensor.Tensor, power: float) -> nuTens._pyNuTens.tensor.Tensor

Raise to scalar power

  1. pow(t1: nuTens._pyNuTens.tensor.Tensor, power: complex) -> nuTens._pyNuTens.tensor.Tensor

Raise to scalar power

nuTens.tensor.scale(*args, **kwargs)

Overloaded function.

  1. scale(t1: nuTens._pyNuTens.tensor.Tensor, scalar: float) -> nuTens._pyNuTens.tensor.Tensor

Scalar multiplication

  1. scale(t1: nuTens._pyNuTens.tensor.Tensor, scalar: complex) -> nuTens._pyNuTens.tensor.Tensor

Scalar multiplication

nuTens.tensor.sin(t1: nuTens._pyNuTens.tensor.Tensor) nuTens._pyNuTens.tensor.Tensor

Element-wise trigonometric sine function

nuTens.tensor.sum(*args, **kwargs)

Overloaded function.

  1. sum(t1: nuTens._pyNuTens.tensor.Tensor) -> nuTens._pyNuTens.tensor.Tensor

Get the sum of all values in a tensor

  1. sum(t1: nuTens._pyNuTens.tensor.Tensor, dimensions: list[int]) -> nuTens._pyNuTens.tensor.Tensor

Get the sum over particular dimensions

nuTens.tensor.transpose(t1: nuTens._pyNuTens.tensor.Tensor, index_1: int, index_2: int) nuTens._pyNuTens.tensor.Tensor

Get the matrix transpose