NVIDIA / warp

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

[REQUEST] Shadowing python built-in function names with warp.func #308

Closed steinraf closed 2 months ago

steinraf commented 2 months ago

Description

Would it be possible to allow shadowing python built-in functions with functions decorated by wp.func?

Context

The following code

import warp as wp

@wp.func
def sum(a: wp.vec3) -> float:
    return a[0] + a[1] + a[2]

@wp.kernel
def k():
    sum(wp.vec3(1.0))

wp.launch(k, [1])

results in ;Could not find function sum as a built-in or user-defined function. Note that user functions must be annotated with a @wp.func decorator to be called from a kernel.

This would not only be useful for sum, but also for other built-in names like abs, filter, hash or others.

Currently this also prohibits function names shadowing built-in constants like Ellipsis or NotImplemented, but this is probably a sane design choice.

nvlukasz commented 2 months ago

I agree that the current behaviour seems wrong. Python allows shadowing builtins, so we should allow that as well in Warp. I can take a look, thanks for reporting!