@@ -8,7 +8,8 @@ use std::{
88
99use ndarray:: {
1010 Array , ArrayBase , ArrayView , ArrayViewMut , Axis , Data , Dim , Dimension , IntoDimension , Ix0 , Ix1 ,
11- Ix2 , Ix3 , Ix4 , Ix5 , Ix6 , IxDyn , RawData , Shape , ShapeBuilder , StrideShape ,
11+ Ix2 , Ix3 , Ix4 , Ix5 , Ix6 , IxDyn , RawArrayView , RawArrayViewMut , RawData , Shape , ShapeBuilder ,
12+ StrideShape ,
1213} ;
1314use num_traits:: AsPrimitive ;
1415use pyo3:: {
@@ -809,7 +810,7 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
809810 res
810811 }
811812
812- /// Returns the internal array as `ArrayViewMut`. See also [`as_array`](#method.as_array).
813+ /// Returns the internal array as [ `ArrayViewMut`] . See also [`as_array`](#method.as_array).
813814 ///
814815 /// # Safety
815816 /// If another reference to the internal data exists(e.g., `&[T]` or `ArrayView`),
@@ -821,6 +822,22 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
821822 res
822823 }
823824
825+ /// Returns the internal array as [`RawArrayView`] enabling element access via raw pointers
826+ pub fn as_raw_array ( & self ) -> RawArrayView < T , D > {
827+ let ( shape, ptr, inverted_axises) = self . ndarray_shape_ptr ( ) ;
828+ let mut res = unsafe { RawArrayView :: from_shape_ptr ( shape, ptr) } ;
829+ inverted_axises. invert ( & mut res) ;
830+ res
831+ }
832+
833+ /// Returns the internal array as [`RawArrayViewMut`] enabling element access via raw pointers
834+ pub fn as_raw_array_mut ( & self ) -> RawArrayViewMut < T , D > {
835+ let ( shape, ptr, inverted_axises) = self . ndarray_shape_ptr ( ) ;
836+ let mut res = unsafe { RawArrayViewMut :: from_shape_ptr ( shape, ptr) } ;
837+ inverted_axises. invert ( & mut res) ;
838+ res
839+ }
840+
824841 /// Get a copy of `PyArray` as
825842 /// [`ndarray::Array`](https://docs.rs/ndarray/latest/ndarray/type.Array.html).
826843 ///
0 commit comments