multiarray 0.22.0 → 0.23.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/multiarray.rb +53 -16
- data/lib/multiarray/bool.rb +1 -1
- data/lib/multiarray/complex.rb +76 -68
- data/lib/multiarray/components.rb +11 -10
- data/lib/multiarray/composite.rb +1 -1
- data/lib/multiarray/diagonal.rb +11 -12
- data/lib/multiarray/element.rb +3 -3
- data/lib/multiarray/elementwise.rb +14 -14
- data/lib/multiarray/field.rb +380 -0
- data/lib/multiarray/float.rb +10 -10
- data/lib/multiarray/gcccache.rb +1 -1
- data/lib/multiarray/gcccontext.rb +35 -54
- data/lib/multiarray/gccfunction.rb +12 -19
- data/lib/multiarray/gcctype.rb +1 -1
- data/lib/multiarray/gccvalue.rb +63 -43
- data/lib/multiarray/histogram.rb +17 -19
- data/lib/multiarray/index.rb +7 -8
- data/lib/multiarray/inject.rb +11 -12
- data/lib/multiarray/int.rb +12 -11
- data/lib/multiarray/integral.rb +11 -12
- data/lib/multiarray/lambda.rb +23 -18
- data/lib/multiarray/list.rb +1 -1
- data/lib/multiarray/lookup.rb +18 -13
- data/lib/multiarray/lut.rb +13 -16
- data/lib/multiarray/malloc.rb +1 -1
- data/lib/multiarray/mask.rb +11 -8
- data/lib/multiarray/methods.rb +10 -10
- data/lib/multiarray/multiarray.rb +15 -44
- data/lib/multiarray/node.rb +64 -138
- data/lib/multiarray/object.rb +2 -6
- data/lib/multiarray/operations.rb +116 -134
- data/lib/multiarray/pointer.rb +7 -19
- data/lib/multiarray/random.rb +11 -8
- data/lib/multiarray/rgb.rb +53 -53
- data/lib/multiarray/sequence.rb +11 -496
- data/lib/multiarray/shortcuts.rb +4 -4
- data/lib/multiarray/store.rb +14 -11
- data/lib/multiarray/unmask.rb +10 -7
- data/lib/multiarray/variable.rb +11 -3
- data/test/tc_bool.rb +0 -8
- data/test/tc_compile.rb +72 -0
- data/test/tc_float.rb +0 -8
- data/test/tc_int.rb +0 -8
- data/test/tc_lazy.rb +22 -3
- data/test/tc_multiarray.rb +100 -126
- data/test/tc_object.rb +0 -16
- data/test/tc_rgb.rb +0 -16
- data/test/tc_sequence.rb +151 -165
- data/test/ts_multiarray.rb +2 -0
- metadata +7 -4
data/lib/multiarray/pointer.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# multiarray - Lazy multi-dimensional arrays for Ruby
|
2
|
-
# Copyright (C) 2010 Jan Wedekind
|
2
|
+
# Copyright (C) 2010, 2011 Jan Wedekind
|
3
3
|
#
|
4
4
|
# This program is free software: you can redistribute it and/or modify
|
5
5
|
# it under the terms of the GNU General Public License as published by
|
@@ -109,22 +109,6 @@ module Hornetseye
|
|
109
109
|
target.basetype
|
110
110
|
end
|
111
111
|
|
112
|
-
# Get type of result of delayed operation
|
113
|
-
#
|
114
|
-
# @return [Class] Type of result.
|
115
|
-
#
|
116
|
-
# @private
|
117
|
-
def array_type
|
118
|
-
target
|
119
|
-
end
|
120
|
-
|
121
|
-
# Get corresponding pointer type
|
122
|
-
#
|
123
|
-
# @return [Class] Returns +self+.
|
124
|
-
def pointer_type
|
125
|
-
self
|
126
|
-
end
|
127
|
-
|
128
112
|
# Check whether objects of this class are finalised computations
|
129
113
|
#
|
130
114
|
# @return [Boolean] Returns +false+.
|
@@ -143,6 +127,10 @@ module Hornetseye
|
|
143
127
|
@value = value
|
144
128
|
end
|
145
129
|
|
130
|
+
def sexp?
|
131
|
+
true
|
132
|
+
end
|
133
|
+
|
146
134
|
# Get access to storage object
|
147
135
|
#
|
148
136
|
# @return [Malloc,List] The object used to store the data.
|
@@ -209,7 +197,7 @@ module Hornetseye
|
|
209
197
|
# @private
|
210
198
|
def store( value )
|
211
199
|
result = value.simplify
|
212
|
-
self.class.target.new(
|
200
|
+
self.class.target.new(result.get).write @value
|
213
201
|
result
|
214
202
|
end
|
215
203
|
|
@@ -221,7 +209,7 @@ module Hornetseye
|
|
221
209
|
#
|
222
210
|
# @private
|
223
211
|
def demand
|
224
|
-
self.class.target.fetch(
|
212
|
+
self.class.target.fetch(@value).simplify
|
225
213
|
end
|
226
214
|
|
227
215
|
# Lookup element of an array
|
data/lib/multiarray/random.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# multiarray - Lazy multi-dimensional arrays for Ruby
|
2
|
-
# Copyright (C) 2010 Jan Wedekind
|
2
|
+
# Copyright (C) 2010, 2011 Jan Wedekind
|
3
3
|
#
|
4
4
|
# This program is free software: you can redistribute it and/or modify
|
5
5
|
# it under the terms of the GNU General Public License as published by
|
@@ -29,6 +29,10 @@ module Hornetseye
|
|
29
29
|
@dest, @n = dest, n
|
30
30
|
end
|
31
31
|
|
32
|
+
def sexp?
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
32
36
|
# Get unique descriptor of this object
|
33
37
|
#
|
34
38
|
# @param [Hash] hash Labels for any variables.
|
@@ -40,13 +44,12 @@ module Hornetseye
|
|
40
44
|
"Random(#{@dest.descriptor( hash )},#{@n.descriptor( hash )})"
|
41
45
|
end
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
@dest.array_type
|
47
|
+
def typecode
|
48
|
+
@dest.typecode
|
49
|
+
end
|
50
|
+
|
51
|
+
def shape
|
52
|
+
@dest.shape
|
50
53
|
end
|
51
54
|
|
52
55
|
# Reevaluate computation
|
data/lib/multiarray/rgb.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# multiarray - Lazy multi-dimensional arrays for Ruby
|
2
|
-
# Copyright (C) 2010 Jan Wedekind
|
2
|
+
# Copyright (C) 2010, 2011 Jan Wedekind
|
3
3
|
#
|
4
4
|
# This program is free software: you can redistribute it and/or modify
|
5
5
|
# it under the terms of the GNU General Public License as published by
|
@@ -33,8 +33,8 @@ module Hornetseye
|
|
33
33
|
# coercion.
|
34
34
|
#
|
35
35
|
# @private
|
36
|
-
def generic?(
|
37
|
-
value.is_a?(
|
36
|
+
def generic?(value)
|
37
|
+
value.is_a?(Numeric) or value.is_a?(GCCValue)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Defines a unary operation
|
@@ -46,9 +46,9 @@ module Hornetseye
|
|
46
46
|
# @return [Proc] The new method.
|
47
47
|
#
|
48
48
|
# @private
|
49
|
-
def define_unary_op(
|
50
|
-
define_method
|
51
|
-
RGB.new r.send(
|
49
|
+
def define_unary_op(op)
|
50
|
+
define_method op do
|
51
|
+
RGB.new r.send(op), g.send(op), b.send(op)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -61,8 +61,8 @@ module Hornetseye
|
|
61
61
|
# @return [Proc] The new method.
|
62
62
|
#
|
63
63
|
# @private
|
64
|
-
def define_binary_op(
|
65
|
-
define_method
|
64
|
+
def define_binary_op(op)
|
65
|
+
define_method op do |other|
|
66
66
|
if other.is_a? RGB
|
67
67
|
RGB.new r.send( op, other.r ), g.send( op, other.g ),
|
68
68
|
b.send( op, other.b )
|
@@ -125,7 +125,7 @@ module Hornetseye
|
|
125
125
|
# @return [Object] Returns +value+.
|
126
126
|
#
|
127
127
|
# @private
|
128
|
-
def assign(
|
128
|
+
def assign(value)
|
129
129
|
@r, @g, @b = value.r, value.g, value.b
|
130
130
|
end
|
131
131
|
|
@@ -136,7 +136,7 @@ module Hornetseye
|
|
136
136
|
# @return [Array<RGB>] Result of coercion.
|
137
137
|
#
|
138
138
|
# @private
|
139
|
-
def coerce(
|
139
|
+
def coerce(other)
|
140
140
|
if other.is_a? RGB
|
141
141
|
return other, self
|
142
142
|
else
|
@@ -197,11 +197,11 @@ module Hornetseye
|
|
197
197
|
#
|
198
198
|
# @return [Boolean] Returns boolean indicating whether objects are
|
199
199
|
# equal or not.
|
200
|
-
def ==(
|
200
|
+
def ==(other)
|
201
201
|
if other.is_a? RGB
|
202
202
|
@r.eq( other.r ).and( @g.eq( other.g ) ).and( @b.eq( other.b ) )
|
203
203
|
elsif RGB.generic? other
|
204
|
-
@r.eq(
|
204
|
+
@r.eq(other).and( @g.eq(other) ).and( @b.eq(other) )
|
205
205
|
else
|
206
206
|
false
|
207
207
|
end
|
@@ -214,7 +214,7 @@ module Hornetseye
|
|
214
214
|
# @return [Node] An array with the three channel values as elements.
|
215
215
|
#
|
216
216
|
# @private
|
217
|
-
def decompose(
|
217
|
+
def decompose(i)
|
218
218
|
[ @r, @g, @b ][ i ]
|
219
219
|
end
|
220
220
|
|
@@ -238,10 +238,16 @@ module Hornetseye
|
|
238
238
|
# @return The return value should be ignored.
|
239
239
|
#
|
240
240
|
# @private
|
241
|
-
def inherited(
|
241
|
+
def inherited(subclass)
|
242
242
|
subclass.num_elements = 3
|
243
243
|
end
|
244
244
|
|
245
|
+
def inherit(element_type)
|
246
|
+
retval = Class.new self
|
247
|
+
retval.element_type = element_type
|
248
|
+
retval
|
249
|
+
end
|
250
|
+
|
245
251
|
# Construct new object from arguments
|
246
252
|
#
|
247
253
|
# @param [Object] r Value for red channel.
|
@@ -283,11 +289,7 @@ module Hornetseye
|
|
283
289
|
# @return [String] Text with information about this class (e.g. "DFLOATRGB").
|
284
290
|
def inspect
|
285
291
|
unless element_type.nil?
|
286
|
-
|
287
|
-
( class << self; self; end ).instance_eval do
|
288
|
-
define_method( :inspect ) { retval }
|
289
|
-
end
|
290
|
-
retval
|
292
|
+
IDENTIFIER[ element_type ] || "RGB(#{element_type.inspect})"
|
291
293
|
else
|
292
294
|
super
|
293
295
|
end
|
@@ -318,11 +320,11 @@ module Hornetseye
|
|
318
320
|
# @return [Class] Result of coercion.
|
319
321
|
#
|
320
322
|
# @private
|
321
|
-
def coercion(
|
323
|
+
def coercion(other)
|
322
324
|
if other < RGB_
|
323
325
|
Hornetseye::RGB element_type.coercion( other.element_type )
|
324
326
|
elsif other < INT_ or other < FLOAT_
|
325
|
-
Hornetseye::RGB element_type.coercion(
|
327
|
+
Hornetseye::RGB element_type.coercion(other)
|
326
328
|
else
|
327
329
|
super other
|
328
330
|
end
|
@@ -335,11 +337,11 @@ module Hornetseye
|
|
335
337
|
# @return [Array<Class>] Result of coercion.
|
336
338
|
#
|
337
339
|
# @private
|
338
|
-
def coerce(
|
340
|
+
def coerce(other)
|
339
341
|
if other < RGB_
|
340
342
|
return other, self
|
341
343
|
elsif other < INT_ or other < FLOAT_
|
342
|
-
return Hornetseye::RGB(
|
344
|
+
return Hornetseye::RGB(other), self
|
343
345
|
else
|
344
346
|
super other
|
345
347
|
end
|
@@ -350,7 +352,7 @@ module Hornetseye
|
|
350
352
|
# @param [Object] other Object to compare with.
|
351
353
|
#
|
352
354
|
# @return [Boolean] Boolean indicating whether classes are equal.
|
353
|
-
def ==(
|
355
|
+
def ==(other)
|
354
356
|
other.is_a? Class and other < RGB_ and
|
355
357
|
element_type == other.element_type
|
356
358
|
end
|
@@ -371,7 +373,7 @@ module Hornetseye
|
|
371
373
|
# @return [Boolean] Returns +true+ if objects are equal.
|
372
374
|
#
|
373
375
|
# @private
|
374
|
-
def eql?(
|
376
|
+
def eql?(other)
|
375
377
|
self == other
|
376
378
|
end
|
377
379
|
|
@@ -423,7 +425,7 @@ module Hornetseye
|
|
423
425
|
# @return [Object] Returns +value+.
|
424
426
|
#
|
425
427
|
# @private
|
426
|
-
def assign(
|
428
|
+
def assign(value)
|
427
429
|
value = value.simplify
|
428
430
|
if @value.r.respond_to? :assign
|
429
431
|
@value.r.assign value.get.r
|
@@ -502,9 +504,9 @@ module Hornetseye
|
|
502
504
|
# @param [Class] context Other type to align with.
|
503
505
|
#
|
504
506
|
# @private
|
505
|
-
def align(
|
507
|
+
def align(context)
|
506
508
|
if self < RGB_
|
507
|
-
Hornetseye::RGB element_type.align(
|
509
|
+
Hornetseye::RGB element_type.align(context)
|
508
510
|
else
|
509
511
|
super context
|
510
512
|
end
|
@@ -516,7 +518,7 @@ module Hornetseye
|
|
516
518
|
|
517
519
|
end
|
518
520
|
|
519
|
-
|
521
|
+
class Node
|
520
522
|
|
521
523
|
define_unary_op :r, :scalar
|
522
524
|
define_unary_op :g, :scalar
|
@@ -527,7 +529,7 @@ module Hornetseye
|
|
527
529
|
#
|
528
530
|
# @return [Node] Array with red channel.
|
529
531
|
def r_with_decompose
|
530
|
-
if typecode == OBJECT or is_a?(
|
532
|
+
if typecode == OBJECT or is_a?(Variable) or Thread.current[:lazy]
|
531
533
|
r_without_decompose
|
532
534
|
elsif typecode < RGB_
|
533
535
|
decompose 0
|
@@ -543,7 +545,7 @@ module Hornetseye
|
|
543
545
|
# @param [Object] Value or array of values to assign to red channel.
|
544
546
|
#
|
545
547
|
# @return [Object] Returns +value+.
|
546
|
-
def r=(
|
548
|
+
def r=(value)
|
547
549
|
if typecode < RGB_
|
548
550
|
decompose( 0 )[] = value
|
549
551
|
elsif typecode == OBJECT
|
@@ -551,7 +553,7 @@ module Hornetseye
|
|
551
553
|
value * RGB.new( 1, 0, 0 ) + g * RGB.new( 0, 1, 0 ) + b * RGB.new( 0, 0, 1 )
|
552
554
|
end
|
553
555
|
else
|
554
|
-
raise "Cannot assign red channel to
|
556
|
+
raise "Cannot assign red channel to elements of type #{typecode.inspect}"
|
555
557
|
end
|
556
558
|
end
|
557
559
|
|
@@ -559,7 +561,7 @@ module Hornetseye
|
|
559
561
|
#
|
560
562
|
# @return [Node] Array with green channel.
|
561
563
|
def g_with_decompose
|
562
|
-
if typecode == OBJECT or is_a?(
|
564
|
+
if typecode == OBJECT or is_a?(Variable) or Thread.current[:lazy]
|
563
565
|
g_without_decompose
|
564
566
|
elsif typecode < RGB_
|
565
567
|
decompose 1
|
@@ -575,7 +577,7 @@ module Hornetseye
|
|
575
577
|
# @param [Object] Value or array of values to assign to green channel.
|
576
578
|
#
|
577
579
|
# @return [Object] Returns +value+.
|
578
|
-
def g=(
|
580
|
+
def g=(value)
|
579
581
|
if typecode < RGB_
|
580
582
|
decompose( 1 )[] = value
|
581
583
|
elsif typecode == OBJECT
|
@@ -583,7 +585,7 @@ module Hornetseye
|
|
583
585
|
r * RGB.new( 1, 0, 0 ) + value * RGB.new( 0, 1, 0 ) + b * RGB.new( 0, 0, 1 )
|
584
586
|
end
|
585
587
|
else
|
586
|
-
raise "Cannot assign green channel to
|
588
|
+
raise "Cannot assign green channel to elements of type #{typecode.inspect}"
|
587
589
|
end
|
588
590
|
end
|
589
591
|
|
@@ -591,7 +593,7 @@ module Hornetseye
|
|
591
593
|
#
|
592
594
|
# @return [Node] Array with blue channel.
|
593
595
|
def b_with_decompose
|
594
|
-
if typecode == OBJECT or is_a?(
|
596
|
+
if typecode == OBJECT or is_a?(Variable) or Thread.current[:lazy]
|
595
597
|
b_without_decompose
|
596
598
|
elsif typecode < RGB_
|
597
599
|
decompose 2
|
@@ -607,7 +609,7 @@ module Hornetseye
|
|
607
609
|
# @param [Object] Value or array of values to assign to blue channel.
|
608
610
|
#
|
609
611
|
# @return [Object] Returns +value+.
|
610
|
-
def b=(
|
612
|
+
def b=(value)
|
611
613
|
if typecode < RGB_
|
612
614
|
decompose( 2 )[] = value
|
613
615
|
elsif typecode == OBJECT
|
@@ -615,7 +617,7 @@ module Hornetseye
|
|
615
617
|
r * RGB.new( 1, 0, 0 ) + g * RGB.new( 0, 1, 0 ) + value * RGB.new( 0, 0, 1 )
|
616
618
|
end
|
617
619
|
else
|
618
|
-
raise "Cannot assign blue channel to
|
620
|
+
raise "Cannot assign blue channel to elements of type #{typecode.inspect}"
|
619
621
|
end
|
620
622
|
end
|
621
623
|
|
@@ -694,9 +696,7 @@ module Hornetseye
|
|
694
696
|
# @see RGB_.element_type
|
695
697
|
def RGB( arg, g = nil, b = nil )
|
696
698
|
if g.nil? and b.nil?
|
697
|
-
|
698
|
-
retval.element_type = arg
|
699
|
-
retval
|
699
|
+
RGB_.inherit arg
|
700
700
|
else
|
701
701
|
RGB.new arg, g, b
|
702
702
|
end
|
@@ -743,7 +743,7 @@ module Hornetseye
|
|
743
743
|
# @return [BYTERGB] The wrapped RGB value.
|
744
744
|
#
|
745
745
|
# @private
|
746
|
-
def BYTERGB(
|
746
|
+
def BYTERGB(value)
|
747
747
|
BYTERGB.new value
|
748
748
|
end
|
749
749
|
|
@@ -756,7 +756,7 @@ module Hornetseye
|
|
756
756
|
# @return [UBYTERGB] The wrapped RGB value.
|
757
757
|
#
|
758
758
|
# @private
|
759
|
-
def UBYTERGB(
|
759
|
+
def UBYTERGB(value)
|
760
760
|
UBYTERGB.new value
|
761
761
|
end
|
762
762
|
|
@@ -769,7 +769,7 @@ module Hornetseye
|
|
769
769
|
# @return [SINTRGB] The wrapped RGB value.
|
770
770
|
#
|
771
771
|
# @private
|
772
|
-
def SINTRGB(
|
772
|
+
def SINTRGB(value)
|
773
773
|
SINTRGB.new value
|
774
774
|
end
|
775
775
|
|
@@ -782,7 +782,7 @@ module Hornetseye
|
|
782
782
|
# @return [USINTRGB] The wrapped RGB value.
|
783
783
|
#
|
784
784
|
# @private
|
785
|
-
def USINTRGB(
|
785
|
+
def USINTRGB(value)
|
786
786
|
USINTRGB.new value
|
787
787
|
end
|
788
788
|
|
@@ -795,7 +795,7 @@ module Hornetseye
|
|
795
795
|
# @return [INTRGB] The wrapped RGB value.
|
796
796
|
#
|
797
797
|
# @private
|
798
|
-
def INTRGB(
|
798
|
+
def INTRGB(value)
|
799
799
|
INTRGB.new value
|
800
800
|
end
|
801
801
|
|
@@ -808,7 +808,7 @@ module Hornetseye
|
|
808
808
|
# @return [UINTRGB] The wrapped RGB value.
|
809
809
|
#
|
810
810
|
# @private
|
811
|
-
def UINTRGB(
|
811
|
+
def UINTRGB(value)
|
812
812
|
UINTRGB.new value
|
813
813
|
end
|
814
814
|
|
@@ -821,7 +821,7 @@ module Hornetseye
|
|
821
821
|
# @return [LONGRGB] The wrapped RGB value.
|
822
822
|
#
|
823
823
|
# @private
|
824
|
-
def LONGRGB(
|
824
|
+
def LONGRGB(value)
|
825
825
|
LONGRGB.new value
|
826
826
|
end
|
827
827
|
|
@@ -834,7 +834,7 @@ module Hornetseye
|
|
834
834
|
# @return [ULONGRGB] The wrapped RGB value.
|
835
835
|
#
|
836
836
|
# @private
|
837
|
-
def ULONGRGB(
|
837
|
+
def ULONGRGB(value)
|
838
838
|
ULONGRGB.new value
|
839
839
|
end
|
840
840
|
|
@@ -847,7 +847,7 @@ module Hornetseye
|
|
847
847
|
# @return [SFLOATRGB] The wrapped RGB value.
|
848
848
|
#
|
849
849
|
# @private
|
850
|
-
def SFLOATRGB(
|
850
|
+
def SFLOATRGB(value)
|
851
851
|
SFLOATRGB.new value
|
852
852
|
end
|
853
853
|
|
@@ -860,7 +860,7 @@ module Hornetseye
|
|
860
860
|
# @return [DFLOATRGB] The wrapped RGB value.
|
861
861
|
#
|
862
862
|
# @private
|
863
|
-
def DFLOATRGB(
|
863
|
+
def DFLOATRGB(value)
|
864
864
|
DFLOATRGB.new value
|
865
865
|
end
|
866
866
|
|
@@ -920,7 +920,7 @@ class Fixnum
|
|
920
920
|
# @return [Object] Result of binary operation.
|
921
921
|
#
|
922
922
|
# @private
|
923
|
-
def power_with_rgb(
|
923
|
+
def power_with_rgb(other)
|
924
924
|
if other.is_a? Hornetseye::RGB
|
925
925
|
x, y = other.coerce self
|
926
926
|
x ** y
|
@@ -937,7 +937,7 @@ end
|
|
937
937
|
|
938
938
|
module Math
|
939
939
|
|
940
|
-
def sqrt_with_rgb(
|
940
|
+
def sqrt_with_rgb(c)
|
941
941
|
if c.is_a? Hornetseye::RGB
|
942
942
|
Hornetseye::RGB.new sqrt( c.r ), sqrt( c.g ), sqrt( c.b )
|
943
943
|
else
|