Skip to content

Commit 4442480

Browse files
authored
Implement SVR and SVR kernels with Enum. Add tests for argsort_mut (#303)
* Add tests for argsort_mut * Add formatting and cleaning up .github directory * fix clippy error. suggestion to use .contains() * define type explicitly for variable jstack * Implement kernel as enumerator * basic svr and svr_params implementation * Complete enum implementation for Kernels. Implement search grid for SVR. Add documentation. * Fix serde configuration in cargo clippy * Implement search parameters (#304) * Implement SVR kernels as enumerator * basic svr and svr_params implementation * Implement search grid for SVR. Add documentation. * Fix serde configuration in cargo clippy * Fix wasm32 typetag * fix typetag * Bump to version 0.4.2
1 parent 76d1ef6 commit 4442480

File tree

9 files changed

+621
-309
lines changed

9 files changed

+621
-309
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
# the repo. Unless a later match takes precedence,
33
# Developers in this list will be requested for
44
# review when someone opens a pull request.
5-
* @VolodymyrOrlov
65
* @morenol
76
* @Mec-iS

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ $ rust-code-analysis-cli -p src/algorithm/neighbour/fastpair.rs --ls 22 --le 213
5050

5151
1. After a PR is opened maintainers are notified
5252
2. Probably changes will be required to comply with the workflow, these commands are run automatically and all tests shall pass:
53-
* **Coverage** (optional): `tarpaulin` is used with command `cargo tarpaulin --out Lcov --all-features -- --test-threads 1`
5453
* **Formatting**: run `rustfmt src/*.rs` to apply automatic formatting
5554
* **Linting**: `clippy` is used with command `cargo clippy --all-features -- -Drust-2018-idioms -Dwarnings`
55+
* **Coverage** (optional): `tarpaulin` is used with command `cargo tarpaulin --out Lcov --all-features -- --test-threads 1`
5656
* **Testing**: multiple test pipelines are run for different targets
5757
3. When everything is OK, code is merged.
5858

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "smartcore"
33
description = "Machine Learning in Rust."
44
homepage = "https://smartcorelib.org"
5-
version = "0.4.1"
5+
version = "0.4.2"
66
authors = ["smartcore Developers"]
77
edition = "2021"
88
license = "Apache-2.0"

src/linalg/basic/arrays.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ pub trait MutArrayView1<T: Debug + Display + Copy + Sized>:
619619
T: Number + PartialOrd,
620620
{
621621
let stack_size = 64;
622-
let mut jstack = -1;
622+
let mut jstack: i32 = -1;
623623
let mut l = 0;
624624
let mut istack = vec![0; stack_size];
625625
let mut ir = self.shape() - 1;
@@ -2190,4 +2190,29 @@ mod tests {
21902190

21912191
assert_eq!(result, [65, 581, 30])
21922192
}
2193+
2194+
#[test]
2195+
fn test_argsort_mut_exact_boundary() {
2196+
// Test index == length - 1 case
2197+
let boundary =
2198+
DenseMatrix::from_2d_array(&[&[1.0, 2.0, 3.0, f64::MAX], &[3.0, f64::MAX, 0.0, 2.0]])
2199+
.unwrap();
2200+
let mut view0: Vec<f64> = boundary.get_col(0).iterator(0).copied().collect();
2201+
let indices = view0.argsort_mut();
2202+
assert_eq!(indices.last(), Some(&1));
2203+
assert_eq!(indices.first(), Some(&0));
2204+
2205+
let mut view1: Vec<f64> = boundary.get_col(3).iterator(0).copied().collect();
2206+
let indices = view1.argsort_mut();
2207+
assert_eq!(indices.last(), Some(&0));
2208+
assert_eq!(indices.first(), Some(&1));
2209+
}
2210+
2211+
#[test]
2212+
fn test_argsort_mut_filled_array() {
2213+
let matrix = DenseMatrix::<f64>::rand(1000, 1000);
2214+
let mut view: Vec<f64> = matrix.get_col(0).iterator(0).copied().collect();
2215+
let sorted = view.argsort_mut();
2216+
assert_eq!(sorted.len(), 1000);
2217+
}
21932218
}

src/neighbors/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl KNNWeightFunction {
6464
KNNWeightFunction::Distance => {
6565
// if there are any points that has zero distance from one or more training points,
6666
// those training points are weighted as 1.0 and the other points as 0.0
67-
if distances.iter().any(|&e| e == 0f64) {
67+
if distances.contains(&0f64) {
6868
distances
6969
.iter()
7070
.map(|e| if *e == 0f64 { 1f64 } else { 0f64 })

0 commit comments

Comments
 (0)