use crate::Tensor;
use std::ops::{Add, Div, Mul, Sub};
impl Add<f64> for &Tensor {
type Output = Tensor;
fn add(self, rhs: f64) -> Tensor {
Tensor {
data: self.data.iter().map(|&v| v + rhs).collect(),
shape: self.shape.clone(),
#[cfg(feature = "dynamic")]
dynamic: None,
}
}
}
impl Sub<f64> for &Tensor {
type Output = Tensor;
fn sub(self, rhs: f64) -> Tensor {
Tensor {
data: self.data.iter().map(|&v| v - rhs).collect(),
shape: self.shape.clone(),
#[cfg(feature = "dynamic")]
dynamic: None,
}
}
}
impl Mul<f64> for &Tensor {
type Output = Tensor;
fn mul(self, rhs: f64) -> Tensor {
Tensor {
data: self.data.iter().map(|&v| v * rhs).collect(),
shape: self.shape.clone(),
#[cfg(feature = "dynamic")]
dynamic: None,
}
}
}
impl Div<f64> for &Tensor {
type Output = Tensor;
fn div(self, rhs: f64) -> Tensor {
Tensor {
data: self.data.iter().map(|&v| v / rhs).collect(),
shape: self.shape.clone(),
#[cfg(feature = "dynamic")]
dynamic: None,
}
}
}
impl Add<&Tensor> for f64 {
type Output = Tensor;
fn add(self, rhs: &Tensor) -> Tensor {
Tensor {
data: rhs.data.iter().map(|&v| self + v).collect(),
shape: rhs.shape.clone(),
#[cfg(feature = "dynamic")]
dynamic: None,
}
}
}
impl Sub<&Tensor> for f64 {
type Output = Tensor;
fn sub(self, rhs: &Tensor) -> Tensor {
Tensor {
data: rhs.data.iter().map(|&v| self - v).collect(),
shape: rhs.shape.clone(),
#[cfg(feature = "dynamic")]
dynamic: None,
}
}
}
impl Mul<&Tensor> for f64 {
type Output = Tensor;
fn mul(self, rhs: &Tensor) -> Tensor {
Tensor {
data: rhs.data.iter().map(|&v| self * v).collect(),
shape: rhs.shape.clone(),
#[cfg(feature = "dynamic")]
dynamic: None,
}
}
}
impl Div<&Tensor> for f64 {
type Output = Tensor;
fn div(self, rhs: &Tensor) -> Tensor {
Tensor {
data: rhs.data.iter().map(|&v| self / v).collect(),
shape: rhs.shape.clone(),
#[cfg(feature = "dynamic")]
dynamic: None,
}
}
}