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:
@@ -159,6 +159,7 @@ impl<T: RealNumber, V: BaseVector<T>> Kernel<T, V> for SigmoidKernel<T> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn linear_kernel() {
|
||||
let v1 = vec![1., 2., 3.];
|
||||
@@ -167,6 +168,7 @@ mod tests {
|
||||
assert_eq!(32f64, Kernels::linear().apply(&v1, &v2));
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn rbf_kernel() {
|
||||
let v1 = vec![1., 2., 3.];
|
||||
@@ -175,6 +177,7 @@ mod tests {
|
||||
assert!((0.2265f64 - Kernels::rbf(0.055).apply(&v1, &v2)).abs() < 1e-4);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn polynomial_kernel() {
|
||||
let v1 = vec![1., 2., 3.];
|
||||
@@ -186,6 +189,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn sigmoid_kernel() {
|
||||
let v1 = vec![1., 2., 3.];
|
||||
|
||||
@@ -729,6 +729,7 @@ mod tests {
|
||||
#[cfg(feature = "serde")]
|
||||
use crate::svm::*;
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn svc_fit_predict() {
|
||||
let x = DenseMatrix::from_2d_array(&[
|
||||
@@ -771,6 +772,7 @@ mod tests {
|
||||
assert!(accuracy(&y_hat, &y) >= 0.9);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn svc_fit_predict_rbf() {
|
||||
let x = DenseMatrix::from_2d_array(&[
|
||||
@@ -814,6 +816,7 @@ mod tests {
|
||||
assert!(accuracy(&y_hat, &y) >= 0.9);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
#[cfg(feature = "serde")]
|
||||
fn svc_serde() {
|
||||
|
||||
@@ -536,6 +536,7 @@ mod tests {
|
||||
#[cfg(feature = "serde")]
|
||||
use crate::svm::*;
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
fn svr_fit_predict() {
|
||||
let x = DenseMatrix::from_2d_array(&[
|
||||
@@ -569,6 +570,7 @@ mod tests {
|
||||
assert!(mean_squared_error(&y_hat, &y) < 2.5);
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[test]
|
||||
#[cfg(feature = "serde")]
|
||||
fn svr_serde() {
|
||||
|
||||
Reference in New Issue
Block a user