[Rcpp-devel] Error still there

Amina Shahzadi aminashahzadi at gmail.com
Fri Sep 23 08:17:16 CEST 2016


Hello Dirk, Adler and Rcpp Colleagues

Would you please guide me why the following code is giving the error of "

cannot convert 'arma::subview_elem1<double, arma::mtOp<unsigned int,
arma::mtGlue<unsigned int, arma::mtOp<unsigned int, arma::Col<unsigned
int>, arma::op_rel_noteq>, arma::mtOp<unsigned int, arma::Col<unsigned
int>, arma::op_rel_noteq>, arma::glue_rel_and>, arma::op_find_simple>
>' to 'double' in initialization"


The problem is in double alpha1 and double beta1.



The code is:

#include <RcppArmadillo.h>
using namespace Rcpp;
using namespace RcppArmadillo;
//[[Rcpp::depends(RcppArmadillo)]]
//[[Rcpp::export]]

// A example of indexing some elements of a vector

arma::vec Vec_Index(arma::vec alpha, arma::vec beta)
{
  int m = alpha.size();
  arma::uvec index(m);
  arma::vec a(m);
  for(int i=0; i<m; i++)
  {
    index(i) = i;
  }
  for(int i=0; i<m; i++){
    for(int j=0; j<m; j++){
      double alpha1 = alpha.elem(find(index !=i && index !=j));
      double beta1 = beta.elem(find(index !=j && index !=j));
    a(i) = exp(alpha1+beta1);
  }
  }
  return a;
}









On Thu, Sep 15, 2016 at 2:52 AM, Avraham Adler <avraham.adler at gmail.com>
wrote:

> Amina and I continued the conversation off list, but for closure purposes,
> the "multiple" version was tweaked a bit as there was comparison between
> signed and unsigned ints which did not throw an error for me, but did for
> Amina. Final multiple version posted below.
>
> Thanks,
>
> Avi
>
>
> #include <RcppArmadillo.h>
> using namespace Rcpp;
> using namespace RcppArmadillo;
> using namespace arma;
> //[[Rcpp::depends(RcppArmadillo)]]
>
> //[[Rcpp::export]]
> vec Sample_Exp_Multi(size_t n, vec alpha, vec beta) {
>   size_t m = alpha.size();
>   vec answers(n);
>   uvec2 S;
>   for (size_t i = 0; i < n; ++i){
>     do {
>       S = randi<uvec>(2, distr_param(0, m - 1));
>     } while (S(0) == S(1));
>     answers(i) = exp(alpha(S(0)) + beta(S(1)));
>   }
>   return(answers);
> }
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>



-- 
*Amina Shahzadi*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20160923/07201c4e/attachment-0001.html>


More information about the Rcpp-devel mailing list