00001 #ifndef Impala_Core_Column_Equals_h
00002 #define Impala_Core_Column_Equals_h
00003
00004 #include <iostream>
00005 #include "Core/Column/InvalidColumn.h"
00006
00007 namespace Impala
00008 {
00009 namespace Core
00010 {
00011 namespace Column
00012 {
00013
00014
00015 template <class C1, class C2>
00016 inline bool
00017 Equals(const C1* t1, const C2* t2, int nrElem)
00018 {
00019 ILOG_VAR(Impala.Core.Column.Equals);
00020 if (nrElem > t2->Capacity())
00021 {
00022 ILOG_ERROR("incompatible t2 range");
00023 return false;
00024 }
00025 if (nrElem > t1->Capacity())
00026 {
00027 ILOG_ERROR("incompatible t1 range");
00028 return false;
00029 }
00030
00031 for (int i=0 ; i<nrElem ; i++)
00032 if(t1->Get(i) != t2->Get(i))
00033 return false;
00034
00035 return true;
00036 }
00037
00038 template <>
00039 inline bool
00040 Equals(const InvalidColumn* t1, const InvalidColumn* t2, int nrElem)
00041 {
00042 return true;
00043 }
00044
00045
00058 template <class C1, class C2>
00059 inline bool
00060 Equals(const C1* t1, const C2* t2, int nrElem, double tolerance)
00061 {
00062 ILOG_VAR(Impala.Core.Column.Equals);
00063 if (nrElem > t2->Capacity())
00064 {
00065 ILOG_ERROR("incompatible t2 range");
00066 return false;
00067 }
00068 if (nrElem > t1->Capacity())
00069 {
00070 ILOG_ERROR("incompatible t1 range");
00071 return false;
00072 }
00073
00074 double maxdiff = 0;
00075 for (int i=0 ; i<nrElem ; i++)
00076 {
00077 double diff = abs((double)t1->Get(i) - t2->Get(i));
00078 if(diff > tolerance)
00079 {
00080 ILOG_DEBUG(std::setiosflags(std::ios_base::scientific) <<
00081 diff << " > " << tolerance <<
00082 std::resetiosflags(std::ios_base::scientific));
00083 return false;
00084 }
00085 }
00086
00087 return true;
00088 }
00089
00090 template <>
00091 inline bool
00092 Equals(const InvalidColumn* t1, const InvalidColumn* t2,
00093 int nrElem, double tolerance)
00094 {
00095 return true;
00096 }
00097
00098
00099 }
00100 }
00101 }
00102
00103 #endif