lightgbm 0.2.4 → 0.2.5

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: ece3e7bbda5153f43414bf2ed89f2b218dbf910dd9caf7b83bd62539fdf73eb2
4
- data.tar.gz: 59310169d8139ef88b3d2da0d02cb500a0f33b8ee748f759110af8ddd28eff4b
3
+ metadata.gz: ec446571f84421dcaf4d9453dce40aabdd8e76534e263b8de52566efc1d94560
4
+ data.tar.gz: 4be2791d0753e1f8848581c84c80c8952aa131e3eb33435293b37beee963ae19
5
5
  SHA512:
6
- metadata.gz: f2cbec33b45493d8a24123a5b478790bf98363e26ca9d49beb35ff4346ed28b8caaaffcd45e3a6e5af282efe76a29b51b77050e67c17fd74c7719ab5c0f9ceeb
7
- data.tar.gz: dd0be1257ab211855e8e40f7f63b7a2e23de64298989357694361cd966e37530054489d2d0389b2fd748ed56f4fd75a90005700ff2ba6bc6023cca2d92358a86
6
+ metadata.gz: 03317e8af302bfbe6d3cd6b5d9499696c249bcfadaa0d265ca04cbd4b0d5801a1379cefc6789b1d0ad7e4d3ef1e2f9f3728f3654195823b55821b226141e41e8
7
+ data.tar.gz: b94edee304531f64a605785a707fdc4ae3b1d7879a121d98708ce5f32eef747d483f396e6a164f3fad76e0d0dcb63b46a05f68fa7fb57f3d7c6c2e1070ecabbe
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.5 (2021-07-07)
2
+
3
+ - Added `feature_name` method to boosters
4
+
1
5
  ## 0.2.4 (2021-03-26)
2
6
 
3
7
  - Updated LightGBM to 3.2.0
@@ -76,6 +76,26 @@ module LightGBM
76
76
  out_result.read_array_of_double(num_feature).map(&:to_i)
77
77
  end
78
78
 
79
+ def feature_name
80
+ len = self.num_feature
81
+ out_len = ::FFI::MemoryPointer.new(:size_t)
82
+ buffer_len = 255
83
+ out_buffer_len = ::FFI::MemoryPointer.new(:size_t)
84
+ out_strs = ::FFI::MemoryPointer.new(:pointer, num_feature)
85
+ str_ptrs = len.times.map { ::FFI::MemoryPointer.new(:char, buffer_len) }
86
+ out_strs.write_array_of_pointer(str_ptrs)
87
+ check_result FFI.LGBM_BoosterGetFeatureNames(handle_pointer, len, out_len, buffer_len, out_buffer_len, out_strs)
88
+
89
+ actual_len = out_buffer_len.read(:size_t)
90
+ if actual_len > buffer_len
91
+ str_ptrs = len.times.map { ::FFI::MemoryPointer.new(:char, actual_len) }
92
+ out_strs.write_array_of_pointer(str_ptrs)
93
+ check_result FFI.LGBM_BoosterGetFeatureNames(handle_pointer, len, out_len, actual_len, out_buffer_len, out_strs)
94
+ end
95
+
96
+ str_ptrs[0, out_len.read(:size_t)].map(&:read_string)
97
+ end
98
+
79
99
  def model_from_string(model_str)
80
100
  out_num_iterations = ::FFI::MemoryPointer.new(:int)
81
101
  check_result FFI.LGBM_BoosterLoadModelFromString(model_str, out_num_iterations, @handle)
@@ -185,6 +205,14 @@ module LightGBM
185
205
  str_ptrs = eval_counts.times.map { ::FFI::MemoryPointer.new(:char, buffer_len) }
186
206
  out_strs.write_array_of_pointer(str_ptrs)
187
207
  check_result FFI.LGBM_BoosterGetEvalNames(handle_pointer, eval_counts, out_len, buffer_len, out_buffer_len, out_strs)
208
+
209
+ actual_len = out_buffer_len.read(:size_t)
210
+ if actual_len > buffer_len
211
+ str_ptrs = eval_counts.times.map { ::FFI::MemoryPointer.new(:char, actual_len) }
212
+ out_strs.write_array_of_pointer(str_ptrs)
213
+ check_result FFI.LGBM_BoosterGetEvalNames(handle_pointer, eval_counts, out_len, actual_len, out_buffer_len, out_strs)
214
+ end
215
+
188
216
  str_ptrs.map(&:read_string)
189
217
  end
190
218
 
@@ -34,6 +34,18 @@ module LightGBM
34
34
  str_ptrs = len.times.map { ::FFI::MemoryPointer.new(:char, buffer_len) }
35
35
  out_strs.write_array_of_pointer(str_ptrs)
36
36
  check_result FFI.LGBM_DatasetGetFeatureNames(handle_pointer, len, num_feature_names, buffer_len, out_buffer_len, out_strs)
37
+
38
+ num_features = num_feature_names.read_int
39
+ actual_len = out_buffer_len.read(:size_t)
40
+ if num_features > len || actual_len > buffer_len
41
+ out_strs = ::FFI::MemoryPointer.new(:pointer, num_features) if num_features > len
42
+ str_ptrs = num_features.times.map { ::FFI::MemoryPointer.new(:char, actual_len) }
43
+ out_strs.write_array_of_pointer(str_ptrs)
44
+ check_result FFI.LGBM_DatasetGetFeatureNames(handle_pointer, num_features, num_feature_names, actual_len, out_buffer_len, out_strs)
45
+ end
46
+
47
+ # should be the same, but get number of features
48
+ # from most recent call (instead of num_features)
37
49
  str_ptrs[0, num_feature_names.read_int].map(&:read_string)
38
50
  end
39
51
 
data/lib/lightgbm/ffi.rb CHANGED
@@ -45,6 +45,7 @@ module LightGBM
45
45
  attach_function :LGBM_BoosterNumberOfTotalModel, %i[pointer pointer], :int
46
46
  attach_function :LGBM_BoosterGetEvalCounts, %i[pointer pointer], :int
47
47
  attach_function :LGBM_BoosterGetEvalNames, %i[pointer int pointer size_t pointer pointer], :int
48
+ attach_function :LGBM_BoosterGetFeatureNames, %i[pointer int pointer size_t pointer pointer], :int
48
49
  attach_function :LGBM_BoosterGetNumFeature, %i[pointer pointer], :int
49
50
  attach_function :LGBM_BoosterGetEval, %i[pointer int pointer pointer], :int
50
51
  attach_function :LGBM_BoosterPredictForMat, %i[pointer pointer int int32 int32 int int int int string pointer pointer], :int
@@ -1,3 +1,3 @@
1
1
  module LightGBM
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightgbm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-26 00:00:00.000000000 Z
11
+ date: 2021-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi