Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / test / common / gapi_core_tests_inl.hpp
index d33b5cc..ca4190b 100644 (file)
@@ -2,7 +2,7 @@
 // It is subject to the license terms in the LICENSE file found in the top-level directory
 // of this distribution and at http://opencv.org/license.html.
 //
-// Copyright (C) 2018 Intel Corporation
+// Copyright (C) 2018-2019 Intel Corporation
 
 
 #ifndef OPENCV_GAPI_CORE_TESTS_INL_HPP
@@ -681,11 +681,11 @@ TEST_P(AbsDiffCTest, AccuracyTest)
 TEST_P(SumTest, AccuracyTest)
 {
     auto param = GetParam();
+    compare_scalar_f cmpF = get<3>(GetParam());
+    MatType type = std::get<0>(param);
     cv::Size sz_in = std::get<1>(param);
-    auto tolerance = std::get<3>(param);
     auto compile_args = std::get<4>(param);
-    //initMatrixRandU(std::get<0>(param), sz_in, std::get<2>(param));
-    initMatsRandN(std::get<0>(param), sz_in, std::get<2>(param)); //TODO: workaround trying to fix SumTest failures
+    initMatrixRandU(type, sz_in, type, std::get<2>(param));
 
 
     cv::Scalar out_sum;
@@ -703,8 +703,7 @@ TEST_P(SumTest, AccuracyTest)
     }
     // Comparison //////////////////////////////////////////////////////////////
     {
-        EXPECT_LE(std::abs(out_sum[0] - out_sum_ocv[0]) / std::max(1.0, std::abs(out_sum_ocv[0])), tolerance)
-            << "OCV=" << out_sum_ocv[0] << "   GAPI=" << out_sum[0];
+        EXPECT_TRUE(cmpF(out_sum, out_sum_ocv));
     }
 }
 
@@ -714,8 +713,8 @@ TEST_P(AddWeightedTest, AccuracyTest)
     cv::Size sz_in;
     bool initOut = false;
     cv::GCompileArgs compile_args;
-    double tolerance = 0.0;
-    std::tie(type, sz_in, dtype, initOut, tolerance, compile_args) = GetParam();
+    compare_f cmpF;
+    std::tie(type, sz_in, dtype, initOut, cmpF, compile_args) = GetParam();
 
     auto& rng = cv::theRNG();
     double alpha = rng.uniform(0.0, 1.0);
@@ -735,53 +734,19 @@ TEST_P(AddWeightedTest, AccuracyTest)
         cv::addWeighted(in_mat1, alpha, in_mat2, beta, gamma, out_mat_ocv, dtype);
     }
     // Comparison //////////////////////////////////////////////////////////////
-    {
-        // Note, that we cannot expect bitwise results for add-weighted:
-        //
-        //    tmp = src1*alpha + src2*beta + gamma;
-        //    dst = saturate<DST>( round(tmp) );
-        //
-        // Because tmp is floating-point, dst depends on compiler optimizations
-        //
-        // However, we must expect good accuracy of tmp, and rounding correctly
-
-        cv::Mat failures;
-
-        if (out_mat_ocv.type() == CV_32FC1)
-        {
-            // result: float - may vary in 7th decimal digit
-            failures = abs(out_mat_gapi - out_mat_ocv) > abs(out_mat_ocv) * 1e-6;
-        }
-        else
-        {
-            // result: integral - rounding may vary if fractional part of tmp
-            //                    is nearly 0.5
-
-            cv::Mat inexact, incorrect, diff, tmp;
-
-            inexact = out_mat_gapi != out_mat_ocv;
-
-            // even if rounded differently, check if still rounded correctly
-            cv::addWeighted(in_mat1, alpha, in_mat2, beta, gamma, tmp, CV_32F);
-            cv::subtract(out_mat_gapi, tmp, diff, cv::noArray(), CV_32F);
-            incorrect = abs(diff) >= tolerance;// 0.5000005f; // relative to 6 digits
-
-            failures = inexact & incorrect;
-        }
+    EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
+    EXPECT_EQ(out_mat_gapi.size(), sz_in);
 
-        EXPECT_EQ(0, cv::countNonZero(failures));
-        EXPECT_EQ(out_mat_gapi.size(), sz_in);
-    }
 }
 
 TEST_P(NormTest, AccuracyTest)
 {
+    compare_scalar_f cmpF;
     NormTypes opType = NORM_INF;
     int type = 0;
     cv::Size sz;
-    double tolerance = 0.0;
     cv::GCompileArgs compile_args;
-    std::tie(opType, type, sz, tolerance, compile_args) = GetParam();
+    std::tie(opType, type, sz, cmpF, compile_args) = GetParam();
     initMatrixRandU(type, sz, type, false);
 
     cv::Scalar out_norm;
@@ -803,8 +768,7 @@ TEST_P(NormTest, AccuracyTest)
 
     // Comparison //////////////////////////////////////////////////////////////
     {
-        EXPECT_LE(std::abs(out_norm[0] - out_norm_ocv[0]) / std::max(1.0, std::abs(out_norm_ocv[0])), tolerance)
-            << "OCV=" << out_norm_ocv[0] << "   GAPI=" << out_norm[0];
+        EXPECT_TRUE(cmpF(out_norm, out_norm_ocv));
     }
 }