Skip to content
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

Vector quantities with units #439

Open
correaa opened this issue Feb 17, 2023 · 7 comments
Open

Vector quantities with units #439

correaa opened this issue Feb 17, 2023 · 7 comments
Labels
design Design-related discussion high priority EXTRA URGENT
Milestone

Comments

@correaa
Copy link

correaa commented Feb 17, 2023

Do you have any strategy or plans to support units for vectors? (Let's say non-dynamically sized vectors.)
For example, I have a position in 3D space that can be in Angstroms or Bohr units (or meters and inches).

Have you put some thought into it?

I know the question is tricky because it is not the vector components or the vector as a whole that carries the units but the "metric tensor", but still.

I find the approach in https://www.youtube.com/watch?v=J6H9CwzynoQ [Daniel Withopf - Physical Units for Matrices] overly complicated, but perhaps it is unavoidable to do it that way.

@dwith-ts
Copy link

If you want to use uniform vectors where each entry has the same physical unit then there are easier solutions, the V1 doc contained code examples for this, not sure if they are still part of the documentation.

@mpusz
Copy link
Owner

mpusz commented Feb 17, 2023

As @dwith-ts mentioned, in cases where all quantities in the vector/matrix store the same type, then it works nicely already. See https://mpusz.github.io/units/use_cases/linear_algebra.html. It gets tricky when you want to use various types in a matrix (i.e. kalman filters), but this is a limitation of the LA library and not mp-units. In such cases, an additional level of abstraction will be needed as mentioned by Daniel Withopf in his talk.

@mpusz
Copy link
Owner

mpusz commented Feb 17, 2023

I also plan to provide examples with BLAS-based LA and SIMD which both were proposed for standardization recently.

@correaa
Copy link
Author

correaa commented Feb 17, 2023

Yes, I think you can get away with components-as-quantities for vectors, (which might also imply "cartesian", BTW).
But for matrices (and higher rank tensors) it is not possible to use this trick, I think.

Also, I am hesitant about the implicit equivalency (ambiguity?) between components-as-quantities and vector-as-quantity:
e.g. {1*meter, 2*meter}[0] == ({1,2}*meter)[0]
(I know that the RHS probably doesn't compile, but you get the point, even this issue of indexing opens a can of worms).

I have my own library for arrays (dynamic, arbitrary static dimension), https://gitlab.com/correaa/boost-multi.
I wonder how I have to generalize my container class to support some kind of units.
Since I purposely left linear algebra out, I think I probably shouldn't do anything, because, after all, any implicit connection between arrays and units is "through" linear algebra.

Any feedback is welcome, BTW.

In any case, I expect it to be used as a backend (representation) of linear algebra, I want it to be compatible with linear algebra applications (and also with units).
On these lines, I gave some feedback to the linear algebra proposal already based on the experience with my library, BobSteagall/wg21#74.

@mpusz
Copy link
Owner

mpusz commented Feb 17, 2023

Also, I am hesitant about the implicit equivalency (ambiguity?) between components-as-quantities and vector-as-quantity:
e.g. {1meter, 2meter}[0] == ({1,2}*meter)[0].

I think we might support such an equivalency. Please note that ISO 80000-2 explicitly states:

Instead of treating each coordinate of a vector as a physical quantity value (i.e. a number multiplied by
a unit), the vector could be written as a numerical vector multiplied by a unit. All units are scalars.

EXAMPLE Force acting on a given particle, e.g. in Cartesian components (Fx; Fy; Fz) = (−31,5; 43,2; 17,0) N.

@correaa
Copy link
Author

correaa commented Feb 17, 2023

I think we might support such an equivalency.

That would be a bold move, indeed.

It probably makes sense because, in linear algebra, indexing can be seen as a linear operator.
Same logic as why units pertain to multiplication and addition, and now indexing(?).

I tried to hack Boost.Units to make that work, but I think I gave up.

I hope it goes well. ... and that it doesn't open a can of worms (e.g., what if operator[] is not semantically indexing or not an "orthogonal" decomposition?, or should operator() be supported? :) , (cos*meter)(1.2) == cos(1.2)*meter 🤡 )

Please note that ISO 80000-2 explicitly states:

You are taking this seriously. 👍
Nice to see that.

Instead of treating each coordinate of a vector as a physical quantity value (i.e., a number multiplied by
a unit), the vector could be written as a numerical vector multiplied by a unit. All units are scalars.

EXAMPLE Force acting on a given particle, e.g., in Cartesian components (Fx; Fy; Fz) = (−31,5; 43,2; 17,0) N.

Interesting, I do that all the time, of course, but I didn't know I was allowed by ISO. (Indeed, using units over vectors/components implies cartesian components, in contrast to components on a non-orthogonal basis.)

I guess it is risky to take ISO as a source of mathematical knowledge (mathematics by committee?), but it does point in a reasonable direction in this case.

@dwith-ts
Copy link

The equivalency only makes sense for uniform vectors. As soon as we have non-uniformity it will no longer work.

This also shows that this is not a mathematical relationship in the general case, it is merely a notational convenience for this special case.

@mpusz mpusz added the design Design-related discussion label Jun 24, 2023
@mpusz mpusz added the high priority EXTRA URGENT label Feb 28, 2024
@mpusz mpusz added this to the v2.4.0 milestone Jun 22, 2024
@mpusz mpusz modified the milestones: v2.4.0, v2.5.0 Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design-related discussion high priority EXTRA URGENT
Projects
None yet
Development

No branches or pull requests

3 participants