Class: Hornetseye::Variable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

===, #[], #[]=, array_type, basetype, #basetype, bool, byte, #check_shape, #coerce, coercion_bool, coercion_byte, coercion_maxint, compilable?, #compilable?, cond, contiguous, #decompose, #demand, descriptor, dimension, #dimension, #dup, empty?, #empty?, #finalised?, finalised?, float, float_scalar, floating, #force, #get, height, #height, indgen, match, maxint, #memory, pointer_type, #pointer_type, #rgb?, rgb?, scalar, #shape, shape, #simplify, size, #storage_size, strip, subst, #to_a, #to_s, to_s, to_type, #typecode, typecode, typecodes, variables, #width, width

Methods included from FLOAT_::Match

#align, #fit

Methods included from OBJECT::Match

#align, #fit

Methods included from COMPLEX_::Match

#align, #fit

Methods included from Sequence_::Match

#align, #fit

Methods included from BOOL::Match

#fit

Methods included from RGB_::Match

#align, #fit

Methods included from INT_::Match

#fit

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, #imag=, #imag_with_decompose, #inject, #integral, #lut, #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(meta) ⇒ Variable

Returns a new instance of Variable.



27
28
29
# File 'lib/multiarray/variable.rb', line 27

def initialize( meta )
  @meta = meta
end

Instance Attribute Details

#metaClass (readonly)

Type information about this variable

Returns:

  • (Class)

    Returns type information about this variable.



25
26
27
# File 'lib/multiarray/variable.rb', line 25

def meta
  @meta
end

Instance Method Details

#array_typeClass

Get type of result of delayed operation

Returns:

  • (Class)

    Type of result.



75
76
77
# File 'lib/multiarray/variable.rb', line 75

def array_type
  @meta.array_type
end

#descriptor(hash) ⇒ String

Get unique descriptor of this object

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    Descriptor of this object,



46
47
48
49
50
51
52
# File 'lib/multiarray/variable.rb', line 46

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)’).



35
36
37
# File 'lib/multiarray/variable.rb', line 35

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.



131
132
133
# File 'lib/multiarray/variable.rb', line 131

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

#sizeNode

Get array size for index variable

Returns:

  • (Node)

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



57
58
59
# File 'lib/multiarray/variable.rb', line 57

def size
  @meta.size
end

#size=(value) ⇒ Object

Set array size for index variable

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

Parameters:

  • value (Node)

    The new size.



66
67
68
# File 'lib/multiarray/variable.rb', line 66

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.



143
144
145
146
147
148
149
# File 'lib/multiarray/variable.rb', line 143

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:



88
89
90
91
92
93
94
95
# File 'lib/multiarray/variable.rb', line 88

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.



106
107
108
109
110
111
112
113
114
# File 'lib/multiarray/variable.rb', line 106

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

#variablesSet

Get variables contained in this object

Returns:

  • (Set)

    Returns Set[ self ].



121
122
123
# File 'lib/multiarray/variable.rb', line 121

def variables
  Set[ self ]
end