lib/lightgbm/booster.rb in lightgbm-0.2.4 vs lib/lightgbm/booster.rb in lightgbm-0.2.5

- old
+ new

@@ -74,10 +74,30 @@ out_result = ::FFI::MemoryPointer.new(:double, num_feature) check_result FFI.LGBM_BoosterFeatureImportance(handle_pointer, iteration, importance_type, out_result) out_result.read_array_of_double(num_feature).map(&:to_i) end + def feature_name + len = self.num_feature + out_len = ::FFI::MemoryPointer.new(:size_t) + buffer_len = 255 + out_buffer_len = ::FFI::MemoryPointer.new(:size_t) + out_strs = ::FFI::MemoryPointer.new(:pointer, num_feature) + str_ptrs = len.times.map { ::FFI::MemoryPointer.new(:char, buffer_len) } + out_strs.write_array_of_pointer(str_ptrs) + check_result FFI.LGBM_BoosterGetFeatureNames(handle_pointer, len, out_len, buffer_len, out_buffer_len, out_strs) + + actual_len = out_buffer_len.read(:size_t) + if actual_len > buffer_len + str_ptrs = len.times.map { ::FFI::MemoryPointer.new(:char, actual_len) } + out_strs.write_array_of_pointer(str_ptrs) + check_result FFI.LGBM_BoosterGetFeatureNames(handle_pointer, len, out_len, actual_len, out_buffer_len, out_strs) + end + + str_ptrs[0, out_len.read(:size_t)].map(&:read_string) + end + def model_from_string(model_str) out_num_iterations = ::FFI::MemoryPointer.new(:int) check_result FFI.LGBM_BoosterLoadModelFromString(model_str, out_num_iterations, @handle) self end @@ -183,9 +203,17 @@ out_strs = ::FFI::MemoryPointer.new(:pointer, eval_counts) buffer_len = 255 str_ptrs = eval_counts.times.map { ::FFI::MemoryPointer.new(:char, buffer_len) } out_strs.write_array_of_pointer(str_ptrs) check_result FFI.LGBM_BoosterGetEvalNames(handle_pointer, eval_counts, out_len, buffer_len, out_buffer_len, out_strs) + + actual_len = out_buffer_len.read(:size_t) + if actual_len > buffer_len + str_ptrs = eval_counts.times.map { ::FFI::MemoryPointer.new(:char, actual_len) } + out_strs.write_array_of_pointer(str_ptrs) + check_result FFI.LGBM_BoosterGetEvalNames(handle_pointer, eval_counts, out_len, actual_len, out_buffer_len, out_strs) + end + str_ptrs.map(&:read_string) end def inner_eval(name, i) eval_names ||= eval_names()