![]() |
Blitz Support : |
From: Patrick Guio (Patrick.Guio_at_[hidden])
Date: 2005-04-01 11:58:19
On Fri, 1 Apr 2005, Breeveld, Eddie (Reigate) wrote:
> Dear Blitz++ Support,
>
> We use a lot of functions that take Blitz++ arrays, and these work fine
> provided we do not supply an array expression as an argument. For
> instance, if we have a function "Afun", and a Blitz++ array "arrayArg",
> our functions work well with
>
> result = Afun (arrayArg);
>
> Here "Afun" is defined as a templated function to take Blitz arrays of
> any rank and shape:
>
> template<typename T, int N> inline
> T Afun (const Array<T,N> &arrayArg)
> {
> // some function that returns (in this case) a scalar of type T
> ...
> };
>
> Unfortunately this does not work with expressions as arguments. How do I
> define a function that will work with both arrays directly (as above)
> and expressions such as
>
> result = Afun (arrayArg + 6);
> result = Afun (arrayArg1 * arrayArg2);
> result = Afun (arrayArg1 * Bfun(arrayArg2 * arrayArg3) + 11.56);
>
> I can set up temporary arrays to hold the intermediate results, but this
> is very awkward in our code, as some of it is automatically generated. I
> can also cast the result of the expression back into an array, but again
> this works but is awkward. I would much rather have one or more
> templated functions that can take arrays directly, as well as
> expressions involving arrays.
>
Hi Eddie,
I think you should pass the argument by value instead of by reference.
> template<typename T, int N> inline
> T Afun (const Array<T,N> arrayArg)
instead of
> template<typename T, int N> inline
> T Afun (const Array<T,N> &arrayArg)
Sincerely,
Patrick