From a9038736d644ca58874b24f30e8d2c39d42c49e4 Mon Sep 17 00:00:00 2001 From: Gabriel Vainer <67750020+vai9er@users.noreply.github.com> Date: Mon, 12 Dec 2022 04:17:35 -0500 Subject: [PATCH 1/8] Update dac --- docs/lang/articles/advanced/data_oriented_class.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/lang/articles/advanced/data_oriented_class.md b/docs/lang/articles/advanced/data_oriented_class.md index d0deeca91374a..114f18a5151ef 100644 --- a/docs/lang/articles/advanced/data_oriented_class.md +++ b/docs/lang/articles/advanced/data_oriented_class.md @@ -2,7 +2,7 @@ sidebar_position: 3 --- -# Data-oriented Class +# Data-Oriented Class To define a Taichi kernel as a Python class member function: From 614535c7394f4d9bdf5a4e25d3cf8ef60b7957bf Mon Sep 17 00:00:00 2001 From: Gabriel Vainer <67750020+vai9er@users.noreply.github.com> Date: Mon, 12 Dec 2022 09:28:27 +0000 Subject: [PATCH 2/8] fix doc.md --- .../articles/advanced/data_oriented_class.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/lang/articles/advanced/data_oriented_class.md b/docs/lang/articles/advanced/data_oriented_class.md index 114f18a5151ef..51722d056db70 100644 --- a/docs/lang/articles/advanced/data_oriented_class.md +++ b/docs/lang/articles/advanced/data_oriented_class.md @@ -7,15 +7,15 @@ sidebar_position: 3 To define a Taichi kernel as a Python class member function: 1. Decorate the class with a `@ti.data_oriented` decorator. -2. Define `ti.kernel`s and `ti.func`s in your data-oriented Python class. +2. Define `ti.kernel`s and `ti.func`s in your Data-Oriented Python class. :::note The first argument of the function should be the class instance ("`self`"), unless you are defining a `@staticmethod`. ::: -A brief example: +A brief example. Notice the use of `@ti.data_oriented` and `@ti.kernel` in lines 1 and 6, respectively: -```python {1} +```python {1,6} @ti.data_oriented class TiArray: def __init__(self, n): @@ -30,7 +30,7 @@ a = TiArray(32) a.inc() ``` -Definitions of Taichi fields can be made not only in _init_ functions, but also at any place of a Python-scope function in a data-oriented class. For example, +Definitions of Taichi fields can be made not only in _init_ functions, but also at any place of a Python-scope function in a Data-Oriented class. ```python {21,25} import taichi as ti @@ -51,9 +51,9 @@ class MyClass: self.temp = ti.field(dtype = ti.i32, shape=n) -a = MyClass() +a = MyClass() # creating an instance of Data-Oriented Class # a.call_inc() cannot be called, because a.temp has not been allocated at this point -a.allocate_temp(4) +a.allocate_temp(4) #c a.call_inc() a.call_inc() print(a.temp) # [2 2 2 2] @@ -95,9 +95,9 @@ print(a.y) # [ 5. 13. 21. 29.] ``` -## Inheritance of data-oriented classes +## Inheritance of Data-Oriented Classes -The data-oriented property is automatically carried along with the Python class inheriting. This means that you can call a Taichi Kernel if any of its ancestor classes is decorated with `@ti.data_oriented`. +The Data-Oriented property is automatically carried along with the Python class inheritence. This implies that you can call a Taichi Kernel if any of its ancestor classes is decorated with `@ti.data_oriented`, which is shown in the example below: An example: ```python @@ -152,7 +152,7 @@ c = BaseClass() ## Python built-in decorators -Common decorators that are pre-built in Python, `@staticmethod`[^1] and `@classmethod`[^2], can decorate a Taichi kernel in data-oriented classes. +Common decorators that are pre-built in Python, `@staticmethod`[^1] and `@classmethod`[^2], can decorate a Taichi kernel in Data-Oriented classes. [^1]: [Python built-in functions - staticmethod](https://docs.python.org/3/library/functions.html#staticmethod) [^2]: [Python built-in functions - classmethod](https://docs.python.org/3/library/functions.html#classmethod) From b62e12c10a27a2dd924c4e909976cdfe98a109ce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Dec 2022 09:30:17 +0000 Subject: [PATCH 3/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/lang/articles/advanced/data_oriented_class.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/lang/articles/advanced/data_oriented_class.md b/docs/lang/articles/advanced/data_oriented_class.md index 51722d056db70..48115c3baac34 100644 --- a/docs/lang/articles/advanced/data_oriented_class.md +++ b/docs/lang/articles/advanced/data_oriented_class.md @@ -51,7 +51,7 @@ class MyClass: self.temp = ti.field(dtype = ti.i32, shape=n) -a = MyClass() # creating an instance of Data-Oriented Class +a = MyClass() # creating an instance of Data-Oriented Class # a.call_inc() cannot be called, because a.temp has not been allocated at this point a.allocate_temp(4) #c a.call_inc() From 44edb1eb014847fb36a4d76082085f7e3e2b6fc4 Mon Sep 17 00:00:00 2001 From: Gabriel Vainer <67750020+vai9er@users.noreply.github.com> Date: Tue, 13 Dec 2022 02:16:55 +0000 Subject: [PATCH 4/8] fix code comments --- .../articles/advanced/data_oriented_class.md | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/lang/articles/advanced/data_oriented_class.md b/docs/lang/articles/advanced/data_oriented_class.md index 51722d056db70..20bb31af8fd84 100644 --- a/docs/lang/articles/advanced/data_oriented_class.md +++ b/docs/lang/articles/advanced/data_oriented_class.md @@ -41,8 +41,10 @@ ti.init() class MyClass: @ti.kernel def inc(self, temp: ti.template()): + + #increment all elements in array by 1 for I in ti.grouped(temp): - temp[I] += 1 + temp[I] += 1 def call_inc(self): self.inc(self.temp) @@ -52,14 +54,16 @@ class MyClass: a = MyClass() # creating an instance of Data-Oriented Class + # a.call_inc() cannot be called, because a.temp has not been allocated at this point -a.allocate_temp(4) #c -a.call_inc() -a.call_inc() -print(a.temp) # [2 2 2 2] -a.allocate_temp(8) -a.call_inc() -print(a.temp) # [1 1 1 1 1 1 1 1] +a.allocate_temp(4) # [0 0 0 0] +a.call_inc() # [1 1 1 1] +a.call_inc() # [2 2 2 2] +print(a.temp) # will print [2 2 2 2] + +a.allocate_temp(8) # [0 0 0 0 0 0 0 0 0] +a.call_inc() # [1 1 1 1 1 1 1 1] +print(a.temp) # will print [1 1 1 1 1 1 1 1] ``` Another memory recycling example: From b4c6bf82b9ecfadd3c42d1ec09f78ccb4302ddae Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Dec 2022 02:20:37 +0000 Subject: [PATCH 5/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/lang/articles/advanced/data_oriented_class.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/lang/articles/advanced/data_oriented_class.md b/docs/lang/articles/advanced/data_oriented_class.md index 101b656dd5ae6..07359397bf66d 100644 --- a/docs/lang/articles/advanced/data_oriented_class.md +++ b/docs/lang/articles/advanced/data_oriented_class.md @@ -44,7 +44,7 @@ class MyClass: #increment all elements in array by 1 for I in ti.grouped(temp): - temp[I] += 1 + temp[I] += 1 def call_inc(self): self.inc(self.temp) @@ -54,7 +54,7 @@ class MyClass: <<<<<<< HEAD -a = MyClass() # creating an instance of Data-Oriented Class +a = MyClass() # creating an instance of Data-Oriented Class ======= a = MyClass() # creating an instance of Data-Oriented Class From f34c256ef7603137916bfd0e61eb454811a068bd Mon Sep 17 00:00:00 2001 From: Olinaaaloompa <106292061+Olinaaaloompa@users.noreply.github.com> Date: Wed, 14 Dec 2022 10:44:12 +0800 Subject: [PATCH 6/8] Update docs/lang/articles/advanced/data_oriented_class.md --- docs/lang/articles/advanced/data_oriented_class.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/lang/articles/advanced/data_oriented_class.md b/docs/lang/articles/advanced/data_oriented_class.md index 07359397bf66d..827f4104eff37 100644 --- a/docs/lang/articles/advanced/data_oriented_class.md +++ b/docs/lang/articles/advanced/data_oriented_class.md @@ -103,7 +103,7 @@ print(a.y) # [ 5. 13. 21. 29.] ``` -## Inheritance of Data-Oriented Classes +## Inheritance of Data-Oriented classes The Data-Oriented property is automatically carried along with the Python class inheritence. This implies that you can call a Taichi Kernel if any of its ancestor classes is decorated with `@ti.data_oriented`, which is shown in the example below: From bc26d3057880f724f1b5b36b13439b191ae50f22 Mon Sep 17 00:00:00 2001 From: Gabriel Vainer <67750020+vai9er@users.noreply.github.com> Date: Thu, 15 Dec 2022 08:29:48 +0000 Subject: [PATCH 7/8] resolve --- docs/lang/articles/advanced/data_oriented_class.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/lang/articles/advanced/data_oriented_class.md b/docs/lang/articles/advanced/data_oriented_class.md index 101b656dd5ae6..53272867f6864 100644 --- a/docs/lang/articles/advanced/data_oriented_class.md +++ b/docs/lang/articles/advanced/data_oriented_class.md @@ -53,12 +53,6 @@ class MyClass: self.temp = ti.field(dtype = ti.i32, shape=n) -<<<<<<< HEAD -a = MyClass() # creating an instance of Data-Oriented Class - -======= -a = MyClass() # creating an instance of Data-Oriented Class ->>>>>>> b62e12c10a27a2dd924c4e909976cdfe98a109ce # a.call_inc() cannot be called, because a.temp has not been allocated at this point a.allocate_temp(4) # [0 0 0 0] a.call_inc() # [1 1 1 1] From b949e52790f56259cbc91b4c3e868d07443cd0d4 Mon Sep 17 00:00:00 2001 From: Gabriel Vainer <67750020+vai9er@users.noreply.github.com> Date: Thu, 15 Dec 2022 08:32:42 +0000 Subject: [PATCH 8/8] resolve --- docs/lang/articles/advanced/data_oriented_class.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docs/lang/articles/advanced/data_oriented_class.md b/docs/lang/articles/advanced/data_oriented_class.md index 4103729d6a310..836bb15f82d4c 100644 --- a/docs/lang/articles/advanced/data_oriented_class.md +++ b/docs/lang/articles/advanced/data_oriented_class.md @@ -52,16 +52,9 @@ class MyClass: def allocate_temp(self, n): self.temp = ti.field(dtype = ti.i32, shape=n) - -<<<<<<< HEAD -======= -<<<<<<< HEAD a = MyClass() # creating an instance of Data-Oriented Class -======= a = MyClass() # creating an instance of Data-Oriented Class ->>>>>>> b62e12c10a27a2dd924c4e909976cdfe98a109ce ->>>>>>> f34c256ef7603137916bfd0e61eb454811a068bd # a.call_inc() cannot be called, because a.temp has not been allocated at this point a.allocate_temp(4) # [0 0 0 0] a.call_inc() # [1 1 1 1]