I want a matrix which is the result of the multiplication of each element in a vector (rowvec) by all elements in another vector (colvec), of different size. Here's a sample code of what I want to achieve but I'm looking for a faster way to do it.
#include <RcppArmadillo.h>
using namespace Rcpp;
// [[Rcpp::export]]
arma::mat myMultiplication() {
arma::colvec cx = {0, 1, 2, 3, 4};
arma::rowvec rx = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
arma::mat x(cx.size(), rx.size());
for (unsigned int i = 0; i < cx.size(); i++) {
x.row(i) = rx;
}
return cx % x.each_col();
}