Skip to content

Commit 4c21cb2

Browse files
committed
Adjust code and examples to PyO3 0.16 API changes.
1 parent 89a0fff commit 4c21cb2

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
7070
) -> &'py PyArrayDyn<f64> {
7171
let x = x.as_array();
7272
let y = y.as_array();
73-
axpy(a, x, y).into_pyarray(py)
73+
let z = axpy(a, x, y);
74+
z.into_pyarray(py)
7475
}
7576

7677
// wrapper of `mult`
7778
#[pyfn(m)]
7879
#[pyo3(name = "mult")]
79-
fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn<f64>) -> PyResult<()> {
80+
fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn<f64>) {
8081
let x = unsafe { x.as_array_mut() };
8182
mult(a, x);
82-
Ok(())
8383
}
8484

8585
Ok(())

src/array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ impl<D: Dimension> PyArray<PyObject, D> {
922922
///
923923
/// let pyarray = PyArray::from_owned_object_array(py, array);
924924
///
925-
/// assert!(pyarray.readonly().get(0).unwrap().as_ref(py).is_instance::<CustomElement>().unwrap());
925+
/// assert!(pyarray.readonly().get(0).unwrap().as_ref(py).is_instance_of::<CustomElement>().unwrap());
926926
/// });
927927
/// ```
928928
pub fn from_owned_object_array<'py, T>(py: Python<'py>, arr: Array<Py<T>, D>) -> &'py Self {

src/slice_container.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use std::{mem, slice};
22

33
use ndarray::{ArrayBase, Dimension, OwnedRepr};
4-
use pyo3::class::impl_::{PyClassImpl, ThreadCheckerStub};
5-
use pyo3::pyclass::PyClass;
6-
use pyo3::pyclass_slots::PyClassDummySlot;
7-
use pyo3::type_object::{LazyStaticType, PyTypeInfo};
8-
use pyo3::{ffi, types::PyAny, PyCell, Python};
4+
use pyo3::{
5+
ffi,
6+
impl_::pyclass::{PyClassDummySlot, PyClassImpl, PyClassItems, ThreadCheckerStub},
7+
pyclass::PyClass,
8+
type_object::{LazyStaticType, PyTypeInfo},
9+
PyAny, PyCell, Python,
10+
};
911

1012
/// Utility type to safely store `Box<[_]>` or `Vec<_>` on the Python heap
1113
pub(crate) struct PySliceContainer {
@@ -95,6 +97,8 @@ impl PyClassImpl for PySliceContainer {
9597
type BaseType = PyAny;
9698
type Layout = PyCell<Self>;
9799
type ThreadChecker = ThreadCheckerStub<Self>;
100+
101+
fn for_all_items(_visitor: &mut dyn FnMut(&PyClassItems)) {}
98102
}
99103

100104
unsafe impl PyTypeInfo for PySliceContainer {

tests/array.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ fn as_slice() {
120120
fn is_instance() {
121121
pyo3::Python::with_gil(|py| {
122122
let arr = PyArray2::<f64>::zeros(py, [3, 5], false);
123-
assert!(arr.is_instance::<PyArray2<f64>>().unwrap());
124-
assert!(!arr.is_instance::<PyList>().unwrap());
123+
assert!(arr.is_instance_of::<PyArray2<f64>>().unwrap());
124+
assert!(!arr.is_instance_of::<PyList>().unwrap());
125125
})
126126
}
127127

0 commit comments

Comments
 (0)