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 vectorized ! and ~ in favor of dot syntax #20543

Merged
merged 3 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 2 deletions base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ julia> A
"""
conj!(A::AbstractArray{<:Number}) = (@inbounds broadcast!(conj, A, A); A)

for f in (:-, :~, :conj, :real, :imag)
for f in (:-, :conj, :real, :imag)
@eval ($f)(A::AbstractArray) = broadcast($f, A)
end

!(A::AbstractArray{Bool}) = broadcast(!, A)

## Binary arithmetic operators ##

Expand Down
5 changes: 2 additions & 3 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ function (-)(B::BitArray)
end
broadcast(::typeof(sign), B::BitArray) = copy(B)

function (~)(B::BitArray)
function broadcast(::typeof(~), B::BitArray)
C = similar(B)
Bc = B.chunks
if !isempty(Bc)
Expand Down Expand Up @@ -1236,7 +1236,6 @@ function flipbits!(B::BitArray)
return B
end

!(B::BitArray) = ~B

## Binary arithmetic operators ##

Expand Down Expand Up @@ -1269,7 +1268,7 @@ broadcast(::typeof(&), B::BitArray, x::Bool) = x ? copy(B) : falses(size(B))
broadcast(::typeof(&), x::Bool, B::BitArray) = broadcast(&, B, x)
broadcast(::typeof(|), B::BitArray, x::Bool) = x ? trues(size(B)) : copy(B)
broadcast(::typeof(|), x::Bool, B::BitArray) = broadcast(|, B, x)
broadcast(::typeof(xor), B::BitArray, x::Bool) = x ? ~B : copy(B)
broadcast(::typeof(xor), B::BitArray, x::Bool) = x ? .~B : copy(B)
broadcast(::typeof(xor), x::Bool, B::BitArray) = broadcast(xor, B, x)
for f in (:&, :|, :xor)
@eval begin
Expand Down
8 changes: 8 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,14 @@ end
@deprecate ifelse(c::AbstractArray{Bool}, x::AbstractArray, y) ifelse.(c, x, y)
@deprecate ifelse(c::AbstractArray{Bool}, x::AbstractArray, y::AbstractArray) ifelse.(c, x, y)

# Deprecate vectorized !
@deprecate(!(A::AbstractArray{Bool}), .!A) # parens for #20541
@deprecate(!(B::BitArray), .!B) # parens for #20541

# Deprecate vectorized ~
@deprecate ~(A::AbstractArray) .~A
@deprecate ~(B::BitArray) .~B

function frexp(A::Array{<:AbstractFloat})
depwarn("`frexp(x::Array)` is discontinued.", :frexp)
F = similar(A)
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ function pinv{T}(A::StridedMatrix{T}, tol::Real)
Sinv = zeros(Stype, length(SVD.S))
index = SVD.S .> tol*maximum(SVD.S)
Sinv[index] = one(Stype) ./ SVD.S[index]
Sinv[find(!isfinite.(Sinv))] = zero(Stype)
Sinv[find(.!isfinite.(Sinv))] = zero(Stype)
return SVD.Vt' * (Diagonal(Sinv) * SVD.U')
end
function pinv{T}(A::StridedMatrix{T})
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function prefetch(pkg::AbstractString, url::AbstractString, sha1s::Vector)
LibGit2.fetch(repo)
in_cache = BitArray(map(sha1->LibGit2.iscommit(sha1, repo), sha1s))
end
sha1s[!in_cache]
sha1s[.!in_cache]
finally
close(repo) # closing repo opened/created above
end
Expand Down
2 changes: 1 addition & 1 deletion base/profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function parse_flat(iplist, n, lidict::LineInfoFlatDict, C::Bool)
# The ones with no line number might appear multiple times in a single
# backtrace, giving the wrong impression about the total number of backtraces.
# Delete them too.
keep = !Bool[x == UNKNOWN || x.line == 0 || (x.from_c && !C) for x in lilist]
keep = .!Bool[x == UNKNOWN || x.line == 0 || (x.from_c && !C) for x in lilist]
n = n[keep]
lilist = lilist[keep]
return (lilist, n)
Expand Down
4 changes: 2 additions & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
t))
(define (operator-precedence op) (get prec-table op 0))

(define unary-ops (append! '(|<:| |>:| ~)
(add-dots '(+ - ! ¬ √ ∛ ∜))))
(define unary-ops (append! '(|<:| |>:|)
(add-dots '(+ - ! ~ ¬ √ ∛ ∜))))

; operators that are both unary and binary
(define unary-and-binary-ops '(+ - $ & ~ |.+| |.-|))
Expand Down
4 changes: 2 additions & 2 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1863,8 +1863,8 @@ end
@test typeof(conj(B)) == Vector{Float64}
@test typeof(conj(C)) == Vector{Complex{Int}}

@test ~A == [9,-1,-4]
@test typeof(~A) == Vector{Int}
@test .~A == [9,-1,-4]
@test typeof(.~A) == Vector{Int}
end

@testset "issue #16247" begin
Expand Down
30 changes: 15 additions & 15 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -721,24 +721,24 @@ timesofar("dequeue")

@testset "Unary operators" begin
b1 = bitrand(n1, n2)
@check_bit_operation (~)(b1) BitMatrix
@check_bit_operation (!)(b1) BitMatrix
@check_bit_operation broadcast(~, b1) BitMatrix
@check_bit_operation broadcast(!, b1) BitMatrix
@check_bit_operation (-)(b1) Matrix{Int}
@check_bit_operation broadcast(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 broadcast(~, b0) BitVector
@check_bit_operation broadcast(!, b0) BitVector
@check_bit_operation (-)(b0) Vector{Int}
@check_bit_operation broadcast(sign, b0) BitVector

@testset "flipbits!" begin
b1 = bitrand(n1, n2)
i1 = Array(b1)
@test flipbits!(b1) == ~i1
@test flipbits!(b1) == .~i1
@test bitcheck(b1)
end
end
Expand Down Expand Up @@ -1072,13 +1072,13 @@ timesofar("datamove")
b1 = trues(v1)
for i = 0:(v1-1)
@test findfirst(b1 >> i) == i+1
@test Base.findfirstnot(~(b1 >> i)) == i+1
@test Base.findfirstnot(.~(b1 >> i)) == i+1
end

for i = 3:(v1-1), j = 2:i
submask = b1 << (v1-j+1)
@test findnext((b1 >> i) .| submask, j) == i+1
@test findnextnot((~(b1 >> i)) .⊻ submask, j) == i+1
@test findnextnot((.~(b1 >> i)) .⊻ submask, j) == i+1
end

b1 = bitrand(n1, n2)
Expand Down Expand Up @@ -1116,8 +1116,8 @@ timesofar("nnz&find")
n = maximum(elts)
for c = [falses, trues]
b1 = c(n)
b1[elts] = !b1[elts]
b2 = ~b1
b1[elts] = .!b1[elts]
b2 = .~b1
i1 = Array(b1)
for i = 1:n
@test findprev(b1, i) == findprev(i1, i) == findprevnot(b2, i) == findprev(!, b2, i)
Expand All @@ -1128,7 +1128,7 @@ timesofar("nnz&find")
b1 = falses(1000)
b1[77] = true
b1[777] = true
b2 = ~b1
b2 = .~b1
@test_throws BoundsError findprev(b1, 1001)
@test_throws BoundsError findprevnot(b2, 1001)
@test_throws BoundsError findprev(!, b2, 1001)
Expand Down Expand Up @@ -1184,13 +1184,13 @@ timesofar("nnz&find")
@test findprev(t, l) == findprevnot(f, l) == l
b1 = falses(l)
b1[end] = true
b2 = ~b1
b2 = .~b1
@test findprev(b1, l) == findprevnot(b2, l) == l
@test findprevnot(b1, l) == findprev(b2, l) == l-1
if l > 1
b1 = falses(l)
b1[end-1] = true
b2 = ~b1
b2 = .~b1
@test findprev(b1, l) == findprevnot(b2, l) == l-1
@test findprevnot(b1, l) == findprev(b2, l) == l
end
Expand Down Expand Up @@ -1223,7 +1223,7 @@ timesofar("reductions")
for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401]
b1 = bitrand(l)
b2 = bitrand(l)
@test map(~, b1) == map(x->~x, b1) == ~b1
@test map(~, b1) == map(x->~x, b1) == broadcast(~, b1)
@test map(identity, b1) == map(x->x, b1) == b1

@test map(&, b1, b2) == map((x,y)->x&y, b1, b2) == broadcast(&, b1, b2)
Expand All @@ -1245,8 +1245,8 @@ timesofar("reductions")

@testset "map! for length $l" begin
b = BitArray(l)
@test map!(~, b, b1) == map!(x->~x, b, b1) == ~b1 == b
@test map!(!, b, b1) == map!(x->!x, b, b1) == ~b1 == b
@test map!(~, b, b1) == map!(x->~x, b, b1) == broadcast(~, b1) == b
@test map!(!, b, b1) == map!(x->!x, b, b1) == broadcast(~, b1) == b
@test map!(identity, b, b1) == map!(x->x, b, b1) == b1 == b
@test map!(zero, b, b1) == map!(x->false, b, b1) == falses(l) == b
@test map!(one, b, b1) == map!(x->true, b, b1) == trues(l) == b
Expand Down
4 changes: 2 additions & 2 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,8 @@ let A = -1:1, B = -1.0:1.0
@test conj(A) === A
@test conj(B) === B

@test ~A == [0,-1,-2]
@test typeof(~A) == Vector{Int}
@test .~A == [0,-1,-2]
@test typeof(.~A) == Vector{Int}
end

# conversion to Array
Expand Down
2 changes: 1 addition & 1 deletion test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ end
FS = Array(S)
FI = Array(I)
@test sparse(FS[FI]) == S[I] == S[FI]
@test sum(S[FI]) + sum(S[!FI]) == sum(S)
@test sum(S[FI]) + sum(S[.!FI]) == sum(S)
@test countnz(I) == count(I)

sumS1 = sum(S)
Expand Down