Batched truncated tensor exponential with a shared batch axis.
Computes the truncated tensor exponential exp(input) - 1 for batched inputs,
returning homogeneous components at each depth level. Each batch element
receives the homogeneous components, enabling efficient signature scans
over a batch of paths.
Parameters:
| Name |
Type |
Description |
Default |
input
|
Tensor
|
Tensor of shape (batch, width) representing degree-1 elements.
|
required
|
depth
|
int
|
|
required
|
Returns:
| Type |
Description |
list[Tensor]
|
List of length depth where entry k has shape
(batch, width, ..., width) with k+1 trailing width dimensions
(equivalently width**(k+1) elements when flattened).
|
Examples:
>>> import torch
>>> from tensorsig.tensor_ops.series import batch_restricted_exp
>>>
>>> input_tensor = torch.tensor([[1.0, 2.0], [3.0, 4.0]]) # (batch=2, width=2)
>>> result = batch_restricted_exp(input_tensor, depth=2)
>>> len(result)
2
>>> result[0].shape # depth 1
torch.Size([2, 2])
>>> result[1].shape # depth 2
torch.Size([2, 2, 2])
Source code in src/tensorsig/tensor_ops/series.py
| def batch_restricted_exp(input: Tensor, depth: int) -> list[Tensor]:
"""Batched truncated tensor exponential with a shared batch axis.
Computes the truncated tensor exponential exp(input) - 1 for batched inputs,
returning homogeneous components at each depth level. Each batch element
receives the homogeneous components, enabling efficient signature scans
over a batch of paths.
Parameters
----------
input : Tensor
Tensor of shape ``(batch, width)`` representing degree-1 elements.
depth : int
Truncation depth (>=1).
Returns
-------
list[Tensor]
List of length ``depth`` where entry ``k`` has shape
``(batch, width, ..., width)`` with ``k+1`` trailing width dimensions
(equivalently ``width**(k+1)`` elements when flattened).
Examples
--------
>>> import torch
>>> from tensorsig.tensor_ops.series import batch_restricted_exp
>>>
>>> input_tensor = torch.tensor([[1.0, 2.0], [3.0, 4.0]]) # (batch=2, width=2)
>>> result = batch_restricted_exp(input_tensor, depth=2)
>>> len(result)
2
>>> result[0].shape # depth 1
torch.Size([2, 2])
>>> result[1].shape # depth 2
torch.Size([2, 2, 2])
"""
depth = _positive_integer(depth, "depth")
if input.ndim != 2:
raise ValueError(
f"input must have shape (batch, width); got {tuple(input.shape)}."
)
if input.shape[1] < 1:
raise ValueError("input must have positive tensor-algebra width.")
if not input.is_floating_point() and not input.is_complex():
raise ValueError("input must have a floating-point or complex dtype.")
ret = [input]
for i in range(2, depth + 1):
ret.append(tensor_product(ret[-1], input / i, shared_dims=1))
return ret
|