Conversation
alalek
left a comment
There was a problem hiding this comment.
You can add test here (preferred way is adding a separate test for that).
There are already ".div()" methods (per-element, I found with Matx only, looks like scalars are not supported). Should we extend them?
There are already multiplication operation "*".
Users can write: P1 *= 0.5f instead of P1 /= 2 (div by integer is questionable anyway - unclear, not well defined - see example below).
In "integer" case there are different results:
{
Matx<int, 3, 1> P1(1, 2, 3);
P1 /= 2;
std::cout << "P1: " << P1.t() << std::endl;
}
{
Matx<int, 3, 1> P1(1, 2, 3), P2;
P2 = P1 / 2;
std::cout << "P2: " << P2.t() << std::endl;
}
| } | ||
|
|
||
| template<typename _Tp, int m, int n> static inline | ||
| Matx<_Tp, m, n>& operator /= (Matx<_Tp, m, n>& a, int alpha) |
There was a problem hiding this comment.
Matx usually makes sense (used) with floating point numbers (float/double).
So "int" scalar looks out of scope here. Do we really need it?
For floating point computations we can replace multiple divisions by multiplications (they are still more effective than divisions):
_Tp alpha_inv = (_Tp)1.0f / alpha;
for( int i = 0; i < m*n; i++ )
a.val[i] = a.val[i] * alpha_inv;
saturate_cast() is not used for floating point numbers too.
|
Things to be done to complete this PR:
|
cc9510e to
c87b99e
Compare
|
@alalek I finalized the PR as it was discussed on the meeting. Please take a look and merge. |
Add the following operations for
Matx:Output:
TODO: