Boost logo

Boost :

From: Sergei Katkovsky (kots_at_[hidden])
Date: 2002-01-04 06:15:23


> -----Original Message-----
> From: rwgk [mailto:rwgk_at_[hidden]]
> Sent: Friday, January 04, 2002 4:04 AM
> To: boost_at_[hidden]
> Subject: [boost] Re: multi-array comments/questions

[..]

> How wise would it be to define the full set of operators?
> E.g., do you want them to work element-wise or as matrix
> operations (a * b), or element-wise (a < b -> multiarray
> of bool) or as reductions (a < b -> one bool)?
>
> A few weeks ago I posted a proposal for a scheme that
> gives the user the choice of selecting the desired
> set of operators at run-time with a using directive.
> The basic idea:

[..]

> An alternative to my proposed scheme that I could think of
> is to use inheritance, e.g.:
> class matrix : public multi_array {
> // define the matrix-algebra operators here
> };
> class marray : public multi_array {
> // define the element-wise operators here
> };
> But this could easily lead to a proliferation of derived
> types (matrix algebra with < working as reduction,
> matrix algebra with < working element-wise, etc.).

Hello!

Although the "using operation-set-namespace" technique looks interesting and
pretty, my vote is for "alternative" scheme. Let me explain why.

First, I believe that "alternative" scheme is better because it seems more
"natural". The "natural" definition for (multi)arrays * is element-wise
multiplication, and for matrices is matrix multiplication. The matrices and
2d arrays are different objects, and moreover, different level objects. The
fact that 2d array is the only possible representation of matrix shouldn't
be confused with that. (One can compare this to tensor - matrix relation.
Although 2d rank tensors are often represented as matrices, they are
different objects with different sets of operations.)

Next, let's look at multiplication operation behavior. Matrix multiplication
and element-wise multiplication not only have different results, but also
different requirements for their arguments. Element-wise multiplication is
commutative, while matrix multiplication isn't.

Also I think it will be best (if possible) to define all multy_array
operations as element-wise (as in std::valarray). If one can simply say "all
operations are element-wise", it definitely will be less error-prone than
"subtraction is element-wise, comparison is lexicographical etc". And I
believe this is what most users expect.

And what if one needs both element-wise and matrix operations in the same
scope (though it's relatively rare situation)?

At last I think this scheme will have less compiler requirements.

Sergei Katkovsky

P.S. Sorry for bad English :(


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk