Abstract base class that defines the interface for tensor operations across different frameworks. All backend implementations must inherit from this class and implement the required methods.
new()
Initialize the backend and check for required packages. It is assumed that the constructor will fully load and setup all dependencies and error otherwise.
EinopsBackend$new()
A new EinopsBackend instance.
...
arguments passed to pprint()
This object, invisibly
repr()
Get a string representation of this backend.
EinopsBackend$repr()
A character string describing the backend.
tensor_type()
Get the type of tensor this backend supports. This method should be overridden in subclasses to return the specific tensor type (e.g., "torch_tensor", "array").
EinopsBackend$tensor_type()
A string representing the tensor type.
preprocess()
Do any relevant preprocessing of a tensor before any operations are done on it. This should always be called before running any backend operations on a tensor
EinopsBackend$preprocess(x)
x
The input raw tensor-like object
A preprocessed version of the input, may or may not have changed classes
create_tensor()
Create a tensor of the specified type with given values and dimensions.
EinopsBackend$create_tensor(values, dims, ...)
values
A vector of values to initialize the tensor.
dims
A numeric vector specifying the dimensions of the tensor.
...
Additional arguments for specific backend implementations.
A tensor of the specified type.
x
The input tensor/array.
A standard array representation of the tensor.
flatten()
Return a flattened version of the tensor. Note that the order of calling as_array and flatten does matter because different frameworks may store data differently.
EinopsBackend$flatten(x)
x
The input tensor/array
A 1 dimensional tensor
arange()
EinopsBackend$arange(start, stop)
start
integer, inclusive
stop
integer, inclusive
a sequence from start to stop
shape()
Get the shape of a tensor. Shape should return a tuple with integers or "shape symbols" (which will evaluate to actual size).
EinopsBackend$shape(x)
x
The input tensor/array.
A numeric vector representing the tensor shape.
reshape()
Reshape a tensor to the specified dimensions.
EinopsBackend$reshape(x, shape)
x
The input tensor/array.
shape
A numeric vector specifying the new shape.
The reshaped tensor/array.
transpose()
Transpose a tensor along the specified axes.
EinopsBackend$transpose(x, axes)
x
The input tensor/array.
axes
A numeric vector specifying the new axis order.
The transposed tensor/array.
reduce()
Reduce a tensor along specified axes using the given operation.
EinopsBackend$reduce(x, operation, axes)
x
The input tensor/array.
operation
A character string specifying the reduction operation (e.g., "sum", "mean", "max", "min", "prod", "all", "any"), OR a two argument function, with the first argument being the tensor to modify, and the second argument being an integer list of axes to perform the reduction over.
axes
A numeric vector specifying which axes to reduce over.
The reduced tensor/array.
stack_on_zeroth_dimension()
Stack multiple tensors along a new zeroth dimension.
EinopsBackend$stack_on_zeroth_dimension(tensors)
tensors
A list of tensors/arrays to stack.
A tensor/array with the input tensors stacked along dimension 1.
add_axis()
Add a new axis to a tensor at the specified position.
EinopsBackend$add_axis(x, new_position)
x
The input tensor/array.
new_position
The position (1-based) where to insert the new axis.
The tensor/array with a new axis added.
add_axes()
Add multiple axes to a tensor and tile along specified axes.
This function adds new axes to the input tensor at the specified positions and tiles the tensor along those axes according to the provided lengths.
EinopsBackend$add_axes(x, n_axes, pos2len)
x
The input tensor/array.
n_axes
The total number of axes after addition.
pos2len
int->int r2r::hashmap()
mapping positions to lengths.
The tensor/array with new axes added and tiled as specified.
tile()
Tile (repeat) a tensor along each axis according to the repeat counts. The repeats vector should have the same length as the tensor's shape.
EinopsBackend$tile(x, repeats)
x
The input tensor/array.
repeats
A numeric vector specifying how many times to repeat along each axis. Must have same length as x.shape.
The tiled tensor/array.
concat()
Concatenate tensors along the specified axis. Assumes identical devices, dtypes and shapes except for the selected axis.
EinopsBackend$concat(tensors, axis)
tensors
A list of tensors/arrays to concatenate.
axis
The axis along which to concatenate (1-based).
The concatenated tensor/array.
is_float_type()
Check if the tensor has a floating point data type.
EinopsBackend$is_float_type(x)
x
The input tensor/array.
A logical value indicating if the tensor is of float type.
layers()
Get neural network layers specific to this backend.
EinopsBackend$layers()
Backend-specific layer implementations.
einsum()
Perform Einstein summation on tensors.
EinopsBackend$einsum(pattern, ...)
pattern
A character string specifying the einsum pattern.
...
Additional tensors to operate on.
The result of the einsum operation.