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.
- #sexp? ⇒ Boolean
-
#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, #memorise, #min, #normalise, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, rgb?, #roll, scalar, shape, #shift, #simplify, #size, #sobel, 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
214 215 216 |
# File 'lib/multiarray/lambda.rb', line 214 def compilable? @term.compilable? end |
#decompose(i) ⇒ Node
Decompose composite elements
This method decomposes composite elements into array.
205 206 207 |
# File 'lib/multiarray/lambda.rb', line 205 def decompose( i ) Lambda.new @index, @term.decompose( i ) end |
#descriptor(hash) ⇒ String
Get unique descriptor of this object
71 72 73 74 |
# File 'lib/multiarray/lambda.rb', line 71 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.
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/multiarray/lambda.rb', line 167 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
224 225 226 |
# File 'lib/multiarray/lambda.rb', line 224 def finalised? @term.finalised? end |
#lookup(value, stride) ⇒ Lookup, Lambda
Lookup element of an array
138 139 140 141 142 143 144 |
# File 'lib/multiarray/lambda.rb', line 138 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
41 42 43 |
# File 'lib/multiarray/lambda.rb', line 41 def memory @term.memory end |
#sexp? ⇒ Boolean
34 35 36 |
# File 'lib/multiarray/lambda.rb', line 34 def sexp? true end |
#shape ⇒ Array<Integer>
Get shape of this term
86 87 88 |
# File 'lib/multiarray/lambda.rb', line 86 def shape @term.shape + [@index.size.get] end |
#skip(index, start) ⇒ Node
Skip elements of an array
154 155 156 |
# File 'lib/multiarray/lambda.rb', line 154 def skip( index, start ) Lambda.new @index, @term.skip( index, start ) end |
#slice(start, length) ⇒ Node
Extract array view with part of array
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/multiarray/lambda.rb', line 186 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
60 61 62 |
# File 'lib/multiarray/lambda.rb', line 60 def stride( index ) @term.stride index end |
#strides ⇒ Array<Integer>, NilClass
Get strides of array
50 51 52 53 |
# File 'lib/multiarray/lambda.rb', line 50 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.
108 109 110 111 112 |
# File 'lib/multiarray/lambda.rb', line 108 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.
123 124 125 126 127 128 |
# File 'lib/multiarray/lambda.rb', line 123 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
79 80 81 |
# File 'lib/multiarray/lambda.rb', line 79 def typecode @term.typecode end |
#variables ⇒ Set
Get variables contained in this term
95 96 97 |
# File 'lib/multiarray/lambda.rb', line 95 def variables @term.variables - @index.variables + @index..variables end |