From 84e773d5e7d1032b09213c1766d7f19ed92d7ff9 Mon Sep 17 00:00:00 2001 From: schillic Date: Sun, 29 Dec 2024 12:54:59 +0100 Subject: [PATCH 1/2] make tolerance functions type stable --- src/Comparison/tolerance.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Comparison/tolerance.jl b/src/Comparison/tolerance.jl index 79ad0ce..de4e6ef 100644 --- a/src/Comparison/tolerance.jl +++ b/src/Comparison/tolerance.jl @@ -82,10 +82,10 @@ set_ztol(::Type{<:Rational}, ε::Rational) = _TOL_RAT.ztol = ε set_atol(::Type{<:Rational}, ε::Rational) = _TOL_RAT.atol = ε # global default tolerances for other numeric types -TOL_N = Dict{Type{<:Number},Tolerance}() -_rtol(N::Type{<:Number}) = get!(TOL_N, N, default_tolerance(N)).rtol -_ztol(N::Type{<:Number}) = get!(TOL_N, N, default_tolerance(N)).ztol -_atol(N::Type{<:Number}) = get!(TOL_N, N, default_tolerance(N)).atol +const TOL_N = Dict{Type{<:Number},Tolerance}() +_rtol(N::Type{<:Number})::N = get!(TOL_N, N, default_tolerance(N)).rtol +_ztol(N::Type{<:Number})::N = get!(TOL_N, N, default_tolerance(N)).ztol +_atol(N::Type{<:Number})::N = get!(TOL_N, N, default_tolerance(N)).atol set_rtol(N::Type{NT}, ε::NT) where {NT<:Number} = begin if N ∉ keys(TOL_N) From 11c9713cf178d3e046ac223d5ec30f3757b76358 Mon Sep 17 00:00:00 2001 From: schillic Date: Sun, 29 Dec 2024 13:00:42 +0100 Subject: [PATCH 2/2] simplify Dict interaction with 'get' --- src/Comparison/tolerance.jl | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Comparison/tolerance.jl b/src/Comparison/tolerance.jl index de4e6ef..72d30bc 100644 --- a/src/Comparison/tolerance.jl +++ b/src/Comparison/tolerance.jl @@ -87,23 +87,17 @@ _rtol(N::Type{<:Number})::N = get!(TOL_N, N, default_tolerance(N)).rtol _ztol(N::Type{<:Number})::N = get!(TOL_N, N, default_tolerance(N)).ztol _atol(N::Type{<:Number})::N = get!(TOL_N, N, default_tolerance(N)).atol -set_rtol(N::Type{NT}, ε::NT) where {NT<:Number} = begin - if N ∉ keys(TOL_N) - TOL_N[N] = default_tolerance(N) - end - TOL_N[N].rtol = ε +function set_rtol(N::Type{NT}, ε::NT) where {NT<:Number} + tol = get!(TOL_N, N, default_tolerance(N)) + tol.rtol = ε end -set_ztol(N::Type{NT}, ε::NT) where {NT<:Number} = begin - if N ∉ keys(TOL_N) - TOL_N[N] = default_tolerance(N) - end - TOL_N[N].ztol = ε +function set_ztol(N::Type{NT}, ε::NT) where {NT<:Number} + tol = get!(TOL_N, N, default_tolerance(N)) + tol.ztol = ε end -set_atol(N::Type{NT}, ε::NT) where {NT<:Number} = begin - if N ∉ keys(TOL_N) - TOL_N[N] = default_tolerance(N) - end - TOL_N[N].atol = ε +function set_atol(N::Type{NT}, ε::NT) where {NT<:Number} + tol = get!(TOL_N, N, default_tolerance(N)) + tol.atol = ε end