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:
@@ -346,6 +346,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::linalg::naive::dense_matrix::DenseMatrix;
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn run_bernoulli_naive_bayes() {
|
||||
// Tests that BernoulliNB when alpha=1.0 gives the same values as
|
||||
@@ -398,6 +399,7 @@ mod tests {
|
||||
assert_eq!(y_hat, &[1.]);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn bernoulli_nb_scikit_parity() {
|
||||
let x = DenseMatrix::<f64>::from_2d_array(&[
|
||||
@@ -460,6 +462,7 @@ mod tests {
|
||||
));
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
#[cfg(feature = "serde")]
|
||||
fn serde() {
|
||||
|
||||
@@ -351,6 +351,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::linalg::naive::dense_matrix::DenseMatrix;
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn run_categorical_naive_bayes() {
|
||||
let x = DenseMatrix::from_2d_array(&[
|
||||
@@ -431,6 +432,7 @@ mod tests {
|
||||
assert_eq!(y_hat, vec![0., 1.]);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn run_categorical_naive_bayes2() {
|
||||
let x = DenseMatrix::from_2d_array(&[
|
||||
@@ -459,6 +461,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
#[cfg(feature = "serde")]
|
||||
fn serde() {
|
||||
|
||||
@@ -259,6 +259,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::linalg::naive::dense_matrix::DenseMatrix;
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn run_gaussian_naive_bayes() {
|
||||
let x = DenseMatrix::from_2d_array(&[
|
||||
@@ -295,6 +296,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn run_gaussian_naive_bayes_with_priors() {
|
||||
let x = DenseMatrix::from_2d_array(&[
|
||||
@@ -314,6 +316,7 @@ mod tests {
|
||||
assert_eq!(gnb.class_priors(), &priors);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
#[cfg(feature = "serde")]
|
||||
fn serde() {
|
||||
|
||||
@@ -297,6 +297,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::linalg::naive::dense_matrix::DenseMatrix;
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn run_multinomial_naive_bayes() {
|
||||
// Tests that MultinomialNB when alpha=1.0 gives the same values as
|
||||
@@ -352,6 +353,7 @@ mod tests {
|
||||
assert_eq!(y_hat, &[0.]);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn multinomial_nb_scikit_parity() {
|
||||
let x = DenseMatrix::<f64>::from_2d_array(&[
|
||||
@@ -411,6 +413,7 @@ mod tests {
|
||||
1e-5
|
||||
));
|
||||
}
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
#[cfg(feature = "serde")]
|
||||
fn serde() {
|
||||
|
||||
Reference in New Issue
Block a user