-
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.
* [Test] Update float64 random number test * [LLVM] Update float64 random number generator * [skip ci] enforce code format * [test] simpifies test_random_f64 granularity test * [Lang] Add ti.randn() for Gaussian random numbers * [test] Add ti.randn() test * [doc] add documentation for ti.randn() * [skip ci] enforce code format Co-authored-by: Taichi Gardener <taichigardener@gmail.com>
- Loading branch information
1 parent
939e1d3
commit 3711a04
Showing
4 changed files
with
57 additions
and
4 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
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,17 @@ | ||
import math | ||
|
||
import taichi as ti | ||
|
||
|
||
@ti.func | ||
def randn(dt): | ||
''' | ||
Generates a random number from standard normal distribution | ||
using the Box-Muller transform. | ||
''' | ||
assert dt == ti.f32 or dt == ti.f64 | ||
u1 = ti.random(dt) | ||
u2 = ti.random(dt) | ||
r = ti.sqrt(-2 * ti.log(u1)) | ||
c = ti.cos(math.tau * u2) | ||
return r * c |
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