-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Prompted by JuliaPhysics/Unitful.jl#44
@stevengj The docstring for quadgk says:
The integrand f(x) can return any numeric scalar, vector, or matrix type,
or in fact any type supporting +, -, multiplication by real values, and a
norm (i.e., any normed vector space).
While Unitful numbers support +, -, multiplication by real values, and vecnorm, quadgk does not work with Unitful. I'd like to suggest making very small modifications to quadgk.jl, or at least clarifying the docstring to say that the result of the norm needs to be a real number.
The field named E in the type Base.QuadGK.Segment is restricted to Reals. This is problematic as unitful numbers are not real numbers, so I would remove the restriction. I presume it was intended to ensure that the type of E implements isless comparisons, but perhaps there's another way to do this without preventing unitful numbers from working?
With this small change, I just need to implement a quadgk method in Unitful to make quadgk compatible with unitful numbers. I've tried it out and it seems to work well. It is however possible that the default abstol will be dimensionally inconsistent with the results of integration. Without knowing the return type of the function being integrated I'm not sure one can do anything cleanly in Base (I guess you could try zero(f(x)*x) where x is some point within an integration interval?). I could always just suggest that Unitful users explicitly provide an abstol.
I'm happy to provide a PR if this change is acceptable.