a part of PR269 (parallelization of several functions) by Alexander Mordvintsev

pull/405/head
Vadim Pisarevsky 12 years ago
parent b179e2dd2d
commit 51eba617a8
  1. 20
      modules/core/src/matrix.cpp
  2. 8
      modules/core/src/stat.cpp

@ -2459,7 +2459,7 @@ static void generateRandomCenter(const vector<Vec2f>& box, float* center, RNG& r
center[j] = ((float)rng*(1.f+margin*2.f)-margin)*(box[j][1] - box[j][0]) + box[j][0];
}
class KMeansPPDistanceComputer
class KMeansPPDistanceComputer : public ParallelLoopBody
{
public:
KMeansPPDistanceComputer( float *_tdist2,
@ -2475,10 +2475,10 @@ public:
step(_step),
stepci(_stepci) { }
void operator()( const cv::BlockedRange& range ) const
void operator()( const cv::Range& range ) const
{
const int begin = range.begin();
const int end = range.end();
const int begin = range.start;
const int end = range.end;
for ( int i = begin; i<end; i++ )
{
@ -2534,7 +2534,7 @@ static void generateCentersPP(const Mat& _data, Mat& _out_centers,
break;
int ci = i;
parallel_for(BlockedRange(0, N),
parallel_for_(Range(0, N),
KMeansPPDistanceComputer(tdist2, data, dist, dims, step, step*ci));
for( i = 0; i < N; i++ )
{
@ -2562,7 +2562,7 @@ static void generateCentersPP(const Mat& _data, Mat& _out_centers,
}
}
class KMeansDistanceComputer
class KMeansDistanceComputer : public ParallelLoopBody
{
public:
KMeansDistanceComputer( double *_distances,
@ -2576,10 +2576,10 @@ public:
{
}
void operator()( const BlockedRange& range ) const
void operator()( const Range& range ) const
{
const int begin = range.begin();
const int end = range.end();
const int begin = range.start;
const int end = range.end;
const int K = centers.rows;
const int dims = centers.cols;
@ -2836,7 +2836,7 @@ double cv::kmeans( InputArray _data, int K,
// assign labels
Mat dists(1, N, CV_64F);
double* dist = dists.ptr<double>(0);
parallel_for(BlockedRange(0, N),
parallel_for_(Range(0, N),
KMeansDistanceComputer(dist, labels, data, centers));
compactness = 0;
for( i = 0; i < N; i++ )

@ -1726,7 +1726,7 @@ typedef void (*BatchDistFunc)(const uchar* src1, const uchar* src2, size_t step2
int nvecs, int len, uchar* dist, const uchar* mask);
struct BatchDistInvoker
struct BatchDistInvoker : public ParallelLoopBody
{
BatchDistInvoker( const Mat& _src1, const Mat& _src2,
Mat& _dist, Mat& _nidx, int _K,
@ -1743,12 +1743,12 @@ struct BatchDistInvoker
func = _func;
}
void operator()(const BlockedRange& range) const
void operator()(const Range& range) const
{
AutoBuffer<int> buf(src2->rows);
int* bufptr = buf;
for( int i = range.begin(); i < range.end(); i++ )
for( int i = range.start; i < range.end; i++ )
{
func(src1->ptr(i), src2->ptr(), src2->step, src2->rows, src2->cols,
K > 0 ? (uchar*)bufptr : dist->ptr(i), mask->data ? mask->ptr(i) : 0);
@ -1899,7 +1899,7 @@ void cv::batchDistance( InputArray _src1, InputArray _src2,
("The combination of type=%d, dtype=%d and normType=%d is not supported",
type, dtype, normType));
parallel_for(BlockedRange(0, src1.rows),
parallel_for_(Range(0, src1.rows),
BatchDistInvoker(src1, src2, dist, nidx, K, mask, update, func));
}

Loading…
Cancel
Save