1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
|
tc{N}(r1::NTuple{N}, r2::NTuple{N}) = all(map(x->tc(x...), [zip(r1,r2)...]))
tc{N}(r1::BitArray{N}, r2::Union(BitArray{N},Array{Bool,N})) = true
tc{T}(r1::T, r2::T) = true
tc(r1,r2) = false
function check_bitop(ret_type, func, args...)
r1 = func(args...)
r2 = func(map(x->(isa(x, BitArray) ? bitunpack(x) : x), args)...)
@test isa(r1, ret_type)
@test tc(r1, r2)
@test isequal(r1, convert(ret_type, r2))
end
macro check_bit_operation(ex, ret_type)
@assert Meta.isexpr(ex, :call)
Expr(:call, :check_bitop, esc(ret_type), map(esc,ex.args)...)
end
let t0 = time()
global timesofar
function timesofar(str)
return # no-op, comment to see timings
t1 = time()
println(str, ": ", t1-t0, " seconds")
t0 = t1
end
end
# vectors size
v1 = 260
# matrices size
n1, n2 = 17, 20
# arrays size
s1, s2, s3, s4 = 5, 8, 3, 4
allsizes = [((), BitArray{0}), ((v1,), BitVector),
((n1,n2), BitMatrix), ((s1,s2,s3,s4), BitArray{4})]
## Conversions ##
for (sz,T) in allsizes
b1 = randbool!(falses(sz...))
@test isequal(bitpack(bitunpack(b1)), b1)
@test isequal(convert(Array{Float64,ndims(b1)}, b1),
convert(Array{Float64,ndims(b1)}, bitunpack(b1)))
@test isequal(convert(AbstractArray{Float64,ndims(b1)}, b1),
convert(AbstractArray{Float64,ndims(b1)}, bitunpack(b1)))
i1 = rand!(false:true, zeros(Bool, sz...))
@test isequal(bitunpack(bitpack(i1)), i1)
end
timesofar("conversions")
## utility functions ##
b1 = randbool(v1)
@test isequal(fill!(b1, true), trues(size(b1)))
@test isequal(fill!(b1, false), falses(size(b1)))
for (sz,T) in allsizes
@test isequal(bitunpack(trues(sz...)), ones(Bool, sz...))
@test isequal(bitunpack(falses(sz...)), zeros(Bool, sz...))
b1 = randbool!(falses(sz...))
@test isa(b1, T)
@check_bit_operation length(b1) Int
@check_bit_operation ndims(b1) Int
@check_bit_operation size(b1) (Int...)
b2 = similar(b1)
@check_bit_operation copy!(b2, b1) T
end
timesofar("utils")
## Indexing ##
# 0d
for (sz,T) in allsizes
b1 = randbool!(falses(sz...))
@check_bit_operation getindex(b1) Bool
@check_bit_operation setindex!(b1, true) T
@check_bit_operation setindex!(b1, false) T
@check_bit_operation setindex!(b1, 1.0) T
end
# linear
for (sz,T) in allsizes[2:end]
l = *(sz...)
b1 = randbool!(falses(sz...))
for j = 1:l
@check_bit_operation getindex(b1, j) Bool
end
@check_bit_operation getindex(b1, 100.0) Bool
for j in [0, 1, 63, 64, 65, 127, 128, 129, 191, 192, 193, l-1, l]
@check_bit_operation getindex(b1, 1:j) BitVector
@check_bit_operation getindex(b1, j+1:l) BitVector
end
for j in [1, 63, 64, 65, 127, 128, 129, div(l,2)]
m1 = j:(l-j)
@check_bit_operation getindex(b1, m1) BitVector
end
@check_bit_operation getindex(b1, 1.0:100.0) BitVector
t1 = find(randbool(l))
@check_bit_operation getindex(b1, t1) BitVector
@check_bit_operation getindex(b1, float(t1)) BitVector
for j = 1:l
x = randbool()
@check_bit_operation setindex!(b1, x, j) T
end
x = randbool()
@check_bit_operation setindex!(b1, x, 100.0) T
y = rand(0.0:1.0)
@check_bit_operation setindex!(b1, y, 100) T
y = rand(0.0:1.0)
@check_bit_operation setindex!(b1, y, 100.0) T
for j in [1, 63, 64, 65, 127, 128, 129, 191, 192, 193, l-1]
x = randbool()
@check_bit_operation setindex!(b1, x, 1:j) T
b2 = randbool(j)
@check_bit_operation setindex!(b1, b2, 1:j) T
x = randbool()
@check_bit_operation setindex!(b1, x, j+1:l) T
b2 = randbool(l-j)
@check_bit_operation setindex!(b1, b2, j+1:l) T
end
for j in [1, 63, 64, 65, 127, 128, 129, div(l,2)]
m1 = j:(l-j)
x = randbool()
@check_bit_operation setindex!(b1, x, m1) T
b2 = randbool(length(m1))
@check_bit_operation setindex!(b1, b2, m1) T
end
x = randbool()
@check_bit_operation setindex!(b1, x, 1.0:100.0) T
b2 = randbool(100)
@check_bit_operation setindex!(b1, b2, 1.0:100.0) T
y = rand(0.0:1.0)
@check_bit_operation setindex!(b1, y, 1:100) T
f2 = float(randbool(100))
@check_bit_operation setindex!(b1, f2, 1:100) T
f2 = float(randbool(100))
@check_bit_operation setindex!(b1, f2, 1.0:100.0) T
t1 = find(randbool(l))
x = randbool()
@check_bit_operation setindex!(b1, x, t1) T
b2 = randbool(length(t1))
@check_bit_operation setindex!(b1, b2, t1) T
y = rand(0.0:1.0)
@check_bit_operation setindex!(b1, y, t1) T
f2 = float(randbool(length(t1)))
@check_bit_operation setindex!(b1, f2, t1) T
ft1 = float(t1)
x = randbool()
@check_bit_operation setindex!(b1, x, ft1) T
b2 = randbool(length(t1))
@check_bit_operation setindex!(b1, b2, ft1) T
y = rand(0.0:1.0)
@check_bit_operation setindex!(b1, y, ft1) T
f2 = float(randbool(length(t1)))
@check_bit_operation setindex!(b1, f2, ft1) T
end
# multidimensional
rand_m1m2() = rand(1:n1), rand(1:n2)
b1 = randbool(n1, n2)
m1, m2 = rand_m1m2()
b2 = randbool(m1, m2)
@check_bit_operation copy!(b1, b2) BitMatrix
function gen_getindex_data()
m1, m2 = rand_m1m2()
produce((m1, m2, Bool))
m1, m2 = rand_m1m2()
produce((m1, 1:m2, BitMatrix))
m1, m2 = rand_m1m2()
produce((m1, randperm(m2), BitMatrix))
m1, m2 = rand_m1m2()
produce((1:m1, m2, BitVector))
m1, m2 = rand_m1m2()
produce((1:m1, 1:m2, BitMatrix))
m1, m2 = rand_m1m2()
produce((1:m1, randperm(m2), BitMatrix))
m1, m2 = rand_m1m2()
produce((randperm(m1), m2, BitVector))
m1, m2 = rand_m1m2()
produce((randperm(m1), 1:m2, BitMatrix))
m1, m2 = rand_m1m2()
produce((randperm(m1), randperm(m2), BitMatrix))
end
for (k1, k2, T) in Task(gen_getindex_data)
# println(typeof(k1), " ", typeof(k2), " ", T) # uncomment to debug
@check_bit_operation getindex(b1, k1, k2) T
@check_bit_operation getindex(b1, k1, k2, 1) T
#@check_bit_operation getindex(b1, float(k1), k2) T
#@check_bit_operation getindex(b1, k1, float(k2)) T
@check_bit_operation getindex(b1, float(k1), float(k2)) T
@check_bit_operation getindex(b1, k1, k2, 1.0) T
#@check_bit_operation getindex(b1, float(k1), float(k2), 1.0) T
end
function gen_setindex_data()
m1, m2 = rand_m1m2()
produce((randbool(), m1, m2))
m1, m2 = rand_m1m2()
produce((randbool(), m1, 1:m2))
produce((randbool(m2), m1, 1:m2))
m1, m2 = rand_m1m2()
produce((randbool(), m1, randperm(m2)))
produce((randbool(m2), m1, randperm(m2)))
m1, m2 = rand_m1m2()
produce((randbool(), 1:m1, m2))
produce((randbool(m1), 1:m1, m2))
m1, m2 = rand_m1m2()
produce((randbool(), 1:m1, 1:m2))
produce((randbool(m1, m2), 1:m1, 1:m2))
m1, m2 = rand_m1m2()
produce((randbool(), 1:m1, randperm(m2)))
produce((randbool(m1, m2), 1:m1, randperm(m2)))
m1, m2 = rand_m1m2()
produce((randbool(), randperm(m1), m2))
produce((randbool(m1), randperm(m1), m2))
m1, m2 = rand_m1m2()
produce((randbool(), randperm(m1), 1:m2))
produce((randbool(m1,m2), randperm(m1), 1:m2))
m1, m2 = rand_m1m2()
produce((randbool(), randperm(m1), randperm(m2)))
produce((randbool(m1,m2), randperm(m1), randperm(m2)))
end
for (b2, k1, k2) in Task(gen_setindex_data)
# println(typeof(b2), " ", typeof(k1), " ", typeof(k2)) # uncomment to debug
@check_bit_operation setindex!(b1, b2, k1, k2) BitMatrix
@check_bit_operation setindex!(b1, float(b2), k1, k2) BitMatrix
@check_bit_operation setindex!(b1, b2, float(k1), k2) BitMatrix
#@check_bit_operation setindex!(b1, b2, k1, float(k2)) BitMatrix
#@check_bit_operation setindex!(b1, float(b2), float(k1), k2) BitMatrix
#@check_bit_operation setindex!(b1, float(b2), k1, float(k2)) BitMatrix
#@check_bit_operation setindex!(b1, b2, float(k1), float(k2)) BitMatrix
@check_bit_operation setindex!(b1, float(b2), float(k1), float(k2)) BitMatrix
end
m1, m2 = rand_m1m2()
b2 = randbool(1, 1, m2)
@check_bit_operation setindex!(b1, b2, m1, 1:m2) BitMatrix
x = randbool()
b2 = randbool(1, m2, 1)
@check_bit_operation setindex!(b1, x, m1, 1:m2, 1) BitMatrix
@check_bit_operation setindex!(b1, b2, m1, 1:m2, 1) BitMatrix
for p1 = [rand(1:v1) 1 63 64 65 191 192 193]
for p2 = [rand(1:v1) 1 63 64 65 191 192 193]
for n = 0 : min(v1 - p1 + 1, v1 - p2 + 1)
b1 = randbool(v1)
b2 = randbool(v1)
@check_bit_operation copy!(b1, p1, b2, p2, n) BitVector
end
end
end
# logical indexing
b1 = randbool(n1, n2)
t1 = randbool(n1, n2)
@test isequal(bitunpack(b1[t1]), bitunpack(b1)[t1])
@test isequal(bitunpack(b1[t1]), bitunpack(b1)[bitunpack(t1)])
t1 = randbool(n1)
t2 = randbool(n2)
@test isequal(bitunpack(b1[t1, t2]), bitunpack(b1)[t1, t2])
@test isequal(bitunpack(b1[t1, t2]), bitunpack(b1)[bitunpack(t1), bitunpack(t2)])
b1 = randbool(n1, n2)
t1 = randbool(n1, n2)
@check_bit_operation setindex!(b1, true, t1) BitMatrix
t1 = randbool(n1, n2)
b2 = randbool(countnz(t1))
@check_bit_operation setindex!(b1, b2, t1) BitMatrix
m1 = rand(1:n1)
m2 = rand(1:n2)
t1 = randbool(n1)
b2 = randbool(countnz(t1), m2)
k2 = randperm(m2)
@check_bit_operation setindex!(b1, b2, t1, 1:m2) BitMatrix
@check_bit_operation setindex!(b1, b2, t1, n2-m2+1:n2) BitMatrix
@check_bit_operation setindex!(b1, b2, t1, k2) BitMatrix
t2 = randbool(n2)
b2 = randbool(m1, countnz(t2))
k1 = randperm(m1)
@check_bit_operation setindex!(b1, b2, 1:m1, t2) BitMatrix
@check_bit_operation setindex!(b1, b2, n1-m1+1:n1, t2) BitMatrix
@check_bit_operation setindex!(b1, b2, k1, t2) BitMatrix
timesofar("indexing")
## Dequeue functionality ##
b1 = BitArray(0)
i1 = Bool[]
for m = 1 : v1
x = randbool()
push!(b1, x)
push!(i1, x)
@test isequal(bitunpack(b1), i1)
end
for m1 = 0 : v1
for m2 = [0, 1, 63, 64, 65, 127, 128, 129]
b1 = randbool(m1)
b2 = randbool(m2)
i1 = bitunpack(b1)
i2 = bitunpack(b2)
@test isequal(bitunpack(append!(b1, b2)), append!(i1, i2))
end
end
for m1 = 0 : v1
for m2 = [0, 1, 63, 64, 65, 127, 128, 129]
b1 = randbool(m1)
b2 = randbool(m2)
i1 = bitunpack(b1)
i2 = bitunpack(b2)
@test isequal(bitunpack(prepend!(b1, b2)), prepend!(i1, i2))
end
end
b1 = randbool(v1)
i1 = bitunpack(b1)
for m = 1 : v1
jb = pop!(b1)
ji = pop!(i1)
@test jb == ji
@test isequal(bitunpack(b1), i1)
end
@test length(b1) == 0
b1 = BitArray(0)
i1 = Bool[]
for m = 1 : v1
x = randbool()
unshift!(b1, x)
unshift!(i1, x)
@test isequal(bitunpack(b1), i1)
end
b1 = randbool(v1)
i1 = bitunpack(b1)
for m = 1 : v1
jb = shift!(b1)
ji = shift!(i1)
@test jb == ji
@test isequal(bitunpack(b1), i1)
end
@test length(b1) == 0
b1 = BitArray(0)
@test_throws BoundsError insert!(b1, 2, false)
@test_throws BoundsError insert!(b1, 0, false)
i1 = bitunpack(b1)
for m = 1 : v1
j = rand(1:m)
x = randbool()
@test insert!(b1, j, x) === b1
insert!(i1, j, x)
@test isequal(bitunpack(b1), i1)
end
b1 = randbool(v1)
i1 = bitunpack(b1)
for j in [63, 64, 65, 127, 128, 129, 191, 192, 193]
x = rand(0:1)
@test insert!(b1, j, x) === b1
insert!(i1, j, x)
@test isequal(bitunpack(b1), i1)
end
b1 = randbool(v1)
i1 = bitunpack(b1)
for m = v1 : -1 : 1
j = rand(1:m)
b = splice!(b1, j)
i = splice!(i1, j)
@test isequal(bitunpack(b1), i1)
@test b == i
end
@test length(b1) == 0
b1 = randbool(v1)
i1 = bitunpack(b1)
for m = v1 : -1 : 1
j = rand(1:m)
deleteat!(b1, j)
deleteat!(i1, j)
@test isequal(bitunpack(b1), i1)
end
@test length(b1) == 0
b1 = randbool(v1)
i1 = bitunpack(b1)
for j in [63, 64, 65, 127, 128, 129, 191, 192, 193]
b = splice!(b1, j)
i = splice!(i1, j)
@test isequal(bitunpack(b1), i1)
@test b == i
end
b1 = randbool(v1)
i1 = bitunpack(b1)
for j in [63, 64, 65, 127, 128, 129, 191, 192, 193]
deleteat!(b1, j)
deleteat!(i1, j)
@test isequal(bitunpack(b1), i1)
end
b1 = randbool(v1)
i1 = bitunpack(b1)
for m1 = 1 : v1
for m2 = m1 : v1
b2 = copy(b1)
i2 = copy(i1)
b = splice!(b2, m1:m2)
i = splice!(i2, m1:m2)
@test isequal(bitunpack(b2), i2)
@test b == i
end
end
b1 = randbool(v1)
i1 = bitunpack(b1)
for m1 = 1 : v1
for m2 = m1 : v1
b2 = copy(b1)
i2 = copy(i1)
deleteat!(b2, m1:m2)
deleteat!(i2, m1:m2)
@test isequal(bitunpack(b2), i2)
end
end
b1 = randbool(v1)
i1 = bitunpack(b1)
for m1 = 1 : v1 + 1
for m2 = m1 - 1 : v1
for v2 = [0, 1, 63, 64, 65, 127, 128, 129, 191, 192, 193, rand(1:v1)]
b2 = copy(b1)
i2 = copy(i1)
b3 = randbool(v2)
i3 = bitunpack(b3)
b = splice!(b2, m1:m2, b3)
i = splice!(i2, m1:m2, i3)
@test isequal(bitunpack(b2), i2)
@test b == i
end
end
end
b1 = randbool(v1)
i1 = bitunpack(b1)
for m1 = 1 : v1
for v2 = [0, 1, 63, 64, 65, 127, 128, 129, 191, 192, 193, rand(1:v1)]
b2 = copy(b1)
i2 = copy(i1)
b3 = randbool(v2)
i3 = bitunpack(b3)
b = splice!(b2, m1, b3)
i = splice!(i2, m1, i3)
@test isequal(bitunpack(b2), i2)
@test b == i
end
end
b1 = randbool(v1)
i1 = bitunpack(b1)
for m1 = 1 : v1 - 1
for m2 = m1 + 1 : v1
locs = randbool(m2-m1+1)
m = [m1:m2...][locs]
b2 = copy(b1)
i2 = copy(i1)
deleteat!(b2, m)
deleteat!(i2, m)
@test isequal(bitunpack(b2), i2)
end
end
b1 = randbool(v1)
i1 = bitunpack(b1)
empty!(b1)
empty!(i1)
@test isequal(bitunpack(b1), i1)
timesofar("dequeue")
## Unary operators ##
b1 = randbool(n1, n2)
@check_bit_operation (~)(b1) BitMatrix
@check_bit_operation (!)(b1) BitMatrix
@check_bit_operation (-)(b1) Matrix{Int}
@check_bit_operation sign(b1) BitMatrix
@check_bit_operation real(b1) BitMatrix
@check_bit_operation imag(b1) BitMatrix
@check_bit_operation conj(b1) BitMatrix
b0 = falses(0)
@check_bit_operation (~)(b0) BitVector
@check_bit_operation (!)(b0) BitVector
@check_bit_operation (-)(b0) Vector{Int}
@check_bit_operation sign(b0) BitVector
timesofar("unary arithmetic")
## Binary arithmetic operators ##
# Matrix{Bool}/Matrix{Bool}
b1 = randbool(n1, n2)
b2 = randbool(n1, n2)
@check_bit_operation (&)(b1, b2) BitMatrix
@check_bit_operation (|)(b1, b2) BitMatrix
@check_bit_operation ($)(b1, b2) BitMatrix
@check_bit_operation (+)(b1, b2) Matrix{Int}
@check_bit_operation (-)(b1, b2) Matrix{Int}
@check_bit_operation (.*)(b1, b2) BitMatrix
@check_bit_operation (./)(b1, b2) Matrix{Float64}
@check_bit_operation (.^)(b1, b2) BitMatrix
b2 = trues(n1, n2)
@check_bit_operation div(b1, b2) BitMatrix
@check_bit_operation mod(b1, b2) BitMatrix
while true
global b1
b1 = randbool(n1, n1)
if abs(det(float64(b1))) > 1e-6
break
end
end
b2 = randbool(n1, n1)
@check_bit_operation (*)(b1, b2) Matrix{Int}
@check_bit_operation (/)(b1, b1) Matrix{Float64}
@check_bit_operation (\)(b1, b1) Matrix{Float64}
b0 = falses(0)
@check_bit_operation (&)(b0, b0) BitVector
@check_bit_operation (|)(b0, b0) BitVector
@check_bit_operation ($)(b0, b0) BitVector
@check_bit_operation (.*)(b0, b0) BitVector
@check_bit_operation (*)(b0, b0') Matrix{Int}
# Matrix{Bool}/Matrix{Int}
b1 = randbool(n1, n2)
i2 = rand(1:10, n1, n2)
@check_bit_operation (&)(b1, i2) Matrix{Int}
@check_bit_operation (|)(b1, i2) Matrix{Int}
@check_bit_operation ($)(b1, i2) Matrix{Int}
@check_bit_operation (+)(b1, i2) Matrix{Int}
@check_bit_operation (-)(b1, i2) Matrix{Int}
@check_bit_operation (.*)(b1, i2) Matrix{Int}
@check_bit_operation (./)(b1, i2) Matrix{Float64}
@check_bit_operation (.^)(b1, i2) BitMatrix
@check_bit_operation div(b1, i2) Matrix{Int}
@check_bit_operation mod(b1, i2) Matrix{Int}
# Matrix{Bool}/Matrix{Float64}
b1 = randbool(n1, n2)
f2 = 1.0 .+ rand(n1, n2)
@check_bit_operation (.*)(b1, f2) Matrix{Float64}
@check_bit_operation (./)(b1, f2) Matrix{Float64}
@check_bit_operation (.^)(b1, f2) Matrix{Float64}
@check_bit_operation div(b1, f2) Matrix{Float64}
@check_bit_operation mod(b1, f2) Matrix{Float64}
# Number/Matrix
b2 = randbool(n1, n2)
i1 = rand(1:10)
u1 = uint8(i1)
f1 = float64(i1)
ci1 = complex(i1)
cu1 = complex(u1)
cf1 = complex(f1)
@check_bit_operation (&)(i1, b2) Matrix{Int}
@check_bit_operation (|)(i1, b2) Matrix{Int}
@check_bit_operation ($)(i1, b2) Matrix{Int}
@check_bit_operation (.+)(i1, b2) Matrix{Int}
@check_bit_operation (.-)(i1, b2) Matrix{Int}
@check_bit_operation (.*)(i1, b2) Matrix{Int}
@check_bit_operation (&)(u1, b2) Matrix{Uint8}
@check_bit_operation (|)(u1, b2) Matrix{Uint8}
@check_bit_operation ($)(u1, b2) Matrix{Uint8}
@check_bit_operation (.+)(u1, b2) Matrix{Uint8}
@check_bit_operation (.-)(u1, b2) Matrix{Uint8}
@check_bit_operation (.*)(u1, b2) Matrix{Uint8}
for (x1,t1) = {(f1, Float64),
(ci1, Complex{Int}),
(cu1, Complex{Uint8}),
(cf1, Complex128)}
@check_bit_operation (.+)(x1, b2) Matrix{t1}
@check_bit_operation (.-)(x1, b2) Matrix{t1}
@check_bit_operation (.*)(x1, b2) Matrix{t1}
end
b2 = trues(n1, n2)
@check_bit_operation (./)(true, b2) Matrix{Float64}
@check_bit_operation div(true, b2) BitMatrix
@check_bit_operation mod(true, b2) BitMatrix
@check_bit_operation (./)(false, b2) Matrix{Float64}
@check_bit_operation div(false, b2) BitMatrix
@check_bit_operation mod(false, b2) BitMatrix
@check_bit_operation (./)(i1, b2) Matrix{Float64}
@check_bit_operation div(i1, b2) Matrix{Int}
@check_bit_operation mod(i1, b2) Matrix{Int}
@check_bit_operation (./)(u1, b2) Matrix{Float64}
@check_bit_operation div(u1, b2) Matrix{Uint8}
@check_bit_operation mod(u1, b2) Matrix{Uint8}
@check_bit_operation (./)(f1, b2) Matrix{Float64}
@check_bit_operation div(f1, b2) Matrix{Float64}
@check_bit_operation mod(f1, b2) Matrix{Float64}
@check_bit_operation (./)(ci1, b2) Matrix{Complex128}
@check_bit_operation (./)(cu1, b2) Matrix{Complex128}
@check_bit_operation (./)(cf1, b2) Matrix{Complex128}
b2 = randbool(n1, n2)
@check_bit_operation (.^)(false, b2) BitMatrix
@check_bit_operation (.^)(true, b2) BitMatrix
@check_bit_operation (.^)(0x0, b2) Matrix{Uint8}
@check_bit_operation (.^)(0x1, b2) Matrix{Uint8}
@check_bit_operation (.^)(-1, b2) Matrix{Int}
@check_bit_operation (.^)(0, b2) Matrix{Int}
@check_bit_operation (.^)(1, b2) Matrix{Int}
@check_bit_operation (.^)(0.0, b2) Matrix{Float64}
@check_bit_operation (.^)(1.0, b2) Matrix{Float64}
@check_bit_operation (.^)(0.0im, b2) Matrix{Complex128}
@check_bit_operation (.^)(1.0im, b2) Matrix{Complex128}
@check_bit_operation (.^)(0im, b2) Matrix{Complex{Int}}
@check_bit_operation (.^)(1im, b2) Matrix{Complex{Int}}
@check_bit_operation (.^)(0x0im, b2) Matrix{Complex{Uint8}}
@check_bit_operation (.^)(0x1im, b2) Matrix{Complex{Uint8}}
# Matrix/Number
b1 = randbool(n1, n2)
i2 = rand(1:10)
u2 = uint8(i2)
f2 = float64(i2)
ci2 = complex(i2)
cu2 = complex(u2)
cf2 = complex(f2)
@check_bit_operation (&)(b1, true) BitMatrix
@check_bit_operation (&)(b1, false) BitMatrix
@check_bit_operation (|)(b1, true) BitMatrix
@check_bit_operation (|)(b1, false) BitMatrix
@check_bit_operation ($)(b1, true) BitMatrix
@check_bit_operation ($)(b1, false) BitMatrix
@check_bit_operation (.+)(b1, true) Matrix{Int}
@check_bit_operation (.+)(b1, false) Matrix{Int}
@check_bit_operation (.-)(b1, true) Matrix{Int}
@check_bit_operation (.-)(b1, false) Matrix{Int}
@check_bit_operation (.*)(b1, true) BitMatrix
@check_bit_operation (.*)(b1, false) BitMatrix
@check_bit_operation (./)(b1, true) Matrix{Float64}
@check_bit_operation (./)(b1, false) Matrix{Float64}
@check_bit_operation div(b1, true) BitMatrix
@check_bit_operation mod(b1, true) BitMatrix
@check_bit_operation (&)(b1, i2) Matrix{Int}
@check_bit_operation (|)(b1, i2) Matrix{Int}
@check_bit_operation ($)(b1, i2) Matrix{Int}
@check_bit_operation (.+)(b1, i2) Matrix{Int}
@check_bit_operation (.-)(b1, i2) Matrix{Int}
@check_bit_operation (.*)(b1, i2) Matrix{Int}
@check_bit_operation (./)(b1, i2) Matrix{Float64}
@check_bit_operation div(b1, i2) Matrix{Int}
@check_bit_operation mod(b1, i2) Matrix{Int}
@check_bit_operation (&)(b1, u2) Matrix{Uint8}
@check_bit_operation (|)(b1, u2) Matrix{Uint8}
@check_bit_operation ($)(b1, u2) Matrix{Uint8}
@check_bit_operation (.+)(b1, u2) Matrix{Uint8}
@check_bit_operation (.-)(b1, u2) Matrix{Uint8}
@check_bit_operation (.*)(b1, u2) Matrix{Uint8}
@check_bit_operation (./)(b1, u2) Matrix{Float64}
@check_bit_operation div(b1, u2) Matrix{Uint8}
@check_bit_operation mod(b1, u2) Matrix{Uint8}
@check_bit_operation (.+)(b1, f2) Matrix{Float64}
@check_bit_operation (.-)(b1, f2) Matrix{Float64}
@check_bit_operation (.*)(b1, f2) Matrix{Float64}
@check_bit_operation (./)(b1, f2) Matrix{Float64}
@check_bit_operation div(b1, f2) Matrix{Float64}
@check_bit_operation mod(b1, f2) Matrix{Float64}
@check_bit_operation (.+)(b1, ci2) Matrix{Complex{Int}}
@check_bit_operation (.-)(b1, ci2) Matrix{Complex{Int}}
@check_bit_operation (.*)(b1, ci2) Matrix{Complex{Int}}
@check_bit_operation (./)(b1, ci2) Matrix{Complex128}
@check_bit_operation (.+)(b1, cu2) Matrix{Complex{Uint8}}
@check_bit_operation (.-)(b1, cu2) Matrix{Complex{Uint8}}
@check_bit_operation (.*)(b1, cu2) Matrix{Complex{Uint8}}
@check_bit_operation (./)(b1, cu2) Matrix{Complex128}
@check_bit_operation (.+)(b1, cf2) Matrix{Complex128}
@check_bit_operation (.-)(b1, cf2) Matrix{Complex128}
@check_bit_operation (.*)(b1, cf2) Matrix{Complex128}
@check_bit_operation (./)(b1, cf2) Matrix{Complex128}
@check_bit_operation (.^)(b1, false) BitMatrix
@check_bit_operation (.^)(b1, true) BitMatrix
@check_bit_operation (.^)(b1, 0x0) BitMatrix
@check_bit_operation (.^)(b1, 0x1) BitMatrix
@check_bit_operation (.^)(b1, 0) BitMatrix
@check_bit_operation (.^)(b1, 1) BitMatrix
@check_bit_operation (.^)(b1, -1.0) Matrix{Float64}
@check_bit_operation (.^)(b1, 0.0) Matrix{Float64}
@check_bit_operation (.^)(b1, 1.0) Matrix{Float64}
@check_bit_operation (.^)(b1, 0.0im) Matrix{Complex128}
@check_bit_operation (.^)(b1, 0x0im) Matrix{Complex128}
@check_bit_operation (.^)(b1, 0im) Matrix{Complex128}
b1 = trues(n1, n2)
@check_bit_operation (.^)(b1, -1.0im) Matrix{Complex128}
@check_bit_operation (.^)(b1, 1.0im) Matrix{Complex128}
@check_bit_operation (.^)(b1, -1im) Matrix{Complex128}
@check_bit_operation (.^)(b1, 1im) Matrix{Complex128}
@check_bit_operation (.^)(b1, 0x1im) Matrix{Complex128}
timesofar("binary arithmetic")
## Binary comparison operators ##
b1 = randbool(n1, n2)
b2 = randbool(n1, n2)
@check_bit_operation (.==)(b1, b2) BitMatrix
@check_bit_operation (.!=)(b1, b2) BitMatrix
@check_bit_operation (.<)(b1, b2) BitMatrix
@check_bit_operation (.<=)(b1, b2) BitMatrix
timesofar("binary comparison")
## Data movement ##
b1 = randbool(s1, s2, s3, s4)
for d = 1 : 4
j = rand(1:size(b1, d))
#for j = 1 : size(b1, d)
@check_bit_operation slicedim(b1, d, j) BitArray{4}
#end
@check_bit_operation flipdim(b1, d) BitArray{4}
end
b1 = randbool(n1, n2)
for k = 1 : 4
@check_bit_operation rotl90(b1, k) BitMatrix
end
for m = 0 : v1
b1 = randbool(m)
@check_bit_operation reverse(b1) BitVector
end
b1 = randbool(v1)
for m = [rand(1:v1)-1 0 1 63 64 65 191 192 193 v1-1]
@test isequal(b1 << m, [ b1[m+1:end]; falses(m) ])
@test isequal(b1 >>> m, [ falses(m); b1[1:end-m] ])
@test isequal(rol(b1, m), [ b1[m+1:end]; b1[1:m] ])
@test isequal(ror(b1, m), [ b1[end-m+1:end]; b1[1:end-m] ])
@test isequal(ror(b1, m), rol(b1, -m))
@test isequal(rol(b1, m), ror(b1, -m))
end
timesofar("datamove")
## countnz & find ##
for m = 0:v1, b1 in {randbool(m), trues(m), falses(m)}
@check_bit_operation countnz(b1) Int
@check_bit_operation findfirst(b1) Int
@check_bit_operation findfirst(b1, true) Int
@check_bit_operation findfirst(b1, false) Int
@check_bit_operation findfirst(b1, 3) Int
@check_bit_operation findfirst(x->x, b1) Int
@check_bit_operation findfirst(x->!x, b1) Int
@check_bit_operation findfirst(x->true, b1) Int
@check_bit_operation findfirst(x->false, b1) Int
@check_bit_operation find(b1) Vector{Int}
end
b1 = trues(v1)
for i = 0:v1-1
@test findfirst(b1 >> i) == i+1
@test Base.findfirstnot(~(b1 >> i)) == i+1
end
for i = 3:v1-1
for j = 2:i
submask = b1 << (v1-j+1)
@test findnext((b1 >> i) | submask, j) == i+1
@test Base.findnextnot((~(b1 >> i)) $ submask, j) == i+1
end
end
b1 = randbool(n1, n2)
@check_bit_operation findnz(b1) (Vector{Int}, Vector{Int}, BitArray)
timesofar("nnz&find")
## Reductions ##
b1 = randbool(s1, s2, s3, s4)
m1 = 1
m2 = 3
@check_bit_operation maximum(b1, (m1, m2)) BitArray{4}
@check_bit_operation minimum(b1, (m1, m2)) BitArray{4}
@check_bit_operation sum(b1, (m1, m2)) Array{Int,4}
@check_bit_operation maximum(b1) Bool
@check_bit_operation minimum(b1) Bool
@check_bit_operation any(b1) Bool
@check_bit_operation all(b1) Bool
@check_bit_operation sum(b1) Int
b0 = falses(0)
@check_bit_operation any(b0) Bool
@check_bit_operation all(b0) Bool
@check_bit_operation sum(b0) Int
timesofar("reductions")
## map over bitarrays ##
# TODO (not implemented)
## Filter ##
# TODO
## Transpose ##
b1 = randbool(v1)
@check_bit_operation transpose(b1) BitMatrix
for m1 = 0 : n1
for m2 = 0 : n2
b1 = randbool(m1, m2)
@check_bit_operation transpose(b1) BitMatrix
end
end
timesofar("transpose")
## Permutedims ##
b1 = randbool(s1, s2, s3, s4)
p = randperm(4)
@check_bit_operation permutedims(b1, p) BitArray{4}
@check_bit_operation permutedims(b1, tuple(p...)) BitArray{4}
timesofar("permutedims")
## Concatenation ##
b1 = randbool(v1)
b2 = randbool(v1)
@check_bit_operation hcat(b1, b2) BitMatrix
for m = 1 : v1 - 1
@check_bit_operation vcat(b1[1:m], b1[m+1:end]) BitVector
end
b1 = randbool(n1, n2)
b2 = randbool(n1)
b3 = randbool(n1, n2)
b4 = randbool(1, n2)
@check_bit_operation hcat(b1, b2, b3) BitMatrix
@check_bit_operation vcat(b1, b4, b3) BitMatrix
b1 = randbool(s1, s2, s3, s4)
b2 = randbool(s1, s3, s3, s4)
b3 = randbool(s1, s2, s3, s1)
@check_bit_operation cat(2, b1, b2) BitArray{4}
@check_bit_operation cat(4, b1, b3) BitArray{4}
@check_bit_operation cat(6, b1, b1) BitArray{6}
b1 = randbool(1, v1, 1)
@check_bit_operation cat(2, 0, b1, 1, 1, b1) Array{Int,3}
@check_bit_operation cat(2, 3, b1, 4, 5, b1) Array{Int,3}
@check_bit_operation cat(2, false, b1, true, true, b1) BitArray{3}
b1 = randbool(n1, n2)
for m1 = 1 : n1 - 1
for m2 = 1 : n2 - 1
@test isequal([b1[1:m1,1:m2] b1[1:m1,m2+1:end]; b1[m1+1:end,1:m2] b1[m1+1:end,m2+1:end]], b1)
end
end
timesofar("cat")
# Linear algebra
b1 = randbool(v1)
b2 = randbool(v1)
@check_bit_operation dot(b1, b2) Int
b1 = randbool(n1, n2)
for k = -max(n1,n2) : max(n1,n2)
@check_bit_operation tril(b1, k) BitMatrix
@check_bit_operation triu(b1, k) BitMatrix
end
b1 = randbool(n1, n1)
@check_bit_operation istril(b1) Bool
b1 = randbool(n1, n2)
@check_bit_operation istril(b1) Bool
b1 = randbool(n2, n1)
@check_bit_operation istril(b1) Bool
b1 = tril(randbool(n1, n1))
@check_bit_operation istril(b1) Bool
b1 = tril(randbool(n1, n2))
@check_bit_operation istril(b1) Bool
b1 = tril(randbool(n2, n1))
@check_bit_operation istril(b1) Bool
b1 = randbool(n1, n1)
@check_bit_operation istriu(b1) Bool
b1 = randbool(n1, n2)
@check_bit_operation istriu(b1) Bool
b1 = randbool(n2, n1)
@check_bit_operation istriu(b1) Bool
b1 = triu(randbool(n1, n1))
@check_bit_operation istriu(b1) Bool
b1 = triu(randbool(n1, n2))
@check_bit_operation istriu(b1) Bool
b1 = triu(randbool(n2, n1))
@check_bit_operation istriu(b1) Bool
b1 = randbool(n1)
b2 = randbool(n2)
@check_bit_operation kron(b1, b2) BitVector
b1 = randbool(s1, s2)
b2 = randbool(s3, s4)
@check_bit_operation kron(b1, b2) BitMatrix
#b1 = randbool(v1)
#@check_bit_operation diff(b1) Vector{Int}
#b1 = randbool(n1, n2)
#@check_bit_operation diff(b1) Vector{Int}
timesofar("linalg")
# issue #7515
@test sizeof(BitArray(64)) == 8
@test sizeof(BitArray(65)) == 16
|