tensor#

The category of matrices with the Kronecker product as monoidal product.

Summary#

Dim

A dimension is a tuple of integers greater than one seen as a type.

Tensor

A tensor is a Matrix with dimensions as domain and codomain and the Kronecker product as tensor.

Functor

A tensor functor is a frobenius functor with a domain category dom and Tensor[dtype] as codomain for a given dtype.

Diagram

A tensor diagram is a frobenius diagram with tensor boxes.

CMap

alias of CMap[Diagram]

Box

A tensor box is a frobenius box with an array as data.

Swap

A tensor swap is a frobenius swap in a tensor diagram.

Cup

A tensor cup is a frobenius cup in a tensor diagram.

Cap

A tensor cap is a frobenius cap in a tensor diagram.

Spider

A tensor spider is a frobenius spider in a tensor diagram.

Sum

A formal sum of tensor diagrams with the same domain and codomain.

Bubble

Bubble in a tensor diagram, applies a function elementwise.

Tensor combinatorial maps#

A CMap is a tensor network stored as a combinatorial map, whose boxes are tensors, edges are summed indices and boundary ports are free indices. Swaps, cups and caps become wiring while spiders stay as boxes.

>>> vector = Box('vector', Dim(1), Dim(2), [0, 1])
>>> assert (vector >> vector[::-1]).to_map().eval().array == 1
>>> with backend('jax'):  
...     import jax, jax.numpy as jnp
...     b = lambda x: Box[float]('v', Dim(1), Dim(2), x * jnp.ones(2))
...     f = lambda x: (b(x) >> b(x)[::-1]).to_map().eval().array
...     assert jax.grad(f)(1.) == 4.