Einsums Utilities Module#

This module contains extra utilities written in Python for the Einsums library.

class einsums.utils.TensorIndices(other[, reverse : bool = False])#

This is an iterator that goes through all possible combinations of indices for a tensor.

Parameters:
  • other – The tensor to use to generate index combinations, or a TensorIndices object to copy.

  • reverse – If true, walk through the indices in reverse. Otherwise, walk forward.

__iter__()#

Return the iterator for this iterator (itself).

Returns:

The object itself.

__reversed__()#

Return the iterator that goes in reverse.

Returns:

The iterator that goes from the current index back to the beginning.

__next__()#

Get the next index and update the internal state.

Returns:

The next index.

Raises:

StopIteration – Raises this if there are no more indices.

einsums.utils.create_tensor(*args[, dtype = float]) einsums.core.RuntimeTensor#

Create a new tensor with the given data type. The arguments will be passed to the proper constructor.

Parameters:
  • args – Arguments to pass to the constructor.

  • dtype – The data type of the tensor.

Returns:

A tensor that holds the requested type.

einsums.utils.create_random_tensor(name: str, dims: list[int], dtype=float, random_func=random.random)#

Creates a tensor with the given name, dimensions, and data type, then fills that tensor with random data. An optional function for specifying the random numbers can be given as well. By default, this is the random.random() function, which gives a uniformly distributed random number on the range \([0, 1)\) for real values, and complex values \(a + b i\) where \(a\) and \(b\) are each uniformly distributed on the range \([0, 1)\).

If the random function returns real values and a complex tensor is requested, then the real and imaginary parts will each be distributed according to that random distribution. If the random function returns complex values and a real tensor is requested, then the values of the tensor will be taken from the real part of the random values.

Parameters:
  • name – The name of the tensor.

  • dims – The dimensions of the tensor. The rank will be determined from these dimensions.

  • dtype – The type of data to store.

  • random_func – The function that will give the random values.

Returns:

A tensor with the specified name, dimensions, and data type that has been filled with random data.