Skip to content

Commit 20db52a

Browse files
authored
Merge pull request #207 from JuliaDiff/ox/short
use digits=5 (not sigdigits) to generate nice random numbers.
2 parents ae32599 + 6eb3529 commit 20db52a

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ChainRulesTestUtils"
22
uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a"
3-
version = "1.2.0"
3+
version = "1.2.1"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/rand_tangent.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rand_tangent(rng::AbstractRNG, x::Integer) = NoTangent()
1717
# while also not biasing the sample space too much
1818
function rand_tangent(rng::AbstractRNG, x::T) where {T<:Number}
1919
# 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)
20+
return round(9 * randn(rng, T), digits=5, base=2)
2121
end
2222
rand_tangent(rng::AbstractRNG, x::Float64) = rand(rng, -9:0.01:9)
2323
function rand_tangent(rng::AbstractRNG, x::ComplexF64)
@@ -27,7 +27,7 @@ end
2727
#BigFloat/MPFR is finicky about short numbers, this doesn't always work as well as it should
2828

2929
# 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)
30+
rand_tangent(rng::AbstractRNG, ::BigFloat) = round(big(9 * randn(rng)), digits=5, base=2)
3131

3232

3333
rand_tangent(rng::AbstractRNG, x::Array{<:Any, 0}) = _compress_notangent(fill(rand_tangent(rng, x[])))

test/rand_tangent.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ struct Bar
105105
end
106106

107107
# Julia 1.6 changed to using Ryu printing algorithm and seems better at printing short
108-
VERSION > v"1.6" && @testset "niceness of printing" begin
109-
rng = MersenneTwister()
108+
VERSION >= v"1.6" && @testset "niceness of printing" begin
109+
rng = MersenneTwister(1)
110110
for i in 1:50
111-
@test length(string(rand_tangent(1.0))) <= 6
112-
@test length(string(rand_tangent(1.0 + 1.0im))) <= 12
113-
@test length(string(rand_tangent(1f0))) <= 12
114-
@test length(string(rand_tangent(big"1.0"))) <= 20
111+
@test length(string(rand_tangent(rng, 1.0))) <= 6
112+
@test length(string(rand_tangent(rng, 1.0 + 1.0im))) <= 12
113+
@test length(string(rand_tangent(rng, 1f0))) <= 9
114+
@test length(string(rand_tangent(rng, big"1.0"))) <= 9
115115
end
116116
end
117117
end

0 commit comments

Comments
 (0)