Class: Hornetseye::Diagonal

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

Overview

Class for representing diagonal injections

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, #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

#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(value, index0, index1, index2, initial, block, var1, var2) ⇒ Diagonal

Constructor

Parameters:

  • value (Node)

    Initial value of injection.

  • index0 (Node)

    Index to select starting point of injection.

  • index1 (Node)

    Index to diagonally iterate over value.

  • index2 (Node)

    Index to diagonally iterate over value.

  • initial (Node, NilClass)

    Initial value for injection.

  • block (Node)

    Expression with body of injection.

  • var1 (Variable)

    Variable for performing substitutions on body of injection.

  • var2 (Variable)

    Variable for performing substitutions on body of injection.



50
51
52
53
54
# File 'lib/multiarray/diagonal.rb', line 50

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

Returns:

  • (Boolean)

    Returns false.



30
31
32
# File 'lib/multiarray/diagonal.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.



183
184
185
186
# File 'lib/multiarray/diagonal.rb', line 183

def compilable?
  initial_compilable = @initial ? @initial.compilable? : true
  @value.compilable? and initial_compilable and @block.compilable?
end

#demandNode, Object

Reevaluate computation

Returns:

See Also:



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/multiarray/diagonal.rb', line 89

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.assign @block.subst( @var1 => retval, @var2 => sub )
  end
  retval
end

#descriptor(hash) ⇒ String

Get unique descriptor of this object

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    Descriptor of this object,



63
64
65
66
67
68
69
70
71
72
# File 'lib/multiarray/diagonal.rb', line 63

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

Parameters:

  • i (Integer, Node)

    Index of desired element.

Returns:

  • (Node, Object)

    Element of diagonal injection.



116
117
118
119
# File 'lib/multiarray/diagonal.rb', line 116

def element( i )
  Diagonal.new @value.element( i ), @index0, @index1, @index2, @initial,
    @block, @var1, @var2
end

#shapeObject



78
79
80
# File 'lib/multiarray/diagonal.rb', line 78

def shape
  @value.shape
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:



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/multiarray/diagonal.rb', line 141

def strip
  meta_vars1, meta_values1, var1 = @index1.strip
  meta_vars2, meta_values2, 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 + meta_vars1 + meta_vars2 + vars2 + vars3,
    values1 + meta_values1 + meta_values2 + 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.

Parameters:

  • hash (Hash)

    Substitutions to apply.

Returns:

  • (Node)

    Term with substitutions applied.



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

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

#typecodeObject



74
75
76
# File 'lib/multiarray/diagonal.rb', line 74

def typecode
  @block.typecode
end

#variablesSet

Get variables contained in this term

Returns:

  • (Set)

    Returns list of variables.



126
127
128
129
130
# File 'lib/multiarray/diagonal.rb', line 126

def variables
  initial_variables = @initial ? @initial.variables : Set[]
  @value.variables + initial_variables + @index0.variables - 
    ( @index1.variables + @index2.variables )
end