arrayfire / arrayfire-python

Python bindings for ArrayFire: A general purpose GPU library.
https://arrayfire.com
BSD 3-Clause "New" or "Revised" License
417 stars 65 forks source link

remainder function giving negative result (af.rem) #180

Closed matkraj closed 6 years ago

matkraj commented 6 years ago

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

-1

which should be:

2

pavanky commented 6 years ago

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

matkraj commented 6 years ago

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

matkraj commented 6 years ago

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)
pavanky commented 6 years ago

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

matkraj commented 6 years ago

pull request https://github.com/arrayfire/arrayfire-python/pull/181