Skip to content

Commit

Permalink
Merge branch 'master' of github.com:searchivarius/nmslib
Browse files Browse the repository at this point in the history
  • Loading branch information
searchivairus committed Jul 20, 2018
2 parents b133329 + 1be8dcb commit 727648b
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 46 deletions.
46 changes: 30 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ matrix:
- os: linux
env: PYTHON=3
- os: osx
env: PYTHON=3.6
env: PYTHON=3
osx_image: xcode9.3
python: 3.7.0
- os: osx
env: PYTHON=2
osx_image: xcode9.3
python: 2.7.14
allow_failures:
- os: osx

Expand All @@ -29,17 +35,27 @@ addons:

before_install:
- |
if [ "$TRAVIS_OS_NAME" = "linux" ]; then export CXX=g++-4.8 CC=gcc-4.8; fi
if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "${PYTHON:0:1}" = "3" ]; then
brew update
brew upgrade python
command curl -sSL https://rvm.io/mpapis.asc | gpg --import -;
rvm get stable
else
PIP=pip
PY=python
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
export CXX=g++-4.8 CC=gcc-4.8;
pip install --user --upgrade pip virtualenv
virtualenv -p python$PYTHON venv
source venv/bin/activate
fi
fi
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew update
brew install gcc
PIP=pip2
PY=python2
if [ "${PYTHON:0:1}" = "3" ]; then
brew upgrade python
brew install python3
PIP=pip3
PY=python3
fi
fi
install:
- |
Expand All @@ -49,22 +65,20 @@ install:
cmake similarity_search
fi
make -j 4
travis_wait travis_retry pip install -r python_bindings/requirements.txt scipy six flake8
travis_retry cd python_bindings && python setup.py build install && cd ..
travis_wait travis_retry $PIP install -r python_bindings/requirements.txt scipy six flake8
travis_retry cd python_bindings && $PY setup.py build install && cd ..
script:
- $PY --version
- cd python_bindings && $PY setup.py test && flake8 && cd ..
- |
set -e
if [ "$TRAVIS_OS_NAME" = "linux" -o "$TRAVIS_OS_NAME" = "osx" ] ; then
if [ "$TRAVIS_OS_NAME" = "linux" ] ; then
cd similarity_search;
./release/bunit
./release/test_integr integr.log
cd ..
fi
cd python_bindings
python setup.py test
flake8
cd ..
cache:
- apt
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Non-Metric Space Library (NMSLIB)
=================
The latest **pre**-release is [1.7.2](https://github.com/nmslib/nmslib/releases/tag/v1.7.1). Note that the manual is not updated to reflect some of the changes. In particular, we changed the build procedure for Windows. Also note that the manual targets primiarily developers who will extend the library. For most other folks, [Python binding docs should be sufficient](python_bindings). The basic parameter tuning/selection guidelines are also available [online](/python_bindings/parameters.md).
The latest **pre**-release is [1.7.3.2](https://github.com/nmslib/nmslib/releases/tag/v1.7.3.2). Note that the manual is not updated to reflect some of the changes. In particular, we changed the build procedure for Windows. Also note that the manual targets primiarily developers who will extend the library. For most other folks, [Python binding docs should be sufficient](python_bindings). The basic parameter tuning/selection guidelines are also available [online](/python_bindings/parameters.md).
-----------------
Non-Metric Space Library (NMSLIB) is an **efficient** cross-platform similarity search library and a toolkit for evaluation of similarity search methods. The core-library does **not** have any third-party dependencies.

Expand Down
47 changes: 29 additions & 18 deletions python_bindings/nmslib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ struct IndexWrapper {
}

~IndexWrapper() {
LOG(LIB_DEBUG) << "Destroying Index";
// In cases when the interpreter was shutting down, attempting to log in python
// could throw an exception (https://github.com/nmslib/nmslib/issues/327).
//LOG(LIB_DEBUG) << "Destroying Index";
freeObjectVector(&data);
}

Expand Down Expand Up @@ -388,23 +390,32 @@ class PythonLogger
int line,
const char * function,
const std::string & message) {
AcquireGIL l;
switch(severity) {
case LIB_DEBUG:
inner.attr("debug")(message);
break;
case LIB_INFO:
inner.attr("info")(message);
break;
case LIB_WARNING:
inner.attr("warning")(message);
break;
case LIB_ERROR:
inner.attr("error")(message);
break;
case LIB_FATAL:
inner.attr("critical")(message);
break;
// In cases when the interpreter was shutting down, attempting to log in python
// could throw an exception (https://github.com/nmslib/nmslib/issues/327).
// Logging shouldn't cause exceptions, so catch it and dump to stderr instead.
try {
AcquireGIL l;
switch(severity) {
case LIB_DEBUG:
inner.attr("debug")(message);
break;
case LIB_INFO:
inner.attr("info")(message);
break;
case LIB_WARNING:
inner.attr("warning")(message);
break;
case LIB_ERROR:
inner.attr("error")(message);
break;
case LIB_FATAL:
inner.attr("critical")(message);
break;
}
} catch (const std::exception & e) {
std::cerr << "Failed to log '" << message << "'. Exception:" << e.what() << std::endl;
} catch (...) {
std::cerr << "Failed to log '" << message << "'" << std::endl;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion python_bindings/notebooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ We have Python notebooks for the following scenarios:
3. [The Euclidean space ofr for 8-bit integer SIFT vectors (the index is not optimized)](search_sift_uint8.ipynb);
4. [KL-divergence (non-optimized index)](search_vector_dense_kldiv.ipynb);
3. [Sparse cosine similarity (non-optimized index)](search_sparse_cosine.ipynb);
4. [Sparse Jaccard similarity (non-optimized index)](search_sparse_cosine.ipynb).
4. [Sparse Jaccard similarity (non-optimized index)](search_generic_sparse_jaccard.ipynb).

Note that for for the dense space, we have examples of the so-called optimized and non-optimized indices. Except HNSW, all the methods save meta-indices rather than real ones. Meta indices contain only index structure, but not the data. Hence, before a meta-index can be loaded, we need to re-load data. One example is a memory efficient space to search for SIFT vectors.

Expand Down
5 changes: 3 additions & 2 deletions python_bindings/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import setuptools

__version__ = '1.7.2'
__version__ = '1.7.3.2'

libdir = os.path.join(".", "nmslib", "similarity_search")
library_file = os.path.join(libdir, "release", "libNonMetricSpaceLib.a")
Expand All @@ -19,7 +19,7 @@

else:
# Otherwise build all the files here directly (excluding extras which need eigen/boost)
exclude_files = set("""lsh.cc lsh_multiprobe.cc lsh_space.cc falconn.cc nndes.cc space_sqfd.cc
exclude_files = set("""bbtree.cc lsh.cc lsh_multiprobe.cc lsh_space.cc falconn.cc nndes.cc space_sqfd.cc
dummy_app.cc main.cc""".split())

for root, subdirs, files in os.walk(os.path.join("nmslib", "similarity_search", "src")):
Expand Down Expand Up @@ -137,6 +137,7 @@ def build_extensions(self):
high dimensions and/or non-metric spaces. Hence, the main focus is on approximate methods.""",
ext_modules=ext_modules,
install_requires=['pybind11>=2.0', 'numpy'],
setup_requires=['pybind11>=2.0', 'numpy'],
cmdclass={'build_ext': BuildExt},
test_suite="tests",
zip_safe=False,
Expand Down
6 changes: 6 additions & 0 deletions python_bindings/tests/bindings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,11 @@ def testSparse(self):
self.assertEqual(index[3], [(3, 1.0)])


class GlobalTestCase(unittest.TestCase):
def testGlobal(self):
# this is a one line reproduction of https://github.com/nmslib/nmslib/issues/327
GlobalTestCase.index = nmslib.init()


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion similarity_search/include/factory/method/bbtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef _FACTORY_BBTREE_H_
#define _FACTORY_BBTREE_H_

#if WITH_EXTRAS
#ifdef WITH_EXTRAS

#include <method/bbtree.h>

Expand Down
2 changes: 1 addition & 1 deletion similarity_search/include/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class RuntimeErrorWrapper {

#define CHECK_MSG(condition,message) \
if (!(condition)) {\
LOG(LIB_ERROR) << "Check failed: " << #condition; \
LOG(LIB_ERROR) << "Check failed: " << #condition << " " << string(message); \
throw runtime_error("Check failed: " + string(message)); \
}

Expand Down
4 changes: 0 additions & 4 deletions similarity_search/include/method/bbtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#ifndef _BBTREE_H_
#define _BBTREE_H_

#if WITH_EXTRAS

#include "index.h"
#include "params.h"

Expand Down Expand Up @@ -128,6 +126,4 @@ class BBTree : public Index<dist_t> {

} // namespace similarity

#endif

#endif // _BBTREE_H_
2 changes: 1 addition & 1 deletion similarity_search/src/method/hnsw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ namespace similarity {
void
Hnsw<dist_t>::Search(KNNQuery<dist_t> *query, IdType) const
{
if (this->data_.empty()) {
if (this->data_.empty() and this->data_rearranged_.empty()) {
return;
}
bool useOld = searchAlgoType_ == kOld || (searchAlgoType_ == kHybrid && ef_ >= 1000);
Expand Down
2 changes: 1 addition & 1 deletion similarity_search/test/test_integr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ vector<MethodTestCase> vTestCaseDesc = {
MethodTestCase(DIST_TYPE_FLOAT, "l2", "final8_10K.txt", "list_clusters", false, "strategy=random,useBucketSize=1,bucketSize=10", "",
0 /* no KNN */, 0.5 /* range search radius 0.5*/ , 1.0, 1.0, 0.0, 0.0, 2.4, 3.4),

#ifdef WITH_EXTRAS
// *************** bbtree tests ******************** //
// knn
/*
Expand All @@ -311,7 +312,6 @@ vector<MethodTestCase> vTestCaseDesc = {
MethodTestCase(DIST_TYPE_FLOAT, "kldivgenfast", "final8_10K.txt", "bbtree", false, "bucketSize=10", "",
0 /* no KNN */, 0.5 /* range search radius 0.5*/ , 0.999, 1.0, 0.0, 0.0, 1.2, 2.4),

#ifdef WITH_EXTRAS

// *************** multi-probe LSH tests ******************** //
// knn
Expand Down

0 comments on commit 727648b

Please sign in to comment.