Class: Hornetseye::Lut

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

Overview

Class for representing lookup operations

Class Method Summary collapse

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?, #components, cond, #conditional, #convolve, define_binary_op, define_unary_op, descriptor, #diagonal, #dilate, dimension, #dimension, #downsample, #dup, #each, #empty?, #eq_with_multiarray, #erode, #fill!, #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, #memory, #min, #normalise, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, rgb?, #roll, scalar, shape, #shift, #simplify, #size, #sobel, #stride, #strides, 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(*sources, table) ⇒ Lut

Constructor

Parameters:

  • sources (Array<Node>)

    Arrays with elements for lookup

  • table (Node)

    Lookup table



43
44
45
# File 'lib/multiarray/lut.rb', line 43

def initialize( *args )
  @sources, @table = args[ 0 ... -1 ], args.last
end

Class Method Details

.finalised?Boolean

Check whether objects of this class are finalised computations

Returns:

  • (Boolean)

    Returns false.



30
31
32
# File 'lib/multiarray/lut.rb', line 30

def finalised?
  false
end

Instance Method Details

#compilable?Boolean

Check whether this term is compilable

Returns:

  • (Boolean)

    Returns whether this term is compilable.



194
195
196
# File 'lib/multiarray/lut.rb', line 194

def compilable?
  @sources.all? { |source| source.compilable? } and @table.compilable?
end

#decompose(i) ⇒ Node

Decompose composite elements

This method decomposes composite elements into array.

Returns:

  • (Node)

    Result of decomposition.



185
186
187
# File 'lib/multiarray/lut.rb', line 185

def decompose( i )
  self.class.new *( @sources + [ @table.decompose( i ) ] )
end

#demandNode, Object

Reevaluate computation

Returns:

See Also:



80
81
82
# File 'lib/multiarray/lut.rb', line 80

def demand
  @sources.lut @table, :safe => false
end

#descriptor(hash) ⇒ String

Get unique descriptor of this object

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    Descriptor of this object,



58
59
60
61
# File 'lib/multiarray/lut.rb', line 58

def descriptor( hash )
  "Lut(#{@sources.collect { |source| source.descriptor( hash ) }.join ','}," +
    "#{@table.descriptor( hash )})"
end

#element(i) ⇒ Node, Object

Get element of unary operation

Parameters:

  • i (Integer, Node)

    Index of desired element.

Returns:



144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/multiarray/lut.rb', line 144

def element( i )
  sources, table = @sources, @table
  if sources.any? { |source| source.dimension > 0 }
    sources = sources.
      collect { |source| source.dimension > 0 ? source.element( i ) : source }
    self.class.new *( sources + [ table ] )
  elsif table.dimension > sources.size
    n = sources.size
    self.class.new *( sources + [ table.unroll( n ).element( i ).roll( n ) ] )
  else
    super i
  end
end

#sexp?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/multiarray/lut.rb', line 47

def sexp?
  true
end

#shapeObject



67
68
69
70
71
# File 'lib/multiarray/lut.rb', line 67

def shape
  source_shape = @sources.collect { |source| source.shape }.
    inject { |a,b| a.size > b.size ? a : b }
  @table.shape.first(@table.dimension - @sources.size) + source_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)

    Returns element-wise operation with elements skipped on each operand.



132
133
134
135
# File 'lib/multiarray/lut.rb', line 132

def skip( index, start )
  self.class.new *( @sources.skip( index, start ) +
                    [ @table.skip( index, start ) ] )
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.



166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/multiarray/lut.rb', line 166

def slice( start, length )
  source, table = @source, @table
  if source.dimension > 1
    source = source.slice( start, length ).roll
    self.class.new( source, table, @n ).unroll
  elsif table.dimension > @n
    self.class.new( source,
                    table.unroll( @n ).slice( start, length ).roll( @n + 1 ),
                    @n ).unroll
  else
    super i
  end
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:



116
117
118
119
120
121
# File 'lib/multiarray/lut.rb', line 116

def strip
  stripped = ( @sources + [ @table ] ).collect { |source| source.strip }
  return stripped.inject( [] ) { |vars,elem| vars + elem[ 0 ] },
       stripped.inject( [] ) { |values,elem| values + elem[ 1 ] },
       self.class.new( *stripped.collect { |elem| elem[ 2 ] } )
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.



93
94
95
96
# File 'lib/multiarray/lut.rb', line 93

def subst( hash )
  self.class.new *( @sources.collect { |source| source.subst hash } +
                    [ @table.subst( hash ) ] )
end

#typecodeObject



63
64
65
# File 'lib/multiarray/lut.rb', line 63

def typecode
  @table.typecode
end

#variablesSet

Get variables contained in this term

Returns:

  • (Set)

    Returns list of variables.



103
104
105
# File 'lib/multiarray/lut.rb', line 103

def variables
  @sources.inject( @table.variables ) { |a,b| a + b.variables }
end