Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle block types #8

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/floretta/src/reverse/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ fn test_square() {
.test()
}

#[test]
fn test_br_if_return() {
let wat = include_str!("../wat/br_if_return.wat");
let (mut store, function, backprop) =
compile::<(i32, f64, f64), f64, (f64, f64), f64>(wat, "select");
{
let output = function.call(&mut store, (1, 2., 3.)).unwrap();
assert_eq!(output, 2.);
let gradient = backprop.call(&mut store, 1.).unwrap();
assert_eq!(gradient, (1., 0.));
}
{
let output = function.call(&mut store, (0, 2., 3.)).unwrap();
assert_eq!(output, 3.);
let gradient = backprop.call(&mut store, 1.).unwrap();
assert_eq!(gradient, (0., 1.));
}
}

#[test]
fn test_drop_i32() {
Backprop {
Expand Down
7 changes: 7 additions & 0 deletions crates/floretta/src/wat/br_if_return.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(module
(func (export "select") (param i32 f64 f64) (result f64)
local.get 1
local.get 0
br_if 0
drop
local.get 2))
Loading