![]() |
Blitz Support : |
From: Andrius Kurtinaitis (andrius.kurtinaitis_at_[hidden])
Date: 2003-12-10 05:24:08
Hello,
thank you for the quick reply.
I have three ternary functions and a long expression where I want to use
these expressions like that:
result[1] = (a_very_long_expression) + ternary_funtion_1( a1, a2, a3 );
result[2] = (a_very_long_expression) + ternary_funtion_2( a1, a2, a3 );
result[3] = (a_very_long_expression) + ternary_funtion_3( a1, a2, a3 );
I do not want to repeat the long expressions like this because they are
really long and I edit them sometimes and I want to keep them identical.
I can't define long expressions as functions because they would take
more than three arguments.
I could write that the other way:
for(int i=0; i<3 i++)
result[i] = (a_very_long_expression);
result[1] += ternary_funtion_1( a1, a2, a3 );
result[2] += ternary_funtion_2( a1, a2, a3 );
result[3] += ternary_funtion_3( a1, a2, a3 );
But then, according to blitz manual, the loops will not be optimized so
well. Maybe this is not so important at the moment...
I have another one question. I am coding a leap-frog-like finite
difference scheme. But I do not see any way in blitz++ to apply a
stencil to only even (or only odd) components of the Array. Is it not
possible with blitz++ or I simply did not found it yet?
Kind regards,
Andrius
Navneet Dalal wrote:
> Hi Andrius,
>
> By using the BZ_DECLARE_FUNCTION3 macro, overloaded versions of the
> ternary functions are the provided.
> Some struct's are also defined but they are internal to the blitz and
> ideally these should not concern users.
>
> 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
> }
>
> If this is not the case, send a complete example of what you want.
>
> On Wed, 10 Dec 2003 09:31:22 +0200, Andrius Kurtinaitis
> <andrius.kurtinaitis_at_[hidden]> wrote:
>
>> Hello,
>> what is the type of the defined ternary functions?
>> It seems it is a template struct. But is there some short way to
>> specify the type?
>> My problem is that I want to choose one of three functions which
>> should be used in an expression depending on some other parameter.
>> Andrius
>>
> _______________________________________________
> Blitz-support mailing list
> Blitz-support_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>
>