taichi icon indicating copy to clipboard operation
taichi copied to clipboard

[Example] Cast index to int in comet.py to resolve TaichiWarning

Open bluevisor opened this issue 11 months ago • 1 comments

Issue: # This PR addresses a Taichi warning in comet.py by explicitly casting i to an integer in the ti.deactivate function. The warning appeared as follows: TaichiWarning While compiling substep_c76_0, File “taichi/examples/simulation/comet.py”, line 55, in substep: ti.deactivate(x.snode.parent(), [i]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Field index 0 not int32, casting into int32 implicitly

Changes Made

  • Updated ti.deactivate(x.snode.parent(), [i]) to ti.deactivate(x.snode.parent(), [int(i)]) in comet.py.

Rationale

Explicitly casting i to int prevents Taichi from implicitly casting and suppresses the TaichiWarning. This change improves code clarity and ensures compatibility with the expected data type for the function.

Testing

  • Confirmed that the warning is no longer displayed when running comet.py.
  • Functionality of comet.py remains intact after this change.

bluevisor avatar Nov 10 '24 10:11 bluevisor