lib/lightgbm/booster.rb in lightgbm-0.1.6 vs lib/lightgbm/booster.rb in lightgbm-0.1.7
- old
+ new
@@ -28,23 +28,23 @@
self # consistent with Python API
end
def current_iteration
out = ::FFI::MemoryPointer.new(:int)
- check_result FFI::LGBM_BoosterGetCurrentIteration(handle_pointer, out)
+ check_result FFI.LGBM_BoosterGetCurrentIteration(handle_pointer, out)
out.read_int
end
def dump_model(num_iteration: nil, start_iteration: 0)
num_iteration ||= best_iteration
buffer_len = 1 << 20
out_len = ::FFI::MemoryPointer.new(:int64)
- out_str = ::FFI::MemoryPointer.new(:string, buffer_len)
+ out_str = ::FFI::MemoryPointer.new(:char, buffer_len)
check_result FFI.LGBM_BoosterDumpModel(handle_pointer, start_iteration, num_iteration, buffer_len, out_len, out_str)
actual_len = read_int64(out_len)
if actual_len > buffer_len
- out_str = ::FFI::MemoryPointer.new(:string, actual_len)
+ out_str = ::FFI::MemoryPointer.new(:char, actual_len)
check_result FFI.LGBM_BoosterDumpModel(handle_pointer, start_iteration, num_iteration, actual_len, out_len, out_str)
end
out_str.read_string
end
alias_method :to_json, :dump_model
@@ -83,15 +83,15 @@
def model_to_string(num_iteration: nil, start_iteration: 0)
num_iteration ||= best_iteration
buffer_len = 1 << 20
out_len = ::FFI::MemoryPointer.new(:int64)
- out_str = ::FFI::MemoryPointer.new(:string, buffer_len)
+ out_str = ::FFI::MemoryPointer.new(:char, buffer_len)
check_result FFI.LGBM_BoosterSaveModelToString(handle_pointer, start_iteration, num_iteration, buffer_len, out_len, out_str)
actual_len = read_int64(out_len)
if actual_len > buffer_len
- out_str = ::FFI::MemoryPointer.new(:string, actual_len)
+ out_str = ::FFI::MemoryPointer.new(:char, actual_len)
check_result FFI.LGBM_BoosterSaveModelToString(handle_pointer, start_iteration, num_iteration, actual_len, out_len, out_str)
end
out_str.read_string
end
@@ -102,17 +102,17 @@
end
alias_method :num_features, :num_feature # legacy typo
def num_model_per_iteration
out = ::FFI::MemoryPointer.new(:int)
- check_result FFI::LGBM_BoosterNumModelPerIteration(handle_pointer, out)
+ check_result FFI.LGBM_BoosterNumModelPerIteration(handle_pointer, out)
out.read_int
end
def num_trees
out = ::FFI::MemoryPointer.new(:int)
- check_result FFI::LGBM_BoosterNumberOfTotalModel(handle_pointer, out)
+ check_result FFI.LGBM_BoosterNumberOfTotalModel(handle_pointer, out)
out.read_int
end
# TODO support different prediction types
def predict(input, num_iteration: nil, **params)
@@ -129,16 +129,16 @@
num_iteration ||= best_iteration
num_class ||= num_class()
flat_input = input.flatten
handle_missing(flat_input)
- data = ::FFI::MemoryPointer.new(:float, input.count * input.first.count)
- data.put_array_of_float(0, flat_input)
+ data = ::FFI::MemoryPointer.new(:double, input.count * input.first.count)
+ data.write_array_of_double(flat_input)
out_len = ::FFI::MemoryPointer.new(:int64)
out_result = ::FFI::MemoryPointer.new(:double, num_class * input.count)
- check_result FFI.LGBM_BoosterPredictForMat(handle_pointer, data, 0, input.count, input.first.count, 1, 0, num_iteration, params_str(params), out_len, out_result)
+ check_result FFI.LGBM_BoosterPredictForMat(handle_pointer, data, 1, input.count, input.first.count, 1, 0, num_iteration, params_str(params), out_len, out_result)
out = out_result.read_array_of_double(read_int64(out_len))
out = out.each_slice(num_class).to_a if num_class > 1
singular ? out.first : out
end
@@ -166,20 +166,20 @@
@handle.read_pointer
end
def eval_counts
out = ::FFI::MemoryPointer.new(:int)
- check_result FFI::LGBM_BoosterGetEvalCounts(handle_pointer, out)
+ check_result FFI.LGBM_BoosterGetEvalCounts(handle_pointer, out)
out.read_int
end
def eval_names
eval_counts ||= eval_counts()
out_len = ::FFI::MemoryPointer.new(:int)
out_strs = ::FFI::MemoryPointer.new(:pointer, eval_counts)
- str_ptrs = eval_counts.times.map { ::FFI::MemoryPointer.new(:string, 255) }
- out_strs.put_array_of_pointer(0, str_ptrs)
+ str_ptrs = eval_counts.times.map { ::FFI::MemoryPointer.new(:char, 255) }
+ out_strs.write_array_of_pointer(str_ptrs)
check_result FFI.LGBM_BoosterGetEvalNames(handle_pointer, out_len, out_strs)
str_ptrs.map(&:read_string)
end
def inner_eval(name, i)
@@ -196,10 +196,10 @@
end
end
def num_class
out = ::FFI::MemoryPointer.new(:int)
- check_result FFI::LGBM_BoosterGetNumClasses(handle_pointer, out)
+ check_result FFI.LGBM_BoosterGetNumClasses(handle_pointer, out)
out.read_int
end
# read_int64 not available on JRuby
def read_int64(ptr)