Boost logo

Ublas :

From: Michael Stevens (mail_at_[hidden])
Date: 2005-06-20 02:44:30


Hi Dan, interesting feedback,

On Sunday 19 June 2005 23:20, Dan Elliott wrote:

> > First we will need some syntax to tell uBLAS to expect the lvalue to be
> > an alias of something on the RHS and so to use a temporary. My suggestion
> > would be to add the 'alias' function thus:
> > alias (x) = expression;
>
> Would uBLAS still use aliasing by default when dealing with objects like
> matrix/vector ranges/slices? This must be what BLAS implementations
> (like GSL) do.

I can't find anything in the GSL documentation regarding alias. Since GSL is
very BLAS orientated I suspect the results are undefined if you have an
lvalue alias.

For me it would be best to have consistent behaviour for all types on the LHS.

> > Would the change of semantics be a big problem for anyone?
>
> Will a uBLAS neophyte still be able to use uBLAS without having to buy a
> padded helmet to prevent injury caused by repeatedly slamming their head
> against their keyboard out of utter frustration?
:-) :-)

> In other words, if I
> am ignorant of the fact that an operation requires aliasing, will my
> program still work?

I think the idea would be to check in DEBUG mode. That is if NDEBUG is not set
a temporary would always be used in assignment. The expression would be
executed twice (with and without the temporary) and the result compared.
uBLAS already does this in several places to check internal and users errors.

> I would like to express my feeling it is good library behavior to
> *always* provide the correct answer while *allowing* the intelligent
> user to optimize. I am under the impression that uBLAS, in its current
> state, gives us both.

I have to agree with the principle here. This is, I am sure, why Joerg and
Mathias chose these symantics in the design. On the other hand:
a) Most expressions don't involve and unsafe lvalue alias so the user has to
type noalias() a lot!
b) The general experience from BLAS is that no temporaries are used to make
thing safe. uBLAS avoids temporaries except in this case.
c) The test in DEBUG mode makes things nearly safe!

> Therefore, although this has been an
> enlightening, necessary conversation, I fear it is going to yield no
> additional features while decreasing its usability.

I guess in the end we are discussing such subjective matters as user
expectation and how willing they are to type noalias()!

Thanks,
        Michael