JuliaArrays / JuliaArrays/StaticArrays.jl
NaN and Inf issues in exp
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
The test in https://github.com/JuliaArrays/StaticArrays.jl/blob/59f92e0ca7ac391a850a6e7a2ce1eb53aa237fc4/src/expm.jl#L21-L32 don't cover the NaN case so
julia> A = @SMatrix([1.0 0.1; NaN 1.0])
2×2 SArray{Tuple{2,2},Float64,2,4} with indices SOneTo(2)×SOneTo(2):
1.0 0.1
NaN 1.0
julia> exp(A)
2×2 SArray{Tuple{2,2},Float64,2,4} with indices SOneTo(2)×SOneTo(2):
2.71828 0.271828
NaN 2.71828
which should either throw or give a NaN. Also, https://github.com/JuliaArrays/StaticArrays.jl/blob/59f92e0ca7ac391a850a6e7a2ce1eb53aa237fc4/src/expm.jl#L96-L99 can be reached for matrices with Infs which will error in an uninformative way
julia> A = @SMatrix([1.0 0.1 0.0; Inf 1.0 0.1; 0.1 0.0 1.0])
3×3 SArray{Tuple{3,3},Float64,2,9} with indices SOneTo(3)×SOneTo(3):
1.0 0.1 0.0
Inf 1.0 0.1
0.1 0.0 1.0
julia> exp(A)
ERROR: InexactError: trunc(Int64, Inf)
Stacktrace:
[1] trunc at ./float.jl:703 [inlined]
[2] ceil at ./float.jl:365 [inlined]
[3] _exp(::Size{(3, 3)}, ::SArray{Tuple{3,3},Float64,2,9}) at /Users/vagrant/.julia/packages/StaticArrays/LJQEe/src/expm.jl:97
[4] exp(::SArray{Tuple{3,3},Float64,2,9}) at /Users/vagrant/.julia/packages/StaticArrays/LJQEe/src/expm.jl:1
[5] top-level scope at REPL[70]:1
[6] eval(::Module, ::Any) at /Applications/Pumas-1.1.app/Contents/Resources/julia/Contents/Resources/julia/lib/julia/sys.dylib:?
[7] eval_user_input(::Any, ::REPL.REPLBackend) at /Users/vagrant/worker/juliapro-staging-osx1011-0_6/build/tmp_julia/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/REPL/src/REPL.jl:134
[8] repl_backend_loop(::REPL.REPLBackend) at /Users/vagrant/worker/juliapro-staging-osx1011-0_6/build/tmp_julia/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/REPL/src/REPL.jl:195
[9] start_repl_backend(::REPL.REPLBackend, ::Any) at /Users/vagrant/worker/juliapro-staging-osx1011-0_6/build/tmp_julia/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/REPL/src/REPL.jl:180
[10] run_repl(::REPL.AbstractREPL, ::Any; backend_on_current_task::Bool) at /Users/vagrant/worker/juliapro-staging-osx1011-0_6/build/tmp_julia/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/REPL/src/REPL.jl:292
[11] run_repl(::REPL.AbstractREPL, ::Any) at /Users/vagrant/worker/juliapro-staging-osx1011-0_6/build/tmp_julia/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/REPL/src/REPL.jl:288
[12] (::Base.var"#807#809"{Bool,Bool,Bool,Bool})(::Module) at ./client.jl:399
[13] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at /Applications/Pumas-1.1.app/Contents/Resources/julia/Contents/Resources/julia/lib/julia/sys.dylib:?
[14] exec_options(::Base.JLOptions) at /Applications/Pumas-1.1.app/Contents/Resources/julia/Contents/Resources/julia/lib/julia/sys.dylib:?
[15] _start() at /Applications/Pumas-1.1.app/Contents/Resources/julia/Contents/Resources/julia/lib/julia/sys.dylib:?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/expm.jl, especially the existing test area at lines 21–32 and the Inf-related code at lines 96–99. Run the NaN and Inf matrix examples from the issue, then inspect how exp handles these values. Done means the behavior is covered by tests and no longer produces the reported uninformative result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100