use std::ops::Add;
#[cfg(doc)]
use embed_doc_image::embed_doc_image;
use num_traits::Float;
use super::traits::DotAccumulator;
#[cfg_attr(doc, embed_doc_image("NaiveDot", "images/NaiveDot.svg"))]
#[derive(Copy, Clone, Debug)]
pub struct NaiveDot<F>(F);
impl<F> DotAccumulator<F> for NaiveDot<F>
where
F: Float,
{
#[inline]
fn dot(self) -> F {
self.0
}
}
impl<F> Add<(F, F)> for NaiveDot<F>
where
F: Float,
{
type Output = Self;
#[inline]
fn add(self, rhs: (F, F)) -> Self::Output {
NaiveDot(self.0 + rhs.0 * rhs.1)
}
}
impl<F> From<F> for NaiveDot<F>
where
F: Float,
{
fn from(x: F) -> Self {
NaiveDot(x)
}
}
impl<F> Add for NaiveDot<F>
where
F: Float,
{
type Output = Self;
#[inline]
fn add(self, rhs: Self) -> Self::Output {
NaiveDot(self.0 + rhs.0)
}
}
unsafe impl<F> Send for NaiveDot<F> where F: Send {}