Skip to content

Commit

Permalink
Merge pull request #805 from null-a/rename-coroutine-property
Browse files Browse the repository at this point in the history
Rename coroutine property
  • Loading branch information
stuhlmueller committed Mar 30, 2017
2 parents 6120c5d + c7d029c commit 9ac99ad
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/guide.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function guideCoroutine(env) {
sample: sampleNotAllowed,
factor: factorNotAllowed,
incrementalize: env.defaultCoroutine.incrementalize,
coroutine: env.coroutine,
oldCoroutine: env.coroutine,
// A flag used when creating parameters to check whether we're in
// a guide thunk. Note that this does the right thing if Infer is
// used within a guide. This can be checked from a webppl program
Expand Down
3 changes: 2 additions & 1 deletion src/headerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ module.exports = function(env) {
return {
sample: notAllowed('sample', name),
factor: notAllowed('factor', name),
incrementalize: env.defaultCoroutine.incrementalize
incrementalize: env.defaultCoroutine.incrementalize,
oldCoroutine: env.coroutine
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/inference/checkSampleAfterFactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function(env) {
this.hasFactor = false;
// at least one sample appears after factor
this.hasSampleAfterFactor = false;
this.coroutine = env.coroutine;
this.oldCoroutine = env.coroutine;
env.coroutine = this;
}

Expand All @@ -42,7 +42,7 @@ module.exports = function(env) {

// Continuation.
function() {
env.coroutine = this.coroutine;
env.coroutine = this.oldCoroutine;
return this.k(this.s, this.hasSampleAfterFactor);
}.bind(this));

Expand Down
4 changes: 2 additions & 2 deletions src/inference/dream/gradients.ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ module.exports = function(env) {

this.insideMapData = false;

this.coroutine = env.coroutine;
this.oldCoroutine = env.coroutine;
env.coroutine = this;
}

dreamGradients.prototype = {

run: function() {
return this.estimateGradient(function(grad, objVal) {
env.coroutine = this.coroutine;
env.coroutine = this.oldCoroutine;
return this.cont(grad, objVal);
}.bind(this));
},
Expand Down
4 changes: 2 additions & 2 deletions src/inference/dream/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ module.exports = function(env) {

this.insideMapData = false;

this.coroutine = env.coroutine;
this.oldCoroutine = env.coroutine;
env.coroutine = this;
}

dreamSample.prototype = {

run: function() {
return this.wpplFn(_.clone(this.s), function(s, val) {
env.coroutine = this.coroutine;
env.coroutine = this.oldCoroutine;
return this.k(this.s, this.record);
}.bind(this), this.a);
},
Expand Down
4 changes: 2 additions & 2 deletions src/inference/elbo.ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = function(env) {
}
this.baselineUpdates = {};

this.coroutine = env.coroutine;
this.oldCoroutine = env.coroutine;
env.coroutine = this;
}

Expand Down Expand Up @@ -116,7 +116,7 @@ module.exports = function(env) {
paramStruct.divEq(grad, this.opts.samples);
elbo /= this.opts.samples;
this.updateBaselines();
env.coroutine = this.coroutine;
env.coroutine = this.oldCoroutine;
return this.cont(grad, elbo);
}.bind(this));

Expand Down
4 changes: 2 additions & 2 deletions src/inference/enumerate.ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = function(env) {

// Move old coroutine out of the way
// and install this as the current handler
this.coroutine = env.coroutine;
this.oldCoroutine = env.coroutine;
env.coroutine = this;
}

Expand Down Expand Up @@ -191,7 +191,7 @@ module.exports = function(env) {
return this.error('All paths explored by Enumerate have probability zero.');
}
// Reinstate previous coroutine:
env.coroutine = this.coroutine;
env.coroutine = this.oldCoroutine;
// Return from enumeration by calling original continuation with original store:
return this.k(this.store, this.marginal.toDist());
}
Expand Down
4 changes: 2 additions & 2 deletions src/inference/eubo.ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = function(env) {
this.guideRequired = true;
this.isParamBase = true;

this.coroutine = env.coroutine;
this.oldCoroutine = env.coroutine;
env.coroutine = this;
}

Expand All @@ -74,7 +74,7 @@ module.exports = function(env) {
function() {
paramStruct.divEq(grad, traces.length);
eubo /= traces.length;
env.coroutine = this.coroutine;
env.coroutine = this.oldCoroutine;
return this.cont(grad, eubo);
}.bind(this),

Expand Down
4 changes: 2 additions & 2 deletions src/inference/forwardSample.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ module.exports = function(env) {
this.score = 0;
this.logWeight = 0;

this.coroutine = env.coroutine;
this.oldCoroutine = env.coroutine;
env.coroutine = this;
}

RunForward.prototype = {

run: function() {
return this.wpplFn(_.clone(this.s), function(s, val) {
env.coroutine = this.coroutine;
env.coroutine = this.oldCoroutine;
var ret = {val: val, score: this.score, logWeight: this.logWeight};
return this.k(this.s, ret);
}.bind(this), this.a);
Expand Down
4 changes: 2 additions & 2 deletions src/inference/hmckernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function(env) {
this.oldTrace = oldTrace;
this.a = oldTrace.baseAddress; // Support relative addressing.

this.coroutine = env.coroutine;
this.oldCoroutine = env.coroutine;
env.coroutine = this;
}

Expand Down Expand Up @@ -247,7 +247,7 @@ module.exports = function(env) {
};

HMCKernel.prototype.continue = function(trace) {
env.coroutine = this.coroutine;
env.coroutine = this.oldCoroutine;
return this.cont(trace);
};

Expand Down
4 changes: 2 additions & 2 deletions src/inference/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function(env) {

this.ad = options.ad;
this.failures = 0;
this.coroutine = env.coroutine;
this.oldCoroutine = env.coroutine;
env.coroutine = this;
}

Expand Down Expand Up @@ -62,7 +62,7 @@ module.exports = function(env) {
if (this.trace.value === env.query) {
this.trace.value = env.query.getTable();
}
env.coroutine = this.coroutine;
env.coroutine = this.oldCoroutine;
return this.cont(this.trace);
};

Expand Down
4 changes: 2 additions & 2 deletions src/inference/mhkernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function(env) {
this.discreteOnly = options.discreteOnly;
this.adRequired = options.adRequired;

this.coroutine = env.coroutine;
this.oldCoroutine = env.coroutine;
env.coroutine = this;
}

Expand Down Expand Up @@ -149,7 +149,7 @@ module.exports = function(env) {
};

MHKernel.prototype.continue = function(trace) {
env.coroutine = this.coroutine;
env.coroutine = this.oldCoroutine;
return this.cont(trace);
};

Expand Down
4 changes: 2 additions & 2 deletions src/inference/smc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = function(env) {
this.k = k;
this.a = a;

this.coroutine = env.coroutine;
this.oldCoroutine = env.coroutine;
env.coroutine = this;
}

Expand Down Expand Up @@ -339,7 +339,7 @@ module.exports = function(env) {
if (this.saveTraces) {
dist.traces = traces;
}
env.coroutine = this.coroutine;
env.coroutine = this.oldCoroutine;
return this.k(this.s, dist);
}.bind(this),
this.completeParticles);
Expand Down
4 changes: 2 additions & 2 deletions src/params/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ function fetch(name, env) {
function findCoroutine(predicate, coroutine) {
if (predicate(coroutine)) {
return coroutine;
} else if (_.has(coroutine, 'coroutine')) {
return findCoroutine(predicate, coroutine.coroutine);
} else if (_.has(coroutine, 'oldCoroutine')) {
return findCoroutine(predicate, coroutine.oldCoroutine);
} else {
return null;
}
Expand Down

0 comments on commit 9ac99ad

Please sign in to comment.