SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
Create and return a sparse matrix? [ Reply ]
By: Henrik Alsing Friberg on 2011-06-03 14:56
[forum:4531]
Hey All,

I wonder if anybody knows the best way to create and return a sparse matrix from a C++ coded R-package using the functions exported by the Matrix package.

My best guess is to:
(1) Call this function to get a CHM_SP:
M_cholmod_allocate_sparse
(2) Set the values of the CHM_SP.
(3) Call this function to transform the CHM_SP into a SEXP, and free the original CHM_SP which we no longer want:
M_chm_sparse_to_SEXP
(4) Return the obtained SEXP.

The problem with this is that the function M_chm_sparse_to_SEXP copies all of the data from the CHM_SP to another location. This is both time and memory consuming for large matrices.. Do anyone here know a better way?

Thanks to:
Vienna University of Economics and Business Powered By FusionForge