@@ -732,13 +732,26 @@ where
732732 /// ```
733733 pub fn get < I > ( & self , index : I ) -> Option < & A >
734734 where
735- I : NdIndex < D > ,
736735 S : Data ,
736+ I : NdIndex < D > ,
737737 {
738738 unsafe { self . get_ptr ( index) . map ( |ptr| & * ptr) }
739739 }
740740
741- pub ( crate ) fn get_ptr < I > ( & self , index : I ) -> Option < * const A >
741+ /// Return a raw pointer to the element at `index`, or return `None`
742+ /// if the index is out of bounds.
743+ ///
744+ /// ```
745+ /// use ndarray::arr2;
746+ ///
747+ /// let a = arr2(&[[1., 2.], [3., 4.]]);
748+ ///
749+ /// let v = a.raw_view();
750+ /// let p = a.get_ptr((0, 1)).unwrap();
751+ ///
752+ /// assert_eq!(unsafe { *p }, 2.);
753+ /// ```
754+ pub fn get_ptr < I > ( & self , index : I ) -> Option < * const A >
742755 where
743756 I : NdIndex < D > ,
744757 {
@@ -758,7 +771,24 @@ where
758771 unsafe { self . get_ptr_mut ( index) . map ( |ptr| & mut * ptr) }
759772 }
760773
761- pub ( crate ) fn get_ptr_mut < I > ( & mut self , index : I ) -> Option < * mut A >
774+ /// Return a raw pointer to the element at `index`, or return `None`
775+ /// if the index is out of bounds.
776+ ///
777+ /// ```
778+ /// use ndarray::arr2;
779+ ///
780+ /// let mut a = arr2(&[[1., 2.], [3., 4.]]);
781+ ///
782+ /// let v = a.raw_view_mut();
783+ /// let p = a.get_ptr_mut((0, 1)).unwrap();
784+ ///
785+ /// unsafe {
786+ /// *p = 5.;
787+ /// }
788+ ///
789+ /// assert_eq!(a.get((0, 1)), Some(&5.));
790+ /// ```
791+ pub fn get_ptr_mut < I > ( & mut self , index : I ) -> Option < * mut A >
762792 where
763793 S : RawDataMut ,
764794 I : NdIndex < D > ,
0 commit comments