【问题标题】:C++ armadillo princomp() segmentation faultC ++犰狳princomp()分段错误
【发布时间】:2014-11-09 09:27:16
【问题描述】:

我正在运行如下代码:

#define ARMA_64BIT_WORD
#include <iostream>
#include </usr/include/armadillo>
using namespace arma;
typedef Mat<float> fmat;
typedef Col<float> fvec;

int main (int argc, char** argv)
{

    fmat A;
    A.load("matrix.txt");
    fmat coeff;
    fmat score;
    fvec latent;
    fvec tsquared;

    princomp(coeff, score, latent, tsquared, A);
 return 0;
 }

其中 matrix.txt 包含一个 2×46341(2 行,46341 列)矩阵。 它运行良好,但是当我将矩阵增加到 2×46342(2 行,46342 列)时, 发生了分段错误(核心转储)。

对列数有任何限制或限制吗? 或者,我写错了吗?

我在 Ubuntu 12.04.4 LTS (GNU/Linux 3.2.0-40-virtual x86_64) 中运行,Menmory:16GB

谢谢!

【问题讨论】:

    标签: c++ matrix segmentation-fault pca armadillo


    【解决方案1】:

    princomp() 将计算在您的情况下大小为 46342x43642 的协方差矩阵 (X' * X)。它的大小为 16.001 GB,而您只有 16 GB。因此失败了。

    如果您使用调试符号(或没有 -DNDEBUG 或类似符号)进行编译,则应显示实际的内存分配失败。

    我无法推荐任何其他解决方案,因为我不知道您要解决什么问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多