小编mce*_*mce的帖子

使用RcppParallel并行添加向量

我试图使用RcppParallel并行(大)向量的并行.这就是我想出来的.

// [[Rcpp::depends(RcppParallel)]]
#include <RcppParallel.h>
#include <Rcpp.h>
#include <assert.h> 
using namespace RcppParallel;
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector directVectorAddition(NumericVector first, NumericVector second) {
    assert (first.length() == second.length());
    NumericVector results(first.length());
    results = first + second;
    return results;
}

// [[Rcpp::export]]
NumericVector loopVectorAddition(NumericVector first, NumericVector second) {
    assert (first.length() == second.length());
    NumericVector results(first.length());
    for(unsigned i = 0; i != first.length(); i++)
        results[i] = first[i] + second[i];
    return results;
}

struct VectorAddition : public Worker
{
    const RVector<double> first, second;
    RVector<double> results;
    VectorAddition(const …
Run Code Online (Sandbox Code Playgroud)

vector rcpp rcppparallel

4
推荐指数
1
解决办法
44
查看次数

标签 统计

rcpp ×1

rcppparallel ×1

vector ×1