JuliaPhysics / JuliaPhysics/DynamicQuantities.jl
Quantity currently incompatible with QuadGK
- Dominant language
- Julia
- Stars
- 155
- Forks
- 32
- PR merge metrics
- No merged PRs in 30d
Description
I've been testing out **DynamicQuantities** as a replacement for **Unitful** in some of my packages and I discovered that it currently doesn't work with **QuadGK**'s integral solver like **Unitful** does. MWE (issue also opened [here](https://github.com/JuliaMath/QuadGK.jl/issues/88)).
```julia
julia> using DynamicQuantities # [06fc5a27] DynamicQuantities v0.7.0
julia> using QuadGK # [1fd47b50] QuadGK v2.8.2
julia> quadgk(t -> 5u"m/s"*t, 0u"s", 10u"s")
ERROR: MethodError: no method matching cachedrule(::Type{Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}, ::Int64)
Closest candidates are:
cachedrule(::Union{Type{Complex{BigFloat}}, Type{BigFloat}}, ::Integer)
@ QuadGK C:\Users\*\.julia\packages\QuadGK\XqIlh\src\gausskronrod.jl:253
cachedrule(::Type{T}, ::Integer) where T<:Number
@ QuadGK C:\Users\*\.julia\packages\QuadGK\XqIlh\src\gausskronrod.jl:264
```
It looks like the issue probably spawns from [here](https://github.com/SymbolicML/DynamicQuantities.jl/blob/30ac1e8d65c7113ca4d04426375023c915de4c41/src/utils.jl#L116) where `Base.one(::Quantity)` produces a `new_quantity`.
```julia
julia> typeof(one(typeof(1u"s")))
Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}
```
**QuadGK** would expect `Base.one` for the above example to return simply a `Float64` instead. This seems consistent with the docstring for `Base.one`, excerpted:
```
If possible, one(x) returns a value of the same type as x, and one(T) returns a value of type T. However,
this may not be the case for types representing dimensionful quantities (e.g. time in days), since the
multiplicative identity must be dimensionless. In that case, one(x) should return an identity value of
the same precision (and shape, for matrices) as x.
If you want a quantity that is of the same type as x, or of type T, even if x is dimensionful, use
oneunit instead.
...
Examples
≡≡≡≡≡≡≡≡≡≡
...
julia> import Dates; one(Dates.Day(1))
1
```
It also seems consistent with how **Unitful** handles this
```julia
julia> typeof(one(typeof(1.0u"s"))) # Unitful @u_str
Float64
```
Was the current definition of `Base.one` [here](https://github.com/SymbolicML/DynamicQuantities.jl/blob/30ac1e8d65c7113ca4d04426375023c915de4c41/src/utils.jl#L116) intended to return the dimensioned type?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.