use crate::algebra::{
abstr::{Field, Scalar},
linear::{matrix::General, vector::Vector},
};
use std::ops::Mul;
impl<T> Mul<General<T>> for Vector<T>
where
T: Field + Scalar,
{
type Output = Vector<T>;
fn mul(self, rhs: General<T>) -> Self::Output {
&self * &rhs
}
}
impl<'a, 'b, T> Mul<&'b General<T>> for &'a Vector<T>
where
T: Field + Scalar,
{
type Output = Vector<T>;
fn mul(self, rhs: &'b General<T>) -> Self::Output {
let (rhs_m, _): (usize, usize) = rhs.dim();
let (_m, n): (usize, usize) = self.dim();
if n != rhs_m {
panic!("Vector and matrix dimensions do not match");
}
Vector::new_row((&self.data * rhs).convert_to_vec())
}
}
impl<T> Mul<T> for Vector<T>
where
T: Field + Scalar,
{
type Output = Vector<T>;
fn mul(self, rhs: T) -> Self::Output {
Vector {
data: &self.data * (&rhs),
}
}
}
impl<'a, T> Mul<&T> for &'a Vector<T>
where
T: Field + Scalar,
{
type Output = Vector<T>;
fn mul(self, rhs: &T) -> Self::Output {
Vector {
data: &self.data * rhs,
}
}
}
impl<'a, 'b, T> Mul<&'b T> for &'a mut Vector<T>
where
T: Field + Scalar,
{
type Output = &'a mut Vector<T>;
fn mul(self, rhs: &'b T) -> Self::Output {
let _ = &mut self.data * rhs;
self
}
}