1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Operand-count dispatch for [`einsum`].
//!
//! The public entry point parses the subscript once, rejects a count the
//! caller cannot satisfy, and hands the validated operands to the leaf that
//! owns that arity. Keeping recognition tables per arity means a pattern added
//! to one leaf cannot silently change another's matching order.
use ;
use ;
use crateBackendOps;
use ;
use Tensor;
/// Einstein summation over one or two tensor operands.
///
/// Supported patterns (whitespace around labels is ignored):
/// - `"ij,jk->ik"` — 2-D matrix multiply
/// - `"bij,bjk->bik"` — batched 3-D matrix multiply
/// - `"ij->ji"` — 2-D transpose
/// - `"i,i->"` — dot product (inner product)
/// - `"i,j->ij"` — outer product
/// - `"ii->"` — trace (sum of diagonal)
/// - `"ij,j->i"` — matrix-vector multiply
/// - `"bik,bk->bi"` — batched matrix-vector multiply
///
/// # Errors
///
/// Returns a [`BackendError`](coeus_core::BackendError) (as `B::Error`) when the
/// subscript names a different operand count than provided
/// ([`EinsumOperandCount`](coeus_core::BackendError::EinsumOperandCount)),
/// an operand's rank disagrees with its pattern
/// ([`EinsumRank`](coeus_core::BackendError::EinsumRank)), a contraction
/// dimension disagrees ([`EinsumDim`](coeus_core::BackendError::EinsumDim)), or
/// the subscript names no supported pattern
/// ([`EinsumUnsupportedPattern`](coeus_core::BackendError::EinsumUnsupportedPattern)).
/// Caller-supplied subscripts are untrusted input: rejection is typed, never
/// a panic.