multiarray 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/TODO +7 -31
- data/lib/multiarray.rb +8 -4
- data/lib/multiarray/complex.rb +360 -0
- data/lib/multiarray/composite.rb +65 -0
- data/lib/multiarray/diagonal.rb +8 -0
- data/lib/multiarray/element.rb +3 -3
- data/lib/multiarray/{unarymethod.rb → elementwise.rb} +66 -44
- data/lib/multiarray/gccfunction.rb +14 -20
- data/lib/multiarray/gcctype.rb +8 -8
- data/lib/multiarray/gccvalue.rb +57 -15
- data/lib/multiarray/inject.rb +10 -2
- data/lib/multiarray/lambda.rb +21 -3
- data/lib/multiarray/lookup.rb +8 -0
- data/lib/multiarray/methods.rb +10 -4
- data/lib/multiarray/node.rb +80 -15
- data/lib/multiarray/operations.rb +193 -12
- data/lib/multiarray/pointer.rb +19 -0
- data/lib/multiarray/rgb.rb +15 -45
- data/lib/multiarray/sequence.rb +34 -5
- data/test/tc_float.rb +20 -41
- data/test/tc_int.rb +10 -0
- data/test/tc_multiarray.rb +225 -49
- data/test/tc_object.rb +11 -0
- data/test/tc_rgb.rb +15 -0
- data/test/tc_sequence.rb +224 -11
- metadata +13 -9
- data/lib/multiarray/binarymethod.rb +0 -195
- data/lib/multiarray/binaryop.rb +0 -189
- data/lib/multiarray/unaryop.rb +0 -179
data/test/tc_object.rb
CHANGED
@@ -77,6 +77,12 @@ class TC_Object < Test::Unit::TestCase
|
|
77
77
|
assert_equal O( 42 ), Marshal.load( Marshal.dump( O( 42 ) ) )
|
78
78
|
end
|
79
79
|
|
80
|
+
def test_dup
|
81
|
+
o = O( 'abc' )
|
82
|
+
o.dup[] += 'de'
|
83
|
+
assert_equal 'abc', o[]
|
84
|
+
end
|
85
|
+
|
80
86
|
def test_typecode
|
81
87
|
assert_equal O, O.new.typecode
|
82
88
|
end
|
@@ -123,4 +129,9 @@ class TC_Object < Test::Unit::TestCase
|
|
123
129
|
assert_equal O( 3 + 5 ), O( 3 ) + O( 5 )
|
124
130
|
end
|
125
131
|
|
132
|
+
def test_cond
|
133
|
+
assert_equal O( 1 ), O( false ).conditional( O( 2 ), O( 1 ) )
|
134
|
+
assert_equal O( 2 ), O( true ).conditional( O( 2 ), O( 1 ) )
|
135
|
+
end
|
136
|
+
|
126
137
|
end
|
data/test/tc_rgb.rb
CHANGED
@@ -144,6 +144,17 @@ class TC_RGB < Test::Unit::TestCase
|
|
144
144
|
assert_not_equal RGB( 3, 3, 3 ), 4
|
145
145
|
end
|
146
146
|
|
147
|
+
def test_r_g_b
|
148
|
+
c = RGB 1, 2, 3
|
149
|
+
assert_equal 1, c.r
|
150
|
+
assert_equal 2, c.g
|
151
|
+
assert_equal 3, c.b
|
152
|
+
assert_equal 4, c.r = 4
|
153
|
+
assert_equal 5, c.g = 5
|
154
|
+
assert_equal 6, c.b = 6
|
155
|
+
assert_equal RGB( 4, 5, 6 ), c
|
156
|
+
end
|
157
|
+
|
147
158
|
def test_inject
|
148
159
|
assert_equal RGB( 1, 2, 3 ), INTRGB( RGB( 1, 2, 3 ) ).
|
149
160
|
inject { |a,b| a + b }[]
|
@@ -151,6 +162,10 @@ class TC_RGB < Test::Unit::TestCase
|
|
151
162
|
inject( RGB( 2, 3, 4 ) ) { |a,b| a + b }[]
|
152
163
|
end
|
153
164
|
|
165
|
+
def test_decompose
|
166
|
+
assert_equal [ 1, 2, 3 ], RGB( 1, 2, 3 ).decompose.to_a
|
167
|
+
end
|
168
|
+
|
154
169
|
def test_not
|
155
170
|
assert !RGB( 0, 0, 0 ).not
|
156
171
|
assert !RGB( 1, 2, 3 ).not
|
data/test/tc_sequence.rb
CHANGED
@@ -28,6 +28,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
28
28
|
I = Hornetseye::INT
|
29
29
|
S = Hornetseye::Sequence
|
30
30
|
C = Hornetseye::INTRGB
|
31
|
+
X = Hornetseye::DCOMPLEX
|
31
32
|
|
32
33
|
def S( *args )
|
33
34
|
Hornetseye::Sequence *args
|
@@ -36,6 +37,10 @@ class TC_Sequence < Test::Unit::TestCase
|
|
36
37
|
def C( *args )
|
37
38
|
Hornetseye::RGB *args
|
38
39
|
end
|
40
|
+
|
41
|
+
def X( *args )
|
42
|
+
Complex *args
|
43
|
+
end
|
39
44
|
|
40
45
|
def sum( *args, &action )
|
41
46
|
Hornetseye::sum *args, &action
|
@@ -62,12 +67,12 @@ class TC_Sequence < Test::Unit::TestCase
|
|
62
67
|
end
|
63
68
|
|
64
69
|
def test_sequence_indgen
|
65
|
-
assert_equal [ 0, 1, 2 ], S( I, 3 ).indgen
|
66
|
-
assert_equal [ 1, 2, 3 ], S( I, 3 ).indgen( 1 )
|
67
|
-
assert_equal [ 0, 2, 4 ], S( I, 3 ).indgen( 0, 2 )
|
68
|
-
assert_equal [ 1, 3, 5 ], S( I, 3 ).indgen( 1, 2 )
|
69
|
-
assert_equal [ C( 1, 2, 3 ), C( 3, 5, 7 ) ],
|
70
|
-
S( C, 2 ).indgen( C( 1, 2, 3 ), C( 2, 3, 4 ) )
|
70
|
+
assert_equal S( I, 3 )[ 0, 1, 2 ], S( I, 3 ).indgen
|
71
|
+
assert_equal S( I, 3 )[ 1, 2, 3 ], S( I, 3 ).indgen( 1 )
|
72
|
+
assert_equal S( I, 3 )[ 0, 2, 4 ], S( I, 3 ).indgen( 0, 2 )
|
73
|
+
assert_equal S( I, 3 )[ 1, 3, 5 ], S( I, 3 ).indgen( 1, 2 )
|
74
|
+
assert_equal S( C, 2 )[ C( 1, 2, 3 ), C( 3, 5, 7 ) ],
|
75
|
+
S( C, 2 ).indgen( C( 1, 2, 3 ), C( 2, 3, 4 ) )
|
71
76
|
end
|
72
77
|
|
73
78
|
def test_sequence_at
|
@@ -85,6 +90,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
85
90
|
assert_equal B, S[ false, true ].typecode
|
86
91
|
assert_equal I, S[ -2 ** 31, 2 ** 31 - 1 ].typecode
|
87
92
|
assert_equal C, S[ C( -2 ** 31, 2 ** 31 - 1, 0 ) ].typecode
|
93
|
+
assert_equal X, S[ X( 1.5, 2.5 ) ].typecode
|
88
94
|
end
|
89
95
|
|
90
96
|
def test_sequence_typecode
|
@@ -92,6 +98,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
92
98
|
assert_equal B, S( B, 3 ).typecode
|
93
99
|
assert_equal I, S( I, 3 ).typecode
|
94
100
|
assert_equal C, S( C, 3 ).typecode
|
101
|
+
assert_equal X, S( X, 3 ).typecode
|
95
102
|
end
|
96
103
|
|
97
104
|
def test_sequence_dimension
|
@@ -112,6 +119,13 @@ class TC_Sequence < Test::Unit::TestCase
|
|
112
119
|
assert_equal "Sequence(OBJECT,3):\n[ :a, 2, 3 ]", S[ :a, 2, 3 ].inspect
|
113
120
|
end
|
114
121
|
|
122
|
+
def test_dup
|
123
|
+
s = S[ 1, 2, 3 ]
|
124
|
+
v = s.dup
|
125
|
+
v[ 1 ] = 0
|
126
|
+
assert_equal S[ 1, 2, 3 ], s
|
127
|
+
end
|
128
|
+
|
115
129
|
def test_typecode
|
116
130
|
assert_equal O, S.new( O, 3 ).typecode
|
117
131
|
assert_equal I, S.new( I, 3 ).typecode
|
@@ -139,6 +153,11 @@ class TC_Sequence < Test::Unit::TestCase
|
|
139
153
|
for i in 0 ... 3
|
140
154
|
assert_equal i + 1, s[ i ]
|
141
155
|
end
|
156
|
+
assert_raise( RuntimeError ) { s[ -1 ] }
|
157
|
+
assert_raise( RuntimeError ) { s[ 3 ] }
|
158
|
+
assert_raise( RuntimeError ) { s[ -1 ] = 0 }
|
159
|
+
assert_raise( RuntimeError ) { s[ 3 ] = 0 }
|
160
|
+
assert_raise( RuntimeError ) { s[ 0 ] = s }
|
142
161
|
end
|
143
162
|
end
|
144
163
|
|
@@ -155,17 +174,81 @@ class TC_Sequence < Test::Unit::TestCase
|
|
155
174
|
assert_equal [ 1, 6, 7, 4 ], s.to_a
|
156
175
|
s[ 1 ... 3 ] = S[ 8, 9 ]
|
157
176
|
assert_equal [ 1, 8, 9, 4 ], s.to_a
|
177
|
+
assert_nothing_raised { s[ 0 .. 3 ] }
|
178
|
+
assert_nothing_raised { s[ 0 ... 4 ] }
|
179
|
+
assert_raise( RuntimeError ) { s[ -1 .. 1 ] }
|
180
|
+
assert_raise( RuntimeError ) { s[ 2 .. 4 ] }
|
181
|
+
assert_raise( RuntimeError ) { s[ -1 ... 1 ] }
|
182
|
+
assert_raise( RuntimeError ) { s[ 2 ... 5 ] }
|
183
|
+
assert_nothing_raised { s[ 0 .. 3 ] = 0 }
|
184
|
+
assert_nothing_raised { s[ 0 ... 4 ] = 0 }
|
185
|
+
assert_raise( RuntimeError ) { s[ -1 .. 1 ] = 0 }
|
186
|
+
assert_raise( RuntimeError ) { s[ 2 .. 4 ] = 0 }
|
187
|
+
assert_raise( RuntimeError ) { s[ -1 ... 1 ] = 0 }
|
188
|
+
assert_raise( RuntimeError ) { s[ 2 ... 5 ] = 0 }
|
189
|
+
assert_raise( RuntimeError ) { s[ 1 .. 3 ] = s[ 1 .. 2 ] }
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_view
|
194
|
+
[ S( O, 4 ), S( I, 4 ) ].each do |t|
|
195
|
+
s = t[ 1, 2, 3, 4 ]
|
196
|
+
v = s[ 1 .. 2 ]
|
197
|
+
v[] = 0
|
198
|
+
assert_equal [ 1, 0, 0, 4 ], s.to_a
|
158
199
|
end
|
159
200
|
end
|
160
201
|
|
161
202
|
def test_equal
|
162
203
|
assert_equal S[ 2, 3, 5 ], S[ 2, 3, 5 ]
|
163
204
|
assert_not_equal S[ 2, 3, 5 ], S[ 2, 3, 7 ]
|
164
|
-
|
165
|
-
|
205
|
+
assert_equal S[ X( 1, 2 ), 3 ], S[ X( 1, 2 ), X( 3, 0 ) ]
|
206
|
+
assert_not_equal S[ X( 1, 2 ), 3 ], S[ X( 1, 3 ), 3 ]
|
207
|
+
assert_not_equal S[ 2, 3, 5 ], S[ 2, 3 ]
|
208
|
+
assert_not_equal S[ 2, 3, 5 ], S[ 2, 3, 5, 7 ]
|
166
209
|
assert_not_equal S[ 2, 2, 2 ], 2
|
167
210
|
end
|
168
211
|
|
212
|
+
def test_r_g_b
|
213
|
+
[ S( O, 3 ), S( C, 3 ) ].each do |t|
|
214
|
+
assert_equal [ 1, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].r.to_a
|
215
|
+
assert_equal [ 2, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].g.to_a
|
216
|
+
assert_equal [ 3, 4, 5 ], t[ C( 1, 2, 3 ), 4, 5 ].b.to_a
|
217
|
+
s = t[ 0, 0, 0 ]
|
218
|
+
assert_equal 1, s.r = 1
|
219
|
+
assert_equal S[ 1, 2, 3 ], s.g = S[ 1, 2, 3 ]
|
220
|
+
assert_equal S( O, 3 )[ 4, 5, 6 ], s.b = S( O, 3 )[ 4, 5, 6 ]
|
221
|
+
assert_equal t[ C( 1, 1, 4 ), C( 1, 2, 5 ), C( 1, 3, 6 ) ], s
|
222
|
+
assert_raise( RuntimeError ) { s.r = S[ 1, 2 ] }
|
223
|
+
assert_raise( RuntimeError ) { s.g = S[ 1, 2 ] }
|
224
|
+
assert_raise( RuntimeError ) { s.b = S[ 1, 2, 3, 4 ] }
|
225
|
+
end
|
226
|
+
assert_equal S[ 1, 2 ], S[ 1, 2 ].r
|
227
|
+
assert_equal S[ 1, 2 ], S[ 1, 2 ].g
|
228
|
+
assert_equal S[ 1, 2 ], S[ 1, 2 ].b
|
229
|
+
assert_raise( RuntimeError ) { S[ 1, 2 ].r = 1 }
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_real_imag
|
233
|
+
[ S( O, 2 ), S( X, 2 ) ].each do |t|
|
234
|
+
assert_equal [ 1, 3 ], t[ X( 1, 2 ), 3 ].real.to_a
|
235
|
+
assert_equal [ 2, 0 ], t[ X( 1, 2 ), 3 ].imag.to_a
|
236
|
+
s = t[ 0, 0 ]
|
237
|
+
assert_equal 1, s.real = 1
|
238
|
+
assert_equal S[ 2, 3 ], s.imag = S[ 2, 3 ]
|
239
|
+
assert_equal t[ X( 1, 2 ), X( 1, 3 ) ], s
|
240
|
+
assert_raise( RuntimeError ) { s.real = S[ 1 ] }
|
241
|
+
assert_raise( RuntimeError ) { s.imag = S[ 1, 2, 3 ] }
|
242
|
+
end
|
243
|
+
assert_equal S[ 1, 2 ], S[ 1, 2 ].real
|
244
|
+
assert_equal S[ 0, 0 ], S[ 1, 2 ].imag
|
245
|
+
s = S[ 1, 2 ]
|
246
|
+
assert_equal S[ 3, 4 ], s.real = S[ 3, 4 ]
|
247
|
+
assert_equal S[ 3, 4 ], s
|
248
|
+
assert_raise( RuntimeError ) { S[ 1, 2 ].real = S[ 1, 2, 3 ] }
|
249
|
+
assert_raise( RuntimeError ) { S[ 1, 2 ].imag = S[ 0, 0 ] }
|
250
|
+
end
|
251
|
+
|
169
252
|
def test_inject
|
170
253
|
assert_equal 6, S[ 1, 2, 3 ].inject { |a,b| a + b }
|
171
254
|
assert_equal 10, S[ 1, 2, 3 ].inject( 4 ) { |a,b| a + b }
|
@@ -174,6 +257,14 @@ class TC_Sequence < Test::Unit::TestCase
|
|
174
257
|
assert_equal C( 3, 5, 8 ), S[ C( 1, 2, 3 ), C( 2, 3, 5 ) ].inject { |a,b| a + b }
|
175
258
|
assert_equal C( 5, 6, 8 ), S[ C( 1, 2, 3 ), C( 2, 3, 5 ) ].
|
176
259
|
inject( C( 2, 1, 0 ) ) { |a,b| a + b }
|
260
|
+
assert_equal C( 7, 8, 9 ), S[ 1, 2, 3 ].inject( C( 1, 2, 3 ) ) { |a,b| a + b }
|
261
|
+
assert_equal C( 4, 6, 9 ), S[ C( 1, 2, 3 ), C( 2, 3, 5 ) ].
|
262
|
+
inject( 1 ) { |a,b| a + b }
|
263
|
+
assert_equal X( -5, 10 ), S( X, 2 )[ X( 1, 2 ), X( 3, 4 ) ].inject { |a,b| a * b }
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_collect
|
267
|
+
assert_equal S[ 2, 3 ], S[ 1, 2 ].collect { |x| x + 1 }
|
177
268
|
end
|
178
269
|
|
179
270
|
def test_sum
|
@@ -182,6 +273,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
182
273
|
assert_equal [ 1, 2, 3 ], sum { || t[ 1, 2, 3 ] }.to_a
|
183
274
|
end
|
184
275
|
assert_equal C( 3, 5, 8 ), sum { |i| S[ C( 1, 2, 3 ), C( 2, 3, 5 ) ][i] }
|
276
|
+
assert_equal X( 4, 6 ), sum { |i| S[ X( 1, 2 ), X( 3, 4 ) ][i] }
|
185
277
|
end
|
186
278
|
|
187
279
|
def test_min
|
@@ -212,6 +304,7 @@ class TC_Sequence < Test::Unit::TestCase
|
|
212
304
|
S( t, 5 )[ 0, 0, 0, 0, 1 ].convolve( S( t, 3 )[ 1, 2, 3 ] )
|
213
305
|
assert_equal S( t, 4 )[ 1, 2, 3, 0 ],
|
214
306
|
S( t, 4 )[ 0, 1, 0, 0 ].convolve( S( t, 3 )[ 1, 2, 3 ] )
|
307
|
+
assert_raise( RuntimeError ) { S[ 1, 2, 3 ].convolve 1 }
|
215
308
|
end
|
216
309
|
assert_equal S[ C( 1, 0, 0 ), C( 2, 1, 0 ), C( 3, 2, 1 ), C( 0, 3, 2 ),
|
217
310
|
C( 0, 0, 3 ) ],
|
@@ -225,6 +318,8 @@ class TC_Sequence < Test::Unit::TestCase
|
|
225
318
|
end
|
226
319
|
assert_equal S[ false, false, false, true ],
|
227
320
|
S[ C( 1, 0, 0 ), C( 0, 1, 0 ), C( 0, 0, 1 ), C( 0, 0, 0 ) ].zero?
|
321
|
+
assert_equal S[ true, false, false ],
|
322
|
+
S[ X( 0, 0 ), X( 1, 0 ), X( 0, 1 ) ].zero?
|
228
323
|
end
|
229
324
|
|
230
325
|
def test_nonzero
|
@@ -232,6 +327,8 @@ class TC_Sequence < Test::Unit::TestCase
|
|
232
327
|
assert_equal S[ -1, nil, 1 ], S( O, 3 )[ -1, 0, 1 ].nonzero?
|
233
328
|
assert_equal S[ true, true, true, false ],
|
234
329
|
S[ C( 1, 0, 0 ), C( 0, 1, 0 ), C( 0, 0, 1 ), C( 0, 0, 0 ) ].nonzero?
|
330
|
+
assert_equal S[ false, true, true ],
|
331
|
+
S[ X( 0, 0 ), X( 1, 0 ), X( 0, 1 ) ].nonzero?
|
235
332
|
end
|
236
333
|
|
237
334
|
def test_not
|
@@ -333,11 +430,114 @@ class TC_Sequence < Test::Unit::TestCase
|
|
333
430
|
assert_equal S[ C( 2, 3, 4 ), C( 5, 6, 7 ) ], S[ C( 1, 2, 3 ), C( 4, 5, 6 ) ] + 1
|
334
431
|
assert_equal S[ C( 2, 3, 4 ), C( 5, 6, 7 ) ], 1 + S[ C( 1, 2, 3 ), C( 4, 5, 6 ) ]
|
335
432
|
assert_equal S[ C( 2, 3, 4 ), C( 3, 4, 5 ) ], S[ 1, 2 ] + C( 1, 2, 3 )
|
433
|
+
assert_equal S[ X( 4, 6 ) ], S[ X( 1, 2 ) ] + S[ X( 3, 4 ) ]
|
434
|
+
assert_raise( RuntimeError ) { S[ 1, 2, 3 ] + S[ 1, 2 ] }
|
435
|
+
assert_raise( RuntimeError ) { S[ 1, 2 ] + S[ 1, 2, 3 ] }
|
336
436
|
end
|
337
437
|
|
338
|
-
def
|
339
|
-
assert_equal S
|
340
|
-
assert_equal S[ 1
|
438
|
+
def test_minus
|
439
|
+
assert_equal S[ 1, 2, 4 ], S[ 2, 3, 5 ] - 1
|
440
|
+
assert_equal S[ 1, 2, 4 ], 5 - S[ 4, 3, 1 ]
|
441
|
+
assert_equal S[ 1, 2, 3 ], S[ 2, 3, 5 ] - S[ 1, 1, 2 ]
|
442
|
+
assert_equal S[ C( 1, 2, 3 ), C( 4, 5, 6 ) ], S[ C( 2, 3, 4 ), C( 5, 6, 7 ) ] - 1
|
443
|
+
assert_equal S[ C( 6, 5, 4 ), C( 3, 2, 1 ) ], 7 - S[ C( 1, 2, 3 ), C( 4, 5, 6 ) ]
|
444
|
+
assert_equal S[ C( 3, 2, 1 ), C( 4, 3, 2 ) ], S[ 4, 5 ] - C( 1, 2, 3 )
|
445
|
+
assert_equal S[ X( -1.0, 2.0 ) ], -S[ X( 1.0, -2.0 ) ]
|
446
|
+
end
|
447
|
+
|
448
|
+
def test_conj
|
449
|
+
assert_equal S[ 1.5, 2.5 ], S[ 1.5, 2.5 ].conj
|
450
|
+
assert_equal S[ X( 1.5, -2.5 ) ], S[ X( 1.5, 2.5 ) ].conj
|
451
|
+
end
|
452
|
+
|
453
|
+
def test_abs
|
454
|
+
assert_equal [ 1, 0, 1 ], S[ -1, 0, 1 ].abs.to_a
|
455
|
+
assert_equal [ 5 ], S[ X( 3, 4 ) ].abs.to_a
|
456
|
+
end
|
457
|
+
|
458
|
+
def test_arg
|
459
|
+
assert_equal S[ 0.0, Math::PI ], S[ 1, -1 ].arg
|
460
|
+
assert_equal S[ 0.0, Math::PI / 2, Math::PI, -Math::PI / 2 ],
|
461
|
+
S[ X( 1, 0 ), X( 0, 1 ), X( -1, 0 ), X( 0, -1 ) ].arg
|
462
|
+
end
|
463
|
+
|
464
|
+
def test_mul
|
465
|
+
assert_equal S[ 6, 12, 20 ], S[ 2, 3, 4 ] * S[ 3, 4, 5 ]
|
466
|
+
assert_equal S[ C( -2, 0, 4 ) ], S[ C( 2, 3, 4 ) ] * S[ C( -1, 0, 1 ) ]
|
467
|
+
assert_equal S[ X( -11, 2 ) ], S[ X( -1, 2 ) ] * S[ X( 3, 4 ) ]
|
468
|
+
end
|
469
|
+
|
470
|
+
def test_div
|
471
|
+
assert_equal S[ 2, 3, 4 ], S[ 6, 12, 20 ] / S[ 3, 4, 5 ]
|
472
|
+
assert_equal S[ X( -1, 2 ) ], S[ X( -11, 2 ) ] / S[ X( 3, 4 ) ]
|
473
|
+
end
|
474
|
+
|
475
|
+
def test_mod
|
476
|
+
assert_equal S[ 2, 0, 1 ], S[ 2, 3, 4 ] % 3
|
477
|
+
end
|
478
|
+
|
479
|
+
def test_pow
|
480
|
+
assert_equal [ 1, 4, 9 ], ( S[ 1, 2, 3 ] ** 2 ).to_a
|
481
|
+
assert_in_delta 0.0, ( ( S( X, 1 )[ X( 1, 2 ) ] ** 2 )[ 0 ] - X( -3, 4 ) ).abs,
|
482
|
+
1.0e-5
|
483
|
+
assert_in_delta 0.0, ( Math::E ** S( X, 1 )[ X( 0, Math::PI ) ][ 0 ] + 1 ).abs,
|
484
|
+
1.0e-5
|
485
|
+
end
|
486
|
+
|
487
|
+
def test_eq
|
488
|
+
assert_equal S[ false, true, false ], S[ 1, 2, 3 ].eq( 2 )
|
489
|
+
assert_equal S[ false, true ],
|
490
|
+
S[ C( 1, 2, 1 ), C( 2, 1, 0 ) ].eq( S[ C( 1, 2, 3 ), C( 2, 1, 0 ) ] )
|
491
|
+
assert_equal S[ false, true, false ],
|
492
|
+
X( 1, 2 ).eq( S[ X( 1, 1 ), X( 1, 2 ), X( 2, 2 ) ] )
|
493
|
+
end
|
494
|
+
|
495
|
+
def test_ne
|
496
|
+
assert_equal S[ true, false, true ], S[ 1, 2, 3 ].ne( 2 )
|
497
|
+
end
|
498
|
+
|
499
|
+
def test_lt
|
500
|
+
assert_equal S[ true, false, false ], S[ 1, 2, 3 ] < 2
|
501
|
+
end
|
502
|
+
|
503
|
+
def test_le
|
504
|
+
assert_equal S[ true, true, false ], S[ 1, 2, 3 ] <= 2
|
505
|
+
end
|
506
|
+
|
507
|
+
def test_gt
|
508
|
+
assert_equal S[ false, false, true ], S[ 1, 2, 3 ] > 2
|
509
|
+
end
|
510
|
+
|
511
|
+
def test_ge
|
512
|
+
assert_equal S[ false, true, true ], S[ 1, 2, 3 ] >= 2
|
513
|
+
end
|
514
|
+
|
515
|
+
def test_floor
|
516
|
+
assert_equal S[ 0.0, 0.0, 1.0 ], S[ 0.3, 0.7, 1.3 ].floor
|
517
|
+
end
|
518
|
+
|
519
|
+
def test_ceil
|
520
|
+
assert_equal S[ 1.0, 1.0, 2.0 ], S[ 0.3, 0.7, 1.3 ].ceil
|
521
|
+
end
|
522
|
+
|
523
|
+
def test_round
|
524
|
+
assert_equal S[ 0.0, 1.0, 1.0 ], S[ 0.3, 0.7, 1.3 ].round
|
525
|
+
end
|
526
|
+
|
527
|
+
def test_cond
|
528
|
+
assert_equal S[ 1, 2 ], S[ false, true ].conditional( 2, 1 )
|
529
|
+
assert_equal S[ -1, 2 ], S[ false, true ].conditional( S[ 1, 2 ], -1 )
|
530
|
+
assert_equal S[ -1, 1 ], S[ false, true ].conditional( 1, S[ -1, -2 ] )
|
531
|
+
assert_equal S[ -1, 2 ], S[ false, true ].conditional( S[ 1, 2 ], S[ -1, -2 ] )
|
532
|
+
assert_raise( RuntimeError ) { S[ false, true ].conditional( S[ 1, 2 ], S[ 1 ] ) }
|
533
|
+
assert_raise( RuntimeError ) { S[ false, true ].conditional( S[ 1 ], S[ 1, 2 ] ) }
|
534
|
+
assert_raise( RuntimeError ) { S[ false ].conditional( S[ 1, 2 ], S[ 1, 2 ] ) }
|
535
|
+
end
|
536
|
+
|
537
|
+
def test_cmp
|
538
|
+
assert_equal S[ -1, 0, 1 ], S[ 1, 2, 3 ] <=> 2
|
539
|
+
assert_equal S[ 1, 0, -1 ], 2 <=> S[ 1, 2, 3 ]
|
540
|
+
assert_equal S[ -1, 0, 1 ], S[ 1, 3, 5 ] <=> S[ 2, 3, 4 ]
|
341
541
|
end
|
342
542
|
|
343
543
|
def test_major
|
@@ -354,8 +554,21 @@ class TC_Sequence < Test::Unit::TestCase
|
|
354
554
|
assert_equal [ C( 1, 2, 2 ) ], S[ C( 1, 2, 3 ) ].minor( 2 ).to_a
|
355
555
|
end
|
356
556
|
|
557
|
+
def test_sqrt
|
558
|
+
assert_equal S( O, 3 )[ 1, 2, 3 ], Math.sqrt( S( O, 3 )[ 1, 4, 9 ] )
|
559
|
+
assert_equal S[ 1.0, 2.0, 3.0 ], Math.sqrt( S[ 1.0, 4.0, 9.0 ] )
|
560
|
+
end
|
561
|
+
|
357
562
|
def test_hypot
|
358
563
|
assert_equal S[ 5.0, 5.0 ], Math.hypot( S[ 3, 4 ], S[ 4, 3 ] )
|
564
|
+
assert_raise( RuntimeError ) { Math.hypot( S[ 3 ], S[ 4, 3 ] ) }
|
565
|
+
assert_raise( RuntimeError ) { Math.hypot( S[ 3, 4 ], S[ 4 ] ) }
|
566
|
+
end
|
567
|
+
|
568
|
+
def test_to_type
|
569
|
+
assert_equal S( O, 3 )[ 1, 2, 3 ], S( I, 3 )[ 1, 2, 3 ].to_type( O )
|
570
|
+
assert_equal S( I, 3 )[ 1, 2, 3 ], S( O, 3 )[ 1, 2, 3 ].to_type( I )
|
571
|
+
assert_equal S( C, 3 )[ 1, 2, 3 ], S( I, 3 )[ 1, 2, 3 ].to_type( C )
|
359
572
|
end
|
360
573
|
|
361
574
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multiarray
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
9
|
+
- 2
|
10
|
+
version: 0.5.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jan Wedekind
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-09-12 00:00:00 +01:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,10 +26,11 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ~>
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
28
30
|
segments:
|
29
31
|
- 1
|
30
|
-
-
|
31
|
-
version: "1.
|
32
|
+
- 1
|
33
|
+
version: "1.1"
|
32
34
|
type: :runtime
|
33
35
|
version_requirements: *id001
|
34
36
|
- !ruby/object:Gem::Dependency
|
@@ -39,6 +41,7 @@ dependencies:
|
|
39
41
|
requirements:
|
40
42
|
- - ">="
|
41
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
42
45
|
segments:
|
43
46
|
- 0
|
44
47
|
version: "0"
|
@@ -65,28 +68,27 @@ files:
|
|
65
68
|
- lib/multiarray/bool.rb
|
66
69
|
- lib/multiarray/element.rb
|
67
70
|
- lib/multiarray/gcccache.rb
|
68
|
-
- lib/multiarray/binarymethod.rb
|
69
71
|
- lib/multiarray/int.rb
|
70
72
|
- lib/multiarray/gccfunction.rb
|
71
73
|
- lib/multiarray/float.rb
|
72
74
|
- lib/multiarray/diagonal.rb
|
73
75
|
- lib/multiarray/inject.rb
|
74
76
|
- lib/multiarray/list.rb
|
75
|
-
- lib/multiarray/binaryop.rb
|
76
77
|
- lib/multiarray/pointer.rb
|
77
78
|
- lib/multiarray/lambda.rb
|
78
79
|
- lib/multiarray/sequence.rb
|
79
80
|
- lib/multiarray/methods.rb
|
80
|
-
- lib/multiarray/unarymethod.rb
|
81
81
|
- lib/multiarray/multiarray.rb
|
82
82
|
- lib/multiarray/node.rb
|
83
|
-
- lib/multiarray/unaryop.rb
|
84
83
|
- lib/multiarray/malloc.rb
|
85
84
|
- lib/multiarray/index.rb
|
86
85
|
- lib/multiarray/rgb.rb
|
87
86
|
- lib/multiarray/gcccontext.rb
|
87
|
+
- lib/multiarray/composite.rb
|
88
|
+
- lib/multiarray/elementwise.rb
|
88
89
|
- lib/multiarray/lookup.rb
|
89
90
|
- lib/multiarray/gccvalue.rb
|
91
|
+
- lib/multiarray/complex.rb
|
90
92
|
- lib/multiarray.rb
|
91
93
|
- test/ts_multiarray.rb
|
92
94
|
- test/tc_float.rb
|
@@ -111,6 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
113
|
requirements:
|
112
114
|
- - ">="
|
113
115
|
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
114
117
|
segments:
|
115
118
|
- 0
|
116
119
|
version: "0"
|
@@ -119,6 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
122
|
requirements:
|
120
123
|
- - ">="
|
121
124
|
- !ruby/object:Gem::Version
|
125
|
+
hash: 3
|
122
126
|
segments:
|
123
127
|
- 0
|
124
128
|
version: "0"
|