-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is by introducing a new builtin function for conditional values (essentially the C ternary operator), which we then use in the definition of the partial derivative of 2216.
- Loading branch information
Showing
7 changed files
with
104 additions
and
3 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
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,13 @@ | ||
-- The power function has a dangerous kink for x==0. | ||
|
||
-- == | ||
-- entry: fwd | ||
-- input { 0.0 1.0 } output { 1.0 } | ||
|
||
-- == | ||
-- entry: rev | ||
-- input { 0.0 1.0 } output { 1.0 0.0 } | ||
|
||
entry fwd x y : f64 = jvp (\(x, y) -> x ** y) (x, y) (1, 1) | ||
|
||
entry rev x y = vjp (\(x, y) -> x ** y) (x, y) 1f64 |
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,15 @@ | ||
-- == | ||
-- input { [0.0, 0.0, 0.0] } | ||
-- output { [[0.0, 0.0, 0.0], | ||
-- [0.0, 2.0, 0.0], | ||
-- [0.0, 0.0, 2.0]] } | ||
|
||
def identity_mat n = tabulate_2d n n (\i j -> f64.bool (i == j)) | ||
|
||
def Jacobi [n] (f: [n]f64 -> [n]f64) (x: [n]f64) : [n][n]f64 = | ||
map (\i -> jvp f x i) (identity_mat n) | ||
|
||
def Hessian [n] (f: [n]f64 -> f64) (x: [n]f64) : [n][n]f64 = | ||
Jacobi (\x -> vjp f x 1) x | ||
|
||
entry main (x: [3]f64) = Hessian (\x -> x[1] ** 2 + x[2] ** 2) x |