Skip to content

Commit

Permalink
Update to PyO3 0.22 (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
prehner authored Oct 22, 2024
1 parent e0a4630 commit c79b42d
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 82 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[package]
name = "num-dual"
version = "0.9.1"
authors = ["Gernot Bauer <[email protected]>",
"Philipp Rehner <[email protected]>"]
version = "0.10.0"
authors = [
"Gernot Bauer <[email protected]>",
"Philipp Rehner <[email protected]>",
]
rust-version = "1.81"
edition = "2021"
readme = "README.md"
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -29,7 +29,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
num-dual = "0.7"
num-dual = "0.10"
```

## Example
Expand Down
15 changes: 0 additions & 15 deletions license-apache
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
10 changes: 4 additions & 6 deletions src/derivative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,8 @@ where
DefaultAllocator: Allocator<R, C>,
{
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
}
}
}
Expand All @@ -397,9 +396,8 @@ where
DefaultAllocator: Allocator<R, C>,
{
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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/python/dual.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down
2 changes: 1 addition & 1 deletion src/python/dual2.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down
2 changes: 1 addition & 1 deletion src/python/dual3.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down
2 changes: 1 addition & 1 deletion src/python/hyperdual.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down
2 changes: 1 addition & 1 deletion src/python/hyperhyperdual.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::*;
use numpy::{PyArray, PyReadonlyArrayDyn};
use numpy::{PyArray, PyReadonlyArrayDyn, PyReadwriteArrayDyn};
use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;

Expand Down
56 changes: 20 additions & 36 deletions src/python_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,18 @@ macro_rules! impl_dual_num {
)
.into_any());
}
if let Ok(r) = rhs.extract::<PyReadonlyArrayDyn<PyObject>>() {
if let Ok(mut r) = rhs.extract::<PyReadwriteArrayDyn<PyObject>>() {
// check data type of first element
if r.as_array()
.get(0)
.unwrap()
.bind(rhs.py())
.is_instance_of::<Self>()
{
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::<Self>(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::<Self>(rhs.py()).unwrap().0)).unwrap().into_any()
});
return Ok(r.as_any().clone());
} else {
return Err(PyErr::new::<PyTypeError, _>(format!(
"Operation with the provided object type is not implemented. Supported data types are 'float', 'int' and '{}'.",
Expand Down Expand Up @@ -278,22 +274,18 @@ macro_rules! impl_dual_num {
)
.into_any());
}
if let Ok(r) = rhs.extract::<PyReadonlyArrayDyn<PyObject>>() {
if let Ok(mut r) = rhs.extract::<PyReadwriteArrayDyn<PyObject>>() {
// check data type of first element
if r.as_array()
.get(0)
.unwrap()
.bind(rhs.py())
.is_instance_of::<Self>()
{
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::<Self>(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::<Self>(rhs.py()).unwrap().0)).unwrap().into_any()
});
return Ok(r.as_any().clone());
} else {
return Err(PyErr::new::<PyTypeError, _>(format!(
"Operation with the provided object type is not implemented. Supported data types are 'float', 'int' and '{}'.",
Expand Down Expand Up @@ -328,22 +320,18 @@ macro_rules! impl_dual_num {
)
.into_any());
}
if let Ok(r) = rhs.extract::<PyReadonlyArrayDyn<PyObject>>() {
if let Ok(mut r) = rhs.extract::<PyReadwriteArrayDyn<PyObject>>() {
// check data type of first element
if r.as_array()
.get(0)
.unwrap()
.bind(rhs.py())
.is_instance_of::<Self>()
{
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::<Self>(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::<Self>(rhs.py()).unwrap().0)).unwrap().into_any()
});
return Ok(r.as_any().clone());
} else {
return Err(PyErr::new::<PyTypeError, _>(format!(
"Operation with the provided object type is not implemented. Supported data types are 'float', 'int' and '{}'.",
Expand Down Expand Up @@ -378,22 +366,18 @@ macro_rules! impl_dual_num {
)
.into_any());
}
if let Ok(r) = rhs.extract::<PyReadonlyArrayDyn<PyObject>>() {
if let Ok(mut r) = rhs.extract::<PyReadwriteArrayDyn<PyObject>>() {
// check data type of first element
if r.as_array()
.get(0)
.unwrap()
.bind(rhs.py())
.is_instance_of::<Self>()
{
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::<Self>(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::<Self>(rhs.py()).unwrap().0)).unwrap().into_any()
});
return Ok(r.as_any().clone());
} else {
return Err(PyErr::new::<PyTypeError, _>(format!(
"Operation with the provided object type is not implemented. Supported data types are 'float', 'int' and '{}'.",
Expand Down

0 comments on commit c79b42d

Please sign in to comment.