annoy-rb 0.2.3 → 0.3.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: 9a7ab55f832f0ce57d4e8c010e69fdcee979764cea2579d5833ae1d3b0c24af9
4
- data.tar.gz: 245451b8edd07984b8bcfd515bb1caa75a4164309954d9278aabce76ad9646c2
3
+ metadata.gz: a8884d4c472560181032959b32eb3396b698dedc7dac7211af67bdb03aaa90f6
4
+ data.tar.gz: 1eb4acf66b0685e06aed6455c4efd0ffcb17f8805e9b619f003fb62046db41db
5
5
  SHA512:
6
- metadata.gz: b4c357d55bba00461433a2d63350216eaecb45ab421b2acc5a51a7276eb6922ef58ae1ad6775bd847d56805207e24e23c93944b3e434acdd059bc67d2177e2db
7
- data.tar.gz: 4619de7cbde449ba58495ac1a98090cc0c8a6737d31769cb37134f1e351ddc1ad0ade9b4806a9e8d965a1e9272e9df11962f77d5380d6ad0f1819a6ef0dd2164
6
+ metadata.gz: 0103da7a9f443c4fed168ac61004aa135bbd534edaff6f20d641ef818348288a851370693d75657794c8ebfe9dd45dd54177315c7ac68a3400e43c87dfb1c4bb
7
+ data.tar.gz: 8e7314fbee4ed318c47848941aba40f6363f350181c616045354af696dc99cbd678c7b999b5bfa35339ad82e6cb3f6782510354d44db5d4d1fb81591128f4822
@@ -6,8 +6,9 @@ jobs:
6
6
  build:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
+ fail-fast: false
9
10
  matrix:
10
- ruby: [ '2.5', '2.6', '2.7' ]
11
+ ruby: [ '2.6', '2.7', '3.0' ]
11
12
  steps:
12
13
  - uses: actions/checkout@v2
13
14
  - name: Set upt Ruby ${{ matrix.ruby }}
@@ -16,6 +17,6 @@ jobs:
16
17
  ruby-version: ${{ matrix.ruby }}
17
18
  - name: Build and test with Rake
18
19
  run: |
19
- gem install bundler
20
+ gem install --no-document bundler
20
21
  bundle install --jobs 4 --retry 3
21
22
  bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.3.0
2
+ - Add type declaration file: sig/annoy.rbs
3
+ - Fix get_distance method to return integer typed value on hamming metric index.
4
+ - Rename native extension files.
5
+
1
6
  ## 0.2.3
2
7
  - Add GC guard to index saving and loading methods.
3
8
 
data/Gemfile CHANGED
@@ -1,8 +1,10 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in annoy.gemspec
4
4
  gemspec
5
5
 
6
- gem "rake", "~> 12.0"
7
- gem "rake-compiler"
8
- gem "rspec", "~> 3.0"
6
+ gem 'rake', '~> 13.0'
7
+ gem 'rake-compiler', '~> 1.1'
8
+ gem 'rspec', '~> 3.0'
9
+ gem 'rbs', '~> 1.2'
10
+ gem 'steep', '~> 0.44'
data/Rakefile CHANGED
@@ -7,7 +7,8 @@ require 'rake/extensiontask'
7
7
 
8
8
  task :build => :compile
9
9
 
10
- Rake::ExtensionTask.new('annoy') do |ext|
10
+ Rake::ExtensionTask.new('annoyext') do |ext|
11
+ ext.ext_dir = 'ext/annoy'
11
12
  ext.lib_dir = 'lib/annoy'
12
13
  end
13
14
 
data/Steepfile ADDED
@@ -0,0 +1,20 @@
1
+ target :lib do
2
+ signature "sig"
3
+
4
+ check "lib" # Directory name
5
+ # check "Gemfile" # File name
6
+ # check "app/models/**/*.rb" # Glob
7
+ # # ignore "lib/templates/*.rb"
8
+ #
9
+ # # library "pathname", "set" # Standard libraries
10
+ # # library "strong_json" # Gems
11
+ end
12
+
13
+ # target :spec do
14
+ # signature "sig", "sig-private"
15
+ #
16
+ # check "spec"
17
+ #
18
+ # # library "pathname", "set" # Standard libraries
19
+ # # library "rspec"
20
+ # end
@@ -16,10 +16,10 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- #include "annoy.hpp"
19
+ #include "annoyext.hpp"
20
20
 
21
21
  extern "C"
22
- void Init_annoy(void)
22
+ void Init_annoyext(void)
23
23
  {
24
24
  VALUE rb_mAnnoy = rb_define_module("Annoy");
25
25
  RbAnnoyIndex<AnnoyIndexAngular, double>::define_class(rb_mAnnoy, "AnnoyIndexAngular");
@@ -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
 
@@ -271,8 +271,8 @@ template<class T, typename F> class RbAnnoyIndex
271
271
  static VALUE _annoy_index_get_distance(VALUE self, VALUE _i, VALUE _j) {
272
272
  const int i = NUM2INT(_i);
273
273
  const int j = NUM2INT(_j);
274
- const double dist = get_annoy_index(self)->get_distance(i, j);
275
- return DBL2NUM(dist);
274
+ const F dist = get_annoy_index(self)->get_distance(i, j);
275
+ return typeid(F) == typeid(double) ? DBL2NUM(dist) : UINT2NUM(dist);
276
276
  };
277
277
 
278
278
  static VALUE _annoy_index_get_n_items(VALUE self) {
@@ -329,4 +329,4 @@ const rb_data_type_t RbAnnoyIndex<T, F>::annoy_index_type = {
329
329
  RUBY_TYPED_FREE_IMMEDIATELY
330
330
  };
331
331
 
332
- #endif /* ANNOY_HPP */
332
+ #endif /* ANNOYEXT_HPP */
data/ext/annoy/extconf.rb CHANGED
@@ -6,4 +6,4 @@ $CXXFLAGS << " -std=c++14 -march=native -DANNOYLIB_MULTITHREADED_BUILD"
6
6
  $INCFLAGS << " -I$(srcdir)/src"
7
7
  $VPATH << "$(srcdir)/src"
8
8
 
9
- create_makefile('annoy/annoy')
9
+ create_makefile('annoy/annoyext')
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.
data/lib/annoy/version.rb CHANGED
@@ -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.3'.freeze
6
+ VERSION = '0.3.0'.freeze
7
7
  end
data/sig/annoy.rbs ADDED
@@ -0,0 +1,114 @@
1
+ module Annoy
2
+ VERSION: String
3
+
4
+ class AnnoyIndex
5
+ attr_reader n_features: Integer
6
+ attr_reader metric: String
7
+
8
+ def initialize: (n_features: Integer n_features, ?metric: String metric) -> void
9
+ def add_item: (Integer i, Array[Float | Integer] v) -> bool
10
+ def build: (Integer n_trees, ?n_jobs: Integer n_jobs) -> bool
11
+ def save: (String filename, ?prefault: bool prefault) -> bool
12
+ def load: (String filename, ?prefault: bool prefault) -> bool
13
+ def unload: () -> bool
14
+ 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])
15
+ 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])
16
+ def get_item: (Integer i) -> Array[Float | Integer]
17
+ def get_distance: (Integer i, Integer j) -> (Float | Integer)
18
+ def n_items: () -> Integer
19
+ def n_trees: () -> Integer
20
+ def on_disk_build: (String filename) -> bool
21
+ def verbose: (bool flag) -> nil
22
+ def seed: (Integer s) -> nil
23
+ end
24
+
25
+ class AnnoyIndexAngular
26
+ def initialize: (Integer n_features) -> void
27
+ def add_item: (Integer i, Array[Float] v) -> bool
28
+ def build: (Integer n_trees, Integer n_jobs) -> bool
29
+ def save: (String filename, bool prefault) -> bool
30
+ def load: (String filename, bool prefault) -> bool
31
+ def unload: () -> bool
32
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
33
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
34
+ def get_item: (Integer i) -> Array[Float]
35
+ def get_distance: (Integer i, Integer j) -> Float
36
+ def n_items: () -> Integer
37
+ def n_trees: () -> Integer
38
+ def on_disk_build: (String filename) -> bool
39
+ def verbose: (bool flag) -> nil
40
+ def seed: (Integer s) -> nil
41
+ end
42
+
43
+ class AnnoyIndexDotProduct
44
+ def initialize: (Integer n_features) -> void
45
+ def add_item: (Integer i, Array[Float] v) -> bool
46
+ def build: (Integer n_trees, Integer n_jobs) -> bool
47
+ def save: (String filename, bool prefault) -> bool
48
+ def load: (String filename, bool prefault) -> bool
49
+ def unload: () -> bool
50
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
51
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
52
+ def get_item: (Integer i) -> Array[Float]
53
+ def get_distance: (Integer i, Integer j) -> Float
54
+ def n_items: () -> Integer
55
+ def n_trees: () -> Integer
56
+ def on_disk_build: (String filename) -> bool
57
+ def verbose: (bool flag) -> nil
58
+ def seed: (Integer s) -> nil
59
+ end
60
+
61
+ class AnnoyIndexHamming
62
+ def initialize: (Integer n_features) -> void
63
+ def add_item: (Integer i, Array[Integer] v) -> bool
64
+ def build: (Integer n_trees, Integer n_jobs) -> bool
65
+ def save: (String filename, bool prefault) -> bool
66
+ def load: (String filename, bool prefault) -> bool
67
+ def unload: () -> bool
68
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Integer]] | Array[Integer])
69
+ def get_nns_by_vector: (Array[Integer] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Integer]] | Array[Integer])
70
+ def get_item: (Integer i) -> Array[Integer]
71
+ def get_distance: (Integer i, Integer j) -> Integer
72
+ def n_items: () -> Integer
73
+ def n_trees: () -> Integer
74
+ def on_disk_build: (String filename) -> bool
75
+ def verbose: (bool flag) -> nil
76
+ def seed: (Integer s) -> nil
77
+ end
78
+
79
+ class AnnoyIndexEuclidean
80
+ def initialize: (Integer n_features) -> void
81
+ def add_item: (Integer i, Array[Float] v) -> bool
82
+ def build: (Integer n_trees, Integer n_jobs) -> bool
83
+ def save: (String filename, bool prefault) -> bool
84
+ def load: (String filename, bool prefault) -> bool
85
+ def unload: () -> bool
86
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
87
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
88
+ def get_item: (Integer i) -> Array[Float]
89
+ def get_distance: (Integer i, Integer j) -> Float
90
+ def n_items: () -> Integer
91
+ def n_trees: () -> Integer
92
+ def on_disk_build: (String filename) -> bool
93
+ def verbose: (bool flag) -> nil
94
+ def seed: (Integer s) -> nil
95
+ end
96
+
97
+ class AnnoyIndexManhattan
98
+ def initialize: (Integer n_features) -> void
99
+ def add_item: (Integer i, Array[Float] v) -> bool
100
+ def build: (Integer n_trees, Integer n_jobs) -> bool
101
+ def save: (String filename, bool prefault) -> bool
102
+ def load: (String filename, bool prefault) -> bool
103
+ def unload: () -> bool
104
+ def get_nns_by_item: (Integer i, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
105
+ def get_nns_by_vector: (Array[Float] v, Integer n, Integer search_k, (true | false) include_distances) -> ([Array[Integer], Array[Float]] | Array[Integer])
106
+ def get_item: (Integer i) -> Array[Float]
107
+ def get_distance: (Integer i, Integer j) -> Float
108
+ def n_items: () -> Integer
109
+ def n_trees: () -> Integer
110
+ def on_disk_build: (String filename) -> bool
111
+ def verbose: (bool flag) -> nil
112
+ def seed: (Integer s) -> nil
113
+ end
114
+ 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.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-19 00:00:00.000000000 Z
11
+ date: 2021-05-23 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).
@@ -28,15 +28,17 @@ files:
28
28
  - LICENSE.txt
29
29
  - README.md
30
30
  - Rakefile
31
+ - Steepfile
31
32
  - annoy-rb.gemspec
32
- - ext/annoy/annoy.cpp
33
- - ext/annoy/annoy.hpp
33
+ - ext/annoy/annoyext.cpp
34
+ - ext/annoy/annoyext.hpp
34
35
  - ext/annoy/extconf.rb
35
36
  - ext/annoy/src/annoylib.h
36
37
  - ext/annoy/src/kissrandom.h
37
38
  - ext/annoy/src/mman.h
38
39
  - lib/annoy.rb
39
40
  - lib/annoy/version.rb
41
+ - sig/annoy.rbs
40
42
  homepage: https://github.com/yoshoku/annoy.rb
41
43
  licenses:
42
44
  - Apache-2.0
@@ -45,7 +47,7 @@ metadata:
45
47
  source_code_uri: https://github.com/yoshoku/annoy.rb
46
48
  changelog_uri: https://github.com/yoshoku/annoy.rb/blob/main/CHANGELOG.md
47
49
  documentation_uri: https://yoshoku.github.io/annoy.rb/doc/
48
- post_install_message:
50
+ post_install_message:
49
51
  rdoc_options: []
50
52
  require_paths:
51
53
  - lib
@@ -60,8 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
62
  - !ruby/object:Gem::Version
61
63
  version: '0'
62
64
  requirements: []
63
- rubygems_version: 3.1.4
64
- signing_key:
65
+ rubygems_version: 3.1.6
66
+ signing_key:
65
67
  specification_version: 4
66
68
  summary: Ruby binding for the Annoy (Approximate Nearest Neighbors Oh Yeah).
67
69
  test_files: []