rolling.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2022, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cudf/rolling/range_window_bounds.hpp>
20 #include <cudf/types.hpp>
21 
22 #include <memory>
23 
24 namespace cudf {
61 std::unique_ptr<column> rolling_window(
62  column_view const& input,
63  size_type preceding_window,
64  size_type following_window,
65  size_type min_periods,
66  rolling_aggregation const& agg,
67  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
68 
83 std::unique_ptr<column> rolling_window(
84  column_view const& input,
85  column_view const& default_outputs,
86  size_type preceding_window,
87  size_type following_window,
88  size_type min_periods,
89  rolling_aggregation const& agg,
90  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
91 
95 struct window_bounds {
96  public:
102  static window_bounds get(size_type value) { return window_bounds(false, value); }
103 
110  {
111  return window_bounds(true, std::numeric_limits<cudf::size_type>::max());
112  }
113 
114  // TODO: In the future, add units for bounds.
115  // E.g. {value=1, unit=DAYS, unbounded=false}
116  // For the present, assume units from context:
117  // 1. For time-based window functions, assume DAYS as before
118  // 2. For all else, assume ROWS as before.
119  const bool is_unbounded;
120  const size_type value;
121 
122  private:
123  explicit window_bounds(bool is_unbounded_, size_type value_ = 0)
124  : is_unbounded{is_unbounded_}, value{value_}
125  {
126  }
127 };
128 
200 std::unique_ptr<column> grouped_rolling_window(
201  table_view const& group_keys,
202  column_view const& input,
203  size_type preceding_window,
204  size_type following_window,
205  size_type min_periods,
206  rolling_aggregation const& aggr,
207  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
208 
220 std::unique_ptr<column> grouped_rolling_window(
221  table_view const& group_keys,
222  column_view const& input,
223  window_bounds preceding_window,
224  window_bounds following_window,
225  size_type min_periods,
226  rolling_aggregation const& aggr,
227  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
228 
244 std::unique_ptr<column> grouped_rolling_window(
245  table_view const& group_keys,
246  column_view const& input,
247  column_view const& default_outputs,
248  size_type preceding_window,
249  size_type following_window,
250  size_type min_periods,
251  rolling_aggregation const& aggr,
252  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
253 
266 std::unique_ptr<column> grouped_rolling_window(
267  table_view const& group_keys,
268  column_view const& input,
269  column_view const& default_outputs,
270  window_bounds preceding_window,
271  window_bounds following_window,
272  size_type min_periods,
273  rolling_aggregation const& aggr,
274  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
275 
360 std::unique_ptr<column> grouped_time_range_rolling_window(
361  table_view const& group_keys,
362  column_view const& timestamp_column,
363  cudf::order const& timestamp_order,
364  column_view const& input,
365  size_type preceding_window_in_days,
366  size_type following_window_in_days,
367  size_type min_periods,
368  rolling_aggregation const& aggr,
369  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
370 
404 std::unique_ptr<column> grouped_time_range_rolling_window(
405  table_view const& group_keys,
406  column_view const& timestamp_column,
407  cudf::order const& timestamp_order,
408  column_view const& input,
409  window_bounds preceding_window_in_days,
410  window_bounds following_window_in_days,
411  size_type min_periods,
412  rolling_aggregation const& aggr,
413  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
414 
524 std::unique_ptr<column> grouped_range_rolling_window(
525  table_view const& group_keys,
526  column_view const& orderby_column,
527  cudf::order const& order,
528  column_view const& input,
529  range_window_bounds const& preceding,
530  range_window_bounds const& following,
531  size_type min_periods,
532  rolling_aggregation const& aggr,
533  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
534 
570 std::unique_ptr<column> rolling_window(
571  column_view const& input,
572  column_view const& preceding_window,
573  column_view const& following_window,
574  size_type min_periods,
575  rolling_aggregation const& agg,
576  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
577  // end of group
579 } // namespace cudf
cudf::grouped_rolling_window
std::unique_ptr< column > grouped_rolling_window(table_view const &group_keys, column_view const &input, size_type preceding_window, size_type following_window, size_type min_periods, rolling_aggregation const &aggr, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Applies a grouping-aware, fixed-size rolling window function to the values in a column.
cudf::size_type
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:84
cudf::column_view
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
Definition: column_view.hpp:300
types.hpp
Type declarations for libcudf.
cudf::range_window_bounds
Abstraction for window boundary sizes, to be used with grouped_range_rolling_window().
Definition: range_window_bounds.hpp:36
cudf::rolling_window
std::unique_ptr< column > rolling_window(column_view const &input, size_type preceding_window, size_type following_window, size_type min_periods, rolling_aggregation const &agg, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Applies a fixed-size rolling window function to the values in a column.
cudf::grouped_time_range_rolling_window
std::unique_ptr< column > grouped_time_range_rolling_window(table_view const &group_keys, column_view const &timestamp_column, cudf::order const &timestamp_order, column_view const &input, size_type preceding_window_in_days, size_type following_window_in_days, size_type min_periods, rolling_aggregation const &aggr, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Applies a grouping-aware, timestamp-based rolling window function to the values in a column.
cudf::window_bounds
Abstraction for window boundary sizes.
Definition: rolling.hpp:95
cudf::table_view
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:154
cudf::window_bounds::get
static window_bounds get(size_type value)
Construct bounded window boundary.
Definition: rolling.hpp:102
cudf::window_bounds::unbounded
static window_bounds unbounded()
Construct unbounded window boundary.
Definition: rolling.hpp:109
cudf
cuDF interfaces
Definition: aggregation.hpp:34
cudf::rolling_aggregation
Derived class intended for rolling_window specific aggregation usage.
Definition: aggregation.hpp:144
cudf::grouped_range_rolling_window
std::unique_ptr< column > grouped_range_rolling_window(table_view const &group_keys, column_view const &orderby_column, cudf::order const &order, column_view const &input, range_window_bounds const &preceding, range_window_bounds const &following, size_type min_periods, rolling_aggregation const &aggr, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Applies a grouping-aware, value range-based rolling window function to the values in a column.
rmm::mr::device_memory_resource
cudf::order
order
Indicates the order in which elements should be sorted.
Definition: types.hpp:115