I am new to C++ but I am working with R and RcppArmadillo and my goal is to divide element-wise 2 sparse matrices. I have read in the documentation of Armadillo that the operator is /
but when I source my code with sourceCpp
I am getting this error:
no match for 'operator/' (operand types are 'arma::sp_mat' {aka 'arma::SpMat'} and 'arma::sp_mat' {aka 'arma::SpMat'})
I have write a small example of code. Please note that when I remove the division function from the script, the multiplication function works fine.
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
using namespace Rcpp;
//' Sparse Matrix element-wise multiplication
//'
//' @param X sp_mat
// [[Rcpp::export]]
arma::sp_mat sp_mat_mul(arma::sp_mat X){
arma::sp_mat Y = X % X;
return Y;
}
//' Sparse Matrix element-wise division
//'
//' @param X sp_mat
// [[Rcpp::export]]
arma::sp_mat sp_mat_div(arma::sp_mat X){
arma::sp_mat Y = X / X;
return Y;
}
Thank you for your time, I really appreciate it!