00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef REDUCTION_LOC_H
00012 #define REDUCTION_LOC_H
00013
00014
00015 #include "PETE/IpplExpressions.h"
00016
00017
00018 template<unsigned D> class NDIndex;
00019 template<class T, unsigned int D> class BareFieldIterator;
00020 template<class T, unsigned int D> class IndexedBareFieldIterator;
00021
00023
00024
00025
00026 template<class T, class CompOp, class AccOp, unsigned D>
00027 typename T::PETE_Return_t
00028 Reduction(const PETE_Expr<T>& const_expr,
00029 CompOp comp_op,
00030 AccOp acc_op,
00031 NDIndex<D>& loc);
00032
00033
00034
00035 template <unsigned int D>
00036 struct FindLocation
00037 {
00038 typedef int PETE_Return_t;
00039 NDIndex<D>* Loc;
00040 FindLocation(NDIndex<D>& loc) : Loc(&loc) {}
00041 };
00042
00043
00044
00045 template <class T, class C, unsigned int D>
00046 inline int
00047 for_each(const IndexedBareFieldIterator<T,D>& expr,
00048 FindLocation<D>& find_loc, C)
00049 {
00050 int loc[D];
00051 expr.GetCurrentLocation(loc);
00052 for (unsigned d=0; d<D; d++) (*(find_loc.Loc))[d] = Index(loc[d],loc[d]);
00053 return 0;
00054 }
00055
00056 template <class T, class C, unsigned int D>
00057 inline int
00058 for_each(const BareFieldIterator<T,D>& expr, FindLocation<D>& find_loc, C)
00059 {
00060 int loc[D];
00061 expr.GetCurrentLocation(loc);
00062 for (unsigned d=0; d<D; d++) (*(find_loc.Loc))[d] = Index(loc[d],loc[d]);
00063 return 0;
00064 }
00065
00067
00068
00069
00070
00071
00073
00074 #ifdef __MWERKS__
00075
00076
00077
00078 template<class T, unsigned D>
00079 struct MMMin {
00080 typedef typename T::PETE_Expr_t::PETE_Return_t type_t;
00081 static inline type_t apply(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
00082 return Reduction(Expressionize<typename T::PETE_Expr_t>::apply( expr.PETE_unwrap().MakeExpression() ),
00083 OpLT(), OpMinAssign(),loc);
00084 }
00085 };
00086
00087 template<class T, unsigned D>
00088 inline typename MMMin<T,D>::type_t
00089 min(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
00090 return MMMin<T,D>::apply(expr, loc);
00091 }
00092 #else
00093 template<class T, unsigned D>
00094 typename T::PETE_Expr_t::PETE_Return_t
00095 min(const PETE_Expr<T>& expr, NDIndex<D>& loc)
00096 {
00097 return Reduction(Expressionize<typename T::PETE_Expr_t>::apply(expr.PETE_unwrap().MakeExpression()),
00098 OpLT(),OpMinAssign(),loc);
00099 }
00100 #endif // __MWERKS__
00101
00102 #ifdef __MWERKS__
00103
00104
00105
00106 template<class T, unsigned D>
00107 struct MMMax {
00108 typedef typename T::PETE_Expr_t::PETE_Return_t type_t;
00109 static inline type_t apply(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
00110 return Reduction(Expressionize<typename T::PETE_Expr_t>::apply( expr.PETE_unwrap().MakeExpression() ),
00111 OpGT(), OpMaxAssign(),loc);
00112 }
00113 };
00114
00115 template<class T, unsigned D>
00116 inline typename MMMax<T,D>::type_t
00117 max(const PETE_Expr<T>& expr, NDIndex<D>& loc) {
00118 return MMMax<T,D>::apply(expr, loc);
00119 }
00120 #else
00121 template<class T, unsigned D>
00122 typename T::PETE_Expr_t::PETE_Return_t
00123 max(const PETE_Expr<T>& expr, NDIndex<D>& loc)
00124 {
00125 return Reduction(Expressionize<typename T::PETE_Expr_t>::apply(expr.PETE_unwrap().MakeExpression()),
00126 OpGT(),OpMaxAssign(),loc);
00127 }
00128 #endif // __MWERKS__
00129
00131
00132 #include "Field/ReductionLoc.cpp"
00133
00134 #endif // REDUCTION_LOC_H
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144