Class: Hornetseye::INT_
Overview
Class for representing native integers
Defined Under Namespace
Modules: Match
Class Attribute Summary collapse
-
.bits ⇒ Integer
Number of bits of this integer.
-
.signed ⇒ Boolean
Boolean indicating whether this is a signed integer or not.
Class Method Summary collapse
-
.==(other) ⇒ Boolean
Test equality of classes.
-
.coerce(other) ⇒ Array<Class>
Type coercion for native elements.
-
.coercion(other) ⇒ Class
Compute balanced type for binary operation.
-
.default ⇒ Object
Get default value for elements of this type.
-
.descriptor(hash) ⇒ String
Get unique descriptor of this class.
-
.directive ⇒ Object
Directive for packing/unpacking elements of this type.
-
.eql?(other) ⇒ Boolean
Equality for hash operations.
-
.hash ⇒ Fixnum
Compute hash value for this class.
-
.inspect ⇒ String
Get string with information about this class.
-
.maxint ⇒ Class
Get corresponding maximal integer type.
-
.memory ⇒ Class
Memory type required to store elements of this type.
-
.storage_size ⇒ Integer
Get storage size to store an element of this type.
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
Methods included from OBJECT::Match
Methods included from COMPLEX_::Match
Methods included from Sequence_::Match
Methods included from BOOL::Match
Methods included from RGB_::Match
Methods included from Match
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
.bits ⇒ Integer
Number of bits of this integer
28 29 30 |
# File 'lib/multiarray/int.rb', line 28 def bits @bits end |
.signed ⇒ Boolean
Boolean indicating whether this is a signed integer or not
signed integer or not.
34 35 36 |
# File 'lib/multiarray/int.rb', line 34 def signed @signed end |
Class Method Details
.==(other) ⇒ Boolean
Test equality of classes
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
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
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 |
.default ⇒ Object
Get default value for elements of this type
59 60 61 |
# File 'lib/multiarray/int.rb', line 59 def default 0 end |
.descriptor(hash) ⇒ String
Get unique 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 |
.directive ⇒ Object
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
179 180 181 |
# File 'lib/multiarray/int.rb', line 179 def eql?( other ) self == other end |
.hash ⇒ Fixnum
Compute hash value for this class.
168 169 170 |
# File 'lib/multiarray/int.rb', line 168 def hash [ :INT_, bits, signed ].hash end |
.inspect ⇒ String
Get string with information about this class
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 |
.maxint ⇒ Class
Get corresponding maximal integer type.
68 69 70 |
# File 'lib/multiarray/int.rb', line 68 def maxint Hornetseye::INT [ 32, bits ].max, signed end |
.memory ⇒ Class
Memory type required to store elements of this type
41 42 43 |
# File 'lib/multiarray/int.rb', line 41 def memory Malloc end |
.storage_size ⇒ Integer
Get storage size to store an element of this type
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 |