Skip to content

Commit

Permalink
remove old pow
Browse files Browse the repository at this point in the history
  • Loading branch information
orlp committed Oct 16, 2024
1 parent f7eb162 commit bb8e15d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 36 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/polars-arrow/src/legacy/kernels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub mod ewm;
pub mod fixed_size_list;
#[cfg(feature = "compute_take")]
pub mod list;
pub mod pow;
pub mod rolling;
pub mod set;
pub mod sort_partition;
Expand Down
13 changes: 0 additions & 13 deletions crates/polars-arrow/src/legacy/kernels/pow.rs

This file was deleted.

1 change: 1 addition & 0 deletions crates/polars-plan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ either = { workspace = true }
futures = { workspace = true, optional = true }
hashbrown = { workspace = true }
memmap = { workspace = true }
num-traits = { workspace = true }
once_cell = { workspace = true }
percent-encoding = { workspace = true }
pyo3 = { workspace = true, optional = true }
Expand Down
41 changes: 19 additions & 22 deletions crates/polars-plan/src/dsl/function_expr/pow.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use arrow::legacy::kernels::pow::pow as pow_kernel;
use num::pow::Pow;
use num_traits::{Zero, One};
use polars_core::export::num;
use polars_core::export::num::{Float, ToPrimitive};
use polars_core::prelude::arity::unary_elementwise_values;
use polars_core::prelude::arity::{unary_elementwise_values, broadcast_binary_elementwise};
use polars_core::with_match_physical_integer_type;

use super::*;
Expand All @@ -29,30 +29,27 @@ impl Display for PowFunction {
fn pow_on_chunked_arrays<T, F>(
base: &ChunkedArray<T>,
exponent: &ChunkedArray<F>,
) -> PolarsResult<Option<Column>>
) -> ChunkedArray<T>
where
T: PolarsNumericType,
F: PolarsNumericType,
T::Native: num::pow::Pow<F::Native, Output = T::Native> + ToPrimitive,
ChunkedArray<T>: IntoColumn,
{
if (base.len() == 1) && (exponent.len() != 1) {
let name = base.name();
let base = base
.get(0)
.ok_or_else(|| polars_err!(ComputeError: "base is null"))?;

Ok(Some(
unary_elementwise_values(exponent, |exp| Pow::pow(base, exp))
.into_column()
.with_name(name.clone()),
))
} else {
Ok(Some(
polars_core::chunked_array::ops::arity::binary(base, exponent, pow_kernel)
.into_column(),
))
if exponent.len() == 1 {
if let Some(e) = exponent.get(0) {
if e == F::Native::zero() {
return unary_elementwise_values(base, |_| T::Native::one())
}
if e == F::Native::one() {
return base.clone();
}
if e == F::Native::one() + F::Native::one() {
return base * base;
}
}
}

broadcast_binary_elementwise(base, exponent, |b, e| Some(Pow::pow(b?, e?)))
}

fn pow_on_floats<T>(
Expand Down Expand Up @@ -93,7 +90,7 @@ where
};
Ok(Some(s))
} else {
pow_on_chunked_arrays(base, exponent)
Ok(Some(pow_on_chunked_arrays(base, exponent).into_column()))
}
}

Expand Down Expand Up @@ -133,7 +130,7 @@ where
};
Ok(Some(s))
} else {
pow_on_chunked_arrays(base, exponent)
Ok(Some(pow_on_chunked_arrays(base, exponent).into_column()))
}
}

Expand Down

0 comments on commit bb8e15d

Please sign in to comment.