-
Notifications
You must be signed in to change notification settings - Fork 25
Refactor symbolic units module, make all symbols available at import #101
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
Conversation
Benchmark Results
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
@gaurav-arya I wonder if there are any type instabilities that could potentially come from this...? Although the promotion rules seem to be doing their job: julia> [km]
1-element Vector{Quantity{Float64, SymbolicDimensionsSingleton{DynamicQuantities.FixedRational{Int32, 25200}}}}:
1.0 km
julia> [km, km/h]
2-element Vector{Quantity{Float64, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}:
1.0 km
1.0 km h⁻¹
julia> [km, km/h, uexpand(km)]
3-element Vector{Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}:
1000.0 m
0.2777777777777778 m s⁻¹
1000.0 m I guess you could create an instability if you do something like |
It'll take me a bit of time since I'm not quite done with school yet, but I'll give this a review:) |
Thanks very much for the suggestions @devmotion. Everything implemented! |
Let me know if there are any other comments! Otherwise I will try to merge this soon. |
- Now eagerly creates symbolic units as immutable objects, rather than at first call - This uses a new type `SymbolicDimensionsSingleton` that stores a single dimension - Exports `SymbolicUnits` and `SymbolicConstants` for direct imports
Co-authored-by: David Widmann <[email protected]>
196d427
to
fb5e340
Compare
Previously, units were created the first time the user used
sym_uparse
, because otherwise it required creating ~150 arrays at import inside an@eval
. This also means that you could not precompile unit calculations done with symbolic units.With this change, we now eagerly create symbolic units as immutable objects. For example,
h
would be created withand this would represented in memory as the lightweight
(1.0, 85)
, where85
is the index ofhours
in the constant tuple of units and quantities.AbstractSymbolicDimensions <: AbstractDimensions
and defines several of the symbolic dimensions methods on it.SymbolicDimensionsSingleton
that stores a single integer corresponding to the index of the unit/constant in a constant tuple.SymbolicUnits
andSymbolicConstants
, so you can do things like:@devmotion would you be up for reviewing this?
cc @gaurav-arya
Fixes #51 by cadojo (and prevents the need for #58)