Support Wasi as target (#216)

* Improve features
* Add wasm32-wasi as a target
* Update .github/workflows/ci.yml
Co-authored-by: morenol <22335041+morenol@users.noreply.github.com>
This commit is contained in:
Lorenzo
2022-11-02 15:22:38 +00:00
committed by GitHub
parent b60329ca5d
commit cfbd45bfc0
64 changed files with 583 additions and 150 deletions
+28 -7
View File
@@ -159,7 +159,10 @@ mod tests {
use super::*;
use crate::linalg::basic::matrix::DenseMatrix;
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
fn run_kfold_return_test_indices_simple() {
let k = KFold {
@@ -175,7 +178,10 @@ mod tests {
assert_eq!(test_indices[2], (22..33).collect::<Vec<usize>>());
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
fn run_kfold_return_test_indices_odd() {
let k = KFold {
@@ -191,7 +197,10 @@ mod tests {
assert_eq!(test_indices[2], (23..34).collect::<Vec<usize>>());
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
fn run_kfold_return_test_mask_simple() {
let k = KFold {
@@ -218,7 +227,10 @@ mod tests {
}
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
fn run_kfold_return_split_simple() {
let k = KFold {
@@ -235,7 +247,10 @@ mod tests {
assert_eq!(train_test_splits[1].1, (11..22).collect::<Vec<usize>>());
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
fn run_kfold_return_split_simple_shuffle() {
let k = KFold {
@@ -251,7 +266,10 @@ mod tests {
assert_eq!(train_test_splits[1].1.len(), 11_usize);
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
fn numpy_parity_test() {
let k = KFold {
@@ -273,7 +291,10 @@ mod tests {
}
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
fn numpy_parity_test_shuffle() {
let k = KFold {
+16 -4
View File
@@ -321,7 +321,10 @@ mod tests {
use crate::neighbors::knn_regressor::{KNNRegressor, KNNRegressorParameters};
use crate::neighbors::KNNWeightFunction;
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
fn run_train_test_split() {
let n = 123;
@@ -346,7 +349,10 @@ mod tests {
struct BiasedParameters {}
impl NoParameters for BiasedParameters {}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
fn test_cross_validate_biased() {
struct BiasedEstimator {}
@@ -412,7 +418,10 @@ mod tests {
assert_eq!(0.4, results.mean_train_score());
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
fn test_cross_validate_knn() {
let x = DenseMatrix::from_2d_array(&[
@@ -457,7 +466,10 @@ mod tests {
assert!(results.mean_train_score() < results.mean_test_score());
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
fn test_cross_val_predict_knn() {
let x: DenseMatrix<f64> = DenseMatrix::from_2d_array(&[