Skip to content

Commit

Permalink
Fixed a bug when assigning a static func to a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdiataei committed Oct 10, 2024
1 parent cae2ca4 commit 5f58bdf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions warp/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,9 @@ def emit_Name(adj, node):
# lookup symbol, if it has already been assigned to a variable then return the existing mapping
if node.id in adj.symbols:
return adj.symbols[node.id]
# Check if the node has a warp_func attribute
if hasattr(node, 'warp_func'):
return node.warp_func

obj = adj.resolve_external_reference(node.id)

Expand Down Expand Up @@ -2323,6 +2326,18 @@ def emit_Assign(adj, node):
raise WarpCodegenError(
"Tuple constructs are not supported in kernels. Use vectors like `wp.vec3()` for small collections instead."
)
elif isinstance(lhs, ast.Name):
# symbol name
name = lhs.id

# evaluate rhs
rhs = adj.eval(node.value)

# Check if rhs is a function object
if isinstance(rhs, warp.context.Function):
# Assign the function directly to the symbol table
adj.symbols[name] = rhs
return

# handle the case where we are assigning multiple output variables
if isinstance(lhs, ast.Tuple):
Expand Down

0 comments on commit 5f58bdf

Please sign in to comment.