Matrix power segfaults

Submitted by Dale Lukas Peterson

Assigned to Nobody

Link to original bugzilla bug (#614)
Version: 3.2
Operating system: Linux

Description

Created attachment 347
Matrix power segfaults for trivial 2x2 matrix.

The attached file demonstrates pow() segfaulting on trivial matrix powers. I am using g++ (Gentoo 4.7.3 p1.0, pie-0.5.5) 4.7.3. Not all powers segfault, for example A.pow(1.0) does not. When I run the debugger (after compiling with -ggdb3), and step through until it segfaults, I get the following backtrace:

~/tmp/c++/eigen$ gdb ./matrix_power
GNU gdb (Gentoo 7.6 p1) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
http://bugs.gentoo.org/...
Reading symbols from /home/hazelnusse/tmp/c++/eigen/matrix_power...done.

(gdb)   
(gdb) list  
1	// Compiled with:  
2	//  
3	// $ g++ -Wall matrix_power.cc -O2 -I/home/hazelnusse/usr/include/eigen3 -o matrix_power  
4	//  
5	#include <iostream>  
6	#include <Eigen/Dense>  
7	#include <unsupported/Eigen/MatrixFunctions>  
8	int main()  
9	{  
10	  Eigen::MatrixXcd A(2,2);  
(gdb) b main  
Breakpoint 1 at 0x401cd0: file matrix_power.cc, line 9.  
(gdb) run  
Starting program: /home/hazelnusse/tmp/c++/eigen/matrix_power   
warning: Could not load shared library symbols for linux-vdso.so.1.  
Do you need "set solib-search-path" or "set sysroot"?  
  
Breakpoint 1, main () at matrix_power.cc:9  
9	{  
(gdb) n  
10	  Eigen::MatrixXcd A(2,2);  
(gdb)   
9	{  
(gdb)   
10	  Eigen::MatrixXcd A(2,2);  
(gdb)   
11	  A << 1, 1, 4, -2;  
(gdb)   
20	  std::cout << A.pow(3.1) << "\n\n";  
(gdb) print A  
$1 = Eigen::Matrix<std::complex<double>,2,2,ColMajor> (data ptr: 0x632010) = {[0,0] = {_M_value = 1 + 0 * I}, [1,0] = {_M_value = 4 + 0 * I}, [0,1] = {_M_value = 1 + 0 * I}, [1,1] = {_M_value = -2 + 0 * I}}  
(gdb) n  
  
Program received signal SIGSEGV, Segmentation fault.  
0x00000000004068b7 in Eigen::MatrixPowerTriangularAtomic<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> >::compute2x2 (this=0x7fffffffd5d0,   
    res=Eigen::Matrix<std::complex<double>,0,0,ColMajor> (data ptr: 0x0), p=0.10000000000000009) at /home/hazelnusse/usr/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixPowerBase.h:330  
330	  res.coeffRef(0,0) = pow(m_A.coeff(0,0), p);  
(gdb) bt  
#0  0x00000000004068b7 in Eigen::MatrixPowerTriangularAtomic<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> >::compute2x2 (this=0x7fffffffd5d0,   
    res=Eigen::Matrix<std::complex<double>,0,0,ColMajor> (data ptr: 0x0), p=0.10000000000000009) at /home/hazelnusse/usr/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixPowerBase.h:330  
#1  0x00000000004165db in Eigen::MatrixPowerTriangularAtomic<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> >::compute (this=this@entry=0x7fffffffd5d0,   
    res=Eigen::Matrix<std::complex<double>,0,0,ColMajor> (data ptr: 0x0), p=0.10000000000000009) at /home/hazelnusse/usr/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixPowerBase.h:304  
#2  0x0000000000417432 in Eigen::MatrixPower<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> >::computeFracPower<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> > (this=this@entry=0x7fffffffd6e0,   
    res=Eigen::Matrix<std::complex<double>,2,2,ColMajor> (data ptr: 0x6320c0) = {...}, p=<optimized out>) at /home/hazelnusse/usr/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixPower.h:459  
#3  0x00000000004187ed in Eigen::MatrixPower<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> >::compute (this=this@entry=0x7fffffffd6e0,   
    res=Eigen::Matrix<std::complex<double>,2,2,ColMajor> (data ptr: 0x6320c0) = {...}, p=1.0717734625362931) at /home/hazelnusse/usr/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixPower.h:335  
#4  0x0000000000418919 in Eigen::MatrixPowerReturnValue<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> >::evalTo<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> > (  
    this=this@entry=0x7fffffffd8f0, res=Eigen::Matrix<std::complex<double>,2,2,ColMajor> (data ptr: 0x6320c0) = {...})  
    at /home/hazelnusse/usr/include/eigen3/unsupported/Eigen/src/MatrixFunctions/MatrixPower.h:511  
#5  0x00000000004189a6 in evalTo<Eigen::Matrix<std::complex<double>, -1, -1> > (dst=Eigen::Matrix<std::complex<double>,2,2,ColMajor> (data ptr: 0x6320c0) = {...}, this=0x7fffffffd8f0)  
    at /home/hazelnusse/usr/include/eigen3/Eigen/src/Core/ReturnByValue.h:61  
#6  Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1>::Matrix<Eigen::MatrixPowerReturnValue<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> > > (this=0x7fffffffd830, other=...)  
    at /home/hazelnusse/usr/include/eigen3/Eigen/src/Core/Matrix.h:296  
#7  0x0000000000418aaa in eval (this=0x7fffffffd8f0) at /home/hazelnusse/usr/include/eigen3/Eigen/src/Core/DenseBase.h:357  
#8  Eigen::operator<< <Eigen::ReturnByValue<Eigen::MatrixPowerReturnValue<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> > > > (s=..., m=...)  
    at /home/hazelnusse/usr/include/eigen3/Eigen/src/Core/IO.h:244  
#9  0x0000000000401de9 in main () at matrix_power.cc:20  
(gdb)   

I'm not sure how to proceed next...

Attachment 347, "Matrix power segfaults for trivial 2x2 matrix.":
matrix_power.cc

Blocking

#387 (closed)

Edited by Eigen Bugzilla