I already have my sparse matrix data in CSR format, ie: I already have data for non zero values ( in the form of double[]
), the row and the column index ( both in the form of int[]
) of the non zero values.
My problem is, how can I assign them directly to Sparse Matrix in eigen library? I know that the relevant fields in Sparse Matrix are valuePtr
, outerIndexPtr
and innerIndexPtr
, but I can't set the pointer directly as per below:
//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;
}
I don't want to iterate over the non zero values and set everything again. That would be inefficient, I think.
How to set SparseMatrix.valuePtr()
, SparseMatrix.outerIndexPtr()
and SparseMatrix.innerIndexPtr()
, if this is possible at all?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…