pycuda icon indicating copy to clipboard operation
pycuda copied to clipboard

`GPUArray.__div__` does not comply with numpy

Open kaushikcfd opened this issue 3 years ago • 2 comments

Here's an MWE:

>>> import pycuda.autoinit
>>> import pycuda.gpuarray as cu_np
>>> a = cu_np.zeros(10, dtype="int32") + 1
>>> b = cu_np.zeros(10, dtype="int32") + 2
>>> a / b
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int32)

while, Numpy returns an array of 0.5's

>>> import numpy as np
>>> a = np.zeros(10, "int32") + 1
>>> b = np.zeros(10, "int32") + 2
>>> a / b
array([0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5])

kaushikcfd avatar Jun 30 '22 21:06 kaushikcfd

That's clearly a bug. Believe it or not, PyCUDA predates __truediv__, I think. :astonished:

inducer avatar Jun 30 '22 22:06 inducer

There's a proposed fix for this at https://gitlab.tiker.net/inducer/pycuda/-/merge_requests/66.

kaushikcfd avatar Aug 26 '22 22:08 kaushikcfd