00001 #ifndef Impala_Core_Vector_Avg_h
00002 #define Impala_Core_Vector_Avg_h
00003
00004 #include "Core/Vector/VectorSet.h"
00005 #include "Core/Vector/AddAssign.h"
00006 #include "Core/Vector/DivAssign.h"
00007
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Vector
00013 {
00014
00015
00016 template <class ArrayT>
00017 inline void
00018 Avg(typename VectorSet<ArrayT>::VectorT* dst, VectorSet<ArrayT>* src,
00019 int startIdx, int stepSize, int nrSteps)
00020 {
00021 typedef typename VectorSet<ArrayT>::VectorT VectorT;
00022
00023 if (!src->HasConstVectorSize())
00024 {
00025 std::cout << "Vector::Avg: works for constant vector size only" << std::endl;
00026 return;
00027 }
00028 VectorT res(src->GetVectorLength(0));
00029 res = 0;
00030 int endIdx = startIdx + nrSteps * stepSize;
00031 for (int i=startIdx ; i<endIdx ; i+=stepSize)
00032 AddAssign(res, src->GetVector(i, true));
00033 typename VectorSet<ArrayT>::ElemT factor = nrSteps;
00034 DivAssign(res, factor);
00035 if (!dst)
00036 dst = new VectorT(res);
00037 else
00038 *dst = res;
00039 }
00040
00041 template <class ArrayT>
00042 inline void
00043 Avg(typename VectorSet<ArrayT>::VectorT* dst, VectorSet<ArrayT>* src, int size,
00044 bool* filter)
00045 {
00046 typedef typename VectorSet<ArrayT>::VectorT VectorT;
00047
00048 if (!src->HasConstVectorSize())
00049 {
00050 std::cout << "Vector::Avg: works for constant vector size only" << std::endl;
00051 return;
00052 }
00053 VectorT res(src->GetVectorLength(0));
00054 res = 0;
00055 typename VectorSet<ArrayT>::ElemT factor = 0;
00056 for (int i=0 ; i<size ; i++)
00057 {
00058 if (!filter || filter[i])
00059 {
00060 AddAssign(res, src->GetVector(i, true));
00061 factor++;
00062 }
00063 }
00064 DivAssign(res, factor);
00065 if (!dst)
00066 dst = new VectorT(res);
00067 else
00068 *dst = res;
00069 }
00070
00071 }
00072 }
00073 }
00074
00075 #endif