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.



83
84
85
86
87
88
# File 'lib/mlir.rb', line 83

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.



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

def array
  @array
end

#item_sizeObject (readonly)

Returns the value of attribute item_size.



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

def item_size
  @item_size
end

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
end

Instance Method Details

#copy_values(array) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/mlir.rb', line 90

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



100
101
102
# File 'lib/mlir.rb', line 100

def to_ptr
  @array_ref
end

#to_typed_ptrObject



104
105
106
# File 'lib/mlir.rb', line 104

def to_typed_ptr
  @array[0]
end