Class: Hornetseye::ElementWise_
- Defined in:
- lib/multiarray/elementwise.rb
Overview
Class for representing element-wise operations
Class Attribute Summary collapse
-
.conversion ⇒ Proc
Name of method for type conversion.
-
.key ⇒ Symbol, String
Unique key to identify operation.
-
.operation ⇒ Proc
Name of operation.
Class Method Summary collapse
-
.descriptor(hash) ⇒ String
Get unique descriptor of this class.
-
.finalised? ⇒ Boolean
Check whether objects of this class are finalised computations.
-
.inspect ⇒ String
Get string with information about this class.
Instance Method Summary collapse
-
#compilable? ⇒ Boolean
Check whether this term is compilable.
-
#decompose(i) ⇒ Node
Decompose composite elements.
-
#demand ⇒ Node, Object
Reevaluate computation.
-
#descriptor(hash) ⇒ String
Get unique descriptor of this object.
-
#element(i) ⇒ Node, Object
Get element of unary operation.
-
#initialize(*values) ⇒ ElementWise_
constructor
Initialise unary operation.
- #shape ⇒ Object
-
#skip(index, start) ⇒ Node
Skip elements of an array.
-
#slice(start, length) ⇒ Node
Extract array view with part of array.
-
#strip ⇒ Array<Array,Node>
Strip of all values.
-
#subst(hash) ⇒ Node
Substitute variables.
- #typecode ⇒ Object
-
#variables ⇒ Set
Get variables contained in this term.
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, define_binary_op, define_unary_op, #diagonal, #dilate, #dimension, dimension, #downsample, #dup, #each, #empty?, #eq_with_multiarray, #erode, #fill!, #finalised?, #flip, float, float_scalar, floating, #fmod_with_float, #force, #g=, #g_with_decompose, #gauss_blur, #gauss_gradient, #get, #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, #shift, #simplify, #size, #sobel, #stretch, #stride, #strides, strip, 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, typecodes, #unmask, #unroll, 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(*values) ⇒ ElementWise_
Initialise unary operation
72 73 74 75 |
# File 'lib/multiarray/elementwise.rb', line 72 def initialize( *values ) @values = values check_shape *values end |
Class Attribute Details
.conversion ⇒ Proc
Name of method for type conversion
38 39 40 |
# File 'lib/multiarray/elementwise.rb', line 38 def conversion @conversion end |
.key ⇒ Symbol, String
Unique key to identify operation
33 34 35 |
# File 'lib/multiarray/elementwise.rb', line 33 def key @key end |
.operation ⇒ Proc
Name of operation
28 29 30 |
# File 'lib/multiarray/elementwise.rb', line 28 def operation @operation end |
Class Method Details
.descriptor(hash) ⇒ String
Get unique descriptor of this class
54 55 56 |
# File 'lib/multiarray/elementwise.rb', line 54 def descriptor( hash ) inspect end |
.finalised? ⇒ Boolean
Check whether objects of this class are finalised computations
63 64 65 |
# File 'lib/multiarray/elementwise.rb', line 63 def finalised? false end |
.inspect ⇒ String
Get string with information about this class
43 44 45 |
# File 'lib/multiarray/elementwise.rb', line 43 def inspect key.to_s end |
Instance Method Details
#compilable? ⇒ Boolean
Check whether this term is compilable
206 207 208 |
# File 'lib/multiarray/elementwise.rb', line 206 def compilable? typecode.compilable? and @values.all? { |value| value.compilable? } end |
#decompose(i) ⇒ Node
Decompose composite elements
This method decomposes composite elements into array.
196 197 198 199 |
# File 'lib/multiarray/elementwise.rb', line 196 def decompose( i ) values = @values.collect { |value| value.decompose i } self.class.new( *values ).demand end |
#demand ⇒ Node, Object
Reevaluate computation
106 107 108 |
# File 'lib/multiarray/elementwise.rb', line 106 def demand self.class.operation.call *@values end |
#descriptor(hash) ⇒ String
Get unique descriptor of this object
84 85 86 87 |
# File 'lib/multiarray/elementwise.rb', line 84 def descriptor( hash ) "#{self.class.descriptor( hash )}" + "(#{@values.collect { |value| value.descriptor( hash ) }.join ','})" end |
#element(i) ⇒ Node, Object
Get element of unary operation
169 170 171 172 173 174 |
# File 'lib/multiarray/elementwise.rb', line 169 def element( i ) values = @values.collect do |value| value.dimension == 0 ? value : value.element( i ) end self.class.new( *values ).demand end |
#shape ⇒ Object
94 95 96 97 |
# File 'lib/multiarray/elementwise.rb', line 94 def shape shapes = @values.collect { |value| value.shape } shapes.inject { |a,b| a.size > b.size ? a : b } end |
#skip(index, start) ⇒ Node
Skip elements of an array
157 158 159 160 |
# File 'lib/multiarray/elementwise.rb', line 157 def skip( index, start ) skipped = *@values.collect { |value| value.skip( index, start ) } self.class.new( *skipped ).demand end |
#slice(start, length) ⇒ Node
Extract array view with part of array
184 185 186 187 188 189 |
# File 'lib/multiarray/elementwise.rb', line 184 def slice( start, length ) values = @values.collect do |value| value.dimension == 0 ? value : value.slice( start, length ) end self.class.new( *values ).demand 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.
141 142 143 144 145 146 |
# File 'lib/multiarray/elementwise.rb', line 141 def strip stripped = @values.collect { |value| value.strip } return stripped.inject([]) { |vars,elem| vars + elem[0] }, stripped.inject([]) { |values,elem| values + elem[1] }, self.class.new(*stripped.collect { |elem| elem[2] }) end |
#subst(hash) ⇒ Node
Substitute variables
Substitute the variables with the values given in the hash.
119 120 121 |
# File 'lib/multiarray/elementwise.rb', line 119 def subst( hash ) self.class.new *@values.collect { |value| value.subst( hash ) } end |
#typecode ⇒ Object
89 90 91 92 |
# File 'lib/multiarray/elementwise.rb', line 89 def typecode typecodes = @values.collect { |value| value.typecode } self.class.conversion.call *typecodes end |
#variables ⇒ Set
Get variables contained in this term
128 129 130 |
# File 'lib/multiarray/elementwise.rb', line 128 def variables @values.inject(Set[]) { |vars,value| vars + value.variables } end |