Class: Yadriggy::C::Float32Array

Inherits:
FFIArray
  • Object
show all
Defined in:
lib/yadriggy/c/ffi.rb

Overview

Array of 32bit floating point numbers. In C, the type of this array is arrayof(Float32).

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FFIArray

#==, #length, #memory_pointer, #set_values, #size, #to_a

Constructor Details

#initialize(size, ptr = nil) ⇒ Float32Array

Returns a new instance of Float32Array.

Parameters:

  • size (Integer)

    array size.

  • ptr (FFI::MemoryPointer) (defaults to: nil)

    a memory pointer or nil. If nil, a new memory block is allocated.



112
113
114
115
116
117
118
# File 'lib/yadriggy/c/ffi.rb', line 112

def initialize(size, ptr=nil)
  if ptr.nil?
    @array = FFI::MemoryPointer.new(:float, size)
  else
    @array = ptr
  end
end

Class Method Details

.element_typeObject



128
129
130
# File 'lib/yadriggy/c/ffi.rb', line 128

def self.element_type()
  CType::Float32
end

Instance Method Details

#[](index) ⇒ Object



120
121
122
# File 'lib/yadriggy/c/ffi.rb', line 120

def [](index)
  @array.get_float32(index * 4)
end

#[]=(index, value) ⇒ Object



124
125
126
# File 'lib/yadriggy/c/ffi.rb', line 124

def []=(index, value)
  @array.put_float32(index * 4, value)
end