PainterQubits / Unitful.jl

Physical quantities with arbitrary units
Other
612 stars 112 forks source link

Congratulations to Unitful! #302

Closed timholy closed 4 years ago

timholy commented 4 years ago

Happy first birthday!

ajkeller34 commented 4 years ago

This brought a smile to my face 😄

cstjean commented 4 years ago

For our work in industrial engineering, it's been absolutely fantastic, thank you for making it so pleasant to use!

timholy commented 4 years ago

Agreed, Unitful is a major selling point for Julia itself.

Speaking of, I've been idly contemplating a package for unitful matrix operations. For example, if A is a matrix and you want to multiply a vector with it, A[i,j] must have units u[i]*v[j] where u and v are vectors of units. And of course if A*x is going to make sense then x has to have appropriate units of its own. There are even factorizations that have sensible units, e.g., for Cholesky factorization A = L*L', A must have units u*u' and L should have units of u*1'. It also helps one realize that other operations can't be defined except under special circumstances; for example, did you know that "real" Hessian matrices (ones with physical units) don't have ordinary eigenvalues? That's because the equation A*x = λx only makes sense if A has units propotional to u .* (1./u'), e.g., similar to a coordinate transformation but definitely not a Hessian. (Hessians do have generalized eigenvalues A*x = λ*B*x given suitable B.)

Would anyone else find this useful? It seems like it could be a fair amount of work and I'm still not sure how genuinely useful it would be. To handle both large and small arrays one might need both UnitfulStaticArrays and UnitfulLinearAlgebra, where the former is fully inferrable and stores its units in a tuple, whereas the latter would use a Vector{Any} and thus be non-inferrable. That might make it not terribly useful in practice.

cstjean commented 4 years ago

I wanted to do Kalman filtering with units, and I spent a while working on exactly that: https://github.com/PainterQubits/Unitful.jl/pull/191 . It seemed viable, I just couldn't really justify pushing it forward given our priorities. I'd be happy to contribute to the extent time allows if you want to start afresh.

I realized belatedly that if the likelihood P(x1|theta) with one data point has units m^-1, then the likelihood with N datapoints has units m^-N, which is obviously problematic. It was a downer for our application.

giordano commented 4 years ago

Given Julia's tendency of easily combining different packages and data structures with no effort it's a bit unfortunate that we'd need something special like a UnitfulArray, but yeah, linear algebra operations don't seem to be very units-aware: #46

ajkeller34 commented 4 years ago

I'm a little late to the conversation, but as much as I'd like to see a unitful matrix package, I've never found myself completely blocked by its absence. If I had some free time and greater skill, I think I would instead invest in contributing to a Julia rewrite of a linear algebra or sparse matrix library.