use ndarray::Array3;
use ndarray_stats::QuantileExt;
pub enum Operation {
Zero([usize; 3]),
Unit([usize; 3]),
Sum(Vec<Array3<f64>>),
Add(Array3<f64>, f64),
Sub(Array3<f64>, f64),
Mult(Array3<f64>, f64),
Div(Array3<f64>, f64),
Norm(Array3<f64>),
}
impl Operation {
#[allow(clippy::expect_used)]
#[inline]
#[must_use]
pub fn run(&self) -> Array3<f64> {
match *self {
Self::Zero(res) => (Array3::zeros(res)),
Self::Unit(res) => (Array3::zeros(res) + 1.0),
Self::Sum(ref data) => {
let mut base = data[0].clone();
for d in data.iter().skip(1) {
base += d;
}
base
}
Self::Add(ref data, x) => data + x,
Self::Sub(ref data, x) => data - x,
Self::Mult(ref data, x) => data * x,
Self::Div(ref data, x) => data / x,
Self::Norm(ref data) => {
let max = *data.max().expect("Failed to determine maximal value.");
data / max
}
}
}
}