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

How to get evaluated expression type of MatrixBase?

Tags: None
(comma "," separated)
Tal
Registered Member
Posts
30
Karma
0
Scenario:
I'm writing a template function that take a const MatrixBase<Derived>& parameter.
I want to take this matrix and perform operations on it, when it's better to have it evaluated first, instead of evaluating the matrix on every access.

If I was on C++ 11+ only, I would have done:
Code: Select all
auto evaledMat = mat.eval();
// Access evaledMat how much we want now


But prior to C++ 11, how can I do it?

At first I did:
Code: Select all
const typename Derived::PlainObject& evaledMat = mat;
// Access evaledMat how much we want now


But even when it's valid, if the Derived is kind of Map, it get copied to a plain object which is bad.

1. What typedef should I use?
2. Is it on documentation? If not, please add it.


User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
There is typename Derived::EvalReturnType.

Also, if you know what you want but avoid copying Map of sub-matrices, you can use Ref:

Ref<const Matrix3f> evaluatedMat = mat;

You can also combine it with PlainObject:

Ref<const typename Derived::PlainObject> evaluatedMat = mat;

The advantage of Ref<> is that you more precisely control what you will get, for instance you can control alignment and stride requirements.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar