-
Notifications
You must be signed in to change notification settings - Fork 4
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
Equivalence involving nondimensional quantity #6
Comments
I have never seen a “type piracy warning”, can you elaborate on that? The first 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 |
#7 implements the necessary
|
Many thanks for implementing this! And thanks for telling me about 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 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. |
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 |
Thanks, I know about type piracy but did not know that there are linters who warn about it. However, the |
If I define it directly then the warning disappears. |
One more reason to remove the |
In water treatment, for example, it is common to treat
mg/l
asppm
. Currently,UnitfulEquivalences.jl
does not allow equivalences involving nondimensional quantities such as concentration. I managed to do that with two dispatches ofedconvert
:But since it is a direct relation, it would be nice to be able to define them at once with something like
I extended
dimtype
withdimtype(::Unitful.Dimensions{()}) = typeof(Unitful.NoDims)
(despite the type piracy warning) so it could handle nondimensional quantities, but it was not enough since apparentlyedrelation
also complains aboutUnitful.NoDims
as the second argument. I think this is also related to the fact that I had to useUnitful.Quantity{T,D,U}
in my firstedconvert
solution above.As for the second
edconvert
, the following code also works for the conversion fromDensity
toNoDims
, without the need forUnitful.Quantity{T,D,U}
, but for some reason that I do not understand it also gives me a warning of type piracy:So I guess this is a "feature request" to allow one nondimensional quantity in
@eqrelation
.The text was updated successfully, but these errors were encountered: