@@ -150,15 +150,37 @@ impl<T, D> PyArray<T, D> {
150
150
unsafe { ( * self . as_array_ptr ( ) ) . flags & flag == flag }
151
151
}
152
152
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
+ /// ```
153
173
pub fn is_contiguous ( & self ) -> bool {
154
174
self . check_flag ( npyffi:: NPY_ARRAY_C_CONTIGUOUS )
155
175
| self . check_flag ( npyffi:: NPY_ARRAY_F_CONTIGUOUS )
156
176
}
157
177
178
+ /// Returns `true` if the internal data of the array is Fortran-style contiguous.
158
179
pub fn is_fotran_contiguous ( & self ) -> bool {
159
180
self . check_flag ( npyffi:: NPY_ARRAY_F_CONTIGUOUS )
160
181
}
161
182
183
+ /// Returns `true` if the internal data of the array is C-style contiguous.
162
184
pub fn is_c_contiguous ( & self ) -> bool {
163
185
self . check_flag ( npyffi:: NPY_ARRAY_C_CONTIGUOUS )
164
186
}
@@ -426,7 +448,7 @@ impl<T: TypeNum, D: Dimension> PyArray<T, D> {
426
448
/// assert_eq!(py_array.as_slice().unwrap(), &[0, 1, 2, 3]);
427
449
/// let locals = [("np", numpy::get_array_module(py).unwrap())].into_py_dict(py);
428
450
/// 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)
430
452
/// .unwrap()
431
453
/// .downcast_ref()
432
454
/// .unwrap();
0 commit comments