Blitz logo

Blitz Support :

From: Julian Cummings (cummings_at_[hidden])
Date: 2004-09-09 12:37:38


Hi Eddie,

Assuming that the scalar is a constant for the entire array operation,
the most straightforward way to do this is to convert your function into
a functor (a struct with an operator() that performs the operation on a
pair of elements from the two arrays). The constructor for your functor
would take the scalar as an argument and store it. Something like this:

// original function
double foo(double a1, double a2, double scalar1) {/* ... */}

// new functor
struct functor {
    double scalar_m;
    functor(const double& scalar) : scalar_m(scalar) {}
    double operator()(double a1, double a2) { return foo(a1,a2,scalar_m); }
BZ_DECLARE_FUNCTOR2(functor)
};

The BZ_DECLARE_FUNCTOR macro will allow your new functor to operate on
blitz Arrays just like the BZ_DECLARE_FUNCTION macros do for functions
(see the header file <blitz/array/functorExpr.h> for more details).
 Just construct an instance of the functor with the scalar value and
then apply the functor to your Arrays.

We could produce a BZ_DECLARE_FUNCTION3_SCALAR macro, but the
combinations start to get a bit cumbersome at this point. You have to
handle all the possible combinations of two Arrays and one scalar or one
Array and two scalars. I recommend using the functor approach to handle
scalar parameters within an Array function.

Regards, Julian C.

Eddie.Breeveld_at_[hidden] wrote:

>Dear All,
>
>There is a "#define BZ_DECLARE_FUNCTION2_SCALAR(name, sca)" definition
>within Blitz - how easy would it be to implement a ternary equivalent?
>
>We would like to have a function that operates element wise on two arrays,
>and uses a scalar to modify the operation. e.g.,
>Function(Array1,Array2,scalar)
>
>Is it simply a combination of the BZ_DECLARE_FUNCTION2_SCALAR and
>BZ_DECLARE_FUNCTION3 declarations?
>
>All the best,
>Eddie
>
>____________________
>Edward Breeveld
>eSolutions
>Watson Wyatt LLP
>Watson House, London Road,
>Reigate, Surrey, RH2 9PQ, UK
>Tel. +44 (0)1737 274151
>Fax. +44 (0)1737 241496
>www.watsonwyatt.com
>
>_________________________________________________________________
>
>Notice of Confidentiality
>
>This transmission contains information that may be confidential and that may also be privileged. Unless you are the intended recipient of the message (or authorised to receive it for the intended recipient) you may not copy, forward, or otherwise use it, or disclose it or its contents to anyone else. If you have received this transmission in error please notify us immediately and delete it from your system. Please contact the sender if you have any problems with this email.
>
>In the UK, Watson Wyatt LLP is authorised and regulated by the Financial Services Authority and is a member of the General Insurance Standards Council. The services of Watson Wyatt in Ireland are provided by Watson Wyatt LLP, a limited liability partnership incorporated under English Law, with the exception of services which are provided as a Multi-Agency Intermediary, which for regulatory purposes, are provided by Watson Wyatt Partners, which is regulated by the Irish Financial Services Regulatory Authority, on behalf of Watson Wyatt LLP.
>
>_________________________________________________________________
>_______________________________________________
>Blitz-support mailing list
>Blitz-support_at_[hidden]
>http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>
>

-- 
Dr. Julian C. Cummings                       E-mail: cummings_at_[hidden]
California Institute of Technology           Phone:  626-395-2543
1200 E. California Blvd., Mail Code 158-79   Fax:    626-584-5917
Pasadena, CA 91125