lib/xgboost/utils.rb in xgb-0.8.0 vs lib/xgboost/utils.rb in xgb-0.9.0
- old
+ new
@@ -1,18 +1,33 @@
module XGBoost
module Utils
private
- def check_result(err)
+ def check_call(err)
if err != 0
# make friendly
message = FFI.XGBGetLastError.split("\n").first.split(/:\d+: /, 2).last
raise XGBoost::Error, message
end
end
- # read_uint64 not available on JRuby
- def read_uint64(ptr)
- ptr.read_array_of_uint64(1).first
+ def array_of_pointers(values)
+ arr = ::FFI::MemoryPointer.new(:pointer, values.size)
+ arr.write_array_of_pointer(values)
+ # keep reference for string pointers
+ arr.instance_variable_set(:@xgboost_ref, values)
+ arr
+ end
+
+ def string_pointer(value)
+ ::FFI::MemoryPointer.from_string(value.to_s)
+ end
+
+ def from_cstr_to_rbstr(data, length)
+ res = []
+ length.read_uint64.times do |i|
+ res << data.read_pointer[i * ::FFI::Pointer.size].read_pointer.read_string.force_encoding(Encoding::UTF_8)
+ end
+ res
end
end
end