warp.address_of#
- warp.address_of(expr)[source]#
Return the address of an addressable expression as a
warp.uint64.Only valid inside
@warp.kerneland@warp.funcbodies. The codegen intercepts this call and emits a pointer cast; it is not a normal Python function and cannot be called from regular Python code.Accepted expressions: local variables, array elements (
arr[i]), struct fields (s.field), andwarp.ref[T]parameters. Literals and function-call results are rejected with aWarpCodegenErrorat compile time.Use
array.ptrfor the base pointer of an entirewarp.array. Usewarp.address_of(arr[i])when the pointer to a specific element is needed.- Returns:
The address of the expression’s storage.
- Return type:
- Raises:
RuntimeError – Always, when called from regular Python (outside a kernel or func body).
Example:
@wp.func_native("*(int32_t*)ptr = 42;") def set_via_ptr(ptr: wp.uint64): ... @wp.kernel(enable_backward=False) def my_kernel(result: wp.array[wp.int32]): val = wp.int32(0) set_via_ptr(wp.address_of(val)) result[0] = val # writes 42