Message-ID: <20147.59732.908335.421104@max.nulle.part>
Date: 2011-11-04T13:32:04Z
From: Dirk Eddelbuettel
Subject: [Rcpp-devel] can one modify array in R memory from C++ without copying it?
In-Reply-To: <FECA6E72-231E-429D-93D4-00EC2E14AD7D@r-enthusiasts.com>
On 4 November 2011 at 08:28, romain at r-enthusiasts.com wrote:
| Not a bug, this is expected behaviour.
|
| If you pass a matrix of ints to the NumericVector ctor, Rcpp has no choice but to coerce the data to a matrix of double, which means new data, hence the original data does not get modified.
|
| If you pass a matrix of double, no copy is required, therefore Rcpp operates directly on the data.
|
| Those are features.
And they are documented.
Dirk
| Le 4 nov. 2011 ? 08:01, Darren Cook <darren at dcook.org> a ?crit :
|
| >> I.e. the point of his code was to show that a matrix of doubles gets
| >> modified, a matrix of ints does not.
| >
| > Or change the first line from NumericMatrix to:
| > Rcpp::IntegerMatrix r_m(mem);
| >
| > Then the behaviour is reversed. The matrix of doubles does not get
| > modified, but the matrix of ints does!
| >
| > Dirk, Romain, this is a bug-in-waiting. Is there any way to generate a
| > warning when the implicit deep copy happens? Or alternatively when the
| > pointer is being used implicitly... but my hunch is that I want to know
| > when there is any implicit conversion between int and double: modern C++
| > style is to explicitly declare all type conversions with static_cast<>
| > and friends.
| >
| > Darren
| > _______________________________________________
| > Rcpp-devel mailing list
| > Rcpp-devel at lists.r-forge.r-project.org
| > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx