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, #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

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



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

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    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

Parameters:

  • i (Integer, Node)

    Index of desired element.

Returns:



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

Parameters:

  • value (Node)

    Index of element.

  • stride (Node)

    Stride for iterating over elements.



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

#memoryMalloc, ...

Get storage object if there is any

Returns:



39
40
41
# File 'lib/multiarray/lookup.rb', line 39

def memory
  @p.memory
end

#sexp?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/multiarray/lookup.rb', line 32

def sexp?
  true
end

#shapeArray<Integer>

Get shape of this term

Returns:

  • (Array<Integer>)

    Returns shape of array.



46
47
48
# File 'lib/multiarray/lookup.rb', line 46

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.



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

Parameters:

  • start (Integer, Node)

    Number of elements to skip.

  • length (Integer, Node)

    Size of array view.

Returns:

  • (Node)

    Array view with the specified elements.



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

Returns:

  • (Integer, NilClass)

    Array stride of this index.



64
65
66
# File 'lib/multiarray/lookup.rb', line 64

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

#stridesArray<Integer>, NilClass

Get strides of array

Returns:



55
56
57
# File 'lib/multiarray/lookup.rb', line 55

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:



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.

Parameters:

  • hash (Hash)

    Substitutions to apply.

Returns:

  • (Node)

    Term with substitutions applied.



96
97
98
# File 'lib/multiarray/lookup.rb', line 96

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.



83
84
85
# File 'lib/multiarray/lookup.rb', line 83

def typecode
  @p.typecode
end

#variablesSet

Get variables contained in this object

Returns:

  • (Set)

    Returns Set[ self ].



105
106
107
# File 'lib/multiarray/lookup.rb', line 105

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