lib/lightgbm/booster.rb in lightgbm-0.1.5 vs lib/lightgbm/booster.rb in lightgbm-0.1.6

- old
+ new

@@ -38,11 +38,11 @@ num_iteration ||= best_iteration buffer_len = 1 << 20 out_len = ::FFI::MemoryPointer.new(:int64) out_str = ::FFI::MemoryPointer.new(:string, buffer_len) check_result FFI.LGBM_BoosterDumpModel(handle_pointer, start_iteration, num_iteration, buffer_len, out_len, out_str) - actual_len = out_len.read_int64 + actual_len = read_int64(out_len) if actual_len > buffer_len out_str = ::FFI::MemoryPointer.new(:string, actual_len) check_result FFI.LGBM_BoosterDumpModel(handle_pointer, start_iteration, num_iteration, actual_len, out_len, out_str) end out_str.read_string @@ -85,11 +85,11 @@ num_iteration ||= best_iteration buffer_len = 1 << 20 out_len = ::FFI::MemoryPointer.new(:int64) out_str = ::FFI::MemoryPointer.new(:string, buffer_len) check_result FFI.LGBM_BoosterSaveModelToString(handle_pointer, start_iteration, num_iteration, buffer_len, out_len, out_str) - actual_len = out_len.read_int64 + actual_len = read_int64(out_len) if actual_len > buffer_len out_str = ::FFI::MemoryPointer.new(:string, actual_len) check_result FFI.LGBM_BoosterSaveModelToString(handle_pointer, start_iteration, num_iteration, actual_len, out_len, out_str) end out_str.read_string @@ -135,11 +135,11 @@ data.put_array_of_float(0, 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) - out = out_result.read_array_of_double(out_len.read_int64) + 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 @@ -198,9 +198,14 @@ def num_class out = ::FFI::MemoryPointer.new(:int) check_result FFI::LGBM_BoosterGetNumClasses(handle_pointer, out) out.read_int + end + + # read_int64 not available on JRuby + def read_int64(ptr) + ptr.read_array_of_int64(1).first end include Utils end end