-
Notifications
You must be signed in to change notification settings - Fork 920
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
[BUG] pow operator not acting as expected. #10178
Comments
This appears to be some sort of precision issue that manifests for specific numbers, most likely in the libcudf layer (not in cuDF Python). I can reproduce on my machine, and moreover there are other apparently unrelated numbers conforming to no specific pattern that exhibit the same behavior of
|
This comment summarizes some Slack discussions, analysis, and plans for fixing this bug. C++'s We want the We need to change the behavior of
The only piece that still requires some investigation is the choice of conventions for This commit adds a failing C++ test and should be included in a PR to fix this bug: bdice@ae67768 |
This issue has been labeled |
Issue #9346 is also relevant here, since that |
This problem may also affect decimal types, since they use integers to represent the fixed point value. That should be verified before closing this issue. |
Partial fix for #10178 (still need to investigate whether decimal types are also affected). This implements the `INT_POW` binary operator, which can be dispatched for integral types. This uses an [exponentiation-by-squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring) algorithm to compute powers. Unlike `POW`, this does not cast the data to floating-point types which can suffer from precision loss when computing powers and casting back to an integral type. The cuDF Python layer has been updated to dispatch integral data to this operator, which fixes the problems seen for specific values of base and exponent (like `3**1 == 2`) noted in #10178. Authors: - Tim (https://github.com/AtlantaPepsi) - Bradley Dice (https://github.com/bdice) Approvers: - Bradley Dice (https://github.com/bdice) - Mike Wilson (https://github.com/hyperbolic2346) - Jason Lowe (https://github.com/jlowe) - https://github.com/brandon-b-miller URL: #11025
This issue has been labeled |
A separate issue affects decimal types. I filed #11636 and will close this issue. |
Describe the bug
__pow__
/__rpow__
binary operations do not give the expected results in the following cases.Steps/Code to reproduce bug
Powers of
3 ** 1
.This happens for other integers as well:
gives
Also, the power does not have to be 1. There are a lot of integers that fail, always off-by-one in the result.
It gives the wrong results for Series with dtypes
int8
,int16
,int32
,int64
,uint8
,uint16
,uint32
,uint64
,bool
(for the exponent,3 ** cudf.Series([1], dtype=bool)
gives2
).Additionally, pandas raises when computing integers to negative integer powers. cudf gives meaningless results.
Expected behavior
Additional context
Three is a magic number.
Using a floating type on either side gives expected results:
The text was updated successfully, but these errors were encountered: