mpusz / mp-units

The quantities and units library for C++
https://mpusz.github.io/mp-units/
MIT License
997 stars 79 forks source link

[request] Example using Eigen #301

Open rconde01 opened 2 years ago

rconde01 commented 2 years ago

The documentation says this "Even though mp-units library does not implement any Linear Algebra types it is generic enough to be used with other Linear Algebra libraries existing on the market.". A set of examples using Eigen would be helpful. Blaze would probably be good too, but personally I don't use it so it's a lower priority for me.

mpusz commented 2 years ago

Sure, I do not have any experience with Eigen so if you can contribute some examples it would be great. For now, we only have examples basing on the Linear Algebra proposal for C++ (https://mpusz.github.io/units/use_cases/linear_algebra.html).

dwith-ts commented 2 years ago

For Eigen, full support for (uniform) physical units / quantities as scalar type is not working out of the box, it seems you have to define several traits for multiplications. https://stackoverflow.com/questions/43477416/custom-type-matrix-int-in-eigen

Even with this, multiplication is not possible as the resulting scalar type is not identical to the input types. For getting multiplication working, full automatic return type deduction would be needed which is not supported in Eigen as far as I know.

Your question was mainly asking for a solution for the simple(r) case of uniform units in vector, so I am not sure whether my talk on a full-blown solution is interesting for you. I’ll mention it anyways: https://m.youtube.com/watch?v=J6H9CwzynoQ