fx <- cxxfunction( signature(x = "integer", y = "numeric" ) , '
int dim = as( x ) ;
arma::mat z = as(y) * arma::eye( dim, dim ) ;
return wrap( arma::accu(z) ) ;
', plugin = "RcppArmadillo" )
fx( 2L, 5 )