Class: Hornetseye::Lambda
Instance Method Summary collapse
-
#array_type ⇒ Class
Get type of result of delayed operation.
-
#compilable? ⇒ Boolean
Check whether this term is compilable.
-
#decompose(i) ⇒ Node
Decompose composite elements.
-
#descriptor(hash) ⇒ String
Get unique descriptor of this object.
-
#element(i) ⇒ Node, Object
Get element of this term.
-
#finalised? ⇒ Boolean
Check whether this object is a finalised computation.
-
#initialize(index, term) ⇒ Lambda
constructor
A new instance of Lambda.
-
#lookup(value, stride) ⇒ Lookup, Lambda
Lookup element of an array.
- #memory ⇒ 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.
-
#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, #demand, descriptor, dimension, #dimension, #dup, empty?, #empty?, finalised?, float, float_scalar, floating, #force, #get, height, #height, indgen, #inspect, match, maxint, #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, #imag=, #imag_with_decompose, #inject, #integral, #lut, #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(index, term) ⇒ Lambda
Returns a new instance of Lambda.
22 23 24 25 |
# File 'lib/multiarray/lambda.rb', line 22 def initialize( index, term ) @index = index @term = term end |
Instance Method Details
#array_type ⇒ Class
Get type of result of delayed operation
48 49 50 |
# File 'lib/multiarray/lambda.rb', line 48 def array_type Hornetseye::Sequence @term.array_type, @index.size.get end |
#compilable? ⇒ Boolean
Check whether this term is compilable
176 177 178 |
# File 'lib/multiarray/lambda.rb', line 176 def compilable? @term.compilable? end |
#decompose(i) ⇒ Node
Decompose composite elements
This method decomposes composite elements into array.
167 168 169 |
# File 'lib/multiarray/lambda.rb', line 167 def decompose( i ) Lambda.new @index, @term.decompose( i ) end |
#descriptor(hash) ⇒ String
Get unique descriptor of this object
38 39 40 41 |
# File 'lib/multiarray/lambda.rb', line 38 def descriptor( hash ) hash = hash.merge @index => ( ( hash.values.max || 0 ) + 1 ) "Lambda(#{@index.descriptor( hash )},#{@term.descriptor( hash )})" end |
#element(i) ⇒ Node, Object
Get element of this term
Pass i
as argument to this lambda object.
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/multiarray/lambda.rb', line 129 def element( i ) unless i.is_a? Node unless ( 0 ... shape.last ).member? i raise "Index must be in 0 ... #{shape.last} (was #{i})" end i = Node.match( i ).new i end i.size.store @index.size if @index.size.get and i.is_a? Variable @term.subst @index => i end |
#finalised? ⇒ Boolean
Check whether this object is a finalised computation
186 187 188 |
# File 'lib/multiarray/lambda.rb', line 186 def finalised? @term.finalised? end |
#lookup(value, stride) ⇒ Lookup, Lambda
Lookup element of an array
100 101 102 103 104 105 106 |
# File 'lib/multiarray/lambda.rb', line 100 def lookup( value, stride ) if value.is_a? Variable Lookup.new self, value, stride else Lambda.new @index, @term.lookup( value, stride ) end end |
#memory ⇒ Object
27 28 29 |
# File 'lib/multiarray/lambda.rb', line 27 def memory @term.memory end |
#skip(index, start) ⇒ Node
Skip elements of an array
116 117 118 |
# File 'lib/multiarray/lambda.rb', line 116 def skip( index, start ) Lambda.new @index, @term.skip( index, start ) end |
#slice(start, length) ⇒ Node
Extract array view with part of array
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/multiarray/lambda.rb', line 148 def slice( start, length ) unless start.is_a?( Node ) or length.is_a?( Node ) if start < 0 or start + length > shape.last raise "Range must be in 0 ... #{shape.last} " + "(was #{start} ... #{start + length})" end end start = Node.match( start ).new start unless start.is_a? Node length = Node.match( length ).new length unless length.is_a? Node index = Variable.new Hornetseye::INDEX( length ) Lambda.new( index, @term.subst( @index => index ). skip( index, start ) ).unroll 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.
70 71 72 73 74 |
# File 'lib/multiarray/lambda.rb', line 70 def strip , , var = @index.strip vars, values, term = @term.subst( @index => var ).strip return vars + , values + , Lambda.new( var, term ) end |
#subst(hash) ⇒ Node
Substitute variables
Substitute the variables with the values given in the hash.
85 86 87 88 89 90 |
# File 'lib/multiarray/lambda.rb', line 85 def subst( hash ) # subst_var = @index.subst hash # Lambda.new subst_var, @term.subst( @index => subst_var ).subst( hash ) subst_var = @index.subst hash Lambda.new subst_var, @term.subst( hash.merge( @index => subst_var ) ) end |
#variables ⇒ Set
Get variables contained in this term
57 58 59 |
# File 'lib/multiarray/lambda.rb', line 57 def variables @term.variables - @index.variables + @index..variables end |