cmfrec 0.3.4 → 0.4.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: 47db0dbacef97527ad7947e2c9a38daa21700f9159d55fa19bc9efb404fb7b7b
4
- data.tar.gz: 16f3a1a20149a3182d681d0b1c8727eb95c841e7bc459b9fe7abf319df98cb83
3
+ metadata.gz: 69ad906f81dd246a338be341b9e80ed3737fcda945be654128116e16bef07626
4
+ data.tar.gz: 8430bd95b51e2f00dd57976d963fa60bb0d82e334951349be32f0a54f3a0aa1c
5
5
  SHA512:
6
- metadata.gz: 06eced36e5c9d529da867507586c607f3020f0145d473feaae24eaecaebbfe07c2fab82160823aee36ade1f49d5b555dff7e479e16f239d833df09641f04e122
7
- data.tar.gz: b432da1dec1af34c4beaa67413eeb6d58de68df5566b72bb9cab053335300a92f6ec633e14bdb4d824097b03e83aa1970d8d74d983be0b6a2ad270fc03db08b0
6
+ metadata.gz: 59212029fa16618b83b11a9f3e9a5d32feac79c6aa9d017333c6b652d39edb72080efdab2020d5b0ce5b969ca0ca23ca2dfeb846d83f91883bd7d4c024004ac5
7
+ data.tar.gz: d0a3d418eac306dba55a2aa4d5ef605e31f1ac4fa5d2a87adcc0d2c298b374b90b724df88e61910b18aa965e9b76105113164aedf1943200d5b77e0c576d8d26
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.4.0 (2026-04-14)
2
+
3
+ - Dropped support for Ruby < 3.3
4
+
1
5
  ## 0.3.4 (2025-11-22)
2
6
 
3
7
  - Added ARM shared library for Linux
data/LICENSE.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  MIT License
2
2
 
3
3
  Copyright (c) 2020 David Cortes
4
- Copyright (c) 2020-2025 Andrew Kane
4
+ Copyright (c) 2020-2026 Andrew Kane
5
5
 
6
6
  All rights reserved.
7
7
 
data/lib/cmfrec/data.rb CHANGED
@@ -54,9 +54,7 @@ module Cmfrec
54
54
 
55
55
  def download_file(fname, origin, file_hash:)
56
56
  require "digest"
57
- require "fileutils"
58
- require "net/http"
59
- require "tmpdir"
57
+ require "open-uri"
60
58
 
61
59
  cache_home = ENV["XDG_CACHE_HOME"] || "#{ENV.fetch("HOME")}/.cache"
62
60
  dest = "#{cache_home}/cmfrec/#{fname}"
@@ -64,38 +62,24 @@ module Cmfrec
64
62
 
65
63
  return dest if File.exist?(dest)
66
64
 
67
- temp_path = "#{Dir.tmpdir}/cmfrec-#{Time.now.to_f}" # TODO better name
68
-
69
- digest = Digest::SHA2.new
70
-
71
- uri = URI(origin)
72
-
73
- # Net::HTTP automatically adds Accept-Encoding for compression
74
- # of response bodies and automatically decompresses gzip
75
- # and deflateresponses unless a Range header was sent.
76
- # https://ruby-doc.org/stdlib-2.6.4/libdoc/net/http/rdoc/Net/HTTP.html
77
- Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
78
- request = Net::HTTP::Get.new(uri)
79
-
80
- puts "Downloading data from #{origin}"
81
- File.open(temp_path, "wb") do |f|
82
- http.request(request) do |response|
83
- response.read_body do |chunk|
84
- f.write(chunk)
85
- digest.update(chunk)
86
- end
65
+ puts "Downloading data from #{origin}"
66
+ URI.parse(origin).open(redirect: false) do |download|
67
+ digest =
68
+ if download.respond_to?(:path)
69
+ download.flush
70
+ Digest::SHA256.file(download.path).hexdigest
71
+ else
72
+ Digest::SHA256.hexdigest(download.string)
87
73
  end
74
+
75
+ if digest != file_hash
76
+ raise Error, "Bad hash: #{digest}"
88
77
  end
89
- end
78
+ puts "Hash verified: #{file_hash}"
90
79
 
91
- if digest.hexdigest != file_hash
92
- raise Error, "Bad hash: #{digest.hexdigest}"
80
+ IO.copy_stream(download, dest)
93
81
  end
94
82
 
95
- puts "Hash verified: #{file_hash}"
96
-
97
- FileUtils.mv(temp_path, dest)
98
-
99
83
  dest
100
84
  end
101
85
  end
@@ -158,10 +158,10 @@ module Cmfrec
158
158
  @lambda_, @l1_lambda, @alpha, @w_main, @w_user,
159
159
  @w_main_multiplier,
160
160
  @apply_log_transf,
161
- nil, #BeTBe,
162
- nil, #BtB,
163
- nil, #BeTBeChol,
164
- nil, #CtUbias,
161
+ nil, # BeTBe
162
+ nil, # BtB
163
+ nil, # BeTBeChol
164
+ nil, # CtUbias
165
165
  include_ix, n_include,
166
166
  exclude_ix, n_exclude,
167
167
  outp_ix, outp_score,
@@ -194,15 +194,15 @@ module Cmfrec
194
194
  @scale_bias_const, scaling_bias_a,
195
195
  @w_main, @w_user, @w_implicit,
196
196
  n_max, @include_all_x,
197
- nil, #BtB,
198
- nil, #TransBtBinvBt,
199
- nil, #BtXbias,
200
- nil, #BeTBeChol,
201
- nil, #BiTBi,
202
- nil, #CtCw,
203
- nil, #TransCtCinvCt,
204
- nil, #CtUbias,
205
- nil, #B_plus_bias,
197
+ nil, # BtB
198
+ nil, # TransBtBinvBt
199
+ nil, # BtXbias
200
+ nil, # BeTBeChol
201
+ nil, # BiTBi
202
+ nil, # CtCw
203
+ nil, # TransCtCinvCt
204
+ nil, # CtUbias
205
+ nil, # B_plus_bias
206
206
  include_ix, n_include,
207
207
  exclude_ix, n_exclude,
208
208
  outp_ix, outp_score,
@@ -275,7 +275,7 @@ module Cmfrec
275
275
  # mean
276
276
  obj[:global_mean] = @global_mean
277
277
 
278
- unless (@user_info_map.keys + @item_info_map.keys).all? { |v| v.is_a?(Symbol) }
278
+ unless (@user_info_map.keys + @item_info_map.keys).all?(Symbol)
279
279
  raise "Side info keys must be symbols to save"
280
280
  end
281
281
 
@@ -449,10 +449,10 @@ module Cmfrec
449
449
  @use_cg, @max_cg_steps, @precondition_cg, @finalize_chol,
450
450
  @nonneg, @max_cd_steps, @nonneg_c, @nonneg_d,
451
451
  @precompute_for_predictions,
452
- nil, #precomputedBtB,
453
- nil, #precomputedBeTBe,
454
- nil, #precomputedBeTBeChol
455
- nil #precomputedCtUbias
452
+ nil, # precomputedBtB
453
+ nil, # precomputedBeTBe
454
+ nil, # precomputedBeTBeChol
455
+ nil # precomputedCtUbias
456
456
  ]
457
457
  check_status FFI.fit_collective_implicit_als(*fiddle_args(args))
458
458
 
@@ -505,15 +505,15 @@ module Cmfrec
505
505
  @nonneg, @max_cd_steps, @nonneg_c, @nonneg_d,
506
506
  @precompute_for_predictions,
507
507
  @include_all_x,
508
- nil, #B_plus_bias,
509
- nil, #precomputedBtB,
510
- nil, #precomputedTransBtBinvBt,
511
- nil, #precomputedBtXbias
512
- nil, #precomputedBeTBeChol,
513
- nil, #precomputedBiTBi,
514
- nil, #precomputedTransCtCinvCt,
515
- nil, #precomputedCtCw
516
- nil #precomputedCtUbias
508
+ nil, # B_plus_bias
509
+ nil, # precomputedBtB
510
+ nil, # precomputedTransBtBinvBt
511
+ nil, # precomputedBtXbias
512
+ nil, # precomputedBeTBeChol
513
+ nil, # precomputedBiTBi
514
+ nil, # precomputedTransCtCinvCt
515
+ nil, # precomputedCtCw
516
+ nil # precomputedCtUbias
517
517
  ]
518
518
  check_status FFI.fit_collective_explicit_als(*fiddle_args(args))
519
519
 
@@ -604,7 +604,7 @@ module Cmfrec
604
604
  unless ratings.all? { |r| !r.nil? }
605
605
  raise ArgumentError, "Missing ratings"
606
606
  end
607
- unless ratings.all? { |r| r.is_a?(Numeric) }
607
+ unless ratings.all?(Numeric)
608
608
  raise ArgumentError, "Ratings must be numeric"
609
609
  end
610
610
  end
@@ -660,7 +660,7 @@ module Cmfrec
660
660
  def prepare_top_n(count: nil, rated: nil, item_ids: nil)
661
661
  if item_ids
662
662
  # remove missing ids
663
- item_ids = item_ids.map { |v| @item_map[v] }.compact
663
+ item_ids = item_ids.filter_map { |v| @item_map[v] }
664
664
  return [] if item_ids.empty?
665
665
 
666
666
  include_ix = int_ptr(item_ids)
@@ -1,3 +1,3 @@
1
1
  module Cmfrec
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmfrec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
@@ -59,14 +59,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: '3.1'
62
+ version: '3.3'
63
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubygems_version: 3.6.9
69
+ rubygems_version: 4.0.6
70
70
  specification_version: 4
71
71
  summary: Recommendations for Ruby using collective matrix factorization
72
72
  test_files: []