This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 523

Summary: Segfault in sqrt of VectorXd created from Diagonal
Product: Eigen Reporter: Clark <rich.dick.clark>
Component: CholeskyAssignee: Nobody <eigen.nobody>
Status: RESOLVED DUPLICATE    
Severity: major CC: gael.guennebaud
Priority: Normal    
Version: 3.1   
Hardware: x86 - 64-bit   
OS: Linux   
Whiteboard:

Description Clark 2012-10-20 06:52:36 UTC
The following code produces a segfault on the call to sqrt(D):


// Linear algebra library eigen http://eigen.tuxfamily.org
#include <Eigen/Dense>
#include <Eigen/Cholesky>

#include <iostream>
using namespace std;

int main( )  // return L where L*L'=A
{
    Eigen::MatrixXd P(2,2);
    P << 2.0, 1.0, 
         1.0, 3.0;
    
    cerr << "   BEGIN Eigen::LDLT(P)" << endl;
    // LDLT handles semidefinite matrices, unlike LLT
    Eigen::LDLT<Eigen::MatrixXd> cholesky(P);
    cerr << "   END   Eigen::LDLT(P)" << endl; 
    cerr << "   BEGIN Eigen::MatrixXd L(cholesky.matrixL());" << endl;
    Eigen::MatrixXd L(cholesky.matrixL());
    cerr << "   END   Eigen::MatrixXd L(cholesky.matrixL());" << endl;
    cerr << "   BEGIN Eigen::VectorXd D(cholesky.vectorD());" << endl;
    Eigen::VectorXd D(cholesky.vectorD());
    cerr << "   END   Eigen::VectorXd D(cholesky.vectorD());" << endl;
    cerr << "   BEGIN sqrt(D)" << endl;
    Eigen::VectorXd Dsr = sqrt(D); // !!!!SEGFAULT HAPPENS HERE!!!!
    cerr << "   END   sqrt(D)" << endl;
    Eigen::MatrixXd Psr = cholesky.transpositionsP().transpose() * L * Dsr.asDiagonal();            

    return 0;
}
Comment 1 Gael Guennebaud 2012-10-24 10:26:46 UTC
This should not compile at all, we are fixing this issue. Please use:

D.cwiseSqrt() or D.array().sqrt()

*** This bug has been marked as a duplicate of bug 314 ***
Comment 2 Nobody 2019-12-04 11:56:14 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/523.