Class: Hornetseye::Sequence_
Overview
Class for representing n-dimensional native arrays
Defined Under Namespace
Modules: Match
Class Attribute Summary collapse
-
.element_type ⇒ Class
Type of array elements.
-
.num_elements ⇒ Integer
Number of array elements.
Class Method Summary collapse
-
.==(other) ⇒ Boolean
Test equality of classes.
- .[](*args) ⇒ Object
-
.array_type ⇒ Class
Get type of result of delayed operation.
-
.basetype ⇒ Class
Base type of this data type.
- .bool ⇒ Object
- .byte ⇒ Object
-
.coerce(other) ⇒ Array<Class>
Compute balanced type for binary operation.
-
.coercion(other) ⇒ Class
Type coercion for native elements.
- .coercion_bool(other) ⇒ Object
- .coercion_byte(other) ⇒ Object
- .coercion_maxint(other) ⇒ Object
- .compilable? ⇒ Boolean
- .cond(a, b) ⇒ Object
- .contiguous ⇒ Object
-
.default ⇒ Object
Get default value for elements of this type.
-
.descriptor(hash) ⇒ String
Get unique descriptor of this class.
- .dimension ⇒ Object
- .empty? ⇒ Boolean
-
.float ⇒ Class
Convert to type based on floating point numbers.
- .float_scalar ⇒ Object
- .floating(other) ⇒ Object
- .height ⇒ Object
- .indgen(offset = 0, increment = 1) ⇒ Object
- .inspect ⇒ Object
-
.maxint ⇒ Class
Get corresponding maximum integer type.
- .new(memory = nil) ⇒ Object
- .pointer_type ⇒ Object
- .rgb? ⇒ Boolean
-
.scalar ⇒ Class
Get corresponding scalar type.
- .shape ⇒ Object
- .size ⇒ Object
- .storage_size ⇒ Object
- .to_s ⇒ Object
- .to_type(dest) ⇒ Object
- .typecode ⇒ Object
- .width ⇒ Object
Class Attribute Details
.element_type ⇒ Class
Type of array elements
76 77 78 |
# File 'lib/multiarray/sequence.rb', line 76 def element_type @element_type end |
.num_elements ⇒ Integer
Number of array elements
81 82 83 |
# File 'lib/multiarray/sequence.rb', line 81 def num_elements @num_elements end |
Class Method Details
.==(other) ⇒ Boolean
Test equality of classes
282 283 284 285 286 |
# File 'lib/multiarray/sequence.rb', line 282 def ==( other ) other.is_a? Class and other < Sequence_ and other.element_type == element_type and other.num_elements == num_elements end |
.[](*args) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/multiarray/sequence.rb', line 105 def []( *args ) retval = new recursion = lambda do |element,args| if element.dimension > 0 args.each_with_index do |arg,i| recursion.call element.element( i ), arg end else element[] = args end end recursion.call retval, args retval end |
.array_type ⇒ Class
Get type of result of delayed operation
162 163 164 |
# File 'lib/multiarray/sequence.rb', line 162 def array_type self end |
.basetype ⇒ Class
Base type of this data type
153 154 155 |
# File 'lib/multiarray/sequence.rb', line 153 def basetype element_type.basetype end |
.bool ⇒ Object
182 183 184 |
# File 'lib/multiarray/sequence.rb', line 182 def bool Hornetseye::Sequence element_type.bool, num_elements end |
.byte ⇒ Object
212 213 214 |
# File 'lib/multiarray/sequence.rb', line 212 def byte Hornetseye::Sequence element_type.byte, num_elements end |
.coerce(other) ⇒ Array<Class>
Compute balanced type for binary operation
312 313 314 315 316 317 318 |
# File 'lib/multiarray/sequence.rb', line 312 def coerce( other ) if other < Sequence_ return other, self else return Hornetseye::Sequence( other, num_elements ), self end end |
.coercion(other) ⇒ Class
Type coercion for native elements
295 296 297 298 299 300 301 302 303 |
# File 'lib/multiarray/sequence.rb', line 295 def coercion( other ) if other < Sequence_ Hornetseye::Sequence element_type.coercion( other.element_type ), num_elements else Hornetseye::Sequence element_type.coercion( other ), num_elements end end |
.coercion_bool(other) ⇒ Object
186 187 188 |
# File 'lib/multiarray/sequence.rb', line 186 def coercion_bool( other ) coercion( other ).bool end |
.coercion_byte(other) ⇒ Object
216 217 218 |
# File 'lib/multiarray/sequence.rb', line 216 def coercion_byte( other ) coercion( other ).byte end |
.coercion_maxint(other) ⇒ Object
208 209 210 |
# File 'lib/multiarray/sequence.rb', line 208 def coercion_maxint( other ) coercion( other ).maxint end |
.compilable? ⇒ Boolean
324 325 326 |
# File 'lib/multiarray/sequence.rb', line 324 def compilable? element_type.compilable? end |
.cond(a, b) ⇒ Object
233 234 235 236 |
# File 'lib/multiarray/sequence.rb', line 233 def cond( a, b ) t = a.coercion b Hornetseye::MultiArray( t.typecode, *shape ).coercion t end |
.contiguous ⇒ Object
178 179 180 |
# File 'lib/multiarray/sequence.rb', line 178 def contiguous self end |
.default ⇒ Object
Get default value for elements of this type
88 89 90 91 92 93 94 95 96 |
# File 'lib/multiarray/sequence.rb', line 88 def default Hornetseye::lazy( num_elements ) do |i| if element_type.dimension > 0 element = element_type.default else element = element_type.new end end end |
.descriptor(hash) ⇒ String
Get unique descriptor of this class
265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/multiarray/sequence.rb', line 265 def descriptor( hash ) if element_type and num_elements if dimension == 1 "Sequence(#{typecode.descriptor( hash )},#{num_elements.to_s})" else "MultiArray(#{typecode.descriptor( hash )},#{shape.join ','})" end else 'MultiArray(?,?)' end end |
.dimension ⇒ Object
170 171 172 |
# File 'lib/multiarray/sequence.rb', line 170 def dimension element_type.dimension + 1 end |
.empty? ⇒ Boolean
140 141 142 |
# File 'lib/multiarray/sequence.rb', line 140 def empty? size == 0 end |
.float ⇒ Class
Convert to type based on floating point numbers
225 226 227 |
# File 'lib/multiarray/sequence.rb', line 225 def float Hornetseye::Sequence element_type.float, num_elements end |
.float_scalar ⇒ Object
197 198 199 |
# File 'lib/multiarray/sequence.rb', line 197 def float_scalar Hornetseye::Sequence element_type.float_scalar, num_elements end |
.floating(other) ⇒ Object
229 230 231 |
# File 'lib/multiarray/sequence.rb', line 229 def floating( other ) coercion( other ).float end |
.height ⇒ Object
128 129 130 |
# File 'lib/multiarray/sequence.rb', line 128 def height shape[1] end |
.indgen(offset = 0, increment = 1) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/multiarray/sequence.rb', line 98 def indgen( offset = 0, increment = 1 ) Hornetseye::lazy( num_elements ) do |i| ( element_type.size * increment * i + element_type.indgen( offset, increment ) ).to_type typecode end end |
.inspect ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/multiarray/sequence.rb', line 242 def inspect if element_type and num_elements if dimension == 1 "Sequence(#{typecode.inspect},#{num_elements.inspect})" else "MultiArray(#{typecode.inspect},#{shape.join ','})" end else 'MultiArray(?,?)' end end |
.maxint ⇒ Class
Get corresponding maximum integer type
204 205 206 |
# File 'lib/multiarray/sequence.rb', line 204 def maxint Hornetseye::Sequence element_type.maxint, num_elements end |
.new(memory = nil) ⇒ Object
320 321 322 |
# File 'lib/multiarray/sequence.rb', line 320 def new( memory = nil ) MultiArray.new typecode, *( shape + [ :memory => memory ] ) end |
.pointer_type ⇒ Object
166 167 168 |
# File 'lib/multiarray/sequence.rb', line 166 def pointer_type self end |
.rgb? ⇒ Boolean
174 175 176 |
# File 'lib/multiarray/sequence.rb', line 174 def rgb? element_type.rgb? end |
.scalar ⇒ Class
Get corresponding scalar type
193 194 195 |
# File 'lib/multiarray/sequence.rb', line 193 def scalar Hornetseye::Sequence element_type.scalar, num_elements end |
.shape ⇒ Object
120 121 122 |
# File 'lib/multiarray/sequence.rb', line 120 def shape element_type.shape + [ num_elements ] end |
.size ⇒ Object
132 133 134 |
# File 'lib/multiarray/sequence.rb', line 132 def size num_elements * element_type.size end |
.storage_size ⇒ Object
136 137 138 |
# File 'lib/multiarray/sequence.rb', line 136 def storage_size num_elements * element_type.storage_size end |
.to_s ⇒ Object
254 255 256 |
# File 'lib/multiarray/sequence.rb', line 254 def to_s descriptor( {} ) end |
.to_type(dest) ⇒ Object
238 239 240 |
# File 'lib/multiarray/sequence.rb', line 238 def to_type( dest ) Hornetseye::Sequence element_type.to_type( dest ), num_elements end |
.typecode ⇒ Object
144 145 146 |
# File 'lib/multiarray/sequence.rb', line 144 def typecode element_type.typecode end |
.width ⇒ Object
124 125 126 |
# File 'lib/multiarray/sequence.rb', line 124 def width shape[0] end |