pyopencl icon indicating copy to clipboard operation
pyopencl copied to clipboard

The `type<n>` cannot be hinted properly in IDEs.

Open PyMarc2 opened this issue 2 years ago • 3 comments

The type<n> cannot be hinted properly in IDEs.

e.g

import pyopencl as cl
import pyopencl.cltypes

N = 10
HOST_myArray = np.array([cl.cltypes.make_float4(1, 0, 0, 0)] * N, dtype=cl.cltypes.float4)

The make_float4 function and float4 types are not recognized. They are executed, but I think since they are not explicitly declared in cltypes.py, the ides have a hard time understanding

PyMarc2 avatar Apr 01 '22 21:04 PyMarc2

That's because they're generated at runtime:

https://github.com/inducer/pyopencl/blob/291649892f4972e46c5823bfa359b37ad94d6cd5/pyopencl/cltypes.py#L72-L83

I suspect it'd be a simple exercise to rewrite this so that it generates source code that can then be read by an IDE? I'd be open to looking at a PR...

inducer avatar Apr 01 '22 22:04 inducer

I've looked everywhere and tried many things. It's impossible not to declare the variable name before runtime. I would just add empty containers type<n>=None and make_type<n>=None. It seems to work locally because after all the containers are overridden in the global namespace by the set_global from the create_vector_types function call.

Would that be an okay fix?

PyMarc2 avatar Apr 02 '22 19:04 PyMarc2

It's impossible not to declare the variable name before runtime.

I agree. That's why I proposed that we generate the source at install time.

inducer avatar Jun 30 '22 00:06 inducer