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

Consolidate random functions into Random class #1109

Merged
merged 20 commits into from
Sep 9, 2018
Merged

Conversation

jslee02
Copy link
Member

@jslee02 jslee02 commented Sep 7, 2018

This implementation is inspired by ign-math/Rand with some extensions for Eigen objects.

The old-style random functions are deprecated.

The list of functions is not complete yet. Missing functions will be added later such as generating vector/matrix from normal distribution and multivariate normal distribution.

This is a prequel of #1106.


Before creating a pull request

  • Document new methods and classes
  • Format new code files using clang-format

Before merging a pull request

  • Set version target by selecting a milestone on the right side
  • Summarize this change in CHANGELOG.md
  • Add unit test(s) for this change

@jslee02 jslee02 added this to the DART 6.7.0 milestone Sep 7, 2018
@jslee02 jslee02 requested a review from mxgrey September 7, 2018 04:46
@jslee02 jslee02 changed the title Add a set of modern random functions using C++11 Consolidate random functions into Random class Sep 8, 2018
- remove functions end with vector/matrix
- remove functions that take limit argument
- improve documentation
- add more unit tests
@codecov
Copy link

codecov bot commented Sep 8, 2018

Codecov Report

❗ No coverage uploaded for pull request base (release-6.7@da9d27b). Click here to learn what that means.
The diff coverage is 95.77%.

@@              Coverage Diff               @@
##             release-6.7    #1109   +/-   ##
==============================================
  Coverage               ?   56.47%           
==============================================
  Files                  ?      335           
  Lines                  ?    24934           
  Branches               ?        0           
==============================================
  Hits                   ?    14081           
  Misses                 ?    10853           
  Partials               ?        0
Impacted Files Coverage Δ
dart/math/Helpers.hpp 83.87% <ø> (ø)
...art/dynamics/detail/TranslationalJoint2DAspect.hpp 60% <ø> (ø)
dart/common/detail/LockableReference-impl.hpp 35.29% <0%> (ø)
dart/constraint/ContactConstraint.cpp 61.53% <100%> (ø)
dart/math/detail/Random-impl.hpp 100% <100%> (ø)
dart/constraint/BoxedLcpConstraintSolver.cpp 51.82% <100%> (ø)
dart/math/Random.cpp 94.11% <94.11%> (ø)

@jslee02 jslee02 merged commit 23f46cb into release-6.7 Sep 9, 2018
@jslee02 jslee02 deleted the enhance/random branch September 9, 2018 06:12
namespace math {

//==============================================================================
Random::GeneratorType& Random::getRandGenerator()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this getRandGenerator() instead of just getGenerator()? It is already on a Random class and it doesn't seem like there is another generator in this context to worry about 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point!

namespace dart {
namespace math {

class Random final
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is a final class which consists entirely of static methods, would it make more sense to make this a normal class and then have a singleton available here for simpler use cases?

That seems like it would be more flexible for situations where someone might want to use this helpful class but also track multiple RNGs with different seeds, where they can instantiate two of the class, while the singleton can be available for cases where that is not necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

This sounds good to me. In any case, I would like to keep the API simple. We could introduce wrapper functions something like this:

dart::math::uniform(min, max) {
  return Random::getInstance()::uniform(min, max);
}

Let me create an issue for this to track.

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.

2 participants