Skip to content
Prev 4904 / 10988 Next

[Rcpp-devel] Sparse matrices with RcppArmadillo

c s
Hi Romain & Doug,

Two points to note:

(1)
When poking around internal Armadillo pointers and arrays for sparse
matrices, please take into account that the col_ptrs array is slightly
longer than specified by the Compressed Sparse Column (CSC) format.

However, this should not cause any problems when interfacing with
external libraries. If you use the set_size() function before writing
to the values[], row_indices[] and col_ptrs[] arrays, everything
should be okay.

The col_ptrs array is slightly longer in order to allow robust
iterators.  Specifically, instead of the col_ptrs array having a size
of ncols+1 (as specified by CSC), it has a size of ncols+2.  The extra
element is always set to std::numeric_limits<uword>::max().  As such,
be careful not to overwrite this magic number.

For more details within the code, see the function
SpMat<eT>::init(uword in_rows, uword in_cols), on line 3635 in
"SpMat_meat.hpp".

(2)
If you need to allocate memory for the values[] and row_indices[]
arrays, you need to use the memory::acquire_chunked() function.  This
is an alternative memory allocation mechanism designed to reduce the
burden of inserting or removing a non-zero element.  The rest of the
sparse matrix memory management code relies on this.  See the code in
file "memory.hpp" for more details.


On Sun, Dec 9, 2012 at 5:55 AM, Romain Francois
<romain at r-enthusiasts.com> wrote: