2011-10-07 21:55:26 +08:00
|
|
|
#include "perf_precomp.hpp"
|
|
|
|
|
2017-11-05 21:48:40 +08:00
|
|
|
namespace opencv_test
|
|
|
|
{
|
2011-10-07 21:55:26 +08:00
|
|
|
using namespace perf;
|
|
|
|
|
2018-01-18 23:11:30 +08:00
|
|
|
namespace {
|
2011-10-07 21:55:26 +08:00
|
|
|
|
2018-01-18 23:11:30 +08:00
|
|
|
typedef perf::TestBaseWithParam<size_t> VectorLength;
|
2012-10-10 16:28:17 +08:00
|
|
|
|
2011-10-07 21:55:26 +08:00
|
|
|
PERF_TEST_P(VectorLength, phase32f, testing::Values(128, 1000, 128*1024, 512*1024, 1024*1024))
|
|
|
|
{
|
2012-03-17 05:21:04 +08:00
|
|
|
size_t length = GetParam();
|
2011-10-07 21:55:26 +08:00
|
|
|
vector<float> X(length);
|
|
|
|
vector<float> Y(length);
|
|
|
|
vector<float> angle(length);
|
|
|
|
|
|
|
|
declare.in(X, Y, WARMUP_RNG).out(angle);
|
|
|
|
|
2011-12-30 00:46:16 +08:00
|
|
|
TEST_CYCLE_N(200) cv::phase(X, Y, angle, true);
|
2011-10-07 21:55:26 +08:00
|
|
|
|
2011-12-28 00:37:24 +08:00
|
|
|
SANITY_CHECK(angle, 5e-5);
|
2011-10-07 21:55:26 +08:00
|
|
|
}
|
2012-10-10 16:28:17 +08:00
|
|
|
|
2016-05-24 18:57:27 +08:00
|
|
|
PERF_TEST_P(VectorLength, phase64f, testing::Values(128, 1000, 128*1024, 512*1024, 1024*1024))
|
|
|
|
{
|
|
|
|
size_t length = GetParam();
|
|
|
|
vector<double> X(length);
|
|
|
|
vector<double> Y(length);
|
|
|
|
vector<double> angle(length);
|
|
|
|
|
|
|
|
declare.in(X, Y, WARMUP_RNG).out(angle);
|
|
|
|
|
|
|
|
TEST_CYCLE_N(200) cv::phase(X, Y, angle, true);
|
|
|
|
|
|
|
|
SANITY_CHECK(angle, 5e-5);
|
|
|
|
}
|
|
|
|
|
2018-01-18 23:11:30 +08:00
|
|
|
typedef perf::TestBaseWithParam< testing::tuple<int, int, int> > KMeans;
|
|
|
|
|
|
|
|
PERF_TEST_P_(KMeans, single_iter)
|
2012-10-10 16:28:17 +08:00
|
|
|
{
|
|
|
|
RNG& rng = theRNG();
|
2018-01-18 23:11:30 +08:00
|
|
|
const int K = testing::get<0>(GetParam());
|
|
|
|
const int dims = testing::get<1>(GetParam());
|
|
|
|
const int N = testing::get<2>(GetParam());
|
2012-10-10 16:28:17 +08:00
|
|
|
const int attempts = 5;
|
|
|
|
|
2018-01-18 23:11:30 +08:00
|
|
|
Mat data(N, dims, CV_32F);
|
|
|
|
rng.fill(data, RNG::UNIFORM, -0.1, 0.1);
|
2012-10-10 16:28:17 +08:00
|
|
|
|
2018-01-18 23:11:30 +08:00
|
|
|
const int N0 = K;
|
2012-10-10 16:28:17 +08:00
|
|
|
Mat data0(N0, dims, CV_32F);
|
|
|
|
rng.fill(data0, RNG::UNIFORM, -1, 1);
|
|
|
|
|
2018-01-18 23:11:30 +08:00
|
|
|
for (int i = 0; i < N; i++)
|
|
|
|
{
|
|
|
|
int base = rng.uniform(0, N0);
|
|
|
|
cv::add(data0.row(base), data.row(i), data.row(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
declare.in(data);
|
|
|
|
|
|
|
|
Mat labels, centers;
|
|
|
|
|
|
|
|
TEST_CYCLE()
|
|
|
|
{
|
|
|
|
kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 1, 0),
|
|
|
|
attempts, KMEANS_PP_CENTERS, centers);
|
|
|
|
}
|
|
|
|
|
|
|
|
SANITY_CHECK_NOTHING();
|
|
|
|
}
|
|
|
|
|
|
|
|
PERF_TEST_P_(KMeans, good)
|
|
|
|
{
|
|
|
|
RNG& rng = theRNG();
|
|
|
|
const int K = testing::get<0>(GetParam());
|
|
|
|
const int dims = testing::get<1>(GetParam());
|
|
|
|
const int N = testing::get<2>(GetParam());
|
|
|
|
const int attempts = 5;
|
|
|
|
|
2012-10-10 16:28:17 +08:00
|
|
|
Mat data(N, dims, CV_32F);
|
2018-01-18 23:11:30 +08:00
|
|
|
rng.fill(data, RNG::UNIFORM, -0.1, 0.1);
|
|
|
|
|
|
|
|
const int N0 = K;
|
|
|
|
Mat data0(N0, dims, CV_32F);
|
|
|
|
rng.fill(data0, RNG::UNIFORM, -1, 1);
|
|
|
|
|
|
|
|
for (int i = 0; i < N; i++)
|
|
|
|
{
|
|
|
|
int base = rng.uniform(0, N0);
|
|
|
|
cv::add(data0.row(base), data.row(i), data.row(i));
|
|
|
|
}
|
2012-10-10 16:28:17 +08:00
|
|
|
|
|
|
|
declare.in(data);
|
|
|
|
|
2018-01-18 23:11:30 +08:00
|
|
|
Mat labels, centers;
|
|
|
|
|
2012-10-10 16:28:17 +08:00
|
|
|
TEST_CYCLE()
|
|
|
|
{
|
|
|
|
kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0),
|
|
|
|
attempts, KMEANS_PP_CENTERS, centers);
|
|
|
|
}
|
|
|
|
|
2018-01-18 23:11:30 +08:00
|
|
|
SANITY_CHECK_NOTHING();
|
|
|
|
}
|
|
|
|
|
|
|
|
PERF_TEST_P_(KMeans, with_duplicates)
|
|
|
|
{
|
|
|
|
RNG& rng = theRNG();
|
|
|
|
const int K = testing::get<0>(GetParam());
|
|
|
|
const int dims = testing::get<1>(GetParam());
|
|
|
|
const int N = testing::get<2>(GetParam());
|
|
|
|
const int attempts = 5;
|
|
|
|
|
|
|
|
Mat data(N, dims, CV_32F, Scalar::all(0));
|
|
|
|
|
|
|
|
const int N0 = std::max(2, K * 2 / 3);
|
|
|
|
Mat data0(N0, dims, CV_32F);
|
|
|
|
rng.fill(data0, RNG::UNIFORM, -1, 1);
|
|
|
|
|
|
|
|
for (int i = 0; i < N; i++)
|
|
|
|
{
|
|
|
|
int base = rng.uniform(0, N0);
|
|
|
|
data0.row(base).copyTo(data.row(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
declare.in(data);
|
2012-10-10 16:28:17 +08:00
|
|
|
|
2018-01-18 23:11:30 +08:00
|
|
|
Mat labels, centers;
|
|
|
|
|
|
|
|
TEST_CYCLE()
|
2012-10-10 16:28:17 +08:00
|
|
|
{
|
2018-01-18 23:11:30 +08:00
|
|
|
kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0),
|
|
|
|
attempts, KMEANS_PP_CENTERS, centers);
|
2012-10-10 16:28:17 +08:00
|
|
|
}
|
|
|
|
|
2018-01-18 23:11:30 +08:00
|
|
|
SANITY_CHECK_NOTHING();
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(/*nothing*/ , KMeans,
|
|
|
|
testing::Values(
|
|
|
|
// K clusters, dims, N points
|
|
|
|
testing::make_tuple(2, 3, 100000),
|
|
|
|
testing::make_tuple(4, 3, 500),
|
|
|
|
testing::make_tuple(4, 3, 1000),
|
|
|
|
testing::make_tuple(4, 3, 10000),
|
|
|
|
testing::make_tuple(8, 3, 1000),
|
|
|
|
testing::make_tuple(8, 16, 1000),
|
|
|
|
testing::make_tuple(8, 64, 1000),
|
|
|
|
testing::make_tuple(16, 16, 1000),
|
|
|
|
testing::make_tuple(16, 32, 1000),
|
|
|
|
testing::make_tuple(32, 16, 1000),
|
|
|
|
testing::make_tuple(32, 32, 1000),
|
|
|
|
testing::make_tuple(100, 2, 1000)
|
|
|
|
)
|
|
|
|
);
|
2012-10-10 16:28:17 +08:00
|
|
|
|
|
|
|
}
|
2017-11-05 21:48:40 +08:00
|
|
|
|
|
|
|
} // namespace
|