Class: Hornetseye::FLOAT_

Inherits:
Element show all
Defined in:
lib/multiarray/float.rb

Overview

Class for representing native floating point numbers

Defined Under Namespace

Modules: Match

Class Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Element

#assign, #compilable?, construct, #descriptor, #dup, fetch, #get, #initialize, #skip, #strip, #values, #write

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?, compilable?, #components, cond, #conditional, #convolve, #decompose, define_binary_op, define_unary_op, #demand, #descriptor, #diagonal, #dilate, dimension, #dimension, #downsample, #dup, #each, #empty?, #eq_with_multiarray, #erode, #fill!, finalised?, #finalised?, #flip, 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, shape, #shift, #simplify, #size, #sobel, #stretch, #stride, #strides, #strip, strip, #subst, 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, typecode, typecodes, #unmask, #unroll, #variables, variables, #warp, #width

Methods included from Hornetseye::Field_::Match

#align, #fit

Methods included from 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

This class inherits a constructor from Hornetseye::Element

Class Attribute Details

.doubleBoolean

Boolean indicating whether this number is single or double precision

Returns:

  • (Boolean)

    true for double precision, false for single precision.



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

def double
  @double
end

Class Method Details

.==(other) ⇒ Boolean

Test equality of classes

Parameters:

  • other (Object)

    Object to compare with.

Returns:

  • (Boolean)

    Boolean indicating whether classes are equal.



140
141
142
# File 'lib/multiarray/float.rb', line 140

def ==( other )
  other.is_a? Class and other < FLOAT_ and double == other.double
end

.coerce(other) ⇒ Array<Class>

Type coercion for native elements

Parameters:

  • other (Class)

    Other type to coerce with.

Returns:

  • (Array<Class>)

    Result of coercion.



89
90
91
92
93
94
95
96
97
# File 'lib/multiarray/float.rb', line 89

def coerce( other )
  if other < FLOAT_
    return other, self
  elsif other < INT_
    return self, self
  else
    super other
  end
end

.coercion(other) ⇒ Class

Compute balanced type for binary operation

Parameters:

  • other (Class)

    Other native datatype to coerce with.

Returns:

  • (Class)

    Result of coercion.



72
73
74
75
76
77
78
79
80
# File 'lib/multiarray/float.rb', line 72

def coercion( other )
  if other < FLOAT_
    Hornetseye::FLOAT( ( double or other.double ) )
  elsif other < INT_
    self
  else
    super other
  end
end

.defaultObject

Get default value for elements of this type

Returns:



61
62
63
# File 'lib/multiarray/float.rb', line 61

def default
  0.0
end

.descriptor(hash) ⇒ String

Get unique descriptor of this class

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    Descriptor of this class.



131
132
133
# File 'lib/multiarray/float.rb', line 131

def descriptor( hash )
  inspect
end

.directiveString

Directive for packing/unpacking elements of this type

Returns:

  • (String)

    Returns ‘f’ or ‘d’.



113
114
115
# File 'lib/multiarray/float.rb', line 113

def directive
  double ? 'd' : 'f'
end

.eql?(other) ⇒ Boolean

Equality for hash operations

Parameters:

  • other (Object)

    Object to compare with.

Returns:

  • (Boolean)

    Returns true if objects are equal.



160
161
162
# File 'lib/multiarray/float.rb', line 160

def eql?( other )
  self == other
end

.floatClass

Convert to type based on floating point numbers

Returns:

  • (Class)

    Corresponding type based on floating point numbers.



104
105
106
# File 'lib/multiarray/float.rb', line 104

def float
  self
end

.hashFixnum

Compute hash value for this class

Returns:



149
150
151
# File 'lib/multiarray/float.rb', line 149

def hash
  [ :FLOAT_, double ].hash
end

.inherit(double) ⇒ Object



32
33
34
35
36
# File 'lib/multiarray/float.rb', line 32

def inherit(double)
  retval = Class.new self
  retval.double = double
  retval
end

.inspectString

Return string with information about this class

Returns:

  • (String)

    Returns a string (e.g. “SFLOAT”).



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

def inspect
  "#{ double ? 'D' : 'S' }FLOAT"
end

.memory_typeClass

Memory type required to store elements of this type

Returns:

  • (Class)

    Returns Malloc.



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

def memory_type
  Malloc
end

.storage_sizeInteger

Get storage size to store an element of this type

Returns:



52
53
54
# File 'lib/multiarray/float.rb', line 52

def storage_size
  double ? 8 : 4
end