Class: Hornetseye::Element

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

Overview

Base class for representing native elements

Direct Known Subclasses

BOOL, Composite, FLOAT_, INDEX_, INT_, OBJECT

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, #demand, descriptor, #diagonal, #dilate, dimension, #dimension, #downsample, #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, #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, shape, #shift, #simplify, #size, #sobel, #stretch, #stride, #strides, strip, #subst, 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, typecode, typecodes, #unmask, #unroll, #variables, 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 = self.class.default) ⇒ Element

Constructor initialising element with a value

Parameters:

  • value (Object) (defaults to: self.class.default)

    Initial value for element.



67
68
69
70
71
72
73
# File 'lib/multiarray/element.rb', line 67

def initialize( value = self.class.default )
  if Thread.current[ :function ].nil?
    @value = value
  else
    @value = GCCValue.new Thread.current[ :function ], value.to_s
  end
end

Class Method Details

.coercion(other) ⇒ Class

Type coercion for native elements

Parameters:

  • other (Class)

    Other native datatype to coerce with.

Returns:

  • (Class)

    Result of coercion.



53
54
55
56
57
58
59
60
# File 'lib/multiarray/element.rb', line 53

def coercion( other )
  if self == other
    self
  else
    x, y = other.coerce self
    x.coercion y
  end
end

.construct(*args) ⇒ Element

Construct new object from arguments

Parameters:

Returns:

  • (Element)

    New object of this type.



42
43
44
# File 'lib/multiarray/element.rb', line 42

def construct(*args)
  new *args
end

.fetch(ptr) ⇒ Object

Retrieve element from memory

Parameters:

  • ptr (Malloc, List)

    Memory to load element from.

See Also:



31
32
33
# File 'lib/multiarray/element.rb', line 31

def fetch( ptr )
  construct *ptr.load(self)
end

Instance Method Details

#assign(value) ⇒ Object

Store a value in this native element

Parameters:

  • value (Object)

    New value for native element.

Returns:



158
159
160
161
162
163
164
165
# File 'lib/multiarray/element.rb', line 158

def assign( value )
  if @value.respond_to? :assign
    @value.assign value.simplify.get
  else
    @value = value.simplify.get
  end
  value
end

#compilable?Boolean

Check whether this term is compilable

Returns:

  • (Boolean)

    Returns whether this term is compilable.



122
123
124
125
126
127
128
# File 'lib/multiarray/element.rb', line 122

def compilable?
  if @value.respond_to? :compilable?
    @value.compilable?
  else
    super
  end
end

#descriptor(hash) ⇒ String

Get unique descriptor of this object

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    Descriptor of this object,



82
83
84
# File 'lib/multiarray/element.rb', line 82

def descriptor( hash )
  "#{self.class.to_s}(#{@value.to_s})"
end

#dupNode, Object

Reevaluate computation

Returns:

See Also:



93
94
95
96
97
98
99
100
101
# File 'lib/multiarray/element.rb', line 93

def dup
  if Thread.current[ :function ]
    value = Thread.current[ :function ].variable self.class, 'v'
    value.assign get
    self.class.new value
  else
    self.class.new get
  end
end

#getObject

Get value of this native element

Returns:

  • (Object)

    Value of this native element.



147
148
149
# File 'lib/multiarray/element.rb', line 147

def get
  @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)

    Returns self.



138
139
140
# File 'lib/multiarray/element.rb', line 138

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



112
113
114
115
# File 'lib/multiarray/element.rb', line 112

def strip
  variable = Variable.new self.class
  return [ variable ], [ self ], variable
end

#valuesArray<Object>

Get array with components of this value

Returns:

  • (Array<Object>)

    Get array with value of this object as single element.



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

def values
  [ @value ]
end

#write(ptr) ⇒ Object

Write element to memory

Parameters:

  • ptr (Malloc, List)

    Memory to write element to.

See Also:



175
176
177
# File 'lib/multiarray/element.rb', line 175

def write( ptr )
  ptr.save self
end