![]() |
Blitz Support : |
From: Julian Cummings (cummings_at_[hidden])
Date: 2003-07-16 12:47:27
Hi Simon,
An array expression type can be assigned to an array, but they are not
the same type. So there is no implicit conversion that the compiler
can use to let you pass A+B into your function as an Array. However,
Blitz does provide an explicit Array constructor that takes a _bz_ArrayExpr
as its argument. So you should be able to say something like
Array<double,2> A, B, C, D;
D = function(Array<double,2>(A+B), C);
You have to explicitly convert the array expression into the resulting
array type.
The constructor must be explicit to avoid unintended conversions that would
foul up array expression evaluation usings expression templates.
It's not as elegant as you would like, but that is the best that Blitz
can do. The
Pooma library supports passing expressions as function arguments by using an
additional abstraction layer called an engine. All Pooma Arrays contain
an Engine
that supplies the array values, and this can be done using a block of
memory or by
evaluating a function or an expression. In this design, an array
expression is nothing
more than an Array with an ExpressionEngine in it, and it can be passed
to any
function expecting an Array. The price for this elegant syntax and
additional
abstraction is a somewhat more complicated expression evaluation
machinery that
can lead to performance penalties depending on the C++ compiler you use.
Regards, Julian C.
Simon Perreault wrote:
>Hi,
>
>I am having trouble finding how to write a function that takes blitz arrays as
>arguments. This is the current function prototype:
>
>template<class T>
>Array<T,2> function(const Array<T,2>& x, const Array<T,2>& y);
>
>This works fine for this kind of statement:
>
>C = function(A, B);
>
>But then suppose I want to do something like this:
>
>D = function(A+B, C);
>
>Then the function receives a _bz_ArrayExpr<...> for the first argument. I
>think I need to wrap my algorithm into some kind of expression class, am I
>right? How should I go about it? Any reference I should read?
>
>Thanks
>
>
>
-- 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