c++ - Eigen MatrixBase template function -


i don't know how fix following code:

template <class derived, class otherderived> void forw_sub(const matrixbase<derived>& l, const matrixbase<derived>& b,               matrixbase<otherderived> const & x) {     typedef typename derived::scalar scalar;      matrixbase<otherderived>& x_ = const_cast< matrixbase<otherderived>& >(x);      for(int i=0; < l.rows(); i++) {         scalar s = b(i);         for(int j=0; j < i; j++) {             s -= l(i,j)*x_(j);         }         x_(i) = s/l(i,i);     } } 

which when called:

matrixxd l = matrix3d::identity(); vectorxd b = vector3d::ones(); vectorxd x = vector3d::zero();  forw_sub(l,b,x); 

generates error:

/home/vision/workspace/sci-comp/test/test_leq.cpp: in member function ‘virtual void leq_forw_sub_test::testbody()’: /home/vision/workspace/sci-comp/test/test_leq.cpp:15:16: error: no matching function call ‘forw_sub(eigen::matrixxd&, eigen::vectorxd&, eigen::vectorxd&)’ /home/vision/workspace/sci-comp/test/test_leq.cpp:15:16: note: candidate is: /home/vision/workspace/sci-comp/src/leq/leq.hpp:5:6: note: template<class derived, class otherderived> void forw_sub(const eigen::matrixbase<t>&, const eigen::matrixbase<t>&, const eigen::matrixbase<u>&) 

compiling clang generates error:

/home/vision/workspace/sci-comp/test/test_leq.cpp:15:2: error: no matching function call 'forw_sub'     forw_sub(l,b,x);     ^~~~~~~~ /home/vision/workspace/sci-comp/src/leq/leq.hpp:5:6: note: candidate template ignored: failed template argument       deduction 

void forw_sub(const matrixbase& l, const matrixbase& b, ^ 1 error generated.

your declaration requires l , b of same type while in case 1 matrixxd , other vectorxd. proposed solution:

template <class derivedl, class derivedb, class derivedx> void forw_sub(const matrixbase<derivedl>& l, const matrixbase<derivedb>& b,               matrixbase<otherderivedx> const & x) { ... } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -