2022-08-01 07:33:43 +00:00
|
|
|
// borrowed from the auto_ops crate
|
|
|
|
#[doc(hidden)]
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! impl_matrix_op {
|
2022-08-19 04:07:05 +00:00
|
|
|
(neg) => {
|
|
|
|
$crate::_impl_op_m_internal_ex!(Neg, neg);
|
|
|
|
};
|
|
|
|
(!) => {
|
|
|
|
$crate::_impl_op_m_internal_ex!(Not, not);
|
|
|
|
};
|
|
|
|
(+) => {
|
|
|
|
$crate::_impl_op_mm_internal_ex!(Add, add);
|
|
|
|
$crate::_impl_opassign_mm_internal_ex!(AddAssign, add_assign);
|
|
|
|
};
|
|
|
|
(-) => {
|
|
|
|
$crate::_impl_op_mm_internal_ex!(Sub, sub);
|
|
|
|
$crate::_impl_opassign_mm_internal_ex!(SubAssign, sub_assign);
|
|
|
|
};
|
|
|
|
(*) => {
|
|
|
|
$crate::_impl_op_mm_internal_ex!(Mul, mul);
|
|
|
|
$crate::_impl_op_ms_internal_ex!(Mul, mul);
|
|
|
|
$crate::_impl_opassign_mm_internal_ex!(MulAssign, mul_assign);
|
|
|
|
$crate::_impl_opassign_ms_internal_ex!(MulAssign, mul_assign);
|
|
|
|
};
|
|
|
|
(/) => {
|
|
|
|
$crate::_impl_op_mm_internal_ex!(Div, div);
|
|
|
|
$crate::_impl_op_ms_internal_ex!(Div, div);
|
|
|
|
$crate::_impl_opassign_mm_internal_ex!(DivAssign, div_assign);
|
|
|
|
$crate::_impl_opassign_ms_internal_ex!(DivAssign, div_assign);
|
|
|
|
};
|
|
|
|
(%) => {
|
|
|
|
$crate::_impl_op_mm_internal_ex!(Rem, rem);
|
|
|
|
$crate::_impl_op_ms_internal_ex!(Rem, rem);
|
|
|
|
$crate::_impl_opassign_mm_internal_ex!(RemAssign, rem_assign);
|
|
|
|
$crate::_impl_opassign_ms_internal_ex!(RemAssign, rem_assign);
|
|
|
|
};
|
|
|
|
(&) => {
|
|
|
|
$crate::_impl_op_mm_internal_ex!(BitAnd, bitand);
|
|
|
|
$crate::_impl_opassign_mm_internal_ex!(BitAndAssign, bitand_assign);
|
|
|
|
};
|
|
|
|
(|) => {
|
|
|
|
$crate::_impl_op_mm_internal_ex!(BitOr, bitor);
|
|
|
|
$crate::_impl_opassign_mm_internal_ex!(BitOrAssign, bitor_assign);
|
|
|
|
};
|
|
|
|
(^) => {
|
|
|
|
$crate::_impl_op_mm_internal_ex!(BitXor, bitxor);
|
|
|
|
$crate::_impl_opassign_mm_internal_ex!(BitXorAssign, bitxor_assign);
|
|
|
|
};
|
|
|
|
(<<) => {
|
|
|
|
$crate::_impl_op_ms_internal_ex!(Shl, shl);
|
|
|
|
$crate::_impl_opassign_ms_internal_ex!(ShlAssign, shl_assign);
|
|
|
|
};
|
|
|
|
(>>) => {
|
|
|
|
$crate::_impl_op_ms_internal_ex!(Shr, shr);
|
|
|
|
$crate::_impl_opassign_ms_internal_ex!(ShrAssign, shr_assign);
|
2022-08-01 07:33:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! _impl_op_m_internal_ex {
|
2022-08-19 04:07:05 +00:00
|
|
|
($ops_trait:ident, $ops_fn:ident) => {
|
|
|
|
$crate::_impl_op_m_internal!($ops_trait, $ops_fn, Matrix<L,M,N>, Matrix<L,M,N>);
|
|
|
|
$crate::_impl_op_m_internal!($ops_trait, $ops_fn, &Matrix<L,M,N>, Matrix<L,M,N>);
|
2022-08-01 07:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! _impl_op_mm_internal_ex {
|
2022-08-19 04:07:05 +00:00
|
|
|
($ops_trait:ident, $ops_fn:ident) => {
|
|
|
|
$crate::_impl_op_mm_internal!($ops_trait, $ops_fn, Matrix<L,M,N>, Matrix<R,M,N>, Matrix<L,M,N>);
|
|
|
|
$crate::_impl_op_mm_internal!($ops_trait, $ops_fn, &Matrix<L,M,N>, Matrix<R,M,N>, Matrix<L,M,N>);
|
|
|
|
$crate::_impl_op_mm_internal!($ops_trait, $ops_fn, Matrix<L,M,N>, &Matrix<R,M,N>, Matrix<L,M,N>);
|
|
|
|
$crate::_impl_op_mm_internal!($ops_trait, $ops_fn, &Matrix<L,M,N>, &Matrix<R,M,N>, Matrix<L,M,N>);
|
2022-08-01 07:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! _impl_opassign_mm_internal_ex {
|
2022-08-19 04:07:05 +00:00
|
|
|
($ops_trait:ident, $ops_fn:ident) => {
|
|
|
|
$crate::_impl_opassign_mm_internal!($ops_trait, $ops_fn, Matrix<L,M,N>, Matrix<R,M,N>, Matrix<L,M,N>);
|
|
|
|
$crate::_impl_opassign_mm_internal!($ops_trait, $ops_fn, Matrix<L,M,N>, &Matrix<R,M,N>, Matrix<L,M,N>);
|
2022-08-01 07:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! _impl_op_ms_internal_ex {
|
2022-08-19 04:07:05 +00:00
|
|
|
($ops_trait:ident, $ops_fn:ident) => {
|
|
|
|
$crate::_impl_op_ms_internal!($ops_trait, $ops_fn, Matrix<L,M,N>, R, Matrix<L,M,N>);
|
|
|
|
$crate::_impl_op_ms_internal!($ops_trait, $ops_fn, &Matrix<L,M,N>, R, Matrix<L,M,N>);
|
2022-08-01 07:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! _impl_opassign_ms_internal_ex {
|
2022-08-19 04:07:05 +00:00
|
|
|
($ops_trait:ident, $ops_fn:ident) => {
|
|
|
|
$crate::_impl_opassign_ms_internal!($ops_trait, $ops_fn, Matrix<L,M,N>, R, Matrix<L,M,N>);
|
2022-08-01 07:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-08-19 04:07:05 +00:00
|
|
|
macro_rules! _impl_op_m_internal {
|
|
|
|
($ops_trait:ident, $ops_fn:ident, $lhs:ty, $out:ty) => {
|
|
|
|
impl<L, const M: usize, const N: usize> ::std::ops::$ops_trait for $lhs
|
2022-08-01 07:33:43 +00:00
|
|
|
where
|
2022-08-19 04:07:05 +00:00
|
|
|
L: ::std::ops::$ops_trait<Output = L> + Scalar,
|
2022-08-01 07:33:43 +00:00
|
|
|
{
|
|
|
|
type Output = $out;
|
|
|
|
|
2022-08-19 04:07:05 +00:00
|
|
|
#[inline(always)]
|
|
|
|
fn $ops_fn(self) -> Self::Output {
|
2022-08-01 07:33:43 +00:00
|
|
|
let mut result = self.clone();
|
2022-08-19 04:07:05 +00:00
|
|
|
for m in 0..M {
|
|
|
|
for n in 0..N {
|
|
|
|
result.data[m][n] = self.data[m][n].$ops_fn();
|
|
|
|
}
|
2022-08-01 07:33:43 +00:00
|
|
|
}
|
|
|
|
result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-08-19 04:07:05 +00:00
|
|
|
macro_rules! _impl_op_mm_internal {
|
|
|
|
($ops_trait:ident, $ops_fn:ident, $lhs:ty, $rhs:ty, $out:ty) => {
|
2022-08-01 07:33:43 +00:00
|
|
|
impl<L, R, const M: usize, const N: usize> ::std::ops::$ops_trait<$rhs> for $lhs
|
|
|
|
where
|
2022-08-19 04:07:05 +00:00
|
|
|
L: ::std::ops::$ops_trait<R, Output = L> + Scalar,
|
2022-08-01 07:33:43 +00:00
|
|
|
R: Scalar,
|
|
|
|
{
|
2022-08-19 04:07:05 +00:00
|
|
|
type Output = $out;
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn $ops_fn(self, other: $rhs) -> Self::Output {
|
|
|
|
let mut result = self.clone();
|
|
|
|
for m in 0..M {
|
|
|
|
for n in 0..N {
|
|
|
|
result.data[m][n] = self.data[m][n].$ops_fn(other.data[m][n]);
|
|
|
|
}
|
2022-08-01 07:33:43 +00:00
|
|
|
}
|
2022-08-19 04:07:05 +00:00
|
|
|
result
|
2022-08-01 07:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-08-19 04:07:05 +00:00
|
|
|
macro_rules! _impl_opassign_mm_internal {
|
|
|
|
($ops_trait:ident, $ops_fn:ident, $lhs:ty, $rhs:ty, $out:ty) => {
|
|
|
|
impl<L, R, const M: usize, const N: usize> ::std::ops::$ops_trait<$rhs> for $lhs
|
2022-08-01 07:33:43 +00:00
|
|
|
where
|
2022-08-19 04:07:05 +00:00
|
|
|
L: ::std::ops::$ops_trait<R> + Scalar,
|
|
|
|
R: Scalar,
|
2022-08-01 07:33:43 +00:00
|
|
|
{
|
2022-08-19 04:07:05 +00:00
|
|
|
#[inline(always)]
|
|
|
|
fn $ops_fn(&mut self, other: $rhs) {
|
|
|
|
for m in 0..M {
|
|
|
|
for n in 0..N {
|
|
|
|
self.data[m][n].$ops_fn(other.data[m][n]);
|
|
|
|
}
|
2022-08-01 07:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! _impl_op_ms_internal {
|
2022-08-19 04:07:05 +00:00
|
|
|
($ops_trait:ident, $ops_fn:ident, $lhs:ty, $rhs:ty, $out:ty) => {
|
2022-08-01 07:33:43 +00:00
|
|
|
impl<L, R, const M: usize, const N: usize> ::std::ops::$ops_trait<$rhs> for $lhs
|
|
|
|
where
|
2022-08-19 04:07:05 +00:00
|
|
|
L: ::std::ops::$ops_trait<R, Output = L> + Scalar,
|
2022-08-01 07:33:43 +00:00
|
|
|
R: Scalar,
|
|
|
|
{
|
|
|
|
type Output = $out;
|
|
|
|
|
2022-08-19 04:07:05 +00:00
|
|
|
#[inline(always)]
|
|
|
|
fn $ops_fn(self, other: $rhs) -> Self::Output {
|
2022-08-01 07:33:43 +00:00
|
|
|
let mut result = self.clone();
|
2022-08-19 04:07:05 +00:00
|
|
|
for m in 0..M {
|
|
|
|
for n in 0..N {
|
|
|
|
result.data[m][n] = self.data[m][n].$ops_fn(other);
|
|
|
|
}
|
2022-08-01 07:33:43 +00:00
|
|
|
}
|
|
|
|
result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! _impl_opassign_ms_internal {
|
2022-08-19 04:07:05 +00:00
|
|
|
($ops_trait:ident, $ops_fn:ident, $lhs:ty, $rhs:ty, $out:ty) => {
|
2022-08-01 07:33:43 +00:00
|
|
|
impl<L, R, const M: usize, const N: usize> ::std::ops::$ops_trait<$rhs> for $lhs
|
|
|
|
where
|
2022-08-19 04:07:05 +00:00
|
|
|
L: ::std::ops::$ops_trait<R> + Scalar,
|
2022-08-01 07:33:43 +00:00
|
|
|
R: Scalar,
|
|
|
|
{
|
2022-08-19 04:07:05 +00:00
|
|
|
#[inline(always)]
|
2022-08-01 07:33:43 +00:00
|
|
|
fn $ops_fn(&mut self, r: $rhs) {
|
2022-08-19 04:07:05 +00:00
|
|
|
for m in 0..M {
|
|
|
|
for n in 0..N {
|
|
|
|
self.data[m][n].$ops_fn(r);
|
|
|
|
}
|
2022-08-01 07:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|