Hi. I wrote some routines to allow the use of functors (actually any
class member function) with Blitz. They are not really in a finished,
or even fully tested state, but I can give the source code to anyone
who's interested in using or finishing it. The idea is that you can
add something like
BZ_DECLARE_FUNCTOR(classname) // for one argument functors
BZ_DECLARE_FUNCTOR2(classname) // for two argument functors
or
BZ_DECLARE_FUNCTOR_RET(classname, returnType)
BZ_DECLARE_FUNCTOR2_RET(classname, returnType)
to a class that has an operator() defined and then you can use that class in
Blitz++ expressions. E.g.
A = C + classInstance(B * tensor::i);
or
A = C + classInstance(tensor::i, tensor::j)
It also works for member functions:
BZ_DECLARE_MEMBER_FUNCTION(classname, funcname)
BZ_DECLARE_MEMBER_FUNCTION2(classname, funcname)
or
BZ_DECLARE_MEMBER_FUNCTION_RET(classname, funcname, returnType)
BZ_DECLARE_MEMBER_FUNCTION2_RET(classname, funcname, returnType)
allows you to write stuff like
A = C + classInstance.funcname(B * tensor::i);
A = C + classInstance.funcname(tensor::i, tensor::j)
I've also got some support for classes where the source code is not available
or not to be tampered with, e.g.
A = C + applyFunctor(classInstance, B * tensor::i);
A = C + applyFunctor(classInstance, tensor::i, tensor::j);
(This version does not work for member functions.)
Just like any other blitz expression, none of these will produce temporaries.
This is all limited to one and two argument *constant* member
functions, not all of the functionality has been tested, and the
source code does not conform properly to blitz standards (it works
with gcc-2.95.2, 2.95.3, 3.0 and with KCC on Linux), and there are
some parts I copied blindly without understanding from the Blitz
source code, so those parts may be wrong. I've never benchmarked the
thing to see if it's useful for speed (but it's definitely convenient
and the parts I've tested seem to work fine). I've been using the
code for a few months. I keep intending to fix it up enough to submit
it for inclusion in Blitz++, but that never seems to happen. So I
thought I'd offer the "alpha" version to anyone who wants to use it or
work on it. Drop me a line if you'd like the code.
Derrick Bass
--------------------- blitz-dev list --------------------------------
* To subscribe/unsubscribe: use the handy web form at
http://oonumerics.org/blitz/lists.html
This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 04:30:12 EST