Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline the layout-related methods as these basically change types and could benefit from cold branch removal. #332

Merged
merged 1 commit into from Jul 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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