00001 #ifndef Impala_Core_Array_Trait_TalkNgbExtra2P2Loop_h
00002 #define Impala_Core_Array_Trait_TalkNgbExtra2P2Loop_h
00003
00004 #include "Core/Array/Pattern/Categories.h"
00005 #include "Core/Array/Pattern/Cnum.h"
00006 #include "Core/Array/Element/E1Cast.h"
00007
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Array
00013 {
00014 namespace Trait
00015 {
00016
00017
00020 template<class DstArrayT, class SrcArrayT, class ExtraArrayT, class Extra2ArrayT>
00021 class TalkNgbExtra2P2Loop
00022 {
00023 public:
00024
00026 typedef Pattern::TagLoop IteratorCategory;
00027
00029 typedef Pattern::Tag2Phase PhaseCategory;
00030
00031 typedef typename DstArrayT::StorType DstStorType;
00032 typedef typename DstArrayT::ArithType DstArithType;
00033 typedef typename SrcArrayT::StorType SrcStorType;
00034 typedef typename SrcArrayT::ArithType SrcArithType;
00035 typedef typename ExtraArrayT::StorType ExtraStorType;
00036 typedef typename ExtraArrayT::ArithType ExtraArithType;
00037 typedef typename Extra2ArrayT::StorType Extra2StorType;
00038 typedef typename Extra2ArrayT::ArithType Extra2ArithType;
00039
00041 TalkNgbExtra2P2Loop(bool verbose, int ngbWidth, int ngbHeight)
00042 {
00043 mNgbWidth = ngbWidth;
00044 mNgbHeight = ngbHeight;
00045 mFactor = Element::E1Cast(ngbWidth * ngbHeight, DstArithType());
00046 mVerbose = verbose;
00047 }
00048
00050 int
00051 Width()
00052 {
00053 return mNgbWidth;
00054 }
00055
00057 int
00058 Height()
00059 {
00060 return mNgbHeight;
00061 }
00062
00064 void
00065 Init(int x, int y, const SrcArithType& v1, const ExtraArithType& v2,
00066 const Extra2ArithType& v3)
00067 {
00068 if (mVerbose)
00069 std::cout << " TalkNgbExtra2P2Loop::init(" << x << "," << y << ","
00070 << v1 << "," << v2 << "," << v3 << ") " << std::endl;
00071 mResult = Element::E1Cast(0, DstArithType());
00072 }
00073
00075 void
00076 Init2(int x, int y, const SrcArithType& v1, const ExtraArithType& v2,
00077 const Extra2ArithType& v3)
00078 {
00079 if (mVerbose)
00080 std::cout << " TalkNgbExtra2P2Loop::init2(" << x << "," << y << ","
00081 << v1 << "," << v2 << "," << v3 << ") " << std::endl;
00082 }
00083
00085 void
00086 NextEl(int x, int y, const SrcArithType& v1, const ExtraArithType& v2,
00087 const Extra2ArithType& v3)
00088 {
00089 if (mVerbose)
00090 std::cout << " TalkNgbExtra2P2Loop::next(" << x << "," << y
00091 << "," << v1 << "," << v2 << "," << v3 << ") " << std::endl;
00092 DstArithType tmp(v1, v2, v3);
00093 mResult += tmp;
00094 }
00095
00097 void
00098 NextEl2(int x, int y, const SrcArithType& v1, const ExtraArithType& v2,
00099 const Extra2ArithType& v3)
00100 {
00101 if (mVerbose)
00102 std::cout << " TalkNgbExtra2P2Loop::next2(" << x << "," << y
00103 << "," << v1 << "," << v2 << "," << v3 << ") " << std::endl;
00104 DstArithType tmp(v1, v2, v3);
00105 mResult += tmp;
00106 }
00107
00109 DstArithType
00110 Result() const
00111 {
00112 return mResult / mFactor;
00113 }
00114
00115 private:
00116 int mNgbWidth;
00117 int mNgbHeight;
00118 DstArithType mResult;
00119 DstArithType mFactor;
00120 bool mVerbose;
00121 };
00122
00123 }
00124 }
00125 }
00126 }
00127
00128 #endif