Skip to content

Commit 1fb120d

Browse files
committed
Adjust code and examples to PyO3 0.16 API changes.
1 parent 296815c commit 1fb120d

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

README.md

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

4444
```rust
4545
use numpy::ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
46-
use numpy::{IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn};
47-
use pyo3::prelude::{pymodule, PyModule, PyResult, Python};
46+
use numpy::{Complex64, IntoPyArray, PyArrayDyn, PyReadonlyArrayDyn};
47+
use pyo3::{pymodule, types::PyModule, PyResult, Python};
4848

4949
#[pymodule]
5050
fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
@@ -59,7 +59,8 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
5959
}
6060

6161
// wrapper of `axpy`
62-
#[pyfn(m, "axpy")]
62+
#[pyfn(m)]
63+
#[pyo3(name = "axpy")]
6364
fn axpy_py<'py>(
6465
py: Python<'py>,
6566
a: f64,
@@ -68,15 +69,16 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
6869
) -> &'py PyArrayDyn<f64> {
6970
let x = x.as_array();
7071
let y = y.as_array();
71-
axpy(a, x, y).into_pyarray(py)
72+
let z = axpy(a, x, y);
73+
z.into_pyarray(py)
7274
}
7375

7476
// wrapper of `mult`
75-
#[pyfn(m, "mult")]
76-
fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn<f64>) -> PyResult<()> {
77+
#[pyfn(m)]
78+
#[pyo3(name = "mult")]
79+
fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn<f64>) {
7780
let x = unsafe { x.as_array_mut() };
7881
mult(a, x);
79-
Ok(())
8082
}
8183

8284
Ok(())
@@ -96,8 +98,7 @@ numpy = "0.15"
9698

9799
```rust
98100
use numpy::PyArray1;
99-
use pyo3::prelude::{PyResult, Python};
100-
use pyo3::types::IntoPyDict;
101+
use pyo3::{types::IntoPyDict, PyResult, Python};
101102

102103
fn main() -> PyResult<()> {
103104
Python::with_gil(|py| {

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
use crate::dtype::Element;
1114

tests/array.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ fn as_slice() {
110110
fn is_instance() {
111111
pyo3::Python::with_gil(|py| {
112112
let arr = PyArray2::<f64>::zeros(py, [3, 5], false);
113-
assert!(arr.is_instance::<PyArray2<f64>>().unwrap());
114-
assert!(!arr.is_instance::<PyList>().unwrap());
113+
assert!(arr.is_instance_of::<PyArray2<f64>>().unwrap());
114+
assert!(!arr.is_instance_of::<PyList>().unwrap());
115115
})
116116
}
117117

0 commit comments

Comments
 (0)