Skip to content

Commit

Permalink
update code and tests to limit false global sharing (JuliaLang#23631)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Sep 14, 2017
1 parent 1001320 commit a26b7d0
Show file tree
Hide file tree
Showing 59 changed files with 1,497 additions and 1,258 deletions.
2 changes: 1 addition & 1 deletion base/multimedia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ for mime in ["application/atom+xml", "application/ecmascript",
"application/x-latex", "application/xhtml+xml", "application/xml",
"application/xml-dtd", "image/svg+xml", "model/vrml",
"model/x3d+vrml", "model/x3d+xml"]
istextmime(::MIME{Symbol(mime)}) = true
global istextmime(::MIME{Symbol(mime)}) = true
end

###########################################################################
Expand Down
3 changes: 3 additions & 0 deletions base/nullable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ all(f::typeof(hasvalue), t::Tuple{}) = true

# Note this list does not include sqrt since it can raise a DomainError
for op in (+, -, abs, abs2)
global null_safe_op
null_safe_op(::typeof(op), ::NullSafeTypes) = true
null_safe_op(::typeof(op), ::Type{Complex{S}}) where {S} = null_safe_op(op, S)
null_safe_op(::typeof(op), ::Type{Rational{S}}) where {S} = null_safe_op(op, S)
Expand All @@ -404,11 +405,13 @@ null_safe_op(::typeof(!), ::Type{Bool}) = true
for op in (+, -, *, /, &, |, <<, >>, >>>,
scalarmin, scalarmax)
# to fix ambiguities
global null_safe_op
null_safe_op(::typeof(op), ::NullSafeFloats, ::NullSafeFloats) = true
null_safe_op(::typeof(op), ::NullSafeSignedInts, ::NullSafeSignedInts) = true
null_safe_op(::typeof(op), ::NullSafeUnsignedInts, ::NullSafeUnsignedInts) = true
end
for op in (+, -, *, /)
global null_safe_op
null_safe_op(::typeof(op), ::Type{Complex{S}}, ::Type{T}) where {S,T} =
null_safe_op(op, T, S)
null_safe_op(::typeof(op), ::Type{Rational{S}}, ::Type{T}) where {S,T} =
Expand Down
2 changes: 1 addition & 1 deletion base/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ function testset_forloop(args, testloop)
end
quote
arr = Array{Any,1}(0)
first_iteration = true
local first_iteration = true
local ts
try
$(Expr(:for, Expr(:block, [esc(v) for v in loopvars]...), blk))
Expand Down
2 changes: 1 addition & 1 deletion test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ end
@test ind2sub((0:3,3:5,-101:-100), l) == (i-1, j+2, k-102)
end

A = reshape(collect(1:9), (3,3))
local A = reshape(collect(1:9), (3,3))
@test ind2sub(size(A), 6) == (3,2)
@test sub2ind(size(A), 3, 2) == 6
@test ind2sub(A, 6) == (3,2)
Expand Down
123 changes: 71 additions & 52 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -585,30 +585,34 @@ end

# unique across dim

# All rows and columns unique
A = ones(10, 10)
A[diagind(A)] = shuffle!([1:10;])
@test unique(A, 1) == A
@test unique(A, 2) == A

# 10 repeats of each row
B = A[shuffle!(repmat(1:10, 10)), :]
C = unique(B, 1)
@test sortrows(C) == sortrows(A)
@test unique(B, 2) == B
@test unique(B.', 2).' == C

# Along third dimension
D = cat(3, B, B)
@test unique(D, 1) == cat(3, C, C)
@test unique(D, 3) == cat(3, B)

# With hash collisions
struct HashCollision
x::Float64
end
Base.hash(::HashCollision, h::UInt) = h
@test map(x->x.x, unique(map(HashCollision, B), 1)) == C

# All rows and columns unique
let A, B, C, D
A = ones(10, 10)
A[diagind(A)] = shuffle!([1:10;])
@test unique(A, 1) == A
@test unique(A, 2) == A

# 10 repeats of each row
B = A[shuffle!(repmat(1:10, 10)), :]
C = unique(B, 1)
@test sortrows(C) == sortrows(A)
@test unique(B, 2) == B
@test unique(B.', 2).' == C

# Along third dimension
D = cat(3, B, B)
@test unique(D, 1) == cat(3, C, C)
@test unique(D, 3) == cat(3, B)

# With hash collisions
@test map(x -> x.x, unique(map(HashCollision, B), 1)) == C
end

@testset "large matrices transpose" begin
for i = 1 : 3
Expand Down Expand Up @@ -956,7 +960,7 @@ end
end

@testset "mapslices" begin
local a,h,i
local a, b, c, m, h, s
a = rand(5,5)
s = mapslices(sort, a, [1])
S = mapslices(sort, a, [2])
Expand Down Expand Up @@ -1124,7 +1128,9 @@ end
for idx in Any[1, 2, 5, 9, 10, 1:0, 2:1, 1:1, 2:2, 1:2, 2:4, 9:8, 10:9, 9:9, 10:10,
8:9, 9:10, 6:9, 7:10]
for repl in Any[[], [11], [11,22], [11,22,33,44,55]]
a = [1:10;]; acopy = copy(a)
local a
a = [1:10;]
acopy = copy(a)
@test splice!(a, idx, repl) == acopy[idx]
@test a == [acopy[1:(first(idx)-1)]; repl; acopy[(last(idx)+1):end]]
end
Expand Down Expand Up @@ -1266,9 +1272,10 @@ end
end

# issue 4228
A = [[i i; i i] for i=1:2]
@test cumsum(A) == Any[[1 1; 1 1], [3 3; 3 3]]
@test cumprod(A) == Any[[1 1; 1 1], [4 4; 4 4]]
let A = [[i i; i i] for i=1:2]
@test cumsum(A) == Any[[1 1; 1 1], [3 3; 3 3]]
@test cumprod(A) == Any[[1 1; 1 1], [4 4; 4 4]]
end

@testset "prepend/append" begin
# PR #4627
Expand All @@ -1293,9 +1300,10 @@ A = [[i i; i i] for i=1:2]
@test prepend!([1,2], OffsetArray([9,8], (-3,))) == [9,8,1,2]
end

A = [1,2]
s = Set([1,2,3])
@test sort(append!(A, s)) == [1,1,2,2,3]
let A = [1,2]
s = Set([1,2,3])
@test sort(append!(A, s)) == [1,1,2,2,3]
end

@testset "cases where shared arrays can/can't be grown" begin
A = [1 3;2 4]
Expand Down Expand Up @@ -1332,8 +1340,10 @@ end

# issue #6645 (32-bit)
let x = Float64[]
for i=1:5; push!(x, 1.0); end
@test dot(zeros(5),x) == 0.0
for i = 1:5
push!(x, 1.0)
end
@test dot(zeros(5), x) == 0.0
end

# issue #6977
Expand All @@ -1346,10 +1356,12 @@ end
@test map(join, ["z", "я"]) == ["z", "я"]

# Handle block matrices
A = [randn(2,2) for i = 1:2, j = 1:2]
@test issymmetric(A.'A)
A = [complex.(randn(2,2), randn(2,2)) for i = 1:2, j = 1:2]
@test ishermitian(A'A)
let A = [randn(2, 2) for i = 1:2, j = 1:2]
@test issymmetric(A.'A)
end
let A = [complex.(randn(2, 2), randn(2, 2)) for i = 1:2, j = 1:2]
@test ishermitian(A'A)
end

# issue #7197
function i7197()
Expand Down Expand Up @@ -1794,25 +1806,30 @@ for (a,s) in zip(A, S)
@test a == s
end

C = copy(B)
@test A == C
@test B == C
let C = copy(B)
@test A == C
@test B == C
end

@test vec(A) == vec(B) == vec(S)
@test minimum(A) == minimum(B) == minimum(S)
@test maximum(A) == maximum(B) == maximum(S)

a, ai = findmin(A)
b, bi = findmin(B)
s, si = findmin(S)
@test a == b == s
@test ai == bi == si
let
a, ai = findmin(A)
b, bi = findmin(B)
s, si = findmin(S)
@test a == b == s
@test ai == bi == si
end

a, ai = findmax(A)
b, bi = findmax(B)
s, si = findmax(S)
@test a == b == s
@test ai == bi == si
let
a, ai = findmax(A)
b, bi = findmax(B)
s, si = findmax(S)
@test a == b == s
@test ai == bi == si
end

for X in (A, B, S)
@test findmin(X) == findmin(Dict(pairs(X)))
Expand Down Expand Up @@ -1970,6 +1987,7 @@ end
end

@testset "sign, conj, ~" begin
local A, B, C
A = [-10,0,3]
B = [-10.0,0.0,3.0]
C = [1,im,0]
Expand All @@ -1991,7 +2009,7 @@ end
end

@testset "issue #16247" begin
A = zeros(3,3)
local A = zeros(3,3)
@test size(A[:,0x1:0x2]) == (3, 2)
@test size(A[:,UInt(1):UInt(2)]) == (3,2)
@test size(similar(A, UInt(3), 0x3)) == size(similar(A, (UInt(3), 0x3))) == (3,3)
Expand All @@ -2007,11 +2025,12 @@ for op in (:+, :*, :÷, :%, :<<, :>>, :-, :/, :\, :https://, :^)
@eval import Base.$(op)
@eval $(op)(::Foo, ::Foo) = Foo()
end
A = fill(Foo(), 10, 10)
@test typeof(A+A) == Matrix{Foo}
@test typeof(A-A) == Matrix{Foo}
for op in (:.+, :.*, :, :.%, :.<<, :.>>, :.-, :./, :.\, :.//, :.^)
@eval @test typeof($(op)(A,A)) == Matrix{Foo}
let A = fill(Foo(), 10, 10)
@test isa(A + A, Matrix{Foo})
@test isa(A - A, Matrix{Foo})
for op in (:+, :*, :÷, :%, :<<, :>>, :-, :/, :\, ://, :^)
@test isa(broadcast(eval(op), A, A), Matrix{Foo})
end
end

end # module AutoRetType
Expand Down
10 changes: 5 additions & 5 deletions test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ for l in bt
lkup = ccall(:jl_lookup_code_address, Any, (Ptr{Void}, Cint), l, true)
if lkup[1][1] == :backtrace
@test lkup[1][5] == false # fromC
have_backtrace = true
global have_backtrace = true
break
end
end
Expand Down Expand Up @@ -115,10 +115,10 @@ hasbt = hasbt2 = false
for sfs in lkup
for sf in sfs
if sf.func == :bt
hasbt = true
global hasbt = true
end
if sf.func == :bt2
hasbt2 = true
global hasbt2 = true
end
end
end
Expand All @@ -138,10 +138,10 @@ hasme = hasbtmacro = false
for sfs in lkup
for sf in sfs
if sf.func == Symbol("macro expansion")
hasme = true
global hasme = true
end
if sf.func == :btmacro
hasbtmacro = true
global hasbtmacro = true
end
end
end
Expand Down
25 changes: 13 additions & 12 deletions test/bigint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,22 @@ function bigfib(n)
end
@test [bigfib(n) for n=0:10] == [0,1,1,2,3,5,8,13,21,34,55]

n = bigfib(1000001)
@test ndigits(n) == 208988
@test mod(n,big(10)^15) == 359244926937501
@test div(n,big(10)^208973) == 316047687386689

s = string(n)
@test length(s) == 208988
@test endswith(s, "359244926937501")
@test startswith(s, "316047687386689")
let s, n = bigfib(1000001)
@test ndigits(n) == 208988
@test mod(n,big(10)^15) == 359244926937501
@test div(n,big(10)^208973) == 316047687386689

s = string(n)
@test length(s) == 208988
@test endswith(s, "359244926937501")
@test startswith(s, "316047687386689")
end

# serialization (#5133)
let n = parse(BigInt,"359334085968622831041960188598043661065388726959079837")
let n = parse(BigInt, "359334085968622831041960188598043661065388726959079837"),
b = IOBuffer()
serialize(b,n)
seek(b,0)
serialize(b, n)
seek(b, 0)
@test deserialize(b) == n
end

Expand Down
Loading

0 comments on commit a26b7d0

Please sign in to comment.