Sha256: a520ac638c6564bb56ca2408a5dd7d172ee63d590c0607f8206177d3f2613470

Contents?: true

Size: 1013 Bytes

Versions: 1

Compression:

Stored size: 1013 Bytes

Contents

module Xgb
  class DMatrix
    attr_reader :data, :label, :weight

    def initialize(data, label: nil, weight: nil, missing: Float::NAN)
      @data = data
      @label = label
      @weight = weight

      c_data = ::FFI::MemoryPointer.new(:float, data.count * data.first.count)
      c_data.put_array_of_float(0, data.flatten)
      @handle = ::FFI::MemoryPointer.new(:pointer)
      check_result FFI.XGDMatrixCreateFromMat(c_data, data.count, data.first.count, missing, @handle)

      set_float_info("label", label) if label
    end

    def num_col
      out = ::FFI::MemoryPointer.new(:long)
      FFI.XGDMatrixNumCol(handle_pointer, out)
      out.read_long
    end

    def handle_pointer
      @handle.read_pointer
    end

    private

    def set_float_info(field, data)
      c_data = ::FFI::MemoryPointer.new(:float, data.count)
      c_data.put_array_of_float(0, data)
      check_result FFI.XGDMatrixSetFloatInfo(handle_pointer, field.to_s, c_data, data.size)
    end

    include Utils
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xgb-0.1.0 lib/xgb/dmatrix.rb