我已经有了我的稀疏矩阵数据CSR format,即:我已经有非零值的数据(形式为double[]
),非零值的行和列索引(形式为int[]
)。如何为CSR格式设置SparseMatrix.valuePtr(),SparseMatrix.outerIndexPtr()和SparseMatrix.innerIndexPtr()?
我的问题是,我如何将它们直接分配给特征库中的稀疏矩阵?我知道,在稀疏矩阵相关领域是valuePtr
,outerIndexPtr
和innerIndexPtr
,但我不能直接设置指针为每如下:
//the relevant SpMat fields (valuePtr,outerIndexPtr,innerIndexPtr) are not able to set
static SpMat CSRFormat2(double* nonZeroPtr, int* rowIndex,
int* colIndex, int totDOF, int nonZeroCount)
{
SpMat sparseMatrix = SpMat(totDOF,totDOF);
double *nonZ=sparseMatrix.valuePtr();
nonZ=nonZeroPtr;
int *outerIndex = sparseMatrix.outerIndexPtr();
outerIndex=rowIndex;
int *innerIndex = sparseMatrix.innerIndexPtr();
innerIndex = colIndex;
sparseMatrix.reserve(nonZeroCount);
return sparseMatrix;
}
我不想遍历非零值和集再一次。我认为这样做效率不高。
如何设置SparseMatrix.valuePtr()
,SparseMatrix.outerIndexPtr()
和SparseMatrix.innerIndexPtr()
,如果可以的话?
您正在寻找[地图<稀疏矩阵>](https://eigen.tuxfamily.org/dox-devel/classEigen_1_1Map_3_01SparseMatrixType_01_4。 html) –
ggael
@ggael,您想将您的评论扩展为正确的答案吗?这样它可以被投票(上) – Graviton