[Rcpp-devel] Problems indexing matrics
Dirk Eddelbuettel
edd at debian.org
Wed Jan 4 22:19:14 CET 2012
On 4 January 2012 at 15:59, Yasir Suhail wrote:
| Actually,
| Rcpp::NumericMatrix output(x_s + x_k - 1, y_s + y_k - 1); output.fill(0.0);
| should do it.
|
| Perhaps the following could be added to Matrix.h?
|
| template <typename U> Matrix( const int& nrows_, const int& ncols, const U& u)
| :
| VECTOR( Dimension( nrows_, ncols ) ),
| nrows(nrows_)
| { fill(u); }
| for completeness? Or does this conflict with the other constructor?
Well, zero fill is already a default.
Look at the code for _Vector_ as matrix is 'merely' a vector with dimension
attributes; there are plenty of other constructors.
R> library(inline)
R> f <- cxxfunction(signature(), body='
+ return Rcpp::NumericMatrix(2,3);
+ ', plugin="Rcpp")
R> f()
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 0
R>
Dirk
--
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx
More information about the Rcpp-devel
mailing list