-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.0-dev: improve printing and fix alignment issue #555
Conversation
Codecov ReportBase: 85.22% // Head: 85.13% // Decreases project coverage by
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## 1.0-dev #555 +/- ##
===========================================
- Coverage 85.22% 85.13% -0.09%
===========================================
Files 34 34
Lines 1793 1837 +44
===========================================
+ Hits 1528 1564 +36
- Misses 265 273 +8
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice job overall, I'm very thankful you decided to delve into this!
Also thanks very much for the informative comments and docstrings.
@Kolaru @lucaferranti I have made the requested changes. The commit cbbd9ed (which introduces tests for large exponents) revealed that the printing of large exponent changes depending on the OS, e.g. Windows. Since I work on macOS, I did not see this issue. Moreover, the two last commits are worth discussing. The commit f66abd1 defines |
Oh no. This is concerning, I will try to reproduce locally (I've access to linux and windows) and see if can understand where it comes from.
I think it feels right as well, but we need to check if the IEEE standard as an opinion about representing intervals as string. Worst case we need an additional specific method to have the output prescribed by the standard. |
Thanks for looking into this!
I just had a look at the standard and, as far as I can tell, they only specify "interval literals" for parsing purposing. So the meaning of the function |
sorry for the very slow follow-up. I am in a very busy couple of weeks, with several paper deadlines approaching. I'll try to double check the discussion today |
I checked and the test are passing on my CentOS machine. So I'm very confused. I will run the tests with the PR on my windows machine tonight. |
This is a platform dependent behavior (bug ?) of BigFloat. I reported it there JuliaLang/julia#48678. On Windows: julia> big"-5.87565e+1388255822130839282"
-Inf On Ubuntu (WSL): julia> big"-5.87565e+1388255822130839282"
-5.875649999999999999999999999999999999999999999999999999999999999999999999999983e+1388255822130839282 For now I think it would be good enough to test with a slightly less crazy bound like |
Thanks @Kolaru for looking into this! The CI now runs successfully with the smaller exponent that you suggested 🎉 |
|
||
setformat(:full) | ||
@test string(a) == "DecoratedInterval(Interval(2.0, 3.0), com)" | ||
@test sprint(show, MIME("text/plain"), a) == "DecoratedInterval(Interval(2.0, 3.0), com)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a comment/suggestion, which I guess is small enough to be incorporated for intervals/decorated intervals with BigFloat
s: I like that the :standard
format shows the precision of the BigFloat end-points; this is not included in the :full
format, as shown by this example. I think displaying the precision is informative; while we usually fix it (and forget it), MPFR allows to work with different precisions, which is a case where it is worth a reminder.
So, what about including the precision for Interval{BigFloat}
and DecoratedInterval{BigFloat}
always?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not a bad idea. Note that we need a signature for show
which returns parseable Julia code (cf. docstring for show
). In this PR this behaviour is tied with the formatting mechanism via setformat(:full)
.
I think the best option would be to add an other symbol, say :parseable
, such that setformat(:parseable)
replaces the current setformat(:full)
. Then, setformat(:full)
can have the behaviour you suggest.
Also, do you have a display in mind? Something like @biginterval(1)
is displayed as "Interval(1.0, 1.0)₂₅₆"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, what about doing this for :midpoint
as well?
So it would look like
julia> setformat(:midpoint)
Display options:
- format: midpoint
- decorations: true
- significant digits: 6
julia> big(1)..2
(1.5 ± 0.5)₂₅₆
julia> setformat(:full); # full display of the bounds and show precision if BigFloat
julia> big(1)..2
Interval(1.0, 2.0)₂₅₆
julia> setformat(:parseable); # parseable Julia code
julia> big(1)..2
Interval(1.0, 2.0)
EDIT: Mhmm looking at this a bit closer, I am not sure this is really the right call. It seems more logical to display Interval{BigFloat}
for :full
. Then the user would know that they are dealing with BigFloat (unlike for :standard
) and checking the precision is as easy as precision(BigFloat)
.
This would keep the setformat
mechanism simple (no need to add another symbol :parseable
). Also, this is more consistent with the behaviour in Base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great that the comment was useful! 😄
I like all proposals:
- the
:raw
and:full
formats, where the raw format is for copy-paste (or saving results to be reused), and the full format is to have all details displayed; - I like the display you propose
Interval(1.0, 1.0)₂₅₆
; - include the precision in the
:midpoint
format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But now I am not unsure about the :raw
/:parseable
options 🤔. Mainly because the way Julia gives information of the precision for BigFloat
is through the function precision
and not the display.
So showing Interval{BigFloat}
is sufficient and consistent with Base. A user would know that they have an interval with bounds of type BigFloat
which has precision precision(BigFloat)
.
But it is definitely useful to display the precision for :midpoint
. So I will add a commit for this.
With the last two commits, the decorations are shown by default and the precision for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good to me, thanks a lot!
LGTM too, so let's go ahead and merge this! |
Thanks a lot @OlivierHnt |
Over the week-end I experimented with the printing mechanism of the 1.0-dev branch. This is the resulting PR 🙂.
Fix #316, #434.
It seems that the alignment issue when printing arrays is linked to the fact that
Interval <: Real
and sometimes the bounds of the intervals are printed with no decimal points. The current behaviour (before this PR) relies on the format"%.g"
which gives the shortest form for a given number (e.g.1.0
would be returned as1
).So this would explain also why
IntervalBox
had no printing issues: it is not a subtype ofReal
.In this PR I tried to stay as close as possible to the current behaviour, so the only visual change is that exact integers are displayed with a trailing decimal point and 0, for instance
1
is printed as1.0
.I have modified the tests to comply with this change.
Before this PR:
After this PR:
Other changes
Before this PR:
After this PR:
I uncommented some tests for
Complex{<:Interval}
, they pass successfully. In the file changelog.md, it is mentioned that support forComplex{<:Interval}
is dropped 🙁. However, there are still existing functionalities forComplex{<:Interval}
on this branch and the display tests pass without extra work.Rename the keyword argument
sigfigs
ofsetformat
tosigdigits
to match the naming convention of Julia (e.g. see the keywords ofround
).Fix all the inconsistencies where
==
was used instead of===
(or!=
instead of!==
). In particular, use===
to compare symbols.Improve performance of printing. For instance, faster
supscriptify
andsubscriptify
andrepresentation
is now type-stable.For instance, before this PR:
After this PR: