简体   繁体   中英

Eigen complex matrix-vector multiplication

I have these Eigen complex matrices:

Eigen::MatrixXcd matrix;
Eigen::VectorXcd rhs;
Eigen::VectorXcd solution;

I can successfully load values and compute the solution, but if I try:

rhs = matrix*solution;

I get compiler errors related to overloaded "+=" operator and double/complex conversion in Eigen files GeneralProduct.h and CxRealAbs.h

Similar issues with trying to compute a residual.

Is there an

Help ??

thanks

Kevin

According to their documentation, Eigen checks the validity of operations:

Validity of operations Eigen checks the validity of the operations that you perform. When possible, it checks them at compile-time, producing compilation errors. These error messages can be long and ugly, but Eigen writes the important message in UPPERCASE_LETTERS_SO_IT_STANDS_OUT. For example:

 Matrix3f m; Vector4f v; v = m*v; // Compile-time error: YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES

Of course, in many cases, for example when checking dynamic sizes, the check cannot be performed at compile time. Eigen then uses runtime assertions. This means that the program will abort with an error message when executing an illegal operation if it is run in "debug mode", and it will probably crash if assertions are turned off.

 MatrixXf m(3,3); VectorXf v(4); v = m * v; // Run-time assertion failure here: "invalid matrix product"

Eigen

Your RHS is a vector and you are trying to assign it a value or set of values from a matrix and vector product. Even from a mathematical perspective, you should ask yourself if this is a valid type of operation.

Consider that M and N are matrices and A & B are vectors what are the results of the following operations:

M = AB // Cross product and not a dot product
M = AM, MA, BM, MB // yields a transformed matrix using the original matrix
M = AN, NA, BN, NB // yields a transformed matrix using a supplied matrix

A = AA, AB, BA // cross product and not the dot product

A = AM, MA, AN, NA, BM, MB, BN, NB // yields what? 

So within Eigen at compile time it is checking the validity of your operators and therefore it is giving you the compile-time error that the += is not defined and that you have not provided an overloaded version of one. It simply doesn't know how to perform the intended operation. It shouldn't matter what the underlying type of the matrix and vector classes are. It pertains to the fact that the operators you are trying to perform are not defined somewhere.


Edit

Here is a link that describes matrix and vector multiplication. Intuitively we would assume that this yields a vector, however, this is implicitly understood, but from a matrix perspective, this vector can be row or column such that the returned vector could either be a 1xM or a Mx1 matrix.

Here is a link to show the different interpretations even though they will return the same result: This can be found in section 3.2.3 of the documentation: Maxtrix-Vector Product

The number of operations between the two different interpretations varies although they provide the same final result. Without explicitly stating if it should be a row or column product this could lead to some type of ambiguity. I don't know how Eigen determines which method it would use, I would assume that it would choose the one with the fewest operations with the least amount of computations.

This isn't the main issue of your problem. At the end of the day, the compiler is still generating an error message that an overloaded operator is not being defined. I don't know where this is coming from within your code. So this could be within their library itself when trying to perform the operations on their version of the Complex types. Without being able to run and compile your full source code I can not easily determine what exactly is generating this compiler error and I also don't know what compiler you are using that is generating your errors.

The problem was mine. I had overloaded the *operator for std::complex * real because some earlier versions of std were incomplete. The first error listed was into Eigen, which led me astray.

GeneralProduct.h(287): no viable overloaded '+='

CxRealAbs.h(111): cannot convert 'const Eigen::Map, -1, 1, 0, -1, 1>, 1, Eigen::Stride<0, 0> >' to 'double' without a conversion

Remove my overload and it compiles and runs ok. No problem with Eigen dynamic matrices.

thanks for the replies.

Kevin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM