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
-
#assign(value) ⇒ Object
Store a value in this native element.
-
#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.
-
#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
#+@, #<=>, ===, #[], #[]=, #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
Methods included from FLOAT_::Match
Methods included from OBJECT::Match
Methods included from COMPLEX_::Match
Methods included from BOOL::Match
Methods included from RGB_::Match
Methods included from INT_::Match
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
#assign(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 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
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.assign 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 |
#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 |