Blitz logo

Blitz Support :

From: Julian Cummings (cummings_at_[hidden])
Date: 2004-08-25 18:15:37


Hello Andre,

I understand why your code fails to compile, but I am a little puzzled
as to why it would have worked with the older gcc compiler and
blitz-0.6. The reason for the failure is that the constructor that
creates a blitz Array from an Array expression is labeled *explicit*,
meaning that implicit conversions are not allowed. This is important
for the workings of the expression template machinery that blitz uses to
evaluate Array expressions. We don't want the compiler to jump in and
start converting Array subexpressions into Arrays before an entire
expression can be evaluated. The solution is to store the Array
expression as a temporary Array before passing it into your functor, as
you did below. Actually, you don't need to name the temporary. You can
just explicitly construct it like this:

Z(Range::all(),j) = f(t_c[j],Array<Real,2>(x+Z(Range::all(),j)));

[Note: Here I have also replaced Range(j,j) with simply j. You can
slice an Array using an int rather than a Range of length one.] I'm
afraid that this explicit conversion of the Array expression to an Array
is required. I am surprised that this code used to work with gcc-2.95
and blitz-0.6. In the <blitz/array-impl.h> header file that I have from
the old blitz-0.6, the Array constructor taking a _bz_ArrayExpr (an
Array expression object) is labeled with "_bz_explicit". This macro is
defined to be the keyword "explicit" as long as the compiler supports
this feature of the C++ language. You might check the header file
<blitz/config.h> in your blitz-0.6 installation and see if BZ_EXPLICIT
is defined. I don't remember if this feature was properly supported in
gcc-2.95. It could be that the older compiler just accepted and ignored
"explicit".

Regards, Julian C.

Andre Massing wrote:

>Hello,
>
>A few months ago I wrote a numerical programm using the blitz++0.6 libary
>and gcc 2.95... The source-code was compiled without any problem.
>Meanwhile I updated to blitz0.7 and gcc 3.3.3 and now the the compiler gives
>some error messages, especially when I try to compute something inside
>the function argument. So here are some pieces of my code:
>
>Operatordefintion:
> Array<Real,2> DiffParser:: operator()(const Real& t, const Array<Real,2>& Vars);
>
>critical code:
>
>int newton(..., Array<Real,2>& Z,...)
>{
>.
>.
>Z = 0;
>.
>.
>//critical line:
>Z(Range::all(),Range(j,j)) = f(t_c[j],x+Z(Range::all(),Range(j,j)));
>.
>.
>}
>
>error-messages:
>
>g++ -c newton.cpp
>
>newton.cpp: In function `int newton(const Real&, const int&, const blitz::Array<Real, 2>&, DiffParser&,
>bool, const int&, Real&, bool&, const Real*, const Real*, const bool&, blitz::Array<Real, 2>&,
>blitz::Array<Real, 2>&, const int&, int&, const Real&, const Real&)':
>newton.cpp:148: error: no match for call to
>`(DiffParser) (Real&, blitz::_bz_ArrayExpr<blitz::_bz_ArrayExprOp<blitz::FastArrayIterator<Real, 2>,
> blitz::FastArrayIterator<Real, 2>, blitz::Add<Real, Real> > >)'
>
>DiffParser.h:25: error: candidates are:
>blitz::Array<Real, 2> DiffParser::operator()(const Real&, const blitz::Array<Real, 2>&)
>make: *** [newton.o] error 1
>
>For some reason the compiler complains about trying to compute "x+Z(Range::all(),Range(j,j))"
>inside the function f. It was possible to resolve this problem by introducing
>a temporary variable:
>XTEMP = x+Z(Range::all(),Range(j,j));
>Z(Range::all(),Range(j,j)) = f(t_c[j],XTEMP);
>
>Modifying the code this way results in a compilation without any errors, but
>it seems to me somewhat complicate, since the original code worked well under older versions
>of gcc and blitz++.
>Any ideas about the reason for that error?
>(Unfortunately I'am not that much experienced using blitz++, so sorry for my probably somewhat
>stupid question.)
>
>Best regards
>Andre
>
>
>
>_______________________________________________
>Blitz-support mailing list
>Blitz-support_at_[hidden]
>http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>
>

-- 
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