Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/checking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,24 @@ jobs:

- name: Run cargo check (with serde)
run: cargo check --workspace --all-targets --features "linfa-clustering/serde linfa-ica/serde linfa-kernel/serde linfa-reduction/serde linfa-svm/serde linfa-elasticnet/serde linfa-pls/serde linfa-trees/serde linfa-nn/serde linfa-linear/serde linfa-preprocessing/serde linfa-bayes/serde linfa-logistic/serde linfa-ftrl/serde"

check-wasm-browser:
name: check-wasm-browser
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@master

- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: wasm32-unknown-unknown

- name: Run browser WASM checks
run: |
cargo check -p linfa --lib --target wasm32-unknown-unknown --features wasm-bindgen
cargo check -p linfa-linear --lib --target wasm32-unknown-unknown --features wasm-bindgen
cargo check -p linfa-logistic --lib --target wasm32-unknown-unknown --features wasm-bindgen
cargo check -p linfa-ftrl --lib --target wasm32-unknown-unknown --features wasm-bindgen
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ intel-mkl-system = ["blas", "ndarray-linalg/intel-mkl-system"]
blas = ["ndarray/blas"]

serde = ["serde_crate", "ndarray/serde"]
wasm-bindgen = ["dep:getrandom"]

[dependencies]
num-traits = "0.2"
rand = { version = "0.8", features = ["small_rng"] }
approx = "0.5"
getrandom = { version = "0.2", optional = true, features = ["js"] }

ndarray = { version = "0.16", features = ["approx"] }
ndarray-linalg = { version = "0.17", optional = true }
Expand Down Expand Up @@ -75,6 +77,7 @@ pprof = { version = "0.15", features = [

[workspace]
members = ["algorithms/*", "datasets"]
resolver = "2"

[profile.release]
opt-level = 3
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ 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!

## Browser WASM

For browser-style WASM on `wasm32-unknown-unknown`, enable `linfa`'s `wasm-bindgen` feature.

## BLAS/Lapack backend

Some algorithm crates need to use an external library for linear algebra routines. By default, we use a pure-Rust implementation. However, you can also choose an external BLAS/LAPACK backend library instead, by enabling the `blas` feature and a feature corresponding to your BLAS backend. Currently you can choose between the following BLAS/LAPACK backends: `openblas`, `netblas` or `intel-mkl`.
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-clustering/src/dbscan/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<F: Float, D: Data<Elem = F>, DF: Distance<F>, N: NearestNeighbour>
continue;
}
neighbors.iter().for_each(|&n| search_found[n] = true);
search_queue.extend(neighbors.into_iter());
search_queue.extend(neighbors);

// Now go over the neighbours adding them to the cluster
cluster_memberships[i] = Some(current_cluster_id);
Expand Down
6 changes: 3 additions & 3 deletions algorithms/linfa-clustering/src/optics/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ impl<F: Float, D: Distance<F>, N: NearestNeighbour>
index += 1;
continue;
}
let mut expected = if processed.is_empty() { 0 } else { index };
let mut points_index = index;
// Look for next point to process starting from lowest possible unprocessed index
for index in processed.range(index..) {
for (expected, index) in
(if processed.is_empty() { 0 } else { index }..).zip(processed.range(index..))
{
if expected != *index {
points_index = expected;
break;
}
expected += 1;
}
index += 1;
let neighbors = self.find_neighbors(&*nn, observations.row(points_index));
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-ftrl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = ["algorithms", "mathematics", "science"]

[features]
serde = ["serde_crate", "linfa/serde", "ndarray/serde", "argmin/serde1"]
wasm-bindgen = ["argmin/wasm-bindgen"]
wasm-bindgen = ["argmin/wasm-bindgen", "linfa/wasm-bindgen"]

[dependencies.serde_crate]
package = "serde"
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-hierarchical/examples/irisflower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.num_clusters(3)
.transform(kernel)?;

for (id, target) in kernel.targets().iter().zip(dataset.targets().into_iter()) {
for (id, target) in kernel.targets().iter().zip(dataset.targets()) {
let name = match *target {
0 => "setosa",
1 => "versicolor",
Expand Down
6 changes: 1 addition & 5 deletions algorithms/linfa-hierarchical/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ impl<F: Float> Transformer<Kernel<F>, DatasetBase<Kernel<F>, Vec<usize>>>
.map(|x| (x, vec![x]))
.collect::<HashMap<_, _>>();

// counter for new clusters, which are formed as unions of previous ones
let mut ct = num_observations;

for step in res.steps() {
for (ct, step) in (num_observations..).zip(res.steps().iter()) {
let should_stop = match self.stopping {
Criterion::NumClusters(max_clusters) => clusters.len() <= max_clusters,
Criterion::Distance(dis) => step.dissimilarity >= dis,
Expand All @@ -164,7 +161,6 @@ impl<F: Float> Transformer<Kernel<F>, DatasetBase<Kernel<F>, Vec<usize>>>

// insert into hashmap and increase counter
clusters.insert(ct, ids);
ct += 1;
}

// flatten resulting clusters and reverse index
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-linear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ categories = ["algorithms", "mathematics", "science"]
[features]
blas = ["ndarray-linalg", "linfa/ndarray-linalg"]
serde = ["serde_crate", "linfa/serde", "ndarray/serde", "argmin/serde1"]
wasm-bindgen = ["argmin/wasm-bindgen"]
wasm-bindgen = ["argmin/wasm-bindgen", "linfa/wasm-bindgen"]

[dependencies.serde_crate]
package = "serde"
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-logistic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = ["algorithms", "mathematics", "science"]

[features]
serde = ["serde_crate", "linfa/serde", "ndarray/serde", "argmin/serde1"]
wasm-bindgen = ["argmin/wasm-bindgen"]
wasm-bindgen = ["argmin/wasm-bindgen", "linfa/wasm-bindgen"]

[dependencies.serde_crate]
package = "serde"
Expand Down
6 changes: 6 additions & 0 deletions datasets/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ use std::io::Read;

use csv::ReaderBuilder;
use flate2::read::GzDecoder;
#[cfg(any(
feature = "iris",
feature = "diabetes",
feature = "winequality",
feature = "linnerud"
))]
use linfa::Dataset;
use ndarray::prelude::*;
use ndarray_csv::{Array2Reader, ReadError};
Expand Down
2 changes: 1 addition & 1 deletion src/composing/multi_class_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<L: Clone + Default, F, D: Data<Elem = F>> PredictInplace<ArrayBase<D, Ix2>,
// if probability is higher
res = res
.into_iter()
.zip(pairs.into_iter())
.zip(pairs)
.map(|(c, d)| if d.1 > c.1 { d } else { c })
.collect();
}
Expand Down
Loading