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.
- #sexp? ⇒ Boolean
- #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, #memorise, #memory, #min, #normalise, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, rgb?, #roll, scalar, shape, #shift, #simplify, #size, #sobel, #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
210 211 212 |
# File 'lib/multiarray/elementwise.rb', line 210 def compilable? typecode.compilable? and @values.all? { |value| value.compilable? } end |
#decompose(i) ⇒ Node
Decompose composite elements
This method decomposes composite elements into array.
200 201 202 203 |
# File 'lib/multiarray/elementwise.rb', line 200 def decompose( i ) values = @values.collect { |value| value.decompose i } self.class.new( *values ).demand end |
#demand ⇒ Node, Object
Reevaluate computation
110 111 112 |
# File 'lib/multiarray/elementwise.rb', line 110 def demand self.class.operation.call *@values end |
#descriptor(hash) ⇒ String
Get unique descriptor of this object
88 89 90 91 |
# File 'lib/multiarray/elementwise.rb', line 88 def descriptor( hash ) "#{self.class.descriptor( hash )}" + "(#{@values.collect { |value| value.descriptor( hash ) }.join ','})" end |
#element(i) ⇒ Node, Object
Get element of unary operation
173 174 175 176 177 178 |
# File 'lib/multiarray/elementwise.rb', line 173 def element( i ) values = @values.collect do |value| value.dimension == 0 ? value : value.element( i ) end self.class.new( *values ).demand end |
#sexp? ⇒ Boolean
77 78 79 |
# File 'lib/multiarray/elementwise.rb', line 77 def sexp? true end |
#shape ⇒ Object
98 99 100 101 |
# File 'lib/multiarray/elementwise.rb', line 98 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
161 162 163 164 |
# File 'lib/multiarray/elementwise.rb', line 161 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
188 189 190 191 192 193 |
# File 'lib/multiarray/elementwise.rb', line 188 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.
145 146 147 148 149 150 |
# File 'lib/multiarray/elementwise.rb', line 145 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.
123 124 125 |
# File 'lib/multiarray/elementwise.rb', line 123 def subst( hash ) self.class.new *@values.collect { |value| value.subst( hash ) } end |
#typecode ⇒ Object
93 94 95 96 |
# File 'lib/multiarray/elementwise.rb', line 93 def typecode typecodes = @values.collect { |value| value.typecode } self.class.conversion.call *typecodes end |
#variables ⇒ Set
Get variables contained in this term
132 133 134 |
# File 'lib/multiarray/elementwise.rb', line 132 def variables @values.inject( Set[] ) { |vars,value| vars + value.variables } end |