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
//! Semiring matrix multiplication trait.
use crate;
use crateSemiringOp;
use crateRuntime;
use crateTensor;
/// Generalized matrix multiplication over arbitrary semirings.
///
/// Standard matmul computes `` `C[i,j] = Σ_k A[i,k] * B[k,j]` `` using the (+, ×) semiring.
/// This trait generalizes to `` `C[i,j] = ⊕_k (A[i,k] ⊗ B[k,j])` `` for any semiring (⊕, ⊗).
///
/// # Supported Semirings
///
/// | Variant | Reduce (⊕) | Combine (⊗) | Application |
/// |-----------|-----------|------------|-------------|
/// | MinPlus | min | + | Shortest paths |
/// | MaxPlus | max | + | Longest paths |
/// | MaxMin | max | min | Bottleneck/capacity |
/// | MinMax | min | max | Fuzzy relations |
/// | OrAnd | OR | AND | Transitive closure |
/// | PlusMax | + | max | DP formulations |
///
/// # DType Support
///
/// - **F32, F64, I32, I64**: All semiring ops except OrAnd
/// - **F16, BF16**: All semiring ops except OrAnd (with `f16` feature)
/// - **Bool**: OrAnd only
///
/// # Batched Operation
///
/// Supports batched matmul with the same broadcasting rules as standard matmul.