BDCSVD::compute calls Matrix copy constructor when passed a Map

Summary

Passing a Map<MatrixXf> as input argument to BDCSVD::compute calls the Matrix copy constructor on the input instead of reading the values directly from the Map.

This seems an unnecessary copy that can be problematic for big matrices or if one wants to avoid dynamic memory allocation.

Environment

  • Operating System : Windows
  • Architecture : x64
  • Eigen Version : 3.4.90 ( 5e4f3475)
  • Compiler Version : MSVC 19.40.33811.0
  • Compile Flags : /Od

Minimal Example

float arr[4];
for (int i = 0; i < 4; i++)
    arr[i] = (float) i;
Eigen::Map<Eigen::MatrixXf> arrMap (arr, 2, 2);
Eigen::BDCSVD<Eigen::MatrixXf> svd (2, 2);
svd.compute (arrMap); // allocates

Steps to reproduce

  1. Construct BDCSVD with memory preallocation.
  2. Construct a Map<MatrixXf>.
  3. Call BDCSVD::compute with the Map as an argument.

What is the current bug behavior?

The Matrix copy constructor is called on the input argument.

What is the expected correct behavior?

BDCSVD::compute reads the data directly from the Map, avoiding an unnecessary copy.