Class: Hornetseye::Random

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

Overview

Class for generating random number arrays

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?, #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, #memory, #min, #normalise, #prod, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #reshape, #rgb?, rgb?, #roll, scalar, shape, #shift, #simplify, #size, #sobel, #stretch, #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 Hornetseye::RGB_::Match

#align, #fit

Methods included from INT_::Match

#fit

Constructor Details

#initialize(dest, n) ⇒ Random

Constructor

Parameters:

  • dest (Node)

    Target array to write array to.

  • n (Node)

    Upper boundary for random value.



28
29
30
# File 'lib/multiarray/random.rb', line 28

def initialize( dest, n )
  @dest, @n = dest, n
end

Instance Method Details

#compilable?Boolean

Check whether this term is compilable

Returns:

  • (Boolean)

    Returns whether this term is compilable.



120
121
122
# File 'lib/multiarray/random.rb', line 120

def compilable?
  @dest.compilable? and @n.compilable?
end

#demandNode, Object

Reevaluate computation

Returns:

See Also:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/multiarray/random.rb', line 58

def demand
  if variables.empty?
    if dimension > 0
      shape.last.times do |i|
        dest = @dest.element INT.new( i )
        Random.new( dest, @n ).demand
      end  
    else
      if @n.typecode < INT_ or ( @n.typecode < OBJECT and @n.get.is_a? Integer )
        @dest.store @n.typecode.new( @n.get.lrand )
      else
        @dest.store @n.typecode.new( @n.get.drand )
      end
    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,



39
40
41
# File 'lib/multiarray/random.rb', line 39

def descriptor( hash )
  "Random(#{@dest.descriptor( hash )},#{@n.descriptor( hash )})"
end

#shapeObject



47
48
49
# File 'lib/multiarray/random.rb', line 47

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:



109
110
111
112
113
# File 'lib/multiarray/random.rb', line 109

def strip
  vars1, values1, term1 = @dest.strip
  vars2, values2, term2 = @n.strip
  return vars1 + vars2, values1 + values2, Random.new( term1, term2 )
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.



87
88
89
# File 'lib/multiarray/random.rb', line 87

def subst( hash )
  self.class.new @dest.subst( hash ), @n.subst( hash )
end

#typecodeObject



43
44
45
# File 'lib/multiarray/random.rb', line 43

def typecode
  @dest.typecode
end

#variablesSet

Get variables contained in this term

Returns:

  • (Set)

    Returns list of variables.



96
97
98
# File 'lib/multiarray/random.rb', line 96

def variables
  @dest.variables + @n.variables
end