Blitz logo

Blitz Support :

From: Breeveld, Eddie \(Reigate\) (Eddie.Breeveld_at_[hidden])
Date: 2005-04-04 07:01:29


Hi Derrick and Patrick,

This is brilliant! My C++ is 'improving', and the routine Derrick
suggested works. I have modified Derrick's suggestion by using a cast
to remove the temporary array, and I'm also passing the array as a const
by reference to avoid too much copying:

template<class T_expr> inline
typename _bz_ArrayExpr<T_expr>::T_numtype
Afun(const blitz::_bz_ArrayExpr<T_expr> &expr)
{
   typedef blitz::_bz_ArrayExpr<T_expr> exprT;
   return Afun(
        (blitz::Array<typename exprT::T_numtype, exprT::rank>)expr );
}

I am now trying to do something similar for functions that return arrays
different shapes to the original. What are the other class members of
_bz_ArrayExpr?

Patrick, a sample program that does not compile in Microsoft VS.NET 7.1
would be

        #include "c:\program files\blitz-0.8\blitz\array.h"
        BZ_USING_NAMESPACE(blitz)

        template<typename T, int N> inline
        T RTSumAll(const Array<T,N> A)
        {
           // complex processing in here ...
           return sum(A);
        };

        int main(int argc, char* argv[])
        {
           Array<double, 2> fund(2,2);
           fund = 3.0;
           double rate = RTSumAll(fund * 6.0);
        }

It would be interesting to know if it works with other compilers.

All the best,
Eddie

-----Original Message-----
From: Derrick Bass
Sent: 04 April 2005 09:44
To: Breeveld, Eddie (Reigate)
Subject: Re: [Blitz-support] Functions that take array expressions

There is no way to do this directly. If you are really good at C++, you
can take a look at the code for similar blitz functions like sum() and
try to do something similar. If you are willing to have a single
temporary array, though, then something like this should work:

template<class T_expr>
inline
typename _bz_ArrayExpr<T_expr>::T_numtype Afun( blitz::_bz_ArrayExpr<
T_expr> expr) {
        typedef blitz::_bz_ArrayExpr<T_expr> exprT;
           blitz::Array< typename exprT::T_numtype, exprT::rank > A( expr
);
        return Afun( A );
}

_________________________________________________________________

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.

_________________________________________________________________