Comments (3)
Cool, but I think #89 is much simpler, it's just one line 😅
from measurements.jl.
Sorry, I got only now the time to look into this.
I suspect the culprit is Unitful.jl
here. In this line of QuadGK
, when T = typeof((10±1)u"m")
we have
julia> T = typeof((10±1)u"m")
Quantity{Measurement{Float64}, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}
julia> typeof(float(real(one(T))))
Measurement{Float64}
so the Quantity
information of the type is stripped away, leading to an inconsistency.
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 Unitful.jl
(if it is indeed an issue there), but I think I have a workaround that can be applied here, I only need to make sure it doesn't break too much stuff.
from measurements.jl.
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
from measurements.jl.
Related Issues (20)
- making measurements work with Printf
- Error when hashing Measurement{Float64} HOT 5
- Adding measurement components back to a measurement after iteratively solving for a value HOT 7
- [FR] Plot recipe: ribbon plots option beside error bars HOT 11
- tryparse for Measurement type
- Can't use unique with measurements HOT 1
- Measurements with missing errors HOT 4
- Measurements.value(x::Missing) = missing HOT 1
- Integration with Zygote
- `weightedmean()` returns `NaN ± 0`? HOT 1
- Use auto-differentiation engine
- Bad integration with Plots' boxplot HOT 2
- Move to pkgextensions for Julia v1.9+
- one(measurement) should return 1, not 1 ± 0 HOT 8
- `Symbolics.jl` support? HOT 7
- Plotting mixture of measurements and missing data HOT 1
- Trying to use Measurements to differentiate respect to a unitful quantity. HOT 12
- Is there an autodiff package that is compatible? HOT 3
- Broken `MeasurementsJunoExt.jl` HOT 1
- Julia 1.6 incompatibility from stdlib compat bounds HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from measurements.jl.