Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate flipbits! in favor of dot-broadcasting #27067

Merged
merged 4 commits into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 0 additions & 30 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 (:+, :-)
Expand Down
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ export

# bitarrays
falses,
flipbits!,
trues,

# dequeues
Expand Down
10 changes: 0 additions & 10 deletions doc/src/base/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
```
4 changes: 4 additions & 0 deletions doc/src/manual/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,8 @@ timesofar("dequeue")
@testset "flipbits!" begin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"in-place .!"?

b1 = bitrand(n1, n2)
i1 = Array(b1)
@test flipbits!(b1) == .~i1
b1 .= .!b1
@test b1 == .~i1
@test bitcheck(b1)
end
end
Expand Down