Skip to content

Implement erfcx in the SpecialFunctions extension - #645

Open
timholy wants to merge 1 commit into
JuliaGPU:mainfrom
timholy:teh/erfcx
Open

timholy wants to merge 1 commit into
JuliaGPU:mainfrom
timholy:teh/erfcx

Conversation

@timholy

@timholy timholy commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

OpenCL has no erfcx builtin, and SpecialFunctions' Float32 and Float64 methods call into libopenspecfun, so kernels using erfcx failed to compile.

The device implementation is pure Julia. The implementation is from

Shepherd & Laframboise, "Chebyshev approximation of (1+2x)exp(x²)erfc x in 0 ≤ x < ∞", Math. Comp. 36 (1981), 249–253).

Against a 256-bit reference on PoCL, the maximum error is 1.43 ulp (Float64) and 1.41 ulp (Float32) for x >= 0, and 1.84 and 1.86 ulp for x < 0.

I also decided to commit the script that calculates the coefficients as lib/intrinsics/gen/erfcx.jl. Let me know if you want me to strip that out.

Fixes JuliaGPU/GPUArrays.jl#877

Assisted-by: Claude Opus 5.5 noreply@anthropic.com

@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.57%. Comparing base (3951cbc) to head (d74ccef).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #645      +/-   ##
==========================================
- Coverage   90.42%   88.57%   -1.85%     
==========================================
  Files          18       18              
  Lines        1681     1681              
==========================================
- Hits         1520     1489      -31     
- Misses        161      192      +31     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

OpenCL has no erfcx builtin, and SpecialFunctions' Float32 and Float64
methods call into libopenspecfun, so kernels using erfcx failed to
compile.

The device implementation is pure Julia. The implementation is from

    Shepherd & Laframboise, "Chebyshev approximation of (1+2x)exp(x²)erfc x
    in 0 ≤ x < ∞", Math. Comp. 36 (1981), 249–253).

Against a 256-bit reference on PoCL, the maximum error is 1.43 ulp
(Float64) and 1.41 ulp (Float32) for x >= 0, and 1.84 and 1.86 ulp for
x < 0. lib/intrinsics/gen/erfcx.jl regenerates the coefficients.

Fixes JuliaGPU/GPUArrays.jl#877

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
@timholy

timholy commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

AFAICT the remaining failures have nothing to do with this PR

This branch has not been deployed

No deployments
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.

JLArrays 0.5: erfcx, logerfc, logerfcx fail (worked in 0.4)

1 participant