ngt 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +1 -1
- data/lib/ngt/ffi.rb +9 -0
- data/lib/ngt/index.rb +5 -11
- data/lib/ngt/optimizer.rb +3 -10
- data/lib/ngt/version.rb +1 -1
- data/lib/ngt.rb +4 -4
- data/vendor/aarch64-linux/libngt.so +0 -0
- data/vendor/arm64-darwin/libngt.dylib +0 -0
- data/vendor/x86_64-darwin/libngt.dylib +0 -0
- data/vendor/x86_64-linux/libngt.so +0 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51b1abeb2e5e028a0481de31deef2b037d71ad718e3a498b9a98eff6dcb4162f
|
4
|
+
data.tar.gz: c1f81fac7b48002a1718a9259e2594ac5ff1bfb204cf56e3badb163d567e6df0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 854abeff08d395907fe40042b123e95b8622733098ade14b9f9c47a8afd8e3856c78e40659521ee7853586ba6ab5208c37fd97bb7c7e028cb768f1c7b541335d
|
7
|
+
data.tar.gz: e0dd9ef7c8e2c298e8a07d98993a8b2ec0c651f960361b341ae3c49d613b10708e00e9256d454ef7a72bcc1ba03461233de1339447b744f3e4a16204f9910a15
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[NGT](https://github.com/yahoojapan/NGT) - high-speed approximate nearest neighbors - for Ruby
|
4
4
|
|
5
|
-
[![Build Status](https://github.com/ankane/ngt-ruby/workflows/build/badge.svg
|
5
|
+
[![Build Status](https://github.com/ankane/ngt-ruby/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/ngt-ruby/actions)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
data/lib/ngt/ffi.rb
CHANGED
@@ -76,5 +76,14 @@ module Ngt
|
|
76
76
|
attach_function :ngt_optimizer_execute, %i[pointer string string pointer], :bool
|
77
77
|
attach_function :ngt_optimizer_set, %i[pointer int int int float float float float double double pointer], :bool
|
78
78
|
attach_function :ngt_destroy_optimizer, %i[pointer], :void
|
79
|
+
|
80
|
+
def self.add_finalizer(pointer, method)
|
81
|
+
ObjectSpace.define_finalizer(pointer, finalize(pointer.to_i, method))
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.finalize(addr, method)
|
85
|
+
# must use proc instead of stabby lambda
|
86
|
+
proc { FFI.send(method, ::FFI::Pointer.new(:pointer, addr)) }
|
87
|
+
end
|
79
88
|
end
|
80
89
|
end
|
data/lib/ngt/index.rb
CHANGED
@@ -9,10 +9,11 @@ module Ngt
|
|
9
9
|
@path = path
|
10
10
|
|
11
11
|
@error = FFI.ngt_create_error_object
|
12
|
+
FFI.add_finalizer(@error, :ngt_destroy_error_object)
|
13
|
+
|
12
14
|
@property = ffi(:ngt_create_property)
|
15
|
+
FFI.add_finalizer(@property, :ngt_destroy_property)
|
13
16
|
ffi(:ngt_get_property, @index, @property)
|
14
|
-
|
15
|
-
ObjectSpace.define_finalizer(self, self.class.finalize(@error, @index, @property))
|
16
17
|
end
|
17
18
|
|
18
19
|
def dimensions
|
@@ -177,6 +178,8 @@ module Ngt
|
|
177
178
|
end
|
178
179
|
end
|
179
180
|
|
181
|
+
FFI.add_finalizer(index, :ngt_close_index)
|
182
|
+
|
180
183
|
super(index, path)
|
181
184
|
ensure
|
182
185
|
FFI.ngt_destroy_error_object(error) if error
|
@@ -197,15 +200,6 @@ module Ngt
|
|
197
200
|
Utils.ffi(*args)
|
198
201
|
end
|
199
202
|
|
200
|
-
def self.finalize(error, index, property)
|
201
|
-
# must use proc instead of stabby lambda
|
202
|
-
proc do
|
203
|
-
FFI.ngt_destroy_error_object(error)
|
204
|
-
FFI.ngt_close_index(index)
|
205
|
-
FFI.ngt_destroy_property(property)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
203
|
private
|
210
204
|
|
211
205
|
def narray?(data)
|
data/lib/ngt/optimizer.rb
CHANGED
@@ -4,12 +4,13 @@ module Ngt
|
|
4
4
|
|
5
5
|
def initialize(outgoing: 10, incoming: 120, queries: 100, low_accuracy_from: 0.3, low_accuracy_to: 0.5, high_accuracy_from: 0.8, high_accuracy_to: 0.9, gt_epsilon: 0.1, merge: 0.2)
|
6
6
|
@error = FFI.ngt_create_error_object
|
7
|
+
FFI.add_finalizer(@error, :ngt_destroy_error_object)
|
8
|
+
|
7
9
|
@optimizer = ffi(:ngt_create_optimizer, true)
|
10
|
+
FFI.add_finalizer(@optimizer, :ngt_destroy_optimizer)
|
8
11
|
|
9
12
|
ffi(:ngt_optimizer_set, @optimizer, outgoing, incoming, queries, low_accuracy_from,
|
10
13
|
low_accuracy_to, high_accuracy_from, high_accuracy_to, gt_epsilon, merge)
|
11
|
-
|
12
|
-
ObjectSpace.define_finalizer(self, self.class.finalize(@optimizer, @error))
|
13
14
|
end
|
14
15
|
|
15
16
|
def execute(in_index_path, out_index_path)
|
@@ -20,14 +21,6 @@ module Ngt
|
|
20
21
|
ffi(:ngt_optimizer_adjust_search_coefficients, @optimizer, path(index_path))
|
21
22
|
end
|
22
23
|
|
23
|
-
def self.finalize(optimizer, error)
|
24
|
-
# must use proc instead of stabby lambda
|
25
|
-
proc do
|
26
|
-
FFI.ngt_destroy_optimizer(optimizer)
|
27
|
-
FFI.ngt_destroy_error_object(error)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
24
|
private
|
32
25
|
|
33
26
|
def path(obj)
|
data/lib/ngt/version.rb
CHANGED
data/lib/ngt.rb
CHANGED
@@ -5,10 +5,10 @@ require "ffi"
|
|
5
5
|
require "tmpdir"
|
6
6
|
|
7
7
|
# modules
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
require_relative "ngt/utils"
|
9
|
+
require_relative "ngt/index"
|
10
|
+
require_relative "ngt/optimizer"
|
11
|
+
require_relative "ngt/version"
|
12
12
|
|
13
13
|
module Ngt
|
14
14
|
class Error < StandardError; end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -64,14 +64,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
64
|
requirements:
|
65
65
|
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
67
|
+
version: '3.1'
|
68
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
69
|
requirements:
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0'
|
73
73
|
requirements: []
|
74
|
-
rubygems_version: 3.
|
74
|
+
rubygems_version: 3.5.16
|
75
75
|
signing_key:
|
76
76
|
specification_version: 4
|
77
77
|
summary: High-speed approximate nearest neighbors for Ruby
|