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

Replaced std::random_shuffle with std::shuffle in tri #24062

Merged
merged 14 commits into from
Oct 28, 2022

Conversation

tybeller
Copy link
Contributor

@tybeller tybeller commented Oct 1, 2022

PR Summary

Replaced std::random_shuffle with std::shuffle for compliance with C++17. Deleted RandomNumberGenerator class. Included random library and used 32 bit mersenne twister as uniform random bit generator for shuffle. Note: TrapezoidMapTriFinder, triangulation interpolation, and refinement may yield different results due to this change. Closes #24010

PR Checklist

Tests and Styling

  • [N/A ] Has pytest style unit tests (and pytest passes).
  • [N/A ] Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

…om_shuffle with shuffle and used mersenne twister engine to generate uniform random bit generator for the shuffle.
@tacaswell tacaswell added this to the v3.7.0 milestone Oct 1, 2022
@tacaswell
Copy link
Member

It looks like std::shuffle came in in c++11 which we just switch to having as our floor. It looks like moving that forwards was a good choice as it made this simple (I assume with enough #ifdef we could support a wider range of c++ versions....).

This seems reasonable and at least our tests are not sensitive to the different random order.

@ianthomas23
Copy link
Member

Thanks @tybeller. It is usual to mention the issue that the PR closes within the text (not just within the title) so that there is a link between the two and the issue automatically closes when the PR is merged.

Also, I said in the issue that it would need a release note but I realise now that this is classified as a behaviour change ("API that stays valid but will yield a different result") which therefore needs an API change note. The README file in the next_api_changes directory describes what is required here, see https://github.com/matplotlib/matplotlib/blob/main/doc/api/next_api_changes/README.rst and let me know if this is not clear enough and I will help out.

@tybeller
Copy link
Contributor Author

tybeller commented Oct 1, 2022

Thank you, sorry for any issues as this is my first time. If I'm reading this right I need to add the issue within the pull request and add and API change note correct? I'll get working on that and please let me know if there is anything else I'm missing.

@tybeller
Copy link
Contributor Author

tybeller commented Oct 1, 2022

One question, is there a way to edit these changes into this pull request or should I make a separate pull request with these fixes?

@rcomer
Copy link
Member

rcomer commented Oct 1, 2022

@tybeller if you edit your original post here and put “closes #24010“, that will link the issue to the PR, see https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword

Once you make any changes to you branch and push them to github, they will show in this pull request. There is advice for updating your branch in response to the review here: https://matplotlib.org/devdocs/devel/coding_guide.html#summary-for-pull-request-authors

@tybeller tybeller changed the title c++17 removed random_shuffle #24010 Replaced std::random_shuffle with std::shuffle in tri Oct 2, 2022
Added API notes for changed output from TrapezoidMapTriFinder, triangulation interpolation, and refinement
Copy link
Member

@ianthomas23 ianthomas23 left a comment

Choose a reason for hiding this comment

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

The code changes are fine, just a slight tweak to the API change note and this will be good to merge.

doc/api/next_api_changes/behavior/24062-tb.rst Outdated Show resolved Hide resolved
Fix api change

Co-authored-by: Ian Thomas <ianthomas23@gmail.com>
@@ -0,0 +1,3 @@
Change in TrapezoidMapTriFinder, triangulation interpolation, and refinement output due to change in shuffle.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

would solve the failing doc build (if I got the length right...).

Copy link
Member

Choose a reason for hiding this comment

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

If you're having trouble aligning the underline, then that's a sign the title is probably too long. I would leave out all of the details and just say "Change in triangulation output ..." Also, no trailing period in titles.

@@ -0,0 +1,3 @@
Change in TrapezoidMapTriFinder, triangulation interpolation, and refinement output due to change in shuffle.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Copy link
Member

Choose a reason for hiding this comment

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

If you're having trouble aligning the underline, then that's a sign the title is probably too long. I would leave out all of the details and just say "Change in triangulation output ..." Also, no trailing period in titles.

@@ -0,0 +1,3 @@
Change in TrapezoidMapTriFinder, triangulation interpolation, and refinement output due to change in shuffle.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
With std::random_shuffle removed from C++17, TrapezoidMapTriFinder, triangular grid interpolation and refinement now use std::shuffle with a new random generator which may give different results.
Copy link
Member

Choose a reason for hiding this comment

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

Different results how? Does a plot change? Is the order different? This is too vague and as a user I have no idea whether I need to do anything here. Also, please word-wrap lines at 80 characters.

tybeller and others added 3 commits October 5, 2022 03:34
Co-authored-by: Oscar Gustafsson <oscar.gustafsson@gmail.com>
clarified that the conditions of the change in output
@ianthomas23
Copy link
Member

@tybeller The definition of class RandomNumberGenerator at the end of src/tri/_tri.h can be removed.

@ianthomas23
Copy link
Member

Here is a possible improved api change note:

``TrapezoidMapTriFinder`` uses different random number generator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The random number generator used to determine the order of insertion of
triangle edges in ``TrapezoidMapTriFinder`` has changed. This can result in a
different triangle index being returned for a point that lies exactly on an
edge between two triangles. This can also affect triangulation interpolation
and refinement algorithms that use ``TrapezoidMapTriFinder``.

@ianthomas23
Copy link
Member

@tybeller Don't forget the changes in src/tri/_tri.h.

src/tri/_tri.cpp Outdated
_seed = (_seed*_a + _c) % _m;
return (_seed*max_value) / _m;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Please end the file with an empty line. That will fix the pre-commit issue. (The pyside6 issue is fixed in #24158.)

added empty line at end
@tacaswell tacaswell merged commit 1bb5816 into matplotlib:main Oct 28, 2022
@tacaswell
Copy link
Member

Thank you for this work @tybeller and congratulations on your first merged Matplotlib PR 🎉 Hopefully we will hear from you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

c++17 removed random_shuffle
6 participants