From: Andreas R. <and...@we...> - 2005-12-08 15:45:02
|
Hello. If I define a stencil operator like described in the docu: BZ_DECLARE_STENCIL_OPERATOR1(IsLocalMaximum2D, A) return (A(0,0) > A( 0, 1) && A(0,0) > A( 1, 0) && A(0,0) > A( 1, 1) && A(0,0) > A( 0,-1) && A(0,0) > A(-1, 0) && A(0,0) > A(-1,-1) && A(0,0) > A(-1, 1) && A(0,0) > A( 1,-1) ? 1 : 0); BZ_END_STENCIL_OPERATOR and use it like shown below (in getPeaks(...)), it compiles, but crashes if the following code line is omitted. In array/stencil-et.h I found the same for Laplacian2D: BZ_ET_STENCIL(IsLocalMaximum2D, P_numtype) The follwing code compiles without warnings and runs without problems (as long as we do not use const modifier for the Array): Array<float, 2> getPeaks(Array<float, 2> last_observed) { // ... Array<float, 2> is_local_maximum( IsLocalMaximum2D(last_observed) ); // ... } #define printVar(x) std::cout << #x << "="; std::cout << "`" << x << "'\n" If const Array<float, 2> or const Array<float, 2>& is used, we get a warning and a failure: Array<float, 2> getPeaks(const Array<float, 2>& last_observed) { // ... printVar(last_observed.shape()); Array<float, 2> is_local_maximum( IsLocalMaximum2D(last_observed) ); // <= line 516 printVar(is_local_maximum.shape()); // ... } The following warning message is printed during compilation: StencilsPrice.cpp: In member function `blitz::Array<float, 2> PriceDefectMarker2DStencilWrapper::getPeaks(const blitz::Array<float, 2>&)': StencilsPrice.cpp:516: warning: passing `float' for converting 1 of ` blitz::Array<T, N>::Array(int, blitz::GeneralArrayStorage<N_rank>) [with P_numtype = float, int N_rank = 2]' And when the program runs (in the code without const they have the same size): last_observed.shape()=`2 [ 258 258 ]' is_local_maximum.shape()=`2 [ 0 0 ]' So, for some reason the stencil behaves differently for const and non-const arrays. Is it Blitz, gcc, or am I doing something wrong? Blitz version: 0.9. gcc (GCC) 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8) Regards, Andreas R. |