pub trait Semiring: Algebra {
// Required methods
fn zero() -> Self::Scalar;
fn one() -> Self::Scalar;
fn add(a: Self::Scalar, b: Self::Scalar) -> Self::Scalar;
fn mul(a: Self::Scalar, b: Self::Scalar) -> Self::Scalar;
}Expand description
Semiring trait for algebra-generic operations.
The algebra type Alg carries its scalar type via Alg::Scalar. This
is the core algebra model — primitive-family trait bounds and
einsum/linalg contracts are centered on Alg::Scalar.
Defines the four fundamental operations needed for tensor contractions under a given algebra:
zero(): Additive identityone(): Multiplicative identityadd(a, b): Semiring addition (e.g.,+for Standard,maxfor MaxPlus)mul(a, b): Semiring multiplication (e.g.,*for Standard,+for MaxPlus)
§Examples
Standard arithmetic (Standard<f64>):
zero() = 0,one() = 1,add = +,mul = *
Tropical (MaxPlus) semiring (in external crate):
zero() = -∞,one() = 0,add = max,mul = +
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.