Neural Network/Brain/node_modules/gpu.js/src/backend/web-gl2/kernel.js
/**
   * @desc Validate settings related to Kernel, such as dimensions size, and auto output support.
   * @param {IArguments} args
   */
@desc Validate settings related to Kernel, such as dimensions size, and auto output support.
@desc Validate settings related to Kernel such as dimensions size and auto output support .
validateSettings(args) {
    if (!this.validate) {
      this.texSize = utils.getKernelTextureSize({
        optimizeFloatMemory: this.optimizeFloatMemory,
        precision: this.precision,
      }, this.output);
      return;
    }
    const features = this.constructor.features;
    if (this.precision === 'single' && !features.isFloatRead) {
      throw new Error('Float texture outputs are not supported');
    } else if (!this.graphical && this.precision === null) {
      this.precision = features.isFloatRead ? 'single' : 'unsigned';
    }
    if (this.fixIntegerDivisionAccuracy === null) {
      this.fixIntegerDivisionAccuracy = !features.isIntegerDivisionAccurate;
    } else if (this.fixIntegerDivisionAccuracy && features.isIntegerDivisionAccurate) {
      this.fixIntegerDivisionAccuracy = false;
    }
    this.checkOutput();
    if (!this.output || this.output.length === 0) {
      if (args.length !== 1) {
        throw new Error('Auto output only supported for kernels with only one input');
      }
      const argType = utils.getVariableType(args[0], this.strictIntegers);
      switch (argType) {
        case 'Array':
          this.output = utils.getDimensions(argType);
          break;
        case 'NumberTexture':
        case 'MemoryOptimizedNumberTexture':
        case 'ArrayTexture(1)':
        case 'ArrayTexture(2)':
        case 'ArrayTexture(3)':
        case 'ArrayTexture(4)':
          this.output = args[0].output;
          break;
        default:
          throw new Error('Auto output not supported for input type: ' + argType);
      }
    }
    if (this.graphical) {
      if (this.output.length !== 2) {
        throw new Error('Output must have 2 dimensions on graphical mode');
      }
      if (this.precision === 'single') {
        console.warn('Cannot use graphical mode and single precision at the same time');
        this.precision = 'unsigned';
      }
      this.texSize = utils.clone(this.output);
      return;
    } else if (!this.graphical && this.precision === null && features.isTextureFloat) {
      this.precision = 'single';
    }
    this.texSize = utils.getKernelTextureSize({
      optimizeFloatMemory: this.optimizeFloatMemory,
      precision: this.precision,
    }, this.output);
  }
validateSettings ( args ) { if ( ! this . validate ) { this . texSize = utils . getKernelTextureSize ( { optimizeFloatMemory : this . optimizeFloatMemory , precision : this . precision , } , this . output ) ; return ; } const features = this . constructor . features ; if ( this . precision === 'single' && ! features . isFloatRead ) { throw new Error ( 'Float texture outputs are not supported' ) ; } else if ( ! this . graphical && this . precision === null ) { this . precision = features . isFloatRead ? 'single' : 'unsigned' ; } if ( this . fixIntegerDivisionAccuracy === null ) { this . fixIntegerDivisionAccuracy = ! features . isIntegerDivisionAccurate ; } else if ( this . fixIntegerDivisionAccuracy && features . isIntegerDivisionAccurate ) { this . fixIntegerDivisionAccuracy = false ; } this . checkOutput ( ) ; if ( ! this . output || this . output . length === 0 ) { if ( args . length !== 1 ) { throw new Error ( 'Auto output only supported for kernels with only one input' ) ; } const argType = utils . getVariableType ( args [ 0 ] , this . strictIntegers ) ; switch ( argType ) { case 'Array' : this . output = utils . getDimensions ( argType ) ; break ; case 'NumberTexture' : case 'MemoryOptimizedNumberTexture' : case 'ArrayTexture(1)' : case 'ArrayTexture(2)' : case 'ArrayTexture(3)' : case 'ArrayTexture(4)' : this . output = args [ 0 ] . output ; break ; default : throw new Error ( 'Auto output not supported for input type: ' + argType ) ; } } if ( this . graphical ) { if ( this . output . length !== 2 ) { throw new Error ( 'Output must have 2 dimensions on graphical mode' ) ; } if ( this . precision === 'single' ) { console . warn ( 'Cannot use graphical mode and single precision at the same time' ) ; this . precision = 'unsigned' ; } this . texSize = utils . clone ( this . output ) ; return ; } else if ( ! this . graphical && this . precision === null && features . isTextureFloat ) { this . precision = 'single' ; } this . texSize = utils . getKernelTextureSize ( { optimizeFloatMemory : this . optimizeFloatMemory , precision : this . precision , } , this . output ) ; }
@desc Validate settings related to Kernel, such as dimensions size, and auto output support.
@desc Validate settings related to Kernel such as dimensions size and auto output support .