From 893f75444dc051b98eae5fb8aa37b5ed9b2aeac4 Mon Sep 17 00:00:00 2001 From: Kirill Kornyakov Date: Thu, 22 Dec 2011 06:22:16 +0000 Subject: [PATCH] Optimized version of ReduceR functions and one ReduceC function added Attention! Optimized ReduceC function produced the bug --- modules/core/src/matrix.cpp | 54 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 8188c1b..deb0638 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -1933,10 +1933,10 @@ reduceC_( const Mat& srcmat, Mat& dstmat ) a0 = op(a0, (WT)src[i+k]); } a0 = op(a0, a1); - dst[k] = (ST)a0; + dst[k] = (ST)a0; } } - } + } } typedef void (*ReduceFunc)( const Mat& src, Mat& dst ); @@ -1977,7 +1977,11 @@ void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype) if( op == CV_REDUCE_SUM ) { if(sdepth == CV_8U && ddepth == CV_32S) +#ifdef HAVE_TEGRA_OPTIMIZATION + func = tegra::getTegraOptimized_reduceR8uAdd(tegra::reduceR8uAdd); +#else func = reduceR_ >; +#endif else if(sdepth == CV_8U && ddepth == CV_32F) func = reduceR_ >; else if(sdepth == CV_8U && ddepth == CV_64F) @@ -1990,8 +1994,12 @@ void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype) func = reduceR_ >; else if(sdepth == CV_16S && ddepth == CV_64F) func = reduceR_ >; - else if(sdepth == CV_32F && ddepth == CV_32F) - func = reduceR_ >; + else if(sdepth == CV_32F && ddepth == CV_32F) + #ifdef HAVE_TEGRA_OPTIMIZATION + func = tegra::getTegraOptimized_reduceR32fAdd(tegra::reduceR32fAdd); +#else + func = reduceR_ >; +#endif else if(sdepth == CV_32F && ddepth == CV_64F) func = reduceR_ >; else if(sdepth == CV_64F && ddepth == CV_64F) @@ -2000,26 +2008,42 @@ void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype) else if(op == CV_REDUCE_MAX) { if(sdepth == CV_8U && ddepth == CV_8U) +#ifdef HAVE_TEGRA_OPTIMIZATION + func = tegra::getTegraOptimized_reduceR8uMax(tegra::reduceR8uMax); +#else func = reduceR_ >; - else if(sdepth == CV_16U && ddepth == CV_16U) +#endif + else if(sdepth == CV_16U && ddepth == CV_16U) func = reduceR_ >; else if(sdepth == CV_16S && ddepth == CV_16S) func = reduceR_ >; else if(sdepth == CV_32F && ddepth == CV_32F) +#ifdef HAVE_TEGRA_OPTIMIZATION + func = tegra::getTegraOptimized_reduceR32fMax(tegra::reduceR32fMax); +#else func = reduceR_ >; - else if(sdepth == CV_64F && ddepth == CV_64F) +#endif + else if(sdepth == CV_64F && ddepth == CV_64F) func = reduceR_ >; } else if(op == CV_REDUCE_MIN) { if(sdepth == CV_8U && ddepth == CV_8U) +#ifdef HAVE_TEGRA_OPTIMIZATION + func = tegra::getTegraOptimized_reduceR8uMin(tegra::reduceR8uMin); +#else func = reduceR_ >; +#endif else if(sdepth == CV_16U && ddepth == CV_16U) func = reduceR_ >; else if(sdepth == CV_16S && ddepth == CV_16S) func = reduceR_ >; else if(sdepth == CV_32F && ddepth == CV_32F) +#ifdef HAVE_TEGRA_OPTIMIZATION + func = tegra::getTegraOptimized_reduceR32fMin(tegra::reduceR32fMin); +#else func = reduceR_ >; +#endif else if(sdepth == CV_64F && ddepth == CV_64F) func = reduceR_ >; } @@ -2029,7 +2053,11 @@ void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype) if(op == CV_REDUCE_SUM) { if(sdepth == CV_8U && ddepth == CV_32S) - func = reduceC_ >; +#ifdef HAVE_TEGRA_OPTIMIZATION + func = tegra::getTegraOptimized_reduceC8uAdd(tegra::reduceC8uAdd); +#else + func = reduceC_ >; +#endif else if(sdepth == CV_8U && ddepth == CV_32F) func = reduceC_ >; else if(sdepth == CV_8U && ddepth == CV_64F) @@ -2042,7 +2070,7 @@ void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype) func = reduceC_ >; else if(sdepth == CV_16S && ddepth == CV_64F) func = reduceC_ >; - else if(sdepth == CV_32F && ddepth == CV_32F) + else if(sdepth == CV_32F && ddepth == CV_32F) func = reduceC_ >; else if(sdepth == CV_32F && ddepth == CV_64F) func = reduceC_ >; @@ -2052,8 +2080,8 @@ void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype) else if(op == CV_REDUCE_MAX) { if(sdepth == CV_8U && ddepth == CV_8U) - func = reduceC_ >; - else if(sdepth == CV_16U && ddepth == CV_16U) + func = reduceC_ >; + else if(sdepth == CV_16U && ddepth == CV_16U) func = reduceC_ >; else if(sdepth == CV_16S && ddepth == CV_16S) func = reduceC_ >; @@ -2083,10 +2111,10 @@ void cv::reduce(InputArray _src, OutputArray _dst, int dim, int op, int dtype) func( src, temp ); - if( op0 == CV_REDUCE_AVG ) + if( op0 == CV_REDUCE_AVG ) temp.convertTo(dst, dst.type(), 1./(dim == 0 ? src.rows : src.cols)); -} - + } + //////////////////////////////////////// sort /////////////////////////////////////////// -- 2.7.4