Class: Hornetseye::Histogram
Overview
Class for representing histogram computations
Class Method Summary collapse
-
.finalised? ⇒ Boolean
Check whether objects of this class are finalised computations.
Instance Method Summary collapse
-
#compilable? ⇒ Boolean
Check whether this term is compilable.
-
#demand ⇒ Node, Object
Reevaluate computation.
-
#descriptor(hash) ⇒ String
Get unique descriptor of this object.
-
#initialize(dest, weight, *sources) ⇒ Histogram
constructor
Constructor.
- #sexp? ⇒ Boolean
- #shape ⇒ Object
-
#strip ⇒ Array<Array,Node>
Strip of all values.
-
#subst(hash) ⇒ Node
Substitute variables.
- #typecode ⇒ Object
-
#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, #decompose, define_binary_op, define_unary_op, 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, #memory, #min, #normalise, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, rgb?, #roll, scalar, shape, #shift, #simplify, #size, #sobel, #stride, #strides, 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(dest, weight, *sources) ⇒ Histogram
Constructor
43 44 45 |
# File 'lib/multiarray/histogram.rb', line 43 def initialize( dest, weight, *sources ) @dest, @weight, @sources = dest, weight, sources end |
Class Method Details
.finalised? ⇒ Boolean
Check whether objects of this class are finalised computations
30 31 32 |
# File 'lib/multiarray/histogram.rb', line 30 def finalised? false end |
Instance Method Details
#compilable? ⇒ Boolean
Check whether this term is compilable
147 148 149 150 |
# File 'lib/multiarray/histogram.rb', line 147 def compilable? @dest.compilable? and @weight.compilable? and @sources.all? { |source| source.compilable? } end |
#demand ⇒ Node, Object
Reevaluate computation
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/multiarray/histogram.rb', line 79 def demand if variables.empty? if @sources.any? { |source| source.dimension > 0 } source_type = @sources.inject { |a,b| a.dimension > b.dimension ? a : b } source_type.shape.last.times do |i| sources = @sources.collect do |source| source.dimension > 0 ? source.element(INT.new(i)) : source end weight = @weight.dimension > 0 ? @weight.element(INT.new(i)) : @weight Histogram.new(@dest, weight, *sources).demand end else dest = @dest (@dest.dimension - 1).downto(0) do |i| dest = dest.element @sources[i].demand end dest.store dest + @weight end @dest else super end end |
#descriptor(hash) ⇒ String
Get unique descriptor of this object
58 59 60 61 62 |
# File 'lib/multiarray/histogram.rb', line 58 def descriptor( hash ) "Histogram(#{@dest.descriptor( hash )}," + "#{@weight.descriptor( hash )}," + "#{@sources.collect { |source| source.descriptor( hash ) }.join ','})" end |
#sexp? ⇒ Boolean
47 48 49 |
# File 'lib/multiarray/histogram.rb', line 47 def sexp? true end |
#shape ⇒ Object
68 69 70 |
# File 'lib/multiarray/histogram.rb', line 68 def shape @dest.shape 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.
135 136 137 138 139 140 |
# File 'lib/multiarray/histogram.rb', line 135 def strip stripped = ( [ @dest, @weight ] + @sources ).collect { |source| source.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.
112 113 114 115 |
# File 'lib/multiarray/histogram.rb', line 112 def subst( hash ) self.class.new @dest.subst( hash ), @weight.subst( hash ), *@sources.collect { |source| source.subst hash } end |
#typecode ⇒ Object
64 65 66 |
# File 'lib/multiarray/histogram.rb', line 64 def typecode @dest.typecode end |
#variables ⇒ Set
Get variables contained in this term
122 123 124 |
# File 'lib/multiarray/histogram.rb', line 122 def variables @sources.inject( @dest.variables + @weight.variables ) { |a,b| a + b.variables } end |