Skip to content

Commit

Permalink
as_view
Browse files Browse the repository at this point in the history
  • Loading branch information
termoshtt committed Jun 20, 2020
1 parent 8dc079d commit c9e46a9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 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,14 @@ 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())
}
}

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

0 comments on commit c9e46a9

Please sign in to comment.