Class: Hornetseye::ElementWise_
- Defined in:
- lib/multiarray/elementwise.rb
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
-
#array_type ⇒ Class
Get type of result of delayed operation.
-
#compilable? ⇒ Boolean
Check whether this term is compilable.
-
#decompose ⇒ 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.
-
#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.
-
#variables ⇒ Set
Get variables contained in this term.
Methods inherited from Node
===, #[], #[]=, array_type, basetype, #basetype, bool, byte, #check_shape, #coerce, coercion_bool, coercion_byte, coercion_maxint, compilable?, cond, contiguous, dimension, #dimension, #dup, empty?, #empty?, #finalised?, float, float_scalar, floating, #force, #get, #height, height, indgen, #inspect, match, maxint, #memory, pointer_type, #pointer_type, rgb?, #rgb?, scalar, #shape, shape, #simplify, #size, size, #storage_size, strip, subst, #to_a, to_s, #to_s, to_type, #typecode, typecode, typecodes, 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, #histogram_with_composite, #imag=, #imag_with_decompose, #inject, #integral, #lut, #lut_with_composite, #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(*values) ⇒ ElementWise_
Initialise unary operation
71 72 73 74 |
# File 'lib/multiarray/elementwise.rb', line 71 def initialize( *values ) @values = values check_shape *values end |
Class Attribute Details
.conversion ⇒ Proc
Name of method for type conversion
37 38 39 |
# File 'lib/multiarray/elementwise.rb', line 37 def conversion @conversion end |
.key ⇒ Symbol, String
Unique key to identify operation.
32 33 34 |
# File 'lib/multiarray/elementwise.rb', line 32 def key @key end |
.operation ⇒ Proc
Name of operation
27 28 29 |
# File 'lib/multiarray/elementwise.rb', line 27 def operation @operation end |
Class Method Details
.descriptor(hash) ⇒ String
Get unique descriptor of this class
53 54 55 |
# File 'lib/multiarray/elementwise.rb', line 53 def descriptor( hash ) inspect end |
.finalised? ⇒ Boolean
Check whether objects of this class are finalised computations
62 63 64 |
# File 'lib/multiarray/elementwise.rb', line 62 def finalised? false end |
.inspect ⇒ String
Get string with information about this class
42 43 44 |
# File 'lib/multiarray/elementwise.rb', line 42 def inspect key.to_s end |
Instance Method Details
#array_type ⇒ Class
Get type of result of delayed operation
93 94 95 96 |
# File 'lib/multiarray/elementwise.rb', line 93 def array_type array_types = @values.collect { |value| value.array_type } self.class.conversion.call *array_types end |
#compilable? ⇒ Boolean
Check whether this term is compilable
205 206 207 |
# File 'lib/multiarray/elementwise.rb', line 205 def compilable? array_type.compilable? and @values.all? { |value| value.compilable? } end |
#decompose ⇒ Node
Decompose composite elements
This method decomposes composite elements into array.
195 196 197 198 |
# File 'lib/multiarray/elementwise.rb', line 195 def decompose values = @values.collect { |value| value.decompose } self.class.new( *values ).demand end |
#demand ⇒ Node, Object
Reevaluate computation
105 106 107 |
# File 'lib/multiarray/elementwise.rb', line 105 def demand self.class.operation.call *@values end |
#descriptor(hash) ⇒ String
Get unique descriptor of this object
83 84 85 86 |
# File 'lib/multiarray/elementwise.rb', line 83 def descriptor( hash ) "#{self.class.descriptor( hash )}" + "(#{@values.collect { |value| value.descriptor( hash ) }.join ','})" end |
#element(i) ⇒ Node, Object
Get element of unary operation
168 169 170 171 172 173 |
# File 'lib/multiarray/elementwise.rb', line 168 def element( i ) values = @values.collect do |value| value.dimension == 0 ? value : value.element( i ) end self.class.new( *values ).demand end |
#skip(index, start) ⇒ Node
Skip elements of an array
156 157 158 159 |
# File 'lib/multiarray/elementwise.rb', line 156 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
183 184 185 186 187 188 |
# File 'lib/multiarray/elementwise.rb', line 183 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.
140 141 142 143 144 145 |
# File 'lib/multiarray/elementwise.rb', line 140 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.
118 119 120 |
# File 'lib/multiarray/elementwise.rb', line 118 def subst( hash ) self.class.new *@values.collect { |value| value.subst( hash ) } end |
#variables ⇒ Set
Get variables contained in this term
127 128 129 |
# File 'lib/multiarray/elementwise.rb', line 127 def variables @values.inject( Set[] ) { |vars,value| vars + value.variables } end |