Re: [eigen] Matrix multiplication seems to be exceptionally slow in one specific case

[ Thread Index | Date Index | More Archives ]

On Mon, 16 Jun 2014, Christoph Hertzberg wrote:

On 16.06.2014 17:02, Marc Glisse wrote:
On Mon, 16 Jun 2014, Christian Seiler wrote:

There has been a proposal for 'operator auto' in C++ because of this,
but there doesn't seem to be enough traction for it.

The latest related paper is:

and the committee will discuss it this week. If you have any comments,
please feel free to post them on:!forum/std-proposals

There is some resistance to this kind of change, so any extra
information (use cases, requirements, suggestions, etc) helps, not least
because it shows interest in the proposal.

While I like the idea in general, I'm not totally sure about that either.

If you have doubts about the proposal, they are just as welcome on the mailing list I mentioned ;-) Matrix expression-template libraries are the first expected customer for this feature...

This can bring very strange performance differences when switching between different C++ versions.
In some cases it might even degrade performance, e.g.:

I believe it is an acceptable side-effect. Beginner's code is safe by default and may require some tweaking to become as fast as possible; that's better than currently where their code is unsafe, has unpredictable behavior (to them) and just happens to sometimes be magically fast.

 auto AB = A*B;          // shall this evaluate into a temporary?

Write auto&& (or auto const&) if you don't want value semantics.

 MatrixXd result = AB+C; // actually, no explicit temporary AB required
                         // direct evaluation would have been better

Unless there is a second use of AB somewhere further in the code. I think there was an item in bugzilla or elsewhere about adding a profile mode that would among other things tell you if an expression was used enough times that it should have been evaluated eagerly?

What would also be confusing is that passing a product to
 template<class Matrix> void foo(const Matrix&);
will not do automatic 'auto'-conversion, but this would:
 auto X = expression;    // auto-conversion
 foo(X);                 // converted X
 foo(expression);        // no conversion

I think the best thing we can do on our side (and we can do that independently of changes in the standard) is to warn users about pitfalls with the auto-keyword. E.g., we could create a doxygen-page for that and link it prominently (from all starting guides, etc).

I posted a bug for that:

I added a similar warning to the GMP manual some time ago:

Marc Glisse

Mail converted by MHonArc 2.6.19+