redstone_ml/ndarray/
unary_ops.rs1use crate::ops::unary_ops::UnaryOps;
2use crate::{Constructors, NdArray, RawDataType, StridedMemory};
3use std::ops::Neg;
4
5impl<T: RawDataType + UnaryOps> Neg for NdArray<'_, T> {
6 type Output = NdArray<'static, T>;
7
8 fn neg(self) -> Self::Output { -&self }
9}
10
11impl<T: RawDataType + UnaryOps> Neg for &NdArray<'_, T> {
12 type Output = NdArray<'static, T>;
13
14 fn neg(self) -> Self::Output {
15 let mut data = vec![T::default(); self.size()];
16
17 unsafe {
18 <T as UnaryOps>::neg(self.ptr(), self.shape(), self.stride(), data.as_mut_ptr());
19 NdArray::from_contiguous_owned_buffer(self.shape().to_vec(), data)
20 }
21 }
22}