-
Notifications
You must be signed in to change notification settings - Fork 25
Remove SparseArrays dependency #56
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. |
Nice work!! Really appreciate your effort on this. It will take me a bit longer to read through this one but I'll try to get to it soon. |
I'm wondering (maybe I missed it) if there could be some e.g., each operation on SymbolicDimensions could end with something like remove_zeros(v) = filter!(e->!iszero(e), v) (but adapted to the two vector version). I'm not sure where in the operations SparseArrays performs this. Edit: wait, it seems like you do this at the stage of creating a new vector (by simply not pushing zeros), so its fine? |
When performing multiplications and divisions (i.e., addition and subtraction of dimensions) only non-zero dimensions of the result are stored. Similarly, when constructing |
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.
Initial suggestions to change UInt8 to UInt16, and also make that type a global constant for ensuring consistency.
Co-authored-by: Miles Cranmer <[email protected]>
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.
I think everything is looking good. The one thing remaining is adding some unittests to ensure coverage over all the modifications. In particular it looks like all the branches of ==
do not get tested by the current tests (green/red column to the left of code):

which would be good to ensure we test extensively enough, since it is a custom sparse array type. Also, some of the utility functions are not currently tested:

which would be good to add as well.
I added more tests that should improve coverage. |
One more TODO item (I think the last one, we're almost done) is to benchmark QuantityArray broadcasting for SymbolicDimensions. I am curious to see if the compiler inlining on the |
Awesome. I have no idea how, but this PR makes the broadcasting on SymbolicDimensions ~18x as fast as it was before! Before: julia> f(v) = v^2 * 1.5;
julia> @btime $f.(qa) setup=(xa = randn(10000) .* us"km/s"; qa = QuantityArray(xa));
17.795 ms (160019 allocations: 13.05 MiB) after: julia> @btime $f.(qa) setup=(xa = randn(10000) .* us"km/s"; qa = QuantityArray(xa));
1.053 ms (40007 allocations: 2.06 MiB) (Still several orders of magnitude slower than with normal Also, I went ahead and fixed the bug I noted here. |
Hm, I found another bug: > convert(Quantity{Float64,SymbolicDimensions}, u"kg")
1.0 not sure why this happens. |
abf8f89
to
0bcc134
Compare
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.
Cheers for the awesome contribution @devmotion!! 🎉🎉
This PR removes the SparseArrays dependency completely.
Only the implementation of
==
and+
/-
required a bit more code, otherwise not too many changes were needed.Fixes #53.