Skip to content

Map<>.noalias() = A * B triggers memory allocation

Submitted by Chris Dyer

Assigned to Nobody

Link to original bugzilla bug (#1012)
Version: 3.2
Operating system: Other UNIX-like

Description

It seems that noalias() doesn't behave properly with Map<>ed matrices. (However, while this is broken in the current release -- 3.2.4 -- it appears to have been corrected in the development repository, so I'm working around it by using this.)

Here is some repro code:

#define EIGEN_NO_MALLOC
#include <Eigen/Eigen>
#include <cstdlib>

int main() {
using namespace Eigen;
float* a = (float*)malloc(10 * 10 * sizeof(float));
float* b = (float*)malloc(10 * 10 * sizeof(float));
float* c = (float*)malloc(10 * 10 * sizeof(float));
Map<MatrixXf> ma(a, 10, 10);
Map<MatrixXf> mb(b, 10, 10);
Map<MatrixXf> mc(c, 10, 10);
mc.noalias() = ma * mb; // fails with 3.2.4, succeeds with dev
mc.noalias() += ma * mb; // fails with 3.2.4, succeeds with dev
}

Here is my compiler info:
$ g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix

Edited by Eigen Bugzilla