Better printing of variables
Problem
Consider the following example:
julia> using Debugger, Tensors
julia> function f(x, y)
x′ = norm(x); y′ = norm(y)
return x′ * y′
end
f (generic function with 1 method)
julia> x, y, Z = rand(Vec{2}), rand(Vec{2}), rand(Tensor{4,3});
and lets look at the output when we @enter f:
julia> @enter f(x, y)
In f(x, y) at REPL[2]:2
2 x′ = norm(x); y′ = norm(y)
3 return x′ * y′
4 end
About to run: (LinearAlgebra.norm)([0.3829578398362945, 0.21368249577032006])
and the output of @enter f(Z, y):
julia> @enter f(Z, y)
In f(x, y) at REPL[2]:2
2 x′ = norm(x); y′ = norm(y)
3 return x′ * y′
4 end
About to run: (LinearAlgebra.norm)(<suppressed 1602 bytes of output>)
IMO there are a couple of problems here:
- We don't know what type
[0.3829578398362945, 0.21368249577032006]is, but looks like a regularVector{Float64}, which it isn't. - We don't know which variable
[0.3829578398362945, 0.21368249577032006]corresponds to. - We don't know which
normcall we are about to run (line 2 is highligted though, not visible here but in the REPL). - For "long values", e.g. the second example, we get 0 information.
To answer the questions above we would have to run fr and then compare the values to identify which variable [0.3829578398362945, 0.21368249577032006] corresponds to and then match that to the correct norm call.
Possible solutions
1. Print just the variable
I think that instead of printing the value of the arguments we print the variables, e.g.
About to run: (LinearAlgebra.norm)(x)
which would solve 1, 3 and 4 above, and to find out the type (and value) of x one can use fr, or `x.
2. Print variable and type
In addition to 1. we could print the type of the variables:
About to run: (LinearAlgebra.norm)(x::Vec{3,Float64})
but this can be problematic sometimes since the type of parametric composite types can be very long.
3. Print variables and list values after
Basically 1. but print the variables to the call just after, e.g.
About to run: (LinearAlgebra.norm)(x)
x =
3-element Tensor{1,3,Float64,3}:
0.3827836791790604
0.6323433090863673
0.191605815252049
but again, this can be problematic for functions with many arguments, or if each argument takes up much space when printing.
I think I prefer 1 above. If one needs to investigate the values more carefully it is IMO better to use the ` command anyway.
Not sure if this is the same issue, but I'm having to debug code where the debugger freezes at each step. Hitting ^C shows that the issue is with printing:
About to run: (copyto!)(<suppressed 239 bytes of output>, <suppressed printing error>)
This is not surprising as some of the print/show commands end up running infinite-loops for these particular types (infinite arrays). Perhaps a time limit should be put on the printing?
This is not surprising as some of the print/show commands end up running infinite-loops for these particular types (infinite arrays).
It kinda feels like the type should make print not be infinite.
agreed... but which print/show? It works fine on the REPL
(Also, the point of a debugger is to work with buggy code....)
It works fine on the REPL
We call repr on it.
(Also, the point of a debugger is to work with buggy code....)
And it made you find the bug ;)