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
72 73 74 |
# File 'lib/multiarray/sequence.rb', line 72 def element_type @element_type end |
.num_elements ⇒ Integer
Number of array elements
77 78 79 |
# File 'lib/multiarray/sequence.rb', line 77 def num_elements @num_elements end |
Class Method Details
.==(other) ⇒ Boolean
Test equality of classes
278 279 280 281 282 |
# File 'lib/multiarray/sequence.rb', line 278 def ==( other ) other.is_a? Class and other < Sequence_ and other.element_type == element_type and other.num_elements == num_elements end |
.[](*args) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/multiarray/sequence.rb', line 101 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
158 159 160 |
# File 'lib/multiarray/sequence.rb', line 158 def array_type self end |
.basetype ⇒ Class
Base type of this data type
149 150 151 |
# File 'lib/multiarray/sequence.rb', line 149 def basetype element_type.basetype end |
.bool ⇒ Object
178 179 180 |
# File 'lib/multiarray/sequence.rb', line 178 def bool Hornetseye::Sequence element_type.bool, num_elements end |
.byte ⇒ Object
208 209 210 |
# File 'lib/multiarray/sequence.rb', line 208 def byte Hornetseye::Sequence element_type.byte, num_elements end |
.coerce(other) ⇒ Array<Class>
Compute balanced type for binary operation
308 309 310 311 312 313 314 |
# File 'lib/multiarray/sequence.rb', line 308 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
291 292 293 294 295 296 297 298 299 |
# File 'lib/multiarray/sequence.rb', line 291 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
182 183 184 |
# File 'lib/multiarray/sequence.rb', line 182 def coercion_bool( other ) coercion( other ).bool end |
.coercion_byte(other) ⇒ Object
212 213 214 |
# File 'lib/multiarray/sequence.rb', line 212 def coercion_byte( other ) coercion( other ).byte end |
.coercion_maxint(other) ⇒ Object
204 205 206 |
# File 'lib/multiarray/sequence.rb', line 204 def coercion_maxint( other ) coercion( other ).maxint end |
.compilable? ⇒ Boolean
320 321 322 |
# File 'lib/multiarray/sequence.rb', line 320 def compilable? element_type.compilable? end |
.cond(a, b) ⇒ Object
229 230 231 232 |
# File 'lib/multiarray/sequence.rb', line 229 def cond( a, b ) t = a.coercion b Hornetseye::MultiArray( t.typecode, *shape ).coercion t end |
.contiguous ⇒ Object
174 175 176 |
# File 'lib/multiarray/sequence.rb', line 174 def contiguous self end |
.default ⇒ Object
Get default value for elements of this type
84 85 86 87 88 89 90 91 92 |
# File 'lib/multiarray/sequence.rb', line 84 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
261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/multiarray/sequence.rb', line 261 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
166 167 168 |
# File 'lib/multiarray/sequence.rb', line 166 def dimension element_type.dimension + 1 end |
.empty? ⇒ Boolean
136 137 138 |
# File 'lib/multiarray/sequence.rb', line 136 def empty? size == 0 end |
.float ⇒ Class
Convert to type based on floating point numbers
221 222 223 |
# File 'lib/multiarray/sequence.rb', line 221 def float Hornetseye::Sequence element_type.float, num_elements end |
.float_scalar ⇒ Object
193 194 195 |
# File 'lib/multiarray/sequence.rb', line 193 def float_scalar Hornetseye::Sequence element_type.float_scalar, num_elements end |
.floating(other) ⇒ Object
225 226 227 |
# File 'lib/multiarray/sequence.rb', line 225 def floating( other ) coercion( other ).float end |
.height ⇒ Object
124 125 126 |
# File 'lib/multiarray/sequence.rb', line 124 def height shape[1] end |
.indgen(offset = 0, increment = 1) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/multiarray/sequence.rb', line 94 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
238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/multiarray/sequence.rb', line 238 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
200 201 202 |
# File 'lib/multiarray/sequence.rb', line 200 def maxint Hornetseye::Sequence element_type.maxint, num_elements end |
.new(memory = nil) ⇒ Object
316 317 318 |
# File 'lib/multiarray/sequence.rb', line 316 def new( memory = nil ) MultiArray.new typecode, *( shape + [ :memory => memory ] ) end |
.pointer_type ⇒ Object
162 163 164 |
# File 'lib/multiarray/sequence.rb', line 162 def pointer_type self end |
.rgb? ⇒ Boolean
170 171 172 |
# File 'lib/multiarray/sequence.rb', line 170 def rgb? element_type.rgb? end |
.scalar ⇒ Class
Get corresponding scalar type
189 190 191 |
# File 'lib/multiarray/sequence.rb', line 189 def scalar Hornetseye::Sequence element_type.scalar, num_elements end |
.shape ⇒ Object
116 117 118 |
# File 'lib/multiarray/sequence.rb', line 116 def shape element_type.shape + [ num_elements ] end |
.size ⇒ Object
128 129 130 |
# File 'lib/multiarray/sequence.rb', line 128 def size num_elements * element_type.size end |
.storage_size ⇒ Object
132 133 134 |
# File 'lib/multiarray/sequence.rb', line 132 def storage_size num_elements * element_type.storage_size end |
.to_s ⇒ Object
250 251 252 |
# File 'lib/multiarray/sequence.rb', line 250 def to_s descriptor( {} ) end |
.to_type(dest) ⇒ Object
234 235 236 |
# File 'lib/multiarray/sequence.rb', line 234 def to_type( dest ) Hornetseye::Sequence element_type.to_type( dest ), num_elements end |
.typecode ⇒ Object
140 141 142 |
# File 'lib/multiarray/sequence.rb', line 140 def typecode element_type.typecode end |
.width ⇒ Object
120 121 122 |
# File 'lib/multiarray/sequence.rb', line 120 def width shape[0] end |