首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RcppParallel不匹配调用“transform”的函数

RcppParallel不匹配调用“transform”的函数
EN

Stack Overflow用户
提问于 2020-06-17 09:45:54
回答 1查看 161关注 0票数 2

我在克拉恩上发布了一个包,它通过RcppParallel框架使用多个核心。它在r-devel-linux-x86_64-fedora-clangr-patched-solaris-x86.上安装有问题。我得到以下错误消息(有几条与std::transform相关的类似消息,因此我只提供其中一条用于简洁):

1.r-修补-solaris-x86:

代码语言:javascript
复制
ParallelFunctions.cpp: In member function ‘virtual void ParallelVectorExpStruct::operator()(std::size_t, std::size_t)’:
ParallelFunctions.cpp:134:27: error: no matching function for call to ‘transform(RcppParallel::RVector<double>::const_iterator, RcppParallel::RVector<double>::const_iterator, RcppParallel::RVector<double>::iterator, <unresolved overloaded function type>)’
                      ::exp);
                           ^
In file included from /opt/csw/include/c++/5.2.0/algorithm:62:0,
                 from /home/ripley/R/Lib32/Rcpp/include/RcppCommon.h:63,
                 from /home/ripley/R/Lib32/RcppArmadillo/include/RcppArmadilloForward.h:26,
                 from /home/ripley/R/Lib32/RcppArmadillo/include/RcppArmadillo.h:31,
                 from ParallelFunctions.h:4,
                 from ParallelFunctions.cpp:1:
/opt/csw/include/c++/5.2.0/bits/stl_algo.h:4164:5: note: candidate: template<class _IIter, class _OIter, class _UnaryOperation> _OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation)
     transform(_InputIterator __first, _InputIterator __last,
     ^
/opt/csw/include/c++/5.2.0/bits/stl_algo.h:4164:5: note:   template argument deduction/substitution failed:
ParallelFunctions.cpp:134:27: note:   couldn't deduce template parameter ‘_UnaryOperation’
                      ::exp);
                           ^
In file included from /opt/csw/include/c++/5.2.0/algorithm:62:0,
                 from /home/ripley/R/Lib32/Rcpp/include/RcppCommon.h:63,
                 from /home/ripley/R/Lib32/RcppArmadillo/include/RcppArmadilloForward.h:26,
                 from /home/ripley/R/Lib32/RcppArmadillo/include/RcppArmadillo.h:31,
                 from ParallelFunctions.h:4,
                 from ParallelFunctions.cpp:1:
/opt/csw/include/c++/5.2.0/bits/stl_algo.h:4201:5: note: candidate: template<class _IIter1, class _IIter2, class _OIter, class _BinaryOperation> _OIter std::transform(_IIter1, _IIter1, _IIter2, _OIter, _BinaryOperation)
     transform(_InputIterator1 __first1, _InputIterator1 __last1,
     ^
/opt/csw/include/c++/5.2.0/bits/stl_algo.h:4201:5: note:   template argument deduction/substitution failed:
ParallelFunctions.cpp:134:27: note:   candidate expects 5 arguments, 4 provided
                      ::exp);
                           ^

2.对于r-devel-linux-x86_64-fedora-clang:

代码语言:javascript
复制
hpaML.cpp:754:45: warning: explicitly assigning value of variable of type 'Rcpp::NumericVector' (aka 'Vector<14>') to itself [-Wself-assign-overloaded]
                           mean_ind, sd_ind = sd_ind,
                                     ~~~~~~ ^ ~~~~~~
ParallelFunctions.cpp:46:7: error: no matching function for call to 'transform'
      std::transform(input.begin() + begin, 
      ^~~~~~~~~~~~~~
/usr/local/bin/../include/c++/v1/algorithm:1955:1: note: candidate template ignored: couldn't infer template argument '_BinaryOperation'
transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
^
/usr/local/bin/../include/c++/v1/algorithm:1945:1: note: candidate function template not viable: requires 4 arguments, but 5 were provided
transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op)
^

下面是函数的代码,其中调用了std::tansform和std::exp函数:

代码语言:javascript
复制
// Parallel exp of vectors
struct ParallelVectorExpStruct : public Worker
{
  // source matrix
  const RVector<double> input;
  
  // destination matrix
  RVector<double> output;
  
  // initialize with source and destination
  ParallelVectorExpStruct(const NumericVector input, NumericVector output) 
    : input(input), output(output) {}
  
  // take the exponents of the range of elements requested
  void operator()(std::size_t begin, std::size_t end) {
      std::transform(input.begin() + begin, 
                     input.begin() + end,
                     output.begin() + begin, 
                     ::exp);
  }
};

// Parallel exponent of vector elements
NumericVector ParallelVectorExp(NumericVector x) 
{
  // allocate the output matrix
  NumericVector output(x.size());
  
  // ParallelVectorPowStruct functor
  ParallelVectorExpStruct parallelVectorExpStruct(x, output);
  
  // call parallelFor to do the work
  parallelFor(0, x.length(), parallelVectorExpStruct);
  
  // return the output matrix
  return (output);
}

我的描述文件包括SystemRequirements: GNU

我的makevars文件有以下标志

代码语言:javascript
复制
CXX_STD = CXX11
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) 
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_LIBS += $(shell ${R_HOME}/bin/Rscript -e "RcppParallel::RcppParallelLibs()")

请帮我找出如何解决这个错误。将是非常伟大的充分的帮助!

EN

回答 1

Stack Overflow用户

发布于 2020-06-28 11:42:39

我找到了一个奇怪的解决办法。其思想是使以下包装器功能:

代码语言:javascript
复制
double exp_parallel(double x)
{
  return std::exp(x);
}

然后,我将exp替换为exp_parallel收益率:

代码语言:javascript
复制
// Parallel exp of vectors
struct ParallelVectorExpStruct : public Worker
{
  // source matrix
  const RVector<double> input;
  
  // destination matrix
  RVector<double> output;
  
  // initialize with source and destination
  ParallelVectorExpStruct(const NumericVector input, NumericVector output) 
    : input(input), output(output) {}
  
  // take the exponents of the range of elements requested
  void operator()(std::size_t begin, std::size_t end) {
      std::transform(input.begin() + begin, 
                     input.begin() + end,
                     output.begin() + begin, 
                     ::exp_parallel);
  }
};

原因可能是有些系统无法区分std::expRcpp::exp函数。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62426100

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档