Skip to content

Commit

Permalink
improve rolling_quantile kernel (no nulls) ~28x (#3437)
Browse files Browse the repository at this point in the history
* improve quantile kernel (no nulls) ~28x
* improve quantile nulls
  • Loading branch information
ritchie46 committed May 20, 2022
1 parent 2d3727e commit 24ddb90
Show file tree
Hide file tree
Showing 7 changed files with 936 additions and 657 deletions.
37 changes: 37 additions & 0 deletions polars/polars-arrow/src/kernels/rolling/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
pub mod no_nulls;
pub mod nulls;
pub mod quantile_no_nulls;
pub mod quantile_nulls;
mod window;

use crate::data_types::IsFloat;
use crate::prelude::QuantileInterpolOptions;
use crate::utils::CustomIterTools;
use arrow::array::{ArrayRef, PrimitiveArray};
use arrow::bitmap::utils::{count_zeros, get_bit_unchecked};
use arrow::bitmap::{Bitmap, MutableBitmap};
use arrow::types::NativeType;
use num::ToPrimitive;
use num::{Bounded, Float, NumCast, One, Zero};
use std::cmp::Ordering;
use std::ops::AddAssign;
use std::ops::{Add, Div, Mul, Sub};
use std::sync::Arc;
use window::*;

type Start = usize;
type End = usize;
Expand Down Expand Up @@ -58,3 +75,23 @@ where
None
}
}
pub(super) fn sort_buf<T>(buf: &mut [T])
where
T: IsFloat + NativeType + PartialOrd,
{
if T::is_float() {
buf.sort_by(|a, b| {
match (a.is_nan(), b.is_nan()) {
// safety: we checked nans
(false, false) => unsafe { a.partial_cmp(b).unwrap_unchecked() },
(true, true) => Ordering::Equal,
(true, false) => Ordering::Greater,
(false, true) => Ordering::Less,
}
});
} else {
// Safety:
// all integers are Ord
unsafe { buf.sort_by(|a, b| a.partial_cmp(b).unwrap_unchecked()) };
}
}

0 comments on commit 24ddb90

Please sign in to comment.