use crate::ArgminSub;
use faer::{
mat::AsMatRef,
reborrow::{IntoConst, Reborrow, ReborrowMut},
unzip, zip, Mat, MatMut, MatRef,
};
use faer_traits::{ComplexField, Conjugate};
use std::ops::{Sub, SubAssign};
impl<E> ArgminSub<E, Mat<E>> for MatRef<'_, E>
where
E: ComplexField,
{
#[inline]
fn sub(&self, other: &E) -> Mat<E> {
zip!(self).map(|unzip!(this)| this.sub_by_ref(other))
}
}
impl<E> ArgminSub<E, Mat<E>> for Mat<E>
where
E: ComplexField,
{
#[inline]
fn sub(&self, other: &E) -> Mat<E> {
<_ as ArgminSub<_, _>>::sub(&self.as_mat_ref(), other)
}
}
impl<'a, E> ArgminSub<MatRef<'a, E>, Mat<E>> for E
where
E: ComplexField,
{
#[inline]
fn sub(&self, other: &MatRef<'a, E>) -> Mat<E> {
zip!(other).map(|unzip!(other_elem)| self.sub_by_ref(other_elem))
}
}
impl<E> ArgminSub<Mat<E>, Mat<E>> for E
where
E: ComplexField,
{
#[inline]
fn sub(&self, other: &Mat<E>) -> Mat<E> {
<_ as ArgminSub<_, _>>::sub(self, &other.as_mat_ref())
}
}
impl<'a, E: ComplexField> ArgminSub<MatRef<'a, E>, Mat<E>> for MatRef<'_, E> {
#[inline]
fn sub(&self, other: &MatRef<'a, E>) -> Mat<E> {
zip!(self, other).map(|unzip!(this, other)| this.sub_by_ref(other))
}
}
impl<'a, E: ComplexField> ArgminSub<MatRef<'a, E>, Mat<E>> for Mat<E> {
#[inline]
fn sub(&self, other: &MatRef<'a, E>) -> Mat<E> {
<_ as ArgminSub<_, _>>::sub(&self.as_mat_ref(), other)
}
}
impl<E: ComplexField> ArgminSub<Mat<E>, Mat<E>> for MatRef<'_, E> {
#[inline]
fn sub(&self, other: &Mat<E>) -> Mat<E> {
<_ as ArgminSub<_, _>>::sub(self, &other.as_mat_ref())
}
}
impl<E: ComplexField> ArgminSub<Mat<E>, Mat<E>> for Mat<E> {
#[inline]
fn sub(&self, other: &Mat<E>) -> Mat<E> {
<_ as ArgminSub<_, _>>::sub(&self.as_mat_ref(), &other.as_mat_ref())
}
}