Class: Hornetseye::INT_

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

Overview

Class for representing native integers

Defined Under Namespace

Modules: Match

Constant Summary collapse

DIRECTIVES =

Hash table used internally

{ [  8, true  ] => 'c',
[  8, false ] => 'C',
[ 16, true  ] => 's',
[ 16, false ] => 'S',
[ 32, true  ] => 'i',
[ 32, false ] => 'I',
[ 64, true  ] => 'q',
[ 64, false ] => 'Q' }
IDENTIFIER =

Hash table used internally

{ [  8, true  ] => 'BYTE',
[  8, false ] => 'UBYTE',
[ 16, true  ] => 'SINT',
[ 16, false ] => 'USINT',
[ 32, true  ] => 'INT',
[ 32, false ] => 'UINT',
[ 64, true  ] => 'LONG',
[ 64, false ] => 'ULONG' }

Class Attribute Summary collapse

Class Method Summary collapse

Instance 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, 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, #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 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 Match

#fit

Constructor Details

This class inherits a constructor from Hornetseye::Element

Class Attribute Details

.bitsInteger

Number of bits of this integer

Returns:

  • (Integer)

    Number of bits of this integer.



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

def bits
  @bits
end

.signedBoolean

Boolean indicating whether this is a signed integer or not

signed integer or not.

Returns:

  • (Boolean)

    Boolean indicating whether this is a



34
35
36
# File 'lib/multiarray/int.rb', line 34

def signed
  @signed
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.



175
176
177
178
# File 'lib/multiarray/int.rb', line 175

def ==( other )
  other.is_a? Class and other < INT_ and
    bits == other.bits and signed == other.signed
end

.coerce(other) ⇒ Array<Class>

Type coercion for native elements

Parameters:

  • other (Class)

    Other type to coerce with.

Returns:

  • (Array<Class>)

    Result of coercion.



101
102
103
104
105
106
107
# File 'lib/multiarray/int.rb', line 101

def coerce( other )
  if other < INT_
    return other, 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.



86
87
88
89
90
91
92
# File 'lib/multiarray/int.rb', line 86

def coercion( other )
  if other < INT_
    Hornetseye::INT [ bits, other.bits ].max, ( signed or other.signed )
  else
    super other
  end
end

.defaultObject

Get default value for elements of this type

Returns:



66
67
68
# File 'lib/multiarray/int.rb', line 66

def default
  0
end

.descriptor(hash) ⇒ String

Get unique descriptor of this class

Parameters:

  • hash (Hash)

    Labels for any variables.

Returns:

  • (String)

    Descriptor of this class.



162
163
164
165
166
167
168
# File 'lib/multiarray/int.rb', line 162

def descriptor( hash )
  unless bits.nil? or signed.nil?
    inspect
  else
    super hash
  end
end

.directiveObject

Directive for packing/unpacking elements of this type



124
125
126
127
128
# File 'lib/multiarray/int.rb', line 124

def directive
  retval = DIRECTIVES[ [ bits, signed ] ]
  raise "No directive for packing/unpacking #{inspect}" unless retval
  retval
end

.eql?(other) ⇒ Boolean

Equality for hash operations

Parameters:

  • other (Object)

    Object to compare with.

Returns:

  • (Boolean)

    Returns true if objects are equal.



196
197
198
# File 'lib/multiarray/int.rb', line 196

def eql?( other )
  self == other
end

.hashFixnum

Compute hash value for this class

Returns:



185
186
187
# File 'lib/multiarray/int.rb', line 185

def hash
  [ :INT_, bits, signed ].hash
end

.inherit(bits, signed) ⇒ Object



36
37
38
39
40
41
# File 'lib/multiarray/int.rb', line 36

def inherit(bits, signed)
  retval = Class.new self
  retval.bits = bits
  retval.signed = signed
  retval
end

.inspectString

Get string with information about this class

Returns:

  • (String)

    Returns string with information about this class (e.g. “BYTE”).



146
147
148
149
150
151
152
153
# File 'lib/multiarray/int.rb', line 146

def inspect
  unless bits.nil? or signed.nil?
    IDENTIFIER[ [ bits, signed ] ] ||
      "INT(#{bits.inspect},#{ signed ? 'SIGNED' : 'UNSIGNED' })"
  else
    super
  end
end

.maxintClass

Get corresponding maximal integer type

Returns:

  • (Class)

    Returns 32 bit integer or self whichever has more bits.



75
76
77
# File 'lib/multiarray/int.rb', line 75

def maxint
  Hornetseye::INT [ 32, bits ].max, signed
end

.memory_typeClass

Memory type required to store elements of this type

Returns:

  • (Class)

    Returns Malloc.



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

def memory_type
  Malloc
end

.storage_sizeInteger

Get storage size to store an element of this type

Returns:

  • (Integer)

    Returns 1.



57
58
59
# File 'lib/multiarray/int.rb', line 57

def storage_size
  ( bits + 7 ).div 8
end

Instance Method Details

#times(&action) ⇒ GCCValue

Loop statement

Parameters:

  • action (Proc)

    Loop body.

Returns:



209
210
211
212
# File 'lib/multiarray/int.rb', line 209

def times( &action )
  get.times &action
  self
end

#upto(other, &action) ⇒ GCCValue

Loop statement

Parameters:

  • other (Node)

    Upper limit for loop.

  • action (Proc)

    Loop body.

Returns:



222
223
224
225
# File 'lib/multiarray/int.rb', line 222

def upto( other, &action )
  get.upto other.get, &action
  self
end