ocl_pow selects incorrect built-in function (Bug #3977)


Added by Yuri Kulakov over 10 years ago. Updated over 10 years ago.


Status:Done Start date:2014-10-24
Priority:Normal Due date:
Assignee:Alexander Karsakov % Done:

0%

Category:ocl
Target version:3.0-beta
Affected version:branch 'master' (3.0-dev) Operating System:Any
Difficulty:Easy HW Platform:Any
Pull request:https://github.com/Itseez/opencv/pull/3396

Description

modules\core\src\mathfuncs.cpp, ocl_pow function.

There are a couple of issues in the following code:
bool issqrt = std::abs(power - 0.5) < DBL_EPSILON, nonnegative = power >= 0;
const char * const op = issqrt ? "OP_SQRT" : is_ipower ? nonnegative ? "OP_POWN" : "OP_ROOTN" : nonnegative ? "OP_POWR" : "OP_POW";

'nonnegative' here refers to power, and:
- For integer power either pown or rootn built-in function is selected. The choice of rootn is simply wrong - this function calculates x^(1/y) which is not what should be computed here.
- For real values of power powr or pow is selected. But per powr function specification - 'Compute x to the power y, where x is >= 0', so powr should be selected depending on the sign of base (x), not the power (y).

So this code should either completely remove 'nonnegative' logic:
bool issqrt = std::abs(power - 0.5) < DBL_EPSILON;
const char * const op = issqrt ? "OP_SQRT" : is_ipower ? "OP_POWN" : "OP_POW";

or some additional logic should be added to check the sign of the input elements (InputArray _src) and select powr for non-negative values.


History

Updated by Yuri Kulakov over 10 years ago

To reproduce the failure run the following test on Intel CPU platform:

OPENCV_OPENCL_DEVICE=Intel:cpu
opencv_test_core.exe --gtest_filter=OCL_Arithm/Pow*

Updated by Ilya Lavrenov over 10 years ago

Hi Yuri,
You are right, could you submit pull-request with this fix?

Updated by Ilya Lavrenov over 10 years ago

  • Assignee changed from Vadim Pisarevsky to Alexander Karsakov

Updated by Alexander Karsakov over 10 years ago

Hi Yuri,
Thanks for reporting this issue!
I am going to make this fix, if you don't mind.

  • Target version set to 3.0-beta
  • Pull request set to https://github.com/Itseez/opencv/pull/3396

Updated by Alexander Karsakov over 10 years ago

  • Status changed from New to Done

Also available in: Atom PDF