I tried to port m
code to c
or cpp
.
In my code there is a line
A = sparse(I,J,IA,nR,nC);
which converts row index I
, col index J
, and data IA
to sparse matrix A
with size nR x nC
.
Is there any equivalent code with C++ or C?
An naïve algorithm to duplicate result in full matrix is
double *A;
A = malloc(sizeof(double)*nR*nC);
memset(A, 0, sizeof(double));
for(k=0; k<size_of_IA; k++)
A[I[k]*nC + J[k]] += IA[k];
Note that if there is common indices, the value is not over overwritten, but accumulated.