[mlpack-git] master: Fix serialization. (74cdbc8)

gitdub at mlpack.org gitdub at mlpack.org
Wed Jun 8 17:42:43 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/8d7e5db0bed8fc236407bdc5dee00d716d72a5ab...ae6c9e63b56c1ed1faa9aef9352854bbeb826a2f

>---------------------------------------------------------------

commit 74cdbc8dce10b4d2dfb259cd2b6cecdb1af49c1b
Author: Ryan Curtin <ryan at ratml.org>
Date:   Wed Jun 8 17:42:43 2016 -0400

    Fix serialization.


>---------------------------------------------------------------

74cdbc8dce10b4d2dfb259cd2b6cecdb1af49c1b
 src/mlpack/methods/lsh/lsh_search_impl.hpp | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/mlpack/methods/lsh/lsh_search_impl.hpp b/src/mlpack/methods/lsh/lsh_search_impl.hpp
index bd022c8..ac65a86 100644
--- a/src/mlpack/methods/lsh/lsh_search_impl.hpp
+++ b/src/mlpack/methods/lsh/lsh_search_impl.hpp
@@ -555,11 +555,16 @@ void LSHSearch<SortPolicy>::Serialize(Archive& ar,
     arma::Mat<size_t> tmpSecondHashTable;
     ar & CreateNVP(tmpSecondHashTable, "secondHashTable");
 
+    // The old secondHashTable was stored in row-major format, so we transpose
+    // it.
+    tmpSecondHashTable = tmpSecondHashTable.t();
+
     secondHashTable.resize(tmpSecondHashTable.n_cols);
     for (size_t i = 0; i < tmpSecondHashTable.n_cols; ++i)
     {
       // Find length of each column.  We know we are at the end of the list when
       // the value referenceSet->n_cols is seen.
+
       size_t len = 0;
       for ( ; len < tmpSecondHashTable.n_rows; ++len)
         if (tmpSecondHashTable(len, i) == referenceSet->n_cols)
@@ -599,29 +604,24 @@ void LSHSearch<SortPolicy>::Serialize(Archive& ar,
   if (version == 0)
   {
     // The vector was stored in the old uncompressed form.  So we need to shrink
-    // it.
+    // it.  But we can't do that until we have bucketRowInHashTable, so we also
+    // have to load that.
     arma::Col<size_t> tmpBucketContentSize;
     ar & CreateNVP(tmpBucketContentSize, "bucketContentSize");
+    ar & CreateNVP(bucketRowInHashTable, "bucketRowInHashTable");
 
     // Compress into a smaller vector by just dropping all of the zeros.
     bucketContentSize.set_size(secondHashTable.size());
-    size_t loc = 0;
     for (size_t i = 0; i < tmpBucketContentSize.n_elem; ++i)
-    {
       if (tmpBucketContentSize[i] > 0)
-        bucketContentSize[loc++] = tmpBucketContentSize[i];
-
-      // Terminate early, if we can.
-      if (loc == bucketContentSize.n_elem)
-        break;
-    }
+        bucketContentSize[bucketRowInHashTable[i]] = tmpBucketContentSize[i];
   }
   else
   {
     ar & CreateNVP(bucketContentSize, "bucketContentSize");
+    ar & CreateNVP(bucketRowInHashTable, "bucketRowInHashTable");
   }
 
-  ar & CreateNVP(bucketRowInHashTable, "bucketRowInHashTable");
   ar & CreateNVP(distanceEvaluations, "distanceEvaluations");
 }
 




More information about the mlpack-git mailing list