Elementwise matrix multiplication: R versus Rcpp (How to speed this code up?)
I am new to C++ programming (using Rcpp for seamless integration into R ), and I would appreciate some advice on how to speed up some calculations. Consider the following example: testmat <- matrix(1:9, nrow=3) testvec <- 1:3 testmat*testvec # [,1] [,2] [,3] #[1,] 1 4 7 #[2,] 4 10 16 #[3,] 9 18 27 Here, R recycled testvec so that, loosely speaking, testvec "became" a matrix of the same dimensions as testmat for the purpose of this multiplication. Then the Hadamard product is returned. I wish to implement this behavior using Rcpp , that is I want that each element of the i -th row in the matrix