Spenso · latest
On this page

TensorStructure

symbolica.community.tensor Class

TensorStructure(slots: Sequence[Slot | Representation])

The 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

Constructor

#

Describe an opaque tensor by its canonical free axes.

Returns

TensorStructure

Canonical 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

Parameters

NameTypeDefaultDescription
slotsSequence[Slot | Representation]—

Free axes, sorted into canonical order. Repeated unresolved spaces remain distinct axes. This describes a signature without contracting it.

Member details

axes

Property · read-only#
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 Representation

Labeled 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)

rank

Property · read-only#
rank: int

Number of external tensor axes.

Returns

int

Zero 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

shape

Property · read-only#
shape: tuple[int | Expression, ...]

Dimensions in canonical signature order.

Returns

tuple of int or Expression

Concrete 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

is_scalar

Property · read-only#
is_scalar: bool

Whether the tensor has no external axes.

Returns

bool

True 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

__eq__

Method#
__eq__(other: object) -> bool

No description is available for this member.

Parameters

NameTypeDefaultDescription
otherobject——

slots

Method#
slots() -> list[Slot]

Return every external axis as an explicitly indexed slot.

Returns

list of Slot

Slots 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. Use axes to 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()

representations

Method#
representations() -> list[Representation]

Return every external axis as an unresolved representation.

Returns

list of Representation

Representations 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. Use axes to inspect a mixed structure.

Examples

from symbolica.community.tensor import Representation, TensorStructure
spaces = [Representation.mink(4), Representation.euc(3)]
TensorStructure(spaces) == TensorStructure(spaces[::-1])

__repr__

Method#
__repr__() -> str

Return 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)

to_html

Method#
to_html(*, settings: Optional[DisplaySettings] = None) -> str

Render a compact HTML view of this tensor metadata.

Returns

str

HTML 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()

Parameters

NameTypeDefaultDescription
settingsOptional[DisplaySettings]None

Index and tensor presentation choices; defaults to DisplaySettings().

_repr_html_

Method#
_repr_html_() -> str

No description is available for this member.