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 6 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
13 changes: 12 additions & 1 deletion cpp/include/cudf/binaryop.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2023, NVIDIA CORPORATION.
* Copyright (c) 2019-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.
Expand Down Expand Up @@ -237,6 +237,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_binaryop(data_type out, data_type lhs, data_type rhs, binary_operator op);
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved

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

/**
* @brief Returns true if the binary operator is supported for the given input types
*/
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved
bool is_supported_binaryop(data_type out, data_type lhs, data_type rhs, binary_operator op)
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved
{
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 @@ -192,7 +200,7 @@ std::unique_ptr<column> binary_operation(LhsType const& lhs,
rmm::mr::device_memory_resource* 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
41 changes: 31 additions & 10 deletions python/cudf/cudf/_lib/cpp/binaryop.pxd
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

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

from cudf._lib.cpp.column.column cimport column
from cudf._lib.cpp.column.column_view cimport column_view
from cudf._lib.cpp.scalar.scalar cimport scalar
from cudf._lib.cpp.types cimport data_type
from cudf._lib.exception_handler cimport cudf_exception_handler


cdef extern from "cudf/binaryop.hpp" namespace "cudf" nogil:
Expand All @@ -19,47 +21,66 @@ 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
BITWISE_AND
BITWISE_OR
BITWISE_XOR
LOGICAL_AND
LOGICAL_OR
NULL_MAX
NULL_MIN
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_binaryop(
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved
data_type output_type,
data_type lhs_type,
data_type rhs_type,
binary_operator op
) except +cudf_exception_handler
14 changes: 14 additions & 0 deletions python/cudf/cudf/_lib/pylibcudf/binaryop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,17 @@ cpdef Column binary_operation(
raise ValueError(f"Invalid arguments {lhs} and {rhs}")

return Column.from_libcudf(move(result))


def _is_supported_binaryop(
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved
DataType out,
DataType lhs,
DataType rhs,
binary_operator op
):
return cpp_binaryop.is_supported_binaryop(
brandon-b-miller marked this conversation as resolved.
Show resolved Hide resolved
out.c_obj,
lhs.c_obj,
rhs.c_obj,
op
)
Loading
Loading