From 3f5789fd2abc854ca2febeb3b81f592079f99222 Mon Sep 17 00:00:00 2001 From: Philipp Rehner <69816385+prehner@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:18:11 +0100 Subject: [PATCH] Update to PyO3 and numpy v0.23 (#88) --- .github/workflows/documentation.yml | 2 +- .github/workflows/release.yml | 12 ++++++------ .github/workflows/wheels.yml | 10 +++++----- Cargo.toml | 4 ++-- src/derivative.rs | 20 +++++++++----------- src/dual.rs | 4 ++-- src/dual2.rs | 4 ++-- src/dual2_vec.rs | 4 ++-- src/dual3.rs | 4 ++-- src/dual_vec.rs | 4 ++-- src/hyperdual.rs | 4 ++-- src/hyperdual_vec.rs | 8 ++++---- src/hyperhyperdual.rs | 4 ++-- src/python_macro.rs | 8 ++++---- 14 files changed, 45 insertions(+), 47 deletions(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 01a8186..e966c8c 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -15,7 +15,7 @@ jobs: - name: Setup python uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: 3.11 - name: Install python dependencies run: | pip install sphinx sphinx-rtd-theme diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 27362e0..be8ab7c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,7 +29,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: 3.11 - name: Build Wheels uses: PyO3/maturin-action@v1 with: @@ -43,12 +43,12 @@ jobs: path: dist macos-x86_64: - runs-on: macos-12 + runs-on: macos-14 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: 3.11 architecture: x64 - name: Build wheels - x86_64 uses: PyO3/maturin-action@v1 @@ -66,7 +66,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: 3.11 architecture: arm64 - name: Build wheels - aarch64 uses: PyO3/maturin-action@v1 @@ -84,7 +84,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: 3.11 architecture: x64 - name: Build wheels uses: PyO3/maturin-action@v1 @@ -109,7 +109,7 @@ jobs: merge-multiple: true - uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: 3.11 - name: Publish to PyPi env: TWINE_USERNAME: __token__ diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 9c937fe..0859878 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: 3.11 - name: Build Wheels uses: PyO3/maturin-action@v1 with: @@ -24,12 +24,12 @@ jobs: name: wheel-linux-x86_64 path: dist macos-x86_64: - runs-on: macos-12 + runs-on: macos-14 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: 3.11 architecture: x64 - name: Build wheels - x86_64 uses: PyO3/maturin-action@v1 @@ -47,7 +47,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: 3.11 architecture: arm64 - name: Build wheels - aarch64 uses: PyO3/maturin-action@v1 @@ -65,7 +65,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: 3.11 architecture: x64 - name: Build wheels uses: PyO3/maturin-action@v1 diff --git a/Cargo.toml b/Cargo.toml index dd969d9..d53f9d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,13 +23,13 @@ name = "num_dual" num-traits = "0.2" nalgebra = "0.33" ndarray = { version = "0.16", optional = true } -numpy = { version = "0.22", optional = true } +numpy = { version = "0.23", optional = true } approx = "0.5" simba = "0.9" serde = { version = "1.0", features = ["derive"], optional = true } [dependencies.pyo3] -version = "0.22" +version = "0.23" optional = true features = ["multiple-pymethods", "extension-module", "abi3", "abi3-py37"] diff --git a/src/derivative.rs b/src/derivative.rs index 794f2d4..17417c2 100644 --- a/src/derivative.rs +++ b/src/derivative.rs @@ -167,7 +167,7 @@ where } } -impl<'a, T: DualNum, F, R: Dim, C: Dim> Mul for &'a Derivative +impl, F, R: Dim, C: Dim> Mul for &Derivative where DefaultAllocator: Allocator, { @@ -178,8 +178,8 @@ where } } -impl<'a, 'b, T: DualNum, F, R: Dim, C: Dim, R2: Dim, C2: Dim> Mul<&'b Derivative> - for &'a Derivative +impl, F, R: Dim, C: Dim, R2: Dim, C2: Dim> Mul<&Derivative> + for &Derivative where DefaultAllocator: Allocator + Allocator + Allocator, ShapeConstraint: SameNumberOfRows, @@ -202,7 +202,7 @@ where } } -impl<'a, T: DualNum, F, R: Dim, C: Dim> Div for &'a Derivative +impl, F, R: Dim, C: Dim> Div for &Derivative where DefaultAllocator: Allocator, { @@ -250,8 +250,7 @@ where } } -impl<'a, T: DualNum, F, R: Dim, C: Dim> Add<&'a Derivative> - for Derivative +impl, F, R: Dim, C: Dim> Add<&Derivative> for Derivative where DefaultAllocator: Allocator, { @@ -267,7 +266,7 @@ where } } -impl<'a, T: DualNum, F, R: Dim, C: Dim> Add for &'a Derivative +impl, F, R: Dim, C: Dim> Add for &Derivative where DefaultAllocator: Allocator, { @@ -299,8 +298,7 @@ where } } -impl<'a, T: DualNum, F, R: Dim, C: Dim> Sub<&'a Derivative> - for Derivative +impl, F, R: Dim, C: Dim> Sub<&Derivative> for Derivative where DefaultAllocator: Allocator, { @@ -316,7 +314,7 @@ where } } -impl<'a, T: DualNum, F, R: Dim, C: Dim> Sub for &'a Derivative +impl, F, R: Dim, C: Dim> Sub for &Derivative where DefaultAllocator: Allocator, { @@ -332,7 +330,7 @@ where } } -impl<'a, T: DualNum, F, R: Dim, C: Dim> Neg for &'a Derivative +impl, F, R: Dim, C: Dim> Neg for &Derivative where DefaultAllocator: Allocator, { diff --git a/src/dual.rs b/src/dual.rs index bc2ad24..2b6cb4b 100644 --- a/src/dual.rs +++ b/src/dual.rs @@ -94,7 +94,7 @@ impl, F: Float> Dual { } /* product rule */ -impl<'a, 'b, T: DualNum, F: Float> Mul<&'a Dual> for &'b Dual { +impl, F: Float> Mul<&Dual> for &Dual { type Output = Dual; #[inline] fn mul(self, other: &Dual) -> Self::Output { @@ -106,7 +106,7 @@ impl<'a, 'b, T: DualNum, F: Float> Mul<&'a Dual> for &'b Dual { } /* quotient rule */ -impl<'a, 'b, T: DualNum, F: Float> Div<&'a Dual> for &'b Dual { +impl, F: Float> Div<&Dual> for &Dual { type Output = Dual; #[inline] fn div(self, other: &Dual) -> Dual { diff --git a/src/dual2.rs b/src/dual2.rs index 3915b15..5defa11 100644 --- a/src/dual2.rs +++ b/src/dual2.rs @@ -129,7 +129,7 @@ impl, F: Float> Dual2 { } /* product rule */ -impl<'a, 'b, T: DualNum, F: Float> Mul<&'a Dual2> for &'b Dual2 { +impl, F: Float> Mul<&Dual2> for &Dual2 { type Output = Dual2; #[inline] fn mul(self, other: &Dual2) -> Dual2 { @@ -145,7 +145,7 @@ impl<'a, 'b, T: DualNum, F: Float> Mul<&'a Dual2> for &'b Dual2 { } /* quotient rule */ -impl<'a, 'b, T: DualNum, F: Float> Div<&'a Dual2> for &'b Dual2 { +impl, F: Float> Div<&Dual2> for &Dual2 { type Output = Dual2; #[inline] fn div(self, other: &Dual2) -> Dual2 { diff --git a/src/dual2_vec.rs b/src/dual2_vec.rs index 320f1f8..51f9dec 100644 --- a/src/dual2_vec.rs +++ b/src/dual2_vec.rs @@ -129,7 +129,7 @@ where } /* product rule */ -impl<'a, 'b, T: DualNum, F: Float, D: Dim> Mul<&'a Dual2Vec> for &'b Dual2Vec +impl, F: Float, D: Dim> Mul<&Dual2Vec> for &Dual2Vec where DefaultAllocator: Allocator + Allocator, { @@ -148,7 +148,7 @@ where } /* quotient rule */ -impl<'a, 'b, T: DualNum, F: Float, D: Dim> Div<&'a Dual2Vec> for &'b Dual2Vec +impl, F: Float, D: Dim> Div<&Dual2Vec> for &Dual2Vec where DefaultAllocator: Allocator + Allocator, { diff --git a/src/dual3.rs b/src/dual3.rs index 5aa2e87..5fa9cbd 100644 --- a/src/dual3.rs +++ b/src/dual3.rs @@ -103,7 +103,7 @@ impl, F: Float> Dual3 { } } -impl<'a, 'b, T: DualNum, F: Float> Mul<&'a Dual3> for &'b Dual3 { +impl, F: Float> Mul<&Dual3> for &Dual3 { type Output = Dual3; #[inline] fn mul(self, rhs: &Dual3) -> Dual3 { @@ -120,7 +120,7 @@ impl<'a, 'b, T: DualNum, F: Float> Mul<&'a Dual3> for &'b Dual3 { } } -impl<'a, 'b, T: DualNum, F: Float> Div<&'a Dual3> for &'b Dual3 { +impl, F: Float> Div<&Dual3> for &Dual3 { type Output = Dual3; #[inline] fn div(self, rhs: &Dual3) -> Dual3 { diff --git a/src/dual_vec.rs b/src/dual_vec.rs index 66d6168..b1cb6cf 100644 --- a/src/dual_vec.rs +++ b/src/dual_vec.rs @@ -182,7 +182,7 @@ where } /* product rule */ -impl<'a, 'b, T: DualNum, F: Float, D: Dim> Mul<&'a DualVec> for &'b DualVec +impl, F: Float, D: Dim> Mul<&DualVec> for &DualVec where DefaultAllocator: Allocator, { @@ -197,7 +197,7 @@ where } /* quotient rule */ -impl<'a, 'b, T: DualNum, F: Float, D: Dim> Div<&'a DualVec> for &'b DualVec +impl, F: Float, D: Dim> Div<&DualVec> for &DualVec where DefaultAllocator: Allocator, { diff --git a/src/hyperdual.rs b/src/hyperdual.rs index a89102c..3c6fa6f 100644 --- a/src/hyperdual.rs +++ b/src/hyperdual.rs @@ -114,7 +114,7 @@ impl, F: Float> HyperDual { } /* product rule */ -impl<'a, 'b, T: DualNum, F: Float> Mul<&'a HyperDual> for &'b HyperDual { +impl, F: Float> Mul<&HyperDual> for &HyperDual { type Output = HyperDual; #[inline] fn mul(self, other: &HyperDual) -> HyperDual { @@ -131,7 +131,7 @@ impl<'a, 'b, T: DualNum, F: Float> Mul<&'a HyperDual> for &'b HyperDual } /* quotient rule */ -impl<'a, 'b, T: DualNum, F: Float> Div<&'a HyperDual> for &'b HyperDual { +impl, F: Float> Div<&HyperDual> for &HyperDual { type Output = HyperDual; #[inline] fn div(self, other: &HyperDual) -> HyperDual { diff --git a/src/hyperdual_vec.rs b/src/hyperdual_vec.rs index c03d280..e3facfb 100644 --- a/src/hyperdual_vec.rs +++ b/src/hyperdual_vec.rs @@ -163,8 +163,8 @@ where } /* product rule */ -impl<'a, 'b, T: DualNum, F: Float, M: Dim, N: Dim> Mul<&'a HyperDualVec> - for &'b HyperDualVec +impl, F: Float, M: Dim, N: Dim> Mul<&HyperDualVec> + for &HyperDualVec where DefaultAllocator: Allocator + Allocator + Allocator, { @@ -184,8 +184,8 @@ where } /* quotient rule */ -impl<'a, 'b, T: DualNum, F: Float, M: Dim, N: Dim> Div<&'a HyperDualVec> - for &'b HyperDualVec +impl, F: Float, M: Dim, N: Dim> Div<&HyperDualVec> + for &HyperDualVec where DefaultAllocator: Allocator + Allocator + Allocator, { diff --git a/src/hyperhyperdual.rs b/src/hyperhyperdual.rs index 0a64b9c..0cc132d 100644 --- a/src/hyperhyperdual.rs +++ b/src/hyperhyperdual.rs @@ -251,7 +251,7 @@ impl, F: Float> HyperHyperDual { } } -impl<'a, 'b, T: DualNum, F: Float> Mul<&'a HyperHyperDual> for &'b HyperHyperDual { +impl, F: Float> Mul<&HyperHyperDual> for &HyperHyperDual { type Output = HyperHyperDual; #[inline] fn mul(self, rhs: &HyperHyperDual) -> HyperHyperDual { @@ -284,7 +284,7 @@ impl<'a, 'b, T: DualNum, F: Float> Mul<&'a HyperHyperDual> for &'b Hype } } -impl<'a, 'b, T: DualNum, F: Float> Div<&'a HyperHyperDual> for &'b HyperHyperDual { +impl, F: Float> Div<&HyperHyperDual> for &HyperHyperDual { type Output = HyperHyperDual; #[inline] fn div(self, rhs: &HyperHyperDual) -> HyperHyperDual { diff --git a/src/python_macro.rs b/src/python_macro.rs index 0e4a8e2..b635132 100644 --- a/src/python_macro.rs +++ b/src/python_macro.rs @@ -221,7 +221,7 @@ macro_rules! impl_dual_num { return Ok(Bound::new(rhs.py(), Self(self.0.clone() + r.0))?.into_any()); }; if let Ok(r) = rhs.extract::>() { - return Ok(PyArray::from_owned_object_array_bound( + return Ok(PyArray::from_owned_object_array( rhs.py(), r.as_array() .mapv(|ri| Py::new(rhs.py(), Self(self.0.clone() + ri)).unwrap()), @@ -267,7 +267,7 @@ macro_rules! impl_dual_num { return Ok(Bound::new(rhs.py(), Self(self.0.clone() - r.0))?.into_any()); }; if let Ok(r) = rhs.extract::>() { - return Ok(PyArray::from_owned_object_array_bound( + return Ok(PyArray::from_owned_object_array( rhs.py(), r.as_array() .mapv(|ri| Py::new(rhs.py(), Self(self.0.clone() - ri)).unwrap()), @@ -313,7 +313,7 @@ macro_rules! impl_dual_num { return Ok(Bound::new(rhs.py(), Self(self.0.clone() * r.0))?.into_any()); }; if let Ok(r) = rhs.extract::>() { - return Ok(PyArray::from_owned_object_array_bound( + return Ok(PyArray::from_owned_object_array( rhs.py(), r.as_array() .mapv(|ri| Py::new(rhs.py(), Self(self.0.clone() * ri)).unwrap()), @@ -359,7 +359,7 @@ macro_rules! impl_dual_num { return Ok(Bound::new(rhs.py(), Self(self.0.clone() / r.0))?.into_any()); }; if let Ok(r) = rhs.extract::>() { - return Ok(PyArray::from_owned_object_array_bound( + return Ok(PyArray::from_owned_object_array( rhs.py(), r.as_array() .mapv(|ri| Py::new(rhs.py(), Self(self.0.clone() / ri)).unwrap()),