Class: Hornetseye::Lambda
Overview
Class for representing lambda expressions
Instance Method Summary collapse
-
#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
Construct lambda term.
-
#lookup(value, stride) ⇒ Lookup, Lambda
Lookup element of an array.
-
#memory ⇒ Malloc, ...
Get storage object if there is any.
-
#shape ⇒ Array<Integer>
Get shape of this term.
-
#skip(index, start) ⇒ Node
Skip elements of an array.
-
#slice(start, length) ⇒ Node
Extract array view with part of array.
-
#stride(index) ⇒ Integer, NilClass
Get stride for specific index.
-
#strides ⇒ Array<Integer>, NilClass
Get strides of array.
-
#strip ⇒ Array<Array,Node>
Strip of all values.
-
#subst(hash) ⇒ Node
Substitute variables.
-
#typecode ⇒ Class
Element-type of this term.
-
#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, #demand, descriptor, #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, #min, #normalise, #prod, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, rgb?, #roll, scalar, shape, #shift, #simplify, #size, #sobel, #stretch, 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(index, term) ⇒ Lambda
Construct lambda term
29 30 31 32 |
# File 'lib/multiarray/lambda.rb', line 29 def initialize(index, term) @index = index @term = term end |
Instance Method Details
#compilable? ⇒ Boolean
Check whether this term is compilable
210 211 212 |
# File 'lib/multiarray/lambda.rb', line 210 def compilable? @term.compilable? end |
#decompose(i) ⇒ Node
Decompose composite elements
This method decomposes composite elements into array.
201 202 203 |
# File 'lib/multiarray/lambda.rb', line 201 def decompose( i ) Lambda.new @index, @term.decompose( i ) end |
#descriptor(hash) ⇒ String
Get unique descriptor of this object
67 68 69 70 |
# File 'lib/multiarray/lambda.rb', line 67 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.
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/multiarray/lambda.rb', line 163 def element(i) unless i.matched? unless (0 ... shape.last).member? i raise "Index must be in 0 ... #{shape.last} (was #{i})" end i = INT.new i end i.size = @index.size if i.is_a?(Variable) and @index.size.get @term.subst @index => i end |
#finalised? ⇒ Boolean
Check whether this object is a finalised computation
220 221 222 |
# File 'lib/multiarray/lambda.rb', line 220 def finalised? @term.finalised? end |
#lookup(value, stride) ⇒ Lookup, Lambda
Lookup element of an array
134 135 136 137 138 139 140 |
# File 'lib/multiarray/lambda.rb', line 134 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 ⇒ Malloc, ...
Get storage object if there is any
37 38 39 |
# File 'lib/multiarray/lambda.rb', line 37 def memory @term.memory end |
#shape ⇒ Array<Integer>
Get shape of this term
82 83 84 |
# File 'lib/multiarray/lambda.rb', line 82 def shape @term.shape + [@index.size.get] end |
#skip(index, start) ⇒ Node
Skip elements of an array
150 151 152 |
# File 'lib/multiarray/lambda.rb', line 150 def skip( index, start ) Lambda.new @index, @term.skip( index, start ) end |
#slice(start, length) ⇒ Node
Extract array view with part of array
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/multiarray/lambda.rb', line 182 def slice( start, length ) unless start.matched? or length.matched? if start < 0 or start + length > shape.last raise "Range must be in 0 ... #{shape.last} " + "(was #{start} ... #{start + length})" end end start = INT.new start unless start.matched? length = INT.new length unless length.matched? index = Variable.new Hornetseye::INDEX( length ) Lambda.new( index, @term.subst( @index => index ). skip( index, start ) ).unroll end |
#stride(index) ⇒ Integer, NilClass
Get stride for specific index
56 57 58 |
# File 'lib/multiarray/lambda.rb', line 56 def stride( index ) @term.stride index end |
#strides ⇒ Array<Integer>, NilClass
Get strides of array
46 47 48 49 |
# File 'lib/multiarray/lambda.rb', line 46 def strides other = @term.strides other ? other + [ stride( @index ) ] : nil 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.
104 105 106 107 108 |
# File 'lib/multiarray/lambda.rb', line 104 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.
119 120 121 122 123 124 |
# File 'lib/multiarray/lambda.rb', line 119 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 |
#typecode ⇒ Class
Element-type of this term
75 76 77 |
# File 'lib/multiarray/lambda.rb', line 75 def typecode @term.typecode end |
#variables ⇒ Set
Get variables contained in this term
91 92 93 |
# File 'lib/multiarray/lambda.rb', line 91 def variables @term.variables - @index.variables + @index..variables end |