-
-
Notifications
You must be signed in to change notification settings - Fork 56.4k
(2.4) Fix mulSpectrums inplace #7819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(2.4) Fix mulSpectrums inplace #7819
Conversation
|
👍 |
zchrissirhcz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the key for inplace checking and avoid compiler optimization, is to check two Mat's data, instead of two InputArray/OutputArray's obj?
i.e. the follwing approaches, which is correct?
void som_function(InputArray _src, OutputArray _dst)
{
Mat src = _src.getMat( );
Mat dst = _dst.getMat( );
// check approach 1
if ( _src.getObj( ) == _dst.getObj( ) ) {
_src.copyTo(src);
}
// check approach 2
if ( src.data == dst.data ) {
_src.copyTo(src);
}
}| // correct inplace support | ||
| // Case 'dst.data == srcA.data' is handled by implementation, | ||
| // because it is used frequently (filter2D, matchTemplate) | ||
| if (dst.data == srcB.data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dst is a new created Mat, would dst.data equal to srcB.data? Since srcB = _srcB.getMat, and _srcB is passing from external calling, I don't think if (dst.data == srcB.data) is necessary.
@alalek
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dst is a new created Mat
.create() do not reallocate buffer if requested size is the same. Some problems come from this behavior.
|
(Review this pull from cvtColor performance issue in #6760 ) |
Compiler optimizer might reorder instructions for statements like these:
In case of mixed read/write instructions result becomes wrong.