pub trait PyUntypedArrayMethods<'py>: Sealed {
    // Required methods
    fn as_array_ptr(&self) -> *mut PyArrayObject;
    fn dtype(&self) -> Bound<'py, PyArrayDescr>;

    // Provided methods
    fn is_contiguous(&self) -> bool { ... }
    fn is_fortran_contiguous(&self) -> bool { ... }
    fn is_c_contiguous(&self) -> bool { ... }
    fn ndim(&self) -> usize { ... }
    fn strides(&self) -> &[isize] { ... }
    fn shape(&self) -> &[usize] { ... }
    fn len(&self) -> usize { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

Implementation of functionality for PyUntypedArray.

Required Methods§

source

fn as_array_ptr(&self) -> *mut PyArrayObject

Returns a raw pointer to the underlying PyArrayObject.

source

fn dtype(&self) -> Bound<'py, PyArrayDescr>

Returns the dtype of the array.

See also ndarray.dtype and PyArray_DTYPE.

§Example
use numpy::prelude::*;
use numpy::{dtype_bound, PyArray};
use pyo3::Python;

Python::with_gil(|py| {
   let array = PyArray::from_vec_bound(py, vec![1_i32, 2, 3]);

   assert!(array.dtype().is_equiv_to(&dtype_bound::<i32>(py)));
});

Provided Methods§

source

fn is_contiguous(&self) -> bool

Returns true if the internal data of the array is contiguous, indepedently of whether C-style/row-major or Fortran-style/column-major.

§Example
use numpy::{PyArray1, PyUntypedArrayMethods};
use pyo3::{types::{IntoPyDict, PyAnyMethods}, Python};

Python::with_gil(|py| {
    let array = PyArray1::arange_bound(py, 0, 10, 1);
    assert!(array.is_contiguous());

    let view = py
        .eval_bound("array[::2]", None, Some(&[("array", array)].into_py_dict_bound(py)))
        .unwrap()
        .downcast_into::<PyArray1<i32>>()
        .unwrap();
    assert!(!view.is_contiguous());
});
source

fn is_fortran_contiguous(&self) -> bool

Returns true if the internal data of the array is Fortran-style/column-major contiguous.

source

fn is_c_contiguous(&self) -> bool

Returns true if the internal data of the array is C-style/row-major contiguous.

source

fn ndim(&self) -> usize

Returns the number of dimensions of the array.

See also ndarray.ndim and PyArray_NDIM.

§Example
use numpy::{PyArray3, PyUntypedArrayMethods};
use pyo3::Python;

Python::with_gil(|py| {
    let arr = PyArray3::<f64>::zeros_bound(py, [4, 5, 6], false);

    assert_eq!(arr.ndim(), 3);
});
source

fn strides(&self) -> &[isize]

Returns a slice indicating how many bytes to advance when iterating along each axis.

See also ndarray.strides and PyArray_STRIDES.

§Example
use numpy::{PyArray3, PyUntypedArrayMethods};
use pyo3::Python;

Python::with_gil(|py| {
    let arr = PyArray3::<f64>::zeros_bound(py, [4, 5, 6], false);

    assert_eq!(arr.strides(), &[240, 48, 8]);
});
source

fn shape(&self) -> &[usize]

Returns a slice which contains dimmensions of the array.

See also [ndarray.shape][ndaray-shape] and PyArray_DIMS.

§Example
use numpy::{PyArray3, PyUntypedArrayMethods};
use pyo3::Python;

Python::with_gil(|py| {
    let arr = PyArray3::<f64>::zeros_bound(py, [4, 5, 6], false);

    assert_eq!(arr.shape(), &[4, 5, 6]);
});
source

fn len(&self) -> usize

Calculates the total number of elements in the array.

source

fn is_empty(&self) -> bool

Returns true if the there are no elements in the array.

Implementations on Foreign Types§

source§

impl<'py> PyUntypedArrayMethods<'py> for Bound<'py, PyUntypedArray>

source§

impl<'py, T, D> PyUntypedArrayMethods<'py> for Bound<'py, PyArray<T, D>>

Implementors§