Skip to content

Commit

Permalink
arr$max and arr$min behind feature "simd"
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Feb 10, 2024
1 parent a4279fa commit 097da1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 8 additions & 2 deletions R/expr__array.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ ExprArr_sum = function() .pr$Expr$arr_sum(self)
#' schema = list(values = pl$Array(pl$Float64, 2))
#' )
#' df$with_columns(max = pl$col("values")$arr$max())
ExprArr_max = function() .pr$Expr$arr_max(self)
ExprArr_max = function() {
.pr$Expr$arr_max(self) |>
unwrap("in $arr$max():")
}

# TODO: add example with NA when this is fixed:
# https://github.com/pola-rs/polars/issues/14359
Expand All @@ -38,7 +41,10 @@ ExprArr_max = function() .pr$Expr$arr_max(self)
#' schema = list(values = pl$Array(pl$Float64, 2))
#' )
#' df$with_columns(min = pl$col("values")$arr$min())
ExprArr_min = function() .pr$Expr$arr_min(self)
ExprArr_min = function() {
.pr$Expr$arr_min(self) |>
unwrap("in $arr$min():")
}

#' Sort values in an array
#'
Expand Down
16 changes: 12 additions & 4 deletions src/rust/src/lazy/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,12 +1184,20 @@ impl RPolarsExpr {

// array methods

fn arr_max(&self) -> Self {
self.0.clone().arr().max().into()
fn arr_max(&self) -> RResult<RPolarsExpr> {
#[cfg(feature = "simd")]
return (Ok(self.0.clone().arr().max().into()));

#[cfg(not(feature = "simd"))]
rerr().plain("$arr$max() is only available with the 'simd' feature")
}

fn arr_min(&self) -> Self {
self.0.clone().arr().min().into()
fn arr_min(&self) -> RResult<RPolarsExpr> {
#[cfg(feature = "simd")]
return (Ok(self.0.clone().arr().min().into()));

#[cfg(not(feature = "simd"))]
rerr().plain("$arr$min() is only available with the 'simd' feature")
}

fn arr_sum(&self) -> Self {
Expand Down

0 comments on commit 097da1a

Please sign in to comment.