perf_reduce.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "perf_precomp.hpp"
  2. #include "opencv2/core/core_c.h"
  3. namespace opencv_test
  4. {
  5. using namespace perf;
  6. CV_ENUM(ROp, CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN)
  7. typedef tuple<Size, MatType, ROp> Size_MatType_ROp_t;
  8. typedef perf::TestBaseWithParam<Size_MatType_ROp_t> Size_MatType_ROp;
  9. PERF_TEST_P(Size_MatType_ROp, reduceR,
  10. testing::Combine(
  11. testing::Values(TYPICAL_MAT_SIZES),
  12. testing::Values(TYPICAL_MAT_TYPES),
  13. ROp::all()
  14. )
  15. )
  16. {
  17. Size sz = get<0>(GetParam());
  18. int matType = get<1>(GetParam());
  19. int reduceOp = get<2>(GetParam());
  20. int ddepth = -1;
  21. if( CV_MAT_DEPTH(matType) < CV_32S && (reduceOp == REDUCE_SUM || reduceOp == REDUCE_AVG) )
  22. ddepth = CV_32S;
  23. Mat src(sz, matType);
  24. Mat vec(1, sz.width, ddepth < 0 ? matType : ddepth);
  25. declare.in(src, WARMUP_RNG).out(vec);
  26. declare.time(100);
  27. int runs = 15;
  28. TEST_CYCLE_MULTIRUN(runs) reduce(src, vec, 0, reduceOp, ddepth);
  29. SANITY_CHECK(vec, 1);
  30. }
  31. PERF_TEST_P(Size_MatType_ROp, reduceC,
  32. testing::Combine(
  33. testing::Values(TYPICAL_MAT_SIZES),
  34. testing::Values(TYPICAL_MAT_TYPES),
  35. ROp::all()
  36. )
  37. )
  38. {
  39. Size sz = get<0>(GetParam());
  40. int matType = get<1>(GetParam());
  41. int reduceOp = get<2>(GetParam());
  42. int ddepth = -1;
  43. if( CV_MAT_DEPTH(matType)< CV_32S && (reduceOp == REDUCE_SUM || reduceOp == REDUCE_AVG) )
  44. ddepth = CV_32S;
  45. Mat src(sz, matType);
  46. Mat vec(sz.height, 1, ddepth < 0 ? matType : ddepth);
  47. declare.in(src, WARMUP_RNG).out(vec);
  48. declare.time(100);
  49. TEST_CYCLE() reduce(src, vec, 1, reduceOp, ddepth);
  50. SANITY_CHECK(vec, 1);
  51. }
  52. typedef tuple<Size, MatType, int> Size_MatType_RMode_t;
  53. typedef perf::TestBaseWithParam<Size_MatType_RMode_t> Size_MatType_RMode;
  54. PERF_TEST_P(Size_MatType_RMode, DISABLED_reduceArgMinMax, testing::Combine(
  55. testing::Values(TYPICAL_MAT_SIZES),
  56. testing::Values(CV_8U, CV_32F),
  57. testing::Values(0, 1)
  58. )
  59. )
  60. {
  61. Size srcSize = get<0>(GetParam());
  62. int matType = get<1>(GetParam());
  63. int axis = get<2>(GetParam());
  64. Mat src(srcSize, matType);
  65. std::vector<int> dstSize(src.dims);
  66. std::copy(src.size.p, src.size.p + src.dims, dstSize.begin());
  67. dstSize[axis] = 1;
  68. Mat dst(dstSize, CV_32S, 0.);
  69. declare.in(src, WARMUP_RNG).out(dst);
  70. TEST_CYCLE() cv::reduceArgMin(src, dst, axis, true);
  71. SANITY_CHECK_NOTHING();
  72. }
  73. } // namespace