rolling.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2024, 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 
20 #include <cudf/types.hpp>
21 
22 #include <rmm/mr/device/per_device_resource.hpp>
23 #include <rmm/resource_ref.hpp>
24 
25 #include <memory>
26 
27 namespace cudf {
64 std::unique_ptr<column> rolling_window(
65  column_view const& input,
66  size_type preceding_window,
67  size_type following_window,
68  size_type min_periods,
69  rolling_aggregation const& agg,
70  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
71 
86 std::unique_ptr<column> rolling_window(
87  column_view const& input,
88  column_view const& default_outputs,
89  size_type preceding_window,
90  size_type following_window,
91  size_type min_periods,
92  rolling_aggregation const& agg,
93  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
94 
98 struct window_bounds {
99  public:
106  static window_bounds get(size_type value) { return window_bounds(false, value); }
107 
114  {
115  return window_bounds(true, std::numeric_limits<cudf::size_type>::max());
116  }
117 
124  [[nodiscard]] bool is_unbounded() const { return _is_unbounded; }
125 
131  [[nodiscard]] size_type value() const { return _value; }
132 
133  private:
134  explicit window_bounds(bool is_unbounded_, size_type value_ = 0)
135  : _is_unbounded{is_unbounded_}, _value{value_}
136  {
137  }
138 
139  bool const _is_unbounded;
140  size_type const _value;
141 };
142 
234 std::unique_ptr<column> grouped_rolling_window(
235  table_view const& group_keys,
236  column_view const& input,
237  size_type preceding_window,
238  size_type following_window,
239  size_type min_periods,
240  rolling_aggregation const& aggr,
241  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
242 
254 std::unique_ptr<column> grouped_rolling_window(
255  table_view const& group_keys,
256  column_view const& input,
257  window_bounds preceding_window,
258  window_bounds following_window,
259  size_type min_periods,
260  rolling_aggregation const& aggr,
261  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
262 
278 std::unique_ptr<column> grouped_rolling_window(
279  table_view const& group_keys,
280  column_view const& input,
281  column_view const& default_outputs,
282  size_type preceding_window,
283  size_type following_window,
284  size_type min_periods,
285  rolling_aggregation const& aggr,
286  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
287 
300 std::unique_ptr<column> grouped_rolling_window(
301  table_view const& group_keys,
302  column_view const& input,
303  column_view const& default_outputs,
304  window_bounds preceding_window,
305  window_bounds following_window,
306  size_type min_periods,
307  rolling_aggregation const& aggr,
308  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
309 
394 std::unique_ptr<column> grouped_time_range_rolling_window(
395  table_view const& group_keys,
396  column_view const& timestamp_column,
397  cudf::order const& timestamp_order,
398  column_view const& input,
399  size_type preceding_window_in_days,
400  size_type following_window_in_days,
401  size_type min_periods,
402  rolling_aggregation const& aggr,
403  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
404 
423 std::unique_ptr<column> grouped_time_range_rolling_window(
424  table_view const& group_keys,
425  column_view const& timestamp_column,
426  cudf::order const& timestamp_order,
427  column_view const& input,
428  window_bounds preceding_window_in_days,
429  window_bounds following_window_in_days,
430  size_type min_periods,
431  rolling_aggregation const& aggr,
432  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
433 
543 std::unique_ptr<column> grouped_range_rolling_window(
544  table_view const& group_keys,
545  column_view const& orderby_column,
546  cudf::order const& order,
547  column_view const& input,
548  range_window_bounds const& preceding,
549  range_window_bounds const& following,
550  size_type min_periods,
551  rolling_aggregation const& aggr,
552  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
553 
589 std::unique_ptr<column> rolling_window(
590  column_view const& input,
591  column_view const& preceding_window,
592  column_view const& following_window,
593  size_type min_periods,
594  rolling_aggregation const& agg,
595  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
596  // end of group
598 } // namespace cudf
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
Derived class intended for rolling_window specific aggregation usage.
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:187
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::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Applies a grouping-aware, value range-based rolling window function to the values in a column.
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::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Applies a grouping-aware, fixed-size rolling window function to the values in a column.
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::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Applies a fixed-size rolling window function to the values in a column.
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::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Applies a grouping-aware, timestamp-based rolling window function to the values in a column.
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:93
order
Indicates the order in which elements should be sorted.
Definition: types.hpp:116
cuDF interfaces
Definition: aggregation.hpp:34
Abstraction for window boundary sizes, to be used with grouped_range_rolling_window().
Abstraction for window boundary sizes.
Definition: rolling.hpp:98
static window_bounds unbounded()
Construct unbounded window boundary.
Definition: rolling.hpp:113
size_type value() const
Gets the row-boundary for this window_bounds.
Definition: rolling.hpp:131
bool is_unbounded() const
Definition: rolling.hpp:124
static window_bounds get(size_type value)
Construct bounded window boundary.
Definition: rolling.hpp:106
Type declarations for libcudf.