Reply to topic

Get the coefficient type of a matrix

updogliu
Registered Member
Posts
13
Karma
0
OS
I want to write a template function that only works for matrix with float(float/double in C++) type. How do I get the coefficient type of a matrix and check if it is an integer type or float type?
Code: Select all
template<typename Matrix> inline
void Covariance(const Matrix &mat) {
...;
}
Dee33
Registered Member
Posts
54
Karma
0
OS
you can use
Code: Select all
if (Eigen::internal::is_same<typename Matrix::Scalar float>::value) { ... }

is_same is a generic struct defined in Eigen as :
Code: Select all
template<typename T, typename U> struct is_same { enum { value = 0 }; };
template<typename T> struct is_same<T,T> { enum { value = 1 }; };
User avatar ggael
Moderator
Posts
2195
Karma
15
OS
You can also look at NumTraits<typename MatrixType::Scalar>::IsInteger, ::IsComplex,, etc.

 
Reply to topic

Bookmarks



Who is online

Registered users: AGB, anli, Baidu [Spider], bilbo, Bing [Bot], bshah, Exabot [Bot], garthecho, Google [Bot], google01103, Hans, jensreuterberg, jsirek, jstaniek, koriun, metzman, MiceAreVeryNice, MSNbot Media, paulus3005, pedrorodriguez, Sentynel, vascobasque, Yahoo [Bot]