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.
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
#array ⇒ Object (readonly)
Returns the value of attribute array.
71 72 73 |
# File 'lib/mlir.rb', line 71 def array @array end |
#item_size ⇒ Object (readonly)
Returns the value of attribute item_size.
71 72 73 |
# File 'lib/mlir.rb', line 71 def item_size @item_size end |
#klass ⇒ Object (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_ptr ⇒ Object
94 95 96 |
# File 'lib/mlir.rb', line 94 def to_ptr @array_ref end |
#to_typed_ptr ⇒ Object
98 99 100 |
# File 'lib/mlir.rb', line 98 def to_typed_ptr @array[0] end |