Class: Hornetseye::ElementWise_

Inherits:
Node show all
Defined in:
lib/multiarray/elementwise.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#align, #fit

Methods included from OBJECT::Match

#align, #fit

Methods included from COMPLEX_::Match

#align, #fit

Methods included from Sequence_::Match

#align, #fit

Methods included from BOOL::Match

#fit

Methods included from RGB_::Match

#align, #fit

Methods included from INT_::Match

#fit

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

Parameters:

  • value (Node)

    Value to apply operation to.



71
72
73
74
# File 'lib/multiarray/elementwise.rb', line 71

def initialize( *values )
  @values = values
  check_shape *values
end

Class Attribute Details

.conversionProc

Name of method for type conversion

Returns:

  • (Proc)

    A closure for doing the type conversion.



37
38
39
# File 'lib/multiarray/elementwise.rb', line 37

def conversion
  @conversion
end

.keySymbol, String

Unique key to identify operation.

Returns:

  • (Symbol, String)

    A unique key to identify this operation.



32
33
34
# File 'lib/multiarray/elementwise.rb', line 32

def key
  @key
end

.operationProc

Name of operation

Returns:

  • (Proc)

    A closure with the 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

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    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

Returns:

  • (Boolean)

    Returns false.



62
63
64
# File 'lib/multiarray/elementwise.rb', line 62

def finalised?
  false
end

.inspectString

Get string with information about this class

Returns:

  • (String)

    Return 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_typeClass

Get type of result of delayed operation

Returns:

  • (Class)

    Type of result.



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

Returns:

  • (Boolean)

    Returns 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

#decomposeNode

Decompose composite elements

This method decomposes composite elements into array.

Returns:

  • (Node)

    Result of decomposition.



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

#demandNode, Object

Reevaluate computation

Returns:

See Also:



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

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    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

Parameters:

  • i (Integer, Node)

    Index of desired element.

Returns:



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

Parameters:

  • index (Variable)

    Variable identifying index of array.

  • start (Node)

    Wrapped integer with number of elements to skip.

Returns:

  • (Node)

    Returns element-wise operation with elements skipped on each operand.



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

Parameters:

  • start (Integer, Node)

    Number of elements to skip.

  • length (Integer, Node)

    Size of array view.

Returns:

  • (Node)

    Array view with the specified elements.



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

#stripArray<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.

Returns:



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.

Parameters:

  • hash (Hash)

    Substitutions to apply.

Returns:

  • (Node)

    Term with substitutions applied.



118
119
120
# File 'lib/multiarray/elementwise.rb', line 118

def subst( hash )
  self.class.new *@values.collect { |value| value.subst( hash ) }
end

#variablesSet

Get variables contained in this term

Returns:

  • (Set)

    Returns set of variables.



127
128
129
# File 'lib/multiarray/elementwise.rb', line 127

def variables
  @values.inject( Set[] ) { |vars,value| vars + value.variables }
end