* * @param {IReason[]} reasons * @param {IArguments} args * @param {Kernel} _kernel * @returns {*}
(reasons, args, _kernel)
| 268 | * @returns {*} |
| 269 | */ |
| 270 | function onRequestSwitchKernel(reasons, args, _kernel) { |
| 271 | if (_kernel.debug) { |
| 272 | console.warn('Switching kernels'); |
| 273 | } |
| 274 | let newOutput = null; |
| 275 | if (_kernel.signature && !switchableKernels[_kernel.signature]) { |
| 276 | switchableKernels[_kernel.signature] = _kernel; |
| 277 | } |
| 278 | if (_kernel.dynamicOutput) { |
| 279 | for (let i = reasons.length - 1; i >= 0; i--) { |
| 280 | const reason = reasons[i]; |
| 281 | if (reason.type === 'outputPrecisionMismatch') { |
| 282 | newOutput = reason.needed; |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | const Constructor = _kernel.constructor; |
| 288 | const argumentTypes = Constructor.getArgumentTypes(_kernel, args); |
| 289 | const signature = Constructor.getSignature(_kernel, argumentTypes); |
| 290 | const existingKernel = switchableKernels[signature]; |
| 291 | if (existingKernel) { |
| 292 | existingKernel.onActivate(_kernel); |
| 293 | return existingKernel; |
| 294 | } |
| 295 | |
| 296 | const newKernel = switchableKernels[signature] = new Constructor(source, { |
| 297 | argumentTypes, |
| 298 | constantTypes: _kernel.constantTypes, |
| 299 | graphical: _kernel.graphical, |
| 300 | loopMaxIterations: _kernel.loopMaxIterations, |
| 301 | constants: _kernel.constants, |
| 302 | dynamicOutput: _kernel.dynamicOutput, |
| 303 | dynamicArgument: _kernel.dynamicArguments, |
| 304 | context: _kernel.context, |
| 305 | canvas: _kernel.canvas, |
| 306 | output: newOutput || _kernel.output, |
| 307 | precision: _kernel.precision, |
| 308 | pipeline: _kernel.pipeline, |
| 309 | immutable: _kernel.immutable, |
| 310 | optimizeFloatMemory: _kernel.optimizeFloatMemory, |
| 311 | fixIntegerDivisionAccuracy: _kernel.fixIntegerDivisionAccuracy, |
| 312 | functions: _kernel.functions, |
| 313 | nativeFunctions: _kernel.nativeFunctions, |
| 314 | injectedNative: _kernel.injectedNative, |
| 315 | subKernels: _kernel.subKernels, |
| 316 | strictIntegers: _kernel.strictIntegers, |
| 317 | debug: _kernel.debug, |
| 318 | gpu: _kernel.gpu, |
| 319 | validate, |
| 320 | returnType: _kernel.returnType, |
| 321 | tactic: _kernel.tactic, |
| 322 | onRequestFallback, |
| 323 | onRequestSwitchKernel, |
| 324 | texture: _kernel.texture, |
| 325 | mappedTextures: _kernel.mappedTextures, |
| 326 | drawBuffersMap: _kernel.drawBuffersMap, |
| 327 | }); |
no test coverage detected