Skip to content
Prev 4899 / 10988 Next

[Rcpp-devel] Sparse matrices with RcppArmadillo

Le 08/12/12 19:54, Douglas Bates a ?crit :
Alright
Yes. Conrad left a back door open so that we can add things **inside** 
the SpMat template, similar to what we have done in dense matrix classes.

Going from there I was looking at the copy constructor of a SpMat, which 
eventually is a call to init:

/**
  * Copy from another matrix.
  */
template<typename eT>
inline
void
SpMat<eT>::init(const SpMat<eT>& x)
   {
   arma_extra_debug_sigprint();

   // Ensure we are not initializing to ourselves.
   if (this != &x)
     {
     init(x.n_rows, x.n_cols);

     // values and row_indices may not be null.
     if (values != NULL)
       {
       memory::release(values);
       memory::release(row_indices);
       }

     access::rw(values)      = memory::acquire_chunked<eT> 
(x.n_nonzero + 1);
     access::rw(row_indices) = 
memory::acquire_chunked<uword>(x.n_nonzero + 1);

     // Now copy over the elements.
     arrayops::copy(access::rwp(values),      x.values,      x.n_nonzero 
+ 1);
     arrayops::copy(access::rwp(row_indices), x.row_indices, x.n_nonzero 
+ 1);
     arrayops::copy(access::rwp(col_ptrs),    x.col_ptrs,    x.n_cols + 1);

     access::rw(n_nonzero) = x.n_nonzero;
     }
   }

So it all looks very doable.

Romain