[mlpack-git] master: Replaces arma::Row<bool> with std::vector<bool> to conserve space (79b954a)
gitdub at mlpack.org
gitdub at mlpack.org
Thu Jun 23 10:42:57 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/eaa7182ebed8cce3fd6191dc1f8170546ea297da...812048c7c6bee0b6c8d936677f23bbb5930c6cfc
>---------------------------------------------------------------
commit 79b954a71a47e443f9d543d594007ea3d0229fcd
Author: Yannis Mentekidis <mentekid at gmail.com>
Date: Thu Jun 23 15:42:57 2016 +0100
Replaces arma::Row<bool> with std::vector<bool> to conserve space
>---------------------------------------------------------------
79b954a71a47e443f9d543d594007ea3d0229fcd
src/mlpack/methods/lsh/lsh_search_impl.hpp | 54 +++++++++++++++---------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/src/mlpack/methods/lsh/lsh_search_impl.hpp b/src/mlpack/methods/lsh/lsh_search_impl.hpp
index 12ccc6d..f7883bc 100644
--- a/src/mlpack/methods/lsh/lsh_search_impl.hpp
+++ b/src/mlpack/methods/lsh/lsh_search_impl.hpp
@@ -405,28 +405,28 @@ inline bool perturbationValid(const std::vector<size_t>& A,
//Returns the score of a perturbation vector generated by perturbation set A.
//The score of a pertubation set (vector) is the sum of scores of the
//participating actions.
-inline double perturbationScore(const arma::Row<char>& A,
+inline double perturbationScore(const std::vector<bool>& A,
const arma::vec& scores)
{
double score = 0.0;
- for (size_t i = 0; i < A.n_elem; ++i)
- score += A(i) ? scores(i) : 0; //add scores of non-zero indices
+ for (size_t i = 0; i < A.size(); ++i)
+ score += A[i] ? scores(i) : 0; //add scores of non-zero indices
return score;
}
// Inline function used by GetAdditionalProbingBins. The vector shift operation
// replaces the largest element of a vector A with (largest element) + 1.
-inline bool perturbationShift(arma::Row<char>& A)
+inline bool perturbationShift(std::vector<bool>& A)
{
size_t maxPos = 0;
- for (size_t i = 0; i < A.n_elem; ++i)
- if (A(i) == 1) // marked true
+ for (size_t i = 0; i < A.size(); ++i)
+ if (A[i] == 1) // marked true
maxPos=i;
- if ( maxPos + 1 < A.n_elem) // otherwise, this is an invalid vector
+ if ( maxPos + 1 < A.size()) // otherwise, this is an invalid vector
{
- A(maxPos) = 0;
- A(maxPos+1) = 1;
+ A[maxPos] = 0;
+ A[maxPos+1] = 1;
return true; // valid
}
return false; // invalid
@@ -435,17 +435,17 @@ inline bool perturbationShift(arma::Row<char>& A)
// Inline function used by GetAdditionalProbingBins. The vector expansion
// operation adds the element [1 + (largest_element)] to a vector A, where
// largest_element is the largest element of A.
-inline bool perturbationExpand(arma::Row<char>& A)
+inline bool perturbationExpand(std::vector<bool>& A)
{
// Find the last '1' in A
size_t maxPos = 0;
- for (size_t i = 0; i < A.n_elem; ++i)
- if (A(i)) //marked true
+ for (size_t i = 0; i < A.size(); ++i)
+ if (A[i]) //marked true
maxPos = i;
- if ( maxPos + 1 < A.n_elem) // otherwise, this is an invalid vector
+ if ( maxPos + 1 < A.size()) // otherwise, this is an invalid vector
{
- A(maxPos+1) = 1;
+ A[maxPos+1] = 1;
return true;
}
return false;
@@ -455,7 +455,7 @@ inline bool perturbationExpand(arma::Row<char>& A)
// Return true if perturbation set A is valid. A perturbation set is invalid if
// it contains two (or more) actions for the same dimension or dimensions that
// are larger than the queryCode's dimensions.
-inline bool perturbationValid(const arma::Row<char>& A,
+inline bool perturbationValid(const std::vector<bool>& A,
const size_t numProj)
{
// Stack allocation and initialization to 0 (bool check[numProj] = {0}) made
@@ -463,17 +463,17 @@ inline bool perturbationValid(const arma::Row<char>& A,
// on implementation) so this saves some space.
std::vector<bool> check(numProj);
- if (A.n_elem > 2 * numProj)
+ if (A.size() > 2 * numProj)
{
Log::Assert(1 == 2);
return false; // This should never happen
}
// Check that we only see each dimension once. If not, vector is not valid.
- for (size_t i = 0; i < A.n_elem; ++i)
+ for (size_t i = 0; i < A.size(); ++i)
{
// Only check dimensions that were included.
- if (!A(i))
+ if (!A[i])
continue;
// If dimesnion is unseen thus far, mark it as seen.
@@ -599,7 +599,7 @@ void LSHSearch<SortPolicy>::GetAdditionalProbingBins(
// Theory:
- // From the paper: This is the part that creates the probing sequence.
+ // This is the part that creates the probing sequence.
// A probing sequence is a sequence of T probing bins where a query's
// neighbors are most likely to be. Likelihood is dependent only on a bin's
// score, which is the sum of scores of all dimension-action pairs, so we
@@ -682,10 +682,10 @@ void LSHSearch<SortPolicy>::GetAdditionalProbingBins(
// Perturbation sets (A) mark with 1 the (score, action, dimension) positions
// included in a given perturbation vector. Other spaces are 0.
- arma::Row<char> Ao(2 * numProj, arma::fill::zeros);
- Ao(0) = 1; // Smallest vector includes only smallest score.
+ std::vector<bool> Ao(2 * numProj);
+ Ao[0] = 1; // Smallest vector includes only smallest score.
- std::vector< arma::Row<char> > perturbationSets;
+ std::vector< std::vector<bool> > perturbationSets;
perturbationSets.push_back(Ao); // storage of perturbation sets
std::priority_queue<
@@ -706,7 +706,7 @@ void LSHSearch<SortPolicy>::GetAdditionalProbingBins(
// neighbors of the query).
for (size_t pvec = 0; pvec < T; ++pvec)
{
- arma::Row<char> Ai;
+ std::vector<bool> Ai;
do
{
// get the perturbation set corresponding to the minimum score
@@ -714,7 +714,7 @@ void LSHSearch<SortPolicy>::GetAdditionalProbingBins(
minHeap.pop(); // .top() returns, .pop() removes
// modify Ai (shift)
- arma::Row<char> As = Ai;
+ std::vector<bool> As = Ai;
if ( perturbationShift(As) && perturbationValid(As, numProj) ) // Don't add invalid sets.
{
perturbationSets.push_back(As); // add shifted set to sets
@@ -726,7 +726,7 @@ void LSHSearch<SortPolicy>::GetAdditionalProbingBins(
}
// modify Ai (expand)
- arma::Row<char> Ae = Ai;
+ std::vector<bool> Ae = Ai;
if ( perturbationExpand(Ae) && perturbationValid(Ae, numProj) ) // Don't add invalid sets.
{
perturbationSets.push_back(Ae); // add expanded set to sets
@@ -740,9 +740,9 @@ void LSHSearch<SortPolicy>::GetAdditionalProbingBins(
}while (! perturbationValid(Ai, numProj) );//Discard invalid perturbations
// add perturbation vector to probing sequence if valid
- for (size_t i = 0; i < Ai.n_elem; ++i)
+ for (size_t i = 0; i < Ai.size(); ++i)
additionalProbingBins(positions(i), pvec)
- += Ai(i) ? actions(i) : 0; // if A(i) marked, add action to probing vector
+ += Ai[i] ? actions(i) : 0; // if A(i) marked, add action to probing vector
}
}
More information about the mlpack-git
mailing list