Sha256: 205717df9d22743935e15f1a1b07a4b3737b0fa81871a14199f77b5f09282117

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

module Libmf
  module FFI
    extend ::FFI::Library

    ffi_lib Libmf.ffi_lib

    class Node < ::FFI::Struct
      layout :u, :int,
        :v, :int,
        :r, :float
    end

    class Problem < ::FFI::Struct
      layout :m, :int,
        :n, :int,
        :nnz, :long_long,
        :r, :pointer
    end

    class Parameter < ::FFI::Struct
      layout :fun, :int,
        :k, :int,
        :nr_threads, :int,
        :nr_bins, :int,
        :nr_iters, :int,
        :lambda_p1, :float,
        :lambda_p2, :float,
        :lambda_q1, :float,
        :lambda_q2, :float,
        :eta, :float,
        :alpha, :float,
        :c, :float,
        :do_nmf, :bool,
        :quiet, :bool,
        :copy_data, :bool
    end

    class Model < ::FFI::Struct
      layout :fun, :int,
        :m, :int,
        :n, :int,
        :k, :int,
        :b, :float,
        :p, :pointer,
        :q, :pointer

      def self.release(pointer)
        unless pointer.null?
          ref = ::FFI::MemoryPointer.new(:pointer).write_pointer(pointer)
          FFI.mf_destroy_model(ref)
        end
      end
    end

    attach_function :mf_get_default_param, [], Parameter.by_value
    attach_function :mf_read_problem, [:string], Problem.by_value
    attach_function :mf_save_model, [Model.by_ref, :string], :int
    attach_function :mf_load_model, [:string], Model.auto_ptr
    attach_function :mf_destroy_model, [:pointer], :void
    attach_function :mf_train, [Problem.by_ref, Parameter.by_value], Model.auto_ptr
    attach_function :mf_train_with_validation, [Problem.by_ref, Problem.by_ref, Parameter.by_value], Model.auto_ptr
    attach_function :mf_predict, [Model.by_ref, :int, :int], :float
    attach_function :mf_cross_validation, [Problem.by_ref, :int, Parameter.by_value], :double
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
libmf-0.2.6 lib/libmf/ffi.rb
libmf-0.2.5 lib/libmf/ffi.rb
libmf-0.2.4 lib/libmf/ffi.rb