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
2206
Karma
15
OS
You can also look at NumTraits<typename MatrixType::Scalar>::IsInteger, ::IsComplex,, etc.

 
Reply to topic

Bookmarks



Who is online

Registered users: Alastair, apater, Baidu [Spider], Bing [Bot], Exabot [Bot], garthecho, ggael, Google [Bot], google01103, Horus, jitseniesen, Joif, kde-jriddell, ken300, La Ninje, Mamarok, mmistretta, Nuc!eoN, psbot [Picsearch], rbruce, renatoatilio, sacarde, sinclair, stephans, TheraHedwig, tienhung, wolfi323, Yahoo [Bot]