Boost logo

Ublas :

From: Michael Stevens (mail_at_[hidden])
Date: 2005-06-22 04:49:21

Hi Karl,

On Monday 20 June 2005 10:22, Karl Meerbergen wrote:
> Would it be easy to detect? I guess this is so for some expressions.
> For example, we could introduce
> safe( x ) = expression
> where safe creates a temporary whenever it is not sure a temporary is not
> needed. This would be an alternative to
> alias( x ) = expression
> that always creates a temporary.

I like your 'safe' with your described semantics.

> > b) The general experience from BLAS is that no temporaries are used to
> > make thing safe. uBLAS avoids temporaries except in this case.
> I am not sure I understand this. The user of BLAS calls has to make sure
> that arrays do not overlap (except for read only arrays I suppose). So the
> user may have to create temporaries to avoid possible messing up of arrays.
> Do I understand something wrongly?

I think I expressed myself badly.
What I meant is that BLAS calls don't create their own temporaries. So a user
 of BLAS expects to have to deal with aliases themselves.
Also uBLAS expression templates exist to avoid temporaries. The only place
uBLAS uses temporaries is in the assignment to lvalues.

By defaulting to unsafe assignment we would be following BLAS and also the
rest of the uBLAS aim of avoiding temporaries.

> Generally speaking, we have two potential classes of users: those who want
> efficient code and reduce the creation of a large number of temporaries,
> where this may lead to a significant overhead. And those who want safe
> code. Both mechanisms should be there, and the syntax might be a bit more
> complicated for the experienced programmer, i.e. those who want efficient
> code. The 'safe' could avoid aliasing when possible, as explained above.