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

 
Reply to topic

Bookmarks



Who is online

Registered users: Amadiro, andreas_k, Baidu [Spider], Bing [Bot], brandy_000, brunodog, ChemBro, davidemme, Deevad, Exabot [Bot], Google [Bot], iconberg, jmf, koriun, odysseus-art, paulus3005, rumangerst, rv8ter, Saabhero, slangkamp, TheraHedwig, tresmon, Yahoo [Bot], zekthedeadcow