Skip to content

Commit b35a1ea

Browse files
strongoierlin-hitonami
authored andcommitted
[Doc] Update doc regarding dynamic index (#7148)
Issue: #2590
1 parent 58ace06 commit b35a1ea

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

docs/lang/articles/advanced/meta.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,27 @@ def func():
166166
print(3)
167167
```
168168

169-
## When to use `ti.static` with for loops
170-
171-
There are two reasons to use `ti.static` with for loops:
172-
173-
- Loop unrolling for improving runtime performance (see [Compile-time evaluations](#compile-time-evaluations)).
174-
- Accessing elements of Taichi matrices/vectors. Indices for accessing Taichi fields can be runtime variables, while indices for Taichi matrices/vectors **must be a compile-time constant**.
169+
:::note
170+
Before v1.4.0, indices for accessing Taichi matrices/vectors must be compile-time constants.
171+
Therefore, if the indices come from a loop, the loop must be unrolled:
175172

176-
For example, when accessing a vector field `x` with `x[field_index][vector_component_index]`, the `field_index` can be a runtime variable, while the `vector_component_index` must be a compile-time constant:
173+
```python {7}
174+
# Here we declare a field containing 3 vectors. Each vector contains 8 elements.
175+
x = ti.Vector.field(8, ti.f32, shape=3)
177176

178-
```python {6}
179-
# Here we declare a field contains 3 vector. Each vector contains 8 elements.
180-
x = ti.Vector.field(8, ti.f32, shape=(3))
181177
@ti.kernel
182178
def reset():
183-
for i in x:
184-
for j in ti.static(range(x.n)):
185-
# The inner loop must be unrolled since j is an index for accessing a vector
186-
x[i][j] = 0
179+
for i in x:
180+
for j in ti.static(range(x.n)):
181+
# The inner loop must be unrolled since j is an index for accessing a vector.
182+
x[i][j] = 0
187183
```
188184

185+
Starting from v1.4.0, indices for accessing Taichi matrices/vectors can be runtime variables.
186+
Therefore, the loop above is no longer required to be unrolled.
187+
That said, unrolling it will still help you reduce runtime overhead.
188+
:::
189+
189190
## Compile-time recursion of `ti.func`
190191

191192
A compile-time recursive function is a function with recursion that can be recursively inlined at compile time. The condition which determines whether to recurse is evaluated at compile time.

docs/lang/articles/contribution/write_test.md

-1
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,3 @@ Now, Taichi supports the following extensions:
283283
| bls | Block-local storage |
284284
| assertion | Run-time asserts in Taichi kernels |
285285
| extfunc | Support inserting external function calls or backend source |
286-
| dynamic_index | Dynamic index support for tensors |

docs/lang/articles/reference/global_settings.md

-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ Following are some frequently-used configurations in `ti.init()`:
5858
default_ip: [ti.i32, ti.i64]
5959
Set the default precision of integers in the Taichi scope.
6060
61-
dynamic_index: bool
62-
Enable/disable the use of variables as indices when accessing vector/matrix elements in the Taichi scope.
63-
6461
kernel_profiler: bool
6562
Turn on/off kernel performance profiling.
6663

docs/lang/articles/reference/language_reference.md

-6
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,6 @@ Otherwise, `primary` has a Taichi type. All Taichi types excluding primitive
252252
types support subscriptions. You can refer to documentation of these types
253253
for subscription usage.
254254

255-
:::note
256-
When `primary` has a Taichi matrix type, all expressions in `expression_list`
257-
are required to be evaluated to Python values. This restriction can be got rid
258-
of by setting `ti.init(dynamic_index=True)`.
259-
:::
260-
261255
#### Slicings
262256

263257
```

0 commit comments

Comments
 (0)