2021-09-15 20:48:23 -07:00
|
|
|
import pytest
|
|
|
|
|
|
2021-05-12 14:00:48 +08:00
|
|
|
import taichi as ti
|
2022-02-10 12:37:36 +08:00
|
|
|
from tests import test_utils
|
2021-05-12 14:00:48 +08:00
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda])
|
2021-05-12 14:00:48 +08:00
|
|
|
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
|
2021-05-18 13:25:13 +08:00
|
|
|
def foo(val: ti.i32):
|
2021-05-12 14:00:48 +08:00
|
|
|
x[None] += val
|
|
|
|
|
|
|
|
|
|
@ti.kernel
|
|
|
|
|
def run():
|
|
|
|
|
foo(40)
|
|
|
|
|
foo(2)
|
|
|
|
|
|
|
|
|
|
x[None] = 0
|
|
|
|
|
run()
|
|
|
|
|
assert x[None] == 42
|
|
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda], debug=True)
|
2022-03-08 14:33:08 +08:00
|
|
|
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
|
2022-03-08 14:33:08 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda])
|
2022-03-08 14:33:08 +08:00
|
|
|
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
|
2022-03-08 14:33:08 +08:00
|
|
|
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
|
2021-05-12 14:00:48 +08:00
|
|
|
|
|
|
|
|
|
2022-02-10 12:37:36 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda], debug=True)
|
2021-09-15 10:48:06 +08:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda])
|
2021-09-15 10:48:06 +08:00
|
|
|
def test_experimental_templates():
|
2021-05-12 14:00:48 +08:00
|
|
|
x = ti.field(ti.i32, shape=())
|
|
|
|
|
y = ti.field(ti.i32, shape=())
|
2021-06-22 17:46:07 +08:00
|
|
|
answer = ti.field(ti.i32, shape=8)
|
2021-05-12 14:00:48 +08:00
|
|
|
|
|
|
|
|
@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
|
2021-05-12 14:00:48 +08:00
|
|
|
def inc(x: ti.template()):
|
|
|
|
|
x[None] += 1
|
|
|
|
|
|
|
|
|
|
@ti.kernel
|
2023-06-06 14:55:16 +08:00
|
|
|
def run_func(a: ti.u1):
|
2021-05-12 14:00:48 +08:00
|
|
|
x[None] = 10
|
|
|
|
|
y[None] = 20
|
2023-06-06 14:55:16 +08:00
|
|
|
if a:
|
|
|
|
|
inc(x)
|
2021-06-22 17:46:07 +08:00
|
|
|
answer[0] = x[None]
|
|
|
|
|
answer[1] = y[None]
|
2023-06-06 14:55:16 +08:00
|
|
|
if a:
|
|
|
|
|
inc(y)
|
2021-06-22 17:46:07 +08:00
|
|
|
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
|
2021-05-12 14:00:48 +08:00
|
|
|
|
|
|
|
|
run_kernel()
|
2023-06-06 14:55:16 +08:00
|
|
|
run_func(True)
|
2021-06-22 17:46:07 +08:00
|
|
|
verify()
|
2021-09-15 20:48:23 -07:00
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda])
|
2021-09-15 20:48:23 -07:00
|
|
|
def test_missing_arg_annotation():
|
2022-01-28 11:16:32 +08:00
|
|
|
with pytest.raises(ti.TaichiSyntaxError, match="must be type annotated"):
|
2021-09-15 20:48:23 -07:00
|
|
|
|
[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
|
2021-09-15 20:48:23 -07:00
|
|
|
def add(a, b: ti.i32) -> ti.i32:
|
|
|
|
|
return a + b
|
|
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda])
|
2021-09-15 20:48:23 -07:00
|
|
|
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
|
2021-09-15 20:48:23 -07:00
|
|
|
def add(a: ti.i32, b: ti.i32):
|
|
|
|
|
return a + b
|
|
|
|
|
|
|
|
|
|
@ti.kernel
|
|
|
|
|
def run():
|
|
|
|
|
add(30, 2)
|
|
|
|
|
|
|
|
|
|
run()
|
2022-03-09 16:21:48 +08:00
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda])
|
2022-03-15 23:57:25 +08:00
|
|
|
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
|
2022-03-15 23:57:25 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2022-11-16 18:09:13 +08:00
|
|
|
@pytest.mark.run_in_serial
|
2023-04-27 16:00:46 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda], cuda_stack_limit=8192)
|
2022-03-09 16:21:48 +08:00
|
|
|
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
|
2022-03-09 16:21:48 +08:00
|
|
|
def sum(f: ti.template(), l: ti.i32, r: ti.i32) -> ti.i32:
|
|
|
|
|
if l == r:
|
2022-03-18 15:19:13 +08:00
|
|
|
return f[l]
|
2022-03-09 16:21:48 +08:00
|
|
|
else:
|
2022-03-18 15:19:13 +08:00
|
|
|
return sum(f, l, (l + r) // 2) + sum(f, (l + r) // 2 + 1, r)
|
2022-03-09 16:21:48 +08:00
|
|
|
|
|
|
|
|
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
|
2022-03-18 15:19:13 +08:00
|
|
|
|
|
|
|
|
|
2022-11-10 13:08:47 +08:00
|
|
|
@pytest.mark.run_in_serial
|
2022-10-27 21:50:45 +08:00
|
|
|
@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
|
2022-10-27 21:50:45 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda])
|
2022-03-18 15:19:13 +08:00
|
|
|
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
|
2022-03-18 15:19:13 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda])
|
2022-03-18 15:19:13 +08:00
|
|
|
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
|
2022-03-18 15:19:13 +08:00
|
|
|
def foo() -> ti.i32:
|
|
|
|
|
for i in range(10):
|
|
|
|
|
return 42
|
|
|
|
|
|
|
|
|
|
@ti.kernel
|
|
|
|
|
def bar() -> ti.i32:
|
|
|
|
|
return foo()
|
|
|
|
|
|
|
|
|
|
assert bar() == 42
|
|
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda])
|
2022-03-18 15:19:13 +08:00
|
|
|
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
|
2022-03-18 15:19:13 +08:00
|
|
|
def foo() -> ti.i32:
|
|
|
|
|
i = 1
|
|
|
|
|
while i:
|
|
|
|
|
return 42
|
|
|
|
|
|
|
|
|
|
@ti.kernel
|
|
|
|
|
def bar() -> ti.i32:
|
|
|
|
|
return foo()
|
|
|
|
|
|
|
|
|
|
assert bar() == 42
|
|
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda])
|
2022-03-18 15:19:13 +08:00
|
|
|
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
|
2022-03-18 15:19:13 +08:00
|
|
|
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
|
2022-05-12 13:38:28 +08:00
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda], debug=True)
|
2022-05-12 13:38:28 +08:00
|
|
|
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
|
2022-05-12 13:38:28 +08:00
|
|
|
def foo(a: ti.ref(ti.f32)):
|
|
|
|
|
a = 7
|
|
|
|
|
|
|
|
|
|
@ti.kernel
|
2023-06-06 14:55:16 +08:00
|
|
|
def bar():
|
2022-05-12 13:38:28 +08:00
|
|
|
a = 5.0
|
|
|
|
|
foo(a)
|
2023-06-06 14:55:16 +08:00
|
|
|
assert a == 7
|
2022-05-12 13:38:28 +08:00
|
|
|
|
2023-06-06 14:55:16 +08:00
|
|
|
bar()
|
2022-05-12 13:38:28 +08:00
|
|
|
|
|
|
|
|
|
2022-10-27 15:30:13 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda], debug=True)
|
2022-05-12 13:38:28 +08:00
|
|
|
def test_ref_atomic():
|
2023-06-06 14:55:16 +08:00
|
|
|
# FIXME: failed test on Pascal (and potentially older) architecture.
|
2022-11-10 14:18:18 +08:00
|
|
|
# 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:
|
2022-11-15 14:28:48 +08:00
|
|
|
pytest.skip(
|
|
|
|
|
"Skip this test on Pascal (and potentially older) architecture, ask turbo0628/Proton for more information"
|
|
|
|
|
)
|
2022-11-10 14:18:18 +08:00
|
|
|
|
[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
|
2022-05-12 13:38:28 +08:00
|
|
|
def foo(a: ti.ref(ti.f32)):
|
|
|
|
|
a += a
|
|
|
|
|
|
|
|
|
|
@ti.kernel
|
2023-06-06 14:55:16 +08:00
|
|
|
def bar():
|
2022-05-12 13:38:28 +08:00
|
|
|
a = 5.0
|
|
|
|
|
foo(a)
|
2023-06-06 14:55:16 +08:00
|
|
|
assert a == 10.0
|
2022-05-12 13:38:28 +08:00
|
|
|
|
2023-06-06 14:55:16 +08:00
|
|
|
bar()
|
2022-08-24 14:36:32 +08:00
|
|
|
|
|
|
|
|
|
2022-12-13 10:12:48 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda], debug=True)
|
|
|
|
|
def test_func_ndarray_arg():
|
2022-08-24 14:36:32 +08:00
|
|
|
vec3 = ti.types.vector(3, ti.f32)
|
|
|
|
|
|
|
|
|
|
@ti.func
|
2022-11-22 09:48:35 +08:00
|
|
|
def test(a: ti.types.ndarray(ndim=1)):
|
2022-08-24 14:36:32 +08:00
|
|
|
a[0] = [100, 100, 100]
|
|
|
|
|
|
|
|
|
|
@ti.kernel
|
2022-11-22 09:48:35 +08:00
|
|
|
def test_k(x: ti.types.ndarray(ndim=1)):
|
2022-08-24 14:36:32 +08:00
|
|
|
test(x)
|
|
|
|
|
|
|
|
|
|
@ti.func
|
2022-11-22 09:48:35 +08:00
|
|
|
def test_error_func(a: ti.types.ndarray(dtype=ti.math.vec2, ndim=1)):
|
2022-11-18 15:59:55 +08:00
|
|
|
a[0] = [100, 100]
|
2022-08-24 14:36:32 +08:00
|
|
|
|
|
|
|
|
@ti.kernel
|
2022-11-22 09:48:35 +08:00
|
|
|
def test_error(x: ti.types.ndarray(ndim=1)):
|
2022-08-24 14:36:32 +08:00
|
|
|
test_error_func(x)
|
|
|
|
|
|
|
|
|
|
arr = ti.ndarray(vec3, shape=(4))
|
|
|
|
|
arr[0] = [20, 20, 20]
|
|
|
|
|
test_k(arr)
|
|
|
|
|
|
|
|
|
|
assert arr[0] == [20, 20, 20]
|
|
|
|
|
|
2023-06-14 14:01:43 +08:00
|
|
|
with pytest.raises(ti.TaichiCompilationError, match=r"Invalid value for argument a"):
|
2022-08-24 14:36:32 +08:00
|
|
|
test_error(arr)
|
|
|
|
|
|
|
|
|
|
|
2022-12-13 10:12:48 +08:00
|
|
|
@test_utils.test(debug=True)
|
|
|
|
|
def test_func_matrix_arg():
|
2022-08-24 14:36:32 +08:00
|
|
|
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
|
|
|
|
|
|
2022-10-12 17:53:32 +08:00
|
|
|
test_k()
|
|
|
|
|
|
|
|
|
|
|
2022-12-13 10:12:48 +08:00
|
|
|
@test_utils.test()
|
|
|
|
|
def test_func_matrix_arg_with_error():
|
2022-10-12 17:53:32 +08:00
|
|
|
vec3 = ti.types.vector(3, ti.f32)
|
|
|
|
|
|
|
|
|
|
@ti.func
|
|
|
|
|
def test(a: vec3):
|
|
|
|
|
a[0] = 100
|
|
|
|
|
|
2022-08-24 14:36:32 +08:00
|
|
|
@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()
|
2022-10-12 17:53:32 +08:00
|
|
|
|
|
|
|
|
|
2022-12-23 11:36:08 +08:00
|
|
|
@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()
|
|
|
|
|
|
|
|
|
|
|
2022-12-13 10:12:48 +08:00
|
|
|
@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
|
2022-11-07 09:32:53 +08:00
|
|
|
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
|
2022-11-03 13:03:50 +08:00
|
|
|
|
|
|
|
|
@ti.kernel
|
|
|
|
|
def foo() -> float:
|
|
|
|
|
a = ti.math.mat2(1, 2, 3, 4)
|
2022-11-07 09:32:53 +08:00
|
|
|
return mat_arg(a, b[()])
|
|
|
|
|
|
|
|
|
|
assert foo() == pytest.approx(21)
|
|
|
|
|
|
|
|
|
|
|
2023-06-16 15:33:27 +08:00
|
|
|
@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
|
2023-06-16 15:33:27 +08:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
2022-11-24 10:49:41 +08:00
|
|
|
@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
|
2022-11-24 10:49:41 +08:00
|
|
|
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)
|
2022-11-28 17:22:42 +08:00
|
|
|
|
|
|
|
|
|
2022-12-13 10:12:48 +08:00
|
|
|
@test_utils.test(arch=[ti.cpu, ti.cuda])
|
|
|
|
|
def test_real_func_struct_ret_with_matrix():
|
2022-11-28 17:22:42 +08:00
|
|
|
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
|
2022-11-28 17:22:42 +08:00
|
|
|
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)
|
2023-07-14 11:04:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@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
|
2023-07-14 11:04:37 +08:00
|
|
|
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
|
2023-07-14 11:04:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@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
|
2023-07-14 11:04:38 +08:00
|
|
|
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
|