NVIDIA / warp

A Python framework for high performance GPU simulation and graphics
https://nvidia.github.io/warp/
Other
4.07k stars 224 forks source link

Suggestion: Make `wp.array` class Generic #20

Open lebrice opened 2 years ago

lebrice commented 2 years ago

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:

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!

mmacklin commented 2 years ago

Ah, this is a great suggestion, thanks @lebrice! I will look into what it would mean for the code base.

kmarchais commented 6 months ago

Hello, indeed this feature would be great, is there any news about it?