Skip to content
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

Index out of bounds using with_min_distance #2

Closed
pmagaz opened this issue Feb 21, 2022 · 2 comments
Closed

Index out of bounds using with_min_distance #2

pmagaz opened this issue Feb 21, 2022 · 2 comments

Comments

@pmagaz
Copy link

pmagaz commented Feb 21, 2022

Hi,

I'm using your library and I'm having cases in that I get an error using with_min_distance().

let mut local_minima_fp = PeakFinder::new(&data); // a Vec<f64>
local_minima_fp.with_min_prominence(4.764600000000001);
local_minima_fp.with_min_distance(20);

This is the error message:

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /Users/pmagaz/.cargo/registry/src/github.com-1ecc6299db9ec823/find_peaks-0.1.2/src/lib.rs:285:23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Taking a quick look at the code, it looks like peaks variable could have no elements, therefore peaks[0] could be the reason?

let mut filtered = Vec::with_capacity(peaks.len());
filtered.push(peaks[0].clone());

Thanks in advance!

@tungli
Copy link
Owner

tungli commented Mar 6, 2022

Thanks for reporting the issue!
I added a check for empty peaks vector before using distance-based filtering which should solve the issue.
Should be fixed in version 0.1.3

@pmagaz
Copy link
Author

pmagaz commented Mar 7, 2022

Many thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants