Skip to content

Conversation

@jjerphan
Copy link
Member

@jjerphan jjerphan commented Nov 14, 2022

Reference Issues/PRs

Towards #24875 for -Woverflow

Relates to #13422 and #24895

What does this implement/fix? Explain your changes.

This removes the -Woverflow warnings observed when building scikit-learn.

RAND_R_MAX is the max value for uint8, incrementing it causes an overflow (hence the warning).

Elements were originally mentioned but seem to
have been left unreviewed, see:
https://github.com/scikit-learn/scikit-learn/pull/13422#issuecomment-472894022

I think this commit fixes the implementation, yet I comes with a backwards incompatible results and tests for implementation relying on our_rand_r fails because results are now different.

I see several alternatives to remove the warning while having tests pass:

  • preferred solution: adapt the test suite using the new results so that all tests pass and acknowledge the change of behavior for impacted user-facing APIs in the change-log
  • accept the quirk of this implementation but hardcode and rename the effective constant
  • silent the -Woverflow warning by another mean

Any other comments?

Any other alternative one can think of?

@glemaitre and I, have been capilotracting ourselves on finding the reason of using the modulo as the source linked for the 32bit XorShift generator does not mention.

Any memory @ClemDoum?

This removes the -Woverflow warnings observed
when building scikit-learn.

RAND_R_MAX is the max value for uint8, incrementing
it causes an overflow (hence the warning).

Elements were originally mentioned but seem to
have been left unreviewed, see:
scikit-learn#13422 (comment)

I think this commit fixes the implementation, yet
I comes with a backwards incompatible results and
tests for implementation relying on `our_rand_r`
fails because results are now different.

I see several alternatives to remove the warning while
having tests pass

  - preferred solution: adapt the test suite using the
    new results so that all tests pass and acknowledge
    the change of behavior for impacted user-facing APIs
    in the change-log
  - accept the quirk of this implementation but hardcode
    and rename the effective constant
  - silent the -Woverflow warning by another mean

Relates to:
scikit-learn#13422
scikit-learn#24895
@jjerphan jjerphan marked this pull request as draft November 14, 2022 15:46
@jjerphan jjerphan added the Bug label Nov 14, 2022
@jjerphan jjerphan added Build / CI Breaking Change Issue resolution would not be easily handled by the usual deprecation cycle. and removed module:utils labels Nov 14, 2022
@glemaitre
Copy link
Member

For reference, the Xorshift implementation is shown on Wikipedia:https://en.wikipedia.org/wiki/Xorshift. Additional discussions are made in the Numerical Recipes: http://numerical.recipes/

I still don't get:

  • why do we need the modulo operator
  • why the compiler seems to change the uint32 into a int64 magically to avoid the overflow

@glemaitre
Copy link
Member

I opened #24955 that fixes the overflow.
We were wrong when thinking that Ox7FFFFFFF is the biggest uint32 integer because it is only the maximum for a int32. Therefore, this value will not overflow an uint32.

@jjerphan
Copy link
Member Author

Closed as it has been superseded by #24955 which has been merged.

@jjerphan jjerphan closed this Nov 17, 2022
@jjerphan jjerphan deleted the maint/remove-Woverflow branch November 17, 2022 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking Change Issue resolution would not be easily handled by the usual deprecation cycle. Bug Build / CI cython

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants