Registered Member
|
Hello!
I'm trying to compute the sign() matrix (vector in this case) that is similar to GLSL's sign() https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/sign.xhtml The main difference is in the behavior of when the input is 0. GLSL returns 1 and cwiseSign returns 0. I've found two propose methods of replicating this behavior in Eigen: Using select:
Using unary expressions:
What would be the most efficient way to achieve this? Thanks! |
Registered Member
|
Wanted to loop back on this. After some investigation, it looks like the most efficient way I could find was to use the unaryExpr with std::copysignf()
This, for Vector4fs translates to only 6 SSE instructions: https://godbolt.org/z/6q15ddTE1 |
Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]