annoy-rb 0.2.3 → 0.6.0

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: 9a7ab55f832f0ce57d4e8c010e69fdcee979764cea2579d5833ae1d3b0c24af9
4
- data.tar.gz: 245451b8edd07984b8bcfd515bb1caa75a4164309954d9278aabce76ad9646c2
3
+ metadata.gz: 1ae4f03fb87f0ea9ab0ff8ff13eb5c011cfd51931e5b4fc63c9a480560e9b102
4
+ data.tar.gz: 815d1f92d975ad932cc608a50a0bf983477d4fb3554aec5cd2978d904fe766b1
5
5
  SHA512:
6
- metadata.gz: b4c357d55bba00461433a2d63350216eaecb45ab421b2acc5a51a7276eb6922ef58ae1ad6775bd847d56805207e24e23c93944b3e434acdd059bc67d2177e2db
7
- data.tar.gz: 4619de7cbde449ba58495ac1a98090cc0c8a6737d31769cb37134f1e351ddc1ad0ade9b4806a9e8d965a1e9272e9df11962f77d5380d6ad0f1819a6ef0dd2164
6
+ metadata.gz: 2dd6f50030ac181a66633ea63c1e616ddb3b931227ce002d25b8ec5fb5b7d9094e6e0970bb9367bfe63004bce448bdb318658d17bc089d7af2978cdfdc33c776
7
+ data.tar.gz: f6c5995f2a7986e2c6dfba83bccf3a41b52e564dfce503c4def30395c3c19287422a93d1e62fd5a139e824bf2372910c415cb6cc66c22c41833153790f3bbc1f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,41 @@
1
+ ## 0.6.0
2
+ - Add `dtype` argument to initialize method to specify the data type of vector element.
3
+ If you want to load a search index created with the Python bindings, specify 'float32' to the dtype argument.
4
+
5
+ ```
6
+ require 'annoy'
7
+
8
+ f = 40
9
+ t = Annoy::AnnoyIndex.new(n_features: f, metric: 'angular', dtype: 'float32')
10
+ t.load('index_with_python_bindings.ann')
11
+ ```
12
+
13
+ - Change the data type of item index from int to int32_t.
14
+ - Update type declarations and documentations.
15
+ - Introduce conventional commits.
16
+
17
+ ## 0.5.0
18
+ ### Breaking change
19
+ - Remove `-march=native` and `-DANNOYLIB_MULTITHREADED_BUILD` from CXXFLAGS.
20
+ For example, the installation command to reproduce the same build as the previous version is as follows:
21
+
22
+ ```
23
+ $ gem install annoy-rb -- --with-cxxflags=-march=native -DANNOYLIB_MULTITHREADED_BUILD
24
+ ```
25
+
26
+ ```
27
+ $ bundle config --local build.annoy-rb "--with-cxxflags=-march=native -DANNOYLIB_MULTITHREADED_BUILD"
28
+ $ bundle install
29
+ ```
30
+
31
+ ## 0.4.0
32
+ - Add dummy constructor call at memory allocation of binding class to prevent occuring segment fault on GC when initialize method is failed.
33
+
34
+ ## 0.3.0
35
+ - Add type declaration file: sig/annoy.rbs
36
+ - Fix get_distance method to return integer typed value on hamming metric index.
37
+ - Rename native extension files.
38
+
1
39
  ## 0.2.3
2
40
  - Add GC guard to index saving and loading methods.
3
41
 
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/yoshoku/annoy.rb/blob/main/LICENSE.txt)
6
6
  [![Documentation](http://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/annoy.rb/doc/)
7
7
 
8
- Annoy.rb is a Ruby binding for the [Annoy (Approximate Nearest Neighbors Oh Yeah)](https://github.com/spotify/annoy).
8
+ Annoy.rb provides Ruby bindings for the [Annoy (Approximate Nearest Neighbors Oh Yeah)](https://github.com/spotify/annoy).
9
9
 
10
10
  ## Installation
11
11
 
@@ -50,14 +50,24 @@ u.load('test.ann')
50
50
  p u.get_nns_by_item(0, 100) # will find the 100 nearest neighbors.
51
51
  ```
52
52
 
53
+ With the default argument, annoy.rb uses double precision floating point type for the data type of vector element.
54
+ On the other hand, the [Python bindings of Annoy](https://pypi.org/project/annoy/) use single precision floating point type.
55
+ If you want to load a search index created with the Python bindings, specify 'float32' to the dtype argument.
56
+
57
+ ```ruby
58
+ require 'annoy'
59
+
60
+ f = 40
61
+ t = Annoy::AnnoyIndex.new(n_features: f, metric: 'angular', dtype: 'float32')
62
+ t.load('index_with_python_bindings.ann')
63
+ ```
64
+
53
65
  ## License
54
66
 
55
67
  The gem is available as open source under the terms of the [Apache-2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
56
68
 
57
69
  ## Contributing
58
70
 
59
- Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/annoy.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yoshoku/annoy.rb/blob/main/CODE_OF_CONDUCT.md).
60
-
61
- ## Code of Conduct
62
-
63
- Everyone interacting in the Annoy.rb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/annoy.rb/blob/main/CODE_OF_CONDUCT.md).
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/annoy.rb.
72
+ This project is intended to be a safe, welcoming space for collaboration,
73
+ and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Annoy.rb is a Ruby binding for the Annoy (Approximate Nearest Neighbors Oh Yeah).
3
+ *
4
+ * Copyright (c) 2020-2022 Atsushi Tatsuma
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include "annoyext.hpp"
20
+
21
+ extern "C"
22
+ void Init_annoyext(void)
23
+ {
24
+ VALUE rb_mAnnoy = rb_define_module("Annoy");
25
+ RbAnnoyIndex<AnnoyIndexAngular<double>, double>::define_class(rb_mAnnoy, "AnnoyIndexAngular");
26
+ RbAnnoyIndex<AnnoyIndexDotProduct<double>, double>::define_class(rb_mAnnoy, "AnnoyIndexDotProduct");
27
+ RbAnnoyIndex<AnnoyIndexHamming<uint64_t>, uint64_t>::define_class(rb_mAnnoy, "AnnoyIndexHamming");
28
+ RbAnnoyIndex<AnnoyIndexEuclidean<double>, double>::define_class(rb_mAnnoy, "AnnoyIndexEuclidean");
29
+ RbAnnoyIndex<AnnoyIndexManhattan<double>, double>::define_class(rb_mAnnoy, "AnnoyIndexManhattan");
30
+
31
+ RbAnnoyIndex<AnnoyIndexAngular<float>, float>::define_class(rb_mAnnoy, "AnnoyIndexAngularFloat32");
32
+ RbAnnoyIndex<AnnoyIndexDotProduct<float>, float>::define_class(rb_mAnnoy, "AnnoyIndexDotProductFloat32");
33
+ RbAnnoyIndex<AnnoyIndexEuclidean<float>, float>::define_class(rb_mAnnoy, "AnnoyIndexEuclideanFloat32");
34
+ RbAnnoyIndex<AnnoyIndexManhattan<float>, float>::define_class(rb_mAnnoy, "AnnoyIndexManhattanFloat32");
35
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Annoy.rb is a Ruby binding for the Annoy (Approximate Nearest Neighbors Oh Yeah).
3
3
  *
4
- * Copyright (c) 2020 Atsushi Tatsuma
4
+ * Copyright (c) 2020-2022 Atsushi Tatsuma
5
5
  *
6
6
  * Licensed under the Apache License, Version 2.0 (the "License");
7
7
  * you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- #ifndef ANNOY_HPP
20
- #define ANNOY_HPP 1
19
+ #ifndef ANNOYEXT_HPP
20
+ #define ANNOYEXT_HPP 1
21
21
 
22
22
  #include <typeinfo>
23
23
 
@@ -31,17 +31,18 @@
31
31
  typedef AnnoyIndexSingleThreadedBuildPolicy AnnoyIndexThreadedBuildPolicy;
32
32
  #endif
33
33
 
34
- typedef AnnoyIndex<int, double, Angular, Kiss64Random, AnnoyIndexThreadedBuildPolicy> AnnoyIndexAngular;
35
- typedef AnnoyIndex<int, double, DotProduct, Kiss64Random, AnnoyIndexThreadedBuildPolicy> AnnoyIndexDotProduct;
36
- typedef AnnoyIndex<int, uint64_t, Hamming, Kiss64Random, AnnoyIndexThreadedBuildPolicy> AnnoyIndexHamming;
37
- typedef AnnoyIndex<int, double, Euclidean, Kiss64Random, AnnoyIndexThreadedBuildPolicy> AnnoyIndexEuclidean;
38
- typedef AnnoyIndex<int, double, Manhattan, Kiss64Random, AnnoyIndexThreadedBuildPolicy> AnnoyIndexManhattan;
34
+ template<typename F> using AnnoyIndexAngular = AnnoyIndex<int32_t, F, Angular, Kiss64Random, AnnoyIndexThreadedBuildPolicy>;
35
+ template<typename F> using AnnoyIndexDotProduct = AnnoyIndex<int32_t, F, DotProduct, Kiss64Random, AnnoyIndexThreadedBuildPolicy>;
36
+ template<typename F> using AnnoyIndexHamming = AnnoyIndex<int32_t, F, Hamming, Kiss64Random, AnnoyIndexThreadedBuildPolicy>;
37
+ template<typename F> using AnnoyIndexEuclidean = AnnoyIndex<int32_t, F, Euclidean, Kiss64Random, AnnoyIndexThreadedBuildPolicy>;
38
+ template<typename F> using AnnoyIndexManhattan = AnnoyIndex<int32_t, F, Manhattan, Kiss64Random, AnnoyIndexThreadedBuildPolicy>;
39
39
 
40
40
  template<class T, typename F> class RbAnnoyIndex
41
41
  {
42
42
  public:
43
43
  static VALUE annoy_index_alloc(VALUE self) {
44
44
  T* ptr = (T*)ruby_xmalloc(sizeof(T));
45
+ new (ptr) T();
45
46
  return TypedData_Wrap_Struct(self, &annoy_index_type, ptr);
46
47
  };
47
48
 
@@ -93,7 +94,7 @@ template<class T, typename F> class RbAnnoyIndex
93
94
  };
94
95
 
95
96
  static VALUE _annoy_index_add_item(VALUE self, VALUE _idx, VALUE arr) {
96
- const int idx = NUM2INT(_idx);
97
+ const int32_t idx = (int32_t)NUM2INT(_idx);
97
98
  const int n_dims = get_annoy_index(self)->get_f();
98
99
 
99
100
  if (!RB_TYPE_P(arr, T_ARRAY)) {
@@ -171,11 +172,11 @@ template<class T, typename F> class RbAnnoyIndex
171
172
  };
172
173
 
173
174
  static VALUE _annoy_index_get_nns_by_item(VALUE self, VALUE _idx, VALUE _n_neighbors, VALUE _search_k, VALUE _include_distances) {
174
- const int idx = NUM2INT(_idx);
175
+ const int32_t idx = (int32_t)NUM2INT(_idx);
175
176
  const int n_neighbors = NUM2INT(_n_neighbors);
176
177
  const int search_k = NUM2INT(_search_k);
177
178
  const bool include_distances = _include_distances == Qtrue ? true : false;
178
- std::vector<int> neighbors;
179
+ std::vector<int32_t> neighbors;
179
180
  std::vector<F> distances;
180
181
 
181
182
  get_annoy_index(self)->get_nns_by_item(idx, n_neighbors, search_k, &neighbors, include_distances ? &distances : NULL);
@@ -184,7 +185,7 @@ template<class T, typename F> class RbAnnoyIndex
184
185
  VALUE neighbors_arr = rb_ary_new2(sz_neighbors);
185
186
 
186
187
  for (int i = 0; i < sz_neighbors; i++) {
187
- rb_ary_store(neighbors_arr, i, INT2NUM(neighbors[i]));
188
+ rb_ary_store(neighbors_arr, i, INT2NUM((int)(neighbors[i])));
188
189
  }
189
190
 
190
191
  if (include_distances) {
@@ -223,7 +224,7 @@ template<class T, typename F> class RbAnnoyIndex
223
224
  const int n_neighbors = NUM2INT(_n_neighbors);
224
225
  const int search_k = NUM2INT(_search_k);
225
226
  const bool include_distances = _include_distances == Qtrue ? true : false;
226
- std::vector<int> neighbors;
227
+ std::vector<int32_t> neighbors;
227
228
  std::vector<F> distances;
228
229
 
229
230
  get_annoy_index(self)->get_nns_by_vector(vec, n_neighbors, search_k, &neighbors, include_distances ? &distances : NULL);
@@ -234,7 +235,7 @@ template<class T, typename F> class RbAnnoyIndex
234
235
  VALUE neighbors_arr = rb_ary_new2(sz_neighbors);
235
236
 
236
237
  for (int i = 0; i < sz_neighbors; i++) {
237
- rb_ary_store(neighbors_arr, i, INT2NUM(neighbors[i]));
238
+ rb_ary_store(neighbors_arr, i, INT2NUM((int)(neighbors[i])));
238
239
  }
239
240
 
240
241
  if (include_distances) {
@@ -253,7 +254,7 @@ template<class T, typename F> class RbAnnoyIndex
253
254
  };
254
255
 
255
256
  static VALUE _annoy_index_get_item(VALUE self, VALUE _idx) {
256
- const int idx = NUM2INT(_idx);
257
+ const int32_t idx = (int32_t)NUM2INT(_idx);
257
258
  const int n_dims = get_annoy_index(self)->get_f();
258
259
  F* vec = (F*)ruby_xmalloc(n_dims * sizeof(F));
259
260
  VALUE arr = rb_ary_new2(n_dims);
@@ -269,10 +270,10 @@ template<class T, typename F> class RbAnnoyIndex
269
270
  };
270
271
 
271
272
  static VALUE _annoy_index_get_distance(VALUE self, VALUE _i, VALUE _j) {
272
- const int i = NUM2INT(_i);
273
- const int j = NUM2INT(_j);
274
- const double dist = get_annoy_index(self)->get_distance(i, j);
275
- return DBL2NUM(dist);
273
+ const int32_t i = (int32_t)NUM2INT(_i);
274
+ const int32_t j = (int32_t)NUM2INT(_j);
275
+ const F dist = get_annoy_index(self)->get_distance(i, j);
276
+ return typeid(F) == typeid(double) ? DBL2NUM(dist) : UINT2NUM(dist);
276
277
  };
277
278
 
278
279
  static VALUE _annoy_index_get_n_items(VALUE self) {
@@ -329,4 +330,4 @@ const rb_data_type_t RbAnnoyIndex<T, F>::annoy_index_type = {
329
330
  RUBY_TYPED_FREE_IMMEDIATELY
330
331
  };
331
332
 
332
- #endif /* ANNOY_HPP */
333
+ #endif /* ANNOYEXT_HPP */
data/ext/annoy/extconf.rb CHANGED
@@ -2,8 +2,8 @@ require 'mkmf'
2
2
 
3
3
  abort 'libstdc++ is not found.' unless have_library('stdc++')
4
4
 
5
- $CXXFLAGS << " -std=c++14 -march=native -DANNOYLIB_MULTITHREADED_BUILD"
5
+ $CXXFLAGS << " -std=c++14"
6
6
  $INCFLAGS << " -I$(srcdir)/src"
7
7
  $VPATH << "$(srcdir)/src"
8
8
 
9
- create_makefile('annoy/annoy')
9
+ create_makefile('annoy/annoyext')
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -868,6 +868,8 @@ protected:
868
868
  bool _built;
869
869
  public:
870
870
 
871
+ AnnoyIndex() : _f(0), _fd(0), _nodes(NULL), _n_items(0), _n_nodes(0), _nodes_size(0),
872
+ _is_seeded(false), _loaded(false), _verbose(false), _on_disk(false), _built(false) { }
871
873
  AnnoyIndex(int f) : _f(f) {
872
874
  _s = offsetof(Node, v) + _f * sizeof(T); // Size of each node
873
875
  _verbose = false;
data/lib/annoy/version.rb CHANGED
@@ -3,5 +3,8 @@
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.3'.freeze
6
+ VERSION = '0.6.0'
7
+
8
+ # The version of Annoy included with gem.
9
+ ANNOY_VERSION = '1.17.0'
7
10
  end
data/lib/annoy.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'annoy/version'
4
- require 'annoy/annoy'
4
+ require 'annoy/annoyext'
5
5
 
6
6
  module Annoy
7
7
  # AnnoyIndex is a class that provides functions for k-nearest neighbors search.
@@ -30,27 +30,35 @@ module Annoy
30
30
  # @return [String]
31
31
  attr_reader :metric
32
32
 
33
+ # Returns the data type of feature.
34
+ # @return [String]
35
+ attr_reader :dtype
36
+
33
37
  # Create a new search index.
34
38
  #
35
39
  # @param n_features [Integer] The number of features (dimensions) of stored vector.
36
40
  # @param metric [String] The distance metric between vectors ('angular', 'dot', 'hamming', 'euclidean', or 'manhattan').
37
- def initialize(n_features:, metric: 'angular')
41
+ # @param dtype [String] The data type of features ('float64' and 'float32').
42
+ # If metric is given 'hamming', 'uint64' is automatically assigned to this argument.
43
+ def initialize(n_features:, metric: 'angular', dtype: 'float64')
38
44
  raise ArgumentError, 'Expect n_features to be Integer.' unless n_features.is_a?(Numeric)
39
45
 
40
46
  @n_features = n_features.to_i
41
47
  @metric = metric
48
+ @dtype = dtype
42
49
 
43
50
  @index = case @metric
44
51
  when 'angular'
45
- AnnoyIndexAngular.new(@n_features)
52
+ @dtype == 'float64' ? AnnoyIndexAngular.new(@n_features) : AnnoyIndexAngularFloat32.new(@n_features)
46
53
  when 'dot'
47
- AnnoyIndexDotProduct.new(@n_features)
54
+ @dtype == 'float64' ? AnnoyIndexDotProduct.new(@n_features) : AnnoyIndexDotProductFloat32.new(@n_features)
48
55
  when 'hamming'
56
+ @dtype = 'uint64'
49
57
  AnnoyIndexHamming.new(@n_features)
50
58
  when 'euclidean'
51
- AnnoyIndexEuclidean.new(@n_features)
59
+ @dtype == 'float64' ? AnnoyIndexEuclidean.new(@n_features) : AnnoyIndexEuclideanFloat32.new(@n_features)
52
60
  when 'manhattan'
53
- AnnoyIndexManhattan.new(@n_features)
61
+ @dtype == 'float64' ? AnnoyIndexManhattan.new(@n_features) : AnnoyIndexManhattanFloat32.new(@n_features)
54
62
  else
55
63
  raise ArgumentError, "No such metric: #{@metric}."
56
64
  end
@@ -69,6 +77,7 @@ module Annoy
69
77
  #
70
78
  # @param n_trees [Integer] The number of trees. More trees gives higher search precision.
71
79
  # @param n_jobs [Integer] The number of threads used to build the trees. If -1 is given, uses all available CPU cores.
80
+ # This parameter is enabled only if "-DANNOYLIB_MULTITHREADED_BUILD" is specified on gem installation.
72
81
  # @return [Boolean]
73
82
  def build(n_trees, n_jobs: -1)
74
83
  @index.build(n_trees, n_jobs)
data/sig/annoy.rbs ADDED
@@ -0,0 +1,188 @@
1
+ module Annoy
2
+ VERSION: String
3
+ ANNOY_VERSION: String
4
+
5
+ class AnnoyIndex
6
+ attr_reader n_features: Integer
7
+ attr_reader metric: String
8
+ attr_reader dtype: String
9
+
10
+ def initialize: (n_features: Integer n_features, ?metric: String metric, ?dtype: String dtype) -> void
11
+ def add_item: (Integer i, Array[Float | Integer] v) -> bool
12
+ def build: (Integer n_trees, ?n_jobs: Integer n_jobs) -> bool
13
+ def save: (String filename, ?prefault: bool prefault) -> bool
14
+ def load: (String filename, ?prefault: bool prefault) -> bool
15
+ def unload: () -> bool
16
+ def get_nns_by_item: (Integer i, Integer n, ?search_k: Integer search_k, ?include_distances: (true | false) include_distances) -> ([Array[Integer], Array[Float | Integer]] | Array[Integer])
17
+ def get_nns_by_vector: (Array[Float | Integer] v, Integer n, ?search_k: Integer search_k, ?include_distances: (true | false) include_distances) -> ([Array[Integer], Array[Float | Integer]] | Array[Integer])
18
+ def get_item: (Integer i) -> Array[Float | Integer]
19
+ def get_distance: (Integer i, Integer j) -> (Float | Integer)
20
+ def n_items: () -> Integer
21
+ def n_trees: () -> Integer
22
+ def on_disk_build: (String filename) -> bool
23
+ def verbose: (bool flag) -> nil
24
+ def seed: (Integer s) -> nil
25
+ end
26
+
27
+ class AnnoyIndexAngular
28
+ def initialize: (Integer n_features) -> void
29
+ def add_item: (Integer i, Array[Float] v) -> bool
30
+ def build: (Integer n_trees, Integer n_jobs) -> bool
31
+ def save: (String filename, bool prefault) -> bool
32
+ def load: (String filename, bool prefault) -> bool
33
+ def unload: () -> bool
34
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
35
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
36
+ def get_item: (Integer i) -> Array[Float]
37
+ def get_distance: (Integer i, Integer j) -> Float
38
+ def n_items: () -> Integer
39
+ def n_trees: () -> Integer
40
+ def on_disk_build: (String filename) -> bool
41
+ def verbose: (bool flag) -> nil
42
+ def seed: (Integer s) -> nil
43
+ end
44
+
45
+ class AnnoyIndexAngularFloat32
46
+ def initialize: (Integer n_features) -> void
47
+ def add_item: (Integer i, Array[Float] v) -> bool
48
+ def build: (Integer n_trees, Integer n_jobs) -> bool
49
+ def save: (String filename, bool prefault) -> bool
50
+ def load: (String filename, bool prefault) -> bool
51
+ def unload: () -> bool
52
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
53
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
54
+ def get_item: (Integer i) -> Array[Float]
55
+ def get_distance: (Integer i, Integer j) -> Float
56
+ def n_items: () -> Integer
57
+ def n_trees: () -> Integer
58
+ def on_disk_build: (String filename) -> bool
59
+ def verbose: (bool flag) -> nil
60
+ def seed: (Integer s) -> nil
61
+ end
62
+
63
+ class AnnoyIndexDotProduct
64
+ def initialize: (Integer n_features) -> void
65
+ def add_item: (Integer i, Array[Float] v) -> bool
66
+ def build: (Integer n_trees, Integer n_jobs) -> bool
67
+ def save: (String filename, bool prefault) -> bool
68
+ def load: (String filename, bool prefault) -> bool
69
+ def unload: () -> bool
70
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
71
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
72
+ def get_item: (Integer i) -> Array[Float]
73
+ def get_distance: (Integer i, Integer j) -> Float
74
+ def n_items: () -> Integer
75
+ def n_trees: () -> Integer
76
+ def on_disk_build: (String filename) -> bool
77
+ def verbose: (bool flag) -> nil
78
+ def seed: (Integer s) -> nil
79
+ end
80
+
81
+ class AnnoyIndexDotProductFloat32
82
+ def initialize: (Integer n_features) -> void
83
+ def add_item: (Integer i, Array[Float] v) -> bool
84
+ def build: (Integer n_trees, Integer n_jobs) -> bool
85
+ def save: (String filename, bool prefault) -> bool
86
+ def load: (String filename, bool prefault) -> bool
87
+ def unload: () -> bool
88
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
89
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
90
+ def get_item: (Integer i) -> Array[Float]
91
+ def get_distance: (Integer i, Integer j) -> Float
92
+ def n_items: () -> Integer
93
+ def n_trees: () -> Integer
94
+ def on_disk_build: (String filename) -> bool
95
+ def verbose: (bool flag) -> nil
96
+ def seed: (Integer s) -> nil
97
+ end
98
+
99
+ class AnnoyIndexHamming
100
+ def initialize: (Integer n_features) -> void
101
+ def add_item: (Integer i, Array[Integer] v) -> bool
102
+ def build: (Integer n_trees, Integer n_jobs) -> bool
103
+ def save: (String filename, bool prefault) -> bool
104
+ def load: (String filename, bool prefault) -> bool
105
+ def unload: () -> bool
106
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Integer]] | Array[Integer])
107
+ def get_nns_by_vector: (Array[Integer] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Integer]] | Array[Integer])
108
+ def get_item: (Integer i) -> Array[Integer]
109
+ def get_distance: (Integer i, Integer j) -> Integer
110
+ def n_items: () -> Integer
111
+ def n_trees: () -> Integer
112
+ def on_disk_build: (String filename) -> bool
113
+ def verbose: (bool flag) -> nil
114
+ def seed: (Integer s) -> nil
115
+ end
116
+
117
+ class AnnoyIndexEuclidean
118
+ def initialize: (Integer n_features) -> void
119
+ def add_item: (Integer i, Array[Float] v) -> bool
120
+ def build: (Integer n_trees, Integer n_jobs) -> bool
121
+ def save: (String filename, bool prefault) -> bool
122
+ def load: (String filename, bool prefault) -> bool
123
+ def unload: () -> bool
124
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
125
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
126
+ def get_item: (Integer i) -> Array[Float]
127
+ def get_distance: (Integer i, Integer j) -> Float
128
+ def n_items: () -> Integer
129
+ def n_trees: () -> Integer
130
+ def on_disk_build: (String filename) -> bool
131
+ def verbose: (bool flag) -> nil
132
+ def seed: (Integer s) -> nil
133
+ end
134
+
135
+ class AnnoyIndexEuclideanFloat32
136
+ def initialize: (Integer n_features) -> void
137
+ def add_item: (Integer i, Array[Float] v) -> bool
138
+ def build: (Integer n_trees, Integer n_jobs) -> bool
139
+ def save: (String filename, bool prefault) -> bool
140
+ def load: (String filename, bool prefault) -> bool
141
+ def unload: () -> bool
142
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
143
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
144
+ def get_item: (Integer i) -> Array[Float]
145
+ def get_distance: (Integer i, Integer j) -> Float
146
+ def n_items: () -> Integer
147
+ def n_trees: () -> Integer
148
+ def on_disk_build: (String filename) -> bool
149
+ def verbose: (bool flag) -> nil
150
+ def seed: (Integer s) -> nil
151
+ end
152
+
153
+ class AnnoyIndexManhattan
154
+ def initialize: (Integer n_features) -> void
155
+ def add_item: (Integer i, Array[Float] v) -> bool
156
+ def build: (Integer n_trees, Integer n_jobs) -> bool
157
+ def save: (String filename, bool prefault) -> bool
158
+ def load: (String filename, bool prefault) -> bool
159
+ def unload: () -> bool
160
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
161
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
162
+ def get_item: (Integer i) -> Array[Float]
163
+ def get_distance: (Integer i, Integer j) -> Float
164
+ def n_items: () -> Integer
165
+ def n_trees: () -> Integer
166
+ def on_disk_build: (String filename) -> bool
167
+ def verbose: (bool flag) -> nil
168
+ def seed: (Integer s) -> nil
169
+ end
170
+
171
+ class AnnoyIndexManhattanFloat32
172
+ def initialize: (Integer n_features) -> void
173
+ def add_item: (Integer i, Array[Float] v) -> bool
174
+ def build: (Integer n_trees, Integer n_jobs) -> bool
175
+ def save: (String filename, bool prefault) -> bool
176
+ def load: (String filename, bool prefault) -> bool
177
+ def unload: () -> bool
178
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
179
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
180
+ def get_item: (Integer i) -> Array[Float]
181
+ def get_distance: (Integer i, Integer j) -> Float
182
+ def n_items: () -> Integer
183
+ def n_trees: () -> Integer
184
+ def on_disk_build: (String filename) -> bool
185
+ def verbose: (bool flag) -> nil
186
+ def seed: (Integer s) -> nil
187
+ end
188
+ end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annoy-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-19 00:00:00.000000000 Z
11
+ date: 2022-01-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Annoy.rb is a Ruby binding for the Annoy (Approximate Nearest Neighbors
13
+ description: Annoy.rb provides Ruby bindings for the Annoy (Approximate Nearest Neighbors
14
14
  Oh Yeah).
15
15
  email:
16
16
  - yoshoku@outlook.com
@@ -19,24 +19,19 @@ extensions:
19
19
  - ext/annoy/extconf.rb
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - ".github/workflows/build.yml"
23
- - ".gitignore"
24
- - ".rspec"
25
22
  - CHANGELOG.md
26
- - CODE_OF_CONDUCT.md
27
- - Gemfile
28
23
  - LICENSE.txt
29
24
  - README.md
30
- - Rakefile
31
- - annoy-rb.gemspec
32
- - ext/annoy/annoy.cpp
33
- - ext/annoy/annoy.hpp
25
+ - ext/annoy/annoyext.cpp
26
+ - ext/annoy/annoyext.hpp
34
27
  - ext/annoy/extconf.rb
28
+ - ext/annoy/src/LICENSE
35
29
  - ext/annoy/src/annoylib.h
36
30
  - ext/annoy/src/kissrandom.h
37
31
  - ext/annoy/src/mman.h
38
32
  - lib/annoy.rb
39
33
  - lib/annoy/version.rb
34
+ - sig/annoy.rbs
40
35
  homepage: https://github.com/yoshoku/annoy.rb
41
36
  licenses:
42
37
  - Apache-2.0
@@ -60,8 +55,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
55
  - !ruby/object:Gem::Version
61
56
  version: '0'
62
57
  requirements: []
63
- rubygems_version: 3.1.4
58
+ rubygems_version: 3.3.3
64
59
  signing_key:
65
60
  specification_version: 4
66
- summary: Ruby binding for the Annoy (Approximate Nearest Neighbors Oh Yeah).
61
+ summary: Ruby bindings for the Annoy (Approximate Nearest Neighbors Oh Yeah).
67
62
  test_files: []
@@ -1,21 +0,0 @@
1
- name: build
2
-
3
- on: [push, pull_request]
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/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- *.bundle
10
- *.so
11
- *.o
12
- *.a
13
- mkmf.log
14
-
15
- # rspec failure tracking
16
- .rspec_status
17
-
18
- *.swp
19
- *.dat
20
- tags
21
- .DS_Store
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at yoshoku@outlook.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [https://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: https://contributor-covenant.org
74
- [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in annoy.gemspec
4
- gemspec
5
-
6
- gem "rake", "~> 12.0"
7
- gem "rake-compiler"
8
- gem "rspec", "~> 3.0"
data/Rakefile DELETED
@@ -1,14 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- require 'rake/extensiontask'
7
-
8
- task :build => :compile
9
-
10
- Rake::ExtensionTask.new('annoy') do |ext|
11
- ext.lib_dir = 'lib/annoy'
12
- end
13
-
14
- task :default => [:clobber, :compile, :spec]
data/annoy-rb.gemspec DELETED
@@ -1,28 +0,0 @@
1
- require_relative 'lib/annoy/version'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = 'annoy-rb'
5
- spec.version = Annoy::VERSION
6
- spec.authors = ['yoshoku']
7
- spec.email = ['yoshoku@outlook.com']
8
-
9
- spec.summary = 'Ruby binding for the Annoy (Approximate Nearest Neighbors Oh Yeah).'
10
- spec.description = 'Annoy.rb is a Ruby binding for the Annoy (Approximate Nearest Neighbors Oh Yeah).'
11
- spec.homepage = 'https://github.com/yoshoku/annoy.rb'
12
- spec.license = 'Apache-2.0'
13
-
14
- spec.metadata['homepage_uri'] = spec.homepage
15
- spec.metadata['source_code_uri'] = spec.homepage
16
- spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/annoy.rb/blob/main/CHANGELOG.md'
17
- spec.metadata['documentation_uri'] = 'https://yoshoku.github.io/annoy.rb/doc/'
18
-
19
- # Specify which files should be added to the gem when it is released.
20
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
- end
24
- spec.bindir = 'exe'
25
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
- spec.require_paths = ['lib']
27
- spec.extensions = ['ext/annoy/extconf.rb']
28
- end
data/ext/annoy/annoy.cpp DELETED
@@ -1,30 +0,0 @@
1
- /**
2
- * Annoy.rb is a Ruby binding for the Annoy (Approximate Nearest Neighbors Oh Yeah).
3
- *
4
- * Copyright (c) 2020 Atsushi Tatsuma
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- #include "annoy.hpp"
20
-
21
- extern "C"
22
- void Init_annoy(void)
23
- {
24
- VALUE rb_mAnnoy = rb_define_module("Annoy");
25
- RbAnnoyIndex<AnnoyIndexAngular, double>::define_class(rb_mAnnoy, "AnnoyIndexAngular");
26
- RbAnnoyIndex<AnnoyIndexDotProduct, double>::define_class(rb_mAnnoy, "AnnoyIndexDotProduct");
27
- RbAnnoyIndex<AnnoyIndexHamming, uint64_t>::define_class(rb_mAnnoy, "AnnoyIndexHamming");
28
- RbAnnoyIndex<AnnoyIndexEuclidean, double>::define_class(rb_mAnnoy, "AnnoyIndexEuclidean");
29
- RbAnnoyIndex<AnnoyIndexManhattan, double>::define_class(rb_mAnnoy, "AnnoyIndexManhattan");
30
- }