feat: add a process-wide random seed to UniformRandomGenerator#51
Draft
f-dy wants to merge 1 commit into
Draft
Conversation
Adds UniformRandomGenerator::setGlobalSeed(seed) / clearGlobalSeed(), mirroring cv::setRNGSeed. When a seed is set, every subsequently constructed generator is seeded deterministically (std::mt19937(seed)) instead of from std::random_device; clearing restores nondeterministic behavior. Default behavior is unchanged. This makes RANSAC sampling reproducible for debugging. All URG-based samplers (Uniform, PROSAC, Progressive-NAPSAC, Importance) construct their generator via the default constructor, so they all honor the seed with no per-sampler change. Samplers/solvers that use std::rand()/Eigen::Random (AdaptiveReordering, PnP bundle adjustment, DLS/SIFT) are made reproducible by the caller via std::srand(seed). Enables the seed parameter exposed in the pymagsac Python API (companion magsac PR).
f-dy
added a commit
to f-dy/magsac
that referenced
this pull request
May 31, 2026
Adds a 'seed' argument (default -1 = nondeterministic) to all 14 find* estimators. When seed >= 0 the run is reproducible: a shared helper (applyMagsacSeed) sets UniformRandomGenerator::setGlobalSeed(seed) for all URG-based samplers and std::srand(seed) for the std::rand()/Eigen::Random solver paths. Bumps the graph-cut-ransac submodule to include setGlobalSeed/clearGlobalSeed. Combines danini#48 (seed for the pre-existing estimators) and danini/graph-cut-ransac#51 (the seed mechanism), extended to the new estimators added in danini#45 (incl. findPlane3D).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: add a process-wide random seed to
UniformRandomGeneratorWhat
Adds
UniformRandomGenerator::setGlobalSeed(uint64_t)andclearGlobalSeed()(
src/pygcransac/include/uniform_random_generator.h). When a seed is set, everysubsequently constructed generator is seeded deterministically
(
std::mt19937(seed)) instead of fromstd::random_device; clearing restores thedefault. Default behavior (no seed) is unchanged.
This mirrors OpenCV's
cv::setRNGSeed— a process-wide reproducibility switch.Why
There is currently no way to make RANSAC sampling reproducible, which makes
debugging non-deterministic failures hard. A fixed seed gives repeatable runs.
Coverage
UniformSampler,ProsacSampler,ProgressiveNapsacSampler,ImportanceSampler) build their generator via thedefault
UniformRandomGenerator()constructor, so they honor the global seedwith no per-sampler change.
std::rand()/Eigen::…::Random()(
AdaptiveReorderingSampler, PnP bundle-adjustment, DLS/SIFT solvers) are notdriven by this generator; the caller makes those reproducible with
std::srand(seed)(Eigen::Randomusesstd::randby default).will seed each nested generator with the same value → correlated sub-sequences.
Fine for reproducible debugging; deriving distinct sub-seeds is a possible
later refinement.
Companion PR
This is the enabling change. The seed is exposed to users through the
seedparameter added to the
pymagsacPython API in the companion magsac PR,danini/magsac#48, which calls
setGlobalSeed(seed)+std::srand(seed)before running. That PR depends onthis one (and bumps the submodule to this commit).