Skip to content

signature_multiply

from tensorsig.tensor_ops.series import signature_multiply

Multiply two truncated tensor series using Chen's identity.

Parameters:

Name Type Description Default
left list[Tensor]

Batched homogeneous levels with equal truncation depth.

required
right list[Tensor]

Batched homogeneous levels with equal truncation depth.

required

Returns:

Type Description
list[Tensor]

Product levels with the same shapes as the operands.

Source code in src/tensorsig/tensor_ops/series.py
def signature_multiply(left: list[Tensor], right: list[Tensor]) -> list[Tensor]:
    """Multiply two truncated tensor series using Chen's identity.

    Parameters
    ----------
    left, right : list[Tensor]
        Batched homogeneous levels with equal truncation depth.

    Returns
    -------
    list[Tensor]
        Product levels with the same shapes as the operands.
    """
    if not isinstance(left, list) or not isinstance(right, list):
        raise TypeError("left and right must be lists of tensors.")
    if len(left) != len(right):
        raise ValueError("Signatures must have the same depth for multiplication.")
    shared_dims, left_shared, left_width = _series_layout(left, "left")
    right_shared_dims, right_shared, right_width = _series_layout(right, "right")
    if (
        right_shared_dims != shared_dims
        or right_shared != left_shared
        or right_width != left_width
    ):
        raise ValueError("Signatures must have the same leading shape and width.")
    if left[0].dtype != right[0].dtype:
        raise ValueError("Signatures must have the same dtype.")
    if left[0].device != right[0].device:
        raise ValueError("Signatures must be on the same device.")

    product: list[Tensor] = []
    for depth_index in range(len(left)):
        current = left[depth_index] + right[depth_index]
        for index in range(depth_index):
            current = current + tensor_product(
                left[index],
                right[depth_index - index - 1],
                shared_dims=shared_dims,
            )
        product.append(current)
    return product