Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Eigen #135

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/annoylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <algorithm>
#include <queue>
#include <limits>
#include <eigen3/Eigen/Dense>

// This allows others to supply their own logger / error printer without
// requiring Annoy to import their headers. See RcppAnnoy for a use case.
Expand Down Expand Up @@ -202,17 +203,13 @@ struct Euclidean {
};
template<typename T>
static inline T distance(const T* x, const T* y, int f) {
T d = 0.0;
for (int i = 0; i < f; i++, x++, y++)
d += ((*x) - (*y)) * ((*x) - (*y));
return d;
Eigen::Map<const Eigen::VectorXf, Eigen::Aligned> p(x, f, 1), q(y, f, 1);
return (p - q).squaredNorm();
}
template<typename S, typename T>
static inline T margin(const Node<S, T>* n, const T* y, int f) {
T dot = n->a;
for (int z = 0; z < f; z++)
dot += n->v[z] * y[z];
return dot;
Eigen::Map<const Eigen::VectorXf, Eigen::Aligned> p((float *)n->v, f, 1), q(y, f, 1);
return n->a + p.dot(q);
}
template<typename S, typename T, typename Random>
static inline bool side(const Node<S, T>* n, const T* y, int f, Random& random) {
Expand Down