-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[autodiff] Fix AdStackAllocaStmt not correctly backup (#5692)
* [autodiff] Fix AdStackAllocaStmt not correctly backup * remove redundant replace * add comments * add polar decompose test * erase outdated AdStackAllocaStmt
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import taichi as ti | ||
from tests import test_utils | ||
|
||
|
||
@test_utils.test(require=ti.extension.adstack) | ||
def test_polar_decompose_2D(): | ||
# `polar_decompose3d` in current Taichi version (v1.1) does not support autodiff, | ||
# becasue it mixed usage of for-loops and statements without looping. | ||
dim = 2 | ||
F_1 = ti.Matrix.field(dim, dim, dtype=ti.f32, shape=(), needs_grad=True) | ||
F = ti.Matrix.field(dim, dim, dtype=ti.f32, shape=(), needs_grad=True) | ||
loss = ti.field(dtype=ti.f32, shape=(), needs_grad=True) | ||
|
||
@ti.kernel | ||
def polar_decompose_2D(): | ||
r, s = ti.polar_decompose(F[None]) | ||
F_1[None] += r | ||
|
||
with ti.ad.Tape(loss=loss): | ||
polar_decompose_2D() |