Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for pylibcudf binaryops #15470

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1b482bf
patch changes from original PR
brandon-b-miller Apr 4, 2024
0a46a0f
first halfway decent testing strategy
brandon-b-miller Apr 4, 2024
f5f33e6
refactor out a lot of repeated code
brandon-b-miller Apr 4, 2024
61ab85b
cleanup
brandon-b-miller Apr 4, 2024
ba03539
add some more tests
brandon-b-miller Apr 4, 2024
4911f33
start to work nulls in
brandon-b-miller Apr 5, 2024
9eba971
merge latest/resolve conflicts
brandon-b-miller Jul 1, 2024
562c765
start to refactor, pass add, almost sub
brandon-b-miller Jul 1, 2024
e533469
simpler approach
brandon-b-miller Jul 8, 2024
b81e017
Merge branch 'branch-24.08' into pylibcudf-binops-tests
brandon-b-miller Jul 8, 2024
e5f34e7
merge latest / resolve conflicts
brandon-b-miller Jul 9, 2024
322a7de
address reviews
brandon-b-miller Jul 9, 2024
ecbb895
refactor again
brandon-b-miller Jul 10, 2024
076b83d
address reviews, add tests
brandon-b-miller Jul 10, 2024
e06d5cd
fix a few ops
brandon-b-miller Jul 11, 2024
473845f
few more fixes
brandon-b-miller Jul 11, 2024
6e0c816
address more reviews
brandon-b-miller Jul 15, 2024
f0a62a9
Merge branch 'branch-24.08' into pylibcudf-binops-tests
brandon-b-miller Jul 16, 2024
77c709f
fix cpp test
brandon-b-miller Jul 16, 2024
4e653d6
fix atan2
brandon-b-miller Jul 16, 2024
6968f95
update assert_column_eq to handle nans
brandon-b-miller Jul 16, 2024
cc8afe9
only check nans for floating
brandon-b-miller Jul 16, 2024
12a748b
Merge branch 'branch-24.08' into pylibcudf-binops-tests
brandon-b-miller Jul 16, 2024
8c44149
address reviews
brandon-b-miller Jul 18, 2024
959e9a7
refactor again
brandon-b-miller Jul 18, 2024
367dfe9
merge /resolve
brandon-b-miller Jul 18, 2024
849e586
adjust docstring
brandon-b-miller Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cpp/include/cudf/binaryop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ cudf::data_type binary_operation_fixed_point_output_type(binary_operator op,

namespace binops {

/**
* @brief Returns true if the binary operator is supported for the given input types.
*
* @param out The output data type
* @param lhs The left-hand cudf::data_type
* @param rhs The right-hand cudf::data_type
* @param op The binary operator
* @return true if the binary operator is supported for the given input types
*/
bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also #16239. That PR exposes reflection for casting.


/**
* @brief Computes output valid mask for op between a column and a scalar
*
Expand Down
7 changes: 6 additions & 1 deletion cpp/src/binaryop/binaryop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
namespace cudf {
namespace binops {

bool is_supported_operation(data_type out, data_type lhs, data_type rhs, binary_operator op)
{
return cudf::binops::compiled::is_supported_operation(out, lhs, rhs, op);
}

/**
* @brief Computes output valid mask for op between a column and a scalar
*/
Expand Down Expand Up @@ -194,7 +199,7 @@ std::unique_ptr<column> binary_operation(LhsType const& lhs,
rmm::device_async_resource_ref mr)
{
if constexpr (std::is_same_v<LhsType, column_view> and std::is_same_v<RhsType, column_view>)
CUDF_EXPECTS(lhs.size() == rhs.size(), "Column sizes don't match");
CUDF_EXPECTS(lhs.size() == rhs.size(), "Column sizes don't match", std::invalid_argument);

if (lhs.type().id() == type_id::STRING and rhs.type().id() == type_id::STRING and
output_type.id() == type_id::STRING and
Expand Down
9 changes: 9 additions & 0 deletions python/cudf/cudf/_lib/pylibcudf/binaryop.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright (c) 2024, NVIDIA CORPORATION.

from libcpp cimport bool

from cudf._lib.pylibcudf.libcudf.binaryop cimport binary_operator

from .column cimport Column
Expand All @@ -22,3 +24,10 @@ cpdef Column binary_operation(
binary_operator op,
DataType output_type
)

cpdef bool is_supported_operation(
DataType out,
DataType lhs,
DataType rhs,
binary_operator op
)
37 changes: 37 additions & 0 deletions python/cudf/cudf/_lib/pylibcudf/binaryop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from cython.operator import dereference

from libcpp cimport bool
from libcpp.memory cimport unique_ptr
from libcpp.utility cimport move

Expand Down Expand Up @@ -84,3 +85,39 @@ cpdef Column binary_operation(
raise ValueError(f"Invalid arguments {lhs} and {rhs}")

return Column.from_libcudf(move(result))


cpdef bool is_supported_operation(
DataType out,
DataType lhs,
DataType rhs,
binary_operator op
):
"""Check if an operation is supported for the given data types.

Parameters
----------
out
Output data type
lhs
Left operand type
rhs
Right operand type
op
Binary operation to check
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
True if the operation is supported for the requested types.

See Also
--------
:cpp:func:`is_supported_operation`
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved
"""

return cpp_binaryop.is_supported_operation(
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved
out.c_obj,
lhs.c_obj,
rhs.c_obj,
op
)
39 changes: 30 additions & 9 deletions python/cudf/cudf/_lib/pylibcudf/libcudf/binaryop.pxd
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

from libc.stdint cimport int32_t
from libcpp cimport bool
from libcpp.memory cimport unique_ptr
from libcpp.string cimport string

from cudf._lib.exception_handler cimport cudf_exception_handler
from cudf._lib.pylibcudf.libcudf.column.column cimport column
from cudf._lib.pylibcudf.libcudf.column.column_view cimport column_view
from cudf._lib.pylibcudf.libcudf.scalar.scalar cimport scalar
Expand All @@ -19,48 +21,67 @@ cdef extern from "cudf/binaryop.hpp" namespace "cudf" nogil:
TRUE_DIV
FLOOR_DIV
MOD
PMOD
PYMOD
POW
INT_POW
LOG_BASE
ATAN2
SHIFT_LEFT
SHIFT_RIGHT
SHIFT_RIGHT_UNSIGNED
BITWISE_AND
BITWISE_OR
BITWISE_XOR
LOGICAL_AND
LOGICAL_OR
EQUAL
NOT_EQUAL
LESS
GREATER
LESS_EQUAL
GREATER_EQUAL
NULL_EQUALS
NULL_MAX
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved
NULL_MIN
NULL_NOT_EQUALS
BITWISE_AND
BITWISE_OR
BITWISE_XOR
LOGICAL_AND
LOGICAL_OR
GENERIC_BINARY
NULL_LOGICAL_AND
NULL_LOGICAL_OR
INVALID_BINARY

cdef unique_ptr[column] binary_operation (
const scalar& lhs,
const column_view& rhs,
binary_operator op,
data_type output_type
) except +
) except +cudf_exception_handler

cdef unique_ptr[column] binary_operation (
const column_view& lhs,
const scalar& rhs,
binary_operator op,
data_type output_type
) except +
) except +cudf_exception_handler

cdef unique_ptr[column] binary_operation (
const column_view& lhs,
const column_view& rhs,
binary_operator op,
data_type output_type
) except +
) except +cudf_exception_handler

cdef unique_ptr[column] binary_operation (
const column_view& lhs,
const column_view& rhs,
const string& op,
data_type output_type
) except +
) except +cudf_exception_handler

cdef extern from "cudf/binaryop.hpp" namespace "cudf::binops" nogil:
cdef bool is_supported_operation(
data_type output_type,
data_type lhs_type,
data_type rhs_type,
binary_operator op
) except +cudf_exception_handler
Loading
Loading