Skip to content

Commit 00596e3

Browse files
committed
Explain why scaling randn
1 parent a7a416c commit 00596e3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/rand_tangent.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ rand_tangent(rng::AbstractRNG, x::Integer) = NoTangent()
1616
# Try and make nice numbers with short decimal representations for good error messages
1717
# while also not biasing the sample space too much
1818
function rand_tangent(rng::AbstractRNG, x::T) where {T<:Number}
19-
return round(8randn(rng, T), sigdigits=5, base=2)
19+
# multiply by 9 to give a bigger range of values tested: no so tightly clustered around 0.
20+
return round(9 * randn(rng, T), sigdigits=5, base=2)
2021
end
2122
rand_tangent(rng::AbstractRNG, x::Float64) = rand(rng, -9:0.01:9)
2223
function rand_tangent(rng::AbstractRNG, x::ComplexF64)
2324
return ComplexF64(rand(rng, -9:0.1:9), rand(rng, -9:0.1:9))
2425
end
2526

2627
#BigFloat/MPFR is finicky about short numbers, this doesn't always work as well as it should
27-
rand_tangent(rng::AbstractRNG, ::BigFloat) = round(big(8randn(rng)), sigdigits=5, base=2)
28+
29+
# multiply by 9 to give a bigger range of values tested: no so tightly clustered around 0.
30+
rand_tangent(rng::AbstractRNG, ::BigFloat) = round(big(9 * randn(rng)), sigdigits=5, base=2)
2831

2932
rand_tangent(rng::AbstractRNG, x::StridedArray) = rand_tangent.(Ref(rng), x)
3033
rand_tangent(rng::AbstractRNG, x::Adjoint) = adjoint(rand_tangent(rng, parent(x)))

0 commit comments

Comments
 (0)