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
WIP: Unitful arrays #191
base: master
Are you sure you want to change the base?
WIP: Unitful arrays #191
Conversation
Codecov Report
@@ Coverage Diff @@
## master #191 +/- ##
==========================================
- Coverage 74.65% 74.58% -0.08%
==========================================
Files 14 15 +1
Lines 947 968 +21
==========================================
+ Hits 707 722 +15
- Misses 240 246 +6
Continue to review full report at Codecov.
|
I recently started to encounter issues with arrays of Unitful values, and wanted to present one example. @cstjean, do you think this would be addressable? # fit a quadratic to three points, y = 5x^2 + 0.1, x in meters, y in seconds
using Unitful.DefaultSymbols
x = [0.0s 1.0s 2.0s]'
y = [0.2m 5.2m 20.2m]'
A = [x[1]^2 x[1]^1 x[1]^0
x[2]^2 x[2]^1 x[2]^0
x[3]^2 x[3]^1 x[3]^0]
# ideally, units would be calculated rather than assigned here
coeffs = ustrip.(A)\ustrip.(y) .* [m/s^2; m/s; m]
@assert all(ustrip.(abs.(coeffs - [5.0m/s^2; 0.0m/s; 0.2m])) .< 1.0e-12)
coeffs |
It's should be doable with another special array type, but this PR only supports units of the form
There might already be a package that generates arrays of the form your |
I believe that the datastructure is fine, but I am unhappy with everything else. My use case is with
StaticArrays
, and there doesn't seem to be a nice way of accommodating bothArray
andSArray
objects in the unit conversion routines. At least, not without also requiringStaticArrays
, and at that point, we should probably start a new package entirely. Suggestions are welcome.Update: it seems that there's a solution to this problem after all. To be implemented.
cc. @mschauer