binaryop.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
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 
20 namespace CUDF_EXPORT cudf {
21 
30 enum class binary_operator : int32_t {
31  ADD,
32  SUB,
33  MUL,
34  DIV,
35  TRUE_DIV,
36  FLOOR_DIV,
44  MOD,
45  PMOD,
48  PYMOD,
49  POW,
50  INT_POW,
52  LOG_BASE,
53  ATAN2,
54  SHIFT_LEFT,
55  SHIFT_RIGHT,
58  BITWISE_AND,
59  BITWISE_OR,
60  BITWISE_XOR,
61  LOGICAL_AND,
63  LOGICAL_OR,
65  EQUAL,
67  NOT_EQUAL,
69  LESS,
70  GREATER,
71  LESS_EQUAL,
72  GREATER_EQUAL,
73  NULL_EQUALS,
79  NULL_MAX,
81  NULL_MIN,
85  NULL_LOGICAL_AND,
87  NULL_LOGICAL_OR,
90 };
91 
93 template <typename L, typename R, typename = void>
95 
97 template <typename L, typename R>
98 struct binary_op_common_type<L, R, std::enable_if_t<has_common_type_v<L, R>>> {
100  using type = std::common_type_t<L, R>;
101 };
102 
104 template <typename L, typename R>
106  L,
107  R,
108  std::enable_if_t<is_fixed_point<L>() && cuda::std::is_floating_point_v<R>>> {
110  using type = L;
111 };
112 
114 template <typename L, typename R>
116  L,
117  R,
118  std::enable_if_t<is_fixed_point<R>() && cuda::std::is_floating_point_v<L>>> {
120  using type = R;
121 };
122 
124 template <typename L, typename R>
126 
127 namespace detail {
128 template <typename AlwaysVoid, typename L, typename R>
129 struct binary_op_has_common_type_impl : std::false_type {};
130 
131 template <typename L, typename R>
132 struct binary_op_has_common_type_impl<std::void_t<binary_op_common_type_t<L, R>>, L, R>
133  : std::true_type {};
134 } // namespace detail
135 
137 template <typename L, typename R>
138 constexpr inline bool binary_op_has_common_type_v =
139  detail::binary_op_has_common_type_impl<void, L, R>::value;
140 
166 std::unique_ptr<column> binary_operation(
167  scalar const& lhs,
168  column_view const& rhs,
169  binary_operator op,
170  data_type output_type,
171  cuda::stream_ref stream = cudf::get_default_stream(),
173 
199 std::unique_ptr<column> binary_operation(
200  column_view const& lhs,
201  scalar const& rhs,
202  binary_operator op,
203  data_type output_type,
204  cuda::stream_ref stream = cudf::get_default_stream(),
206 
231 std::unique_ptr<column> binary_operation(
232  column_view const& lhs,
233  column_view const& rhs,
234  binary_operator op,
235  data_type output_type,
236  cuda::stream_ref stream = cudf::get_default_stream(),
238 
262 std::unique_ptr<column> binary_operation(
263  column_view const& lhs,
264  column_view const& rhs,
265  std::string const& ptx,
266  data_type output_type,
267  cuda::stream_ref stream = cudf::get_default_stream(),
269 
279  int32_t left_scale,
280  int32_t right_scale);
281 
291  cudf::data_type const& lhs,
292  cudf::data_type const& rhs);
293 
294 namespace binops {
295 
307 
317 std::pair<rmm::device_buffer, size_type> scalar_col_valid_mask_and(
318  column_view const& col,
319  scalar const& s,
320  cuda::stream_ref stream = cudf::get_default_stream(),
322 
323 } // namespace binops
324  // end of group
326 } // namespace CUDF_EXPORT cudf
327 
328 namespace CUDF_EXPORT cudf {
329 namespace binops::compiled::detail {
330 
343  column_view const& lhs,
344  column_view const& rhs,
345  bool is_lhs_scalar,
346  bool is_rhs_scalar,
347  binary_operator op,
348  cuda::stream_ref stream);
349 } // namespace binops::compiled::detail
350 } // namespace CUDF_EXPORT cudf
std::pair< rmm::device_buffer, size_type > scalar_col_valid_mask_and(column_view const &col, scalar const &s, cuda::stream_ref 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, cuda::stream_ref 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:279
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:42
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.
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:30
typename binary_op_common_type< L, R >::type binary_op_common_type_t
Binary operation common type helper.
Definition: binaryop.hpp:125
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, cuda::stream_ref 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:138
@ 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:30
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:27
Class definitions for cudf::scalar.
std::common_type_t< L, R > type
The common type of the template parameters.
Definition: binaryop.hpp:100
Binary operation common type default.
Definition: binaryop.hpp:94