![]() |
Blitz Support : |
From: Julian Cummings (cummings_at_[hidden])
Date: 2005-05-24 16:55:54
Hello All,
I wanted to reply to the e-mail that Andrius Kurtinaitis posted here back on
April 12th about a test program that worked with blitz-0.7 but does not work
in blitz-0.8. (Sorry Andrius, but I lost your original e-mail, although it
is in the mailing list archive.) I understand what the problem is, but the
complete solution is non-trivial. I made changes in blitz-0.8 to migrate
the Array and "Array-like" classes to the "new" Expression Template
machinery (which is not so new anymore). In this ET system, the Array-like
classes all inherit from an ETBase class, and we use the Barton-Nackman
recursive template technique to manage expression evaluation. In such a
system, the Arrays act as a container class with elements that we iterate
over to evaluate an expression. The element type is typically some
"concrete data type" such as a built-in integral or floating-point type or
the std::complex type.
The question is, where do things like TinyVector fit in in this scheme?
They are often used as the element type of an Array. In many respects,
TinyVector is a concrete data type. But TinyVector is also a small
container with elements that you want to iterate over when performing math
operations. In the original blitz expression template scheme, the handling
of TinyVector objects is done in the same way as the Vector container class.
Convolving the expression template treatment of TinyVector and Vector is a
mistake, IMO, because it complicates handling TinyVector as a typical
concrete data type. Currently, the TinyVector and Vector classes (along
with a whole bunch of "Vector-like" types) are operating under a separate
"old" Expression Template machinery in which all of the possible binary
operation combinations are written out explicitly. There is no "link"
between this set of classes and the Array-like classes, so they cannot
interact in math expressions. This is probably a good thing since the
semantics of Arrays and Vectors are fairly distinct.
I found a relatively simple way to at least resolve the problem that Andrius
reported. His test code was trying to multiply an Array of TinyVectors of
complex<double> by a TinyVector of double. This expression should simply
multiply each element of the Array by the "scalar" TinyVector of double
object. What I have done to address this problem is to extend the
definition of Array/scalar binary operations in <blitz/array/ops.h> to
include Array/TinyVector binary operations. So now you will be able to
perform binary math operations between an Array of arbitrary element type
and a TinyVector of any
element type (including complex) and any dimension. Of course, the binary
operation between the Array's element type and the TinyVector type must be
defined. The definitions for binary ops between TinyVectors or TinyVectors
and scalars will still be provided by the old ET machinery in
<blitz/vector-et.h> for the time being. Longer term, I would prefer to
separate out the TinyVector binary ops from <blitz/vector-et.h> and then
experiment with replacing TinyVector with the tvmet Vector class, which has
improved coding for TinyVector-type operations.
Any comments about these topics and my proposed changes are most welcome.
Regards, Julian C.
Dr. Julian C. Cummings Office: PB-111
Caltech/CACR, MC 158-79 Phone: 626-395-2543
1200 E. California Blvd. Fax: 626-584-5917
Pasadena, CA 91125
Dr. Julian C. Cummings Office: PB-111
Caltech/CACR, MC 158-79 Phone: 626-395-2543
1200 E. California Blvd. Fax: 626-584-5917
Pasadena, CA 91125