Skip to content

Commit

Permalink
more cache friendly chunkededarray operation number operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 6, 2020
1 parent 97937c0 commit 0b98992
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 47 deletions.
4 changes: 3 additions & 1 deletion polars/src/chunked_array/apply.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Implementations of the ChunkApply Trait.
use crate::prelude::*;
use crate::utils::Xob;

impl<'a, T> ChunkApply<'a, T::Native, T::Native> for ChunkedArray<T>
where
Expand All @@ -21,7 +22,8 @@ where
F: Fn(T::Native) -> T::Native + Copy,
{
if let Ok(slice) = self.cont_slice() {
slice.iter().copied().map(f).map(Some).collect()
let new: Xob<ChunkedArray<T>> = slice.iter().copied().map(f).collect();
new.into_inner()
} else {
let mut ca: ChunkedArray<T> = self
.data_views()
Expand Down
48 changes: 5 additions & 43 deletions polars/src/chunked_array/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,7 @@ where

fn add(self, rhs: N) -> Self::Output {
let adder: T::Native = NumCast::from(rhs).unwrap();
if self.is_optimal_aligned() {
let intermed: Xob<_> = self.into_no_null_iter().map(|val| val + adder).collect();
intermed.into_inner()
} else {
self.into_iter()
.map(|opt_val| opt_val.map(|val| val + adder))
.collect()
}
self.apply(|val| val + adder)
}
}

Expand All @@ -326,14 +319,7 @@ where

fn sub(self, rhs: N) -> Self::Output {
let subber: T::Native = NumCast::from(rhs).unwrap();
if self.is_optimal_aligned() {
let intermed: Xob<_> = self.into_no_null_iter().map(|val| val - subber).collect();
intermed.into_inner()
} else {
self.into_iter()
.map(|opt_val| opt_val.map(|val| val - subber))
.collect()
}
self.apply(|val| val - subber)
}
}

Expand All @@ -352,14 +338,7 @@ where

fn div(self, rhs: N) -> Self::Output {
let divider: T::Native = NumCast::from(rhs).unwrap();
if self.is_optimal_aligned() {
let intermed: Xob<_> = self.into_no_null_iter().map(|val| val / divider).collect();
intermed.into_inner()
} else {
self.into_iter()
.map(|opt_val| opt_val.map(|val| val / divider))
.collect()
}
self.apply(|val| val / divider)
}
}

Expand All @@ -378,17 +357,7 @@ where

fn mul(self, rhs: N) -> Self::Output {
let multiplier: T::Native = NumCast::from(rhs).unwrap();
if self.is_optimal_aligned() {
let intermed: Xob<_> = self
.into_no_null_iter()
.map(|val| val * multiplier)
.collect();
intermed.into_inner()
} else {
self.into_iter()
.map(|opt_val| opt_val.map(|val| val * multiplier))
.collect()
}
self.apply(|val| val * multiplier)
}
}

Expand All @@ -403,14 +372,7 @@ where

fn rem(self, rhs: N) -> Self::Output {
let operand: T::Native = NumCast::from(rhs).unwrap();
if self.is_optimal_aligned() {
let intermed: Xob<_> = self.into_no_null_iter().map(|val| val % operand).collect();
intermed.into_inner()
} else {
self.into_iter()
.map(|opt_val| opt_val.map(|val| val % operand))
.collect()
}
self.apply(|val| val % operand)
}
}

Expand Down
10 changes: 7 additions & 3 deletions polars/src/doc/changelog/v0_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
//! * melt operation
//! * df! macro
//! * Rem trait implemented for Series and ChunkedArrays
//! * ChunkedArrays broadcasting arithmetic
//! * laziness api initiated.
//! - PredicatePushdown Optimizer
//! - ProjectionPushdown Optimizer
//! - Predicate pushdown optimizer
//! - Projection pushdown optimizer
//! - Type coercion optimizer
//! - Selection (filter, where clause)
//! - Projection (select foo from bar)
//! - Aggregation (groupby)
//! - all eager aggregations supported
//! - Joins
//! - DSL (col, lit, lt, lt_eq, alias, etc.)
//! - DSL
//! * (col, lit, lt, lt_eq, alias, etc.)
//! * arithmetic

0 comments on commit 0b98992

Please sign in to comment.