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.
- #sexp? ⇒ Boolean
-
#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, #memorise, #min, #normalise, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, rgb?, #roll, scalar, shape, #shift, #simplify, #size, #sobel, 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.
183 184 185 186 187 188 189 |
# File 'lib/multiarray/lookup.rb', line 183 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
75 76 77 78 |
# File 'lib/multiarray/lookup.rb', line 75 def descriptor( hash ) "Lookup(#{@p.descriptor( hash )},#{@index.descriptor( hash )}," + "#{@stride.descriptor( hash )})" end |
#element(i) ⇒ Node, Object
Get element if lookup term
162 163 164 |
# File 'lib/multiarray/lookup.rb', line 162 def element(i) Lookup.new @p.element(i), @index, @stride end |
#lookup(value, stride) ⇒ Object
Lookup element of an array
131 132 133 134 135 136 137 |
# File 'lib/multiarray/lookup.rb', line 131 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
39 40 41 |
# File 'lib/multiarray/lookup.rb', line 39 def memory @p.memory end |
#sexp? ⇒ Boolean
32 33 34 |
# File 'lib/multiarray/lookup.rb', line 32 def sexp? true end |
#shape ⇒ Array<Integer>
Get shape of this term
46 47 48 |
# File 'lib/multiarray/lookup.rb', line 46 def shape @p.shape end |
#skip(index, start) ⇒ Node
Skip elements of an array
147 148 149 150 151 152 153 |
# File 'lib/multiarray/lookup.rb', line 147 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
174 175 176 |
# File 'lib/multiarray/lookup.rb', line 174 def slice( start, length ) Lookup.new @p.slice( start, length ), @index, @stride end |
#stride(index) ⇒ Integer, NilClass
Get stride for specific index
64 65 66 |
# File 'lib/multiarray/lookup.rb', line 64 def stride( index ) @index == index ? @stride.get : @p.stride( index ) end |
#strides ⇒ Array<Integer>, NilClass
Get strides of array
55 56 57 |
# File 'lib/multiarray/lookup.rb', line 55 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.
118 119 120 121 122 123 |
# File 'lib/multiarray/lookup.rb', line 118 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.
96 97 98 |
# File 'lib/multiarray/lookup.rb', line 96 def subst( hash ) @p.subst( hash ).lookup @index.subst( hash ), @stride.subst( hash ) end |
#typecode ⇒ Class
Element-type of this term
83 84 85 |
# File 'lib/multiarray/lookup.rb', line 83 def typecode @p.typecode end |
#variables ⇒ Set
Get variables contained in this object
105 106 107 |
# File 'lib/multiarray/lookup.rb', line 105 def variables @p.variables + @index.variables + @stride.variables end |