ngt 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +9 -4
- data/lib/ngt/ffi.rb +10 -7
- data/lib/ngt/index.rb +1 -1
- data/lib/ngt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d97bd9eb8a0db31ece99f2ad749e00b9b46ae5929f4d4be4863aae7f68bc2167
|
4
|
+
data.tar.gz: 64bef298d58ed4e5c8c7215d7bc19e7b918b51a2f83113277da3a8c7d08080a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ef9696c68b051f1f225cdb2bcdce06859ea4d6321382a0702e4c32915d3d347caa4d4a697b54ada8f1956602b158f0f5bcb2006561052d0e9b0acd2962fc68c
|
7
|
+
data.tar.gz: f6f027ec3f216660482323bb44a822f8bcca59ff5e0bf35ce3f27dbb7331e933bf700de73a20a0094790f758fc5b3a946378ec8b8ad69444b472bbf6a9a9a21d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,15 @@
|
|
2
2
|
|
3
3
|
[NGT](https://github.com/yahoojapan/NGT) - high-speed approximate nearest neighbors - for Ruby
|
4
4
|
|
5
|
+
[](https://travis-ci.org/ankane/ngt)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
|
-
First, [install NGT](https://github.com/yahoojapan/NGT/blob/master/README.md#Installation).
|
9
|
+
First, [install NGT](https://github.com/yahoojapan/NGT/blob/master/README.md#Installation). For Homebrew, use:
|
10
|
+
|
11
|
+
```sh
|
12
|
+
brew install ngt
|
13
|
+
```
|
8
14
|
|
9
15
|
Add this line to your application’s Gemfile:
|
10
16
|
|
@@ -51,7 +57,7 @@ index.save
|
|
51
57
|
Load an index
|
52
58
|
|
53
59
|
```ruby
|
54
|
-
Ngt::Index.new(path)
|
60
|
+
index = Ngt::Index.new(path)
|
55
61
|
```
|
56
62
|
|
57
63
|
Get an object by id
|
@@ -96,8 +102,7 @@ result = index.search(query, size: 3)
|
|
96
102
|
|
97
103
|
result.each do |res|
|
98
104
|
puts "#{res[:id]}, #{res[:distance]}"
|
99
|
-
|
100
|
-
p object
|
105
|
+
p index.object(res[:id])
|
101
106
|
end
|
102
107
|
```
|
103
108
|
|
data/lib/ngt/ffi.rb
CHANGED
@@ -12,6 +12,9 @@ module Ngt
|
|
12
12
|
# https://github.com/yahoojapan/NGT/blob/master/lib/NGT/Capi.h
|
13
13
|
# keep same order
|
14
14
|
|
15
|
+
# use uint32 instead of uint32_t
|
16
|
+
# to prevent "unable to resolve type" error on Ubuntu
|
17
|
+
|
15
18
|
class ObjectDistance < ::FFI::Struct
|
16
19
|
layout :id, :int,
|
17
20
|
:distance, :float
|
@@ -36,15 +39,15 @@ module Ngt
|
|
36
39
|
attach_function :ngt_set_property_distance_type_hamming, %i[pointer pointer], :bool
|
37
40
|
attach_function :ngt_set_property_distance_type_jaccard, %i[pointer pointer], :bool
|
38
41
|
attach_function :ngt_set_property_distance_type_cosine, %i[pointer pointer], :bool
|
39
|
-
attach_function :ngt_batch_insert_index, %i[pointer pointer
|
40
|
-
attach_function :ngt_create_index, %i[pointer
|
42
|
+
attach_function :ngt_batch_insert_index, %i[pointer pointer uint32 pointer pointer], :bool
|
43
|
+
attach_function :ngt_create_index, %i[pointer uint32 pointer], :bool
|
41
44
|
attach_function :ngt_remove_index, %i[pointer int pointer], :bool
|
42
|
-
attach_function :ngt_insert_index, %i[pointer pointer
|
43
|
-
attach_function :ngt_insert_index_as_float, %i[pointer pointer
|
45
|
+
attach_function :ngt_insert_index, %i[pointer pointer uint32 pointer], :int
|
46
|
+
attach_function :ngt_insert_index_as_float, %i[pointer pointer uint32 pointer], :int
|
44
47
|
attach_function :ngt_create_empty_results, %i[pointer], :pointer
|
45
|
-
attach_function :ngt_search_index, %i[pointer pointer
|
46
|
-
attach_function :ngt_get_result_size, %i[pointer pointer], :
|
47
|
-
attach_function :ngt_get_result, %i[pointer
|
48
|
+
attach_function :ngt_search_index, %i[pointer pointer int32 size_t float float pointer pointer], :bool
|
49
|
+
attach_function :ngt_get_result_size, %i[pointer pointer], :uint32
|
50
|
+
attach_function :ngt_get_result, %i[pointer uint32 pointer], ObjectDistance.by_value
|
48
51
|
attach_function :ngt_get_object_space, %i[pointer pointer], :pointer
|
49
52
|
attach_function :ngt_get_object_as_float, %i[pointer int pointer], :pointer
|
50
53
|
attach_function :ngt_get_object_as_integer, %i[pointer int pointer], :pointer
|
data/lib/ngt/index.rb
CHANGED
@@ -29,7 +29,7 @@ module Ngt
|
|
29
29
|
obj = ::FFI::MemoryPointer.new(:float, flat_objects.size)
|
30
30
|
obj.write_array_of_float(flat_objects)
|
31
31
|
|
32
|
-
ids = ::FFI::MemoryPointer.new(:
|
32
|
+
ids = ::FFI::MemoryPointer.new(:uint32, objects.size)
|
33
33
|
ffi(:ngt_batch_insert_index, @index, obj, objects.size, ids)
|
34
34
|
|
35
35
|
build_index(num_threads: num_threads)
|
data/lib/ngt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ngt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|