Skip to content

Commit

Permalink
Merge pull request #332 from PyO3/inline-layout-methods
Browse files Browse the repository at this point in the history
Inline the layout-related methods as these basically change types and could benefit from cold branch removal.
  • Loading branch information
adamreichold committed Jul 3, 2022
2 parents 93a3aaf + 5a4df5a commit c0549bd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/array.rs
Expand Up @@ -151,6 +151,7 @@ impl<'py, T: Element, D: Dimension> FromPyObject<'py> for &'py PyArray<T, D> {

impl<T, D> PyArray<T, D> {
/// Returns a raw pointer to the underlying [`PyArrayObject`][npyffi::PyArrayObject].
#[inline]
pub fn as_array_ptr(&self) -> *mut npyffi::PyArrayObject {
self.as_ptr() as _
}
Expand Down Expand Up @@ -282,6 +283,7 @@ impl<T, D> PyArray<T, D> {
///
/// [ndarray-ndim]: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.ndim.html
/// [PyArray_NDIM]: https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_NDIM
#[inline]
pub fn ndim(&self) -> usize {
unsafe { (*self.as_array_ptr()).nd as usize }
}
Expand All @@ -304,6 +306,7 @@ impl<T, D> PyArray<T, D> {
/// ```
/// [ndarray-strides]: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.strides.html
/// [PyArray_STRIDES]: https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_STRIDES
#[inline]
pub fn strides(&self) -> &[isize] {
let n = self.ndim();
if n == 0 {
Expand Down Expand Up @@ -336,6 +339,7 @@ impl<T, D> PyArray<T, D> {
///
/// [ndarray-shape]: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.shape.html
/// [PyArray_DIMS]: https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_DIMS
#[inline]
pub fn shape(&self) -> &[usize] {
let n = self.ndim();
if n == 0 {
Expand Down

0 comments on commit c0549bd

Please sign in to comment.