I'm trying to use Rcpp to multiply part of a row of a NumericMatrix by a NumericVector. A simple version of my situation is follows:
int temp() {
NumericMatrix matr(3,3);
NumericVector vec(2, 5);
int matsize = matr.nrow() * matr.ncol();
for(int i = 0; i < matsize; i++)
matr[i] = i;
int value = sum(matr(1, Range(1,2)) * vec );
return(value);
}
The part that is giving me difficulty is int value = sum(matr(1, Range(1,2)) * vec );
.
This line gives the error
no matching function for call to object of type 'NumericMatrix' (aka 'Matrix<14>')
when I hover over the red x on the code line in RStudio.
Does anyone have a solution?
Edit: I found a solution using a temp variable.
int temp() {
NumericMatrix matr(3,3);
NumericVector vec = NumericVector::create(2, 5);
int matsize = matr.nrow() * matr.ncol();
for(int i = 0; i < matsize; i++)
matr[i] = i;
NumericVector temp = matr(1, _);
NumericVector value = temp[Range(1,2)] * vec ;
return(sum(value));
}