Skip to content

Tuple-unpack assignment to wp.ref parameters fails #1581

Description

@shi-eric

Description

Tuple-unpack assignment to wp.ref[T] parameters does not behave like sequential assignment.

wp.ref[T] assignment is documented as mutating the caller's storage, and simple assignment is covered by test_ref_simple_assignment_mutates. Tuple-unpack assignment should preserve the same behavior for each ref target.

Reproducer

import warp as wp


@wp.func
def set_pair(x: wp.ref[wp.float32], y: wp.ref[wp.float32], a: wp.float32, b: wp.float32):
    x, y = a, b


@wp.kernel(enable_backward=False)
def kernel(out: wp.array(dtype=wp.float32)):
    x = wp.float32(0.0)
    y = wp.float32(0.0)

    set_pair(x, y, wp.float32(3.0), wp.float32(4.0))

    out[0] = x
    out[1] = y


out = wp.zeros(2, dtype=wp.float32, device="cpu")
wp.launch(kernel, dim=1, outputs=[out], device="cpu")
print(out.numpy())

Expected behavior

The tuple assignment should be equivalent to:

x = a
y = b

and out should contain:

[3.0, 4.0]

Actual behavior

Codegen rejects the assignment:

WarpCodegenTypeError: Error, assigning to existing symbol x (wp.ref[float32]) with different type (<class 'warp._src.types.float32'>)

Verification

Reproduced on main at 57f7a778c8cb08c73b3e6ed820759f9ee26ad10f with a CPU launch.

Related

Follow-up from #1277.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions