From 51eba617a8a99951ebe7ac6836a8056976f8cd4b Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Fri, 1 Feb 2013 14:01:44 +0400 Subject: [PATCH] a part of PR269 (parallelization of several functions) by Alexander Mordvintsev --- modules/core/src/matrix.cpp | 20 ++++++++++---------- modules/core/src/stat.cpp | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 54adb5d..f21e6ac 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -2459,7 +2459,7 @@ static void generateRandomCenter(const vector& 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(0); - parallel_for(BlockedRange(0, N), + parallel_for_(Range(0, N), KMeansDistanceComputer(dist, labels, data, centers)); compactness = 0; for( i = 0; i < N; i++ ) diff --git a/modules/core/src/stat.cpp b/modules/core/src/stat.cpp index fe98cf7..b62f10a 100644 --- a/modules/core/src/stat.cpp +++ b/modules/core/src/stat.cpp @@ -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 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,8 +1899,8 @@ 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), - BatchDistInvoker(src1, src2, dist, nidx, K, mask, update, func)); + parallel_for_(Range(0, src1.rows), + BatchDistInvoker(src1, src2, dist, nidx, K, mask, update, func)); } -- 2.7.4