multiarray 0.10.2 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/multiarray/complex.rb +6 -6
- data/lib/multiarray/elementwise.rb +2 -2
- data/lib/multiarray/lambda.rb +2 -2
- data/lib/multiarray/lookup.rb +3 -3
- data/lib/multiarray/lut.rb +2 -2
- data/lib/multiarray/node.rb +1 -1
- data/lib/multiarray/operations.rb +8 -8
- data/lib/multiarray/pointer.rb +2 -4
- data/lib/multiarray/rgb.rb +14 -14
- data/test/tc_multiarray.rb +3 -2
- data/test/tc_rgb.rb +0 -4
- data/test/tc_sequence.rb +1 -0
- metadata +2 -2
data/Rakefile
CHANGED
data/lib/multiarray/complex.rb
CHANGED
@@ -201,8 +201,8 @@ module Hornetseye
|
|
201
201
|
#
|
202
202
|
# @return [Node] Returns an array with the real and imaginary component as
|
203
203
|
# elements.
|
204
|
-
def decompose
|
205
|
-
|
204
|
+
def decompose( i )
|
205
|
+
[ @real, @imag ][ i ]
|
206
206
|
end
|
207
207
|
|
208
208
|
end
|
@@ -696,7 +696,7 @@ module Hornetseye
|
|
696
696
|
|
697
697
|
def real_with_decompose
|
698
698
|
if typecode < COMPLEX_
|
699
|
-
decompose
|
699
|
+
decompose 0
|
700
700
|
elsif typecode == OBJECT
|
701
701
|
real_without_decompose
|
702
702
|
else
|
@@ -708,7 +708,7 @@ module Hornetseye
|
|
708
708
|
|
709
709
|
def real=( value )
|
710
710
|
if typecode < COMPLEX_
|
711
|
-
decompose
|
711
|
+
decompose( 0 )[] = value
|
712
712
|
elsif typecode == OBJECT
|
713
713
|
self[] = Hornetseye::lazy do
|
714
714
|
value + imag * Complex::I
|
@@ -720,7 +720,7 @@ module Hornetseye
|
|
720
720
|
|
721
721
|
def imag_with_decompose
|
722
722
|
if typecode < COMPLEX_
|
723
|
-
decompose
|
723
|
+
decompose 1
|
724
724
|
elsif typecode == OBJECT
|
725
725
|
imag_without_decompose
|
726
726
|
else
|
@@ -732,7 +732,7 @@ module Hornetseye
|
|
732
732
|
|
733
733
|
def imag=( value )
|
734
734
|
if typecode < COMPLEX_
|
735
|
-
decompose
|
735
|
+
decompose( 1 )[] = value
|
736
736
|
elsif typecode == OBJECT
|
737
737
|
self[] = Hornetseye::lazy do
|
738
738
|
real + value * Complex::I
|
@@ -192,8 +192,8 @@ module Hornetseye
|
|
192
192
|
# This method decomposes composite elements into array.
|
193
193
|
#
|
194
194
|
# @return [Node] Result of decomposition.
|
195
|
-
def decompose
|
196
|
-
values = @values.collect { |value| value.decompose }
|
195
|
+
def decompose( i )
|
196
|
+
values = @values.collect { |value| value.decompose i }
|
197
197
|
self.class.new( *values ).demand
|
198
198
|
end
|
199
199
|
|
data/lib/multiarray/lambda.rb
CHANGED
@@ -164,8 +164,8 @@ module Hornetseye
|
|
164
164
|
# This method decomposes composite elements into array.
|
165
165
|
#
|
166
166
|
# @return [Node] Result of decomposition.
|
167
|
-
def decompose
|
168
|
-
Lambda.new @index, @term.decompose
|
167
|
+
def decompose( i )
|
168
|
+
Lambda.new @index, @term.decompose( i )
|
169
169
|
end
|
170
170
|
|
171
171
|
# Check whether this term is compilable
|
data/lib/multiarray/lookup.rb
CHANGED
@@ -153,11 +153,11 @@ module Hornetseye
|
|
153
153
|
# This method decomposes composite elements into array.
|
154
154
|
#
|
155
155
|
# @return [Node] Result of decomposition.
|
156
|
-
def decompose
|
156
|
+
def decompose( i )
|
157
157
|
if typecode < Composite
|
158
|
-
Lookup.new @p.decompose, @index, @stride * typecode.num_elements
|
158
|
+
Lookup.new @p.decompose( i ), @index, @stride * typecode.num_elements
|
159
159
|
else
|
160
|
-
Lookup.new @p.decompose, @index, @stride
|
160
|
+
Lookup.new @p.decompose( i ), @index, @stride
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
data/lib/multiarray/lut.rb
CHANGED
data/lib/multiarray/node.rb
CHANGED
@@ -395,11 +395,11 @@ module Hornetseye
|
|
395
395
|
left
|
396
396
|
end
|
397
397
|
|
398
|
-
def histogram_with_composite( *ret_shape )
|
399
|
-
|
400
|
-
end
|
398
|
+
#def histogram_with_composite( *ret_shape )
|
399
|
+
# decompose.histogram_without_composite *ret_shape
|
400
|
+
#end
|
401
401
|
|
402
|
-
alias_method_chain :histogram, :composite
|
402
|
+
#alias_method_chain :histogram, :composite
|
403
403
|
|
404
404
|
def lut( table, options = {} )
|
405
405
|
options = { :safe => true }.merge options
|
@@ -441,11 +441,11 @@ module Hornetseye
|
|
441
441
|
end
|
442
442
|
end
|
443
443
|
|
444
|
-
def lut_with_composite( table, options = {} )
|
445
|
-
|
446
|
-
end
|
444
|
+
#def lut_with_composite( table, options = {} )
|
445
|
+
# decompose.lut_without_composite table, options
|
446
|
+
#end
|
447
447
|
|
448
|
-
alias_method_chain :lut, :composite
|
448
|
+
#alias_method_chain :lut, :composite
|
449
449
|
|
450
450
|
def integral
|
451
451
|
left = pointer_type.new
|
data/lib/multiarray/pointer.rb
CHANGED
@@ -208,12 +208,10 @@ module Hornetseye
|
|
208
208
|
# This method decomposes composite elements into array.
|
209
209
|
#
|
210
210
|
# @return [Node] Result of decomposition.
|
211
|
-
def decompose
|
211
|
+
def decompose( i )
|
212
212
|
if self.class.target < Composite
|
213
213
|
pointer = Hornetseye::Pointer( self.class.target.element_type ).new @value
|
214
|
-
|
215
|
-
var = Variable.new Hornetseye::INDEX( INT.new( num_elements ) )
|
216
|
-
Lambda.new var, Lookup.new( pointer, var, INT.new( 1 ) )
|
214
|
+
pointer.lookup INT.new( i ), INT.new( 1 )
|
217
215
|
else
|
218
216
|
super
|
219
217
|
end
|
data/lib/multiarray/rgb.rb
CHANGED
@@ -173,8 +173,8 @@ module Hornetseye
|
|
173
173
|
# This method decomposes the RGB value into an array.
|
174
174
|
#
|
175
175
|
# @return [Node] An array with the three channel values as elements.
|
176
|
-
def decompose
|
177
|
-
|
176
|
+
def decompose( i )
|
177
|
+
[ @r, @g, @b ][ i ]
|
178
178
|
end
|
179
179
|
|
180
180
|
end
|
@@ -456,10 +456,10 @@ module Hornetseye
|
|
456
456
|
define_unary_op :b, :scalar
|
457
457
|
|
458
458
|
def r_with_decompose
|
459
|
-
if typecode
|
460
|
-
decompose.roll.element 0
|
461
|
-
elsif typecode == OBJECT
|
459
|
+
if typecode == OBJECT or is_a?( Variable )
|
462
460
|
r_without_decompose
|
461
|
+
elsif typecode < RGB_
|
462
|
+
decompose 0
|
463
463
|
else
|
464
464
|
self
|
465
465
|
end
|
@@ -469,7 +469,7 @@ module Hornetseye
|
|
469
469
|
|
470
470
|
def r=( value )
|
471
471
|
if typecode < RGB_
|
472
|
-
decompose
|
472
|
+
decompose( 0 )[] = value
|
473
473
|
elsif typecode == OBJECT
|
474
474
|
self[] = Hornetseye::lazy do
|
475
475
|
value * RGB.new( 1, 0, 0 ) + g * RGB.new( 0, 1, 0 ) + b * RGB.new( 0, 0, 1 )
|
@@ -480,10 +480,10 @@ module Hornetseye
|
|
480
480
|
end
|
481
481
|
|
482
482
|
def g_with_decompose
|
483
|
-
if typecode
|
484
|
-
decompose.roll.element 1
|
485
|
-
elsif typecode == OBJECT
|
483
|
+
if typecode == OBJECT or is_a?( Variable )
|
486
484
|
g_without_decompose
|
485
|
+
elsif typecode < RGB_
|
486
|
+
decompose 1
|
487
487
|
else
|
488
488
|
self
|
489
489
|
end
|
@@ -493,7 +493,7 @@ module Hornetseye
|
|
493
493
|
|
494
494
|
def g=( value )
|
495
495
|
if typecode < RGB_
|
496
|
-
decompose
|
496
|
+
decompose( 1 )[] = value
|
497
497
|
elsif typecode == OBJECT
|
498
498
|
self[] = Hornetseye::lazy do
|
499
499
|
r * RGB.new( 1, 0, 0 ) + value * RGB.new( 0, 1, 0 ) + b * RGB.new( 0, 0, 1 )
|
@@ -504,10 +504,10 @@ module Hornetseye
|
|
504
504
|
end
|
505
505
|
|
506
506
|
def b_with_decompose
|
507
|
-
if typecode
|
508
|
-
decompose.roll.element 2
|
509
|
-
elsif typecode == OBJECT
|
507
|
+
if typecode == OBJECT or is_a?( Variable )
|
510
508
|
b_without_decompose
|
509
|
+
elsif typecode < RGB_
|
510
|
+
decompose 2
|
511
511
|
else
|
512
512
|
self
|
513
513
|
end
|
@@ -517,7 +517,7 @@ module Hornetseye
|
|
517
517
|
|
518
518
|
def b=( value )
|
519
519
|
if typecode < RGB_
|
520
|
-
decompose
|
520
|
+
decompose( 2 )[] = value
|
521
521
|
elsif typecode == OBJECT
|
522
522
|
self[] = Hornetseye::lazy do
|
523
523
|
r * RGB.new( 1, 0, 0 ) + g * RGB.new( 0, 1, 0 ) + value * RGB.new( 0, 0, 1 )
|
data/test/tc_multiarray.rb
CHANGED
@@ -363,6 +363,7 @@ class TC_MultiArray < Test::Unit::TestCase
|
|
363
363
|
def test_collect
|
364
364
|
assert_equal M[ [ 2, 3, 4 ], [ 5, 6, 7 ] ],
|
365
365
|
M[ [ 1, 2, 3 ], [ 4, 5, 6 ] ].collect { |x| x + 1 }
|
366
|
+
assert_equal M[ [ 6 ] ], M[ [ C( 1, 2, 3 ) ] ].collect { |x| x.r + x.g + x.b }
|
366
367
|
end
|
367
368
|
|
368
369
|
def test_sum
|
@@ -428,8 +429,8 @@ class TC_MultiArray < Test::Unit::TestCase
|
|
428
429
|
M[ [ 1, 2 ], [ 3, 3 ] ].histogram( 5, :target => I )
|
429
430
|
assert_equal M( I, 2, 2 )[ [ 1, 0 ], [ 1, 1 ] ],
|
430
431
|
M[ [ 0, 0 ], [ 0, 1 ], [ 1, 1 ] ].histogram( 2, 2, :target => I )
|
431
|
-
assert_equal M( I, 2, 2, 1 )[ [ [ 0, 1 ], [ 1, 0 ] ] ],
|
432
|
-
|
432
|
+
#assert_equal M( I, 2, 2, 1 )[ [ [ 0, 1 ], [ 1, 0 ] ] ],
|
433
|
+
# S[ C( 1, 0, 0 ), C( 0, 1, 0 ) ].histogram( 2, 2, 1, :target => I )
|
433
434
|
assert_raise( RuntimeError ) { S[ 1, 2, 3 ].histogram 4, 4 }
|
434
435
|
assert_raise( RuntimeError ) { M[ [ -1, 0 ] ].histogram 3, 2 }
|
435
436
|
assert_raise( RuntimeError ) { M[ [ 0, -1 ] ].histogram 3, 2 }
|
data/test/tc_rgb.rb
CHANGED
@@ -162,10 +162,6 @@ class TC_RGB < Test::Unit::TestCase
|
|
162
162
|
inject( RGB( 2, 3, 4 ) ) { |a,b| a + b }[]
|
163
163
|
end
|
164
164
|
|
165
|
-
def test_decompose
|
166
|
-
assert_equal [ 1, 2, 3 ], RGB( 1, 2, 3 ).decompose.to_a
|
167
|
-
end
|
168
|
-
|
169
165
|
def test_not
|
170
166
|
assert !RGB( 0, 0, 0 ).not
|
171
167
|
assert !RGB( 1, 2, 3 ).not
|
data/test/tc_sequence.rb
CHANGED
@@ -277,6 +277,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
277
277
|
def test_collect
|
278
278
|
assert_equal S[ 2, 3 ], S[ 1, 2 ].collect { |x| x + 1 }
|
279
279
|
assert_equal S[ 2, 4 ], S[ 1, 2 ].map { |x| 2 * x }
|
280
|
+
assert_equal S[ 6 ], S[ C( 1, 2, 3 ) ].collect { |x| x.r + x.g + x.b }
|
280
281
|
end
|
281
282
|
|
282
283
|
def test_sum
|