opensrdk-linear-algebra 0.8.5

Standard linear algebra library using blas and lapack for OpenSRDK toolchain.
Documentation
use crate::{
    number::{c64, Number},
    sparse::SparseTensor,
};
use rayon::prelude::*;
use std::ops::Mul;

pub(crate) fn mul_scalar<T>(slf: T, mut rhs: SparseTensor<T>) -> SparseTensor<T>
where
    T: Number,
{
    todo!()
}

pub(crate) fn mul<T>(slf: &SparseTensor<T>, rhs: &SparseTensor<T>) -> SparseTensor<T>
where
    T: Number,
{
    todo!()
}

macro_rules! impl_mul_scalar {
    {$t: ty} => {
        impl Mul<SparseTensor<$t>> for $t {
          type Output = SparseTensor<$t>;

          fn mul(self, rhs: SparseTensor<$t>) -> Self::Output {
            mul_scalar(self, rhs)
          }
        }

        impl Mul<SparseTensor<$t>> for &$t {
          type Output = SparseTensor<$t>;

          fn mul(self, rhs: SparseTensor<$t>) -> Self::Output {
            mul_scalar(*self, rhs)
          }
        }

        impl Mul<$t> for SparseTensor<$t> {
          type Output = SparseTensor<$t>;

          fn mul(self, rhs: $t) -> Self::Output {
            mul_scalar(rhs, self)
          }
        }

        impl Mul<&$t> for SparseTensor<$t> {
          type Output = SparseTensor<$t>;

          fn mul(self, rhs: &$t) -> Self::Output {
            mul_scalar(*rhs, self)
          }
        }
    };
}

impl_mul_scalar! {f64}
impl_mul_scalar! {c64}

macro_rules! impl_mul {
  {$t: ty} => {
      impl Mul<SparseTensor<$t>> for SparseTensor<$t> {
          type Output = SparseTensor<$t>;

          fn mul(self, rhs: SparseTensor<$t>) -> Self::Output {
            mul(&self, &rhs)
          }
      }

      impl Mul<&SparseTensor<$t>> for SparseTensor<$t> {
          type Output = SparseTensor<$t>;

          fn mul(self, rhs: &SparseTensor<$t>) -> Self::Output {
            mul(&self, rhs)
          }
      }

      impl Mul<SparseTensor<$t>> for &SparseTensor<$t> {
          type Output = SparseTensor<$t>;

          fn mul(self, rhs: SparseTensor<$t>) -> Self::Output {
            mul(self, &rhs)
          }
      }

      impl Mul<&SparseTensor<$t>> for &SparseTensor<$t> {
          type Output = SparseTensor<$t>;

          fn mul(self, rhs: &SparseTensor<$t>) -> Self::Output {
            mul(self, rhs)
          }
      }
  };
}

impl_mul! {f64}
impl_mul! {c64}