本文整理汇总了C++中NumericMatrix::length方法的典型用法代码示例。如果您正苦于以下问题:C++ NumericMatrix::length方法的具体用法?C++ NumericMatrix::length怎么用?C++ NumericMatrix::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NumericMatrix
的用法示例。
在下文中一共展示了NumericMatrix::length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parallelMatrixSqrt
// [[Rcpp::export]]
NumericMatrix parallelMatrixSqrt(NumericMatrix x) {
// allocate the output matrix
NumericMatrix output(x.nrow(), x.ncol());
// SquareRoot instance that takes a pointer to the input & output data
SquareRoot squareRoot(x.begin(), output.begin());
// call parallelFor to do the work
parallelFor(0, x.length(), squareRoot);
// return the output matrix
return output;
}
示例2: samplehouseholds_format2
// [[Rcpp::export]]
NumericMatrix samplehouseholds_format2(NumericMatrix phi, NumericMatrix w, NumericVector pi,
NumericVector d, List lambda,
int currrentbatch, int nHouseholds, int householdsize) {
int K = w.nrow();
int L = w.ncol();
int p = d.length();
int n_lambdas = lambda.length();
int *lambda_columns = new int[n_lambdas];
double **lambdas = new double*[n_lambdas];
int maxDDtp = phi.nrow();
int maxdd = maxDDtp / p;
//int ncol = householdsize * DIM + 1 + householdsize;
//output data: zero-based
//column 0: household unique index
//column 1: member index within the household (pernum:person number?)
//column 2 to 2+p-1: individual data
//column 2+p: 2+p+n_lambdas-2: household level data
//column 2+p+n_lambdas-1: household group indicator
//column last hh_size: individual group indicator
int DIM = 2 + p + n_lambdas - 1; //not output the household size
int ncol = DIM * householdsize + householdsize + 1;
NumericMatrix data(nHouseholds, ncol);
//copy data from list of matrices to C++
for (int i = 0; i < n_lambdas; i++) {
NumericMatrix l = lambda[i];
lambda_columns[i] = l.ncol();
lambdas[i] = new double[l.length()];
std::copy(l.begin(), l.end(), lambdas[i]);
}
//printf("in samplehouseholds\n");
NumericVector rand = runif(nHouseholds * ncol); //at most this many
sampleHouseholds_imp_format2(data.begin(), rand.begin(), lambdas, lambda_columns, w.begin(),
phi.begin(), pi.begin(),d.begin(),
nHouseholds, householdsize, K, L,maxdd,p, currrentbatch,n_lambdas);
//clean up
delete [] lambda_columns;
for (int i = 0; i < n_lambdas; i++) {
delete [] lambdas[i];
}
delete [] lambdas;
//printf("done samplehouseholds\n");
return data;
}