Skip to content

Commit

Permalink
Update to PyO3 and numpy v0.23 (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
prehner authored Dec 5, 2024
1 parent b35a81f commit 3f5789f
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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__
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
20 changes: 9 additions & 11 deletions src/derivative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ where
}
}

impl<'a, T: DualNum<F>, F, R: Dim, C: Dim> Mul<T> for &'a Derivative<T, F, R, C>
impl<T: DualNum<F>, F, R: Dim, C: Dim> Mul<T> for &Derivative<T, F, R, C>
where
DefaultAllocator: Allocator<R, C>,
{
Expand All @@ -178,8 +178,8 @@ where
}
}

impl<'a, 'b, T: DualNum<F>, F, R: Dim, C: Dim, R2: Dim, C2: Dim> Mul<&'b Derivative<T, F, R2, C2>>
for &'a Derivative<T, F, R, C>
impl<T: DualNum<F>, F, R: Dim, C: Dim, R2: Dim, C2: Dim> Mul<&Derivative<T, F, R2, C2>>
for &Derivative<T, F, R, C>
where
DefaultAllocator: Allocator<R, C> + Allocator<R2, C2> + Allocator<R, C2>,
ShapeConstraint: SameNumberOfRows<C, R2>,
Expand All @@ -202,7 +202,7 @@ where
}
}

impl<'a, T: DualNum<F>, F, R: Dim, C: Dim> Div<T> for &'a Derivative<T, F, R, C>
impl<T: DualNum<F>, F, R: Dim, C: Dim> Div<T> for &Derivative<T, F, R, C>
where
DefaultAllocator: Allocator<R, C>,
{
Expand Down Expand Up @@ -250,8 +250,7 @@ where
}
}

impl<'a, T: DualNum<F>, F, R: Dim, C: Dim> Add<&'a Derivative<T, F, R, C>>
for Derivative<T, F, R, C>
impl<T: DualNum<F>, F, R: Dim, C: Dim> Add<&Derivative<T, F, R, C>> for Derivative<T, F, R, C>
where
DefaultAllocator: Allocator<R, C>,
{
Expand All @@ -267,7 +266,7 @@ where
}
}

impl<'a, T: DualNum<F>, F, R: Dim, C: Dim> Add for &'a Derivative<T, F, R, C>
impl<T: DualNum<F>, F, R: Dim, C: Dim> Add for &Derivative<T, F, R, C>
where
DefaultAllocator: Allocator<R, C>,
{
Expand Down Expand Up @@ -299,8 +298,7 @@ where
}
}

impl<'a, T: DualNum<F>, F, R: Dim, C: Dim> Sub<&'a Derivative<T, F, R, C>>
for Derivative<T, F, R, C>
impl<T: DualNum<F>, F, R: Dim, C: Dim> Sub<&Derivative<T, F, R, C>> for Derivative<T, F, R, C>
where
DefaultAllocator: Allocator<R, C>,
{
Expand All @@ -316,7 +314,7 @@ where
}
}

impl<'a, T: DualNum<F>, F, R: Dim, C: Dim> Sub for &'a Derivative<T, F, R, C>
impl<T: DualNum<F>, F, R: Dim, C: Dim> Sub for &Derivative<T, F, R, C>
where
DefaultAllocator: Allocator<R, C>,
{
Expand All @@ -332,7 +330,7 @@ where
}
}

impl<'a, T: DualNum<F>, F, R: Dim, C: Dim> Neg for &'a Derivative<T, F, R, C>
impl<T: DualNum<F>, F, R: Dim, C: Dim> Neg for &Derivative<T, F, R, C>
where
DefaultAllocator: Allocator<R, C>,
{
Expand Down
4 changes: 2 additions & 2 deletions src/dual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<T: DualNum<F>, F: Float> Dual<T, F> {
}

/* product rule */
impl<'a, 'b, T: DualNum<F>, F: Float> Mul<&'a Dual<T, F>> for &'b Dual<T, F> {
impl<T: DualNum<F>, F: Float> Mul<&Dual<T, F>> for &Dual<T, F> {
type Output = Dual<T, F>;
#[inline]
fn mul(self, other: &Dual<T, F>) -> Self::Output {
Expand All @@ -106,7 +106,7 @@ impl<'a, 'b, T: DualNum<F>, F: Float> Mul<&'a Dual<T, F>> for &'b Dual<T, F> {
}

/* quotient rule */
impl<'a, 'b, T: DualNum<F>, F: Float> Div<&'a Dual<T, F>> for &'b Dual<T, F> {
impl<T: DualNum<F>, F: Float> Div<&Dual<T, F>> for &Dual<T, F> {
type Output = Dual<T, F>;
#[inline]
fn div(self, other: &Dual<T, F>) -> Dual<T, F> {
Expand Down
4 changes: 2 additions & 2 deletions src/dual2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<T: DualNum<F>, F: Float> Dual2<T, F> {
}

/* product rule */
impl<'a, 'b, T: DualNum<F>, F: Float> Mul<&'a Dual2<T, F>> for &'b Dual2<T, F> {
impl<T: DualNum<F>, F: Float> Mul<&Dual2<T, F>> for &Dual2<T, F> {
type Output = Dual2<T, F>;
#[inline]
fn mul(self, other: &Dual2<T, F>) -> Dual2<T, F> {
Expand All @@ -145,7 +145,7 @@ impl<'a, 'b, T: DualNum<F>, F: Float> Mul<&'a Dual2<T, F>> for &'b Dual2<T, F> {
}

/* quotient rule */
impl<'a, 'b, T: DualNum<F>, F: Float> Div<&'a Dual2<T, F>> for &'b Dual2<T, F> {
impl<T: DualNum<F>, F: Float> Div<&Dual2<T, F>> for &Dual2<T, F> {
type Output = Dual2<T, F>;
#[inline]
fn div(self, other: &Dual2<T, F>) -> Dual2<T, F> {
Expand Down
4 changes: 2 additions & 2 deletions src/dual2_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ where
}

/* product rule */
impl<'a, 'b, T: DualNum<F>, F: Float, D: Dim> Mul<&'a Dual2Vec<T, F, D>> for &'b Dual2Vec<T, F, D>
impl<T: DualNum<F>, F: Float, D: Dim> Mul<&Dual2Vec<T, F, D>> for &Dual2Vec<T, F, D>
where
DefaultAllocator: Allocator<U1, D> + Allocator<D, D>,
{
Expand All @@ -148,7 +148,7 @@ where
}

/* quotient rule */
impl<'a, 'b, T: DualNum<F>, F: Float, D: Dim> Div<&'a Dual2Vec<T, F, D>> for &'b Dual2Vec<T, F, D>
impl<T: DualNum<F>, F: Float, D: Dim> Div<&Dual2Vec<T, F, D>> for &Dual2Vec<T, F, D>
where
DefaultAllocator: Allocator<U1, D> + Allocator<D, D>,
{
Expand Down
4 changes: 2 additions & 2 deletions src/dual3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<T: DualNum<F>, F: Float> Dual3<T, F> {
}
}

impl<'a, 'b, T: DualNum<F>, F: Float> Mul<&'a Dual3<T, F>> for &'b Dual3<T, F> {
impl<T: DualNum<F>, F: Float> Mul<&Dual3<T, F>> for &Dual3<T, F> {
type Output = Dual3<T, F>;
#[inline]
fn mul(self, rhs: &Dual3<T, F>) -> Dual3<T, F> {
Expand All @@ -120,7 +120,7 @@ impl<'a, 'b, T: DualNum<F>, F: Float> Mul<&'a Dual3<T, F>> for &'b Dual3<T, F> {
}
}

impl<'a, 'b, T: DualNum<F>, F: Float> Div<&'a Dual3<T, F>> for &'b Dual3<T, F> {
impl<T: DualNum<F>, F: Float> Div<&Dual3<T, F>> for &Dual3<T, F> {
type Output = Dual3<T, F>;
#[inline]
fn div(self, rhs: &Dual3<T, F>) -> Dual3<T, F> {
Expand Down
4 changes: 2 additions & 2 deletions src/dual_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ where
}

/* product rule */
impl<'a, 'b, T: DualNum<F>, F: Float, D: Dim> Mul<&'a DualVec<T, F, D>> for &'b DualVec<T, F, D>
impl<T: DualNum<F>, F: Float, D: Dim> Mul<&DualVec<T, F, D>> for &DualVec<T, F, D>
where
DefaultAllocator: Allocator<D>,
{
Expand All @@ -197,7 +197,7 @@ where
}

/* quotient rule */
impl<'a, 'b, T: DualNum<F>, F: Float, D: Dim> Div<&'a DualVec<T, F, D>> for &'b DualVec<T, F, D>
impl<T: DualNum<F>, F: Float, D: Dim> Div<&DualVec<T, F, D>> for &DualVec<T, F, D>
where
DefaultAllocator: Allocator<D>,
{
Expand Down
4 changes: 2 additions & 2 deletions src/hyperdual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<T: DualNum<F>, F: Float> HyperDual<T, F> {
}

/* product rule */
impl<'a, 'b, T: DualNum<F>, F: Float> Mul<&'a HyperDual<T, F>> for &'b HyperDual<T, F> {
impl<T: DualNum<F>, F: Float> Mul<&HyperDual<T, F>> for &HyperDual<T, F> {
type Output = HyperDual<T, F>;
#[inline]
fn mul(self, other: &HyperDual<T, F>) -> HyperDual<T, F> {
Expand All @@ -131,7 +131,7 @@ impl<'a, 'b, T: DualNum<F>, F: Float> Mul<&'a HyperDual<T, F>> for &'b HyperDual
}

/* quotient rule */
impl<'a, 'b, T: DualNum<F>, F: Float> Div<&'a HyperDual<T, F>> for &'b HyperDual<T, F> {
impl<T: DualNum<F>, F: Float> Div<&HyperDual<T, F>> for &HyperDual<T, F> {
type Output = HyperDual<T, F>;
#[inline]
fn div(self, other: &HyperDual<T, F>) -> HyperDual<T, F> {
Expand Down
8 changes: 4 additions & 4 deletions src/hyperdual_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ where
}

/* product rule */
impl<'a, 'b, T: DualNum<F>, F: Float, M: Dim, N: Dim> Mul<&'a HyperDualVec<T, F, M, N>>
for &'b HyperDualVec<T, F, M, N>
impl<T: DualNum<F>, F: Float, M: Dim, N: Dim> Mul<&HyperDualVec<T, F, M, N>>
for &HyperDualVec<T, F, M, N>
where
DefaultAllocator: Allocator<M> + Allocator<M, N> + Allocator<U1, N>,
{
Expand All @@ -184,8 +184,8 @@ where
}

/* quotient rule */
impl<'a, 'b, T: DualNum<F>, F: Float, M: Dim, N: Dim> Div<&'a HyperDualVec<T, F, M, N>>
for &'b HyperDualVec<T, F, M, N>
impl<T: DualNum<F>, F: Float, M: Dim, N: Dim> Div<&HyperDualVec<T, F, M, N>>
for &HyperDualVec<T, F, M, N>
where
DefaultAllocator: Allocator<M> + Allocator<M, N> + Allocator<U1, N>,
{
Expand Down
4 changes: 2 additions & 2 deletions src/hyperhyperdual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<T: DualNum<F>, F: Float> HyperHyperDual<T, F> {
}
}

impl<'a, 'b, T: DualNum<F>, F: Float> Mul<&'a HyperHyperDual<T, F>> for &'b HyperHyperDual<T, F> {
impl<T: DualNum<F>, F: Float> Mul<&HyperHyperDual<T, F>> for &HyperHyperDual<T, F> {
type Output = HyperHyperDual<T, F>;
#[inline]
fn mul(self, rhs: &HyperHyperDual<T, F>) -> HyperHyperDual<T, F> {
Expand Down Expand Up @@ -284,7 +284,7 @@ impl<'a, 'b, T: DualNum<F>, F: Float> Mul<&'a HyperHyperDual<T, F>> for &'b Hype
}
}

impl<'a, 'b, T: DualNum<F>, F: Float> Div<&'a HyperHyperDual<T, F>> for &'b HyperHyperDual<T, F> {
impl<T: DualNum<F>, F: Float> Div<&HyperHyperDual<T, F>> for &HyperHyperDual<T, F> {
type Output = HyperHyperDual<T, F>;
#[inline]
fn div(self, rhs: &HyperHyperDual<T, F>) -> HyperHyperDual<T, F> {
Expand Down
8 changes: 4 additions & 4 deletions src/python_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<PyReadonlyArrayDyn<f64>>() {
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()),
Expand Down Expand Up @@ -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::<PyReadonlyArrayDyn<f64>>() {
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()),
Expand Down Expand Up @@ -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::<PyReadonlyArrayDyn<f64>>() {
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()),
Expand Down Expand Up @@ -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::<PyReadonlyArrayDyn<f64>>() {
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()),
Expand Down

0 comments on commit 3f5789f

Please sign in to comment.