c++ - RcppArmadillo: "-=" operation on list elements -
i have list of complex matrices same k*k dimensions, , need subtract k*k complex matrix x each element of list. application, x vary depending on position of elements in list, here simplicity, x fixed. code task:
# include <rcpparmadillo.h> // [[rcpp::depends(rcpparmadillo)]] using namespace rcpp; using namespace arma; // [[rcpp::export]] list fn(int& length, int& k) { list out(length); cx_mat m(k, k, fill::zeros); out.fill(m); cx_mat x(k, k, fill::ones); for(int i=0; i<length; i++) { out(i) -= x; } return out; } this throw error during compiling:
g++ -m64 -i"c:/progra~1/r/r-32~1.3/include" -dndebug -i"c:/progra~1/r/r-32~1.3/library/rcpp/include" -i"c:/progra~1/r/r-32~1.3/library/rcppar~1/include" -i"c:/users/shuang/docume~1/markov~1/rcode~1" -i"d:/rcompile/r-compiling/local/local323/include" -o2 -wall -mtune=core2 -c test3.cpp -o test3.o test3.cpp: in function 'rcpp::list fn4(int&, int&)': test3.cpp:77:15: error: no match 'operator-=' in 'rcpp::vector<rtype, storagepolicy>::operator()(const size_t&) [with int rtype = 19, storagepolicy = rcpp::preservestorage, rcpp::vector<rtype, storagepolicy>::proxy = rcpp::internal::generic_proxy<19>, size_t = long long unsigned int]((* &((size_t)i))) -= x' make: *** [test3.o] error 1 however, if change body of for loop using intermediate variable, code compiles , works fine:
# include <rcpparmadillo.h> // [[rcpp::depends(rcpparmadillo)]] using namespace rcpp; using namespace arma; // [[rcpp::export]] list fn(int& length, int& k) { list out(length); cx_mat m(k, k, fill::zeros); out.fill(m); cx_mat x(k, k, fill::ones); for(int i=0; i<length; i++) { cx_mat temp = out(i); temp -= x; out(i) = temp; } return out; } i not well-versed in c++ grasp error message means, guess have type mismatch here since list rcpp type. there anyway make work without using intermediate variable? thanks.
you jumping , forth between arma , rcpp types, invoking implicit conversions. needs help, , more explicit rewrite provided help.
Comments
Post a Comment