lib/lightgbm/dataset.rb in lightgbm-0.1.8 vs lib/lightgbm/dataset.rb in lightgbm-0.1.9
- old
+ new
@@ -128,21 +128,26 @@
ncol = data.column_count
flat_data = data.to_a.flatten
elsif daru?(data)
nrow, ncol = data.shape
flat_data = data.map_rows(&:to_a).flatten
- elsif narray?(data)
+ elsif numo?(data) || rover?(data)
+ data = data.to_numo if rover?(data)
nrow, ncol = data.shape
- flat_data = data.flatten.to_a
else
nrow = data.count
ncol = data.first.count
flat_data = data.flatten
end
- handle_missing(flat_data)
c_data = ::FFI::MemoryPointer.new(:double, nrow * ncol)
- c_data.write_array_of_double(flat_data)
+ if numo?(data)
+ c_data.write_bytes(data.cast_to(Numo::DFloat).to_string)
+ else
+ handle_missing(flat_data)
+ 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
self.label = @label if @label