binaryop.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <cudf/column/column.hpp>
9 #include <cudf/scalar/scalar.hpp>
10 #include <cudf/utilities/export.hpp>
12 
13 #include <memory>
14 
15 namespace CUDF_EXPORT cudf {
16 
27 enum class binary_operator : int32_t {
28  ADD,
29  SUB,
30  MUL,
31  DIV,
32  TRUE_DIV,
33  FLOOR_DIV,
41  MOD,
42  PMOD,
45  PYMOD,
46  POW,
47  INT_POW,
49  LOG_BASE,
50  ATAN2,
51  SHIFT_LEFT,
52  SHIFT_RIGHT,
55  BITWISE_AND,
56  BITWISE_OR,
57  BITWISE_XOR,
58  LOGICAL_AND,
59  LOGICAL_OR,
60  EQUAL,
61  NOT_EQUAL,
62  LESS,
63  GREATER,
64  LESS_EQUAL,
65  GREATER_EQUAL,
66  NULL_EQUALS,
70  NULL_MAX,
72  NULL_MIN,
76  NULL_LOGICAL_AND,
78  NULL_LOGICAL_OR,
81 };
82 
84 template <typename L, typename R, typename = void>
86 
88 template <typename L, typename R>
89 struct binary_op_common_type<L, R, std::enable_if_t<has_common_type_v<L, R>>> {
91  using type = std::common_type_t<L, R>;
92 };
93 
95 template <typename L, typename R>
97  L,
98  R,
99  std::enable_if_t<is_fixed_point<L>() && cuda::std::is_floating_point_v<R>>> {
101  using type = L;
102 };
103 
105 template <typename L, typename R>
107  L,
108  R,
109  std::enable_if_t<is_fixed_point<R>() && cuda::std::is_floating_point_v<L>>> {
111  using type = R;
112 };
113 
115 template <typename L, typename R>
117 
118 namespace detail {
119 template <typename AlwaysVoid, typename L, typename R>
120 struct binary_op_has_common_type_impl : std::false_type {};
121 
122 template <typename L, typename R>
123 struct binary_op_has_common_type_impl<std::void_t<binary_op_common_type_t<L, R>>, L, R>
124  : std::true_type {};
125 } // namespace detail
126 
128 template <typename L, typename R>
129 constexpr inline bool binary_op_has_common_type_v =
130  detail::binary_op_has_common_type_impl<void, L, R>::value;
131 
155 std::unique_ptr<column> binary_operation(
156  scalar const& lhs,
157  column_view const& rhs,
158  binary_operator op,
159  data_type output_type,
162 
186 std::unique_ptr<column> binary_operation(
187  column_view const& lhs,
188  scalar const& rhs,
189  binary_operator op,
190  data_type output_type,
193 
216 std::unique_ptr<column> binary_operation(
217  column_view const& lhs,
218  column_view const& rhs,
219  binary_operator op,
220  data_type output_type,
223 
247 std::unique_ptr<column> binary_operation(
248  column_view const& lhs,
249  column_view const& rhs,
250  std::string const& ptx,
251  data_type output_type,
254 
264  int32_t left_scale,
265  int32_t right_scale);
266 
276  cudf::data_type const& lhs,
277  cudf::data_type const& rhs);
278 
279 namespace binops {
280 
292 
302 std::pair<rmm::device_buffer, size_type> scalar_col_valid_mask_and(
303  column_view const& col,
304  scalar const& s,
307 
308 } // namespace binops
309  // end of group
311 } // namespace CUDF_EXPORT cudf
312 
313 namespace CUDF_EXPORT cudf {
314 namespace binops::compiled::detail {
315 
328  column_view const& lhs,
329  column_view const& rhs,
330  bool is_lhs_scalar,
331  bool is_rhs_scalar,
332  binary_operator op,
333  rmm::cuda_stream_view stream);
334 } // namespace binops::compiled::detail
335 } // namespace CUDF_EXPORT cudf
std::pair< rmm::device_buffer, size_type > scalar_col_valid_mask_and(column_view const &col, scalar const &s, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Computes output valid mask for op between a column and a scalar.
void apply_sorting_struct_binary_op(mutable_column_view &out, column_view const &lhs, column_view const &rhs, bool is_lhs_scalar, bool is_rhs_scalar, binary_operator op, rmm::cuda_stream_view stream)
struct binary operation using NaN aware sorting physical element comparators
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
Indicator for the logical data type of an element in a column.
Definition: types.hpp:238
A non-owning, mutable view of device data as a column of elements, some of which may be null as indic...
An owning class to represent a singular value.
Definition: scalar.hpp:40
Class definition for cudf::column.
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
rmm::device_async_resource_ref get_current_device_resource_ref()
Get the current device memory resource reference.
detail::cccl_async_resource_ref< cuda::mr::resource_ref< cuda::mr::device_accessible > > device_async_resource_ref
binary_operator
Types of binary operations that can be performed on data.
Definition: binaryop.hpp:27
typename binary_op_common_type< L, R >::type binary_op_common_type_t
Binary operation common type helper.
Definition: binaryop.hpp:116
cudf::data_type binary_operation_fixed_point_output_type(binary_operator op, cudf::data_type const &lhs, cudf::data_type const &rhs)
Computes the data_type for a fixed_point number based on given binary operator op
bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op)
Returns true if the binary operator is supported for the given input types.
int32_t binary_operation_fixed_point_scale(binary_operator op, int32_t left_scale, int32_t right_scale)
Computes the scale for a fixed_point number based on given binary operator op
std::unique_ptr< column > binary_operation(column_view const &lhs, column_view const &rhs, std::string const &ptx, data_type output_type, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Performs a binary operation between two columns using a user-defined PTX function.
constexpr bool binary_op_has_common_type_v
Checks if binary operation types have a common type.
Definition: binaryop.hpp:129
@ INVALID_BINARY
invalid operation
@ LOG_BASE
logarithm to the base
@ SHIFT_LEFT
operator <<
@ SHIFT_RIGHT
operator >>
@ ATAN2
2-argument arctangent
void void_t
Utility metafunction that maps a sequence of any types to the type void.
Definition: traits.hpp:26
cuDF interfaces
Definition: host_udf.hpp:26
Class definitions for cudf::scalar.
std::common_type_t< L, R > type
The common type of the template parameters.
Definition: binaryop.hpp:91
Binary operation common type default.
Definition: binaryop.hpp:85