Merge pull request #3661 from t-bltg/rng

Use a stable RNG in fakedata
This commit is contained in:
t-bltg 2021-07-23 19:50:54 +02:00 committed by GitHub
commit 878e590125
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 10 deletions

View File

@ -118,7 +118,6 @@ export
scalefontsizes, scalefontsizes,
resetfontsizes resetfontsizes
# --------------------------------------------------------- # ---------------------------------------------------------
import NaNMath # define functions that ignores NaNs. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563 import NaNMath # define functions that ignores NaNs. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563
@ -250,6 +249,7 @@ end
# --------------------------------------------------------- # ---------------------------------------------------------
const CURRENT_BACKEND = CurrentBackend(:none) const CURRENT_BACKEND = CurrentBackend(:none)
const PLOTS_SEED = 1234
include("precompile_includer.jl") include("precompile_includer.jl")

View File

@ -128,8 +128,7 @@ const _examples = PlotExample[
:( :(
begin begin
import FileIO import FileIO
path = path = download("http://juliaplots.org/PlotReferenceImages.jl/Plots/pyplot/0.7.0/ref1.png")
download("http://juliaplots.org/PlotReferenceImages.jl/Plots/pyplot/0.7.0/ref1.png")
img = FileIO.load(path) img = FileIO.load(path)
plot(img) plot(img)
end end

View File

@ -303,10 +303,12 @@ function convert_to_polar(theta, r, r_extrema = ignorenan_extrema(r))
x, y x, y
end end
function fakedata(sz...) fakedata(sz::Int...) = fakedata(Random.seed!(PLOTS_SEED), sz...)
function fakedata(rng::AbstractRNG, sz...)
y = zeros(sz...) y = zeros(sz...)
for r in 2:size(y,1) for r in 2:size(y,1)
y[r,:] = 0.95 * vec(y[r-1,:]) + randn(size(y,2)) y[r,:] = 0.95 * vec(y[r-1,:]) + randn(rng, size(y,2))
end end
y y
end end

View File

@ -6,14 +6,14 @@ function replace_rand!(ex::Expr)
for arg in ex.args for arg in ex.args
replace_rand!(arg) replace_rand!(arg)
end end
if ex.head === :call && ex.args[1] (:rand, :randn) if ex.head === :call && ex.args[1] (:rand, :randn, :(Plots.fakedata))
pushfirst!(ex.args, ex.args[1]) pushfirst!(ex.args, ex.args[1])
ex.args[2] = :rng ex.args[2] = :rng
end end
end end
function fix_rand!(ex) function fix_rand!(ex)
replace_rand!(ex) replace_rand!(ex)
pushfirst!(ex.args[1].args, :(rng = StableRNG(1234))) pushfirst!(ex.args[1].args, :(rng = StableRNG(PLOTS_SEED)))
end end
function image_comparison_tests( function image_comparison_tests(
@ -35,6 +35,7 @@ function image_comparison_tests(
fn = "ref$idx.png" fn = "ref$idx.png"
reffn = reference_file(pkg, idx, _current_plots_version) reffn = reference_file(pkg, idx, _current_plots_version)
newfn = joinpath(reference_path(pkg, _current_plots_version), fn) newfn = joinpath(reference_path(pkg, _current_plots_version), fn)
@debug example.exprs
# test function # test function
func = (fn, idx) -> begin func = (fn, idx) -> begin

View File

@ -1,4 +1,4 @@
using Plots: guidefont, series_annotations using Plots: guidefont, series_annotations, PLOTS_SEED
import ImageMagick import ImageMagick
using VisualRegressionTests using VisualRegressionTests
using Plots using Plots
@ -13,7 +13,6 @@ import GeometryBasics
using Dates using Dates
using RecipesBase using RecipesBase
@testset "Plotly standalone" begin @testset "Plotly standalone" begin
@test_nowarn Plots._init_ijulia_plotting() @test_nowarn Plots._init_ijulia_plotting()
@test Plots.plotly_local_file_path[] === nothing @test Plots.plotly_local_file_path[] === nothing
@ -68,7 +67,7 @@ end
include("imgcomp.jl") include("imgcomp.jl")
# don't actually show the plots # don't actually show the plots
Random.seed!(1234) Random.seed!(PLOTS_SEED)
default(show=false, reuse=true) default(show=false, reuse=true)
is_ci() = get(ENV, "CI", "false") == "true" is_ci() = get(ENV, "CI", "false") == "true"
const PLOTS_IMG_TOL = parse( const PLOTS_IMG_TOL = parse(