[mlpack-git] master: More style fixes (5d603b2)
gitdub at mlpack.org
gitdub at mlpack.org
Fri Jun 24 04:57:13 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/eaa7182ebed8cce3fd6191dc1f8170546ea297da...812048c7c6bee0b6c8d936677f23bbb5930c6cfc
>---------------------------------------------------------------
commit 5d603b205d9068c7a5529b3ab207df10435d78a8
Author: Yannis Mentekidis <mentekid at gmail.com>
Date: Fri Jun 24 09:57:13 2016 +0100
More style fixes
>---------------------------------------------------------------
5d603b205d9068c7a5529b3ab207df10435d78a8
src/mlpack/methods/lsh/lsh_search.hpp | 6 +++---
src/mlpack/methods/lsh/lsh_search_impl.hpp | 27 +++++++++++++--------------
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/src/mlpack/methods/lsh/lsh_search.hpp b/src/mlpack/methods/lsh/lsh_search.hpp
index e557e45..dce275d 100644
--- a/src/mlpack/methods/lsh/lsh_search.hpp
+++ b/src/mlpack/methods/lsh/lsh_search.hpp
@@ -359,10 +359,10 @@ class LSHSearch
* @param additionalProbingBins matrix. Each column will hold one additional
* bin.
*/
- void GetAdditionalProbingBins(const arma::vec &queryCode,
- const arma::vec &queryCodeNotFloored,
+ void GetAdditionalProbingBins(const arma::vec& queryCode,
+ const arma::vec& queryCodeNotFloored,
const size_t T,
- arma::mat &additionalProbingBins) const;
+ arma::mat& additionalProbingBins) const;
//! Reference dataset.
const arma::mat* referenceSet;
diff --git a/src/mlpack/methods/lsh/lsh_search_impl.hpp b/src/mlpack/methods/lsh/lsh_search_impl.hpp
index 5bf5318..bf9dd5b 100644
--- a/src/mlpack/methods/lsh/lsh_search_impl.hpp
+++ b/src/mlpack/methods/lsh/lsh_search_impl.hpp
@@ -402,20 +402,22 @@ 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.
+// 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 std::vector<bool>& A,
const arma::vec& scores)
{
double score = 0.0;
for (size_t i = 0; i < A.size(); ++i)
- score += A[i] ? scores(i) : 0; //add scores of non-zero indices
+ if (A[i])
+ score += scores(i) // 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.
+// Returns true if resulting vector is valid, otherwise false.
inline bool perturbationShift(std::vector<bool>& A)
{
size_t maxPos = 0;
@@ -434,18 +436,19 @@ inline bool perturbationShift(std::vector<bool>& 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.
+// largest_element is the largest element of A. Returns true if resulting vector
+// is valid, otherwise false.
inline bool perturbationExpand(std::vector<bool>& A)
{
// Find the last '1' in A
size_t maxPos = 0;
for (size_t i = 0; i < A.size(); ++i)
- if (A[i]) //marked true
+ if (A[i]) // marked true
maxPos = i;
if ( maxPos + 1 < A.size()) // otherwise, this is an invalid vector
{
- A[maxPos+1] = 1;
+ A[maxPos + 1] = 1;
return true;
}
return false;
@@ -458,16 +461,12 @@ inline bool perturbationExpand(std::vector<bool>& A)
inline bool perturbationValid(const std::vector<bool>& A,
const size_t numProj)
{
- // Stack allocation and initialization to 0 (bool check[numProj] = {0}) made
- // some compilers complain, and std::vector might even be compressed (depends
- // on implementation) so this saves some space.
+ // Use check to mark dimensions we have seen before in A. If a dimension is
+ // seen twice (or more), A is not a valid perturbation.
std::vector<bool> check(numProj);
if (A.size() > 2 * numProj)
- {
- Log::Assert(1 == 2);
- return false; // This should never happen
- }
+ 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.size(); ++i)
More information about the mlpack-git
mailing list