Class: Hornetseye::Lut
Overview
Class for representing lookup operations
Class Method Summary collapse
-
.finalised? ⇒ Boolean
Check whether objects of this class are finalised computations.
Instance Method Summary collapse
-
#compilable? ⇒ Boolean
Check whether this term is compilable.
-
#decompose(i) ⇒ Node
Decompose composite elements.
-
#demand ⇒ Node, Object
Reevaluate computation.
-
#descriptor(hash) ⇒ String
Get unique descriptor of this object.
-
#element(i) ⇒ Node, Object
Get element of unary operation.
-
#initialize(*sources, table) ⇒ Lut
constructor
Constructor.
- #shape ⇒ Object
-
#skip(index, start) ⇒ Node
Skip elements of an array.
-
#slice(start, length) ⇒ Node
Extract array view with part of array.
-
#strip ⇒ Array<Array,Node>
Strip of all values.
-
#subst(hash) ⇒ Node
Substitute variables.
- #typecode ⇒ Object
-
#variables ⇒ Set
Get variables contained in this term.
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
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(*sources, table) ⇒ Lut
Constructor
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
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
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.
181 182 183 |
# File 'lib/multiarray/lut.rb', line 181 def decompose( i ) self.class.new *( @sources + [ @table.decompose( i ) ] ) end |
#demand ⇒ Node, Object
Reevaluate computation
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
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
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 |
#shape ⇒ Object
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
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
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 |
#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.
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.
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 |
#typecode ⇒ Object
59 60 61 |
# File 'lib/multiarray/lut.rb', line 59 def typecode @table.typecode end |
#variables ⇒ Set
Get variables contained in this term
99 100 101 |
# File 'lib/multiarray/lut.rb', line 99 def variables @sources.inject(@table.variables) { |a,b| a + b.variables } end |