Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PyMarc2 opened this issue Apr 1, 2022 · 3 comments
Open

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

PyMarc2 opened this issue Apr 1, 2022 · 3 comments
Labels

Comments

@PyMarc2
Copy link

PyMarc2 commented Apr 1, 2022

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 PyMarc2 added the bug label Apr 1, 2022
@inducer
Copy link
Owner

inducer commented Apr 1, 2022

That's because they're generated at runtime:

names = ["s%d" % i for i in range(count)]
while len(names) < padded_count:
names.append("padding%d" % (len(names) - count))
if len(titles) < len(names):
titles.extend((len(names) - len(titles)) * [None])
try:
dtype = np.dtype(dict(
names=names,
formats=[base_type] * padded_count,
titles=titles))

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
Copy link
Author

PyMarc2 commented Apr 2, 2022

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
Copy link
Owner

inducer commented Jun 30, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants