Class: MLIR::CAPI::MlirArrayRef

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/mlir.rb

Overview

Helper class to create C array of Mlir C API structs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ MlirArrayRef

Returns a new instance of MlirArrayRef.



77
78
79
80
81
82
# File 'lib/mlir.rb', line 77

def initialize(array)
  @klass = array.first.class
  @item_size = klass.size
  @array_ref = FFI::MemoryPointer.new(:pointer, array.size * item_size)
  copy_values(array)
end

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



71
72
73
# File 'lib/mlir.rb', line 71

def array
  @array
end

#item_sizeObject (readonly)

Returns the value of attribute item_size.



71
72
73
# File 'lib/mlir.rb', line 71

def item_size
  @item_size
end

#klassObject (readonly)

Returns the value of attribute klass.



71
72
73
# File 'lib/mlir.rb', line 71

def klass
  @klass
end

Instance Method Details

#copy_values(array) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/mlir.rb', line 84

def copy_values(array)
  @array = array.each_with_index.collect do |item, index|
    x = klass.new(@array_ref + (index * item_size))
    item.members.each do |member|
      x[member] = item[member]
    end
    x
  end
end

#to_ptrObject



94
95
96
# File 'lib/mlir.rb', line 94

def to_ptr
  @array_ref
end

#to_typed_ptrObject



98
99
100
# File 'lib/mlir.rb', line 98

def to_typed_ptr
  @array[0]
end