Class: MLIR::CAPI::MlirArrayRef
- Inherits:
-
Object
- Object
- MLIR::CAPI::MlirArrayRef
- 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
-
#array ⇒ Object
readonly
Returns the value of attribute array.
-
#item_size ⇒ Object
readonly
Returns the value of attribute item_size.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #copy_values(array) ⇒ Object
-
#initialize(array) ⇒ MlirArrayRef
constructor
A new instance of MlirArrayRef.
- #to_ptr ⇒ Object
- #to_typed_ptr ⇒ Object
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
#array ⇒ Object (readonly)
Returns the value of attribute array.
77 78 79 |
# File 'lib/mlir.rb', line 77 def array @array end |
#item_size ⇒ Object (readonly)
Returns the value of attribute item_size.
77 78 79 |
# File 'lib/mlir.rb', line 77 def item_size @item_size end |
#klass ⇒ Object (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_ptr ⇒ Object
100 101 102 |
# File 'lib/mlir.rb', line 100 def to_ptr @array_ref end |
#to_typed_ptr ⇒ Object
104 105 106 |
# File 'lib/mlir.rb', line 104 def to_typed_ptr @array[0] end |