Skip to content

Commit

Permalink
Make cudf::round for fixed_point when scale = -decimal_places a…
Browse files Browse the repository at this point in the history
… no-op(#6975)

@nartal1 found a small bug while working on: NVIDIA/spark-rapids#1244

Problem is that for `fixed_point`, when the column `scale = -decimal_places`, it should be a no-op. Fix is to make it a no-op.

Authors:
  - Conor Hoekstra <codereport@outlook.com>

Approvers:
  - David
  - Karthikeyan

URL: #6975
  • Loading branch information
codereport authored Dec 11, 2020
1 parent b136469 commit 13acc98
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cpp/src/round/round.cu
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ std::unique_ptr<column> round_with(column_view const& input,
using Type = device_storage_type_t<T>;
using FixedPointRoundFunctor = RoundFunctor<Type>;

if (input.type().scale() == -decimal_places)
return std::make_unique<cudf::column>(input, stream, mr);

// if rounding to more precision than fixed_point is capable of, just need to rescale
// note: decimal_places has the opposite sign of numeric::scale_type (therefore have to negate)
if (input.type().scale() > -decimal_places) {
Expand Down
13 changes: 13 additions & 0 deletions cpp/tests/round/round_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ TYPED_TEST(RoundTestsFixedPointTypes, SimpleFixedPointTestHalfUpZero)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, result->view());
}

TYPED_TEST(RoundTestsFixedPointTypes, SimpleFixedPointTestHalfUpZeroNoOp)
{
using namespace numeric;
using decimalXX = TypeParam;
using RepType = cudf::device_storage_type_t<decimalXX>;
using fp_wrapper = cudf::test::fixed_point_column_wrapper<RepType>;

auto const input = fp_wrapper{{1125, 1150, 1160, 1240, 1250, 1260}, scale_type{0}};
auto const result = cudf::round(input);

CUDF_TEST_EXPECT_COLUMNS_EQUAL(input, result->view());
}

TYPED_TEST(RoundTestsFixedPointTypes, SimpleFixedPointTestHalfEvenZero)
{
using namespace numeric;
Expand Down

0 comments on commit 13acc98

Please # to comment.