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

Apply.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Vector_Apply_h
00002 #define Impala_Core_Vector_Apply_h
00003 
00004 #include "Core/Vector/VectorSet.h"
00005 #include "Core/Matrix/Mat.h"
00006 #include "Util/ProgressPrinter.h"
00007 #include "Link/Mpi/MpiFuncs.h"
00008 
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace Vector
00014 {
00015 
00016 // is this a pattern?
00021 Matrix::Mat* Apply(double (*fn)(const VectorTem<double>&, const VectorTem<double>&),
00022                    const VectorSet<Array::Array2dScalarReal64>* horizontal,
00023                    const VectorSet<Array::Array2dScalarReal64>* vertical)
00024 {
00025     ILOG_VAR(Core.Vector.Apply);
00026 
00027     int size1 = horizontal->Size(), size2 = vertical->Size();
00028     ILOG_DEBUG("s1 = " << size1 << ", s2 = " << size2);
00029     Matrix::Mat* m = new Matrix::Mat(size1, size2, 0, 0);
00030 
00031     double *ptr = m->CPB();
00032     for(int row=0 ; row<size2 ; ++row)
00033     {
00034         for(int col=0 ; col<size1 ; ++col)
00035         {
00036             VectorTem<double> v1(horizontal->GetVector(col, true));
00037             VectorTem<double> v2(vertical->GetVector(row, true));
00038             *ptr = (*fn)(v1, v2);
00039             ++ptr;
00040         }
00041     }
00042 
00043     return m;
00044 }
00045 
00046 void Kernelise(VectorTem<double>* dst, VectorTem<double> src, 
00047                const VectorSet<Array::Array2dScalarReal64>* set,
00048                double (*fn)(const VectorTem<double>&, const VectorTem<double>&))
00049 {
00050     ILOG_VAR(Core.Vector.Kernelise);
00051 
00052     int size = set->Size();
00053     ILOG_DEBUG("size = " << size);
00054     if(size != dst->Size())
00055         ILOG_ERROR("sizes of dst and set don't match: "<<dst->Size()<<"!="<<size);
00056     if(set->GetVectorLength(0) != src.Size())
00057         ILOG_ERROR("sizes of src and set feature length don't match: "<<src.Size()<<"!="<<set->GetVectorLength(0));
00058 
00059     double *ptr = dst->GetData();
00060     for(int row=0 ; row<size ; ++row)
00061     {
00062         VectorTem<double> v1(set->GetVector(row, true));
00063         *ptr = (*fn)(v1, src);
00064         ++ptr;
00065     }
00066 }
00067 
00068 } // namespace Vector
00069 } // namespace Core
00070 } // namespace Impala
00071 
00072 
00073 #endif

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