Aliasing detected while no alias actually occurs
Submitted by tar..@..ok.com
Assigned to Nobody
Link to original bugzilla bug (#1646)
Version: 3.3 (current stable)
Description
Here is my environment information although I don't think this bug is related to this:
OS: Windows 10 (17763) x64
Compiler: Visual Studio 2017
Eigen: 3.3.7
Take the following code for example (I am aware that SelfAdointView can achieve the same thing; it is just an example):
int n = 100;
MatrixXd A = MatrixXd::Random(n, n);
for (int j = 1; j < n; ++j) {
A.col(j).head(j) = A.row(j).head(j);
}
std::cout << (A - A.adjoint()).norm() << std::endl;
Running this code in debug mode, I got the assertion failure:
Assertion failed: (!check_transpose_aliasing_run_time_selector <typename Derived::Scalar,blas_traits<Derived>::IsTransposed,OtherDerived> ::run(extract_data(dst), other)) && "aliasing detected during transposition, use transposeInPlace() " "or evaluate the rhs into a temporary using .eval()", file path\to\eigen\src\core\transpose.h, line 378
Apparently A.col(j).head(j) and A.row(j).head(j) does not share the same memory. It makes no sense to evaluate the rhs into a temporary. Also, if the code is compiled in release mode (with NDEBUG defined), the code runs perfectly.
I find out that changing this code to
A.col(j).head(j).noalias() = A.row(j).head(j);
does not help. But
A.col(j).head(j) = A.row(j).adjoint().head(j);
works fine.
I have no idea when the assertion will be triggered. Do I have a way to explicitly disable it? I am very sure that aliasing does not occur.