Class: Hornetseye::INT_

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

Overview

Class for representing native integers

Defined Under Namespace

Modules: Match

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

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

Methods inherited from Node

===, #[], #[]=, #array_type, array_type, basetype, #basetype, bool, byte, #check_shape, #coerce, coercion_bool, coercion_byte, coercion_maxint, compilable?, #compilable?, cond, contiguous, #decompose, #demand, #descriptor, dimension, #dimension, #dup, empty?, #empty?, #finalised?, finalised?, float, float_scalar, floating, #force, #get, height, #height, indgen, #inspect, match, #memory, #pointer_type, pointer_type, rgb?, #rgb?, scalar, #shape, shape, #simplify, size, #size, #storage_size, strip, #strip, subst, #subst, #to_a, to_s, #to_s, to_type, #typecode, typecode, typecodes, variables, #variables, #width, width

Methods included from FLOAT_::Match

#align, #fit

Methods included from OBJECT::Match

#align, #fit

Methods included from COMPLEX_::Match

#align, #fit

Methods included from Sequence_::Match

#align, #fit

Methods included from BOOL::Match

#fit

Methods included from RGB_::Match

#align, #fit

Methods included from Match

#fit

Methods included from Operations

#+@, #<=>, #b=, #b_with_decompose, #collect, #conditional, #convolve, define_binary_op, define_unary_op, #diagonal, #eq_with_multiarray, #fill!, #g=, #g_with_decompose, #histogram, #histogram_with_composite, #imag=, #imag_with_decompose, #inject, #integral, #lut, #lut_with_composite, #max, #min, #normalise, #product, #r=, #r_with_decompose, #range, #real=, #real_with_decompose, #roll, #sum, #to_type, #to_type_with_rgb, #transpose, #unroll

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.



158
159
160
161
# File 'lib/multiarray/int.rb', line 158

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.



94
95
96
97
98
99
100
# File 'lib/multiarray/int.rb', line 94

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.



79
80
81
82
83
84
85
# File 'lib/multiarray/int.rb', line 79

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:



59
60
61
# File 'lib/multiarray/int.rb', line 59

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.



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

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

.directiveObject

Directive for packing/unpacking elements of this type



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/multiarray/int.rb', line 105

def directive
  retval = { [  8, true  ] => 'c',
             [  8, false ] => 'C',
             [ 16, true  ] => 's',
             [ 16, false ] => 'S',
             [ 32, true  ] => 'i',
             [ 32, false ] => 'I',
             [ 64, true  ] => 'q',
             [ 64, false ] => 'Q' }[ [ 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.



179
180
181
# File 'lib/multiarray/int.rb', line 179

def eql?( other )
  self == other
end

.hashFixnum

Compute hash value for this class.

Returns:



168
169
170
# File 'lib/multiarray/int.rb', line 168

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

.inspectString

Get string with information about this class

Returns:

  • (String)

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



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/multiarray/int.rb', line 122

def inspect
  unless bits.nil? or signed.nil?
    retval = { [  8, true  ] => 'BYTE',
               [  8, false ] => 'UBYTE',
               [ 16, true  ] => 'SINT',
               [ 16, false ] => 'USINT',
               [ 32, true  ] => 'INT',
               [ 32, false ] => 'UINT',
               [ 64, true  ] => 'LONG',
               [ 64, false ] => 'ULONG' }[ [ 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.



68
69
70
# File 'lib/multiarray/int.rb', line 68

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

.memoryClass

Memory type required to store elements of this type

Returns:

  • (Class)

    Returns Malloc.



41
42
43
# File 'lib/multiarray/int.rb', line 41

def memory
  Malloc
end

.storage_sizeInteger

Get storage size to store an element of this type

Returns:

  • (Integer)

    Returns 1.



50
51
52
# File 'lib/multiarray/int.rb', line 50

def storage_size
  ( bits + 7 ).div 8
end

Instance Method Details

#times(&action) ⇒ Object



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

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

#upto(other, &action) ⇒ Object



190
191
192
193
# File 'lib/multiarray/int.rb', line 190

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