Numpy aware implementation of modulo

Thanks coyotte for hinting.
Note that the branch is remove by both GCC and Clang.