Class: Hornetseye::Lookup

Inherits:
Node show all
Defined in:
lib/multiarray/lookup.rb

Overview

Class for lazy array lookup

Instance Method Summary collapse

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

#align, #fit

Methods included from FLOAT_::Match

#align, #fit

Methods included from OBJECT::Match

#align, #fit

Methods included from COMPLEX_::Match

#align, #fit

Methods included from BOOL::Match

#fit

Methods included from RGB_::Match

#align, #fit

Methods included from INT_::Match

#fit

Constructor Details

#initialize(p, index, stride) ⇒ Lookup

Create array lookup

Parameters:

  • p (Node)

    Object supporting lookup.

  • index (Variable)

    The array index.

  • stride (Node)

    The array stride.



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.

Returns:

  • (Node)

    Result of decomposition.



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

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    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

Parameters:

Returns:



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

Parameters:

  • value (Node)

    Index of element.

  • stride (Node)

    Stride for iterating over elements.



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

#memoryMalloc, ...

Get storage object if there is any

Returns:



35
36
37
# File 'lib/multiarray/lookup.rb', line 35

def memory
  @p.memory
end

#shapeArray<Integer>

Get shape of this term

Returns:



42
43
44
# File 'lib/multiarray/lookup.rb', line 42

def shape
  @p.shape
end

#skip(index, start) ⇒ Node

Skip elements of an array

Parameters:

  • index (Variable)

    Variable identifying index of array.

  • start (Node)

    Wrapped integer with number of elements to skip.

Returns:

  • (Node)

    Lookup object with elements skipped.



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

Parameters:

Returns:

  • (Node)

    Array view with the specified elements.



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

Returns:



60
61
62
# File 'lib/multiarray/lookup.rb', line 60

def stride( index )
  @index == index ? @stride.get : @p.stride( index )
end

#stridesArray<Integer>, NilClass

Get strides of array

Returns:



51
52
53
# File 'lib/multiarray/lookup.rb', line 51

def strides
  @p.strides
end

#stripArray<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.

Returns:



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.

Parameters:

  • hash (Hash)

    Substitutions to apply.

Returns:

  • (Node)

    Term with substitutions applied.



92
93
94
# File 'lib/multiarray/lookup.rb', line 92

def subst( hash )
  @p.subst( hash ).lookup @index.subst( hash ), @stride.subst( hash )
end

#typecodeClass

Element-type of this term

Returns:

  • (Class)

    Element-type of this datatype.



79
80
81
# File 'lib/multiarray/lookup.rb', line 79

def typecode
  @p.typecode
end

#variablesSet

Get variables contained in this object

Returns:

  • (Set)

    Returns Set[ self ].



101
102
103
# File 'lib/multiarray/lookup.rb', line 101

def variables
  @p.variables + @index.variables + @stride.variables
end