use a stable RNG in fakedata

This commit is contained in:
t-bltg 2021-07-22 11:49:31 +02:00
parent a39582c06e
commit fe7d957be3
6 changed files with 11 additions and 12 deletions

View File

@ -31,6 +31,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
[compat] [compat]
Contour = "0.5" Contour = "0.5"
@ -65,7 +66,6 @@ OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925" PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925"
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a" PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b" RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
@ -74,4 +74,4 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92" VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
[targets] [targets]
test = ["Distributions", "FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "HDF5", "RDatasets", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "VisualRegressionTests"] test = ["Distributions", "FileIO", "Gtk", "ImageMagick", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "HDF5", "RDatasets", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "VisualRegressionTests"]

View File

@ -11,6 +11,7 @@ using Reexport
import GeometryBasics import GeometryBasics
using Dates, Printf, Statistics, Base64, LinearAlgebra, Random using Dates, Printf, Statistics, Base64, LinearAlgebra, Random
using SparseArrays using SparseArrays
using StableRNGs
using FFMPEG using FFMPEG
@ -118,7 +119,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 +250,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,10 @@ function convert_to_polar(theta, r, r_extrema = ignorenan_extrema(r))
x, y x, y
end end
function fakedata(sz...) function fakedata(sz...; rng=StableRNG(PLOTS_SEED))
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

@ -13,7 +13,7 @@ function replace_rand!(ex::Expr)
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(

View File

@ -1,9 +1,8 @@
using Plots: guidefont, series_annotations using Plots: guidefont, series_annotations, PLOTS_SEED
import ImageMagick import ImageMagick
using VisualRegressionTests using VisualRegressionTests
using Plots using Plots
using Random using Random
using StableRNGs
using Test using Test
using TestImages using TestImages
using FileIO using FileIO
@ -12,7 +11,7 @@ using LibGit2
import GeometryBasics import GeometryBasics
using Dates using Dates
using RecipesBase using RecipesBase
using StableRNGs
@testset "Plotly standalone" begin @testset "Plotly standalone" begin
@test_nowarn Plots._init_ijulia_plotting() @test_nowarn Plots._init_ijulia_plotting()
@ -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(