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

bug fix: support cmake 11.0+ #496

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.9.1)
set(FLANN_VERSION 1.9.2)
DISSECT_VERSION()
GET_OS_INFO()

Expand Down Expand Up @@ -148,6 +148,7 @@ endif(BUILD_CUDA_LIB)

find_package(PkgConfig REQUIRED)
pkg_check_modules(LZ4 REQUIRED liblz4)
include_directories(${LZ4_INCLUDE_DIRS})

#set the C/C++ include path to the "include" directory
include_directories(BEFORE ${PROJECT_SOURCE_DIR}/src/cpp)
Expand Down
22 changes: 22 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
Version 1.9.2
* Removed redundant assignment (issue #422 @fluber)
* Removed unnecessary null checks before delete (issue #420 @elfring)
* Reverted PR #424 due to lack of portability
* fscanf fix (PR #467 @rdelfin)
* Out of bounds check (modified PR #455 @legrosbuffle, also included in PR #319 @seth-planet)
* Fixed MacOS build (PR #470 @johnhe4, modified for linux)
* Fixed build system with dummy.c hack (PR #457 @pemmanuelviel)
* Fixed misleading indentation in util/any.h (PR #365 @psteinb, also PR #428, #430, #459)
* Included datasets in repo
* Correct typo in definition (PR #419 @SergioRAgostinho)
* Fix typos (PR #279 @gadomski)
* CMakefile CUDA sources fix (PR #458 @pemmanuelviel)
* Documentation fix (PR #456 @pemmanuelviel)
* Scoping issue fix (PR #405 @greenbrettmichael, also PR #469, issue #386)
* Documentation fixes (PR #460 @pemmanuelviel)
* Changed return value (PR #461 @pemmanuelviel)
* Fixed CUDA crash - guarantee prealloc > 0 (PR #437 @neka-rat)
* Fixed wrong variable use (PR #433 @XinyiYS)
* Fixed RNG initialization (PR #424 @SiddhantRanade)
* Updated link to PDF (PR #474 @kleinma)

Version 1.6.11
* bug fixes

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Documentation on how to use the library can be found in the doc/manual.pdf file

More information and experimental results can be found in the following paper:

* Marius Muja and David G. Lowe, "Fast Approximate Nearest Neighbors with Automatic Algorithm Configuration", in International Conference on Computer Vision Theory and Applications (VISAPP'09), 2009 [(PDF)](http://people.cs.ubc.ca/~mariusm/uploads/FLANN/flann_visapp09.pdf) [(BibTex)](http://people.cs.ubc.ca/~mariusm/index.php/FLANN/BibTex)
* Marius Muja and David G. Lowe, "Fast Approximate Nearest Neighbors with Automatic Algorithm Configuration", in International Conference on Computer Vision Theory and Applications (VISAPP'09), 2009 [(PDF)](https://www.cs.ubc.ca/research/flann/uploads/FLANN/flann_visapp09.pdf) [(BibTex)](http://people.cs.ubc.ca/~mariusm/index.php/FLANN/BibTex)


Getting FLANN
Expand Down
20 changes: 3 additions & 17 deletions cmake/flann_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ macro(flann_add_gtest exe)
DEPENDS ${exe}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test
VERBATIM
COMMENT "Runnint gtest test(s) ${exe}")
COMMENT "Running gtest test(s) ${exe}")
# add dependency to 'test' target
add_dependencies(flann_gtest test_${_testname})
endmacro(flann_add_gtest)
Expand All @@ -76,7 +76,7 @@ macro(flann_add_cuda_gtest exe)
DEPENDS ${exe}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test
VERBATIM
COMMENT "Runnint gtest test(s) ${exe}")
COMMENT "Running gtest test(s) ${exe}")
# add dependency to 'test' target
add_dependencies(test test_${_testname})
endmacro(flann_add_cuda_gtest)
Expand All @@ -100,18 +100,4 @@ macro(flann_add_pyunit file)
# add dependency to 'test' target
add_dependencies(pyunit_${_testname} flann)
add_dependencies(test pyunit_${_testname})
endmacro(flann_add_pyunit)



macro(flann_download_test_data _name _md5)
string(REPLACE "/" "_" _dataset_name dataset_${_name})

add_custom_target(${_dataset_name}
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/bin/download_checkmd5.py http://people.cs.ubc.ca/~mariusm/uploads/FLANN/datasets/${_name} ${TEST_OUTPUT_PATH}/${_name} ${_md5}
VERBATIM)

# Also make sure that downloads are done before we run any tests
add_dependencies(tests ${_dataset_name})

endmacro(flann_download_test_data)
endmacro(flann_add_pyunit)
Binary file added datasets/brief100K.h5
Binary file not shown.
Binary file added datasets/cloud.h5
Binary file not shown.
Binary file added datasets/sift100K.h5
Binary file not shown.
Binary file added datasets/sift100K_byte.h5
Binary file not shown.
Binary file added datasets/sift10K.h5
Binary file not shown.
Binary file added datasets/sift10K_byte.h5
Binary file not shown.
7 changes: 3 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
add_custom_target(examples ALL)


if (BUILD_C_BINDINGS)
add_executable(flann_example_c flann_example.c)
target_link_libraries(flann_example_c -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
target_link_libraries(flann_example_c ${LZ4_LINK_LIBRARIES})
target_link_libraries(flann_example_c flann)
set_target_properties(flann_example_c PROPERTIES COMPILE_FLAGS -std=c99)

Expand All @@ -15,7 +14,7 @@ if (HDF5_FOUND)
include_directories(${HDF5_INCLUDE_DIR})

add_executable(flann_example_cpp flann_example.cpp)
target_link_libraries(flann_example_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
target_link_libraries(flann_example_cpp ${LZ4_LINK_LIBRARIES})
target_link_libraries(flann_example_cpp ${HDF5_LIBRARIES} flann_cpp)
if (HDF5_IS_PARALLEL)
target_link_libraries(flann_example_cpp ${MPI_LIBRARIES})
Expand All @@ -27,7 +26,7 @@ if (HDF5_FOUND)

if (USE_MPI AND HDF5_IS_PARALLEL)
add_executable(flann_example_mpi flann_example_mpi.cpp)
target_link_libraries(flann_example_mpi -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
target_link_libraries(flann_example_mpi ${LZ4_LINK_LIBRARIES})
target_link_libraries(flann_example_mpi flann_cpp ${HDF5_LIBRARIES} ${MPI_LIBRARIES} ${Boost_LIBRARIES})

add_dependencies(examples flann_example_mpi)
Expand Down
6 changes: 4 additions & 2 deletions examples/flann_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ float* read_points(const char* filename, int rows, int cols)

for (i=0;i<rows;++i) {
for (j=0;j<cols;++j) {
fscanf(fin,"%g ",p);
p++;
if(fscanf(fin,"%g ",p) != 1) {
printf("Input file is incorrectly formatted.\n");
exit(1);
}
}
}

Expand Down
21 changes: 11 additions & 10 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ file(GLOB_RECURSE CPP_SOURCES flann_cpp.cpp)
file(GLOB_RECURSE CU_SOURCES *.cu)

add_library(flann_cpp_s STATIC ${CPP_SOURCES})
target_link_libraries(flann_cpp_s ${LZ4_LIBRARIES})
target_link_libraries(flann_cpp_s PUBLIC ${LZ4_LINK_LIBRARIES})
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
set_target_properties(flann_cpp_s PROPERTIES COMPILE_FLAGS -fPIC)
endif()
set_property(TARGET flann_cpp_s PROPERTY COMPILE_DEFINITIONS FLANN_STATIC FLANN_USE_CUDA)

if (BUILD_CUDA_LIB)
SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-DFLANN_USE_CUDA")
SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-DFLANN_USE_CUDA;-Xcudafe \"--diag_suppress=partial_override\" ;-gencode=arch=compute_52,code=\"sm_52,compute_52\";-gencode=arch=compute_61,code=\"sm_61,compute_61\"")
if(CMAKE_COMPILER_IS_GNUCC)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-Xcompiler;-fPIC;" )
if (NVCC_COMPILER_BINDIR)
Expand All @@ -30,24 +30,24 @@ if (BUILD_CUDA_LIB)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_COMPILER_IS_GNUCC)
add_library(flann_cpp SHARED "")
add_library(flann_cpp SHARED dummy.c)
set_target_properties(flann_cpp PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(flann_cpp -Wl,-whole-archive flann_cpp_s -Wl,-no-whole-archive)
target_link_libraries(flann_cpp PUBLIC ${LZ4_LINK_LIBRARIES})

if (BUILD_CUDA_LIB)
cuda_add_library(flann_cuda SHARED "")
cuda_add_library(flann_cuda SHARED dummy.c)
set_target_properties(flann_cuda PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(flann_cuda -Wl,-whole-archive flann_cuda_s -Wl,-no-whole-archive)
set_property(TARGET flann_cpp_s PROPERTY COMPILE_DEFINITIONS FLANN_USE_CUDA)
# target_link_libraries(flann_cuda cudpp_x86_64)
endif()
else()
add_library(flann_cpp SHARED ${CPP_SOURCES})
target_link_libraries(flann_cpp -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
target_link_libraries(flann_cpp PUBLIC ${LZ4_LINK_LIBRARIES})
# export lz4 headers, so that MSVC to creates flann_cpp.lib
set_target_properties(flann_cpp PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)
if (BUILD_CUDA_LIB)
cuda_add_library(flann_cuda SHARED ${CPP_SOURCES})
cuda_add_library(flann_cuda SHARED ${CU_SOURCES})
set_property(TARGET flann_cpp PROPERTY COMPILE_DEFINITIONS FLANN_USE_CUDA)
endif()
endif()
Expand Down Expand Up @@ -81,19 +81,20 @@ endif()

if (BUILD_C_BINDINGS)
add_library(flann_s STATIC ${C_SOURCES})
target_link_libraries(flann_s -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
target_link_libraries(flann_s ${LZ4_LINK_LIBRARIES})
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
set_target_properties(flann_s PROPERTIES COMPILE_FLAGS -fPIC)
endif()
set_property(TARGET flann_s PROPERTY COMPILE_DEFINITIONS FLANN_STATIC)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_COMPILER_IS_GNUCC)
add_library(flann SHARED "")
add_library(flann SHARED dummy.c)
set_target_properties(flann PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(flann -Wl,-whole-archive flann_s -Wl,-no-whole-archive)
target_link_libraries(flann PUBLIC ${LZ4_LINK_LIBRARIES})
else()
add_library(flann SHARED ${C_SOURCES})
target_link_libraries(flann -Wl,--push-state,--no-as-needed ${LZ4_LIBRARIES} -Wl,--pop-state)
target_link_libraries(flann PUBLIC ${LZ4_LINK_LIBRARIES})

if(MINGW AND OPENMP_FOUND)
target_link_libraries(flann gomp)
Expand Down
Empty file added src/cpp/dummy.c
Empty file.
4 changes: 2 additions & 2 deletions src/cpp/flann/algorithms/autotuned_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ inline NNIndex<Distance>*

struct AutotunedIndexParams : public IndexParams
{
AutotunedIndexParams(float target_precision = 0.8, float build_weight = 0.01, float memory_weight = 0, float sample_fraction = 0.1)
AutotunedIndexParams(float target_precision = 0.8f, float build_weight = 0.01f, float memory_weight = 0.f, float sample_fraction = 0.1f)
{
(*this)["algorithm"] = FLANN_INDEX_AUTOTUNED;
// precision desired (used for autotuning, -1 otherwise)
Expand Down Expand Up @@ -161,7 +161,7 @@ class AutotunedIndex : public NNIndex<Distance>
}


void addPoints(const Matrix<ElementType>& points, float rebuild_threshold = 2)
void addPoints(const Matrix<ElementType>& points, float rebuild_threshold = 2.f)
{
if (bestIndex_) {
bestIndex_->addPoints(points, rebuild_threshold);
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/flann/algorithms/composite_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace flann
struct CompositeIndexParams : public IndexParams
{
CompositeIndexParams(int trees = 4, int branching = 32, int iterations = 11,
flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM, float cb_index = 0.2 )
flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM, float cb_index = 0.2f )
{
(*this)["algorithm"] = FLANN_INDEX_KMEANS;
// number of randomized trees to use (for kdtree)
Expand Down Expand Up @@ -166,7 +166,7 @@ class CompositeIndex : public NNIndex<Distance>
kdtree_index_->buildIndex();
}

void addPoints(const Matrix<ElementType>& points, float rebuild_threshold = 2)
void addPoints(const Matrix<ElementType>& points, float rebuild_threshold = 2.f)
{
kmeans_index_->addPoints(points, rebuild_threshold);
kdtree_index_->addPoints(points, rebuild_threshold);
Expand Down
5 changes: 3 additions & 2 deletions src/cpp/flann/algorithms/dist.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ struct HammingPopcnt
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const
{
ResultType result = 0;

//for portability just use unsigned long -- and use the __builtin_popcountll (see docs for __builtin_popcountll)
typedef unsigned long long pop_t;
#if __GNUC__
#if ANDROID && HAVE_NEON
static uint64_t features = android_getCpuFeatures();
Expand All @@ -499,8 +502,6 @@ struct HammingPopcnt
}
else
#endif
//for portability just use unsigned long -- and use the __builtin_popcountll (see docs for __builtin_popcountll)
typedef unsigned long long pop_t;
const size_t modulo = size % sizeof(pop_t);
const pop_t* a2 = reinterpret_cast<const pop_t*> (a);
const pop_t* b2 = reinterpret_cast<const pop_t*> (b);
Expand Down
19 changes: 12 additions & 7 deletions src/cpp/flann/algorithms/hierarchical_clustering_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,14 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
* Node points (only for terminal nodes)
*/
std::vector<PointInfo> points;

Node(){
pivot = NULL;
pivot_index = SIZE_MAX;
}
/**
* constructor
*/
Node()
{
pivot = NULL;
pivot_index = SIZE_MAX;
}
/**
* destructor
* calling Node destructor explicitly
Expand All @@ -378,7 +381,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
for(size_t i=0; i<childs.size(); i++){
childs[i]->~Node();
pivot = NULL;
pivot_index = -1;
pivot_index = SIZE_MAX;
}
};

Expand Down Expand Up @@ -444,7 +447,9 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
{
dst = new(pool_) Node();
dst->pivot_index = src->pivot_index;
dst->pivot = points_[dst->pivot_index];

if(dst->pivot_index != SIZE_MAX)
dst->pivot = points_[dst->pivot_index];

if (src->childs.size()==0) {
dst->points = src->points;
Expand Down
Loading