Skip to content

Commit

Permalink
fix typos in Xoshiro RNG implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Sep 10, 2021
1 parent 3a775cf commit f28ecd5
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 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.166507 0.97397
0.754392 0.831383
0.442623 0.0530526
0.201893 0.504489
julia> S2 = view(A, 1, :, 2:3)
3×2 view(::Array{Float64, 3}, 1, :, 2:3) with eltype Float64:
0.166507 0.97397
0.518957 0.0705793
0.503714 0.825124
0.442623 0.0530526
0.720089 0.661983
0.0939203 0.457032
```
```@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.026328 seconds (9.30 k allocations: 416.747 KiB, 36.50% gc time, 99.48% compilation time)
508.39048990953665
0.026174 seconds (9.07 k allocations: 373.448 KiB, 98.80% compilation time)
496.44917496523266
julia> @time sum_global()
0.000075 seconds (3.49 k allocations: 70.156 KiB)
508.39048990953665
0.000116 seconds (3.49 k allocations: 70.156 KiB)
496.44917496523266
```

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.010298 seconds (4.23 k allocations: 226.021 KiB, 99.81% compilation time)
508.39048990953665
0.009579 seconds (3.96 k allocations: 200.171 KiB, 99.77% compilation time)
496.44917496523266
julia> @time sum_arg(x)
0.000005 seconds (1 allocation: 16 bytes)
508.39048990953665
496.44917496523266
```

The 1 allocation seen is from running the `@time` macro itself in global scope. If we instead run
Expand All @@ -129,7 +129,7 @@ julia> time_sum(x) = @time sum_arg(x);
julia> time_sum(x)
0.000001 seconds
508.39048990953665
496.44917496523266
```

In some situations, your function may need to allocate memory as part of its operation, and this
Expand Down
2 changes: 1 addition & 1 deletion src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ JL_DLLEXPORT uint64_t jl_tasklocal_genrandom(jl_task_t *task) JL_NOTSAFEPOINT
uint64_t s2 = task->rngState2;
uint64_t s3 = task->rngState3;

uint64_t t = s0 << 17;
uint64_t t = s1 << 17;
uint64_t tmp = s0 + s3;
uint64_t res = ((tmp << 23) | (tmp >> 41)) + s0;
s2 ^= s0;
Expand Down
8 changes: 4 additions & 4 deletions stdlib/LinearAlgebra/test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ Random.seed!(1234323)
@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) 50.60863783272028 atol=0.5
@test cond(a,2) 23.059634761613314 atol=0.5
@test cond(a,Inf) 45.12503933120795 atol=0.4
@test cond(a[:,1:5]) 5.719500544258695 atol=0.01
@test cond(a,1) 855.6103637603965 atol=0.5
@test cond(a,2) 570.5296048445405 atol=0.5
@test cond(a,Inf) 1210.8340599789594 atol=0.4
@test cond(a[:,1:5]) 12.140520859885147 atol=0.01
@test_throws ArgumentError cond(a,3)
end
end
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 @@ -141,7 +141,7 @@ end
end

@testset "arithmetic with Number" begin
α = randn()
α = rand()
@test α + I == α + 1
@test I + α == α + 1
@test α - I == α - 1
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Random/src/Xoshiro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ rng_native_52(::Xoshiro) = UInt64
@inline function rand(rng::Xoshiro, ::SamplerType{UInt64})
s0, s1, s2, s3 = rng.s0, rng.s1, rng.s2, rng.s3
tmp = s0 + s3
res = tmp << 23 | tmp >> 41
res = ((tmp << 23) | (tmp >> 41)) + s0
t = s1 << 17
s2 = xor(s2, s0)
s3 = xor(s3, s1)
Expand Down
12 changes: 6 additions & 6 deletions stdlib/Random/src/XoshiroSimd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ end

i = 0
while i+8 <= len
res = _rotl23(_plus(s0,s3))
res = _plus(_rotl23(_plus(s0,s3)),s0)
unsafe_store!(reinterpret(Ptr{UInt64}, dst + i), f(res, T))
t = _shl17(s1)
s2 = _xor(s2, s0)
Expand All @@ -170,7 +170,7 @@ end
i += 8
end
if i < len
res = _rotl23(_plus(s0,s3))
res = _plus(_rotl23(_plus(s0,s3)),s0)
t = _shl17(s1)
s2 = _xor(s2, s0)
s3 = _xor(s3, s1)
Expand Down Expand Up @@ -200,7 +200,7 @@ end

i = 0
while i+8 <= len
res = _rotl23(_plus(s0,s3))
res = _plus(_rotl23(_plus(s0,s3)),s0)
shift = 0
while i+8 <= len && shift < 8
resLoc = _and(_lshr(res, shift), 0x0101010101010101)
Expand All @@ -219,7 +219,7 @@ end
end
if i < len
# we may overgenerate some bytes here, if len mod 64 <= 56 and len mod 8 != 0
res = _rotl23(_plus(s0,s3))
res = _plus(_rotl23(_plus(s0,s3)),s0)
resLoc = _and(res, 0x0101010101010101)
ref = Ref(resLoc)
ccall(:memcpy, Ptr{Cvoid}, (Ptr{UInt8}, Ptr{UInt64}, Csize_t), dst+i, ref, len-i)
Expand All @@ -245,7 +245,7 @@ end

i = 0
while i + 8*N <= len
res = _rotl23(_plus(s0,s3))
res = _plus(_rotl23(_plus(s0,s3)),s0)
t = _shl17(s1)
s2 = _xor(s2, s0)
s3 = _xor(s3, s1)
Expand All @@ -264,7 +264,7 @@ end
msk = ntuple(i->VecElement(0x0101010101010101), Val(N))
i = 0
while i + 64*N <= len
res = _rotl23(_plus(s0,s3))
res = _plus(_rotl23(_plus(s0,s3)),s0)
t = _shl17(s1)
s2 = _xor(s2, s0)
s3 = _xor(s3, s1)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1647,8 +1647,8 @@ julia> sprand(Bool, 2, 2, 0.5)
julia> sprand(Float64, 3, 0.75)
3-element SparseVector{Float64, Int64} with 2 stored entries:
[1] = 0.523355
[2] = 0.0890391
[1] = 0.787459
[2] = 0.544574
```
"""
function sprand(r::AbstractRNG, m::Integer, n::Integer, density::AbstractFloat, rfn::Function, ::Type{T}=eltype(rfn(r, 1))) where T
Expand Down

0 comments on commit f28ecd5

Please sign in to comment.