BZDEV: matrix product in Blitz

From: Allan Stokes [cbi] (allan@stokes.ca)
Date: Fri Dec 11 1998 - 21:08:02 EST


Hello all,

Luc Bourhis wrote yesterday about the efficiency of matrix product chains
under Blitz. He was concerned that the expression A*B*C would generate an
expression template which would lead to repetitive evaluations of A*B
sub-terms.

I thought I would try out this experiment and see exactly how Blitz behaves.
My experiments were conducted using the Intel compiler.

My discovery was that the matrix product support in Blitz is on the raw
side.

SAMPLE #1
  typedef TinyMatrix<double,3,2> spinor;
  typedef TinyMatrix<double,3,3> gauge;
  spinor()*gauge();

error: no operator "*" matches these operands
  operand types are: blitz::TinyMatrix<double, 3, 2> *
blitz::TinyMatrix<double, 3, 3>

It seems that Blitz does not support infix syntax.

SAMPLE #2
  typedef TinyMatrix<double,3,2> spinor;
  typedef TinyMatrix<double,3,3> gauge;
  spinor temp = product(gauge(),spinor());

error: no suitable user-defined conversion from
  _bz_tinyMatExpr<_bz_tinyMatrixMatrixProduct<double, double, 3, 3, 2, 3, 1,
2, 1>>
to spinor exists

Here we see that Blitz does not provide a valid copy constructor.

SAMPLE #3
  typedef TinyMatrix<double,3,2> spinor;
  typedef TinyMatrix<double,3,3> gauge;
  spinor temp;
  temp = product(gauge(),spinor());

This snippet becomes valid when making use of assignment rather than the
copy constructor.

SAMPLE #4
  typedef TinyMatrix<double,3,2> spinor;
  typedef TinyMatrix<double,3,3> gauge;
  spinor temp;
  temp = product(gauge(), product(gauge(),spinor()));

error: no instance of overloaded function "product" matches the argument
list
    argument types are: (TinyMatrix<double, 3, 3>,
    _bz_tinyMatExpr<_bz_tinyMatrixMatrixProduct<double, double, 3, 3, 2, 3,
1, 2, 1>>)

Here we see that Blitz does not (yet) directly support product chains. Of
course this can also be written out long-hand by explicitly declaring the
intermediate temporary.

When Blitz reaches the point where it _does_ allow product chain expressions
(I assume features are still evolving in this area), I suspect it will not
prove too difficult for Blitz to make sensible--though not
optimal--decisions about how to best perform the product evaluation.

Optimal evaluation of matrix product chains is a dynamic programming
problem. It would be quite a feat to find the optimal solution at compile
time through the use of template facilities.

Luc's concern seems to be based on the assumption that Blitz will generate
an evaluation strategy which does not introduce a temporary object--that the
entire expression will be "dragged" through the various layers of
iterations.

My understanding of Blitz is that it generates compound expression objects
(recursively) so that it can defer its choice of execution strategy until
the full expression is known. By providing specializations for different
kinds of expression object sub-structure I believe that Blitz is free to use
any implementation strategy which one might desire.

Do matrix product chains occur often enough to make it worth the trouble?

I'll end off here with a quick update on the Intel compiler.

Bretton Wade proved correct in his observation that the Intel 4.0 compiler
sometimes binds template methods incorrectly at runtime.

In some circumstances multiple instantiations are correctly generated at
compile time, yet at runtime only one of these instantiations proves to be
reachable. This is a somewhat scary state of affairs with regards to the
Blitz idiom.

Allan

--------------------- blitz-dev list --------------------------------
* To subscribe/unsubscribe: mail to majordomo@oonumerics.org, with
"subscribe blitz-dev" or "unsubscribe blitz-dev" in the body of the message
* Blitz++ web page: http://oonumerics.org/blitz/



This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 04:30:08 EST