[Rcpp-devel] Working with indicators in Armadillo
Simon Zehnder
szehnder at uni-bonn.de
Sat Feb 23 21:33:56 CET 2013
Dear Rcpp-Devels,
I try to write some code in C++, where S is a classification vector (arma::uvec) with entries in between 1 and K:
1 arma::mat repS = arma::repmat(S, 1, K);
2 arma::mat compM = arma::ones(S.n_rows, K);
3 arma::rowvec par_post(K);
4
5 for(unsigned int k = 0; k < K; ++k) {
6 compM.col(k) = compM.col(k) * (k + 1);
7 }
8
9 arma::umat ind = (repS == compM);
10 par_post = sum(ind);
I get an error with this code:
error: no match for ‘operator=’ in ‘par_post = arma::sum(const T1&, arma::uword, const typename arma::enable_if<(arma::is_arma_type<T1>::value == true)>::result*, const typename arma::enable_if<(arma::resolves_to_vector<T1>::value == false)>::result*) [with T1 = arma::Mat<unsigned int>; arma::uword = unsigned int; typename arma::enable_if<(arma::is_arma_type<T1>::value == true)>::result = int; typename arma::enable_if<(arma::resolves_to_vector<T1>::value == false)>::result = int](0u, 0u, 0u)’
I think the problem in line 10 is passing an arma::uvec object to an arma::rowvec (double) object. Has anybody an idea to make the code a little more elegant and especially: functional?
Best
Simon
More information about the Rcpp-devel
mailing list