tropical_matmul

Function tropical_matmul 

Source
pub fn tropical_matmul<T: TropicalSemiring + KernelDispatch>(
    a: &[T::Scalar],
    m: usize,
    k: usize,
    b: &[T::Scalar],
    n: usize,
) -> Vec<T>
Expand description

Simple tropical matrix multiplication: C = A ⊗ B

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

§Arguments

  • a: Matrix A data in row-major order
  • m: Number of rows in A
  • k: Number of columns in A / rows in B
  • b: Matrix B data in row-major order
  • n: Number of columns in B

§Returns

Result matrix C of size m×n in row-major order

§Example

use tropical_gemm::{tropical_matmul, TropicalMaxPlus};

let a = vec![1.0f32, 2.0, 3.0, 4.0, 5.0, 6.0]; // 2x3
let b = vec![1.0f32, 2.0, 3.0, 4.0, 5.0, 6.0]; // 3x2

let c = tropical_matmul::<TropicalMaxPlus<f32>>(&a, 2, 3, &b, 2);
assert_eq!(c.len(), 4); // 2x2 result