This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Problem with VS 2005: Could not deduce template argument.

Tags: None
(comma "," separated)
-Roman-
Registered Member
Posts
16
Karma
0
Hi,

this problem is most probably not directly related to Eigen. The following code compiles just fine with GCC 4.2, but gives a 'could not deduce template argument' compile time error on VS 2005:

Code: Select all
template <int T>
Eigen::Matrix<double, T, 1> clamp01 (const Eigen::Matrix<double, T, 1>* const v_) {
   Eigen::Matrix<double, T, 1> v (*v_);
   for (int i=0;i<T;++i) {
      if ((*v_)[i] > 1)
         v[i] = 1;
      else if ((*v_)[i] < 0)
         v[i] = 0;
   }
   return v;
};


Code: Select all
error C2784: 'Eigen::Matrix<double,T,1> clamp01(const Eigen::Matrix<double,T,1> *const )' : could not deduce template argument for 'const Eigen::Matrix<double,T,1> *const ' from 'Vector4 *__w64 '


Vector4 is declared as

Code: Select all
typedef Eigen::Vector4d Vector4


I would be deeply grateful for hints on how to resolve this issue.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
I don't have MSVC to test, but the quickest work-around that I can think of, is to make your function templated in VectorType, like:

Code: Select all
template <typename VectorType>
VectorType clamp01 (const VectorType* v_) {
   VectorType v (*v_);
   for (int i=0;i<T;++i) {
      if ((*v_)[i] > 1)
         v[i] = 1;
      else if ((*v_)[i] < 0)
         v[i] = 0;
   }
   return v;
}


(The 2nd "const" here was really useless, in my humble opinion)

Also, note that Eigen already provides the possibility to implement custom coeff-wise operations like this, that will be more efficient, see:
http://eigen.tuxfamily.org/dox/classEig ... 045c8a2e9e


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
-Roman-
Registered Member
Posts
16
Karma
0
Thanks a lot! I used your suggested custom coeff-wise implementation and it works like a charm. I even notice a slight overall increase in the performance of my application! :)


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]