Skip to content

Commit

Permalink
Support min and max operations for structs in rolling window (#10332
Browse files Browse the repository at this point in the history
)

This PR adds support for `min` and `max` operations in rolling window for STRUCT type. It also does some minor modifications to the existing code, such as renaming some variables and refining some comments.

Partially addresses #8974.

Authors:
  - Nghia Truong (https://github.com/ttnghia)

Approvers:
  - Jake Hemstad (https://github.com/jrhemstad)
  - David Wendt (https://github.com/davidwendt)

URL: #10332
  • Loading branch information
ttnghia authored Mar 7, 2022
1 parent b782281 commit a584cdc
Show file tree
Hide file tree
Showing 3 changed files with 440 additions and 123 deletions.
10 changes: 5 additions & 5 deletions cpp/src/reductions/struct_minmax_util.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ namespace detail {
struct row_arg_minmax_fn {
size_type const num_rows;
row_lexicographic_comparator<nullate::DYNAMIC> const comp;
bool const arg_min;
bool const is_arg_min;

row_arg_minmax_fn(table_device_view const& table,
bool has_nulls,
null_order const* null_precedence,
bool const arg_min)
bool const is_arg_min)
: num_rows(table.num_rows()),
comp(nullate::DYNAMIC{has_nulls}, table, table, nullptr, null_precedence),
arg_min(arg_min)
is_arg_min(is_arg_min)
{
}

Expand All @@ -53,7 +53,7 @@ struct row_arg_minmax_fn {
// `thrust::reduce_by_key` or `thrust::scan_by_key` will result in significant compile time.
__attribute__((noinline)) __device__ auto operator()(size_type lhs_idx, size_type rhs_idx) const
{
// The extra bounds checking is due to issue github.com/rapidsai/cudf/9156 and
// The extra bounds checking is due to issue github.com/rapidsai/cudf/issues/9156 and
// github.com/NVIDIA/thrust/issues/1525
// where invalid random values may be passed here by thrust::reduce_by_key
if (lhs_idx < 0 || lhs_idx >= num_rows) { return rhs_idx; }
Expand All @@ -62,7 +62,7 @@ struct row_arg_minmax_fn {
// Return `lhs_idx` iff:
// row(lhs_idx) < row(rhs_idx) and finding ArgMin, or
// row(lhs_idx) >= row(rhs_idx) and finding ArgMax.
return comp(lhs_idx, rhs_idx) == arg_min ? lhs_idx : rhs_idx;
return comp(lhs_idx, rhs_idx) == is_arg_min ? lhs_idx : rhs_idx;
}
};

Expand Down
Loading

0 comments on commit a584cdc

Please sign in to comment.