Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit fba8c89

Browse files
PaoloPenazzilm98
authored andcommitted
fix: change rep and foldhood internal behaviour
1 parent 38083a8 commit fba8c89

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/core/lang/lang.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,32 @@ pub fn nbr<A: Copy + 'static>(mut vm: RoundVM, expr: impl Fn(RoundVM) -> (RoundV
1717
}
1818

1919
pub fn rep<A: Copy + 'static>(mut vm: RoundVM, init: impl Fn() -> A, fun: impl Fn(RoundVM, A) -> (RoundVM, A)) -> (RoundVM, A) {
20-
println!("rep: Init nbrs: {:?}", vm.aligned_neighbours());
2120
vm.nest_in(Rep(vm.index().clone()));
22-
let prev = vm.previous_round_val().unwrap_or(&init()).clone();
23-
let (mut vm_, val) = locally(vm, |vm1| fun(vm1, prev));
21+
let (mut vm_, val) = locally(vm, |vm1| {
22+
let prev = vm1.previous_round_val().unwrap_or(&init()).clone();
23+
fun(vm1, prev)
24+
});
2425
let res = vm_.nest_write(vm_.unless_folding_on_others(), val);
2526
vm_.nest_out(true);
26-
println!("rep: End nbrs: {:?}", vm_.aligned_neighbours());
2727
(vm_, res)
2828
}
2929

3030
pub fn foldhood<A: Copy + 'static + Debug>(mut vm: RoundVM, init: impl Fn() -> A, aggr: impl Fn(A, A) -> A, expr: impl Fn(RoundVM) -> (RoundVM, A)) -> (RoundVM, A) {
3131
// here we do nest_in after retrieving the neighbours because otherwise it would disalign the device
3232
let nbrs = vm.aligned_neighbours().clone();
33-
println!("foldhood: nbrs: {:?}", nbrs);
3433
vm.nest_in(FoldHood(vm.index().clone()));
35-
let (mut vm_, preval) = expr(vm);
34+
let (vm_, preval) = expr(vm);
35+
let (mut vm__, local_init) = locally(vm_, |vm_| (vm_, init()));
3636
let nbrfield =
3737
nbrs.iter()
3838
.map(|id| {
39-
let res= vm_.folded_eval(|| preval, id.clone()).unwrap_or(init());
39+
let res= vm__.folded_eval(|| preval, id.clone()).unwrap_or(local_init);
4040
res
4141
});
42-
let val = nbrfield.fold(init(), |x, y| aggr(x, y));
43-
let res = vm_.nest_write(true, val);
44-
vm_.nest_out(true);
45-
(vm_, res)
42+
let val = nbrfield.fold(local_init, |x, y| aggr(x, y));
43+
let res = vm__.nest_write(true, val);
44+
vm__.nest_out(true);
45+
(vm__, res)
4646
}
4747

4848
pub fn branch<A: Copy + 'static>(mut vm: RoundVM, cond: impl Fn() -> bool, thn: impl Fn(RoundVM) -> (RoundVM, A), els: impl Fn(RoundVM) -> (RoundVM, A)) -> (RoundVM, A) {

0 commit comments

Comments
 (0)