annoy-rb 0.2.0 → 0.2.1

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: f81b49dd55acb002949f5da8cd3e1dc39ab14b2020cf61e9046dfe71356d603f
4
- data.tar.gz: 3cd782e87cc70d0517504bdfc233e720c5aeaa15d4f03c7887e0d859f84cc2cc
3
+ metadata.gz: 70396ca8391b29a97b873c9e19a604cbc7257ce4b78cdf8381be4e892c518b62
4
+ data.tar.gz: 56feaa427374443780b141a3edf3707cf350409a229367f052436f773b6d1c75
5
5
  SHA512:
6
- metadata.gz: dda8c77484034cbaaf3f9b5a6ea6558040350ef3e75121b699aab5f011722a0d79039c037ee63641cd1da7588d5e7dedb56fae91a37489300e1780934eaec80d
7
- data.tar.gz: 8ad8aef4eac7ec930f4f1ffea12db8d944a7ee36e2140c7533ab4054586024af42befc3a113312d6289e5587a45b4f500c109dccad17330f0a20b5e349018a9a
6
+ metadata.gz: a3c736168dcea72535931d759c849ffc006bfcfecf3cdca704fc0b1859712a810817bfc7581f87dc40754bedea07563dd5ad777ca54b028acc4d5c3dcf3f6671
7
+ data.tar.gz: 65ada80b03e1e1ffec4353f7db9c77c2aca8bc79523229b8b52865f38524a272bac10c650d0333b46fee2d13c8109a1fa61ee41d2eb022eaeefdee0509a3bf54
@@ -0,0 +1,21 @@
1
+ name: build
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: [ '2.5', '2.6', '2.7' ]
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set upt Ruby ${{ matrix.ruby }}
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ - name: Build and test with Rake
18
+ run: |
19
+ gem install bundler
20
+ bundle install --jobs 4 --retry 3
21
+ bundle exec rake
@@ -1,3 +1,7 @@
1
+ ## 0.2.1
2
+ - Fix to free char array of error message before calling rb_raise.
3
+ - Fix to use array allocated with ruby_xmalloc instead of vector class in C++.
4
+
1
5
  ## 0.2.0
2
6
  - Update bundled Annoy version to 1.17.0.
3
7
  - Support multithreaded index building.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Annoy.rb
2
2
 
3
- [![Build Status](https://travis-ci.org/yoshoku/annoy.rb.svg?branch=master)](https://travis-ci.org/yoshoku/annoy.rb)
3
+ [![Build Status](https://github.com/yoshoku/annoy.rb/workflows/build/badge.svg)](https://github.com/yoshoku/annoy.rb/actions?query=workflow%3Abuild)
4
4
  [![Gem Version](https://badge.fury.io/rb/annoy-rb.svg)](https://badge.fury.io/rb/annoy-rb)
5
5
  [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/yoshoku/annoy.rb/blob/master/LICENSE.txt)
6
6
  [![Documentation](http://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/annoy.rb/doc/)
@@ -25,6 +25,10 @@ Or install it yourself as:
25
25
 
26
26
  Note: Annoy.rb does not require the installation of another external library.
27
27
 
28
+ ## Documentation
29
+
30
+ * [Annoy.rb API Documentation](https://yoshoku.github.io/annoy.rb/doc/)
31
+
28
32
  ## Usage
29
33
 
30
34
  ```ruby
@@ -101,18 +101,21 @@ template<class T, typename F> class RbAnnoyIndex
101
101
  return Qfalse;
102
102
  }
103
103
 
104
- std::vector<F> vec(n_dims, 0);
104
+ F* vec = (F*)ruby_xmalloc(n_dims * sizeof(F));
105
105
  for (int i = 0; i < n_dims; i++) {
106
106
  vec[i] = typeid(F) == typeid(double) ? NUM2DBL(rb_ary_entry(arr, i)) : NUM2UINT(rb_ary_entry(arr, i));
107
107
  }
108
108
 
109
109
  char* error;
110
- if (!get_annoy_index(self)->add_item(idx, &vec[0], &error)) {
111
- rb_raise(rb_eRuntimeError, "%s", error);
110
+ if (!get_annoy_index(self)->add_item(idx, vec, &error)) {
111
+ VALUE error_str = rb_str_new_cstr(error);
112
112
  free(error);
113
+ ruby_xfree(vec);
114
+ rb_raise(rb_eRuntimeError, "%s", StringValuePtr(error_str));
113
115
  return Qfalse;
114
116
  }
115
117
 
118
+ ruby_xfree(vec);
116
119
  return Qtrue;
117
120
  };
118
121
 
@@ -120,13 +123,12 @@ template<class T, typename F> class RbAnnoyIndex
120
123
  const int n_trees = NUM2INT(_n_trees);
121
124
  const int n_jobs = NUM2INT(_n_jobs);
122
125
  char* error;
123
-
124
126
  if (!get_annoy_index(self)->build(n_trees, n_jobs, &error)) {
125
- rb_raise(rb_eRuntimeError, "%s", error);
127
+ VALUE error_str = rb_str_new_cstr(error);
126
128
  free(error);
129
+ rb_raise(rb_eRuntimeError, "%s", StringValuePtr(error_str));
127
130
  return Qfalse;
128
131
  }
129
-
130
132
  return Qtrue;
131
133
  };
132
134
 
@@ -134,13 +136,12 @@ template<class T, typename F> class RbAnnoyIndex
134
136
  const char* filename = StringValuePtr(_filename);
135
137
  const bool prefault = _prefault == Qtrue ? true : false;
136
138
  char* error;
137
-
138
139
  if (!get_annoy_index(self)->save(filename, prefault, &error)) {
139
- rb_raise(rb_eRuntimeError, "%s", error);
140
+ VALUE error_str = rb_str_new_cstr(error);
140
141
  free(error);
142
+ rb_raise(rb_eRuntimeError, "%s", StringValuePtr(error_str));
141
143
  return Qfalse;
142
144
  }
143
-
144
145
  return Qtrue;
145
146
  };
146
147
 
@@ -148,13 +149,12 @@ template<class T, typename F> class RbAnnoyIndex
148
149
  const char* filename = StringValuePtr(_filename);
149
150
  const bool prefault = _prefault == Qtrue ? true : false;
150
151
  char* error;
151
-
152
152
  if (!get_annoy_index(self)->load(filename, prefault, &error)) {
153
- rb_raise(rb_eRuntimeError, "%s", error);
153
+ VALUE error_str = rb_str_new_cstr(error);
154
154
  free(error);
155
+ rb_raise(rb_eRuntimeError, "%s", StringValuePtr(error_str));
155
156
  return Qfalse;
156
157
  }
157
-
158
158
  return Qtrue;
159
159
  };
160
160
 
@@ -208,7 +208,7 @@ template<class T, typename F> class RbAnnoyIndex
208
208
  return Qfalse;
209
209
  }
210
210
 
211
- std::vector<F> vec(n_dims, 0);
211
+ F* vec = (F*)ruby_xmalloc(n_dims * sizeof(F));
212
212
  for (int i = 0; i < n_dims; i++) {
213
213
  vec[i] = typeid(F) == typeid(double) ? NUM2DBL(rb_ary_entry(_vec, i)) : NUM2UINT(rb_ary_entry(_vec, i));
214
214
  }
@@ -219,7 +219,9 @@ template<class T, typename F> class RbAnnoyIndex
219
219
  std::vector<int> neighbors;
220
220
  std::vector<F> distances;
221
221
 
222
- get_annoy_index(self)->get_nns_by_vector(&vec[0], n_neighbors, search_k, &neighbors, include_distances ? &distances : NULL);
222
+ get_annoy_index(self)->get_nns_by_vector(vec, n_neighbors, search_k, &neighbors, include_distances ? &distances : NULL);
223
+
224
+ ruby_xfree(vec);
223
225
 
224
226
  const int sz_neighbors = neighbors.size();
225
227
  VALUE neighbors_arr = rb_ary_new2(sz_neighbors);
@@ -246,15 +248,16 @@ template<class T, typename F> class RbAnnoyIndex
246
248
  static VALUE _annoy_index_get_item(VALUE self, VALUE _idx) {
247
249
  const int idx = NUM2INT(_idx);
248
250
  const int n_dims = get_annoy_index(self)->get_f();
249
- std::vector<F> vec(n_dims, 0);
251
+ F* vec = (F*)ruby_xmalloc(n_dims * sizeof(F));
250
252
  VALUE arr = rb_ary_new2(n_dims);
251
253
 
252
- get_annoy_index(self)->get_item(idx, &vec[0]);
254
+ get_annoy_index(self)->get_item(idx, vec);
253
255
 
254
256
  for (int i = 0; i < n_dims; i++) {
255
257
  rb_ary_store(arr, i, typeid(F) == typeid(double) ? DBL2NUM(vec[i]) : UINT2NUM(vec[i]));
256
258
  }
257
259
 
260
+ ruby_xfree(vec);
258
261
  return arr;
259
262
  };
260
263
 
@@ -279,8 +282,9 @@ template<class T, typename F> class RbAnnoyIndex
279
282
  const char* filename = StringValuePtr(_filename);
280
283
  char* error;
281
284
  if (!get_annoy_index(self)->on_disk_build(filename, &error)) {
282
- rb_raise(rb_eRuntimeError, "%s", error);
285
+ VALUE error_str = rb_str_new_cstr(error);
283
286
  free(error);
287
+ rb_raise(rb_eRuntimeError, "%s", StringValuePtr(error_str));
284
288
  return Qfalse;
285
289
  }
286
290
  return Qtrue;
@@ -3,5 +3,5 @@
3
3
  # Annoy.rb is a Ruby wrapper for Annoy (Approximate Nearest Neighbors Oh Yeah).
4
4
  module Annoy
5
5
  # The version of Annoy.rb you are using.
6
- VERSION = '0.2.0'.freeze
6
+ VERSION = '0.2.1'.freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annoy-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-19 00:00:00.000000000 Z
11
+ date: 2020-10-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Annoy.rb is a Ruby binding for the Annoy (Approximate Nearest Neighbors
14
14
  Oh Yeah).
@@ -19,9 +19,9 @@ extensions:
19
19
  - ext/annoy/extconf.rb
20
20
  extra_rdoc_files: []
21
21
  files:
22
+ - ".github/workflows/build.yml"
22
23
  - ".gitignore"
23
24
  - ".rspec"
24
- - ".travis.yml"
25
25
  - CHANGELOG.md
26
26
  - CODE_OF_CONDUCT.md
27
27
  - Gemfile
@@ -45,7 +45,7 @@ metadata:
45
45
  source_code_uri: https://github.com/yoshoku/annoy.rb
46
46
  changelog_uri: https://github.com/yoshoku/annoy.rb/blob/master/CHANGELOG.md
47
47
  documentation_uri: https://yoshoku.github.io/annoy.rb/doc/
48
- post_install_message:
48
+ post_install_message:
49
49
  rdoc_options: []
50
50
  require_paths:
51
51
  - lib
@@ -60,8 +60,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 3.1.2
64
- signing_key:
63
+ rubygems_version: 3.1.4
64
+ signing_key:
65
65
  specification_version: 4
66
66
  summary: Ruby binding for the Annoy (Approximate Nearest Neighbors Oh Yeah).
67
67
  test_files: []
@@ -1,12 +0,0 @@
1
- ---
2
- os: linux
3
- dist: xenial
4
- language: ruby
5
- cache: bundler
6
- rvm:
7
- - '2.5'
8
- - '2.6'
9
- - '2.7'
10
-
11
- before_install:
12
- - gem install bundler -v 2.1.2