-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Use random generator from C++11 instead of from Boost #2956
Use random generator from C++11 instead of from Boost #2956
Conversation
077cda6
to
7125cc1
Compare
///////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
template <typename T> | ||
pcl::common::UniformGenerator<T>::UniformGenerator(T min, T max, pcl::uint32_t seed) | ||
: distribution_ (min, max) | ||
, generator_ (rng_, distribution_) | ||
{ | ||
parameters_ = Parameters (min, max, seed); | ||
if(parameters_.seed != -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw a compiler warning related to this:
common/include/pcl/common/impl/random.hpp:49:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(parameters_.seed != -1)
Even I didn't touched here anything: Should we fix this warning in this PR (and how?) or in a separate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can fix it here. Just static_cast<pcl::uint32_t>(-1)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering about this:
pcl/common/include/pcl/common/random.h
Lines 163 to 186 in b4c785b
struct Parameters | |
{ | |
Parameters (T _mean = 0, T _sigma = 1, pcl::uint32_t _seed = 1) | |
: mean (_mean) | |
, sigma (_sigma) | |
, seed (_seed) | |
{} | |
T mean; | |
T sigma; | |
pcl::uint32_t seed; | |
}; | |
/** Constructor | |
* \param[in] mean normal mean | |
* \param[in] sigma normal variation | |
* \param[in] seed seeding value | |
*/ | |
NormalGenerator(T mean = 0, T sigma = 1, pcl::uint32_t seed = -1); | |
/** Constructor | |
* \param parameters normal distribution parameters and seed | |
*/ | |
NormalGenerator(const Parameters& parameters); |
One constructor of NormalGenerator
has as default seed -1
during the other one (via Parameters
) has 1
as default seed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think -1
should be the default everywhere. However, thinking more about this, wouldn't it be better if -1
meant "seed with random device" instead of "not seed at all".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
-1
should be the default everywhere. However, thinking more about this, wouldn't it be better if-1
meant "seed with random device" instead of "not seed at all".
It's a valid point, but I'm not sure if it's a good idea to change the behavior already on this PR. Once the review is complete, I would be open to give it a try on a separate commit or PR just to see if the change is harmless or if it causes unit tests to start exploding like last time... Then we can decide based on the result.
Edit: I started the review before Heiko replied and wrote the comment then. Just leaving it for the extra info on my stance. I'm supportive of addressing it on a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved discussion to #2985. I think it is better, if this behavior changes are not part of this PR.
77f65ba
to
49d051a
Compare
Tests seems to fail, because std random number generator produce other random numbers as boost random number generator with same seed. But not sure if this is always the reason - I even can't reproduce all test failures (Ubuntu just has 3, during Mac has 5). So it would be nice, if another can check this too. |
Seems like you opened another can of worms :) This is a very big PR, so I'm in favor of splitting it up after we agree on good splitting points. After quickly skimming through the PR and getting acquainted with the new semantics behind One source [1] claims the method might actually throw on some implementations, source [2] only focuses on the aspect that it might still be pseudo random if there's no hardware support. I don't have experience with other platforms other than desktops so I'm not sure if the concern in [1] is applicable to us. I'm tempted to say that no. Opinions? Regarding the PR split, I feel the per module approach is worthy once more. I'm more interested in revising the core modules first and then progressing towards apps, examples and tools. [1] - http://www.cplusplus.com/reference/random/random_device/ |
Indeed, I wasn't expected this issues at the time I started :(
I was already thinking about it. My idea was to split everthing out, which causes tests to fail.
Well, I don't think [1] is an issue for us. I believe all modern platforms (mobile and desktop) can handle this. Maybe some specific platforms doesn't have it, but I'm nearly sure they are not part of the target group of the PCL.
Adjusting app, example and tools is easy, because they have no tests which depends on the result of generated values by the random generator, so they are straight forward during core components could be difficult to adjust. Nevertheless we should discuss about another thing: Is it really necessary to generate random data within core classes? Usually you have separate factory classes in case you need random content. And btw: It is really ugly to have test which expect specific values of random generator. |
49d051a
to
3e5eab2
Compare
Fully agree. We can drop such tests, but then we may be left without any tests at all :D |
Let's go with the easy cases then first 👍 and progress to the more challenging problems as we progress.
Likely not. But correcting this behaviour is not really mandatory at the moment.
😅 |
...d_rec_framework/include/pcl/apps/3d_rec_framework/pipeline/impl/global_nn_recognizer_crh.hpp
Outdated
Show resolved
Hide resolved
///////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
template <typename T> | ||
pcl::common::UniformGenerator<T>::UniformGenerator(T min, T max, pcl::uint32_t seed) | ||
: distribution_ (min, max) | ||
, generator_ (rng_, distribution_) | ||
{ | ||
parameters_ = Parameters (min, max, seed); | ||
if(parameters_.seed != -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
-1
should be the default everywhere. However, thinking more about this, wouldn't it be better if-1
meant "seed with random device" instead of "not seed at all".
It's a valid point, but I'm not sure if it's a good idea to change the behavior already on this PR. Once the review is complete, I would be open to give it a try on a separate commit or PR just to see if the change is harmless or if it causes unit tests to start exploding like last time... Then we can decide based on the result.
Edit: I started the review before Heiko replied and wrote the comment then. Just leaving it for the extra info on my stance. I'm supportive of addressing it on a separate PR.
test/search/test_search.cpp
Outdated
indices.push_back (idx); | ||
|
||
boost::variate_generator< boost::mt19937, boost::uniform_int<> > rand_indices(boost::mt19937 (), boost::uniform_int<> (0, static_cast<int> (indices.size ()) - 1)); | ||
std::uniform_int_distribution<> rand_indices(0, static_cast<int> (indices.size ()) - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the point behind this static_cast<int>
. Just remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indices.size ()
is a size_t
, so we have an unsigned type here. In case size()
returns 0 we got with static_cast<int> (indices.size ()) - 1
-1
as value, during with without this cast we got std::numeric_limits<size_t>::max()
=> out of integer range => 0. Because this is test code it doesn't maybe matters. Just want to say we change behavior with it.
# pragma GCC system_header | ||
#endif | ||
|
||
#include <boost/random.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to keep this file around for deprecation purposes, open for discussion. Since it is a header just emit pragma warning.
# pragma GCC system_header | ||
#endif | ||
|
||
#include <boost/random.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... I'm starting to notice a shortcoming on my request. I wanted to keep pcl/tracking/boost.h
around, so it exists as a file, but I didn't want to include any boost headers inside it. If anyone was using this header for some reason it was just because of boost/random.hpp
, then removing this line will still break their code, which means we need to keep it around. :/
The test are "legitimately" failing on windows. Shall we pull out/revert the the failing case and associated class to a new PR so that we can address the unit test correction there? |
I reverted changes to this test as I have no idea why they are failing. As we have already splitted other changes to other PRs from this PR because of failing tests, we could do this here too. |
Let's definitely do that. That way we can look at it from a finer scope. |
There are still three occurences of Boost random generator: #2954 (metslib) #2955 (OutofcoreOctreeDiskContainer), #2988 (RangeLikelihood)
Solves partially #2803