multiarray 0.11.3 → 0.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +61 -0
- data/Rakefile +1 -1
- data/lib/multiarray.rb +28 -0
- data/lib/multiarray/complex.rb +310 -13
- data/lib/multiarray/composite.rb +7 -0
- data/lib/multiarray/diagonal.rb +18 -3
- data/lib/multiarray/elementwise.rb +7 -2
- data/lib/multiarray/float.rb +43 -3
- data/lib/multiarray/gcccache.rb +4 -1
- data/lib/multiarray/gcccontext.rb +119 -21
- data/lib/multiarray/gccfunction.rb +92 -3
- data/lib/multiarray/gcctype.rb +26 -0
- data/lib/multiarray/gccvalue.rb +204 -2
- data/lib/multiarray/histogram.rb +65 -1
- data/lib/multiarray/index.rb +11 -0
- data/lib/multiarray/inject.rb +18 -1
- data/lib/multiarray/int.rb +49 -18
- data/lib/multiarray/integral.rb +65 -1
- data/lib/multiarray/lambda.rb +19 -5
- data/lib/multiarray/list.rb +8 -0
- data/lib/multiarray/lookup.rb +8 -1
- data/lib/multiarray/lut.rb +96 -2
- data/lib/multiarray/methods.rb +13 -3
- data/lib/multiarray/multiarray.rb +11 -0
- data/lib/multiarray/node.rb +52 -9
- data/lib/multiarray/operations.rb +118 -15
- data/lib/multiarray/pointer.rb +35 -1
- data/lib/multiarray/rgb.rb +139 -14
- data/lib/multiarray/sequence.rb +140 -2
- data/lib/multiarray/shortcuts.rb +76 -30
- data/lib/multiarray/store.rb +54 -0
- data/lib/multiarray/variable.rb +19 -0
- data/test/tc_lazy.rb +9 -0
- metadata +3 -3
data/lib/multiarray/pointer.rb
CHANGED
@@ -14,8 +14,10 @@
|
|
14
14
|
# You should have received a copy of the GNU General Public License
|
15
15
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
16
|
|
17
|
+
# Namespace of Hornetseye computer vision library
|
17
18
|
module Hornetseye
|
18
19
|
|
20
|
+
# Class for representing native pointer types
|
19
21
|
class Pointer_ < Node
|
20
22
|
|
21
23
|
class << self
|
@@ -71,7 +73,7 @@ module Hornetseye
|
|
71
73
|
target == other.target
|
72
74
|
end
|
73
75
|
|
74
|
-
# Compute hash value for this class
|
76
|
+
# Compute hash value for this class
|
75
77
|
#
|
76
78
|
# @return [Fixnum] Hash value
|
77
79
|
#
|
@@ -134,10 +136,16 @@ module Hornetseye
|
|
134
136
|
|
135
137
|
end
|
136
138
|
|
139
|
+
# Constructor for pointer object
|
140
|
+
#
|
141
|
+
# @param [Malloc,List] value Initial value for pointer object.
|
137
142
|
def initialize( value = self.class.default )
|
138
143
|
@value = value
|
139
144
|
end
|
140
145
|
|
146
|
+
# Get access to storage object
|
147
|
+
#
|
148
|
+
# @return [Malloc,List] The object used to store the data.
|
141
149
|
def memory
|
142
150
|
@value
|
143
151
|
end
|
@@ -156,6 +164,13 @@ module Hornetseye
|
|
156
164
|
return [ variable ], [ self ], variable
|
157
165
|
end
|
158
166
|
|
167
|
+
# Get unique descriptor of this object
|
168
|
+
#
|
169
|
+
# @param [Hash] hash Labels for any variables.
|
170
|
+
#
|
171
|
+
# @return [String] Descriptor of this object,
|
172
|
+
#
|
173
|
+
# @private
|
159
174
|
def descriptor( hash )
|
160
175
|
"#{self.class.to_s}(#{@value.to_s})"
|
161
176
|
end
|
@@ -199,6 +214,14 @@ module Hornetseye
|
|
199
214
|
end
|
200
215
|
end
|
201
216
|
|
217
|
+
# Skip elements of an array
|
218
|
+
#
|
219
|
+
# @param [Variable] index Variable identifying index of array.
|
220
|
+
# @param [Node] start Wrapped integer with number of elements to skip.
|
221
|
+
#
|
222
|
+
# @return [Node] Lookup object with elements skipped.
|
223
|
+
#
|
224
|
+
# @private
|
202
225
|
def skip( index, start )
|
203
226
|
self
|
204
227
|
end
|
@@ -228,6 +251,17 @@ module Hornetseye
|
|
228
251
|
|
229
252
|
end
|
230
253
|
|
254
|
+
# Create a class deriving from +Pointer_+
|
255
|
+
#
|
256
|
+
# Create a class deriving from +Pointer_+. The parameter +target+ is assigned to
|
257
|
+
# the corresponding attribute of the resulting class.
|
258
|
+
#
|
259
|
+
# @param [Class] target The native type of the complex components.
|
260
|
+
#
|
261
|
+
# @return [Class] A class deriving from +Pointer_+.
|
262
|
+
#
|
263
|
+
# @see Pointer_
|
264
|
+
# @see Pointer_.target
|
231
265
|
def Pointer( target )
|
232
266
|
p = Class.new Pointer_
|
233
267
|
p.target = target
|
data/lib/multiarray/rgb.rb
CHANGED
@@ -31,6 +31,8 @@ module Hornetseye
|
|
31
31
|
#
|
32
32
|
# @return [Boolean] Returns +false+ if Ruby object requires
|
33
33
|
# coercion.
|
34
|
+
#
|
35
|
+
# @private
|
34
36
|
def generic?( value )
|
35
37
|
value.is_a?( Numeric ) or value.is_a?( GCCValue )
|
36
38
|
end
|
@@ -40,6 +42,10 @@ module Hornetseye
|
|
40
42
|
# This method uses meta-programming to define channel-wise unary operations.
|
41
43
|
#
|
42
44
|
# @param [Symbol,String] op Operation to define channel-wise operation.
|
45
|
+
#
|
46
|
+
# @return [Proc] The new method.
|
47
|
+
#
|
48
|
+
# @private
|
43
49
|
def define_unary_op( op )
|
44
50
|
define_method( op ) do
|
45
51
|
RGB.new r.send( op ), g.send( op ), b.send( op )
|
@@ -51,6 +57,10 @@ module Hornetseye
|
|
51
57
|
# This method uses meta-programming to define channel-wise binary operations.
|
52
58
|
#
|
53
59
|
# @param [Symbol,String] op Operation to define channel-wise operation.
|
60
|
+
#
|
61
|
+
# @return [Proc] The new method.
|
62
|
+
#
|
63
|
+
# @private
|
54
64
|
def define_binary_op( op )
|
55
65
|
define_method( op ) do |other|
|
56
66
|
if other.is_a? RGB
|
@@ -94,14 +104,14 @@ module Hornetseye
|
|
94
104
|
@r, @g, @b = r, g, b
|
95
105
|
end
|
96
106
|
|
97
|
-
# Return string with information about this object
|
107
|
+
# Return string with information about this object
|
98
108
|
#
|
99
109
|
# @return [String] Returns a string (e.g. "RGB(1,2,3)").
|
100
110
|
def inspect
|
101
111
|
"RGB(#{@r.inspect},#{@g.inspect},#{@b.inspect})"
|
102
112
|
end
|
103
113
|
|
104
|
-
# Return string with information about this object
|
114
|
+
# Return string with information about this object
|
105
115
|
#
|
106
116
|
# @return [String] Returns a string (e.g. "RGB(1,2,3)").
|
107
117
|
def to_s
|
@@ -119,6 +129,13 @@ module Hornetseye
|
|
119
129
|
@r, @g, @b = value.r, value.g, value.b
|
120
130
|
end
|
121
131
|
|
132
|
+
# Coerce with other object
|
133
|
+
#
|
134
|
+
# @param [RGB] other Other object.
|
135
|
+
#
|
136
|
+
# @return [Array<RGB>] Result of coercion.
|
137
|
+
#
|
138
|
+
# @private
|
122
139
|
def coerce( other )
|
123
140
|
if other.is_a? RGB
|
124
141
|
return other, self
|
@@ -127,6 +144,11 @@ module Hornetseye
|
|
127
144
|
end
|
128
145
|
end
|
129
146
|
|
147
|
+
# This operation has no effect
|
148
|
+
#
|
149
|
+
# @return [InternalComplex] Returns +self+.
|
150
|
+
#
|
151
|
+
# @private
|
130
152
|
def +@
|
131
153
|
self
|
132
154
|
end
|
@@ -150,14 +172,32 @@ module Hornetseye
|
|
150
172
|
define_binary_op :minor
|
151
173
|
define_binary_op :major
|
152
174
|
|
175
|
+
# Check whether value is equal to zero
|
176
|
+
#
|
177
|
+
# @return [Boolean,GCCValue] The result.
|
178
|
+
#
|
179
|
+
# @private
|
153
180
|
def zero?
|
154
181
|
@r.zero?.and( @g.zero? ).and( @b.zero? )
|
155
182
|
end
|
156
183
|
|
184
|
+
# Check whether value is not equal to zero
|
185
|
+
#
|
186
|
+
# @return [Boolean,GCCValue] The result.
|
187
|
+
#
|
188
|
+
# @private
|
157
189
|
def nonzero?
|
158
190
|
@r.nonzero?.or( @g.nonzero? ).or( @b.nonzero? )
|
159
191
|
end
|
160
192
|
|
193
|
+
# Test on equality
|
194
|
+
#
|
195
|
+
# @param [Object] other Object to compare with.
|
196
|
+
#
|
197
|
+
# @return [Boolean] Returns boolean indicating whether objects are
|
198
|
+
# equal or not.
|
199
|
+
#
|
200
|
+
# @private
|
161
201
|
def ==( other )
|
162
202
|
if other.is_a? RGB
|
163
203
|
@r.eq( other.r ).and( @g.eq( other.g ) ).and( @b.eq( other.b ) )
|
@@ -183,6 +223,7 @@ end
|
|
183
223
|
|
184
224
|
module Hornetseye
|
185
225
|
|
226
|
+
# Class for representing native RGB values
|
186
227
|
class RGB_ < Composite
|
187
228
|
|
188
229
|
class << self
|
@@ -190,6 +231,12 @@ module Hornetseye
|
|
190
231
|
# Set base class attribute
|
191
232
|
#
|
192
233
|
# Sets number of elements to three.
|
234
|
+
#
|
235
|
+
# @param [Class] subclass The class inheriting from +RGB_+.
|
236
|
+
#
|
237
|
+
# @return The return value should be ignored.
|
238
|
+
#
|
239
|
+
# @private
|
193
240
|
def inherited( subclass )
|
194
241
|
subclass.num_elements = 3
|
195
242
|
end
|
@@ -216,22 +263,30 @@ module Hornetseye
|
|
216
263
|
RGB.new 0, 0, 0
|
217
264
|
end
|
218
265
|
|
266
|
+
# Identifier array used internally
|
267
|
+
#
|
268
|
+
# @private
|
269
|
+
IDENTIFIER = { BYTE => 'BYTERGB',
|
270
|
+
UBYTE => 'UBYTERGB',
|
271
|
+
SINT => 'SINTRGB',
|
272
|
+
USINT => 'USINTRGB',
|
273
|
+
INT => 'INTRGB',
|
274
|
+
UINT => 'UINTRGB',
|
275
|
+
LONG => 'LONGRGB',
|
276
|
+
ULONG => 'ULONGRGB',
|
277
|
+
SFLOAT => 'SFLOATRGB',
|
278
|
+
DFLOAT => 'DFLOATRGB' }
|
279
|
+
|
219
280
|
# Diplay information about this class
|
220
281
|
#
|
221
282
|
# @return [String] Text with information about this class (e.g. "DFLOATRGB").
|
222
283
|
def inspect
|
223
284
|
unless element_type.nil?
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
UINT => 'UINTRGB',
|
230
|
-
LONG => 'LONGRGB',
|
231
|
-
ULONG => 'ULONGRGB',
|
232
|
-
SFLOAT => 'SFLOATRGB',
|
233
|
-
DFLOAT => 'DFLOATRGB' }[ element_type ] ||
|
234
|
-
"RGB(#{element_type.inspect})"
|
285
|
+
retval = IDENTIFIER[ element_type ] || "RGB(#{element_type.inspect})"
|
286
|
+
( class << self; self; end ).instance_eval do
|
287
|
+
define_method( :inspect ) { retval }
|
288
|
+
end
|
289
|
+
retval
|
235
290
|
else
|
236
291
|
super
|
237
292
|
end
|
@@ -299,7 +354,7 @@ module Hornetseye
|
|
299
354
|
element_type == other.element_type
|
300
355
|
end
|
301
356
|
|
302
|
-
# Compute hash value for this class
|
357
|
+
# Compute hash value for this class
|
303
358
|
#
|
304
359
|
# @return [Fixnum] Hash value
|
305
360
|
#
|
@@ -319,12 +374,18 @@ module Hornetseye
|
|
319
374
|
self == other
|
320
375
|
end
|
321
376
|
|
377
|
+
# Check whether this object is an RGB value
|
378
|
+
#
|
379
|
+
# @return [Boolean] Returns +true+.
|
322
380
|
def rgb?
|
323
381
|
true
|
324
382
|
end
|
325
383
|
|
326
384
|
end
|
327
385
|
|
386
|
+
# Constructor for native RGB value
|
387
|
+
#
|
388
|
+
# @param [RGB] value Initial RGB value.
|
328
389
|
def initialize( value = self.class.default )
|
329
390
|
if Thread.current[ :function ].nil? or
|
330
391
|
[ value.r, value.g, value.b ].all? { |c| c.is_a? GCCValue }
|
@@ -390,6 +451,11 @@ module Hornetseye
|
|
390
451
|
[ @value.r, @value.g, @value.b ]
|
391
452
|
end
|
392
453
|
|
454
|
+
# Namespace containing method for matching elements of type RGB_
|
455
|
+
#
|
456
|
+
# @see RGB_
|
457
|
+
#
|
458
|
+
# @private
|
393
459
|
module Match
|
394
460
|
|
395
461
|
# Method for matching elements of type RGB_
|
@@ -455,6 +521,9 @@ module Hornetseye
|
|
455
521
|
define_unary_op :g, :scalar
|
456
522
|
define_unary_op :b, :scalar
|
457
523
|
|
524
|
+
# Fast extraction for red channel of RGB array
|
525
|
+
#
|
526
|
+
# @return [Node] Array with red channel.
|
458
527
|
def r_with_decompose
|
459
528
|
if typecode == OBJECT or is_a?( Variable )
|
460
529
|
r_without_decompose
|
@@ -467,6 +536,11 @@ module Hornetseye
|
|
467
536
|
|
468
537
|
alias_method_chain :r, :decompose
|
469
538
|
|
539
|
+
# Assignment for red channel values of RGB array
|
540
|
+
#
|
541
|
+
# @param [Object] Value or array of values to assign to red channel.
|
542
|
+
#
|
543
|
+
# @return [Object] Returns +value+.
|
470
544
|
def r=( value )
|
471
545
|
if typecode < RGB_
|
472
546
|
decompose( 0 )[] = value
|
@@ -479,6 +553,9 @@ module Hornetseye
|
|
479
553
|
end
|
480
554
|
end
|
481
555
|
|
556
|
+
# Fast extraction for green channel of RGB array
|
557
|
+
#
|
558
|
+
# @return [Node] Array with green channel.
|
482
559
|
def g_with_decompose
|
483
560
|
if typecode == OBJECT or is_a?( Variable )
|
484
561
|
g_without_decompose
|
@@ -491,6 +568,11 @@ module Hornetseye
|
|
491
568
|
|
492
569
|
alias_method_chain :g, :decompose
|
493
570
|
|
571
|
+
# Assignment for green channel values of RGB array
|
572
|
+
#
|
573
|
+
# @param [Object] Value or array of values to assign to green channel.
|
574
|
+
#
|
575
|
+
# @return [Object] Returns +value+.
|
494
576
|
def g=( value )
|
495
577
|
if typecode < RGB_
|
496
578
|
decompose( 1 )[] = value
|
@@ -503,6 +585,9 @@ module Hornetseye
|
|
503
585
|
end
|
504
586
|
end
|
505
587
|
|
588
|
+
# Fast extraction for blue channel of RGB array
|
589
|
+
#
|
590
|
+
# @return [Node] Array with blue channel.
|
506
591
|
def b_with_decompose
|
507
592
|
if typecode == OBJECT or is_a?( Variable )
|
508
593
|
b_without_decompose
|
@@ -515,6 +600,11 @@ module Hornetseye
|
|
515
600
|
|
516
601
|
alias_method_chain :b, :decompose
|
517
602
|
|
603
|
+
# Assignment for blue channel values of RGB array
|
604
|
+
#
|
605
|
+
# @param [Object] Value or array of values to assign to blue channel.
|
606
|
+
#
|
607
|
+
# @return [Object] Returns +value+.
|
518
608
|
def b=( value )
|
519
609
|
if typecode < RGB_
|
520
610
|
decompose( 2 )[] = value
|
@@ -529,6 +619,25 @@ module Hornetseye
|
|
529
619
|
|
530
620
|
end
|
531
621
|
|
622
|
+
# Create a class deriving from +RGB_+ or instantiate an +RGB+ object
|
623
|
+
#
|
624
|
+
# @overload RGB( element_type )
|
625
|
+
# Create a class deriving from +RGB_+. The parameters +element_type+ is
|
626
|
+
# assigned to the corresponding attribute of the resulting class.
|
627
|
+
# @param [Class] element_type Element type of native RGB value.
|
628
|
+
# @return [Class] A class deriving from +RGB_+.
|
629
|
+
#
|
630
|
+
# @overload RGB( r, g, b )
|
631
|
+
# This is a shortcut for +RGB.new( r, g, b )+.
|
632
|
+
# @param [Object] r Initial value for red channel.
|
633
|
+
# @param [Object] g Initial value for green channel.
|
634
|
+
# @param [Object] b Initial value for blue channel.
|
635
|
+
# @return [RGB] The RGB value.
|
636
|
+
#
|
637
|
+
# @return [Class,RGB] A class deriving from +RGB_+ or an RGB value.
|
638
|
+
#
|
639
|
+
# @see RGB_
|
640
|
+
# @see RGB_.element_type
|
532
641
|
def RGB( arg, g = nil, b = nil )
|
533
642
|
if g.nil? and b.nil?
|
534
643
|
retval = Class.new RGB_
|
@@ -541,24 +650,34 @@ module Hornetseye
|
|
541
650
|
|
542
651
|
module_function :RGB
|
543
652
|
|
653
|
+
# 24-bit unsigned RGB-triplet
|
544
654
|
BYTERGB = RGB BYTE
|
545
655
|
|
656
|
+
# 24-bit signed RGB-triplet
|
546
657
|
UBYTERGB = RGB UBYTE
|
547
658
|
|
659
|
+
# 48-bit unsigned RGB-triplet
|
548
660
|
SINTRGB = RGB SINT
|
549
661
|
|
662
|
+
# 48-bit signed RGB-triplet
|
550
663
|
USINTRGB = RGB USINT
|
551
664
|
|
665
|
+
# 96-bit unsigned RGB-triplet
|
552
666
|
INTRGB = RGB INT
|
553
667
|
|
668
|
+
# 96-bit signed RGB-triplet
|
554
669
|
UINTRGB = RGB UINT
|
555
670
|
|
671
|
+
# 192-bit unsigned RGB-triplet
|
556
672
|
LONGRGB = RGB LONG
|
557
673
|
|
674
|
+
# 192-bit signed RGB-triplet
|
558
675
|
ULONGRGB = RGB ULONG
|
559
676
|
|
677
|
+
# single precision RGB-triplet
|
560
678
|
SFLOATRGB = RGB SFLOAT
|
561
679
|
|
680
|
+
# double precision RGB-triplet
|
562
681
|
DFLOATRGB = RGB DFLOAT
|
563
682
|
|
564
683
|
# Shortcut for constructor
|
@@ -708,6 +827,12 @@ class Fixnum
|
|
708
827
|
|
709
828
|
if method_defined? :rpower
|
710
829
|
|
830
|
+
# +**+ is modified to work with RGB values
|
831
|
+
#
|
832
|
+
# @param [Object] other Second operand for binary operation.
|
833
|
+
# @return [Object] Result of binary operation.
|
834
|
+
#
|
835
|
+
# @private
|
711
836
|
def power_with_rgb( other )
|
712
837
|
if other.is_a? Hornetseye::RGB
|
713
838
|
x, y = other.coerce self
|
data/lib/multiarray/sequence.rb
CHANGED
@@ -32,6 +32,15 @@ module Hornetseye
|
|
32
32
|
MultiArray.new typecode, size
|
33
33
|
end
|
34
34
|
|
35
|
+
# Import array from string
|
36
|
+
#
|
37
|
+
# Create an array from raw data provided as a string.
|
38
|
+
#
|
39
|
+
# @param [Class] typecode Type of the elements in the string.
|
40
|
+
# @param [String] string String with raw data.
|
41
|
+
# @param [Integer] size Size of array.
|
42
|
+
#
|
43
|
+
# @return [Node] One-dimensional array with imported data.
|
35
44
|
def import( typecode, string, size )
|
36
45
|
t = Hornetseye::Sequence typecode, size
|
37
46
|
if string.is_a? Malloc
|
@@ -95,6 +104,12 @@ module Hornetseye
|
|
95
104
|
end
|
96
105
|
end
|
97
106
|
|
107
|
+
# Create (lazy) index array
|
108
|
+
#
|
109
|
+
# @param [Integer] offset First value of array.
|
110
|
+
# @param [Integer] increment Increment for subsequent values.
|
111
|
+
#
|
112
|
+
# @return [Node] Lazy term generating the array.
|
98
113
|
def indgen( offset = 0, increment = 1 )
|
99
114
|
Hornetseye::lazy( num_elements ) do |i|
|
100
115
|
( element_type.size * increment * i +
|
@@ -102,6 +117,11 @@ module Hornetseye
|
|
102
117
|
end
|
103
118
|
end
|
104
119
|
|
120
|
+
# Construct native array from Ruby array
|
121
|
+
#
|
122
|
+
# @param [Array<Object>] args Array with Ruby values.
|
123
|
+
#
|
124
|
+
# @return [Node] Native array with specified values.
|
105
125
|
def []( *args )
|
106
126
|
retval = new
|
107
127
|
recursion = lambda do |element,args|
|
@@ -117,30 +137,51 @@ module Hornetseye
|
|
117
137
|
retval
|
118
138
|
end
|
119
139
|
|
140
|
+
# Get dimensions of array type
|
141
|
+
#
|
142
|
+
# @return [Array<Integer>]
|
120
143
|
def shape
|
121
144
|
element_type.shape + [ num_elements ]
|
122
145
|
end
|
123
146
|
|
147
|
+
# Get width of two-dimensional array type
|
148
|
+
#
|
149
|
+
# @return [Integer] Width of array.
|
124
150
|
def width
|
125
151
|
shape[0]
|
126
152
|
end
|
127
153
|
|
154
|
+
# Get height of two-dimensional array
|
155
|
+
#
|
156
|
+
# @return [Integer] Height of array.
|
128
157
|
def height
|
129
158
|
shape[1]
|
130
159
|
end
|
131
160
|
|
161
|
+
# Get size of array type
|
162
|
+
#
|
163
|
+
# @return [Integer] Size of array.
|
132
164
|
def size
|
133
165
|
num_elements * element_type.size
|
134
166
|
end
|
135
167
|
|
168
|
+
# Get storage size of array type
|
169
|
+
#
|
170
|
+
# @return [Integer] Storage size of array.
|
136
171
|
def storage_size
|
137
172
|
num_elements * element_type.storage_size
|
138
173
|
end
|
139
174
|
|
175
|
+
# Check whether type denotes an empty array
|
176
|
+
#
|
177
|
+
# @return [Boolean] Return +true+ for empty array.
|
140
178
|
def empty?
|
141
179
|
size == 0
|
142
180
|
end
|
143
181
|
|
182
|
+
# Get element type of array type
|
183
|
+
#
|
184
|
+
# @return [Class] Element type of array.
|
144
185
|
def typecode
|
145
186
|
element_type.typecode
|
146
187
|
end
|
@@ -163,26 +204,53 @@ module Hornetseye
|
|
163
204
|
self
|
164
205
|
end
|
165
206
|
|
207
|
+
# Get pointer type of delayed operation
|
208
|
+
#
|
209
|
+
# @return [Class] Type of result.
|
210
|
+
#
|
211
|
+
# @private
|
166
212
|
def pointer_type
|
167
213
|
self
|
168
214
|
end
|
169
215
|
|
216
|
+
# Get dimension of type of delayed operation
|
217
|
+
#
|
218
|
+
# @return [Integer] Number of dimensions.
|
170
219
|
def dimension
|
171
220
|
element_type.dimension + 1
|
172
221
|
end
|
173
222
|
|
223
|
+
# Check whether delayed operation will have colour
|
224
|
+
#
|
225
|
+
# @return [Boolean] Boolean indicating whether the array has elements of type
|
226
|
+
# RGB.
|
174
227
|
def rgb?
|
175
228
|
element_type.rgb?
|
176
229
|
end
|
177
230
|
|
231
|
+
# Get corresponding contiguous type
|
232
|
+
#
|
233
|
+
# @return [Class] Returns +self+.
|
234
|
+
#
|
235
|
+
# @private
|
178
236
|
def contiguous
|
179
237
|
self
|
180
238
|
end
|
181
239
|
|
240
|
+
# Get corresponding boolean type
|
241
|
+
#
|
242
|
+
# @return [Class] Returns type for array of boolean values.
|
243
|
+
#
|
244
|
+
# @private
|
182
245
|
def bool
|
183
246
|
Hornetseye::Sequence element_type.bool, num_elements
|
184
247
|
end
|
185
248
|
|
249
|
+
# Coerce and convert to boolean type
|
250
|
+
#
|
251
|
+
# @return [Class] Returns type for array of boolean values.
|
252
|
+
#
|
253
|
+
# @private
|
186
254
|
def coercion_bool( other )
|
187
255
|
coercion( other ).bool
|
188
256
|
end
|
@@ -190,10 +258,17 @@ module Hornetseye
|
|
190
258
|
# Get corresponding scalar type
|
191
259
|
#
|
192
260
|
# @return [Class] Returns type for array of scalars.
|
261
|
+
#
|
262
|
+
# @private
|
193
263
|
def scalar
|
194
264
|
Hornetseye::Sequence element_type.scalar, num_elements
|
195
265
|
end
|
196
266
|
|
267
|
+
# Get corresponding floating point type
|
268
|
+
#
|
269
|
+
# @return [Class] Returns type for array of floating point numbers.
|
270
|
+
#
|
271
|
+
# @private
|
197
272
|
def float_scalar
|
198
273
|
Hornetseye::Sequence element_type.float_scalar, num_elements
|
199
274
|
end
|
@@ -201,18 +276,35 @@ module Hornetseye
|
|
201
276
|
# Get corresponding maximum integer type
|
202
277
|
#
|
203
278
|
# @return [Class] Returns type based on maximum integers.
|
279
|
+
#
|
280
|
+
# @private
|
204
281
|
def maxint
|
205
282
|
Hornetseye::Sequence element_type.maxint, num_elements
|
206
283
|
end
|
207
284
|
|
285
|
+
# Coerce and convert to maximum integer type
|
286
|
+
#
|
287
|
+
# @return [Class] Returns type based on maximum integers.
|
288
|
+
#
|
289
|
+
# @private
|
208
290
|
def coercion_maxint( other )
|
209
291
|
coercion( other ).maxint
|
210
292
|
end
|
211
293
|
|
294
|
+
# Get corresponding byte type
|
295
|
+
#
|
296
|
+
# @return [Class] Returns type based on byte.
|
297
|
+
#
|
298
|
+
# @private
|
212
299
|
def byte
|
213
300
|
Hornetseye::Sequence element_type.byte, num_elements
|
214
301
|
end
|
215
302
|
|
303
|
+
# Coerce and convert to byte type
|
304
|
+
#
|
305
|
+
# @return [Class] Returns type based on byte.
|
306
|
+
#
|
307
|
+
# @private
|
216
308
|
def coercion_byte( other )
|
217
309
|
coercion( other ).byte
|
218
310
|
end
|
@@ -226,31 +318,56 @@ module Hornetseye
|
|
226
318
|
Hornetseye::Sequence element_type.float, num_elements
|
227
319
|
end
|
228
320
|
|
321
|
+
# Coerce and convert to type based on floating point numbers
|
322
|
+
#
|
323
|
+
# @return [Class] Corresponding type based on floating point numbers.
|
324
|
+
#
|
325
|
+
# @private
|
229
326
|
def floating( other )
|
230
327
|
coercion( other ).float
|
231
328
|
end
|
232
329
|
|
330
|
+
# Coerce with two other types
|
331
|
+
#
|
332
|
+
# @return [Class] Result of coercion.
|
333
|
+
#
|
334
|
+
# @private
|
233
335
|
def cond( a, b )
|
234
336
|
t = a.coercion b
|
235
337
|
Hornetseye::MultiArray( t.typecode, *shape ).coercion t
|
236
338
|
end
|
237
339
|
|
340
|
+
# Replace element type
|
341
|
+
#
|
342
|
+
# @return [Class] Result of conversion.
|
343
|
+
#
|
344
|
+
# @private
|
238
345
|
def to_type( dest )
|
239
346
|
Hornetseye::Sequence element_type.to_type( dest ), num_elements
|
240
347
|
end
|
241
348
|
|
349
|
+
# Display this type
|
350
|
+
#
|
351
|
+
# @return [String] String with description of this type.
|
242
352
|
def inspect
|
243
353
|
if element_type and num_elements
|
244
354
|
if dimension == 1
|
245
|
-
"Sequence(#{typecode.inspect},#{num_elements.inspect})"
|
355
|
+
retval = "Sequence(#{typecode.inspect},#{num_elements.inspect})"
|
246
356
|
else
|
247
|
-
"MultiArray(#{typecode.inspect},#{shape.join ','})"
|
357
|
+
retval = "MultiArray(#{typecode.inspect},#{shape.join ','})"
|
248
358
|
end
|
359
|
+
( class << self; self; end ).instance_eval do
|
360
|
+
define_method( :inspect ) { retval }
|
361
|
+
end
|
362
|
+
retval
|
249
363
|
else
|
250
364
|
'MultiArray(?,?)'
|
251
365
|
end
|
252
366
|
end
|
253
367
|
|
368
|
+
# Compute unique descriptor
|
369
|
+
#
|
370
|
+
# @return [String] Unique descriptor of this type.
|
254
371
|
def to_s
|
255
372
|
descriptor( {} )
|
256
373
|
end
|
@@ -317,10 +434,18 @@ module Hornetseye
|
|
317
434
|
end
|
318
435
|
end
|
319
436
|
|
437
|
+
# Instantiate array of this type
|
438
|
+
#
|
439
|
+
# @param [Malloc,List] memory Object for storing array elements.
|
440
|
+
#
|
441
|
+
# @return [Node] The array expression.
|
320
442
|
def new( memory = nil )
|
321
443
|
MultiArray.new typecode, *( shape + [ :memory => memory ] )
|
322
444
|
end
|
323
445
|
|
446
|
+
# Check whether this array expression allows compilation
|
447
|
+
#
|
448
|
+
# @return [Boolean] Returns +true+ if this expression supports compilation.
|
324
449
|
def compilable?
|
325
450
|
element_type.compilable?
|
326
451
|
end
|
@@ -380,6 +505,19 @@ module Hornetseye
|
|
380
505
|
|
381
506
|
end
|
382
507
|
|
508
|
+
# Create a class deriving from +Sequence_+
|
509
|
+
#
|
510
|
+
# Create a class deriving from +Sequence_+. The parameters +element_type+ and
|
511
|
+
# +num_elements+ are assigned to the corresponding attribute of the resulting class.
|
512
|
+
#
|
513
|
+
# @param [Class] element_type The element type of the native array.
|
514
|
+
# @param [Integer] num_elements The number of elements.
|
515
|
+
#
|
516
|
+
# @return [Class] A class deriving from +Sequence_+.
|
517
|
+
#
|
518
|
+
# @see Sequence_
|
519
|
+
# @see Sequence_.element_type
|
520
|
+
# @see Sequence_.num_elements
|
383
521
|
def Sequence( element_type, num_elements )
|
384
522
|
retval = Class.new Sequence_
|
385
523
|
retval.element_type = element_type
|