Einsums Python Runtime Tensor Views#

These tensor views are how the Python and C++ sides of Einsums are able to interact. There are four tensor views, RuntimeTensorViewF, RuntimeTensorViewD, RuntimeTensorViewC, and RuntimeTensorViewZ, corresponding to single-precision real values, double-precision real values, single-precision complex values, and double-precision complex values respecively. In order to increase brevity, these will all be referred to as RuntimeTensorViewX, where X should be replaced by the respective letter. There is also the base class, RuntimeTensorView, though this does not have much code to itself. These views share data with the respective RuntimeTensorX such that a change in one is reflected in the other.

class einsums.core.RuntimeTensorView#

Very basic class. Should not be instantiated. It is the superclass for all RuntimeTensorViewX types.

class einsums.core.RuntimeTensorViewX#

These are the tensor view classes that allow the Einsums Python code to interface with the C++ library. It has a runtime-computed rank, since compile-time computed ranks are not available in Python. This wraps the einsums::RuntimeTensorView class with a trampoline class provided by einsums::python::PyTensorView. The data contained in these views is shared with a tensor so that changes in either are reflected in both.

__init__()#

Construct a new empty tensor view.

__init__(tensor[, dims])

Create a view of a tensor. The tensor can be a einsums.core.RuntimeTensorX of the same underyling type, a einsums.core.RuntimeTensorViewX of the same underlying type, or a buffer object of the same underlying type. The dims argument indicates the dimensions of the view.

Parameters:
  • tensor – The tensor to view.

  • dims – The dimensions of the view.

zero() None#

Zero out the data in the tensor. Wraps einsums::RuntimeTensorView::zero().

set_all(value) None#

Set all values in the tensor to the value passed to the function. Wraps einsums::RuntimeTensorView::set_all()

Parameters:

value – The value to fill the tensor with.

__getitem__(index)#

Get the value at an index using Python’s bracket syntax.

Parameters:

index – The index to pass. Can be a single value, a tuple, a slice, or pretty much anything that normally works.

Returns:

Return value depends on the index passed. It may be a single value or it may be a einsums.core.RuntimeTensorView object.

__setitem__(key, value)#

Similar to __getitem__(), it can take pretty much anything that will normally work for the key. For the value, a single value is always accepted. If the key creates a view, this will fill the view with the single value. If the key is a single value, it will only set that value. Otherwise, if the value is a buffer object, including a tensor or tensor view, the key must refer to a view with the same dimensions as that buffer object. It will then copy that object into the view.

Parameters:
  • key – Which item or items to set.

  • value – The value or buffer of values to set that key to.

__imul__(other)#
__itruediv__(other)#
__iadd__(other)#
__isub__(other)#

In-place arithmetic operations. These can accept either a single value or a buffer object. If other is a single value, it will operate every single element with that value. If it is a buffer, then it must have the same dimensions as this tensor, and it will then perform the element-wise operation between the elements of the tensor and the buffer.

Parameters:

other – The object to operate with.

assign(buffer)#

Copy the buffer into this tensor. The tensor will resize and reshape to fit the buffer.

Parameters:

buffer – The buffer object to assign from.

dim(axis: int) int#

Get the dimension along the given axis.

Parameters:

axis – The axis whose dimension should be found.

dims() list[int]#

Get the dimensions of the tensor.

stride(axis: int) int#

Get the stride in elements along the given axis.

Parameters:

axis – The axis whos stride should be found.

strides() list[int]#

Get the strides of the tensor, in elements.

get_name() str#

Get the name of the tensor.

set_name(name: str)#

Set the name of the tensor.

Parameters:

name – The new name of the tensor.

property name#

Python property wrapping get_name() and set_name().

size() int#
__len__() int#

Get the number of elements in the tensor. size and __len__ are synonyms of each other.

Returns:

The number of elements in the tensor.

__iter__() einsums.core.PyTensorIteratorX#

Get an iterator that iterates over the elements in the tensor.

Returns:

An iterator that will iterate over the elements.

__reversed__() einsums.core.PyTensorIteratorX#

Get an iterator that iterates over the elements in the tensor in reverse.

Returns:

An iterator that will iterate over the elements in reverse.

rank() int#

Get the rank of the tensor, or the number of dimensions.

Returns:

The rank of the tensor.

__copy__()#
__deepcopy__()#
copy()#
deepcopy()#

Create a copy of the tensor. These are all synonyms of each other.

Returns:

A copy of the tensor.

__str__() str#

Return a string representation of the tensor.