torch.Sublist
export type Sublist = readonly SublistElement[];A sublist of dimension specifications for einsum.
Array of subscript indices and/or ellipsis symbols that describe the dimensions of a tensor in einsum sublist notation.
Notation:
- Sublist notation:
[0, 1, 2]represents dimensions'ABC' - With ellipsis:
[Ellipsis, 0, 1]represents dimensions'...AB' - Can appear: start, middle, or end of sublist
Rules:
- Subscript indices: 0-51 (A-Z = 0-25, a-z = 26-51)
- Ellipsis can only appear once per sublist
- Elements must be of type SublistElement
Use in einsum:
torch.einsum(tensorA, sublista, tensorB, sublistb, [sublistout])
Examples
// Simple matrix multiplication sublist notation
const a = torch.randn([2, 3]);
const b = torch.randn([3, 4]);
// Equivalent to einsum('ij,jk->ik', a, b)
const result = torch.einsum(
a, [0, 1], // Sublist: [0, 1] = 'ij'
b, [1, 2], // Sublist: [1, 2] = 'jk'
[0, 2] // Output: [0, 2] = 'ik'
);
// With batch dimensions using ellipsis
const batchA = torch.randn([32, 2, 3]);
const batchB = torch.randn([32, 3, 4]);
// Equivalent to einsum('...ij,...jk->...ik', batchA, batchB)
const batchResult = torch.einsum(
batchA, [torch.Ellipsis, 0, 1],
batchB, [torch.Ellipsis, 1, 2],
[torch.Ellipsis, 0, 2]
);