Class: Hornetseye::Diagonal
Overview
Class for representing diagonal injections
Class Method Summary collapse
-
.finalised? ⇒ Boolean
Check whether objects of this class are finalised computations.
Instance Method Summary collapse
-
#array_type ⇒ Class
Get type of result of delayed operation.
-
#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 diagonal injection.
-
#initialize(value, index0, index1, index2, initial, block, var1, var2) ⇒ Diagonal
constructor
Constructor.
-
#strip ⇒ Array<Array,Node>
Strip of all values.
-
#subst(hash) ⇒ Node
Substitute variables.
-
#variables ⇒ Set
Get variables contained in this term.
Methods inherited from Node
===, #[], #[]=, array_type, basetype, #basetype, bool, byte, #check_shape, #coerce, coercion_bool, coercion_byte, coercion_maxint, compilable?, cond, contiguous, #decompose, descriptor, dimension, #dimension, #dup, empty?, #empty?, #finalised?, float, float_scalar, floating, #force, #get, height, #height, indgen, #inspect, match, maxint, #memory, #pointer_type, pointer_type, rgb?, #rgb?, scalar, #shape, shape, #simplify, size, #size, #storage_size, strip, subst, #to_a, #to_s, to_s, to_type, #typecode, typecode, typecodes, variables, #width, width
Methods included from FLOAT_::Match
Methods included from OBJECT::Match
Methods included from COMPLEX_::Match
Methods included from Sequence_::Match
Methods included from BOOL::Match
Methods included from RGB_::Match
Methods included from INT_::Match
Methods included from Operations
#+@, #<=>, #b=, #b_with_decompose, #collect, #conditional, #convolve, define_binary_op, define_unary_op, #diagonal, #eq_with_multiarray, #fill!, #g=, #g_with_decompose, #histogram, #histogram_with_composite, #imag=, #imag_with_decompose, #inject, #integral, #lut, #lut_with_composite, #max, #min, #normalise, #product, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #roll, #sum, #to_type, #to_type_with_rgb, #transpose, #unroll
Constructor Details
#initialize(value, index0, index1, index2, initial, block, var1, var2) ⇒ Diagonal
Constructor
40 41 42 43 44 |
# File 'lib/multiarray/diagonal.rb', line 40 def initialize( value, index0, index1, index2, initial, block, var1, var2 ) @value, @index0, @index1, @index2, @initial, @block, @var1, @var2 = value, index0, index1, index2, 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/diagonal.rb', line 30 def finalised? false end |
Instance Method Details
#array_type ⇒ Class
Get type of result of delayed operation
69 70 71 |
# File 'lib/multiarray/diagonal.rb', line 69 def array_type Hornetseye::MultiArray @block.typecode, *@value.shape end |
#compilable? ⇒ Boolean
Check whether this term is compilable
174 175 176 177 |
# File 'lib/multiarray/diagonal.rb', line 174 def compilable? initial_compilable = @initial ? @initial.compilable? : true @value.compilable? and initial_compilable and @block.compilable? end |
#demand ⇒ Node, Object
Reevaluate computation
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/multiarray/diagonal.rb', line 80 def demand s1 = @index2.size / 2 j0 = INT.new( 0 ).major( @index0 + s1 + 1 - @index1.size ) if @initial retval = @initial.simplify else j = j0.get i = @index0.get + s1.get - j retval = @value.subst( @index1 => INT.new( i ), @index2 => INT.new( j ) ).simplify j0 = ( j0 + 1 ).simplify end j0.upto( ( @index2.size - 1 ).minor( @index0 + s1 ) ) do |j| i = @index0.get + s1.get - j sub = @value.subst @index1 => INT.new( i ), @index2 => INT.new( j ) retval.store @block.subst( @var1 => retval, @var2 => sub ) end retval end |
#descriptor(hash) ⇒ String
Get unique descriptor of this object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/multiarray/diagonal.rb', line 53 def descriptor( hash ) hash = hash.merge @index1 => ( ( hash.values.max || 0 ) + 1 ) hash = hash.merge @index2 => ( ( hash.values.max || 0 ) + 1 ) hash = hash.merge @var1 => ( ( hash.values.max || 0 ) + 1 ) hash = hash.merge @var2 => ( ( hash.values.max || 0 ) + 1 ) "Diagonal(#{@value.descriptor( hash )},#{@index0.descriptor( hash )}," + "#{@index1.descriptor( hash )},#{@index2.descriptor( hash )}," + "#{@initial ? @initial.descriptor( hash ) : 'nil'}," + "#{@block.descriptor( hash )})" end |
#element(i) ⇒ Node, Object
Get element of diagonal injection
107 108 109 110 |
# File 'lib/multiarray/diagonal.rb', line 107 def element( i ) Diagonal.new @value.element( i ), @index0, @index1, @index2, @initial, @block, @var1, @var2 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.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/multiarray/diagonal.rb', line 132 def strip , , var1 = @index1.strip , , var2 = @index2.strip vars1, values1, term1 = @value.subst( @index1 => var1, @index2 => var2 ).strip if @initial vars2, values2, term2 = @initial.strip else vars2, values2, term2 = [], [], nil end vars3, values3, term3 = @block.strip return vars1 + + + vars2 + vars3, values1 + + + values2 + values3, Diagonal.new( term1, @index0, var1, var2, term2, term3, @var1, @var2 ) end |
#subst(hash) ⇒ Node
Substitute variables
Substitute the variables with the values given in the hash.
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/multiarray/diagonal.rb', line 157 def subst( hash ) subst_var0 = @index0.subst hash subst_var1 = @index1.subst hash subst_var2 = @index2.subst hash value = @value.subst( @index0 => subst_var0, @index1 => subst_var1, @index2 => subst_var2 ).subst hash initial = @initial ? @initial.subst( hash ) : nil block = @block.subst hash Diagonal.new value, subst_var0, subst_var1, subst_var2, initial, block, @var1, @var2 end |
#variables ⇒ Set
Get variables contained in this term
117 118 119 120 121 |
# File 'lib/multiarray/diagonal.rb', line 117 def variables initial_variables = @initial ? @initial.variables : Set[] @value.variables + initial_variables + @index0.variables - ( @index1.variables + @index2.variables ) end |