Skip to content

Commit

Permalink
Now check during reduce phase whether there are no neighbors. For 64-…
Browse files Browse the repository at this point in the history
…bit build.
  • Loading branch information
elbamos committed Dec 22, 2016
1 parent 2997605 commit 3219209
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Makevars
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(SHLIB_OPENMP_CFLAGS) $(FLIBS) $(LAPACK_LIBS) $(BLAS_LIBS)
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_64BIT_WORD
CXX_STD=CXX11
LDFLAGS = $(LDFLAGS)
2 changes: 1 addition & 1 deletion src/distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ arma::vec fastDistance(const IntegerVector is,
#ifdef _OPENMP
#pragma omp parallel for shared (xs)
#endif
for (vertexidxtype i=0; i < is.length(); i++) if (p.increment()) xs[i] =
for (arma::uword i=0; i < is.length(); i++) if (p.increment()) xs[i] =
distanceFunction(data.col(is[i]), data.col(js[i]));
return xs;
};
Expand Down
5 changes: 3 additions & 2 deletions src/neighbors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ void AnnoySearch<M, V>::reduceOne(const vertexidxtype& i,
*/
auto continueWriting = std::transform(newNeighborhood.begin(), newNeighborhood.end(), knns.begin_col(i),
[](const std::pair<distancetype, vertexidxtype>& input) {return input.second;});
if (continueWriting == knns.begin_col(i)) stop("At reduction, no neighbors for vertex " + std::to_string(i));
sort(knns.begin_col(i), continueWriting);
std::fill(continueWriting, knns.end_col(i), -1);

Expand Down Expand Up @@ -262,14 +263,14 @@ void AnnoySearch<M,V>::exploreOne(const vertexidxtype& i,

/*
* Before the last iteration, we keep the matrix sorted by vertexid, which makes the merge above
* more efficient. In the last iteration, sort by distance.
* more efficient.
*
* We can't use std:copy because we're copying from a vector of pairs
*/
auto copyContinuation = std::transform(nodeHeap.begin(), nodeHeap.end(), knns.begin_col(i),
[](const std::pair<distancetype, vertexidxtype>& input) {return input.second;});
if (copyContinuation == knns.begin_col(i)) stop("No neighbors after exploration - this is a bug. Vertex " + std::to_string(i));
sort(knns.begin_col(i), copyContinuation);
if (copyContinuation == knns.begin_col(i)) stop("Neighbor exploration failure.");
std::fill(copyContinuation, knns.end_col(i), -1);
}

Expand Down

0 comments on commit 3219209

Please sign in to comment.