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

Get the coefficient type of a matrix

Tags: None
(comma "," separated)
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
3447
Karma
19
OS
You can also look at NumTraits<typename MatrixType::Scalar>::IsInteger, ::IsComplex,, etc.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]