SIGN IN SIGN UP
taichi-dev / taichi UNCLAIMED

Productive, portable, and performant GPU programming in Python.

import pytest
import taichi as ti
from tests import test_utils
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_function_without_return():
x = ti.field(ti.i32, shape=())
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def foo(val: ti.i32):
x[None] += val
@ti.kernel
def run():
foo(40)
foo(2)
x[None] = 0
run()
assert x[None] == 42
@test_utils.test(arch=[ti.cpu, ti.cuda], debug=True)
def test_function_with_return():
x = ti.field(ti.i32, shape=())
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def foo(val: ti.i32) -> ti.i32:
x[None] += val
return val
@ti.kernel
def run():
a = foo(40)
foo(2)
assert a == 40
x[None] = 0
run()
assert x[None] == 42
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_call_expressions():
x = ti.field(ti.i32, shape=())
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def foo(val: ti.i32) -> ti.i32:
if x[None] > 10:
x[None] += 1
x[None] += val
return 0
@ti.kernel
def run():
assert foo(15) == 0
assert foo(10) == 0
x[None] = 0
run()
assert x[None] == 26
@test_utils.test(arch=[ti.cpu, ti.cuda], debug=True)
def test_default_templates():
@ti.func
def func1(x: ti.template()):
x = 1
@ti.func
def func2(x: ti.template()):
x += 1
@ti.func
def func3(x):
x = 1
@ti.func
def func4(x):
x += 1
@ti.func
def func1_field(x: ti.template()):
x[None] = 1
@ti.func
def func2_field(x: ti.template()):
x[None] += 1
@ti.func
def func3_field(x):
x[None] = 1
@ti.func
def func4_field(x):
x[None] += 1
v = ti.field(dtype=ti.i32, shape=())
@ti.kernel
def run_func():
a = 0
func1(a)
assert a == 1
b = 0
func2(b)
assert b == 1
c = 0
func3(c)
assert c == 0
d = 0
func4(d)
assert d == 0
v[None] = 0
func1_field(v)
assert v[None] == 1
v[None] = 0
func2_field(v)
assert v[None] == 1
v[None] = 0
func3_field(v)
assert v[None] == 1
v[None] = 0
func4_field(v)
assert v[None] == 1
run_func()
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_experimental_templates():
x = ti.field(ti.i32, shape=())
y = ti.field(ti.i32, shape=())
answer = ti.field(ti.i32, shape=8)
@ti.kernel
def kernel_inc(x: ti.template()):
x[None] += 1
def run_kernel():
x[None] = 10
y[None] = 20
kernel_inc(x)
assert x[None] == 11
assert y[None] == 20
kernel_inc(y)
assert x[None] == 11
assert y[None] == 21
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def inc(x: ti.template()):
x[None] += 1
@ti.kernel
[opt] Properly handle FuncCallStmt in CFG and simplify passes (#8139) Issue: #602 Assuming `FuncCallStmt` can load or modify any address. I will write a pass to find out all the addresses loaded and modified in a `FuncCallStmt` later. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at cf4766c</samp> ### Summary 📞🔧🧪 <!-- 1. 📞 for enhancing the control flow graph analysis and optimization to support function calls. 2. 🔧 for improving the simplification of basic blocks by removing a redundant check and adding a condition for function call statements. 3. 🧪 for testing some experimental features of taichi, such as template arguments and assertions in kernels. --> This pull request enhances the control flow graph analysis and optimization to support function calls in taichi kernels. It also improves the simplification of basic blocks and tests some experimental features of taichi. The main files affected are `taichi/ir/control_flow_graph.cpp`, `taichi/transforms/simplify.cpp`, and `tests/python/test_function.py`. > _We unleash the power of `function calls`_ > _We optimize the `control flow graph`_ > _We test the limits of `taichi`'s core_ > _We simplify the `basic blocks` of wrath_ ### Walkthrough * Add support for function calls in control flow graph analysis and optimization ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fR220-R222), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fL979-R983)) * Prevent simplifying function call statements that may have side effects or modify global variables ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edR107-R108)) * Test the experimental template feature that allows passing arguments to functions as template parameters ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L158-R166), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L175-R177)) * Test the support for assertions inside kernels ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L335-R344), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L361-R362)) * Remove a redundant check for function call statements in `BasicBlockSimplify` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100)) * Remove a comment that is no longer relevant in `test_function.py` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329))
2023-06-06 14:55:16 +08:00
def run_func(a: ti.u1):
x[None] = 10
y[None] = 20
[opt] Properly handle FuncCallStmt in CFG and simplify passes (#8139) Issue: #602 Assuming `FuncCallStmt` can load or modify any address. I will write a pass to find out all the addresses loaded and modified in a `FuncCallStmt` later. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at cf4766c</samp> ### Summary 📞🔧🧪 <!-- 1. 📞 for enhancing the control flow graph analysis and optimization to support function calls. 2. 🔧 for improving the simplification of basic blocks by removing a redundant check and adding a condition for function call statements. 3. 🧪 for testing some experimental features of taichi, such as template arguments and assertions in kernels. --> This pull request enhances the control flow graph analysis and optimization to support function calls in taichi kernels. It also improves the simplification of basic blocks and tests some experimental features of taichi. The main files affected are `taichi/ir/control_flow_graph.cpp`, `taichi/transforms/simplify.cpp`, and `tests/python/test_function.py`. > _We unleash the power of `function calls`_ > _We optimize the `control flow graph`_ > _We test the limits of `taichi`'s core_ > _We simplify the `basic blocks` of wrath_ ### Walkthrough * Add support for function calls in control flow graph analysis and optimization ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fR220-R222), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fL979-R983)) * Prevent simplifying function call statements that may have side effects or modify global variables ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edR107-R108)) * Test the experimental template feature that allows passing arguments to functions as template parameters ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L158-R166), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L175-R177)) * Test the support for assertions inside kernels ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L335-R344), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L361-R362)) * Remove a redundant check for function call statements in `BasicBlockSimplify` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100)) * Remove a comment that is no longer relevant in `test_function.py` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329))
2023-06-06 14:55:16 +08:00
if a:
inc(x)
answer[0] = x[None]
answer[1] = y[None]
[opt] Properly handle FuncCallStmt in CFG and simplify passes (#8139) Issue: #602 Assuming `FuncCallStmt` can load or modify any address. I will write a pass to find out all the addresses loaded and modified in a `FuncCallStmt` later. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at cf4766c</samp> ### Summary 📞🔧🧪 <!-- 1. 📞 for enhancing the control flow graph analysis and optimization to support function calls. 2. 🔧 for improving the simplification of basic blocks by removing a redundant check and adding a condition for function call statements. 3. 🧪 for testing some experimental features of taichi, such as template arguments and assertions in kernels. --> This pull request enhances the control flow graph analysis and optimization to support function calls in taichi kernels. It also improves the simplification of basic blocks and tests some experimental features of taichi. The main files affected are `taichi/ir/control_flow_graph.cpp`, `taichi/transforms/simplify.cpp`, and `tests/python/test_function.py`. > _We unleash the power of `function calls`_ > _We optimize the `control flow graph`_ > _We test the limits of `taichi`'s core_ > _We simplify the `basic blocks` of wrath_ ### Walkthrough * Add support for function calls in control flow graph analysis and optimization ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fR220-R222), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fL979-R983)) * Prevent simplifying function call statements that may have side effects or modify global variables ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edR107-R108)) * Test the experimental template feature that allows passing arguments to functions as template parameters ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L158-R166), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L175-R177)) * Test the support for assertions inside kernels ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L335-R344), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L361-R362)) * Remove a redundant check for function call statements in `BasicBlockSimplify` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100)) * Remove a comment that is no longer relevant in `test_function.py` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329))
2023-06-06 14:55:16 +08:00
if a:
inc(y)
answer[2] = x[None]
answer[3] = y[None]
def verify():
assert answer[0] == 11
assert answer[1] == 20
assert answer[2] == 11
assert answer[3] == 21
run_kernel()
[opt] Properly handle FuncCallStmt in CFG and simplify passes (#8139) Issue: #602 Assuming `FuncCallStmt` can load or modify any address. I will write a pass to find out all the addresses loaded and modified in a `FuncCallStmt` later. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at cf4766c</samp> ### Summary 📞🔧🧪 <!-- 1. 📞 for enhancing the control flow graph analysis and optimization to support function calls. 2. 🔧 for improving the simplification of basic blocks by removing a redundant check and adding a condition for function call statements. 3. 🧪 for testing some experimental features of taichi, such as template arguments and assertions in kernels. --> This pull request enhances the control flow graph analysis and optimization to support function calls in taichi kernels. It also improves the simplification of basic blocks and tests some experimental features of taichi. The main files affected are `taichi/ir/control_flow_graph.cpp`, `taichi/transforms/simplify.cpp`, and `tests/python/test_function.py`. > _We unleash the power of `function calls`_ > _We optimize the `control flow graph`_ > _We test the limits of `taichi`'s core_ > _We simplify the `basic blocks` of wrath_ ### Walkthrough * Add support for function calls in control flow graph analysis and optimization ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fR220-R222), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fL979-R983)) * Prevent simplifying function call statements that may have side effects or modify global variables ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edR107-R108)) * Test the experimental template feature that allows passing arguments to functions as template parameters ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L158-R166), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L175-R177)) * Test the support for assertions inside kernels ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L335-R344), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L361-R362)) * Remove a redundant check for function call statements in `BasicBlockSimplify` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100)) * Remove a comment that is no longer relevant in `test_function.py` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329))
2023-06-06 14:55:16 +08:00
run_func(True)
verify()
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_missing_arg_annotation():
with pytest.raises(ti.TaichiSyntaxError, match="must be type annotated"):
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def add(a, b: ti.i32) -> ti.i32:
return a + b
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_missing_return_annotation():
with pytest.raises(ti.TaichiCompilationError, match="return value must be annotated"):
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def add(a: ti.i32, b: ti.i32):
return a + b
@ti.kernel
def run():
add(30, 2)
run()
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_different_argument_type():
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def add(a: ti.f32, b: ti.f32) -> ti.f32:
return a + b
@ti.kernel
def run() -> ti.i32:
return add(1, 2)
assert run() == 3
@pytest.mark.run_in_serial
[cuda] Only set CU_LIMIT_STACK_SIZE when necessary (#7906) If we set it to 8192 unconditionally it'll increase CUDA memory usage by ~800MB on my 3090. It's not necessary when deep recursively real function call isn't involved so let's default to not set it. Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 378709f</samp> Removed redundant and potentially harmful stack size limit settings for CUDA kernels using the LLVM backend. Added a single stack size limit setting based on user preference or default value in the `ti.init` function. These changes aim to improve the performance and compatibility of Taichi on CUDA devices. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 378709f</samp> * Remove redundant and potentially harmful stack size limit settings for every kernel launch on CUDA devices using the LLVM backend ([link](https://github.com/taichi-dev/taichi/pull/7906/files?diff=unified&w=0#diff-d8cf951dea16cc738fc36faee3a158f37a605abccd312c4a6f18d73fd2504332L137-L138)) * Set the stack size limit only once per device, and only if the user specifies a non-zero value in the `ti.init` function, in the function that defines the Taichi runtime functions on CUDA devices using the LLVM backend ([link](https://github.com/taichi-dev/taichi/pull/7906/files?diff=unified&w=0#diff-b9155792159f392bd8bacd44cb1819be5239b022d707499fc364c0f93dd8c5e5R124-R127)) * Change the default value of `cuda_stack_limit` in the `CompileConfig` struct from 8192 to 0, to avoid unnecessary stack size limit settings unless the user explicitly requests them ([link](https://github.com/taichi-dev/taichi/pull/7906/files?diff=unified&w=0#diff-604e33db5b7c4f4b819098dee1f2634a36c0974822c1538aec0d57d28ca00dd9L102-R102))
2023-04-27 16:00:46 +08:00
@test_utils.test(arch=[ti.cpu, ti.cuda], cuda_stack_limit=8192)
def test_recursion():
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def sum(f: ti.template(), l: ti.i32, r: ti.i32) -> ti.i32:
if l == r:
return f[l]
else:
return sum(f, l, (l + r) // 2) + sum(f, (l + r) // 2 + 1, r)
f = ti.field(ti.i32, shape=100)
for i in range(100):
f[i] = i
@ti.kernel
def get_sum() -> ti.i32:
return sum(f, 0, 99)
assert get_sum() == 99 * 50
@pytest.mark.run_in_serial
@test_utils.test(arch=[ti.cpu, ti.cuda], cuda_stack_limit=32768)
def test_deep_recursion():
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def sum_func(n: ti.i32) -> ti.i32:
if n == 0:
return 0
return sum_func(n - 1) + n
@ti.kernel
def sum(n: ti.i32) -> ti.i32:
return sum_func(n)
assert sum(100) == 5050
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_multiple_return():
x = ti.field(ti.i32, shape=())
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def foo(val: ti.i32) -> ti.i32:
if x[None] > 10:
if x[None] > 20:
return 1
x[None] += 1
x[None] += val
return 0
@ti.kernel
def run():
assert foo(15) == 0
assert foo(10) == 0
assert foo(100) == 1
x[None] = 0
run()
assert x[None] == 26
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_return_in_for():
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def foo() -> ti.i32:
for i in range(10):
return 42
@ti.kernel
def bar() -> ti.i32:
return foo()
assert bar() == 42
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_return_in_while():
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def foo() -> ti.i32:
i = 1
while i:
return 42
@ti.kernel
def bar() -> ti.i32:
return foo()
assert bar() == 42
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_return_in_if_in_for():
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def foo(a: ti.i32) -> ti.i32:
s = 0
for i in range(100):
if i == a + 1:
return s
s = s + i
return s
@ti.kernel
def bar(a: ti.i32) -> ti.i32:
return foo(a)
assert bar(10) == 11 * 5
assert bar(200) == 99 * 50
@test_utils.test(arch=[ti.cpu, ti.cuda], debug=True)
def test_ref():
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def foo(a: ti.ref(ti.f32)):
a = 7
@ti.kernel
[opt] Properly handle FuncCallStmt in CFG and simplify passes (#8139) Issue: #602 Assuming `FuncCallStmt` can load or modify any address. I will write a pass to find out all the addresses loaded and modified in a `FuncCallStmt` later. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at cf4766c</samp> ### Summary 📞🔧🧪 <!-- 1. 📞 for enhancing the control flow graph analysis and optimization to support function calls. 2. 🔧 for improving the simplification of basic blocks by removing a redundant check and adding a condition for function call statements. 3. 🧪 for testing some experimental features of taichi, such as template arguments and assertions in kernels. --> This pull request enhances the control flow graph analysis and optimization to support function calls in taichi kernels. It also improves the simplification of basic blocks and tests some experimental features of taichi. The main files affected are `taichi/ir/control_flow_graph.cpp`, `taichi/transforms/simplify.cpp`, and `tests/python/test_function.py`. > _We unleash the power of `function calls`_ > _We optimize the `control flow graph`_ > _We test the limits of `taichi`'s core_ > _We simplify the `basic blocks` of wrath_ ### Walkthrough * Add support for function calls in control flow graph analysis and optimization ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fR220-R222), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fL979-R983)) * Prevent simplifying function call statements that may have side effects or modify global variables ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edR107-R108)) * Test the experimental template feature that allows passing arguments to functions as template parameters ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L158-R166), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L175-R177)) * Test the support for assertions inside kernels ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L335-R344), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L361-R362)) * Remove a redundant check for function call statements in `BasicBlockSimplify` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100)) * Remove a comment that is no longer relevant in `test_function.py` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329))
2023-06-06 14:55:16 +08:00
def bar():
a = 5.0
foo(a)
[opt] Properly handle FuncCallStmt in CFG and simplify passes (#8139) Issue: #602 Assuming `FuncCallStmt` can load or modify any address. I will write a pass to find out all the addresses loaded and modified in a `FuncCallStmt` later. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at cf4766c</samp> ### Summary 📞🔧🧪 <!-- 1. 📞 for enhancing the control flow graph analysis and optimization to support function calls. 2. 🔧 for improving the simplification of basic blocks by removing a redundant check and adding a condition for function call statements. 3. 🧪 for testing some experimental features of taichi, such as template arguments and assertions in kernels. --> This pull request enhances the control flow graph analysis and optimization to support function calls in taichi kernels. It also improves the simplification of basic blocks and tests some experimental features of taichi. The main files affected are `taichi/ir/control_flow_graph.cpp`, `taichi/transforms/simplify.cpp`, and `tests/python/test_function.py`. > _We unleash the power of `function calls`_ > _We optimize the `control flow graph`_ > _We test the limits of `taichi`'s core_ > _We simplify the `basic blocks` of wrath_ ### Walkthrough * Add support for function calls in control flow graph analysis and optimization ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fR220-R222), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fL979-R983)) * Prevent simplifying function call statements that may have side effects or modify global variables ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edR107-R108)) * Test the experimental template feature that allows passing arguments to functions as template parameters ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L158-R166), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L175-R177)) * Test the support for assertions inside kernels ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L335-R344), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L361-R362)) * Remove a redundant check for function call statements in `BasicBlockSimplify` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100)) * Remove a comment that is no longer relevant in `test_function.py` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329))
2023-06-06 14:55:16 +08:00
assert a == 7
[opt] Properly handle FuncCallStmt in CFG and simplify passes (#8139) Issue: #602 Assuming `FuncCallStmt` can load or modify any address. I will write a pass to find out all the addresses loaded and modified in a `FuncCallStmt` later. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at cf4766c</samp> ### Summary 📞🔧🧪 <!-- 1. 📞 for enhancing the control flow graph analysis and optimization to support function calls. 2. 🔧 for improving the simplification of basic blocks by removing a redundant check and adding a condition for function call statements. 3. 🧪 for testing some experimental features of taichi, such as template arguments and assertions in kernels. --> This pull request enhances the control flow graph analysis and optimization to support function calls in taichi kernels. It also improves the simplification of basic blocks and tests some experimental features of taichi. The main files affected are `taichi/ir/control_flow_graph.cpp`, `taichi/transforms/simplify.cpp`, and `tests/python/test_function.py`. > _We unleash the power of `function calls`_ > _We optimize the `control flow graph`_ > _We test the limits of `taichi`'s core_ > _We simplify the `basic blocks` of wrath_ ### Walkthrough * Add support for function calls in control flow graph analysis and optimization ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fR220-R222), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fL979-R983)) * Prevent simplifying function call statements that may have side effects or modify global variables ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edR107-R108)) * Test the experimental template feature that allows passing arguments to functions as template parameters ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L158-R166), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L175-R177)) * Test the support for assertions inside kernels ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L335-R344), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L361-R362)) * Remove a redundant check for function call statements in `BasicBlockSimplify` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100)) * Remove a comment that is no longer relevant in `test_function.py` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329))
2023-06-06 14:55:16 +08:00
bar()
@test_utils.test(arch=[ti.cpu, ti.cuda], debug=True)
def test_ref_atomic():
[opt] Properly handle FuncCallStmt in CFG and simplify passes (#8139) Issue: #602 Assuming `FuncCallStmt` can load or modify any address. I will write a pass to find out all the addresses loaded and modified in a `FuncCallStmt` later. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at cf4766c</samp> ### Summary 📞🔧🧪 <!-- 1. 📞 for enhancing the control flow graph analysis and optimization to support function calls. 2. 🔧 for improving the simplification of basic blocks by removing a redundant check and adding a condition for function call statements. 3. 🧪 for testing some experimental features of taichi, such as template arguments and assertions in kernels. --> This pull request enhances the control flow graph analysis and optimization to support function calls in taichi kernels. It also improves the simplification of basic blocks and tests some experimental features of taichi. The main files affected are `taichi/ir/control_flow_graph.cpp`, `taichi/transforms/simplify.cpp`, and `tests/python/test_function.py`. > _We unleash the power of `function calls`_ > _We optimize the `control flow graph`_ > _We test the limits of `taichi`'s core_ > _We simplify the `basic blocks` of wrath_ ### Walkthrough * Add support for function calls in control flow graph analysis and optimization ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fR220-R222), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fL979-R983)) * Prevent simplifying function call statements that may have side effects or modify global variables ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edR107-R108)) * Test the experimental template feature that allows passing arguments to functions as template parameters ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L158-R166), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L175-R177)) * Test the support for assertions inside kernels ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L335-R344), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L361-R362)) * Remove a redundant check for function call statements in `BasicBlockSimplify` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100)) * Remove a comment that is no longer relevant in `test_function.py` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329))
2023-06-06 14:55:16 +08:00
# FIXME: failed test on Pascal (and potentially older) architecture.
# Please remove this guardiance when you fix this issue
cur_arch = ti.lang.impl.get_runtime().prog.config().arch
if cur_arch == ti.cuda and ti.lang.impl.get_cuda_compute_capability() < 70:
pytest.skip(
"Skip this test on Pascal (and potentially older) architecture, ask turbo0628/Proton for more information"
)
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def foo(a: ti.ref(ti.f32)):
a += a
@ti.kernel
[opt] Properly handle FuncCallStmt in CFG and simplify passes (#8139) Issue: #602 Assuming `FuncCallStmt` can load or modify any address. I will write a pass to find out all the addresses loaded and modified in a `FuncCallStmt` later. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at cf4766c</samp> ### Summary 📞🔧🧪 <!-- 1. 📞 for enhancing the control flow graph analysis and optimization to support function calls. 2. 🔧 for improving the simplification of basic blocks by removing a redundant check and adding a condition for function call statements. 3. 🧪 for testing some experimental features of taichi, such as template arguments and assertions in kernels. --> This pull request enhances the control flow graph analysis and optimization to support function calls in taichi kernels. It also improves the simplification of basic blocks and tests some experimental features of taichi. The main files affected are `taichi/ir/control_flow_graph.cpp`, `taichi/transforms/simplify.cpp`, and `tests/python/test_function.py`. > _We unleash the power of `function calls`_ > _We optimize the `control flow graph`_ > _We test the limits of `taichi`'s core_ > _We simplify the `basic blocks` of wrath_ ### Walkthrough * Add support for function calls in control flow graph analysis and optimization ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fR220-R222), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fL979-R983)) * Prevent simplifying function call statements that may have side effects or modify global variables ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edR107-R108)) * Test the experimental template feature that allows passing arguments to functions as template parameters ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L158-R166), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L175-R177)) * Test the support for assertions inside kernels ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L335-R344), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L361-R362)) * Remove a redundant check for function call statements in `BasicBlockSimplify` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100)) * Remove a comment that is no longer relevant in `test_function.py` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329))
2023-06-06 14:55:16 +08:00
def bar():
a = 5.0
foo(a)
[opt] Properly handle FuncCallStmt in CFG and simplify passes (#8139) Issue: #602 Assuming `FuncCallStmt` can load or modify any address. I will write a pass to find out all the addresses loaded and modified in a `FuncCallStmt` later. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at cf4766c</samp> ### Summary 📞🔧🧪 <!-- 1. 📞 for enhancing the control flow graph analysis and optimization to support function calls. 2. 🔧 for improving the simplification of basic blocks by removing a redundant check and adding a condition for function call statements. 3. 🧪 for testing some experimental features of taichi, such as template arguments and assertions in kernels. --> This pull request enhances the control flow graph analysis and optimization to support function calls in taichi kernels. It also improves the simplification of basic blocks and tests some experimental features of taichi. The main files affected are `taichi/ir/control_flow_graph.cpp`, `taichi/transforms/simplify.cpp`, and `tests/python/test_function.py`. > _We unleash the power of `function calls`_ > _We optimize the `control flow graph`_ > _We test the limits of `taichi`'s core_ > _We simplify the `basic blocks` of wrath_ ### Walkthrough * Add support for function calls in control flow graph analysis and optimization ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fR220-R222), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fL979-R983)) * Prevent simplifying function call statements that may have side effects or modify global variables ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edR107-R108)) * Test the experimental template feature that allows passing arguments to functions as template parameters ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L158-R166), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L175-R177)) * Test the support for assertions inside kernels ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L335-R344), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L361-R362)) * Remove a redundant check for function call statements in `BasicBlockSimplify` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100)) * Remove a comment that is no longer relevant in `test_function.py` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329))
2023-06-06 14:55:16 +08:00
assert a == 10.0
[opt] Properly handle FuncCallStmt in CFG and simplify passes (#8139) Issue: #602 Assuming `FuncCallStmt` can load or modify any address. I will write a pass to find out all the addresses loaded and modified in a `FuncCallStmt` later. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at cf4766c</samp> ### Summary 📞🔧🧪 <!-- 1. 📞 for enhancing the control flow graph analysis and optimization to support function calls. 2. 🔧 for improving the simplification of basic blocks by removing a redundant check and adding a condition for function call statements. 3. 🧪 for testing some experimental features of taichi, such as template arguments and assertions in kernels. --> This pull request enhances the control flow graph analysis and optimization to support function calls in taichi kernels. It also improves the simplification of basic blocks and tests some experimental features of taichi. The main files affected are `taichi/ir/control_flow_graph.cpp`, `taichi/transforms/simplify.cpp`, and `tests/python/test_function.py`. > _We unleash the power of `function calls`_ > _We optimize the `control flow graph`_ > _We test the limits of `taichi`'s core_ > _We simplify the `basic blocks` of wrath_ ### Walkthrough * Add support for function calls in control flow graph analysis and optimization ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fR220-R222), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-837b90142d1730f6a3ab20c91f1f35c95335ef82a021c74fd4dbdb05ff0e164fL979-R983)) * Prevent simplifying function call statements that may have side effects or modify global variables ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edR107-R108)) * Test the experimental template feature that allows passing arguments to functions as template parameters ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L158-R166), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L175-R177)) * Test the support for assertions inside kernels ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L335-R344), [link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L361-R362)) * Remove a redundant check for function call statements in `BasicBlockSimplify` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-58b0ebe6a129091d8ae4753ba2bba80c7cc000e7f8eab635a337094582f543edL98-L100)) * Remove a comment that is no longer relevant in `test_function.py` ([link](https://github.com/taichi-dev/taichi/pull/8139/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L327-L329))
2023-06-06 14:55:16 +08:00
bar()
@test_utils.test(arch=[ti.cpu, ti.cuda], debug=True)
def test_func_ndarray_arg():
vec3 = ti.types.vector(3, ti.f32)
@ti.func
def test(a: ti.types.ndarray(ndim=1)):
a[0] = [100, 100, 100]
@ti.kernel
def test_k(x: ti.types.ndarray(ndim=1)):
test(x)
@ti.func
def test_error_func(a: ti.types.ndarray(dtype=ti.math.vec2, ndim=1)):
a[0] = [100, 100]
@ti.kernel
def test_error(x: ti.types.ndarray(ndim=1)):
test_error_func(x)
arr = ti.ndarray(vec3, shape=(4))
arr[0] = [20, 20, 20]
test_k(arr)
assert arr[0] == [20, 20, 20]
with pytest.raises(ti.TaichiCompilationError, match=r"Invalid value for argument a"):
test_error(arr)
@test_utils.test(debug=True)
def test_func_matrix_arg():
vec3 = ti.types.vector(3, ti.f32)
@ti.func
def test(a: vec3):
a[0] = 100
@ti.kernel
def test_k():
x = ti.Matrix([3, 4, 5])
x[0] = 20
test(x)
assert x[0] == 20
test_k()
@test_utils.test()
def test_func_matrix_arg_with_error():
vec3 = ti.types.vector(3, ti.f32)
@ti.func
def test(a: vec3):
a[0] = 100
@ti.kernel
def test_error():
x = ti.Matrix([3, 4])
test(x)
with pytest.raises(ti.TaichiSyntaxError, match=r"is expected to be a Matrix with n 3, but got 2"):
test_error()
@test_utils.test(debug=True)
def test_func_struct_arg():
@ti.dataclass
class C:
i: int
@ti.func
def f(c: C):
return c.i
@ti.kernel
def k():
c = C(i=2)
assert f(c) == 2
k()
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_real_func_matrix_arg():
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def mat_arg(a: ti.math.mat2, b: ti.math.vec2) -> float:
return a[0, 0] + a[0, 1] + a[1, 0] + a[1, 1] + b[0] + b[1]
b = ti.Vector.field(n=2, dtype=float, shape=())
b[()][0] = 5
b[()][1] = 6
@ti.kernel
def foo() -> float:
a = ti.math.mat2(1, 2, 3, 4)
return mat_arg(a, b[()])
assert foo() == pytest.approx(21)
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_real_func_matrix_return():
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def mat_ret() -> ti.math.mat2:
return ti.math.mat2(1, 2, 3, 4)
@ti.kernel
def foo() -> ti.math.mat2:
return mat_ret()
assert (foo() == ti.math.mat2(1, 2, 3, 4)).all()
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_real_func_struct_ret():
s = ti.types.struct(a=ti.i16, b=ti.f64)
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def bar() -> s:
return s(a=123, b=ti.f64(1.2345e300))
@ti.kernel
def foo() -> ti.f64:
a = bar()
return a.a * a.b
assert foo() == pytest.approx(123 * 1.2345e300)
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_real_func_struct_ret_with_matrix():
s0 = ti.types.struct(a=ti.math.vec3, b=ti.i16)
s1 = ti.types.struct(a=ti.f32, b=s0)
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def bar() -> s1:
return s1(a=1, b=s0(a=ti.Vector([100, 0.2, 3], dt=ti.f32), b=65537))
@ti.kernel
def foo() -> ti.f32:
s = bar()
return s.a + s.b.a[0] + s.b.a[1] + s.b.a[2] + s.b.b
assert foo() == pytest.approx(105.2)
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_break_in_real_func():
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def bar() -> int:
a = 0
for i in range(10):
if i == 5:
break
a += 1
return a
@ti.kernel
def foo() -> int:
return bar()
assert foo() == 5
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_continue_in_real_func():
[Lang] Move real function out of the experimental module (#8399) Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> This pull request updates the `real_func` examples and tests to use the stable `ti.real_func` decorator and the new vector, matrix, and field APIs. It also refactors some code for readability, performance, and consistency, and removes the deprecated `experimental` module. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 8c46960</samp> * Remove `experimental` module and move `real_func` decorator to top-level `taichi` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e0e39c57bc92c0e1da4c831f8820a4082a3cc26a9b88962bee72964dfa26a74aL13-R13), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L1235-R1235)) * Update all examples and tests that use `real_func` decorator to import it from `taichi` module instead of `experimental` module ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL58-R58), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL72-R82), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-9cbae292e39bc9b37e4cfab4bfef6f363788d06ecb7757753ee5c0ba7ad0afcdL136-R136), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL33-R33), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL55-R55), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f6098eab3d43899f2146cafc8454b2d9bae86064709eb2eeb43e0edbf459f22fL93-R98), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL43-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL89-R94), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-86667a5be06e5995f4b15199aa3d4b655e64cceed6d108185d5cc71e03f0bb1fL108-R108), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL51-R51), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL61-R61), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL68-R68), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL78-R78), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL89-R89), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL116-R116), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f9f9a26653afb587b73d90d08c099a8236820fc72b4d247e001954d620073ebcL124-R124), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL66-R71), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL80-R80), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL86-R86), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL95-R95), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL105-R105), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL119-R119), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL125-R125), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL132-R132), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-52ca6a00561cb88b076a00d2ae2a30dca3d46713e52f0f5ca6b52ecfd95545daL344-R344), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-f2d9c4a8c504d2073549cde99b31a733a2f39bba4ce9f062cbaa09e1be17aa87L243-R243), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L11-R11), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L29-R29), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L49-R49), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L153-R153), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L185-R185), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L194-R194), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L207-R207), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L221-R221), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L242-R242), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L259-R259), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L281-R281), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L295-R295), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L310-R310), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L329-R329), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L352-R352), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L451-R451), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L469-R469), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L484-R484), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L501-R501), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L515-R515), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-d6f5c74e17462c8ff96d5bba06ebf81d16c015ca667fa945513a80be17bef017L533-R533), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1035-R1035), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1052-R1052), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1134-R1134), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1149-R1149), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L480-R480), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-85fb062b09589d588166180e3c7954753018dc39474d3846346f2a8bb3faac32L494-R494), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-8641463ffef94529453efd945e02d056e4339417cc65aad074d4e6b3ef093244L49-R53), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L218-R218), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L238-R238), [link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-e206c19691b4678b401a5e2787000e93ab0b0060cbf4ac2625b51f87599d98d8L258-R258)) * Delete `python/taichi/experimental.py` file as it is no longer needed ([link](https://github.com/taichi-dev/taichi/pull/8399/files?diff=unified&w=0#diff-60267f25c1e1dfada9487235a4a793b63a49aa3d33c93b8449e24ac821a33174))
2023-10-31 14:11:53 +08:00
@ti.real_func
def bar() -> int:
a = 0
for i in range(10):
if i % 2 == 0:
continue
a += 1
return a
@ti.kernel
def foo() -> int:
return bar()
assert foo() == 5