【发布时间】:2017-05-18 20:23:32
【问题描述】:
我有一个用 RcppArmadillo 风格编写的函数,我想用它来更改调用环境中的变量。我知道这样做是不可取的,但这对我来说很有帮助。具体来说,我正在尝试这个:
#include <RcppArmadillo.h>
#include <iostream>
//[[Rcpp::export]]
void myfun(double &x){
arma::mat X = arma::randu<arma::mat>(5,5);
arma::mat Y = X.t()*X;
arma::mat R1 = chol(Y);
x = arma::det(R1);
std::cout << "Inside myfun: x = " << x << std::endl;
}
/*** R
x = 1.0 // initialize x
myfun(x) // update x to a new value calculated internally
x // return the new x; it should be different from 1
*/
我错过了什么?为什么不工作?
【问题讨论】: