Skip to content

Commit c1727fb

Browse files
authored
update PyO3 0.26 (#506)
1 parent 45734dd commit c1727fb

30 files changed

+372
-367
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- v0.26.0
33
- bump MSRV to 1.74, matching PyO3 ([#504](https://github.com/PyO3/rust-numpy/pull/504))
44
- extend supported `nalgebra` version to `0.34` ([#503](https://github.com/PyO3/rust-numpy/pull/503))
5+
- Bump PyO3 dependency to v0.26.0. ([#506](https://github.com/PyO3/rust-numpy/pull/506))
56

67
- v0.25.0,
78
- Bump PyO3 dependency to v0.25.0. ([#492](https://github.com/PyO3/rust-numpy/pull/492))

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "numpy"
3-
version = "0.25.0"
3+
version = "0.26.0"
44
authors = [
55
"The rust-numpy Project Developers",
66
"PyO3 Project and Contributors <https://github.com/PyO3>",
@@ -22,19 +22,19 @@ num-complex = ">= 0.2, < 0.5"
2222
num-integer = "0.1"
2323
num-traits = "0.2"
2424
ndarray = ">= 0.15, < 0.17"
25-
pyo3 = { version = "0.25.0", default-features = false, features = ["macros"] }
25+
pyo3 = { version = "0.26.0", default-features = false, features = ["macros"]}
2626
rustc-hash = "2.0"
2727

2828
[dev-dependencies]
29-
pyo3 = { version = "0.25", default-features = false, features = [
29+
pyo3 = { version = "0.26.0", default-features = false, features = [
3030
"auto-initialize",
3131
] }
3232
nalgebra = { version = ">=0.30, <0.35", default-features = false, features = [
3333
"std",
3434
] }
3535

3636
[build-dependencies]
37-
pyo3-build-config = { version = "0.25", features = ["resolve-config"] }
37+
pyo3-build-config = { version = "0.26", features = ["resolve-config"]}
3838

3939
[package.metadata.docs.rs]
4040
all-features = true

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ use numpy::{PyArray1, PyArrayMethods};
102102
use pyo3::{types::{IntoPyDict, PyAnyMethods}, PyResult, Python, ffi::c_str};
103103

104104
fn main() -> PyResult<()> {
105-
Python::with_gil(|py| {
105+
Python::attach(|py| {
106106
let np = py.import("numpy")?;
107107
let locals = [("np", np)].into_py_dict(py)?;
108108

109109
let pyarray = py
110110
.eval(c_str!("np.absolute(np.array([-1, -2, -3], dtype='int32'))"), Some(&locals), None)?
111-
.downcast_into::<PyArray1<i32>>()?;
111+
.cast_into::<PyArray1<i32>>()?;
112112

113113
let readonly = pyarray.readonly();
114114
let slice = readonly.as_slice()?;

benches/array.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use pyo3::{types::PyAnyMethods, Bound, IntoPyObjectExt, Python};
1010

1111
#[bench]
1212
fn extract_success(bencher: &mut Bencher) {
13-
Python::with_gil(|py| {
13+
Python::attach(|py| {
1414
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();
1515

1616
bencher.iter(|| {
@@ -23,7 +23,7 @@ fn extract_success(bencher: &mut Bencher) {
2323

2424
#[bench]
2525
fn extract_failure(bencher: &mut Bencher) {
26-
Python::with_gil(|py| {
26+
Python::attach(|py| {
2727
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();
2828

2929
bencher.iter(|| {
@@ -35,20 +35,20 @@ fn extract_failure(bencher: &mut Bencher) {
3535
}
3636

3737
#[bench]
38-
fn downcast_success(bencher: &mut Bencher) {
39-
Python::with_gil(|py| {
38+
fn cast_success(bencher: &mut Bencher) {
39+
Python::attach(|py| {
4040
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();
4141

42-
bencher.iter(|| black_box(&any).downcast::<PyArray2<f64>>().unwrap());
42+
bencher.iter(|| black_box(&any).cast::<PyArray2<f64>>().unwrap());
4343
});
4444
}
4545

4646
#[bench]
47-
fn downcast_failure(bencher: &mut Bencher) {
48-
Python::with_gil(|py| {
47+
fn cast_failure(bencher: &mut Bencher) {
48+
Python::attach(|py| {
4949
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();
5050

51-
bencher.iter(|| black_box(&any).downcast::<PyArray2<f64>>().unwrap_err());
51+
bencher.iter(|| black_box(&any).cast::<PyArray2<f64>>().unwrap_err());
5252
});
5353
}
5454

@@ -63,7 +63,7 @@ impl Iterator for Iter {
6363
}
6464

6565
fn from_iter(bencher: &mut Bencher, size: usize) {
66-
Python::with_gil(|py| {
66+
Python::attach(|py| {
6767
bencher.iter(|| {
6868
let iter = black_box(Iter(0..size));
6969

@@ -90,7 +90,7 @@ fn from_iter_large(bencher: &mut Bencher) {
9090
fn from_slice(bencher: &mut Bencher, size: usize) {
9191
let vec = (0..size).collect::<Vec<_>>();
9292

93-
Python::with_gil(|py| {
93+
Python::attach(|py| {
9494
bencher.iter(|| {
9595
let slice = black_box(&vec);
9696

@@ -115,13 +115,13 @@ fn from_slice_large(bencher: &mut Bencher) {
115115
}
116116

117117
fn from_object_slice(bencher: &mut Bencher, size: usize) {
118-
let vec = Python::with_gil(|py| {
118+
let vec = Python::attach(|py| {
119119
(0..size)
120120
.map(|val| val.into_py_any(py).unwrap())
121121
.collect::<Vec<_>>()
122122
});
123123

124-
Python::with_gil(|py| {
124+
Python::attach(|py| {
125125
bencher.iter(|| {
126126
let slice = black_box(&vec);
127127

@@ -148,7 +148,7 @@ fn from_object_slice_large(bencher: &mut Bencher) {
148148
fn from_vec2(bencher: &mut Bencher, size: usize) {
149149
let vec2 = vec![vec![0; size]; size];
150150

151-
Python::with_gil(|py| {
151+
Python::attach(|py| {
152152
bencher.iter(|| {
153153
let vec2 = black_box(&vec2);
154154

@@ -175,7 +175,7 @@ fn from_vec2_large(bencher: &mut Bencher) {
175175
fn from_vec3(bencher: &mut Bencher, size: usize) {
176176
let vec3 = vec![vec![vec![0; size]; size]; size];
177177

178-
Python::with_gil(|py| {
178+
Python::attach(|py| {
179179
bencher.iter(|| {
180180
let vec3 = black_box(&vec3);
181181

benches/borrow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use pyo3::Python;
88

99
#[bench]
1010
fn initial_shared_borrow(bencher: &mut Bencher) {
11-
Python::with_gil(|py| {
11+
Python::attach(|py| {
1212
let array = PyArray::<f64, _>::zeros(py, (6, 5, 4, 3, 2, 1), false);
1313

1414
bencher.iter(|| {
@@ -21,7 +21,7 @@ fn initial_shared_borrow(bencher: &mut Bencher) {
2121

2222
#[bench]
2323
fn additional_shared_borrow(bencher: &mut Bencher) {
24-
Python::with_gil(|py| {
24+
Python::attach(|py| {
2525
let array = PyArray::<f64, _>::zeros(py, (6, 5, 4, 3, 2, 1), false);
2626

2727
let _shared = (0..128).map(|_| array.readonly()).collect::<Vec<_>>();
@@ -36,7 +36,7 @@ fn additional_shared_borrow(bencher: &mut Bencher) {
3636

3737
#[bench]
3838
fn exclusive_borrow(bencher: &mut Bencher) {
39-
Python::with_gil(|py| {
39+
Python::attach(|py| {
4040
let array = PyArray::<f64, _>::zeros(py, (6, 5, 4, 3, 2, 1), false);
4141

4242
bencher.iter(|| {

examples/linalg/Cargo.lock

Lines changed: 13 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/linalg/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "rust_linalg"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
pyo3 = { version = "0.25.0", features = ["extension-module"] }
12+
pyo3 = { version = "0.26.0", features = ["extension-module"] }
1313
numpy = { path = "../.." }
1414
ndarray-linalg = { version = "0.14.1", features = ["openblas-system"] }
1515

examples/parallel/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "rust_parallel"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
pyo3 = { version = "0.25.0", features = ["extension-module", "multiple-pymethods"] }
12+
pyo3 = { version = "0.26.0", features = ["extension-module", "multiple-pymethods"] }
1313
numpy = { path = "../.." }
1414
ndarray = { version = "0.16", features = ["rayon", "blas"] }
1515
blas-src = { version = "0.8", features = ["openblas"] }

examples/simple/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "rust_ext"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
pyo3 = { version = "0.25.0", features = ["extension-module", "abi3-py37"] }
12+
pyo3 = { version = "0.26.0", features = ["extension-module", "abi3-py37"] }
1313
numpy = { path = "../.." }
1414

1515
[workspace]

examples/simple/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use numpy::{
99
use pyo3::{
1010
exceptions::PyIndexError,
1111
pymodule,
12-
types::{PyAnyMethods, PyDict, PyDictMethods, PyModule},
13-
Bound, FromPyObject, PyAny, PyObject, PyResult, Python,
12+
types::{PyDict, PyDictMethods, PyModule},
13+
Bound, FromPyObject, Py, PyAny, PyResult, Python,
1414
};
1515

1616
#[pymodule]
1717
fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
18-
// example using generic PyObject
19-
fn head(py: Python<'_>, x: ArrayViewD<'_, PyObject>) -> PyResult<PyObject> {
18+
// example using generic Py<PyAny>
19+
fn head(py: Python<'_>, x: ArrayViewD<'_, Py<PyAny>>) -> PyResult<Py<PyAny>> {
2020
x.get(0)
2121
.map(|obj| obj.clone_ref(py))
2222
.ok_or_else(|| PyIndexError::new_err("array index out of range"))
@@ -48,7 +48,7 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
4848
// wrapper of `head`
4949
#[pyfn(m)]
5050
#[pyo3(name = "head")]
51-
fn head_py<'py>(x: PyReadonlyArrayDyn<'py, PyObject>) -> PyResult<PyObject> {
51+
fn head_py<'py>(x: PyReadonlyArrayDyn<'py, Py<PyAny>>) -> PyResult<Py<PyAny>> {
5252
head(x.py(), x.as_array())
5353
}
5454

@@ -92,7 +92,7 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
9292
.get_item("x")
9393
.unwrap()
9494
.unwrap()
95-
.downcast_into::<PyArray1<f64>>()
95+
.cast_into::<PyArray1<f64>>()
9696
.unwrap();
9797

9898
x.readonly().as_array().sum()
@@ -141,7 +141,7 @@ fn rust_ext<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
141141
.into_any()),
142142
(SupportedArray::F64(x), SupportedArray::I64(y))
143143
| (SupportedArray::I64(y), SupportedArray::F64(x)) => {
144-
let y = y.cast::<f64>(false)?;
144+
let y = y.cast_array::<f64>(false)?;
145145

146146
Ok(
147147
generic_add(x.readonly().as_array(), y.readonly().as_array())

0 commit comments

Comments
 (0)