1 #include "perf_precomp.hpp" 2 3 using namespace std; 4 using namespace cv; 5 using namespace perf; 6 using std::tr1::make_tuple; 7 using std::tr1::get; 8 9 typedef perf::TestBaseWithParam<size_t> VectorLength; 10 11 typedef std::tr1::tuple<int, int> MaxDim_MaxPoints_t; 12 typedef perf::TestBaseWithParam<MaxDim_MaxPoints_t> MaxDim_MaxPoints; 13 14 PERF_TEST_P(VectorLength, phase32f, testing::Values(128, 1000, 128*1024, 512*1024, 1024*1024)) 15 { 16 size_t length = GetParam(); 17 vector<float> X(length); 18 vector<float> Y(length); 19 vector<float> angle(length); 20 21 declare.in(X, Y, WARMUP_RNG).out(angle); 22 23 TEST_CYCLE_N(200) cv::phase(X, Y, angle, true); 24 25 SANITY_CHECK(angle, 5e-5); 26 } 27 28 PERF_TEST_P( MaxDim_MaxPoints, kmeans, 29 testing::Combine( testing::Values( 16, 32, 64 ), 30 testing::Values( 300, 400, 500) ) ) 31 { 32 RNG& rng = theRNG(); 33 const int MAX_DIM = get<0>(GetParam()); 34 const int MAX_POINTS = get<1>(GetParam()); 35 const int attempts = 5; 36 37 Mat labels, centers; 38 int i, N = 0, N0 = 0, K = 0, dims = 0; 39 dims = rng.uniform(1, MAX_DIM+1); 40 N = rng.uniform(1, MAX_POINTS+1); 41 N0 = rng.uniform(1, MAX(N/10, 2)); 42 K = rng.uniform(1, N+1); 43 44 Mat data0(N0, dims, CV_32F); 45 rng.fill(data0, RNG::UNIFORM, -1, 1); 46 47 Mat data(N, dims, CV_32F); 48 for( i = 0; i < N; i++ ) 49 data0.row(rng.uniform(0, N0)).copyTo(data.row(i)); 50 51 declare.in(data); 52 53 TEST_CYCLE() 54 { 55 kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0), 56 attempts, KMEANS_PP_CENTERS, centers); 57 } 58 59 Mat clusterPointsNumber = Mat::zeros(1, K, CV_32S); 60 61 for( i = 0; i < labels.rows; i++ ) 62 { 63 int clusterIdx = labels.at<int>(i); 64 clusterPointsNumber.at<int>(clusterIdx)++; 65 } 66 67 Mat sortedClusterPointsNumber; 68 cv::sort(clusterPointsNumber, sortedClusterPointsNumber, cv::SORT_EVERY_ROW + cv::SORT_ASCENDING); 69 70 SANITY_CHECK(sortedClusterPointsNumber); 71 } 72