-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
38 lines (31 loc) · 1.16 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef UTIL_H
#define UTIL_H
#include <Eigen/Dense>
#include <stdexcept>
#include <vector>
#include <iostream>
#include <string>
#include <assert.h>
#include <sys/stat.h>
#include <unordered_map>
enum Metric {
DIST_L2 = 0,
DIST_COS = 1
};
typedef float VectorElemType;
// The default Matrix is defined as row matrix.
typedef Eigen::Matrix<VectorElemType, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> Matrix;
typedef Eigen::Ref<Matrix> MatrixRef;
// The default Vector is defined as row vector.
typedef Eigen::Matrix<VectorElemType, 1, Eigen::Dynamic> Vector;
typedef Eigen::Ref<Vector> VectorRef;
typedef Eigen::Matrix<VectorElemType, Eigen::Dynamic, 1> ColVector;
typedef Eigen::Matrix<int, 1, Eigen::Dynamic> IntegerVector;
typedef Eigen::Ref<IntegerVector> IntegerVectorRef;
float L2_distance(VectorRef p1, VectorRef p2);
float cosine_distance(VectorRef p1, VectorRef p2);
ColVector L2_distances(VectorRef query, MatrixRef points);
ColVector cosine_distances(VectorRef query, MatrixRef points);
ColVector one_to_all_distances(VectorRef query, MatrixRef points, Metric distance_metric);
Matrix pairwise_distances(MatrixRef points, Metric distance_metric);
#endif