Giter VIP home page Giter VIP logo

Comments (7)

sostock avatar sostock commented on June 24, 2024

I have never seen a “type piracy warning”, can you elaborate on that?

The first edconvert methods can be simplified as follows:

edconvert(::dimtype(Unitful.Density), x::DimensionlessQuantity, e::DensityConcentration) = x * 1u"kg/L"

But I agree that this should work with the macro. I will implement it so that @eqrelation can be used with DimensionlessQuantity.

from unitfulequivalences.jl.

sostock avatar sostock commented on June 24, 2024

#7 implements the necessary dimtype method.

One thing that is still missing for dimensionless quantities to work correctly is support for plain numbers: uconvert(u"kg/L", 5u"mm/m", DensityConcentration()) works, but uconvert(u"kg/L", 5, DensityConcentration()) does not. I will implement that as well. Note that the conversion to plain numbers already works: uconvert(NoUnits, 5u"kg/L", DensityConcentration()) Support for plain numbers is now included in #7 as well.

from unitfulequivalences.jl.

rmsrosa avatar rmsrosa commented on June 24, 2024

Many thanks for implementing this!

And thanks for telling me about DimensionlessQuantity. I was looking for something like this to use as you mentioned, but somehow I missed it.

As for the type piracy, the warning I get is "An imported function has been extended without using module defined typed arguments.", which shows up in julia-vscode/StaticLint.jl as "TypePiracy".

I just learned about this so I will just point to two places that explain it better: julialang docs: Avoid type piracy and discourse: Clarification on type piracy.

So I agree that my extension to dimtype is a type piracy since both types I use are defined in other modules, but the following extensions use the type DensityConcentration, which is defined in my module, but they still give me this warning:

edconvert(d::dimtype(Unitful.Density), x::Unitful.DimensionlessQuantity, e::DensityConcentration) = x * 1u"kg/l"

edconvert(d::dimtype(NoDims), x::Unitful.Density, e::DensityConcentration) = x * 1u"L/kg"

Anyways, I will try out now with the direct relation that you implemented and get back here to let you know.

from unitfulequivalences.jl.

rmsrosa avatar rmsrosa commented on June 24, 2024

Ah, I guess I need to wait till the pull-request is closed, no worries. And I like that you proposed to make the definition of DimensionlessQuantity in Unitful.jl consistent with the others.

from unitfulequivalences.jl.

sostock avatar sostock commented on June 24, 2024

Thanks, I know about type piracy but did not know that there are linters who warn about it.

However, the edconvert methods are not type piracy (since you own DensityConcentration), so I wonder why you get a warning for them. Maybe the linter doesn’t recognise that DensityConcentration is a type from your module, since its definition is obfuscated by the @equivalence macro? Is the warning fixed by defining the DensityConcentration struct yourself instead of using the macro?

from unitfulequivalences.jl.

rmsrosa avatar rmsrosa commented on June 24, 2024

Is the warning fixed by defining the DensityConcentration struct yourself instead of using the macro?

If I define it directly then the warning disappears.

from unitfulequivalences.jl.

sostock avatar sostock commented on June 24, 2024

If I define it directly then the warning disappears.

One more reason to remove the @equivalence macro 😄

from unitfulequivalences.jl.

Related Issues (8)

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.