Skip to content
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

Avoid StackOverflowError with erf* functions #353

Merged
merged 2 commits into from
Oct 1, 2021

Conversation

devmotion
Copy link
Member

In the same way as #347, this PR avoids StackOverflowErrors and manually thrown MethodErrors by forwarding the erf* functions to an internal function (for which a MethodError is thrown if an implementation is missing).

Fixes #352, with this PR is a MethodError is thrown instead of a StackOverflowError:

julia> using SpecialFunctions, VectorizationBase

julia> vx = Vec(ntuple(_ -> 10randn(), VectorizationBase.pick_vector_width(Float64))...)
Vec{4, Float64}<-12.340876887492247, 12.779513587757672, -1.5552071156137923, -2.563055489830334>

julia> erf(vx)
ERROR: MethodError: no method matching _erf(::Vec{4, Float64})
Closest candidates are:
  _erf(::Float64) at /home/david/.julia/dev/SpecialFunctions/src/erf.jl:12
  _erf(::Float32) at /home/david/.julia/dev/SpecialFunctions/src/erf.jl:13
  _erf(::Float16) at /home/david/.julia/dev/SpecialFunctions/src/erf.jl:14
  ...
Stacktrace:
 [1] erf(x::Vec{4, Float64})
   @ SpecialFunctions ~/.julia/dev/SpecialFunctions/src/erf.jl:10
 [2] top-level scope
   @ REPL[6]:1

src/erf.jl Show resolved Hide resolved
src/erf.jl Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 30, 2021

Codecov Report

Merging #353 (d086782) into master (c0442c2) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #353      +/-   ##
==========================================
+ Coverage   92.55%   92.58%   +0.03%     
==========================================
  Files          12       12              
  Lines        2712     2710       -2     
==========================================
- Hits         2510     2509       -1     
+ Misses        202      201       -1     
Flag Coverage Δ
unittests 92.58% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/erf.jl 100.00% <100.00%> (+2.04%) ⬆️
src/beta_inc.jl 89.47% <0.00%> (-0.31%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c0442c2...d086782. Read the comment docs.

@stevengj stevengj merged commit a1df96d into JuliaMath:master Oct 1, 2021
@devmotion devmotion deleted the dw/erf_methoderror branch October 1, 2021 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

erf(x::Vec{4,Float64}) infinitely recurses
2 participants