std ::变换犰狳矢量的矢量

时间:2014-06-24 15:02:51

标签: c++ vector armadillo

我有2个std::vector< arma::rowvec::fixed<3> >,我想将这两个向量的每个元素连接在一起,这样我最终得到std::vector< arma::rowvec::fixed<3> >。使用for循环来实现arma::join_horiz()没有问题,但是在尝试使用std::transform而不是for循环时遇到了一些困难。我尝试了不同的解决方案,但总是遇到一些编译错误:

首次尝试:

// Create dummy vectors
arma::rowvec::fixed<3> A, B, C, D;
A << 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> >());

编译输出:

./armadillo_test/main.cpp: In function 'int main(int, char**)':
../armadillo_test/main.cpp:81:87: error: no matching function for call to '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>&)

基于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);

编译输出:

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 from 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> >&' from expression of type 'arma::Row<double>::fixed<3u>'

我想我在调用arma::join_horiz时使用的类型/模板是错误的,但我无法弄清楚正确的语法。有什么想法吗?

0 个答案:

没有答案