-
-
Notifications
You must be signed in to change notification settings - Fork 39
Less verbose type printing in stacktrace #42
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
Conversation
YingboMa
commented
Aug 7, 2020
Codecov Report
@@ Coverage Diff @@
## master #42 +/- ##
==========================================
- Coverage 58.06% 55.41% -2.65%
==========================================
Files 16 16
Lines 403 406 +3
==========================================
- Hits 234 225 -9
- Misses 169 181 +12
Continue to review full report at Codecov.
|
|
I like this, but I think I want to add an additional method like Although I wonder if the it would be better to have the eltype printed as well. Because it's reasonable that someone might have a method defined on a julia> sum_magnitudes(x::ComponentArray{<:Complex}) = sum(abs, x)
sum_magnitudes (generic function with 1 method)
julia> ca = ComponentArray(a=42, b=rand(3))
ComponentVector{Float64}(a = 42.0, b = [0.7541071306370861, 0.16224993425651957, 0.30748376563379165])
julia> sum_magnitudes(ca)
ERROR: MethodError: no method matching sum_magnitudes(::ComponentArray)
Closest candidates are:
sum_magnitudes(::ComponentArray) at REPL[9]:1
Stacktrace:
[1] top-level scope at REPL[13]:1
[2] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1088I'm going to give this some thought. ComponentVectors and ComponentMatrices are already printing similarly, this would just make it the same for their types too: julia> ca
ComponentVector{Float64}(a = 42.0, b = [0.7541071306370861, 0.16224993425651957, 0.30748376563379165])
julia> ca * ca'
ComponentMatrix{Float64} with axes (a = 1, b = 2:4) × (a = 1, b = 2:4)
1764.0 31.6725 6.8145 12.9143
31.6725 0.568678 0.122354 0.231876
6.8145 0.122354 0.026325 0.0498892
12.9143 0.231876 0.0498892 0.0945463Or maybe including the dimension size would be good too, so it would mirror normal arrays? |
|
Now it looks like this julia> foo(u0) = sqrt(-u0[1])
foo (generic function with 1 method)
julia> foo(u0)
ERROR: DomainError with -2.8e6:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:33
[2] sqrt at ./math.jl:573 [inlined]
[3] foo(::ComponentVector{Float64}) at ./REPL[4]:1
[4] top-level scope at REPL[5]:1
julia> foo(u0*u0')
ERROR: DomainError with -7.84e12:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:33
[2] sqrt at ./math.jl:573 [inlined]
[3] foo(::ComponentMatrix{Float64}) at ./REPL[4]:1
[4] top-level scope at REPL[6]:1
julia> foo(u0.*u0'.*reshape(u0, (1,1,length(u0))))
ERROR: DomainError with -2.1952e19:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
[1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:33
[2] sqrt at ./math.jl:573 [inlined]
[3] foo(::ComponentArray{Float64, 3}) at ./REPL[4]:1
[4] top-level scope at REPL[7]:1 |
|
That's, perfect. Thanks! |