Suggestion: Make `wp.array` class Generic
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.1k
- Forks
- 624
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 5
Description
Hello! I've got a question: Have you considered making wp.array a Generic type, rather than passing the arguments to the constructor in type annotations?
For example, from this:
@wp.kernel
def apply_forces(grid : wp.uint64,
particle_x: wp.array(dtype=wp.vec3),
particle_v: wp.array(dtype=wp.vec3),
particle_f: wp.array(dtype=wp.vec3),
radius: float,
k_contact: float,
k_damp: float,
k_friction: float,
k_mu: float):
...
to this:
@wp.kernel
def apply_forces(grid : wp.uint64,
particle_x: wp.array[wp.vec3],
particle_v: wp.array[wp.vec3],
particle_f: wp.array[wp.vec3],
radius: float,
k_contact: float,
k_damp: float,
k_friction: float,
k_mu: float):
...
This would have the following benefits:
- This would make the annotations "valid" (i.e. no calls inside annotations), so that type checkers could be used in the codebase.
- This would make it possible to enable postponed evaluation of type annotations in the user code (https://peps.python.org/pep-0563/), which doesn't seem to be supported atm (but correct me if I'm wrong).
I assume you're using something like typing.get_type_hints or the __annotations__ dict directly in wp.kernel to extract the type annotations from the function, correct?
With a generic wp.array type, the dtype can still be easily be recovered using typing.get_args on the annotation.
Let me know what you think!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing wp.array and the @wp.kernel annotation-processing entry point, checking whether typing.get_type_hints or annotations is used. Compare how typing.get_args could recover the dtype, and define done as supporting wp.array[T] while preserving kernel annotation behavior and postponed-evaluation use cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100