-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add AbstractRealQuantity #85
Conversation
Benchmark Results
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
Actually I think we shouldn't make all default quantities |
eb29a36
to
1d14589
Compare
12ab7e4
to
c98958b
Compare
c98958b
to
79bfd78
Compare
@gaurav-arya I'm wondering if we should just make |
Why not choose the most specific type given the value type? E.g. In this scenario, I wonder if we even need a single |
Yeah good point. The current behavior in this PR is actually
Maybe do you mean like #66? Although I don't think we necessarily need an |
Also:
Is this semantically correct? One could indeed argue that 1.0 meters is a type of number... But is it a real? Let me give an example. Would you agree with the statement ? I think it kind of seems incorrect... It's more like: for some abstract space Whereas This semantic ambiguity leads me to want to keep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some small comments! FYI this has been a bit of a "drive by" review, I'm a little swamped with my semester. But the overall idea I'm totally in support of.
Regarding aggressively defaulting to <: Real
: point taken that it might require more thought, can easily be a separate PR (which we could arguably say is non-breaking, while going the other way around and reverting the aggressive default would deifnitely be breaking). One counterpoint is that ForwardDiff.Dual <: Real
-- I would be interested in seeing if there's any practical use case where a quantity breaks the expected semantics of Real
. (Edit: I see there's some interesting discussion about this in PainterQubits/Unitful.jl#680)
Edit: one more thing -- conditional on the default type definition remaining, I do agree with the current PR decision to keep it as Number
rather than Real
.
Co-authored-by: Gaurav Arya <[email protected]>
Thanks! |
8205e49
to
d312e31
Compare
d312e31
to
50e3f2d
Compare
This adds a new
AbstractRealQuantity <: Real
and a concrete typeRealQuantity
. Users can wrap quantities withRealQuantity(0.3u"km/s")
to pass to functions that require real input. But the default would still beQuantity <: Number
for reasons discussed here.I also introduce a new function
promote_quantity
which one can overload as a sort of custom type hierarchy, so thatRealQuantity -> Quantity
if it interacts with a non-real, and{RealQuantity,Quantity} -> GenericQuantity
if they interact with non-numeric.However this is a bit of a mess right now due to promotion complexities, makingFixed!(0.3+2im)u"km/s"
promote to aComplex{<:Quantity}
instead of aQuantity
... Anybody interested in having a go?