Skip to content

Commit

Permalink
Initial changes for binary_v_v
Browse files Browse the repository at this point in the history
  • Loading branch information
codereport committed Feb 24, 2021
1 parent 580f9a2 commit d07c35f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cpp/include/cudf/binaryop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ std::unique_ptr<column> binary_operation(
column_view const& lhs,
column_view const& rhs,
binary_operator op,
data_type output_type,
thrust::optional<data_type> output_type,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/cudf/detail/binaryop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::unique_ptr<column> binary_operation(
column_view const& lhs,
column_view const& rhs,
binary_operator op,
data_type output_type,
thrust::optional<data_type> output_type,
rmm::cuda_stream_view stream = rmm::cuda_stream_default,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

Expand Down
29 changes: 19 additions & 10 deletions cpp/src/binaryop/binaryop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,27 +783,36 @@ std::unique_ptr<column> binary_operation(column_view const& lhs,
std::unique_ptr<column> binary_operation(column_view const& lhs,
column_view const& rhs,
binary_operator op,
data_type output_type,
thrust::optional<data_type> output_type,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
CUDF_EXPECTS(lhs.size() == rhs.size(), "Column sizes don't match");

if (lhs.type().id() == type_id::STRING and rhs.type().id() == type_id::STRING)
return binops::compiled::binary_operation(lhs, rhs, op, output_type, stream, mr);

if (is_fixed_point(lhs.type()) or is_fixed_point(rhs.type())) {
auto const type =
op == binary_operator::TRUE_DIV ? output_type : thrust::optional<data_type>{thrust::nullopt};
return fixed_point_binary_operation(lhs, rhs, op, type, stream, mr);
if (op != binary_operator::TRUE_DIV) {
CUDF_EXPECTS(
not output_type.has_value(),
"Only TRUE_DIV supports specified output_type for fixed_point binary operations. For other "
"fixed_point binary operations, please pass {} or std::nullopt for output_type and the "
"cudf::data_type and numeric::scale_type will be automatically calculated.");
}

return fixed_point_binary_operation(lhs, rhs, op, output_type, stream, mr);
}

CUDF_EXPECTS(output_type.has_value(), "Must specify output_type of column.");
// Use output_type.value() for the rest of the function

if (lhs.type().id() == type_id::STRING and rhs.type().id() == type_id::STRING)
return binops::compiled::binary_operation(lhs, rhs, op, output_type.value(), stream, mr);

// Check for datatype
CUDF_EXPECTS(is_fixed_width(output_type), "Invalid/Unsupported output datatype");
CUDF_EXPECTS(is_fixed_width(type), "Invalid/Unsupported output datatype");
CUDF_EXPECTS(is_fixed_width(lhs.type()), "Invalid/Unsupported lhs datatype");
CUDF_EXPECTS(is_fixed_width(rhs.type()), "Invalid/Unsupported rhs datatype");

auto out = make_fixed_width_column_for_output(lhs, rhs, op, output_type, stream, mr);
auto out = make_fixed_width_column_for_output(lhs, rhs, op, output_type.value(), stream, mr);

if (lhs.is_empty() or rhs.is_empty()) return out;

Expand Down Expand Up @@ -868,7 +877,7 @@ std::unique_ptr<column> binary_operation(column_view const& lhs,
std::unique_ptr<column> binary_operation(column_view const& lhs,
column_view const& rhs,
binary_operator op,
data_type output_type,
thrust::optional<data_type> output_type,
rmm::mr::device_memory_resource* mr)
{
CUDF_FUNC_RANGE();
Expand Down
4 changes: 4 additions & 0 deletions cpp/tests/binaryop/binop-integration-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cudf/fixed_point/fixed_point.hpp>
#include <cudf/scalar/scalar_factories.hpp>
#include <cudf/types.hpp>
#include <cudf/utilities/error.hpp>
#include <cudf/utilities/type_dispatcher.hpp>

#include <cudf_test/column_utilities.hpp>
Expand Down Expand Up @@ -2123,6 +2124,9 @@ TYPED_TEST(FixedPointTestBothReps, FixedPointBinaryOpDiv2)
auto const result = cudf::binary_operation(lhs, rhs, cudf::binary_operator::DIV, {});

CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, result->view());
auto output_type = cudf::data_type{type_to_id<decimalXX>(), scale_type{1}};
EXPECT_THROW(cudf::binary_operation(lhs, rhs, cudf::binary_operator::DIV, output_type),
cudf::logic_error);
}

TYPED_TEST(FixedPointTestBothReps, FixedPointBinaryOpDiv3)
Expand Down

0 comments on commit d07c35f

Please sign in to comment.