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, #mean, #memorise, #memory, #min, #normalise, #prod, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, rgb?, #roll, scalar, shape, #shift, #simplify, #size, #sobel, #stretch, #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.



190
191
192
# File 'lib/multiarray/lut.rb', line 190

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.



181
182
183
# File 'lib/multiarray/lut.rb', line 181

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

#demandNode, Object

Reevaluate computation

Returns:

See Also:



76
77
78
# File 'lib/multiarray/lut.rb', line 76

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,



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

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:



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/multiarray/lut.rb', line 140

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

#shapeObject



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

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.



128
129
130
131
# File 'lib/multiarray/lut.rb', line 128

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.



162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/multiarray/lut.rb', line 162

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:



112
113
114
115
116
117
# File 'lib/multiarray/lut.rb', line 112

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.



89
90
91
92
# File 'lib/multiarray/lut.rb', line 89

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

#typecodeObject



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

def typecode
  @table.typecode
end

#variablesSet

Get variables contained in this term

Returns:

  • (Set)

    Returns list of variables.



99
100
101
# File 'lib/multiarray/lut.rb', line 99

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