Class: Hornetseye::MultiArray
- Extended by:
- MultiArrayConstructor
- Defined in:
- lib/multiarray/multiarray.rb
Overview
This class provides methods for initialising multi-dimensional arrays
Class Method Summary collapse
-
.[](*args) ⇒ Node
Convert Ruby array to uniform multi-dimensional array.
- .import(typecode, string, *shape) ⇒ Object
-
.new(typecode, *shape) ⇒ Object
Create new multi-dimensional array.
Methods included from MultiArrayConstructor
Class Method Details
.[](*args) ⇒ Node
Convert Ruby array to uniform multi-dimensional array
Type matching is used to find a common element type. Furthermore the required shape of the array is determined. Finally the elements are coopied to the resulting array.
67 68 69 70 |
# File 'lib/multiarray/multiarray.rb', line 67 def []( *args ) target = Node.fit args target[ *args ] end |
.import(typecode, string, *shape) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/multiarray/multiarray.rb', line 47 def import( typecode, string, *shape ) t = Hornetseye::MultiArray typecode, *shape if string.is_a? Malloc memory = string else memory = Malloc.new t.storage_size memory.write string end t.new memory end |
.new(typecode, *shape) ⇒ Object
Create new multi-dimensional array
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/multiarray/multiarray.rb', line 29 def new( typecode, *shape ) = shape.last.is_a?( Hash ) ? shape.pop : {} count = [ :count ] || 1 if shape.empty? memory = [ :memory ] || typecode.memory.new( typecode.storage_size * count ) Hornetseye::Pointer( typecode ).new memory else size = shape.pop stride = shape.inject( 1 ) { |a,b| a * b } Hornetseye::lazy( size ) do |index| pointer = new typecode, *( shape + [ :count => count * size, :memory => [ :memory ] ] ) Lookup.new pointer, index, INT.new( stride ) end end end |