From 713d24f463e69d52f0c104909ee872021abd0d9a Mon Sep 17 00:00:00 2001 From: kngwyu Date: Mon, 2 Sep 2019 23:12:33 +0900 Subject: [PATCH 1/3] Update pyo3 to 0.8 --- Cargo.toml | 2 +- src/array.rs | 5 +++-- src/slice_box.rs | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9f0f4a344..0cd9d8196 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ libc = "0.2" num-complex = "0.2" num-traits = "0.2" ndarray = "0.12" -pyo3 = "0.7" +pyo3 = {git = "https://github.com/PyO3/pyo3"} [features] # In default setting, python version is automatically detected diff --git a/src/array.rs b/src/array.rs index 7c7817cf2..ba1664443 100644 --- a/src/array.rs +++ b/src/array.rs @@ -102,6 +102,7 @@ pub fn get_array_module(py: Python<'_>) -> PyResult<&PyModule> { pyobject_native_type_convert!( PyArray, *npyffi::PY_ARRAY_API.get_type_object(npyffi::ArrayType::PyArray_Type), + Some("numpy"), npyffi::PyArray_Check, T, D ); @@ -133,8 +134,8 @@ impl<'a, T: TypeNum, D: Dimension> FromPyObject<'a> for &'a PyArray { } } -impl IntoPyObject for PyArray { - fn into_object(self, _py: Python<'_>) -> PyObject { +impl IntoPy for PyArray { + fn into_py(self, _py: Python<'_>) -> PyObject { self.0 } } diff --git a/src/slice_box.rs b/src/slice_box.rs index d8f32cd87..6b5c3fb95 100644 --- a/src/slice_box.rs +++ b/src/slice_box.rs @@ -29,6 +29,7 @@ impl type_object::PyTypeInfo for SliceBox { type Type = (); type BaseType = PyAny; const NAME: &'static str = "SliceBox"; + const MODULE: Option<&'static str> = Some("_rust_numpy"); const DESCRIPTION: &'static str = "Memory store for PyArray using rust's Box<[T]>."; const FLAGS: usize = 0; const SIZE: usize = std::mem::size_of::(); From a11ca3bb415e8c5ef15f8922c6fcd3ae44fbf3cf Mon Sep 17 00:00:00 2001 From: kngwyu Date: Sat, 7 Sep 2019 14:23:16 +0900 Subject: [PATCH 2/3] Bump version to 0.7 --- CHANGELOG.md | 3 +++ Cargo.toml | 4 ++-- README.md | 8 ++++---- examples/linalg/Cargo.toml | 2 +- examples/linalg/setup.py | 2 +- examples/simple-extension/Cargo.toml | 2 +- examples/simple-extension/setup.py | 2 +- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fefaff8e..28d898480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +- v0.7.0 + - Update PyO3 to 0.8 + - v0.6.0 - Update PyO3 to 0.7 - Drop Python2 support diff --git a/Cargo.toml b/Cargo.toml index 0cd9d8196..27c8b5beb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "numpy" -version = "0.6.0" +version = "0.7.0" authors = ["Toshiki Teramura ", "Yuji Kanagawa "] description = "Rust binding of NumPy C-API" documentation = "https://rust-numpy.github.io/rust-numpy/numpy" @@ -15,7 +15,7 @@ libc = "0.2" num-complex = "0.2" num-traits = "0.2" ndarray = "0.12" -pyo3 = {git = "https://github.com/PyO3/pyo3"} +pyo3 = "0.8" [features] # In default setting, python version is automatically detected diff --git a/README.md b/README.md index 1835f435b..4f1871690 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,8 @@ using [setuptools-rust](https://github.com/PyO3/setuptools-rust). name = "numpy-test" [dependencies] -pyo3 = "0.7" -numpy = "0.6.0" +pyo3 = "0.8" +numpy = "0.7.0" ``` ```rust @@ -98,11 +98,11 @@ name = "rust_ext" crate-type = ["cdylib"] [dependencies] -numpy = "0.6.0" +numpy = "0.7.0" ndarray = "0.12" [dependencies.pyo3] -version = "0.7" +version = "0.8" features = ["extension-module"] ``` diff --git a/examples/linalg/Cargo.toml b/examples/linalg/Cargo.toml index 6dcdcd673..62a2b0e6e 100644 --- a/examples/linalg/Cargo.toml +++ b/examples/linalg/Cargo.toml @@ -14,5 +14,5 @@ ndarray = "0.12" ndarray-linalg = { version = "0.10", features = ["openblas"] } [dependencies.pyo3] -version = "0.7" +version = "0.8" features = ["extension-module"] diff --git a/examples/linalg/setup.py b/examples/linalg/setup.py index 52dfa0d10..6cf319441 100644 --- a/examples/linalg/setup.py +++ b/examples/linalg/setup.py @@ -2,7 +2,7 @@ from setuptools_rust import RustExtension -setup_requires = ['setuptools-rust>=0.6.0'] +setup_requires = ['setuptools-rust>=0.10.2'] install_requires = ['numpy'] test_requires = install_requires + ['pytest'] diff --git a/examples/simple-extension/Cargo.toml b/examples/simple-extension/Cargo.toml index ac196678e..07b1ae309 100644 --- a/examples/simple-extension/Cargo.toml +++ b/examples/simple-extension/Cargo.toml @@ -13,5 +13,5 @@ numpy = { path = "../.." } ndarray = "0.12" [dependencies.pyo3] -version = "0.7" +version = "0.8" features = ["extension-module"] diff --git a/examples/simple-extension/setup.py b/examples/simple-extension/setup.py index 569ac0c58..3f7d43c97 100644 --- a/examples/simple-extension/setup.py +++ b/examples/simple-extension/setup.py @@ -2,7 +2,7 @@ from setuptools_rust import RustExtension -setup_requires = ['setuptools-rust>=0.6.0'] +setup_requires = ['setuptools-rust>=0.10.2'] install_requires = ['numpy'] test_requires = install_requires + ['pytest'] From 745fc052ff19d9f6adf0303f691641f9a5832f6c Mon Sep 17 00:00:00 2001 From: kngwyu Date: Sat, 7 Sep 2019 14:37:17 +0900 Subject: [PATCH 3/3] Make it work with the latest ndarray --- Cargo.toml | 2 +- src/array.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 27c8b5beb..9fa72de85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ cfg-if = "0.1" libc = "0.2" num-complex = "0.2" num-traits = "0.2" -ndarray = "0.12" +ndarray = ">=0.12" pyo3 = "0.8" [features] diff --git a/src/array.rs b/src/array.rs index ba1664443..5e0ca4b6b 100644 --- a/src/array.rs +++ b/src/array.rs @@ -414,7 +414,7 @@ impl PyArray { /// # #[macro_use] extern crate ndarray; fn main() { /// use numpy::PyArray2; /// let gil = pyo3::Python::acquire_gil(); - /// let pyarray = PyArray2::zeros(gil.python(), [2, 2], false); + /// let pyarray: &PyArray2 = PyArray2::zeros(gil.python(), [2, 2], false); /// assert_eq!(pyarray.as_array(), array![[0, 0], [0, 0]]); /// # } /// ```