@@ -1992,32 +1992,34 @@ maximum(B::BitArray) = isempty(B) ? throw(ArgumentError("argument must be non-em
1992
1992
# arrays since there can be a 64x speedup by working at the level of Int64
1993
1993
# instead of looping bit-by-bit.
1994
1994
1995
- map (f:: Function , A:: BitArray ) = map! (f, similar (A), A)
1996
- map (f:: Function , A:: BitArray , B:: BitArray ) = map! (f, similar (A), A, B)
1995
+ map (:: Union{typeof(~), typeof(!)} , A:: BitArray ) = bit_map! (~ , similar (A), A)
1996
+ map (:: typeof (zero), A:: BitArray ) = fill! (similar (A), false )
1997
+ map (:: typeof (one), A:: BitArray ) = fill! (similar (A), true )
1998
+ map (:: typeof (identity), A:: BitArray ) = copy (A)
1997
1999
1998
2000
map! (f, A:: BitArray ) = map! (f, A, A)
1999
- map! (f:: typeof (! ), dest:: BitArray , A:: BitArray ) = map! (~ , dest, A)
2000
- map! (f:: typeof (zero), dest:: BitArray , A:: BitArray ) = fill! (dest, false )
2001
- map! (f:: typeof (one), dest:: BitArray , A:: BitArray ) = fill! (dest, true )
2002
-
2003
- immutable BitChunkFunctor{F<: Function }
2004
- f:: F
2001
+ map! (:: typeof (identity), A:: BitArray ) = A
2002
+ map! (:: Union{typeof(~), typeof(!)} , dest:: BitArray , A:: BitArray ) = bit_map! (~ , dest, A)
2003
+ map! (:: typeof (zero), dest:: BitArray , A:: BitArray ) = fill! (dest, false )
2004
+ map! (:: typeof (one), dest:: BitArray , A:: BitArray ) = fill! (dest, true )
2005
+ map! (:: typeof (identity), dest:: BitArray , A:: BitArray ) = copy! (dest, A)
2006
+
2007
+ for (T, f) in ((:(Union{typeof (& ), typeof (* ), typeof (min)}), :(& )),
2008
+ (:(Union{typeof (| ), typeof (max)}), :(| )),
2009
+ (:(Union{typeof ($ ), typeof (!= )}), :($ )),
2010
+ (:(Union{typeof (>= ), typeof (^ )}), :((p, q) -> p | ~ q)),
2011
+ (:(typeof (<= )), :((p, q) -> ~ p | q)),
2012
+ (:(typeof (== )), :((p, q) -> ~ (p $ q))),
2013
+ (:(typeof (< )), :((p, q) -> ~ p & q)),
2014
+ (:(typeof (> )), :((p, q) -> p & ~ q)))
2015
+ @eval map (:: $T , A:: BitArray , B:: BitArray ) = bit_map! ($ f, similar (A), A, B)
2016
+ @eval map! (:: $T , dest:: BitArray , A:: BitArray , B:: BitArray ) = bit_map! ($ f, dest, A, B)
2005
2017
end
2006
- (f:: BitChunkFunctor )(x, y) = f. f (x,y)
2007
-
2008
- map! (f:: Union{typeof(*), typeof(min)} , dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (& , dest, A, B)
2009
- map! (f:: typeof (max), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (| , dest, A, B)
2010
- map! (f:: typeof (!= ), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! ($ , dest, A, B)
2011
- map! (f:: Union{typeof(>=), typeof(^)} , dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (BitChunkFunctor ((p, q) -> p | ~ q), dest, A, B)
2012
- map! (f:: typeof (<= ), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (BitChunkFunctor ((p, q) -> ~ p | q), dest, A, B)
2013
- map! (f:: typeof (== ), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (BitChunkFunctor ((p, q) -> ~ (p $ q)), dest, A, B)
2014
- map! (f:: typeof (< ), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (BitChunkFunctor ((p, q) -> ~ p & q), dest, A, B)
2015
- map! (f:: typeof (> ), dest:: BitArray , A:: BitArray , B:: BitArray ) = map! (BitChunkFunctor ((p, q) -> p & ~ q), dest, A, B)
2016
2018
2017
2019
# If we were able to specialize the function to a known bitwise operation,
2018
2020
# map across the chunks. Otherwise, fall-back to the AbstractArray method that
2019
2021
# iterates bit-by-bit.
2020
- function map! (f:: Union{typeof(identity), typeof(~)} , dest:: BitArray , A:: BitArray )
2022
+ function bit_map! {F} (f:: F , dest:: BitArray , A:: BitArray )
2021
2023
size (A) == size (dest) || throw (DimensionMismatch (" sizes of dest and A must match" ))
2022
2024
isempty (A) && return dest
2023
2025
destc = dest. chunks
@@ -2028,7 +2030,7 @@ function map!(f::Union{typeof(identity), typeof(~)}, dest::BitArray, A::BitArray
2028
2030
destc[end ] = f (Ac[end ]) & _msk_end (A)
2029
2031
dest
2030
2032
end
2031
- function map! (f:: Union{BitChunkFunctor, typeof(&), typeof(|), typeof($)} , dest:: BitArray , A:: BitArray , B:: BitArray )
2033
+ function bit_map! {F} (f:: F , dest:: BitArray , A:: BitArray , B:: BitArray )
2032
2034
size (A) == size (B) == size (dest) || throw (DimensionMismatch (" sizes of dest, A, and B must all match" ))
2033
2035
isempty (A) && return dest
2034
2036
destc = dest. chunks
0 commit comments