-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested Types issue #75
Comments
Sorry, I got only now the time to look into this. I suspect the culprit is julia> T = typeof((10±1)u"m")
Quantity{Measurement{Float64}, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}
julia> typeof(float(real(one(T))))
Measurement{Float64} so the For comparison, when the number has only errors, but not units: julia> T = typeof(10±1)
Measurement{Float64}
julia> typeof(float(real(one(T))))
Measurement{Float64} the information of the type is preserved. Honestly, I have no idea how to fix this in |
I wrote a bandaid fix that i wrote based on your quadgk code. It's a little brute force, but seems to work: function quadunitmeas_result(integ::Quantity{<:Measurement},deriv,a::Measurement)
u=unit(integ)
integstrip=ustrip(integ)
derivstrip=ustrip.(deriv)
derivtuple=(1,Measurement.value.(derivstrip)...)
meastuple=(integstrip,ustrip.(a)...)
u*Measurements.quadgk_result(integstrip.val,derivtuple,meastuple)
end
function quadunitmeas_result(integ::Quantity,deriv,a)
u=unit(integ)
u*Measurements.quadgk_result(ustrip(upreferred(integ)),ustrip.(upreferred.(deriv)), ustrip.(upreferred.(a)))
#u*Measurements.quadgk_result(ustrip((integ,deriv,a)))
end
function QuadGK.quadgk(f,a::Quantity{<:Measurement},b::Quantity;kws...)
av=Measurements.value(a)
integ=quadgk(f,av,b;kws...)
deriv=-f(av)
meas = quadunitmeas_result(integ[1],deriv,a)
(meas,integ[2])
end
function QuadGK.quadgk(f,a::Quantity,b::Quantity{<:Measurement};kws...)
bv=Measurements.value(b)
integ=quadgk(f,a,bv;kws...)
deriv=f(bv)
meas = quadunitmeas_result(integ[1],deriv,b)
(meas,integ[2])
end
function QuadGK.quadgk(f, a::Quantity{<:Measurement}, b::Quantity{<:Measurement}; kws...)
av=Measurements.value(a)
bv=Measurements.value(b)
integ=quadgk(f,av,bv;kws...)
deriv=(-f(av),f(bv))
meas = quadunitmeas_result(integ[1],deriv,(a,b))
(meas,integ[2])
end |
Cool, but I think #89 is much simpler, it's just one line 😅 |
I'm having trouble integrating with units and measurements.
that fails with:
The following partial combinations work
The text was updated successfully, but these errors were encountered: