diff --git a/gtsam/linear/GaussianBayesNet.cpp b/gtsam/linear/GaussianBayesNet.cpp index 41a734b34..229d4a932 100644 --- a/gtsam/linear/GaussianBayesNet.cpp +++ b/gtsam/linear/GaussianBayesNet.cpp @@ -64,8 +64,9 @@ namespace gtsam { return sample(result, rng); } - VectorValues GaussianBayesNet::sample(VectorValues result, + VectorValues GaussianBayesNet::sample(const VectorValues& given, std::mt19937_64* rng) const { + VectorValues result(given); // sample each node in reverse topological sort order (parents first) for (auto cg : boost::adaptors::reverse(*this)) { const VectorValues sampled = cg->sample(result, rng); @@ -79,7 +80,7 @@ namespace gtsam { return sample(&kRandomNumberGenerator); } - VectorValues GaussianBayesNet::sample(VectorValues given) const { + VectorValues GaussianBayesNet::sample(const VectorValues& given) const { return sample(given, &kRandomNumberGenerator); } diff --git a/gtsam/linear/GaussianBayesNet.h b/gtsam/linear/GaussianBayesNet.h index 83328576f..e81d6af33 100644 --- a/gtsam/linear/GaussianBayesNet.h +++ b/gtsam/linear/GaussianBayesNet.h @@ -110,13 +110,13 @@ namespace gtsam { * VectorValues given = ...; * auto sample = gbn.sample(given, &rng); */ - VectorValues sample(VectorValues given, std::mt19937_64* rng) const; + VectorValues sample(const VectorValues& given, std::mt19937_64* rng) const; /// Sample using ancestral sampling, use default rng VectorValues sample() const; /// Sample from an incomplete BayesNet, use default rng - VectorValues sample(VectorValues given) const; + VectorValues sample(const VectorValues& given) const; /** * Return ordering corresponding to a topological sort.