chela 0.0.2

High-performance Machine Learning, Auto-Differentiation and Tensor Algebra crate for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::{NdArray, StridedMemory, RawDataType};
use std::ops::Neg;

pub(crate) trait UnaryOps<T: RawDataType> {
    fn neg<'a, 'b>(rhs: impl AsRef<NdArray<'a, T>>) -> NdArray<'static, T>
    where
        T: Neg<Output=T>,
    {
        let rhs = rhs.as_ref();

        let data = rhs.flatiter().map(|rhs| -rhs).collect();
        unsafe { NdArray::from_contiguous_owned_buffer(rhs.shape().to_vec(), data) }
    }
}

impl<T: RawDataType> UnaryOps<T> for T {}