-
Notifications
You must be signed in to change notification settings - Fork 921
Update sample methods
#2137
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
Update sample methods
#2137
Changes from all commits
95af327
d4c9c68
bc7646f
995bedb
8302f2d
12baf54
4b6af3d
618505e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,12 @@ | |
| * @author Christian Potthast, Frank Dellaert | ||
| */ | ||
|
|
||
| #include <gtsam/base/utilities.h> | ||
| #include <gtsam/hybrid/HybridValues.h> | ||
| #include <gtsam/linear/GaussianConditional.h> | ||
| #include <gtsam/linear/Sampler.h> | ||
| #include <gtsam/linear/VectorValues.h> | ||
| #include <gtsam/linear/linearExceptions.h> | ||
| #include <gtsam/hybrid/HybridValues.h> | ||
|
|
||
| #ifdef __GNUC__ | ||
| #pragma GCC diagnostic push | ||
|
|
@@ -34,9 +35,6 @@ | |
| #include <string> | ||
| #include <cmath> | ||
|
|
||
| // In wrappers we can access std::mt19937_64 via gtsam.MT19937 | ||
| static std::mt19937_64 kRandomNumberGenerator(42); | ||
|
|
||
| using namespace std; | ||
|
|
||
| namespace gtsam { | ||
|
|
@@ -347,6 +345,10 @@ namespace gtsam { | |
|
|
||
| VectorValues solution = solve(parentsValues); | ||
| Key key = firstFrontalKey(); | ||
|
|
||
| // Check if rng is nullptr, then assign default | ||
| rng = (rng == nullptr) ? &kRandomNumberGenerator : rng; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a local or a global default rng?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a global default. There is one definition in |
||
|
|
||
| // The vector of sigma values for sampling. | ||
| // If no model, initialize sigmas to 1, else to model sigmas | ||
| const Vector& sigmas = (!model_) ? Vector::Ones(rows()) : model_->sigmas(); | ||
|
|
@@ -359,16 +361,7 @@ namespace gtsam { | |
| throw std::invalid_argument( | ||
| "sample() can only be invoked on no-parent prior"); | ||
| VectorValues values; | ||
| return sample(values); | ||
| } | ||
|
|
||
| /* ************************************************************************ */ | ||
| VectorValues GaussianConditional::sample() const { | ||
| return sample(&kRandomNumberGenerator); | ||
| } | ||
|
|
||
| VectorValues GaussianConditional::sample(const VectorValues& given) const { | ||
| return sample(given, &kRandomNumberGenerator); | ||
| return sample(values, rng); | ||
| } | ||
|
|
||
| /* ************************************************************************ */ | ||
|
|
||
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.
What happens when nullptr? Seems different from yesterday's PR where we pass in a kSomething
Uh oh!
There was an error while loading. Please reload this page.
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.
Passing in a static variable address as a default argument is
nullptras the default for a raw pointer.Whenever a
samplemethod gets a nullptr for therng, it keeps passing it along until we actually use the rng (e.g. inSample::sample). At that point, I have a simple check:This makes the code really clean since we don't have to worry about the rng pointer until we actually need 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.
Ok. And yesterday’s changes are now also defaulting to null ptr?
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.
Yes, I needed to do that to get the CI passing.