Axect / Peroxide

Rust numeric library with R, MATLAB & Python syntax
https://crates.io/crates/peroxide
Apache License 2.0
499 stars 29 forks source link

`quantile` may panic #39

Closed asmyers closed 3 years ago

asmyers commented 3 years ago
#![feature(drain_filter)]

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;
use peroxide::statistics::*;

use std::{env, ops::Index};

fn main() -> Result<(), Box<dyn Error>> {
    let data = vec![0f64; 7592];
    let q = quantile(&data, QType::Type1);
    println!("{:?}", q);
    Ok(())
}

Panics with the following:

   Running `target\debug\o2ring.exe C:\Users\asm19\OneDrive\zettlekasten\o2ring\2021-03-28.csv`
thread 'main' panicked at 'index out of bounds: the len is 7592 but the index is 7592', C:\Users\asm19\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\slice\mod.rs:566:36
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597\/library\std\src\panicking.rs:493
   1: core::panicking::panic_fmt
             at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597\/library\core\src\panicking.rs:92
   2: core::panicking::panic_bounds_check
             at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597\/library\core\src\panicking.rs:69
   3: core::slice::{{impl}}::swap<f64>
             at C:\Users\asm19\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\slice\mod.rs:566
   4: order_stat::floyd_rivest::select_<f64,closure-0>
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\order-stat-0.1.3\src\floyd_rivest.rs:37
   5: order_stat::floyd_rivest::select_<f64,closure-0>
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\order-stat-0.1.3\src\floyd_rivest.rs:32
   6: order_stat::floyd_rivest::select<f64,closure-0>
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\order-stat-0.1.3\src\floyd_rivest.rs:8
   7: order_stat::kth_by<f64,closure-0>
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\order-stat-0.1.3\src\lib.rs:192
   8: peroxide::statistics::stat::quantile_mut
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\peroxide-0.30.5\src\statistics\stat.rs:504
   9: peroxide::statistics::stat::{{impl}}::quantiles
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\peroxide-0.30.5\src\statistics\stat.rs:485
  10: peroxide::statistics::stat::quantile
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\peroxide-0.30.5\src\statistics\stat.rs:527
  11: o2ring::main
             at .\src\main.rs:12
  12: core::ops::function::FnOnce::call_once<fn() -> core::result::Result<tuple<>, alloc::boxed::Box<Error, alloc::alloc::Global>>,tuple<>>
             at C:\Users\asm19\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Axect commented 3 years ago

Thank you so much! I didn't consider that case. (k >= l) Now, I fix bugs in quantile_mut, quantile, quantiles and publish Ver 0.30.6. Thank you once again for your great contribution! :+1:

asmyers commented 3 years ago

Awesome, works for me now! Thank you!