Skip to content

Commit

Permalink
Implement new backend features (#69)
Browse files Browse the repository at this point in the history
* Re-export ndarray_linalg to linfa

* Move to new backend infrastructure

* Readd tests for linfa-logistic

* Run on intelMKL image

* Use intelMKL image for tarpauling

* Improve wording

* Remove beta building

* Remove all features from clippy and re-add beta
  • Loading branch information
bytesnake authored Dec 10, 2020
1 parent 4f0b63b commit 7296c9e
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 46 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/codequality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --all-features -- -D warnings
args: --all-targets -- -D warnings

coverage:
name: coverage
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
container:
image: rustmath/mkl-rust:1.43.0
options: --security-opt seccomp=unconfined

steps:
- name: Checkout sources
Expand Down Expand Up @@ -72,7 +75,7 @@ jobs:

- name: Generate code coverage
run: |
cargo +nightly tarpaulin --verbose --all-features --timeout 120 --out Xml
cargo +nightly tarpaulin --verbose --features intel-mkl-system --timeout 120 --out Xml --all --release
- name: Upload to codecov.io
uses: codecov/codecov-action@v1
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ name: Run Tests
jobs:
testing:
name: testing
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
container:
image: rustmath/mkl-rust:1.43.0
options: --security-opt seccomp=unconfined
strategy:
matrix:
toolchain:
Expand All @@ -15,9 +18,6 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install ubuntu packages
run: sudo apt-get install libssl-dev gfortran libopenblas-dev liblapack-dev liblapacke-dev libatlas-base-dev

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
Expand All @@ -29,6 +29,4 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --all --release
env:
RUSTFLAGS: -C link-arg=-llapacke -C link-arg=-lcblas
args: --all --release --features intel-mkl-system
32 changes: 31 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,40 @@ categories = ["algorithms", "mathematics", "science"]

exclude = [".github/"]

[features]
default = []

netlib-static = ["ndarray-linalg", "netlib-src/static"]
netlib-system = ["ndarray-linalg", "netlib-src/system"]

openblas-static = ["ndarray-linalg", "openblas-src/static"]
openblas-system = ["ndarray-linalg", "openblas-src/system"]

intel-mkl-static = ["ndarray-linalg", "intel-mkl-src/mkl-static-lp64-seq", "intel-mkl-src/download"]
intel-mkl-system = ["ndarray-linalg", "intel-mkl-src/mkl-dynamic-lp64-seq"]

[dependencies]
num-traits = "0.2"
rand = "0.7"
ndarray = { version = "0.13", default-features = false }
ndarray = { version = "0.13", default-features = false, features = ["blas"] }
ndarray-linalg = { version = "0.12", optional = true }

[dependencies.intel-mkl-src]
version = "0.6.0"
default-features = false
optional = true

[dependencies.netlib-src]
version = "0.8.0"
optional = true
features = ["cblas"]
default-features = false

[dependencies.openblas-src]
version = "0.9.0"
optional = true
default-features = false
features = ["cblas"]

[dev-dependencies]
ndarray-rand = "0.12"
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ We believe that only a significant community effort can nurture, build, and sust

If this strikes a chord with you, please take a look at the [roadmap](https://github.com/rust-ml/linfa/issues/7) and get involved!

## BLAS/Lapack backend

At the moment you can choose between the following BLAS/LAPACK backends: `openblas`, `netblas` or `intel-mkl`

|Backend | Linux | Windows | macOS |
|:--------|:-----:|:-------:|:-----:|
|OpenBLAS |✔️ |- |- |
|Netlib |✔️ |- |- |
|Intel MKL|✔️ |✔️ |✔️ |

For example if you want to use the system IntelMKL library for the PCA example, then pass the corresponding feature:
```
cd linfa-reduction && cargo run --release --example pca --features linfa/intel-mkl-system
```
This selects the `intel-mkl` system library as BLAS/LAPACK backend. On the other hand if you want to compile the library and link it with the generated artifacts, pass `intel-mkl-static`.

# License
Dual-licensed to be compatible with the Rust project.

Expand Down
1 change: 0 additions & 1 deletion linfa-clustering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ linfa = { version = "0.2.1", path = ".." }
partitions = "0.2.4"

[dev-dependencies]
openblas-src = { version = "0.9", default-features = false, features = ["system"] }
ndarray-npy = { version = "0.5", default-features = false }
criterion = "0.3"
serde_json = "1"
Expand Down
3 changes: 0 additions & 3 deletions linfa-clustering/src/gaussian_mixture/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use serde_crate::{Deserialize, Serialize};
/// Let's do a walkthrough of a training-predict-save example.
///
/// ```rust, ignore
/// extern crate openblas_src;
/// use linfa::Dataset;
/// use linfa::traits::{Fit, Predict};
/// use linfa_clustering::{GmmHyperParams, GaussianMixtureModel, generate_blobs};
Expand Down Expand Up @@ -478,8 +477,6 @@ impl<F: Float + Lapack + Scalar, D: Data<Elem = F>, T: Targets>

#[cfg(test)]
mod tests {
extern crate openblas_src;

use super::*;
use crate::generate_blobs;
use approx::assert_abs_diff_eq;
Expand Down
2 changes: 0 additions & 2 deletions linfa-clustering/src/k_means/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,6 @@ fn get_random_centroids<F: Float, D: Data<Elem = F>>(

#[cfg(test)]
mod tests {
extern crate openblas_src;

use super::*;
use approx::assert_abs_diff_eq;
use ndarray::{array, stack, Array, Array1, Array2, Axis};
Expand Down
4 changes: 2 additions & 2 deletions linfa-ica/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ categories = ["algorithms", "mathematics", "science"]
[features]
default = []
serde = ["serde_crate", "ndarray/serde"]

[dependencies.serde_crate]
package = "serde"
optional = true
Expand All @@ -24,15 +25,14 @@ features = ["std", "derive"]

[dependencies]
ndarray = { version = "0.13", default-features = false }
ndarray-linalg = "0.12"
ndarray-rand = "0.11"
ndarray-stats = "0.3"
ndarray-linalg = "0.12"
num-traits = "0.2"
rand_isaac = "0.2.0"

linfa = { version = "0.2.1", path = ".." }

[dev-dependencies]
openblas-src = { version = "0.9", default-features = false, features = ["system"] }
ndarray-npy = { version = "0.5", default-features = false }
paste = "1.0"
2 changes: 0 additions & 2 deletions linfa-ica/examples/fast_ica.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate openblas_src;

use linfa::{
dataset::Dataset,
traits::{Fit, Predict},
Expand Down
2 changes: 0 additions & 2 deletions linfa-ica/src/fast_ica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ impl GFunc {

#[cfg(test)]
mod tests {
extern crate openblas_src;

use super::*;
use linfa::traits::{Fit, Predict};

Expand Down
1 change: 0 additions & 1 deletion linfa-linear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ serde = { version = "1.0", default-features = false, features = ["derive"] }
linfa = { version = "0.2.1", path = ".." }

[dev-dependencies]
openblas-src = { version = "0.9", default-features = false, features = ["system"] }
csv = "1.1"
ndarray-csv = "0.4"
approx = "0.3.2"
Expand Down
2 changes: 0 additions & 2 deletions linfa-linear/examples/diabetes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate openblas_src;

use std::error::Error;
use std::fs::File;

Expand Down
2 changes: 0 additions & 2 deletions linfa-linear/examples/glm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate openblas_src;

use csv::ReaderBuilder;
use flate2::read::GzDecoder;
use linfa_linear::TweedieRegressor;
Expand Down
2 changes: 0 additions & 2 deletions linfa-linear/src/ols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ impl<F: Float, D: Data<Elem = F>> Predict<&ArrayBase<D, Ix2>, Array1<F>>

#[cfg(test)]
mod tests {
extern crate openblas_src;

use super::*;
use approx::abs_diff_eq;
use ndarray::array;
Expand Down
5 changes: 3 additions & 2 deletions linfa-logistic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ keywords = ["machine-learning", "linfa", "ai", "ml", "linear"]
categories = ["algorithms", "mathematics", "science"]

[dependencies]
ndarray = {version = "0.13", features = ["blas", "approx"]}
ndarray = {version = "0.13", features = ["approx", "blas"]}
ndarray-linalg = "0.12"
num-traits = "0.2"
argmin = {version="0.3.1", features=["ndarrayl"]}
serde = "1.0"

linfa = { version = "0.2.1", path = ".." }

[dev-dependencies]
openblas-src = { version = "0.9", default-features = false, features = ["system"] }
approx = "0.3.2"
2 changes: 1 addition & 1 deletion linfa-logistic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl<'a, F: Float, A: Data<Elem = F>> ArgminOp for LogisticRegressionProblem<'a,

#[cfg(test)]
mod test {
extern crate openblas_src;
extern crate linfa;

use super::*;
use approx::AbsDiffEq;
Expand Down
6 changes: 3 additions & 3 deletions linfa-reduction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ categories = ["algorithms", "mathematics", "science"]

[features]
default = []

serde = ["serde_crate", "ndarray/serde"]

[dependencies.serde_crate]
Expand All @@ -24,16 +25,15 @@ default-features = false
features = ["std", "derive"]

[dependencies]
ndarray = "0.13"
ndarray = { version = "0.13", default-features = false }
ndarray-linalg = "0.12"
ndarray-rand = "0.11"
ndarray-stats = "0.3"
ndarray-linalg = "0.12"
num-traits = "0.2"

linfa = { version = "0.2.1", path = ".." }
linfa-kernel = { version = "0.2.1", path = "../linfa-kernel" }

[dev-dependencies]
openblas-src = { version = "0.9", default-features=false, features = ["system"] }
rand_isaac = "0.2.0"
ndarray-npy = { version = "0.5", default-features = false }
2 changes: 0 additions & 2 deletions linfa-reduction/examples/diffusion_map.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate openblas_src;

use linfa::traits::Transformer;
use linfa_kernel::{Kernel, KernelMethod, KernelType};
use linfa_reduction::utils::generate_convoluted_rings2d;
Expand Down
2 changes: 0 additions & 2 deletions linfa-reduction/examples/pca.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate openblas_src;

use linfa::prelude::*;
use linfa_reduction::{utils::generate_blobs, Pca};
use ndarray::array;
Expand Down
3 changes: 2 additions & 1 deletion linfa-reduction/src/diffusion_map/algorithms.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use ndarray::{Array1, Array2, ArrayView2};
use ndarray_linalg::{
eigh::EighInto, lapack::UPLO, lobpcg, lobpcg::LobpcgResult, Lapack, Scalar, TruncatedOrder,
eigh::EighInto, lobpcg, lobpcg::LobpcgResult, Lapack, Scalar, TruncatedOrder, UPLO,
};
use ndarray_rand::{rand_distr::Uniform, RandomExt};
use num_traits::NumCast;

use linfa::{traits::Transformer, Float};

use linfa_kernel::Kernel;

use super::hyperparameters::{DiffusionMapHyperParams, DiffusionMapHyperParamsBuilder};
Expand Down
2 changes: 1 addition & 1 deletion linfa-svm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ features = ["std", "derive"]

[dependencies]
ndarray = { version = "0.13", default-features=false, features=["blas"] }
ndarray-linalg = "0.12"
ndarray-rand = "0.11"
num-traits = "0.1.32"

linfa = { version = "0.2.1", path = ".." }
linfa-kernel = { version = "0.2.1", path = "../linfa-kernel" }

[dev-dependencies]
openblas-src = { version = "0.9", default-features = false, features = ["system"] }
csv = "1.1"
ndarray-csv = "0.4"
flate2 = "1.0"
Expand Down
2 changes: 0 additions & 2 deletions linfa-svm/examples/winequality.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate openblas_src;

use std::error::Error;
use std::fs::File;

Expand Down
2 changes: 0 additions & 2 deletions linfa-svm/src/classification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ impl<'a, F: Float, T: Targets, D: Data<Elem = F>>

#[cfg(test)]
mod tests {
extern crate openblas_src;

use super::Svm;
use linfa::dataset::Dataset;
use linfa::metrics::ToConfusionMatrix;
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ pub mod traits;

pub use dataset::{Dataset, Float, Label};

#[cfg(feature = "ndarray-linalg")]
pub use ndarray_linalg as linalg;

#[cfg(any(feature = "intel-mkl-system", feature = "intel-mkl-static"))]
extern crate intel_mkl_src;

#[cfg(any(feature = "openblas-system", feature = "openblas-static"))]
extern crate openblas_src;

#[cfg(any(feature = "netblas-system", feature = "netblas-static"))]
extern crate netblas_src;

/// Common metrics functions for classification and regression
pub mod metrics {
pub use crate::metrics_classification::{
Expand Down

0 comments on commit 7296c9e

Please sign in to comment.