Transformation Binaryops#

group Binary Operations

Typedefs

template<typename L, typename R>
using binary_op_common_type_t = typename binary_op_common_type<L, R>::type#

Binary operation common type helper.

Enums

enum class binary_operator : int32_t#

Types of binary operations that can be performed on data.

Values:

enumerator ADD#

operator +

enumerator SUB#

operator -

enumerator MUL#

operator *

enumerator DIV#

operator / using common type of lhs and rhs

enumerator TRUE_DIV#

operator / after promoting type to floating point

enumerator FLOOR_DIV#

operator // integer division rounding towards negative infinity if both arguments are integral; floor division for floating types (using C++ type promotion for mixed integral/floating arguments) If different promotion semantics are required, it is the responsibility of the caller to promote manually before calling in to this function.

enumerator MOD#

operator %

enumerator PMOD#

positive modulo operator If remainder is negative, this returns (remainder + divisor) % divisor else, it returns (dividend % divisor)

enumerator PYMOD#

operator % but following Python’s sign rules for negatives

enumerator POW#

lhs ^ rhs

enumerator INT_POW#

int ^ int, used to avoid floating point precision loss. Returns 0 for negative exponents.

enumerator LOG_BASE#

logarithm to the base

enumerator ATAN2#

2-argument arctangent

enumerator SHIFT_LEFT#

operator <<

enumerator SHIFT_RIGHT#

operator >>

enumerator SHIFT_RIGHT_UNSIGNED#

operator >>> (from Java) Logical right shift. Casts to an unsigned value before shifting.

enumerator BITWISE_AND#

operator &

enumerator BITWISE_OR#

operator |

enumerator BITWISE_XOR#

operator ^

enumerator LOGICAL_AND#

operator &&: returns NULL when either operand is NULL, otherwise returns true only if both operands are true

enumerator LOGICAL_OR#

operator ||: returns NULL when either operand is NULL, otherwise returns true only if either or both operands are true

enumerator EQUAL#

operator ==: returns NULL when either operand is NULL, otherwise returns whether they are equal

enumerator NOT_EQUAL#

operator !=: returns NULL when either operand is NULL, otherwise returns whether they are unequal

enumerator LESS#

operator <

enumerator GREATER#

operator >

enumerator LESS_EQUAL#

operator <=

enumerator GREATER_EQUAL#

operator >=

enumerator NULL_EQUALS#

null-safe equality (result is never null): returns true if both operands are null, false if one is null, otherwise returns whether they are equal

enumerator NULL_NOT_EQUALS#

null-safe inequality (result is never null): returns false if both operands are null, true if one is null, otherwise returns whether they are unequal

enumerator NULL_MAX#

Returns max of operands when both are non-null; returns the non-null operand when one is null; or invalid when both are null

enumerator NULL_MIN#

Returns min of operands when both are non-null; returns the non-null operand when one is null; or invalid when both are null

enumerator GENERIC_BINARY#

generic binary operator to be generated with input ptx code

enumerator NULL_LOGICAL_AND#

three-valued (Kleene) &&: if any operand is false, returns false; if both operands are true, returns true; otherwise returns null

enumerator NULL_LOGICAL_OR#

three-valued (Kleene) ||: if any operand is true, returns true; if both operands are false, returns false; otherwise returns null

enumerator INVALID_BINARY#

invalid operation

Functions

std::unique_ptr<column> binary_operation(
scalar const &lhs,
column_view const &rhs,
binary_operator op,
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 a scalar and a column.

The output contains the result of op(lhs, rhs[i]) for all 0 <= i < rhs.size() The scalar is the left operand and the column elements are the right operand. This distinction is significant in case of non-commutative binary operations

Regardless of the operator, the validity of the output value is the logical AND of the validity of the two operands, except NULL_MIN and NULL_MAX (logical OR), NULL_EQUALS and NULL_NOT_EQUALS (always valid), and NULL_LOGICAL_AND and NULL_LOGICAL_OR (see binary_operator).

Parameters:
  • lhs – The left operand scalar

  • rhs – The right operand column

  • op – The binary operator

  • output_type – The desired data type of the output column

  • stream – CUDA stream used for device memory operations and kernel launches

  • mr – Device memory resource used to allocate the returned column’s device memory

Throws:
  • cudf::logic_error – if output_type dtype isn’t fixed-width

  • cudf::logic_error – if output_type dtype isn’t boolean for comparison and logical operations.

  • cudf::data_type_error – if the operation is not supported for the types of lhs and rhs

Returns:

Output column of output_type type containing the result of the binary operation

std::unique_ptr<column> binary_operation(
column_view const &lhs,
scalar const &rhs,
binary_operator op,
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 a column and a scalar.

The output contains the result of op(lhs[i], rhs) for all 0 <= i < lhs.size() The column elements are the left operand and the scalar is the right operand. This distinction is significant in case of non-commutative binary operations

Regardless of the operator, the validity of the output value is the logical AND of the validity of the two operands, except NULL_MIN and NULL_MAX (logical OR), NULL_EQUALS and NULL_NOT_EQUALS (always valid), and NULL_LOGICAL_AND and NULL_LOGICAL_OR (see binary_operator).

Parameters:
  • lhs – The left operand column

  • rhs – The right operand scalar

  • op – The binary operator

  • output_type – The desired data type of the output column

  • stream – CUDA stream used for device memory operations and kernel launches

  • mr – Device memory resource used to allocate the returned column’s device memory

Throws:
  • cudf::logic_error – if output_type dtype isn’t fixed-width

  • cudf::logic_error – if output_type dtype isn’t boolean for comparison and logical operations.

  • cudf::data_type_error – if the operation is not supported for the types of lhs and rhs

Returns:

Output column of output_type type containing the result of the binary operation

std::unique_ptr<column> binary_operation(
column_view const &lhs,
column_view const &rhs,
binary_operator op,
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.

The output contains the result of op(lhs[i], rhs[i]) for all 0 <= i < lhs.size()

Regardless of the operator, the validity of the output value is the logical AND of the validity of the two operands, except NULL_MIN and NULL_MAX (logical OR), NULL_EQUALS and NULL_NOT_EQUALS (always valid), and NULL_LOGICAL_AND and NULL_LOGICAL_OR (see binary_operator).

Parameters:
  • lhs – The left operand column

  • rhs – The right operand column

  • op – The binary operator

  • output_type – The desired data type of the output column

  • stream – CUDA stream used for device memory operations and kernel launches

  • mr – Device memory resource used to allocate the returned column’s device memory

Throws:
Returns:

Output column of output_type type containing the result of the binary operation

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.

The output contains the result of op(lhs[i], rhs[i]) for all 0 <= i < lhs.size()

Regardless of the operator, the validity of the output value is the logical AND of the validity of the two operands

Parameters:
  • lhs – The left operand column

  • rhs – The right operand column

  • ptx – String containing the PTX of a binary function

  • output_type – The desired data type of the output column. It is assumed that output_type is compatible with the output data type of the function in the PTX code

  • stream – CUDA stream used for device memory operations and kernel launches

  • mr – Device memory resource used to allocate the returned column’s device memory

Throws:
Returns:

Output column of output_type type containing the result of the binary operation

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

Parameters:
  • op – The binary_operator used for two fixed_point numbers

  • left_scale – Scale of left fixed_point number

  • right_scale – Scale of right fixed_point number

Returns:

The resulting scale of the computed fixed_point number

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

Parameters:
  • op – The binary_operator used for two fixed_point numbers

  • lhscudf::data_type of left fixed_point number

  • rhscudf::data_type of right fixed_point number

Returns:

The resulting cudf::data_type of the computed fixed_point number

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.

Parameters:
Returns:

true if the binary operator is supported for the given input types

Variables

template<typename L, typename R>
constexpr bool binary_op_has_common_type_v = detail::binary_op_has_common_type_impl<void, L, R>::value#

Checks if binary operation types have a common type.

template<typename L, typename R, typename = void>
struct binary_op_common_type#
#include <cudf/binaryop.hpp>

Binary operation common type default.

template<typename L, typename R>
struct binary_op_common_type<L, R, std::enable_if_t<has_common_type_v<L, R>>>#
#include <cudf/binaryop.hpp>

Binary operation common type specialization.

Public Types

using type = std::common_type_t<L, R>#

The common type of the template parameters.

template<typename L, typename R>
struct binary_op_common_type<L, R, std::enable_if_t<is_fixed_point<L>() && cuda::std::is_floating_point_v<R>>>#
#include <cudf/binaryop.hpp>

Binary operation common type specialization.

Public Types

using type = L#

The common type of the template parameters.

template<typename L, typename R>
struct binary_op_common_type<L, R, std::enable_if_t<is_fixed_point<R>() && cuda::std::is_floating_point_v<L>>>#
#include <cudf/binaryop.hpp>

Binary operation common type specialization.

Public Types

using type = R#

The common type of the template parameters.