Chris Hecker wrote:
>Todd Veldhuizen wrote:
>> A = product(B, C);
>> for a matrix product on our desktop Mac.
>
>Yes, we can write it (and even as A = B * C; in C++, if you're into that
>sort of thing), but I think it's unclear how to make it both easy to use and
>efficient. If you want your code to look exactly like that, what does
>product(,) return? My experience is with C++, where this becomes a real
>problem. product(,) can't return strictly by value or you've just copied
>the A matrix. It can't return by reference for obvious reasons.
I would do something like A.product(B,C);
A is created by the caller, and dilemmas about what to
return are avoided. It doesn't solve the problem of overloading "=",
but it still makes code which is very readable.
> ... what do you get
>when you do this: D = A; Is D a new copy of A, or just another reference to
>its data? Do you give it copy on write semantics?
In this case, D is a new copy of A. If you want D to be a reference to A,
you can do that with something like:
Matrix& D = A;
I agree that there are many issues like this in linear algebra operations,
but generally they are solvable, and there really isn't anything wrong with
doing some procedural stuff like product(B,C,A); when necessary.
The 'mixed language' programming that Todd mentioned is, I think, a selling
point for object-orientation, giving a combination of elegance at the
algorithm level and speed where it's needed.
Alan
This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:05 EST