Skip to content

Commit

Permalink
Reorganize features in order to use crate without openblas (#34)
Browse files Browse the repository at this point in the history
* Reorganize features in order to use crate without openblas

* fix doctests

* add eigenvalue calculation and fix norm

* add tests for norm

* move ScalarOperand impl to ndarray feature

* remove too strict singularity criterion

* Separate python wheel (#35)

* Adds build_wheel directory that is used to build the python wheel

* Change workflows to use new crate for wheels

* change email adress in Cargo.toml and fix path for workflows

* update version and add changelog

* update README

Co-authored-by: Gernot Bauer <Bauer@itt.uni-stuttgart.de>
  • Loading branch information
prehner and g-bauer authored Dec 16, 2021
1 parent adf0ace commit 499a441
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 226 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
manylinux: auto
command: build
args: --release --out dist --no-sdist --cargo-extra-args="--features python"
args: --release --out dist --no-sdist -m build_wheel/Cargo.toml
- name: Install module
run: |
pip install num_dual --no-index --find-links dist --force-reinstall
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
with:
manylinux: auto
command: build
args: --release --out dist --no-sdist --cargo-extra-args="--features python"
args: --release --out dist --no-sdist -m build_wheel/Cargo.toml
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
Expand All @@ -60,11 +60,11 @@ jobs:
uses: messense/maturin-action@v1
with:
target: x86_64
args: --release --out dist --no-sdist --cargo-extra-args="--features python"
args: --release --out dist --no-sdist -m build_wheel/Cargo.toml
- name: Build wheels - universal2
uses: messense/maturin-action@v1
with:
args: --release --universal2 --out dist --no-sdist --cargo-extra-args="--features python"
args: --release --universal2 --out dist --no-sdist -m build_wheel/Cargo.toml
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
uses: messense/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --no-sdist --cargo-extra-args="--features python"
args: --release --out dist --no-sdist -m build_wheel/Cargo.toml
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
with:
manylinux: auto
command: build
args: --release --out dist --no-sdist --cargo-extra-args="--features python"
args: --release --out dist --no-sdist -m build_wheel/Cargo.toml
- name: Install module
run: |
pip install num_dual --no-index --find-links dist --force-reinstall
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose --features="linalg openblas-static"
run: cargo test --verbose --features="openblas-static"
10 changes: 5 additions & 5 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
manylinux: auto
command: build
args: --release --out dist --no-sdist --cargo-extra-args="--features python"
args: --release --out dist --no-sdist -m build_wheel/Cargo.toml
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
Expand All @@ -41,11 +41,11 @@ jobs:
uses: messense/maturin-action@main
with:
target: x86_64
args: --release --out dist --no-sdist --cargo-extra-args="--features python"
args: --release --out dist --no-sdist -m build_wheel/Cargo.toml
- name: Build wheels - universal2
uses: messense/maturin-action@main
with:
args: --release --universal2 --out dist --no-sdist --cargo-extra-args="--features python"
args: --release --universal2 --out dist --no-sdist -m build_wheel/Cargo.toml
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
Expand All @@ -72,9 +72,9 @@ jobs:
uses: messense/maturin-action@main
with:
target: ${{ matrix.target }}
args: --release --out dist --no-sdist --cargo-extra-args="--features python"
args: --release --out dist --no-sdist -m build_wheel/Cargo.toml
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
path: dist
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.4.0] - 2021-12-16
### Added
- Implementations for LU decomposition and eigendecomposition of symmetric matrices that do not depend on external libraries (BLAS, LAPACK). [#34](https://github.com/itt-ustutt/num-dual/pull/34)

### Packaging
- Updated `pyo3` dependency to 0.15.
27 changes: 9 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "num-dual"
version = "0.3.0"
version = "0.4.0"
authors = ["Gernot Bauer <bauer@itt.uni-stuttgart.de>",
"Philipp Rehner <rehner@itt.uni-stuttgart.de>"]
"Philipp Rehner <prehner@ethz.ch>"]
edition = "2018"
readme = "README.md"
license = "MIT OR Apache-2.0"
Expand All @@ -13,30 +13,21 @@ keywords = ["mathematics", "numerics", "differentiation"]
categories = ["data-structures", "science", "mathematics"]
exclude = ["/.github/*", "*.ipynb", "./docs/*"]

[lib]
name = "num_dual"
crate-type = ["cdylib", "lib"]

[dependencies]
num-traits = "0.2"
ndarray = { version = "0.15", optional = true }
ndarray-linalg = { version = "0.14", optional = true }

[dependencies.pyo3]
version = "0.14"
optional = true
features = ["extension-module", "abi3", "abi3-py36", "multiple-pymethods"]
pyo3 = { version = "0.15", optional = true }

[features]
default = []
python = ["pyo3"]
linalg = ["ndarray", "ndarray-linalg"]
openblas-system = ["ndarray-linalg/openblas-system"]
openblas-static = ["ndarray-linalg/openblas-static"]
netlib-system = ["ndarray-linalg/netlib-system"]
netlib-static = ["ndarray-linalg/netlib-static"]
intel-mkl-static = ["ndarray-linalg/intel-mkl-static"]
intel-mkl-system = ["ndarray-linalg/intel-mkl-system"]
openblas-system = ["ndarray", "ndarray-linalg/openblas-system"]
openblas-static = ["ndarray", "ndarray-linalg/openblas-static"]
netlib-system = ["ndarray", "ndarray-linalg/netlib-system"]
netlib-static = ["ndarray", "ndarray-linalg/netlib-static"]
intel-mkl-static = ["ndarray", "ndarray-linalg/intel-mkl-static"]
intel-mkl-system = ["ndarray", "ndarray-linalg/intel-mkl-system"]

[dev-dependencies]
criterion = "0.3"
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ Including bindings for python.

### Python

You can install the python package either from pypi:
The python package can be installed directly from PyPI:
```
pip install num_dual
```
or from source (you need a rust compiler for that):
```
pip install git+https://github.com/itt-ustutt/num-dual
```
[//]: # "or from source (you need a rust compiler for that):"
[//]: # "```"
[//]: # "pip install git+https://github.com/itt-ustutt/num-dual"
[//]: # "```"

### Rust

Add this to your `Cargo.toml`:

```toml
[dependencies]
num-dual = "0.3"
num-dual = "0.4"
```

## Example
Expand Down
22 changes: 22 additions & 0 deletions build_wheel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "num_dual"
version = "0.4.0"
authors = ["Gernot Bauer <bauer@itt.uni-stuttgart.de>",
"Philipp Rehner <prehner@ethz.ch>"]
edition = "2018"
readme = "../README.md"
license = "MIT OR Apache-2.0"
description = "Generalized (hyper) dual numbers for the calculation of exact (partial) derivatives"
homepage = "https://github.com/itt-ustutt/num-dual"
repository = "https://github.com/itt-ustutt/num-dual"
keywords = ["mathematics", "numerics", "differentiation"]
categories = ["data-structures", "science", "mathematics"]
exclude = ["/.github/*", "*.ipynb", "./docs/*"]

[lib]
name = "num_dual"
crate-type = ["cdylib"]

[dependencies]
num-dual = { path = "..", features = ["python"]}
pyo3 = { version = "0.15", features = ["extension-module", "abi3", "abi3-py36", "multiple-pymethods"] }
8 changes: 8 additions & 0 deletions build_wheel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use num_dual as num_dual_rs;
use pyo3::prelude::*;

/// Implementation of SI numbers.
#[pymodule]
pub fn num_dual(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
num_dual_rs::python::num_dual(_py, m)
}
6 changes: 2 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ pub use hyperdual::{
};
pub use static_mat::{StaticMat, StaticVec};

#[cfg(feature = "linalg")]
mod linalg;
#[cfg(feature = "linalg")]
pub use linalg::*;
#[cfg(feature = "ndarray")]
pub mod linalg;

#[cfg(feature = "python")]
pub mod python;
Expand Down
18 changes: 7 additions & 11 deletions src/linalg/linalg_ndarray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ use ndarray_linalg::convert::replicate;
use ndarray_linalg::error::Result;
use ndarray_linalg::*;

impl<T: Clone + 'static, F: Clone + 'static> ScalarOperand for Dual<T, F> {}
impl<T: Clone + 'static, F: Clone + 'static> ScalarOperand for HyperDual<T, F> {}
impl<T: Clone + 'static, F: Clone + 'static> ScalarOperand for Dual3<T, F> {}

type LU64 = LUFactorized<OwnedRepr<f64>>;

pub trait FactorizeIntoDual {
Expand Down Expand Up @@ -58,7 +54,7 @@ impl SolveDual<f64> for Array2<f64> {
/// is the argument, and `x` is the successful result.
/// ```
/// # use approx::assert_abs_diff_eq;
/// # use num_dual::SolveDual;
/// # use num_dual::linalg::SolveDual;
/// # use ndarray::{arr1, arr2};
/// let a = arr2(&[[1.0, 3.0],
/// [5.0, 7.0]]);
Expand Down Expand Up @@ -89,7 +85,7 @@ where
/// ```
/// # use approx::assert_abs_diff_eq;
/// # use num_dual::Dual64;
/// # use num_dual::SolveDual;
/// # use num_dual::linalg::SolveDual;
/// # use ndarray::{arr1, arr2};
/// let a = arr2(&[[Dual64::new_scalar(1.0, 2.0), Dual64::new_scalar(3.0, 4.0)],
/// [Dual64::new_scalar(5.0, 6.0), Dual64::new_scalar(7.0, 8.0)]]);
Expand Down Expand Up @@ -128,7 +124,7 @@ where
/// ```
/// # use approx::assert_abs_diff_eq;
/// # use num_dual::{DualVec64, StaticVec};
/// # use num_dual::SolveDual;
/// # use num_dual::linalg::SolveDual;
/// # use ndarray::{arr1, arr2};
/// let a = arr2(&[[DualVec64::new(1.0, StaticVec::new_vec([2.0, 1.0])), DualVec64::new(3.0, StaticVec::new_vec([4.0, 1.0]))],
/// [DualVec64::new(5.0, StaticVec::new_vec([6.0, 1.0])), DualVec64::new(7.0, StaticVec::new_vec([8.0, 1.0]))]]);
Expand Down Expand Up @@ -176,7 +172,7 @@ where
/// ```
/// # use approx::assert_abs_diff_eq;
/// # use num_dual::HyperDual64;
/// # use num_dual::SolveDual;
/// # use num_dual::linalg::SolveDual;
/// # use ndarray::{arr1, arr2};
/// let a = arr2(&[[HyperDual64::new_scalar(1.0, 2.0, 3.0, 4.0), HyperDual64::new_scalar(2.0, 3.0, 4.0, 5.0)],
/// [HyperDual64::new_scalar(3.0, 4.0, 5.0, 6.0), HyperDual64::new_scalar(4.0, 5.0, 6.0, 7.0)]]);
Expand Down Expand Up @@ -225,7 +221,7 @@ where
/// ```
/// # use approx::assert_abs_diff_eq;
/// # use num_dual::Dual3_64;
/// # use num_dual::SolveDual;
/// # use num_dual::linalg::SolveDual;
/// # use ndarray::{arr1, arr2};
/// let a = arr2(&[[Dual3_64::new(1.0, 2.0, 3.0, 4.0), Dual3_64::new(2.0, 3.0, 4.0, 5.0)],
/// [Dual3_64::new(3.0, 4.0, 5.0, 6.0), Dual3_64::new(4.0, 5.0, 6.0, 7.0)]]);
Expand Down Expand Up @@ -276,7 +272,7 @@ impl EighDual<Dual64> for Array2<Dual64> {
/// ```
/// # use approx::assert_abs_diff_eq;
/// # use num_dual::Dual64;
/// # use num_dual::EighDual;
/// # use num_dual::linalg::EighDual;
/// # use ndarray::{arr1, arr2};
/// # use ndarray_linalg::UPLO;
/// let a = arr2(&[[Dual64::new_scalar(2.0, 1.0), Dual64::new_scalar(2.0, 2.0)],
Expand Down Expand Up @@ -318,7 +314,7 @@ impl EighDual<DualVec64<2>> for Array2<DualVec64<2>> {
/// ```
/// # use approx::assert_abs_diff_eq;
/// # use num_dual::{DualVec64, StaticVec};
/// # use num_dual::EighDual;
/// # use num_dual::linalg::EighDual;
/// # use ndarray::{arr1, arr2};
/// # use ndarray_linalg::UPLO;
/// let a = arr2(&[[DualVec64::new(2.0, StaticVec::new_vec([1.0, 1.0])), DualVec64::new(2.0, StaticVec::new_vec([2.0, 1.0]))],
Expand Down
Loading

0 comments on commit 499a441

Please sign in to comment.