lib/lightgbm/dataset.rb in lightgbm-0.1.6 vs lib/lightgbm/dataset.rb in lightgbm-0.1.7

- old
+ new

@@ -15,11 +15,11 @@ @handle = ::FFI::MemoryPointer.new(:pointer) parameters = params_str(params) reference = reference.handle_pointer if reference if used_indices used_row_indices = ::FFI::MemoryPointer.new(:int32, used_indices.count) - used_row_indices.put_array_of_int32(0, used_indices) + used_row_indices.write_array_of_int32(used_indices) check_result FFI.LGBM_DatasetGetSubset(reference, used_row_indices, used_indices.count, parameters, @handle) elsif data.is_a?(String) check_result FFI.LGBM_DatasetCreateFromFile(data, parameters, reference, @handle) else if matrix?(data) @@ -37,13 +37,13 @@ ncol = data.first.count flat_data = data.flatten end handle_missing(flat_data) - c_data = ::FFI::MemoryPointer.new(:float, nrow * ncol) - c_data.put_array_of_float(0, flat_data) - check_result FFI.LGBM_DatasetCreateFromMat(c_data, 0, nrow, ncol, 1, parameters, reference, @handle) + c_data = ::FFI::MemoryPointer.new(:double, nrow * ncol) + c_data.write_array_of_double(flat_data) + 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 self.label = label if label self.weight = weight if weight @@ -65,12 +65,12 @@ def feature_names # must preallocate space num_feature_names = ::FFI::MemoryPointer.new(:int) out_strs = ::FFI::MemoryPointer.new(:pointer, 1000) - str_ptrs = 1000.times.map { ::FFI::MemoryPointer.new(:string, 255) } - out_strs.put_array_of_pointer(0, str_ptrs) + str_ptrs = 1000.times.map { ::FFI::MemoryPointer.new(:char, 255) } + out_strs.write_array_of_pointer(str_ptrs) check_result FFI.LGBM_DatasetGetFeatureNames(handle_pointer, out_strs, num_feature_names) str_ptrs[0, num_feature_names.read_int].map(&:read_string) end def weight=(weight) @@ -139,14 +139,14 @@ def set_field(field_name, data, type: :float) data = data.to_a unless data.is_a?(Array) if type == :int32 c_data = ::FFI::MemoryPointer.new(:int32, data.count) - c_data.put_array_of_int32(0, data) + c_data.write_array_of_int32(data) check_result FFI.LGBM_DatasetSetField(handle_pointer, field_name, c_data, data.count, 2) else c_data = ::FFI::MemoryPointer.new(:float, data.count) - c_data.put_array_of_float(0, data) + c_data.write_array_of_float(data) check_result FFI.LGBM_DatasetSetField(handle_pointer, field_name, c_data, data.count, 0) end end include Utils