Skip to content

Commit

Permalink
Merge pull request #958 from adarshpalaskar1/reduce-sigdigits-display…
Browse files Browse the repository at this point in the history
…-948

Reduce sigdigits in parameter range display #948
  • Loading branch information
ablaom authored Feb 3, 2024
2 parents f3da249 + 02af6e0 commit 831abfa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/hyperparam/one_dimensional_ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ end
# throws an exception:
function _repr(r::NumericRange{T}, field) where T
value = getproperty(r, field)
if !(value isa Integer)
value = round(value, sigdigits=4)
end
r.scale isa Symbol && return repr(value)
return try
scaled = (r.scale)(value)
Expand Down
3 changes: 3 additions & 0 deletions test/hyperparam/one_dimensional_ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,13 @@ end
io = IOBuffer()
r1 = range(Int, :junk, lower=1, upper=10)
r2 = range(Char, :junk, values=['c', 'd'])
r3 = range(Float64, :junk, lower=3.14159, upper=6.283185)
show(io, r1)
@test String(take!(io)) == "NumericRange(1 ≤ junk ≤ 10; origin=5.5, unit=4.5)"
show(io, r2)
@test String(take!(io)) == "NominalRange(junk = c, d)"
show(io, r3)
@test String(take!(io)) == "NumericRange(3.142 ≤ junk ≤ 6.283; origin=4.712, unit=1.571)"
close(io)
end

Expand Down

0 comments on commit 831abfa

Please sign in to comment.