Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

MatSum.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Matrix_MatSum_h
00002 #define Impala_Core_Matrix_MatSum_h
00003 
00004 #include "Core/Matrix/MatFunc.h"
00005 #include "Core/Array/SetVal.h"
00006 
00007 namespace Impala
00008 {
00009 namespace Core
00010 {
00011 namespace Matrix
00012 {
00013 
00014 /* sum over the rows (result = size(R,1)) */
00015 template<class ArrayT>
00016 inline ArrayT*
00017 MatSumAxis1(ArrayT* m)
00018 {
00019     ArrayT* res = MatCreate<ArrayT>(MatNrRow(m), 1);
00020     SetVal(res, res, 0.0);
00021     for (int i=0 ; i<MatNrRow(m) ; i++)
00022         for (int j=0 ; j<MatNrCol(m) ; j++)
00023             *MatE(res, i, 0) = *MatE(res, i, 0) + *MatE(m, i, j);
00024     return res;
00025 }
00026 
00027 template<class ArrayT>
00028 inline ArrayT*
00029 MatSumRows(ArrayT* m)
00030 {
00031     return MatSumAxis1(m);
00032 }
00033     
00034 /* sum over the columns (result = size(1,C)) */
00035 template<class ArrayT>
00036 inline ArrayT*
00037 MatSumAxis0(ArrayT* m)
00038 {
00039     ArrayT* res = MatCreate<ArrayT>(1, MatNrCol(m));
00040     SetVal(res, res, 0.0);
00041     for (int i=0 ; i<MatNrRow(m) ; i++)
00042         for (int j=0 ; j<MatNrCol(m) ; j++)
00043             *MatE(res, 0, j) = *MatE(res, 0, j) + *MatE(m, i, j);
00044     return res;
00045 }
00046 
00047 template<class ArrayT>
00048 inline ArrayT*
00049 MatSumColumns(ArrayT* m)
00050 {
00051     return MatSumAxis0(m);
00052 }
00053 
00054 } // namespace Matrix
00055 } // namespace Core
00056 } // namespace Impala
00057 
00058 #endif

Generated on Fri Mar 19 09:31:16 2010 for ImpalaSrc by  doxygen 1.5.1