Skip to content

Commit 3a51c0a

Browse files
authored
Merge pull request #847 from null-a/use-helper-to-parse-kernel-opts
Minor clean-up in kernel option parsing.
2 parents 1b5a0bf + 9d0a763 commit 3a51c0a

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

src/inference/kernels.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,14 @@ module.exports = function(env) {
3434
// Expects either a kernel name or an object containing a single
3535
// key/value pair where the key is a kernel name and the value is
3636
// an options object. e.g. 'MH' or { MH: { ... } }
37-
38-
function isKernelOption(obj) {
39-
return _.isString(obj) && _.has(kernels, obj) ||
40-
_.size(obj) === 1 && _.has(kernels, _.keys(obj)[0]);
41-
}
42-
43-
if (!isKernelOption(obj)) {
44-
throw new Error('Unrecognized kernel option: ' + JSON.stringify(obj));
45-
}
46-
47-
var name = _.isString(obj) ? obj : _.keys(obj)[0];
48-
var options = _.isString(obj) ? {} : _.values(obj)[0];
49-
return kernels[name](options);
37+
return util.getValAndOpts(obj, function(name, options) {
38+
if (!_.has(kernels, name)) {
39+
throw new Error(name + ' is not a valid kernel. ' +
40+
'The following kernels are available: ' +
41+
_.keys(kernels).join(', ') + '.');
42+
}
43+
return kernels[name](options);
44+
});
5045
}
5146

5247
// Combinators for kernel functions.

0 commit comments

Comments
 (0)