Skip to content

Commit e55a8e8

Browse files
authored
No string interpolation in show methods (#456)
* No string interpolation in `show` methods * Fix format
1 parent e485198 commit e55a8e8

File tree

9 files changed

+63
-24
lines changed

9 files changed

+63
-24
lines changed

src/adaptation/Adaptation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct NaiveHMCAdaptor{M<:MassMatrixAdaptor,Tssa<:StepSizeAdaptor} <: AbstractAd
3838
ssa::Tssa
3939
end
4040
function Base.show(io::IO, ::MIME"text/plain", a::NaiveHMCAdaptor)
41-
return print(io, "NaiveHMCAdaptor(pc=$(a.pc), ssa=$(a.ssa))")
41+
return print(io, "NaiveHMCAdaptor(pc=", a.pc, ", ssa=", a.ssa, ")")
4242
end
4343

4444
getM⁻¹(ca::NaiveHMCAdaptor) = getM⁻¹(ca.pc)

src/adaptation/massmatrix.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ end
2424
struct UnitMassMatrix{T<:AbstractFloat} <: MassMatrixAdaptor end
2525

2626
function Base.show(io::IO, mime::MIME"text/plain", ::UnitMassMatrix{T}) where {T}
27-
return print(io, "UnitMassMatrix{$T} adaptor")
27+
return print(io, "UnitMassMatrix{", T, "} adaptor")
2828
end
2929

3030
UnitMassMatrix() = UnitMassMatrix{Float64}()
@@ -94,7 +94,7 @@ mutable struct WelfordVar{T<:AbstractFloat,E<:AbstractVecOrMat{T},V<:AbstractVec
9494
end
9595

9696
function Base.show(io::IO, mime::MIME"text/plain", ::WelfordVar{T}) where {T}
97-
return print(io, "WelfordVar{$T} adaptor")
97+
return print(io, "WelfordVar{", T, "} adaptor")
9898
end
9999

100100
function WelfordVar{T}(
@@ -195,7 +195,7 @@ mutable struct WelfordCov{F<:AbstractFloat,C<:AbstractMatrix{F}} <: DenseMatrixE
195195
end
196196

197197
function Base.show(io::IO, mime::MIME"text/plain", ::WelfordCov{T}) where {T}
198-
return print(io, "WelfordCov{$T} adaptor")
198+
return print(io, "WelfordCov{", T, "} adaptor")
199199
end
200200

201201
function WelfordCov{T}(

src/adaptation/stan_adaptor.jl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ function initialize!(
5050
end
5151

5252
function Base.show(io::IO, mime::MIME"text/plain", state::StanHMCAdaptorState)
53-
return print(
54-
io,
55-
"window($(state.window_start), $(state.window_end)), window_splits(" *
56-
string(join(state.window_splits, ", ")) *
57-
")",
58-
)
53+
print(io, "window(", state.window_start, ", ", state.window_end, "), window_splits(")
54+
join(io, state.window_splits, ", ")
55+
return print(io, ")")
5956
end
6057

6158
### Stan's windowed adaptation
@@ -72,7 +69,19 @@ end
7269
function Base.show(io::IO, mime::MIME"text/plain", a::StanHMCAdaptor)
7370
return print(
7471
io,
75-
"StanHMCAdaptor(\n pc=$(a.pc),\n ssa=$(a.ssa),\n init_buffer=$(a.init_buffer), term_buffer=$(a.term_buffer), window_size=$(a.window_size),\n state=$(a.state)\n)",
72+
"StanHMCAdaptor(\n pc=",
73+
a.pc,
74+
",\n ssa=",
75+
a.ssa,
76+
",\n init_buffer=",
77+
a.init_buffer,
78+
", term_buffer=",
79+
a.term_buffer,
80+
", window_size=",
81+
a.window_size,
82+
",\n state=",
83+
a.state,
84+
"\n)",
7685
)
7786
end
7887

src/adaptation/stepsize.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct ManualSSAdaptor{T<:AbstractScalarOrVec{<:AbstractFloat}} <: StepSizeAdapt
8787
state::MSSState{T}
8888
end
8989
function Base.show(io::IO, mime::MIME"text/plain", a::ManualSSAdaptor{T}) where {T}
90-
return print(io, "ManualSSAdaptor{$T} with step size of $(a.state.ϵ)")
90+
return print(io, "ManualSSAdaptor{", T, "} with step size of ", a.state.ϵ)
9191
end
9292

9393
function ManualSSAdaptor(initϵ::T) where {T<:AbstractScalarOrVec{<:AbstractFloat}}
@@ -122,7 +122,9 @@ end
122122
function Base.show(io::IO, mime::MIME"text/plain", a::NesterovDualAveraging{T}) where {T}
123123
return print(
124124
io,
125-
"NesterovDualAveraging{$T} with\n",
125+
"NesterovDualAveraging{",
126+
T,
127+
"} with\n",
126128
"Scaling γ=",
127129
a.γ,
128130
"\n",

src/integrator.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct Leapfrog{T<:AbstractScalarOrVec{<:AbstractFloat}} <: AbstractLeapfrog{T}
7373
ϵ::T
7474
end
7575
function Base.show(io::IO, mime::MIME"text/plain", l::Leapfrog)
76-
return print(io, "Leapfrog with step size ϵ=$(round.(l.ϵ; sigdigits=3))")
76+
return print(io, "Leapfrog with step size ϵ=", round.(l.ϵ; sigdigits=3), ")")
7777
end
7878
integrator_eltype(i::AbstractLeapfrog{T}) where {T<:AbstractFloat} = T
7979

@@ -123,7 +123,12 @@ JitteredLeapfrog(ϵ0, jitter) = JitteredLeapfrog(ϵ0, jitter, ϵ0)
123123
function Base.show(io::IO, mime::MIME"text/plain", l::JitteredLeapfrog)
124124
return print(
125125
io,
126-
"JitteredLeapfrog with step size $(round.(l.ϵ0; sigdigits=3)), jitter $(round.(l.jitter; sigdigits=3)), jittered step size $(round.(l.ϵ; sigdigits=3))",
126+
"JitteredLeapfrog with step size ",
127+
round.(l.ϵ0; sigdigits=3),
128+
", jitter ",
129+
round.(l.jitter; sigdigits=3),
130+
", jittered step size ",
131+
round.(l.ϵ; sigdigits=3),
127132
)
128133
end
129134

@@ -176,7 +181,10 @@ end
176181
function Base.show(io::IO, mime::MIME"text/plain", l::TemperedLeapfrog)
177182
return print(
178183
io,
179-
"TemperedLeapfrog with step size ϵ=$(round.(l.ϵ; sigdigits=3)) and temperature parameter α=$(round.(l.α; sigdigits=3))",
184+
"TemperedLeapfrog with step size ϵ=",
185+
round.(l.ϵ; sigdigits=3),
186+
" and temperature parameter α=",
187+
round.(l.α; sigdigits=3),
180188
)
181189
end
182190

src/metric.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ Base.size(e::UnitEuclideanMetric, dim::Int) = e.size[dim]
3636
function Base.show(io::IO, ::MIME"text/plain", uem::UnitEuclideanMetric{T}) where {T}
3737
return print(
3838
io,
39-
"UnitEuclideanMetric{$T} with size $(size(uem)) mass matrix:\n",
39+
"UnitEuclideanMetric{",
40+
T,
41+
"} with size ",
42+
size(uem),
43+
" mass matrix:\n",
4044
_string_M⁻¹(ones(uem.size)),
4145
)
4246
end
@@ -65,7 +69,11 @@ Base.size(e::DiagEuclideanMetric, dim...) = size(e.M⁻¹, dim...)
6569
function Base.show(io::IO, ::MIME"text/plain", dem::DiagEuclideanMetric{T}) where {T}
6670
return print(
6771
io,
68-
"DiagEuclideanMetric{$T} with size $(size(dem)) mass matrix:\n",
72+
"DiagEuclideanMetric{",
73+
T,
74+
"} with size ",
75+
size(dem),
76+
" mass matrix:\n",
6977
_string_M⁻¹(dem.M⁻¹),
7078
)
7179
end
@@ -105,7 +113,11 @@ Base.size(e::DenseEuclideanMetric, dim...) = size(e._temp, dim...)
105113
function Base.show(io::IO, ::MIME"text/plain", dem::DenseEuclideanMetric{T}) where {T}
106114
return print(
107115
io,
108-
"DenseEuclideanMetric{$T} with size $(size(dem)) mass matrix:\n",
116+
"DenseEuclideanMetric{",
117+
T,
118+
"} with size ",
119+
size(dem),
120+
" mass matrix:\n",
109121
_string_M⁻¹(dem.M⁻¹),
110122
)
111123
end

src/riemannian/hamiltonian.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct GeneralizedLeapfrog{T<:AbstractScalarOrVec{<:AbstractFloat}} <: AbstractL
2020
n::Int
2121
end
2222
function Base.show(io::IO, l::GeneralizedLeapfrog)
23-
return print(io, "GeneralizedLeapfrog(ϵ=$(round.(l.ϵ; sigdigits=3)), n=$(l.n))")
23+
return print(io, "GeneralizedLeapfrog(ϵ=", round.(l.ϵ; sigdigits=3), ", n=", l.n, ")")
2424
end
2525

2626
# Fallback to ignore return_cache & cache kwargs for other ∂H∂θ

src/riemannian/integrator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct GeneralizedLeapfrog{T<:AbstractScalarOrVec{<:AbstractFloat}} <: AbstractL
1818
n::Int
1919
end
2020
function Base.show(io::IO, l::GeneralizedLeapfrog)
21-
return print(io, "GeneralizedLeapfrog(ϵ=$(round.(l.ϵ; sigdigits=3)), n=$(l.n))")
21+
return print(io, "GeneralizedLeapfrog(ϵ=", round.(l.ϵ; sigdigits=3), ", n=", l.n, ")")
2222
end
2323

2424
# fallback to ignore return_cache & cache kwargs for other ∂H∂θ

src/trajectory.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ end
111111
function Base.show(io::IO, mime::MIME"text/plain", s::SliceTS)
112112
return print(
113113
io,
114-
"SliceTS with slice variable ℓu=$(s.ℓu) and number of acceptable candiadtes n=$(s.n)",
114+
"SliceTS with slice variable ℓu=",
115+
s.ℓu,
116+
" and number of acceptable candiadtes n=",
117+
s.n,
115118
)
116119
end
117120

@@ -225,7 +228,12 @@ ConstructionBase.constructorof(::Type{<:Trajectory{TS}}) where {TS} = Trajectory
225228
function Base.show(io::IO, mime::MIME"text/plain", τ::Trajectory{TS}) where {TS}
226229
return print(
227230
io,
228-
"Trajectory{$TS} with $(τ.integrator) and termination criterion $(τ.termination_criterion)",
231+
"Trajectory{",
232+
TS,
233+
"} with ",
234+
τ.integrator,
235+
" and termination criterion ",
236+
τ.termination_criterion,
229237
)
230238
end
231239

@@ -476,7 +484,7 @@ end
476484

477485
function Base.show(io::IO, mime::MIME"text/plain", d::Termination)
478486
return print(
479-
io, "Termination reasons of (dynamic=$(d.dynamic), numerical=$(d.numerical))"
487+
io, "Termination reasons of (dynamic=", d.dynamic, ", numerical=", d.numerical, ")"
480488
)
481489
end
482490
function Base.:*(d1::Termination, d2::Termination)

0 commit comments

Comments
 (0)