Skip to content

Fix tests #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2022
Merged
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
3 changes: 1 addition & 2 deletions src/dataset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ pub mod digits;
pub mod generator;
pub mod iris;

use crate::numbers::basenum::Number;
#[cfg(not(target_arch = "wasm32"))]
use crate::numbers::realnum::RealNumber;
use crate::numbers::{basenum::Number, realnum::RealNumber};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a change to remove compilation warning about unused code in wasm32

#[cfg(not(target_arch = "wasm32"))]
use std::fs::File;
use std::io;
Expand Down
10 changes: 7 additions & 3 deletions src/linear/logistic_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ mod tests {
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn lr_fit_predict() {
let x = DenseMatrix::from_2d_array(&[
let x: DenseMatrix<f64> = DenseMatrix::from_2d_array(&[
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using f64 instead of f32 for better precision in wasm32 tests

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably f64 is more stable but possibly less supported

&[1., -5.],
&[2., 5.],
&[3., -2.],
Expand All @@ -739,8 +739,12 @@ mod tests {
assert_eq!(lr.coefficients().shape(), (3, 2));
assert_eq!(lr.intercept().shape(), (3, 1));

assert!((*lr.coefficients().get((0, 0)) - 0.0435f32).abs() < 1e-4);
assert!((*lr.intercept().get((0, 0)) - 0.1250f32).abs() < 1e-4);
assert!((*lr.coefficients().get((0, 0)) - 0.0435).abs() < 1e-4);
assert!(
(*lr.intercept().get((0, 0)) - 0.1250).abs() < 1e-4,
"expected to be least than 1e-4, got {}",
(*lr.intercept().get((0, 0)) - 0.1250).abs()
);

let y_hat = lr.predict(&x).unwrap();

Expand Down
4 changes: 4 additions & 0 deletions src/naive_bayes/multinomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ mod tests {
&distribution.class_priors,
&vec!(0.4666666666666667, 0.2, 0.3333333333333333)
);

// Due to float differences in WASM32,
// we disable this test for that arch
#[cfg(not(target_arch = "wasm32"))]
assert_eq!(
&nb.feature_log_prob()[1],
&vec![
Expand Down