JuliaDiff / JuliaDiff/FiniteDifferences.jl

Accuracy with Float32s is bad

Open
#98 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug good first issue help wanted
Dominant language
Julia
Stars
318
Forks
32
PR merge metrics
No merged PRs in 30d

Description

@wesselb and I had a discussion about this a while ago, and I completely forgot to raise an issue about it. While FiniteDifferences accuracy for functions of Float64s is as you would expect, other types are a different matter. Of particular concern is Float32 as it's almost certainty the next most used type.

IIRC the issue is an issue of defaults. Specifically this one. float always yields a Float64, and eps(::Float64) is very different from eps(Float32). This changes the step-size calculation here.

If someone has time to look into this it would be greatly appreciated. I'm not entirely sure what the correct solution is, but a good approach to solving it might be

  1. recap how in principle to set the eps parameter that is causing the problems (perhaps @wesselb could help here?)
  2. figure out how to set eps based on this and make the appropriate changes
  3. test that it works

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading src/methods.jl at the referenced lines around 225 and 262 to trace how the default eps and step size behave for Float32 versus Float64. Review the numerical guidance for choosing eps, then add tests showing the expected Float32 accuracy and run the relevant test suite to confirm the change.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.