From 97df0c3f57adc04fde7fae36aab662a9315bf22c Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Thu, 10 May 2018 19:12:27 -0400 Subject: [PATCH 1/4] Deprecate flipbits! in favor of dot-broadcasting Seems like we no longer need this function: ```julia julia> B = bitrand(100,1000); julia> @benchmark flipbits!($B) BenchmarkTools.Trial: memory estimate: 0 bytes allocs estimate: 0 -------------- minimum time: 87.996 ns (0.00% GC) median time: 88.474 ns (0.00% GC) mean time: 88.596 ns (0.00% GC) maximum time: 118.378 ns (0.00% GC) -------------- samples: 10000 evals/sample: 960 julia> @benchmark $B .= .!$B BenchmarkTools.Trial: memory estimate: 0 bytes allocs estimate: 0 -------------- minimum time: 88.060 ns (0.00% GC) median time: 88.202 ns (0.00% GC) mean time: 88.314 ns (0.00% GC) maximum time: 137.057 ns (0.00% GC) -------------- samples: 10000 evals/sample: 960 ``` --- base/bitarray.jl | 30 ------------------------------ base/deprecated.jl | 3 +++ base/exports.jl | 1 - doc/src/base/arrays.md | 10 ---------- doc/src/manual/arrays.md | 4 ++++ 5 files changed, 7 insertions(+), 41 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index fd826ef13cd1d..d37ce044bdda5 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1062,36 +1062,6 @@ function (-)(B::BitArray) return A end -""" - flipbits!(B::BitArray{N}) -> BitArray{N} - -Performs a bitwise not operation on `B`. See [`~`](@ref). - -# Examples -```jldoctest -julia> A = trues(2,2) -2×2 BitArray{2}: - true true - true true - -julia> flipbits!(A) -2×2 BitArray{2}: - false false - false false -``` -""" -function flipbits!(B::BitArray) - Bc = B.chunks - @inbounds if !isempty(Bc) - for i = 1:length(Bc) - Bc[i] = ~Bc[i] - end - Bc[end] &= _msk_end(B) - end - return B -end - - ## Binary arithmetic operators ## for f in (:+, :-) diff --git a/base/deprecated.jl b/base/deprecated.jl index 7e94eefa03047..a597df5bca7c1 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1644,6 +1644,9 @@ function search(buf::IOBuffer, delim::UInt8) return Int(q-p+1) end +# Issue #27067 +@deprecate flipbits!(B::BitArray) B .= .!B + @deprecate linearindices(x::AbstractArray) LinearIndices(x) # PR #26647 diff --git a/base/exports.jl b/base/exports.jl index 41f6961957d71..681cfe3eb87af 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -469,7 +469,6 @@ export # bitarrays falses, - flipbits!, trues, # dequeues diff --git a/doc/src/base/arrays.md b/doc/src/base/arrays.md index 83ca58cdf90df..70bed76836a3a 100644 --- a/doc/src/base/arrays.md +++ b/doc/src/base/arrays.md @@ -160,13 +160,3 @@ Base.reverse(::AbstractVector; kwargs...) Base.reverseind Base.reverse! ``` - -## BitArrays - -[`BitArray`](@ref)s are space-efficient "packed" boolean arrays, which store one bit per boolean value. -They can be used similarly to `Array{Bool}` arrays (which store one byte per boolean value), -and can be converted to/from the latter via `Array(bitarray)` and `BitArray(array)`, respectively. - -```@docs -Base.flipbits! -``` diff --git a/doc/src/manual/arrays.md b/doc/src/manual/arrays.md index 2492125e9c1ff..d969fc1eeb93a 100644 --- a/doc/src/manual/arrays.md +++ b/doc/src/manual/arrays.md @@ -722,6 +722,10 @@ indirectly. By putting the [`@views`](@ref) macro in front of an expression or block of code, any `array[...]` slice in that expression will be converted to create a `SubArray` view instead. +[`BitArray`](@ref)s are space-efficient "packed" boolean arrays, which store one bit per boolean value. +They can be used similarly to `Array{Bool}` arrays (which store one byte per boolean value), +and can be converted to/from the latter via `Array(bitarray)` and `BitArray(array)`, respectively. + A "strided" array is stored in memory with elements laid out in regular offsets such that an instance with a supported `isbits` element type can be passed to external C and Fortran functions that expect this memory layout. Strided arrays From ca94b704b8d18c4d540bdb7c7fc728d0b29779f1 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Fri, 11 May 2018 11:16:22 -0400 Subject: [PATCH 2/4] Remove straggling flipbits! from test --- test/bitarray.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/bitarray.jl b/test/bitarray.jl index 6c3ee50c7561b..326fee929e8e6 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -779,7 +779,8 @@ timesofar("dequeue") @testset "flipbits!" begin b1 = bitrand(n1, n2) i1 = Array(b1) - @test flipbits!(b1) == .~i1 + b1 .= .!b1 + @test b1 == .~i1 @test bitcheck(b1) end end From a37e7921b0e6292fd5cee2b60d828d5e064129d8 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Fri, 11 May 2018 14:44:09 -0400 Subject: [PATCH 3/4] Add NEWS.md [ci skip] --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index d5e9da05761a8..e999e16dc5860 100644 --- a/NEWS.md +++ b/NEWS.md @@ -977,6 +977,9 @@ Deprecated or removed been deprecated due to inconsistency with linear algebra. Use `.+` and `.-` for these operations instead ([#22880], [#22932]). + * `flipbits!(B)` is deprecated in favor of using in-place broadcast to negate each element: + `B .= .!B` ([#27067]). + * `isleaftype` is deprecated in favor of the simpler predicates `isconcretetype` and `isdispatchtuple`. Concrete types are those that might equal `typeof(x)` for some `x`; `isleaftype` included some types for which this is not true. Those are now categorized more precisely From eff3e3e4cb91f86e4edbf4008474a105a20e31d9 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Mon, 14 May 2018 10:29:51 -0400 Subject: [PATCH 4/4] rename testset --- test/bitarray.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bitarray.jl b/test/bitarray.jl index 326fee929e8e6..77e856b35f7cc 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -776,7 +776,7 @@ timesofar("dequeue") @check_bit_operation (-)(b0) Vector{Int} @check_bit_operation broadcast(sign, b0) BitVector - @testset "flipbits!" begin + @testset "in-place .!" begin b1 = bitrand(n1, n2) i1 = Array(b1) b1 .= .!b1