00001 #ifndef Impala_Core_Vector_HistogramIntersection_h
00002 #define Impala_Core_Vector_HistogramIntersection_h
00003
00004 #include "Core/Vector/VectorTem.h"
00005
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Vector
00011 {
00012
00013
00014 template <class ElemT>
00015 inline ElemT
00016 HistogramIntersection(const VectorTem<ElemT>& v1, const VectorTem<ElemT>& v2)
00017 {
00018 ElemT score = 0;
00019 for (int i=0 ; i<v1.Size() ; i++)
00020 score += Impala::Min(v1[i], v2[i]);
00021 return score;
00022 }
00023
00024 inline double
00025 HistogramIntersectionDouble(const Vector::VectorTem<double>& v1,
00026 const Vector::VectorTem<double>& v2)
00027 {
00028 double accumulator = 0;
00029 for(int i = 0; i < v1.Size(); i++)
00030 {
00031 accumulator += Impala::Min(v1[i], v2[i]);
00032 }
00033 return accumulator;
00034 }
00035
00036 template <class ElemT>
00037 class HistogramIntersectionFtor
00038 {
00039 public:
00040
00041 ElemT
00042 DoIt(const VectorTem<ElemT>& v1, const VectorTem<ElemT>& v2)
00043 {
00044 ElemT score = 0;
00045 for (int i=0 ; i<v1.Size() ; i++)
00046 score += Impala::Min(v1[i], v2[i]);
00047 return score;
00048 }
00049 };
00050
00060 template <class FType>
00061 inline void
00062 DoSlabHistogramIntersection(FType* C, const FType* A, const FType* B,
00063 unsigned int slabSizeA, unsigned int slabSizeB,
00064 unsigned int vectorSize)
00065 {
00066 #pragma omp parallel for
00067 for (unsigned int a = 0; a < slabSizeA; a++)
00068 {
00069 for (unsigned int b = 0; b < slabSizeB; b++)
00070 {
00071 const FType* baseA = A + (a * vectorSize);
00072 const FType* baseB = B + (b * vectorSize);
00073 FType sum = 0;
00074 for (unsigned int k = 0; k < vectorSize; k++)
00075 {
00076 if (baseA[k] < baseB[k])
00077 {
00078 sum += baseA[k];
00079 }
00080 else
00081 {
00082 sum += baseB[k];
00083 }
00084 }
00085 C[b * slabSizeA + a] = (FType)sum;
00086 }
00087 }
00088 }
00089
00090 }
00091 }
00092 }
00093
00094 #endif