Skip to content

Use std::shuffle instead of std::random_shuffle in igl/randperm#1062

Merged
jdumas merged 6 commits intolibigl:devfrom
ycjungSubhuman:master
Feb 23, 2019
Merged

Use std::shuffle instead of std::random_shuffle in igl/randperm#1062
jdumas merged 6 commits intolibigl:devfrom
ycjungSubhuman:master

Conversation

@ycjungSubhuman
Copy link
Copy Markdown
Contributor

@ycjungSubhuman ycjungSubhuman commented Dec 27, 2018

This pull request addresses #1025 and #1026

Check all that apply (change to [x])

  • All changes meet libigl style-guidelines.
  • Adds new .cpp file.
  • Adds corresponding unit test.
  • Adds corresponding python binding.
  • This is a minor change.

Yucheol Jung and others added 6 commits November 21, 2018 10:38
The reason behind this change is UniformRandomBitGenerator that
std::shuffle takes require max() and min() to be accessible
in compile-time. Therefore, template specializations for igl::randperm
will require max() and min() values as template variables, which is not
desirable. Instead, we declare template specializations for
pre-defined UniformRandomBitGenerator specified in c++11 standard.
@ycjungSubhuman ycjungSubhuman changed the title Use std::shuffle instread of std::random_shuffle in igl/randperm Use std::shuffle instead of std::random_shuffle in igl/randperm Dec 27, 2018
@alecjacobson
Copy link
Copy Markdown
Contributor

Thanks. Well have to wait until dev is passing again. Meanwhile, there are some style issues with this PR. For example if urbg is an input it should be const.

@jdumas
Copy link
Copy Markdown
Collaborator

jdumas commented Dec 27, 2018

Technically, the random number generator URBG should be passed as a rvalue reference URBG &&, similar to the signature of std::shuffle.

@ycjungSubhuman
Copy link
Copy Markdown
Contributor Author

@alecjacobson Thanks for reviewing. Yes. I guess I'll have to wait until the issue with CGAL is resolved. About the style, I forgot to make urbg const reference and put it before output parameters. I'll try to change this.

@ycjungSubhuman
Copy link
Copy Markdown
Contributor Author

ycjungSubhuman commented Dec 27, 2018

@jdumas True... If std::shuffle takes rvalue reference, may be a good idea to follow it. However, I have a feelling that const URBG urbg can be a valid option, too. If a user wants to pass a URBG using move semantics, he or she can just call randperm(n, std::move(urbg), I)

EDIT : I guess it depends on what kind of interaction we want to get. If we want the urbg to produce different values after the call to randperm, URBG &&urbg will be a good choice. Otherwise, I think const URBG urbg is a way to go.

EDIT 2: standard rng engines does not have rvalue constructors (i.e. std::linear_congruential_engine). So std::move() will be equivalent to copy construction.
(http://www.cplusplus.com/reference/random/linear_congruential_engine/linear_congruential_engine/)

@ycjungSubhuman
Copy link
Copy Markdown
Contributor Author

I guess URBG &&urbg is better because it is intended to be used that way, as shown in the example of std::shuffle signature. I'm more inclined towards this approach.

@jdumas
Copy link
Copy Markdown
Collaborator

jdumas commented Dec 27, 2018

Yes, let's not try to be smart and follow the signature of the stdlib function :D

@jdumas jdumas merged commit 4575cbd into libigl:dev Feb 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants