pub struct TropicalMatrix<T>where
T: Float,{
pub rows: usize,
pub cols: usize,
pub data: Vec<Vec<TropicalNumber<T>>>,
}Expand description
A matrix in tropical algebra
Stores elements as a 2D vector with dimensions (rows × cols). Matrix operations follow tropical semiring rules:
- Matrix addition: element-wise max
- Matrix multiplication: tropical matrix product
Fields§
§rows: usize§cols: usize§data: Vec<Vec<TropicalNumber<T>>>Implementations§
Source§impl<T> TropicalMatrix<T>where
T: Float,
impl<T> TropicalMatrix<T>where
T: Float,
Sourcepub fn new(rows: usize, cols: usize) -> TropicalMatrix<T>
pub fn new(rows: usize, cols: usize) -> TropicalMatrix<T>
Create a new tropical matrix with given dimensions
Initializes all elements to tropical zero (-∞)
Sourcepub fn from_vec(data: Vec<Vec<T>>) -> Result<TropicalMatrix<T>, TropicalError>
pub fn from_vec(data: Vec<Vec<T>>) -> Result<TropicalMatrix<T>, TropicalError>
Create a tropical matrix from raw 2D data
Data must be a Vec of rows, where each row is a Vec of values
Sourcepub fn get(
&self,
row: usize,
col: usize,
) -> Result<TropicalNumber<T>, TropicalError>
pub fn get( &self, row: usize, col: usize, ) -> Result<TropicalNumber<T>, TropicalError>
Get element at (row, col)
Sourcepub fn set(
&mut self,
row: usize,
col: usize,
value: TropicalNumber<T>,
) -> Result<(), TropicalError>
pub fn set( &mut self, row: usize, col: usize, value: TropicalNumber<T>, ) -> Result<(), TropicalError>
Set element at (row, col)
Sourcepub fn identity(size: usize) -> TropicalMatrix<T>
pub fn identity(size: usize) -> TropicalMatrix<T>
Create tropical identity matrix
Diagonal elements are tropical one (0), off-diagonal are tropical zero (-∞)
Sourcepub fn from_log_probs(log_probs: &[Vec<T>]) -> TropicalMatrix<T>
pub fn from_log_probs(log_probs: &[Vec<T>]) -> TropicalMatrix<T>
Create tropical matrix from log probabilities
In tropical algebra, log probabilities are natural since:
- log(p1 * p2) = log(p1) + log(p2) (tropical multiplication)
- log(max(p1, p2)) ≈ max(log(p1), log(p2)) (tropical addition)
This method converts a 2D array of log probabilities into a tropical matrix.
Sourcepub fn tropical_matmul(
&self,
other: &TropicalMatrix<T>,
) -> Result<TropicalMatrix<T>, TropicalError>
pub fn tropical_matmul( &self, other: &TropicalMatrix<T>, ) -> Result<TropicalMatrix<T>, TropicalError>
Tropical matrix multiplication
(A ⊗ B)[i,j] = max_k(A[i,k] + B[k,j])
Sourcepub fn data(&self) -> &Vec<Vec<TropicalNumber<T>>>
pub fn data(&self) -> &Vec<Vec<TropicalNumber<T>>>
Get the underlying data as a 2D vector
Sourcepub fn data_mut(&mut self) -> &mut Vec<Vec<TropicalNumber<T>>>
pub fn data_mut(&mut self) -> &mut Vec<Vec<TropicalNumber<T>>>
Get mutable access to the underlying data
Trait Implementations§
Source§impl<T> Clone for TropicalMatrix<T>
impl<T> Clone for TropicalMatrix<T>
Source§fn clone(&self) -> TropicalMatrix<T>
fn clone(&self) -> TropicalMatrix<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for TropicalMatrix<T>
impl<T> Debug for TropicalMatrix<T>
Source§impl<T> Display for TropicalMatrix<T>
impl<T> Display for TropicalMatrix<T>
Source§impl<T> PartialEq for TropicalMatrix<T>
impl<T> PartialEq for TropicalMatrix<T>
impl<T> StructuralPartialEq for TropicalMatrix<T>where
T: Float,
Auto Trait Implementations§
impl<T> Freeze for TropicalMatrix<T>
impl<T> RefUnwindSafe for TropicalMatrix<T>where
T: RefUnwindSafe,
impl<T> Send for TropicalMatrix<T>where
T: Send,
impl<T> Sync for TropicalMatrix<T>where
T: Sync,
impl<T> Unpin for TropicalMatrix<T>where
T: Unpin,
impl<T> UnwindSafe for TropicalMatrix<T>where
T: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.