1

我正在尝试使用 Blitz++ 用户指南中的模板对象

#include <blitz/array.h>
using namespace blitz;

BZ_DECLARE_STENCIL4(test,P1,P2,P3,c)
    P3 = 2 * P2 + c * Laplacian3D(P2) - P1;
BZ_END_STENCIL

applyStencil(test(), P1, P2, P3, c);

但是编译后我有这个错误

test_blitz.cpp: In static member function ‘static void test::apply(T1&, T2&, T3&, T4&, T5, T6, T7, T8, T9, T10, T11) [with T1 = blitz::FastArrayIterator<long double, 3>, T2 = blitz::FastArrayIterator<long double, 3>, T3 = blitz::FastArrayIterator<long double, 3>, T4 = blitz::FastArrayIterator<long double, 3>, T5 = blitz::dummy<double>, T6 = blitz::dummy<double>, T7 = blitz::dummy<double>, T8 = blitz::dummy<double>, T9 = blitz::dummy<double>, T10 = blitz::dummy<double>, T11 = blitz::dummy<double>]’:
/usr/include/blitz/array/stencils.cc:288:13:   instantiated from ‘void blitz::applyStencil_imp(const T_stencil&, blitz::Array<T_numtype1, 3>&, T_array2&, T_array3&, T_array4&, T_array5&, T_array6&, T_array7&, T_array8&, T_array9&, T_array10&, T_array11&) [with T_stencil = test, T_numtype1 = long double, T_array2 = blitz::Array<long double, 3>, T_array3 = blitz::Array<long double, 3>, T_array4 = blitz::Array<long double, 3>, T_array5 = blitz::dummyArray, T_array6 = blitz::dummyArray, T_array7 = blitz::dummyArray, T_array8 = blitz::dummyArray, T_array9 = blitz::dummyArray, T_array10 = blitz::dummyArray, T_array11 = blitz::dummyArray]’
/usr/include/blitz/array/stencils.cc:535:5:   instantiated from ‘void blitz::applyStencil(const T_stencil&, blitz::Array<T_numtype1, N_rank>&, T_array2&, T_array3&, T_array4&) [with T_stencil = test, T_numtype1 = long double, int N_rank = 3, T_array2 = blitz::Array<long double, 3>, T_array3 = blitz::Array<long double, 3>, T_array4 = blitz::Array<long double, 3>]’
test_blitz.cpp:35:36:   instantiated from here
test_blitz.cpp:9:5: error: ‘Laplacian3D’ was not declared in this scope

其他数组操作(乘法、位置等)正在工作。谁能解释我做错了什么?

UPD

看起来我错过了标题blitz/array/stencil-et.h(在示例中stencil2.cpp),但还有另一个错误

test_blitz.cpp: In static member function ‘static void test::apply(T1&, T2&, T3, T4, T5, T6, T7, T8, T9, T10, T11) [with T1 = blitz::FastArrayIterator<long double, 3>, T2 = blitz::FastArrayIterator<long double, 3>, T3 = blitz::dummy<double>, T4 = blitz::dummy<double>, T5 = blitz::dummy<double>, T6 = blitz::dummy<double>, T7 = blitz::dummy<double>, T8 = blitz::dummy<double>, T9 = blitz::dummy<double>, T10 = blitz::dummy<double>, T11 = blitz::dummy<double>]’:
/usr/include/blitz/array/stencils.cc:288:13:   instantiated from ‘void blitz::applyStencil_imp(const T_stencil&, blitz::Array<T_numtype1, 3>&, T_array2&, T_array3&, T_array4&, T_array5&, T_array6&, T_array7&, T_array8&, T_array9&, T_array10&, T_array11&) [with T_stencil = test, T_numtype1 = long double, T_array2 = blitz::Array<long double, 3>, T_array3 = blitz::dummyArray, T_array4 = blitz::dummyArray, T_array5 = blitz::dummyArray, T_array6 = blitz::dummyArray, T_array7 = blitz::dummyArray, T_array8 = blitz::dummyArray, T_array9 = blitz::dummyArray, T_array10 = blitz::dummyArray, T_array11 = blitz::dummyArray]’
/usr/include/blitz/array/stencils.cc:515:5:   instantiated from ‘void blitz::applyStencil(const T_stencil&, blitz::Array<T_numtype1, N_rank>&, T_array2&) [with T_stencil = test, T_numtype1 = long double, int N_rank = 3, T_array2 = blitz::Array<long double, 3>]’
test_blitz.cpp:38:30:   instantiated from here
test_blitz.cpp:12:5: error: no matching function for call to ‘Laplacian3D(blitz::FastArrayIterator<long double, 3>&)’
test_blitz.cpp:12:5: note: candidates are:
/usr/include/blitz/array/stencil-classes.cc:15348:3: note: template<class T1> blitz::_bz_ArrayExpr<blitz::Laplacian3D_et<typename blitz::asExpr<T>::T_expr::T_range_result, typename blitz::asExpr<T>::T_expr::T_numtype> > blitz::Laplacian3D(const blitz::ETBase<T>&)
/usr/include/blitz/array/stencil-classes.cc:15356:3: note: template<class T, int N> blitz::_bz_ArrayExpr<blitz::Laplacian3D_et<typename blitz::asExpr<blitz::Array<T, N> >::T_expr::T_range_result, T> > blitz::Laplacian3D(const blitz::Array<T, N>&)
/usr/include/blitz/array/stencil-classes.cc:15361:3: note: template<class T, int N> blitz::_bz_ArrayExpr<blitz::Laplacian3D_et<typename blitz::asExpr<blitz::Array<T, N> >::T_expr::T_range_result, T> > blitz::Laplacian3D(blitz::Array<T, N>&)

有任何想法吗?

链接到带有错误消息的完整代码示例https://gist.github.com/erthalion/8784150

4

2 回答 2

1

我认为您缺少#include。也许#include <blitz/array/stencilops.h>,或者通过系统上的 blitz 标头 grep 来找到 Laplacian3D。

于 2014-02-01T12:31:47.100 回答
0

代替

BZ_DECLARE_STENCIL4(test,P1,P2,P3,c)
    P3 = 2 * P2 + c * Laplacian3D(P2) - P1;
BZ_END_STENCIL

尝试使用

BZ_DECLARE_STENCIL4(test,P1,P2,P3,c)
    P3 = 2 * P2 + c * Laplacian3D_stencilop(P2) - P1;
BZ_END_STENCIL

我的理解是这Laplacian是一个模板(就像你声明的那个),并且Laplacian3D_stencilop是一个模板运算符(就像一个差异运算符),你可以在你自己的模板对象中使用它。

于 2016-01-18T20:34:28.947 回答