[Rcpp-devel] Rccp code with vector and matrix inputs and matrix output

Dirk Eddelbuettel edd at debian.org
Mon Mar 31 13:36:31 CEST 2014


On 31 March 2014 at 10:51, Petre Caraiani wrote:
|          Am(ii,jj) = exp((jj+1)/(T-1)) ;

[...]
 
| and use  fun(a,b,A,T), I get a matrix of 1s. Is there something wrong with the
| division in this Cpp code?
| 
| I get the same thing when I write: Am(ii,jj) = exp((jj+1)/(T-1)*log(a[ii])) ;
| but, again, the results are normal if I just write: Am(ii,jj) = log(a[ii])

You sometimes need to help the compiler and make things a double variable.
Try this

         Am(ii,jj) = exp((jj+1.0)/(T-1.0));     // 1.0 forces double

and/or

         Am(ii,jj) = exp((jj+1.0)/(T-1.0)*log(a[ii]));

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list