@@ -1047,12 +1047,11 @@ for f in (:+, :-)
1047
1047
return r
1048
1048
end
1049
1049
end
1050
- for (f,F) in ((:.+ , DotAddFun ()),
1051
- (:.- , DotSubFun ()))
1050
+ for (f) in (:.+ , :.- )
1052
1051
for (arg1, arg2, T, fargs) in ((:(B:: BitArray ), :(x:: Bool ) , Int , :(b, x)),
1053
- (:(B:: BitArray ), :(x:: Number ) , :(promote_array_type ($ F , typeof (x), Bool)), :(b, x)),
1052
+ (:(B:: BitArray ), :(x:: Number ) , :(promote_array_type ($ f , typeof (x), Bool)), :(b, x)),
1054
1053
(:(x:: Bool ) , :(B:: BitArray ), Int , :(x, b)),
1055
- (:(x:: Number ) , :(B:: BitArray ), :(promote_array_type ($ F , typeof (x), Bool)), :(x, b)))
1054
+ (:(x:: Number ) , :(B:: BitArray ), :(promote_array_type ($ f , typeof (x), Bool)), :(x, b)))
1056
1055
@eval function ($ f)($ arg1, $ arg2)
1057
1056
r = Array ($ T, size (B))
1058
1057
bi = start (B)
@@ -1091,7 +1090,7 @@ function div(x::Bool, B::BitArray)
1091
1090
end
1092
1091
function div (x:: Number , B:: BitArray )
1093
1092
all (B) || throw (DivideError ())
1094
- pt = promote_array_type (IDivFun () , typeof (x), Bool)
1093
+ pt = promote_array_type (div , typeof (x), Bool)
1095
1094
y = div (x, true )
1096
1095
reshape (pt[ y for i = 1 : length (B) ], size (B))
1097
1096
end
@@ -1112,16 +1111,15 @@ function mod(x::Bool, B::BitArray)
1112
1111
end
1113
1112
function mod (x:: Number , B:: BitArray )
1114
1113
all (B) || throw (DivideError ())
1115
- pt = promote_array_type (ModFun () , typeof (x), Bool)
1114
+ pt = promote_array_type (mod , typeof (x), Bool)
1116
1115
y = mod (x, true )
1117
1116
reshape (pt[ y for i = 1 : length (B) ], size (B))
1118
1117
end
1119
1118
1120
- for (f,F) in ((:div , IDivFun ()),
1121
- (:mod , ModFun ()))
1119
+ for f in (:div , :mod )
1122
1120
@eval begin
1123
1121
function ($ f)(B:: BitArray , x:: Number )
1124
- F = Array (promote_array_type ($ F , typeof (x), Bool), size (B))
1122
+ F = Array (promote_array_type ($ f , typeof (x), Bool), size (B))
1125
1123
for i = 1 : length (F)
1126
1124
F[i] = ($ f)(B[i], x)
1127
1125
end
@@ -1676,7 +1674,7 @@ end
1676
1674
1677
1675
# # Reductions ##
1678
1676
1679
- sum (A:: BitArray , region) = reducedim (AddFun () , A, region)
1677
+ sum (A:: BitArray , region) = reducedim (+ , A, region)
1680
1678
sum (B:: BitArray ) = countnz (B)
1681
1679
1682
1680
function all (B:: BitArray )
@@ -1711,19 +1709,32 @@ maximum(B::BitArray) = isempty(B) ? throw(ArgumentError("argument must be non-em
1711
1709
# arrays since there can be a 64x speedup by working at the level of Int64
1712
1710
# instead of looping bit-by-bit.
1713
1711
1714
- map (f:: Function , A:: BitArray ) = map (specialized_bitwise_unary (f), A)
1715
- map (f:: Function , A:: BitArray , B:: BitArray ) = map (specialized_bitwise_binary (f), A, B)
1716
- map (f:: BitFunctorUnary , A:: BitArray ) = map! (f, similar (A), A)
1717
- map (f:: BitFunctorBinary , A:: BitArray , B:: BitArray ) = map! (f, similar (A), A, B)
1712
+ map (f:: Function , A:: BitArray ) = map! (f, similar (A), A)
1713
+ map (f:: Function , A:: BitArray , B:: BitArray ) = map! (f, similar (A), A, B)
1718
1714
1719
1715
map! (f, A:: BitArray ) = map! (f, A, A)
1720
- map! (f:: Function , dest:: BitArray , A:: BitArray ) = map! (specialized_bitwise_unary (f), dest, A)
1721
- map! (f:: Function , dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (specialized_bitwise_binary (f), dest, A, B)
1716
+ map! (f:: typeof (! ), dest:: BitArray , A:: BitArray ) = map! (~ , dest, A)
1717
+ map! (f:: typeof (zero), dest:: BitArray , A:: BitArray ) = fill! (dest, false )
1718
+ map! (f:: typeof (one), dest:: BitArray , A:: BitArray ) = fill! (dest, true )
1719
+
1720
+ immutable BitChunkFunctor{F<: Function }
1721
+ f:: F
1722
+ end
1723
+ (f:: BitChunkFunctor )(x, y) = f. f (x,y)
1724
+
1725
+ map! (f:: Union{typeof(*), typeof(min)} , dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (& , dest, A, B)
1726
+ map! (f:: typeof (max), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (| , dest, A, B)
1727
+ map! (f:: typeof (!= ), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! ($ , dest, A, B)
1728
+ map! (f:: Union{typeof(>=), typeof(^)} , dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (BitChunkFunctor ((p, q) -> p | ~ q), dest, A, B)
1729
+ map! (f:: typeof (<= ), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (BitChunkFunctor ((p, q) -> ~ p | q), dest, A, B)
1730
+ map! (f:: typeof (== ), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (BitChunkFunctor ((p, q) -> ~ (p $ q)), dest, A, B)
1731
+ map! (f:: typeof (< ), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (BitChunkFunctor ((p, q) -> ~ p & q), dest, A, B)
1732
+ map! (f:: typeof (> ), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (BitChunkFunctor ((p, q) -> p & ~ q), dest, A, B)
1722
1733
1723
1734
# If we were able to specialize the function to a known bitwise operation,
1724
1735
# map across the chunks. Otherwise, fall-back to the AbstractArray method that
1725
1736
# iterates bit-by-bit.
1726
- function map! (f:: BitFunctorUnary , dest:: BitArray , A:: BitArray )
1737
+ function map! (f:: Union{typeof(identity), typeof(~)} , dest:: BitArray , A:: BitArray )
1727
1738
size (A) == size (dest) || throw (DimensionMismatch (" sizes of dest and A must match" ))
1728
1739
isempty (A) && return dest
1729
1740
for i= 1 : length (A. chunks)- 1
@@ -1732,7 +1743,7 @@ function map!(f::BitFunctorUnary, dest::BitArray, A::BitArray)
1732
1743
dest. chunks[end ] = f (A. chunks[end ]) & _msk_end (A)
1733
1744
dest
1734
1745
end
1735
- function map! (f:: BitFunctorBinary , dest:: BitArray , A:: BitArray , B:: BitArray )
1746
+ function map! (f:: Union{BitChunkFunctor, typeof(&), typeof(|), typeof($)} , dest:: BitArray , A:: BitArray , B:: BitArray )
1736
1747
size (A) == size (B) == size (dest) || throw (DimensionMismatch (" sizes of dest, A, and B must all match" ))
1737
1748
isempty (A) && return dest
1738
1749
for i= 1 : length (A. chunks)- 1
0 commit comments