JuliaDiff / JuliaDiff/FiniteDifferences.jl
Accept Unitful numbers as input
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 318
- Forks
- 32
- PR merge metrics
- No merged PRs in 30d
Description
Currently, when attempting to use unitful numbers from Unitful.jl with the functions in this library, one gets MethodErrors related to the fact that Unitful.Quantity{...} <: Number instead of Unitful.Quantity{...} <: Real:
ERROR: MethodError: no method matching (::FiniteDifferences.AdaptedFiniteDifferenceMethod{…})(::var"#35#36", ::Quantity{…})
The object of type `FiniteDifferences.AdaptedFiniteDifferenceMethod{3, 1, FiniteDifferences.UnadaptedFiniteDifferenceMethod{5, 3}}` exists, but no method is defined for this combination of argument types when trying to treat it as a callable object.
Closest candidates are:
(::FiniteDifferences.AdaptedFiniteDifferenceMethod)(::TF, ::Real) where TF
@ FiniteDifferences ~/.julia/packages/FiniteDifferences/IPGFN/src/methods.jl:191
(::FiniteDifferences.AdaptedFiniteDifferenceMethod{P, Q})(::TF, ::Real, ::Real) where {P, Q, TF}
@ FiniteDifferences ~/.julia/packages/FiniteDifferences/IPGFN/src/methods.jl:238
At this point I am not sure whether simply relaxing the argument type restriction of functions like FiniteDifferences.central_fdm from Real to Number would suffice (with the possible risk of introducing silent semantic errors), or whether separate methods, that explicitly handle the units in some way (e.g. first stripping them and then reattaching the proper ones to the results) should be defined for Unitful numbers.
Regardless, it would be very nice if this library supported unitful numbers out of the box.
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 by reproducing the Unitful.Quantity MethodError and inspect methods.jl around the reported methods at lines 191 and 238, including the central_fdm entry point. Determine whether accepting Number preserves finite-difference semantics or requires explicit unit handling; done means Unitful inputs work without MethodErrors and return correctly handled results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100