Friday, 15 May 2015

c++ - std::transform on vectors of Armadillo vectors -



c++ - std::transform on vectors of Armadillo vectors -

i have 2 std::vector< arma::rowvec::fixed<3> > , concatenate each element of these 2 vectors end std::vector< arma::rowvec::fixed<3> >. no problem using loop accomplish arma::join_horiz(), have difficulties when trying utilize std::transform instead of loop. tried different solutions, end compilation errors :

first effort :

// create dummy vectors arma::rowvec::fixed<3> a, b, c, d; << 1 << 2 << 3 << arma::endr; b << 4 << 5 << 6 << arma::endr; c << 7 << 8 << 9 << arma::endr; d << 10 << 11 << 12 << arma::endr; std::vector< arma::rowvec::fixed<3> > ab; ab.push_back(a); ab.push_back(b); std::vector< arma::rowvec::fixed<3> > cd; cd.push_back(c); cd.push_back(d); // concatenate 1 std::vector< arma::rowvec::fixed<6> > concat; std::transform(ab.begin(), ab.end(), cd.begin(), concat.begin(), arma::join_horiz< arma::rowvec::fixed<3>, arma::rowvec::fixed<3> >());

compilation output :

./armadillo_test/main.cpp: in function 'int main(int, char**)': ../armadillo_test/main.cpp:81:87: error: no matching function phone call 'join_horiz()' ../armadillo_test/main.cpp:81:87: note: candidate is: /usr/local/include/armadillo_bits/fn_join.hpp:53:1: note: template<class t1, class t2> const arma::glue<t1, t2, arma::glue_join> arma::join_horiz(const arma::base<typename t1::elem_type, t1>&, const arma::base<typename t1::elem_type, t2>&)

second effort based on this question:

typedef const arma::glue< arma::rowvec::fixed<3>, arma::rowvec::fixed<3>, arma::glue_join > (*join_ft) (const arma::base< arma::rowvec::fixed<3>::elem_type, arma::rowvec::fixed<3> >&, const arma::base< arma::rowvec::fixed<3>::elem_type, arma::rowvec::fixed<3> >&); join_ft join_fptr = &arma::join_horiz; std::transform(ab.begin(), ab.end(), cd.begin(), concat.begin(), join_fptr);

compilation output :

from ../armadillo_test/main.cpp:1: /usr/include/c++/4.6/bits/stl_algo.h: in function '_oiter std::transform(_iiter1, _iiter1, _iiter2, _oiter, _binaryoperation) [with _iiter1 = __gnu_cxx::__normal_iterator<arma::row<double>::fixed<3u>*, std::vector<arma::row<double>::fixed<3u> > >, _iiter2 = __gnu_cxx::__normal_iterator<arma::row<double>::fixed<3u>*, std::vector<arma::row<double>::fixed<3u> > >, _oiter = __gnu_cxx::__normal_iterator<arma::row<double>::fixed<6u>*, std::vector<arma::row<double>::fixed<6u> > >, _binaryoperation = const arma::glue<arma::row<double>::fixed<3u>, arma::row<double>::fixed<3u>, arma::glue_join> (*)(const arma::base<double, arma::row<double>::fixed<3u> >&, const arma::base<double, arma::row<double>::fixed<3u> >&)]': ../armadillo_test/main.cpp:85:79: instantiated here /usr/include/c++/4.6/bits/stl_algo.h:4920:2: error: invalid initialization of reference of type 'const arma::base<double, arma::row<double>::fixed<3u> >&' look of type 'arma::row<double>::fixed<3u>'

i guess types/templates i'm using when calling arma::join_horiz wrong, can't figure out right syntax. thought ?

c++ vector armadillo

No comments:

Post a Comment