GeneralizedEigenSolver::alphas and betas return copy instead of reference
Summary
GeneralizedEigenSolver::alphas() and betas() is documented to return a const reference, but in fact copies the underlying arrays (in the source code here). I discovered this when trying to minimize allocations based on this guide.
Environment
- Operating System : macOS
- Architecture : Arm64
- Eigen Version : 3.4.0
- Compiler Version : Apple clang version 13.0.0 (clang-1300.0.29.30)
- Vector Extension : None enabled
Minimal Example
#define EIGEN_RUNTIME_NO_MALLOC
#include <Eigen/Dense>
using namespace Eigen;
int main() {
GeneralizedEigenSolver<MatrixXf> ges;
MatrixXf A = MatrixXf::Random(4,4);
MatrixXf B = MatrixXf::Random(4,4);
ges.compute(A, B);
Eigen::internal::set_is_malloc_allowed(false);
const auto& alphas = ges.alphas();
const auto& betas = ges.betas();
return 0;
}
Steps to reproduce
- Run the code above
- Notice that it throws an assertion error
What is the current bug behavior?
Arrays are copied, which violates the set_is_malloc_allowed(false) configuration
What is the expected correct behavior?
Return a const reference, like the docstring suggests.
Other notes
I'm happy to open a PR if the fix is as simple as returning const ComplexVectorType& / const VectorType&.