Skip to content

Commit

Permalink
Merge branch 'main' into fix-dot-recall
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbern authored Aug 17, 2023
2 parents 359aaa5 + 75429e5 commit edca4f6
Show file tree
Hide file tree
Showing 26 changed files with 1,476 additions and 1,348 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Annoy

on:
push:
branches:
- main
pull_request:

jobs:
unit-tests:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
os: ["ubuntu-20.04", "macos-latest", "windows-latest"]

steps:
- uses: actions/checkout@v3 # Pull the repository
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: pip install .
- run: pip install h5py numpy pytest
- run: pytest -v
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

38 changes: 25 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.15...3.25 FATAL_ERROR)

project(Annoy
DESCRIPTION "Approximate Nearest Neighbors Oh Yeah"
VERSION 1.17.0
LANGUAGES CXX
)
DESCRIPTION "Approximate Nearest Neighbors Oh Yeah"
VERSION 1.17.1
LANGUAGES CXX)

add_library(Annoy INTERFACE)
add_library(Annoy::Annoy ALIAS Annoy)

set(ANNOY_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/annoy)
file(MAKE_DIRECTORY ${ANNOY_INCLUDE_DIR})
foreach (HEADER annoylib.h kissrandom.h mman.h)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/src/${HEADER} DESTINATION ${ANNOY_INCLUDE_DIR})
endforeach()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/${HEADER}" "${CMAKE_CURRENT_BINARY_DIR}/include/annoy/${HEADER}" COPYONLY)
endforeach ()

target_include_directories(Annoy INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>)

# Install
include(GNUInstallDirs)

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

target_include_directories(Annoy INTERFACE include/)
install(TARGETS Annoy
EXPORT AnnoyTargets)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# Add Python set-up code here.
endif()
install(EXPORT AnnoyTargets
FILE AnnoyConfig.cmake
NAMESPACE Annoy::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/annoy)

export(TARGETS Annoy NAMESPACE Annoy:: FILE AnnoyConfig.cmake)
10 changes: 2 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ Annoy
:alt: Annoy example
:align: center

.. image:: https://img.shields.io/travis/spotify/annoy/master.svg?style=flat
:target: https://travis-ci.org/spotify/annoy

.. image:: https://ci.appveyor.com/api/projects/status/github/spotify/annoy?svg=true&pendingText=windows%20-%20Pending&passingText=windows%20-%20OK&failingText=windows%20-%20Failing
:target: https://ci.appveyor.com/project/erikbern/annoy

.. image:: https://img.shields.io/pypi/v/annoy.svg?style=flat
:target: https://pypi.python.org/pypi/annoy
.. image:: https://github.com/spotify/annoy/actions/workflows/ci.yml/badge.svg
:target: https://github.com/spotify/annoy/actions

Annoy (`Approximate Nearest Neighbors <http://en.wikipedia.org/wiki/Nearest_neighbor_search#Approximate_nearest_neighbor>`__ Oh Yeah) is a C++ library with Python bindings to search for points in space that are close to a given query point. It also creates large read-only file-based data structures that are `mmapped <https://en.wikipedia.org/wiki/Mmap>`__ into memory so that many processes may share the same data.

Expand Down
2 changes: 1 addition & 1 deletion annoy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from typing import Sized, overload
from typing_extensions import Literal, Protocol

class _Vector(Protocol, Sized):
def __getitem__(self, i: int) -> float: ...
def __getitem__(self, __index: int) -> float: ...

class AnnoyIndex:
f: int
Expand Down
21 changes: 0 additions & 21 deletions appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion examples/precision_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <map>
#include <random>


using namespace Annoy;
int precision(int f=40, int n=1000000){
std::chrono::high_resolution_clock::time_point t_start, t_end;

Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
# Various platform-dependent extras
extra_compile_args = ['-D_CRT_SECURE_NO_WARNINGS', '-fpermissive']
extra_link_args = []

# Not all CPUs have march as a tuning parameter
cputune = ['-march=native',]
if platform.machine() == 'ppc64le':
extra_compile_args += ['-mcpu=native',]

if platform.machine() == 'x86_64':
extra_compile_args += cputune
# do not apply march on Intel Darwin
if platform.system() != 'Darwin':
# Not all CPUs have march as a tuning parameter
extra_compile_args += ['-march=native',]

if os.name != 'nt':
extra_compile_args += ['-O3', '-ffast-math', '-fno-associative-math']
Expand Down Expand Up @@ -73,7 +73,7 @@
extra_link_args = manual_linker_args.split(',')

setup(name='annoy',
version='1.17.1',
version='1.17.3',
description='Approximate Nearest Neighbors in C++/Python optimized for memory usage and loading/saving to disk.',
packages=['annoy'],
package_data={'annoy': ['__init__.pyi', 'py.typed']},
Expand Down
24 changes: 22 additions & 2 deletions src/annoylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,11 @@ template<typename S, typename T, typename Distance, typename Random, class Threa

bool on_disk_build(const char* file, char** error=NULL) {
_on_disk = true;
#ifndef _MSC_VER
_fd = open(file, O_RDWR | O_CREAT | O_TRUNC, (int) 0600);
#else
_fd = _open(file, _O_RDWR | _O_CREAT | _O_TRUNC, (int) 0600);
#endif
if (_fd == -1) {
set_error_from_errno(error, "Unable to open");
_fd = 0;
Expand Down Expand Up @@ -1095,7 +1099,11 @@ template<typename S, typename T, typename Distance, typename Random, class Threa
return true;
} else {
// Delete file if it already exists (See issue #335)
#ifndef _MSC_VER
unlink(filename);
#else
_unlink(filename);
#endif

FILE *f = fopen(filename, "wb");
if (f == NULL) {
Expand Down Expand Up @@ -1132,12 +1140,20 @@ template<typename S, typename T, typename Distance, typename Random, class Threa

void unload() {
if (_on_disk && _fd) {
#ifndef _MSC_VER
close(_fd);
#else
_close(_fd);
#endif
munmap(_nodes, _s * _nodes_size);
} else {
if (_fd) {
// we have mmapped data
#ifndef _MSC_VER
close(_fd);
#else
_close(_fd);
#endif
munmap(_nodes, _n_nodes * _s);
} else if (_nodes) {
// We have heap allocated data
Expand All @@ -1149,7 +1165,11 @@ template<typename S, typename T, typename Distance, typename Random, class Threa
}

bool load(const char* filename, bool prefault=false, char** error=NULL) {
#ifndef _MSC_VER
_fd = open(filename, O_RDONLY, (int)0400);
#else
_fd = _open(filename, _O_RDONLY, (int)0400);
#endif
if (_fd == -1) {
set_error_from_errno(error, "Unable to open");
_fd = 0;
Expand Down Expand Up @@ -1197,7 +1217,7 @@ template<typename S, typename T, typename Distance, typename Random, class Threa
_loaded = true;
_built = true;
_n_items = m;
if (_verbose) annoylib_showUpdate("found %lu roots with degree %d\n", _roots.size(), m);
if (_verbose) annoylib_showUpdate("found %zu roots with degree %d\n", _roots.size(), m);
return true;
}

Expand Down Expand Up @@ -1387,7 +1407,7 @@ template<typename S, typename T, typename Distance, typename Random, class Threa
// If we didn't find a hyperplane, just randomize sides as a last option
while (_split_imbalance(children_indices[0], children_indices[1]) > 0.99) {
if (_verbose)
annoylib_showUpdate("\tNo hyperplane found (left has %ld children, right has %ld children)\n",
annoylib_showUpdate("\tNo hyperplane found (left has %zu children, right has %zu children)\n",
children_indices[0].size(), children_indices[1].size());

children_indices[0].clear();
Expand Down
2 changes: 2 additions & 0 deletions src/annoymodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ get_nns_to_python(const vector<int32_t>& result, const vector<float>& distances,
if ((t = PyTuple_Pack(2, l, d)) == NULL) {
goto error;
}
Py_XDECREF(l);
Py_XDECREF(d);

return t;

Expand Down
Loading

0 comments on commit edca4f6

Please # to comment.