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