torch.Ellipsis
export type Ellipsis = typeof Ellipsis;Sentinel symbol representing ellipsis (...) in einsum sublist notation.
Use this symbol as a placeholder for any number of dimensions when using the sublist notation for einsum operations.
What is Ellipsis?
- Represents "..." (ellipsis) in einsum notation
- Matches any number of dimensions
- Useful for batch dimensions or unknown number of intermediate dimensions
- Used only in sublist notation:
einsum(a, [0, Ellipsis, 2], ...)
String vs Sublist Notation:
- String notation:
einsum('...ij,jk->...ik')- use the string '...' - Sublist notation:
einsum(a, [Ellipsis, 0, 1], b, [1, 2], [Ellipsis, 0, 2])
Use Cases:
- Batch matrix multiplication:
einsum('...ij,jk->...ik', batched_matrix, matrix) - Preserve batch dimensions:
einsum(x, [Ellipsis, 0, 1], [Ellipsis, 1, 0]) - Unknown number of leading dimensions
Constraints:
- Can only appear once in a subscript list
- Must be used in sublist notation (not string notation which uses '...')
- Subscript indices must be 0-51 (A-Z = 0-25, a-z = 26-51)
Examples
// Batch matrix multiplication using Ellipsis
const X = torch.randn([5, 3, 4]); // [batch, m, n]
const W = torch.randn([4, 2]); // [n, p]
const result = torch.einsum(
X, [torch.Ellipsis, 0, 1],
W, [1, 2],
[torch.Ellipsis, 0, 2]
); // [batch, m, p]
// Equivalent string notation
const result2 = torch.einsum('...ij,jk->...ik', X, W);
// Transpose preserving batch dimensions
const transposed = torch.einsum(
X, [torch.Ellipsis, 0, 1],
[torch.Ellipsis, 1, 0]
); // [batch, n, m]