-
Notifications
You must be signed in to change notification settings - Fork 915
/
range_window_bounds.cpp
97 lines (85 loc) · 3.69 KB
/
range_window_bounds.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2021-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "detail/range_window_bounds.hpp"
#include <cudf/rolling/range_window_bounds.hpp>
#include <cudf/scalar/scalar_factories.hpp>
#include <cudf/types.hpp>
#include <cudf/wrappers/durations.hpp>
namespace cudf {
namespace {
/**
* @brief Factory to (copy) construct scalars.
*
* Derived types of scalars are cloned, to be adopted by `range_window_bounds`.
* This makes it possible to copy construct and copy assign `range_window_bounds` objects.
*/
struct range_scalar_constructor {
template <typename T, CUDF_ENABLE_IF(not detail::is_supported_range_type<T>())>
std::unique_ptr<scalar> operator()(scalar const& range_scalar_,
rmm::cuda_stream_view stream) const
{
CUDF_FAIL(
"Unsupported range type. "
"Only durations, fixed-point, and non-boolean numeric range types are allowed.");
}
template <typename T, CUDF_ENABLE_IF(cudf::is_duration<T>())>
std::unique_ptr<scalar> operator()(scalar const& range_scalar_,
rmm::cuda_stream_view stream) const
{
return std::make_unique<duration_scalar<T>>(
static_cast<duration_scalar<T> const&>(range_scalar_), stream);
}
template <typename T, CUDF_ENABLE_IF(cudf::is_numeric<T>() && not cudf::is_boolean<T>())>
std::unique_ptr<scalar> operator()(scalar const& range_scalar_,
rmm::cuda_stream_view stream) const
{
return std::make_unique<numeric_scalar<T>>(static_cast<numeric_scalar<T> const&>(range_scalar_),
stream);
}
template <typename T, CUDF_ENABLE_IF(cudf::is_fixed_point<T>())>
std::unique_ptr<scalar> operator()(scalar const& range_scalar_,
rmm::cuda_stream_view stream) const
{
return std::make_unique<fixed_point_scalar<T>>(
static_cast<fixed_point_scalar<T> const&>(range_scalar_), stream);
}
};
} // namespace
range_window_bounds::range_window_bounds(extent_type extent_,
std::unique_ptr<scalar> range_scalar_,
rmm::cuda_stream_view stream)
: _extent{extent_}, _range_scalar{std::move(range_scalar_)}
{
CUDF_EXPECTS(_range_scalar.get(), "Range window scalar cannot be null.");
CUDF_EXPECTS(_extent == extent_type::UNBOUNDED || _extent == extent_type::CURRENT_ROW ||
_range_scalar->is_valid(stream),
"Bounded Range window scalar must be valid.");
}
range_window_bounds range_window_bounds::unbounded(data_type type, rmm::cuda_stream_view stream)
{
return {extent_type::UNBOUNDED, make_default_constructed_scalar(type, stream), stream};
}
range_window_bounds range_window_bounds::current_row(data_type type, rmm::cuda_stream_view stream)
{
return {extent_type::CURRENT_ROW, make_default_constructed_scalar(type, stream), stream};
}
range_window_bounds range_window_bounds::get(scalar const& boundary, rmm::cuda_stream_view stream)
{
return {extent_type::BOUNDED,
cudf::type_dispatcher(boundary.type(), range_scalar_constructor{}, boundary, stream),
stream};
}
} // namespace cudf