would it possible to have a modulo (%) operator on Array objects?
Gael, Christoph, what are your thoughts about this? In the tensor library we have defined operators scalar_fmod_op, scalar_mod_op, and scalar_mod2_op:
Should we move that to core? fmod is not trivial to implement correctly, so perhaps we could defer vectorizing it, but having a vectorized integer modulo operator seems like low-hanging fruit.
The lack of vectorized division on x86 makes it not very attractive, of course.
Why not. I think the easiest way to vectorize this for integers on x86 is to cast to double, divide, and cast back (and calculate the remainder).
We could also vectorize pdiv<int32> that way.
And in theory, a constant divider could be vectorized by some multiplication and shifting and subtracting.
For floats/doubles I guess it is relatively simple to get a "good-enough" solution. But getting things like `fmod(MAX_FLOAT, 99.f)` accurate is not trivial, of course. We could implement something which works correctly in most cases and falls down to a non-vectorized path otherwise (similar to our range-reduction in sincos).
API-wise, I'm not sure if we should overload `%` for that or just provide functions (also with one argument a Scalar):
mod(Array,Array), Array::mod(Array), Matrix::cwiseMod(Matrix)
I'm preferring the latter, since % is not overloaded for float and double either. And overloading it only for Array<int> seems unnecessarily complicated.
-- GitLab Migration Automatic Message --
This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.
You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/467.