本征乘法悬挂

时间:2018-07-04 16:25:15

标签: c++ eigen eigen3

这是有问题的功能(在我的调试尝试中进行了一些修改):

// note: using MatrixX = Eigen::MatrixXd;
VectorX Foo::bar(const MatrixX &mat,
                                                const VectorX &b,
                                                const MatrixX &D,
                                                MatrixX &cov,
                                                double *chisq,
                                                double *cond)
{
    std::cout << "size of the matrices...." << std::endl;
    std::cout << "D row/col: " << D.rows() << '/' << D.cols() << std::endl;
    std::cout << "mat row/col: " << mat.rows() << '/' << mat.cols() << std::endl;
    std::cout << "D: " << std::endl;
    std::cout << D << std::endl;
    std::cout << "mat: " << std::endl;
    std::cout << mat << std::endl;
    std::cout << "And A = D*mat:" << std::endl;
    MatrixX A = D * mat;
    std::cout << A << std::endl;

    return {}; // of course we do more here but to make debugging easier yknow...
}

发生了什么事?最后一个提示从未显示。 当然,您会说矩阵大小必须不兼容,当然,我希望它是如此简单:

size of the matrices....
D row/col: 4/4
mat row/col: 4/3
D: 
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
mat: 
        -1          0  0.0377692
        -0         -1  -0.218875
 -0.958009 -0.0190212  -0.292296
  0.148245  -0.896453  -0.473009
And A = D*mat:
^C

因此,应将A计算为4 * 3矩阵。

我试图用下面这段简单的代码来重现这一点:

#include <eigen3/Eigen/Eigen>
#include <iostream>

using M = Eigen::MatrixXd;

void stupid_piece_of_shit(M const &mat, M const &D_)
{
    M A_ = D_ * mat;
    std::cout << A_ << std::endl; // making sure A_ is actually evaluated
}

int main(int argc, char *argv[])
{
    auto mat = M(4, 3);
    auto D_ = M(4, 4);

    mat << -1, 0, 0.0377692,
        -0, -1, -0.218875,
        -0.958009, -0.0190212, -0.292296,
        0.148245, -0.896453, -0.473009;

    D_ << 1, 0, 0, 0,
        0, 1, 0, 0,
        0, 0, 1, 0,
        0, 0, 0, 1;

    wat(mat, D_);
    return 0;
}

当然该示例可以很好地工作。

所以我在程序挂起时用gdb ^ C来运行它,然后得到了回溯:

Thread 1 "foo" received signal SIGINT, Interrupt.
0x00007ffff6fa2be3 in Eigen::internal::gebp_kernel<double, double, long, Eigen::internal::blas_data_mapper<double, long, 0, 0>, 4, 4, false, false>::operator()(Eigen::internal::blas_data_mapper<double, long
, 0, 0> const&, double const*, double const*, long, long, long, double, long, long, long, long) () from blabla

(gdb) bt
#0  0x00007ffff6fa2be3 in Eigen::internal::gebp_kernel<double, double, long, Eigen::internal::blas_data_mapper<double, long, 0, 0>, 4, 4, false, false>::operator()(Eigen::internal::blas_data_mapper<double,
long, 0, 0> const&, double const*, double const*, long, long, long, double, long, long, long, long) () from blabla.so

#1  0x00007ffff6fa8c83 in Eigen::internal::general_matrix_matrix_product<long, double, 0, false, double, 0, false, 0>::run(long, long, long, double const*, long, double const*, long, double*, long, double,
Eigen::internal::level3_blocking<double, double>&, Eigen::internal::GemmParallelInfo<long>*) () from blabla.so

#2  0x00007fffcdfb2002 in Eigen::internal::gemm_functor<double, long, Eigen::internal::general_matrix_matrix_product<long, double, 0, false, double, 0, false, 0>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, E
igen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::internal::gemm_blocking_space<0, double, double, -1, -1, -1, 1, false> >::operator() (this=0x7fffffff9f50, row=0, ro
ws=4, col=0, cols=3, info=0x0) at project/3rdparty/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix.h:223

#3  0x00007fffcdfb11d6 in Eigen::internal::parallelize_gemm<true, Eigen::internal::gemm_functor<double, long, Eigen::internal::general_matrix_matrix_product<long, double, 0, false, double, 0, false, 0>, Eig
en::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::internal::gemm_blocking_space<0, double, double, -1, -1, -1, 1, false> >, lo
ng> (func=..., rows=4, cols=3, transpose=false) at project/3rdparty/eigen3/Eigen/src/Core/products/Parallelizer.h:96

#4  0x00007fffcdfb1074 in Eigen::GeneralProduct<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, 5>::scaleAndAddTo<Eigen::Matrix<double, -1, -1, 0, -1, -1> > (this=0x7ffff
fffa770, dst=Eigen::Matrix<double,4,3,ColMajor> (data ptr: 0x161b3000) = {...}, alpha=@0x7fffffffa048: 1) at project/3rdparty/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix.h:
427

#5  0x00007fffcdfb0e20 in Eigen::ProductBase<Eigen::GeneralProduct<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, 5>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Ma
trix<double, -1, -1, 0, -1, -1> >::scaleAndAddTo<Eigen::Matrix<double, -1, -1, 0, -1, -1> > (this=0x7fffffffa770, dst=Eigen::Matrix<double,4,3,ColMajor> (data ptr: 0x161b3000) = {...}, alpha=@0x7fffffffa048
: 1) at project/3rdparty/eigen3/Eigen/src/Core/ProductBase.h:118

#6  0x00007fffcdfb0db6 in Eigen::ProductBase<Eigen::GeneralProduct<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, 5>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Ma
trix<double, -1, -1, 0, -1, -1> >::evalTo<Eigen::Matrix<double, -1, -1, 0, -1, -1> > (this=0x7fffffffa770, dst=Eigen::Matrix<double,4,3,ColMajor> (data ptr: 0x161b3000) = {...}) at project/3rdparty/eigen3/Eigen/src/Core/ProductBase.h:109

#7  0x00007fffcdf7c4ea in Eigen::ProductBase<Eigen::GeneralProduct<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, 5>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Ma
trix<double, -1, -1, 0, -1, -1> >::operator Eigen::Matrix<double, -1, -1, 0, -1, -1> const& (this=0x7fffffffa770) at project/3rdparty/eigen3/Eigen/src/Core/ProductBase.h:127

#8  0x00007fffcdf79cd7 in Bar::bar2 (mat=Eigen::Matrix<double,4,3,ColMajor> (data ptr: 0x1528cdc0) = {...}, b=Eigen::Matrix<double,4,1,ColMajor> (data ptr: 0x1513e5b0) = {...}, D=Eigen::Matri
x<double,4,4,ColMajor> (data ptr: 0x16172b20) = {...}, cov=Eigen::Matrix<double,3,3,ColMajor> (data ptr: 0x161b8400) = {...}, chisq=0x7fffffffa968, cond=0x7fffffffa960) at project
somefile.cpp

#9  0x00007fffcdf79906 in Bar::bar (poses=std::vector of length 2, capacity 2 = {...}, image_points=std::vector of length 2, capacity 2 = {...}, point_3d_W=Eigen::Matrix<doubl
e,3,1,ColMajor> (data ptr: 0x7fffffffc320) = {...}, covariance_W=Eigen::Matrix<double,3,3,ColMajor> (data ptr: 0x7fffffffc338) = {...}) at somefile2.cpp

#10 0x000000000041d10e in main (argc=1, argv=0x7fffffffd9c8) at project/applications/bar/src/main.cpp:376

更多详细信息:

  • 程序挂起时,CPU使用率为100%
  • 该代码在Windows(VC 14)上运行正常(根据我的同事)
  • clang和gcc都遇到了问题
  • 作为参数传递的矩阵是在堆栈上声明的(不是来自struct的 ),因此它不应该是一些奇怪的分配器问题

我明天将尝试进入Eigen调用堆栈,查找正在发生的事情,但是从我看到的结果来看,这很容易 (而且gdb不会加载Eigen :: internal一些理由)。因此,如果有人对这个非常奇怪的问题有指示/解决方案,那么……谢谢您使我的星期四变得更好

0 个答案:

没有答案