Wrong matrix product with complex row major and ffast-math
Hi, the following code
#include <iostream>
#include <Eigen/Core>
using namespace Eigen;
using myMatrix=Matrix<std::complex<double>, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
int main(int argc, char* argv[]){
myMatrix mat = myMatrix::Random(2,2);
const auto m1 = mat.adjoint() * mat;
const myMatrix m2 = mat.adjoint() * mat;
std::cout << "m1 = \n" << m1 << std::endl;
std::cout << "m2 = \n" << m2 << std::endl;
std::cout << "diff=\n" << m1-m2 << std::endl;
}
gives wrong results (m1-m2 != 0) when compiled with
g++ -O3 -ffast-math
It works if -ffast-math is disabled. It also works for Eigen::ColMajor.
What I don't understand is that the wrong result also occurs when enabling MKL (-DEIGEN_USE_MKL_ALL).
Compiling the code with clang or with icpc (using -fast as option) does not lead to errors.
My g++ is
g++ (Arch Linux 9.2.1+20200130-2) 9.2.1 20200130
Copyright (C) 2019 Free Software Foundation, Inc.
I'm using Eigen commit a45d28256d020a4e871267c9bf00206fe9d2265e (Fri Jan 10, 2020)