inducer / pyopencl

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

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

Open PyMarc2 opened 2 years ago

PyMarc2 commented 2 years ago

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

inducer commented 2 years ago

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...

PyMarc2 commented 2 years ago

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?

inducer commented 2 years ago

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.