【发布时间】:2018-04-19 16:05:18
【问题描述】:
我正在使用 RcppArmadillo 在 R / Rcpp 中开发应用程序,并且我需要使用 arma::cube 对象的向量。以下示例运行良好。
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace std;
using namespace Rcpp;
using namespace arma;
// [[Rcpp::export]]
bool posterior(int n, int L, NumericVector N, int TIME) {
vector<cube> A(TIME);
for (int t = 0; t < TIME; t++) A[t] = cube(n, L, max(N), fill::zeros);
Rprintf("*** %.2f ***\n", A[3].at(5, 1, 2));
return true;
}
这里有一些 R 代码来测试它。
library(Rcpp)
sourceCpp("VectorOfCubes.cpp")
posterior(200, 3, c(10, 5, 2), 10^4)
我的问题是:可以去掉上面C++函数中的for,直接初始化向量A吗?
【问题讨论】: