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

TestMatNorm2Dist.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Test_TestMatNorm2Dist_h
00002 #define Impala_Core_Test_TestMatNorm2Dist_h
00003 
00004 #include "Core/Test/TestBase.h"
00005 #include "Core/Matrix/MatNorm2Dist.h"
00006 #include "Core/Matrix/Mat.h"
00007 #include "Core/Array/Abs.h"
00008 #include "Core/Array/PixSum.h"
00009 #include "Core/Array/Sub.h"
00010 #include "Core/Array/PrintData.h"
00011 #include "Core/Array/ReadRaw.h"
00012 #include "Util/Database.h"
00013 
00014 namespace Impala
00015 {
00016 namespace Core
00017 {
00018 namespace Test
00019 {
00020 
00021 using namespace Impala::Core::Array;
00022 using namespace Impala::Core::Matrix;
00023 
00024 class TestMatNorm2Dist : public TestBase
00025 {
00026 public:
00027 
00028     TestMatNorm2Dist(int testIndex)
00029     {
00030         mTestNameBase = "MatNorm2Dist";
00031         mTestIndex = testIndex;
00032     }
00033 
00034     virtual void
00035     Run()
00036     {
00037         Mat* a = 0;
00038         Mat* b = 0;
00039         Mat* c = 0;
00040         if(mTestIndex == 0) {
00041             /*
00042 >> distance2([1,2,3,4,5; 4 3 2 9 0], [2.5 5 3; 0.9 0.4 3])
00043 
00044 ans =
00045 
00046     3.4438    5.3814    2.2361
00047     2.1587    3.9699    1.0000
00048     1.2083    2.5612    1.0000
00049     8.2377    8.6579    6.0828
00050     2.6571    0.4000    3.6056*/
00051 
00052             a = MatCreate<Mat>(2, 5);
00053             *MatE(a, 0, 0) = 1;
00054             *MatE(a, 0, 1) = 2;
00055             *MatE(a, 0, 2) = 3;
00056             *MatE(a, 0, 3) = 4;
00057             *MatE(a, 0, 4) = 5;
00058             *MatE(a, 1, 0) = 4;
00059             *MatE(a, 1, 1) = 3;
00060             *MatE(a, 1, 2) = 2;
00061             *MatE(a, 1, 3) = 9;
00062             *MatE(a, 1, 4) = 0;
00063             b = MatCreate<Mat>(2, 3);
00064             *MatE(b, 0, 0) = 2.5;
00065             *MatE(b, 0, 1) = 5;
00066             *MatE(b, 0, 2) = 3;
00067             *MatE(b, 1, 0) = 0.9;
00068             *MatE(b, 1, 1) = 0.4;
00069             *MatE(b, 1, 2) = 3;
00070             c = MatCreate<Mat>(5, 3);
00071             *MatE(c, 0, 0) = 3.4438;
00072             *MatE(c, 0, 1) = 5.3814;
00073             *MatE(c, 0, 2) = 2.2361;
00074             *MatE(c, 1, 0) = 2.1587;
00075             *MatE(c, 1, 1) = 3.9699;
00076             *MatE(c, 1, 2) = 1.0;
00077             *MatE(c, 2, 0) = 1.2083;
00078             *MatE(c, 2, 1) = 2.5612;
00079             *MatE(c, 2, 2) = 1.0;
00080             *MatE(c, 3, 0) = 8.2377;
00081             *MatE(c, 3, 1) = 8.6579;
00082             *MatE(c, 3, 2) = 6.0828;
00083             *MatE(c, 4, 0) = 2.6571;
00084             *MatE(c, 4, 1) = 0.4000;
00085             *MatE(c, 4, 2) = 3.6056;
00086         } else if((mTestIndex == 1) || (mTestIndex == 2))
00087         {
00088             ReadRaw(a, "norm2dist_a.raw", &Util::Database::GetInstance());
00089             ReadRaw(b, "norm2dist_b.raw", &Util::Database::GetInstance());
00090             ReadRaw(c, "norm2dist_c.raw", &Util::Database::GetInstance());
00091             if(mTestIndex == 2)
00092             {
00093                 Mat* temp1 = MatTranspose(a);
00094                 Mat* temp2 = MatTranspose(b);
00095                 delete a;
00096                 delete b;
00097                 a = temp1;
00098                 b = temp2;
00099             }
00100         }
00101         Mat* result = 0;
00102         Timer speedTimer;
00103         if(mTestIndex <= 1) result = MatNorm2Dist(a,b);
00104         if(mTestIndex > 1) result = MatNorm2DistTransposed(a,b);
00105         std::cout << "Speed of " << mTestIndex << " " << speedTimer.SplitTimeStr() << std::endl;
00106         //PrintData(result);
00107         Sub(result, result, c);
00108         Abs(result, result);
00109         //PrintData(result);
00110         //PrintData(c);
00111         Real64 diff = PixSum(result);
00112         AddReport("Difference:" + MakeString(diff));
00113         std::cout << "Difference:" + MakeString(diff) << std::endl;
00114         if(diff > 0.0005) {
00115             // require small difference
00116             SetFailure("MatNorm2Dist too much difference failure!");
00117         }
00118         delete a;
00119         delete b;
00120         delete c;
00121         delete result;
00122     }
00123 
00124     virtual String
00125     Name() const
00126     {
00127         return FileNameCtor(mTestNameBase, MakeString(mTestIndex), "");
00128     }
00129 
00130 private:
00131     String mTestNameBase;
00132     int    mTestIndex;
00133 
00134 };
00135 
00136 
00137 static TestBase* gMatNorm2DistSuite[] =
00138     {
00139         new TestMatNorm2Dist(0),
00140         new TestMatNorm2Dist(1),
00141         new TestMatNorm2Dist(2),
00142         (TestBase*)0
00143     };
00144 
00145 } // namespace Test
00146 } // namespace Core
00147 } // namespace Impala
00148 
00149 #endif

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