incorrect reductions after reshaped()
Summary
I obtain incorrect reductions after reshaped()
Environment
- Operating System : Windows
- Architecture : x64
- Eigen Version : 3.4
- Compiler Version : MinGW64 / GCC12
- Compile Flags : -O3
-
- Vector Extension : Intel(R) Core(TM) i7-1065G7 CPU
Minimal Example
#include <iostream>
#include <Eigen/Dense>
using namespace std;
using namespace Eigen;
typedef Matrix< double, Dynamic, Dynamic, RowMajor> matrix;
int main(int argc, char** argv) {
int draws = 100;
int blocksize = draws / 10;
matrix input = matrix::Random(draws,3);
ArrayXXd blocks = input.col(0).reshaped(blocksize, 10);
cout << "blocks = " << endl << blocks << endl << endl;
cout << "ERROR: blockSums = " << input.col(0).reshaped(blocksize, 10).colwise().sum() << endl;
cout << "ERROR: blockMeans = " << input.col(0).reshaped(blocksize, 10).colwise().mean() << endl;
cout << "OK: blockSums = " << input.col(0).reshaped(blocksize, 10).eval().colwise().sum() << endl;
cout << "OK: blockMeans = " << input.col(0).reshaped(blocksize, 10).eval().colwise().mean() << endl;
}
What is the current bug behavior?
Reductions on the reshaped() view produce incorrect results.
What is the expected correct behavior?
I expected reductions on the reshaped() view to work without requiring an .eval(); error is difficult to track down.