inducer / pyopencl

OpenCL integration for Python, plus shiny features
http://mathema.tician.de/software/pyopencl
Other
1.05k stars 241 forks source link

Return NotImplented for arithmetic on non-scalars, non-cl.Arrays #495

Closed kaushikcfd closed 3 years ago

kaushikcfd commented 3 years ago

On main, the following (buggy) behavior is seen:

$ cat fail_pyopencl_arith.py 
from dataclasses import dataclass
import numpy as np
import pyopencl as cl
import pyopencl.array as cla

ctx = cl.create_some_context()
cq = cl.CommandQueue(ctx)

@dataclass
class ArrayContainer:
    _data: np.ndarray

    def __eq__(self, other):
        return ArrayContainer(self._data == other)

print(ArrayContainer(np.ones(100)) + cla.zeros(cq, (10,), dtype=np.float64))

$ python fail_pyopencl_arith.py 
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
inducer commented 3 years ago

Yikes, this is bad. Thanks for catching and fixing this. I'll roll a release to avoid other folks being bitten by it.

inducer commented 3 years ago

436a5cbd2e25c5ef0eff610df0a13a7a18803f45 / https://pypi.org/project/pyopencl/2021.2.4/