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 
23 
24 #include <memory>
25 
26 namespace cudf {
63 std::unique_ptr<column> rolling_window(
64  column_view const& input,
65  size_type preceding_window,
66  size_type following_window,
67  size_type min_periods,
68  rolling_aggregation const& agg,
69  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
70 
85 std::unique_ptr<column> rolling_window(
86  column_view const& input,
87  column_view const& default_outputs,
88  size_type preceding_window,
89  size_type following_window,
90  size_type min_periods,
91  rolling_aggregation const& agg,
92  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
93 
97 struct window_bounds {
98  public:
105  static window_bounds get(size_type value) { return window_bounds(false, value); }
106 
113  {
114  return window_bounds(true, std::numeric_limits<cudf::size_type>::max());
115  }
116 
117  // TODO: In the future, add units for bounds.
118  // E.g. {value=1, unit=DAYS, unbounded=false}
119  // For the present, assume units from context:
120  // 1. For time-based window functions, assume DAYS as before
121  // 2. For all else, assume ROWS as before.
122  const bool is_unbounded;
123  const size_type value;
124 
125  private:
126  explicit window_bounds(bool is_unbounded_, size_type value_ = 0)
127  : is_unbounded{is_unbounded_}, value{value_}
128  {
129  }
130 };
131 
203 std::unique_ptr<column> grouped_rolling_window(
204  table_view const& group_keys,
205  column_view const& input,
206  size_type preceding_window,
207  size_type following_window,
208  size_type min_periods,
209  rolling_aggregation const& aggr,
210  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
211 
223 std::unique_ptr<column> grouped_rolling_window(
224  table_view const& group_keys,
225  column_view const& input,
226  window_bounds preceding_window,
227  window_bounds following_window,
228  size_type min_periods,
229  rolling_aggregation const& aggr,
230  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
231 
247 std::unique_ptr<column> grouped_rolling_window(
248  table_view const& group_keys,
249  column_view const& input,
250  column_view const& default_outputs,
251  size_type preceding_window,
252  size_type following_window,
253  size_type min_periods,
254  rolling_aggregation const& aggr,
255  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
256 
269 std::unique_ptr<column> grouped_rolling_window(
270  table_view const& group_keys,
271  column_view const& input,
272  column_view const& default_outputs,
273  window_bounds preceding_window,
274  window_bounds following_window,
275  size_type min_periods,
276  rolling_aggregation const& aggr,
277  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
278 
363 std::unique_ptr<column> grouped_time_range_rolling_window(
364  table_view const& group_keys,
365  column_view const& timestamp_column,
366  cudf::order const& timestamp_order,
367  column_view const& input,
368  size_type preceding_window_in_days,
369  size_type following_window_in_days,
370  size_type min_periods,
371  rolling_aggregation const& aggr,
372  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
373 
392 std::unique_ptr<column> grouped_time_range_rolling_window(
393  table_view const& group_keys,
394  column_view const& timestamp_column,
395  cudf::order const& timestamp_order,
396  column_view const& input,
397  window_bounds preceding_window_in_days,
398  window_bounds following_window_in_days,
399  size_type min_periods,
400  rolling_aggregation const& aggr,
401  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
402 
512 std::unique_ptr<column> grouped_range_rolling_window(
513  table_view const& group_keys,
514  column_view const& orderby_column,
515  cudf::order const& order,
516  column_view const& input,
517  range_window_bounds const& preceding,
518  range_window_bounds const& following,
519  size_type min_periods,
520  rolling_aggregation const& aggr,
521  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
522 
558 std::unique_ptr<column> rolling_window(
559  column_view const& input,
560  column_view const& preceding_window,
561  column_view const& following_window,
562  size_type min_periods,
563  rolling_aggregation const& agg,
564  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
565  // end of group
567 } // namespace cudf
per_device_resource.hpp
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::window_bounds::is_unbounded
const bool is_unbounded
Whether the window boundary is unbounded.
Definition: rolling.hpp:122
cudf::size_type
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:80
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:322
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:97
cudf::table_view
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:187
cudf::window_bounds::value
const size_type value
Finite window boundary value (in days or rows)
Definition: rolling.hpp:123
cudf::window_bounds::get
static window_bounds get(size_type value)
Construct bounded window boundary.
Definition: rolling.hpp:105
cudf::window_bounds::unbounded
static window_bounds unbounded()
Construct unbounded window boundary.
Definition: rolling.hpp:112
cudf
cuDF interfaces
Definition: aggregation.hpp:34
cudf::rolling_aggregation
Derived class intended for rolling_window specific aggregation usage.
Definition: aggregation.hpp:182
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:111