Skip to content

Commit f56aff3

Browse files
committed
Allow setting max print width of IDs via Convex.MAXDIGITS.
1 parent 4f70b9b commit f56aff3

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/Convex.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ Controls width of tree printing globally for Convex.jl; defaults to 15. Set via
6666
"""
6767
const MAXWIDTH= Ref(15)
6868

69+
"""
70+
MAXDIGITS
71+
72+
When priting IDs of variables, only show the initial and final digits
73+
if the full ID has more than double the number of digits specified
74+
here. So, with the default setting MAXDIGITS=3, any ID longer than 7
75+
digits would be shortened; for example, ID `14656210999710729289`
76+
would be printed as `146…289`.
77+
78+
This setting controls tree printing globally for Convex.jl; defaults to 3.
79+
80+
Set via:
81+
82+
Convex.MAXDIGITS[] = 3
83+
"""
84+
const MAXDIGITS= Ref(3)
85+
6986
### modeling framework
7087
include("dcp.jl")
7188
include("expressions.jl")

src/utilities/show.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ julia> Convex.show_id(stdout, x)
1616
id: 163…906
1717
```
1818
"""
19-
show_id(io::IO, x::Union{AbstractExpr, Constraint}; digits = 3) = print(io, show_id(x; digits=digits))
19+
show_id(io::IO, x::Union{AbstractExpr, Constraint}; digits = MAXDIGITS[]) = print(io, show_id(x; digits=digits))
2020

21-
function show_id(x::Union{AbstractExpr, Constraint}; digits = 3)
21+
function show_id(x::Union{AbstractExpr, Constraint}; digits = MAXDIGITS[])
2222
hash_str = string(x.id_hash)
23-
return "id: " * first(hash_str, digits) * "" * last(hash_str, digits)
23+
if length(hash_str) > (2*digits + 1);
24+
return "id: " * first(hash_str, digits) * "" * last(hash_str, digits)
25+
else
26+
return "id: " * hash_str
27+
end
2428
end
2529

2630
"""

0 commit comments

Comments
 (0)