use super::super::traversal::{map_into_gated, mapv};
use crate::domain::RealScalar;
use leto::{Array, ArrayView, ArrayViewMut, Result, VecStorage};
pub trait UnaryOp<T: RealScalar>: Copy + Send + Sync + 'static {
fn apply(&self, x: T) -> T;
const COMPUTE_BOUND: bool = true;
}
#[inline]
pub fn unary_map_into<T, Op, const N: usize>(
op: Op,
input: &ArrayView<'_, T, N>,
output: &mut ArrayViewMut<'_, T, N>,
) -> Result<()>
where
T: RealScalar,
Op: UnaryOp<T>,
{
map_into_gated(input, output, move |x| op.apply(x), Op::COMPUTE_BOUND)
}
#[inline]
pub fn unary_map<T, Op, const N: usize>(
op: Op,
input: &ArrayView<'_, T, N>,
) -> Result<Array<T, VecStorage<T>, N>>
where
T: RealScalar,
Op: UnaryOp<T>,
{
mapv(input, move |x| op.apply(x))
}