# [Rcpp-devel] Error still there

Tue Sep 13 03:19:44 CEST 2016

```Hello, Amina.

My apologies but it is still unclear as to what you want to do.

Your inputs are two vectors of length m.

What do you expect as output?

Looking at the for loop in your code, you are running m² calculations
as you have nested loops. Is that what you truly want? Let's start
with something simpler. Pass in the two vectors of length m and
receive back ONE number. This one number is the exponentiation of the
sum of two random selections from the two provided vectors, as long as
they are not in the same "position". The other option I had to
understand your code was that you wanted 1 sample per entry in your
vectors.

Look at the code below. The first function returns one element, the
second returns n elements, n being an input in case you want more or
fewer than the size of alpha and beta. Hope that helps.

Avi

using namespace Rcpp;
using namespace arma;

//[[Rcpp::export]]
double Sample_Exp_Single(vec alpha, vec beta) {
int m = alpha.size();
ivec S(2);
do {
S = randi<ivec>(2, distr_param(0, m - 1));
} while (S[0] == S[1]);
return exp(alpha(S[0]) + beta(S[1]));
}

//[[Rcpp::export]]
vec Sample_Exp_Multi(int n, vec alpha, vec beta) {
int m = alpha.size();
ivec S(2);
for (std::size_t i = 0; i < n; ++i){
do {
S = randi<ivec>(2, distr_param(0, m - 1));
} while (S[0] == S[1]);
}
}

On Mon, Sep 12, 2016 at 8:21 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
>
> On 12 September 2016 at 19:05, Avraham Adler wrote:
> | What exactly is it that you are trying to do?
>
> Also review some resources on 'minimally reproducible example' as eg
>
> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>
> Dirk
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
```