CountingTropical

Struct CountingTropical 

Source
#[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: T

The tropical value (using MaxPlus semantics).

§count: C

The count of paths achieving this value.

Implementations§

Source§

impl<T: TropicalScalar, C: TropicalScalar> CountingTropical<T, C>

Source

pub fn new(value: T, count: C) -> Self

Create a new CountingTropical value.

Source

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>

Source§

type Output = CountingTropical<T, C>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Clone + TropicalScalar, C: Clone + TropicalScalar> Clone for CountingTropical<T, C>

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<T: TropicalScalar, C: TropicalScalar> Debug for CountingTropical<T, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: TropicalScalar, C: TropicalScalar> Default for CountingTropical<T, C>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: TropicalScalar, C: TropicalScalar> Display for CountingTropical<T, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: TropicalScalar, C: TropicalScalar> From<T> for CountingTropical<T, C>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: TropicalScalar, C: TropicalScalar> Mul for CountingTropical<T, C>

Source§

type Output = CountingTropical<T, C>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: PartialEq + TropicalScalar, C: PartialEq + TropicalScalar> PartialEq for CountingTropical<T, C>

Source§

fn eq(&self, other: &CountingTropical<T, C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: TropicalScalar, C: TropicalScalar> SimdTropical for CountingTropical<T, C>

Source§

const SIMD_AVAILABLE: bool = true

Whether SIMD operations are available for this type.
Source§

const SIMD_WIDTH: usize = 8

The SIMD width in elements.
Source§

impl<T: TropicalScalar, C: TropicalScalar> TropicalSemiring for CountingTropical<T, C>

Source§

type Scalar = T

The underlying scalar type.
Source§

fn tropical_zero() -> Self

Returns the additive identity (zero element for ⊕).
Source§

fn tropical_one() -> Self

Returns the multiplicative identity (one element for ⊗).
Source§

fn tropical_add(self, rhs: Self) -> Self

Tropical addition (⊕).
Source§

fn tropical_mul(self, rhs: Self) -> Self

Tropical multiplication (⊗).
Source§

fn value(&self) -> T

Get the underlying scalar value.
Source§

fn from_scalar(s: T) -> Self

Create from a scalar value.
Source§

impl<T: TropicalScalar, C: TropicalScalar> TropicalWithArgmax for CountingTropical<T, C>

Source§

type Index = u32

The index type used for argmax tracking.
Source§

fn tropical_add_argmax( self, self_idx: u32, rhs: Self, rhs_idx: u32, ) -> (Self, u32)

Tropical addition with argmax tracking. Read more
Source§

impl<T: Copy + TropicalScalar, C: Copy + TropicalScalar> Copy for CountingTropical<T, C>

Source§

impl<T: TropicalScalar, C: TropicalScalar> StructuralPartialEq for CountingTropical<T, C>

Auto Trait Implementations§

§

impl<T, C> Freeze for CountingTropical<T, C>
where T: Freeze, C: Freeze,

§

impl<T, C> RefUnwindSafe for CountingTropical<T, C>

§

impl<T, C> Send for CountingTropical<T, C>

§

impl<T, C> Sync for CountingTropical<T, C>

§

impl<T, C> Unpin for CountingTropical<T, C>
where T: Unpin, C: Unpin,

§

impl<T, C> UnwindSafe for CountingTropical<T, C>
where T: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.