multiarray 0.22.0 → 0.23.1
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/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/test/tc_object.rb
CHANGED
@@ -53,22 +53,6 @@ class TC_Object < Test::Unit::TestCase
|
|
53
53
|
assert_equal 1, O.indgen( 1, 2 )
|
54
54
|
end
|
55
55
|
|
56
|
-
def test_object_typecode
|
57
|
-
assert_equal O, O.typecode
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_object_dimension
|
61
|
-
assert_equal 0, O.dimension
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_object_shape
|
65
|
-
assert_equal [], O.shape
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_object_size
|
69
|
-
assert_equal 1, O.size
|
70
|
-
end
|
71
|
-
|
72
56
|
def test_inspect
|
73
57
|
assert_equal 'OBJECT(42)', O( 42 ).inspect
|
74
58
|
end
|
data/test/tc_rgb.rb
CHANGED
@@ -88,22 +88,6 @@ class TC_RGB < Test::Unit::TestCase
|
|
88
88
|
assert_equal RGB( 1, 2, 3 ), INTRGB.indgen( RGB( 1, 2, 3 ), 1 )
|
89
89
|
end
|
90
90
|
|
91
|
-
def test_rgb_typecode
|
92
|
-
assert_equal BYTERGB, BYTERGB.typecode
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_rgb_dimension
|
96
|
-
assert_equal 0, SFLOATRGB.dimension
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_rgb_shape
|
100
|
-
assert_equal [], SFLOATRGB.shape
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_rgb_size
|
104
|
-
assert_equal 1, SINTRGB.size
|
105
|
-
end
|
106
|
-
|
107
91
|
def test_inspect
|
108
92
|
assert_equal 'RGB(1,2,3)', RGB( 1, 2, 3 ).inspect
|
109
93
|
end
|
data/test/tc_sequence.rb
CHANGED
@@ -55,47 +55,41 @@ class TC_Sequence < Test::Unit::TestCase
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_sequence_inspect
|
58
|
-
assert_equal 'Sequence(OBJECT
|
58
|
+
assert_equal 'Sequence(OBJECT)', S(O).inspect
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_sequence_to_s
|
62
|
-
assert_equal 'Sequence(OBJECT
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_sequence_default
|
66
|
-
assert_equal [ nil ] * 3, S( O, 3 ).default.to_a
|
67
|
-
assert_equal [ 0 ] * 3, S( I, 3 ).default.to_a
|
68
|
-
assert_equal [ C( 0, 0, 0 ) ] * 3, S( C, 3 ).default.to_a
|
62
|
+
assert_equal 'Sequence(OBJECT)', S(O).to_s
|
69
63
|
end
|
70
64
|
|
71
65
|
def test_sequence_indgen
|
72
|
-
assert_equal S(
|
73
|
-
assert_equal S(
|
74
|
-
assert_equal S(
|
75
|
-
assert_equal S(
|
76
|
-
assert_equal S(
|
77
|
-
S(
|
66
|
+
assert_equal S(I)[0, 1, 2], S(I).indgen(3)
|
67
|
+
assert_equal S(I)[1, 2, 3], S(I).indgen(3, 1)
|
68
|
+
assert_equal S(I)[0, 2, 4], S(I).indgen(3, 0, 2)
|
69
|
+
assert_equal S(I)[1, 3, 5], S(I).indgen(3, 1, 2)
|
70
|
+
assert_equal S(C)[C( 1, 2, 3 ), C( 3, 5, 7 )],
|
71
|
+
S(C).indgen(2, C(1, 2, 3), C(2, 3, 4))
|
78
72
|
end
|
79
73
|
|
80
74
|
def test_sequence_random
|
81
|
-
r = S(
|
75
|
+
r = S(O).random(100, 10).range
|
82
76
|
assert r.begin >= 0
|
83
77
|
assert r.end < 10
|
84
|
-
r = S(
|
78
|
+
r = S(I).random(100, 10).range
|
85
79
|
assert r.begin >= 0
|
86
80
|
assert r.end < 10
|
87
|
-
r = S(
|
81
|
+
r = S(F).random(100, 10.0).range
|
88
82
|
assert r.begin >= 0
|
89
83
|
assert r.end < 10
|
90
84
|
end
|
91
85
|
|
92
86
|
def test_sequence_at
|
93
|
-
assert_equal "Sequence(INT
|
94
|
-
S(
|
95
|
-
assert_equal "Sequence(OBJECT
|
96
|
-
S(
|
97
|
-
assert_equal "Sequence(INTRGB
|
98
|
-
S(
|
87
|
+
assert_equal "Sequence(INT):\n[ 1, 2, 3 ]",
|
88
|
+
S(I)[ 1, 2, 3 ].inspect
|
89
|
+
assert_equal "Sequence(OBJECT):\n[ 1, 2, 3 ]",
|
90
|
+
S(O)[ 1, 2, 3 ].inspect
|
91
|
+
assert_equal "Sequence(INTRGB):\n[ RGB(1,2,3), RGB(4,5,6) ]",
|
92
|
+
S(C)[ C( 1, 2, 3 ), C( 4, 5, 6 ) ].inspect
|
99
93
|
end
|
100
94
|
|
101
95
|
def test_sequence_match
|
@@ -108,29 +102,20 @@ class TC_Sequence < Test::Unit::TestCase
|
|
108
102
|
end
|
109
103
|
|
110
104
|
def test_sequence_typecode
|
111
|
-
assert_equal O, S(
|
112
|
-
assert_equal B, S(
|
113
|
-
assert_equal I, S(
|
114
|
-
assert_equal C, S(
|
115
|
-
assert_equal X, S(
|
105
|
+
assert_equal O, S(O).typecode
|
106
|
+
assert_equal B, S(B).typecode
|
107
|
+
assert_equal I, S(I).typecode
|
108
|
+
assert_equal C, S(C).typecode
|
109
|
+
assert_equal X, S(X).typecode
|
116
110
|
end
|
117
111
|
|
118
112
|
def test_sequence_dimension
|
119
|
-
assert_equal 1, S(
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_sequence_shape
|
123
|
-
assert_equal [ 3 ], S( O, 3 ).shape
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_sequence_size
|
127
|
-
assert_equal 3, S( O, 3 ).size
|
128
|
-
assert_equal 3, S( C, 3 ).size
|
113
|
+
assert_equal 1, S(O).dimension
|
129
114
|
end
|
130
115
|
|
131
116
|
def test_inspect
|
132
|
-
assert_equal "Sequence(OBJECT
|
133
|
-
assert_equal "Sequence(OBJECT
|
117
|
+
assert_equal "Sequence(OBJECT):\n[]", S[].inspect
|
118
|
+
assert_equal "Sequence(OBJECT):\n[ :a, 2, 3 ]", S[ :a, 2, 3 ].inspect
|
134
119
|
end
|
135
120
|
|
136
121
|
def test_dup
|
@@ -141,8 +126,8 @@ class TC_Sequence < Test::Unit::TestCase
|
|
141
126
|
end
|
142
127
|
|
143
128
|
def test_typecode
|
144
|
-
assert_equal O, S.object(
|
145
|
-
assert_equal I, S.int(
|
129
|
+
assert_equal O, S.object(3).typecode
|
130
|
+
assert_equal I, S.int(3).typecode
|
146
131
|
end
|
147
132
|
|
148
133
|
def test_dimension
|
@@ -168,8 +153,8 @@ class TC_Sequence < Test::Unit::TestCase
|
|
168
153
|
end
|
169
154
|
|
170
155
|
def test_at_assign
|
171
|
-
[ S(
|
172
|
-
s = t.new
|
156
|
+
[ S(O), S(I) ].each do |t|
|
157
|
+
s = t.new 3
|
173
158
|
for i in 0 ... 3
|
174
159
|
assert_equal i + 1, s[ i ] = i + 1
|
175
160
|
end
|
@@ -185,8 +170,8 @@ class TC_Sequence < Test::Unit::TestCase
|
|
185
170
|
end
|
186
171
|
|
187
172
|
def test_slice
|
188
|
-
[ S(
|
189
|
-
s = t.indgen( 1
|
173
|
+
[ S(O), S(I) ].each do |t|
|
174
|
+
s = t.indgen(4, 1)[]
|
190
175
|
assert_equal [ 2, 3 ], s[ 1 .. 2 ].to_a
|
191
176
|
assert_equal [ 2, 3 ], s[ 1 ... 3 ].to_a
|
192
177
|
s[ 1 .. 2 ] = 0
|
@@ -214,7 +199,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
214
199
|
end
|
215
200
|
|
216
201
|
def test_view
|
217
|
-
[ S(
|
202
|
+
[ S(O), S(I) ].each do |t|
|
218
203
|
s = t[ 1, 2, 3, 4 ]
|
219
204
|
v = s[ 1 .. 2 ]
|
220
205
|
v[] = 0
|
@@ -233,7 +218,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
233
218
|
end
|
234
219
|
|
235
220
|
def test_r_g_b
|
236
|
-
[ S(
|
221
|
+
[ S(O), S(C) ].each do |t|
|
237
222
|
assert_equal [ 1, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].r.to_a
|
238
223
|
assert_equal [ 2, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].g.to_a
|
239
224
|
assert_equal [ 3, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].b.to_a
|
@@ -244,7 +229,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
244
229
|
s = t[ 0, 0, 0 ]
|
245
230
|
assert_equal 1, s.r = 1
|
246
231
|
assert_equal S[ 1, 2, 3 ], s.g = S[ 1, 2, 3 ]
|
247
|
-
assert_equal S(
|
232
|
+
assert_equal S(O)[ 4, 5, 6 ], s.b = S(O)[ 4, 5, 6 ]
|
248
233
|
assert_equal t[ C( 1, 1, 4 ), C( 1, 2, 5 ), C( 1, 3, 6 ) ], s
|
249
234
|
assert_raise( RuntimeError ) { s.r = S[ 1, 2 ] }
|
250
235
|
assert_raise( RuntimeError ) { s.g = S[ 1, 2 ] }
|
@@ -257,7 +242,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
257
242
|
end
|
258
243
|
|
259
244
|
def test_real_imag
|
260
|
-
[ S(
|
245
|
+
[ S(O), S(X) ].each do |t|
|
261
246
|
assert_equal [ 1, 3 ], t[ X( 1, 2 ), 3 ].real.to_a
|
262
247
|
assert_equal [ 2, 0 ], t[ X( 1, 2 ), 3 ].imag.to_a
|
263
248
|
assert_equal [ 1, 3 ], t[ X( 1, 2 ), 3 ].collect { |x| x.real }.to_a
|
@@ -289,7 +274,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
289
274
|
assert_equal C( 7, 8, 9 ), S[ 1, 2, 3 ].inject( C( 1, 2, 3 ) ) { |a,b| a + b }
|
290
275
|
assert_equal C( 4, 6, 9 ), S[ C( 1, 2, 3 ), C( 2, 3, 5 ) ].
|
291
276
|
inject( 1 ) { |a,b| a + b }
|
292
|
-
assert_equal X( -5, 10 ), S(
|
277
|
+
assert_equal X( -5, 10 ), S(X)[ X( 1, 2 ), X( 3, 4 ) ].inject { |a,b| a * b }
|
293
278
|
assert_raise( RuntimeError ) { S[].inject { |a,b| a + b } }
|
294
279
|
assert_equal 0, S[].inject( 0 ) { |a,b| a + b }
|
295
280
|
end
|
@@ -307,7 +292,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
307
292
|
end
|
308
293
|
|
309
294
|
def test_sum
|
310
|
-
[ S(
|
295
|
+
[ S(O), S(I) ].each do |t|
|
311
296
|
assert_equal 6, t[ 1, 2, 3 ].sum
|
312
297
|
assert_equal 6, sum { |i| t[ 1, 2, 3 ][ i ] }
|
313
298
|
assert_equal [ 1, 2, 3 ], sum { || t[ 1, 2, 3 ] }.to_a
|
@@ -321,17 +306,17 @@ class TC_Sequence < Test::Unit::TestCase
|
|
321
306
|
end
|
322
307
|
|
323
308
|
def test_min
|
324
|
-
[
|
325
|
-
assert_equal 2, S(
|
309
|
+
[O, I].each do |t|
|
310
|
+
assert_equal 2, S(t)[4, 2, 3].min
|
326
311
|
end
|
327
|
-
assert_equal C(
|
312
|
+
assert_equal C(1, 2, 1), S[C(1, 2, 3), C(3, 2, 1)].min
|
328
313
|
end
|
329
314
|
|
330
315
|
def test_max
|
331
|
-
[
|
332
|
-
assert_equal 4, S(
|
316
|
+
[O, I].each do |t|
|
317
|
+
assert_equal 4, S(t)[4, 2, 3].max
|
333
318
|
end
|
334
|
-
assert_equal C(
|
319
|
+
assert_equal C(3, 2, 3), S[C(1, 2, 3), C(3, 2, 1)].max
|
335
320
|
end
|
336
321
|
|
337
322
|
def test_between
|
@@ -349,26 +334,26 @@ class TC_Sequence < Test::Unit::TestCase
|
|
349
334
|
end
|
350
335
|
|
351
336
|
def test_sum
|
352
|
-
[ S(
|
337
|
+
[ S(O), S(I) ].each do |t|
|
353
338
|
assert_equal 9, t[ 4, 2, 3 ].sum
|
354
339
|
end
|
355
340
|
assert_equal C( 4, 4, 4 ), S[ C( 1, 2, 3 ), C( 3, 2, 1 ) ].sum
|
356
341
|
end
|
357
342
|
|
358
343
|
def test_convolve
|
359
|
-
[
|
360
|
-
assert_equal S(
|
361
|
-
S(
|
362
|
-
assert_equal S(
|
363
|
-
S(
|
364
|
-
assert_equal S(
|
365
|
-
S(
|
366
|
-
assert_equal S(
|
367
|
-
S(
|
368
|
-
assert_equal S(
|
369
|
-
S(
|
370
|
-
assert_equal S(
|
371
|
-
S(
|
344
|
+
[O, I].each do |t|
|
345
|
+
assert_equal S(t)[2, 3, 0, 0, 0],
|
346
|
+
S(t)[1, 0, 0, 0, 0].convolve( S(t)[ 1, 2, 3 ] )
|
347
|
+
assert_equal S(t)[1, 2, 3, 0, 0],
|
348
|
+
S(t)[0, 1, 0, 0, 0].convolve( S(t)[ 1, 2, 3 ] )
|
349
|
+
assert_equal S(t)[0, 1, 2, 3, 0],
|
350
|
+
S(t)[0, 0, 1, 0, 0].convolve( S(t)[ 1, 2, 3 ] )
|
351
|
+
assert_equal S(t)[0, 0, 1, 2, 3],
|
352
|
+
S(t)[0, 0, 0, 1, 0].convolve( S(t)[ 1, 2, 3 ] )
|
353
|
+
assert_equal S(t)[0, 0, 0, 1, 2],
|
354
|
+
S(t)[0, 0, 0, 0, 1].convolve( S(t)[ 1, 2, 3 ] )
|
355
|
+
assert_equal S(t)[1, 2, 3, 0],
|
356
|
+
S(t)[0, 1, 0, 0].convolve( S(t)[ 1, 2, 3 ] )
|
372
357
|
end
|
373
358
|
assert_equal S[ C( 1, 0, 0 ), C( 2, 1, 0 ), C( 3, 2, 1 ), C( 0, 3, 2 ),
|
374
359
|
C( 0, 0, 3 ) ],
|
@@ -377,19 +362,19 @@ class TC_Sequence < Test::Unit::TestCase
|
|
377
362
|
end
|
378
363
|
|
379
364
|
def test_erode
|
380
|
-
[
|
381
|
-
assert_equal [
|
365
|
+
[O, I].each do |t|
|
366
|
+
assert_equal [1, 1, 1, 2, 2, 2], S(t)[1, 1, 2, 3, 2, 2].erode.to_a
|
382
367
|
end
|
383
|
-
assert_equal S[
|
384
|
-
S[
|
368
|
+
assert_equal S[false, false, true, false, false],
|
369
|
+
S[false, true, true, true, false].erode
|
385
370
|
end
|
386
371
|
|
387
372
|
def test_dilate
|
388
|
-
[
|
389
|
-
assert_equal [
|
373
|
+
[O, I].each do |t|
|
374
|
+
assert_equal [1, 2, 3, 3, 3, 2], S(t)[1, 1, 2, 3, 2, 2].dilate.to_a
|
390
375
|
end
|
391
|
-
assert_equal S[
|
392
|
-
S[
|
376
|
+
assert_equal S[false, true, true, true, false],
|
377
|
+
S[false, false, true, false, false].dilate
|
393
378
|
end
|
394
379
|
|
395
380
|
def test_sobel
|
@@ -397,76 +382,75 @@ class TC_Sequence < Test::Unit::TestCase
|
|
397
382
|
end
|
398
383
|
|
399
384
|
def test_histogram
|
400
|
-
[
|
401
|
-
assert_equal [
|
402
|
-
S(
|
403
|
-
assert_equal S(
|
404
|
-
S(
|
405
|
-
assert_equal [
|
406
|
-
S(
|
385
|
+
[O, I].each do |t|
|
386
|
+
assert_equal [0, 1, 2, 1, 1],
|
387
|
+
S(t)[1, 2, 2, 3, 4].histogram(5, :weight => 1).to_a
|
388
|
+
assert_equal S(t)[0, 1, 2, 3, 0],
|
389
|
+
S(t)[1, 3, 2 ].histogram(5, :weight => S(t)[1, 3, 2] )
|
390
|
+
assert_equal [0, 1, 1, 0],
|
391
|
+
S(t)[1.0, 2.0].histogram(4, :weight => 1).to_a
|
407
392
|
end
|
408
|
-
assert_raise(
|
409
|
-
assert_raise(
|
410
|
-
assert_raise(
|
411
|
-
assert_raise(
|
393
|
+
assert_raise(RuntimeError) { S[-1, 0, 1].histogram 3 }
|
394
|
+
assert_raise(RuntimeError) { S[1, 2, 3].histogram 3 }
|
395
|
+
assert_raise(RuntimeError) { S[0, 0, 0].histogram 3, 2 }
|
396
|
+
assert_raise(RuntimeError) { S[0, 1].histogram 3, :weight => S[0] }
|
412
397
|
end
|
413
398
|
|
414
399
|
def test_lut
|
415
|
-
[
|
416
|
-
assert_equal S(
|
417
|
-
S(
|
418
|
-
assert_equal S(
|
419
|
-
S(
|
400
|
+
[O, I].each do |t|
|
401
|
+
assert_equal S(t)[3, 1, 2, 1],
|
402
|
+
S(t)[0, 2, 1, 2].lut(S(t)[3, 2, 1])
|
403
|
+
assert_equal S(t)[2, 1],
|
404
|
+
S(t)[1.0, 2.0].lut(S(t)[3, 2, 1])
|
420
405
|
end
|
421
|
-
assert_raise( RuntimeError ) { S[
|
422
|
-
assert_raise( RuntimeError ) { S[
|
406
|
+
assert_raise( RuntimeError ) { S[-1, 0].lut S[0, 1] }
|
407
|
+
assert_raise( RuntimeError ) { S[1, 2].lut S[0, 1] }
|
423
408
|
end
|
424
409
|
|
425
410
|
def test_warp
|
426
411
|
[ O, I ].each do |t1|
|
427
412
|
[ O, I ].each do |t2|
|
428
|
-
assert_equal S(
|
429
|
-
S( t1, 2 )[ 1, 2 ].warp( S( t2, 3 )[ 0, 1, 2 ] )
|
413
|
+
assert_equal S(t1)[1, 2, t1.default], S(t1)[1, 2].warp(S(t2)[0, 1, 2])
|
430
414
|
end
|
431
415
|
end
|
432
416
|
end
|
433
417
|
|
434
418
|
def test_flip
|
435
419
|
[ O, I ].each do |t|
|
436
|
-
assert_equal S(
|
420
|
+
assert_equal S(t)[3, 2, 1], S(t)[1, 2, 3].flip( 0 )
|
437
421
|
end
|
438
422
|
end
|
439
423
|
|
440
424
|
def test_shift
|
441
425
|
[ O, I ].each do |t|
|
442
|
-
assert_equal S(
|
443
|
-
assert_equal S(
|
444
|
-
assert_equal S(
|
426
|
+
assert_equal S(t)[1, 2, 3], S(t)[1, 2, 3].shift(0)
|
427
|
+
assert_equal S(t)[3, 1, 2], S(t)[1, 2, 3].shift(1)
|
428
|
+
assert_equal S(t)[2, 3, 1], S(t)[1, 2, 3].shift(2)
|
445
429
|
end
|
446
430
|
end
|
447
431
|
|
448
432
|
def test_downsample
|
449
433
|
[ O, I ].each do |t|
|
450
|
-
assert_equal S(
|
451
|
-
S(
|
452
|
-
assert_equal S(
|
453
|
-
S(
|
434
|
+
assert_equal S(t)[2, 4],
|
435
|
+
S(t)[1, 2, 3, 4].downsample(2)
|
436
|
+
assert_equal S(t)[1, 3],
|
437
|
+
S(t)[1, 2, 3, 4].downsample(2, :offset => [0])
|
454
438
|
end
|
455
439
|
end
|
456
440
|
|
457
441
|
def test_zero
|
458
|
-
[
|
459
|
-
assert_equal [
|
442
|
+
[S(O), S(I)].each do |t|
|
443
|
+
assert_equal [false, true, false], t[-1, 0, 1].zero?.to_a
|
460
444
|
end
|
461
|
-
assert_equal S[
|
462
|
-
S[
|
463
|
-
assert_equal S[
|
464
|
-
S[
|
445
|
+
assert_equal S[false, false, false, true],
|
446
|
+
S[C(1, 0, 0 ), C(0, 1, 0), C(0, 0, 1), C(0, 0, 0)].zero?
|
447
|
+
assert_equal S[true, false, false],
|
448
|
+
S[X(0, 0), X(1, 0), X(0, 1)].zero?
|
465
449
|
end
|
466
450
|
|
467
451
|
def test_nonzero
|
468
|
-
assert_equal S[ true, false, true ], S(
|
469
|
-
assert_equal S[ -1, nil, 1 ], S(
|
452
|
+
assert_equal S[ true, false, true ], S(I)[ -1, 0, 1 ].nonzero?
|
453
|
+
assert_equal S[ -1, nil, 1 ], S(O)[ -1, 0, 1 ].nonzero?
|
470
454
|
assert_equal S[ true, true, true, false ],
|
471
455
|
S[ C( 1, 0, 0 ), C( 0, 1, 0 ), C( 0, 0, 1 ), C( 0, 0, 0 ) ].nonzero?
|
472
456
|
assert_equal S[ false, true, true ],
|
@@ -474,8 +458,8 @@ class TC_Sequence < Test::Unit::TestCase
|
|
474
458
|
end
|
475
459
|
|
476
460
|
def test_not
|
477
|
-
assert_equal [ true, false ], S(
|
478
|
-
assert_equal [ true, false ], S(
|
461
|
+
assert_equal [ true, false ], S(O)[ false, true ].not.to_a
|
462
|
+
assert_equal [ true, false ], S(B)[ false, true ].not.to_a
|
479
463
|
assert_equal [ true, false, false ], S[ 0, 1, 2 ].not.to_a
|
480
464
|
end
|
481
465
|
|
@@ -498,48 +482,48 @@ class TC_Sequence < Test::Unit::TestCase
|
|
498
482
|
end
|
499
483
|
|
500
484
|
def test_bitwise_not
|
501
|
-
[ S(
|
485
|
+
[ S(O), S(I) ].each do |t|
|
502
486
|
assert_equal [ 0, -1, -2, -3 ], ( ~t[ -1, 0, 1, 2 ] ).to_a
|
503
487
|
end
|
504
488
|
assert_equal [ C( -2, -3, -4 ), C( -5, -6, -7 ) ],
|
505
|
-
( ~S(
|
489
|
+
( ~S(C)[ C( 1, 2, 3 ), C( 4, 5, 6 ) ] ).to_a
|
506
490
|
end
|
507
491
|
|
508
492
|
def test_bitwise_and
|
509
|
-
[ S(
|
493
|
+
[ S(O), S(I) ].each do |t|
|
510
494
|
assert_equal [ 0, 1, 0 ], ( t[ 0, 1, 2 ] & 1 ).to_a
|
511
495
|
assert_equal [ 0, 1, 0 ], ( 1 & t[ 0, 1, 2 ] ).to_a
|
512
496
|
assert_equal [ 0, 1, 2 ], ( t[ 0, 1, 3 ] & t[ 4, 3, 2 ] ).to_a
|
513
497
|
end
|
514
|
-
assert_equal [ C( 0, 2, 2 ) ], ( S(
|
515
|
-
assert_equal [ C( 1, 0, 1 ) ], ( 1 & S(
|
516
|
-
assert_equal [ C( 1, 2, 1 ) ], ( S(
|
498
|
+
assert_equal [ C( 0, 2, 2 ) ], ( S(C)[ C( 1, 2, 3 ) ] & 2 ).to_a
|
499
|
+
assert_equal [ C( 1, 0, 1 ) ], ( 1 & S(C)[ C( 1, 2, 3 ) ] ).to_a
|
500
|
+
assert_equal [ C( 1, 2, 1 ) ], ( S(C)[ C( 1, 2, 3 ) ] & C( 3, 2, 1 ) ).to_a
|
517
501
|
end
|
518
502
|
|
519
503
|
def test_bitwise_or
|
520
|
-
[ S(
|
504
|
+
[ S(O), S(I) ].each do |t|
|
521
505
|
assert_equal [ 1, 1, 3 ], ( t[ 0, 1, 2 ] | 1 ).to_a
|
522
506
|
assert_equal [ 1, 1, 3 ], ( 1 | t[ 0, 1, 2 ] ).to_a
|
523
507
|
assert_equal [ 4, 3, 3 ], ( t[ 0, 1, 2 ] | t[ 4, 3, 1 ] ).to_a
|
524
508
|
end
|
525
|
-
assert_equal [ C( 3, 2, 3 ) ], ( S(
|
526
|
-
assert_equal [ C( 1, 3, 3 ) ], ( 1 | S(
|
527
|
-
assert_equal [ C( 3, 2, 3 ) ], ( S(
|
509
|
+
assert_equal [ C( 3, 2, 3 ) ], ( S(C)[ C( 1, 2, 3 ) ] | 2 ).to_a
|
510
|
+
assert_equal [ C( 1, 3, 3 ) ], ( 1 | S(C)[ C( 1, 2, 3 ) ] ).to_a
|
511
|
+
assert_equal [ C( 3, 2, 3 ) ], ( S(C)[ C( 1, 2, 3 ) ] | C( 3, 2, 1 ) ).to_a
|
528
512
|
end
|
529
513
|
|
530
514
|
def test_bitwise_xor
|
531
|
-
[ S(
|
515
|
+
[ S(O), S(I) ].each do |t|
|
532
516
|
assert_equal [ 1, 0, 3 ], ( t[ 0, 1, 2 ] ^ 1 ).to_a
|
533
517
|
assert_equal [ 1, 0, 3 ], ( 1 ^ t[ 0, 1, 2 ] ).to_a
|
534
518
|
assert_equal [ 4, 2, 3 ], ( t[ 0, 1, 2 ] ^ t[ 4, 3, 1 ] ).to_a
|
535
519
|
end
|
536
|
-
assert_equal [ C( 3, 0, 1 ) ], ( S(
|
537
|
-
assert_equal [ C( 0, 3, 2 ) ], ( 1 ^ S(
|
538
|
-
assert_equal [ C( 2, 0, 2 ) ], ( S(
|
520
|
+
assert_equal [ C( 3, 0, 1 ) ], ( S(C)[ C( 1, 2, 3 ) ] ^ 2 ).to_a
|
521
|
+
assert_equal [ C( 0, 3, 2 ) ], ( 1 ^ S(C)[ C( 1, 2, 3 ) ] ).to_a
|
522
|
+
assert_equal [ C( 2, 0, 2 ) ], ( S(C)[ C( 1, 2, 3 ) ] ^ C( 3, 2, 1 ) ).to_a
|
539
523
|
end
|
540
524
|
|
541
525
|
def test_shl
|
542
|
-
[ S(
|
526
|
+
[ S(O), S(I) ].each do |t|
|
543
527
|
assert_equal [ 2, 4, 6 ], ( t[ 1, 2, 3 ] << 1 ).to_a
|
544
528
|
assert_equal [ 6, 12, 24 ], ( 3 << t[ 1, 2, 3 ] ).to_a
|
545
529
|
assert_equal [ 8, 8, 6 ], ( t[ 1, 2, 3 ] << t[ 3, 2, 1 ] ).to_a
|
@@ -547,7 +531,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
547
531
|
end
|
548
532
|
|
549
533
|
def test_shr
|
550
|
-
[ S(
|
534
|
+
[ S(O), S(I) ].each do |t|
|
551
535
|
assert_equal [ 1, 2, 3 ], ( t[ 2, 4, 6 ] >> 1 ).to_a
|
552
536
|
assert_equal [ 12, 6, 3 ], ( 24 >> t[ 1, 2, 3 ] ).to_a
|
553
537
|
assert_equal [ 2, 1, 3 ], ( t[ 16, 4, 6 ] >> t[ 3, 2, 1 ] ).to_a
|
@@ -555,11 +539,11 @@ class TC_Sequence < Test::Unit::TestCase
|
|
555
539
|
end
|
556
540
|
|
557
541
|
def test_negate
|
558
|
-
[ S(
|
542
|
+
[ S(O), S(I) ].each do |t|
|
559
543
|
assert_equal t[ -1, 2, -3 ], -t[ 1, -2, 3 ]
|
560
544
|
end
|
561
|
-
assert_equal S(
|
562
|
-
-S(
|
545
|
+
assert_equal S(C)[ C( -1, -2, -3 ), C( -2, -1, 0 ) ],
|
546
|
+
-S(C)[ C( 1, 2, 3 ), C( 2, 1, 0 ) ]
|
563
547
|
end
|
564
548
|
|
565
549
|
def test_plus
|
@@ -588,8 +572,8 @@ class TC_Sequence < Test::Unit::TestCase
|
|
588
572
|
end
|
589
573
|
|
590
574
|
def test_conj
|
591
|
-
assert_equal S(
|
592
|
-
assert_equal S(
|
575
|
+
assert_equal S(O)[ 1.5, 2.5 ], S(O)[ 1.5, 2.5 ].conj
|
576
|
+
assert_equal S(F)[ 1.5, 2.5 ], S(F)[ 1.5, 2.5 ].conj
|
593
577
|
assert_equal S[ X( 1.5, -2.5 ) ], S[ X( 1.5, 2.5 ) ].conj
|
594
578
|
end
|
595
579
|
|
@@ -629,9 +613,9 @@ class TC_Sequence < Test::Unit::TestCase
|
|
629
613
|
def test_pow
|
630
614
|
assert_equal [ 1, 4, 9 ], ( S[ 1, 2, 3 ] ** 2 ).to_a
|
631
615
|
assert_equal [ C( 2, 4, 8 ) ], ( 2 ** S[ C( 1, 2, 3 ) ] ).to_a
|
632
|
-
assert_in_delta 0.0, ( ( S(
|
616
|
+
assert_in_delta 0.0, ( ( S(X)[ X( 1, 2 ) ] ** 2 )[ 0 ] - X( -3, 4 ) ).abs,
|
633
617
|
1.0e-5
|
634
|
-
assert_in_delta 0.0, ( Math::E ** S(
|
618
|
+
assert_in_delta 0.0, ( Math::E ** S(X)[ X( 0, Math::PI ) ][ 0 ] + 1 ).abs,
|
635
619
|
1.0e-5
|
636
620
|
end
|
637
621
|
|
@@ -703,6 +687,8 @@ class TC_Sequence < Test::Unit::TestCase
|
|
703
687
|
assert_equal [ 2, 2, 3 ], 2.major( S[ 1, 2, 3 ] ).to_a
|
704
688
|
assert_equal [ 3, 2, 3 ], S[ 1, 2, 3 ].major( S[ 3, 2, 1 ] ).to_a
|
705
689
|
assert_equal [ C( 2, 2, 3 ) ], S[ C( 1, 2, 3 ) ].major( 2 ).to_a
|
690
|
+
assert_equal [C(1, 2, 3), C(2, 2, 3), C(3, 3, 3)], S[1, 2, 3].major(C(1, 2, 3)).to_a
|
691
|
+
assert_equal [C(1, 2, 3), C(2, 2, 3), C(3, 3, 3)], C(1, 2, 3).major(S[1, 2, 3]).to_a
|
706
692
|
end
|
707
693
|
|
708
694
|
def test_minor
|
@@ -710,10 +696,12 @@ class TC_Sequence < Test::Unit::TestCase
|
|
710
696
|
assert_equal [ 1, 2, 2 ], 2.minor( S[ 1, 2, 3 ] ).to_a
|
711
697
|
assert_equal [ 1, 2, 1 ], S[ 1, 2, 3 ].minor( S[ 3, 2, 1 ] ).to_a
|
712
698
|
assert_equal [ C( 1, 2, 2 ) ], S[ C( 1, 2, 3 ) ].minor( 2 ).to_a
|
699
|
+
assert_equal [C(1, 1, 1), C(1, 2, 2), C(1, 2, 3)], S[1, 2, 3].minor(C(1, 2, 3)).to_a
|
700
|
+
assert_equal [C(1, 1, 1), C(1, 2, 2), C(1, 2, 3)], C(1, 2, 3).minor(S[1, 2, 3]).to_a
|
713
701
|
end
|
714
702
|
|
715
703
|
def test_sqrt
|
716
|
-
assert_equal S(
|
704
|
+
assert_equal S(O)[ 1, 2, 3 ], Math.sqrt( S(O)[ 1, 4, 9 ] )
|
717
705
|
assert_equal S[ 1.0, 2.0, 3.0 ], Math.sqrt( S[ 1.0, 4.0, 9.0 ] )
|
718
706
|
[ Math.sqrt( X( 1, 2 ) ), Math.sqrt( X( 2, -1 ) ) ].
|
719
707
|
zip( Math.sqrt( S[ X( 1, 2 ), X( 2, -1 ) ] ).to_a ).each do |x,y|
|
@@ -915,7 +903,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
915
903
|
end
|
916
904
|
|
917
905
|
def test_fill
|
918
|
-
[ S(
|
906
|
+
[ S(O), S(I) ].each do |t|
|
919
907
|
s = t[ 1, 2, 3 ]
|
920
908
|
assert_equal t[ 1, 1, 1 ], s.fill!( 1 )
|
921
909
|
assert_equal t[ 1, 1, 1 ], s
|
@@ -923,22 +911,22 @@ class TC_Sequence < Test::Unit::TestCase
|
|
923
911
|
end
|
924
912
|
|
925
913
|
def test_to_type
|
926
|
-
assert_equal S(
|
927
|
-
assert_equal S(
|
928
|
-
assert_equal S(
|
914
|
+
assert_equal S(O)[ 1, 2, 3 ], S(I)[ 1, 2, 3 ].to_object
|
915
|
+
assert_equal S(I)[ 1, 2, 3 ], S(O)[ 1, 2, 3 ].to_int
|
916
|
+
assert_equal S(C)[ 1, 2, 3 ], S(I)[ 1, 2, 3 ].to_intrgb
|
929
917
|
end
|
930
918
|
|
931
919
|
def test_reshape
|
932
920
|
[ O, I ].each do |t|
|
933
|
-
assert_equal S(
|
934
|
-
assert_raise( RuntimeError ) { S(
|
935
|
-
assert_raise( RuntimeError ) { S(
|
921
|
+
assert_equal S(t)[ 1, 2, 3 ], S(t)[ 1, 2, 3 ].reshape(3)
|
922
|
+
assert_raise( RuntimeError ) { S(t)[ 1, 2, 3 ].reshape 2 }
|
923
|
+
assert_raise( RuntimeError ) { S(t)[ 1, 2, 3 ].reshape 4 }
|
936
924
|
end
|
937
925
|
end
|
938
926
|
|
939
927
|
def test_integral
|
940
|
-
assert_equal S(
|
941
|
-
assert_equal S(
|
928
|
+
assert_equal S(O)[ 1, 3, 6 ], S(O)[ 1, 2, 3 ].integral
|
929
|
+
assert_equal S(I)[ 1, 3, 6 ], S(I)[ 1, 2, 3 ].integral
|
942
930
|
end
|
943
931
|
|
944
932
|
def test_components
|
@@ -947,24 +935,22 @@ class TC_Sequence < Test::Unit::TestCase
|
|
947
935
|
end
|
948
936
|
|
949
937
|
def test_mask
|
950
|
-
assert_equal S(
|
951
|
-
|
952
|
-
|
953
|
-
mask( S[ true, false, true ] )
|
954
|
-
assert_raise( RuntimeError ) { S[ 1, 2 ].mask S[ true ] }
|
938
|
+
assert_equal S(O)[2, 5], S(O)[2, 3, 5].mask( S[true, false, true])
|
939
|
+
assert_equal S(I)[2, 5], S(I)[2, 3, 5].mask( S[true, false, true])
|
940
|
+
assert_raise( RuntimeError ) { S[1, 2].mask S[ true ] }
|
955
941
|
end
|
956
942
|
|
957
943
|
def test_unmask
|
958
|
-
[
|
959
|
-
assert_equal S(
|
960
|
-
S(
|
961
|
-
assert_equal S(
|
962
|
-
S(
|
963
|
-
|
964
|
-
assert_raise(
|
965
|
-
S(
|
944
|
+
[O, I].each do |t|
|
945
|
+
assert_equal S(t)[2, 3, 5],
|
946
|
+
S(t)[2, 5].unmask( S[true, false, true], :default => 3)
|
947
|
+
assert_equal S(t)[2, 3, 5],
|
948
|
+
S(t)[2, 5].unmask( S[true, false, true],
|
949
|
+
:default => S[2, 3, 4] )
|
950
|
+
assert_raise(RuntimeError) do
|
951
|
+
S(t)[1].unmask S[true], :default => S[1, 2]
|
966
952
|
end
|
967
|
-
assert_raise(
|
953
|
+
assert_raise(RuntimeError) { S(t)[1].unmask S[true, true] }
|
968
954
|
end
|
969
955
|
end
|
970
956
|
|