From e7602f8cd9084208c8173698bd072cd231205573 Mon Sep 17 00:00:00 2001 From: Femi Oho <47154698+oojo12@users.noreply.github.com> Date: Mon, 31 Oct 2022 16:29:34 -0400 Subject: [PATCH 1/6] remove blas support --- .../src/gaussian_mixture/algorithm.rs | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/algorithms/linfa-clustering/src/gaussian_mixture/algorithm.rs b/algorithms/linfa-clustering/src/gaussian_mixture/algorithm.rs index 1e640cd59..99d2cb0a7 100644 --- a/algorithms/linfa-clustering/src/gaussian_mixture/algorithm.rs +++ b/algorithms/linfa-clustering/src/gaussian_mixture/algorithm.rs @@ -3,14 +3,9 @@ use crate::gaussian_mixture::hyperparams::{ GmmCovarType, GmmInitMethod, GmmParams, GmmValidParams, }; use crate::k_means::KMeans; -#[cfg(feature = "blas")] -use linfa::dataset::{WithLapack, WithoutLapack}; use linfa::{prelude::*, DatasetBase, Float}; -#[cfg(not(feature = "blas"))] use linfa_linalg::{cholesky::*, triangular::*}; use ndarray::{s, Array, Array1, Array2, Array3, ArrayBase, Axis, Data, Ix2, Ix3, Zip}; -#[cfg(feature = "blas")] -use ndarray_linalg::{cholesky::*, triangular::*}; use ndarray_rand::rand::Rng; use ndarray_rand::rand_distr::Uniform; use ndarray_rand::RandomExt; @@ -265,14 +260,6 @@ impl GaussianMixtureModel { let n_features = covariances.shape()[1]; let mut precisions_chol = Array::zeros((n_clusters, n_features, n_features)); for (k, covariance) in covariances.outer_iter().enumerate() { - #[cfg(feature = "blas")] - let sol = { - let decomp = covariance.with_lapack().cholesky(UPLO::Lower)?; - decomp - .solve_triangular_into(UPLO::Lower, Diag::NonUnit, Array::eye(n_features))? - .without_lapack() - }; - #[cfg(not(feature = "blas"))] let sol = { let decomp = covariance.cholesky()?; decomp.solve_triangular_into(Array::eye(n_features), UPLO::Lower)? @@ -495,19 +482,10 @@ impl> PredictInplace, Array1, covariance: &ArrayView2) -> LAResult { - #[cfg(feature = "blas")] - let lower = covariance.cholesky(UPLO::Lower)?; - #[cfg(not(feature = "blas"))] let lower = covariance.cholesky()?; Ok(MultivariateNormal { mean: mean.to_owned(), @@ -625,12 +600,6 @@ mod tests { match gmm.expect_err("should generate an error with reg_covar being nul") { GmmError::LinalgError(e) => { - #[cfg(feature = "blas")] - assert!(matches!( - e, - LinalgError::Lapack(Error::LapackComputationalFailure { return_code: 2 }) - )); - #[cfg(not(feature = "blas"))] assert!(matches!(e, LinalgError::NotPositiveDefinite)); } e => panic!("should be a linear algebra error: {:?}", e), @@ -654,17 +623,6 @@ mod tests { .reg_covariance(0.) .fit(&dataset); - #[cfg(feature = "blas")] - match gmm.expect_err("should generate an error with reg_covar being nul") { - GmmError::LinalgError(e) => { - assert!(matches!( - e, - LinalgError::Lapack(Error::LapackComputationalFailure { return_code: 1 }) - )); - } - e => panic!("should be a linear algebra error: {:?}", e), - } - #[cfg(not(feature = "blas"))] gmm.expect_err("should generate an error with reg_covar being nul"); // Test it passes when default value is used From b3b5ba3dcb688445fd8f4847f65a9f66843427c3 Mon Sep 17 00:00:00 2001 From: Femi Oho <47154698+oojo12@users.noreply.github.com> Date: Mon, 31 Oct 2022 16:34:00 -0400 Subject: [PATCH 2/6] remove blas feature --- algorithms/linfa-clustering/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/algorithms/linfa-clustering/Cargo.toml b/algorithms/linfa-clustering/Cargo.toml index 8cdb52c8c..693979ca3 100644 --- a/algorithms/linfa-clustering/Cargo.toml +++ b/algorithms/linfa-clustering/Cargo.toml @@ -18,7 +18,6 @@ categories = ["algorithms", "mathematics", "science"] [features] default = [] -blas = ["ndarray-linalg", "linfa/ndarray-linalg"] serde = ["serde_crate", "ndarray/serde", "linfa-nn/serde"] [dependencies.serde_crate] From 40abb6f66fb27d2ad79cd497c856f26fa39929e8 Mon Sep 17 00:00:00 2001 From: Femi Oho <47154698+oojo12@users.noreply.github.com> Date: Mon, 31 Oct 2022 17:02:10 -0400 Subject: [PATCH 3/6] rustfmt run --- algorithms/linfa-clustering/src/gaussian_mixture/algorithm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms/linfa-clustering/src/gaussian_mixture/algorithm.rs b/algorithms/linfa-clustering/src/gaussian_mixture/algorithm.rs index 99d2cb0a7..5a34cd1e9 100644 --- a/algorithms/linfa-clustering/src/gaussian_mixture/algorithm.rs +++ b/algorithms/linfa-clustering/src/gaussian_mixture/algorithm.rs @@ -483,9 +483,9 @@ mod tests { use super::*; use approx::{abs_diff_eq, assert_abs_diff_eq}; use linfa_datasets::generate; - use ndarray::{array, concatenate, ArrayView1, ArrayView2, Axis}; use linfa_linalg::LinalgError; use linfa_linalg::Result as LAResult; + use ndarray::{array, concatenate, ArrayView1, ArrayView2, Axis}; use ndarray_rand::rand::prelude::ThreadRng; use ndarray_rand::rand::SeedableRng; use ndarray_rand::rand_distr::{Distribution, StandardNormal}; From 517c362369b3f134917e0c16e90cd13b45713f8b Mon Sep 17 00:00:00 2001 From: Femi <47154698+oojo12@users.noreply.github.com> Date: Mon, 31 Oct 2022 20:51:20 -0400 Subject: [PATCH 4/6] Update BLAS/Lapack backend note --- algorithms/linfa-clustering/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/algorithms/linfa-clustering/README.md b/algorithms/linfa-clustering/README.md index ea9f6f49a..ded3c8d7d 100644 --- a/algorithms/linfa-clustering/README.md +++ b/algorithms/linfa-clustering/README.md @@ -24,8 +24,7 @@ Implementation choices, algorithmic details and a tutorial can be found **WARNING:** Currently the Approximated DBSCAN implementation is slower than the normal DBSCAN implementation. Therefore DBSCAN should always be used over Approximated DBSCAN. ## BLAS/Lapack backend - -See [this section](../../README.md#blaslapack-backend) to enable an external BLAS/LAPACK backend. +We found that the pure Rust implementation maintained similar performance to the BLAS/LAPACK version. Thus, to reduce code complexity BLAS support has been removed for this module. ## License Dual-licensed to be compatible with the Rust project. From bfbabfba6dde9ae89a9c2e268a21caff05ae2158 Mon Sep 17 00:00:00 2001 From: Femi <47154698+oojo12@users.noreply.github.com> Date: Mon, 31 Oct 2022 20:52:20 -0400 Subject: [PATCH 5/6] remove linfa-clustering --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 950b045d7..cce3c1daa 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -51,4 +51,4 @@ jobs: toolchain: ${{ matrix.toolchain }} - name: Run cargo test with BLAS enabled - run: cargo test --release --workspace --features intel-mkl-static,linfa-clustering/blas,linfa-ica/blas,linfa-reduction/blas,linfa-linear/blas,linfa-preprocessing/blas,linfa-pls/blas,linfa-elasticnet/blas + run: cargo test --release --workspace --features intel-mkl-static,linfa-ica/blas,linfa-reduction/blas,linfa-linear/blas,linfa-preprocessing/blas,linfa-pls/blas,linfa-elasticnet/blas From 5ac003eb2ae9d5cc16aeee47ebceb2aba3d2ae06 Mon Sep 17 00:00:00 2001 From: Femi <47154698+oojo12@users.noreply.github.com> Date: Mon, 31 Oct 2022 22:04:41 -0400 Subject: [PATCH 6/6] mention PR --- algorithms/linfa-clustering/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms/linfa-clustering/README.md b/algorithms/linfa-clustering/README.md index ded3c8d7d..c3ef4aac6 100644 --- a/algorithms/linfa-clustering/README.md +++ b/algorithms/linfa-clustering/README.md @@ -24,7 +24,7 @@ Implementation choices, algorithmic details and a tutorial can be found **WARNING:** Currently the Approximated DBSCAN implementation is slower than the normal DBSCAN implementation. Therefore DBSCAN should always be used over Approximated DBSCAN. ## BLAS/Lapack backend -We found that the pure Rust implementation maintained similar performance to the BLAS/LAPACK version. Thus, to reduce code complexity BLAS support has been removed for this module. +We found that the pure Rust implementation maintained similar performance to the BLAS/LAPACK version and have removed it with this [PR](https://github.com/rust-ml/linfa/pull/257). Thus, to reduce code complexity BLAS support has been removed for this module. ## License Dual-licensed to be compatible with the Rust project.