@@ -150,15 +150,37 @@ impl<T, D> PyArray<T, D> {
150150 unsafe { ( * self . as_array_ptr ( ) ) . flags & flag == flag }
151151 }
152152
153+ /// Returns `true` if the internal data of the array is C-style contiguous
154+ /// (default of numpy and ndarray) or Fortran-style contiguous.
155+ ///
156+ /// # Example
157+ /// ```
158+ /// # extern crate pyo3; extern crate numpy; fn main() {
159+ /// use pyo3::types::IntoPyDict;
160+ /// let gil = pyo3::Python::acquire_gil();
161+ /// let py = gil.python();
162+ /// let array = numpy::PyArray::arange(py, 0, 1, 10);
163+ /// assert!(array.is_contiguous());
164+ /// let locals = [("np", numpy::get_array_module(py).unwrap())].into_py_dict(py);
165+ /// let not_contiguous: &numpy::PyArray1<f32> = py
166+ /// .eval("np.zeros((3, 5))[::2, 4]", Some(locals), None)
167+ /// .unwrap()
168+ /// .downcast_ref()
169+ /// .unwrap();
170+ /// assert!(!not_contiguous.is_contiguous());
171+ /// # }
172+ /// ```
153173 pub fn is_contiguous ( & self ) -> bool {
154174 self . check_flag ( npyffi:: NPY_ARRAY_C_CONTIGUOUS )
155175 | self . check_flag ( npyffi:: NPY_ARRAY_F_CONTIGUOUS )
156176 }
157177
178+ /// Returns `true` if the internal data of the array is Fortran-style contiguous.
158179 pub fn is_fotran_contiguous ( & self ) -> bool {
159180 self . check_flag ( npyffi:: NPY_ARRAY_F_CONTIGUOUS )
160181 }
161182
183+ /// Returns `true` if the internal data of the array is C-style contiguous.
162184 pub fn is_c_contiguous ( & self ) -> bool {
163185 self . check_flag ( npyffi:: NPY_ARRAY_C_CONTIGUOUS )
164186 }
@@ -426,7 +448,7 @@ impl<T: TypeNum, D: Dimension> PyArray<T, D> {
426448 /// assert_eq!(py_array.as_slice().unwrap(), &[0, 1, 2, 3]);
427449 /// let locals = [("np", numpy::get_array_module(py).unwrap())].into_py_dict(py);
428450 /// let not_contiguous: &PyArray1<f32> = py
429- /// .eval("np.zeros(10)[::2 ]", Some(locals), None)
451+ /// .eval("np.zeros((3, 5))[[0, 2], [3, 4] ]", Some(locals), None)
430452 /// .unwrap()
431453 /// .downcast_ref()
432454 /// .unwrap();
0 commit comments