Sha256: b186fc71e9d08731dbb2964bdf9ace58d9e10705711347b4b7599b6bd6f62e3e

Contents?: true

Size: 835 Bytes

Versions: 2

Compression:

Stored size: 835 Bytes

Contents

module XGBoost
  module Utils
    private

    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

    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

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
honzasterba_xgb-0.9.0 lib/xgboost/utils.rb
xgb-0.9.0 lib/xgboost/utils.rb