00001 #ifndef Impala_Core_Array_Trait_BpoTestEqual_h 00002 #define Impala_Core_Array_Trait_BpoTestEqual_h 00003 00004 #include "Core/Array/Pattern/Categories.h" 00005 #include "Core/Array/Element/E1Cast.h" 00006 #include "Core/Array/Element/E1Abs.h" 00007 #include "Core/Array/Element/E1Sum.h" 00008 00009 namespace Impala 00010 { 00011 namespace Core 00012 { 00013 namespace Array 00014 { 00015 namespace Trait 00016 { 00017 00018 using namespace Impala::Core::Array::Element; 00019 00020 00021 template<class DstArrayT, class Src1ArrayT, class Src2ArrayT> 00022 class BpoTestEqual 00023 { 00024 public: 00026 typedef Pattern::TagTransInVar TransVarianceCategory; 00027 00029 typedef Pattern::TagCallValue CallCategory; 00030 00031 typedef typename DstArrayT::ArithType DstArithT; 00032 typedef typename Src1ArrayT::ArithType Src1ArithT; 00033 typedef typename Src2ArrayT::ArithType Src2ArithT; 00034 00035 BpoTestEqual(Real64 epsilon) 00036 { 00037 mEpsilon = epsilon; 00038 mNr = 0; 00039 mNrDiff = 0; 00040 mSumSrc1 = 0; 00041 mSumSrc2 = 0; 00042 mSumDiff = 0; 00043 } 00044 00045 DstArithT 00046 DoIt(const Src1ArithT& x, const Src2ArithT& y) 00047 { 00048 mSumSrc1 += E1Sum(E1Abs(x)); 00049 mSumSrc2 += E1Sum(E1Abs(y)); 00050 mNr++; 00051 Real64 d = E1Sum(E1Abs(x - y)); 00052 if (d > mEpsilon) { 00053 mNrDiff++; 00054 mSumDiff += d; 00055 return E1Cast(d, DstArithT()); 00056 } 00057 return E1Cast(0, DstArithT()); 00058 } 00059 00060 //private: 00061 Real64 mEpsilon; 00062 Real64 mSumSrc1; 00063 Real64 mSumSrc2; 00064 Real64 mSumDiff; 00065 Int32 mNr; 00066 Int32 mNrDiff; 00067 }; 00068 00069 } // namespace Trait 00070 } // namespace Array 00071 } // namespace Core 00072 } // namespace Impala 00073 00074 #endif