pub struct ArgmaxTracker { /* private fields */ }Expand description
Tracks winner indices from tropical forward-pass operations.
During a tropical contraction C[i,j] = max_k (A[i,k] + B[k,j]),
the tracker records which k achieved the maximum for each (i,j).
The backward pass uses these indices to route gradients.
§Examples
use tenferro_ext_tropical::ArgmaxTracker;
// Create a tracker for a 3x5 output
let tracker = ArgmaxTracker::new(&[3, 5]);
// After forward pass, query the winner index for output element (1, 2)
let k_winner = tracker.winner_index(&[1, 2]);
assert_eq!(k_winner, 0); // initialized to 0Implementations§
Source§impl ArgmaxTracker
impl ArgmaxTracker
Sourcepub fn new(output_shape: &[usize]) -> Self
pub fn new(output_shape: &[usize]) -> Self
Create a new tracker for an output of the given shape.
All winner indices are initialized to 0.
§Examples
use tenferro_ext_tropical::ArgmaxTracker;
let tracker = ArgmaxTracker::new(&[3, 5]);
assert_eq!(tracker.output_shape(), &[3, 5]);Sourcepub fn output_shape(&self) -> &[usize]
pub fn output_shape(&self) -> &[usize]
Return the output shape.
Sourcepub fn indices_mut(&mut self) -> &mut [usize]
pub fn indices_mut(&mut self) -> &mut [usize]
Return a mutable reference to the winner indices.
Sourcepub fn winner_index(&self, position: &[usize]) -> usize
pub fn winner_index(&self, position: &[usize]) -> usize
Look up the winner index for a given multi-dimensional output position.
§Examples
use tenferro_ext_tropical::ArgmaxTracker;
let tracker = ArgmaxTracker::new(&[3, 5]);
let k = tracker.winner_index(&[1, 2]);
assert_eq!(k, 0); // initialized to 0§Panics
Panics if position has the wrong rank or any index is out of bounds
for the tracked output shape.
Auto Trait Implementations§
impl Freeze for ArgmaxTracker
impl RefUnwindSafe for ArgmaxTracker
impl Send for ArgmaxTracker
impl Sync for ArgmaxTracker
impl Unpin for ArgmaxTracker
impl UnwindSafe for ArgmaxTracker
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
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
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