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

Make cudf::round for fixed_point when scale = -decimal_places a no-op #6975

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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