![]() |
Blitz Support : |
From: Julian Cummings (cummings_at_[hidden])
Date: 2003-12-10 14:41:46
Hello Navneet,
Navneet Dalal wrote:
>
> Coming to your problerm (if I understood it right) you want to define,
> let us say, two functions:
>
> double gauss(double val, double mean, double var);
> float gauss(float val, float mean, float var);
>
> And then you would like to evaluate gauss on a Array<double,1> or on a
> Array<float,1>.
> For this, you just use BZ_DECLARE_FUNCTION3 as:
>
> BZ_DECLARE_FUNCTION3(gauss);
>
> int main() {
> Array<double,1> a(10);
> Array<float ,1> b(10);
>
> // initialize arrays
> Array<double,1> resA(10);
> resA = gauss(a, 0, 10); // 0 mean and 10 var
>
> Array<float ,1> resB(10);
> resB = gauss(b, 2, 5); // 2 mean and 5 var
> }
Just an aside: this example is not a proper trinary function. A trinary
function would act on three arrays of data. What you have here is a
function that acts on a single array of data and requires two additional
scalar input parameters. Such a function would best be captured in
blitz by implementing it as a functor object that is initialized with
values for the two scalar parameters. The functor would store these
parameters as member data and operate on an array by providing an
operator() method. See <blitz/array/functorExpr.h> for details.
-- Julian C.
P.S. Apparently, trinary and ternary are synonyms, but ternary is the
more commonly used term for an operator taking three arguments.
-- 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