Skip to content

Commit 1fed0aa

Browse files
committed
Adjust code and examples to PyO3 0.16 API changes.
1 parent 0684f69 commit 1fed0aa

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ numpy = "0.15"
4545

4646
```rust
4747
use numpy::ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
48-
use numpy::{IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn};
49-
use pyo3::prelude::{pymodule, PyModule, PyResult, Python};
48+
use numpy::{Complex64, IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn};
49+
use pyo3::{pymodule, types::PyModule, PyResult, Python};
5050

5151
#[pymodule]
5252
fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
@@ -61,7 +61,8 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
6161
}
6262

6363
// wrapper of `axpy`
64-
#[pyfn(m, "axpy")]
64+
#[pyfn(m)]
65+
#[pyo3(name = "axpy")]
6566
fn axpy_py<'py>(
6667
py: Python<'py>,
6768
a: f64,
@@ -70,15 +71,16 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
7071
) -> &'py PyArrayDyn<f64> {
7172
let x = x.as_array();
7273
let y = y.as_array();
73-
axpy(a, x, y).into_pyarray(py)
74+
let z = axpy(a, x, y);
75+
z.into_pyarray(py)
7476
}
7577

7678
// wrapper of `mult`
77-
#[pyfn(m, "mult")]
78-
fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn<f64>) -> PyResult<()> {
79+
#[pyfn(m)]
80+
#[pyo3(name = "mult")]
81+
fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn<f64>) {
7982
let x = unsafe { x.as_array_mut() };
8083
mult(a, x);
81-
Ok(())
8284
}
8385

8486
Ok(())
@@ -98,8 +100,7 @@ numpy = "0.15"
98100

99101
```rust
100102
use numpy::PyArray1;
101-
use pyo3::prelude::{PyResult, Python};
102-
use pyo3::types::IntoPyDict;
103+
use pyo3::{types::IntoPyDict, PyResult, Python};
103104

104105
fn main() -> PyResult<()> {
105106
Python::with_gil(|py| {

src/array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ impl<D: Dimension> PyArray<PyObject, D> {
904904
///
905905
/// let pyarray = PyArray::from_owned_object_array(py, array);
906906
///
907-
/// assert!(pyarray.readonly().get(0).unwrap().as_ref(py).is_instance::<CustomElement>().unwrap());
907+
/// assert!(pyarray.readonly().get(0).unwrap().as_ref(py).is_instance_of::<CustomElement>().unwrap());
908908
/// });
909909
/// ```
910910
pub fn from_owned_object_array<'py, T>(py: Python<'py>, arr: Array<Py<T>, D>) -> &'py Self {

src/slice_container.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
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};
4+
use pyo3::{
5+
class::impl_::{PyClassImpl, ThreadCheckerStub},
6+
ffi,
7+
impl_::pyclass::PyClassDummySlot,
8+
pyclass::PyClass,
9+
type_object::{LazyStaticType, PyTypeInfo},
10+
PyAny, PyCell,
11+
};
912

1013
/// Utility type to safely store Box<[_]> or Vec<_> on the Python heap
1114
pub(crate) struct 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)