Skip to content

Commit 39e50c4

Browse files
committed
✨ add my code base
1 parent c3a34ed commit 39e50c4

32 files changed

+1928
-0
lines changed

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
TODO.md
2+
main.rs
3+
4+
### ----- rust gitignore
5+
6+
# Generated by Cargo
7+
# will have compiled files and executables
8+
debug/
9+
target/
10+
11+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
12+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
13+
Cargo.lock
14+
15+
# These are backup files generated by rustfmt
16+
**/*.rs.bk
17+
18+
# MSVC Windows builds of rustc generate these, which store debugging information
19+
*.pdb
20+
21+
22+
### ----- Python gitignore
23+
124
# Byte-compiled / optimized / DLL files
225
__pycache__/
326
*.py[cod]

Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "tsdownsample_rs"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["Jeroen Van Der Donckt"]
6+
description = "Python bindings for time series downsampling algorithms"
7+
repository = "https://github.com/predict-idlab/tsdownsample"
8+
license = "MIT"
9+
10+
11+
[dependencies]
12+
downsample_rs = { path = "downsample_rs", features = ["half"]}
13+
pyo3 = { version = "0.17.2", features = ["extension-module"] }
14+
numpy = { git = "https://github.com/PyO3/rust-numpy", features = ["half"] } # Replace this once new release is done
15+
half = { version = "2.1", default-features = false }
16+
paste = { version = "1.0.9", default-features = false }
17+
18+
[lib]
19+
name = "tsdownsample_rs"
20+
crate-type = ["cdylib"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Jeroen Van Der Donckt
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

downsample_rs/Cargo.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[package]
2+
name = "downsample_rs"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["Jeroen Van Der Donckt"]
6+
description = "Downsample time series data"
7+
license = "MIT"
8+
9+
[dependencies]
10+
ndarray = {version = "0.15.6", default-features = false, features = ["rayon"] }
11+
argminmax = { version = "0.2" , features = ["half"] }
12+
half = { version = "2.1", default-features = false , optional = true}
13+
14+
[dev-dependencies]
15+
criterion = "0.3.0"
16+
dev_utils = { path = "dev_utils" }
17+
18+
[[bench]]
19+
name = "bench_m4"
20+
harness = false
21+
22+
[[bench]]
23+
name = "bench_minmax"
24+
harness = false
25+
26+
[[bench]]
27+
name = "bench_lttb"
28+
harness = false
29+
30+
[[bench]]
31+
name = "bench_minmaxlttb"
32+
harness = false

downsample_rs/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Jeroen Van Der Donckt
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

downsample_rs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# downsample_rs
2+
3+
Implementation of (time series) downsampling algorithms in rust.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#[macro_use]
2+
extern crate criterion;
3+
extern crate dev_utils;
4+
5+
use downsample_rs::lttb as lttb_mod;
6+
7+
use criterion::{black_box, Criterion};
8+
use dev_utils::{config, utils};
9+
use ndarray::Array1;
10+
11+
fn lttb_f32_random_array_long(c: &mut Criterion) {
12+
let n = config::ARRAY_LENGTH_LONG;
13+
let x = Array1::from((0..n).map(|i| i as i32).collect::<Vec<i32>>());
14+
let y = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
15+
c.bench_function("lttb_scal_f32", |b| {
16+
b.iter(|| lttb_mod::lttb(black_box(x.view()), black_box(y.view()), black_box(2_000)))
17+
});
18+
}
19+
fn lttb_f32_random_array_50m(c: &mut Criterion) {
20+
let n = 50_000_000;
21+
let x = Array1::from((0..n).map(|i| i as i32).collect::<Vec<i32>>());
22+
let y = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
23+
c.bench_function("lttb_scal_50M_f32", |b| {
24+
b.iter(|| lttb_mod::lttb(black_box(x.view()), black_box(y.view()), black_box(2_000)))
25+
});
26+
}
27+
28+
fn lttb_without_x_f32_random_array_long(c: &mut Criterion) {
29+
let n = config::ARRAY_LENGTH_LONG;
30+
let y = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
31+
c.bench_function("lttbnox_scal_f32", |b| {
32+
b.iter(|| lttb_mod::lttb_without_x(black_box(y.view()), black_box(2_000)))
33+
});
34+
}
35+
fn lttb_without_x_f32_random_array_50m(c: &mut Criterion) {
36+
let n = 50_000_000;
37+
let y = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
38+
c.bench_function("lttbnox_scal_50M_f32", |b| {
39+
b.iter(|| lttb_mod::lttb_without_x(black_box(y.view()), black_box(2_000)))
40+
});
41+
}
42+
43+
criterion_group!(
44+
benches,
45+
// lttb_f32_random_array_long,
46+
lttb_f32_random_array_50m,
47+
// lttb_without_x_f32_random_array_long,
48+
lttb_without_x_f32_random_array_50m,
49+
);
50+
criterion_main!(benches);

downsample_rs/benches/bench_m4.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#[macro_use]
2+
extern crate criterion;
3+
extern crate dev_utils;
4+
5+
use downsample_rs::m4 as m4_mod;
6+
7+
use criterion::{black_box, Criterion};
8+
use dev_utils::{config, utils};
9+
10+
fn m4_f32_random_array_long_single_core(c: &mut Criterion) {
11+
let n = config::ARRAY_LENGTH_LONG;
12+
let data = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
13+
c.bench_function("m4_scal_f32", |b| {
14+
b.iter(|| m4_mod::m4_scalar(black_box(data.view()), black_box(2_000)))
15+
});
16+
c.bench_function("m4_simd_f32", |b| {
17+
b.iter(|| m4_mod::m4_simd(black_box(data.view()), black_box(2_000)))
18+
});
19+
}
20+
21+
fn m4_f32_random_array_long_multi_core(c: &mut Criterion) {
22+
let n = config::ARRAY_LENGTH_LONG;
23+
let data = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
24+
c.bench_function("m4_scal_p_f32", |b| {
25+
b.iter(|| m4_mod::m4_scalar_parallel(black_box(data.view()), black_box(2_000)))
26+
});
27+
c.bench_function("m4_simd_p_f32", |b| {
28+
b.iter(|| m4_mod::m4_simd_parallel(black_box(data.view()), black_box(2_000)))
29+
});
30+
}
31+
32+
fn m4_f32_random_array_50M_single_core(c: &mut Criterion) {
33+
let n = 50_000_000;
34+
let data = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
35+
c.bench_function("m4_scal_50M_f32", |b| {
36+
b.iter(|| m4_mod::m4_scalar(black_box(data.view()), black_box(2_000)))
37+
});
38+
c.bench_function("m4_simd_50M_f32", |b| {
39+
b.iter(|| m4_mod::m4_simd(black_box(data.view()), black_box(2_000)))
40+
});
41+
}
42+
43+
fn m4_f32_random_array_50M_multi_core(c: &mut Criterion) {
44+
let n = 50_000_000;
45+
let data = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
46+
c.bench_function("m4_scal_p_50M_f32", |b| {
47+
b.iter(|| m4_mod::m4_scalar_parallel(black_box(data.view()), black_box(2_000)))
48+
});
49+
c.bench_function("m4_simd_p_50M_f32", |b| {
50+
b.iter(|| m4_mod::m4_simd_parallel(black_box(data.view()), black_box(2_000)))
51+
});
52+
}
53+
54+
// fn m4_f32_worst_case_array_long(c: &mut Criterion) {
55+
// let n = config::ARRAY_LENGTH_LONG;
56+
// let data = utils::get_worst_case_array::<f32>(n, 1.0);
57+
// c.bench_function("overlap_worst_long_f32", |b| {
58+
// b.iter(|| minmax_mod::min_max_overlap(black_box(data.view()), black_box(2_000)))
59+
// });
60+
// c.bench_function("simple_worst_long_f32", |b| {
61+
// b.iter(|| minmax_mod::min_max(black_box(data.view()), black_box(2_000)))
62+
// });
63+
// c.bench_function("simd_worst_long_f32", |b| {
64+
// b.iter(|| minmax_mod::min_max_simd_f32(black_box(data.view()), black_box(2_000)))
65+
// });
66+
// }
67+
68+
criterion_group!(
69+
benches,
70+
// m4_f32_random_array_long_single_core,
71+
// m4_f32_random_array_long_multi_core,
72+
m4_f32_random_array_50M_single_core,
73+
m4_f32_random_array_50M_multi_core,
74+
// m4_f32_worst_case_array_long,
75+
);
76+
criterion_main!(benches);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#[macro_use]
2+
extern crate criterion;
3+
extern crate dev_utils;
4+
5+
use downsample_rs::minmax as minmax_mod;
6+
7+
use criterion::{black_box, Criterion};
8+
use dev_utils::{config, utils};
9+
10+
fn minmax_f32_random_array_long_single_core(c: &mut Criterion) {
11+
let n = config::ARRAY_LENGTH_LONG;
12+
let data = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
13+
c.bench_function("minmax_scal_f32", |b| {
14+
b.iter(|| minmax_mod::min_max_scalar(black_box(data.view()), black_box(2_000)))
15+
});
16+
c.bench_function("minmax_simd_f32", |b| {
17+
b.iter(|| minmax_mod::min_max_simd(black_box(data.view()), black_box(2_000)))
18+
});
19+
}
20+
21+
fn minmax_f32_random_array_long_multi_core(c: &mut Criterion) {
22+
let n = config::ARRAY_LENGTH_LONG;
23+
let data = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
24+
c.bench_function("minmax_scal_p_f32", |b| {
25+
b.iter(|| minmax_mod::min_max_scalar_parallel(black_box(data.view()), black_box(2_000)))
26+
});
27+
c.bench_function("minmax_simd_p_f32", |b| {
28+
b.iter(|| minmax_mod::min_max_simd_parallel(black_box(data.view()), black_box(2_000)))
29+
});
30+
}
31+
32+
fn minmax_f32_random_array_50M_single_core(c: &mut Criterion) {
33+
let n = 50_000_000;
34+
let data = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
35+
c.bench_function("minmax_scal_50M_f32", |b| {
36+
b.iter(|| minmax_mod::min_max_scalar(black_box(data.view()), black_box(2_000)))
37+
});
38+
c.bench_function("minmax_simd_50M_f32", |b| {
39+
b.iter(|| minmax_mod::min_max_simd(black_box(data.view()), black_box(2_000)))
40+
});
41+
}
42+
43+
fn minmax_f32_random_array_50M_long_multi_core(c: &mut Criterion) {
44+
let n = 50_000_000;
45+
let data = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX);
46+
c.bench_function("minmax_scal_p_50M_f32", |b| {
47+
b.iter(|| minmax_mod::min_max_scalar_parallel(black_box(data.view()), black_box(2_000)))
48+
});
49+
c.bench_function("minmax_simd_p_50M_f32", |b| {
50+
b.iter(|| minmax_mod::min_max_simd_parallel(black_box(data.view()), black_box(2_000)))
51+
});
52+
}
53+
54+
// fn minmax_f32_worst_case_array_long(c: &mut Criterion) {
55+
// let n = config::ARRAY_LENGTH_LONG;
56+
// let data = utils::get_worst_case_array::<f32>(n, 1.0);
57+
// c.bench_function("overlap_worst_long_f32", |b| {
58+
// b.iter(|| minmax_mod::min_max_overlap(black_box(data.view()), black_box(2_000)))
59+
// });
60+
// c.bench_function("simple_worst_long_f32", |b| {
61+
// b.iter(|| minmax_mod::min_max(black_box(data.view()), black_box(2_000)))
62+
// });
63+
// c.bench_function("simd_worst_long_f32", |b| {
64+
// b.iter(|| minmax_mod::min_max_simd_f32(black_box(data.view()), black_box(2_000)))
65+
// });
66+
// }
67+
68+
criterion_group!(
69+
benches,
70+
// minmax_f32_random_array_long_single_core,
71+
// minmax_f32_random_array_long_multi_core,
72+
minmax_f32_random_array_50M_single_core,
73+
minmax_f32_random_array_50M_long_multi_core,
74+
// minmax_f32_worst_case_array_long,
75+
);
76+
criterion_main!(benches);

0 commit comments

Comments
 (0)