From c79b42dc3429904646b0ed7f6d3fc5d159a83f54 Mon Sep 17 00:00:00 2001 From: Philipp Rehner <69816385+prehner@users.noreply.github.com> Date: Tue, 22 Oct 2024 21:32:29 +0200 Subject: [PATCH] Update to PyO3 0.22 (#80) --- .github/workflows/release.yml | 9 ++---- .github/workflows/wheels.yml | 9 ++---- CHANGELOG.md | 11 +++++++ Cargo.toml | 18 +++++++---- README.md | 4 +-- license-apache | 15 ---------- src/derivative.rs | 10 +++---- src/python/dual.rs | 2 +- src/python/dual2.rs | 2 +- src/python/dual3.rs | 2 +- src/python/hyperdual.rs | 2 +- src/python/hyperhyperdual.rs | 2 +- src/python_macro.rs | 56 +++++++++++++---------------------- 13 files changed, 60 insertions(+), 82 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eff4ceb..27362e0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -80,24 +80,21 @@ jobs: path: dist windows: runs-on: windows-latest - strategy: - matrix: - target: [x64, x86] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: 3.9 - architecture: ${{ matrix.target }} + architecture: x64 - name: Build wheels uses: PyO3/maturin-action@v1 with: - target: ${{ matrix.target }} + target: x64 args: --release --out dist - name: Upload wheels uses: actions/upload-artifact@v4 with: - name: wheel-${{ matrix.target }} + name: wheel-windows-x64 path: dist deploy-pypi: diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 433d02c..9c937fe 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -61,22 +61,19 @@ jobs: path: dist windows: runs-on: windows-latest - strategy: - matrix: - target: [x64, x86] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: 3.9 - architecture: ${{ matrix.target }} + architecture: x64 - name: Build wheels uses: PyO3/maturin-action@v1 with: - target: ${{ matrix.target }} + target: x64 args: --release --out dist - name: Upload wheels uses: actions/upload-artifact@v4 with: - name: wheel-${{ matrix.target }} + name: wheel-windows-x64 path: dist diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a861e3..922e65d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.10.0] - 2024-10-22 +### Packaging +- Updated `nalgebra` dependency to 0.33. [#75](https://github.com/itt-ustutt/num-dual/pull/75) +- Updated `simba` dependency to 0.9. [#75](https://github.com/itt-ustutt/num-dual/pull/75) +- Updated `pyo3` and `numpy` dependencies to 0.22. [#80](https://github.com/itt-ustutt/num-dual/pull/80) +- Updated `ndarray` dependency to 0.16. [#80](https://github.com/itt-ustutt/num-dual/pull/80) +- Increased minimum supported Rust version to 1.81. [#77](https://github.com/itt-ustutt/num-dual/pull/77) + +## Removed +- Due to limitations in the `numpy` dependency, Python wheels for 32-bit Windows are no longer supported. [#80](https://github.com/itt-ustutt/num-dual/pull/80) + ## [0.9.1] - 2024-04-15 ### Added - Added `serde` feature that enables serialization and deserialization of all scalar dual numbers. [#74](https://github.com/itt-ustutt/num-dual/pull/74) diff --git a/Cargo.toml b/Cargo.toml index da5b3d0..7b1eb1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,10 @@ [package] name = "num-dual" -version = "0.9.1" -authors = ["Gernot Bauer ", - "Philipp Rehner "] +version = "0.10.0" +authors = [ + "Gernot Bauer ", + "Philipp Rehner ", +] rust-version = "1.81" edition = "2021" readme = "README.md" @@ -20,13 +22,17 @@ name = "num_dual" [dependencies] num-traits = "0.2" nalgebra = "0.33" -pyo3 = { version = "0.21", optional = true, features = ["multiple-pymethods", "extension-module", "abi3", "abi3-py37"] } -ndarray = { version = "0.15", optional = true } -numpy = { version = "0.21", optional = true } +ndarray = { version = "0.16", optional = true } +numpy = { version = "0.22", optional = true } approx = "0.5" simba = "0.9" serde = { version = "1.0", features = ["derive"], optional = true } +[dependencies.pyo3] +version = "0.22" +optional = true +features = ["multiple-pymethods", "extension-module", "abi3", "abi3-py37"] + [profile.release] lto = true diff --git a/README.md b/README.md index 18db253..f8bb85e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![crate](https://img.shields.io/crates/v/num-dual.svg)](https://crates.io/crates/num-dual) [![documentation](https://docs.rs/num-dual/badge.svg)](https://docs.rs/num-dual) -[![minimum rustc 1.51](https://img.shields.io/badge/rustc-1.51+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) +[![minimum rustc 1.81](https://img.shields.io/badge/rustc-1.81+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) [![documentation](https://img.shields.io/badge/docs-github--pages-blue)](https://itt-ustutt.github.io/num-dual/) [![PyPI version](https://badge.fury.io/py/num_dual.svg)](https://badge.fury.io/py/num_dual) @@ -29,7 +29,7 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -num-dual = "0.7" +num-dual = "0.10" ``` ## Example diff --git a/license-apache b/license-apache index 7a57fbb..895657b 100644 --- a/license-apache +++ b/license-apache @@ -1,18 +1,3 @@ - Copyright (c) 2021-present num-dual and Contributors. https://github.com/itt-ustutt/num_dual - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ diff --git a/src/derivative.rs b/src/derivative.rs index d9513dd..794f2d4 100644 --- a/src/derivative.rs +++ b/src/derivative.rs @@ -385,9 +385,8 @@ where DefaultAllocator: Allocator, { fn mul_assign(&mut self, rhs: T) { - match &mut self.0 { - Some(s) => *s *= rhs, - None => (), + if let Some(s) = &mut self.0 { + *s *= rhs } } } @@ -397,9 +396,8 @@ where DefaultAllocator: Allocator, { fn div_assign(&mut self, rhs: T) { - match &mut self.0 { - Some(s) => *s /= rhs, - None => (), + if let Some(s) = &mut self.0 { + *s /= rhs } } } diff --git a/src/python/dual.rs b/src/python/dual.rs index 3003f3e..abfc38f 100644 --- a/src/python/dual.rs +++ b/src/python/dual.rs @@ -1,6 +1,6 @@ use crate::*; use nalgebra::{DVector, SVector}; -use numpy::{PyArray, PyReadonlyArrayDyn}; +use numpy::{PyArray, PyReadonlyArrayDyn, PyReadwriteArrayDyn}; use pyo3::exceptions::PyTypeError; use pyo3::prelude::*; diff --git a/src/python/dual2.rs b/src/python/dual2.rs index b7d026a..1f95301 100644 --- a/src/python/dual2.rs +++ b/src/python/dual2.rs @@ -1,7 +1,7 @@ use super::dual::PyDual64; use crate::*; use nalgebra::{DVector, SVector}; -use numpy::{PyArray, PyReadonlyArrayDyn}; +use numpy::{PyArray, PyReadonlyArrayDyn, PyReadwriteArrayDyn}; use pyo3::exceptions::PyTypeError; use pyo3::prelude::*; diff --git a/src/python/dual3.rs b/src/python/dual3.rs index 8411ada..59c8311 100644 --- a/src/python/dual3.rs +++ b/src/python/dual3.rs @@ -1,6 +1,6 @@ use super::dual::PyDual64; use crate::*; -use numpy::{PyArray, PyReadonlyArrayDyn}; +use numpy::{PyArray, PyReadonlyArrayDyn, PyReadwriteArrayDyn}; use pyo3::exceptions::PyTypeError; use pyo3::prelude::*; diff --git a/src/python/hyperdual.rs b/src/python/hyperdual.rs index 70a148a..fc7f76c 100644 --- a/src/python/hyperdual.rs +++ b/src/python/hyperdual.rs @@ -1,7 +1,7 @@ use super::dual::PyDual64; use crate::*; use nalgebra::{DVector, SVector}; -use numpy::{PyArray, PyReadonlyArrayDyn}; +use numpy::{PyArray, PyReadonlyArrayDyn, PyReadwriteArrayDyn}; use pyo3::exceptions::PyTypeError; use pyo3::prelude::*; diff --git a/src/python/hyperhyperdual.rs b/src/python/hyperhyperdual.rs index 8c0fe5e..d0f350a 100644 --- a/src/python/hyperhyperdual.rs +++ b/src/python/hyperhyperdual.rs @@ -1,5 +1,5 @@ use crate::*; -use numpy::{PyArray, PyReadonlyArrayDyn}; +use numpy::{PyArray, PyReadonlyArrayDyn, PyReadwriteArrayDyn}; use pyo3::exceptions::PyTypeError; use pyo3::prelude::*; diff --git a/src/python_macro.rs b/src/python_macro.rs index c7ca6c3..0e4a8e2 100644 --- a/src/python_macro.rs +++ b/src/python_macro.rs @@ -228,7 +228,7 @@ macro_rules! impl_dual_num { ) .into_any()); } - if let Ok(r) = rhs.extract::>() { + if let Ok(mut r) = rhs.extract::>() { // check data type of first element if r.as_array() .get(0) @@ -236,14 +236,10 @@ macro_rules! impl_dual_num { .bind(rhs.py()) .is_instance_of::() { - return Ok(PyArray::from_owned_object_array_bound( - rhs.py(), - r.as_array().mapv(|ri| { - Py::new(rhs.py(), Self(self.0.clone() + ri.extract::(rhs.py()).unwrap().0)) - .unwrap() - }), - ) - .into_any()); + r.as_array_mut().map_inplace(|ri| { + *ri = Py::new(rhs.py(), Self(self.0.clone() + ri.extract::(rhs.py()).unwrap().0)).unwrap().into_any() + }); + return Ok(r.as_any().clone()); } else { return Err(PyErr::new::(format!( "Operation with the provided object type is not implemented. Supported data types are 'float', 'int' and '{}'.", @@ -278,7 +274,7 @@ macro_rules! impl_dual_num { ) .into_any()); } - if let Ok(r) = rhs.extract::>() { + if let Ok(mut r) = rhs.extract::>() { // check data type of first element if r.as_array() .get(0) @@ -286,14 +282,10 @@ macro_rules! impl_dual_num { .bind(rhs.py()) .is_instance_of::() { - return Ok(PyArray::from_owned_object_array_bound( - rhs.py(), - r.as_array().mapv(|ri| { - Py::new(rhs.py(), Self(self.0.clone() - ri.extract::(rhs.py()).unwrap().0)) - .unwrap() - }), - ) - .into_any()); + r.as_array_mut().map_inplace(|ri| { + *ri = Py::new(rhs.py(), Self(self.0.clone() - ri.extract::(rhs.py()).unwrap().0)).unwrap().into_any() + }); + return Ok(r.as_any().clone()); } else { return Err(PyErr::new::(format!( "Operation with the provided object type is not implemented. Supported data types are 'float', 'int' and '{}'.", @@ -328,7 +320,7 @@ macro_rules! impl_dual_num { ) .into_any()); } - if let Ok(r) = rhs.extract::>() { + if let Ok(mut r) = rhs.extract::>() { // check data type of first element if r.as_array() .get(0) @@ -336,14 +328,10 @@ macro_rules! impl_dual_num { .bind(rhs.py()) .is_instance_of::() { - return Ok(PyArray::from_owned_object_array_bound( - rhs.py(), - r.as_array().mapv(|ri| { - Py::new(rhs.py(), Self(self.0.clone() * ri.extract::(rhs.py()).unwrap().0)) - .unwrap() - }), - ) - .into_any()); + r.as_array_mut().map_inplace(|ri| { + *ri = Py::new(rhs.py(), Self(self.0.clone() * ri.extract::(rhs.py()).unwrap().0)).unwrap().into_any() + }); + return Ok(r.as_any().clone()); } else { return Err(PyErr::new::(format!( "Operation with the provided object type is not implemented. Supported data types are 'float', 'int' and '{}'.", @@ -378,7 +366,7 @@ macro_rules! impl_dual_num { ) .into_any()); } - if let Ok(r) = rhs.extract::>() { + if let Ok(mut r) = rhs.extract::>() { // check data type of first element if r.as_array() .get(0) @@ -386,14 +374,10 @@ macro_rules! impl_dual_num { .bind(rhs.py()) .is_instance_of::() { - return Ok(PyArray::from_owned_object_array_bound( - rhs.py(), - r.as_array().mapv(|ri| { - Py::new(rhs.py(), Self(self.0.clone() / ri.extract::(rhs.py()).unwrap().0)) - .unwrap() - }), - ) - .into_any()); + r.as_array_mut().map_inplace(|ri| { + *ri = Py::new(rhs.py(), Self(self.0.clone() / ri.extract::(rhs.py()).unwrap().0)).unwrap().into_any() + }); + return Ok(r.as_any().clone()); } else { return Err(PyErr::new::(format!( "Operation with the provided object type is not implemented. Supported data types are 'float', 'int' and '{}'.",