cmfrec 0.3.0 → 0.3.2

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: d3cc7d70530eefc7b13324753b454d03573da7d832c46cb4dee2ab9213eafcdd
4
- data.tar.gz: 662af2ec4ab1a1bd33a39c18773d0c48967422286a2fa137960772b7e67d437a
3
+ metadata.gz: 9d530b650bba045d26a7c683ca7c8b8e7321c2043a8e80556c3c7c865a441432
4
+ data.tar.gz: d49736337135bc7b956a96f631ad54b88b354d3fbbe91e925962ba15fbd3735d
5
5
  SHA512:
6
- metadata.gz: 8fd6f1f8f0bd7d7c870c28fb57a0cec89aacf2d27aed53b5d68fb6935f5071dbe73931a5ff776f4a864f0cc91a17c793eabfe2a2b21f9b368a4c36ada5cb929d
7
- data.tar.gz: 116d26ddafeeb439ef0895e30805afa0d2d2a453aeb369cf7122f13f5bf3ad457dac65c974d26debc84f353baf5f0c889c559e56620ef7458af4968ee9f5262a
6
+ metadata.gz: 36d8fcfd4cd87539f728afd2d927bc8c4ea9a75a437bc32617dabb416ba9b322dcdc135855fa7144615955b42013029ada465c6209c38f9beca2e77f2d1059e9
7
+ data.tar.gz: c21ca152c2ec3edcf134ac9c915ca8ee3bd06c7ebd2c09e95bce592e9d5d64ac1dbbb8f7791756377b7febc899113ce255b4a8054b843fc1a6042ea50b8acaa3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.3.2 (2025-05-04)
2
+
3
+ - Fixed crash with Fiddle 1.1.7+
4
+ - Fixed memory leaks
5
+
6
+ ## 0.3.1 (2024-12-29)
7
+
8
+ - Removed dependency on `base64` gem for serialization
9
+
1
10
  ## 0.3.0 (2024-10-23)
2
11
 
3
12
  - Changed dataset directory to match XDG Base Directory Specification
data/lib/cmfrec/data.rb CHANGED
@@ -30,7 +30,7 @@ module Cmfrec
30
30
  next if movie_names[row[1]]
31
31
  movie_names[row[1]] = true
32
32
 
33
- item = {item_id: row[1], year: !row[2].empty? ? Date.parse(row[2]).year : 1970}
33
+ item = {item_id: row[1], year: !row[2].empty? ? Date.strptime(row[2], "%d-%b-%Y").year : 1970}
34
34
  genres.each_with_index do |genre, i|
35
35
  item[:"genre_#{genre}"] = row[i + 5].to_i
36
36
  end
data/lib/cmfrec/ffi.rb CHANGED
@@ -12,7 +12,6 @@ module Cmfrec
12
12
 
13
13
  # https://github.com/david-cortes/cmfrec/blob/master/src/cmfrec.h
14
14
 
15
- typealias "bool", "char"
16
15
  # determined by CMakeLists.txt
17
16
  typealias "int_t", "int"
18
17
  typealias "real_t", "double"
@@ -35,7 +35,7 @@ module Cmfrec
35
35
  row = int_ptr(u)
36
36
  col = int_ptr(i)
37
37
  n_predict = data.size
38
- predicted = Fiddle::Pointer.malloc(n_predict * Fiddle::SIZEOF_DOUBLE)
38
+ predicted = Fiddle::Pointer.malloc(n_predict * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
39
39
 
40
40
  if @implicit
41
41
  check_status FFI.predict_X_old_collective_implicit(
@@ -250,7 +250,6 @@ module Cmfrec
250
250
  end
251
251
 
252
252
  def to_json
253
- require "base64"
254
253
  require "json"
255
254
 
256
255
  obj = {
@@ -415,16 +414,16 @@ module Cmfrec
415
414
  # initialize w/ normal distribution
416
415
  reset_values = !@fit
417
416
 
418
- @a = Fiddle::Pointer.malloc([@m, @m_u].max * (@k_user + @k + @k_main) * Fiddle::SIZEOF_DOUBLE)
419
- @b = Fiddle::Pointer.malloc([@n, @n_i].max * (@k_item + @k + @k_main) * Fiddle::SIZEOF_DOUBLE)
420
- @c = p_ > 0 ? Fiddle::Pointer.malloc(p_ * (@k_user + @k) * Fiddle::SIZEOF_DOUBLE) : nil
421
- @d = q > 0 ? Fiddle::Pointer.malloc(q * (@k_item + @k) * Fiddle::SIZEOF_DOUBLE) : nil
417
+ @a = Fiddle::Pointer.malloc([@m, @m_u].max * (@k_user + @k + @k_main) * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
418
+ @b = Fiddle::Pointer.malloc([@n, @n_i].max * (@k_item + @k + @k_main) * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
419
+ @c = p_ > 0 ? Fiddle::Pointer.malloc(p_ * (@k_user + @k) * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE) : nil
420
+ @d = q > 0 ? Fiddle::Pointer.malloc(q * (@k_item + @k) * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE) : nil
422
421
 
423
422
  @bias_a = nil
424
423
  @bias_b = nil
425
424
 
426
- u_colmeans = Fiddle::Pointer.malloc(p_ * Fiddle::SIZEOF_DOUBLE)
427
- i_colmeans = Fiddle::Pointer.malloc(q * Fiddle::SIZEOF_DOUBLE)
425
+ u_colmeans = Fiddle::Pointer.malloc(p_ * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
426
+ i_colmeans = Fiddle::Pointer.malloc(q * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
428
427
 
429
428
  if @implicit
430
429
  set_implicit_vars
@@ -459,18 +458,18 @@ module Cmfrec
459
458
 
460
459
  @global_mean = 0
461
460
  else
462
- @bias_a = Fiddle::Pointer.malloc([@m, @m_u].max * Fiddle::SIZEOF_DOUBLE) if @user_bias
463
- @bias_b = Fiddle::Pointer.malloc([@n, @n_i].max * Fiddle::SIZEOF_DOUBLE) if @item_bias
461
+ @bias_a = Fiddle::Pointer.malloc([@m, @m_u].max * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE) if @user_bias
462
+ @bias_b = Fiddle::Pointer.malloc([@n, @n_i].max * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE) if @item_bias
464
463
 
465
464
  if @add_implicit_features
466
- @ai = Fiddle::Pointer.malloc([@m, @m_u].max * (@k + @k_main) * Fiddle::SIZEOF_DOUBLE)
467
- @bi = Fiddle::Pointer.malloc([@n, @n_i].max * (@k + @k_main) * Fiddle::SIZEOF_DOUBLE)
465
+ @ai = Fiddle::Pointer.malloc([@m, @m_u].max * (@k + @k_main) * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
466
+ @bi = Fiddle::Pointer.malloc([@n, @n_i].max * (@k + @k_main) * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
468
467
  else
469
468
  @ai = nil
470
469
  @bi = nil
471
470
  end
472
471
 
473
- glob_mean = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE)
472
+ glob_mean = Fiddle::Pointer.malloc(Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
474
473
 
475
474
  # TODO add
476
475
  scaling_bias_a = nil
@@ -690,8 +689,8 @@ module Cmfrec
690
689
  n_exclude = 0
691
690
  end
692
691
 
693
- outp_ix = Fiddle::Pointer.malloc(count * Fiddle::SIZEOF_INT)
694
- outp_score = Fiddle::Pointer.malloc(count * Fiddle::SIZEOF_DOUBLE)
692
+ outp_ix = Fiddle::Pointer.malloc(count * Fiddle::SIZEOF_INT, Fiddle::RUBY_FREE)
693
+ outp_score = Fiddle::Pointer.malloc(count * Fiddle::SIZEOF_DOUBLE, Fiddle::RUBY_FREE)
695
694
 
696
695
  [include_ix, n_include, exclude_ix, n_exclude, outp_ix, outp_score, count]
697
696
  end
@@ -743,9 +742,8 @@ module Cmfrec
743
742
  end
744
743
  end
745
744
 
746
- # convert boolean to int
747
745
  def fiddle_args(args)
748
- args.map { |v| v == true || v == false ? (v ? 1 : 0) : v }
746
+ args
749
747
  end
750
748
 
751
749
  def check_status(ret_val)
@@ -791,11 +789,11 @@ module Cmfrec
791
789
  end
792
790
 
793
791
  def int_array(ptr)
794
- ptr.to_s(ptr.size).unpack("i*")
792
+ ptr.to_str(ptr.size).unpack("i*")
795
793
  end
796
794
 
797
795
  def real_array(ptr)
798
- ptr.to_s(ptr.size).unpack("d*")
796
+ ptr.to_str(ptr.size).unpack("d*")
799
797
  end
800
798
 
801
799
  def set_implicit_vars
@@ -812,16 +810,14 @@ module Cmfrec
812
810
  end
813
811
 
814
812
  def json_dump_ptr(ptr)
815
- Base64.strict_encode64(ptr.to_s(ptr.size)) if ptr
813
+ [ptr.to_str(ptr.size)].pack("m0") if ptr
816
814
  end
817
815
 
818
816
  def json_load_ptr(str)
819
- Fiddle::Pointer[Base64.strict_decode64(str)] if str
817
+ Fiddle::Pointer[str.unpack1("m0")] if str
820
818
  end
821
819
 
822
820
  def json_load(obj)
823
- require "base64"
824
-
825
821
  @implicit = obj["implicit"]
826
822
 
827
823
  # options
@@ -1,3 +1,3 @@
1
1
  module Cmfrec
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.2"
3
3
  end
data/lib/cmfrec.rb CHANGED
@@ -3,9 +3,9 @@ require "etc"
3
3
  require "fiddle/import"
4
4
 
5
5
  # modules
6
- require "cmfrec/data"
7
- require "cmfrec/recommender"
8
- require "cmfrec/version"
6
+ require_relative "cmfrec/data"
7
+ require_relative "cmfrec/recommender"
8
+ require_relative "cmfrec/version"
9
9
 
10
10
  module Cmfrec
11
11
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmfrec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-23 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: fiddle
@@ -16,15 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: 1.1.7
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '0'
27
- description:
25
+ version: 1.1.7
28
26
  email: andrew@ankane.org
29
27
  executables: []
30
28
  extensions: []
@@ -51,7 +49,6 @@ homepage: https://github.com/ankane/cmfrec-ruby
51
49
  licenses:
52
50
  - MIT
53
51
  metadata: {}
54
- post_install_message:
55
52
  rdoc_options: []
56
53
  require_paths:
57
54
  - lib
@@ -66,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
63
  - !ruby/object:Gem::Version
67
64
  version: '0'
68
65
  requirements: []
69
- rubygems_version: 3.5.16
70
- signing_key:
66
+ rubygems_version: 3.6.7
71
67
  specification_version: 4
72
68
  summary: Recommendations for Ruby using collective matrix factorization
73
69
  test_files: []