libmf 0.2.0 → 0.2.4

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: 58c3cf0afbb36ff976cb7641104f363795499023ce04c859beedf17bccaaffa1
4
- data.tar.gz: '09a6b70c631ae252b24bd83c3cbb08ff3a9468d6b174b0255cf8223aaf77ea4d'
3
+ metadata.gz: ca5a2bbda585f7e2f57630d20dfb6cf6091ab33e90227edd277c457af7f8dac7
4
+ data.tar.gz: 3f8a1612c831223e552cf5af4172f31080d297f2e3f059624d66790613333890
5
5
  SHA512:
6
- metadata.gz: ad1aad8cdb571fd5fa99aa121a67cf172f6686b793a89a82b555005116378a07772c6675e20308f8575419d618edfa368c0adef738da06847f0c06e860ab650e
7
- data.tar.gz: 87f4260c2bccc5f5da8c44497d656fd367467b1d403de6584d802700359f455e55e7f9cbf71db515a5252012e27ace4cf52f5e284528b05a1a6b0be72c693a0d
6
+ metadata.gz: 6d8cf1bf142c4e365c2b01a10c5e407d331d24d8410f8ee2b262c6ca6c94dfe129c5ac0a3dc6ae97e0739884aaeec9483c39546714975a8e9929c8a63799f15c
7
+ data.tar.gz: 80356261c846d506160df89424b9f67d070908e1cc1f9c583e83cbbec5b7ebce272acb5146e447dd1394bb7c5d3268bf00837dc0814eb5ccb23d8c23c53efae3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## 0.2.4 (2021-08-05)
2
+
3
+ - Fixed memory leak
4
+
5
+ ## 0.2.3 (2021-03-14)
6
+
7
+ - Added ARM shared library for Linux
8
+
9
+ ## 0.2.2 (2021-02-04)
10
+
11
+ - Reduced allocations
12
+ - Improved ARM detection
13
+
14
+ ## 0.2.1 (2020-12-28)
15
+
16
+ - Added ARM shared library for Mac
17
+
1
18
  ## 0.2.0 (2020-03-26)
2
19
 
3
20
  - Changed to BSD 3-Clause license to match LIBMF
data/LICENSE.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  BSD 3-Clause License
2
2
 
3
- Copyright (c) 2019-2020, Andrew Kane
3
+ Copyright (c) 2014-2015, The LIBMF Project
4
+ Copyright (c) 2019-2021, Andrew Kane
4
5
  All rights reserved.
5
6
 
6
7
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Check out [Disco](https://github.com/ankane/disco) for higher-level collaborative filtering
6
6
 
7
- [![Build Status](https://travis-ci.org/ankane/libmf.svg?branch=master)](https://travis-ci.org/ankane/libmf) [![Build status](https://ci.appveyor.com/api/projects/status/92fbip1bd8sjd2tj/branch/master?svg=true)](https://ci.appveyor.com/project/ankane/libmf/branch/master)
7
+ [![Build Status](https://github.com/ankane/libmf/workflows/build/badge.svg?branch=master)](https://github.com/ankane/libmf/actions)
8
8
 
9
9
  ## Installation
10
10
 
@@ -39,14 +39,19 @@ Make predictions
39
39
  model.predict(row_index, column_index)
40
40
  ```
41
41
 
42
- Get the bias and latent factors
42
+ Get the latent factors (these approximate the training matrix)
43
43
 
44
44
  ```ruby
45
- model.bias
46
45
  model.p_factors
47
46
  model.q_factors
48
47
  ```
49
48
 
49
+ Get the bias (average of all elements in the training matrix)
50
+
51
+ ```ruby
52
+ model.bias
53
+ ```
54
+
50
55
  Save the model to a file
51
56
 
52
57
  ```ruby
data/lib/libmf.rb CHANGED
@@ -15,9 +15,17 @@ module Libmf
15
15
  if Gem.win_platform?
16
16
  "mf.dll"
17
17
  elsif RbConfig::CONFIG["host_os"] =~ /darwin/i
18
- "libmf.dylib"
18
+ if RbConfig::CONFIG["host_cpu"] =~ /arm/i
19
+ "libmf.arm64.dylib"
20
+ else
21
+ "libmf.dylib"
22
+ end
19
23
  else
20
- "libmf.so"
24
+ if RbConfig::CONFIG["host_cpu"] =~ /aarch64/i
25
+ "libmf.arm64.so"
26
+ else
27
+ "libmf.so"
28
+ end
21
29
  end
22
30
  vendor_lib = File.expand_path("../vendor/#{lib_name}", __dir__)
23
31
  self.ffi_lib = [vendor_lib]
data/lib/libmf/ffi.rb CHANGED
@@ -43,15 +43,22 @@ module Libmf
43
43
  :b, :float,
44
44
  :p, :pointer,
45
45
  :q, :pointer
46
+
47
+ def self.release(pointer)
48
+ unless pointer.null?
49
+ ref = ::FFI::MemoryPointer.new(:pointer).write_pointer(pointer)
50
+ FFI.mf_destroy_model(ref)
51
+ end
52
+ end
46
53
  end
47
54
 
48
55
  attach_function :mf_get_default_param, [], Parameter.by_value
49
56
  attach_function :mf_read_problem, [:string], Problem.by_value
50
57
  attach_function :mf_save_model, [Model.by_ref, :string], :int
51
- attach_function :mf_load_model, [:string], Model.by_ref
52
- attach_function :mf_destroy_model, [Model.by_ref], :void
53
- attach_function :mf_train, [Problem.by_ref, Parameter.by_value], Model.by_ref
54
- attach_function :mf_train_with_validation, [Problem.by_ref, Problem.by_ref, Parameter.by_value], Model.by_ref
58
+ attach_function :mf_load_model, [:string], Model.auto_ptr
59
+ attach_function :mf_destroy_model, [:pointer], :void
60
+ attach_function :mf_train, [Problem.by_ref, Parameter.by_value], Model.auto_ptr
61
+ attach_function :mf_train_with_validation, [Problem.by_ref, Problem.by_ref, Parameter.by_value], Model.auto_ptr
55
62
  attach_function :mf_predict, [Model.by_ref, :int, :int], :float
56
63
  attach_function :mf_cross_validation, [Problem.by_ref, :int, Parameter.by_value], :double
57
64
  end
data/lib/libmf/model.rb CHANGED
@@ -111,10 +111,11 @@ module Libmf
111
111
 
112
112
  # TODO do in C for better performance
113
113
  # can use FIX2INT() and RFLOAT_VALUE() instead of pack
114
+ # and write directly to C string
114
115
  buffer = String.new
116
+ pack_format = "iif"
115
117
  data.each do |row|
116
- row[0, 2].pack("i*".freeze, buffer: buffer)
117
- row[2, 1].pack("f".freeze, buffer: buffer)
118
+ row.pack(pack_format, buffer: buffer)
118
119
  end
119
120
 
120
121
  r = ::FFI::MemoryPointer.new(FFI::Node, data.size)
data/lib/libmf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Libmf
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.4"
3
3
  end
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libmf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-26 00:00:00.000000000 Z
11
+ date: 2021-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -24,78 +24,8 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '5'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '5'
69
- - !ruby/object:Gem::Dependency
70
- name: benchmark-ips
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: numo-narray
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- description:
98
- email: andrew@chartkick.com
27
+ description:
28
+ email: andrew@ankane.org
99
29
  executables: []
100
30
  extensions: []
101
31
  extra_rdoc_files: []
@@ -110,6 +40,8 @@ files:
110
40
  - vendor/COPYRIGHT
111
41
  - vendor/demo/real_matrix.te.txt
112
42
  - vendor/demo/real_matrix.tr.txt
43
+ - vendor/libmf.arm64.dylib
44
+ - vendor/libmf.arm64.so
113
45
  - vendor/libmf.dylib
114
46
  - vendor/libmf.so
115
47
  - vendor/mf.dll
@@ -117,7 +49,7 @@ homepage: https://github.com/ankane/libmf
117
49
  licenses:
118
50
  - BSD-3-Clause
119
51
  metadata: {}
120
- post_install_message:
52
+ post_install_message:
121
53
  rdoc_options: []
122
54
  require_paths:
123
55
  - lib
@@ -132,8 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
64
  - !ruby/object:Gem::Version
133
65
  version: '0'
134
66
  requirements: []
135
- rubygems_version: 3.1.2
136
- signing_key:
67
+ rubygems_version: 3.2.22
68
+ signing_key:
137
69
  specification_version: 4
138
70
  summary: Large-scale sparse matrix factorization for Ruby
139
71
  test_files: []