Class: Hornetseye::Lookup
Overview
Class for lazy array lookup
Instance Method Summary collapse
-
#array_type ⇒ Class
Get type of result of delayed operation.
-
#decompose(i) ⇒ Node
Decompose composite elements.
-
#descriptor(hash) ⇒ String
Get unique descriptor of this object.
-
#element(i) ⇒ Node, Object
Get element if lookup term.
-
#initialize(p, index, stride) ⇒ Lookup
constructor
Create array lookup.
-
#lookup(value, stride) ⇒ Object
Lookup element of an array.
- #memory ⇒ Object
-
#skip(index, start) ⇒ Node
Skip elements of an array.
-
#slice(start, length) ⇒ Node
Extract array view with part of array.
-
#strip ⇒ Array<Array,Node>
Strip of all values.
-
#subst(hash) ⇒ Node
Substitute variables.
-
#variables ⇒ Set
Get variables contained in this object.
Methods inherited from Node
===, #[], #[]=, array_type, basetype, #basetype, bool, byte, #check_shape, #coerce, coercion_bool, coercion_byte, coercion_maxint, #compilable?, compilable?, cond, contiguous, #demand, descriptor, dimension, #dimension, #dup, empty?, #empty?, finalised?, #finalised?, float, float_scalar, floating, #force, #get, height, #height, indgen, #inspect, match, maxint, pointer_type, #pointer_type, rgb?, #rgb?, scalar, #shape, shape, #simplify, size, #size, #storage_size, strip, subst, #to_a, #to_s, to_s, to_type, #typecode, typecode, typecodes, variables, #width, width
Methods included from FLOAT_::Match
Methods included from OBJECT::Match
Methods included from COMPLEX_::Match
Methods included from Sequence_::Match
Methods included from BOOL::Match
Methods included from RGB_::Match
Methods included from INT_::Match
Methods included from Operations
#+@, #<=>, #b=, #b_with_decompose, #collect, #conditional, #convolve, define_binary_op, define_unary_op, #diagonal, #eq_with_multiarray, #fill!, #g=, #g_with_decompose, #histogram, #imag=, #imag_with_decompose, #inject, #integral, #lut, #max, #min, #normalise, #product, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #roll, #sum, #to_type, #to_type_with_rgb, #transpose, #unroll
Constructor Details
#initialize(p, index, stride) ⇒ Lookup
Create array lookup
28 29 30 |
# File 'lib/multiarray/lookup.rb', line 28 def initialize( p, index, stride ) @p, @index, @stride = p, index, stride end |
Instance Method Details
#array_type ⇒ Class
Get type of result of delayed operation
56 57 58 |
# File 'lib/multiarray/lookup.rb', line 56 def array_type @p.array_type end |
#decompose(i) ⇒ Node
Decompose composite elements
This method decomposes composite elements into array.
156 157 158 159 160 161 162 |
# File 'lib/multiarray/lookup.rb', line 156 def decompose( i ) if typecode < Composite Lookup.new @p.decompose( i ), @index, @stride * typecode.num_elements else Lookup.new @p.decompose( i ), @index, @stride end end |
#descriptor(hash) ⇒ String
Get unique descriptor of this object
46 47 48 49 |
# File 'lib/multiarray/lookup.rb', line 46 def descriptor( hash ) "Lookup(#{@p.descriptor( hash )},#{@index.descriptor( hash )}," + "#{@stride.descriptor( hash )})" end |
#element(i) ⇒ Node, Object
Get element if lookup term
135 136 137 |
# File 'lib/multiarray/lookup.rb', line 135 def element( i ) Lookup.new @p.element( i ), @index, @stride end |
#lookup(value, stride) ⇒ Object
Lookup element of an array
104 105 106 107 108 109 110 |
# File 'lib/multiarray/lookup.rb', line 104 def lookup( value, stride ) if value.is_a? Variable Lookup.new self, value, stride else Lookup.new @p.lookup( value, stride ), @index, @stride end end |
#memory ⇒ Object
32 33 34 35 36 37 |
# File 'lib/multiarray/lookup.rb', line 32 def memory #if array_type.storage_size != @stride.get * typecode.storage_size # raise 'Memory is not contiguous' #end @p.memory end |
#skip(index, start) ⇒ Node
Skip elements of an array
120 121 122 123 124 125 126 |
# File 'lib/multiarray/lookup.rb', line 120 def skip( index, start ) if @index == index Lookup.new @p.lookup( start, @stride ), @index, @stride else Lookup.new @p.skip( index, start ), @index, @stride end end |
#slice(start, length) ⇒ Node
Extract array view with part of array
147 148 149 |
# File 'lib/multiarray/lookup.rb', line 147 def slice( start, length ) Lookup.new @p.slice( start, length ), @index, @stride end |
#strip ⇒ Array<Array,Node>
Strip of all values
Split up into variables, values, and a term where all values have been replaced with variables.
values, and the term based on variables.
91 92 93 94 95 96 |
# File 'lib/multiarray/lookup.rb', line 91 def strip vars1, values1, term1 = @p.strip vars2, values2, term2 = @stride.strip return vars1 + vars2, values1 + values2, Lookup.new( term1, @index, term2 ) end |
#subst(hash) ⇒ Node
Substitute variables
Substitute the variables with the values given in the hash.
69 70 71 |
# File 'lib/multiarray/lookup.rb', line 69 def subst( hash ) @p.subst( hash ).lookup @index.subst( hash ), @stride.subst( hash ) end |
#variables ⇒ Set
Get variables contained in this object
78 79 80 |
# File 'lib/multiarray/lookup.rb', line 78 def variables @p.variables + @index.variables + @stride.variables end |