perf_reduce.cpp 2.5 KB

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