Giter Club home page Giter Club logo

Comments (3)

giordano avatar giordano commented on May 29, 2024 1

Cool, but I think #89 is much simpler, it's just one line 😅

from measurements.jl.

giordano avatar giordano commented on May 29, 2024

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.

DanDeepPhase avatar DanDeepPhase commented on May 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.