具有特征大稀疏矩阵的OOM?

问题描述 投票:0回答:2

我用eigen测试SparseMatrix,似乎当我新建一个只包含几个非零元素的10 * 50亿SparseMatrix时,需要50gb的内存!

演示代码:

#include <Eigen/Core>
#include <Eigen/SparseCore>
#include <iostream>
using namespace std;

int main()
{
    typedef Eigen::SparseMatrix<double, 0, long int> SMatrixXd;
    cout << "tag1"<< endl;
    SMatrixXd sfeature(10, 5000000000);
    cout << "tag1 done" << endl;

    // load data
    typedef Eigen::Triplet<double, long int> T;
    std::vector<T> tripletList;
    tripletList.push_back(T(0, 1, 1.0));
    tripletList.push_back(T(0, 2, 2.0));
    tripletList.push_back(T(1, 3, 2.0));
    tripletList.push_back(T(2, 4, 2.0));
    tripletList.push_back(T(3, 5, 2.0));
    tripletList.push_back(T(4, 6, 2.0));
    tripletList.push_back(T(5, 7, 2.0));
    cout << "tag2 " << endl;
    sfeature.setFromTriplets(tripletList.begin(), tripletList.end());
    cout << "tag2 done" << endl;
    return 0;
}
eigen eigen3
2个回答
0
投票

看看stored稀疏矩阵是如何理解的,在你的情况下它需要分配一个5000000000 long int的数组。在您的情况下,只需使用RowMajor布局:

typedef Eigen::SparseMatrix<double, RowMajor, long int> SMatrixXd;

而之前的巨大数组将归结为10个long int的数组。


0
投票

您的矩阵有10行和5000000000列。但是,可以存储为“long int”的最大值(在typedef Eigen :: SparseMatrix SmatrixXd中指定)是2,147,483,647。结果,截断了5000000000(列数)的值。截断的具体值取决于您的计算机,我猜(在我的计算机上它被截断为705032704)。这是执行SMatrixXd sfeature(10,5000000000)时EIGEN获得的列数。

可以在此处找到Microsoft编译器(我使用Visual C ++)的值范围:https://msdn.microsoft.com/en-us/library/s3f49ktz.aspx

您的编译器应该警告您截断问题。

我尝试使用__int64或long long运行您的示例,但列值仍然被截断为705032704(我在Visual C ++中通过Debugger运行它):

Proprietary :: SparseMatrix A(10,500,000,000); Proprietary :: SparseMatrix A(10,500,000,000);

这不是编译器问题,因为如果我设置__int64 ival64 = 5000000000; long long ival_ll = 5000000000;价值很好。

因此,我怀疑你的矩阵可以使用EIGEN进行处理。

© www.soinside.com 2019 - 2024. All rights reserved.