From c9e46a9ff7cfe50d724a853162c1271b817fdde5 Mon Sep 17 00:00:00 2001 From: Toshiki Teramura Date: Fri, 28 Jun 2019 14:24:28 +0900 Subject: [PATCH 1/2] as_view --- fftw/src/array.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fftw/src/array.rs b/fftw/src/array.rs index 3c3bfc5c..70c2b625 100644 --- a/fftw/src/array.rs +++ b/fftw/src/array.rs @@ -2,6 +2,7 @@ use crate::types::*; use ffi; +use ndarray::*; use num_traits::Zero; use std::ops::{Deref, DerefMut}; @@ -55,6 +56,14 @@ impl AlignedVec { pub fn as_slice_mut(&mut self) -> &mut [T] { unsafe { from_raw_parts_mut(self.data, self.n) } } + + pub fn as_view(&self, shape: Shape) -> Result, ShapeError> + where + D: Dimension, + Shape: Into>, + { + ArrayView::from_shape(shape, self.as_slice()) + } } impl Deref for AlignedVec { From 4f803b8bd38712aa25228c701c0ba316182b652a Mon Sep 17 00:00:00 2001 From: Toshiki Teramura Date: Fri, 28 Jun 2019 14:38:29 +0900 Subject: [PATCH 2/2] as_view_mut --- fftw/src/array.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fftw/src/array.rs b/fftw/src/array.rs index 70c2b625..745a1fbe 100644 --- a/fftw/src/array.rs +++ b/fftw/src/array.rs @@ -64,6 +64,14 @@ impl AlignedVec { { ArrayView::from_shape(shape, self.as_slice()) } + + pub fn as_view_mut(&mut self, shape: Shape) -> Result, ShapeError> + where + D: Dimension, + Shape: Into>, + { + ArrayViewMut::from_shape(shape, self.as_slice_mut()) + } } impl Deref for AlignedVec {