arrayfire / arrayfire-python

Python bindings for ArrayFire: A general purpose GPU library.

Home Page:https://arrayfire.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

remainder function giving negative result (af.rem)

matkraj opened this issue · comments

Hi, I noticed if I calculate reminder function I get:
print(af.rem(af.constant(11,1,1),3))

-1

which should be:

2

@matkraj I think you should be looking at af.mod. This behavior is consistent with IEE (check std::remainder)

@pavanky Thanks, I got confused because there is no af.mod in arrayfire-python.

Probably this needs to be added to arrayfire/arith.py

def mod(lhs, rhs):
    """
    Find the modulus.
    Parameters
    ----------
    lhs : af.Array or scalar
          Multi dimensional arrayfire array or a scalar number.
    rhs : af.Array or scalar
          Multi dimensional arrayfire array or a scalar number.
    Returns
    --------
    out : af.Array
         Contains the moduli after dividing each value of lhs` with those in `rhs`.
    Note
    -------
    - Atleast one of `lhs` and `rhs` needs to be af.Array.
    - If `lhs` and `rhs` are both af.Array, they must be of same size.
    """
    return _arith_binary_func(lhs, rhs, backend.get().af_mod)

@matkraj Do you want to send in a review with this change ?

pull request #181