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
| Name | Type | Default | Description |
|---|---|---|---|
reps_and_additional_args | TensorIndices | list[Slot] | — | — |
name | TensorName | str | Expression | None | None | Optional tensor name to assign to the structure |
Member details
set_name
Methodset_name(name: TensorName | str | Expression) -> NoneNo description is available for this member.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | TensorName | str | Expression | — | — |
get_name
Method__repr__
Method__str__
Method__len__
Method__getitem__
MethodOverloads
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
| Name | Type | Default | Description |
|---|---|---|---|
item | slice | — | Slice object defining the range of indices |
Overload 2 #
__getitem__(item: Sequence[int]) -> Expression | complex | floatGet flattened index associated to this expanded index.
Returns
int
The flat index
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
item | Sequence[int] | — | Multi-dimensional index coordinates |
Overload 3 #
__getitem__(item: int) -> Expression | complex | floatGet expanded index associated to this flat index.
Returns
list of int
Multi-dimensional index coordinates
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
item | int | — | Flat index into the tensor |
__call__
Method__call__(*args: int | Expression | str, extra_args: Sequence[Expression | int | str | float | complex] | None = None) -> ExpressionConvenience 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
| Name | Type | Default | Description |
|---|---|---|---|
args | int | Expression | str | — | — |
extra_args | Sequence[Expression | int | str | float | complex] | None | None | Optional list of additional non-tensorial arguments |
symbolic
Methodsymbolic(*args: int | Expression | str, extra_args: Sequence[Expression | int | str | float | complex] | None = None) -> ExpressionCreate 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
| Name | Type | Default | Description |
|---|---|---|---|
args | int | Expression | str | — | — |
extra_args | Sequence[Expression | int | str | float | complex] | None | None | Optional list of additional non-tensorial arguments |
index
Methodindex(*args: int | Expression | str, extra_args: Sequence[Expression] | None = None, cook_indices: bool = False) -> TensorIndicesCreate 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
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
| Name | Type | Default | Description |
|---|---|---|---|
args | int | Expression | str | — | — |
extra_args | Sequence[Expression] | None | None | Optional list of additional non-tensorial arguments |
cook_indices | bool | False | If True, attempt to convert expressions to valid indices |
View generated signature source: docs/api/python/spynso3.pyi:1757