
Boost : 
From: Sergei Katkovsky (kots_at_[hidden])
Date: 20020104 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: multiarray comments/questions
[..]
> How wise would it be to define the full set of operators?
> E.g., do you want them to work elementwise or as matrix
> operations (a * b), or elementwise (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 runtime 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 matrixalgebra operators here
> };
> class marray : public multi_array {
> // define the elementwise operators here
> };
> But this could easily lead to a proliferation of derived
> types (matrix algebra with < working as reduction,
> matrix algebra with < working elementwise, etc.).
Hello!
Although the "using operationsetnamespace" 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 elementwise
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 elementwise multiplication not only have different results, but also
different requirements for their arguments. Elementwise multiplication is
commutative, while matrix multiplication isn't.
Also I think it will be best (if possible) to define all multy_array
operations as elementwise (as in std::valarray). If one can simply say "all
operations are elementwise", it definitely will be less errorprone than
"subtraction is elementwise, comparison is lexicographical etc". And I
believe this is what most users expect.
And what if one needs both elementwise 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