Class: Hornetseye::Element
Overview
Base class for representing native elements
Class Method Summary collapse
-
.coercion(other) ⇒ Class
Type coercion for native elements.
-
.construct(*args) ⇒ Element
Construct new object from arguments.
-
.fetch(ptr) ⇒ Object
Retrieve element from memory.
Instance Method Summary collapse
-
#compilable? ⇒ Boolean
Check whether this term is compilable.
-
#descriptor(hash) ⇒ String
Get unique descriptor of this object.
-
#dup ⇒ Node, Object
Reevaluate computation.
-
#get ⇒ Object
Get value of this native element.
-
#initialize(value = self.class.default) ⇒ Element
constructor
Constructor initialising element with a value.
-
#skip(index, start) ⇒ Node
Skip elements of an array.
-
#store(value) ⇒ Object
Store a value in this native element.
-
#strip ⇒ Array<Array,Node>
Strip of all values.
-
#values ⇒ Array<Object>
Get array with components of this value.
-
#write(ptr) ⇒ Object
Write element to memory.
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
Methods included from OBJECT::Match
Methods included from COMPLEX_::Match
Methods included from Sequence_::Match
Methods included from BOOL::Match
Methods included from RGB_::Match
Methods included from INT_::Match
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
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
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
42 43 44 |
# File 'lib/multiarray/element.rb', line 42 def construct( *args ) new *args end |
.fetch(ptr) ⇒ Object
Retrieve element from memory
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
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
82 83 84 |
# File 'lib/multiarray/element.rb', line 82 def descriptor( hash ) "#{self.class.to_s}(#{@value.to_s})" end |
#dup ⇒ Node, Object
Reevaluate computation
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 |
#get ⇒ Object
Get 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
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
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 |
#strip ⇒ Array<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.
112 113 114 115 |
# File 'lib/multiarray/element.rb', line 112 def strip variable = Variable.new self.class return [ variable ], [ self ], variable end |
#values ⇒ Array<Object>
Get array with components of this value
184 185 186 |
# File 'lib/multiarray/element.rb', line 184 def values [ @value ] end |
#write(ptr) ⇒ Object
Write element to memory
175 176 177 |
# File 'lib/multiarray/element.rb', line 175 def write( ptr ) ptr.save self end |