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

Fix inaccurate ceil/floor and inaccurate rescaling casts of fixed-point values. #14242

Merged

Conversation

bdice
Copy link
Contributor

@bdice bdice commented Oct 2, 2023

Description

This is a follow-up PR to #14233. This PR fixes a bug where floating-point values were used as intermediates in ceil/floor unary operations and cast operations that require rescaling for fixed-point types, giving inaccurate results.

See also:

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@github-actions github-actions bot added the libcudf Affects libcudf (C++/CUDA) code. label Oct 2, 2023
@harrism
Copy link
Member

harrism commented Oct 3, 2023

Why in a subsequent release? Why not just fix them now?

@bdice
Copy link
Contributor Author

bdice commented Oct 3, 2023

Why in a subsequent release? Why not just fix them now?

This PR is not ready for review yet, I'm still moving things around. I'm targeting a fix for the problems with floating precision loss in fixed point operations and tests that catch these bugs for 23.10. Those fixes and tests will go in this PR. The refactoring of intpow operations across libcudf will target 23.12 after this PR and #14233 are forward-merged.

@bdice bdice changed the title Avoid std::pow in fixed-point rescaling operations. Fix inaccurate ceil/floor and inaccurate casts of fixed-point values. Oct 3, 2023
@bdice bdice changed the title Fix inaccurate ceil/floor and inaccurate casts of fixed-point values. Fix inaccurate ceil/floor and inaccurate rescaling casts of fixed-point values. Oct 3, 2023
@bdice bdice self-assigned this Oct 3, 2023
@bdice bdice force-pushed the decimal128-rescaling-errors branch from 37e79f4 to 1fc7fb5 Compare October 3, 2023 06:40
@bdice bdice changed the base branch from branch-23.12 to branch-23.10 October 3, 2023 06:44
@bdice bdice marked this pull request as ready for review October 3, 2023 06:45
@bdice bdice requested a review from a team as a code owner October 3, 2023 06:45
@bdice bdice requested review from hyperbolic2346 and vuule and removed request for a team October 3, 2023 06:45
@bdice bdice added bug Something isn't working non-breaking Non-breaking change labels Oct 3, 2023
@@ -199,7 +199,13 @@ std::unique_ptr<column> rescale(column_view input,
}
return output_column;
}
auto const scalar = make_fixed_point_scalar<T>(std::pow(10, -diff), scale_type{diff}, stream);

RepType scalar_value = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the next step to consolidate this logic into a single function somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. See #14243.

Copy link
Contributor

@vuule vuule left a comment

Choose a reason for hiding this comment

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

As @hyperbolic2346 implied, it would be nice to consolidate logic into a util function, but the fix looks good.


Type n = 10;
for (int i = 1; i < -input.type().scale(); ++i) {
n *= 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to worry about overflow?

Copy link
Contributor Author

@bdice bdice Oct 3, 2023

Choose a reason for hiding this comment

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

No, I don't think so. We know that the value 10^-scale is representable by the device storage type (e.g. __int128_t or int64_t). And in the worst case, this won't introduce a new overflow if one already existed, because the value was already being converted to that type (it was just an inaccurate value).

@raydouglass raydouglass merged commit 3964950 into rapidsai:branch-23.10 Oct 3, 2023
56 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants