Skip to content

Commit

Permalink
fix test seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 21, 2021
1 parent 5c5f40b commit 501493b
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 30 deletions.
10 changes: 5 additions & 5 deletions doc/src/devdocs/subarrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ julia> A = rand(2,3,4);
julia> S1 = view(A, :, 1, 2:3)
2×2 view(::Array{Float64, 3}, :, 1, 2:3) with eltype Float64:
0.762657 0.545403
0.66338 0.866199
0.98627 0.991588
0.523355 0.105192
julia> S2 = view(A, 1, :, 2:3)
3×2 view(::Array{Float64, 3}, 1, :, 2:3) with eltype Float64:
0.762657 0.545403
0.704125 0.0802701
0.886174 0.535537
0.98627 0.991588
0.0890391 0.904316
0.134982 0.299203
```
```@meta
DocTestSetup = nothing
Expand Down
16 changes: 8 additions & 8 deletions doc/src/manual/performance-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ julia> function sum_global()
end;
julia> @time sum_global()
0.011001 seconds (9.30 k allocations: 417.044 KiB, 98.77% compilation time)
503.4466694614652
0.026328 seconds (9.30 k allocations: 416.747 KiB, 36.50% gc time, 99.48% compilation time)
508.39048990953665
julia> @time sum_global()
0.000075 seconds (3.49 k allocations: 70.156 KiB)
503.4466694614652
508.39048990953665
```

On the first call (`@time sum_global()`) the function gets compiled. (If you've not yet used [`@time`](@ref)
Expand Down Expand Up @@ -113,12 +113,12 @@ julia> function sum_arg(x)
end;
julia> @time sum_arg(x)
0.007258 seconds (4.24 k allocations: 226.052 KiB, 99.74% compilation time)
503.4466694614652
0.010298 seconds (4.23 k allocations: 226.021 KiB, 99.81% compilation time)
508.39048990953665
julia> @time sum_arg(x)
0.000005 seconds (1 allocation: 16 bytes)
503.4466694614652
508.39048990953665
```

The 1 allocation seen is from running the `@time` macro itself in global scope. If we instead run
Expand All @@ -128,8 +128,8 @@ the timing in a function, we can see that indeed no allocations are performed:
julia> time_sum(x) = @time sum_arg(x);
julia> time_sum(x)
0.000002 seconds
503.4466694614652
0.000001 seconds
508.39048990953665
```

In some situations, your function may need to allocate memory as part of its operation, and this
Expand Down
10 changes: 5 additions & 5 deletions stdlib/LinearAlgebra/test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ n = 10
n1 = div(n, 2)
n2 = 2*n1

Random.seed!(1234321)
Random.seed!(1234323)

@testset "Matrix condition number" begin
ainit = rand(n,n)
@testset "for $elty" for elty in (Float32, Float64, ComplexF32, ComplexF64)
ainit = convert(Matrix{elty}, ainit)
for a in (copy(ainit), view(ainit, 1:n, 1:n))
@test cond(a,1) 11860.833898970453 atol=0.5
@test cond(a,2) 5578.947735096807 atol=0.5
@test cond(a,Inf) 9974.454657908922 atol=0.4
@test cond(a[:,1:5]) 5.956698046316083 atol=0.01
@test cond(a,1) 162.93076496229205 atol=0.5
@test cond(a,2) 97.7362909028399 atol=0.5
@test cond(a,Inf) 196.00888526411242 atol=0.4
@test cond(a[:,1:5]) 10.466183798451308 atol=0.01
@test_throws ArgumentError cond(a,3)
end
end
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/test/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ n = 10
n1 = div(n, 2)
n2 = 2*n1

Random.seed!(1234324)
Random.seed!(12343215)

areal = randn(n,n)/2
aimg = randn(n,n)/2
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/test/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ n = 10
n1 = div(n, 2)
n2 = 2*n1

Random.seed!(1234322)
Random.seed!(1234323)

areal = randn(n,n)/2
aimg = randn(n,n)/2
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/test/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ n = 10
n1 = div(n, 2)
n2 = 2*n1

Random.seed!(1234324)
Random.seed!(1234325)

areal = randn(n,n)/2
aimg = randn(n,n)/2
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/test/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using .Main.Quaternions
isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "OffsetArrays.jl"))
using .Main.OffsetArrays

Random.seed!(1234)
Random.seed!(1234543)

@testset "basic functions" begin
@test I === I' # transpose
Expand Down
15 changes: 8 additions & 7 deletions stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1598,13 +1598,14 @@ argument specifies a random number generator, see [Random Numbers](@ref).
# Examples
```jldoctest; setup = :(using Random; Random.seed!(1234))
julia> sprand(Bool, 2, 2, 0.5)
2×2 SparseMatrixCSC{Bool, Int64} with 4 stored entries:
1 1
2×2 SparseMatrixCSC{Bool, Int64} with 2 stored entries:
⋅ ⋅
1 1
julia> sprand(Float64, 3, 0.75)
3-element SparseVector{Float64, Int64} with 1 stored entry:
[1] = 0.66338
3-element SparseVector{Float64, Int64} with 2 stored entries:
[1] = 0.523355
[2] = 0.0890391
```
"""
function sprand(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloat, rfn::Function, ::Type{T}=eltype(rfn(r, 1))) where T
Expand Down Expand Up @@ -1645,9 +1646,9 @@ argument specifies a random number generator, see [Random Numbers](@ref).
# Examples
```jldoctest; setup = :(using Random; Random.seed!(0))
julia> sprandn(2, 2, 0.75)
2×2 SparseMatrixCSC{Float64, Int64} with 4 stored entries:
1.49137 1.09378
-1.56692 1.1035
2×2 SparseMatrixCSC{Float64, Int64} with 3 stored entries:
-1.92631 -0.858041
⋅ 0.0213808
```
"""
sprandn(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloat) =
Expand Down
2 changes: 1 addition & 1 deletion stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ end
local A = guardseed(1234321) do
triu(sprand(10, 10, 0.2))
end
@test getcolptr(SparseArrays.droptol!(A, 0.01)) == [1, 1, 1, 1, 4, 5, 6, 6, 9, 11, 14]
@test getcolptr(SparseArrays.droptol!(A, 0.01)) == [1, 1, 1, 1, 3, 3, 4, 5, 7, 10, 11]
@test isequal(SparseArrays.droptol!(sparse([1], [1], [1]), 1), SparseMatrixCSC(1, 1, Int[1, 1], Int[], Int[]))
end

Expand Down

0 comments on commit 501493b

Please sign in to comment.