Class: Hornetseye::Lookup
Overview
Class for lazy array lookup
Instance Method Summary collapse
-
#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 ⇒ Malloc, ...
Get storage object if there is any.
-
#shape ⇒ Array<Integer>
Get shape of this term.
-
#skip(index, start) ⇒ Node
Skip elements of an array.
-
#slice(start, length) ⇒ Node
Extract array view with part of array.
-
#stride(index) ⇒ Integer, NilClass
Get stride for specific index.
-
#strides ⇒ Array<Integer>, NilClass
Get strides of array.
-
#strip ⇒ Array<Array,Node>
Strip of all values.
-
#subst(hash) ⇒ Node
Substitute variables.
-
#typecode ⇒ Class
Element-type of this term.
-
#variables ⇒ Set
Get variables contained in this object.
Methods inherited from Node
#+@, #<=>, ===, #[], #[]=, #allocate, #b=, #b_with_decompose, basetype, #basetype, #between?, bool, byte, #check_shape, #clip, #coerce, coercion_bool, coercion_byte, coercion_maxint, #collect, compilable?, #compilable?, #components, cond, #conditional, #convolve, define_binary_op, define_unary_op, #demand, descriptor, #diagonal, #dilate, dimension, #dimension, #downsample, #dup, #each, #empty?, #eq_with_multiarray, #erode, #fill!, #finalised?, finalised?, #flip, float, float_scalar, floating, #fmod_with_float, #force, #g=, #g_with_decompose, #gauss_blur, #gauss_gradient, #get, #height, #histogram, #histogram_with_rgb, identity, #if, #if_else, #imag=, #imag_with_decompose, indgen, #inject, #inspect, #integral, #lut, #lut_with_rgb, #malloc, #mask, match, #matched?, #max, maxint, #mean, #memorise, #min, #normalise, #prod, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, rgb?, #roll, scalar, shape, #shift, #simplify, #size, #sobel, #stretch, strip, subst, #sum, #swap_rgb_with_scalar, #table, #to_a, #to_s, to_s, #to_type, to_type, #to_type_with_identity, #to_type_with_rgb, #transpose, typecode, typecodes, #unmask, #unroll, variables, #warp, #width
Methods included from Field_::Match
Methods included from FLOAT_::Match
Methods included from OBJECT::Match
Methods included from COMPLEX_::Match
Methods included from BOOL::Match
Methods included from RGB_::Match
Methods included from INT_::Match
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
#decompose(i) ⇒ Node
Decompose composite elements
This method decomposes composite elements into array.
179 180 181 182 183 184 185 |
# File 'lib/multiarray/lookup.rb', line 179 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
71 72 73 74 |
# File 'lib/multiarray/lookup.rb', line 71 def descriptor( hash ) "Lookup(#{@p.descriptor( hash )},#{@index.descriptor( hash )}," + "#{@stride.descriptor( hash )})" end |
#element(i) ⇒ Node, Object
Get element if lookup term
158 159 160 |
# File 'lib/multiarray/lookup.rb', line 158 def element(i) Lookup.new @p.element(i), @index, @stride end |
#lookup(value, stride) ⇒ Object
Lookup element of an array
127 128 129 130 131 132 133 |
# File 'lib/multiarray/lookup.rb', line 127 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 ⇒ Malloc, ...
Get storage object if there is any
35 36 37 |
# File 'lib/multiarray/lookup.rb', line 35 def memory @p.memory end |
#shape ⇒ Array<Integer>
Get shape of this term
42 43 44 |
# File 'lib/multiarray/lookup.rb', line 42 def shape @p.shape end |
#skip(index, start) ⇒ Node
Skip elements of an array
143 144 145 146 147 148 149 |
# File 'lib/multiarray/lookup.rb', line 143 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
170 171 172 |
# File 'lib/multiarray/lookup.rb', line 170 def slice( start, length ) Lookup.new @p.slice( start, length ), @index, @stride end |
#stride(index) ⇒ Integer, NilClass
Get stride for specific index
60 61 62 |
# File 'lib/multiarray/lookup.rb', line 60 def stride( index ) @index == index ? @stride.get : @p.stride( index ) end |
#strides ⇒ Array<Integer>, NilClass
Get strides of array
51 52 53 |
# File 'lib/multiarray/lookup.rb', line 51 def strides @p.strides 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.
114 115 116 117 118 119 |
# File 'lib/multiarray/lookup.rb', line 114 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.
92 93 94 |
# File 'lib/multiarray/lookup.rb', line 92 def subst( hash ) @p.subst( hash ).lookup @index.subst( hash ), @stride.subst( hash ) end |
#typecode ⇒ Class
Element-type of this term
79 80 81 |
# File 'lib/multiarray/lookup.rb', line 79 def typecode @p.typecode end |
#variables ⇒ Set
Get variables contained in this object
101 102 103 |
# File 'lib/multiarray/lookup.rb', line 101 def variables @p.variables + @index.variables + @stride.variables end |