Skip to content

Commit f0aa807

Browse files
authored
Merge pull request #54 from tkf/prettyprint
Pretty-print `ScalarTransform`s
2 parents a7795ae + a8a0329 commit f0aa807

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/scalar.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,23 @@ Transform to the real line (identity).
209209
const asℝ = as(Real, -∞, ∞)
210210

211211
const as_real = asℝ
212+
213+
Base.show(io::IO, t::ShiftedExp) =
214+
if t === asℝ₊
215+
print(io, "asℝ₊")
216+
elseif t === asℝ₋
217+
print(io, "asℝ₋")
218+
elseif t isa ShiftedExp{true}
219+
print(io, "as(Real, ", t.shift, ", ∞)")
220+
else
221+
print(io, "as(Real, -∞, ", t.shift, ")")
222+
end
223+
224+
Base.show(io::IO, t::ScaledShiftedLogistic) =
225+
if t === as𝕀
226+
print(io, "as𝕀")
227+
else
228+
print(io, "as(Real, ", t.shift, ", ", t.shift + t.scale, ")")
229+
end
230+
231+
Base.show(io::IO, t::Identity) = print(io, "asℝ")

test/runtests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,17 @@ end
462462
x = [zeros(d), zeros(d)]
463463
@test t.(x) == map(t, x)
464464
end
465+
466+
####
467+
#### show
468+
####
469+
470+
@testset "scalar show" begin
471+
@test string(asℝ) == "asℝ"
472+
@test string(asℝ₊) == "asℝ₊"
473+
@test string(asℝ₋) == "asℝ₋"
474+
@test string(as𝕀) == "as𝕀"
475+
@test string(as(Real, 0.0, 2.0)) == "as(Real, 0.0, 2.0)"
476+
@test string(as(Real, 1.0, ∞)) == "as(Real, 1.0, ∞)"
477+
@test string(as(Real, -∞, 1.0)) == "as(Real, -∞, 1.0)"
478+
end

0 commit comments

Comments
 (0)