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

===, #[], #[]=, #array_type, array_type, basetype, #basetype, bool, byte, #check_shape, #coerce, coercion_bool, coercion_byte, coercion_maxint, compilable?, cond, contiguous, #decompose, #demand, descriptor, dimension, #dimension, empty?, #empty?, finalised?, #finalised?, float, float_scalar, floating, #force, #height, height, indgen, #inspect, match, maxint, #memory, pointer_type, #pointer_type, rgb?, #rgb?, scalar, #shape, shape, #simplify, size, #size, #storage_size, strip, subst, #subst, #to_a, to_s, #to_s, to_type, #typecode, typecode, typecodes, variables, #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(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

#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.store 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

#store(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 store( value )
  if @value.respond_to? :store
    @value.store value.simplify.get
  else
    @value = value.simplify.get
  end
  value
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