ForwardDiff.jl icon indicating copy to clipboard operation
ForwardDiff.jl copied to clipboard

printf formatting causes stack overflow

Open ikirill opened this issue 7 years ago • 1 comments

I know it's not really well-defined to try to print a dual number like this, but it would be better if it failed more gracefully, for example by printing the number with the right formatting and omitting the partials, or printing the partials with the same formatting, or something.

julia> Pkg.status("ForwardDiff")
 - ForwardDiff                   0.7.0              master

julia> ForwardDiff.derivative(x -> (@printf "%f\n" x; x), 0.0)
ERROR: StackOverflowError:
Stacktrace:
 [1] fix_dec(::ForwardDiff.Dual{ForwardDiff.Tag{##3#4,Float64},Float64,1}, ::Int64) at ./printf.jl:949 (repeats 80000 times)

julia> ForwardDiff.derivative(x -> (@printf "%s\n" x; x), 0.0)
Dual{ForwardDiff.Tag{##5#6,Float64}}(0.0,1.0)
1.0

julia> ForwardDiff.derivative(x -> (@printf "%e\n" x; x), 0.0)
ERROR: StackOverflowError:
Stacktrace:
 [1] ini_dec(::ForwardDiff.Dual{ForwardDiff.Tag{##7#8,Float64},Float64,1}, ::Int64) at ./printf.jl:970 (repeats 80000 times)

julia> ForwardDiff.derivative(x -> (@printf "%.2e\n" x; x), 0.0)
ERROR: StackOverflowError:
Stacktrace:
 [1] ini_dec(::ForwardDiff.Dual{ForwardDiff.Tag{##9#10,Float64},Float64,1}, ::Int64) at ./printf.jl:970 (repeats 80000 times)

julia> ForwardDiff.derivative(x -> (@printf "%g\n" x; x), 0.0)
ERROR: StackOverflowError:
Stacktrace:
 [1] ini_dec(::ForwardDiff.Dual{ForwardDiff.Tag{##11#12,Float64},Float64,1}, ::Int64) at ./printf.jl:970 (repeats 80000 times)
julia> versioninfo()
Julia Version 0.6.0
Commit 903644385b (2017-06-19 13:05 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

ikirill avatar Jan 06 '18 04:01 ikirill

Yes, it would be nice if the print functions works for Duals

jerlich avatar Mar 23 '19 16:03 jerlich