* * Create a super kernel which executes sub kernels * and saves their output to be used with the next sub kernel. * This can be useful if we want to save the output on one kernel, * and then use it as an input to another kernel. *Machine Learning* * * @param {Object|Array} subKern
()
| 391 | * |
| 392 | */ |
| 393 | createKernelMap() { |
| 394 | let fn; |
| 395 | let settings; |
| 396 | const argument2Type = typeof arguments[arguments.length - 2]; |
| 397 | if (argument2Type === 'function' || argument2Type === 'string') { |
| 398 | fn = arguments[arguments.length - 2]; |
| 399 | settings = arguments[arguments.length - 1]; |
| 400 | } else { |
| 401 | fn = arguments[arguments.length - 1]; |
| 402 | } |
| 403 | |
| 404 | if (this.mode !== 'dev') { |
| 405 | if (!this.Kernel.isSupported || !this.Kernel.features.kernelMap) { |
| 406 | if (this.mode && kernelTypes.indexOf(this.mode) < 0) { |
| 407 | throw new Error(`kernelMap not supported on ${this.Kernel.name}`); |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | const settingsCopy = upgradeDeprecatedCreateKernelSettings(settings); |
| 413 | // handle conversion of argumentTypes |
| 414 | if (settings && typeof settings.argumentTypes === 'object') { |
| 415 | settingsCopy.argumentTypes = Object.keys(settings.argumentTypes).map(argumentName => settings.argumentTypes[argumentName]); |
| 416 | } |
| 417 | |
| 418 | if (Array.isArray(arguments[0])) { |
| 419 | settingsCopy.subKernels = []; |
| 420 | const functions = arguments[0]; |
| 421 | for (let i = 0; i < functions.length; i++) { |
| 422 | const source = functions[i].toString(); |
| 423 | const name = utils.getFunctionNameFromString(source); |
| 424 | settingsCopy.subKernels.push({ |
| 425 | name, |
| 426 | source, |
| 427 | property: i, |
| 428 | }); |
| 429 | } |
| 430 | } else { |
| 431 | settingsCopy.subKernels = []; |
| 432 | const functions = arguments[0]; |
| 433 | for (let p in functions) { |
| 434 | if (!functions.hasOwnProperty(p)) continue; |
| 435 | const source = functions[p].toString(); |
| 436 | const name = utils.getFunctionNameFromString(source); |
| 437 | settingsCopy.subKernels.push({ |
| 438 | name: name || p, |
| 439 | source, |
| 440 | property: p, |
| 441 | }); |
| 442 | } |
| 443 | } |
| 444 | return this.createKernel(fn, settingsCopy); |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * |
no test coverage detected