mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge pull request #25671 from savuor:rv/arithm_extend_tests
Tests added for mixed type arithmetic operations #25671 ### Changes * added accuracy tests for mixed type arithmetic operations _Note: div-by-zero values are removed from checking since the result is implementation-defined in common case_ * added perf tests for the same cases * fixed a typo in `getMulExtTab()` function that lead to dead code ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
committed by
GitHub
parent
1bd5ca1ebe
commit
a7e53aa184
@@ -452,6 +452,260 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/ , BinaryOpTest,
|
||||
)
|
||||
);
|
||||
|
||||
///////////// Mixed type arithmetics ////////
|
||||
|
||||
typedef perf::TestBaseWithParam<std::tuple<cv::Size, std::tuple<perf::MatType, perf::MatType>>> ArithmMixedTest;
|
||||
|
||||
PERF_TEST_P_(ArithmMixedTest, add)
|
||||
{
|
||||
auto p = GetParam();
|
||||
Size sz = get<0>(p);
|
||||
int srcType = get<0>(get<1>(p));
|
||||
int dstType = get<1>(get<1>(p));
|
||||
|
||||
cv::Mat a = Mat(sz, srcType);
|
||||
cv::Mat b = Mat(sz, srcType);
|
||||
cv::Mat c = Mat(sz, dstType);
|
||||
|
||||
declare.in(a, b, WARMUP_RNG).out(c);
|
||||
declare.time(50);
|
||||
|
||||
if (CV_MAT_DEPTH(dstType) == CV_32S)
|
||||
{
|
||||
//see ticket 1529: add can be without saturation on 32S
|
||||
a /= 2;
|
||||
b /= 2;
|
||||
}
|
||||
|
||||
TEST_CYCLE() cv::add(a, b, c, /* mask */ noArray(), dstType);
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(ArithmMixedTest, addScalarDouble)
|
||||
{
|
||||
auto p = GetParam();
|
||||
Size sz = get<0>(p);
|
||||
int srcType = get<0>(get<1>(p));
|
||||
int dstType = get<1>(get<1>(p));
|
||||
|
||||
cv::Mat a = Mat(sz, srcType);
|
||||
cv::Scalar b;
|
||||
cv::Mat c = Mat(sz, dstType);
|
||||
|
||||
declare.in(a, b, WARMUP_RNG).out(c);
|
||||
|
||||
if (CV_MAT_DEPTH(dstType) == CV_32S)
|
||||
{
|
||||
//see ticket 1529: add can be without saturation on 32S
|
||||
a /= 2;
|
||||
b /= 2;
|
||||
}
|
||||
|
||||
TEST_CYCLE() cv::add(a, b, c, /* mask */ noArray(), dstType);
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(ArithmMixedTest, addScalarSameType)
|
||||
{
|
||||
auto p = GetParam();
|
||||
Size sz = get<0>(p);
|
||||
int srcType = get<0>(get<1>(p));
|
||||
int dstType = get<1>(get<1>(p));
|
||||
|
||||
cv::Mat a = Mat(sz, srcType);
|
||||
cv::Scalar b;
|
||||
cv::Mat c = Mat(sz, dstType);
|
||||
|
||||
declare.in(a, b, WARMUP_RNG).out(c);
|
||||
|
||||
if (CV_MAT_DEPTH(dstType) < CV_32S)
|
||||
{
|
||||
b = Scalar(1, 0, 3, 4); // don't pass non-integer values for 8U/8S/16U/16S processing
|
||||
}
|
||||
else if (CV_MAT_DEPTH(dstType) == CV_32S)
|
||||
{
|
||||
//see ticket 1529: add can be without saturation on 32S
|
||||
a /= 2;
|
||||
b = Scalar(1, 0, -3, 4); // don't pass non-integer values for 32S processing
|
||||
}
|
||||
|
||||
TEST_CYCLE() cv::add(a, b, c, /* mask */ noArray(), dstType);
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(ArithmMixedTest, subtract)
|
||||
{
|
||||
auto p = GetParam();
|
||||
Size sz = get<0>(p);
|
||||
int srcType = get<0>(get<1>(p));
|
||||
int dstType = get<1>(get<1>(p));
|
||||
|
||||
cv::Mat a = Mat(sz, srcType);
|
||||
cv::Mat b = Mat(sz, srcType);
|
||||
cv::Mat c = Mat(sz, dstType);
|
||||
|
||||
declare.in(a, b, WARMUP_RNG).out(c);
|
||||
|
||||
if (CV_MAT_DEPTH(dstType) == CV_32S)
|
||||
{
|
||||
//see ticket 1529: subtract can be without saturation on 32S
|
||||
a /= 2;
|
||||
b /= 2;
|
||||
}
|
||||
|
||||
TEST_CYCLE() cv::subtract(a, b, c, /* mask */ noArray(), dstType);
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(ArithmMixedTest, subtractScalarDouble)
|
||||
{
|
||||
auto p = GetParam();
|
||||
Size sz = get<0>(p);
|
||||
int srcType = get<0>(get<1>(p));
|
||||
int dstType = get<1>(get<1>(p));
|
||||
|
||||
cv::Mat a = Mat(sz, srcType);
|
||||
cv::Scalar b;
|
||||
cv::Mat c = Mat(sz, dstType);
|
||||
|
||||
declare.in(a, b, WARMUP_RNG).out(c);
|
||||
|
||||
if (CV_MAT_DEPTH(dstType) == CV_32S)
|
||||
{
|
||||
//see ticket 1529: subtract can be without saturation on 32S
|
||||
a /= 2;
|
||||
b /= 2;
|
||||
}
|
||||
|
||||
TEST_CYCLE() cv::subtract(a, b, c, /* mask */ noArray(), dstType);
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(ArithmMixedTest, subtractScalarSameType)
|
||||
{
|
||||
auto p = GetParam();
|
||||
Size sz = get<0>(p);
|
||||
int srcType = get<0>(get<1>(p));
|
||||
int dstType = get<1>(get<1>(p));
|
||||
|
||||
cv::Mat a = Mat(sz, srcType);
|
||||
cv::Scalar b;
|
||||
cv::Mat c = Mat(sz, dstType);
|
||||
|
||||
declare.in(a, b, WARMUP_RNG).out(c);
|
||||
|
||||
if (CV_MAT_DEPTH(dstType) < CV_32S)
|
||||
{
|
||||
b = Scalar(1, 0, 3, 4); // don't pass non-integer values for 8U/8S/16U/16S processing
|
||||
}
|
||||
else if (CV_MAT_DEPTH(dstType) == CV_32S)
|
||||
{
|
||||
//see ticket 1529: subtract can be without saturation on 32S
|
||||
a /= 2;
|
||||
b = Scalar(1, 0, -3, 4); // don't pass non-integer values for 32S processing
|
||||
}
|
||||
|
||||
TEST_CYCLE() cv::subtract(a, b, c, /* mask */ noArray(), dstType);
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(ArithmMixedTest, multiply)
|
||||
{
|
||||
auto p = GetParam();
|
||||
Size sz = get<0>(p);
|
||||
int srcType = get<0>(get<1>(p));
|
||||
int dstType = get<1>(get<1>(p));
|
||||
|
||||
cv::Mat a(sz, srcType), b(sz, srcType), c(sz, dstType);
|
||||
|
||||
declare.in(a, b, WARMUP_RNG).out(c);
|
||||
if (CV_MAT_DEPTH(dstType) == CV_32S)
|
||||
{
|
||||
//According to docs, saturation is not applied when result is 32bit integer
|
||||
a /= (2 << 16);
|
||||
b /= (2 << 16);
|
||||
}
|
||||
|
||||
TEST_CYCLE() cv::multiply(a, b, c, /* scale */ 1.0, dstType);
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(ArithmMixedTest, multiplyScale)
|
||||
{
|
||||
auto p = GetParam();
|
||||
Size sz = get<0>(p);
|
||||
int srcType = get<0>(get<1>(p));
|
||||
int dstType = get<1>(get<1>(p));
|
||||
|
||||
cv::Mat a(sz, srcType), b(sz, srcType), c(sz, dstType);
|
||||
double scale = 0.5;
|
||||
|
||||
declare.in(a, b, WARMUP_RNG).out(c);
|
||||
|
||||
if (CV_MAT_DEPTH(dstType) == CV_32S)
|
||||
{
|
||||
//According to docs, saturation is not applied when result is 32bit integer
|
||||
a /= (2 << 16);
|
||||
b /= (2 << 16);
|
||||
}
|
||||
|
||||
TEST_CYCLE() cv::multiply(a, b, c, scale, dstType);
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(ArithmMixedTest, divide)
|
||||
{
|
||||
auto p = GetParam();
|
||||
Size sz = get<0>(p);
|
||||
int srcType = get<0>(get<1>(p));
|
||||
int dstType = get<1>(get<1>(p));
|
||||
|
||||
cv::Mat a(sz, srcType), b(sz, srcType), c(sz, dstType);
|
||||
double scale = 0.5;
|
||||
|
||||
declare.in(a, b, WARMUP_RNG).out(c);
|
||||
|
||||
TEST_CYCLE() cv::divide(a, b, c, scale, dstType);
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
PERF_TEST_P_(ArithmMixedTest, reciprocal)
|
||||
{
|
||||
auto p = GetParam();
|
||||
Size sz = get<0>(p);
|
||||
int srcType = get<0>(get<1>(p));
|
||||
int dstType = get<1>(get<1>(p));
|
||||
|
||||
cv::Mat b(sz, srcType), c(sz, dstType);
|
||||
double scale = 0.5;
|
||||
|
||||
declare.in(b, WARMUP_RNG).out(c);
|
||||
|
||||
TEST_CYCLE() cv::divide(scale, b, c, dstType);
|
||||
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/ , ArithmMixedTest,
|
||||
testing::Combine(
|
||||
testing::Values(szVGA, sz720p, sz1080p),
|
||||
testing::Values(std::tuple<perf::MatType, perf::MatType>{CV_8U, CV_16U},
|
||||
std::tuple<perf::MatType, perf::MatType>{CV_8S, CV_16S},
|
||||
std::tuple<perf::MatType, perf::MatType>{CV_8U, CV_32F},
|
||||
std::tuple<perf::MatType, perf::MatType>{CV_8S, CV_32F}
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
///////////// Rotate ////////////////////////
|
||||
|
||||
typedef perf::TestBaseWithParam<std::tuple<cv::Size, int, perf::MatType>> RotateTest;
|
||||
|
||||
Reference in New Issue
Block a user