ngt 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 349ccec555d0066d9ccf024a40cf0ecaa478ac628d7cc1240ac2ffa288735a29
4
- data.tar.gz: 6242793a35080d8b52c650ebb3b24bee762b36bcf5035bd99263ac2657f3f12c
3
+ metadata.gz: bff3db4fe839a13d6c1d0c5c959c4e42bf738670c69b0fd4792a1209c7e7165f
4
+ data.tar.gz: ed3c9d563903be2c8d550bccbeb7efd40cb78b1f5d78e8d6846e9dc4063f78f6
5
5
  SHA512:
6
- metadata.gz: 9fe092180d1a68e7843089a2a6c1fda1475ca2ad05d302209db501704994b694a5e94ac34daa9898d26efdf739c775741b79e24bd5aa3fbcdd58fb28063c1bef
7
- data.tar.gz: 866b54645ab021c69b50967ae5952d159d4e45ff850f450500c550c154a5f9b224ca45e36ead4f4d3ed96d43a26d3ad601040ba91a31671d815789161a981a83
6
+ metadata.gz: 7e85cd285bac398611fcae5d3bae99f9b13422b1dab068387f787d91b9137eb7ffdf6b96e1d64a5719ce6eef8fef8c2a2e7f8553893ee535f8f9f09ca55ca9b3
7
+ data.tar.gz: 9645e1859e2c65d88688b23006a94bb272b8ad19c6df64a43427c8842d1e49b26fe3431524c02c74eefacfa0c20360760fb6c31691583190d1d323efb688a7ed
@@ -1,3 +1,8 @@
1
+ ## 0.2.3 (2020-03-08)
2
+
3
+ - Added `load` method
4
+ - Deprecated `create` and passing path to `new`
5
+
1
6
  ## 0.2.2 (2020-02-11)
2
7
 
3
8
  - Fixed `Could not find NGT` error on some Linux platforms
@@ -11,6 +16,7 @@
11
16
  - Changed to Apache 2.0 license to match NGT
12
17
  - Added shared libraries
13
18
  - Added optimizer
19
+ - Improved performance of `batch_insert` for Numo
14
20
 
15
21
  ## 0.1.1 (2019-10-27)
16
22
 
data/README.md CHANGED
@@ -29,7 +29,7 @@ objects = [
29
29
  Create an index
30
30
 
31
31
  ```ruby
32
- index = Ngt::Index.create(path, dimensions)
32
+ index = Ngt::Index.new(dimensions)
33
33
  ```
34
34
 
35
35
  Insert objects
@@ -47,13 +47,13 @@ index.search(query, size: 3)
47
47
  Save the index
48
48
 
49
49
  ```ruby
50
- index.save
50
+ index.save(path)
51
51
  ```
52
52
 
53
53
  Load an index
54
54
 
55
55
  ```ruby
56
- index = Ngt::Index.new(path)
56
+ index = Ngt::Index.load(path)
57
57
  ```
58
58
 
59
59
  Get an object by id
@@ -96,9 +96,8 @@ objects = []
96
96
  objects << dim.times.map { rand(100) }
97
97
  end
98
98
 
99
- index = Ngt::Index.create("tmp", dim)
99
+ index = Ngt::Index.new(dim)
100
100
  index.batch_insert(objects)
101
- index.save
102
101
 
103
102
  query = objects[0]
104
103
  result = index.search(query, size: 3)
data/lib/ngt.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # dependencies
2
2
  require "ffi"
3
3
 
4
+ # stdlib
5
+ require "tmpdir"
6
+
4
7
  # modules
5
8
  require "ngt/utils"
6
9
  require "ngt/index"
@@ -80,8 +80,9 @@ module Ngt
80
80
  ret
81
81
  end
82
82
 
83
- def save(path: nil)
84
- path ||= @path
83
+ def save(path2 = nil, path: nil)
84
+ warn "[ngt] Passing path as an option is deprecated - use an argument instead" if path
85
+ path ||= path2 || @path
85
86
  ffi(:ngt_save_index, @index, path)
86
87
  end
87
88
 
@@ -89,9 +90,20 @@ module Ngt
89
90
  FFI.ngt_close_index(@index)
90
91
  end
91
92
 
92
- def self.create(path, dimension, edge_size_for_creation: 10,
93
+ def self.new(dimension, path: nil, edge_size_for_creation: 10,
93
94
  edge_size_for_search: 40, object_type: "Float", distance_type: "L2")
94
95
 
96
+ # called from load
97
+ return super(path) if path && dimension.nil?
98
+
99
+ # TODO remove in 0.3.0
100
+ create = dimension.is_a?(Integer) || path
101
+ unless create
102
+ warn "[ngt] Passing a path to new is deprecated - use load instead"
103
+ return super(dimension)
104
+ end
105
+
106
+ path ||= Dir.mktmpdir
95
107
  error = FFI.ngt_create_error_object
96
108
  property = ffi(:ngt_create_property, error)
97
109
  ffi(:ngt_set_property_dimension, property, dimension, error)
@@ -128,13 +140,22 @@ module Ngt
128
140
  FFI.ngt_close_index(index)
129
141
  index = nil
130
142
 
131
- Index.new(path)
143
+ super(path)
132
144
  ensure
133
145
  FFI.ngt_destroy_error_object(error) if error
134
146
  FFI.ngt_destroy_property(property) if property
135
147
  FFI.ngt_close_index(index) if index
136
148
  end
137
149
 
150
+ def self.load(path)
151
+ new(nil, path: path)
152
+ end
153
+
154
+ def self.create(path, dimension, **options)
155
+ warn "[ngt] create is deprecated - use new instead"
156
+ new(dimension, path: path, **options)
157
+ end
158
+
138
159
  # private
139
160
  def self.ffi(*args)
140
161
  Utils.ffi(*args)
@@ -1,3 +1,3 @@
1
1
  module Ngt
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
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.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-12 00:00:00.000000000 Z
11
+ date: 2020-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi