Class: Hornetseye::Unmask

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

Overview

Class for representing inverse masking operations

Class Method Summary collapse

Instance Method Summary collapse

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

#align, #fit

Methods included from FLOAT_::Match

#align, #fit

Methods included from OBJECT::Match

#align, #fit

Methods included from COMPLEX_::Match

#align, #fit

Methods included from BOOL::Match

#fit

Methods included from RGB_::Match

#align, #fit

Methods included from INT_::Match

#fit

Constructor Details

#initialize(dest, source, m, index, default) ⇒ Unmask

Constructor

Parameters:

  • dest (Node)

    Target array to write histogram to.

  • source (Node)

    Source array with values to apply mask to.

  • m (Node)

    Boolean array with values of mask.

  • default (Node)

    Default value for unaffected elements.



44
45
46
# File 'lib/multiarray/unmask.rb', line 44

def initialize( dest, source, m, index, default )
  @dest, @source, @m, @index, @default = dest, source, m, index, default
end

Class Method Details

.finalised?Boolean

Check whether objects of this class are finalised computations

Returns:

  • (Boolean)

    Returns false.



30
31
32
# File 'lib/multiarray/unmask.rb', line 30

def finalised?
  false
end

Instance Method Details

#compilable?Boolean

Check whether this term is compilable

Returns:

  • (Boolean)

    Returns whether this term is compilable.



154
155
156
# File 'lib/multiarray/unmask.rb', line 154

def compilable?
  [ @dest, @source, @m, @index, @default ].all? { |value| value.compilable? }
end

#demandNode

Perform masking operation

Returns:

  • (Node)

    Result of computation



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/multiarray/unmask.rb', line 78

def demand
  if variables.empty?
    index = @index.simplify
    if @m.dimension > 0
      @m.shape.last.times do |i|
        m = @m.element INT.new( i )
        dest = @dest.element INT.new( i )
        default = @default.dimension > 0 ?
                  @default.element( INT.new( i ) ) : @default
        Unmask.new( dest, @source, m, index, default ).demand
      end  
    else
      @m.if_else( proc do
        Store.new( @dest, @source.element( index ) ).demand
        index.assign index + 1
      end, proc do
        Store.new( @dest, @default ).demand
      end )
    end
    if @index.is_a? Pointer_
      @index.store index
    else
      @index.assign index
    end
    @dest
  else
    super
  end
end

#descriptor(hash) ⇒ String

Get unique descriptor of this object

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    Descriptor of this object,



59
60
61
62
63
# File 'lib/multiarray/unmask.rb', line 59

def descriptor( hash )
  "Unmask(#{@dest.descriptor( hash )},#{@source.descriptor( hash )}," +
    "#{@m.descriptor( hash )},#{@index.descriptor( hash )}," +
    "#{@default.descriptor( hash )})"
end

#sexp?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/multiarray/unmask.rb', line 48

def sexp?
  true
end

#shapeObject



69
70
71
# File 'lib/multiarray/unmask.rb', line 69

def shape
  @dest.shape
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:



141
142
143
144
145
146
147
# File 'lib/multiarray/unmask.rb', line 141

def strip
  stripped = [ @dest, @source, @m, @index, @default ].
    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.



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

def subst( hash )
  self.class.new @dest.subst( hash ), @source.subst( hash ), @m.subst( hash ),
                 @index.subst( hash ), @default.subst( hash )
end

#typecodeObject



65
66
67
# File 'lib/multiarray/unmask.rb', line 65

def typecode
  @dest.typecode
end

#variablesSet

Get variables contained in this term

Returns:

  • (Set)

    Returns list of variables.



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

def variables
  @dest.variables + @source.variables + @m.variables + @index.variables +
    @default.variables
end