From c87b99e82bd27bd78cfc9be29804b7059e05c196 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 21 Feb 2020 09:57:37 +0300 Subject: [PATCH] Added test for new MatX division. --- modules/core/include/opencv2/core/matx.hpp | 18 +------- modules/core/test/test_operations.cpp | 52 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/modules/core/include/opencv2/core/matx.hpp b/modules/core/include/opencv2/core/matx.hpp index d384f8e1b2..a68e34edd6 100644 --- a/modules/core/include/opencv2/core/matx.hpp +++ b/modules/core/include/opencv2/core/matx.hpp @@ -1275,19 +1275,11 @@ Matx<_Tp, m, n> operator * (double alpha, const Matx<_Tp, m, n>& a) return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); } -template static inline -Matx<_Tp, m, n>& operator /= (Matx<_Tp, m, n>& a, int alpha) -{ - for( int i = 0; i < m*n; i++ ) - a.val[i] = saturate_cast<_Tp>(a.val[i] / alpha); - return a; -} - template static inline Matx<_Tp, m, n>& operator /= (Matx<_Tp, m, n>& a, float alpha) { for( int i = 0; i < m*n; i++ ) - a.val[i] = saturate_cast<_Tp>(a.val[i] / alpha); + a.val[i] = a.val[i] / alpha; return a; } @@ -1295,16 +1287,10 @@ template static inline Matx<_Tp, m, n>& operator /= (Matx<_Tp, m, n>& a, double alpha) { for( int i = 0; i < m*n; i++ ) - a.val[i] = saturate_cast<_Tp>(a.val[i] / alpha); + a.val[i] = a.val[i] / alpha; return a; } -template static inline -Matx<_Tp, m, n> operator / (const Matx<_Tp, m, n>& a, int alpha) -{ - return Matx<_Tp, m, n>(a, 1./alpha, Matx_ScaleOp()); -} - template static inline Matx<_Tp, m, n> operator / (const Matx<_Tp, m, n>& a, float alpha) { diff --git a/modules/core/test/test_operations.cpp b/modules/core/test/test_operations.cpp index aea6f229ac..c380568d9f 100644 --- a/modules/core/test/test_operations.cpp +++ b/modules/core/test/test_operations.cpp @@ -69,6 +69,8 @@ protected: bool TestVec(); bool TestMatxMultiplication(); bool TestMatxElementwiseDivison(); + bool TestDivisionByValue(); + bool TestInplaceDivisionByValue(); bool TestMatMatxCastSum(); bool TestSubMatAccess(); bool TestExp(); @@ -976,6 +978,50 @@ bool CV_OperationsTest::TestMatxElementwiseDivison() return true; } +bool CV_OperationsTest::TestDivisionByValue() +{ + try + { + Matx22f mat(2, 4, 6, 8); + float alpha = 2.f; + + Matx22f res = mat / alpha; + + if(res(0, 0) != 1.0) throw test_excep(); + if(res(0, 1) != 2.0) throw test_excep(); + if(res(1, 0) != 3.0) throw test_excep(); + if(res(1, 1) != 4.0) throw test_excep(); + } + catch(const test_excep&) + { + ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); + return false; + } + return true; +} + + +bool CV_OperationsTest::TestInplaceDivisionByValue() +{ + try + { + Matx22f mat(2, 4, 6, 8); + float alpha = 2.f; + + mat /= alpha; + + if(mat(0, 0) != 1.0) throw test_excep(); + if(mat(0, 1) != 2.0) throw test_excep(); + if(mat(1, 0) != 3.0) throw test_excep(); + if(mat(1, 1) != 4.0) throw test_excep(); + } + catch(const test_excep&) + { + ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); + return false; + } + return true; +} bool CV_OperationsTest::TestVec() { @@ -1204,6 +1250,12 @@ void CV_OperationsTest::run( int /* start_from */) if (!TestMatxElementwiseDivison()) return; + if (!TestDivisionByValue()) + return; + + if (!TestInplaceDivisionByValue()) + return; + if (!TestMatMatxCastSum()) return;