On this page

TensorStructure

symbolica.community.spenso Class

TensorStructure(*reps_and_additional_args: TensorIndices | list[Slot], name: TensorName | str | Expression | None = None)

A tensor structure without abstract indices, defined purely by representations.

TensorStructure represents the shape and representation structure of tensors without specific index assignments. It's used for defining tensor templates in libraries and for creating indexless tensor computations.

Examples

from symbolica.community.spenso import TensorStructure, Representation, TensorName

# Create from representations
rep = Representation.euc(3)
structure = TensorStructure(rep, rep)  # 3x3 matrix structure

# With name for library registration
T = TensorName("T")
named_structure = TensorStructure(rep, rep, name=T)

# Use to create indexed tensor
indices = structure.index('mu', 'nu')  # Assign specific indices

# Create symbolic expression
expr = structure.symbolic('a', 'b')  # T(a, b)

Constructor

#

Construct a new TensorStructure with the given representations.

Returns

TensorStructure

A new TensorStructure object

Examples

from symbolica import S
from symbolica.community.spenso import TensorStructure, Representation, TensorName
rep = Representation.euc(3)
structure = TensorStructure(rep, rep)
x = S('x')
structure_with_args = TensorStructure(rep, rep, x)
T = TensorName("T")
named_structure = TensorStructure(rep, rep, name=T)

Parameters

NameTypeDefaultDescription
reps_and_additional_argsTensorIndices | list[Slot]
nameTensorName | str | Expression | NoneNone

Optional tensor name to assign to the structure

Member details

set_name

Method
#
set_name(name: TensorName | str | Expression) -> None

No description is available for this member.

Parameters

NameTypeDefaultDescription
nameTensorName | str | Expression

get_name

Method
#
get_name() -> Optional[TensorName]

No description is available for this member.

__repr__

Method
#
__repr__() -> str

No description is available for this member.

__str__

Method
#
__str__() -> str

No description is available for this member.

__len__

Method
#
__len__() -> int

No description is available for this member.

__getitem__

Method
#

Overloads

Overload 1 #
__getitem__(item: slice) -> list[Expression | complex | float]

Get expanded indices at the specified range of flattened indices.

Returns

list of list of int

List of expanded indices

Parameters
NameTypeDefaultDescription
itemslice

Slice object defining the range of indices

Overload 2 #
__getitem__(item: Sequence[int]) -> Expression | complex | float

Get flattened index associated to this expanded index.

Returns

int

The flat index

Parameters
NameTypeDefaultDescription
itemSequence[int]

Multi-dimensional index coordinates

Overload 3 #
__getitem__(item: int) -> Expression | complex | float

Get expanded index associated to this flat index.

Returns

list of int

Multi-dimensional index coordinates

Parameters
NameTypeDefaultDescription
itemint

Flat index into the tensor

__call__

Method
#
__call__(*args: int | Expression | str, extra_args: Sequence[Expression | int | str | float | complex] | None = None) -> Expression

Convenience method for creating symbolic expressions.

This is a shorthand for calling symbolic(*args, extra_args=extra_args). Creates a symbolic Expression representing this tensor structure.

Returns

Expression

A symbolic Expression representing the tensor

Examples

structure = TensorStructure(rep, rep, name="T")
expr = structure('mu', 'nu')

Parameters

NameTypeDefaultDescription
argsint | Expression | str
extra_argsSequence[Expression | int | str | float | complex] | NoneNone

Optional list of additional non-tensorial arguments

symbolic

Method
#
symbolic(*args: int | Expression | str, extra_args: Sequence[Expression | int | str | float | complex] | None = None) -> Expression

Create a symbolic expression representing this tensor structure.

Builds a symbolic tensor expression with the specified indices. Arguments can be separated using a semicolon (';') to distinguish between additional arguments and tensor indices.

Returns

Expression

A symbolic Expression representing the tensor with indices

Examples

import symbolica as sp
from symbolica.community.spenso import TensorStructure, Representation, TensorName
rep = Representation.euc(3)
T = TensorName("T")
structure = TensorStructure([rep, rep], name=T)
expr = structure.symbolic('mu', 'nu')
x = sp.S('x')
expr = structure.symbolic(x, ';', 'mu', 'nu')
expr = structure.symbolic('mu', 'nu', extra_args=[x])

Parameters

NameTypeDefaultDescription
argsint | Expression | str
extra_argsSequence[Expression | int | str | float | complex] | NoneNone

Optional list of additional non-tensorial arguments

index

Method
#
index(*args: int | Expression | str, extra_args: Sequence[Expression] | None = None, cook_indices: bool = False) -> TensorIndices

Create an indexed tensor (TensorIndices) from this structure.

Converts this structure template into a concrete indexed tensor by assigning specific abstract indices to each representation slot.

Returns

TensorIndices

A TensorIndices object with concrete index assignments

Examples

import symbolica as sp
from symbolica.community.spenso import TensorStructure, Representation, TensorName
rep = Representation.cof(3)
T = TensorName("T")
structure = TensorStructure([rep, rep], name=T)
indices = structure.index('mu', 'nu')
x = sp.S('x')
indices = structure.index(x, ';', 'mu', 'nu')

Parameters

NameTypeDefaultDescription
argsint | Expression | str
extra_argsSequence[Expression] | NoneNone

Optional list of additional non-tensorial arguments

cook_indicesboolFalse

If True, attempt to convert expressions to valid indices