-
Notifications
You must be signed in to change notification settings - Fork 25
Modifications for linear algebra #18
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
Not yet ready for merge. We might need:
|
Benchmark Results
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
Sparspak works with PetrKryslUCSD/Sparspak.jl#25 |
Base.:+(l::Quantity, r::Quantity) = Quantity(l.value + r.value, l.dimensions, l.valid && r.valid && l.dimensions == r.dimensions) | ||
Base.:-(l::Quantity, r::Quantity) = Quantity(l.value - r.value, l.dimensions, l.valid && r.valid && l.dimensions == r.dimensions) | ||
function Base.:+(l::Quantity, r::Quantity) | ||
if iszero(l) |
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.
Wouldn't you want a DimensionError to still be raised even if iszero
is true? If adding a 2D vector to a 3D vector, you would always want to raise an error, regardless of if one of them was zero, no?
It might not even be the case that iszero
is defined for all possible Quantity
, since the value of a Quantity
might be an abstract object, rather than just a scalar real
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.
The use case is that there are places where a value is initialized with zero, and than += or -= are used to add other quantities to it.
This can be solved also e.g. in Sparspak. But IMHO it this belongs to the algebraic properties of Quantity. What is zero
and what is one
?
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.
It looks like other unit packages also raise DimensionErrors even if the value is zero. e.g., astropy:
from astropy import units as u
q = 10 * u.m # 10 meters
q2 = 10 * u.s # 10 seconds
q * 0 + q2
# ^ Raises UnitConversionsError
likewise with Unitful.jl
julia> using Unitful
julia> 0.0u"m" + 10.0u"s"
ERROR: DimensionError: 0.0 m and 10.0 s are not dimensionally compatible.
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 "zero meters" + "one second" raising an error makes the most sense as a default? Thoughts?
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.
In Sparspak maybe you can do:
x = iszero(x) ? q : x + q
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 had it running like this, so for sparspak I certainly could switch to this. But sparspak may not be the only place where this functionality may be needed.
Fundamentally this leads to the question how units are working algebraically. I'll try to think more about it to find a less ad-hoc approach.
IMHO it would be good if DynamicQuantities could be used like Dual numbers, MultiFloats, Measurements and the like as a drop-in replacement for Float64.
But I am aware that this may be not everyone's version for this package.
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 even if there are a few additional packages that need this, it is better left out of the main package, because it will slow down every call to +
with 3x as many comparisons on the dimensions (i.e., rather than just dimension(l) == dimension(r)
, now it has to also compute dimension(l) == Dimensions()
and dimension(r) == Dimensions()
).
Not sure if this is relevant, but I've been experimenting with this "WildcardDimensionWrapper" type in SymbolicRegression.jl: https://github.com/MilesCranmer/SymbolicRegression.jl/blob/6ed49f166483ec130bc0350d69d6e2214666aeda/ext/SymbolicRegressionUnitfulExt.jl#L58-L69 It's basically a way of adding a regexp to a The way it works is as follows. Any free constant (here:
Any other operator, if undefined for |
Just got the following idea: DynamicalQuantities provides |
I think that’s a good idea — though perhaps just |
Possibly can be closed in favor of #24. |
Maybe we can put the |
I think most of these are superseded or already implemented now? Closing to clean the repo up |
Figure out what is needed to solve linear systems with dynamic quantities.