~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to test/bitarray.jl

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-02-11 03:51:26 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130211035126-hap464pbhd97wjbl
Tags: 0.1~20130211.git86fbe98d-1
* New upstream snapshot.
* debian/control:
   + add git to Recommends (for Julia package manager)
   + remove dependencies on libglpk-dev (it moved to its own package)
   + add explicit dependency on libgmp10 (there is no more a wrapper)
* fix-clean-rules.patch: remove patch, applied upstream
* gsvddense_blasint.patch: new patch
* Refresh other patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# for now, manually import necessary bit array functions:
2
 
 
3
1
macro check_bit_operation(func, RetT, args)
4
2
    quote
5
 
        r1 = ($func)($(args.args...))
 
3
        r1 = ($func)($args...)
6
4
        r2 = ($func)(map(x->(isa(x, BitArray) ? bitunpack(x) : x), $args)...)
7
5
        @test isa(r1, $RetT)
8
6
        @test isequal(r1, convert($RetT, r2))
65
63
@check_bit_operation ref BitMatrix (b1, 1:m1, [n2,m2,1])
66
64
b2 = randbool(m1, m2)
67
65
@check_bit_operation assign BitMatrix (b1, b2, 1:m1, n2-m2+1:n2)
 
66
k1 = randperm(m1)
 
67
k2 = randperm(m2)
 
68
@check_bit_operation assign BitMatrix (b1, b2, 1:m1, k2)
 
69
@check_bit_operation assign BitMatrix (b1, b2, k1, k2)
68
70
b2 = randbool(m1)
69
71
@check_bit_operation assign BitMatrix (b1, b2, 1:m1, m2)
70
72
 
204
206
b1 = randbool(n1, n2)
205
207
@check_bit_operation (~) BitMatrix (b1,)
206
208
@check_bit_operation (!) BitMatrix (b1,)
207
 
#@check_bit_operation (-) Matrix{Int} (b1,)
 
209
@check_bit_operation (-) Matrix{Int} (b1,)
208
210
@check_bit_operation sign BitMatrix (b1,)
209
211
@check_bit_operation real BitMatrix (b1,)
210
212
@check_bit_operation imag BitMatrix (b1,)
213
215
b0 = falses(0)
214
216
@check_bit_operation (~) BitVector (b0,)
215
217
@check_bit_operation (!) BitVector (b0,)
216
 
#@check_bit_operation (-) Vector{Int} (b0,)
 
218
@check_bit_operation (-) Vector{Int} (b0,)
217
219
@check_bit_operation sign BitVector (b0,)
218
220
 
219
221
timesofar("unary arithmetic")
220
222
 
221
223
## Binary arithmetic operators ##
222
224
 
 
225
# Matrix{Bool}/Matrix{Bool}
 
226
 
223
227
b1 = randbool(n1, n2)
224
228
b2 = randbool(n1, n2)
225
229
@check_bit_operation (&) BitMatrix (b1, b2)
226
230
@check_bit_operation (|) BitMatrix (b1, b2)
227
231
@check_bit_operation ($) BitMatrix (b1, b2)
 
232
@check_bit_operation (+) Matrix{Int} (b1, b2)
228
233
@check_bit_operation (-) Matrix{Int} (b1, b2)
229
234
@check_bit_operation (.*) BitMatrix (b1, b2)
230
235
@check_bit_operation (./) Matrix{Float64} (b1, b2)
231
 
@check_bit_operation (.^) Matrix{Float64} (b1, b2)
 
236
@check_bit_operation (.^) BitMatrix (b1, b2)
232
237
 
233
238
b2 = trues(n1, n2)
234
239
@check_bit_operation div Matrix{Bool} (b1, b2)
247
252
@check_bit_operation (/) Matrix{Float64} (b1, b1)
248
253
@check_bit_operation (\) Matrix{Float64} (b1, b1)
249
254
 
250
 
b1 = randbool(n1, n2)
251
 
b2 = rand(1:10, n1, n2)
 
255
b0 = falses(0)
 
256
@check_bit_operation (&) BitVector (b0, b0)
 
257
@check_bit_operation (|) BitVector (b0, b0)
 
258
@check_bit_operation ($) BitVector (b0, b0)
 
259
@check_bit_operation (.*) BitVector (b0, b0)
 
260
@check_bit_operation (*) BitMatrix (b0, b0')
 
261
 
 
262
# Matrix{Bool}/Matrix{Int}
 
263
b1 = randbool(n1, n2)
 
264
i2 = rand(1:10, n1, n2)
 
265
@check_bit_operation (&) Matrix{Int} (b1, i2)
 
266
@check_bit_operation (|) Matrix{Int} (b1, i2)
 
267
@check_bit_operation ($) Matrix{Int} (b1, i2)
 
268
@check_bit_operation (+) Matrix{Int} (b1, i2)
 
269
@check_bit_operation (-) Matrix{Int} (b1, i2)
 
270
@check_bit_operation (.*) Matrix{Int} (b1, i2)
 
271
@check_bit_operation (./) Matrix{Float64} (b1, i2)
 
272
@check_bit_operation (.^) BitMatrix (b1, i2)
 
273
@check_bit_operation div Matrix{Int} (b1, i2)
 
274
@check_bit_operation mod Matrix{Int} (b1, i2)
 
275
 
 
276
# Matrix{Bool}/Matrix{Float64}
 
277
b1 = randbool(n1, n2)
 
278
f2 = 1.0 + rand(n1, n2)
 
279
@check_bit_operation (.*) Matrix{Float64} (b1, f2)
 
280
@check_bit_operation (./) Matrix{Float64} (b1, f2)
 
281
@check_bit_operation (.^) Matrix{Float64} (b1, f2)
 
282
@check_bit_operation div Matrix{Float64} (b1, f2)
 
283
@check_bit_operation mod Matrix{Float64} (b1, f2)
 
284
 
 
285
# Number/Matrix
 
286
b2 = randbool(n1, n2)
 
287
i1 = rand(1:10)
 
288
@check_bit_operation (&) Matrix{Int} (i1, b2)
 
289
@check_bit_operation (|) Matrix{Int} (i1, b2)
 
290
@check_bit_operation ($) Matrix{Int} (i1, b2)
 
291
@check_bit_operation (+) Matrix{Int} (i1, b2)
 
292
@check_bit_operation (-) Matrix{Int} (i1, b2)
 
293
@check_bit_operation (.*) Matrix{Int} (i1, b2)
 
294
u1 = uint8(rand(1:10))
 
295
@check_bit_operation (&) Matrix{Uint8} (u1, b2)
 
296
@check_bit_operation (|) Matrix{Uint8} (u1, b2)
 
297
@check_bit_operation ($) Matrix{Uint8} (u1, b2)
 
298
@check_bit_operation (+) Matrix{Uint} (u1, b2)
 
299
@check_bit_operation (-) Matrix{Uint} (u1, b2)
 
300
@check_bit_operation (.*) Matrix{Uint8} (u1, b2)
 
301
 
 
302
f1 = float64(i1)
 
303
ci1 = complex(i1)
 
304
cu1 = complex(u1)
 
305
cf1 = complex(f1)
 
306
 
 
307
for (x1,t1,t2) = {(f1, Float64, Float64),
 
308
                  (ci1, ComplexPair{Int}, ComplexPair{Int}),
 
309
                  (cu1, ComplexPair{Uint}, ComplexPair{Uint8}),
 
310
                  (cf1, Complex128, Complex128)}
 
311
    @check_bit_operation (+) Matrix{t1} (x1, b2)
 
312
    @check_bit_operation (-) Matrix{t1} (x1, b2)
 
313
    @check_bit_operation (.*) Matrix{t2} (x1, b2)
 
314
end
 
315
 
 
316
b2 = trues(n1, n2)
 
317
@check_bit_operation (./) Matrix{Float64} (i1, b2)
 
318
@check_bit_operation div Matrix{Int} (i1, b2)
 
319
@check_bit_operation mod Matrix{Int} (i1, b2)
 
320
 
 
321
@check_bit_operation (./) Matrix{Float64} (f1, b2)
 
322
@check_bit_operation div Matrix{Float64} (f1, b2)
 
323
@check_bit_operation mod Matrix{Float64} (f1, b2)
 
324
 
 
325
for x1 = {ci1, cu1, cf1}
 
326
    @check_bit_operation (./) Matrix{Complex128} (x1, b2)
 
327
end
 
328
 
 
329
@check_bit_operation (.^) BitMatrix (false, b1)
 
330
@check_bit_operation (.^) BitMatrix (true, b1)
 
331
@check_bit_operation (.^) Matrix{Uint8} (0x0, b1)
 
332
@check_bit_operation (.^) Matrix{Uint8} (0x1, b1)
 
333
@check_bit_operation (.^) Matrix{Int} (-1, b1)
 
334
@check_bit_operation (.^) Matrix{Int} (0, b1)
 
335
@check_bit_operation (.^) Matrix{Int} (1, b1)
 
336
@check_bit_operation (.^) Matrix{Float64} (0.0, b1)
 
337
@check_bit_operation (.^) Matrix{Float64} (1.0, b1)
 
338
@check_bit_operation (.^) Matrix{Complex128} (0.0im, b1)
 
339
@check_bit_operation (.^) Matrix{Complex128} (1.0im, b1)
 
340
@check_bit_operation (.^) Matrix{ComplexPair{Int}} (0im, b1)
 
341
@check_bit_operation (.^) Matrix{ComplexPair{Int}} (1im, b1)
 
342
 
 
343
# Matrix/Number
 
344
b1 = randbool(n1, n2)
 
345
b2 = rand(1:10)
252
346
@check_bit_operation (&) Matrix{Int} (b1, b2)
253
347
@check_bit_operation (|) Matrix{Int} (b1, b2)
254
348
@check_bit_operation ($) Matrix{Int} (b1, b2)
255
349
@check_bit_operation (-) Matrix{Int} (b1, b2)
256
350
@check_bit_operation (.*) Matrix{Int} (b1, b2)
257
351
@check_bit_operation (./) Matrix{Float64} (b1, b2)
258
 
@check_bit_operation (.^) Matrix{Float64} (b1, b2)
259
352
@check_bit_operation div Matrix{Int} (b1, b2)
260
353
@check_bit_operation mod Matrix{Int} (b1, b2)
261
354
 
262
 
b1 = randbool(n1, n2)
263
 
b2 = randbool(n1, n2)
264
 
@check_bit_operation (&) BitMatrix (b1, b2)
265
 
@check_bit_operation (|) BitMatrix (b1, b2)
266
 
@check_bit_operation ($) BitMatrix (b1, b2)
267
 
@check_bit_operation (.*) BitMatrix (b1, b2)
268
 
@check_bit_operation (*) BitMatrix (b1, b1')
 
355
@check_bit_operation (.^) BitMatrix (b1, false)
 
356
@check_bit_operation (.^) BitMatrix (b1, true)
 
357
@check_bit_operation (.^) BitMatrix (b1, 0x0)
 
358
@check_bit_operation (.^) BitMatrix (b1, 0x1)
 
359
@check_bit_operation (.^) BitMatrix (b1, 0)
 
360
@check_bit_operation (.^) BitMatrix (b1, 1)
 
361
@check_bit_operation (.^) Matrix{Float64} (b1, -1.0)
 
362
@check_bit_operation (.^) Matrix{Float64} (b1, 0.0)
 
363
@check_bit_operation (.^) Matrix{Float64} (b1, 1.0)
 
364
@check_bit_operation (.^) Matrix{Complex128} (b1, 0.0im)
 
365
@check_bit_operation (.^) Matrix{ComplexPair{Int}} (b1, 0im)
269
366
 
270
 
b0 = falses(0)
271
 
@check_bit_operation (&) BitVector (b0, b0)
272
 
@check_bit_operation (|) BitVector (b0, b0)
273
 
@check_bit_operation ($) BitVector (b0, b0)
274
 
@check_bit_operation (.*) BitVector (b0, b0)
275
 
@check_bit_operation (*) BitMatrix (b0, b0')
 
367
b1 = trues(n1, n2)
 
368
@check_bit_operation (.^) Matrix{Complex128} (b1, -1.0im)
 
369
@check_bit_operation (.^) Matrix{Complex128} (b1, 1.0im)
 
370
@check_bit_operation (.^) Matrix{Complex128} (b1, -1im)
 
371
@check_bit_operation (.^) Matrix{Complex128} (b1, 1im)
276
372
 
277
373
timesofar("binary arithmetic")
278
374
 
312
408
for m = [rand(1:v1)-1 0 1 63 64 65 191 192 193 v1-1]
313
409
    @test isequal(b1 << m, [ b1[m+1:end]; falses(m) ])
314
410
    @test isequal(b1 >>> m, [ falses(m); b1[1:end-m] ])
315
 
    @test isequal(rotl(b1, m), [ b1[m+1:end]; b1[1:m] ])
316
 
    @test isequal(rotr(b1, m), [ b1[end-m+1:end]; b1[1:end-m] ])
 
411
    @test isequal(rol(b1, m), [ b1[m+1:end]; b1[1:m] ])
 
412
    @test isequal(ror(b1, m), [ b1[end-m+1:end]; b1[1:end-m] ])
317
413
end
318
414
 
319
415
timesofar("datamove")
391
487
 
392
488
timesofar("transpose")
393
489
 
394
 
## Permute ##
 
490
## Permutedims ##
395
491
 
396
492
b1 = randbool(s1, s2, s3, s4)
397
493
p = randperm(4)
398
 
@check_bit_operation permute BitArray{4} (b1, p)
 
494
@check_bit_operation permutedims BitArray{4} (b1, p)
399
495
 
400
 
timesofar("permute")
 
496
timesofar("permutedims")
401
497
 
402
498
## Concatenation ##
403
499