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 +4 -4
- data/.github/workflows/build.yml +21 -0
- data/CHANGELOG.md +4 -0
- data/README.md +5 -1
- data/ext/annoy/annoy.hpp +21 -17
- data/lib/annoy/version.rb +1 -1
- metadata +7 -7
- data/.travis.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70396ca8391b29a97b873c9e19a604cbc7257ce4b78cdf8381be4e892c518b62
|
4
|
+
data.tar.gz: 56feaa427374443780b141a3edf3707cf350409a229367f052436f773b6d1c75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Annoy.rb
|
2
2
|
|
3
|
-
[![Build Status](https://
|
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
|
data/ext/annoy/annoy.hpp
CHANGED
@@ -101,18 +101,21 @@ template<class T, typename F> class RbAnnoyIndex
|
|
101
101
|
return Qfalse;
|
102
102
|
}
|
103
103
|
|
104
|
-
|
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,
|
111
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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(
|
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
|
-
|
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,
|
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
|
-
|
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;
|
data/lib/annoy/version.rb
CHANGED
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.
|
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-
|
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.
|
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: []
|