added tests for gpu::mulSpectrums
authorAlexey Spizhevoy <no@email>
Wed, 22 Dec 2010 14:01:26 +0000 (14:01 +0000)
committerAlexey Spizhevoy <no@email>
Wed, 22 Dec 2010 14:01:26 +0000 (14:01 +0000)
tests/gpu/src/dft_routines.cpp [new file with mode: 0644]

diff --git a/tests/gpu/src/dft_routines.cpp b/tests/gpu/src/dft_routines.cpp
new file mode 100644 (file)
index 0000000..b97df2f
--- /dev/null
@@ -0,0 +1,202 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////\r
+//\r
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
+//\r
+//  By downloading, copying, installing or using the software you agree to this license.\r
+//  If you do not agree to this license, do not download, install,\r
+//  copy or use the software.\r
+//\r
+//\r
+//                        Intel License Agreement\r
+//                For Open Source Computer Vision Library\r
+//\r
+// Copyright (C) 2000, Intel Corporation, all rights reserved.\r
+// Third party copyrights are property of their respective owners.\r
+//\r
+// Redistribution and use in source and binary forms, with or without modification,\r
+// are permitted provided that the following conditions are met:\r
+//\r
+//   * Redistribution's of source code must retain the above copyright notice,\r
+//     this list of conditions and the following disclaimer.\r
+//\r
+//   * Redistribution's in binary form must reproduce the above copyright notice,\r
+//     this list of conditions and the following disclaimer in the documentation\r
+//     and/or other materials provided with the distribution.\r
+//\r
+//   * The name of Intel Corporation may not be used to endorse or promote products\r
+//     derived from this software without specific prior written permission.\r
+//\r
+// This software is provided by the copyright holders and contributors "as is" and\r
+// any express or implied warranties, including, but not limited to, the implied\r
+// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+// In no event shall the Intel Corporation or contributors be liable for any direct,\r
+// indirect, incidental, special, exemplary, or consequential damages\r
+// (including, but not limited to, procurement of substitute goods or services;\r
+// loss of use, data, or profits; or business interruption) however caused\r
+// and on any theory of liability, whether in contract, strict liability,\r
+// or tort (including negligence or otherwise) arising in any way out of\r
+// the use of this software, even if advised of the possibility of such damage.\r
+//\r
+//M*/\r
+\r
+#include "gputest.hpp"\r
+\r
+using namespace cv;\r
+using namespace cv::gpu;\r
+using namespace std;\r
+\r
+struct CV_GpuMulSpectrumsTest: CvTest\r
+{\r
+    CV_GpuMulSpectrumsTest(): CvTest("GPU-MulSpectrumsTest", "mulSpectrums") {}\r
+\r
+    void run(int)\r
+    {\r
+        try\r
+        {\r
+            if (!test(1 + rand() % 100, 1 + rand() % 1000)) return;\r
+            if (!testConj(1 + rand() % 100, 1 + rand() % 1000)) return;\r
+            if (!testScaled(1 + rand() % 100, 1 + rand() % 1000)) return;\r
+            if (!testScaledConj(1 + rand() % 100, 1 + rand() % 1000)) return;\r
+        }\r
+        catch (const Exception& e)\r
+        {\r
+            if (!check_and_treat_gpu_exception(e, ts)) throw;\r
+            return;\r
+        }\r
+    }\r
+\r
+    void gen(int cols, int rows, Mat& mat)\r
+    {\r
+        RNG rng;\r
+        mat.create(rows, cols, CV_32FC2);\r
+        rng.fill(mat, RNG::UNIFORM, Scalar::all(0.f), Scalar::all(10.f));\r
+    }\r
+\r
+    bool cmp(const Mat& gold, const Mat& mine, float max_err=1e-3f)\r
+    {\r
+        if (gold.size() != mine.size())\r
+        {\r
+            ts->printf(CvTS::CONSOLE, "bad sizes: gold: %d d%, mine: %d %d\n", gold.cols, gold.rows, mine.cols, mine.rows);\r
+            ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);\r
+            return false;\r
+        }\r
+        if (gold.type() != mine.type())\r
+        {\r
+            ts->printf(CvTS::CONSOLE, "bad types: gold=%d, mine=%d\n", gold.type(), mine.type());\r
+            ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);\r
+            return false;\r
+        }\r
+        for (int i = 0; i < gold.rows; ++i)\r
+        {\r
+            for (int j = 0; j < gold.cols * 2; ++j)\r
+            {\r
+                float gold_ = gold.at<float>(i, j);\r
+                float mine_ = mine.at<float>(i, j);\r
+                if (fabs(gold_ - mine_) > max_err)\r
+                {\r
+                    ts->printf(CvTS::CONSOLE, "bad values at %d %d: gold=%f, mine=%f\n", j, i, gold_, mine_);\r
+                    ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);\r
+                    return false;\r
+                }\r
+            }\r
+        }\r
+        return true;\r
+    }\r
+\r
+    bool cmpScaled(const Mat& gold, const Mat& mine, float scale, float max_err=1e-3f)\r
+    {\r
+        if (gold.size() != mine.size())\r
+        {\r
+            ts->printf(CvTS::CONSOLE, "bad sizes: gold: %d d%, mine: %d %d\n", gold.cols, gold.rows, mine.cols, mine.rows);\r
+            ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);\r
+            return false;\r
+        }\r
+        if (gold.type() != mine.type())\r
+        {\r
+            ts->printf(CvTS::CONSOLE, "bad types: gold=%d, mine=%d\n", gold.type(), mine.type());\r
+            ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);\r
+            return false;\r
+        }\r
+        for (int i = 0; i < gold.rows; ++i)\r
+        {\r
+            for (int j = 0; j < gold.cols * 2; ++j)\r
+            {\r
+                float gold_ = gold.at<float>(i, j) * scale;\r
+                float mine_ = mine.at<float>(i, j);\r
+                if (fabs(gold_ - mine_) > max_err)\r
+                {\r
+                    ts->printf(CvTS::CONSOLE, "bad values at %d %d: gold=%f, mine=%f\n", j, i, gold_, mine_);\r
+                    ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);\r
+                    return false;\r
+                }\r
+            }\r
+        }\r
+        return true;\r
+    }\r
+\r
+    bool test(int cols, int rows)\r
+    {\r
+        Mat a, b;\r
+        gen(cols, rows, a);\r
+        gen(cols, rows, b);\r
+\r
+        Mat c_gold;\r
+        mulSpectrums(a, b, c_gold, 0, false);\r
+\r
+        GpuMat d_c;\r
+        mulSpectrums(GpuMat(a), GpuMat(b), d_c, 0, false);\r
+\r
+        return cmp(c_gold, Mat(d_c)) \r
+            || (ts->printf(CvTS::CONSOLE, "test failed: cols=%d, rows=%d\n", cols, rows), false);\r
+    }\r
+\r
+    bool testConj(int cols, int rows)\r
+    {\r
+        Mat a, b;\r
+        gen(cols, rows, a);\r
+        gen(cols, rows, b);\r
+\r
+        Mat c_gold;\r
+        mulSpectrums(a, b, c_gold, 0, true);\r
+\r
+        GpuMat d_c;\r
+        mulSpectrums(GpuMat(a), GpuMat(b), d_c, 0, true);\r
+\r
+        return cmp(c_gold, Mat(d_c)) \r
+            || (ts->printf(CvTS::CONSOLE, "testConj failed: cols=%d, rows=%d\n", cols, rows), false);\r
+    }\r
+\r
+    bool testScaled(int cols, int rows)\r
+    {\r
+        Mat a, b;\r
+        gen(cols, rows, a);\r
+        gen(cols, rows, b);\r
+        float scale = 1.f / a.size().area();\r
+\r
+        Mat c_gold;\r
+        mulSpectrums(a, b, c_gold, 0, false);\r
+\r
+        GpuMat d_c;\r
+        mulAndScaleSpectrums(GpuMat(a), GpuMat(b), d_c, 0, scale, false);\r
+\r
+        return cmpScaled(c_gold, Mat(d_c), scale) \r
+            || (ts->printf(CvTS::CONSOLE, "testScaled failed: cols=%d, rows=%d\n", cols, rows), false);\r
+    }\r
+\r
+    bool testScaledConj(int cols, int rows)\r
+    {\r
+        Mat a, b;\r
+        gen(cols, rows, a);\r
+        gen(cols, rows, b);\r
+        float scale = 1.f / a.size().area();\r
+\r
+        Mat c_gold;\r
+        mulSpectrums(a, b, c_gold, 0, true);\r
+\r
+        GpuMat d_c;\r
+        mulAndScaleSpectrums(GpuMat(a), GpuMat(b), d_c, 0, scale, true);\r
+\r
+        return cmpScaled(c_gold, Mat(d_c), scale) \r
+            || (ts->printf(CvTS::CONSOLE, "testScaledConj failed: cols=%d, rows=%d\n", cols, rows), false);\r
+    }\r
+} CV_GpuMulSpectrumsTest_inst;
\ No newline at end of file