#[repr(C)]pub struct CountingTropical<T: TropicalScalar, C: TropicalScalar = T> {
pub value: T,
pub count: C,
}Expand description
CountingTropical semiring: tracks both the tropical value and the count of optimal paths.
For TropicalMaxPlus semantics:
- Multiplication: (n₁, c₁) ⊗ (n₂, c₂) = (n₁ + n₂, c₁ × c₂)
- Addition: (n₁, c₁) ⊕ (n₂, c₂) =
- if n₁ > n₂: (n₁, c₁)
- if n₁ < n₂: (n₂, c₂)
- if n₁ = n₂: (n₁, c₁ + c₂)
This is used for:
- Counting optimal paths in dynamic programming
- Computing partition functions
- Gradient computations in certain neural network architectures
Fields§
§value: TThe tropical value (using MaxPlus semantics).
count: CThe count of paths achieving this value.
Implementations§
Source§impl<T: TropicalScalar, C: TropicalScalar> CountingTropical<T, C>
impl<T: TropicalScalar, C: TropicalScalar> CountingTropical<T, C>
Sourcepub fn from_value(value: T) -> Self
pub fn from_value(value: T) -> Self
Create a CountingTropical from a single value with count 1.
Trait Implementations§
Source§impl<T: TropicalScalar, C: TropicalScalar> Add for CountingTropical<T, C>
impl<T: TropicalScalar, C: TropicalScalar> Add for CountingTropical<T, C>
Source§impl<T: Clone + TropicalScalar, C: Clone + TropicalScalar> Clone for CountingTropical<T, C>
impl<T: Clone + TropicalScalar, C: Clone + TropicalScalar> Clone for CountingTropical<T, C>
Source§fn clone(&self) -> CountingTropical<T, C>
fn clone(&self) -> CountingTropical<T, C>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: TropicalScalar, C: TropicalScalar> Debug for CountingTropical<T, C>
impl<T: TropicalScalar, C: TropicalScalar> Debug for CountingTropical<T, C>
Source§impl<T: TropicalScalar, C: TropicalScalar> Default for CountingTropical<T, C>
impl<T: TropicalScalar, C: TropicalScalar> Default for CountingTropical<T, C>
Source§impl<T: TropicalScalar, C: TropicalScalar> Display for CountingTropical<T, C>
impl<T: TropicalScalar, C: TropicalScalar> Display for CountingTropical<T, C>
Source§impl<T: TropicalScalar, C: TropicalScalar> From<T> for CountingTropical<T, C>
impl<T: TropicalScalar, C: TropicalScalar> From<T> for CountingTropical<T, C>
Source§impl<T: TropicalScalar, C: TropicalScalar> Mul for CountingTropical<T, C>
impl<T: TropicalScalar, C: TropicalScalar> Mul for CountingTropical<T, C>
Source§impl<T: PartialEq + TropicalScalar, C: PartialEq + TropicalScalar> PartialEq for CountingTropical<T, C>
impl<T: PartialEq + TropicalScalar, C: PartialEq + TropicalScalar> PartialEq for CountingTropical<T, C>
Source§impl<T: TropicalScalar, C: TropicalScalar> SimdTropical for CountingTropical<T, C>
impl<T: TropicalScalar, C: TropicalScalar> SimdTropical for CountingTropical<T, C>
Source§const SIMD_AVAILABLE: bool = true
const SIMD_AVAILABLE: bool = true
Whether SIMD operations are available for this type.
Source§const SIMD_WIDTH: usize = 8
const SIMD_WIDTH: usize = 8
The SIMD width in elements.
Source§impl<T: TropicalScalar, C: TropicalScalar> TropicalSemiring for CountingTropical<T, C>
impl<T: TropicalScalar, C: TropicalScalar> TropicalSemiring for CountingTropical<T, C>
Source§fn tropical_zero() -> Self
fn tropical_zero() -> Self
Returns the additive identity (zero element for ⊕).
Source§fn tropical_one() -> Self
fn tropical_one() -> Self
Returns the multiplicative identity (one element for ⊗).
Source§fn tropical_add(self, rhs: Self) -> Self
fn tropical_add(self, rhs: Self) -> Self
Tropical addition (⊕).
Source§fn tropical_mul(self, rhs: Self) -> Self
fn tropical_mul(self, rhs: Self) -> Self
Tropical multiplication (⊗).
Source§fn from_scalar(s: T) -> Self
fn from_scalar(s: T) -> Self
Create from a scalar value.
Source§impl<T: TropicalScalar, C: TropicalScalar> TropicalWithArgmax for CountingTropical<T, C>
impl<T: TropicalScalar, C: TropicalScalar> TropicalWithArgmax for CountingTropical<T, C>
impl<T: Copy + TropicalScalar, C: Copy + TropicalScalar> Copy for CountingTropical<T, C>
impl<T: TropicalScalar, C: TropicalScalar> StructuralPartialEq for CountingTropical<T, C>
Auto Trait Implementations§
impl<T, C> Freeze for CountingTropical<T, C>
impl<T, C> RefUnwindSafe for CountingTropical<T, C>where
T: RefUnwindSafe,
C: RefUnwindSafe,
impl<T, C> Send for CountingTropical<T, C>
impl<T, C> Sync for CountingTropical<T, C>
impl<T, C> Unpin for CountingTropical<T, C>
impl<T, C> UnwindSafe for CountingTropical<T, C>where
T: UnwindSafe,
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more