Skip to content
Prev 2591 / 10988 Next

[Rcpp-devel] Deep copying a matrix

Doug first wrote:
| >> I would rewrite your code fragment as
| >>
| >> ? ?const Rcpp::NumericMatrix ?m_source(origin);
| >> ? ?Rcpp::NumericMatrix m_copy = Rcpp::clone(m_source);

Seconded.
On 14 July 2011 at 12:22, Douglas Bates wrote:
| On Thu, Jul 14, 2011 at 12:03 PM, Etienne B. Racine <etiennebr at gmail.com> wrote:
| > Thanks Douglas,
| >
| > However just to be sure I get it, const is in fact protecting the pointer on
| > origin, but not its values. Is there a way to protect the values ? This is
| > running fine :
| > const Rcpp::NumericMatrix m_source(origin);
| > m_source(0,0) = 0;
| 
| We're getting into areas where Dirk and Romain will need to take over
| from me as I am out of my depth.  I would have thought that the
| compiler should complain about the assignment to elements of a const
| matrix.  It may have something to do with whether there is a const
| version of operator()

Possibly.  

If Etienne needs new behaviour very badly, he may have to look into
contributing it, or providing funding which may give a higher chance to have
this getting push up on the priority list.

Dirk