Any C++/C equivalent function with sparse in MATLAB -
i tried port m
code c
or cpp
.
in code there line
a = sparse(i,j,ia,nr,nc);
which converts row index i
, col index j
, , data ia
sparse matrix a
size nr x nc
.
is there equivalent code c++ or c?
an naïve algorithm duplicate result in full matrix is
double *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 if there common indices, value not on overwritten, accumulated.
eigen example of c++ math matrix library cobtains sparse matrices. overloads operators make feel built in feature.
there many c , c++ matrix libraries. none ship part of std
, nor there built in.
writing sparse matrix library quite hard; best bet finding pre-written one. recommendation questions off topic
Comments
Post a Comment