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

Getting the base scalar type of a MatrixBase object

Tags: None
(comma "," separated)
User avatar
fasih
Registered Member
Posts
3
Karma
0
If I have a function defined as
Code: Select all
template <typename Derived>
int foo(MatrixBase<Derived>& mat);

and I call it like so:
Code: Select all
Matrix<uint16_t, Dynamic, Dynamic> data;
int return_code = foo<Matrix<uint16_t, Dynamic, Dynamic>>(data);

how can I, inside the `foo()` function, obtain the underlying scalar type of the `mat` input argument, namely, `uint16_t`? Is there a typedef that I can invoke on `Derived` to get at that underlying type?

(I need this in order to read from disk: I'll wind up calling `sizeof()` on this type, i.e., `uint16_t`. I'd rather not template `foo` using this scalar type because I'd like the function to be as general as possible, working with static and dynamic Eigen matrixes. This is based on the examples at http://eigen.tuxfamily.org/dox/TopicFun ... Types.html)
User avatar
fasih
Registered Member
Posts
3
Karma
0
I noticed the `Scalar` typedef while reading http://eigen.tuxfamily.org/dox/MatrixBa ... ource.html (source, I couldn't seem to find a reference to this typedef in the regular docs?) and it works a treat. Inside `foo()`, I can do:
Code: Select all
typedef typename Derived::Scalar Scalar;

and work with `Scalar` (for reading bytes from disk, e.g.).
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Indeed, we have a lot of issues with doxygen not being able to properly understand Eigen's code. Regarding this specific issue, I filled a bug entry: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=728


Bookmarks



Who is online

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