Skip to content

Commit

Permalink
Fix serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcurtin committed Feb 27, 2017
1 parent a85c8d2 commit e0f6e97
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/mlpack/core/dists/discrete_distribution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,24 @@ class DiscreteDistribution
template<typename Archive>
void Serialize(Archive& ar, const unsigned int /* version */)
{
// We only need to save the probabilities, since that's all we hold.
ar & data::CreateNVP(probabilities, "probabilities");
// We serialize the vector manually since there seem to be some problems
// with some boost versions.
size_t dimensionality;
dimensionality = probabilities.size();
ar & data::CreateNVP(dimensionality, "dimensionality");

if (Archive::is_loading::value)
{
probabilities.clear();
probabilities.resize(dimensionality);
}

for (size_t i = 0; i < dimensionality; ++i)
{
std::ostringstream oss;
oss << "probabilities" << i;
ar & data::CreateNVP(probabilities[i], oss.str());
}
}

private:
Expand Down

0 comments on commit e0f6e97

Please sign in to comment.