TensorStructure
TensorStructure
class TensorStructureThe canonical external signature of an opaque tensor.
A Slot denotes a labeled axis; a Representation denotes an unresolved axis. This immutable signature contains only free axes: no tensor name, scalar arguments, expression, component data, or layout permutation. Axes follow Spenso’s canonical representation/index ordering. A(i,j), A(j,i), and their sum have the same structure. The expression retains argument order; tensor and network component views retain their own axis order.
Examples
from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(3)
A = TensorName("A")(space, space)
metadata = A.structure
metadata.rank
2Attributes
| Name | Description |
|---|---|
axes |
Free axes in canonical representation/index order |
is_scalar |
Whether the tensor has no external axes. |
rank |
Number of external tensor axes. |
shape |
Dimensions in canonical signature order. |
axes
TensorStructure.axes: tuple[Slot | Representation, ...]Free axes in canonical representation/index order.
The signature is independent of argument order, factor order, and summand order. It describes the whole expression as an opaque tensor. Component coordinates belong to the tensor’s current view, not to this signature.
Returns
tuple of Slot or RepresentationLabeled and unresolved axes, respectively.
Examples
from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(3)
A = TensorName("A")(space, space)
A.structure.axes == (space, space)
Trueis_scalar
TensorStructure.is_scalar: builtins.boolWhether the tensor has no external axes.
Returns
boolTrue exactly when rank is zero.
Examples
from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(3)
A = TensorName("A")(space, space)
A = A.structure
A.is_scalar
Falserank
TensorStructure.rank: builtins.intNumber of external tensor axes.
Returns
intZero for a scalar.
Examples
from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(3)
A = TensorName("A")(space, space)
A = A.structure
A.rank
2shape
TensorStructure.shape: tuple[int | Expression, ...]Dimensions in canonical signature order.
Returns
tuple of int or ExpressionConcrete dimensions are integers; symbolic dimensions remain expressions.
Examples
from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(3)
A = TensorName("A")(space, space)
A = A.structure
A.shape
(3, 3)Methods
| Name | Description |
|---|---|
__eq__ |
|
__new__ |
Describe an opaque tensor by its canonical free axes. |
__repr__ |
Return a readable object description for inspection. |
_repr_html_ |
|
representations |
Return every external axis as an unresolved representation. |
slots |
Return every external axis as an explicitly indexed slot. |
to_html |
Render a compact HTML view of this tensor metadata. |
__eq__
TensorStructure.__eq__(other: builtins.object) -> builtins.bool__new__
TensorStructure.__new__(slots: typing.Sequence[Slot | Representation]) -> TensorStructureDescribe an opaque tensor by its canonical free axes.
Parameters
slots(sequence of Slot or Representation) Free axes, sorted into canonical order. Repeated unresolved spaces remain distinct axes. This describes a signature without contracting it.
Returns
TensorStructureCanonical signature, independent of the supplied sequence order.
Examples
from symbolica.community.tensor import Representation, TensorStructure
metadata = TensorStructure([Representation.euc(2), Representation.euc(3)])
metadata.shape
(2, 3)__repr__
TensorStructure.__repr__() -> builtins.strReturn a readable object description for inspection.
Examples
from symbolica.community import tensor as sp
r = sp.Representation.euc(2)
structure = sp.TensorStructure([r("i"), r("j")])
text = repr(structure)_repr_html_
TensorStructure._repr_html_() -> builtins.strrepresentations
TensorStructure.representations() -> builtins.list[Representation]Return every external axis as an unresolved representation.
Returns
list of RepresentationRepresentations in canonical order; an empty list for a scalar. Different spaces, dimensions, and dualities are allowed.
Raises
ValueError: If any axis has an explicit index. Labels are never discarded. Useaxesto inspect a mixed structure.
Examples
from symbolica.community.tensor import Representation, TensorStructure
spaces = [Representation.mink(4), Representation.euc(3)]
TensorStructure(spaces) == TensorStructure(spaces[::-1])
Trueslots
TensorStructure.slots() -> builtins.list[Slot]Return every external axis as an explicitly indexed slot.
Returns
list of SlotSlots in canonical order; an empty list for a scalar. Representations and dimensions may differ between axes.
Raises
ValueError: If any axis is unresolved. No indices are invented or axes omitted. Useaxesto inspect a mixed structure.
Examples
from symbolica.community.tensor import Representation, TensorStructure
space = Representation.euc(3)
metadata = TensorStructure([space("j"), space("i")])
metadata.slots() == TensorStructure([space("i"), space("j")]).slots()
Trueto_html
TensorStructure.to_html(*, settings: typing.Optional[DisplaySettings] = None) -> builtins.strRender a compact HTML view of this tensor metadata.
Parameters
settings(DisplaySettings, optional) Index and tensor presentation choices; defaults to DisplaySettings().
Returns
strHTML fragment for display in a notebook or page.
Examples
from symbolica.community.tensor import Representation, TensorName, TensorExpression
space = Representation.euc(2)
A = TensorName("M")(space, space)
value = A.structure
html = value.to_html()