Skip to content

Commit

Permalink
Merge pull request #743 from null-a/fix-warnings-in-browser
Browse files Browse the repository at this point in the history
Fix warnings in the browser
  • Loading branch information
stuhlmueller committed Jan 2, 2017
2 parents 940c855 + 1f448a6 commit e81328b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
7 changes: 1 addition & 6 deletions src/guide.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,9 @@ function runIfThunkElseAuto(maybeThunk, targetDist, env, s, a, k) {
// independent guide distributions and optimizing the elbo yields
// mean-field variational inference.

var autoGuideWarningIssued = false;

function independent(targetDist, sampleAddress, env) {

if (!autoGuideWarningIssued) {
autoGuideWarningIssued = true;
util.warn('Automatically generating guide for one or more choices.');
}
util.warn('Automatically generating guide for one or more choices.', true);

// Include the distribution name in the guide parameter name to
// avoid collisions when the distribution type changes between
Expand Down
8 changes: 1 addition & 7 deletions src/inference/optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,8 @@ module.exports = function(env) {
});
}

var issuedGradWarning = {};

function logGradWarning(name, i, problem) {
var key = name + i + problem;
if (!_.has(issuedGradWarning, key)) {
console.warn('Gradient for param ' + name + ':' + i + ' is ' + problem + '.');
issuedGradWarning[key] = true;
}
util.warn('Gradient for param ' + name + ':' + i + ' is ' + problem + '.', true);
}

return {
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ function prepare(codeAndAssets, k, options) {
var initialAddress = '';
return wpplFn(options.initialStore, finish, initialAddress);
});
util.resetWarnings();
};

return { run: run };
Expand Down
6 changes: 2 additions & 4 deletions src/params/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function getParamsId(s, k, a, id) {
module.exports = function(env) {

var dimsForScalarParam = [1];
var paramWarningIssued = false;

// param provides a convenient wrapper around the primitive
// params.register.
Expand All @@ -50,9 +49,8 @@ module.exports = function(env) {
dims: dimsForScalarParam
});

if (!env.coroutine._guide && !paramWarningIssued) {
paramWarningIssued = true;
util.warn('Warning: Parameter created outside of the guide.');
if (!env.coroutine._guide) {
util.warn('Warning: Parameter created outside of the guide.', true);
}

var mu = options.mu;
Expand Down
17 changes: 14 additions & 3 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,19 @@ function timeif(bool, name, thunk) {
return bool ? time(name, thunk) : thunk();
}

function warn(msg) {
if (!global.suppressWarnings) {
console.warn(msg)
var warningsIssued = {};

function resetWarnings() {
warningsIssued = {};
}

function warn(msg, onceOnly) {
if (!global.suppressWarnings &&
(!onceOnly || !_.has(warningsIssued, msg))) {
console.warn(msg);
if (onceOnly) {
warningsIssued[msg] = true;
}
}
}

Expand Down Expand Up @@ -368,6 +378,7 @@ module.exports = {
deserialize: deserialize,
timeif: timeif,
warn: warn,
resetWarnings: resetWarnings,
fatal: fatal,
jsnew: jsnew,
isInteger: isInteger,
Expand Down
4 changes: 4 additions & 0 deletions tests/test-inference.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,15 @@ var generateTestCases = function(seed) {
exports[testDef.name][modelName] = _.partial(performTest, modelName, testDef);
});
});
var oldSuppressWarnings;
exports.setUp = function(callback) {
oldSuppressWarnings = global.suppressWarnings;
global.suppressWarnings = true;
util.seedRNG(seed);
callback();
};
exports.tearDown = function(callback) {
global.suppressWarnings = oldSuppressWarnings;
util.resetRNG();
callback();
};
Expand Down

0 comments on commit e81328b

Please sign in to comment.