class CooCoo::CUDA::HostBuffer
Attributes
size[R]
type[R]
Public Class Methods
[](other, length = nil)
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 27 def self.[](other, length = nil) if other.kind_of?(self) return other.resize(length || other.size) elsif other.respond_to?(:each_with_index) return self.new(length || other.size).set(other) elsif other.kind_of?(Numeric) return self.new(length || 1).set(other) else return self[other.to_enum, length] end end
new(size, type = :double)
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 39 def initialize(size, type = :double) @size = size @type = type @buffer = ::FFI::MemoryPointer.new(type, size) end
Public Instance Methods
[](index)
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 86 def [](index) @buffer[index].send(type_reader) end
[]=(index, value)
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 82 def []=(index, value) @buffer[index].send(type_writer, type_convertor.call(value)) end
byte_size()
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 51 def byte_size @size * type_size end
each(&block)
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 90 def each(&block) return to_enum(__method__) unless block_given? size.times do |i| block.call(self[i]) end end
get()
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 74 def get @buffer end
resize(new_size)
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 45 def resize(new_size) return self if @size == new_size self.class.new(new_size).set(self.each) end
set(values)
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 59 def set(values) if values.respond_to?(:each_with_index) values.each_with_index do |v, i| break if i >= size self[i] = v end else size.times do |i| self[i] = values end end self end
to_a()
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 110 def to_a @size.times.collect do |i| self[i] end end
to_ptr()
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 78 def to_ptr @buffer end
type_convertor()
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 102 def type_convertor @type_convertor ||= TYPE_CONVERTOR[@type] end
type_reader()
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 106 def type_reader @type_reader ||= TYPE_GETTER[@type] end
type_size()
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 55 def type_size ::FFI.type_size(@type) end
type_writer()
click to toggle source
# File lib/coo-coo/cuda/host_buffer.rb, line 98 def type_writer @type_writer ||= TYPE_WRITER[@type] end