Skip to content

Commit

Permalink
Add helper function to empty stack
Browse files Browse the repository at this point in the history
  • Loading branch information
stuhlmueller committed Aug 13, 2014
1 parent a5e3b68 commit ba1cc2f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions compiled/webppl.js
Original file line number Diff line number Diff line change
Expand Up @@ -17482,7 +17482,8 @@ ParticleFilter.prototype.factor = function(cc, score) {
// Advance to the next particle
this.particleIndex += 1;
}
this.activeParticle().continuation();

util.withEmptyStack(this.activeParticle().continuation);
};

ParticleFilter.prototype.activeParticle = function() {
Expand Down Expand Up @@ -17764,11 +17765,16 @@ var logsumexp = function(a) {
return m + Math.log(sum);
};

var withEmptyStack = function(thunk){
setTimeout(thunk, 0);
};

module.exports = {
gensym: gensym,
prettyJSON: prettyJSON,
sum: sum,
normalize: normalize,
logsumexp: logsumexp
logsumexp: logsumexp,
withEmptyStack: withEmptyStack
}
},{"underscore":51}]},{},[54]);
3 changes: 2 additions & 1 deletion src/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ ParticleFilter.prototype.factor = function(cc, score) {
// Advance to the next particle
this.particleIndex += 1;
}
this.activeParticle().continuation();

util.withEmptyStack(this.activeParticle().continuation);
};

ParticleFilter.prototype.activeParticle = function() {
Expand Down
7 changes: 6 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ var logsumexp = function(a) {
return m + Math.log(sum);
};

var withEmptyStack = function(thunk){
setTimeout(thunk, 0);
};

module.exports = {
gensym: gensym,
prettyJSON: prettyJSON,
sum: sum,
normalize: normalize,
logsumexp: logsumexp
logsumexp: logsumexp,
withEmptyStack: withEmptyStack
}

2 comments on commit ba1cc2f

@ngoodman
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit broke the particle filter test in a way i don't understand.

Note that this seems to be specific to the test runner setup, because particle filtering in a standalone file seems to be fine.

@stuhlmueller
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, the current tests treat the continuations within a webppl program basically as delimited continuations and assume that the part of the stack that is about future tests etc. is untouchable. If we throw away the entire stack, this breaks. I'll think about a workaround tomorrow.

Please sign in to comment.