-
Notifications
You must be signed in to change notification settings - Fork 25
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
quantile_mut: fatal runtime error: stack overflow #86
Comments
Exceeding the stack limit suggests to me either infinite recursion or a large data structure is being placed on the heap. I don't see an obvious source of either of those causes in the code. It's possible that more generalized memory corruption could cause this behaviour. ndarray-stats/src/quantile/mod.rs Lines 437 to 498 in 9ed9373
|
Line 293 in b6628c6
Looks like this recursive function call _get_many_from_sorted_mut_unchecked is recursing probably not infinitely but once per size of the vector, and blowing through the stack, perhaps because all the elements in the array are equal. (thanks to @evolvedmicrobe for discovering)
|
I think this issue may be fixed by #80; I'll take another look at that PR this weekend to see if we can get it merged. |
I checked, and #80 doesn't fix this issue as-is. It's a bit tricky to avoid stack overflow with the recursive algorithm for large arrays with all equal elements. At first glance, I suspect that the best fix would be for partitioning to handle |
Thank you for checking, Jim! I have a work around for now using /// Return the median. Sorts its argument in place.
pub fn median_mut<T>(xs: &mut Array1<T>) -> Result<T, QuantileError>
where
T: Clone + Copy + Ord + FromPrimitive,
T: Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Rem<Output = T>,
{
if false {
// quantile_mut may fail with the error: fatal runtime error: stack overflow
// See https://github.com/rust-ndarray/ndarray-stats/issues/86
xs.quantile_mut(n64(0.5), &Midpoint)
} else {
if xs.is_empty() {
return Err(QuantileError::EmptyInput);
}
xs.as_slice_mut().unwrap().sort_unstable();
Ok(if xs.len() % 2 == 0 {
(xs[xs.len() / 2] + xs[xs.len() / 2 - 1]) / (T::from_u64(2).unwrap())
} else {
xs[xs.len() / 2]
})
}
} |
Description
quantile_mut
can fail with the error message:Version Information
ndarray
: 0.15.4ndarray-stats
: 0.5.0To Reproduce
Observed behavior
Expected behavior
Additional context
ulimit -s
reports 8192)The text was updated successfully, but these errors were encountered: