lib/lightgbm/dataset.rb in lightgbm-0.2.7 vs lib/lightgbm/dataset.rb in lightgbm-0.3.0
- old
+ new
@@ -73,11 +73,10 @@
# TODO only update reference if not in chain
def reference=(reference)
if reference != @reference
@reference = reference
- free_handle
construct
end
end
def num_data
@@ -108,13 +107,13 @@
def handle_pointer
@handle.read_pointer
end
- def self.finalize(pointer)
+ def self.finalize(addr)
# must use proc instead of stabby lambda
- proc { FFI.LGBM_DatasetFree(pointer) }
+ proc { FFI.LGBM_DatasetFree(::FFI::Pointer.new(:pointer, addr)) }
end
private
def construct
@@ -162,20 +161,15 @@
c_data.write_array_of_double(flat_data)
end
check_result FFI.LGBM_DatasetCreateFromMat(c_data, 1, nrow, ncol, 1, parameters, reference, @handle)
end
- ObjectSpace.define_finalizer(self, self.class.finalize(handle_pointer)) unless used_indices
+ ObjectSpace.define_finalizer(@handle, self.class.finalize(handle_pointer.to_i)) unless used_indices
self.label = @label if @label
self.weight = @weight if @weight
self.group = @group if @group
self.feature_names = @feature_names if @feature_names
- end
-
- def free_handle
- FFI.LGBM_DatasetFree(handle_pointer)
- ObjectSpace.undefine_finalizer(self)
end
def dump_text(filename)
check_result FFI.LGBM_DatasetDumpText(handle_pointer, filename)
end