[Rcpp-devel] Error still there

Avraham Adler avraham.adler at gmail.com
Tue Sep 13 01:05:35 CEST 2016


Hello, Amina.

I am having trouble understanding your code, however,one thing that
stands out is that your return statement is inside your for loop which
looks strange. Secondly in your first branch, you seem to want to
return a scalar and in your second branch, you seem to want to return
a vector of length greater than 1. If that is the case, you need to
return a vector of length 1 in the first branch.

What exactly is it that you are trying to do?

Avi

On Mon, Sep 12, 2016 at 6:45 PM, Amina Shahzadi <aminashahzadi at gmail.com> wrote:
> Thank you for welcoming me.
> Your help will be appreciatable.
>
> My problem is still there and getting the following error.
> sample.cpp: In function ‘double sample(arma::vec, arma::vec)’:
> sample.cpp:29:29: error: cannot convert ‘arma::enable_if2<true, const
> arma::eOp<                             arma::eGlue<arma::Col<double>,
> arma::Col<double>, arma::eglue_plus>, arma::eop_e
> xp> >::result {aka const arma::eOp<arma::eGlue<arma::Col<double>,
> arma::Col<doub                             le>, arma::eglue_plus>,
> arma::eop_exp>}’ to ‘double’ in return
>       return exp(alpha2+beta2);
>                              ^
> sample.cpp:34:1: warning: control reaches end of non-void function
> [-Wreturn-typ                             e]
>  }
>
>
> My sample code is
>
> #include <RcppArmadillo.h>
> using namespace Rcpp;
> using namespace RcppArmadillo;
> //[[Rcpp::depends(RcppArmadillo)]]
> //[[Rcpp::export]]
>
> double sample(arma::vec alpha, arma::vec beta)
> {
>         int m = alpha.size();
>         arma::uvec index(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++)
>                 {
>                         if(i==j)
>                                 {
>                                         arma::vec alpha1 =
> alpha.elem(find(index !=j));
>                                         arma::vec beta1 =
> beta.elem(find(index!=j));
>                                         return exp(alpha1(0)+beta1(1));
>                                 }
>                                 else
>                                 {
>                                         arma::vec  alpha2 =
> alpha.elem(find(index !=i && index !=j));
>                                         arma::vec beta2 =
> beta.elem(find(index !=i && index !=j));
>                                         return exp(alpha2+beta2);
>                                 }
>                 }
>         }
>
> }
>
>
> Thank you
>
>
> --
> Amina Shahzadi
>
> _______________________________________________
> 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


More information about the Rcpp-devel mailing list