RcppParallel: no matching constructor for initialization of const_iterator

31 Views Asked by At

I am trying to implement a distance measure using the RcppParallel package, but I am having a problem when I compile my code. The error message "no matching constructor for initialization of const_iterator (aka 'row_iterator). I am new to using Rcpp and RcppParallel, so I think the solution might be trivial.
Could you help me understand what's going on? or have a solution to this problem?

  
  // [[Rcpp::export]]
double mop_dist(arma::mat &x, arma::mat &y, arma::vec &prob){
  int n_rowy = y.n_rows;
  arma::vec output(n_rowy);
  arma::mat A = x.row(0);
  for(int i = 0; i < n_rowy; i++){
    arma::mat B = y.row(i);
    output[i] = arma::accu(arma::square(A - B));
  }
  arma::vec outq = arma::quantile(output,prob);
  return outq[0];
}
struct mop : public Worker {
  
  // input
  const RMatrix<double> mat;
  const RMatrix<double> rmat;
  RVector<double> prob;
  // output
  RVector<double> output;
  
  // initialize from Rcpp input and output 
  mop(NumericMatrix mat, NumericMatrix rmat, NumericVector prob, NumericVector output)
  : mat(mat), rmat(rmat), prob(prob), output(output) {}
  
  void operator()(std::size_t begin, std::size_t end) {
    int n_rowy = mat.nrow();
    arma::vec p = as<arma::vec>(wrap(prob));
    arma::vec output(n_rowy);
    arma::mat B = as<arma::mat>(wrap(rmat));
    for (std::size_t i = begin; i < end; i++) {
      arma::mat A = as<arma::mat>(wrap(mat.row(i)));
      output[i] = mop_dist(A,B,p);
    }
    Rcpp::NumericVector vec_Rcpp = as<NumericVector>(wrap(output));
  }
  
};

// [[Rcpp::export]]
NumericVector mop_parallel(NumericMatrix mat, NumericMatrix rmat,
                           NumericVector prob, NumericVector output) {
  
  // create the worker
  mop mop(mat, rmat, prob,output);
  
  // call it with parallelFor
  parallelFor(0, mat.nrow(), mop);
  
  return output;
}

0

There are 0 best solutions below