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

How to determine what operations are produced?

Tags: None
(comma "," separated)
SAnton
Registered Member
Posts
16
Karma
0
I see that expression templates can produce optimal code for non-optimal expressions. But how can I determine what code is produced?

I have found in other topic that
Code: Select all
(D.diagonal()*scalar).asDiagonal()

can multiply diagonal matrix D by the scalar without overhead. But how can I prove that? (Without looking into the assemply code produced by the compiler)

More important: how to detect bad expressions and how to find ways to improve them?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This is a tricky question. In general we try to avoid to make it easy to write poor code, but in doubt and for critical expressions you can still ask on this forum.
SAnton
Registered Member
Posts
16
Karma
0
Is .cast<TYPE> a no-op when matrix already has TYPE type?

Also I think it is possible to implement function like this which will report information about the code produced by the expression:
Code: Select all
A = (D.diagonal()*scalar).asDiagonal(); //Some expression
std::cout << eigen::report( A, (D.diagonal()*scalar).asDiagonal() ) //Report which code is generated
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
yes it's a no-op, like .conjugate() or .real() with non-complex scalar type.

Regarding a "report" mechanism as you suggest, yes this could be doable but that's quite a lot of work with a lot of code duplication, not very funny for the maintenance.


Bookmarks



Who is online

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