【发布时间】:2016-02-19 04:07:57
【问题描述】:
我想对 ComplexVector 类型使用糖匹配函数,但出现错误
g++ -m64 -I"C:/PROGRA~1/R/R-32~1.3/include" -DNDEBUG -I"*path*"
-I"*path*" -I"d:/RCompile/r-compiling/local/local323/include"
-O2 -Wall -mtune=core2 -c setdiffComplexVectorsC.cpp
-o setdiffComplexVectorsC.o
g++ -m64 -shared -s -static-libgcc -o sourceCpp_38.dll tmp.def
setdiffComplexVectorsC.o -Ld:/RCompile/r-compiling/local/local323/lib/x64
-Ld:/RCompile/r-compiling/local/local323/lib
-LC:/PROGRA~1/R/R-32~1.3/bin/x64
-lR setdiffComplexVectorsC.o:setdiffComplexVectorsC.cpp:(.text+0x5e0):
undefined reference to `Rcpp::sugar::IndexHash<15>::get_addr(Rcomplex) const'
setdiffComplexVectorsC.o:setdiffComplexVectorsC.cpp:(.text+0x788): undefined
reference to `Rcpp::sugar::IndexHash<15>::get_addr(Rcomplex) const'
collect2: ld returned 1 exit status
Error in Rcpp::sourceCpp("setdiffComplexVectorsC.cpp") :
**Error occurred building shared library.**
使用以下代码:
#include <Rcpp.h>
using namespace Rcpp;
using namespace std;
using namespace sugar;
// [[Rcpp::export]]
ComplexVector setdiffComplexVectorsC(ComplexVector
ComplexVector2Curt,ComplexVector ComplexVector2compare){
// setdiffComplexVectors shortens ComplexVector2Curt by those rows that
//are in both matrices.
// INPUT
// ComplexVector2Curt(n) complexvector, which will be shortened by ComplexVector2compare
// ComplexVector2compare(m) complexvector whose elements will be compared to those of ComplexVector2Curt
//
// OUTPUT
// CurtedComplexVector[n-x] complexvector, Shortened ComplexVector2Curt
//by x same elements of ComplexVector2compare
IntegerVector Y = match(ComplexVector2Curt,ComplexVector2compare);
//FoundPositions <- ComplexVector2Curt[Y];
int n=sum(abs(Y-1)); //length of open positions (FALSE)
if(n<1){
ComplexVector Nix;
return(Nix);
}
//ComplexVector OpenPositions = ComplexVector2Curt[!Y];
ComplexVector OpenPositions(n);
for(int i=0;i<n;i++){
if(Y(i)==0){
OpenPositions(i)= ComplexVector2Curt(i);
}
}
return(OpenPositions);
}
有没有办法解决这个问题? 也许有人知道如何以另一种方式比较 ComplexVectors:目标是找到“ComplexVector2Curt”的不匹配元素。
【问题讨论】:
-
您在寻找
x[!(x %in% y)]的等价物吗? R API 还提供了一个您可以检查的match函数。 -
是的,我目前正在使用 R 匹配函数:我的代码有一个 for 循环,我想将它移植到 C++,为此我必须在我所在的 C++ 中使用这个函数出现上述错误。
-
也许它不接受“复杂”(CPLXSXP)作为输入?