feat: added support to wasm (#94)

* test: run tests also in wasm targets

* fix: install rand with wasm-bindgen por wasm targets

* fix: use actual usize size to access buffer.

* fix: do not run functions that create files in wasm.

* test: do not run in wasm test that panics.

Co-authored-by: Luis Moreno <morenol@users.noreply.github.com>
This commit is contained in:
Luis Moreno
2021-04-28 15:58:39 -04:00
committed by GitHub
parent 5ed5772a4e
commit 162bed2aa2
71 changed files with 294 additions and 51 deletions
+5
View File
@@ -225,6 +225,7 @@ mod tests {
use crate::linalg::naive::dense_matrix::DenseMatrix;
use crate::preprocessing::series_encoder::CategoryMapper;
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn adjust_idxs() {
assert_eq!(find_new_idxs(0, &[], &[]), Vec::<usize>::new());
@@ -269,6 +270,7 @@ mod tests {
(orig, oh_enc)
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn hash_encode_f64_series() {
let series = vec![3.0, 1.0, 2.0, 1.0];
@@ -279,6 +281,7 @@ mod tests {
let orig_val: f64 = inv.unwrap().into();
assert_eq!(orig_val, 2.0);
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn test_fit() {
let (x, _) = build_fake_matrix();
@@ -294,6 +297,7 @@ mod tests {
assert_eq!(num_cat, vec![2, 4]);
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn matrix_transform_test() {
let (x, expected_x) = build_fake_matrix();
@@ -309,6 +313,7 @@ mod tests {
assert_eq!(nm, expected_x);
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn fail_on_bad_category() {
let m = DenseMatrix::from_2d_array(&[
+6
View File
@@ -201,6 +201,7 @@ where
mod tests {
use super::*;
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn from_categories() {
let fake_categories: Vec<usize> = vec![1, 2, 3, 4, 5, 3, 5, 3, 1, 2, 4];
@@ -219,12 +220,14 @@ mod tests {
let enc = CategoryMapper::<&str>::from_positional_category_vec(fake_category_pos);
enc
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn ordinal_encoding() {
let enc = build_fake_str_enc();
assert_eq!(1f64, enc.get_ordinal::<f64>(&"dog").unwrap())
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn category_map_and_vec() {
let category_map: HashMap<&str, usize> = vec![("background", 0), ("dog", 1), ("cat", 2)]
@@ -239,6 +242,7 @@ mod tests {
assert_eq!(oh_vec, res);
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn positional_categories_vec() {
let enc = build_fake_str_enc();
@@ -250,6 +254,7 @@ mod tests {
assert_eq!(oh_vec, res);
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn invert_label_test() {
let enc = build_fake_str_enc();
@@ -262,6 +267,7 @@ mod tests {
};
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn test_many_categorys() {
let enc = build_fake_str_enc();