Class: Hornetseye::Variable

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

Overview

Clas for representing variables

Instance Attribute 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?, compilable?, #components, cond, #conditional, #convolve, #decompose, define_binary_op, define_unary_op, #demand, descriptor, #diagonal, #dilate, dimension, #dimension, #downsample, #dup, #each, #empty?, #eq_with_multiarray, #erode, #fill!, finalised?, #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, #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, #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(meta) ⇒ Variable

Constructor creating a variable

Parameters:

  • meta (Class)

    The type of this variable.



37
38
39
# File 'lib/multiarray/variable.rb', line 37

def initialize( meta )
  @meta = meta
end

Instance Attribute Details

#metaClass (readonly)

Type information about this variable

Returns:

  • (Class)

    Returns type information about this variable.



30
31
32
# File 'lib/multiarray/variable.rb', line 30

def meta
  @meta
end

Instance Method Details

#descriptor(hash) ⇒ String

Get unique descriptor of this object

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    Descriptor of this object,



58
59
60
61
62
63
64
# File 'lib/multiarray/variable.rb', line 58

def descriptor( hash )
  if hash[ self ]
    "Variable#{hash[ self ]}(#{@meta.descriptor( hash )})"
  else
    "Variable(#{@meta.descriptor( hash )})"
  end
end

#inspectString

Display string with information about this object

Returns:

  • (String)

    String with information about this object (e.g. ‘Variable(INT)’).



47
48
49
# File 'lib/multiarray/variable.rb', line 47

def inspect
  "Variable(#{@meta.inspect})"
end

#lookup(value, stride) ⇒ Object

Lookup element of an array

Parameters:

  • value (Node)

    Index of element.

  • stride (Node)

    Stride for iterating over elements.



153
154
155
# File 'lib/multiarray/variable.rb', line 153

def lookup( value, stride )
  Lookup.new self, value, stride
end

#shapeObject



97
98
99
# File 'lib/multiarray/variable.rb', line 97

def shape
  @meta.shape
end

#sizeNode

Get array size for index variable

Returns:

  • (Node)

    Get the dimension of the array if this is an index variable.



71
72
73
# File 'lib/multiarray/variable.rb', line 71

def size
  @meta.size
end

#size=(value) ⇒ Node

Set array size for index variable

Set the dimension of the array assuming this is an index variable.

Parameters:

  • value (Node)

    The new size.

Returns:

  • (Node)

    Returns value.



84
85
86
# File 'lib/multiarray/variable.rb', line 84

def size=( value )
  @meta.size = value
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)

    Return variable with offset added or self.



165
166
167
168
169
170
171
# File 'lib/multiarray/variable.rb', line 165

def skip( index, start )
  if index == self
    self + start
  else
    self
  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:



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

def strip
  meta_vars, meta_values, meta_term = @meta.strip
  if meta_vars.empty?
    return [], [], self
  else
    return meta_vars, meta_values, Variable.new( meta_term )
  end
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.



128
129
130
131
132
133
134
135
136
# File 'lib/multiarray/variable.rb', line 128

def subst( hash )
  if hash[ self ]
    hash[ self ]
  elsif not @meta.variables.empty? and hash[ @meta.variables.to_a.first ]
    Variable.new @meta.subst( hash )
  else
    self
  end
end

#typecodeClass

Get type of result of delayed operation

Returns:

  • (Class)

    Type of result.



93
94
95
# File 'lib/multiarray/variable.rb', line 93

def typecode
  @meta.typecode
end

#variablesSet

Get variables contained in this object

Returns:

  • (Set)

    Returns Set[ self ].



143
144
145
# File 'lib/multiarray/variable.rb', line 143

def variables
  Set[ self ]
end