MatRef

Struct MatRef 

Source
pub struct MatRef<'a, S: TropicalSemiring> { /* private fields */ }
Expand description

Immutable view over scalar data interpreted as a tropical matrix.

This is a lightweight view type that can be copied freely. It references scalar data and interprets operations using the specified semiring type.

use tropical_gemm::{MatRef, MaxPlus};

let data = [1.0f32, 2.0, 3.0, 4.0, 5.0, 6.0];
let a = MatRef::<MaxPlus<f32>>::from_slice(&data, 2, 3);

assert_eq!(a.nrows(), 2);
assert_eq!(a.ncols(), 3);
assert_eq!(a.get(0, 0), 1.0);

Implementations§

Source§

impl<'a, S: TropicalSemiring> MatRef<'a, S>

Source

pub fn from_slice(data: &'a [S::Scalar], nrows: usize, ncols: usize) -> Self

Create a matrix reference from a slice of scalars.

The data must be in column-major order with length nrows * ncols.

Source

pub fn nrows(&self) -> usize

Number of rows.

Source

pub fn ncols(&self) -> usize

Number of columns.

Source

pub fn as_slice(&self) -> &[S::Scalar]

Get the underlying scalar data.

Source

pub fn get(&self, i: usize, j: usize) -> S::Scalar
where S::Scalar: Copy,

Get the scalar value at position (i, j).

Source

pub fn to_owned(&self) -> Mat<S>
where S::Scalar: Copy,

Convert to an owned matrix.

Source§

impl<'a, S: TropicalSemiring + KernelDispatch> MatRef<'a, S>

Source

pub fn matmul(&self, b: &MatRef<'_, S>) -> Mat<S>

Perform tropical matrix multiplication: C = A ⊗ B.

Computes C[i,j] = ⊕_k (A[i,k] ⊗ B[k,j])

§Panics

Panics if dimensions don’t match (self.ncols != b.nrows).

Source§

impl<'a, S> MatRef<'a, S>

Source

pub fn matmul_argmax(&self, b: &MatRef<'_, S>) -> MatWithArgmax<S>

Perform tropical matrix multiplication with argmax tracking.

Returns both the result matrix and the argmax indices indicating which k-index produced each optimal value.

§Panics

Panics if dimensions don’t match (self.ncols != b.nrows).

Trait Implementations§

Source§

impl<'a, S: TropicalSemiring> Clone for MatRef<'a, S>

Source§

fn clone(&self) -> Self

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<'a, S: Debug + TropicalSemiring> Debug for MatRef<'a, S>
where S::Scalar: Debug,

Source§

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

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

impl<'a, S> Mul<&'a MatRef<'a, S>> for &Mat<S>

Source§

type Output = Mat<S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &'a MatRef<'a, S>) -> Mat<S>

Performs the * operation. Read more
Source§

impl<'a, 'b, S> Mul<&'b MatRef<'b, S>> for &'a MatRef<'a, S>

Source§

type Output = Mat<S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &'b MatRef<'b, S>) -> Mat<S>

Performs the * operation. Read more
Source§

impl<'a, 'b, S> Mul<MatRef<'b, S>> for MatRef<'a, S>

Source§

type Output = Mat<S>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: MatRef<'b, S>) -> Mat<S>

Performs the * operation. Read more
Source§

impl<'a, S: TropicalSemiring> Copy for MatRef<'a, S>

Auto Trait Implementations§

§

impl<'a, S> Freeze for MatRef<'a, S>

§

impl<'a, S> RefUnwindSafe for MatRef<'a, S>

§

impl<'a, S> Send for MatRef<'a, S>

§

impl<'a, S> Sync for MatRef<'a, S>

§

impl<'a, S> Unpin for MatRef<'a, S>
where S: Unpin,

§

impl<'a, S> UnwindSafe for MatRef<'a, S>

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, 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.