Skip to content

Commit

Permalink
update setup.py to build ngtpy for QG and QBG
Browse files Browse the repository at this point in the history
  • Loading branch information
masajiro committed Sep 21, 2022
1 parent 55580de commit 4e93ecd
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 118 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,6 @@ QG and QBG require BLAS and LAPACK libraries. If you would not like to install t

$ brew install ngt


License
-------

Copyright (C) 2015 Yahoo Japan Corporation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.

Contributor License Agreement
-----------------------------

This project requires contributors to accept the terms in the [Contributor License Agreement (CLA)](https://gist.github.com/yahoojapanoss/9bf8afd6ea67f32d29b4082abf220340).

Please note that contributors to the NGT repository on GitHub (https://github.com/yahoojapan/NGT) shall be deemed to have accepted the CLA without individual written agreements.

NGT (Graph and tree-based method)
=================================

Expand Down Expand Up @@ -227,6 +207,26 @@ The followings are the results of [ann benchmarks](https://github.com/erikbern/a
#### sift-128-euclidean
<img src="./tests/ann-benchmarks-results/sift-128-euclidean.png?raw=true" width="400">


License
-------

Copyright (C) 2015 Yahoo Japan Corporation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.

Contributor License Agreement
-----------------------------

This project requires contributors to accept the terms in the [Contributor License Agreement (CLA)](https://gist.github.com/yahoojapanoss/9bf8afd6ea67f32d29b4082abf220340).

Please note that contributors to the NGT repository on GitHub (https://github.com/yahoojapan/NGT) shall be deemed to have accepted the CLA without individual written agreements.

Contact Person
--------------
[masajiro](https://github.com/masajiro)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.3
2.0.4
10 changes: 8 additions & 2 deletions lib/NGT/NGTQ/Quantizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,8 @@ class QuantizedObjectDistanceFloat : public QuantizedObjectDistance {
}




#if defined(NGTQG_AVX2)
inline float horizontalMin(__m256 &a, __m256 &b, float noOfObjects) {
__m256 seq = _mm256_set_ps(8, 7, 6, 5, 4, 3, 2, 1);
__m256 mask = _mm256_sub_ps(_mm256_set1_ps(noOfObjects), seq);
Expand All @@ -1604,7 +1605,8 @@ class QuantizedObjectDistanceFloat : public QuantizedObjectDistance {
//std::cerr << "ret=" << data[0] << std::endl;
return data[0];
}

#endif

#if defined(NGTQG_AVX512) || defined(NGTQG_AVX2)
#if defined(NGTQ_TOTAL_SCALE_OFFSET_COMPRESSION)
#ifdef NGTQBG_MIN
Expand Down Expand Up @@ -1896,7 +1898,11 @@ class QuantizedObjectDistanceFloat : public QuantizedObjectDistance {
#endif /// NGTQ_TOTAL_SCALE_OFFSET_COMPRESSION ////////////////////////////////////////

#else
#ifdef NGTQBG_MIN
inline float operator()(void *inv, float *distances, size_t size, DistanceLookupTableUint8 &distanceLUT) {
#else
inline void operator()(void *inv, float *distances, size_t size, DistanceLookupTableUint8 &distanceLUT) {
#endif
uint8_t *localID = static_cast<uint8_t*>(inv);
size_t numOfAlignedSubvectors = ((localDivisionNo - 1) / NGTQ_BATCH_SIZE + 1) * NGTQ_BATCH_SIZE;
size_t alignedSize = ((size - 1) / 2 + 1) * 2;
Expand Down
33 changes: 1 addition & 32 deletions python/README-jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
```
pip3 install ngt
```
ctypes (ngt) の python binding を利用になりたい場合には、さらに、[README-jp](../README-jp.md#build)にしたがってNGTライブラリをインストールしてください。

また、ソースコードからも pybind11 と ctypes のpython binding をインストールできます。ただし、python NGTをインストールする前にNGTライブラリを[README-jp](../README-jp.md#build)にしたがって**必ず**インストールしてください。
また、ソースコードからもpython bindingsをインストールできます。ただし、python bindingsをインストールする前にNGTライブラリを[README-jp](../README-jp.md#build)にしたがって**必ず**インストールしてください。
```
pip3 install pybind11
pip3 install numpy
Expand Down Expand Up @@ -56,32 +54,3 @@ ngtpy(pybind11)はngt(ctypes)より処理時間を削減できます。特に短

ご参考: [sample.py](sample/sample.py).

### ngt (ctypes)

```python
from ngt import base as ngt
import random

dim = 10
objects = []
for i in range(0, 100) :
vector = random.sample(range(100), dim)
objects.append(vector)

query = objects[0]
index = ngt.Index.create(b"tmp", dim)
index.insert(objects)
# You can also insert objects from a file like this.
# index.insert_from_tsv('list.tsv')

index.save()
# You can load saved the index like this.
# index = ngt.Index(b"tmp")

result = index.search(query, 3)

for i, o in enumerate(result) :
print(str(i) + ": " + str(o.id) + ", " + str(o.distance))
object = index.get_object(o.id)
print(object)
```
70 changes: 58 additions & 12 deletions python/README-ngtpy-jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Class Index
### search
指定されたクエリオブジェクトに対する近傍のオブジェクトを検索します。

object search(self: ngtpy.Index, query: object, size: int, epsilon: float=0.1, edge_size: int=-1, with_distance: bool=True)
object search(self: ngtpy.Index, query: object, size: int, epsilon: float, edge_size: int, with_distance: bool=True)

**Returns**
検索結果としてタプル(ID、距離)のリスト
Expand All @@ -132,18 +132,21 @@ Class Index
距離付きオブジェクトIDの検索結果を返すことを指定します。Falseは結果がオブジェクトIDののみのリストとなることを意味します。

### set
検索パラメータを指定します
検索パラメータのデフォルト値を指定します

set(self: ngtpy.Index, num_of_search_objects: int, search_radius: float)
set(self: ngtpy.Index, num_of_search_objects: int, epsilon: float, search_radius: float)

**Returns**
なし。

**num_of_search_objects**
検索結果数を指定します。デフォルトは10です。
検索結果数を指定します。初期デフォルト値は20です。

**epsilon**
グラフの探索範囲を決定する変数イプシロンを指定します。初期デフォルト値は0.1です。

**search_radius**
検索範囲を指定します。デフォルトは無限です
検索範囲を指定します。初期デフォルト値は無限です

### export_index
インデックスをエクスポートします。
Expand Down Expand Up @@ -207,7 +210,6 @@ FUNCTIONS
- __Float16__: 2 バイト浮動小数点
- __Byte__: 1 バイト符号なし整数


Class Optimizer
===============

Expand All @@ -231,7 +233,6 @@ Class Optimizer
### execute
事前に指定されたパラメータを用いて指定されたインデックスから新なインデックスを再構築し、検索時の係数を最適化します。この最適化は*adjust_search_coefficients*を呼び出すのと同じです。


execute(self: ngtpy.Optimizer, in_index_path: str, out_index_path: str)


Expand All @@ -250,16 +251,61 @@ Class Optimizer
**index_path**
最適化するインデックスを指定します。

Class QuantizedIndex
===========

## Member Functions

### \_\_init\_\_
指定された量子化インデックスをオープンし、そのインデックスのオブジェクトを生成します。

__init__(self: ngtpy.QuantizedIndex, path: str, zero_based_numbering: bool=True, log_disabled: bool=False)

**Returns**
なし

**path**
オープンするインデックスのパスを指定します。量子化インデックスは`qbg create-qg``qbg build-qg`で事前にONNGやANNGからビルドしてください。pythonでの量子化する関数はまだ利用できません。

**zero_based_numbering**
オブジェクトIDが0から始まることを指定します。Falseは1から始まることを意味します。

**log_disabled**
処理の進捗に関する標準エラーのメッセージを無効にします。

### search
指定されたクエリオブジェクトに対する近傍のオブジェクトを検索します。

object search(self: ngtpy.QuantizedIndex, query: object, size: int=20, epsilon: float, result_expansion: float)

**Returns**
検索結果としてタプル(ID、距離)のリスト

**query**
クエリオブジェクトを指定します。

**size**
検索結果として返るオブジェクトの数を指定します。

**epsilon**
グラフの探索範囲を決定する変数イプシロンを指定します。

**result_expansion**
検索結果数に対する内部の近似検索結果数の拡張割合を指定します。例えば、この割合が10で検索結果数が20の場合には、検索処理中の近似検索数は200に設定されます。大きな値ほど精度は高くなりますが、検索に時間がかかります。

### set
検索パラメータを指定します
検索パラメータのデフォルト値を指定します

set(self: ngtpy.Index, num_of_search_objects: int, search_radius: float)
set(self: ngtpy.QuantizedIndex, num_of_search_objects: int, epsilon: float, result_expansion: float)

**Returns**
なし。

**num_of_search_objects**
検索結果数を指定します。デフォルトは10です
検索結果数を指定します。初期デフォルト値は20です

**search_radius**
検索範囲を指定します。デフォルトは無限です。
**epsilon**
グラフの探索範囲を決定する変数イプシロンを指定します。初期デフォルト値は0.02です。

**result_expansion**
検索結果数に対する内部の近似検索結果数の拡張割合を指定します。初期デフォルト値は3.0です。
35 changes: 20 additions & 15 deletions python/README-ngtpy.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ The number of the registered objects.
### search
Search the nearest objects to the specified query object.

object search(self: ngtpy.Index, query: object, size: int, epsilon: float=0.1, edge_size: int=-1, with_distance: bool=True)
object search(self: ngtpy.Index, query: object, size: int, epsilon: float, edge_size: int, with_distance: bool=True)

**Returns**
The list of tuples(object ID, distance) as the search result.
Expand All @@ -135,18 +135,21 @@ Specify object IDs with distances as the result. False means that the result is


### set
Specify the search parameters.
Specify the default search parameters.

set(self: ngtpy.Index, num_of_search_objects: int, search_radius: float)
set(self: ngtpy.Index, num_of_search_objects: int, epsilon: float, search_radius: float)

**Returns**
None.

**num_of_search_objects**
Specify the number of search objects. The default is 10.
Specify the number of search objects. The initial default is 20.

**epsilon**
Specify the epsilon which defines the explored range for the graph. The initial default is 0.1.

**search_radius**
Specify the search radius. The default is infinity.
Specify the search radius. The initial default is infinity.

### export_index
Exports the index to a file.
Expand Down Expand Up @@ -213,7 +216,6 @@ Specify the data type of the objects.
- __Float16__: 2 byte floating point number
- __Byte__: 1 byte unsigned integer


Class Optimizer
===============

Expand Down Expand Up @@ -241,7 +243,7 @@ Reconstruct an index from the specified index with the previously specified para
execute(self: ngtpy.Optimizer, in_index_path: str, out_index_path: str)


**in_index_path**
**in_index_path**
Specify the input index path.

**out_index_path**
Expand All @@ -252,7 +254,7 @@ Optimize search coefficients.

adjust_search_coefficients(self: ngtpy.Optimizer, index_path: str)

**index_path**
**index_path**
Specify the index which is optimized.

Class QuantizedIndex
Expand All @@ -263,7 +265,7 @@ Class QuantizedIndex
### \_\_init\_\_
Open the specified quantized index and create the index object for the index.

__init__(self: ngtpy.Index, path: str, zero_based_numbering: bool=True, log_disabled: bool=False)
__init__(self: ngtpy.QuantizedIndex, path: str, zero_based_numbering: bool=True, log_disabled: bool=False)

**Returns**
None.
Expand All @@ -280,7 +282,7 @@ Disable stderr messages about the progression of an operation.
### search
Search the nearest objects to the specified query object.

object search(self: ngtpy.Index, query: object, size: int=20, epsilon: float=0.02, result_expansion: float=3.0)
object search(self: ngtpy.QuantizedIndex, query: object, size: int, epsilon: float, result_expansion: float)

**Returns**
The list of tuples(object ID, distance) as the search result.
Expand All @@ -298,16 +300,19 @@ Specify epsilon which defines the explored range for the quantized graph.
Specify the expansion ratio of the number of approximate inner search objects to the number of search objects. For example, when the ratio is 10 and the number of search objects is 20, the number of the approximate search objects is set to 200 inside the search processing. A larger value brings higher accuracy but slower searching.

### set
Specify the search parameters.
Specify the default search parameters.

set(self: ngtpy.Index, num_of_search_objects: int, search_radius: float)
set(self: ngtpy.QuantizedIndex, num_of_search_objects: int, search_radius: float, result_expansion: float)

**Returns**
None.

**num_of_search_objects**
Specify the number of search objects. The default is 10.
Specify the number of search objects. The initial default is 20.

**search_radius**
Specify the search radius. The default is infinity.
**epsilon**
Specify epsilon which defines the explored range for the graph. The initial default is 0.02.

**result_expansion**
Specify the expansion ratio of the number of approximate inner search objects to the number of search objects. The initial default is 3.0.

Loading

0 comments on commit 4e93ecd

Please sign in to comment.