lib/lightgbm/booster.rb in lightgbm-0.1.3 vs lib/lightgbm/booster.rb in lightgbm-0.1.4

- old
+ new

@@ -12,23 +12,18 @@ else params ||= {} set_verbosity(params) check_result FFI.LGBM_BoosterCreate(train_set.handle_pointer, params_str(params), @handle) end - # causes "Stack consistency error" - # ObjectSpace.define_finalizer(self, self.class.finalize(handle_pointer)) + ObjectSpace.define_finalizer(self, self.class.finalize(handle_pointer)) self.best_iteration = -1 # TODO get names when loaded from file @name_valid_sets = [] end - def self.finalize(pointer) - -> { FFI.LGBM_BoosterFree(pointer) } - end - def add_valid(data, name) check_result FFI.LGBM_BoosterAddValidData(handle_pointer, data.handle_pointer) @name_valid_sets << name self # consistent with Python API end @@ -149,9 +144,14 @@ def update finished = ::FFI::MemoryPointer.new(:int) check_result FFI.LGBM_BoosterUpdateOneIter(handle_pointer, finished) finished.read_int == 1 + end + + def self.finalize(pointer) + # must use proc instead of stabby lambda + proc { FFI.LGBM_BoosterFree(pointer) } end private def handle_pointer