Class: Hornetseye::Inject
Overview
Class for representing injections
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.
-
#demand ⇒ Node, Object
Reevaluate computation.
-
#descriptor(hash) ⇒ String
Get unique descriptor of this object.
-
#element(i) ⇒ Node, Object
Get element of injection.
-
#initialize(value, index, initial, block, var1, var2) ⇒ Inject
constructor
Constructor.
- #shape ⇒ Object
-
#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, #decompose, 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 Hornetseye::INT_::Match
Constructor Details
#initialize(value, index, initial, block, var1, var2) ⇒ Inject
Constructor
48 49 50 51 |
# File 'lib/multiarray/inject.rb', line 48 def initialize( value, index, initial, block, var1, var2 ) @value, @index, @initial, @block, @var1, @var2 = value, index, initial, block, var1, var2 end |
Class Method Details
.finalised? ⇒ Boolean
Check whether objects of this class are finalised computations
30 31 32 |
# File 'lib/multiarray/inject.rb', line 30 def finalised? false end |
Instance Method Details
#compilable? ⇒ Boolean
Check whether this term is compilable
165 166 167 168 |
# File 'lib/multiarray/inject.rb', line 165 def compilable? initial_compilable = @initial ? @initial.compilable? : true @value.compilable? and initial_compilable and @block.compilable? end |
#demand ⇒ Node, Object
Reevaluate computation
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/multiarray/inject.rb', line 84 def demand if @initial retval = @initial.to_type( typecode ).simplify # !!! offset = INT.new 0 else retval = @value.subst( @index => INT.new( 0 ) ).simplify # !!! offset = INT.new 1 end offset.upto @index.size - 1 do |i| sub = @value.subst @index => INT.new( i ) retval.assign @block.subst(@var1 => retval, @var2 => sub) end retval end |
#descriptor(hash) ⇒ String
Get unique descriptor of this object
60 61 62 63 64 65 66 67 |
# File 'lib/multiarray/inject.rb', line 60 def descriptor( hash ) hash = hash.merge @index => ( ( hash.values.max || 0 ) + 1 ) hash = hash.merge @var1 => ( ( hash.values.max || 0 ) + 1 ) hash = hash.merge @var2 => ( ( hash.values.max || 0 ) + 1 ) "Inject(#{@value.descriptor( hash )}," + "#{@initial ? @initial.descriptor( hash ) : 'nil'}," + "#{@index.descriptor( hash )},#{@block.descriptor( hash )})" end |
#element(i) ⇒ Node, Object
Get element of injection
106 107 108 |
# File 'lib/multiarray/inject.rb', line 106 def element( i ) self.class.new @value.element( i ), @index, @initial, @block, @var1, @var2 end |
#shape ⇒ Object
73 74 75 |
# File 'lib/multiarray/inject.rb', line 73 def shape @value.to_type(@block.typecode).shape 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.
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/multiarray/inject.rb', line 129 def strip , , var = @index.strip vars1, values1, term1 = @value.subst( @index => var ).strip if @initial vars2, values2, term2 = @initial.strip else vars2, values2 = [], [], nil end vars3, values3, term3 = @block.strip return vars1 + vars2 + vars3 + , values1 + values2 + values3 + , self.class.new( term1, var, term2, term3, @var1, @var2 ) end |
#subst(hash) ⇒ Node
Substitute variables
Substitute the variables with the values given in the hash.
152 153 154 155 156 157 158 |
# File 'lib/multiarray/inject.rb', line 152 def subst( hash ) subst_var = @index.subst hash value = @value.subst( @index => subst_var ).subst hash initial = @initial ? @initial.subst( hash ) : nil block = @block.subst hash self.class.new value, subst_var, initial, block, @var1, @var2 end |
#typecode ⇒ Object
69 70 71 |
# File 'lib/multiarray/inject.rb', line 69 def typecode @block.typecode end |
#variables ⇒ Set
Get variables contained in this term
115 116 117 118 |
# File 'lib/multiarray/inject.rb', line 115 def variables initial_variables = @initial ? @initial.variables : Set[] ( @value.variables + initial_variables ) - @index.variables end |