diff --git a/CMakeLists.txt b/CMakeLists.txt index ecbcb02f4785c1fe51b815d772be91b0a7ae36ef..091e69658cd5715e37a440dc15ffc1dc633dba4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project(flann) string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) include(${PROJECT_SOURCE_DIR}/cmake/flann_utils.cmake) -set(FLANN_VERSION 1.5.0) +set(FLANN_VERSION 1.6.0) DISSECT_VERSION() GET_OS_INFO() diff --git a/doc/manual.tex b/doc/manual.tex index c657aeb3c46bcad89ee47b4e05cf1059ee263fdd..26714d3018f929f36220b000711629e0c1b08ffe 100644 --- a/doc/manual.tex +++ b/doc/manual.tex @@ -16,7 +16,7 @@ Manual\\[1cm]} \author{Marius Muja, mariusm@cs.ubc.ca\\David Lowe, lowe@cs.ubc.ca} -\date{September 26, 2009} +\date{November 26, 2009} \begin{document} @@ -60,8 +60,7 @@ through the C, MATLAB and Python bindings provided with the library. This section contains small examples of how to use the FLANN library from -different programming languages (C++, C, MATLAB and Python) and from the -command line. +different programming languages (C++, C, MATLAB and Python). \begin{itemize} @@ -88,7 +87,7 @@ int main(int argc, char** argv) flann::Matrix dists(new float[query.rows*nn], query.rows, nn); // construct an randomized kd-tree index using 4 kd-trees - flann::Index index(dataset, flann::KDTreeIndexParams(4)); + flann::Index > index(dataset, flann::KDTreeIndexParams(4)); index.buildIndex(); // do a knn search, using 128 checks @@ -189,22 +188,6 @@ result,dists = flann.nn(dataset,testset,5,algorithm="kmeans", branching=32, iterations=7, checks=16); \end{Verbatim} -\item \textbf{Command line application} - - - -\begin{Verbatim}[fontsize=\scriptsize,frame=single] -$ flann compute_nn --input-file=dataset.dat --test-file=testset.dat ---algorithm=kdtree --trees=8 --checks=64 --nn=5 --output-file=nn.dat -Reading input dataset from dataset.dat -Building index -Building index took: 0.76 -Reading test dataset from testset.dat -Searching for nearest neighbors -Searching took 0.06 seconds -Writing matches to nn.dat -\end{Verbatim} - \end{itemize} @@ -270,25 +253,27 @@ types of nearest neighbor search indexes. \begin{Verbatim}[fontsize=\footnotesize,frame=single] namespace flann { - template + template class Index { + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; public: - Index(const Matrix& features, const IndexParams& params); + Index(const Matrix& features, const IndexParams& params); ~Index(); void buildIndex(); - void knnSearch(const Matrix& queries, + void knnSearch(const Matrix& queries, Matrix& indices, - Matrix& dists, + Matrix& dists, int knn, const SearchParams& params); - int radiusSearch(const Matrix& query, + int radiusSearch(const Matrix& query, Matrix& indices, - Matrix& dists, + Matrix& dists, float radius, const SearchParams& params); @@ -306,7 +291,7 @@ namespace flann \textbf{flann::Index::Index} Constructs a nearest neighbor search index for a given dataset. \begin{Verbatim}[fontsize=\footnotesize,frame=single] -Index(const Matrix& features, const IndexParams& params); +Index(const Matrix& features, const IndexParams& params); \end{Verbatim} \begin{description} \item[features] Matrix containing the features(points) to index. The size of the matrix is $num\_features \times dimensionality$. @@ -437,9 +422,9 @@ exception of saved index type). \subsubsection{flann::Index::knnSearch} Performs a K-nearest neighbor search for a given query point using the index. \begin{Verbatim}[fontsize=\footnotesize,frame=single] -void Index::knnSearch(const Matrix& queries, +void Index::knnSearch(const Matrix& queries, Matrix& indices, - Matrix& dists, + Matrix& dists, int knn, const SearchParams& params); \end{Verbatim} @@ -459,9 +444,9 @@ precision was also computed, in which case this parameter is ignored.} \subsubsection{flann::Index::radiusSearch} Performs a radius nearest neighbor search for a given query point. \begin{Verbatim}[fontsize=\footnotesize,frame=single] -int Index::radiusSearch(const Matrix& query, +int Index::radiusSearch(const Matrix& query, Matrix& indices, - Matrix& dists, + Matrix& dists, float radius, const SearchParams& params); \end{Verbatim} @@ -485,39 +470,16 @@ Saves the index to a file. \item[filename]{The file to save the index to} \end{description} -\subsubsection{flann::set\_distance\_type} -\label{flann::setDistanceType} -This function chooses the distance function to use when computing distances between -data points. -\begin{Verbatim}[fontsize=\footnotesize,frame=single] -void set_distance_type(flann_distance_t distance_type, int order); -\end{Verbatim} -\begin{description} -\item[distance\_type] The distance type to use. Possible values are -\begin{Verbatim}[fontsize=\footnotesize] -enum flann_distance_t { - EUCLIDEAN = 1, // squared euclidean distance - MANHATTAN = 2, - MINKOWSKI = 3, - MAX_DIST = 4, // L_infinity - not valid for kd-tree index type - HIK = 5, - HELLINGER = 6, - CS = 7, // chi-square - KL = 8, // kullback-leibler divergence -}; -\end{Verbatim} -\item[order] Used in for the \texttt{MINKOWSKI} distance type, to choose the order of the Minkowski distance. -\end{description} - - \subsubsection{flann::hierarchicalClustering} \label{flann::hierarchicalClustering} Clusters the given points by constructing a hierarchical k-means tree and choosing a cut in the tree that minimizes the clusters' variance. \begin{Verbatim}[fontsize=\footnotesize,frame=single] -template -int hierarchicalClustering(const Matrix& features, - Matrix& centers, const KMeansIndexParams& params) +template +int hierarchicalClustering(const Matrix& features, + Matrix& centers, + const KMeansIndexParams& params, + Distance d = Distance()) \end{Verbatim} \begin{description} \item[features]{The points to be clustered} @@ -751,11 +713,29 @@ This function deletes a previously constructed index and frees all the memory used by it. \subsubsection{flann\_set\_distance\_type} +\label{flann::setDistanceType} This function chooses the distance function to use when computing distances between -data points (see \ref{flann::setDistanceType}). +data points. \begin{Verbatim}[fontsize=\footnotesize,frame=single] void flann_set_distance_type(enum flann_distance_t distance_type, int order); \end{Verbatim} +\begin{description} +\item[distance\_type] The distance type to use. Possible values are +\begin{Verbatim}[fontsize=\footnotesize] +enum flann_distance_t { + EUCLIDEAN = 1, // squared euclidean distance + MANHATTAN = 2, + MINKOWSKI = 3, + HIK = 5, + HELLINGER = 6, + CS = 7, // chi-square + KL = 8, // kullback-leibler divergence +}; +\end{Verbatim} +\item[order] Used in for the \texttt{MINKOWSKI} distance type, to choose the order of the Minkowski distance. +\end{description} + + \subsubsection{flann\_compute\_cluster\_centers()} @@ -1179,76 +1159,6 @@ See section \ref{sec:quickstart} for an example of how to use the Python bindings. -\subsection{Using the \texttt{flann} command line application} - -The FLANN distribution also contains a command line application that can be -used to perform nearest-neighbor searches using datasets stored in files. The -application can read datasets stored in CSV format, space-separated values or -raw binary format. - -The command line application takes a command name as the first argument and -then the arguments for that command: -\begin{Verbatim}[fontsize=\footnotesize,frame=single] -$ flann -Usage: flann.py [command commans_args] - -Comamnds: - generate_random - compute_gt - compute_nn - autotune - sample_dataset - cluster - run_test - -For command specific help type: flann.py -h -\end{Verbatim} - -To see the possible arguments for each command, use \texttt{flann help -}. For example: - -\begin{Verbatim}[fontsize=\footnotesize,frame=single] -$ flann run_test -h -Usage: flann.py [command command_args] - -Options: - -h, --help show this help message and exit - -i FILE, --input-file=FILE - Name of file with input dataset - -a ALGORITHM, --algorithm=ALGORITHM - The algorithm to use when constructing the index - (kdtree, kmeans...) - -r TREES, --trees=TREES - Number of parallel trees to use (where available, for - example kdtree) - -b BRANCHING, --branching=BRANCHING - Branching factor (where applicable, for example - kmeans) (default: 2) - -C CENTERS_INIT, --centers-init=CENTERS_INIT - How to choose the initial cluster centers for kmeans - (random, gonzales) (default: random) - -M MAX_ITERATIONS, --max-iterations=MAX_ITERATIONS - Max iterations to perform for kmeans (default: until - convergence) - -l LOG_LEVEL, --log-level=LOG_LEVEL - Log level (none < fatal < error < warning < info) - (Default: info) - -t FILE, --test-file=FILE - Name of file with test dataset - -m FILE, --match-file=FILE - File with ground truth matches - -n NN, --nn=NN Number of nearest neighbors to search for - -c CHECKS, --checks=CHECKS - Number of times to restart search (in best-bin-first - manner) - -P PRECISION, --precision=PRECISION - Run the test until reaching this precision - -K NUM, --skip-matches=NUM - Skip the first NUM matches at test phase - -\end{Verbatim} - - \bibliographystyle{alpha} \bibliography{references} diff --git a/src/cpp/flann/flann.cpp b/src/cpp/flann/flann.cpp index 5e2811676a1ac6745686804f2c83ede55daaafdb..b95a7ccdd8511b7d9019edddb1008150556e7110 100644 --- a/src/cpp/flann/flann.cpp +++ b/src/cpp/flann/flann.cpp @@ -95,7 +95,7 @@ flann_index_t __flann_build_index(typename Distance::ElementType* dataset, int r index_params->toParameters(*flann_params); if (index->getIndex()->getType()==AUTOTUNED) { - AutotunedIndex* autotuned_index = (AutotunedIndex*)index->getIndex(); + AutotunedIndex* autotuned_index = (AutotunedIndex*)index->getIndex(); flann_params->checks = autotuned_index->getSearchParameters()->checks; *speedup = autotuned_index->getSpeedup(); } @@ -762,4 +762,3 @@ EXPORTED int flann_compute_cluster_centers_int(int* dataset, int rows, int cols, return _flann_compute_cluster_centers(dataset, rows, cols, clusters, result, flann_params); } -} diff --git a/src/cpp/flann/flann.hpp b/src/cpp/flann/flann.hpp index 55f144f9a3e5816251bb9fa4407c979a94d4f793..da8124219f0438f397b36804125525e4ca517d82 100644 --- a/src/cpp/flann/flann.hpp +++ b/src/cpp/flann/flann.hpp @@ -259,7 +259,7 @@ int Index::veclen() const template int hierarchicalClustering(const Matrix& features, Matrix& centers, - const KMeansIndexParams& params, Distance d) + const KMeansIndexParams& params, Distance d = Distance()) { KMeansIndex kmeans(features, params, d); kmeans.buildIndex(); diff --git a/src/cpp/flann/util/saving.cpp b/src/cpp/flann/util/saving.cpp index 722e112b83cd05e0d26c427862b6ceef228c4da8..c976db8818f5e46a3cb65dcc4c2761f775eba460 100644 --- a/src/cpp/flann/util/saving.cpp +++ b/src/cpp/flann/util/saving.cpp @@ -34,7 +34,7 @@ namespace flann { const char FLANN_SIGNATURE[] = "FLANN_INDEX"; -const char FLANN_VERSION[] = "1.5.0"; +const char FLANN_VERSION[] = "1.6.0"; IndexHeader load_header(FILE* stream) diff --git a/src/python/pyflann/bindings/flann_ctypes.py b/src/python/pyflann/bindings/flann_ctypes.py index 98093546a4d653976584f75436092283db9d7723..345eae484837d27b96e2ed8dfbac0707eb918828 100644 --- a/src/python/pyflann/bindings/flann_ctypes.py +++ b/src/python/pyflann/bindings/flann_ctypes.py @@ -353,58 +353,6 @@ flannlib.flann_free_index_%(C)s.argtypes = [ flann.free_index[%(numpy)s] = flannlib.flann_free_index_%(C)s """) -flannlib.compute_ground_truth_float.restype = None -flannlib.compute_ground_truth_float.argtypes = [ - ndpointer(float32, ndim = 2, flags='aligned, c_contiguous'), # dataset - c_int, # dshape - c_int, - ndpointer(float32, ndim = 2, flags='aligned, c_contiguous'), # testset - c_int, # tshape - c_int, - ndpointer(int32, ndim = 2, flags='aligned, c_contiguous, writeable'), # matches - c_int, # mshape - c_int, - c_int # skip -] - -flannlib.test_with_precision.restype = c_float -flannlib.test_with_precision.argtypes = [ - FLANN_INDEX, - ndpointer(float32, ndim = 2, flags='aligned, c_contiguous'), # dataset - c_int, # dshape - c_int, - ndpointer(float32, ndim = 2, flags='aligned, c_contiguous'), # testset - c_int, # tshape - c_int, - ndpointer(int32, ndim = 2, flags='aligned, c_contiguous'), # matches - c_int, # mshape - c_int, - c_int, # nn - c_float, #precision - POINTER(c_int), # checks - c_int # skip -] - - -flannlib.test_with_checks.restype = c_float -flannlib.test_with_checks.argtypes = [ - FLANN_INDEX, - ndpointer(float32, ndim = 2, flags='aligned, c_contiguous'), # dataset - c_int, # dshape - c_int, - ndpointer(float32, ndim = 2, flags='aligned, c_contiguous'), # testset - c_int, # tshape - c_int, - ndpointer(int32, ndim = 2, flags='aligned, c_contiguous'), # matches - c_int, # mshape - c_int, - c_int, # nn - c_int, # checks - POINTER(c_float), #precision - c_int # skip -] - - def ensure_2d_array(array, flags, **kwargs): array = require(array, requirements = flags, **kwargs) diff --git a/src/python/setup.py b/src/python/setup.py index 07fdb91acfd2233dd28f26d027db1871a569d134..b6f614ec4d1f3fc4903fe305a013972be6e7d423 100644 --- a/src/python/setup.py +++ b/src/python/setup.py @@ -8,13 +8,14 @@ setup_path = os.path.dirname(os.path.abspath(sys.argv[0])) lib_path = os.path.abspath(os.path.join(setup_path,'../../../lib')) setup(name='flann', - version='1.5.0', + version='1.6.0', description='Fast Library for Approximate Nearest Neighbors', author='Marius Muja', author_email='mariusm@cs.ubc.ca', license='BSD', url='http://www.cs.ubc.ca/~mariusm/flann/', - packages=['pyflann', 'pyflann.io', 'pyflann.bindings', 'pyflann.util', 'pyflann.lib'], + packages=['pyflann','pyflann.command', 'pyflann.io', 'pyflann.bindings', 'pyflann.util', 'pyflann.lib'], + scripts=['flann'], package_dir={'pyflann.lib':lib_path}, package_data={'pyflann.lib': ['libflann.so','flann.dll', 'libflann.dylib']}, )