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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94ae9612ba58d3e5aa3fecdea4ccb93e6ecaa8086c7b5e5e64a626962a3c7dbf
4
- data.tar.gz: 6bf8e3fc92f83994e47caf230027199a2da2c0464b5cce0cdaf0f861ce2b05e2
3
+ metadata.gz: 51b1abeb2e5e028a0481de31deef2b037d71ad718e3a498b9a98eff6dcb4162f
4
+ data.tar.gz: c1f81fac7b48002a1718a9259e2594ac5ff1bfb204cf56e3badb163d567e6df0
5
5
  SHA512:
6
- metadata.gz: 8580f88ad7c6fa1527445aeeba274e67bcf76612cf3aa2c100afe53ca62628df59237119d1878b3244517bd8c01a75cfc5015176c2baf9e2d6eb9617876d4fd1
7
- data.tar.gz: 92e66568528c8cc76fe38efdb2795106bea0e50ca1263bf659ef52e26b4f4c36e192e5180a304acd186c746f3b02a3cf2488c2e95c786d024174b8411e5f8fba
6
+ metadata.gz: 854abeff08d395907fe40042b123e95b8622733098ade14b9f9c47a8afd8e3856c78e40659521ee7853586ba6ab5208c37fd97bb7c7e028cb768f1c7b541335d
7
+ data.tar.gz: e0dd9ef7c8e2c298e8a07d98993a8b2ec0c651f960361b341ae3c49d613b10708e00e9256d454ef7a72bcc1ba03461233de1339447b744f3e4a16204f9910a15
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.5.0 (2024-10-23)
2
+
3
+ - Updated NGT to 2.2.4
4
+ - Dropped support for Ruby < 3.1
5
+
6
+ ## 0.4.2 (2023-07-24)
7
+
8
+ - Fixed error with `dup` and `clone`
9
+
1
10
  ## 0.4.1 (2022-12-08)
2
11
 
3
12
  - Added support for `:float16` object type
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?branch=master)](https://github.com/ankane/ngt-ruby/actions)
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
@@ -1,3 +1,3 @@
1
1
  module Ngt
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/ngt.rb CHANGED
@@ -5,10 +5,10 @@ require "ffi"
5
5
  require "tmpdir"
6
6
 
7
7
  # modules
8
- require "ngt/utils"
9
- require "ngt/index"
10
- require "ngt/optimizer"
11
- require "ngt/version"
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.1
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: 2022-12-09 00:00:00.000000000 Z
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: '2.7'
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.3.7
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