-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a0bf31
commit f8c6249
Showing
4 changed files
with
73 additions
and
6 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,29 @@ | ||
-- #1878 | ||
-- == | ||
-- entry: fwd_J rev_J | ||
-- input { [1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0] } | ||
-- output { [[0.0, 2.0, 3.0, 4.0], | ||
-- [0.0, 0.0, 1.0, 1.0], | ||
-- [0.0, 0.0, 0.0, 1.0], | ||
-- [0.0, 0.0, 0.0, 0.0], | ||
-- [-4.0, -6.0, -7.0, -8.0], | ||
-- [0.0, 0.0, -1.0, -1.0], | ||
-- [0.0, 0.0, 0.0, -1.0], | ||
-- [0.0, 0.0, 0.0, 0.0]] | ||
-- } | ||
|
||
def obj (x : [8]f64) = | ||
#[unsafe] -- For simplicity of generated code. | ||
let col_w_pre_red = | ||
tabulate_3d 4 2 4 (\ k i j -> x[k+j]*x[i+j]) | ||
let col_w_red = | ||
map (map f64.sum) col_w_pre_red | ||
let col_eq : [4]f64 = | ||
map (\w -> w[0] - w[1]) col_w_red | ||
in col_eq | ||
|
||
entry fwd_J (x : [8]f64) = | ||
tabulate 8 (\i -> jvp obj x (replicate 8 0 with [i] = 1)) | ||
|
||
entry rev_J (x : [8]f64) = | ||
transpose (tabulate 4 (\i -> vjp obj x (replicate 4 0 with [i] = 1))) |
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,22 @@ | ||
-- #1878. The interesting thing here is that the sparse adjoint also | ||
-- has active free variables. | ||
-- == | ||
-- entry: fwd_J rev_J | ||
-- input { [1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0] } | ||
-- output { [0.0, 0.0, 0.0, 0.0, -4.0, 0.0, 0.0, 0.0] } | ||
|
||
def obj (x : [8]f64) = | ||
#[unsafe] -- For simplicity of generated code. | ||
let col_w_pre_red = | ||
tabulate_3d 4 2 4 (\ k i j -> x[k+j]*x[i+j]) | ||
let col_w_red = | ||
map (map f64.sum) col_w_pre_red | ||
let col_eq : [4]f64 = | ||
map (\w -> w[0] - w[1]) col_w_red | ||
in f64.maximum col_eq | ||
|
||
entry fwd_J (x : [8]f64) = | ||
tabulate 8 (\i -> jvp obj x (replicate 8 0 with [i] = 1)) | ||
|
||
entry rev_J (x : [8]f64) = | ||
vjp obj x 1 |