Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions fftw/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::types::*;
use ffi;
use ndarray::*;

use num_traits::Zero;
use std::ops::{Deref, DerefMut};
Expand Down Expand Up @@ -55,6 +56,22 @@ impl<T> AlignedVec<T> {
pub fn as_slice_mut(&mut self) -> &mut [T] {
unsafe { from_raw_parts_mut(self.data, self.n) }
}

pub fn as_view<D, Shape>(&self, shape: Shape) -> Result<ArrayView<T, D>, ShapeError>
where
D: Dimension,
Shape: Into<StrideShape<D>>,
{
ArrayView::from_shape(shape, self.as_slice())
}

pub fn as_view_mut<D, Shape>(&mut self, shape: Shape) -> Result<ArrayViewMut<T, D>, ShapeError>
where
D: Dimension,
Shape: Into<StrideShape<D>>,
{
ArrayViewMut::from_shape(shape, self.as_slice_mut())
}
}

impl<T> Deref for AlignedVec<T> {
Expand Down