-
Notifications
You must be signed in to change notification settings - Fork 78
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
Ambiguous overload for 'operator*' (linear_algebra) #88
Comments
Both of the overloads are valid. From mp-units point of view From linear-algebra point of view Please note that I already did the best I could and introduced a As both overloads are valid which of those operators would you like to choose and why? How to deduce it in a generic way at compile time so it works with every library (not only with this particular LA one)? I think the only way to make it work is to define your own operators that will explicitly say on how to multiply those specific types based on your specific use case. |
I resolved this using 4 concepts (N.B not same semantics if similar named std versions) Firstly Numeric<T> which is basically floats and ints (though user defined like angles, rational etc also can be model). N.B Vectors ,Quantities are specifically not Numeric Second Quantity<T> which is physical quantity with Numeric valuetype Thirdly Scalar<T> which is basically Numeric + Quantities Fourth Vector<T> Multiply ops are defined on generic models of these concepts one one side angainst the particular user defined type on the other and unambiguous once so constrained myQuantity * Numeric -> myQuantity // defined by myQuantity library myVector * Scalar -> myVector // defined by myVector library Numeric<T> = false Numeric<int> = true; Scalar<T> = false; Scalar<Numeric> = true Vector<T> = false Vector<myVector> == true https://github.com/kwikius/quan-trunk/blob/master/quan/three_d/vect.hpp#L244 related |
If Scalar is defined as ! Quantity This is the problem. Every type needs to provide strong constraints on its operations to prevent wipeing out other types useful operations. Wikipedia has a good definition,: Scalar (physics), a physical quantity that can be described by a single element of a number field such as a real number |
Term "Scalar" definition depends on a domain. In maths it is the description you provided and this is the one used by the LA. In Physical Units domain a Scalar is not a quantity. Both definitions are and should be different (depending on a domain). When we talk about physical units a scalar can be any user-defined type that provides basic arithmetic operations (i.e. complex number or a vector or matrix). See the following example:
The above would be invalid with your overconstrained |
We could argue what Scalar means but it doesnt solve your problem ;) Surely this should 'just work' without any WrappedQuantity or other mischief? https://github.com/kwikius/units/blob/kwikius_vector_mul_q/example/linear_algebra.cpp#L269 At least it does work for me on Arduino. Nice and neat https://github.com/kwikius/ArduIMU/blob/master/ArduIMU/MPU6000.cpp#L173 The linear algebra lib operator function is entirely S2 unconstrained so Best to be explicit template<class ET1, class OT1, AnyType S2> But actually should be more constrained... |
Agree, if you have a better name for the "Scalar" term in a physical units domain please let me know. I cannot influence other libraries to constrain their operators. I can do everything with mine. For now, I found out that "WrappedQuantity" works well to disambiguate the case of There are 2 solutions here:
|
Sorry but those are not the only choices and this view is not just mine. See also here. See #23 (comment) And please re-read the excellent paper cited there about representing matrices which describes using quantities in matrices, since this https://github.com/mpusz/units/blob/82f493f9ceee08df9e5d589546fdf6ecef77d53a/example/linear_algebra.cpp#L158 is not how matrices work with quantities. The other choice reqarding a physical quantity type for c++ is to restrict the valuetype of the quantity to being a scalar type( According to the widely respected standard definitions https://en.wikipedia.org/wiki/Scalar) as I and https://github.com/dwith-ts said previously and then allow other libraries to provide the vector complex and matrix functionality. This relies on both mpusz/units and a linear algebra library being specified in terms of a common set of concepts, which surely is something that WG21 members understand and can agree on? Alternatively If you allow these types in the standard quantities library then you must also provide the full suite of operations if it is not to be a toy library For complex real imag arg trig array access. etc etc... which ultimately is wasted duplicated effort. My Library constrains its valuetypes to scalar types and works well. converting from a vector of numeric types is a basic op. Mpusz/units fails in a simple case as shown by this issue. |
I think I do not fully agree here.
There is more than one way to do it. I think that in case someone wants a matrix of a specific quantity type it is a valid use case. If I forbid it, I will have a new Issue opened soon by someone wanting such a use case to work. There are no good reasons to disallow it. Sure it can be optimized by the techniques described in the paper. Sure it does not work with matrices of different quantity types. But for this specific use case, it is fine.
I do not see anywhere in this document that Scalar is only an |
"_I do not see anywhere in this document that Scalar is only an I cannot find where I said that? I refer you to #88 (comment) para4 which specifically states that a quantity is a Scalar https://github.com/kwikius/quan-trunk/blob/master/quan/meta/is_scalar.hpp#L43 I also specifically made mpusz/units quantity a model here to work with my 2d 3d vector library In my library, a quantity is specifically a scalar type. I do however restrict to not allowing a quantity to have vector value_type because it causes confusion and ambiguous overloads exactly as pointed out in this issue. Vector is much better handles by its own library, but it needs to be able to work with quantity library, which one would assume might be a goal of WG21 meetings!
Again I refer you to the above link. I have not restricted Scalar to Int or Float. These types, measure, rational may be models of Numeric concept in which case they are also probably models of Scalar concept. |
matrix<R,C,T> wont work in most cases. You need matrix<R,C,T...> |
Does not reproduce in V2 anymore. |
The following code was compiled correctly:
But after one of the last updates, the compilation fails with the following error:
The text was updated successfully, but these errors were encountered: