-
Notifications
You must be signed in to change notification settings - Fork 143
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
allow printing using at-printf #511
Conversation
I implemented specializations of `Printf.tofloat` to allow printing (the `value` of) dual numbers. This is useful when differentiating functions that print some information during the computation, cf. https://discourse.julialang.org/t/forwarddiff-jl-and-printf/57694.
Codecov Report
@@ Coverage Diff @@
## master #511 +/- ##
==========================================
- Coverage 89.36% 84.62% -4.74%
==========================================
Files 10 9 -1
Lines 846 826 -20
==========================================
- Hits 756 699 -57
- Misses 90 127 +37
Continue to review full report at Codecov.
|
Is this really correct? Compare with e.g. complex numbers:
Why shouldn't this give the same error? |
My reason for implementing it like this is something like the following situation. Imagine someone wrote a performant numrical algorithm that can take quite some time in generic Julia code so that AD can just work out of the box. The only problematic part is that some In contrast to dual numbers used for AD, complex numbers usually appear in other situations and people will know more often when they need to support them, at least in my field of interest. Is there a better solution to this problem? |
I don't want to appear rude or demanding and I have never contributed to ForwardDiff.jl before, so it's not up to me to make any requests. However, I would like to know how to approach a situation where people have coded a highly complicated algorithm working on |
Are there any updates on the status of this PR yet?
I second that statement. The difference to complex numbers is that they do not identify as |
Bump. Any thoughts on this? |
@testset "@printf" begin | ||
for T in (Float16, Float32, Float64, BigFloat) | ||
d1 = Dual(one(T)) | ||
@test_nowarn @printf("Testing @printf: %.2e\n", d1) |
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.
Would it make more sense to use @sprintf
and check the result?
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.
Thanks, that's a good suggestion! I added an additional test using @sprintf
where the resulting string is checked (see below).
I personally think this behavior is slightly confusing but people seem to like it so 🤷♂️ |
I implemented specializations of
Printf.tofloat
to allow printing (thevalue
of) dual numbers. This is useful when differentiating functions that print some information during the computation, cf. https://discourse.julialang.org/t/forwarddiff-jl-and-printf/57694.