2020-11-20 14:53:40 +01:00
/ *
Human library
homepage : < https : //github.com/vladmandic/human>
author : < https : //github.com/vladmandic>'
* /
2021-01-18 14:22:25 +01:00
var _ _create = Object . create , _ _defProp = Object . defineProperty , _ _getProtoOf = Object . getPrototypeOf , _ _hasOwnProp = Object . prototype . hasOwnProperty , _ _getOwnPropNames = Object . getOwnPropertyNames , _ _getOwnPropDesc = Object . getOwnPropertyDescriptor ; var _ _markAsModule = target => _ _defProp ( target , "__esModule" , { value : ! 0 } ) ; var _ _commonJS = ( callback , module ) => ( ) => ( module || ( module = { exports : { } } , callback ( module . exports , module ) ) , module . exports ) , _ _export = ( target , all4 ) => { _ _markAsModule ( target ) ; for ( var name in all4 ) _ _defProp ( target , name , { get : all4 [ name ] , enumerable : ! 0 } ) } , _ _exportStar = ( target , module , desc ) => { if ( _ _markAsModule ( target ) , module && typeof module == "object" || typeof module == "function" ) for ( let key of _ _getOwnPropNames ( module ) ) ! _ _hasOwnProp . call ( target , key ) && key !== "default" && _ _defProp ( target , key , { get : ( ) => module [ key ] , enumerable : ! ( desc = _ _getOwnPropDesc ( module , key ) ) || desc . enumerable } ) ; return target } , _ _toModule = module => module && module . _ _esModule ? module : _ _exportStar ( _ _defProp ( module != null ? _ _create ( _ _getProtoOf ( module ) ) : { } , "default" , { value : module , enumerable : ! 0 } ) , module ) ; var require _blazeface = _ _commonJS ( exports => { var NUM _LANDMARKS = 6 ; function generateAnchors ( inputSize ) { let spec = { strides : [ inputSize / 16 , inputSize / 8 ] , anchors : [ 2 , 6 ] } , anchors = [ ] ; for ( let i = 0 ; i < spec . strides . length ; i ++ ) { let stride = spec . strides [ i ] , gridRows = Math . floor ( ( inputSize + stride - 1 ) / stride ) , gridCols = Math . floor ( ( inputSize + stride - 1 ) / stride ) , anchorsNum = spec . anchors [ i ] ; for ( let gridY = 0 ; gridY < gridRows ; gridY ++ ) { let anchorY = stride * ( gridY + . 5 ) ; for ( let gridX = 0 ; gridX < gridCols ; gridX ++ ) { let anchorX = stride * ( gridX + . 5 ) ; for ( let n = 0 ; n < anchorsNum ; n ++ ) anchors . push ( [ anchorX , anchorY ] ) } } } return anchors } var disposeBox = box => { box . startEndTensor . dispose ( ) , box . startPoint . dispose ( ) , box . endPoint . dispose ( ) } , createBox = startEndTensor => ( { startEndTensor , startPoint : slice ( startEndTensor , [ 0 , 0 ] , [ - 1 , 2 ] ) , endPoint : slice ( startEndTensor , [ 0 , 2 ] , [ - 1 , 2 ] ) } ) , scaleBox = ( box , factors ) => { let starts = mul ( box . startPoint , factors ) , ends = mul ( box . endPoint , factors ) , newCoordinates = concat2d ( [ starts , ends ] , 1 ) ; return createBox ( newCoordinates ) } ; function decodeBounds ( boxOutputs , anchors , inputSize ) { let boxStarts = slice ( boxOutputs , [ 0 , 1 ] , [ - 1 , 2 ] ) , centers = add2 ( boxStarts , anchors ) , boxSizes = slice ( boxOutputs , [ 0 , 3 ] , [ - 1 , 2 ] ) , boxSizesNormalized = div ( boxSizes , inputSize ) , centersNormalized = div ( centers , inputSize ) , halfBoxSize = div ( boxSizesNormalized , 2 ) , starts = sub ( centersNormalized , halfBoxSize ) , ends = add2 ( centersNormalized , halfBoxSize ) , startNormalized = mul ( starts , inputSize ) , endNormalized = mul ( ends , inputSize ) ; return concat2d ( [ startNormalized , endNormalized ] , 1 ) } function scaleBoxFromPrediction ( face3 , scaleFactor ) { return tidy ( ( ) => { let box = face3 . box ? face3 . box : face3 ; return scaleBox ( box , scaleFactor ) . startEndTensor . squeeze ( ) } ) } var BlazeFaceModel = class { constructor ( model2 , config2 ) { this . blazeFaceModel = model2 , this . width = config2 . face . detector . inputSize , this . height = config2 . face . detector . inputSize , this . anchorsData = generateAnchors ( config2 . face . detector . inputSize ) , this . anchors = tensor2d ( this . anchorsData ) , this . inputSize = tensor1d ( [ this . width , this . height ] ) , this . config = config2 , this . scaleFaces = . 8 } async getBoundingBoxes ( inputImage ) { if ( ! inputImage || inputImage . isDisposedInternal || inputImage . shape . length !== 4 || inputImage . shape [ 1 ] < 1 || inputImage . shape [ 2 ] < 1 ) return null ; let [ detectedOutputs , boxes , scores ] = tidy ( ( ) => { let resizedImage = inputImage . resizeBilinear ( [ this . width , this . height ] ) , normalizedImage = sub ( resizedImage . div ( 127.5 ) , 1 ) , batchedPrediction = this . blazeFaceModel . predict ( normalizedImage ) , prediction ; if ( Array . isArray ( batchedPrediction ) ) { let sorted = batchedPrediction . sort ( ( a , b ) => a . size - b . size ) , concat384 = concat ( [ sorted [ 0 ] , sorted [ 2 ] ] , 2 ) , concat512 = concat ( [ sorted [ 1 ] , sorted [ 3 ] ] , 2 ) ; prediction = concat ( [ concat512 , concat384 ] , 1 ) . squeeze ( 0 ) } else prediction = batchedPrediction . squeeze ( ) ; let decodedBounds = decodeBounds ( prediction , this . anchors , this . inputSize ) , logits = slice ( prediction , [ 0 , 0 ] , [ - 1 , 1 ] ) , scoresOut = sigmoid ( logits ) . squeeze ( ) ; return [ prediction , decodedBounds , scoresOut ] } ) , boxIndicesTensor = await image . nonMaxSuppressionAsync ( boxes , scores , this . config . face . detector . maxFaces , this . config . face . detector . iouThreshold , this . config . face . detector . scoreThresh
2021-01-13 17:14:23 +01:00
` ),SHADER.FRAGMENT_IDENTITY=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","void main(void) {","gl_FragColor = texture2D(texture, vUv);","}"].join( `
` );let _filter={};_filter.colorMatrix=function(matrix){let m=new Float32Array(matrix);m[4]/=255,m[9]/=255,m[14]/=255,m[19]/=255;let shader=m[18]===1&&m[3]===0&&m[8]===0&&m[13]===0&&m[15]===0&&m[16]===0&&m[17]===0&&m[19]===0?_filter.colorMatrix.SHADER.WITHOUT_ALPHA:_filter.colorMatrix.SHADER.WITH_ALPHA,program=_compileShader(shader);gl.uniform1fv(program.uniform.m,m),_draw()},_filter.colorMatrix.SHADER={},_filter.colorMatrix.SHADER.WITH_ALPHA=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","uniform float m[20];","void main(void) {","vec4 c = texture2D(texture, vUv);","gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[3] * c.a + m[4];","gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[8] * c.a + m[9];","gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[13] * c.a + m[14];","gl_FragColor.a = m[15] * c.r + m[16] * c.g + m[17] * c.b + m[18] * c.a + m[19];","}"].join( `
` ),_filter.colorMatrix.SHADER.WITHOUT_ALPHA=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","uniform float m[20];","void main(void) {","vec4 c = texture2D(texture, vUv);","gl_FragColor.r = m[0] * c.r + m[1] * c.g + m[2] * c.b + m[4];","gl_FragColor.g = m[5] * c.r + m[6] * c.g + m[7] * c.b + m[9];","gl_FragColor.b = m[10] * c.r + m[11] * c.g + m[12] * c.b + m[14];","gl_FragColor.a = c.a;","}"].join( `
` ),_filter.brightness=function(brightness){let b=(brightness||0)+1;_filter.colorMatrix([b,0,0,0,0,0,b,0,0,0,0,0,b,0,0,0,0,0,1,0])},_filter.saturation=function(amount){let x=(amount||0)*2/3+1,y=(x-1)*-.5;_filter.colorMatrix([x,y,y,0,0,y,x,y,0,0,y,y,x,0,0,0,0,0,1,0])},_filter.desaturate=function(){_filter.saturation(-1)},_filter.contrast=function(amount){let v=(amount||0)+1,o=-128*(v-1);_filter.colorMatrix([v,0,0,0,o,0,v,0,0,o,0,0,v,0,o,0,0,0,1,0])},_filter.negative=function(){_filter.contrast(-2)},_filter.hue=function(rotation){rotation=(rotation||0)/180*Math.PI;let cos4=Math.cos(rotation),sin4=Math.sin(rotation),lumR=.213,lumG=.715,lumB=.072;_filter.colorMatrix([lumR+cos4*(1-lumR)+sin4*-lumR,lumG+cos4*-lumG+sin4*-lumG,lumB+cos4*-lumB+sin4*(1-lumB),0,0,lumR+cos4*-lumR+sin4*.143,lumG+cos4*(1-lumG)+sin4*.14,lumB+cos4*-lumB+sin4*-.283,0,0,lumR+cos4*-lumR+sin4*-(1-lumR),lumG+cos4*-lumG+sin4*lumG,lumB+cos4*(1-lumB)+sin4*lumB,0,0,0,0,0,1,0])},_filter.desaturateLuminance=function(){_filter.colorMatrix([.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,0,0,0,1,0])},_filter.sepia=function(){_filter.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])},_filter.brownie=function(){_filter.colorMatrix([.5997023498159715,.34553243048391263,-.2708298674538042,0,47.43192855600873,-.037703249837783157,.8609577587992641,.15059552388459913,0,-36.96841498319127,.24113635128153335,-.07441037908422492,.44972182064877153,0,-7.562075277591283,0,0,0,1,0])},_filter.vintagePinhole=function(){_filter.colorMatrix([.6279345635605994,.3202183420819367,-.03965408211312453,0,9.651285835294123,.02578397704808868,.6441188644374771,.03259127616149294,0,7.462829176470591,.0466055556782719,-.0851232987247891,.5241648018700465,0,5.159190588235296,0,0,0,1,0])},_filter.kodachrome=function(){_filter.colorMatrix([1.1285582396593525,-.3967382283601348,-.03992559172921793,0,63.72958762196502,-.16404339962244616,1.0835251566291304,-.05498805115633132,0,24.732407896706203,-.16786010706155763,-.5603416277695248,1.6014850761964943,0,35.62982807460946,0,0,0,1,0])},_filter.technicolor=function(){_filter.colorMatrix([1.9125277891456083,-.8545344976951645,-.09155508482755585,0,11.793603434377337,-.3087833385928097,1.7658908555458428,-.10601743074722245,0,-70.35205161461398,-.231103377548616,-.7501899197440212,1.847597816108189,0,30.950940869491138,0,0,0,1,0])},_filter.polaroid=function(){_filter.colorMatrix([1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0])},_filter.shiftToBGR=function(){_filter.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])},_filter.convolution=function(matrix){let m=new Float32Array(matrix),pixelSizeX=1/_width,pixelSizeY=1/_height,program=_compileShader(_filter.convolution.SHADER);gl.uniform1fv(program.uniform.m,m),gl.uniform2f(program.uniform.px,pixelSizeX,pixelSizeY),_draw()},_filter.convolution.SHADER=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","uniform vec2 px;","uniform float m[9];","void main(void) {","vec4 c11 = texture2D(texture, vUv - px);","vec4 c12 = texture2D(texture, vec2(vUv.x, vUv.y - px.y));","vec4 c13 = texture2D(texture, vec2(vUv.x + px.x, vUv.y - px.y));","vec4 c21 = texture2D(texture, vec2(vUv.x - px.x, vUv.y) );","vec4 c22 = texture2D(texture, vUv);","vec4 c23 = texture2D(texture, vec2(vUv.x + px.x, vUv.y) );","vec4 c31 = texture2D(texture, vec2(vUv.x - px.x, vUv.y + px.y) );","vec4 c32 = texture2D(texture, vec2(vUv.x, vUv.y + px.y) );","vec4 c33 = texture2D(texture, vUv + px );","gl_FragColor = ","c11 * m[0] + c12 * m[1] + c22 * m[2] +","c21 * m[3] + c22 * m[4] + c23 * m[5] +","c31 * m[6] + c32 * m[7] + c33 * m[8];","gl_FragColor.a = c22.a;","}"].join( `
` ),_filter.detectEdges=function(){_filter.convolution.call(this,[0,1,0,1,-4,1,0,1,0])},_filter.sobelX=function(){_filter.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])},_filter.sobelY=function(){_filter.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])},_filter.sharpen=function(amount){let a=amount||1;_filter.convolution.call(this,[0,-1*a,0,-1*a,1+4*a,-1*a,0,-1*a,0])},_filter.emboss=function(size){let s=size||1;_filter.convolution.call(this,[-2*s,-1*s,0,-1*s,1,1*s,0,1*s,2*s])},_filter.blur=function(size){let blurSizeX=size/7/_width,blurSizeY=size/7/_height,program=_compileShader(_filter.blur.SHADER);gl.uniform2f(program.uniform.px,0,blurSizeY),_draw(DRAW.INTERMEDIATE),gl.uniform2f(program.uniform.px,blurSizeX,0),_draw()},_filter.blur.SHADER=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","uniform vec2 px;","void main(void) {","gl_FragColor = vec4(0.0);","gl_FragColor += texture2D(texture, vUv + vec2(-7.0*px.x, -7.0*px.y))*0.0044299121055113265;","gl_FragColor += texture2D(texture, vUv + vec2(-6.0*px.x, -6.0*px.y))*0.00895781211794;","gl_FragColor += texture2D(texture, vUv + vec2(-5.0*px.x, -5.0*px.y))*0.0215963866053;","gl_FragColor += texture2D(texture, vUv + vec2(-4.0*px.x, -4.0*px.y))*0.0443683338718;","gl_FragColor += texture2D(texture, vUv + vec2(-3.0*px.x, -3.0*px.y))*0.0776744219933;","gl_FragColor += texture2D(texture, vUv + vec2(-2.0*px.x, -2.0*px.y))*0.115876621105;","gl_FragColor += texture2D(texture, vUv + vec2(-1.0*px.x, -1.0*px.y))*0.147308056121;","gl_FragColor += texture2D(texture, vUv )*0.159576912161;","gl_FragColor += texture2D(texture, vUv + vec2( 1.0*px.x, 1.0*px.y))*0.147308056121;","gl_FragColor += texture2D(texture, vUv + vec2( 2.0*px.x, 2.0*px.y))*0.115876621105;","gl_FragColor += texture2D(texture, vUv + vec2( 3.0*px.x, 3.0*px.y))*0.0776744219933;","gl_FragColor += texture2D(texture, vUv + vec2( 4.0*px.x, 4.0*px.y))*0.0443683338718;","gl_FragColor += texture2D(texture, vUv + vec2( 5.0*px.x, 5.0*px.y))*0.0215963866053;","gl_FragColor += texture2D(texture, vUv + vec2( 6.0*px.x, 6.0*px.y))*0.00895781211794;","gl_FragColor += texture2D(texture, vUv + vec2( 7.0*px.x, 7.0*px.y))*0.0044299121055113265;","}"].join( `
` ),_filter.pixelate=function(size){let blurSizeX=size/_width,blurSizeY=size/_height,program=_compileShader(_filter.pixelate.SHADER);gl.uniform2f(program.uniform.size,blurSizeX,blurSizeY),_draw()},_filter.pixelate.SHADER=["precision highp float;","varying vec2 vUv;","uniform vec2 size;","uniform sampler2D texture;","vec2 pixelate(vec2 coord, vec2 size) {","return floor( coord / size ) * size;","}","void main(void) {","gl_FragColor = vec4(0.0);","vec2 coord = pixelate(vUv, size);","gl_FragColor += texture2D(texture, coord);","}"].join( `
` )};exports.Canvas=WebGLImageFilter});var require_image=__commonJS(exports=>{var fxImage=__toModule(require_imagefx()),inCanvas=null,outCanvas=null;function process3(input2,config2){let tensor2;if(input2 instanceof Tensor)tensor2=clone(input2);else{let originalWidth=input2.naturalWidth||input2.videoWidth||input2.width||input2.shape&&input2.shape[1]>0,originalHeight=input2.naturalHeight||input2.videoHeight||input2.height||input2.shape&&input2.shape[2]>0,targetWidth=originalWidth,targetHeight=originalHeight;if(config2.filter.width>0?targetWidth=config2.filter.width:config2.filter.height>0&&(targetWidth=originalWidth*(config2.filter.height/originalHeight)),config2.filter.height>0?targetHeight=config2.filter.height:config2.filter.width>0&&(targetHeight=originalHeight*(config2.filter.width/originalWidth)),!targetWidth||!targetHeight)return log("Human: invalid input",input2),null;(!inCanvas||inCanvas.width!==targetWidth||inCanvas.height!==targetHeight)&&(inCanvas=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(targetWidth,targetHeight):document.createElement("canvas"),inCanvas.width!==targetWidth&&(inCanvas.width=targetWidth),inCanvas.height!==targetHeight&&(inCanvas.height=targetHeight));let ctx=inCanvas.getContext("2d");if(input2 instanceof ImageData?ctx.putImageData(input2,0,0):ctx.drawImage(input2,0,0,originalWidth,originalHeight,0,0,inCanvas.width,inCanvas.height),config2.filter.enabled){if((!this.fx||!outCanvas||inCanvas.width!==outCanvas.width||inCanvas.height!==outCanvas.height)&&(outCanvas=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(inCanvas.width,inCanvas.height):document.createElement("canvas"),outCanvas.width!==inCanvas.width&&(outCanvas.width=inCanvas.width),outCanvas.height!==inCanvas.height&&(outCanvas.height=inCanvas.height),this.fx=ENV.flags.IS_BROWSER?new fxImage.Canvas({canvas:outCanvas}):null),!this.fx)return inCanvas;this.fx.reset(),this.fx.addFilter("brightness",config2.filter.brightness),config2.filter.contrast!==0&&this.fx.addFilter("contrast",config2.filter.contrast),config2.filter.sharpness!==0&&this.fx.addFilter("sharpen",config2.filter.sharpness),config2.filter.blur!==0&&this.fx.addFilter("blur",config2.filter.blur),config2.filter.saturation!==0&&this.fx.addFilter("saturation",config2.filter.saturation),config2.filter.hue!==0&&this.fx.addFilter("hue",config2.filter.hue),config2.filter.negative&&this.fx.addFilter("negative"),config2.filter.sepia&&this.fx.addFilter("sepia"),config2.filter.vintage&&this.fx.addFilter("brownie"),config2.filter.sepia&&this.fx.addFilter("sepia"),config2.filter.kodachrome&&this.fx.addFilter("kodachrome"),config2.filter.technicolor&&this.fx.addFilter("technicolor"),config2.filter.polaroid&&this.fx.addFilter("polaroid"),config2.filter.pixelate!==0&&this.fx.addFilter("pixelate",config2.filter.pixelate),this.fx.apply(inCanvas)}else outCanvas=inCanvas;let pixels;if(outCanvas.data){let shape=[outCanvas.height,outCanvas.width,3];pixels=tensor3d(outCanvas.data,shape,"int32")}else if(config2.backend==="webgl"||outCanvas instanceof ImageData)pixels=browser_exports.fromPixels(outCanvas);else{let tempCanvas=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(targetWidth,targetHeight):document.createElement("canvas");tempCanvas.width=targetWidth,tempCanvas.height=targetHeight;let tempCtx=tempCanvas.getContext("2d");tempCtx==null||tempCtx.drawImage(outCanvas,0,0);let data2=tempCtx==null?void 0:tempCtx.getImageData(0,0,targetWidth,targetHeight);pixels=browser_exports.fromPixels(data2)}let casted=pixels.toFloat();tensor2=casted.expandDims(0),pixels.dispose(),casted.dispose()}return{tensor:tensor2,canvas:config2.filter.return?outCanvas:null}}exports.process=process3});function log(...msg){let dt=new Date,ts= ` $ { dt . getHours ( ) . toString ( ) . padStart ( 2 , "0" ) } : $ { dt . getMinutes ( ) . toString ( ) . padStart ( 2 , "0" ) } : $ { dt . getSeconds ( ) . toString ( ) . padStart ( 2 , "0" ) } . $ { dt . getMilliseconds ( ) . toString ( ) . padStart ( 3 , "0" ) } ` ;msg&&console.log(ts,"Human:",...msg)}var tfjs_esm_exports={};__export(tfjs_esm_exports,{Abs:()=>Abs,Acos:()=>Acos,Acosh:()=>Acosh,AdadeltaOptimizer:()=>AdadeltaOptimizer,Adagra
` )),lines.join( `
` )}function computeMaxSizePerColumn(vals,shape,dtype,strides){let n=sizeFromShape(shape),numCols=strides[strides.length-1],padPerCol=new Array(numCols).fill(0),rank=shape.length,valuesOrTuples=dtype==="complex64"?createComplexTuples(vals):vals;if(rank>1)for(let row=0;row<n/numCols;row++){let offset=row*numCols;for(let j=0;j<numCols;j++)padPerCol[j]=Math.max(padPerCol[j],valToString(valuesOrTuples[offset+j],0,dtype).length)}return padPerCol}function valToString(val,pad3,dtype){let valStr;return Array.isArray(val)?valStr= ` $ { parseFloat ( val [ 0 ] . toFixed ( FORMAT _NUM _SIG _DIGITS ) ) } + $ { parseFloat ( val [ 1 ] . toFixed ( FORMAT _NUM _SIG _DIGITS ) ) } j ` :isString(val)?valStr= ` '${val}' ` :dtype==="bool"?valStr=boolNumToString(val):valStr=parseFloat(val.toFixed(FORMAT_NUM_SIG_DIGITS)).toString(),rightPad(valStr,pad3)}function boolNumToString(v){return v===0?"false":"true"}function subTensorToString(vals,shape,dtype,strides,padPerCol,isLast=!0){let storagePerElement=dtype==="complex64"?2:1,size=shape[0],rank=shape.length;if(rank===0){if(dtype==="complex64"){let complexTuple=createComplexTuples(vals);return[valToString(complexTuple[0],0,dtype)]}return dtype==="bool"?[boolNumToString(vals[0])]:[vals[0].toString()]}if(rank===1){if(size>FORMAT_LIMIT_NUM_VALS){let firstValsSize=FORMAT_NUM_FIRST_LAST_VALS*storagePerElement,firstVals=Array.from(vals.slice(0,firstValsSize)),lastVals=Array.from(vals.slice((size-FORMAT_NUM_FIRST_LAST_VALS)*storagePerElement,size*storagePerElement));return dtype==="complex64"&&(firstVals=createComplexTuples(firstVals),lastVals=createComplexTuples(lastVals)),["["+firstVals.map((x,i)=>valToString(x,padPerCol[i],dtype)).join(", ")+", ..., "+lastVals.map((x,i)=>valToString(x,padPerCol[size-FORMAT_NUM_FIRST_LAST_VALS+i],dtype)).join(", ")+"]"]}let displayVals=dtype==="complex64"?createComplexTuples(vals):Array.from(vals);return["["+displayVals.map((x,i)=>valToString(x,padPerCol[i],dtype)).join(", ")+"]"]}let subshape=shape.slice(1),substrides=strides.slice(1),stride=strides[0]*storagePerElement,lines=[];if(size>FORMAT_LIMIT_NUM_VALS){for(let i=0;i<FORMAT_NUM_FIRST_LAST_VALS;i++){let start=i*stride,end=start+stride;lines.push(...subTensorToString(vals.slice(start,end),subshape,dtype,substrides,padPerCol,!1))}lines.push("...");for(let i=size-FORMAT_NUM_FIRST_LAST_VALS;i<size;i++){let start=i*stride,end=start+stride;lines.push(...subTensorToString(vals.slice(start,end),subshape,dtype,substrides,padPerCol,i===size-1))}}else for(let i=0;i<size;i++){let start=i*stride,end=start+stride;lines.push(...subTensorToString(vals.slice(start,end),subshape,dtype,substrides,padPerCol,i===size-1))}let sep=rank===2?",":"";lines[0]="["+lines[0]+sep;for(let i=1;i<lines.length-1;i++)lines[i]=" "+lines[i]+sep;let newLineSep= ` ,
` ;for(let i=2;i<rank;i++)newLineSep+= `
` ;return lines[lines.length-1]=" "+lines[lines.length-1]+"]"+(isLast?"":newLineSep),lines}function createComplexTuples(vals){let complexTuples=[];for(let i=0;i<vals.length;i+=2)complexTuples.push([vals[i],vals[i+1]]);return complexTuples}var TensorBuffer=class{constructor(shape,dtype,values){if(this.dtype=dtype,this.shape=shape.slice(),this.size=sizeFromShape(shape),values!=null){let n=values.length;assert(n===this.size,()=> ` Length of values '${n}' does not match the size inferred by the shape '${this.size}' . ` )}if(dtype==="complex64")throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");this.values=values||getArrayFromDType(dtype,this.size),this.strides=computeStrides(shape)}set(value,...locs){locs.length===0&&(locs=[0]),assert(locs.length===this.rank,()=> ` The number of provided coordinates ( $ { locs . length } ) must match the rank ( $ { this . rank } ) ` );let index=this.locToIndex(locs);this.values[index]=value}get(...locs){locs.length===0&&(locs=[0]);let i=0;for(let loc of locs){if(loc<0||loc>=this.shape[i]){let msg= ` Requested out of range element at $ { locs } . Buffer shape = $ { this . shape } ` ;throw new Error(msg)}i++}let index=locs[locs.length-1];for(let i2=0;i2<locs.length-1;++i2)index+=this.strides[i2]*locs[i2];return this.values[index]}locToIndex(locs){if(this.rank===0)return 0;if(this.rank===1)return locs[0];let index=locs[locs.length-1];for(let i=0;i<locs.length-1;++i)index+=this.strides[i]*locs[i];return index}indexToLoc(index){if(this.rank===0)return[];if(this.rank===1)return[index];let locs=new Array(this.shape.length);for(let i=0;i<locs.length-1;++i)locs[i]=Math.floor(index/this.strides[i]),index-=locs[i]*this.strides[i];return locs[locs.length-1]=index,locs}get rank(){return this.shape.length}toTensor(){return trackerFn().makeTensor(this.values,this.shape,this.dtype)}},trackerFn=null,opHandler=null,deprecationWarningFn=null;function setTensorTracker(fn){trackerFn=fn}function setOpHandler(handler){opHandler=handler}function setDeprecationWarningFn(fn){deprecationWarningFn=fn}var Tensor=class{constructor(shape,dtype,dataId,id){this.kept=!1,this.isDisposedInternal=!1,this.shape=shape.slice(),this.dtype=dtype||"float32",this.size=sizeFromShape(shape),this.strides=computeStrides(shape),this.dataId=dataId,this.id=id,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){let vals=await this.data();return opHandler.buffer(this.shape,this.dtype,vals)}bufferSync(){return opHandler.buffer(this.shape,this.dtype,this.dataSync())}async array(){let vals=await this.data();return toNestedArray(this.shape,vals)}arraySync(){return toNestedArray(this.shape,this.dataSync())}async data(){this.throwIfDisposed();let data2=trackerFn().read(this.dataId);if(this.dtype==="string"){let bytes=await data2;try{return bytes.map(b=>decodeString(b))}catch(_a){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}}return data2}dataSync(){this.throwIfDisposed();let data2=trackerFn().readSync(this.dataId);if(this.dtype==="string")try{return data2.map(b=>decodeString(b))}catch(_a){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return data2}async bytes(){this.throwIfDisposed();let data2=await trackerFn().read(this.dataId);return this.dtype==="string"?data2:new Uint8Array(data2.buffer)}dispose(){this.isDisposed||(trackerFn().disposeTensor(this),this.isDisposedInternal=!0)}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(verbose=!1){return opHandler.print(this,verbose)}clone(){return this.throwIfDisposed(),opHandler.clone(this)}toString(verbose=!1){let vals=this.dataSync();return tensorToString(vals,this.shape,this.dtype,verbose)}cast(dtype){return this.throwIfDisposed(),opHandler.cast(this,dtype)}variable(trainable=!0,name,dtype){return this.throwIfDisposed(),trackerFn().makeVariable(this,train
Manifest JSON has weights with names : $ { allManifestWeightNames . join ( ", " ) } . ` )}let groupIndicesToFetch=groupIndicesToFetchMap.reduce((accumulator,shouldFetch,i)=>(shouldFetch&&accumulator.push(i),accumulator),[]),fetchUrls=[];groupIndicesToFetch.forEach(i=>{manifest[i].paths.forEach(filepath=>{let fetchUrl=filePathPrefix+(filePathPrefix.endsWith("/")?"":"/")+filepath;fetchUrls.push(fetchUrl)})});let buffers=await fetchWeightsFunction(fetchUrls),weightsTensorMap={},bufferIndexOffset=0;return groupIndicesToFetch.forEach(i=>{let numBuffers=manifest[i].paths.length,groupBytes=0;for(let i2=0;i2<numBuffers;i2++)groupBytes+=buffers[bufferIndexOffset+i2].byteLength;let groupBuffer=new ArrayBuffer(groupBytes),groupByteBuffer=new Uint8Array(groupBuffer),groupBufferOffset=0;for(let i2=0;i2<numBuffers;i2++){let buffer2=new Uint8Array(buffers[bufferIndexOffset+i2]);groupByteBuffer.set(buffer2,groupBufferOffset),groupBufferOffset+=buffer2.byteLength}groupWeightsToFetch[i].forEach(weightsEntry=>{let byteBuffer=groupBuffer.slice(weightsEntry.groupOffset,weightsEntry.groupOffset+weightsEntry.sizeBytes),nameToTensorMap=decodeWeights(byteBuffer,[weightsEntry.manifestEntry]);for(let name in nameToTensorMap)weightsTensorMap[name]=nameToTensorMap[name]}),bufferIndexOffset+=numBuffers}),weightsTensorMap}}var OCTET_STREAM_MIME_TYPE="application/octet-stream",JSON_TYPE="application/json",HTTPRequest=class{constructor(path,loadOptions){if(this.DEFAULT_METHOD="POST",loadOptions==null&&(loadOptions={}),this.weightPathPrefix=loadOptions.weightPathPrefix,this.onProgress=loadOptions.onProgress,this.weightUrlConverter=loadOptions.weightUrlConverter,loadOptions.fetchFunc!=null?(assert(typeof loadOptions.fetchFunc=="function",()=>"Must pass a function that matches the signature of ` fetch ` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"),this.fetch=loadOptions.fetchFunc):this.fetch=env().platform.fetch,assert(path!=null&&path.length>0,()=>"URL path for http must not be null, undefined or empty."),Array.isArray(path)&&assert(path.length===2,()=> ` URL paths for http must have a length of 2 , ( actual length is $ { path . length } ) . ` ),this.path=path,loadOptions.requestInit!=null&&loadOptions.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=loadOptions.requestInit||{}}async save(modelArtifacts){if(modelArtifacts.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");let init2=Object.assign({method:this.DEFAULT_METHOD},this.requestInit);init2.body=new FormData;let weightsManifest=[{paths:["./model.weights.bin"],weights:modelArtifacts.weightSpecs}],modelTopologyAndWeightManifest={modelTopology:modelArtifacts.modelTopology,format:modelArtifacts.format,generatedBy:modelArtifacts.generatedBy,convertedBy:modelArtifacts.convertedBy,weightsManifest};modelArtifacts.signature!=null&&(modelTopologyAndWeightManifest.signature=modelArtifacts.signature),modelArtifacts.userDefinedMetadata!=null&&(modelTopologyAndWeightManifest.userDefinedMetadata=modelArtifacts.userDefinedMetadata),modelArtifacts.modelInitializer!=null&&(modelTopologyAndWeightManifest.modelInitializer=modelArtifacts.modelInitializer),init2.body.append("model.json",new Blob([JSON.stringify(modelTopologyAndWeightManifest)],{type:JSON_TYPE}),"model.json"),modelArtifacts.weightData!=null&&init2.body.append("model.weights.bin",new Blob([modelArtifacts.weightData],{type:OCTET_STREAM_MIME_TYPE}),"model.weights.bin");let response=await this.fetch(this.path,init2);if(response.ok)return{modelArtifactsInfo:getModelArtifactsInfoForJSON(modelArtifacts),responses:[response]};throw new Error( ` BrowserHTTPRequest . save ( ) failed due to HTTP response status $ { response . status } . ` )}async load(){let modelConfigRequest=await this.fetch(this.path,this.requestInit);if(!modelConfigRequest.ok)throw new Error( ` Request to $ { this . path } failed with status code $ { modelConfigRequest . status } . Please verify this URL points to the model JSON of the model to load . ` );let mo
Actual : $ { actualFlat } .
Expected : $ { expectedFlat } . ` );for(let i=0;i<expectedFlat.length;++i){let a=actualFlat[i],e=expectedFlat[i];if(!predicate(a,e))throw new Error( ` Arrays differ : actual [ $ { i } ] = $ { a } , expected [ $ { i } ] = $ { e } .
Actual : $ { actualFlat } .
Expected : $ { expectedFlat } . ` )}}function expectPromiseToFail(fn,done){fn().then(()=>done.fail(),()=>done())}function expectArraysEqual(actual,expected){let exp4=typeof expected=="string"||typeof expected=="number"||typeof expected=="boolean"?[expected]:expected;return isString(actual)||isString(actual[0])||isString(expected)||isString(expected[0])?expectArraysPredicate(actual,exp4,(a,b)=>a==b):expectArraysPredicate(actual,expected,(a,b)=>areClose(a,b,0))}function expectNumbersClose(a,e,epsilon3){if(epsilon3==null&&(epsilon3=testEpsilon()),!areClose(a,e,epsilon3))throw new Error( ` Numbers differ : actual === $ { a } , expected === $ { e } ` )}function areClose(a,e,epsilon3){return!isFinite(a)&&!isFinite(e)?!0:!(isNaN(a)||isNaN(e)||Math.abs(a-e)>epsilon3)}function expectValuesInRange(actual,low,high){for(let i=0;i<actual.length;i++)if(actual[i]<low||actual[i]>high)throw new Error( ` Value out of range : $ { actual [ i ] } low : $ { low } , high : $ { high } ` )}function expectArrayBuffersEqual(actual,expected){expect(new Float32Array(actual)).toEqual(new Float32Array(expected))}function encodeStrings(a){for(let i=0;i<a.length;i++){let val=a[i];Array.isArray(val)?encodeStrings(val):a[i]=encodeString(val)}return a}var version6="2.8.3";function enableProdMode(){env().set("PROD",!0)}function enableDebugMode(){env().set("DEBUG",!0)}function disableDeprecationWarnings(){env().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")}function deprecationWarn(msg){env().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(msg+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}setDeprecationWarningFn(deprecationWarn);function disposeVariables(){ENGINE.disposeVariables()}function engine(){return ENGINE}function memory(){return ENGINE.memory()}function profile(f){return ENGINE.profile(f)}function tidy(nameOrFn,fn){return ENGINE.tidy(nameOrFn,fn)}function dispose(container){getTensorsInContainer(container).forEach(tensor2=>tensor2.dispose())}function keep(result){return ENGINE.keep(result)}function time(f){return ENGINE.time(f)}function setBackend(backendName){return ENGINE.setBackend(backendName)}function ready(){return ENGINE.ready()}function getBackend(){return ENGINE.backendName}function removeBackend(name){ENGINE.removeBackend(name)}function findBackend(name){return ENGINE.findBackend(name)}function findBackendFactory(name){return ENGINE.findBackendFactory(name)}function registerBackend(name,factory,priority=1){return ENGINE.registerBackend(name,factory,priority)}function backend(){return ENGINE.backend}function setPlatform(platformName,platform){env().setPlatform(platformName,platform)}function add_(a,b){let $ a=convertToTensor(a,"a","add"), $ b=convertToTensor(b,"b","add");[ $ a, $ b]=makeTypesMatch( $ a, $ b);let inputs={a: $ a,b: $ b};return ENGINE.runKernel(Add,inputs)}var add2=op({add_});function floorDiv_(a,b){let $ a=convertToTensor(a,"a","floorDiv"), $ b=convertToTensor(b,"b","floorDiv");[ $ a, $ b]=makeTypesMatch( $ a, $ b);let inputs={a: $ a,b: $ b};return ENGINE.runKernel(FloorDiv,inputs)}var floorDiv=op({floorDiv_});function div_(a,b){let $ a=convertToTensor(a,"a","div"), $ b=convertToTensor(b,"b","div");if([ $ a, $ b]=makeTypesMatch( $ a, $ b), $ a.dtype==="int32"&& $ b.dtype==="int32")return floorDiv( $ a, $ b);let inputs={a: $ a,b: $ b},attrs={};return ENGINE.runKernel(RealDiv,inputs,attrs)}var div=op({div_});function mul_(a,b){let $ a=convertToTensor(a,"a","mul"), $ b=convertToTensor(b,"b","mul");[ $ a, $ b]=makeTypesMatch( $ a, $ b);let inputs={a: $ a,b: $ b};return ENGINE.runKernel(Multiply,inputs)}var mul=op({mul_});function abs_(x){let $ x=convertToTensor(x,"x","abs");if( $ x.dtype==="complex64"){let inputs={x: $ x};return ENGINE.runKernel(ComplexAbs,inputs)}else{let inputs={x: $ x};return ENGINE.runKernel(Abs,inputs)}}var abs=op({abs_});function acos_(x){let inputs={x:convertToTensor(x,"x","acos")};return ENGINE.runKernel(Acos,inputs)}var acos=op({acos_});function acosh_(x){let inputs={x:convertToTensor(x,"x","acosh")};return ENGINE.runKernel(Acosh,inputs)}var acosh=op({acosh_});function addN_(tensors){assert(Array.isArray(tensors),()
with dtype $ { tensor2 . dtype } . ` )}), $ tensors.length===1)return clone( $ tensors[0]);let inputs= $ tensors,attr={axis};return ENGINE.runKernel(Concat,inputs,attr)}var concat=op({concat_});function sigmoid_(x){let inputs={x:convertToTensor(x,"x","sigmoid")};return ENGINE.runKernel(Sigmoid,inputs)}var sigmoid=op({sigmoid_});function slice_(x,begin,size){let $ x=convertToTensor(x,"x","slice","string_or_numeric");if( $ x.rank===0)throw new Error("Slicing scalar is not possible");let inputs={x: $ x},attrs={begin,size};return ENGINE.runKernel(Slice,inputs,attrs)}var slice=op({slice_});function tanh_(x){let inputs={x:convertToTensor(x,"x","tanh")};return ENGINE.runKernel(Tanh,inputs)}var tanh2=op({tanh_});function basicLSTMCell_(forgetBias,lstmKernel,lstmBias,data2,c,h){let $ forgetBias=convertToTensor(forgetBias,"forgetBias","basicLSTMCell"), $ lstmKernel=convertToTensor(lstmKernel,"lstmKernel","basicLSTMCell"), $ lstmBias=convertToTensor(lstmBias,"lstmBias","basicLSTMCell"), $ data=convertToTensor(data2,"data","basicLSTMCell"), $ c=convertToTensor(c,"c","basicLSTMCell"), $ h=convertToTensor(h,"h","basicLSTMCell"),combined=concat([ $ data, $ h],1),weighted=matMul(combined, $ lstmKernel),res=add2(weighted, $ lstmBias),batchSize=res.shape[0],sliceCols=res.shape[1]/4,sliceSize=[batchSize,sliceCols],i=slice(res,[0,0],sliceSize),j=slice(res,[0,sliceCols],sliceSize),f=slice(res,[0,sliceCols*2],sliceSize),o=slice(res,[0,sliceCols*3],sliceSize),newC=add2(mul(sigmoid(i),tanh2(j)),mul( $ c,sigmoid(add2( $ forgetBias,f)))),newH=mul(tanh2(newC),sigmoid(o));return[newC,newH]}var basicLSTMCell=op({basicLSTMCell_});function batchToSpaceND_(x,blockShape,crops){let $ x=convertToTensor(x,"x","batchToSpaceND"),prod5=blockShape.reduce((a,b)=>a*b);assert( $ x.rank>=1+blockShape.length,()=> ` input rank is $ { $x . rank } but should be > than blockShape . length $ { blockShape . length } ` ),assert(crops.length===blockShape.length,()=> ` crops . length is $ { crops . length } but should be equal to blockShape . length $ { blockShape . length } ` ),assert( $ x.shape[0]%prod5==0,()=> ` input tensor batch is $ { $x . shape [ 0 ] } but is not divisible by the product of the elements of blockShape $ { blockShape . join ( " * " ) } === $ { prod5 } ` );let inputs={x: $ x},attrs={blockShape,crops};return ENGINE.runKernel(BatchToSpaceND,inputs,attrs)}var batchToSpaceND=op({batchToSpaceND_});function xAs4D(x){let x4D;return x.rank===0||x.rank===1?x4D=reshape(x,[1,1,1,x.size]):x.rank===2?x4D=reshape(x,[1,1,x.shape[0],x.shape[1]]):x.rank===3?x4D=reshape(x,[1,x.shape[0],x.shape[1],x.shape[2]]):x4D=x,x4D}function batchNorm_(x,mean4,variance,offset,scale2,varianceEpsilon){varianceEpsilon==null&&(varianceEpsilon=.001);let $ x=convertToTensor(x,"x","batchNorm"), $ mean=convertToTensor(mean4,"mean","batchNorm"), $ variance=convertToTensor(variance,"variance","batchNorm"), $ scale;scale2!=null&&( $ scale=convertToTensor(scale2,"scale","batchNorm"));let $ offset;offset!=null&&( $ offset=convertToTensor(offset,"offset","batchNorm")),assert( $ mean.rank=== $ variance.rank,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),assert( $ offset==null|| $ mean.rank=== $ offset.rank,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),assert( $ scale==null|| $ mean.rank=== $ scale.rank,()=>"Batch normalization gradient requires mean and scale to have equal ranks.");let inputs={x:xAs4D( $ x),scale: $ scale,offset: $ offset,mean: $ mean,variance: $ variance},attrs={varianceEpsilon},res=ENGINE.runKernel(FusedBatchNorm,inputs,attrs);return reshape(res, $ x.shape)}var batchNorm=op({batchNorm_});function batchNorm2d_(x,mean4,variance,offset,scale2,varianceEpsilon){let $ x=convertToTensor(x,"x","batchNorm"), $ mean=convertToTensor(mean4,"mean","batchNorm"), $ variance=convertToTensor(variance,"variance","batchNorm"), $ scale;scale2!=null&&( $ scale=convertToTensor(scale2,"scale","batchNorm"));let $ offset;return offset!=null&&( $ offset=convertToTensor(offset,"offset","batchNorm")),assert( $ x.rank===2,()=> ` Error in batchNorm2D : x must be rank 2 but got rank $ { $x . rank } . ` ),assert( $ mean.rank===2|| $ mean.rank===1,()=> ` Error in batchNorm2D : mean must be rank 2 or ran
$ { inputHeight } and $ { blockSize } for depthToSpace with input shape
$ { $x . shape } ` ),assert(inputWidth*blockSize>=0,()=> ` Negative dimension size caused by overflow when multiplying
$ { inputWidth } and $ { blockSize } for depthToSpace with input shape
$ { $x . shape } ` ),assert(inputDepth%(blockSize*blockSize)==0,()=> ` Dimension size must be evenly divisible by $ { blockSize * blockSize } but is $ { inputDepth } for depthToSpace with input shape $ { $x . shape } ` );let inputs={x: $ x},attrs={blockSize,dataFormat};return ENGINE.runKernel(DepthToSpace,inputs,attrs)}var depthToSpace=op({depthToSpace_});function depthwiseConv2d_(x,filter,strides,pad3,dataFormat="NHWC",dilations=[1,1],dimRoundingMode){let $ x=convertToTensor(x,"x","depthwiseConv2d"), $ filter=convertToTensor(filter,"filter","depthwiseConv2d"),x4D= $ x,reshapedTo4D=!1; $ x.rank===3&&(reshapedTo4D=!0,x4D=reshape( $ x,[1, $ x.shape[0], $ x.shape[1], $ x.shape[2]])),assert(x4D.rank===4,()=> ` Error in depthwiseConv2d : input must be rank 4 , but got rank $ { x4D . rank } . ` ),assert( $ filter.rank===4,()=> ` Error in depthwiseConv2d : filter must be rank 4 , but got rank $ { $filter . rank } . ` ),assert(x4D.shape[3]=== $ filter.shape[2],()=> ` Error in depthwiseConv2d : number of input channels ( $ { x4D . shape [ 3 ] } ) must match the inChannels dimension in filter $ { $filter . shape [ 2 ] } . ` ),dimRoundingMode!=null&&assert(isInt(pad3),()=> ` Error in depthwiseConv2d : pad must be an integer when using , dimRoundingMode $ { dimRoundingMode } but got pad $ { pad3 } . ` );let inputs={x:x4D,filter: $ filter},attrs={strides,pad:pad3,dataFormat,dilations,dimRoundingMode},res=ENGINE.runKernel(DepthwiseConv2dNative,inputs,attrs);return reshapedTo4D?reshape(res,[res.shape[1],res.shape[2],res.shape[3]]):res}var depthwiseConv2d=op({depthwiseConv2d_});function diag_(x){let inputs={x:convertToTensor(x,"x","diag")};return ENGINE.runKernel(Diag,inputs)}var diag=op({diag_});function dilation2d_(x,filter,strides,pad3,dilations=[1,1],dataFormat="NHWC"){let $ x=convertToTensor(x,"x","dilation2d"), $ filter=convertToTensor(filter,"filter","dilation2d");assert( $ x.rank===3|| $ x.rank===4,()=> ` Error in dilation2d : input must be rank 3 or 4 , but got rank $ { $x . rank } . ` ),assert( $ filter.rank===3,()=> ` Error in dilation2d : filter must be rank 3 , but got rank $ { $filter . rank } . ` ),assert(dataFormat==="NHWC",()=> ` Error in dilation2d : Only NHWC is currently supported , but got dataFormat of $ { dataFormat } ` );let x4D= $ x,reshapedTo4D=!1; $ x.rank===3&&(x4D=reshape( $ x,[1, $ x.shape[0], $ x.shape[1], $ x.shape[2]]),reshapedTo4D=!0);let inputs={x:x4D,filter: $ filter},attrs={strides,pad:pad3,dilations},res=ENGINE.runKernel(Dilation2D,inputs,attrs);return reshapedTo4D?reshape(res,[res.shape[1],res.shape[2],res.shape[3]]):res}var dilation2d=op({dilation2d_});function getBroadcastDims(inShape,outShape){let inRank=inShape.length,dims=[];for(let i=0;i<inRank;i++){let dim=inRank-1-i,a=inShape[dim]||1;(outShape[outShape.length-1-i]||1)>1&&a===1&&dims.unshift(dim)}return dims}function getReductionAxes(inShape,outShape){let result=[];for(let i=0;i<outShape.length;i++){let inDim=inShape[inShape.length-i-1],outAxis=outShape.length-i-1,outDim=outShape[outAxis];(inDim==null||inDim===1&&outDim>1)&&result.unshift(outAxis)}return result}function assertAndGetBroadcastShape(shapeA,shapeB){let result=[],l=Math.max(shapeA.length,shapeB.length);for(let i=0;i<l;i++){let a=shapeA[shapeA.length-i-1];a==null&&(a=1);let b=shapeB[shapeB.length-i-1];if(b==null&&(b=1),a===1)result.unshift(b);else if(b===1)result.unshift(a);else if(a!==b){let errMsg= ` Operands could not be broadcast together with shapes $ { shapeA } and $ { shapeB } . ` ;throw Error(errMsg)}else result.unshift(a)}return result}function equal_(a,b){let $ a=convertToTensor(a,"a","equal"), $ b=convertToTensor(b,"b","equal");[ $ a, $ b]=makeTypesMatch( $ a, $ b),assertAndGetBroadcastShape( $ a.shape, $ b.shape);let inputs={a: $ a,b: $ b};return ENGINE.runKernel(Equal,inputs)}var equal=op({equal_});function where_(condition,a,b){let $ a=convertToTensor(a,"a","where"), $ b=convertToTensor(b,"b","where"), $ condition=convertToTensor(condition,"condition","where","bool"),broadcastShape=assertAndGetBroadcastShape( $ a.shape, $ b.shape), $ broadcastedA=broadcastTo( $ a,broadcastShape), $ broadcastedB=broadcastTo( $ b,broadcastShape); $ condition.rank===1&&assert( $ condition.shape[0]=== $ a.shape[0],()=>"The first dimension of ` a ` must match the size of ` condition ` ."), $ conditi
rank $ { $x . rank } . ` ),assert(isInt(depthRadius),()=> ` Error in localResponseNormalization : depthRadius must be an integer but got depthRadius $ { depthRadius } . ` );let x4D= $ x,reshapedTo4D=!1; $ x.rank===3&&(reshapedTo4D=!0,x4D=reshape( $ x,[1, $ x.shape[0], $ x.shape[1], $ x.shape[2]]));let inputs={x:x4D},attrs={depthRadius,bias,alpha,beta},res=ENGINE.runKernel(LRN,inputs,attrs);return reshapedTo4D?reshape(res,[res.shape[1],res.shape[2],res.shape[3]]):res}var localResponseNormalization=op({localResponseNormalization_});function log_(x){let inputs={x:convertToTensor(x,"x","log")};return ENGINE.runKernel(Log,inputs)}var log2=op({log_});function log1p_(x){let inputs={x:convertToTensor(x,"x","log1p")};return ENGINE.runKernel(Log1p,inputs)}var log1p=op({log1p_});function grad(f){return assert(isFunction(f),()=>"The f passed in grad(f) must be a function"),(x,dy)=>{let $ x=convertToTensor(x,"x","tf.grad","string_or_numeric"), $ dy=dy!=null?convertToTensor(dy,"dy","tf.grad"):null;return ENGINE.tidy(()=>{let{value,grads:grads2}=ENGINE.gradients(()=>f( $ x),[ $ x], $ dy);return $ dy!=null&&assertShapesMatch(value.shape, $ dy.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),checkGrads(grads2),grads2[0]})}}function grads(f){return assert(isFunction(f),()=>"The f passed in grads(f) must be a function"),(args,dy)=>{assert(Array.isArray(args),()=>"The args passed in grads(f)(args) must be an array of ` Tensor ` s or ` TensorLike ` s");let $ args=convertToTensorArray(args,"args","tf.grads","string_or_numeric"), $ dy=dy!=null?convertToTensor(dy,"dy","tf.grads"):null;return ENGINE.tidy(()=>{let{value,grads:grads2}=ENGINE.gradients(()=>f(... $ args), $ args, $ dy);return $ dy!=null&&assertShapesMatch(value.shape, $ dy.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),checkGrads(grads2),grads2})}}function valueAndGrad(f){return assert(isFunction(f),()=>"The f passed in valueAndGrad(f) must be a function"),(x,dy)=>{assert(x instanceof Tensor,()=>"The x passed in valueAndGrad(f)(x) must be a tensor"),assert(dy==null||dy instanceof Tensor,()=>"The dy passed in valueAndGrad(f)(x, dy) must be a tensor");let{grads:grads2,value}=ENGINE.gradients(()=>f(x),[x],dy);return checkGrads(grads2),{grad:grads2[0],value}}}function valueAndGrads(f){return assert(isFunction(f),()=>"The f passed in valueAndGrads(f) must be a function"),(args,dy)=>{assert(Array.isArray(args)&&args.every(arg=>arg instanceof Tensor),()=>"The args passed in valueAndGrads(f)(args) must be array of tensors"),assert(dy==null||dy instanceof Tensor,()=>"The dy passed in valueAndGrads(f)(args, dy) must be a tensor");let res=ENGINE.gradients(()=>f(...args),args,dy);return dy!=null&&assertShapesMatch(res.value.shape,dy.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),checkGrads(res.grads),res}}function variableGrads(f,varList){assert(isFunction(f),()=>"The f passed in variableGrads(f) must be a function"),assert(varList==null||Array.isArray(varList)&&varList.every(v=>v instanceof Variable),()=>"The varList passed in variableGrads(f, varList) must be an array of variables");let specifiedVarList=varList!=null;if(!specifiedVarList){varList=[];for(let varName in ENGINE.registeredVariables)varList.push(ENGINE.registeredVariables[varName])}let specifiedNonTrainable=specifiedVarList?varList.filter(variable2=>!variable2.trainable):null,originalVarCount=varList.length;varList=varList.filter(variable2=>variable2.trainable),assert(varList.length>0,()=> ` variableGrads ( ) expects at least one of the input variables to be trainable , but none of the $ { originalVarCount } variables is trainable . ` );let allowNoGradients=!0,{value,grads:grads2}=ENGINE.gradients(f,varList,null,allowNoGradients);assert(grads2.some(g=>g!=null),()=>"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."),assert(value.rank===0,()=> ` The f passed in variableGrads ( f ) must return a sc
the f you passed encloses all operations that lead from x to y . ` )}function neg_(x){let inputs={x:convertToTensor(x,"x","neg")};return ENGINE.runKernel(Neg,inputs)}var neg=op({neg_});function softplus_(x){let inputs={x:convertToTensor(x,"x","softplus")};return ENGINE.runKernel(Softplus,inputs)}var softplus=op({softplus_});function logSigmoid_(x){let $ x=convertToTensor(x,"x","logSigmoid");return customGrad(x2=>({value:neg(softplus(neg(x2))),gradFunc:dy=>mul(dy,sigmoid(neg(x2)))}))( $ x)}var logSigmoid=op({logSigmoid_});function max_(x,axis=null,keepDims=!1){let inputs={x:convertToTensor(x,"x","max")},attrs={reductionIndices:axis,keepDims};return ENGINE.runKernel(Max,inputs,attrs)}var max=op({max_});function sub_(a,b){let $ a=convertToTensor(a,"a","sub"), $ b=convertToTensor(b,"b","sub");[ $ a, $ b]=makeTypesMatch( $ a, $ b);let inputs={a: $ a,b: $ b};return ENGINE.runKernel(Sub,inputs)}var sub=op({sub_});function sum_(x,axis=null,keepDims=!1){let $ x=convertToTensor(x,"x","sum"); $ x.dtype==="bool"&&( $ x=cast( $ x,"int32"));let inputs={x: $ x},attrs={axis,keepDims};return ENGINE.runKernel(Sum,inputs,attrs)}var sum2=op({sum_});function logSoftmax_(logits,axis=-1){let $ logits=convertToTensor(logits,"logits","logSoftmax");if(axis===-1&&(axis= $ logits.rank-1),axis!== $ logits.rank-1)throw Error( ` Log Softmax along a non - last dimension is not yet supported . Logits was rank $ { $logits . rank } and axis was $ { axis } ` );return customGrad((logits2,save)=>{let keepDims=!0,xMax=max(logits2,axis,!0),shifted=sub(logits2,xMax),value=sub(cast(shifted,"float32"),log2(sum2(exp(shifted),axis,keepDims)));return save([value]),{value,gradFunc:(dy,saved)=>{let[value2]=saved,keepDims2=!0,softmax6=exp(value2);return sub(dy,mul(sum2(dy,axis,keepDims2),softmax6))}}})( $ logits)}var logSoftmax=op({logSoftmax_});function axesAreInnerMostDims(axes,rank){for(let i=0;i<axes.length;++i)if(axes[axes.length-i-1]!==rank-1-i)return!1;return!0}function combineLocations(outputLoc,reduceLoc,axes){let rank=outputLoc.length+reduceLoc.length,loc=[],outIdx=0,reduceIdx=0;for(let dim=0;dim<rank;dim++)axes.indexOf(dim)===-1?loc.push(outputLoc[outIdx++]):loc.push(reduceLoc[reduceIdx++]);return loc}function computeOutAndReduceShapes(aShape,axes){let outShape=[],rank=aShape.length;for(let dim=0;dim<rank;dim++)axes.indexOf(dim)===-1&&outShape.push(aShape[dim]);let reduceShape=axes.map(dim=>aShape[dim]);return[outShape,reduceShape]}function expandShapeToKeepDim(shape,axes){let reduceSubShape=axes.map(x=>1);return combineLocations(shape,reduceSubShape,axes)}function assertAxesAreInnerMostDims(msg,axes,rank){assert(axesAreInnerMostDims(axes,rank),()=> ` $ { msg } supports only inner - most axes for now . Got axes $ { axes } and rank - $ { rank } input . ` )}function getAxesPermutation(axes,rank){if(axesAreInnerMostDims(axes,rank))return null;let result=[];for(let i=0;i<rank;++i)axes.indexOf(i)===-1&&result.push(i);return axes.forEach(axis=>result.push(axis)),result}function getUndoAxesPermutation(axes){return axes.map((axis,i)=>[i,axis]).sort((a,b)=>a[1]-b[1]).map(x=>x[0])}function getInnerMostAxes(numAxes,rank){let res=[];for(let i=rank-numAxes;i<rank;++i)res.push(i);return res}function logSumExp_(x,axis=null,keepDims=!1){let $ x=convertToTensor(x,"x","logSumExp"),axes=parseAxisParam(axis, $ x.shape),xMax=max( $ x,axes,!0),a=sub( $ x,xMax),b=exp(a),c=sum2(b,axes),d=log2(c),res=add2(reshape(xMax,d.shape),d);if(keepDims){let newShape=expandShapeToKeepDim(res.shape,axes);return reshape(res,newShape)}return res}var logSumExp=op({logSumExp_});function logicalAnd_(a,b){let $ a=convertToTensor(a,"a","logicalAnd","bool"), $ b=convertToTensor(b,"b","logicalAnd","bool");assertAndGetBroadcastShape( $ a.shape, $ b.shape);let inputs={a: $ a,b: $ b};return ENGINE.runKernel(LogicalAnd,inputs)}var logicalAnd=op({logicalAnd_});function logicalNot_(x){let inputs={x:convertToTensor(x,"x","logicalNot","bool")};return ENGINE.runKernel(LogicalNot,inputs)}var logicalNot=op({logicalNot_});function logicalOr_(a,b){let $ a=convertToTensor(a,"a","logicalOr","bool"), $ b=convertToTensor(b,"b","logicalOr","bool");assertAndGetBroadcastShape( $ a.shape, $ b.shape);let inputs={a:
$ { xRank } ) . ` );if(axis<batchDims)throw new Error( ` batchDims ( $ { batchDims } ) must be less than or equal to axis ( $ { axis } ) . ` );for(let i=0;i<batchDims;++i)if(x.shape[i]!==indices.shape[i])throw new Error( ` x . shape [ $ { i } ] : $ { x . shape [ i ] } should be equal to indices . shape [ $ { i } ] : $ { indices . shape [ i ] } . ` );let dimSize=x.shape[axis],outputShape=[],batchSize=1,outerSize=1,sliceSize=1;for(let i=0;i<batchDims;++i)outputShape.push(x.shape[i]),batchSize*=x.shape[i];for(let i=batchDims;i<axis;i++)outputShape.push(x.shape[i]),outerSize*=x.shape[i];for(let i=batchDims;i<indicesRank;i++)outputShape.push(indices.shape[i]);for(let i=axis+1;i<xRank;i++)outputShape.push(x.shape[i]),sliceSize*=x.shape[i];return{batchSize,sliceSize,outerSize,dimSize,outputShape}}function castTensor(x,dtype,backend22){if(dtype==="complex64"){if(x.dtype==="complex64")return x.clone();let zerosTensor=zeros(x.shape),floatX=cast(x,"float32"),result=backend22.complex(floatX,zerosTensor);return zerosTensor.dispose(),floatX.dispose(),result}if(!hasEncodingLoss(x.dtype,dtype))return ENGINE.makeTensorFromDataId(x.dataId,x.shape,dtype);if(x.dtype==="complex64"){let real4=backend22.real(x),result=cast(real4,dtype);return real4.dispose(),result}if(dtype==="int32")return backend22.int(x);if(dtype==="bool"){let zero=scalar(0,x.dtype),result=backend22.notEqual(x,zero);return zero.dispose(),result}else throw new Error( ` Error in Cast : failed to cast $ { x . dtype } to $ { dtype } ` )}function reshapeTensor(x,shape){return ENGINE.makeTensorFromDataId(x.dataId,shape,x.dtype)}function fromUint8ToStringArray(vals){try{return vals.map(val=>decodeString(val))}catch(err){throw new Error( ` Failed to decode encoded string bytes into utf - 8 , error : $ { err } ` )}}function fromStringArrayToUint8(strings){return strings.map(s=>encodeString(s))}var kernel_impls_exports={};__export2(kernel_impls_exports,{nonMaxSuppressionV3Impl:()=>nonMaxSuppressionV3Impl,nonMaxSuppressionV4Impl:()=>nonMaxSuppressionV4Impl,nonMaxSuppressionV5Impl:()=>nonMaxSuppressionV5Impl,whereImpl:()=>whereImpl});var absGradConfig={kernelName:Abs,inputsToSave:["x"],gradFunc:(dy,saved)=>{let[x]=saved;return{x:()=>mul(dy,step(cast(x,"float32"),-1))}}},acosGradConfig={kernelName:Acos,inputsToSave:["x"],gradFunc:(dy,saved)=>{let[x]=saved;return{x:()=>{let a=square(cast(x,"float32")),b=sqrt(sub(scalar(1),a));return neg(div(dy,b))}}}},acoshGradConfig={kernelName:Acosh,inputsToSave:["x"],gradFunc:(dy,saved)=>{let[x]=saved;return{x:()=>{let a=sqrt(sub(square(cast(x,"float32")),1));return div(dy,a)}}}},addGradConfig={kernelName:Add,inputsToSave:["a","b"],gradFunc:(dy,saved)=>{let[a,b]=saved,outShape=assertAndGetBroadcastShape(a.shape,b.shape);return{a:()=>{let res=dy,reduceAxes=getReductionAxes(a.shape,outShape);return reduceAxes.length>0&&(res=sum2(res,reduceAxes)),reshape(res,a.shape)},b:()=>{let res=dy,reduceAxes=getReductionAxes(b.shape,outShape);return reduceAxes.length>0&&(res=sum2(res,reduceAxes)),reshape(res,b.shape)}}}},addNGradConfig={kernelName:AddN,saveAllInputs:!0,gradFunc:(dy,saved)=>{let ders={};return saved.forEach((_,i)=>{ders[i]=()=>dy.clone()}),ders}},argMaxGradConfig={kernelName:ArgMax,inputsToSave:["x"],gradFunc:(dy,saved)=>{let[x]=saved;return{x:()=>zerosLike(x)}}},argMinGradConfig={kernelName:ArgMin,inputsToSave:["x"],gradFunc:(dy,saved)=>{let[x]=saved;return{x:()=>zerosLike(x)}}},asinGradConfig={kernelName:Asin,inputsToSave:["x"],gradFunc:(dy,saved)=>{let[x]=saved;return{x:()=>div(dy,sqrt(sub(scalar(1),square(cast(x,"float32")))))}}},asinhGradConfig={kernelName:Asinh,inputsToSave:["x"],gradFunc:(dy,saved)=>{let[x]=saved;return{x:()=>{let a=sqrt(add2(scalar(1),square(cast(x,"float32"))));return div(dy,a)}}}},atan2GradConfig={kernelName:Atan2,inputsToSave:["a","b"],gradFunc:(dy,saved)=>{let[a,b]=saved,outShape=assertAndGetBroadcastShape(a.shape,b.shape);return{a:()=>{let d=add2(square(a),square(b)),res=mul(dy,div(b,d)),reduceAxes=getReductionAxes(a.shape,outShape);return reduceAxes.length>0&&(res=sum2(res,reduceAxes)),reshape(res,a.shape)},b:()=>{let d=add2(square(a),square(b)),res=neg(mul(dy,div(a,d))),reduceAxes=getReductionAxes
2020-11-17 23:42:44 +01:00
=== === === === === === === === === =
Hi there \ u { 1 F44B } . Looks like you are running TensorFlow . js in Node . js . To speed things up dramatically , install our node backend , which binds to TensorFlow C ++ , by running npm i @ tensorflow / tfjs - node , or npm i @ tensorflow / tfjs - node - gpu if you have CUDA . Then call require ( '@tensorflow/tfjs-node' ) ; ( - gpu suffix for CUDA ) at the start of your program . Visit https : //github.com/tensorflow/tfjs-node for more details.
2021-01-13 17:14:23 +01:00
=== === === === === === === === === = ` ));let dataId={};return this.data.set(dataId,{values,dtype,refCount:1}),dataId}makeTensorInfo(shape,dtype,values){let outId;if(dtype==="string"&&values!=null&&values.length>0&&util_exports.isString(values[0])){let encodedValues=values.map(d=>util_exports.encodeString(d));outId=this.write(encodedValues,shape,dtype)}else outId=this.write(values,shape,dtype);return{dataId:outId,shape,dtype}}incRef(dataId){let tensorData=this.data.get(dataId);tensorData.refCount++}decRef(dataId){if(this.data.has(dataId)){let tensorData=this.data.get(dataId);tensorData.refCount--}}move(dataId,values,shape,dtype){this.data.set(dataId,{values,dtype,refCount:1})}numDataIds(){return this.data.numDataIds()}async read(dataId){return this.readSync(dataId)}readSync(dataId){let{dtype,complexTensorInfos}=this.data.get(dataId);if(dtype==="complex64"){let realValues=this.readSync(complexTensorInfos.real.dataId),imagValues=this.readSync(complexTensorInfos.imag.dataId);return backend_util_exports.mergeRealAndImagArrays(realValues,imagValues)}return this.data.get(dataId).values}bufferSync(t){let data2=this.readSync(t.dataId),decodedData=data2;if(t.dtype==="string")try{decodedData=data2.map(d=>util_exports.decodeString(d))}catch(_a){throw new Error("Failed to decode encoded string bytes into utf-8")}return buffer(t.shape,t.dtype,decodedData)}makeOutput(values,shape,dtype){let dataId=this.write(values,shape,dtype);return engine().makeTensorFromDataId(dataId,shape,dtype,this)}disposeData(dataId){if(this.data.has(dataId)){let{complexTensorInfos}=this.data.get(dataId);complexTensorInfos!=null&&(this.disposeData(complexTensorInfos.real.dataId),this.disposeData(complexTensorInfos.imag.dataId)),this.data.delete(dataId)}}disposeIntermediateTensorInfo(tensorInfo){let dataId=tensorInfo.dataId;if(this.data.has(dataId)){let tensorData=this.data.get(dataId);tensorData.refCount--,tensorData.refCount<1&&this.disposeData(dataId)}}async time(f){let start=util_exports.now();return f(),{kernelMs:util_exports.now()-start}}memory(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}}where(condition){assertNotComplex([condition],"where");let condVals=this.readSync(condition.dataId);return whereImpl2(condition.shape,condVals)}dispose(){}floatPrecision(){return 32}epsilon(){return super.epsilon()}},shared_exports={};__export2(shared_exports,{addImpl:()=>addImpl,bincountImpl:()=>bincountImpl,bincountReduceImpl:()=>bincountReduceImpl,ceilImpl:()=>ceilImpl,concatImpl:()=>concatImpl,expImpl:()=>expImpl,expm1Impl:()=>expm1Impl,floorImpl:()=>floorImpl,gatherV2Impl:()=>gatherV2Impl,greaterImpl:()=>greaterImpl,lessImpl:()=>lessImpl,linSpaceImpl:()=>linSpaceImpl,logImpl:()=>logImpl,maxImpl:()=>maxImpl,maximumImpl:()=>maximumImpl,minimumImpl:()=>minimumImpl,multiplyImpl:()=>multiplyImpl,negImpl:()=>negImpl,notEqualImpl:()=>notEqualImpl,prodImpl:()=>prodImpl,rangeImpl:()=>rangeImpl,rsqrtImpl:()=>rsqrtImpl,simpleAbsImpl:()=>simpleAbsImpl,sliceImpl:()=>sliceImpl,squaredDifferenceImpl:()=>squaredDifferenceImpl,stridedSliceImpl:()=>stridedSliceImpl,subImpl:()=>subImpl,tileImpl:()=>tileImpl,topKImpl:()=>topKImpl,transposeImpl:()=>transposeImpl,uniqueImpl:()=>uniqueImpl});function simpleAbsImpl(vals){let resultValues=new Float32Array(vals.length);for(let i=0;i<vals.length;++i)resultValues[i]=Math.abs(vals[i]);return resultValues}var abs2=args=>{let{x}=args.inputs,cpuBackend=args.backend;assertNotComplex(x,"abs");let resultValues=new Float32Array(util_exports.sizeFromShape(x.shape)),values=cpuBackend.data.get(x.dataId).values;return resultValues=simpleAbsImpl(values),cpuBackend.makeOutput(resultValues,x.shape,"float32")},absConfig={kernelName:Abs,backendName:"cpu",kernelFunc:abs2};function createSimpleBinaryKernelImpl(op2){return(aShape,bShape,aVals,bVals,dtype)=>{let newShape=backend_util_exports.assertAndGetBroadcastShape(aShape,bShape),resultRank=newShape.length,resultStrides=util_exports.computeStrides(newShape),resultSize=util_exports.sizeFromShape(newShape),result=util
` ),pad3=shaderLines.length.toString().length+2,linesWithLineNumbers=shaderLines.map((line,lineNumber2)=>util_exports.rightPad((lineNumber2+1).toString(),pad3)+line),maxLineLength=0;for(let i=0;i<linesWithLineNumbers.length;i++)maxLineLength=Math.max(linesWithLineNumbers[i].length,maxLineLength);let beforeErrorLines=linesWithLineNumbers.slice(0,lineNumber-1),errorLine=linesWithLineNumbers.slice(lineNumber-1,lineNumber),afterErrorLines=linesWithLineNumbers.slice(lineNumber);console.log(beforeErrorLines.join( `
` )),console.log(shaderInfoLog.split( `
` )[0]),console.log( ` % c $ { util _exports . rightPad ( errorLine [ 0 ] , maxLineLength ) } ` ,"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(afterErrorLines.join( `
` ))}function createProgram(gl){return throwIfNull(gl,()=>gl.createProgram(),"Unable to create WebGLProgram.")}function linkProgram(gl,program){if(callAndCheck(gl,()=>gl.linkProgram(program)),gl.getProgramParameter(program,gl.LINK_STATUS)===!1)throw console.log(gl.getProgramInfoLog(program)),new Error("Failed to link vertex and fragment shaders.")}function validateProgram(gl,program){if(callAndCheck(gl,()=>gl.validateProgram(program)),gl.getProgramParameter(program,gl.VALIDATE_STATUS)===!1)throw console.log(gl.getProgramInfoLog(program)),new Error("Shader program validation failed.")}function createStaticVertexBuffer(gl,data2){let buffer2=throwIfNull(gl,()=>gl.createBuffer(),"Unable to create WebGLBuffer");return callAndCheck(gl,()=>gl.bindBuffer(gl.ARRAY_BUFFER,buffer2)),callAndCheck(gl,()=>gl.bufferData(gl.ARRAY_BUFFER,data2,gl.STATIC_DRAW)),buffer2}function createStaticIndexBuffer(gl,data2){let buffer2=throwIfNull(gl,()=>gl.createBuffer(),"Unable to create WebGLBuffer");return callAndCheck(gl,()=>gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,buffer2)),callAndCheck(gl,()=>gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,data2,gl.STATIC_DRAW)),buffer2}function getNumChannels(){return env().getNumber("WEBGL_VERSION")===2?1:4}function createTexture(gl){return throwIfNull(gl,()=>gl.createTexture(),"Unable to create WebGLTexture.")}function validateTextureSize(width,height){let maxTextureSize=env().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(width<=0||height<=0){let requested= ` [ $ { width } x$ { height } ] ` ;throw new Error("Requested texture size "+requested+" is invalid.")}if(width>maxTextureSize||height>maxTextureSize){let requested= ` [ $ { width } x$ { height } ] ` ,max6= ` [ $ { maxTextureSize } x$ { maxTextureSize } ] ` ;throw new Error("Requested texture size "+requested+" greater than WebGL maximum on this browser / GPU "+max6+".")}}function createFramebuffer(gl){return throwIfNull(gl,()=>gl.createFramebuffer(),"Unable to create WebGLFramebuffer.")}function bindVertexBufferToProgramAttribute(gl,program,attribute,buffer2,arrayEntriesPerItem,itemStrideInBytes,itemOffsetInBytes){let loc=gl.getAttribLocation(program,attribute);return loc===-1?!1:(callAndCheck(gl,()=>gl.bindBuffer(gl.ARRAY_BUFFER,buffer2)),callAndCheck(gl,()=>gl.vertexAttribPointer(loc,arrayEntriesPerItem,gl.FLOAT,!1,itemStrideInBytes,itemOffsetInBytes)),callAndCheck(gl,()=>gl.enableVertexAttribArray(loc)),!0)}function bindTextureUnit(gl,texture,textureUnit){validateTextureUnit(gl,textureUnit),callAndCheck(gl,()=>gl.activeTexture(gl.TEXTURE0+textureUnit)),callAndCheck(gl,()=>gl.bindTexture(gl.TEXTURE_2D,texture))}function unbindTextureUnit(gl,textureUnit){validateTextureUnit(gl,textureUnit),callAndCheck(gl,()=>gl.activeTexture(gl.TEXTURE0+textureUnit)),callAndCheck(gl,()=>gl.bindTexture(gl.TEXTURE_2D,null))}function getProgramUniformLocationOrThrow(gl,program,uniformName){return throwIfNull(gl,()=>gl.getUniformLocation(program,uniformName),'uniform "'+uniformName+'" not present in program.')}function getProgramUniformLocation(gl,program,uniformName){return gl.getUniformLocation(program,uniformName)}function bindTextureToProgramUniformSampler(gl,texture,uniformSamplerLocation,textureUnit){callAndCheck(gl,()=>bindTextureUnit(gl,texture,textureUnit)),callAndCheck(gl,()=>gl.uniform1i(uniformSamplerLocation,textureUnit))}function bindCanvasToFramebuffer(gl){callAndCheck(gl,()=>gl.bindFramebuffer(gl.FRAMEBUFFER,null)),callAndCheck(gl,()=>gl.viewport(0,0,gl.canvas.width,gl.canvas.height)),callAndCheck(gl,()=>gl.scissor(0,0,gl.canvas.width,gl.canvas.height))}function bindColorTextureToFramebuffer(gl,texture,framebuffer){callAndCheck(gl,()=>gl.bindFramebuffer(gl.FRAMEBUFFER,framebuffer)),callAndCheck(gl,()=>gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,texture,0))}function unbindColorTextureFromFramebuffer(gl,framebuffer){callAndCheck(gl,()=>gl.bindFramebuffer(gl.FRAMEBUFFER,framebuffer)),callAndCheck(gl,()=>gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,null,0))}function validateFramebuffer(gl){let status=gl.checkFramebufferStatus(gl.FRAMEBUFFER);if(status!==gl.FRAM
2020-11-16 21:51:46 +01:00
bool isnan _custom ( float val ) {
return ( val > 0.0 || val < 0.0 ) ? false : val != 0.0 ;
}
bvec4 isnan _custom ( vec4 val ) {
return bvec4 ( isnan _custom ( val . x ) ,
isnan _custom ( val . y ) , isnan _custom ( val . z ) , isnan _custom ( val . w ) ) ;
}
# define isnan ( value ) isnan _custom ( value )
2021-01-13 17:14:23 +01:00
` ,defineSpecialInf="",defineRound= `
2020-11-16 21:51:46 +01:00
# define round ( value ) newRound ( value )
int newRound ( float value ) {
return int ( floor ( value + 0.5 ) ) ;
}
ivec4 newRound ( vec4 value ) {
return ivec4 ( floor ( value + vec4 ( 0.5 ) ) ) ;
}
2021-01-13 17:14:23 +01:00
` ):(version142="",attribute="attribute",varyingVs="varying",varyingFs="varying",texture2D="texture2D",output="gl_FragColor",defineOutput="",defineSpecialNaN= `
2020-11-16 21:51:46 +01:00
# define isnan ( value ) isnan _custom ( value )
bool isnan _custom ( float val ) {
return ( val > 0. || val < 1. || val == 0. ) ? false : true ;
}
bvec4 isnan _custom ( vec4 val ) {
return bvec4 ( isnan ( val . x ) , isnan ( val . y ) , isnan ( val . z ) , isnan ( val . w ) ) ;
}
2021-01-13 17:14:23 +01:00
` ,defineSpecialInf= `
2020-11-16 21:51:46 +01:00
uniform float INFINITY ;
bool isinf ( float val ) {
return abs ( val ) == INFINITY ;
}
bvec4 isinf ( vec4 val ) {
return equal ( abs ( val ) , vec4 ( INFINITY ) ) ;
}
2021-01-13 17:14:23 +01:00
` ,defineRound= `
2020-11-16 21:51:46 +01:00
int round ( float value ) {
return int ( floor ( value + 0.5 ) ) ;
}
ivec4 round ( vec4 value ) {
return ivec4 ( floor ( value + vec4 ( 0.5 ) ) ) ;
}
2021-01-13 17:14:23 +01:00
` ),{version:version142,attribute,varyingVs,varyingFs,texture2D,output,defineOutput,defineSpecialNaN,defineSpecialInf,defineRound}}function getLogicalCoordinatesFromFlatIndex(coords2,shape,index="index"){let strides=util_exports.computeStrides(shape);return strides.map((stride,i)=>{let line1= ` int $ { coords2 [ i ] } = $ { index } / $ { stride } ` ,line2=i===strides.length-1? ` int $ { coords2 [ i + 1 ] } = $ { index } - $ { coords2 [ i ] } * $ { stride } ` : ` index -= $ { coords2 [ i ] } * $ { stride } ` ;return ` $ { line1 } ; $ { line2 } ; ` }).join("")}function getFlatIndexFrom3D(shape){let strides=util_exports.computeStrides(shape).map(d=>d.toString());return `
2020-11-16 21:51:46 +01:00
int getFlatIndex ( ivec3 coords ) {
2021-01-13 17:14:23 +01:00
return coords . x * $ { strides [ 0 ] } + coords . y * $ { strides [ 1 ] } + coords . z ;
2020-11-10 02:13:38 +01:00
}
2021-01-13 17:14:23 +01:00
` }var ENCODE_FLOAT_SNIPPET= `
2020-11-16 21:51:46 +01:00
const float FLOAT _MAX = 1.70141184 e38 ;
const float FLOAT _MIN = 1.17549435 e - 38 ;
2020-11-08 18:32:31 +01:00
2020-11-16 21:51:46 +01:00
lowp vec4 encode _float ( highp float v ) {
if ( isnan ( v ) ) {
return vec4 ( 255 , 255 , 255 , 255 ) ;
2020-11-10 15:54:07 +01:00
}
2020-11-08 18:32:31 +01:00
2020-11-16 21:51:46 +01:00
highp float av = abs ( v ) ;
if ( av < FLOAT _MIN ) {
return vec4 ( 0.0 , 0.0 , 0.0 , 0.0 ) ;
} else if ( v > FLOAT _MAX ) {
return vec4 ( 0.0 , 0.0 , 128.0 , 127.0 ) / 255.0 ;
} else if ( v < - FLOAT _MAX ) {
return vec4 ( 0.0 , 0.0 , 128.0 , 255.0 ) / 255.0 ;
2020-11-08 18:32:31 +01:00
}
2020-11-16 21:51:46 +01:00
highp vec4 c = vec4 ( 0 , 0 , 0 , 0 ) ;
highp float e = floor ( log2 ( av ) ) ;
highp float m = exp2 ( fract ( log2 ( av ) ) ) - 1.0 ;
c [ 2 ] = floor ( 128.0 * m ) ;
m -= c [ 2 ] / 128.0 ;
c [ 1 ] = floor ( 32768.0 * m ) ;
m -= c [ 1 ] / 32768.0 ;
c [ 0 ] = floor ( 8388608.0 * m ) ;
highp float ebias = e + 127.0 ;
c [ 3 ] = floor ( ebias / 2.0 ) ;
ebias -= c [ 3 ] * 2.0 ;
c [ 2 ] += floor ( ebias ) * 128.0 ;
c [ 3 ] += 128.0 * step ( 0.0 , - v ) ;
return c / 255.0 ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ,DecodeMatrixProgram=class{constructor(outputShape){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outPackingScheme=PackingScheme.DENSE;let texShape=getDenseTexShape(outputShape),glsl=getGlslDifferences();this.outputShape=outputShape,this.userCode= `
2021-01-03 16:41:56 +01:00
ivec3 outCoordsFromFlatIndex ( int index ) {
2021-01-13 17:14:23 +01:00
$ { getLogicalCoordinatesFromFlatIndex ( [ "r" , "c" , "d" ] , outputShape ) }
2021-01-03 16:41:56 +01:00
return ivec3 ( r , c , d ) ;
}
void main ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { texShape [ 0 ] } , $ { texShape [ 1 ] } ) ) ;
int index = 4 * ( resTexRC . x * $ { texShape [ 1 ] } + resTexRC . y ) ;
2021-01-03 16:41:56 +01:00
vec4 result = vec4 ( 0. ) ;
for ( int i = 0 ; i < 4 ; i ++ ) {
int flatIndex = index + i ;
ivec3 rc = outCoordsFromFlatIndex ( flatIndex ) ;
result [ i ] = getA ( rc . x , rc . y , rc . z ) ;
}
2021-01-13 17:14:23 +01:00
$ { glsl . output } = result ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }},DecodeMatrixPackedProgram=class{constructor(outputShape){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=PackingScheme.DENSE;let texShape=getDenseTexShape(outputShape),glsl=getGlslDifferences();this.outputShape=outputShape,this.userCode= `
2021-01-03 16:41:56 +01:00
ivec3 outCoordsFromFlatIndex ( int index ) {
2021-01-13 17:14:23 +01:00
$ { getLogicalCoordinatesFromFlatIndex ( [ "r" , "c" , "d" ] , outputShape ) }
2021-01-03 16:41:56 +01:00
return ivec3 ( r , c , d ) ;
}
void main ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { texShape [ 0 ] } , $ { texShape [ 1 ] } ) ) ;
int index = 4 * ( resTexRC . x * $ { texShape [ 1 ] } + resTexRC . y ) ;
2021-01-03 16:41:56 +01:00
vec4 result = vec4 ( 0. ) ;
for ( int i = 0 ; i < 4 ; i ++ ) {
int flatIndex = index + i ;
ivec3 rc = outCoordsFromFlatIndex ( flatIndex ) ;
result [ i ] = getChannel ( getA ( rc . x , rc . y , rc . z ) , vec2 ( rc . y , rc . z ) ) ;
}
2021-01-13 17:14:23 +01:00
$ { glsl . output } = result ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }},EncodeFloatProgram=class{constructor(outputShape){this.variableNames=["A"],this.outTexUsage=TextureUsage.DOWNLOAD;let glsl=getGlslDifferences();this.outputShape=outputShape,this.userCode= `
$ { ENCODE _FLOAT _SNIPPET }
2021-01-03 16:41:56 +01:00
void main ( ) {
float x = getAAtOutCoords ( ) ;
2021-01-13 17:14:23 +01:00
$ { glsl . output } = encode _float ( x ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }},EncodeFloatPackedProgram=class{constructor(outputShape){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=TextureUsage.DOWNLOAD;let glsl=getGlslDifferences();this.outputShape=outputShape,this.userCode= `
$ { ENCODE _FLOAT _SNIPPET }
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
float x = getChannel ( getAAtOutCoords ( ) , vec2 ( coords . y , coords . z ) ) ;
2021-01-13 17:14:23 +01:00
$ { glsl . output } = encode _float ( x ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }},EncodeMatrixProgram=class{constructor(outputShape,texShape,inputIsUnsignedByte=!1){this.variableNames=["A"];let glsl=getGlslDifferences(),[height,width]=texShape;this.outputShape=outputShape;let output="result";inputIsUnsignedByte&&(output="floor(result * 255. + 0.5)"),this.userCode= `
$ { getFlatIndexFrom3D ( outputShape ) }
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
int flatIndex = getFlatIndex ( coords ) ;
int offset = imod ( flatIndex , 4 ) ;
flatIndex = idiv ( flatIndex , 4 , 1. ) ;
2021-01-13 17:14:23 +01:00
int r = flatIndex / $ { width } ;
int c = imod ( flatIndex , $ { width } ) ;
vec2 uv = ( vec2 ( c , r ) + halfCR ) / vec2 ( $ { width } . 0 , $ { height } . 0 ) ;
vec4 values = $ { glsl . texture2D } ( A , uv ) ;
2021-01-03 16:41:56 +01:00
float result ;
if ( offset == 0 ) {
result = values [ 0 ] ;
} else if ( offset == 1 ) {
result = values [ 1 ] ;
} else if ( offset == 2 ) {
result = values [ 2 ] ;
} else {
result = values [ 3 ] ;
}
2021-01-13 17:14:23 +01:00
$ { glsl . output } = vec4 ( $ { output } , 0. , 0. , 0. ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }},EncodeMatrixPackedProgram=class{constructor(outputShape,texShape,inputIsUnsignedByte=!1){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;let glsl=getGlslDifferences(),[height,width]=texShape;this.outputShape=outputShape;let mainLoop="",output="result";inputIsUnsignedByte&&(output="floor(result * 255. + 0.5)");for(let row=0;row<=1;row++)for(let col=0;col<=1;col++){let channel=row*2+col;mainLoop+= `
2021-01-03 16:41:56 +01:00
localCoords = coords ;
2021-01-13 17:14:23 +01:00
if ( localCoords [ 2 ] + $ { col } < $ { outputShape [ 2 ] } ) {
localCoords [ 2 ] += $ { col } ;
if ( localCoords [ 1 ] + $ { row } < $ { outputShape [ 1 ] } ) {
localCoords [ 1 ] += $ { row } ;
2021-01-03 16:41:56 +01:00
flatIndex = getFlatIndex ( localCoords ) ;
offset = imod ( flatIndex , 4 ) ;
flatIndex = idiv ( flatIndex , 4 , 1. ) ;
2021-01-13 17:14:23 +01:00
r = flatIndex / $ { width } ;
c = imod ( flatIndex , $ { width } ) ;
uv = ( vec2 ( c , r ) + halfCR ) / vec2 ( $ { width } . 0 , $ { height } . 0 ) ;
values = $ { glsl . texture2D } ( A , uv ) ;
2021-01-03 16:41:56 +01:00
if ( offset == 0 ) {
2021-01-13 17:14:23 +01:00
result [ $ { channel } ] = values [ 0 ] ;
2021-01-03 16:41:56 +01:00
} else if ( offset == 1 ) {
2021-01-13 17:14:23 +01:00
result [ $ { channel } ] = values [ 1 ] ;
2021-01-03 16:41:56 +01:00
} else if ( offset == 2 ) {
2021-01-13 17:14:23 +01:00
result [ $ { channel } ] = values [ 2 ] ;
2021-01-03 16:41:56 +01:00
} else {
2021-01-13 17:14:23 +01:00
result [ $ { channel } ] = values [ 3 ] ;
2021-01-03 16:41:56 +01:00
}
}
}
` }this.userCode= `
2021-01-13 17:14:23 +01:00
$ { getFlatIndexFrom3D ( outputShape ) }
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
int flatIndex , r , c , offset ;
ivec3 localCoords ;
vec2 uv ;
vec4 values ;
2021-01-13 17:14:23 +01:00
$ { mainLoop }
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
$ { glsl . output } = $ { output } ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }},gpgpu_util_exports={};__export2(gpgpu_util_exports,{bindVertexProgramAttributeStreams:()=>bindVertexProgramAttributeStreams,createBufferFromOutputTexture:()=>createBufferFromOutputTexture,createFloat16MatrixTexture:()=>createFloat16MatrixTexture,createFloat16PackedMatrixTexture:()=>createFloat16PackedMatrixTexture,createFloat32MatrixTexture:()=>createFloat32MatrixTexture,createIndexBuffer:()=>createIndexBuffer,createPackedMatrixTexture:()=>createPackedMatrixTexture,createUnsignedBytesMatrixTexture:()=>createUnsignedBytesMatrixTexture,createVertexBuffer:()=>createVertexBuffer,createVertexShader:()=>createVertexShader2,downloadByteEncodedFloatMatrixFromOutputTexture:()=>downloadByteEncodedFloatMatrixFromOutputTexture,downloadFloat32MatrixFromBuffer:()=>downloadFloat32MatrixFromBuffer,downloadMatrixFromPackedOutputTexture:()=>downloadMatrixFromPackedOutputTexture,downloadPackedMatrixFromBuffer:()=>downloadPackedMatrixFromBuffer,getInternalFormatForFloat16MatrixTexture:()=>getInternalFormatForFloat16MatrixTexture,getInternalFormatForFloat16PackedMatrixTexture:()=>getInternalFormatForFloat16PackedMatrixTexture,getInternalFormatForFloat32MatrixTexture:()=>getInternalFormatForFloat32MatrixTexture,getInternalFormatForPackedMatrixTexture:()=>getInternalFormatForPackedMatrixTexture,getInternalFormatForUnsignedBytesMatrixTexture:()=>getInternalFormatForUnsignedBytesMatrixTexture,uploadDenseMatrixToTexture:()=>uploadDenseMatrixToTexture,uploadPixelDataToTexture:()=>uploadPixelDataToTexture});function createVertexShader2(gl){let glsl=getGlslDifferences(),vertexShaderSource= ` $ { glsl . version }
2021-01-03 16:41:56 +01:00
precision highp float ;
2021-01-13 17:14:23 +01:00
$ { glsl . attribute } vec3 clipSpacePos ;
$ { glsl . attribute } vec2 uv ;
$ { glsl . varyingVs } vec2 resultUV ;
2021-01-03 16:41:56 +01:00
void main ( ) {
gl _Position = vec4 ( clipSpacePos , 1 ) ;
resultUV = uv ;
2021-01-13 17:14:23 +01:00
} ` ;return createVertexShader(gl,vertexShaderSource)}function createVertexBuffer(gl){let vertexArray=new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]);return createStaticVertexBuffer(gl,vertexArray)}function createIndexBuffer(gl){let triangleVertexIndices=new Uint16Array([0,1,2,2,1,3]);return createStaticIndexBuffer(gl,triangleVertexIndices)}function createAndConfigureTexture(gl,width,height,internalFormat,textureFormat,textureType){validateTextureSize(width,height);let texture=createTexture(gl),tex2d=gl.TEXTURE_2D;return callAndCheck(gl,()=>gl.bindTexture(tex2d,texture)),callAndCheck(gl,()=>gl.texParameteri(tex2d,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE)),callAndCheck(gl,()=>gl.texParameteri(tex2d,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE)),callAndCheck(gl,()=>gl.texParameteri(tex2d,gl.TEXTURE_MIN_FILTER,gl.NEAREST)),callAndCheck(gl,()=>gl.texParameteri(tex2d,gl.TEXTURE_MAG_FILTER,gl.NEAREST)),callAndCheck(gl,()=>gl.texImage2D(tex2d,0,internalFormat,width,height,0,textureFormat,textureType,null)),callAndCheck(gl,()=>gl.bindTexture(gl.TEXTURE_2D,null)),texture}function getInternalFormatForFloat32MatrixTexture(textureConfig){return textureConfig.internalFormatFloat}function createFloat32MatrixTexture(gl,rows,columns,textureConfig){let[width,height]=getUnpackedMatrixTextureShapeWidthHeight(rows,columns);return createAndConfigureTexture(gl,width,height,getInternalFormatForFloat32MatrixTexture(textureConfig),textureConfig.textureFormatFloat,gl.FLOAT)}function getInternalFormatForFloat16MatrixTexture(textureConfig){return textureConfig.internalFormatHalfFloat}function createFloat16MatrixTexture(gl,rows,columns,textureConfig){let[width,height]=getUnpackedMatrixTextureShapeWidthHeight(rows,columns);return createAndConfigureTexture(gl,width,height,getInternalFormatForFloat16MatrixTexture(textureConfig),textureConfig.textureFormatFloat,textureConfig.textureTypeHalfFloat)}function getInternalFormatForUnsignedBytesMatrixTexture(textureConfig){return textureConfig.downloadTextureFormat}function createUnsignedBytesMatrixTexture(gl,rows,columns,textureConfig){let[width,height]=getUnpackedMatrixTextureShapeWidthHeight(rows,columns);return createAndConfigureTexture(gl,width,height,getInternalFormatForUnsignedBytesMatrixTexture(textureConfig),gl.RGBA,gl.UNSIGNED_BYTE)}function getInternalFormatForPackedMatrixTexture(textureConfig){return textureConfig.internalFormatPackedFloat}function createPackedMatrixTexture(gl,rows,columns,textureConfig){let[width,height]=getPackedMatrixTextureShapeWidthHeight(rows,columns);return createAndConfigureTexture(gl,width,height,getInternalFormatForPackedMatrixTexture(textureConfig),gl.RGBA,gl.FLOAT)}function getInternalFormatForFloat16PackedMatrixTexture(textureConfig){return textureConfig.internalFormatPackedHalfFloat}function createFloat16PackedMatrixTexture(gl,rows,columns,textureConfig){let[width,height]=getPackedMatrixTextureShapeWidthHeight(rows,columns);return createAndConfigureTexture(gl,width,height,getInternalFormatForFloat16PackedMatrixTexture(textureConfig),gl.RGBA,textureConfig.textureTypeHalfFloat)}function bindVertexProgramAttributeStreams(gl,program,vertexBuffer){let posOffset=0,uvOffset=3*4,stride=3*4+2*4;return callAndCheck(gl,()=>gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuffer)),bindVertexBufferToProgramAttribute(gl,program,"clipSpacePos",vertexBuffer,3,stride,posOffset)&&bindVertexBufferToProgramAttribute(gl,program,"uv",vertexBuffer,2,stride,uvOffset)}function uploadDenseMatrixToTexture(gl,texture,width,height,data2,textureConfig){callAndCheck(gl,()=>gl.bindTexture(gl.TEXTURE_2D,texture));let dataForUpload,texelDataType,internalFormat;data2 instanceof Uint8Array?(dataForUpload=new Uint8Array(width*height*4),texelDataType=gl.UNSIGNED_BYTE,internalFormat=gl.RGBA):(dataForUpload=new Float32Array(width*height*4),texelDataType=gl.FLOAT,internalFormat=textureConfig.internalFormatPackedFloat),dataForUpload.set(data2),callAndCheck(gl,()=>gl.texImage2D(gl.TEXTURE_2D,0,internalFormat,width,height,0,gl.RGBA,texelDataType,dataForUpload)),callAndCheck(gl,()=>gl.bindTexture(gl.TEXTURE_2D,null))}func
` ),inputSamplingSnippet=inputsInfo.map(x=>getInputSamplingSnippet(x,outputShape,usesPackedTextures)).join( `
` ),outTexShape=outputShape.texShape,glsl=getGlslDifferences(),floatTextureSampleSnippet=getFloatTextureSampleSnippet(glsl),outputSamplingSnippet,floatTextureSetOutputSnippet,shaderPrefix=getShaderPrefix(glsl);return outputShape.isPacked?(outputSamplingSnippet=getPackedOutputSamplingSnippet(outputShape.logicalShape,outTexShape),floatTextureSetOutputSnippet=getFloatTextureSetRGBASnippet(glsl)):(outputSamplingSnippet=getOutputSamplingSnippet(outputShape.logicalShape,outTexShape),floatTextureSetOutputSnippet=getFloatTextureSetRSnippet(glsl)),usesPackedTextures&&(shaderPrefix+=SHADER_PACKED_PREFIX),[shaderPrefix,floatTextureSampleSnippet,floatTextureSetOutputSnippet,inputPrefixSnippet,outputSamplingSnippet,inputSamplingSnippet,userCode].join( `
` )}function getSamplerFromInInfo(inInfo){let shape=inInfo.shapeInfo.logicalShape;switch(shape.length){case 0:return getSamplerScalar(inInfo);case 1:return getSampler1D(inInfo);case 2:return getSampler2D(inInfo);case 3:return getSampler3D(inInfo);case 4:return getSampler4D(inInfo);case 5:return getSampler5D(inInfo);case 6:return getSampler6D(inInfo);default:throw new Error( ` $ { shape . length } - D input sampling is not yet supported ` )}}function getPackedSamplerFromInInfo(inInfo){switch(inInfo.shapeInfo.logicalShape.length){case 0:return getPackedSamplerScalar(inInfo);case 1:return getPackedSampler1D(inInfo);case 2:return getPackedSampler2D(inInfo);case 3:return getPackedSampler3D(inInfo);default:return getPackedSamplerND(inInfo)}}function getInputSamplingSnippet(inInfo,outShapeInfo,usesPackedTextures=!1){let res="";usesPackedTextures?res+=getPackedSamplerFromInInfo(inInfo):res+=getSamplerFromInInfo(inInfo);let inShape=inInfo.shapeInfo.logicalShape,outShape=outShapeInfo.logicalShape;return inShape.length<=outShape.length&&(usesPackedTextures?res+=getPackedSamplerAtOutputCoords(inInfo,outShapeInfo):res+=getSamplerAtOutputCoords(inInfo,outShapeInfo)),res}function getPackedOutputSamplingSnippet(outShape,outTexShape){switch(outShape.length){case 0:return getOutputScalarCoords();case 1:return getOutputPacked1DCoords(outShape,outTexShape);case 2:return getOutputPacked2DCoords(outShape,outTexShape);case 3:return getOutputPacked3DCoords(outShape,outTexShape);default:return getOutputPackedNDCoords(outShape,outTexShape)}}function getOutputSamplingSnippet(outShape,outTexShape){switch(outShape.length){case 0:return getOutputScalarCoords();case 1:return getOutput1DCoords(outShape,outTexShape);case 2:return getOutput2DCoords(outShape,outTexShape);case 3:return getOutput3DCoords(outShape,outTexShape);case 4:return getOutput4DCoords(outShape,outTexShape);case 5:return getOutput5DCoords(outShape,outTexShape);case 6:return getOutput6DCoords(outShape,outTexShape);default:throw new Error( ` $ { outShape . length } - D output sampling is not yet supported ` )}}function getFloatTextureSampleSnippet(glsl){return `
2020-11-16 21:51:46 +01:00
float sampleTexture ( sampler2D textureSampler , vec2 uv ) {
2021-01-13 17:14:23 +01:00
return $ { glsl . texture2D } ( textureSampler , uv ) . r ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getFloatTextureSetRSnippet(glsl){return `
2020-11-16 21:51:46 +01:00
void setOutput ( float val ) {
2021-01-13 17:14:23 +01:00
$ { glsl . output } = vec4 ( val , 0 , 0 , 0 ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getFloatTextureSetRGBASnippet(glsl){return `
2020-11-16 21:51:46 +01:00
void setOutput ( vec4 val ) {
2021-01-13 17:14:23 +01:00
$ { glsl . output } = val ;
2020-11-12 18:17:57 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getShaderPrefix(glsl){return ` $ { glsl . version }
2020-11-16 21:51:46 +01:00
precision highp float ;
precision highp int ;
precision highp sampler2D ;
2021-01-13 17:14:23 +01:00
$ { glsl . varyingFs } vec2 resultUV ;
$ { glsl . defineOutput }
2020-11-16 21:51:46 +01:00
const vec2 halfCR = vec2 ( 0.5 , 0.5 ) ;
struct ivec5
{
int x ;
int y ;
int z ;
int w ;
int u ;
} ;
struct ivec6
{
int x ;
int y ;
int z ;
int w ;
int u ;
int v ;
} ;
uniform float NAN ;
2021-01-13 17:14:23 +01:00
$ { glsl . defineSpecialNaN }
$ { glsl . defineSpecialInf }
$ { glsl . defineRound }
2020-11-08 18:32:31 +01:00
2020-11-16 21:51:46 +01:00
int imod ( int x , int y ) {
return x - y * ( x / y ) ;
2020-11-10 02:13:38 +01:00
}
2020-11-16 21:51:46 +01:00
int idiv ( int a , int b , float sign ) {
int res = a / b ;
int mod = imod ( a , b ) ;
if ( sign < 0. && mod != 0 ) {
res -= 1 ;
2020-11-12 18:58:55 +01:00
}
2020-11-16 21:51:46 +01:00
return res ;
2020-11-12 18:58:55 +01:00
}
2020-11-16 21:51:46 +01:00
//Based on the work of Dave Hoskins
//https://www.shadertoy.com/view/4djSRW
# define HASHSCALE1 443.8975
float random ( float seed ) {
vec2 p = resultUV * seed ;
vec3 p3 = fract ( vec3 ( p . xyx ) * HASHSCALE1 ) ;
p3 += dot ( p3 , p3 . yzx + 19.19 ) ;
return fract ( ( p3 . x + p3 . y ) * p3 . z ) ;
2020-11-08 18:32:31 +01:00
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { SAMPLE _1D _SNIPPET }
$ { SAMPLE _2D _SNIPPET }
$ { SAMPLE _3D _SNIPPET }
` }var SAMPLE_1D_SNIPPET= `
2020-11-16 21:51:46 +01:00
vec2 uvFromFlat ( int texNumR , int texNumC , int index ) {
int texR = index / texNumC ;
int texC = index - texR * texNumC ;
return ( vec2 ( texC , texR ) + halfCR ) / vec2 ( texNumC , texNumR ) ;
}
vec2 packedUVfrom1D ( int texNumR , int texNumC , int index ) {
int texelIndex = index / 2 ;
int texR = texelIndex / texNumC ;
int texC = texelIndex - texR * texNumC ;
return ( vec2 ( texC , texR ) + halfCR ) / vec2 ( texNumC , texNumR ) ;
}
2021-01-13 17:14:23 +01:00
` ,SAMPLE_2D_SNIPPET= `
2020-11-16 21:51:46 +01:00
vec2 packedUVfrom2D ( int texelsInLogicalRow , int texNumR ,
int texNumC , int row , int col ) {
int texelIndex = ( row / 2 ) * texelsInLogicalRow + ( col / 2 ) ;
int texR = texelIndex / texNumC ;
int texC = texelIndex - texR * texNumC ;
return ( vec2 ( texC , texR ) + halfCR ) / vec2 ( texNumC , texNumR ) ;
}
2021-01-13 17:14:23 +01:00
` ,SAMPLE_3D_SNIPPET= `
2020-11-16 21:51:46 +01:00
vec2 packedUVfrom3D ( int texNumR , int texNumC ,
int texelsInBatch , int texelsInLogicalRow , int b ,
int row , int col ) {
int index = b * texelsInBatch + ( row / 2 ) * texelsInLogicalRow + ( col / 2 ) ;
int texR = index / texNumC ;
int texC = index - texR * texNumC ;
return ( vec2 ( texC , texR ) + halfCR ) / vec2 ( texNumC , texNumR ) ;
}
2021-01-13 17:14:23 +01:00
` ,SHADER_PACKED_PREFIX= `
2020-11-16 21:51:46 +01:00
float getChannel ( vec4 frag , vec2 innerDims ) {
vec2 modCoord = mod ( innerDims , 2. ) ;
return modCoord . x == 0. ?
( modCoord . y == 0. ? frag . r : frag . g ) :
( modCoord . y == 0. ? frag . b : frag . a ) ;
2020-11-12 18:58:55 +01:00
}
2020-11-16 21:51:46 +01:00
float getChannel ( vec4 frag , int dim ) {
float modCoord = mod ( float ( dim ) , 2. ) ;
return modCoord == 0. ? frag . r : frag . g ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;function getOutputScalarCoords(){return `
2020-11-16 21:51:46 +01:00
int getOutputCoords ( ) {
2020-11-12 18:58:55 +01:00
return 0 ;
}
2021-01-13 17:14:23 +01:00
` }function getOutputPacked1DCoords(shape,texShape){let packedTexShape=[Math.ceil(texShape[0]/2),Math.ceil(texShape[1]/2)];return packedTexShape[0]===1? `
2020-11-16 21:51:46 +01:00
int getOutputCoords ( ) {
2021-01-13 17:14:23 +01:00
return 2 * int ( resultUV . x * $ { packedTexShape [ 1 ] } . 0 ) ;
2020-11-08 18:32:31 +01:00
}
2021-01-13 17:14:23 +01:00
` :packedTexShape[1]===1? `
2020-11-16 21:51:46 +01:00
int getOutputCoords ( ) {
2021-01-13 17:14:23 +01:00
return 2 * int ( resultUV . y * $ { packedTexShape [ 0 ] } . 0 ) ;
2020-11-16 21:51:46 +01:00
}
2020-11-17 23:42:44 +01:00
` : `
2020-11-16 21:51:46 +01:00
int getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { packedTexShape [ 0 ] } , $ { packedTexShape [ 1 ] } ) ) ;
return 2 * ( resTexRC . x * $ { packedTexShape [ 1 ] } + resTexRC . y ) ;
2020-11-10 02:13:38 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getOutput1DCoords(shape,texShape){return texShape[0]===1? `
2020-11-16 21:51:46 +01:00
int getOutputCoords ( ) {
2021-01-13 17:14:23 +01:00
return int ( resultUV . x * $ { texShape [ 1 ] } . 0 ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` :texShape[1]===1? `
2020-11-16 21:51:46 +01:00
int getOutputCoords ( ) {
2021-01-13 17:14:23 +01:00
return int ( resultUV . y * $ { texShape [ 0 ] } . 0 ) ;
2020-11-08 18:32:31 +01:00
}
2020-11-17 23:42:44 +01:00
` : `
2020-11-16 21:51:46 +01:00
int getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { texShape [ 0 ] } , $ { texShape [ 1 ] } ) ) ;
return resTexRC . x * $ { texShape [ 1 ] } + resTexRC . y ;
2020-11-08 18:32:31 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getOutputPacked3DCoords(shape,texShape){let packedTexShape=[Math.ceil(texShape[0]/2),Math.ceil(texShape[1]/2)],texelsInLogicalRow=Math.ceil(shape[2]/2),texelsInBatch=texelsInLogicalRow*Math.ceil(shape[1]/2);return `
2020-11-16 21:51:46 +01:00
ivec3 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { packedTexShape [ 0 ] } , $ { packedTexShape [ 1 ] } ) ) ;
int index = resTexRC . x * $ { packedTexShape [ 1 ] } + resTexRC . y ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
int b = index / $ { texelsInBatch } ;
index -= b * $ { texelsInBatch } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
int r = 2 * ( index / $ { texelsInLogicalRow } ) ;
int c = imod ( index , $ { texelsInLogicalRow } ) * 2 ;
2020-11-16 21:51:46 +01:00
return ivec3 ( b , r , c ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getOutput3DCoords(shape,texShape){let coordsFromIndexSnippet=getLogicalCoordinatesFromFlatIndex(["r","c","d"],shape);return `
2020-11-16 21:51:46 +01:00
ivec3 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { texShape [ 0 ] } , $ { texShape [ 1 ] } ) ) ;
int index = resTexRC . x * $ { texShape [ 1 ] } + resTexRC . y ;
$ { coordsFromIndexSnippet }
2020-11-16 21:51:46 +01:00
return ivec3 ( r , c , d ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getOutputPackedNDCoords(shape,texShape){let packedTexShape=[Math.ceil(texShape[0]/2),Math.ceil(texShape[1]/2)],texelsInLogicalRow=Math.ceil(shape[shape.length-1]/2),texelsInBatch=texelsInLogicalRow*Math.ceil(shape[shape.length-2]/2),texelsInBatchN=texelsInBatch,batches="",coords2="b, r, c";for(let b=2;b<shape.length-1;b++)texelsInBatchN*=shape[shape.length-b-1],batches= `
int b$ { b } = index / $ { texelsInBatchN } ;
index -= b$ { b } * $ { texelsInBatchN } ;
` +batches,coords2= ` b$ { b } , ` +coords2;return `
ivec$ { shape . length } getOutputCoords ( ) {
2020-11-16 21:51:46 +01:00
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { packedTexShape [ 0 ] } , $ { packedTexShape [ 1 ] } ) ) ;
int index = resTexRC . x * $ { packedTexShape [ 1 ] } + resTexRC . y ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { batches }
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
int b = index / $ { texelsInBatch } ;
index -= b * $ { texelsInBatch } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
int r = 2 * ( index / $ { texelsInLogicalRow } ) ;
int c = imod ( index , $ { texelsInLogicalRow } ) * 2 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
return ivec$ { shape . length } ( $ { coords2 } ) ;
2020-11-08 18:32:31 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getOutput4DCoords(shape,texShape){let coordsFromIndexSnippet=getLogicalCoordinatesFromFlatIndex(["r","c","d","d2"],shape);return `
2020-11-16 21:51:46 +01:00
ivec4 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { texShape [ 0 ] } , $ { texShape [ 1 ] } ) ) ;
int index = resTexRC . x * $ { texShape [ 1 ] } + resTexRC . y ;
$ { coordsFromIndexSnippet }
2020-11-16 21:51:46 +01:00
return ivec4 ( r , c , d , d2 ) ;
}
2021-01-13 17:14:23 +01:00
` }function getOutput5DCoords(shape,texShape){let coordsFromIndexSnippet=getLogicalCoordinatesFromFlatIndex(["r","c","d","d2","d3"],shape);return `
2020-11-16 21:51:46 +01:00
ivec5 getOutputCoords ( ) {
2021-01-13 17:14:23 +01:00
ivec2 resTexRC = ivec2 ( resultUV . yx * vec2 ( $ { texShape [ 0 ] } ,
$ { texShape [ 1 ] } ) ) ;
2020-11-08 18:32:31 +01:00
2021-01-13 17:14:23 +01:00
int index = resTexRC . x * $ { texShape [ 1 ] } + resTexRC . y ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { coordsFromIndexSnippet }
2020-11-16 21:51:46 +01:00
ivec5 outShape = ivec5 ( r , c , d , d2 , d3 ) ;
return outShape ;
}
2021-01-13 17:14:23 +01:00
` }function getOutput6DCoords(shape,texShape){let coordsFromIndexSnippet=getLogicalCoordinatesFromFlatIndex(["r","c","d","d2","d3","d4"],shape);return `
2020-11-16 21:51:46 +01:00
ivec6 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { texShape [ 0 ] } , $ { texShape [ 1 ] } ) ) ;
int index = resTexRC . x * $ { texShape [ 1 ] } + resTexRC . y ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { coordsFromIndexSnippet }
2020-11-16 21:51:46 +01:00
ivec6 result = ivec6 ( r , c , d , d2 , d3 , d4 ) ;
return result ;
}
2021-01-13 17:14:23 +01:00
` }function getOutputPacked2DCoords(shape,texShape){let packedTexShape=[Math.ceil(texShape[0]/2),Math.ceil(texShape[1]/2)];if(util_exports.arraysEqual(shape,texShape))return `
2020-11-16 21:51:46 +01:00
ivec2 getOutputCoords ( ) {
2021-01-13 17:14:23 +01:00
return 2 * ivec2 ( resultUV . yx * vec2 ( $ { packedTexShape [ 0 ] } , $ { packedTexShape [ 1 ] } ) ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let texelsInLogicalRow=Math.ceil(shape[1]/2);return `
2020-11-16 21:51:46 +01:00
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { packedTexShape [ 0 ] } , $ { packedTexShape [ 1 ] } ) ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
int index = resTexRC . x * $ { packedTexShape [ 1 ] } + resTexRC . y ;
int r = 2 * ( index / $ { texelsInLogicalRow } ) ;
int c = imod ( index , $ { texelsInLogicalRow } ) * 2 ;
2020-11-16 21:51:46 +01:00
return ivec2 ( r , c ) ;
}
2021-01-13 17:14:23 +01:00
` }function getOutput2DCoords(shape,texShape){return util_exports.arraysEqual(shape,texShape)? `
2020-11-16 21:51:46 +01:00
ivec2 getOutputCoords ( ) {
2021-01-13 17:14:23 +01:00
return ivec2 ( resultUV . yx * vec2 ( $ { texShape [ 0 ] } , $ { texShape [ 1 ] } ) ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` :shape[1]===1? `
2020-11-16 21:51:46 +01:00
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { texShape [ 0 ] } , $ { texShape [ 1 ] } ) ) ;
int index = resTexRC . x * $ { texShape [ 1 ] } + resTexRC . y ;
2020-11-16 21:51:46 +01:00
return ivec2 ( index , 0 ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` :shape[0]===1? `
2020-11-16 21:51:46 +01:00
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { texShape [ 0 ] } , $ { texShape [ 1 ] } ) ) ;
int index = resTexRC . x * $ { texShape [ 1 ] } + resTexRC . y ;
2020-11-16 21:51:46 +01:00
return ivec2 ( 0 , index ) ;
2020-11-10 02:13:38 +01:00
}
2020-11-17 23:42:44 +01:00
` : `
2020-11-16 21:51:46 +01:00
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
2021-01-13 17:14:23 +01:00
vec2 ( $ { texShape [ 0 ] } , $ { texShape [ 1 ] } ) ) ;
int index = resTexRC . x * $ { texShape [ 1 ] } + resTexRC . y ;
int r = index / $ { shape [ 1 ] } ;
int c = index - r * $ { shape [ 1 ] } ;
2020-11-16 21:51:46 +01:00
return ivec2 ( r , c ) ;
}
2021-01-13 17:14:23 +01:00
` }function getFlatOffsetUniformName(texName){return ` offset$ { texName } ` }function getPackedSamplerScalar(inputInfo){let texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1),glsl=getGlslDifferences();return `
vec4 $ { funcName } ( ) {
return $ { glsl . texture2D } ( $ { texName } , halfCR ) ;
2020-11-12 18:17:57 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getSamplerScalar(inputInfo){let texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1);if(inputInfo.shapeInfo.isUniform)return ` float $ { funcName } ( ) { return $ { texName } ; } ` ;let[texNumR,texNumC]=inputInfo.shapeInfo.texShape;if(texNumR===1&&texNumC===1)return `
float $ { funcName } ( ) {
return sampleTexture ( $ { texName } , halfCR ) ;
}
` ;let[tNumR,tNumC]=inputInfo.shapeInfo.texShape,offset=getFlatOffsetUniformName(texName);return `
float $ { funcName } ( ) {
vec2 uv = uvFromFlat ( $ { tNumR } , $ { tNumC } , $ { offset } ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getPackedSampler1D(inputInfo){let texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1),texShape=inputInfo.shapeInfo.texShape,packedTexShape=[Math.ceil(texShape[0]/2),Math.ceil(texShape[1]/2)],glsl=getGlslDifferences();return `
vec4 $ { funcName } ( int index ) {
2020-11-16 21:51:46 +01:00
vec2 uv = packedUVfrom1D (
2021-01-13 17:14:23 +01:00
$ { packedTexShape [ 0 ] } , $ { packedTexShape [ 1 ] } , index ) ;
return $ { glsl . texture2D } ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getSampler1D(inputInfo){let texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1);if(inputInfo.shapeInfo.isUniform)return `
float $ { funcName } ( int index ) {
$ { getUniformSampler ( inputInfo ) }
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let texShape=inputInfo.shapeInfo.texShape,tNumR=texShape[0],tNumC=texShape[1];if(tNumC===1&&tNumR===1)return `
float $ { funcName } ( int index ) {
return sampleTexture ( $ { texName } , halfCR ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let offset=getFlatOffsetUniformName(texName);return tNumC===1? `
float $ { funcName } ( int index ) {
vec2 uv = vec2 ( 0.5 , ( float ( index + $ { offset } ) + 0.5 ) / $ { tNumR } . 0 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` :tNumR===1? `
float $ { funcName } ( int index ) {
vec2 uv = vec2 ( ( float ( index + $ { offset } ) + 0.5 ) / $ { tNumC } . 0 , 0.5 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-12 18:58:55 +01:00
}
2020-11-17 23:42:44 +01:00
` : `
2021-01-13 17:14:23 +01:00
float $ { funcName } ( int index ) {
vec2 uv = uvFromFlat ( $ { tNumR } , $ { tNumC } , index + $ { offset } ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getPackedSampler2D(inputInfo){let shape=inputInfo.shapeInfo.logicalShape,texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1),texShape=inputInfo.shapeInfo.texShape,texNumR=texShape[0],texNumC=texShape[1],glsl=getGlslDifferences();if(texShape!=null&&util_exports.arraysEqual(shape,texShape))return `
vec4 $ { funcName } ( int row , int col ) {
vec2 uv = ( vec2 ( col , row ) + halfCR ) / vec2 ( $ { texNumC } . 0 , $ { texNumR } . 0 ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
return $ { glsl . texture2D } ( $ { texName } , uv ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let packedTexShape=[Math.ceil(texShape[0]/2),Math.ceil(texShape[1]/2)],valuesPerRow=Math.ceil(shape[1]/2);return `
vec4 $ { funcName } ( int row , int col ) {
vec2 uv = packedUVfrom2D ( $ { valuesPerRow } , $ { packedTexShape [ 0 ] } , $ { packedTexShape [ 1 ] } , row , col ) ;
return $ { glsl . texture2D } ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getSampler2D(inputInfo){let shape=inputInfo.shapeInfo.logicalShape,texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1),texShape=inputInfo.shapeInfo.texShape;if(texShape!=null&&util_exports.arraysEqual(shape,texShape)){let texNumR2=texShape[0],texNumC2=texShape[1];return `
float $ { funcName } ( int row , int col ) {
vec2 uv = ( vec2 ( col , row ) + halfCR ) / vec2 ( $ { texNumC2 } . 0 , $ { texNumR2 } . 0 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }let{newShape,keptDims}=util_exports.squeezeShape(shape),squeezedShape=newShape;if(squeezedShape.length<shape.length){let newInputInfo=squeezeInputInfo(inputInfo,squeezedShape),params=["row","col"];return `
$ { getSamplerFromInInfo ( newInputInfo ) }
float $ { funcName } ( int row , int col ) {
return $ { funcName } ( $ { getSqueezedParams ( params , keptDims ) } ) ;
}
` }if(inputInfo.shapeInfo.isUniform)return `
float $ { funcName } ( int row , int col ) {
int index = round ( dot ( vec2 ( row , col ) , vec2 ( $ { shape [ 1 ] } , 1 ) ) ) ;
$ { getUniformSampler ( inputInfo ) }
}
` ;let texNumR=texShape[0],texNumC=texShape[1],offset=getFlatOffsetUniformName(texName);return texNumC===1? `
float $ { funcName } ( int row , int col ) {
float index = dot ( vec3 ( row , col , $ { offset } ) , vec3 ( $ { shape [ 1 ] } , 1 , 1 ) ) ;
vec2 uv = vec2 ( 0.5 , ( index + 0.5 ) / $ { texNumR } . 0 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` :texNumR===1? `
float $ { funcName } ( int row , int col ) {
float index = dot ( vec3 ( row , col , $ { offset } ) , vec3 ( $ { shape [ 1 ] } , 1 , 1 ) ) ;
vec2 uv = vec2 ( ( index + 0.5 ) / $ { texNumC } . 0 , 0.5 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2020-11-17 23:42:44 +01:00
` : `
2021-01-13 17:14:23 +01:00
float $ { funcName } ( int row , int col ) {
2020-11-16 21:51:46 +01:00
// Explicitly use integer operations as dot() only works on floats.
2021-01-13 17:14:23 +01:00
int index = row * $ { shape [ 1 ] } + col + $ { offset } ;
vec2 uv = uvFromFlat ( $ { texNumR } , $ { texNumC } , index ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getPackedSampler3D(inputInfo){let shape=inputInfo.shapeInfo.logicalShape,texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1),texShape=inputInfo.shapeInfo.texShape,packedTexShape=[Math.ceil(texShape[0]/2),Math.ceil(texShape[1]/2)];if(shape[0]===1){let squeezedShape=shape.slice(1),keptDims=[1,2],newInputInfo=squeezeInputInfo(inputInfo,squeezedShape),params=["b","row","col"];return `
$ { getPackedSamplerFromInInfo ( newInputInfo ) }
vec4 $ { funcName } ( int b , int row , int col ) {
return $ { funcName } ( $ { getSqueezedParams ( params , keptDims ) } ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }let texNumR=packedTexShape[0],texNumC=packedTexShape[1],valuesPerRow=Math.ceil(shape[2]/2),texelsInBatch=valuesPerRow*Math.ceil(shape[1]/2),glsl=getGlslDifferences();return `
vec4 $ { funcName } ( int b , int row , int col ) {
2020-11-16 21:51:46 +01:00
vec2 uv = packedUVfrom3D (
2021-01-13 17:14:23 +01:00
$ { texNumR } , $ { texNumC } , $ { texelsInBatch } , $ { valuesPerRow } , b , row , col ) ;
return $ { glsl . texture2D } ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getSampler3D(inputInfo){let shape=inputInfo.shapeInfo.logicalShape,texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1),stride0=shape[1]*shape[2],stride1=shape[2],{newShape,keptDims}=util_exports.squeezeShape(shape),squeezedShape=newShape;if(squeezedShape.length<shape.length){let newInputInfo=squeezeInputInfo(inputInfo,squeezedShape),params=["row","col","depth"];return `
$ { getSamplerFromInInfo ( newInputInfo ) }
float $ { funcName } ( int row , int col , int depth ) {
return $ { funcName } ( $ { getSqueezedParams ( params , keptDims ) } ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }if(inputInfo.shapeInfo.isUniform)return `
float $ { funcName } ( int row , int col , int depth ) {
2020-11-16 21:51:46 +01:00
int index = round ( dot ( vec3 ( row , col , depth ) ,
2021-01-13 17:14:23 +01:00
vec3 ( $ { stride0 } , $ { stride1 } , 1 ) ) ) ;
$ { getUniformSampler ( inputInfo ) }
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let texShape=inputInfo.shapeInfo.texShape,texNumR=texShape[0],texNumC=texShape[1],flatOffset=inputInfo.shapeInfo.flatOffset;if(texNumC===stride0&&flatOffset==null)return `
float $ { funcName } ( int row , int col , int depth ) {
2020-11-16 21:51:46 +01:00
float texR = float ( row ) ;
2021-01-13 17:14:23 +01:00
float texC = dot ( vec2 ( col , depth ) , vec2 ( $ { stride1 } , 1 ) ) ;
2020-11-16 21:51:46 +01:00
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
2021-01-13 17:14:23 +01:00
vec2 ( $ { texNumC } . 0 , $ { texNumR } . 0 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` ;if(texNumC===stride1&&flatOffset==null)return `
float $ { funcName } ( int row , int col , int depth ) {
float texR = dot ( vec2 ( row , col ) , vec2 ( $ { shape [ 1 ] } , 1 ) ) ;
2020-11-16 21:51:46 +01:00
float texC = float ( depth ) ;
2021-01-13 17:14:23 +01:00
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) / vec2 ( $ { texNumC } . 0 , $ { texNumR } . 0 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let offset=getFlatOffsetUniformName(texName);return `
float $ { funcName } ( int row , int col , int depth ) {
2020-11-16 21:51:46 +01:00
// Explicitly use integer operations as dot() only works on floats.
2021-01-13 17:14:23 +01:00
int index = row * $ { stride0 } + col * $ { stride1 } + depth + $ { offset } ;
vec2 uv = uvFromFlat ( $ { texNumR } , $ { texNumC } , index ) ;
return sampleTexture ( $ { texName } , uv ) ;
}
` }function getPackedSamplerND(inputInfo){let shape=inputInfo.shapeInfo.logicalShape,rank=shape.length,texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1),texShape=inputInfo.shapeInfo.texShape,packedTexShape=[Math.ceil(texShape[0]/2),Math.ceil(texShape[1]/2)],texNumR=packedTexShape[0],texNumC=packedTexShape[1],valuesPerRow=Math.ceil(shape[rank-1]/2),texelsInBatch=valuesPerRow*Math.ceil(shape[rank-2]/2),params="int b, int row, int col",index= ` b * $ { texelsInBatch } + ( row / 2 ) * $ { valuesPerRow } + ( col / 2 ) ` ;for(let b=2;b<rank-1;b++)params= ` int b$ { b } , ` +params,texelsInBatch*=shape[rank-b-1],index= ` b$ { b } * $ { texelsInBatch } + ` +index;let glsl=getGlslDifferences();return `
vec4 $ { funcName } ( $ { params } ) {
int index = $ { index } ;
int texR = index / $ { texNumC } ;
int texC = index - texR * $ { texNumC } ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) / vec2 ( $ { texNumC } , $ { texNumR } ) ;
return $ { glsl . texture2D } ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getSampler4D(inputInfo){let shape=inputInfo.shapeInfo.logicalShape,texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1),stride2=shape[3],stride1=shape[2]*stride2,stride0=shape[1]*stride1,{newShape,keptDims}=util_exports.squeezeShape(shape);if(newShape.length<shape.length){let newInputInfo=squeezeInputInfo(inputInfo,newShape),params=["row","col","depth","depth2"];return `
$ { getSamplerFromInInfo ( newInputInfo ) }
float $ { funcName } ( int row , int col , int depth , int depth2 ) {
return $ { funcName } ( $ { getSqueezedParams ( params , keptDims ) } ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }if(inputInfo.shapeInfo.isUniform)return `
float $ { funcName } ( int row , int col , int depth , int depth2 ) {
2020-11-16 21:51:46 +01:00
int index = round ( dot ( vec4 ( row , col , depth , depth2 ) ,
2021-01-13 17:14:23 +01:00
vec4 ( $ { stride0 } , $ { stride1 } , $ { stride2 } , 1 ) ) ) ;
$ { getUniformSampler ( inputInfo ) }
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let flatOffset=inputInfo.shapeInfo.flatOffset,texShape=inputInfo.shapeInfo.texShape,texNumR=texShape[0],texNumC=texShape[1];if(texNumC===stride0&&flatOffset==null)return `
float $ { funcName } ( int row , int col , int depth , int depth2 ) {
2020-11-16 21:51:46 +01:00
float texR = float ( row ) ;
float texC =
dot ( vec3 ( col , depth , depth2 ) ,
2021-01-13 17:14:23 +01:00
vec3 ( $ { stride1 } , $ { stride2 } , 1 ) ) ;
2020-11-16 21:51:46 +01:00
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
2021-01-13 17:14:23 +01:00
vec2 ( $ { texNumC } . 0 , $ { texNumR } . 0 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;if(texNumC===stride2&&flatOffset==null)return `
float $ { funcName } ( int row , int col , int depth , int depth2 ) {
2020-11-16 21:51:46 +01:00
float texR = dot ( vec3 ( row , col , depth ) ,
2021-01-13 17:14:23 +01:00
vec3 ( $ { shape [ 1 ] * shape [ 2 ] } , $ { shape [ 2 ] } , 1 ) ) ;
2020-11-16 21:51:46 +01:00
float texC = float ( depth2 ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
2021-01-13 17:14:23 +01:00
vec2 ( $ { texNumC } . 0 , $ { texNumR } . 0 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let offset=getFlatOffsetUniformName(texName);return `
float $ { funcName } ( int row , int col , int depth , int depth2 ) {
2020-11-16 21:51:46 +01:00
// Explicitly use integer operations as dot() only works on floats.
2021-01-13 17:14:23 +01:00
int index = row * $ { stride0 } + col * $ { stride1 } +
depth * $ { stride2 } + depth2 ;
vec2 uv = uvFromFlat ( $ { texNumR } , $ { texNumC } , index + $ { offset } ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getSampler5D(inputInfo){let shape=inputInfo.shapeInfo.logicalShape,texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1),stride3=shape[4],stride2=shape[3]*stride3,stride1=shape[2]*stride2,stride0=shape[1]*stride1,{newShape,keptDims}=util_exports.squeezeShape(shape);if(newShape.length<shape.length){let newInputInfo=squeezeInputInfo(inputInfo,newShape),params=["row","col","depth","depth2","depth3"];return `
$ { getSamplerFromInInfo ( newInputInfo ) }
float $ { funcName } ( int row , int col , int depth , int depth2 , int depth3 ) {
return $ { funcName } ( $ { getSqueezedParams ( params , keptDims ) } ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }if(inputInfo.shapeInfo.isUniform)return `
float $ { funcName } ( int row , int col , int depth , int depth2 , int depth3 ) {
2020-11-16 21:51:46 +01:00
float index = dot (
vec4 ( row , col , depth , depth2 ) ,
2021-01-13 17:14:23 +01:00
vec4 ( $ { stride0 } , $ { stride1 } , $ { stride2 } , $ { stride3 } ) ) +
2020-11-16 21:51:46 +01:00
depth3 ;
2021-01-13 17:14:23 +01:00
$ { getUniformSampler ( inputInfo ) }
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let flatOffset=inputInfo.shapeInfo.flatOffset,texShape=inputInfo.shapeInfo.texShape,texNumR=texShape[0],texNumC=texShape[1];if(texNumC===stride0&&flatOffset==null)return `
float $ { funcName } ( int row , int col , int depth , int depth2 , int depth3 ) {
2020-11-16 21:51:46 +01:00
int texR = row ;
float texC = dot ( vec4 ( col , depth , depth2 , depth3 ) ,
2021-01-13 17:14:23 +01:00
vec4 ( $ { stride1 } , $ { stride2 } , $ { stride3 } , 1 ) ) ;
2020-11-16 21:51:46 +01:00
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
2021-01-13 17:14:23 +01:00
vec2 ( $ { texNumC } . 0 , $ { texNumR } . 0 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;if(texNumC===stride3&&flatOffset==null)return `
float $ { funcName } ( int row , int col , int depth , int depth2 , int depth3 ) {
2020-11-16 21:51:46 +01:00
float texR = dot (
vec4 ( row , col , depth , depth2 ) ,
2021-01-13 17:14:23 +01:00
vec4 ( $ { shape [ 1 ] * shape [ 2 ] * shape [ 3 ] } ,
$ { shape [ 2 ] * shape [ 3 ] } , $ { shape [ 3 ] } , 1 ) ) ;
2020-11-16 21:51:46 +01:00
int texC = depth3 ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
2021-01-13 17:14:23 +01:00
vec2 ( $ { texNumC } . 0 , $ { texNumR } . 0 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let offset=getFlatOffsetUniformName(texName);return `
float $ { funcName } ( int row , int col , int depth , int depth2 , int depth3 ) {
2020-11-16 21:51:46 +01:00
// Explicitly use integer operations as dot() only works on floats.
2021-01-13 17:14:23 +01:00
int index = row * $ { stride0 } + col * $ { stride1 } + depth * $ { stride2 } +
depth2 * $ { stride3 } + depth3 + $ { offset } ;
vec2 uv = uvFromFlat ( $ { texNumR } , $ { texNumC } , index ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-10 02:13:38 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getSampler6D(inputInfo){let shape=inputInfo.shapeInfo.logicalShape,texName=inputInfo.name,funcName="get"+texName.charAt(0).toUpperCase()+texName.slice(1),{newShape,keptDims}=util_exports.squeezeShape(shape);if(newShape.length<shape.length){let newInputInfo=squeezeInputInfo(inputInfo,newShape),params=["row","col","depth","depth2","depth3","depth4"];return `
$ { getSamplerFromInInfo ( newInputInfo ) }
float $ { funcName } ( int row , int col , int depth ,
2020-11-16 21:51:46 +01:00
int depth2 , int depth3 , int depth4 ) {
2021-01-13 17:14:23 +01:00
return $ { funcName } ( $ { getSqueezedParams ( params , keptDims ) } ) ;
2020-11-10 02:13:38 +01:00
}
2021-01-13 17:14:23 +01:00
` }let stride4=shape[5],stride3=shape[4]*stride4,stride2=shape[3]*stride3,stride1=shape[2]*stride2,stride0=shape[1]*stride1;if(inputInfo.shapeInfo.isUniform)return `
float $ { funcName } ( int row , int col , int depth ,
2020-11-16 21:51:46 +01:00
int depth2 , int depth3 , int depth4 ) {
int index = round ( dot (
vec4 ( row , col , depth , depth2 ) ,
2021-01-13 17:14:23 +01:00
vec4 ( $ { stride0 } , $ { stride1 } , $ { stride2 } , $ { stride3 } ) ) +
2020-11-16 21:51:46 +01:00
dot (
vec2 ( depth3 , depth4 ) ,
2021-01-13 17:14:23 +01:00
vec2 ( $ { stride4 } , 1 ) ) ) ;
$ { getUniformSampler ( inputInfo ) }
2020-11-10 02:13:38 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let flatOffset=inputInfo.shapeInfo.flatOffset,texShape=inputInfo.shapeInfo.texShape,texNumR=texShape[0],texNumC=texShape[1];if(texNumC===stride0&&flatOffset==null)return `
float $ { funcName } ( int row , int col , int depth ,
2020-11-16 21:51:46 +01:00
int depth2 , int depth3 , int depth4 ) {
int texR = row ;
float texC = dot ( vec4 ( col , depth , depth2 , depth3 ) ,
2021-01-13 17:14:23 +01:00
vec4 ( $ { stride1 } , $ { stride2 } , $ { stride3 } , $ { stride4 } ) ) +
2020-11-16 21:51:46 +01:00
float ( depth4 ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
2021-01-13 17:14:23 +01:00
vec2 ( $ { texNumC } . 0 , $ { texNumR } . 0 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;if(texNumC===stride4&&flatOffset==null)return `
float $ { funcName } ( int row , int col , int depth ,
2020-11-16 21:51:46 +01:00
int depth2 , int depth3 , int depth4 ) {
float texR = dot ( vec4 ( row , col , depth , depth2 ) ,
2021-01-13 17:14:23 +01:00
vec4 ( $ { shape [ 1 ] * shape [ 2 ] * shape [ 3 ] * shape [ 4 ] } ,
$ { shape [ 2 ] * shape [ 3 ] * shape [ 4 ] } ,
$ { shape [ 3 ] * shape [ 4 ] } ,
$ { shape [ 4 ] } ) ) + float ( depth3 ) ;
2020-11-16 21:51:46 +01:00
int texC = depth4 ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
2021-01-13 17:14:23 +01:00
vec2 ( $ { texNumC } . 0 , $ { texNumR } . 0 ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` ;let offset=getFlatOffsetUniformName(texName);return `
float $ { funcName } ( int row , int col , int depth ,
2020-11-16 21:51:46 +01:00
int depth2 , int depth3 , int depth4 ) {
// Explicitly use integer operations as dot() only works on floats.
2021-01-13 17:14:23 +01:00
int index = row * $ { stride0 } + col * $ { stride1 } + depth * $ { stride2 } +
depth2 * $ { stride3 } + depth3 * $ { stride4 } + depth4 + $ { offset } ;
vec2 uv = uvFromFlat ( $ { texNumR } , $ { texNumC } , index ) ;
return sampleTexture ( $ { texName } , uv ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getUniformSampler(inputInfo){let texName=inputInfo.name,inSize=util_exports.sizeFromShape(inputInfo.shapeInfo.logicalShape);return inSize<2? ` return $ { texName } ; ` : `
for ( int i = 0 ; i < $ { inSize } ; i ++ ) {
2020-11-16 21:51:46 +01:00
if ( i == index ) {
2021-01-13 17:14:23 +01:00
return $ { texName } [ i ] ;
2020-11-08 18:32:31 +01:00
}
2020-11-10 02:13:38 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getPackedSamplerAtOutputCoords(inputInfo,outShapeInfo){let texName=inputInfo.name,texFuncSnippet=texName.charAt(0).toUpperCase()+texName.slice(1),funcName="get"+texFuncSnippet+"AtOutCoords",inRank=inputInfo.shapeInfo.logicalShape.length,outRank=outShapeInfo.logicalShape.length,broadcastDims=getBroadcastDims2(inputInfo.shapeInfo.logicalShape,outShapeInfo.logicalShape),type=getCoordsDataType(outRank),rankDiff=outRank-inRank,coordsSnippet,fields=["x","y","z","w","u","v"];inRank===0?coordsSnippet="":outRank<2&&broadcastDims.length>=1?coordsSnippet="coords = 0;":coordsSnippet=broadcastDims.map(d=> ` coords . $ { fields [ d + rankDiff ] } = 0 ; ` ).join( `
` );let unpackedCoordsSnippet="";outRank<2&&inRank>0?unpackedCoordsSnippet="coords":unpackedCoordsSnippet=inputInfo.shapeInfo.logicalShape.map((s,i)=> ` coords . $ { fields [ i + rankDiff ] } ` ).join(", ");let output="return outputValue;",isInputScalar=util_exports.sizeFromShape(inputInfo.shapeInfo.logicalShape)===1,isOutputScalar=util_exports.sizeFromShape(outShapeInfo.logicalShape)===1;if(inRank===1&&!isInputScalar&&!isOutputScalar)output= `
2020-11-16 21:51:46 +01:00
return vec4 ( outputValue . xy , outputValue . xy ) ;
2021-01-13 17:14:23 +01:00
` ;else if(isInputScalar&&!isOutputScalar)outRank===1?output= `
2020-11-16 21:51:46 +01:00
return vec4 ( outputValue . x , outputValue . x , 0. , 0. ) ;
2021-01-13 17:14:23 +01:00
` :output= `
2020-11-16 21:51:46 +01:00
return vec4 ( outputValue . x ) ;
2021-01-13 17:14:23 +01:00
` ;else if(broadcastDims.length){let rows=inRank-2,cols=inRank-1;broadcastDims.indexOf(rows)>-1&&broadcastDims.indexOf(cols)>-1?output="return vec4(outputValue.x);":broadcastDims.indexOf(rows)>-1?output="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":broadcastDims.indexOf(cols)>-1&&(output="return vec4(outputValue.xx, outputValue.zz);")}return `
vec4 $ { funcName } ( ) {
$ { type } coords = getOutputCoords ( ) ;
$ { coordsSnippet }
vec4 outputValue = get$ { texFuncSnippet } ( $ { unpackedCoordsSnippet } ) ;
$ { output }
2020-11-10 02:13:38 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getSamplerAtOutputCoords(inputInfo,outShapeInfo){let texName=inputInfo.name,texFuncSnippet=texName.charAt(0).toUpperCase()+texName.slice(1),funcName="get"+texFuncSnippet+"AtOutCoords",outTexShape=outShapeInfo.texShape,inTexShape=inputInfo.shapeInfo.texShape,inRank=inputInfo.shapeInfo.logicalShape.length,outRank=outShapeInfo.logicalShape.length;if(!inputInfo.shapeInfo.isUniform&&inRank===outRank&&inputInfo.shapeInfo.flatOffset==null&&util_exports.arraysEqual(inTexShape,outTexShape))return `
float $ { funcName } ( ) {
return sampleTexture ( $ { texName } , resultUV ) ;
}
` ;let type=getCoordsDataType(outRank),broadcastDims=getBroadcastDims2(inputInfo.shapeInfo.logicalShape,outShapeInfo.logicalShape),rankDiff=outRank-inRank,coordsSnippet,fields=["x","y","z","w","u","v"];inRank===0?coordsSnippet="":outRank<2&&broadcastDims.length>=1?coordsSnippet="coords = 0;":coordsSnippet=broadcastDims.map(d=> ` coords . $ { fields [ d + rankDiff ] } = 0 ; ` ).join( `
` );let unpackedCoordsSnippet="";return outRank<2&&inRank>0?unpackedCoordsSnippet="coords":unpackedCoordsSnippet=inputInfo.shapeInfo.logicalShape.map((s,i)=> ` coords . $ { fields [ i + rankDiff ] } ` ).join(", "), `
float $ { funcName } ( ) {
$ { type } coords = getOutputCoords ( ) ;
$ { coordsSnippet }
return get$ { texFuncSnippet } ( $ { unpackedCoordsSnippet } ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }function getCoordsDataType(rank){if(rank<=1)return"int";if(rank===2)return"ivec2";if(rank===3)return"ivec3";if(rank===4)return"ivec4";if(rank===5)return"ivec5";if(rank===6)return"ivec6";throw Error( ` GPU for rank $ { rank } is not yet supported ` )}function squeezeInputInfo(inInfo,squeezedShape){let newInputInfo=JSON.parse(JSON.stringify(inInfo));return newInputInfo.shapeInfo.logicalShape=squeezedShape,newInputInfo}function getSqueezedParams(params,keptDims){return keptDims.map(d=>params[d]).join(", ")}function compileProgram(gpgpu,program,inputs,output){let userCode=program.userCode,inputInfos=inputs.map((input2,i)=>{let shapeInfo={logicalShape:input2.shape,texShape:input2.isUniform?null:input2.texData.texShape,isUniform:input2.isUniform,isPacked:input2.isUniform?!1:input2.texData.isPacked,flatOffset:null};return input2.texData!=null&&input2.texData.slice!=null&&input2.texData.slice.flatOffset>0&&(shapeInfo.flatOffset=input2.texData.slice.flatOffset),{name:program.variableNames[i],shapeInfo}}),inShapeInfos=inputInfos.map(x=>x.shapeInfo),outShapeInfo={logicalShape:output.shape,texShape:output.texData.texShape,isUniform:!1,isPacked:output.texData.isPacked,flatOffset:null},source=makeShader(inputInfos,outShapeInfo,userCode,program.packedInputs),webGLProgram=gpgpu.createProgram(source),infLoc=null,nanLoc=gpgpu.getUniformLocation(webGLProgram,"NAN",!1);env().getNumber("WEBGL_VERSION")===1&&(infLoc=gpgpu.getUniformLocation(webGLProgram,"INFINITY",!1));let uniformLocations={};for(let i=0;i<program.variableNames.length;i++){let varName=program.variableNames[i],shouldThrow=!1;uniformLocations[varName]=gpgpu.getUniformLocation(webGLProgram,varName,shouldThrow),uniformLocations[ ` offset$ { varName } ` ]=gpgpu.getUniformLocation(webGLProgram, ` offset$ { varName } ` ,shouldThrow)}return{program,source,webGLProgram,uniformLocations,inShapeInfos,outShapeInfo,infLoc,nanLoc}}function validateBinaryAndProgram(shapeInfos,inputs){if(shapeInfos.length!==inputs.length)throw Error( ` Binary was compiled with $ { shapeInfos . length } inputs , but was executed with $ { inputs . length } inputs ` );shapeInfos.forEach((s,i)=>{let shapeA=s.logicalShape,input2=inputs[i],shapeB=input2.shape;if(!util_exports.arraysEqual(shapeA,shapeB))throw Error( ` Binary was compiled with different shapes than the current args . Shapes $ { shapeA } and $ { shapeB } must match ` );if(s.isUniform&&input2.isUniform)return;let texShapeA=s.texShape,texShapeB=input2.isUniform?null:input2.texData.texShape;if(!util_exports.arraysEqual(texShapeA,texShapeB))throw Error( ` Binary was compiled with different texture shapes than the current args . Shape $ { texShapeA } and $ { texShapeB } must match ` )})}function runProgram(gpgpu,binary,inputs,output,customSetup){validateBinaryAndProgram(binary.inShapeInfos,inputs),validateBinaryAndProgram([binary.outShapeInfo],[output]);let outTex=output.texData.texture,outTexShape=output.texData.texShape;output.texData.isPacked?gpgpu.setOutputPackedMatrixTexture(outTex,outTexShape[0],outTexShape[1]):gpgpu.setOutputMatrixTexture(outTex,outTexShape[0],outTexShape[1]),gpgpu.setProgram(binary.webGLProgram),env().getNumber("WEBGL_VERSION")===1&&binary.infLoc!==null&&gpgpu.gl.uniform1f(binary.infLoc,Infinity),binary.nanLoc!==null&&gpgpu.gl.uniform1f(binary.nanLoc,NaN),inputs.forEach((input2,i)=>{let varName=binary.program.variableNames[i],varLoc=binary.uniformLocations[varName],varOffsetLoc=binary.uniformLocations[ ` offset$ { varName } ` ];if(varLoc!=null){if(input2.isUniform){if(util_exports.sizeFromShape(input2.shape)<2)gpgpu.gl.uniform1f(varLoc,input2.uniformValues[0]);else{let vals=input2.uniformValues;vals instanceof Float32Array||(vals=new Float32Array(vals)),gpgpu.gl.uniform1fv(varLoc,vals)}return}input2.texData.slice!=null&&varOffsetLoc!=null&&gpgpu.gl.uniform1i(varOffsetLoc,input2.texData.slice.flatOffset),gpgpu.setInputMatrixTexture(input2.texData.texture,varLoc,i)}}),customSetup!=null&&customSetup(gpgpu,binary.webGLProgram),gpgpu.executeProgram()}function makeShaderKey(program,inputs,output){let keyInputs="";inputs.concat(output).forEach(x=>{let hasOffset=x.texData!=null&&x.texData.slice!=n
2021-01-03 16:41:56 +01:00
void main ( ) {
setOutput ( vec4 ( getA ( ) , 0. , 0. , 0. ) ) ;
2020-12-15 14:44:42 +01:00
}
2021-01-13 17:14:23 +01:00
` ;else{let channels=getChannels("rc",rank),dtype=getCoordsDataType(rank),outOfBoundsCondition=getOutOfBoundsCondition(rank,outputShape,channels),setup41=getSetup(rank,outputShape[outputShape.length-1],outputShape[outputShape.length-2],channels),output=getOutput(outputShape,channels);this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } rc = getOutputCoords ( ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( $ { outOfBoundsCondition } ) {
2021-01-03 16:41:56 +01:00
setOutput ( vec4 ( 0 ) ) ;
} else {
2021-01-13 17:14:23 +01:00
$ { setup41 }
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
setOutput ( vec4 ( $ { output } ) ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }}};function getSourceCoordsArr(rank,dims){let coords2=[];for(let row=0;row<=1;row++)for(let col=0;col<=1;col++){let coord= ` $ { row === 0 ? "r" : "rp1" } , $ { col === 0 ? "c" : "cp1" } ` ;for(let d=2;d<rank;d++)coord= ` $ { dims [ dims . length - 1 - d ] } , ` +coord;coords2.push(coord)}return coords2}function getOutOfBoundsCondition(rank,shape,dims){if(rank===1)return ` rc > $ { shape [ 0 ] } ` ;let cond="";for(let i=rank-2;i<rank;i++)cond+= ` $ { dims [ i ] } >= $ { shape [ i ] } ` ,i<rank-1&&(cond+="||");return cond}function getSetup(rank,cols,rows,dims){if(rank===1)return"";let innerDims=dims.slice(-2);return `
int r = $ { innerDims [ 0 ] } ;
int c = $ { innerDims [ 1 ] } ;
2021-01-03 16:41:56 +01:00
int rp1 = r + 1 ;
int cp1 = c + 1 ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
bool cEdge = cp1 >= $ { cols } ;
bool rEdge = rp1 >= $ { rows } ;
` }function getOutput(shape,dims){let rank=shape.length,sourceCoords=getSourceCoordsArr(rank,dims);return rank===1? ` getA ( rc ) ,
rc + 1 >= $ { shape [ 0 ] } ? 0. : getA ( rc + 1 ) ,
0 , 0 ` : ` getA ( $ { sourceCoords [ 0 ] } ) ,
cEdge ? 0. : getA ( $ { sourceCoords [ 1 ] } ) ,
rEdge ? 0. : getA ( $ { sourceCoords [ 2 ] } ) ,
rEdge || cEdge ? 0. : getA ( $ { sourceCoords [ 3 ] } ) ` }var ReshapePackedProgram=class{constructor(outputShape,inputShape){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=outputShape;let mainLoop="";for(let i=0;i<4;i++){let thisRC="thisRC = rc;";i%2==1&&(thisRC+="thisRC.z += 1;"),i>1&&(thisRC+="thisRC.y += 1;"),mainLoop+= `
$ { thisRC }
$ { i > 0 ? "if(thisRC.y < rows && thisRC.z < cols){" : "" }
2021-01-03 16:41:56 +01:00
int flatIndex = getFlatIndex ( thisRC ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
ivec3 inputRC = inputCoordsFromReshapedOutCoords ( flatIndex ) ;
vec2 inputRCInnerDims = vec2 ( float ( inputRC . y ) , float ( inputRC . z ) ) ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
result [ $ { i } ] =
2021-01-03 16:41:56 +01:00
getChannel ( getA ( inputRC . x , inputRC . y , inputRC . z ) , inputRCInnerDims ) ;
2021-01-13 17:14:23 +01:00
$ { i > 0 ? "}" : "" }
2021-01-03 16:41:56 +01:00
` }this.userCode= `
2021-01-13 17:14:23 +01:00
$ { getReshapedInputCoords ( inputShape ) }
$ { getFlatIndexFrom3D ( outputShape ) }
2020-11-16 21:51:46 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec3 rc = getOutputCoords ( ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
vec4 result = vec4 ( 0. ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
ivec3 thisRC ;
2021-01-13 17:14:23 +01:00
int rows = $ { outputShape [ 1 ] } ;
int cols = $ { outputShape [ 2 ] } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { mainLoop }
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
setOutput ( result ) ;
}
2021-01-13 17:14:23 +01:00
` }};function getReshapedInputCoords(shape){return `
2021-01-03 16:41:56 +01:00
ivec3 inputCoordsFromReshapedOutCoords ( int index ) {
2021-01-13 17:14:23 +01:00
$ { getLogicalCoordinatesFromFlatIndex ( [ "r" , "c" , "d" ] , shape ) }
2021-01-03 16:41:56 +01:00
return ivec3 ( r , c , d ) ;
}
2021-01-13 17:14:23 +01:00
` }var TextureManager=class{constructor(gpgpu){this.gpgpu=gpgpu,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}acquireTexture(shapeRC,usage,isPacked){let physicalTexType=getPhysicalFromLogicalTextureType(usage,isPacked),shapeKey=getKeyFromTextureShape(shapeRC,physicalTexType,isPacked);shapeKey in this.freeTextures||(this.freeTextures[shapeKey]=[]),shapeKey in this.usedTextures||(this.usedTextures[shapeKey]=[]);let texBytes=computeBytes(shapeRC,physicalTexType,this.gpgpu.gl,this.gpgpu.textureConfig,isPacked);if(this.freeTextures[shapeKey].length>0){this.numFreeTextures--,this.numUsedTextures++,this._numBytesFree-=texBytes,this.log();let newTexture2=this.freeTextures[shapeKey].shift();return this.usedTextures[shapeKey].push(newTexture2),newTexture2}let newTexture;return physicalTexType===PhysicalTextureType.PACKED_2X2_FLOAT32?newTexture=this.gpgpu.createPackedMatrixTexture(shapeRC[0],shapeRC[1]):physicalTexType===PhysicalTextureType.PACKED_2X2_FLOAT16?newTexture=this.gpgpu.createFloat16PackedMatrixTexture(shapeRC[0],shapeRC[1]):physicalTexType===PhysicalTextureType.UNPACKED_FLOAT32?newTexture=this.gpgpu.createFloat32MatrixTexture(shapeRC[0],shapeRC[1]):physicalTexType===PhysicalTextureType.UNPACKED_FLOAT16?newTexture=this.gpgpu.createFloat16MatrixTexture(shapeRC[0],shapeRC[1]):physicalTexType===PhysicalTextureType.PACKED_4X1_UNSIGNED_BYTE&&(newTexture=this.gpgpu.createUnsignedBytesMatrixTexture(shapeRC[0],shapeRC[1])),this.usedTextures[shapeKey].push(newTexture),this.numUsedTextures++,this._numBytesAllocated+=texBytes,this.log(),newTexture}releaseTexture(texture,shape,logicalTexType,isPacked){if(this.freeTextures==null)return;let physicalTexType=getPhysicalFromLogicalTextureType(logicalTexType,isPacked),shapeKey=getKeyFromTextureShape(shape,physicalTexType,isPacked);shapeKey in this.freeTextures||(this.freeTextures[shapeKey]=[]);let texBytes=computeBytes(shape,physicalTexType,this.gpgpu.gl,this.gpgpu.textureConfig,isPacked),deleteTexThreshold=env().get("WEBGL_DELETE_TEXTURE_THRESHOLD");deleteTexThreshold!==-1&&this._numBytesAllocated>deleteTexThreshold?(this.gpgpu.deleteMatrixTexture(texture),this._numBytesAllocated-=texBytes):(this.freeTextures[shapeKey].push(texture),this.numFreeTextures++,this._numBytesFree+=texBytes),this.numUsedTextures--;let texList=this.usedTextures[shapeKey],texIndex=texList.indexOf(texture);if(texIndex<0)throw new Error("Cannot release a texture that was never provided by this texture manager");texList.splice(texIndex,1),this.log()}log(){if(!this.logEnabled)return;let total=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used", ` $ { this . numFreeTextures } / $ { this . numUsedTextures } ` , ` ( $ { total } ) ` );let freeRatio=this._numBytesFree/this._numBytesAllocated;console.log( ` Bytes allocated : $ { this . _numBytesAllocated } ` ),console.log( ` Bytes unused : $ { this . _numBytesFree } ( $ { Math . round ( 100 * freeRatio ) } % ) ` )}get numBytesAllocated(){return this._numBytesAllocated}get numBytesFree(){return this._numBytesFree}getNumUsedTextures(){return this.numUsedTextures}getNumFreeTextures(){return this.numFreeTextures}dispose(){if(this.freeTextures!=null){for(let texShape in this.freeTextures)this.freeTextures[texShape].forEach(tex=>{this.gpgpu.deleteMatrixTexture(tex)});for(let texShape in this.usedTextures)this.usedTextures[texShape].forEach(tex=>{this.gpgpu.deleteMatrixTexture(tex)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0}}};function numBytesForInternalFormat(gl,internalFormat){let glany=gl;if(internalFormat===glany.R32F)return 4;if(internalFormat===glany.R16F)return 2;if(internalFormat===glany.RGBA32F||internalFormat===gl.RGBA)return 16;if(internalFormat===glany.RGBA16F)return 8;throw new Error( ` Unknown internal format $ { internalFormat } ` )}function computeBytes(shape,physicalTexType,gl,textureConfig,isPacked){let internalFormat=internalFormatForPhysicalTexType(physicalTexType,textureConfig),numElements;if(isPacked)
2021-01-03 16:41:56 +01:00
float unaryOperation ( float x ) {
2021-01-13 17:14:23 +01:00
$ { opSnippet }
2021-01-03 16:41:56 +01:00
}
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
void main ( ) {
float x = getAAtOutCoords ( ) ;
float y = unaryOperation ( x ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
setOutput ( y ) ;
}
2021-01-13 17:14:23 +01:00
` }},CHECK_NAN_SNIPPET="if (isnan(x)) return x;",LINEAR="return x;",ABS="return abs(x);",ELU="return (x >= 0.0) ? x : (exp(x) - 1.0);",RELU=CHECK_NAN_SNIPPET+ `
2021-01-03 16:41:56 +01:00
return ( x < 0.0 ) ? 0.0 : x ;
2021-01-13 17:14:23 +01:00
` ,RELU6=CHECK_NAN_SNIPPET+ `
2021-01-03 16:41:56 +01:00
return ( x < 0.0 ) ? 0.0 : min ( 6.0 , x ) ;
2021-01-13 17:14:23 +01:00
` ,CLONE="return x;",LINEAR2="return x;",ELU2= `
2021-01-03 16:41:56 +01:00
vec4 result ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
result . r = ( x . r >= 0.0 ) ? x . r : ( exp ( x . r ) - 1.0 ) ;
result . g = ( x . g >= 0.0 ) ? x . g : ( exp ( x . g ) - 1.0 ) ;
result . b = ( x . b >= 0.0 ) ? x . b : ( exp ( x . b ) - 1.0 ) ;
result . a = ( x . a >= 0.0 ) ? x . a : ( exp ( x . a ) - 1.0 ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
return result ;
2021-01-13 17:14:23 +01:00
` ,RELU2= `
2021-01-03 16:41:56 +01:00
vec4 result = x * vec4 ( greaterThanEqual ( x , vec4 ( 0.0 ) ) ) ;
bvec4 isNaN = isnan ( x ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
result . r = isNaN . r ? x . r : result . r ;
result . g = isNaN . g ? x . g : result . g ;
result . b = isNaN . b ? x . b : result . b ;
result . a = isNaN . a ? x . a : result . a ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
return result ;
2021-01-13 17:14:23 +01:00
` ,RELU62= `
2021-01-03 16:41:56 +01:00
vec4 result = min ( x , vec4 ( 6. ) ) * vec4 ( greaterThanEqual ( x , vec4 ( 0.0 ) ) ) ;
bvec4 isNaN = isnan ( x ) ;
result . r = isNaN . r ? x . r : result . r ;
result . g = isNaN . g ? x . g : result . g ;
result . b = isNaN . b ? x . b : result . b ;
result . a = isNaN . a ? x . a : result . a ;
return result ;
2021-01-13 17:14:23 +01:00
` ,UnaryOpPackedProgram=class{constructor(aShape,opSnippet){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=aShape,this.userCode= `
2021-01-03 16:41:56 +01:00
vec4 unaryOperation ( vec4 x ) {
2021-01-13 17:14:23 +01:00
$ { opSnippet }
2021-01-03 16:23:45 +01:00
}
void main ( ) {
2021-01-03 16:41:56 +01:00
vec4 x = getAAtOutCoords ( ) ;
vec4 y = unaryOperation ( x ) ;
setOutput ( y ) ;
}
2021-01-13 17:14:23 +01:00
` }},UnpackProgram=class{constructor(outputShape){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outputShape=outputShape;let rank=outputShape.length,channels=getChannels("rc",rank),dtype=getCoordsDataType(rank),sourceCoords=getSourceCoords(rank,channels),innerDims=channels.slice(-2),coords2=rank<=1?"rc": ` vec2 ( $ { innerDims . join ( "," ) } ) ` ;this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } rc = getOutputCoords ( ) ;
vec4 packedInput = getA ( $ { sourceCoords } ) ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
setOutput ( getChannel ( packedInput , $ { coords2 } ) ) ;
2021-01-03 16:23:45 +01:00
}
2021-01-13 17:14:23 +01:00
` }},whereImpl3=kernel_impls_exports.whereImpl,EPSILON_FLOAT322=1e-7,EPSILON_FLOAT162=1e-4,binaryCaches={};function getBinaryCache(webGLVersion){return webGLVersion in binaryCaches||(binaryCaches[webGLVersion]={}),binaryCaches[webGLVersion]}var CPU_HANDOFF_SIZE_THRESHOLD=128,BEFORE_PAGING_CONSTANT=600;function numMBBeforeWarning(){return env().global.screen==null?1024:env().global.screen.height*env().global.screen.width*window.devicePixelRatio*BEFORE_PAGING_CONSTANT/1024/1024}var MathBackendWebGL=class extends KernelBackend{constructor(gpgpu){super();if(this.pendingRead=new WeakMap,this.pendingDisposal=new WeakSet,this.dataRefCount=new WeakMap,this.numBytesInGPU=0,this.uploadWaitMs=0,this.downloadWaitMs=0,this.warnedAboutMemory=!1,this.warnedAboutCPUBackend=!1,this.pendingDeletes=0,this.disposed=!1,!env().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(gpgpu==null){let gl=getWebGLContext(env().getNumber("WEBGL_VERSION"));this.binaryCache=getBinaryCache(env().getNumber("WEBGL_VERSION")),this.gpgpu=new GPGPUContext(gl),this.canvas=gl.canvas,this.gpgpuCreatedLocally=!0}else this.gpgpu=gpgpu,this.binaryCache={},this.gpgpuCreatedLocally=!1,this.canvas=gpgpu.gl.canvas;this.textureManager=new TextureManager(this.gpgpu),this.numMBBeforeWarning=numMBBeforeWarning(),this.texData=new DataStorage(this,engine())}numDataIds(){return this.texData.numDataIds()+(this.cpuBackend?this.cpuBackend.numDataIds():0)-this.pendingDeletes}write(values,shape,dtype){if((env().getBool("WEBGL_CHECK_NUMERICAL_PROBLEMS")||env().getBool("DEBUG"))&&this.checkNumericalProblems(values),dtype==="complex64"&&values!=null)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");let dataId={};return this.texData.set(dataId,{shape,dtype,values,usage:TextureUsage.UPLOAD,refCount:1,complexParentRefCount:0}),dataId}incRef(dataId){let texData=this.texData.get(dataId);texData.refCount++}decRef(dataId){if(this.texData.has(dataId)){let texData=this.texData.get(dataId);texData.refCount--}}move(dataId,values,shape,dtype){if(env().getBool("DEBUG")&&this.checkNumericalProblems(values),dtype==="complex64")throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(dataId,{shape,dtype,values,usage:TextureUsage.UPLOAD,refCount:1,complexParentRefCount:0})}disposeIntermediateTensorInfo(tensorInfo){let dataId=tensorInfo.dataId;if(this.texData.has(dataId)){let textureData=this.texData.get(dataId);textureData.refCount--,textureData.refCount<1&&this.disposeData(dataId)}}readSync(dataId){let texData=this.texData.get(dataId),{values,dtype,complexTensorInfos,slice:slice5,shape,isPacked}=texData;if(slice5!=null){let program;isPacked?program=new UnaryOpPackedProgram(shape,CLONE):program=new UnaryOpProgram(shape,CLONE);let res=this.runWebGLProgram(program,[{dataId,shape,dtype}],dtype),data2=this.readSync(res.dataId);return this.disposeIntermediateTensorInfo(res),data2}if(values!=null)return this.convertAndCacheOnCPU(dataId);if(dtype==="string")return values;let shouldTimeProgram=this.activeTimers!=null,start;shouldTimeProgram&&(start=util_exports.now());let result;if(dtype==="complex64"){let realValues=this.readSync(complexTensorInfos.real.dataId),imagValues=this.readSync(complexTensorInfos.imag.dataId);result=backend_util_exports.mergeRealAndImagArrays(realValues,imagValues)}else result=this.getValuesFromTexture(dataId);return shouldTimeProgram&&(this.downloadWaitMs+=util_exports.now()-start),this.convertAndCacheOnCPU(dataId,result)}async read(dataId){if(this.pendingRead.has(dataId)){let subscribers2=this.pendingRead.get(dataId);return new Promise(resolve=>subscribers2.push(resolve))}let texData=this.texData.get(dataId),{values,shape,slice:slice5,dtype,complexTensorInfos,isPacked}=texData;if(slice5!=null){let program;isPacked?program=new UnaryOpPackedProgram(shape,CLONE):program=new UnaryOpProgram(shape,CLONE);let res=this.runWebGLProgram(program,[{dataId,shape,dtype}],dtype),data2=this.read(res.dataId);return this.disposeIntermediateTensorInfo(res),data2}if(values!=null)re
2020-11-16 21:51:46 +01:00
if ( isnan ( a ) ) return a ;
if ( isnan ( b ) ) return b ;
2021-01-13 17:14:23 +01:00
` ,BinaryOpProgram=class{constructor(op2,aShape,bShape){this.variableNames=["A","B"],this.outputShape=backend_util_exports.assertAndGetBroadcastShape(aShape,bShape),this.userCode= `
2020-11-16 21:51:46 +01:00
float binaryOperation ( float a , float b ) {
2021-01-13 17:14:23 +01:00
$ { op2 }
2020-11-10 02:13:38 +01:00
}
2020-11-16 21:51:46 +01:00
void main ( ) {
float a = getAAtOutCoords ( ) ;
float b = getBAtOutCoords ( ) ;
setOutput ( binaryOperation ( a , b ) ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }},CHECK_NAN_SNIPPET3= `
2020-11-16 21:51:46 +01:00
result . r = isNaN . r > 0. ? NAN : result . r ;
result . g = isNaN . g > 0. ? NAN : result . g ;
result . b = isNaN . b > 0. ? NAN : result . b ;
result . a = isNaN . a > 0. ? NAN : result . a ;
2021-01-13 17:14:23 +01:00
` ,BinaryOpPackedProgram=class{constructor(op2,aShape,bShape,checkOutOfBounds=!1){this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.packedInputs=!0,this.packedOutput=!0,this.outputShape=backend_util_exports.assertAndGetBroadcastShape(aShape,bShape);let rank=this.outputShape.length,checkOutOfBoundsString="";if(checkOutOfBounds)if(rank===0||util_exports.sizeFromShape(this.outputShape)===1)checkOutOfBoundsString= `
2020-11-16 21:51:46 +01:00
result . y = 0. ;
result . z = 0. ;
result . w = 0. ;
2021-01-13 17:14:23 +01:00
` ;else if(checkOutOfBoundsString= `
$ { getCoordsDataType ( rank ) } coords = getOutputCoords ( ) ;
` ,rank===1)checkOutOfBoundsString+= `
2020-11-16 21:51:46 +01:00
result . y = ( coords + 1 ) >= $ { this . outputShape [ 0 ] } ? 0. : result . y ;
result . z = 0. ;
result . w = 0. ;
2021-01-13 17:14:23 +01:00
` ;else{let channels=getChannels("coords",rank);checkOutOfBoundsString+= `
2020-11-16 21:51:46 +01:00
bool nextRowOutOfBounds =
2021-01-13 17:14:23 +01:00
( $ { channels [ rank - 2 ] } + 1 ) >= $ { this . outputShape [ rank - 2 ] } ;
2020-11-16 21:51:46 +01:00
bool nextColOutOfBounds =
2021-01-13 17:14:23 +01:00
( $ { channels [ rank - 1 ] } + 1 ) >= $ { this . outputShape [ rank - 1 ] } ;
2020-11-16 21:51:46 +01:00
result . y = nextColOutOfBounds ? 0. : result . y ;
result . z = nextRowOutOfBounds ? 0. : result . z ;
result . w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result . w ;
2021-01-03 16:41:56 +01:00
` }this.userCode= `
2020-11-16 21:51:46 +01:00
vec4 binaryOperation ( vec4 a , vec4 b ) {
2021-01-13 17:14:23 +01:00
$ { op2 }
2020-11-08 18:32:31 +01:00
}
2020-11-16 21:51:46 +01:00
void main ( ) {
vec4 a = getAAtOutCoords ( ) ;
vec4 b = getBAtOutCoords ( ) ;
vec4 result = binaryOperation ( a , b ) ;
2021-01-13 17:14:23 +01:00
$ { checkOutOfBoundsString }
2020-11-16 21:51:46 +01:00
setOutput ( result ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function identity2(args){let{inputs,backend:backend22}=args,{x}=inputs;return backend22.incRef(x.dataId),{dataId:x.dataId,shape:x.shape,dtype:x.dtype}}var identityConfig2={kernelName:Identity,backendName:"webgl",kernelFunc:identity2};function complex3(args){let{inputs,backend:backend22}=args,{real:real4,imag:imag4}=inputs,complexInfo=backend22.makeTensorInfo(real4.shape,"complex64"),complex4=backend22.texData.get(complexInfo.dataId),realTensorInfo=identity2({inputs:{x:real4},backend:backend22}),realData=backend22.texData.get(realTensorInfo.dataId);realData.complexParentRefCount++;let imagTensorInfo=identity2({inputs:{x:imag4},backend:backend22}),imagData=backend22.texData.get(imagTensorInfo.dataId);return imagData.complexParentRefCount++,complex4.complexTensorInfos={real:realTensorInfo,imag:imagTensorInfo},complexInfo}var complexConfig2={kernelName:Complex,backendName:"webgl",kernelFunc:complex3},LEAKYRELU="return (a < 0.) ? b * a : a;",LEAKYRELU_PACKED= `
2021-01-03 16:41:56 +01:00
vec4 aLessThanZero = vec4 ( lessThan ( a , vec4 ( 0. ) ) ) ;
return ( aLessThanZero * ( b * a ) ) + ( ( vec4 ( 1.0 ) - aLessThanZero ) * a ) ;
2021-01-13 17:14:23 +01:00
` ;function leakyRelu3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{alpha}=attrs, $ alpha=backend22.makeTensorInfo([],"float32",util_exports.createScalarValue(alpha,"float32")),program=env().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new BinaryOpPackedProgram(LEAKYRELU_PACKED,x.shape, $ alpha.shape):new BinaryOpProgram(LEAKYRELU,x.shape, $ alpha.shape),result=backend22.runWebGLProgram(program,[x, $ alpha],x.dtype);return backend22.disposeIntermediateTensorInfo( $ alpha),result}var leakyReluConfig2={kernelName:LeakyRelu,backendName:"webgl",kernelFunc:leakyRelu3},PRELU="return (a < 0.) ? b * a : a;",PRELU_PACKED= `
2021-01-03 16:41:56 +01:00
vec4 aLessThanZero = vec4 ( lessThan ( a , vec4 ( 0. ) ) ) ;
return ( aLessThanZero * ( b * a ) ) + ( ( vec4 ( 1.0 ) - aLessThanZero ) * a ) ;
2021-01-13 17:14:23 +01:00
` ;function prelu3(args){let{inputs,backend:backend22}=args,{x,alpha}=inputs,program=env().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new BinaryOpPackedProgram(PRELU_PACKED,x.shape,alpha.shape):new BinaryOpProgram(PRELU,x.shape,alpha.shape);return backend22.runWebGLProgram(program,[x,alpha],x.dtype)}var preluConfig2={kernelName:Prelu,backendName:"webgl",kernelFunc:prelu3},CHECK_NAN_SNIPPET_UNARY="if (isnan(x)) return x;",CHECK_NAN_SNIPPET_BINARY= `
2021-01-03 16:41:56 +01:00
if ( isnan ( a ) ) return a ;
if ( isnan ( b ) ) return b ;
2021-01-13 17:14:23 +01:00
` ,CHECK_NAN_SNIPPET_BINARY_PACKED= `
2021-01-03 16:41:56 +01:00
result . r = isNaN . r > 0. ? NAN : result . r ;
result . g = isNaN . g > 0. ? NAN : result . g ;
result . b = isNaN . b > 0. ? NAN : result . b ;
result . a = isNaN . a > 0. ? NAN : result . a ;
2021-01-13 17:14:23 +01:00
` ;function unaryKernelFunc2({opSnippet,packedOpSnippet,cpuKernelImpl,dtype}){return({inputs,backend:backend22})=>{let{x}=inputs,webglBackend=backend22, $ dtype=dtype||x.dtype;if(webglBackend.shouldExecuteOnCPU([x])&&cpuKernelImpl!=null){let xData=webglBackend.texData.get(x.dataId),outValues=cpuKernelImpl(xData.values, $ dtype);return webglBackend.makeTensorInfo(x.shape, $ dtype,outValues)}let shouldUsePackedProgram=env().getBool("WEBGL_PACK_UNARY_OPERATIONS")&&packedOpSnippet!=null,program;return shouldUsePackedProgram?program=new UnaryOpPackedProgram(x.shape,packedOpSnippet):program=new UnaryOpProgram(x.shape,opSnippet),webglBackend.runWebGLProgram(program,[x], $ dtype)}}function binaryKernelFunc2({opSnippet,packedOpSnippet,checkOutOfBounds=!1,supportsComplex=!1,cpuKernelImpl,dtype}){return({inputs,backend:backend22})=>{let{a,b}=inputs,webglBackend=backend22;if(supportsComplex&&a.dtype==="complex64"){let aData=webglBackend.texData.get(a.dataId),bData=webglBackend.texData.get(b.dataId),[real4,imag4]=[[aData.complexTensorInfos.real,bData.complexTensorInfos.real],[aData.complexTensorInfos.imag,bData.complexTensorInfos.imag]].map(complexParts=>{let[aPart,bPart]=complexParts,aHandle={dataId:aPart.dataId,dtype:aPart.dtype,shape:a.shape},bHandle={dataId:bPart.dataId,dtype:bPart.dtype,shape:b.shape},program2=new BinaryOpProgram(opSnippet,a.shape,b.shape);return webglBackend.runWebGLProgram(program2,[aHandle,bHandle],upcastType(aPart.dtype,bPart.dtype))}),complexOutput=complex3({inputs:{real:real4,imag:imag4},backend:webglBackend});return webglBackend.disposeIntermediateTensorInfo(real4),webglBackend.disposeIntermediateTensorInfo(imag4),complexOutput}let $ dtype=dtype||upcastType(a.dtype,b.dtype);if(webglBackend.shouldExecuteOnCPU([a,b])&&cpuKernelImpl!=null){let aData=webglBackend.texData.get(a.dataId),bData=webglBackend.texData.get(b.dataId),[outValues,outShape]=cpuKernelImpl(a.shape,b.shape,aData.values,bData.values, $ dtype),out=webglBackend.makeTensorInfo(outShape, $ dtype),outData=webglBackend.texData.get(out.dataId);return outData.values=outValues,out}let shouldUsePackedProgram=env().getBool("WEBGL_PACK_BINARY_OPERATIONS")&&packedOpSnippet!=null,program;return shouldUsePackedProgram?program=new BinaryOpPackedProgram(packedOpSnippet,a.shape,b.shape,checkOutOfBounds):program=new BinaryOpProgram(opSnippet,a.shape,b.shape),webglBackend.runWebGLProgram(program,[a,b], $ dtype)}}function mapActivationToShaderProgram(activation2,packed=!1){if(activation2==="linear")return packed?LINEAR2:LINEAR;if(activation2==="relu")return packed?RELU2:RELU;if(activation2==="elu")return packed?ELU2:ELU;if(activation2==="relu6")return packed?RELU62:RELU6;if(activation2==="prelu")return packed?PRELU_PACKED:PRELU;if(activation2==="leakyrelu")return packed?LEAKYRELU_PACKED:LEAKYRELU;throw new Error( ` Activation $ { activation2 } has not been implemented for the WebGL backend . ` )}var MatMulPackedProgram=class{constructor(aShape,bShape,outputShape,transposeA=!1,transposeB=!1,addBias=!1,activation2=null,hasPreluActivation=!1,hasLeakyreluActivation=!1){this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=outputShape;let sharedDim=transposeA?aShape[1]:aShape[2],sharedDimensionPacked=Math.ceil(sharedDim/2),aSample=transposeA?"i * 2, rc.y":"rc.y, i * 2",bSample=transposeB?"rc.z, i * 2":"i * 2, rc.z",aSwizzle=transposeA?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],bSwizzle=transposeB?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],activationSnippet="",applyActivationSnippet="";activation2&&(hasPreluActivation?activationSnippet= ` vec4 activation ( vec4 a ) {
2021-01-03 16:41:56 +01:00
vec4 b = getPreluActivationWeightsAtOutCoords ( ) ;
2021-01-13 17:14:23 +01:00
$ { activation2 }
} ` :hasLeakyreluActivation?activationSnippet= ` vec4 activation ( vec4 a ) {
2021-01-03 16:41:56 +01:00
vec4 b = getLeakyreluAlphaAtOutCoords ( ) ;
2021-01-13 17:14:23 +01:00
$ { activation2 }
} ` :activationSnippet= ` vec4 activation ( vec4 x ) {
$ { activation2 }
} ` ,applyActivationSnippet="result = activation(result);");let addBiasSnippet=addBias?"result += getBiasAtOutCoords();":"";addBias&&this.variableNames.push("bias"),hasPreluActivation&&this.variableNames.push("preluActivationWeights"),hasLeakyreluActivation&&this.variableNames.push("leakyreluAlpha");let batchASnippet="rc.x",batchBSnippet="rc.x";aShape[0]<bShape[0]?batchASnippet= ` int ( min ( float ( rc . x ) , $ { aShape [ 0 ] - 1 } . ) ) ` :bShape[0]<aShape[0]&&(batchBSnippet= ` int ( min ( float ( rc . x ) , $ { bShape [ 0 ] - 1 } . ) ) ` ),this.userCode= `
$ { activationSnippet }
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
const float sharedDimension = $ { sharedDimensionPacked } . 0 ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
vec4 dot2x2ARowBCol ( ivec3 rc ) {
vec4 result = vec4 ( 0 ) ;
2021-01-13 17:14:23 +01:00
for ( int i = 0 ; i < $ { sharedDimensionPacked } ; i ++ ) {
int batchA = $ { batchASnippet } ;
int batchB = $ { batchBSnippet } ;
vec4 a = getMatrixA ( batchA , $ { aSample } ) ;
vec4 b = getMatrixB ( batchB , $ { bSample } ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
// These swizzled products need to be separately added.
// See: https://github.com/tensorflow/tfjs/issues/1735
2021-01-13 17:14:23 +01:00
result += ( $ { aSwizzle [ 0 ] } * $ { bSwizzle [ 0 ] } ) ;
result += ( $ { aSwizzle [ 1 ] } * $ { bSwizzle [ 1 ] } ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-03 16:41:56 +01:00
return result ;
2020-12-15 14:44:42 +01:00
}
2021-01-03 16:23:45 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec3 rc = getOutputCoords ( ) ;
vec4 result = dot2x2ARowBCol ( rc ) ;
2021-01-03 16:23:45 +01:00
2021-01-13 17:14:23 +01:00
$ { addBiasSnippet }
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
$ { applyActivationSnippet }
2021-01-03 16:41:56 +01:00
setOutput ( result ) ;
2021-01-03 16:23:45 +01:00
}
2021-01-13 17:14:23 +01:00
` }},COMPLEX_MULTIPLY={REAL:"return areal * breal - aimag * bimag;",IMAG:"return areal * bimag + aimag * breal;"},BinaryOpComplexProgram=class{constructor(op2,aShape,bShape){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=backend_util_exports.assertAndGetBroadcastShape(aShape,bShape),this.userCode= `
2021-01-03 16:41:56 +01:00
float binaryOpComplex (
float areal , float aimag , float breal , float bimag ) {
2021-01-13 17:14:23 +01:00
$ { op2 }
2021-01-03 16:23:45 +01:00
}
void main ( ) {
2021-01-03 16:41:56 +01:00
float areal = getARealAtOutCoords ( ) ;
float aimag = getAImagAtOutCoords ( ) ;
float breal = getBRealAtOutCoords ( ) ;
float bimag = getBImagAtOutCoords ( ) ;
setOutput ( binaryOpComplex ( areal , aimag , breal , bimag ) ) ;
}
2021-01-13 17:14:23 +01:00
` }},MUL="return a * b;";function multiply2(args){let{inputs,backend:backend22}=args,{a,b}=inputs,dtype=backend_util_exports.upcastType(a.dtype,b.dtype);if(a.dtype==="complex64"){let aData=backend22.texData.get(a.dataId),bData=backend22.texData.get(b.dataId),realProgram=new BinaryOpComplexProgram(COMPLEX_MULTIPLY.REAL,a.shape,b.shape),imagProgram=new BinaryOpComplexProgram(COMPLEX_MULTIPLY.IMAG,a.shape,b.shape),inputs2=[{dataId:aData.complexTensorInfos.real.dataId,dtype:aData.complexTensorInfos.real.dtype,shape:a.shape},{dataId:aData.complexTensorInfos.imag.dataId,dtype:aData.complexTensorInfos.imag.dtype,shape:a.shape},{dataId:bData.complexTensorInfos.real.dataId,dtype:bData.complexTensorInfos.real.dtype,shape:b.shape},{dataId:bData.complexTensorInfos.imag.dataId,dtype:bData.complexTensorInfos.imag.dtype,shape:b.shape}],realPart=backend22.runWebGLProgram(realProgram,inputs2,"float32"),imagPart=backend22.runWebGLProgram(imagProgram,inputs2,"float32"),complexOutput=complex3({inputs:{real:realPart,imag:imagPart},backend:backend22});return backend22.disposeIntermediateTensorInfo(realPart),backend22.disposeIntermediateTensorInfo(imagPart),complexOutput}if(backend22.shouldExecuteOnCPU([a,b])){let aData=backend22.texData.get(a.dataId),bData=backend22.texData.get(b.dataId),[outValues,outShape]=multiplyImplCPU(a.shape,b.shape,aData.values,bData.values,dtype),out=backend22.makeTensorInfo(outShape,dtype),outData=backend22.texData.get(out.dataId);return outData.values=outValues,out}let program;return env().getBool("WEBGL_PACK_BINARY_OPERATIONS")?program=new BinaryOpPackedProgram(MUL,a.shape,b.shape):program=new BinaryOpProgram(MUL,a.shape,b.shape),backend22.runWebGLProgram(program,[a,b],dtype)}var multiplyConfig2={kernelName:Multiply,backendName:"webgl",kernelFunc:multiply2};function packedReshape(input2,afterShape,backend22){let input3DShape=[getBatchDim(input2.shape),...getRowsCols(input2.shape)],input3D={dtype:input2.dtype,shape:input3DShape,dataId:input2.dataId},afterShapeAs3D=[getBatchDim(afterShape),...getRowsCols(afterShape)],program=new ReshapePackedProgram(afterShapeAs3D,input3DShape),preventEagerUnpackingOfOutput=!0,output=backend22.runWebGLProgram(program,[input3D],input2.dtype,null,preventEagerUnpackingOfOutput);return{dataId:output.dataId,shape:afterShape,dtype:output.dtype}}function reshape3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{shape}=attrs,webglBackend=backend22,xSize=util_exports.sizeFromShape(x.shape), $ shape=util_exports.inferFromImplicitShape(shape,xSize), $ xSize=util_exports.sizeFromShape( $ shape);util_exports.assert(xSize=== $ xSize,()=> ` The new shape ( $ { $shape } ) has $ { $xSize } elements and the old shape ( $ { x . shape } ) has $ { xSize } elements . The new shape and old shape must have the same number of elements . ` );let xTexData=webglBackend.texData.get(x.dataId);return xTexData.isPacked&&!isReshapeFree(x.shape, $ shape)&&!(xTexData.texture!==null&&isReshapeFree(xTexData.shape, $ shape))?packedReshape(x, $ shape,webglBackend):(webglBackend.incRef(x.dataId),{dataId:x.dataId,shape: $ shape,dtype:x.dtype})}var reshapeConfig2={kernelName:Reshape,backendName:"webgl",kernelFunc:reshape3},MeanProgram=class{constructor(reduceInfo,divisor){this.variableNames=["x"];let{windowSize,batchSize,inSize,outSize}=reduceInfo;this.outputShape=[batchSize,outSize];let windowSizeNearestVec4=Math.floor(windowSize/4)*4,windowSizeVec4Remainder=windowSize%4,updateSnippet="sumValue += dot(values, ones);";if(divisor!=null){let denominator=1/divisor;updateSnippet= ` sumValue += dot ( values * $ { util _exports . isInt ( denominator ) ? denominator . toPrecision ( 2 ) : denominator } , ones ) ; ` }let checkOutOfBounds="";inSize%windowSize>0&&(checkOutOfBounds= `
if ( inIdx < 0 || inIdx >= $ { inSize } ) {
2021-01-03 16:41:56 +01:00
return 0.0 ;
2021-01-03 16:23:45 +01:00
}
2021-01-03 16:41:56 +01:00
` ),this.userCode= `
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
2021-01-03 16:23:45 +01:00
2021-01-03 16:41:56 +01:00
float getValue ( int batch , int inIdx ) {
2021-01-13 17:14:23 +01:00
$ { checkOutOfBounds }
2021-01-03 16:41:56 +01:00
return getX ( batch , inIdx ) ;
2021-01-03 16:23:45 +01:00
}
2021-01-03 16:41:56 +01:00
2020-11-16 21:51:46 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
2021-01-13 17:14:23 +01:00
int inOffset = outIdx * $ { windowSize } ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
float sumValue = 0.0 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int i = 0 ; i < $ { windowSizeNearestVec4 } ; i += 4 ) {
2021-01-03 16:41:56 +01:00
int inIdx = inOffset + i ;
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
getValue ( batch , inIdx + 3 )
) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
2021-01-03 16:41:56 +01:00
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
int inIdx = inOffset + $ { windowSizeNearestVec4 } ;
if ( $ { windowSizeVec4Remainder === 1 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 ( getValue ( batch , inIdx ) , 0.0 , 0.0 , 0.0 ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
} else if ( $ { windowSizeVec4Remainder === 2 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) , 0.0 , 0.0 ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
} else if ( $ { windowSizeVec4Remainder === 3 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) , 0.0 ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
2020-12-15 14:44:42 +01:00
}
2021-01-03 16:41:56 +01:00
setOutput ( sumValue ) ;
}
2021-01-13 17:14:23 +01:00
` }},ReduceProgram=class{constructor(reduceInfo,reduceType){this.variableNames=["x"];let{windowSize,batchSize,inSize,outSize}=reduceInfo;this.outputShape=[batchSize,outSize];let initializationValue="0.0",compareOp="";reduceType==="prod"?initializationValue="1.0":reduceType==="min"?(initializationValue="1.0 / 1e-20",compareOp="min"):reduceType==="max"&&(initializationValue="-1.0 / 1e-20",compareOp="max");let returnValue= ` $ { reduceType } ( $ { reduceType } ( $ { reduceType } ( minMaxValue [ 0 ] , minMaxValue [ 1 ] ) , minMaxValue [ 2 ] ) , minMaxValue [ 3 ] ) ` ;reduceType==="sum"?returnValue="sumValue":reduceType==="prod"?returnValue="prodValue":reduceType==="all"?returnValue="allValue":reduceType==="any"&&(returnValue="anyValue");let windowSizeNearestVec4=Math.floor(windowSize/4)*4,windowSizeVec4Remainder=windowSize%4,updateSnippet= `
if ( $ { reduceType === "sum" } ) {
2021-01-03 16:41:56 +01:00
sumValue += dot ( values , ones ) ;
2021-01-13 17:14:23 +01:00
} else if ( $ { reduceType === "prod" } ) {
2021-01-03 16:41:56 +01:00
vec2 tmp = vec2 ( values [ 0 ] , values [ 1 ] ) * vec2 ( values [ 2 ] , values [ 3 ] ) ;
prodValue *= tmp [ 0 ] * tmp [ 1 ] ;
} else {
2021-01-13 17:14:23 +01:00
minMaxValue = $ { compareOp } ( values , minMaxValue ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` ,vecType="vec4";reduceType==="all"?(initializationValue="1.0",updateSnippet= `
2021-01-03 16:41:56 +01:00
bool reducedAllValue = all ( values ) ;
float floatedReducedAllValue = float ( reducedAllValue ) ;
allValue = float ( allValue >= 1.0 && floatedReducedAllValue >= 1.0 ) ;
2021-01-13 17:14:23 +01:00
` ,vecType="bvec4"):reduceType==="any"&&(initializationValue="0.0",updateSnippet= `
2021-01-03 16:41:56 +01:00
bool reducedAnyValue = any ( values ) ;
float floatedReducedAnyValue = float ( reducedAnyValue ) ;
anyValue = float ( anyValue >= 1.0 || floatedReducedAnyValue >= 1.0 ) ;
2021-01-13 17:14:23 +01:00
` ,vecType="bvec4");let checkOutOfBounds="";inSize%windowSize>0&&(checkOutOfBounds= `
if ( inIdx < 0 || inIdx >= $ { inSize } ) {
2021-01-03 16:41:56 +01:00
return initializationValue ;
}
` ),this.userCode= `
2021-01-13 17:14:23 +01:00
const float initializationValue = $ { initializationValue } ;
2021-01-03 16:41:56 +01:00
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
float getValue ( int batch , int inIdx ) {
2021-01-13 17:14:23 +01:00
$ { checkOutOfBounds }
2021-01-03 16:41:56 +01:00
return getX ( batch , inIdx ) ;
2020-12-15 14:44:42 +01:00
}
2020-11-16 21:51:46 +01:00
2020-12-15 14:44:42 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec2 coords = getOutputCoords ( ) ;
2020-12-15 14:44:42 +01:00
int batch = coords [ 0 ] ;
2021-01-03 16:41:56 +01:00
int outIdx = coords [ 1 ] ;
2021-01-13 17:14:23 +01:00
int inOffset = outIdx * $ { windowSize } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
vec4 minMaxValue = vec4 ( $ { initializationValue } ) ;
2021-01-03 16:41:56 +01:00
float prodValue = 1.0 ;
float sumValue = 0.0 ;
float allValue = 1.0 ;
float anyValue = 0.0 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int i = 0 ; i < $ { windowSizeNearestVec4 } ; i += 4 ) {
2021-01-03 16:41:56 +01:00
int inIdx = inOffset + i ;
2021-01-13 17:14:23 +01:00
$ { vecType } values = $ { vecType } (
2021-01-03 16:41:56 +01:00
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
getValue ( batch , inIdx + 3 )
) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
2021-01-03 16:41:56 +01:00
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
int inIdx = inOffset + $ { windowSizeNearestVec4 } ;
if ( $ { windowSizeVec4Remainder === 1 } ) {
$ { vecType } values = $ { vecType } (
2021-01-03 16:41:56 +01:00
getValue ( batch , inIdx ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
} else if ( $ { windowSizeVec4Remainder === 2 } ) {
$ { vecType } values = $ { vecType } (
2021-01-03 16:41:56 +01:00
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
initializationValue ,
initializationValue
) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
} else if ( $ { windowSizeVec4Remainder === 3 } ) {
$ { vecType } values = $ { vecType } (
2021-01-03 16:41:56 +01:00
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
initializationValue
) ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
setOutput ( $ { returnValue } ) ;
2020-12-15 14:44:42 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function getReductionStages(inShape){let stages=[];for(;stages.length===0||stages[stages.length-1].outSize!==1;){let outSize=stages.length?stages[stages.length-1].outSize:inShape[1],windowSize=backend_util_exports.computeOptimalWindowSize(outSize);stages.push({inSize:outSize,windowSize,outSize:Math.ceil(outSize/windowSize)})}return stages}function reduce(x,dtype,reductionType,backend22){let reductionStages=getReductionStages(x.shape),result=x;for(let i=0;i<reductionStages.length;i++){let{inSize,windowSize,outSize}=reductionStages[i],program,previousResult;reductionType==="mean"?program=i===0?new MeanProgram({windowSize,inSize,batchSize:x.shape[0],outSize},inSize):new MeanProgram({windowSize,inSize,batchSize:x.shape[0],outSize}):program=new ReduceProgram({windowSize,inSize,batchSize:x.shape[0],outSize},reductionType),previousResult=result,result=backend22.runWebGLProgram(program,[result],dtype),previousResult.dataId!==x.dataId&&backend22.disposeIntermediateTensorInfo(previousResult)}return result}var TransposeProgram=class{constructor(aShape,newDim){this.variableNames=["A"];let outputShape=new Array(aShape.length);for(let i=0;i<outputShape.length;i++)outputShape[i]=aShape[newDim[i]];this.outputShape=outputShape,this.rank=outputShape.length;let dtype=getCoordsDataType(this.rank),switched=getSwitchedCoords(newDim);this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } resRC = getOutputCoords ( ) ;
setOutput ( getA ( $ { switched } ) ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function getSwitchedCoords(newDim){let rank=newDim.length;if(rank>6)throw Error( ` Transpose for rank $ { rank } is not yet supported ` );let originalOrder=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],switchedCoords=new Array(rank);for(let i=0;i<newDim.length;i++)switchedCoords[newDim[i]]=originalOrder[i];return switchedCoords.join()}var TransposePackedProgram=class{constructor(aShape,newDim){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0;let outputShape=new Array(aShape.length);for(let i=0;i<outputShape.length;i++)outputShape[i]=aShape[newDim[i]];if(this.outputShape=outputShape,this.rank=outputShape.length,this.rank>6)throw Error( ` Packed transpose for rank $ { this . rank } is not yet supported . ` );let dtype=getCoordsDataType(this.rank),outputOrder=getVecChannels("rc",this.rank),switchedOrder=new Array(this.rank);for(let i=0;i<newDim.length;i++)switchedOrder[newDim[i]]=outputOrder[i];let innerDims= ` vec2 ( $ { switchedOrder . slice ( - 2 ) . join ( ) } ) ` ,nextColumn= ` ++ $ { outputOrder [ this . rank - 1 ] } < $ { outputShape [ this . rank - 1 ] } ` ,getc= ` getChannel ( getA ( $ { switchedOrder . join ( ) } ) , $ { innerDims } ) ` ;this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } rc = getOutputCoords ( ) ;
2021-01-03 16:41:56 +01:00
vec4 result = vec4 ( 0. ) ;
2021-01-13 17:14:23 +01:00
result [ 0 ] = $ { getc } ;
if ( $ { nextColumn } ) {
result [ 1 ] = $ { getc } ;
}
-- $ { outputOrder [ this . rank - 1 ] } ;
if ( ++ $ { outputOrder [ this . rank - 2 ] } < $ { outputShape [ this . rank - 2 ] } ) {
result [ 2 ] = $ { getc } ;
if ( $ { nextColumn } ) {
result [ 3 ] = $ { getc } ;
2021-01-03 16:41:56 +01:00
}
}
setOutput ( result ) ;
}
2021-01-13 17:14:23 +01:00
` }};function transposeImpl2(x,perm,backend22){let program=env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new TransposePackedProgram(x.shape,perm):new TransposeProgram(x.shape,perm);return backend22.runWebGLProgram(program,[x],x.dtype)}function sumImpl(x,axis,keepDims,backend22){let reductionIndices=axis,xRank=x.shape.length,origAxes=util_exports.parseAxisParam(reductionIndices,x.shape),axes=origAxes,permutedAxes=backend_util_exports.getAxesPermutation(axes,xRank),sumInputIsTransposed=permutedAxes!=null,sumInput=x;sumInputIsTransposed&&(sumInput=transposeImpl2(x,permutedAxes,backend22),axes=backend_util_exports.getInnerMostAxes(axes.length,xRank)),backend_util_exports.assertAxesAreInnerMostDims("sum",axes,xRank);let[sumOutShape,reduceShape]=backend_util_exports.computeOutAndReduceShapes(sumInput.shape,axes),outShape=sumOutShape;keepDims&&(outShape=backend_util_exports.expandShapeToKeepDim(sumOutShape,origAxes));let inSize=util_exports.sizeFromShape(reduceShape),batchSize=util_exports.sizeFromShape(x.shape)/inSize,reshapedInput=reshape3({inputs:{x:sumInput},attrs:{shape:[batchSize,inSize]},backend:backend22}),outType=sumOutType(x.dtype),reduced=reduce(reshapedInput,outType,"sum",backend22),out=reshape3({inputs:{x:reduced},attrs:{shape:outShape},backend:backend22});return backend22.disposeIntermediateTensorInfo(reshapedInput),backend22.disposeIntermediateTensorInfo(reduced),sumInputIsTransposed&&backend22.disposeIntermediateTensorInfo(sumInput),out}function sum4(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{axis,keepDims}=attrs;return sumImpl(x,axis,keepDims,backend22)}var sumConfig2={kernelName:Sum,backendName:"webgl",kernelFunc:sum4};function transpose3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{perm}=attrs,webglBackend=backend22,xRank=x.shape.length,newShape=new Array(xRank);for(let i=0;i<newShape.length;i++)newShape[i]=x.shape[perm[i]];let out;if(webglBackend.shouldExecuteOnCPU([x])){let values=webglBackend.texData.get(x.dataId).values,outValues=transposeImplCPU(values,x.shape,x.dtype,perm,newShape);out=webglBackend.makeTensorInfo(newShape,x.dtype);let outData=webglBackend.texData.get(out.dataId);outData.values=outValues}else out=transposeImpl2(x,perm,webglBackend);return out}var transposeConfig2={kernelName:Transpose,backendName:"webgl",kernelFunc:transpose3},MATMUL_SHARED_DIM_THRESHOLD=1e3;function batchMatMulImpl({a,b,transposeA,transposeB,backend:backend22,bias=null,preluActivationWeights=null,leakyreluAlpha=0,activation:activation2=null}){let aRank=a.shape.length,bRank=b.shape.length,innerShapeA=transposeA?a.shape[aRank-2]:a.shape[aRank-1],innerShapeB=transposeB?b.shape[bRank-1]:b.shape[bRank-2],outerShapeA=transposeA?a.shape[aRank-1]:a.shape[aRank-2],outerShapeB=transposeB?b.shape[bRank-2]:b.shape[bRank-1],outerDimsA=a.shape.slice(0,-2),outerDimsB=b.shape.slice(0,-2),batchDimA=util_exports.sizeFromShape(outerDimsA),batchDimB=util_exports.sizeFromShape(outerDimsB),batchDimsCompatible=batchDimA===batchDimB||batchDimA===1||batchDimB===1;util_exports.assert(aRank>=2&&bRank>=2&&batchDimsCompatible,()=> ` Error in matMul : the input batch dimensions must either be the same or at least one input batch dimension must be 1. Got input batch dimensions of ( $ { outerDimsA } ) and ( $ { outerDimsB } ) . ` );let outShape=(batchDimA>batchDimB?a.shape.slice(0,-2):b.shape.slice(0,-2)).concat([outerShapeA,outerShapeB]);util_exports.assert(innerShapeA===innerShapeB,()=> ` Error in matMul : inner shapes ( $ { innerShapeA } ) and ( $ { innerShapeB } ) of Tensors with shapes $ { a . shape } and $ { b . shape } and transposeA = $ { transposeA } and transposeB = $ { transposeB } must match . ` );let a3dShape=transposeA?[batchDimA,innerShapeA,outerShapeA]:[batchDimA,outerShapeA,innerShapeA],b3dShape=transposeB?[batchDimB,outerShapeB,innerShapeB]:[batchDimB,innerShapeB,outerShapeB],a3d=reshape3({inputs:{x:a},backend:backend22,attrs:{shape:a3dShape}}),b3d=reshape3({inputs:{x:b},backend:backend22,attrs:{shape:b3dShape}}),intermediates=[a3d,b3d],batchDim=Math.max(batchDimA,batchDimB),sharedDim=transposeA?a3d.shape[1]:a3d.shape[2],hasBias=bias!=null,hasPreluActi
2021-01-03 16:41:56 +01:00
if ( abs ( x ) > 1. ) {
return NAN ;
}
return acos ( x ) ;
2021-01-13 17:14:23 +01:00
` ,acos3=unaryKernelFunc2({opSnippet:ACOS}),acosConfig2={kernelName:Acos,backendName:"webgl",kernelFunc:acos3},ACOSH=CHECK_NAN_SNIPPET+ `
2021-01-03 16:41:56 +01:00
if ( x < 1.0 ) return NAN ;
2021-01-13 17:14:23 +01:00
return log ( x + sqrt ( x * x - 1.0 ) ) ; ` ,acosh3=unaryKernelFunc2({opSnippet:ACOSH}),acoshConfig2={kernelName:Acosh,backendName:"webgl",kernelFunc:acosh3},ADD="return a + b;",addKernelFunc=binaryKernelFunc2({opSnippet:ADD,packedOpSnippet:ADD,supportsComplex:!0,cpuKernelImpl:addImplCPU}),addConfig2={kernelName:Add,backendName:"webgl",kernelFunc:addKernelFunc},AddNProgram=class{constructor(outputShape,shapes){this.outputShape=[],this.outputShape=outputShape,this.variableNames=shapes.map((_,i)=> ` T$ { i } ` );let snippets=[];this.variableNames.forEach(variable2=>{snippets.push( ` float v$ { variable2 } = get$ { variable2 } AtOutCoords ( ) ; ` )});let operation=this.variableNames.map(variable2=> ` v$ { variable2 } ` ).join(" + ");this.userCode= `
2020-12-15 14:44:42 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { snippets . join ( `
2021-01-03 16:41:56 +01:00
` )}
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
float result = $ { operation } ;
2021-01-03 16:41:56 +01:00
setOutput ( result ) ;
}
2021-01-13 17:14:23 +01:00
` }},AddNPackedProgram=class{constructor(outputShape,shapes){this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=outputShape,this.variableNames=shapes.map((_,i)=> ` T$ { i } ` );let snippets=[];this.variableNames.forEach(variable2=>{snippets.push( ` vec4 v$ { variable2 } = get$ { variable2 } AtOutCoords ( ) ; ` )});let operation=this.variableNames.map(variable2=> ` v$ { variable2 } ` ).join(" + ");this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { snippets . join ( `
2021-01-03 16:41:56 +01:00
` )}
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
vec4 result = $ { operation } ;
2021-01-03 16:41:56 +01:00
setOutput ( result ) ;
}
2021-01-13 17:14:23 +01:00
` }};function addN3(args){let{inputs,backend:backend22}=args,tensors=inputs;if(tensors.length===1)return identity2({inputs:{x:tensors[0]},backend:backend22});if(tensors.length>env().get("WEBGL_MAX_TEXTURES_IN_SHADER")){let midIndex=Math.floor(tensors.length/2),leftSide=addN3({inputs:tensors.slice(0,midIndex),backend:backend22}),rightSide=addN3({inputs:tensors.slice(midIndex),backend:backend22});return addN3({inputs:[leftSide,rightSide],backend:backend22})}let dtype=tensors.map(t=>t.dtype).reduce((d1,d2)=>upcastType(d1,d2)),shapes=tensors.map(t=>t.shape),program=env().getBool("WEBGL_PACK")?new AddNPackedProgram(tensors[0].shape,shapes):new AddNProgram(tensors[0].shape,shapes);return backend22.runWebGLProgram(program,tensors,dtype)}var addNConfig2={kernelName:AddN,backendName:"webgl",kernelFunc:addN3};function all3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{axis,keepDims}=attrs,xRank=x.shape.length,origAxes=util_exports.parseAxisParam(axis,x.shape),axes=origAxes,permutedAxes=backend_util_exports.getAxesPermutation(axes,xRank),permutedX=x;permutedAxes!=null&&(permutedX=transpose3({inputs:{x},backend:backend22,attrs:{perm:permutedAxes}}),axes=backend_util_exports.getInnerMostAxes(axes.length,xRank)),backend_util_exports.assertAxesAreInnerMostDims("all",axes,xRank);let[outShape,reduceShape]=backend_util_exports.computeOutAndReduceShapes(permutedX.shape,axes),inSize=util_exports.sizeFromShape(reduceShape),a2D=reshape3({inputs:{x:permutedX},backend:backend22,attrs:{shape:[-1,inSize]}}),reduced=reduce(a2D,a2D.dtype,"all",backend22),res;if(keepDims){let newShape=backend_util_exports.expandShapeToKeepDim(outShape,origAxes);res=reshape3({inputs:{x:reduced},backend:backend22,attrs:{shape:newShape}})}else res=reshape3({inputs:{x:reduced},backend:backend22,attrs:{shape:outShape}});return backend22.disposeIntermediateTensorInfo(a2D),backend22.disposeIntermediateTensorInfo(reduced),permutedAxes!=null&&backend22.disposeIntermediateTensorInfo(permutedX),res}var allConfig2={kernelName:All,backendName:"webgl",kernelFunc:all3};function any3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{axis,keepDims}=attrs,xRank=x.shape.length,origAxes=util_exports.parseAxisParam(axis,x.shape),axes=origAxes,permutedAxes=backend_util_exports.getAxesPermutation(axes,xRank),permutedX=x;permutedAxes!=null&&(permutedX=transpose3({inputs:{x},backend:backend22,attrs:{perm:permutedAxes}}),axes=backend_util_exports.getInnerMostAxes(axes.length,xRank)),backend_util_exports.assertAxesAreInnerMostDims("any",axes,xRank);let[outShape,reduceShape]=backend_util_exports.computeOutAndReduceShapes(permutedX.shape,axes),inSize=util_exports.sizeFromShape(reduceShape),a2D=reshape3({inputs:{x:permutedX},backend:backend22,attrs:{shape:[-1,inSize]}}),reduced=reduce(a2D,a2D.dtype,"any",backend22),res;if(keepDims){let newShape=backend_util_exports.expandShapeToKeepDim(outShape,origAxes);res=reshape3({inputs:{x:reduced},backend:backend22,attrs:{shape:newShape}})}else res=reshape3({inputs:{x:reduced},backend:backend22,attrs:{shape:outShape}});return backend22.disposeIntermediateTensorInfo(a2D),backend22.disposeIntermediateTensorInfo(reduced),permutedAxes!=null&&backend22.disposeIntermediateTensorInfo(permutedX),res}var anyConfig2={kernelName:Any,backendName:"webgl",kernelFunc:any3},ArgMinMaxProgram=class{constructor(reduceInfo,op2,firstPass){this.variableNames=["A"];let{windowSize,batchSize,outSize}=reduceInfo;firstPass||this.variableNames.push("bestIndicesA"),this.outputShape=[batchSize,outSize];let compOp=op2==="max"?">":"<",indexSnippet=firstPass?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
2021-01-13 17:14:23 +01:00
int inOffset = outIdx * $ { windowSize } ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
int bestIndex = inOffset ;
float bestValue = getA ( batch , bestIndex ) ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
for ( int i = 0 ; i < $ { windowSize } ; i ++ ) {
int inIdx = $ { indexSnippet } ;
2021-01-03 16:41:56 +01:00
float candidate = getA ( batch , inIdx ) ;
2021-01-13 17:14:23 +01:00
if ( candidate $ { compOp } bestValue ) {
2021-01-03 16:41:56 +01:00
bestValue = candidate ;
bestIndex = inIdx ;
2020-11-12 18:17:57 +01:00
}
}
2021-01-03 16:41:56 +01:00
setOutput ( float ( bestIndex ) ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }},ArgMinMaxPackedProgram=class{constructor(shape,windowSize,op2,firstPass){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,util_exports.assert(shape.length>2,()=> ` Packed arg$ { op2 . charAt ( 0 ) . toUpperCase ( ) + op2 . slice ( 1 ) } supports only inputs with rank above 2. ` );let inSize=shape[shape.length-1],outSize=Math.ceil(inSize/windowSize);this.outputShape=shape.slice(0,-1),outSize>1&&this.outputShape.push(outSize),firstPass||this.variableNames.push("bestIndicesA");let outShape=this.outputShape,rank=outShape.length,dtype=getCoordsDataType(rank),coords2=getChannels("coords",rank),sourceLocSetup,sourceRank;if(outSize===1){sourceRank=rank+1;let sourceLocDType=getCoordsDataType(sourceRank);sourceLocSetup= `
$ { sourceLocDType } sourceLocR = $ { sourceLocDType } ( $ { coords2 . join ( ) } , 0 ) ;
++ $ { coords2 [ rank - 1 ] } ;
$ { sourceLocDType } sourceLocG = $ { sourceLocDType } ( $ { coords2 . join ( ) } , 0 ) ;
++ $ { coords2 [ rank - 2 ] } ;
$ { sourceLocDType } sourceLocA = $ { sourceLocDType } ( $ { coords2 . join ( ) } , 0 ) ;
-- $ { coords2 [ rank - 1 ] } ;
$ { sourceLocDType } sourceLocB = $ { sourceLocDType } ( $ { coords2 . join ( ) } , 0 ) ;
-- $ { coords2 [ rank - 2 ] } ; ` }else sourceRank=rank,sourceLocSetup= `
$ { dtype } sourceLocR = coords ;
++ $ { coords2 [ rank - 1 ] } ;
$ { dtype } sourceLocG = coords ;
++ $ { coords2 [ rank - 2 ] } ;
$ { dtype } sourceLocA = coords ;
-- $ { coords2 [ rank - 1 ] } ;
$ { dtype } sourceLocB = coords ;
-- $ { coords2 [ rank - 2 ] } ; ` ;let channels=["x","y","z","w","u","v"].slice(0,sourceRank),inChannel="."+channels[sourceRank-1],intChannels=channels.map(x=>"int "+x),srcRCoords=getChannels("sourceLocR",sourceRank-1).concat("inIdx.r"),srcGCoords=getChannels("sourceLocG",sourceRank-1).concat("inIdx.g"),srcBCoords=getChannels("sourceLocB",sourceRank-1).concat("inIdx.b"),srcACoords=getChannels("sourceLocA",sourceRank-1).concat("inIdx.a"),compOp=op2==="max"?"greaterThan":"lessThan",fetchCandidateIdx=firstPass?"": `
inIdx = round ( vec4 ( getBestIndicesAChannel ( $ { srcRCoords . join ( ) } ) ,
getBestIndicesAChannel ( $ { srcGCoords . join ( ) } ) ,
getBestIndicesAChannel ( $ { srcBCoords . join ( ) } ) ,
getBestIndicesAChannel ( $ { srcACoords . join ( ) } ) ) ) ; ` ,fetchValue= ` vec4 (
getAChannel ( $ { srcRCoords . join ( ) } ) ,
hasNextCol ? getAChannel ( $ { srcGCoords . join ( ) } ) : 0. ,
hasNextRow ? getAChannel ( $ { srcBCoords . join ( ) } ) : 0. ,
hasNextRow && hasNextCol ? getAChannel ( $ { srcACoords . join ( ) } ) : 0. ) ` ,getBestIndicesAChannelSnippet=firstPass?"": `
float getBestIndicesAChannel ( $ { intChannels . join ( ) } ) {
return getChannel ( getBestIndicesA ( $ { channels . join ( ) } ) ,
vec2 ( $ { channels . slice ( - 2 ) . join ( ) } ) ) ;
2021-01-03 16:41:56 +01:00
} ` ;this.userCode= `
2021-01-13 17:14:23 +01:00
float getAChannel ( $ { intChannels . join ( ) } ) {
return getChannel ( getA ( $ { channels . join ( ) } ) ,
vec2 ( $ { channels . slice ( - 2 ) . join ( ) } ) ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
$ { getBestIndicesAChannelSnippet }
2020-11-16 21:51:46 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } coords = getOutputCoords ( ) ;
bool hasNextCol = $ { coords2 [ rank - 1 ] } < $ { outShape [ rank - 1 ] - 1 } ;
bool hasNextRow = $ { coords2 [ rank - 2 ] } < $ { outShape [ rank - 2 ] - 1 } ;
$ { sourceLocSetup }
ivec4 srcIdx = ivec4 ( sourceLocR$ { inChannel } , sourceLocG$ { inChannel } ,
sourceLocB$ { inChannel } , sourceLocA$ { inChannel } ) * $ { windowSize } ;
2021-01-03 16:41:56 +01:00
ivec4 inIdx = srcIdx ;
vec4 bestIndex = vec4 ( inIdx ) ;
2021-01-13 17:14:23 +01:00
vec4 bestValue = $ { fetchValue } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int i = 0 ; i < $ { windowSize } ; i ++ ) {
2021-01-03 16:41:56 +01:00
inIdx = srcIdx ;
2021-01-13 17:14:23 +01:00
$ { fetchCandidateIdx }
vec4 candidate = $ { fetchValue } ;
2021-01-03 16:41:56 +01:00
bvec4 nan = isnan ( candidate ) ;
bvec4 replace = bvec4 (
2021-01-13 17:14:23 +01:00
vec4 ( $ { compOp } ( candidate , bestValue ) ) * ( vec4 ( 1.0 ) - vec4 ( nan ) ) ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
bestValue = vec4 ( replace . x ? candidate . x : bestValue . x ,
replace . y ? candidate . y : bestValue . y ,
replace . z ? candidate . z : bestValue . z ,
replace . w ? candidate . w : bestValue . w ) ;
bestIndex = mix ( bestIndex , vec4 ( inIdx ) , vec4 ( replace ) ) ;
srcIdx ++ ;
}
setOutput ( bestIndex ) ;
}
2021-01-13 17:14:23 +01:00
` }};function argReduce(backend22,x,reduceType,bestIndicesA=null){let batchSize=x.shape[0],inSize=x.shape[1];bestIndicesA!=null&&(batchSize=bestIndicesA.shape[0],inSize=bestIndicesA.shape[1]);let windowSize=backend_util_exports.computeOptimalWindowSize(inSize),reduceInfo={windowSize,inSize,batchSize,outSize:Math.ceil(inSize/windowSize)},program=new ArgMinMaxProgram(reduceInfo,reduceType,bestIndicesA==null),inputs=[x];bestIndicesA!=null&&inputs.push(bestIndicesA);let output=backend22.runWebGLProgram(program,inputs,"int32");if(output.shape[1]===1)return output;let result=argReduce(backend22,x,reduceType,output);return backend22.disposeIntermediateTensorInfo(output),result}function argReducePacked(backend22,x,reduceType,bestIndicesA=null){let inShape=bestIndicesA!=null?bestIndicesA.shape:x.shape,inSize=inShape[inShape.length-1],windowSize=backend_util_exports.computeOptimalWindowSize(inSize),program=new ArgMinMaxPackedProgram(inShape,windowSize,reduceType,bestIndicesA==null),inputs=bestIndicesA==null?[x]:[x,bestIndicesA],output=backend22.runWebGLProgram(program,inputs,"int32");if(output.shape.length===x.shape.length){let result=argReducePacked(backend22,x,reduceType,output);return backend22.disposeIntermediateTensorInfo(output),result}return output}function argMinMaxReduce(backend22,x,axis,reduceType){let axes=[axis];if(backend_util_exports.assertAxesAreInnerMostDims("arg"+reduceType.charAt(0).toUpperCase()+reduceType.slice(1),axes,x.shape.length),!env().getBool("WEBGL_PACK_REDUCE")||x.shape.length<=2){let intermediateTensorInfos=[],[outShape,reduceShape]=backend_util_exports.computeOutAndReduceShapes(x.shape,axes),inSize=util_exports.sizeFromShape(reduceShape),a2D=reshape3({inputs:{x},backend:backend22,attrs:{shape:[-1,inSize]}});intermediateTensorInfos.push(a2D);let reduced=argReduce(backend22,a2D,reduceType);intermediateTensorInfos.push(reduced);let reshaped=reshape3({inputs:{x:reduced},backend:backend22,attrs:{shape:outShape}});return intermediateTensorInfos.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),reshaped}return argReducePacked(backend22,x,reduceType)}function argMax3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{axis}=attrs,axes=util_exports.parseAxisParam(axis,x.shape),permutedAxes=backend_util_exports.getAxesPermutation(axes,x.shape.length), $ x=x,intermediateTensorInfos=[];permutedAxes!=null&&( $ x=transpose3({inputs:{x},backend:backend22,attrs:{perm:permutedAxes}}),intermediateTensorInfos.push( $ x),axes=backend_util_exports.getInnerMostAxes(axes.length, $ x.shape.length)),backend_util_exports.assertAxesAreInnerMostDims("argMax",[axes[0]], $ x.shape.length);let out=argMinMaxReduce(backend22, $ x,axes[0],"max");return intermediateTensorInfos.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),out}var argMaxConfig2={kernelName:ArgMax,backendName:"webgl",kernelFunc:argMax3};function argMin3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{axis}=attrs,axes=util_exports.parseAxisParam(axis,x.shape),permutedAxes=backend_util_exports.getAxesPermutation(axes,x.shape.length), $ x=x,intermediateTensorInfos=[];permutedAxes!=null&&( $ x=transpose3({inputs:{x},backend:backend22,attrs:{perm:permutedAxes}}),intermediateTensorInfos.push( $ x),axes=backend_util_exports.getInnerMostAxes(axes.length, $ x.shape.length)),backend_util_exports.assertAxesAreInnerMostDims("argMin",[axes[0]], $ x.shape.length);let out=argMinMaxReduce(backend22, $ x,axes[0],"min");return intermediateTensorInfos.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),out}var argMinConfig2={kernelName:ArgMin,backendName:"webgl",kernelFunc:argMin3},ASIN=CHECK_NAN_SNIPPET+ `
2021-01-03 16:41:56 +01:00
if ( abs ( x ) > 1. ) {
return NAN ;
}
return asin ( x ) ;
2021-01-13 17:14:23 +01:00
` ,asin3=unaryKernelFunc2({opSnippet:ASIN}),asinConfig2={kernelName:Asin,backendName:"webgl",kernelFunc:asin3},ASINH=CHECK_NAN_SNIPPET+"return log(x + sqrt(x * x + 1.0));",asinh3=unaryKernelFunc2({opSnippet:ASINH}),asinhConfig2={kernelName:Asinh,backendName:"webgl",kernelFunc:asinh3},ATAN=CHECK_NAN_SNIPPET+ `
2021-01-03 16:41:56 +01:00
return atan ( x ) ;
2021-01-13 17:14:23 +01:00
` ,atan4=unaryKernelFunc2({opSnippet:ATAN}),atanConfig2={kernelName:Atan,backendName:"webgl",kernelFunc:atan4},ATAN2=CHECK_NAN_SNIPPET_BINARY+ `
2021-01-03 16:41:56 +01:00
return atan ( a , b ) ;
2021-01-13 17:14:23 +01:00
` ,ATAN2_PACKED= `
2021-01-03 16:41:56 +01:00
vec4 result = atan ( a , b ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
2021-01-13 17:14:23 +01:00
` +CHECK_NAN_SNIPPET_BINARY_PACKED+ `
2021-01-03 16:41:56 +01:00
return result ;
2021-01-13 17:14:23 +01:00
` ,atan23=binaryKernelFunc2({opSnippet:ATAN2,packedOpSnippet:ATAN2_PACKED}),atan2Config2={kernelName:Atan2,backendName:"webgl",kernelFunc:atan23},ATANH=CHECK_NAN_SNIPPET+ `
2021-01-03 16:41:56 +01:00
if ( ( x < - 1.0 ) || ( x > 1.0 ) ) return NAN ;
2021-01-13 17:14:23 +01:00
return ( log ( 1.0 + x ) - log ( 1.0 - x ) ) / 2.0 ; ` ,atanh3=unaryKernelFunc2({opSnippet:ATANH}),atanhConfig2={kernelName:Atanh,backendName:"webgl",kernelFunc:atanh3},Pool2DProgram=class{constructor(convInfo,poolType,computePositions,flattenPositions=!1,includeBatchInIndex=!1){if(this.variableNames=["x"],poolType==="avg"&&computePositions)throw new Error("Cannot compute positions for average pool.");let filterWidth=convInfo.filterWidth,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,dilationHeight=convInfo.dilationHeight,dilationWidth=convInfo.dilationWidth,effectiveFilterHeight=convInfo.effectiveFilterHeight,effectiveFilterWidth=convInfo.effectiveFilterWidth,padTop=convInfo.padInfo.top,padLeft=convInfo.padInfo.left;this.outputShape=convInfo.outShape;let isAvgPool=poolType==="avg",batchFlattenPositionStr= ` ( ( batch * $ { convInfo . inHeight } + xR ) * $ { convInfo . inWidth } + xC ) * $ { convInfo . inChannels } + d ` ,flattenPositionStr= ` ( xR * $ { convInfo . inWidth } + xC ) * $ { convInfo . inChannels } + d ` ,initializationValue="0.0";if(isAvgPool||(initializationValue="-1.0 / 1e-20"),computePositions){let compareOp2=">=";this.userCode= `
const ivec2 strides = ivec2 ( $ { strideHeight } , $ { strideWidth } ) ;
const ivec2 pads = ivec2 ( $ { padTop } , $ { padLeft } ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int d = coords [ 3 ] ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
ivec2 xRCCorner = coords . yz * strides - pads ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
float minMaxValue = 0.0 ;
float minMaxValueFound = 0.0 ;
int minMaxPosition = 0 ;
float avgValue = 0.0 ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { effectiveFilterHeight } ;
wR += $ { dilationHeight } ) {
2021-01-03 16:41:56 +01:00
int xR = xRCorner + wR ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( xR < 0 || xR >= $ { convInfo . inHeight } ) {
2020-11-16 21:51:46 +01:00
continue ;
}
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { effectiveFilterWidth } ;
wC += $ { dilationWidth } ) {
2021-01-03 16:41:56 +01:00
int xC = xCCorner + wC ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
if ( xC < 0 || xC >= $ { convInfo . inWidth } ) {
2020-11-16 21:51:46 +01:00
continue ;
}
2021-01-03 16:41:56 +01:00
float value = getX ( batch , xR , xC , d ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
// If a min / max value has already been found, use it. If not,
// use the current value.
float currMinMaxValue = mix (
value , minMaxValue , minMaxValueFound ) ;
2021-01-13 17:14:23 +01:00
if ( value $ { compareOp2 } currMinMaxValue ) {
2021-01-03 16:41:56 +01:00
minMaxValue = value ;
minMaxValueFound = 1.0 ;
2021-01-13 17:14:23 +01:00
minMaxPosition = $ { flattenPositions ? includeBatchInIndex ? batchFlattenPositionStr : flattenPositionStr : ` wR * ${ effectiveFilterWidth } + wC ` } ;
2020-12-15 14:44:42 +01:00
}
2020-11-16 21:51:46 +01:00
}
2020-11-12 18:58:55 +01:00
}
2021-01-03 16:41:56 +01:00
setOutput ( float ( minMaxPosition ) ) ;
2020-11-08 18:32:31 +01:00
}
2021-01-13 17:14:23 +01:00
` ;return}let compareOp="max",returnValue= ` $ { poolType } ( $ { poolType } ( $ { poolType } ( minMaxValue [ 0 ] , minMaxValue [ 1 ] ) , minMaxValue [ 2 ] ) , minMaxValue [ 3 ] ) ` ;poolType==="avg"&&(returnValue="avgValue / count");let filterWidthNearestVec4=Math.floor(filterWidth/4)*4,filterWidthVec4Remainder=filterWidth%4,updateSnippet= `
if ( $ { isAvgPool } ) {
2021-01-03 16:41:56 +01:00
avgValue += dot ( values , ones ) ;
} else {
2021-01-13 17:14:23 +01:00
minMaxValue = $ { compareOp } ( values , minMaxValue ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-03 16:41:56 +01:00
` ;this.userCode= `
2021-01-13 17:14:23 +01:00
const ivec2 strides = ivec2 ( $ { strideHeight } , $ { strideWidth } ) ;
const ivec2 pads = ivec2 ( $ { padTop } , $ { padLeft } ) ;
const float initializationValue = $ { initializationValue } ;
2021-01-03 16:41:56 +01:00
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
float count = 0.0 ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
float getValue ( int batch , int xR , int xC , int d ) {
2021-01-13 17:14:23 +01:00
if ( xC < 0 || xC >= $ { convInfo . inWidth } ) {
2021-01-03 16:41:56 +01:00
return initializationValue ;
}
count += 1.0 ;
return getX ( batch , xR , xC , d ) ;
}
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int d = coords [ 3 ] ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
ivec2 xRCCorner = coords . yz * strides - pads ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
2021-01-13 17:14:23 +01:00
vec4 minMaxValue = vec4 ( $ { initializationValue } ) ;
2021-01-03 16:41:56 +01:00
float avgValue = 0.0 ;
count = 0.0 ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { effectiveFilterHeight } ;
wR += $ { dilationHeight } ) {
2021-01-03 16:41:56 +01:00
int xR = xRCorner + wR ;
2021-01-13 17:14:23 +01:00
if ( xR < 0 || xR >= $ { convInfo . inHeight } ) {
2021-01-03 16:41:56 +01:00
continue ;
2020-12-16 20:49:14 +01:00
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { filterWidthNearestVec4 } ; wC += 4 ) {
int xC = xCCorner + wC * $ { dilationWidth } ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
2021-01-13 17:14:23 +01:00
getValue ( batch , xR , xC + $ { dilationWidth } , d ) ,
getValue ( batch , xR , xC + 2 * $ { dilationWidth } , d ) ,
getValue ( batch , xR , xC + 3 * $ { dilationWidth } , d )
2021-01-03 16:41:56 +01:00
) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
2021-01-03 16:41:56 +01:00
}
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
int xC = xCCorner + $ { filterWidthNearestVec4 } ;
if ( $ { filterWidthVec4Remainder === 1 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
} else if ( $ { filterWidthVec4Remainder === 2 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
2021-01-13 17:14:23 +01:00
getValue ( batch , xR , xC + $ { dilationWidth } , d ) ,
2021-01-03 16:41:56 +01:00
initializationValue ,
initializationValue
) ;
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
} else if ( $ { filterWidthVec4Remainder === 3 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
2021-01-13 17:14:23 +01:00
getValue ( batch , xR , xC + $ { dilationWidth } , d ) ,
getValue ( batch , xR , xC + 2 * $ { dilationWidth } , d ) ,
2021-01-03 16:41:56 +01:00
initializationValue
) ;
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
2020-11-10 02:13:38 +01:00
}
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
setOutput ( $ { returnValue } ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }},Pool3DProgram=class{constructor(convInfo,poolType,computePositions,flattenPositions=!1,includeBatchInIndex=!1){if(this.variableNames=["x"],poolType==="avg"&&computePositions)throw new Error("Cannot compute positions for average pool.");let filterWidth=convInfo.filterWidth,strideDepth=convInfo.strideDepth,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,dilationDepth=convInfo.dilationDepth,dilationHeight=convInfo.dilationHeight,dilationWidth=convInfo.dilationWidth,effectiveFilterDepth=convInfo.effectiveFilterDepth,effectiveFilterHeight=convInfo.effectiveFilterHeight,effectiveFilterWidth=convInfo.effectiveFilterWidth,padFront=convInfo.padInfo.front,padTop=convInfo.padInfo.top,padLeft=convInfo.padInfo.left;this.outputShape=convInfo.outShape;let isAvgPool=poolType==="avg",initializationValue="0.0";if(isAvgPool||(initializationValue="-1.0 / 1e-20"),computePositions){let compareOp2=">=";this.userCode= `
2021-01-03 16:41:56 +01:00
const ivec3 strides =
2021-01-13 17:14:23 +01:00
ivec3 ( $ { strideDepth } , $ { strideHeight } , $ { strideWidth } ) ;
const ivec3 pads = ivec3 ( $ { padFront } , $ { padTop } , $ { padLeft } ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
ivec3 xCorner = ivec3 ( coords . y , coords . z , coords . w ) * strides - pads ;
int xDCorner = xCorner . x ;
int xRCorner = xCorner . y ;
int xCCorner = xCorner . z ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
// max/min x(?, ?, ?, ch) to get y(yD, yR, yC, ch).
// ? = to be determined
float minMaxValue = 0.0 ;
float minMaxValueFound = 0.0 ;
int minMaxPosition = 0 ;
2021-01-13 17:14:23 +01:00
for ( int wD = 0 ; wD < $ { effectiveFilterDepth } ;
wD += $ { dilationDepth } ) {
2021-01-03 16:41:56 +01:00
int xD = xDCorner + wD ;
2021-01-13 17:14:23 +01:00
if ( xD < 0 || xD >= $ { convInfo . inDepth } ) {
2020-12-16 20:49:14 +01:00
continue ;
}
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { effectiveFilterHeight } ;
wR += $ { dilationHeight } ) {
2021-01-03 16:41:56 +01:00
int xR = xRCorner + wR ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
if ( xR < 0 || xR >= $ { convInfo . inHeight } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { effectiveFilterWidth } ;
wC += $ { dilationWidth } ) {
2021-01-03 16:41:56 +01:00
int xC = xCCorner + wC ;
2021-01-13 17:14:23 +01:00
if ( xC < 0 || xC >= $ { convInfo . inWidth } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
float value = getX ( batch , xD , xR , xC , ch ) ;
// If a min / max value has already been found, use it. If not,
// use the current value.
float currMinMaxValue = mix (
value , minMaxValue , minMaxValueFound ) ;
2021-01-13 17:14:23 +01:00
if ( value $ { compareOp2 } currMinMaxValue ) {
2021-01-03 16:41:56 +01:00
minMaxValue = value ;
minMaxValueFound = 1.0 ;
2021-01-13 17:14:23 +01:00
minMaxPosition = $ { flattenPositions ? includeBatchInIndex ? ` (((batch * ${ convInfo . inDepth } + xD) * ${ convInfo . inHeight } + xR) * ${ convInfo . inWidth } + xC) * ${ convInfo . inChannels } + ch ` : ` ((xD * ${ convInfo . inHeight } + xR) * ${ convInfo . inWidth } + xC) * ${ convInfo . inChannels } + ch ` : ` wD * ${ effectiveFilterHeight } * ${ effectiveFilterWidth } +
wR * $ { effectiveFilterWidth } + wC ` };
2021-01-03 16:41:56 +01:00
}
}
2020-12-16 20:49:14 +01:00
}
2020-11-10 02:13:38 +01:00
}
2021-01-03 16:41:56 +01:00
setOutput ( float ( minMaxPosition ) ) ;
2020-11-08 18:32:31 +01:00
}
2021-01-13 17:14:23 +01:00
` ;return}let compareOp="max",returnValue= ` $ { poolType } ( $ { poolType } ( $ { poolType } ( minMaxValue [ 0 ] , minMaxValue [ 1 ] ) , minMaxValue [ 2 ] ) , minMaxValue [ 3 ] ) ` ;poolType==="avg"&&(returnValue="avgValue / count");let filterWidthNearestVec4=Math.floor(filterWidth/4)*4,filterWidthVec4Remainder=filterWidth%4,updateSnippet= `
if ( $ { isAvgPool } ) {
2021-01-03 16:41:56 +01:00
avgValue += dot ( values , ones ) ;
} else {
2021-01-13 17:14:23 +01:00
minMaxValue = $ { compareOp } ( values , minMaxValue ) ;
2020-11-08 18:32:31 +01:00
}
2021-01-03 16:41:56 +01:00
` ;this.userCode= `
const ivec3 strides =
2021-01-13 17:14:23 +01:00
ivec3 ( $ { strideDepth } , $ { strideHeight } , $ { strideWidth } ) ;
const ivec3 pads = ivec3 ( $ { padFront } , $ { padTop } , $ { padLeft } ) ;
const float initializationValue = $ { initializationValue } ;
2021-01-03 16:41:56 +01:00
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
float count = 0.0 ;
float getValue ( int batch , int xD , int xR , int xC , int ch ) {
2021-01-13 17:14:23 +01:00
if ( xC < 0 || xC >= $ { convInfo . inWidth } ) {
2021-01-03 16:41:56 +01:00
return initializationValue ;
}
count += 1.0 ;
return getX ( batch , xD , xR , xC , ch ) ;
}
2020-11-16 21:51:46 +01:00
2020-12-16 20:49:14 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
ivec3 xCorner = ivec3 ( coords . y , coords . z , coords . w ) * strides - pads ;
int xDCorner = xCorner . x ;
int xRCorner = xCorner . y ;
int xCCorner = xCorner . z ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
// max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).
// ? = to be determined
2021-01-13 17:14:23 +01:00
vec4 minMaxValue = vec4 ( $ { initializationValue } ) ;
2021-01-03 16:41:56 +01:00
float avgValue = 0.0 ;
count = 0.0 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int wD = 0 ; wD < $ { effectiveFilterDepth } ;
wD += $ { dilationDepth } ) {
2021-01-03 16:41:56 +01:00
int xD = xDCorner + wD ;
2021-01-13 17:14:23 +01:00
if ( xD < 0 || xD >= $ { convInfo . inDepth } ) {
2020-12-16 20:49:14 +01:00
continue ;
}
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { effectiveFilterHeight } ;
wR += $ { dilationHeight } ) {
2021-01-03 16:41:56 +01:00
int xR = xRCorner + wR ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
if ( xR < 0 || xR >= $ { convInfo . inHeight } ) {
2020-11-16 21:51:46 +01:00
continue ;
}
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { filterWidthNearestVec4 } ; wC += 4 ) {
int xC = xCCorner + wC * $ { dilationWidth } ;
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
2021-01-13 17:14:23 +01:00
getValue ( batch , xD , xR , xC + $ { dilationWidth } , ch ) ,
getValue ( batch , xD , xR , xC + 2 * $ { dilationWidth } , ch ) ,
getValue ( batch , xD , xR , xC + 3 * $ { dilationWidth } , ch )
2020-12-16 20:49:14 +01:00
) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
2020-12-16 20:49:14 +01:00
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
int xC = xCCorner + $ { filterWidthNearestVec4 } ;
if ( $ { filterWidthVec4Remainder === 1 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
initializationValue ,
initializationValue ,
initializationValue
2020-12-16 20:49:14 +01:00
) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
} else if ( $ { filterWidthVec4Remainder === 2 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
2021-01-13 17:14:23 +01:00
getValue ( batch , xD , xR , xC + $ { dilationWidth } , ch ) ,
2021-01-03 16:41:56 +01:00
initializationValue ,
initializationValue
2020-12-16 20:49:14 +01:00
) ;
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
} else if ( $ { filterWidthVec4Remainder === 3 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
2021-01-13 17:14:23 +01:00
getValue ( batch , xD , xR , xC + $ { dilationWidth } , ch ) ,
getValue ( batch , xD , xR , xC + 2 * $ { dilationWidth } , ch ) ,
2021-01-03 16:41:56 +01:00
initializationValue
) ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
2020-11-16 21:51:46 +01:00
}
2020-11-08 18:32:31 +01:00
}
2021-01-13 17:14:23 +01:00
setOutput ( $ { returnValue } ) ;
2020-11-10 02:13:38 +01:00
}
2020-12-15 14:44:42 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function avgPool3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs;assertNotComplex2(x,"avgPool");let{filterSize,strides,pad:pad3,dimRoundingMode}=attrs,dilations=1;util_exports.assert(backend_util_exports.eitherStridesOrDilationsAreOne(strides,dilations),()=> ` Error in avgPool : Either strides or dilations must be 1. Got strides $ { strides } and dilations '${dilations}' ` );let convInfo=backend_util_exports.computePool2DInfo(x.shape,filterSize,strides,dilations,pad3,dimRoundingMode);if(convInfo.filterWidth===1&&convInfo.filterHeight===1&&util_exports.arraysEqual(convInfo.inShape,convInfo.outShape))return identity2({inputs:{x},backend:backend22});let avgPoolProgram=new Pool2DProgram(convInfo,"avg",!1);return backend22.runWebGLProgram(avgPoolProgram,[x],"float32")}var avgPoolConfig2={kernelName:AvgPool,backendName:"webgl",kernelFunc:avgPool3};function avgPool3D2(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{filterSize,strides,pad:pad3,dimRoundingMode,dataFormat}=attrs,dilations=[1,1,1],convInfo=backend_util_exports.computePool3DInfo(x.shape,filterSize,strides,dilations,pad3,dimRoundingMode,dataFormat),avgPoolProgram=new Pool3DProgram(convInfo,"avg",!1);return backend22.runWebGLProgram(avgPoolProgram,[x],"float32")}var avgPool3DConfig2={kernelName:AvgPool3D,backendName:"webgl",kernelFunc:avgPool3D2},AvgPool2DBackpropProgram=class{constructor(convInfo){this.variableNames=["dy"],this.outputShape=convInfo.inShape;let filterHeight=convInfo.filterHeight,filterWidth=convInfo.filterWidth,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,dilationHeight=convInfo.dilationHeight,dilationWidth=convInfo.dilationWidth,effectiveFilterHeight=convInfo.effectiveFilterHeight,effectiveFilterWidth=convInfo.effectiveFilterWidth,padTop=effectiveFilterHeight-1-convInfo.padInfo.top,padLeft=effectiveFilterWidth-1-convInfo.padInfo.left,avgMultiplier=1/(filterHeight*filterWidth);this.userCode= `
const ivec2 pads = ivec2 ( $ { padTop } , $ { padLeft } ) ;
const float avgMultiplier = float ( $ { avgMultiplier } ) ;
2020-11-16 21:51:46 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
ivec2 dyRCCorner = coords . yz - pads ;
int dyRCorner = dyRCCorner . x ;
int dyCCorner = dyRCCorner . y ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
// Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).
// ? = to be determined. : = across all values in that axis.
2020-12-16 20:49:14 +01:00
float dotProd = 0.0 ;
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { effectiveFilterHeight } ;
wR += $ { dilationHeight } ) {
float dyR = float ( dyRCorner + wR ) / $ { strideHeight } . 0 ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
if ( dyR < 0.0 || dyR >= $ { convInfo . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
2020-11-16 21:51:46 +01:00
continue ;
2020-11-12 18:58:55 +01:00
}
2021-01-03 16:41:56 +01:00
int idyR = int ( dyR ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { effectiveFilterWidth } ;
wC += $ { dilationWidth } ) {
float dyC = float ( dyCCorner + wC ) / $ { strideWidth } . 0 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( dyC < 0.0 || dyC >= $ { convInfo . outWidth } . 0 ||
2021-01-03 16:41:56 +01:00
fract ( dyC ) > 0.0 ) {
2020-11-16 21:51:46 +01:00
continue ;
2020-11-10 02:13:38 +01:00
}
2021-01-03 16:41:56 +01:00
int idyC = int ( dyC ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
float dyValue = getDy ( b , idyR , idyC , d ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
dotProd += dyValue * avgMultiplier ;
2020-11-06 22:21:20 +01:00
}
2020-11-12 18:58:55 +01:00
}
2020-12-16 20:49:14 +01:00
setOutput ( dotProd ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }},AvgPool3DBackpropProgram=class{constructor(convInfo){this.variableNames=["dy"],this.outputShape=convInfo.inShape;let filterDepth=convInfo.filterDepth,filterHeight=convInfo.filterHeight,filterWidth=convInfo.filterWidth,strideDepth=convInfo.strideDepth,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,dilationDepth=convInfo.dilationDepth,dilationHeight=convInfo.dilationHeight,dilationWidth=convInfo.dilationWidth,effectiveFilterDepth=convInfo.effectiveFilterDepth,effectiveFilterHeight=convInfo.effectiveFilterHeight,effectiveFilterWidth=convInfo.effectiveFilterWidth,padFront=effectiveFilterDepth-1-convInfo.padInfo.front,padTop=effectiveFilterHeight-1-convInfo.padInfo.top,padLeft=effectiveFilterWidth-1-convInfo.padInfo.left,avgMultiplier=1/(filterDepth*filterHeight*filterWidth);this.userCode= `
const ivec3 pads = ivec3 ( $ { padFront } , $ { padTop } , $ { padLeft } ) ;
const float avgMultiplier = float ( $ { avgMultiplier } ) ;
2020-11-16 21:51:46 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec5 coords = getOutputCoords ( ) ;
2020-12-16 20:49:14 +01:00
int batch = coords . x ;
2021-01-03 16:41:56 +01:00
int ch = coords . u ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
ivec3 dyCorner = ivec3 ( coords . y , coords . z , coords . w ) - pads ;
int dyDCorner = dyCorner . x ;
int dyRCorner = dyCorner . y ;
int dyCCorner = dyCorner . z ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
// Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get
// dx(xD, xR, xC, ch).
2020-11-16 21:51:46 +01:00
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
2021-01-13 17:14:23 +01:00
for ( int wD = 0 ; wD < $ { effectiveFilterDepth } ;
wD += $ { dilationDepth } ) {
float dyD = float ( dyDCorner + wD ) / $ { strideDepth } . 0 ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
if ( dyD < 0.0 || dyD >= $ { convInfo . outDepth } . 0 || fract ( dyD ) > 0.0 ) {
2020-11-16 21:51:46 +01:00
continue ;
}
2021-01-03 16:41:56 +01:00
int idyD = int ( dyD ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { effectiveFilterHeight } ;
wR += $ { dilationHeight } ) {
float dyR = float ( dyRCorner + wR ) / $ { strideHeight } . 0 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( dyR < 0.0 || dyR >= $ { convInfo . outHeight } . 0 ||
2021-01-03 16:41:56 +01:00
fract ( dyR ) > 0.0 ) {
2020-11-16 21:51:46 +01:00
continue ;
}
2021-01-03 16:41:56 +01:00
int idyR = int ( dyR ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { effectiveFilterWidth } ;
wC += $ { dilationWidth } ) {
float dyC = float ( dyCCorner + wC ) / $ { strideWidth } . 0 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( dyC < 0.0 || dyC >= $ { convInfo . outWidth } . 0 ||
2021-01-03 16:41:56 +01:00
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
float dyValue = getDy ( batch , idyD , idyR , idyC , ch ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
dotProd += dyValue * avgMultiplier ;
}
}
}
setOutput ( dotProd ) ;
}
2021-01-13 17:14:23 +01:00
` }};function avgPool3DGrad2(args){let{inputs,backend:backend22,attrs}=args,{dy,input:input2}=inputs,x=input2,{filterSize,strides,pad:pad3,dimRoundingMode}=attrs,dilations=[1,1,1],convInfo=backend_util_exports.computePool3DInfo(x.shape,filterSize,strides,dilations,pad3,dimRoundingMode),avgPoolBackpropProgram=new AvgPool3DBackpropProgram(convInfo);return backend22.runWebGLProgram(avgPoolBackpropProgram,[dy],x.dtype)}var avgPoolGrad3DConfig={kernelName:AvgPool3DGrad,backendName:"webgl",kernelFunc:avgPool3DGrad2};function avgPoolGrad3(args){let{inputs,backend:backend22,attrs}=args,{dy,input:input2}=inputs,x=input2;assertNotComplex2([dy,input2],"avgPoolGrad");let{filterSize,strides,pad:pad3}=attrs,convInfo=backend_util_exports.computePool2DInfo(x.shape,filterSize,strides,1,pad3),avgPoolBackpropProgram=new AvgPool2DBackpropProgram(convInfo);return backend22.runWebGLProgram(avgPoolBackpropProgram,[dy],x.dtype)}var avgPoolGradConfig3={kernelName:AvgPoolGrad,backendName:"webgl",kernelFunc:avgPoolGrad3};function batchMatMul2(args){let{inputs,backend:backend22,attrs}=args,{a,b}=inputs,{transposeA,transposeB}=attrs;return batchMatMulImpl({a,b,transposeA,transposeB,backend:backend22})}var batchMatMulConfig2={kernelName:BatchMatMul,backendName:"webgl",kernelFunc:batchMatMul2},BatchNormProgram=class{constructor(xShape,meanShape,varianceShape,offsetShape,scaleShape,varianceEpsilon){this.outputShape=[],this.variableNames=["x","mean","variance"],backend_util_exports.assertAndGetBroadcastShape(xShape,meanShape),backend_util_exports.assertAndGetBroadcastShape(xShape,varianceShape);let offsetSnippet="0.0";offsetShape!=null&&(backend_util_exports.assertAndGetBroadcastShape(xShape,offsetShape),this.variableNames.push("offset"),offsetSnippet="getOffsetAtOutCoords()");let scaleSnippet="1.0";scaleShape!=null&&(backend_util_exports.assertAndGetBroadcastShape(xShape,scaleShape),this.variableNames.push("scale"),scaleSnippet="getScaleAtOutCoords()"),this.outputShape=xShape,this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
float x = getXAtOutCoords ( ) ;
float mean = getMeanAtOutCoords ( ) ;
float variance = getVarianceAtOutCoords ( ) ;
2021-01-13 17:14:23 +01:00
float offset = $ { offsetSnippet } ;
float scale = $ { scaleSnippet } ;
float inv = scale * inversesqrt ( variance + float ( $ { varianceEpsilon } ) ) ;
2021-01-03 16:41:56 +01:00
setOutput ( dot ( vec3 ( x , - mean , offset ) , vec3 ( inv , inv , 1 ) ) ) ;
}
2021-01-13 17:14:23 +01:00
` }},BatchNormPackedProgram=class{constructor(xShape,meanShape,varianceShape,offsetShape,scaleShape,varianceEpsilon){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],backend_util_exports.assertAndGetBroadcastShape(xShape,meanShape),backend_util_exports.assertAndGetBroadcastShape(xShape,varianceShape);let offsetSnippet="vec4(0.0)";offsetShape!=null&&(backend_util_exports.assertAndGetBroadcastShape(xShape,offsetShape),this.variableNames.push("offset"),offsetSnippet="getOffsetAtOutCoords()");let scaleSnippet="vec4(1.0)";scaleShape!=null&&(backend_util_exports.assertAndGetBroadcastShape(xShape,scaleShape),this.variableNames.push("scale"),scaleSnippet="getScaleAtOutCoords()"),this.outputShape=xShape,this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
vec4 offset = $ { offsetSnippet } ;
vec4 scale = $ { scaleSnippet } ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
vec4 x = getXAtOutCoords ( ) ;
vec4 mean = getMeanAtOutCoords ( ) ;
vec4 variance = getVarianceAtOutCoords ( ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
vec4 inv = scale * inversesqrt ( variance + vec4 ( $ { varianceEpsilon } ) ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
setOutput ( ( x - mean ) * inv + offset ) ;
}
2021-01-13 17:14:23 +01:00
` }},batchNorm3=({inputs,backend:backend22,attrs})=>{let{x,mean:mean4,variance,offset,scale:scale2}=inputs;util_exports.assert(mean4.shape.length===variance.shape.length,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),util_exports.assert(offset==null||mean4.shape.length===offset.shape.length,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),util_exports.assert(scale2==null||mean4.shape.length===scale2.shape.length,()=>"Batch normalization gradient requires mean and scale to have equal ranks.");let{varianceEpsilon}=attrs;varianceEpsilon==null&&(varianceEpsilon=.001);let finalInputs=[x,mean4,variance],offsetShape=null;offset!=null&&(offsetShape=offset.shape,finalInputs.push(offset));let scaleShape=null;scale2!=null&&(scaleShape=scale2.shape,finalInputs.push(scale2));let program=env().getBool("WEBGL_PACK_NORMALIZATION")?new BatchNormPackedProgram(x.shape,mean4.shape,variance.shape,offsetShape,scaleShape,varianceEpsilon):new BatchNormProgram(x.shape,mean4.shape,variance.shape,offsetShape,scaleShape,varianceEpsilon);return backend22.runWebGLProgram(program,finalInputs,finalInputs[0].dtype)},batchNormConfig2={kernelName:FusedBatchNorm,backendName:"webgl",kernelFunc:batchNorm3},SliceProgram=class{constructor(destSize){this.variableNames=["source"],this.outputShape=destSize,this.rank=destSize.length;let dtype=getCoordsDataType(this.rank),uniformPart= ` uniform int start [ $ { this . rank } ] ; ` ,sourceCoords=getCoords(this.rank),body3,coordSum=destSize.map((_,i)=> ` sourceLoc . $ { coords [ i ] } = start [ $ { i } ] + coords . $ { coords [ i ] } ; ` );body3= `
$ { dtype } sourceLoc ;
$ { dtype } coords = getOutputCoords ( ) ;
$ { coordSum . join ( `
2021-01-03 16:41:56 +01:00
` )}
` ,this.userCode= `
2021-01-13 17:14:23 +01:00
$ { uniformPart }
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { body3 }
setOutput ( getSource ( $ { sourceCoords } ) ) ;
}
` }getCustomSetupFunc(start){if(start.length!==this.rank)throw Error( ` The rank ( $ { this . rank } ) of the program must match the length of start ( $ { start . length } ) ` );return(gpgpu,webGLProgram)=>{this.startLoc==null&&(this.startLoc=gpgpu.getUniformLocationNoThrow(webGLProgram,"start"),this.startLoc==null)||gpgpu.gl.uniform1iv(this.startLoc,start)}}},coords=["x","y","z","w","u","v"];function getCoords(rank){if(rank===1)return"sourceLoc";if(rank<=6)return coords.slice(0,rank).map(x=>"sourceLoc."+x).join(",");throw Error( ` Slicing for rank $ { rank } is not yet supported ` )}var SlicePackedProgram=class{constructor(destSize){this.variableNames=["source"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=destSize,this.rank=destSize.length;let dtype=getCoordsDataType(this.rank),coords2=getChannels("coords",this.rank),sourceLoc=getChannels("sourceLoc",this.rank),innerDims=this.rank===1?"sourceLoc": ` vec2 ( $ { sourceLoc . slice ( - 2 ) . join ( ) } ) ` ,getChannel= ` getChannel ( getSource ( $ { sourceLoc . join ( ) } ) , $ { innerDims } ) ` ,upperRow= `
result . x = $ { getChannel } ;
if ( ++ $ { coords2 [ this . rank - 1 ] } < $ { destSize [ this . rank - 1 ] } ) {
++ $ { sourceLoc [ this . rank - 1 ] } ;
result . y = $ { getChannel } ;
-- $ { sourceLoc [ this . rank - 1 ] } ;
}
` ,lowerRow=this.rank===1?"": `
-- $ { coords2 [ this . rank - 1 ] } ;
if ( ++ $ { coords2 [ this . rank - 2 ] } < $ { destSize [ this . rank - 2 ] } ) {
++ $ { sourceLoc [ this . rank - 2 ] } ;
result . z = $ { getChannel } ;
if ( ++ $ { coords2 [ this . rank - 1 ] } < $ { destSize [ this . rank - 1 ] } ) {
++ $ { sourceLoc [ this . rank - 1 ] } ;
result . w = $ { getChannel } ;
2021-01-03 16:41:56 +01:00
}
}
2021-01-13 17:14:23 +01:00
` ,sourceLocSetup=this.rank<=4? ` sourceLoc = coords +
$ { dtype } ( $ { destSize . map ( ( _ , i ) => ` start[ ${ i } ] ` ) . join ( ) } ) ; ` :destSize.map((_,i)=> ` $ { sourceLoc [ i ] } = $ { coords2 [ i ] } + start [ $ { i } ] ; ` ).join( `
2021-01-03 16:41:56 +01:00
` );this.userCode= `
uniform int start [ $ { this . rank } ] ;
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } coords = getOutputCoords ( ) ;
$ { dtype } sourceLoc ;
$ { sourceLocSetup }
2021-01-03 16:41:56 +01:00
vec4 result = vec4 ( 0. ) ;
2021-01-13 17:14:23 +01:00
$ { upperRow }
$ { lowerRow }
2021-01-03 16:41:56 +01:00
setOutput ( result ) ;
}
2021-01-13 17:14:23 +01:00
` }getCustomSetupFunc(start){if(start.length!==this.rank)throw Error( ` The rank ( $ { this . rank } ) of the program must match the length of start ( $ { start . length } ) ` );return(gpgpu,webGLProgram)=>{this.startLoc==null&&(this.startLoc=gpgpu.getUniformLocationNoThrow(webGLProgram,"start"),this.startLoc==null)||gpgpu.gl.uniform1iv(this.startLoc,start)}}};function shallowSlice(x,begin,size,backend22){let xTexData=backend22.texData.get(x.dataId),t=backend22.makeTensorInfo(size,x.dtype),newTexData=backend22.texData.get(t.dataId);Object.assign(newTexData,xTexData),newTexData.shape=size,newTexData.dtype=x.dtype;let flatOffset=slice_util_exports.computeFlatOffset(begin,util_exports.computeStrides(x.shape));xTexData.slice&&(flatOffset+=xTexData.slice.flatOffset),newTexData.slice={flatOffset,origDataId:xTexData.slice&&xTexData.slice.origDataId||x.dataId};let refCount=backend22.dataRefCount.get(newTexData.slice.origDataId)||1;return backend22.dataRefCount.set(newTexData.slice.origDataId,refCount+1),t}function slice3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{begin,size}=attrs,[ $ begin, $ size]=slice_util_exports.parseSliceParams(x,begin,size);if(slice_util_exports.assertParamsValid(x, $ begin, $ size),util_exports.sizeFromShape( $ size)===0)return backend22.makeTensorInfo( $ size,x.dtype,[]);if(backend22.shouldExecuteOnCPU([x])||x.dtype==="string"){let xTexData=backend22.texData.get(x.dataId),outValues=sliceImplCPU(xTexData.values, $ begin, $ size,x.shape,x.dtype);return backend22.makeTensorInfo( $ size,x.dtype,outValues)}let{isPacked}=backend22.texData.get(x.dataId),isContinous=slice_util_exports.isSliceContinous(x.shape, $ begin, $ size);if(isPacked||!isContinous){let program=env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new SlicePackedProgram( $ size):new SliceProgram( $ size),customSetup=program.getCustomSetupFunc( $ begin);return backend22.runWebGLProgram(program,[x],x.dtype,customSetup)}return backend22.uploadToGPU(x.dataId),shallowSlice(x, $ begin, $ size,backend22)}var sliceConfig2={kernelName:Slice,backendName:"webgl",kernelFunc:slice3},batchToSpaceND3=args=>{let{inputs,backend:backend22,attrs}=args,{x}=inputs,{blockShape,crops}=attrs;util_exports.assert(x.shape.length<=4,()=>"batchToSpaceND for rank > 4 with a WebGL backend not implemented yet");let prod5=blockShape.reduce((a,b)=>a*b),reshaped=backend_util_exports.getReshaped(x.shape,blockShape,prod5),permuted=backend_util_exports.getPermuted(reshaped.length,blockShape.length),reshapedPermuted=backend_util_exports.getReshapedPermuted(x.shape,blockShape,prod5),sliceBeginCoords=backend_util_exports.getSliceBeginCoords(crops,blockShape.length),sliceSize=backend_util_exports.getSliceSize(reshapedPermuted,crops,blockShape.length),toDispose=[],reshapedIntermediate=reshape3({inputs:{x},backend:backend22,attrs:{shape:reshaped}}),transposedIntermediate=transpose3({inputs:{x:reshapedIntermediate},backend:backend22,attrs:{perm:permuted}}),reshapedIntermediate2=reshape3({inputs:{x:transposedIntermediate},backend:backend22,attrs:{shape:reshapedPermuted}}),sliced=slice3({inputs:{x:reshapedIntermediate2},backend:backend22,attrs:{begin:sliceBeginCoords,size:sliceSize}});return toDispose.push(reshapedIntermediate),toDispose.push(transposedIntermediate),toDispose.push(reshapedIntermediate2),toDispose.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),sliced},batchToSpaceNDConfig2={kernelName:BatchToSpaceND,backendName:"webgl",kernelFunc:batchToSpaceND3};function bincount3(args){let{inputs,backend:backend22,attrs}=args,{x,weights}=inputs,{size}=attrs,xVals=backend22.readSync(x.dataId),weightsVals=backend22.readSync(weights.dataId),outVals=bincountImplCPU(xVals,weightsVals,weights.dtype,weights.shape,size);return backend22.makeTensorInfo([size],weights.dtype,outVals)}var bincountConfig2={kernelName:Bincount,backendName:"webgl",kernelFunc:bincount3},NOT_EQUAL="return float(a != b);",notEqual3=binaryKernelFunc2({opSnippet:NOT_EQUAL,dtype:"bool"}),notEqualConfig2={kernelName:NotEqual,backendName:"webgl",kernelFunc:notEqual3};function real3(args){let{inputs,backend:backend22}=args,{input:input2}=inputs,inputData=
2021-01-03 16:41:56 +01:00
uniform float minVal ;
uniform float maxVal ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
void main ( ) {
float value = getAAtOutCoords ( ) ;
if ( isnan ( value ) ) {
setOutput ( value ) ;
return ;
}
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
setOutput ( clamp ( value , minVal , maxVal ) ) ;
}
2021-01-13 17:14:23 +01:00
` }getCustomSetupFunc(min6,max6){return(gpgpu,webGLProgram)=>{this.minLoc==null&&(this.minLoc=gpgpu.getUniformLocationNoThrow(webGLProgram,"minVal"),this.maxLoc=gpgpu.getUniformLocationNoThrow(webGLProgram,"maxVal")),gpgpu.gl.uniform1f(this.minLoc,min6),gpgpu.gl.uniform1f(this.maxLoc,max6)}}},ClipPackedProgram=class{constructor(aShape){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=aShape,this.userCode= `
2021-01-03 16:41:56 +01:00
uniform float minVal ;
uniform float maxVal ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
void main ( ) {
vec4 value = getAAtOutCoords ( ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
if ( any ( isnan ( value ) ) ) {
setOutput ( value ) ;
return ;
}
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
setOutput ( clamp ( value , vec4 ( minVal ) , vec4 ( maxVal ) ) ) ;
}
2021-01-13 17:14:23 +01:00
` }getCustomSetupFunc(min6,max6){return(gpgpu,webGLProgram)=>{this.minLoc==null&&(this.minLoc=gpgpu.getUniformLocationNoThrow(webGLProgram,"minVal"),this.maxLoc=gpgpu.getUniformLocationNoThrow(webGLProgram,"maxVal")),gpgpu.gl.uniform1f(this.minLoc,min6),gpgpu.gl.uniform1f(this.maxLoc,max6)}}};function clipByValue2(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{clipValueMin,clipValueMax}=attrs,program;env().getBool("WEBGL_PACK_CLIP")?program=new ClipPackedProgram(x.shape):program=new ClipProgram(x.shape);let customSetup=program.getCustomSetupFunc(clipValueMin,clipValueMax);return backend22.runWebGLProgram(program,[x],x.dtype,customSetup)}var clipByValueConfig={kernelName:ClipByValue,backendName:"webgl",kernelFunc:clipByValue2},ComplexAbsProgram=class{constructor(shape){this.variableNames=["real","imag"],this.outputShape=shape,this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
float re = abs ( getRealAtOutCoords ( ) ) ;
float im = abs ( getImagAtOutCoords ( ) ) ;
float mx = max ( re , im ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
// sadly the length function in glsl is not underflow-safe
// (at least not on Intel GPUs). So the safe solution is
// to ensure underflow-safety in all cases.
setOutput (
mx == 0.0 ? 0.0 : mx * length ( vec2 ( 1 , min ( re , im ) / mx ) )
) ;
}
2021-01-13 17:14:23 +01:00
` }};function makeComplexComponentTensorInfo(complexTensor,complexPart){return{dataId:complexPart.dataId,dtype:complexPart.dtype,shape:complexTensor.shape}}function complexAbs2(args){let{inputs,backend:backend22}=args,{x}=inputs,xData=backend22.texData.get(x.dataId),program=new ComplexAbsProgram(x.shape),programInputs=[makeComplexComponentTensorInfo(x,xData.complexTensorInfos.real),makeComplexComponentTensorInfo(x,xData.complexTensorInfos.imag)];return backend22.runWebGLProgram(program,programInputs,programInputs[0].dtype)}var complexAbsConfig2={kernelName:ComplexAbs,backendName:"webgl",kernelFunc:complexAbs2},ConcatProgram=class{constructor(shapes){this.outputShape=[],this.outputShape=backend_util_exports.computeOutShape(shapes,1),this.variableNames=shapes.map((_,i)=> ` T$ { i } ` );let offsets=new Array(shapes.length-1);offsets[0]=shapes[0][1];for(let i=1;i<offsets.length;i++)offsets[i]=offsets[i-1]+shapes[i][1];let snippets=[ ` if ( yC < $ { offsets [ 0 ] } ) setOutput ( getT0 ( yR , yC ) ) ; ` ];for(let i=1;i<offsets.length;i++){let shift=offsets[i-1];snippets.push( ` else if ( yC < $ { offsets [ i ] } ) setOutput ( getT$ { i } ( yR , yC - $ { shift } ) ) ; ` )}let lastIndex=offsets.length,lastShift=offsets[offsets.length-1];snippets.push( ` else setOutput ( getT$ { lastIndex } ( yR , yC - $ { lastShift } ) ) ; ` ),this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int yR = coords . x ;
int yC = coords . y ;
2021-01-13 17:14:23 +01:00
$ { snippets . join ( `
2021-01-03 16:41:56 +01:00
` )}
}
2021-01-13 17:14:23 +01:00
` }},ConcatPackedProgram=class{constructor(shapes,axis){this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[],this.outputShape=backend_util_exports.computeOutShape(shapes,axis);let shape=this.outputShape,rank=shape.length,dtype=getCoordsDataType(rank),coords2=getChannels("coords",rank),channels=["x","y","z","w","u","v"].slice(0,rank);this.variableNames=shapes.map((_,i)=> ` T$ { i } ` );let offsets=new Array(shapes.length-1);offsets[0]=shapes[0][axis];for(let i=1;i<offsets.length;i++)offsets[i]=offsets[i-1]+shapes[i][axis];let channel=channels[axis],lastChannels=channels.slice(-2),allChannels=channels.join(),getValueSnippet= ` if ( $ { channel } < $ { offsets [ 0 ] } ) {
2021-01-03 16:41:56 +01:00
return getChannel (
2021-01-13 17:14:23 +01:00
getT0 ( $ { allChannels } ) , vec2 ( $ { lastChannels . join ( ) } ) ) ;
} ` ;for(let i=1;i<offsets.length;i++){let shift2=offsets[i-1];getValueSnippet+= `
if ( $ { channel } < $ { offsets [ i ] } && $ { channel } >= $ { offsets [ i - 1 ] } ) {
2021-01-03 16:41:56 +01:00
return getChannel (
2021-01-13 17:14:23 +01:00
getT$ { i } ( $ { shiftedChannels ( channels , channel , shift2 ) } ) ,
vec2 ( $ { shiftedChannels ( lastChannels , channel , shift2 ) } ) ) ;
} ` }let lastIndex=offsets.length,shift=offsets[offsets.length-1];getValueSnippet+= `
2021-01-03 16:41:56 +01:00
return getChannel (
2021-01-13 17:14:23 +01:00
getT$ { lastIndex } ( $ { shiftedChannels ( channels , channel , shift ) } ) ,
vec2 ( $ { shiftedChannels ( lastChannels , channel , shift ) } ) ) ; ` ,this.userCode= `
float getValue ( $ { channels . map ( x => "int " + x ) } ) {
$ { getValueSnippet }
2021-01-03 16:41:56 +01:00
}
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } coords = getOutputCoords ( ) ;
vec4 result = vec4 ( getValue ( $ { coords2 } ) , 0. , 0. , 0. ) ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
$ { coords2 [ rank - 1 ] } = $ { coords2 [ rank - 1 ] } + 1 ;
if ( $ { coords2 [ rank - 1 ] } < $ { shape [ rank - 1 ] } ) {
result . g = getValue ( $ { coords2 } ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
$ { coords2 [ rank - 2 ] } = $ { coords2 [ rank - 2 ] } + 1 ;
if ( $ { coords2 [ rank - 2 ] } < $ { shape [ rank - 2 ] } ) {
result . a = getValue ( $ { coords2 } ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
$ { coords2 [ rank - 1 ] } = $ { coords2 [ rank - 1 ] } - 1 ;
if ( $ { coords2 [ rank - 2 ] } < $ { shape [ rank - 2 ] } &&
$ { coords2 [ rank - 1 ] } < $ { shape [ rank - 1 ] } ) {
result . b = getValue ( $ { coords2 } ) ;
2021-01-03 16:41:56 +01:00
}
setOutput ( result ) ;
}
2021-01-13 17:14:23 +01:00
` }};function shiftedChannels(channels,channel,shift){let channelIdx=channels.indexOf(channel);return channels.map((c,idx)=>idx===channelIdx? ` $ { c } - $ { shift } ` :c).join()}function imag3(args){let{inputs,backend:backend22}=args,{input:input2}=inputs,inputData=backend22.texData.get(input2.dataId);return identity2({inputs:{x:inputData.complexTensorInfos.imag},backend:backend22})}var imagConfig2={kernelName:Imag,backendName:"webgl",kernelFunc:imag3};function concatImpl2(inputs,axis,backend22){let dtype=inputs[0].dtype;if(dtype==="complex64"){let reals=inputs.map(t=>real3({inputs:{input:t},backend:backend22})),imags=inputs.map(t=>imag3({inputs:{input:t},backend:backend22})),realConcated=concatImpl2(reals,axis,backend22),imagConcated=concatImpl2(imags,axis,backend22),result2=complex3({inputs:{real:realConcated,imag:imagConcated},backend:backend22});return reals.forEach(r=>backend22.disposeIntermediateTensorInfo(r)),imags.forEach(i=>backend22.disposeIntermediateTensorInfo(i)),backend22.disposeIntermediateTensorInfo(realConcated),backend22.disposeIntermediateTensorInfo(imagConcated),result2}if(dtype==="string"){let{tensors2D:tensors2D2,outShape:outShape2}=computeTensors2D(inputs,axis,backend22),inputsValShapes=tensors2D2.map(t=>({vals:backend22.readSync(t.dataId),shape:t.shape})),simplyConcat=tensors2D2[0].shape[0]===1,outVals=concatImplCPU(inputsValShapes,outShape2,dtype,simplyConcat),finalOutShape=backend_util_exports.computeOutShape(inputs.map(t=>t.shape),axis),outInfo=backend22.makeTensorInfo(finalOutShape,dtype,outVals);return tensors2D2.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),outInfo}if(inputs.length>env().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){let midIndex=Math.floor(inputs.length/2),leftSide=concatImpl2(inputs.slice(0,midIndex),axis,backend22),rightSide=concatImpl2(inputs.slice(midIndex),axis,backend22),result2=concatImpl2([leftSide,rightSide],axis,backend22);return backend22.disposeIntermediateTensorInfo(leftSide),backend22.disposeIntermediateTensorInfo(rightSide),result2}if(env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&inputs[0].shape.length>1){let program2=new ConcatPackedProgram(inputs.map(t=>t.shape),axis);return backend22.runWebGLProgram(program2,inputs,dtype)}let{tensors2D,outShape}=computeTensors2D(inputs,axis,backend22),program=new ConcatProgram(tensors2D.map(t=>t.shape)),result=backend22.runWebGLProgram(program,tensors2D,dtype);tensors2D.forEach(r=>backend22.disposeIntermediateTensorInfo(r));let reshapedResult=reshape3({inputs:{x:result},attrs:{shape:outShape},backend:backend22});return backend22.disposeIntermediateTensorInfo(result),reshapedResult}function computeTensors2D(inputs,axis,backend22){let outShape=backend_util_exports.computeOutShape(inputs.map(t=>t.shape),axis);return{tensors2D:inputs.map(x=>reshape3({inputs:{x},attrs:{shape:[-1,util_exports.sizeFromShape(x.shape.slice(axis))]},backend:backend22})),outShape}}function concat3(args){let{inputs,backend:backend22,attrs}=args,{axis}=attrs, $ axis=util_exports.parseAxisParam(axis,inputs[0].shape)[0],outShape=backend_util_exports.computeOutShape(inputs.map(t=>t.shape), $ axis);if(util_exports.sizeFromShape(outShape)===0)return backend22.makeTensorInfo(outShape,inputs[0].dtype,[]);let $ inputs=inputs.filter(t=>util_exports.sizeFromShape(t.shape)>0);if( $ inputs.length===1)return identity2({inputs:{x: $ inputs[0]},backend:backend22});let shapes= $ inputs.map(t=>t.shape);return backend_util_exports.assertParamsConsistent(shapes, $ axis),concatImpl2( $ inputs, $ axis,backend22)}var concatConfig2={kernelName:Concat,backendName:"webgl",kernelFunc:concat3},Conv2DProgram=class{constructor(convInfo,addBias=!1,activation2=null,hasPreluActivationWeights=!1,hasLeakyreluAlpha=!1){this.variableNames=["x","W"],this.outputShape=convInfo.outShape;let padTop=convInfo.padInfo.top,padLeft=convInfo.padInfo.left,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,dilationHeight=convInfo.dilationHeight,dilationWidth=convInfo.dilationWidth,filterHeight=convInfo.filterHeight,filterWidth=convInfo.filterWidth,inputDepthNearestVec4=Math.floor(convInfo.inChannels/
2021-01-03 16:41:56 +01:00
float b = getPreluActivationWeightsAtOutCoords ( ) ;
2021-01-13 17:14:23 +01:00
$ { activation2 }
} ` :hasLeakyreluAlpha?activationSnippet= ` float activation ( float a ) {
2021-01-03 16:41:56 +01:00
float b = getLeakyreluAlphaAtOutCoords ( ) ;
2021-01-13 17:14:23 +01:00
$ { activation2 }
} ` :activationSnippet= `
2021-01-03 16:41:56 +01:00
float activation ( float x ) {
2021-01-13 17:14:23 +01:00
$ { activation2 }
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` ,applyActivationSnippet="result = activation(result);");let addBiasSnippet=addBias?"result += getBiasAtOutCoords();":"";addBias&&this.variableNames.push("bias"),hasPreluActivationWeights&&this.variableNames.push("preluActivationWeights"),hasLeakyreluAlpha&&this.variableNames.push("leakyreluAlpha"),this.userCode= `
$ { activationSnippet }
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
const ivec2 strides = ivec2 ( $ { strideHeight } , $ { strideWidth } ) ;
const ivec2 pads = ivec2 ( $ { padTop } , $ { padLeft } ) ;
2020-11-16 21:51:46 +01:00
void main ( ) {
2020-12-16 20:49:14 +01:00
ivec4 coords = getOutputCoords ( ) ;
2021-01-03 16:41:56 +01:00
int batch = coords [ 0 ] ;
2021-01-13 17:14:23 +01:00
int d2 = coords [ $ { channelDim } ] ;
2021-01-03 16:41:56 +01:00
ivec2 xRCCorner =
2021-01-13 17:14:23 +01:00
ivec2 ( coords [ $ { rowDim } ] , coords [ $ { colDim } ] ) * strides - pads ;
2020-12-16 20:49:14 +01:00
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2021-01-03 16:41:56 +01:00
// Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { filterHeight } ; wR ++ ) {
int xR = xRCorner + wR * $ { dilationHeight } ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
if ( xR < 0 || xR >= $ { convInfo . inHeight } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { filterWidth } ; wC ++ ) {
int xC = xCCorner + wC * $ { dilationWidth } ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
if ( xC < 0 || xC >= $ { convInfo . inWidth } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int d1 = 0 ; d1 < $ { inputDepthNearestVec4 } ; d1 += 4 ) {
2021-01-03 16:41:56 +01:00
vec4 wValues = vec4 (
getW ( wR , wC , d1 , d2 ) ,
getW ( wR , wC , d1 + 1 , d2 ) ,
getW ( wR , wC , d1 + 2 , d2 ) ,
getW ( wR , wC , d1 + 3 , d2 )
) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( $ { isChannelsLast } ) {
2021-01-03 16:41:56 +01:00
vec4 xValues = vec4 (
getX ( batch , xR , xC , d1 ) ,
getX ( batch , xR , xC , d1 + 1 ) ,
getX ( batch , xR , xC , d1 + 2 ) ,
getX ( batch , xR , xC , d1 + 3 )
) ;
dotProd += dot ( xValues , wValues ) ;
} else {
vec4 xValues = vec4 (
getX ( batch , d1 , xR , xC ) ,
getX ( batch , d1 + 1 , xR , xC ) ,
getX ( batch , d1 + 2 , xR , xC ) ,
getX ( batch , d1 + 3 , xR , xC )
) ;
dotProd += dot ( xValues , wValues ) ;
}
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( $ { inputDepthVec4Remainder === 1 } ) {
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( $ { isChannelsLast } ) {
2021-01-03 16:41:56 +01:00
dotProd +=
2021-01-13 17:14:23 +01:00
getX ( batch , xR , xC , $ { inputDepthNearestVec4 } ) *
getW ( wR , wC , $ { inputDepthNearestVec4 } , d2 ) ;
2021-01-03 16:41:56 +01:00
} else {
dotProd +=
2021-01-13 17:14:23 +01:00
getX ( batch , $ { inputDepthNearestVec4 } , xR , xC ) *
getW ( wR , wC , $ { inputDepthNearestVec4 } , d2 ) ;
2021-01-03 16:41:56 +01:00
}
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
} else if ( $ { inputDepthVec4Remainder === 2 } ) {
2021-01-03 16:41:56 +01:00
vec2 wValues = vec2 (
2021-01-13 17:14:23 +01:00
getW ( wR , wC , $ { inputDepthNearestVec4 } , d2 ) ,
getW ( wR , wC , $ { inputDepthNearestVec4 } + 1 , d2 )
2021-01-03 16:41:56 +01:00
) ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
if ( $ { isChannelsLast } ) {
2021-01-03 16:41:56 +01:00
vec2 xValues = vec2 (
2021-01-13 17:14:23 +01:00
getX ( batch , xR , xC , $ { inputDepthNearestVec4 } ) ,
getX ( batch , xR , xC , $ { inputDepthNearestVec4 } + 1 )
2021-01-03 16:41:56 +01:00
) ;
dotProd += dot ( xValues , wValues ) ;
} else {
vec2 xValues = vec2 (
2021-01-13 17:14:23 +01:00
getX ( batch , $ { inputDepthNearestVec4 } , xR , xC ) ,
getX ( batch , $ { inputDepthNearestVec4 } + 1 , xR , xC )
2021-01-03 16:41:56 +01:00
) ;
dotProd += dot ( xValues , wValues ) ;
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
} else if ( $ { inputDepthVec4Remainder === 3 } ) {
2021-01-03 16:41:56 +01:00
vec3 wValues = vec3 (
2021-01-13 17:14:23 +01:00
getW ( wR , wC , $ { inputDepthNearestVec4 } , d2 ) ,
getW ( wR , wC , $ { inputDepthNearestVec4 } + 1 , d2 ) ,
getW ( wR , wC , $ { inputDepthNearestVec4 } + 2 , d2 )
2021-01-03 16:41:56 +01:00
) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( $ { isChannelsLast } ) {
2021-01-03 16:41:56 +01:00
vec3 xValues = vec3 (
2021-01-13 17:14:23 +01:00
getX ( batch , xR , xC , $ { inputDepthNearestVec4 } ) ,
getX ( batch , xR , xC , $ { inputDepthNearestVec4 } + 1 ) ,
getX ( batch , xR , xC , $ { inputDepthNearestVec4 } + 2 )
2021-01-03 16:41:56 +01:00
) ;
dotProd += dot ( xValues , wValues ) ;
} else {
vec3 xValues = vec3 (
2021-01-13 17:14:23 +01:00
getX ( batch , $ { inputDepthNearestVec4 } , xR , xC ) ,
getX ( batch , $ { inputDepthNearestVec4 } + 1 , xR , xC ) ,
getX ( batch , $ { inputDepthNearestVec4 } + 2 , xR , xC )
2021-01-03 16:41:56 +01:00
) ;
dotProd += dot ( xValues , wValues ) ;
}
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
}
}
2020-11-12 18:58:55 +01:00
}
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
float result = dotProd ;
2021-01-13 17:14:23 +01:00
$ { addBiasSnippet }
$ { applyActivationSnippet }
2021-01-03 16:41:56 +01:00
setOutput ( result ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }},Conv3DProgram=class{constructor(convInfo){this.variableNames=["x","W"],this.outputShape=convInfo.outShape;let padFront=convInfo.padInfo.front,padTop=convInfo.padInfo.top,padLeft=convInfo.padInfo.left,strideDepth=convInfo.strideDepth,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,dilationDepth=convInfo.dilationDepth,dilationHeight=convInfo.dilationHeight,dilationWidth=convInfo.dilationWidth,filterDepth=convInfo.filterDepth,filterHeight=convInfo.filterHeight,filterWidth=convInfo.filterWidth,inputDepthNearestVec4=Math.floor(convInfo.inChannels/4)*4,inputDepthVec4Remainder=convInfo.inChannels%4;this.userCode= `
const ivec3 strides = ivec3 ( $ { strideDepth } , $ { strideHeight } , $ { strideWidth } ) ;
const ivec3 pads = ivec3 ( $ { padFront } , $ { padTop } , $ { padLeft } ) ;
2020-11-16 21:51:46 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int d2 = coords . u ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
ivec3 xFRCCorner = ivec3 ( coords . y , coords . z , coords . w ) * strides - pads ;
int xFCorner = xFRCCorner . x ;
int xRCorner = xFRCCorner . y ;
int xCCorner = xFRCCorner . z ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
// Convolve x(?, ?, ?, d1) with w(:, :, :, d1, d2) to get
// y(yF, yR, yC, d2). ? = to be determined. : = across all
// values in that axis.
float dotProd = 0.0 ;
2021-01-13 17:14:23 +01:00
for ( int wF = 0 ; wF < $ { filterDepth } ; wF ++ ) {
int xF = xFCorner + wF * $ { dilationDepth } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( xF < 0 || xF >= $ { convInfo . inDepth } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { filterHeight } ; wR ++ ) {
int xR = xRCorner + wR * $ { dilationHeight } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( xR < 0 || xR >= $ { convInfo . inHeight } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { filterWidth } ; wC ++ ) {
int xC = xCCorner + wC * $ { dilationWidth } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( xC < 0 || xC >= $ { convInfo . inWidth } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int d1 = 0 ; d1 < $ { inputDepthNearestVec4 } ; d1 += 4 ) {
2021-01-03 16:41:56 +01:00
vec4 xValues = vec4 (
getX ( batch , xF , xR , xC , d1 ) ,
getX ( batch , xF , xR , xC , d1 + 1 ) ,
getX ( batch , xF , xR , xC , d1 + 2 ) ,
getX ( batch , xF , xR , xC , d1 + 3 )
) ;
vec4 wValues = vec4 (
getW ( wF , wR , wC , d1 , d2 ) ,
getW ( wF , wR , wC , d1 + 1 , d2 ) ,
getW ( wF , wR , wC , d1 + 2 , d2 ) ,
getW ( wF , wR , wC , d1 + 3 , d2 )
) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
dotProd += dot ( xValues , wValues ) ;
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( $ { inputDepthVec4Remainder === 1 } ) {
2021-01-03 16:41:56 +01:00
dotProd +=
2021-01-13 17:14:23 +01:00
getX ( batch , xF , xR , xC , $ { inputDepthNearestVec4 } ) *
getW ( wF , wR , wC , $ { inputDepthNearestVec4 } , d2 ) ;
} else if ( $ { inputDepthVec4Remainder === 2 } ) {
2021-01-03 16:41:56 +01:00
vec2 xValues = vec2 (
2021-01-13 17:14:23 +01:00
getX ( batch , xF , xR , xC , $ { inputDepthNearestVec4 } ) ,
getX ( batch , xF , xR , xC , $ { inputDepthNearestVec4 } + 1 )
2021-01-03 16:41:56 +01:00
) ;
vec2 wValues = vec2 (
2021-01-13 17:14:23 +01:00
getW ( wF , wR , wC , $ { inputDepthNearestVec4 } , d2 ) ,
getW ( wF , wR , wC , $ { inputDepthNearestVec4 } + 1 , d2 )
2021-01-03 16:41:56 +01:00
) ;
dotProd += dot ( xValues , wValues ) ;
2021-01-13 17:14:23 +01:00
} else if ( $ { inputDepthVec4Remainder === 3 } ) {
2021-01-03 16:41:56 +01:00
vec3 xValues = vec3 (
2021-01-13 17:14:23 +01:00
getX ( batch , xF , xR , xC , $ { inputDepthNearestVec4 } ) ,
getX ( batch , xF , xR , xC , $ { inputDepthNearestVec4 } + 1 ) ,
getX ( batch , xF , xR , xC , $ { inputDepthNearestVec4 } + 2 )
2021-01-03 16:41:56 +01:00
) ;
vec3 wValues = vec3 (
2021-01-13 17:14:23 +01:00
getW ( wF , wR , wC , $ { inputDepthNearestVec4 } , d2 ) ,
getW ( wF , wR , wC , $ { inputDepthNearestVec4 } + 1 , d2 ) ,
getW ( wF , wR , wC , $ { inputDepthNearestVec4 } + 2 , d2 )
2021-01-03 16:41:56 +01:00
) ;
dotProd += dot ( xValues , wValues ) ;
2020-12-16 20:49:14 +01:00
}
}
2020-11-12 18:58:55 +01:00
}
2021-01-03 16:23:45 +01:00
}
2021-01-03 16:41:56 +01:00
setOutput ( dotProd ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
` }},Im2ColPackedProgram=class{constructor(outputShape,inputShape,convInfo){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=outputShape;let{filterWidth,inChannels,strideWidth,strideHeight,padInfo,outWidth,dilationWidth,dilationHeight,dataFormat}=convInfo,{left,top}=padInfo,itemsPerBlockRow=inChannels*filterWidth,glsl=getGlslDifferences(),isChannelsLast=dataFormat==="channelsLast",rowDim=isChannelsLast?0:1,colDim=isChannelsLast?1:2,unrolled="";for(let row=0;row<=1;row++)for(let col=0;col<=1;col++)unrolled+= `
blockIndex = rc . y + $ { col } ;
pos = rc . x + $ { row } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( blockIndex < $ { outputShape [ 1 ] } && pos < $ { outputShape [ 0 ] } ) {
offsetY = int ( blockIndex / ( $ { outWidth } ) ) * $ { strideHeight } - $ { top } ;
d0 = offsetY + $ { dilationHeight } * ( pos / $ { itemsPerBlockRow } ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( d0 < $ { inputShape [ rowDim ] } && d0 >= 0 ) {
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
offsetX = int ( mod ( float ( blockIndex ) , $ { outWidth } . ) * $ { strideWidth } . - $ { left } . ) ;
d1 = offsetX + $ { dilationWidth } * ( int ( mod ( float ( pos ) , $ { itemsPerBlockRow } . ) / $ { inChannels } . ) ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( d1 < $ { inputShape [ colDim ] } && d1 >= 0 ) {
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
ch = int ( mod ( float ( pos ) , $ { inChannels } . ) ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( $ { isChannelsLast } ) {
2020-12-15 14:44:42 +01:00
innerDims = vec2 ( d1 , ch ) ;
2021-01-13 17:14:23 +01:00
result [ $ { row * 2 + col } ] = getChannel (
2020-12-15 14:44:42 +01:00
getA ( d0 , int ( innerDims . x ) ,
int ( innerDims . y ) ) , innerDims ) ;
} else {
innerDims = vec2 ( d0 , d1 ) ;
2021-01-13 17:14:23 +01:00
result [ $ { row * 2 + col } ] = getChannel (
2020-12-15 14:44:42 +01:00
getA ( ch , int ( innerDims . x ) ,
int ( innerDims . y ) ) , innerDims ) ;
}
}
}
2020-11-08 18:32:31 +01:00
}
2020-12-15 14:44:42 +01:00
` ;this.userCode= `
2020-11-16 21:51:46 +01:00
void main ( ) {
2020-12-15 14:44:42 +01:00
ivec2 rc = getOutputCoords ( ) ;
2020-11-16 21:51:46 +01:00
2020-12-15 14:44:42 +01:00
vec4 result = vec4 ( 0 ) ;
2020-11-16 21:51:46 +01:00
2020-12-15 14:44:42 +01:00
int blockIndex , pos , offsetY , d0 , offsetX , d1 , ch ;
vec2 innerDims ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { unrolled }
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
$ { glsl . output } = result ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function conv2dByMatMul({x,filter,convInfo,backend:backend22,bias=null,preluActivationWeights=null,leakyreluAlpha=0,activation:activation2=null}){let xShape=x.shape,xTexData=backend22.texData.get(x.dataId),sharedMatMulDim=convInfo.inChannels,outerShapeX=xShape[0]*xShape[1]*xShape[2],outerShapeFilter=convInfo.outChannels,isChannelsLast=convInfo.dataFormat==="channelsLast",transposeA=!1,transposeB=!1,out,intermediates=[],batchMatMulWillBeUnpacked=(outerShapeX===1||outerShapeFilter===1)&&sharedMatMulDim>MATMUL_SHARED_DIM_THRESHOLD,reshapeWillBeExpensive=xShape[2]%2!=0&&!!xTexData.isPacked;if(batchMatMulWillBeUnpacked||!env().getBool("WEBGL_LAZILY_UNPACK")||!env().getBool("WEBGL_PACK_BINARY_OPERATIONS")||!reshapeWillBeExpensive){let targetShape=isChannelsLast?xShape[0]*xShape[1]*xShape[2]:xShape[0]*xShape[2]*xShape[3],xReshaped=reshape3({inputs:{x},backend:backend22,attrs:{shape:[1,targetShape,convInfo.inChannels]}}),filterReshaped=reshape3({inputs:{x:filter},backend:backend22,attrs:{shape:[1,convInfo.inChannels,convInfo.outChannels]}}),result=batchMatMulImpl({a:xReshaped,b:filterReshaped,transposeA,transposeB,backend:backend22,bias,activation:activation2,preluActivationWeights,leakyreluAlpha});out=reshape3({inputs:{x:result},backend:backend22,attrs:{shape:convInfo.outShape}}),intermediates.push(xReshaped),intermediates.push(filterReshaped),intermediates.push(result)}else{let targetShape=isChannelsLast?xShape[0]*xShape[1]*(xShape[2]+1):xShape[0]*xShape[2]*(xShape[3]+1),xReshaped={dataId:x.dataId,shape:[1,targetShape,convInfo.inChannels],dtype:x.dtype},originalXTexDataShape=xTexData.shape;xTexData.shape=xTexData.shape.slice(),xTexData.shape[xTexData.shape.length-2]++,util_exports.assert(isReshapeFree(xTexData.shape,xReshaped.shape),()=> ` packed reshape $ { xTexData . shape } to $ { xReshaped . shape } isn ' t free ` );let filterReshaped=reshape3({inputs:{x:filter},backend:backend22,attrs:{shape:[1,convInfo.inChannels,convInfo.outChannels]}});intermediates.push(filterReshaped);let pointwiseConv=batchMatMulImpl({a:xReshaped,b:filterReshaped,backend:backend22,transposeA,transposeB,bias,activation:activation2,preluActivationWeights,leakyreluAlpha}),pointwiseConvTexData=backend22.texData.get(pointwiseConv.dataId);util_exports.assert(pointwiseConvTexData.isPacked,()=>"batchMatMul result is expected to be packed"),xTexData.shape=originalXTexDataShape,pointwiseConvTexData.shape=convInfo.outShape,out=identity2({inputs:{x:pointwiseConv},backend:backend22}),out.shape=convInfo.outShape,intermediates.push(pointwiseConv)}for(let i of intermediates)backend22.disposeIntermediateTensorInfo(i);return out}function conv2dWithIm2Row({x,filter,convInfo,backend:backend22,bias=null,preluActivationWeights=null,leakyreluAlpha=0,activation:activation2=null}){let{filterWidth,filterHeight,inChannels,outWidth,outHeight,dataFormat}=convInfo,isChannelsLast=dataFormat==="channelsLast",sharedDim=filterWidth*filterHeight*inChannels,numCols=outHeight*outWidth,x2ColShape=[sharedDim,numCols],transposeA=!0,transposeB=!1,intermediates=[],xSqueezed=reshape3({inputs:{x},backend:backend22,attrs:{shape:x.shape.slice(1)}}),w2Row=reshape3({inputs:{x:filter},backend:backend22,attrs:{shape:[1,sharedDim,util_exports.sizeFromShape(filter.shape)/sharedDim]}});intermediates.push(xSqueezed),intermediates.push(w2Row);let im2ColProgram=new Im2ColPackedProgram(x2ColShape,xSqueezed.shape,convInfo),im2Col=backend22.runWebGLProgram(im2ColProgram,[xSqueezed],"float32"),im2ColReshaped=reshape3({inputs:{x:im2Col},backend:backend22,attrs:{shape:[1,x2ColShape[0],x2ColShape[1]]}});intermediates.push(im2Col),intermediates.push(im2ColReshaped);let hasBias=bias!=null,hasPreluActivationWeights=preluActivationWeights!=null,hasLeakyreluAlpha=activation2==="leakyrelu",fusedActivation=activation2?mapActivationToShaderProgram(activation2,!0):null,matmulProgram=new MatMulPackedProgram(im2ColReshaped.shape,w2Row.shape,[1,numCols,convInfo.outChannels],transposeA,transposeB,hasBias,fusedActivation,hasPreluActivationWeights,hasLeakyreluAlpha),inputs=[im2ColReshaped,w2Row];if(bias&&inputs.push(bias),hasPreluAc
2020-12-16 20:49:14 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
2021-01-03 16:41:56 +01:00
int wR = coords . x ;
int wC = coords . y ;
int d1 = coords . z ;
int d2 = coords . w ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
// Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int b = 0 ; b < $ { convInfo . batchSize } ; b ++ ) {
for ( int yR = 0 ; yR < $ { convInfo . outHeight } ; yR ++ ) {
int xR = wR + yR * $ { strideHeight } - $ { padTop } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( xR < 0 || xR >= $ { convInfo . inHeight } ) {
2020-11-16 21:51:46 +01:00
continue ;
}
2021-01-13 17:14:23 +01:00
for ( int yC = 0 ; yC < $ { convInfo . outWidth } ; yC ++ ) {
int xC = wC + yC * $ { strideWidth } - $ { padLeft } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( xC < 0 || xC >= $ { convInfo . inWidth } ) {
2021-01-03 16:41:56 +01:00
continue ;
2020-11-16 21:51:46 +01:00
}
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
if ( $ { isChannelsLast } ) {
2021-01-03 16:41:56 +01:00
float dyValue = getDy ( b , yR , yC , d2 ) ;
float xValue = getX ( b , xR , xC , d1 ) ;
dotProd += ( xValue * dyValue ) ;
} else {
float dyValue = getDy ( b , d2 , yR , yC ) ;
float xValue = getX ( b , d1 , xR , xC ) ;
dotProd += ( xValue * dyValue ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-03 16:41:56 +01:00
2020-12-16 20:49:14 +01:00
}
}
2021-01-03 16:41:56 +01:00
}
setOutput ( dotProd ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
` }},Conv2DDerInputProgram=class{constructor(convInfo){this.variableNames=["dy","W"],this.outputShape=convInfo.inShape;let filterHeight=convInfo.filterHeight,filterWidth=convInfo.filterWidth,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,isChannelsLast=convInfo.dataFormat==="channelsLast",padTop=filterHeight-1-convInfo.padInfo.top,padLeft=filterWidth-1-convInfo.padInfo.left,rowDim=isChannelsLast?1:2,colDim=isChannelsLast?2:3,channelDim=isChannelsLast?3:1;this.userCode= `
const ivec2 pads = ivec2 ( $ { padTop } , $ { padLeft } ) ;
2021-01-03 16:41:56 +01:00
2020-12-16 20:49:14 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
2021-01-03 16:41:56 +01:00
int batch = coords [ 0 ] ;
2021-01-13 17:14:23 +01:00
int d1 = coords [ $ { channelDim } ] ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
ivec2 dyCorner = ivec2 ( coords [ $ { rowDim } ] , coords [ $ { colDim } ] ) - pads ;
2021-01-03 16:41:56 +01:00
int dyRCorner = dyCorner . x ;
int dyCCorner = dyCorner . y ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
// Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { filterHeight } ; wR ++ ) {
float dyR = float ( dyRCorner + wR ) / $ { strideHeight } . 0 ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
if ( dyR < 0.0 || dyR >= $ { convInfo . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
2021-01-03 16:41:56 +01:00
continue ;
}
int idyR = int ( dyR ) ;
2021-01-13 17:14:23 +01:00
int wRPerm = $ { filterHeight } - 1 - wR ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { filterWidth } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { strideWidth } . 0 ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
if ( dyC < 0.0 || dyC >= $ { convInfo . outWidth } . 0 ||
2021-01-03 16:41:56 +01:00
fract ( dyC ) > 0.0 ) {
continue ;
2020-12-16 20:49:14 +01:00
}
2021-01-03 16:41:56 +01:00
int idyC = int ( dyC ) ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
int wCPerm = $ { filterWidth } - 1 - wC ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
for ( int d2 = 0 ; d2 < $ { convInfo . outChannels } ; d2 ++ ) {
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
if ( $ { isChannelsLast } ) {
2021-01-03 16:41:56 +01:00
float xValue = getDy ( batch , idyR , idyC , d2 ) ;
float wValue = getW ( wRPerm , wCPerm , d1 , d2 ) ;
dotProd += xValue * wValue ;
} else {
float xValue = getDy ( batch , d2 , idyR , idyC ) ;
float wValue = getW ( wRPerm , wCPerm , d1 , d2 ) ;
dotProd += xValue * wValue ;
2020-12-16 20:49:14 +01:00
}
2021-01-03 16:41:56 +01:00
2020-11-16 21:51:46 +01:00
}
}
2020-11-12 18:58:55 +01:00
}
2021-01-03 16:41:56 +01:00
setOutput ( dotProd ) ;
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }},Conv3DDerFilterProgram=class{constructor(convInfo){this.variableNames=["x","dy"],this.outputShape=convInfo.filterShape;let strideDepth=convInfo.strideDepth,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,padFront=convInfo.padInfo.front,padTop=convInfo.padInfo.top,padLeft=convInfo.padInfo.left;this.userCode= `
2020-11-16 21:51:46 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec5 coords = getOutputCoords ( ) ;
int wF = coords . x ;
int wR = coords . y ;
int wC = coords . z ;
int d1 = coords . w ;
int d2 = coords . u ;
2020-11-16 21:51:46 +01:00
2020-12-15 14:44:42 +01:00
float dotProd = 0.0 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int b = 0 ; b < $ { convInfo . batchSize } ; b ++ ) {
for ( int yF = 0 ; yF < $ { convInfo . outDepth } ; yF ++ ) {
int xF = wF + yF * $ { strideDepth } - $ { padFront } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( xF < 0 || xF >= $ { convInfo . inDepth } ) {
2020-12-15 14:44:42 +01:00
continue ;
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int yR = 0 ; yR < $ { convInfo . outHeight } ; yR ++ ) {
int xR = wR + yR * $ { strideHeight } - $ { padTop } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( xR < 0 || xR >= $ { convInfo . inHeight } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int yC = 0 ; yC < $ { convInfo . outWidth } ; yC ++ ) {
int xC = wC + yC * $ { strideWidth } - $ { padLeft } ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
if ( xC < 0 || xC >= $ { convInfo . inWidth } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
float dyValue = getDy ( b , yF , yR , yC , d2 ) ;
float xValue = getX ( b , xF , xR , xC , d1 ) ;
dotProd += ( xValue * dyValue ) ;
}
}
2020-11-10 02:13:38 +01:00
}
}
2020-12-15 14:44:42 +01:00
setOutput ( dotProd ) ;
2020-11-10 02:13:38 +01:00
}
2021-01-13 17:14:23 +01:00
` }},Conv3DDerInputProgram=class{constructor(convInfo){this.variableNames=["dy","W"],this.outputShape=convInfo.inShape;let filterDepth=convInfo.filterDepth,filterHeight=convInfo.filterHeight,filterWidth=convInfo.filterWidth,strideDepth=convInfo.strideDepth,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,padFront=filterDepth-1-convInfo.padInfo.front,padTop=filterHeight-1-convInfo.padInfo.top,padLeft=filterWidth-1-convInfo.padInfo.left;this.userCode= `
const ivec3 pads = ivec3 ( $ { padFront } , $ { padTop } , $ { padLeft } ) ;
2020-12-16 20:49:14 +01:00
2020-12-15 14:44:42 +01:00
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
2020-12-16 20:49:14 +01:00
int batch = coords . x ;
2021-01-03 16:41:56 +01:00
int d1 = coords . u ;
2020-11-16 21:51:46 +01:00
2020-12-15 14:44:42 +01:00
ivec3 dyCorner = ivec3 ( coords . y , coords . z , coords . w ) - pads ;
2021-01-03 16:41:56 +01:00
int dyFCorner = dyCorner . x ;
2020-12-15 14:44:42 +01:00
int dyRCorner = dyCorner . y ;
int dyCCorner = dyCorner . z ;
2020-11-16 21:51:46 +01:00
2020-12-15 14:44:42 +01:00
float dotProd = 0.0 ;
2021-01-13 17:14:23 +01:00
for ( int wF = 0 ; wF < $ { filterDepth } ; wF ++ ) {
float dyF = float ( dyFCorner + wF ) / $ { strideDepth } . 0 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( dyF < 0.0 || dyF >= $ { convInfo . outDepth } . 0 || fract ( dyF ) > 0.0 ) {
2020-11-16 21:51:46 +01:00
continue ;
2020-11-12 18:58:55 +01:00
}
2021-01-03 16:41:56 +01:00
int idyF = int ( dyF ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
int wFPerm = $ { filterDepth } - 1 - wF ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { filterHeight } ; wR ++ ) {
float dyR = float ( dyRCorner + wR ) / $ { strideHeight } . 0 ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
if ( dyR < 0.0 || dyR >= $ { convInfo . outHeight } . 0 ||
2021-01-03 16:41:56 +01:00
fract ( dyR ) > 0.0 ) {
2020-11-16 21:51:46 +01:00
continue ;
}
2020-12-15 14:44:42 +01:00
int idyR = int ( dyR ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
int wRPerm = $ { filterHeight } - 1 - wR ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { filterWidth } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { strideWidth } . 0 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( dyC < 0.0 || dyC >= $ { convInfo . outWidth } . 0 ||
2020-12-15 14:44:42 +01:00
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
int wCPerm = $ { filterWidth } - 1 - wC ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
for ( int d2 = 0 ; d2 < $ { convInfo . outChannels } ; d2 ++ ) {
2021-01-03 16:41:56 +01:00
float xValue = getDy ( batch , idyF , idyR , idyC , d2 ) ;
float wValue = getW ( wFPerm , wRPerm , wCPerm , d1 , d2 ) ;
dotProd += xValue * wValue ;
}
2020-11-16 21:51:46 +01:00
}
2020-11-12 18:17:57 +01:00
}
2020-11-10 02:13:38 +01:00
}
2020-12-15 14:44:42 +01:00
setOutput ( dotProd ) ;
2020-11-12 18:17:57 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function conv2DBackpropFilter3(args){let{inputs,backend:backend22,attrs}=args,{x,dy}=inputs,{strides,pad:pad3,dataFormat,dimRoundingMode,filterShape}=attrs, $ dataFormat=backend_util_exports.convertConv2DDataFormat(dataFormat),convInfo=backend_util_exports.computeConv2DInfo(x.shape,filterShape,strides,1,pad3,dimRoundingMode,!1, $ dataFormat),program=new Conv2DDerFilterProgram(convInfo);return backend22.runWebGLProgram(program,[x,dy],"float32")}var conv2DBackpropFilterConfig2={kernelName:Conv2DBackpropFilter,backendName:"webgl",kernelFunc:conv2DBackpropFilter3};function conv2DBackpropInput3(args){let{inputs,backend:backend22,attrs}=args,{dy,filter}=inputs,{inputShape,strides,pad:pad3,dataFormat,dimRoundingMode}=attrs, $ dataFormat=backend_util_exports.convertConv2DDataFormat(dataFormat),convInfo=backend_util_exports.computeConv2DInfo(inputShape,filter.shape,strides,1,pad3,dimRoundingMode,!1, $ dataFormat),program=new Conv2DDerInputProgram(convInfo);return backend22.runWebGLProgram(program,[dy,filter],"float32")}var conv2DBackpropInputConfig2={kernelName:Conv2DBackpropInput,backendName:"webgl",kernelFunc:conv2DBackpropInput3};function conv3D2(args){let{inputs,backend:backend22,attrs}=args,{x,filter}=inputs,{strides,pad:pad3,dilations}=attrs,convInfo=backend_util_exports.computeConv3DInfo(x.shape,filter.shape,strides,dilations,pad3),program=new Conv3DProgram(convInfo);return backend22.runWebGLProgram(program,[x,filter],"float32")}var conv3DConfig2={kernelName:Conv3D,backendName:"webgl",kernelFunc:conv3D2};function conv3DBackpropFilterV22(args){let{inputs,backend:backend22,attrs}=args,{x,dy}=inputs,{strides,pad:pad3,filterShape}=attrs,convInfo=backend_util_exports.computeConv3DInfo(x.shape,filterShape,strides,1,pad3),program=new Conv3DDerFilterProgram(convInfo);return backend22.runWebGLProgram(program,[x,dy],"float32")}var conv3DBackpropFilterV2Config2={kernelName:Conv3DBackpropFilterV2,backendName:"webgl",kernelFunc:conv3DBackpropFilterV22};function conv3DBackpropInput2(args){let{inputs,backend:backend22,attrs}=args,{dy,filter}=inputs,{pad:pad3,strides,inputShape}=attrs,convInfo=backend_util_exports.computeConv3DInfo(inputShape,filter.shape,strides,1,pad3),program=new Conv3DDerInputProgram(convInfo);return backend22.runWebGLProgram(program,[dy,filter],"float32")}var conv3DBackpropInputConfig={kernelName:Conv3DBackpropInputV2,backendName:"webgl",kernelFunc:conv3DBackpropInput2},COS=CHECK_NAN_SNIPPET_UNARY+ `
2021-01-03 16:41:56 +01:00
return cos ( x ) ;
2021-01-13 17:14:23 +01:00
` ,cos3=unaryKernelFunc2({opSnippet:COS}),cosConfig2={kernelName:Cos,backendName:"webgl",kernelFunc:cos3},COSH= `
2021-01-03 16:41:56 +01:00
float e2x = exp ( - x ) ;
return ( e2x + 1.0 / e2x ) / 2.0 ;
2021-01-13 17:14:23 +01:00
` ,cosh3=unaryKernelFunc2({opSnippet:COSH}),coshConfig2={kernelName:Cosh,backendName:"webgl",kernelFunc:cosh3},CropAndResizeProgram=class{constructor(imageShape,boxShape,cropSize,method,extrapolationValue){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];let[batch,imageHeight,imageWidth,depth]=imageShape,[numBoxes]=boxShape,[cropHeight,cropWidth]=cropSize;this.outputShape=[numBoxes,cropHeight,cropWidth,depth];let methodId=method==="bilinear"?1:0,[inputHeightFloat,inputWidthFloat]=[ ` $ { imageHeight - 1 } . 0 ` , ` $ { imageWidth - 1 } . 0 ` ],[heightRatio,heightScale,inY]=cropHeight>1?[ ` $ { ( imageHeight - 1 ) / ( cropHeight - 1 ) } ` ,"(y2-y1) * height_ratio", ` y1 * $ { inputHeightFloat } + float ( y ) * ( height _scale ) ` ]:["0.0","0.0", ` 0.5 * ( y1 + y2 ) * $ { inputHeightFloat } ` ],[widthRatio,widthScale,inX]=cropWidth>1?[ ` $ { ( imageWidth - 1 ) / ( cropWidth - 1 ) } ` ,"(x2-x1) * width_ratio", ` x1 * $ { inputWidthFloat } + float ( x ) * ( width _scale ) ` ]:["0.0","0.0", ` 0.5 * ( x1 + x2 ) * $ { inputWidthFloat } ` ];this.userCode= `
const float height _ratio = float ( $ { heightRatio } ) ;
const float width _ratio = float ( $ { widthRatio } ) ;
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int y = coords [ 1 ] ;
int x = coords [ 2 ] ;
int d = coords [ 3 ] ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
// get box vals
float y1 = getBoxes ( b , 0 ) ;
float x1 = getBoxes ( b , 1 ) ;
float y2 = getBoxes ( b , 2 ) ;
float x2 = getBoxes ( b , 3 ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
// get image in batch index
int bInd = round ( getBoxInd ( b ) ) ;
2021-01-13 17:14:23 +01:00
if ( bInd < 0 || bInd >= $ { batch } ) {
2021-01-03 16:41:56 +01:00
return ;
2020-11-12 18:58:55 +01:00
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
float height _scale = $ { heightScale } ;
float width _scale = $ { widthScale } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
float in _y = $ { inY } ;
if ( in _y < 0.0 || in _y > $ { inputHeightFloat } ) {
setOutput ( float ( $ { extrapolationValue } ) ) ;
2021-01-03 16:41:56 +01:00
return ;
}
2021-01-13 17:14:23 +01:00
float in _x = $ { inX } ;
if ( in _x < 0.0 || in _x > $ { inputWidthFloat } ) {
setOutput ( float ( $ { extrapolationValue } ) ) ;
2021-01-03 16:41:56 +01:00
return ;
}
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
vec2 sourceFracIndexCR = vec2 ( in _x , in _y ) ;
2021-01-13 17:14:23 +01:00
if ( $ { methodId } == 1 ) {
2021-01-03 16:41:56 +01:00
// Compute the four integer indices.
ivec2 sourceFloorCR = ivec2 ( sourceFracIndexCR ) ;
ivec2 sourceCeilCR = ivec2 ( ceil ( sourceFracIndexCR ) ) ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
float topLeft = getImage ( b , sourceFloorCR . y , sourceFloorCR . x , d ) ;
float bottomLeft = getImage ( b , sourceCeilCR . y , sourceFloorCR . x , d ) ;
float topRight = getImage ( b , sourceFloorCR . y , sourceCeilCR . x , d ) ;
float bottomRight = getImage ( b , sourceCeilCR . y , sourceCeilCR . x , d ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
vec2 fracCR = sourceFracIndexCR - vec2 ( sourceFloorCR ) ;
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
float top = topLeft + ( topRight - topLeft ) * fracCR . x ;
float bottom = bottomLeft + ( bottomRight - bottomLeft ) * fracCR . x ;
float newValue = top + ( bottom - top ) * fracCR . y ;
setOutput ( newValue ) ;
2020-12-16 20:49:14 +01:00
} else {
2021-01-03 16:41:56 +01:00
// Compute the coordinators of nearest neighbor point.
ivec2 sourceNearestCR = ivec2 ( floor (
sourceFracIndexCR + vec2 ( 0.5 , 0.5 ) ) ) ;
float newValue = getImage ( b , sourceNearestCR . y , sourceNearestCR . x , d ) ;
setOutput ( newValue ) ;
2020-12-16 20:49:14 +01:00
}
2020-11-12 18:58:55 +01:00
}
2021-01-13 17:14:23 +01:00
` }},cropAndResize3=args=>{let{inputs,backend:backend22,attrs}=args,{image:image3,boxes,boxInd}=inputs,{cropSize,method,extrapolationValue}=attrs,program=new CropAndResizeProgram(image3.shape,boxes.shape,cropSize,method,extrapolationValue);return backend22.runWebGLProgram(program,[image3,boxes,boxInd],"float32")},cropAndResizeConfig2={kernelName:CropAndResize,backendName:"webgl",kernelFunc:cropAndResize3},CumSumProgram=class{constructor(shape,exclusive,reverse5){this.variableNames=["x"],this.outputShape=shape;let rank=shape.length,val=exclusive?"0.0": ` getX ( $ { getCoords2 ( rank , "coords" ) } ) ` ,length=shape[shape.length-1],condition="",idxString="";exclusive?(condition=reverse5? ` end != $ { length - 1 } ` :"end != 0",idxString=reverse5?"end + 1":"end - 1"):(condition=reverse5? ` end + pow2 < $ { length } ` :"end >= pow2",idxString=reverse5?"end + pow2":"end - pow2"),this.userCode= `
2021-01-03 16:41:56 +01:00
uniform float index ;
2020-12-16 20:49:14 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { getCoordsDataType ( rank ) } coords = getOutputCoords ( ) ;
int end = $ { getFinalCoord ( rank , "coords" ) } ;
float val = $ { val } ;
2021-01-03 16:41:56 +01:00
int pow2 = int ( pow ( 2.0 , index ) ) ;
2021-01-13 17:14:23 +01:00
if ( $ { condition } ) {
int idx = $ { idxString } ;
$ { getFinalCoord ( rank , "coords" ) } = idx ;
val += getX ( $ { getCoords2 ( rank , "coords" ) } ) ;
2021-01-03 16:41:56 +01:00
}
setOutput ( val ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
` }getCustomSetupFunc(index){return(gpgpu,webGLProgram)=>{this.index==null&&(this.index=gpgpu.getUniformLocation(webGLProgram,"index")),gpgpu.gl.uniform1f(this.index,index)}}};function getCoords2(rank,name){if(rank===1)return ` $ { name } ` ;if(rank===2)return ` $ { name } . x , $ { name } . y ` ;if(rank===3)return ` $ { name } . x , $ { name } . y , $ { name } . z ` ;if(rank===4)return ` $ { name } . x , $ { name } . y , $ { name } . z , $ { name } . w ` ;throw Error( ` Cumulative sum for rank $ { rank } is not yet supported ` )}function getFinalCoord(rank,name){if(rank===1)return ` $ { name } ` ;if(rank===2)return ` $ { name } . y ` ;if(rank===3)return ` $ { name } . z ` ;if(rank===4)return ` $ { name } . w ` ;throw Error( ` Cumulative sum for rank $ { rank } is not yet supported ` )}function cumsum3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{axis,exclusive,reverse:reverse5}=attrs,xRank=x.shape.length,permutation=backend_util_exports.getAxesPermutation([axis],xRank),permutedX=x;permutation!=null&&(permutedX=transpose3({inputs:{x},backend:backend22,attrs:{perm:permutation}}));let permutedAxis=backend_util_exports.getInnerMostAxes(1,xRank)[0];if(permutedAxis!==xRank-1)throw new Error( ` WebGL cumsum shader expects an inner - most axis = $ { x . shape . length - 1 } but got axis = $ { axis } ` );let size=x.shape[permutedAxis],result=identity2({inputs:{x:permutedX},backend:backend22});for(let i=0;i<=Math.ceil(Math.log2(size))-1;i++){let program=new CumSumProgram(permutedX.shape,!1,reverse5),customSetup=program.getCustomSetupFunc(i),prevResult=result;result=backend22.runWebGLProgram(program,[result],result.dtype,customSetup),backend22.disposeIntermediateTensorInfo(prevResult)}if(exclusive){let program=new CumSumProgram(permutedX.shape,exclusive,reverse5),prevResult=result;result=backend22.runWebGLProgram(program,[result],result.dtype),backend22.disposeIntermediateTensorInfo(prevResult)}if(permutation!=null){let reversePermutation=backend_util_exports.getUndoAxesPermutation(permutation),reverseTransposedResult=transpose3({inputs:{x:result},backend:backend22,attrs:{perm:reversePermutation}});return backend22.disposeIntermediateTensorInfo(result),backend22.disposeIntermediateTensorInfo(permutedX),reverseTransposedResult}return result}var cumsumConfig2={kernelName:Cumsum,backendName:"webgl",kernelFunc:cumsum3};function denseBincount3(args){let{inputs,backend:backend22,attrs}=args,{x,weights}=inputs,{size,binaryOutput}=attrs;if(x.shape.length===1){let xVals=backend22.readSync(x.dataId),weightsVals=backend22.readSync(weights.dataId),outVals=bincountImplCPU(xVals,weightsVals,weights.dtype,weights.shape,size);return backend22.makeTensorInfo([size],weights.dtype,outVals)}else if(x.shape.length===2){let xBuf=backend22.bufferSync(x),weightsBuf=backend22.bufferSync(weights),outBuf=bincountReduceImplCPU(xBuf,weightsBuf,size,binaryOutput);return backend22.makeTensorInfo(outBuf.shape,weights.dtype,outBuf.values)}throw new Error( ` Error in denseBincount : input must be at most rank 2 , but got rank$ { x . shape . length } . ` )}var denseBincountConfig2={kernelName:DenseBincount,backendName:"webgl",kernelFunc:denseBincount3},DepthToSpaceProgram=class{constructor(outputShape,blockSize,dataFormat){this.variableNames=["x"],this.outputShape=[],this.outputShape=outputShape,this.blockSize=blockSize,this.dataFormat=dataFormat,this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int h = $ { this . getHeightCoordString ( ) } ;
int w = $ { this . getWidthCoordString ( ) } ;
int d = $ { this . getDepthCoordString ( ) } ;
2020-11-10 02:13:38 +01:00
2021-01-13 17:14:23 +01:00
int in _h = h / $ { blockSize } ;
int offset _h = imod ( h , $ { blockSize } ) ;
int in _w = w / $ { blockSize } ;
int offset _w = imod ( w , $ { blockSize } ) ;
int offset _d = ( offset _h * $ { blockSize } + offset _w ) *
2021-01-03 16:41:56 +01:00
$ { this . getOutputDepthSize ( ) } ;
int in _d = d + offset _d ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
float result = $ { this . getInputSamplingString ( ) } ;
setOutput ( result ) ;
}
2021-01-13 17:14:23 +01:00
` }getHeightCoordString(){return this.dataFormat==="NHWC"?"coords[1]":"coords[2]"}getWidthCoordString(){return this.dataFormat==="NHWC"?"coords[2]":"coords[3]"}getDepthCoordString(){return this.dataFormat==="NHWC"?"coords[3]":"coords[1]"}getOutputDepthSize(){return this.dataFormat==="NHWC"?this.outputShape[3]:this.outputShape[1]}getInputSamplingString(){return this.dataFormat==="NHWC"?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"}};function depthToSpace3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{blockSize,dataFormat}=attrs;util_exports.assert(blockSize>1,()=> ` blockSize should be > 1 for depthToSpace , but was : $ { blockSize } ` );let batchSize=x.shape[0],inputHeight=dataFormat==="NHWC"?x.shape[1]:x.shape[2],inputWidth=dataFormat==="NHWC"?x.shape[2]:x.shape[3],inputDepth=dataFormat==="NHWC"?x.shape[3]:x.shape[1],outputHeight=inputHeight*blockSize,outputWidth=inputWidth*blockSize,outputDepth=inputDepth/(blockSize*blockSize),outputShape=dataFormat==="NHWC"?[batchSize,outputHeight,outputWidth,outputDepth]:[batchSize,outputDepth,outputHeight,outputWidth],program=new DepthToSpaceProgram(outputShape,blockSize,dataFormat);return backend22.runWebGLProgram(program,[x],x.dtype)}var depthToSpaceConfig2={kernelName:DepthToSpace,backendName:"webgl",kernelFunc:depthToSpace3},DepthwiseConv2DProgram=class{constructor(convInfo,addBias=!1,activation2=null,hasPreluActivation=!1,hasLeakyReluAlpha=!1){this.variableNames=["x","W"],this.outputShape=convInfo.outShape;let xNumRows=convInfo.inHeight,xNumCols=convInfo.inWidth,padTop=convInfo.padInfo.top,padLeft=convInfo.padInfo.left,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,dilationHeight=convInfo.dilationHeight,dilationWidth=convInfo.dilationWidth,filterHeight=convInfo.filterHeight,filterWidth=convInfo.filterWidth,channelMul=convInfo.outChannels/convInfo.inChannels,activationSnippet="",applyActivationSnippet="";activation2&&(hasPreluActivation?activationSnippet= ` float activation ( float a ) {
2021-01-03 16:41:56 +01:00
float b = getPreluActivationWeightsAtOutCoords ( ) ;
2021-01-13 17:14:23 +01:00
$ { activation2 }
} ` :hasLeakyReluAlpha?activationSnippet= ` float activation ( float a ) {
2021-01-03 16:41:56 +01:00
float b = getLeakyreluAlphaAtOutCoords ( ) ;
2021-01-13 17:14:23 +01:00
$ { activation2 }
} ` :activationSnippet= `
2021-01-03 16:41:56 +01:00
float activation ( float x ) {
2021-01-13 17:14:23 +01:00
$ { activation2 }
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
` ,applyActivationSnippet="result = activation(result);");let addBiasSnippet=addBias?"result += getBiasAtOutCoords();":"";addBias&&this.variableNames.push("bias"),hasPreluActivation&&this.variableNames.push("preluActivationWeights"),hasLeakyReluAlpha&&this.variableNames.push("leakyreluAlpha"),this.userCode= `
$ { activationSnippet }
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
const ivec2 strides = ivec2 ( $ { strideHeight } , $ { strideWidth } ) ;
const ivec2 pads = ivec2 ( $ { padTop } , $ { padLeft } ) ;
2020-11-16 21:51:46 +01:00
2020-12-16 20:49:14 +01:00
void main ( ) {
2020-12-15 14:44:42 +01:00
ivec4 coords = getOutputCoords ( ) ;
2021-01-03 16:41:56 +01:00
int batch = coords . x ;
2020-12-15 14:44:42 +01:00
ivec2 xRCCorner = coords . yz * strides - pads ;
2021-01-03 16:41:56 +01:00
int d2 = coords . w ;
2021-01-13 17:14:23 +01:00
int d1 = d2 / $ { channelMul } ;
int q = d2 - d1 * $ { channelMul } ;
2021-01-03 16:41:56 +01:00
2020-12-15 14:44:42 +01:00
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
// Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
// TO DO(dsmilkov): Flatten the two for loops and vec4 the operations.
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { filterHeight } ; wR ++ ) {
int xR = xRCorner + wR * $ { dilationHeight } ;
2020-11-10 02:13:38 +01:00
2021-01-13 17:14:23 +01:00
if ( xR < 0 || xR >= $ { xNumRows } ) {
2020-12-16 20:49:14 +01:00
continue ;
}
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { filterWidth } ; wC ++ ) {
int xC = xCCorner + wC * $ { dilationWidth } ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
if ( xC < 0 || xC >= $ { xNumCols } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
float xVal = getX ( batch , xR , xC , d1 ) ;
float wVal = getW ( wR , wC , d1 , q ) ;
dotProd += xVal * wVal ;
2020-12-16 20:49:14 +01:00
}
2021-01-03 16:41:56 +01:00
}
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
float result = dotProd ;
2021-01-13 17:14:23 +01:00
$ { addBiasSnippet }
$ { applyActivationSnippet }
2021-01-03 16:41:56 +01:00
setOutput ( result ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }},DepthwiseConvPacked2DProgram=class{constructor(convInfo,addBias=!1,activation2=null,hasPreluActivation=!1,hasLeakyReluAlpha=!1){this.variableNames=["x","W"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=convInfo.outShape;let xNumRows=convInfo.inHeight,xNumCols=convInfo.inWidth,padTop=convInfo.padInfo.top,padLeft=convInfo.padInfo.left,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,dilationHeight=convInfo.dilationHeight,dilationWidth=convInfo.dilationWidth,filterHeight=convInfo.filterHeight,filterWidth=convInfo.filterWidth,texelsAcross=filterWidth,mainLoop="int xR; int xC; int xCOffset;";for(let r=0;r<filterHeight;r++)for(let c=0;c<filterWidth;c++)mainLoop+= `
vec4 xTexelR$ { r } C$ { c * 2 } = vec4 ( 0. ) ;
vec4 wR$ { r } C$ { c } = vec4 ( 0. ) ;
vec4 xR$ { r } C$ { c } = vec4 ( 0. ) ; ` ;for(let r=0;r<filterHeight;r++)for(let texelC=0;texelC<texelsAcross;texelC++){let c=texelC*2;if(mainLoop+= `
xR = xRCorner + $ { r * dilationHeight } ;
xC = xCCorner + $ { c * dilationWidth } ;
` ,strideWidth===1){if(c<filterWidth&&(padLeft%2==1?mainLoop+= `
2021-01-03 16:41:56 +01:00
xCOffset = xC + 1 ;
2021-01-13 17:14:23 +01:00
if ( xR >= 0 && xR < $ { xNumRows } && xCOffset >= 0 && xCOffset < $ { xNumCols } ) {
xTexelR$ { r } C$ { c } = getX ( batch , xR , xCOffset , d1 ) ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
// Need to manually clear unused channels in case
// we're reading from recycled texture.
2021-01-13 17:14:23 +01:00
if ( xCOffset + 1 >= $ { xNumCols } ) {
xTexelR$ { r } C$ { c } . zw = vec2 ( 0. ) ;
2021-01-03 16:41:56 +01:00
}
} else {
2021-01-13 17:14:23 +01:00
xTexelR$ { r } C$ { c } = vec4 ( 0. ) ;
2021-01-03 16:41:56 +01:00
}
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
xCOffset = xC + 1 - 2 ;
2021-01-13 17:14:23 +01:00
if ( xR >= 0 && xR < $ { xNumRows } && xCOffset >= 0 && xCOffset < $ { xNumCols } ) {
2021-01-03 16:41:56 +01:00
vec4 previous = getX ( batch , xR , xCOffset , d1 ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
// Need to manually clear unused channels in case
// we're reading from recycled texture.
2021-01-13 17:14:23 +01:00
if ( xCOffset + 1 >= $ { xNumCols } ) {
2021-01-03 16:41:56 +01:00
previous . zw = vec2 ( 0. ) ;
}
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
xR$ { r } C$ { c } = vec4 ( previous . zw , xTexelR$ { r } C$ { c } . xy ) ;
2021-01-03 16:41:56 +01:00
} else {
2021-01-13 17:14:23 +01:00
xR$ { r } C$ { c } = vec4 ( 0 , 0 , xTexelR$ { r } C$ { c } . xy ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` :mainLoop+= `
if ( xR >= 0 && xR < $ { xNumRows } && xC >= 0 && xC < $ { xNumCols } ) {
xTexelR$ { r } C$ { c } = getX ( batch , xR , xC , d1 ) ;
2021-01-03 16:41:56 +01:00
} else {
2021-01-13 17:14:23 +01:00
xTexelR$ { r } C$ { c } = vec4 ( 0. ) ;
2021-01-03 16:41:56 +01:00
}
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
xR$ { r } C$ { c } = xTexelR$ { r } C$ { c } ;
` ,c+1<filterWidth)){let nextTexelOffset=padLeft%2==0?util_exports.nearestLargerEven(dilationWidth):dilationWidth;dilationWidth%2==0&&padLeft%2==1||dilationWidth%2!=0&&padLeft%2!=1?(mainLoop+= `
xCOffset = xC + $ { padLeft % 2 } + $ { nextTexelOffset } ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
if ( xR >= 0 && xR < $ { xNumRows } &&
xCOffset >= 0 && xCOffset < $ { xNumCols } ) {
xTexelR$ { r } C$ { c + 2 } = getX ( batch , xR , xCOffset , d1 ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` ,dilationWidth>1&&(mainLoop+= `
2021-01-03 16:41:56 +01:00
xCOffset -= 2 ;
2021-01-13 17:14:23 +01:00
if ( xR >= 0 && xR < $ { xNumRows } &&
xCOffset >= 0 && xCOffset < $ { xNumCols } ) {
xTexelR$ { r } C$ { c } = getX ( batch , xR , xCOffset , d1 ) ;
2021-01-03 16:41:56 +01:00
} else {
2021-01-13 17:14:23 +01:00
xTexelR$ { r } C$ { c } = vec4 ( 0. ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` ),mainLoop+= `
xR$ { r } C$ { c + 1 } = vec4 (
xTexelR$ { r } C$ { c } . zw , xTexelR$ { r } C$ { c + 2 } . xy ) ;
` ):mainLoop+= `
xCOffset = xC + $ { nextTexelOffset } ;
if ( xR >= 0 && xR < $ { xNumRows } &&
xCOffset >= 0 && xCOffset < $ { xNumCols } ) {
xTexelR$ { r } C$ { c + 2 } = getX ( batch , xR , xCOffset , d1 ) ;
2021-01-03 16:41:56 +01:00
}
2020-11-10 02:13:38 +01:00
2021-01-13 17:14:23 +01:00
xR$ { r } C$ { c + 1 } = xTexelR$ { r } C$ { c + 2 } ;
` }}else c<filterWidth&&(mainLoop+= `
if ( xR >= 0 && xR < $ { xNumRows } ) {
` ,padLeft%2==1?(mainLoop+= `
xCOffset = xC + 1 - $ { strideWidth } ;
if ( xCOffset >= 0 && xCOffset < $ { xNumCols } ) {
xTexelR$ { r } C$ { c } = getX ( batch , xR , xCOffset , d1 ) ;
2021-01-03 16:41:56 +01:00
} else {
2021-01-13 17:14:23 +01:00
xTexelR$ { r } C$ { c } = vec4 ( 0. ) ;
2021-01-03 16:41:56 +01:00
}
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
if ( xC + 1 >= 0 && xC + 1 < $ { xNumCols } ) {
xTexelR$ { r } C$ { c + 2 } = getX ( batch , xR , xC + 1 , d1 ) ;
2021-01-03 16:41:56 +01:00
} else {
2021-01-13 17:14:23 +01:00
xTexelR$ { r } C$ { c + 2 } = vec4 ( 0. ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
xR$ { r } C$ { c } = vec4 (
xTexelR$ { r } C$ { c } . zw , xTexelR$ { r } C$ { c + 2 } . zw ) ;
` ,c+1<filterWidth&&(mainLoop+= `
2021-01-03 16:41:56 +01:00
vec4 final = vec4 ( 0. ) ;
2021-01-13 17:14:23 +01:00
xCOffset = xC + 1 + $ { strideWidth } ;
if ( xCOffset >= 0 && xCOffset < $ { xNumCols } ) {
2021-01-03 16:41:56 +01:00
final = getX ( batch , xR , xCOffset , d1 ) ;
}
2021-01-13 17:14:23 +01:00
xR$ { r } C$ { c + 1 } = vec4 ( xTexelR$ { r } C$ { c + 2 } . xy , final . xy ) ;
` )):(mainLoop+= `
if ( xC >= 0 && xC < $ { xNumCols } ) {
xTexelR$ { r } C$ { c } = getX ( batch , xR , xC , d1 ) ;
2021-01-03 16:41:56 +01:00
} else {
2021-01-13 17:14:23 +01:00
xTexelR$ { r } C$ { c } = vec4 ( 0. ) ;
2021-01-03 16:41:56 +01:00
}
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
xCOffset = xC + $ { strideWidth } ;
if ( xCOffset >= 0 && xCOffset < $ { xNumCols } ) {
xTexelR$ { r } C$ { c + 2 } = getX ( batch , xR , xCOffset , d1 ) ;
2021-01-03 16:41:56 +01:00
} else {
2021-01-13 17:14:23 +01:00
xTexelR$ { r } C$ { c + 2 } = vec4 ( 0. ) ;
2020-12-15 14:44:42 +01:00
}
2020-11-10 02:13:38 +01:00
2021-01-13 17:14:23 +01:00
xR$ { r } C$ { c } = vec4 (
xTexelR$ { r } C$ { c } . xy , xTexelR$ { r } C$ { c + 2 } . xy ) ;
` ,c+1<filterWidth&&(mainLoop+= `
xR$ { r } C$ { c + 1 } = vec4 (
xTexelR$ { r } C$ { c } . zw , xTexelR$ { r } C$ { c + 2 } . zw ) ;
` )),mainLoop+="}");c<filterWidth&&(mainLoop+= `
vec4 wTexelR$ { r } C$ { c } = getW ( $ { r } , $ { c } , d1 , q ) ;
wR$ { r } C$ { c } = vec4 ( wTexelR$ { r } C$ { c } . xz , wTexelR$ { r } C$ { c } . xz ) ;
` ,c+1<filterWidth&&(mainLoop+= `
vec4 wTexelR$ { r } C$ { c + 1 } = getW ( $ { r } , $ { c + 1 } , d1 , q ) ;
wR$ { r } C$ { c + 1 } =
vec4 ( wTexelR$ { r } C$ { c + 1 } . xz , wTexelR$ { r } C$ { c + 1 } . xz ) ; ` ))}for(let r=0;r<filterHeight;r++)for(let c=0;c<filterWidth;c++)mainLoop+= ` dotProd += xR$ { r } C$ { c } * wR$ { r } C$ { c } ; ` ;let activationSnippet="",applyActivationSnippet="";activation2&&(hasPreluActivation?activationSnippet= ` vec4 activation ( vec4 a ) {
2021-01-03 16:41:56 +01:00
vec4 b = getPreluActivationWeightsAtOutCoords ( ) ;
2021-01-13 17:14:23 +01:00
$ { activation2 }
} ` :hasLeakyReluAlpha?activationSnippet= ` vec4 activation ( vec4 a ) {
2021-01-03 16:41:56 +01:00
vec4 b = getLeakyreluAlphaAtOutCoords ( ) ;
2021-01-13 17:14:23 +01:00
$ { activation2 }
} ` :activationSnippet= ` vec4 activation ( vec4 x ) {
$ { activation2 }
} ` ,applyActivationSnippet="result = activation(result);");let addBiasSnippet=addBias?"result += getBiasAtOutCoords();":"";addBias&&this.variableNames.push("bias"),hasPreluActivation&&this.variableNames.push("preluActivationWeights"),hasLeakyReluAlpha&&this.variableNames.push("leakyreluAlpha"),this.userCode= `
$ { activationSnippet }
2020-11-10 02:13:38 +01:00
2021-01-13 17:14:23 +01:00
const ivec2 strides = ivec2 ( $ { strideHeight } , $ { strideWidth } ) ;
const ivec2 pads = ivec2 ( $ { padTop } , $ { padLeft } ) ;
2020-11-10 02:13:38 +01:00
2020-12-16 20:49:14 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec4 coords = getOutputCoords ( ) ;
2020-12-16 20:49:14 +01:00
int batch = coords . x ;
2021-01-03 16:41:56 +01:00
ivec2 xRCCorner = coords . yz * strides - pads ;
int d2 = coords . w ;
int d1 = d2 ;
int q = 0 ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
vec4 dotProd = vec4 ( 0. ) ;
2020-11-10 02:13:38 +01:00
2021-01-13 17:14:23 +01:00
$ { mainLoop }
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
vec4 result = dotProd ;
2021-01-13 17:14:23 +01:00
$ { addBiasSnippet }
$ { applyActivationSnippet }
2021-01-03 16:41:56 +01:00
setOutput ( result ) ;
}
2021-01-13 17:14:23 +01:00
` }};function depthwiseConv2dNative2(args){let{inputs,backend:backend22,attrs}=args,{x,filter}=inputs,{strides,pad:pad3,dilations,dimRoundingMode}=attrs, $ dilations=dilations; $ dilations==null&&( $ dilations=[1,1]),util_exports.assert(backend_util_exports.eitherStridesOrDilationsAreOne(strides, $ dilations),()=> ` Error in depthwiseConv2d : Either strides or dilations must be 1. Got strides $ { strides } and dilations '${$dilations}' ` );let convInfo=backend_util_exports.computeConv2DInfo(x.shape,filter.shape,strides, $ dilations,pad3,dimRoundingMode,!0),program;return env().getBool("WEBGL_PACK_DEPTHWISECONV")&&convInfo.strideWidth<=2&&convInfo.outChannels/convInfo.inChannels==1?program=new DepthwiseConvPacked2DProgram(convInfo):program=new DepthwiseConv2DProgram(convInfo),backend22.runWebGLProgram(program,[x,filter],"float32")}var depthwiseConv2dNativeConfig2={kernelName:DepthwiseConv2dNative,backendName:"webgl",kernelFunc:depthwiseConv2dNative2},DepthwiseConv2DDerFilterProgram=class{constructor(convInfo){this.variableNames=["x","dy"],this.outputShape=convInfo.filterShape;let strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,padTop=convInfo.padInfo.top,padLeft=convInfo.padInfo.left,channelMul=convInfo.outChannels/convInfo.inChannels;this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int wR = coords . x ;
int wC = coords . y ;
int d1 = coords . z ;
int dm = coords . w ;
2021-01-13 17:14:23 +01:00
int d2 = d1 * $ { channelMul } + dm ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
float dotProd = 0.0 ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
// TO DO: Vec4 over the batch size
2021-01-13 17:14:23 +01:00
for ( int b = 0 ; b < $ { convInfo . batchSize } ; b ++ ) {
for ( int yR = 0 ; yR < $ { convInfo . outHeight } ; yR ++ ) {
int xR = wR + yR * $ { strideHeight } - $ { padTop } ;
2020-11-10 02:13:38 +01:00
2021-01-13 17:14:23 +01:00
if ( xR < 0 || xR >= $ { convInfo . inHeight } ) {
2020-12-16 20:49:14 +01:00
continue ;
}
2020-11-10 02:13:38 +01:00
2021-01-13 17:14:23 +01:00
for ( int yC = 0 ; yC < $ { convInfo . outWidth } ; yC ++ ) {
int xC = wC + yC * $ { strideWidth } - $ { padLeft } ;
2020-11-10 02:13:38 +01:00
2021-01-13 17:14:23 +01:00
if ( xC < 0 || xC >= $ { convInfo . inWidth } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
float dyValue = getDy ( b , yR , yC , d2 ) ;
float xValue = getX ( b , xR , xC , d1 ) ;
dotProd += ( xValue * dyValue ) ;
2020-12-16 20:49:14 +01:00
}
2020-12-15 14:44:42 +01:00
}
2020-12-16 20:49:14 +01:00
}
2021-01-03 16:41:56 +01:00
setOutput ( dotProd ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
` }},DepthwiseConv2DDerInputProgram=class{constructor(convInfo){this.variableNames=["dy","W"],this.outputShape=convInfo.inShape;let filterHeight=convInfo.filterHeight,filterWidth=convInfo.filterWidth,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,padTop=filterHeight-1-convInfo.padInfo.top,padLeft=filterWidth-1-convInfo.padInfo.left,channelMul=convInfo.outChannels/convInfo.inChannels;this.userCode= `
const ivec2 pads = ivec2 ( $ { padTop } , $ { padLeft } ) ;
2020-11-10 02:13:38 +01:00
2020-12-15 14:44:42 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec4 coords = getOutputCoords ( ) ;
2020-12-16 20:49:14 +01:00
int batch = coords [ 0 ] ;
2021-01-03 16:41:56 +01:00
int d1 = coords [ 3 ] ;
ivec2 dyCorner = coords . yz - pads ;
int dyRCorner = dyCorner . x ;
int dyCCorner = dyCorner . y ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
float dotProd = 0.0 ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { filterHeight } ; wR ++ ) {
float dyR = float ( dyRCorner + wR ) / $ { strideHeight } . 0 ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
if ( dyR < 0.0 || dyR >= $ { convInfo . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
2021-01-03 16:41:56 +01:00
continue ;
}
int idyR = int ( dyR ) ;
2020-11-10 02:13:38 +01:00
2021-01-13 17:14:23 +01:00
int wRPerm = $ { filterHeight } - 1 - wR ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { filterWidth } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { strideWidth } . 0 ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
if ( dyC < 0.0 || dyC >= $ { convInfo . outWidth } . 0 ||
2021-01-03 16:41:56 +01:00
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
int wCPerm = $ { filterWidth } - 1 - wC ;
2021-01-03 16:41:56 +01:00
// TO DO: Vec4 over the channelMul
2021-01-13 17:14:23 +01:00
for ( int dm = 0 ; dm < $ { channelMul } ; dm ++ ) {
int d2 = d1 * $ { channelMul } + dm ;
2021-01-03 16:41:56 +01:00
float xValue = getDy ( batch , idyR , idyC , d2 ) ;
float wValue = getW ( wRPerm , wCPerm , d1 , dm ) ;
dotProd += xValue * wValue ;
}
}
2020-12-16 20:49:14 +01:00
}
2021-01-03 16:41:56 +01:00
setOutput ( dotProd ) ;
2020-12-15 14:44:42 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function depthwiseConv2dNativeBackpropFilter3(args){let{inputs,backend:backend22,attrs}=args,{x,dy}=inputs,{strides,dilations,pad:pad3,dimRoundingMode,filterShape}=attrs,convInfo=backend_util_exports.computeConv2DInfo(x.shape,filterShape,strides,dilations,pad3,dimRoundingMode,!0),program=new DepthwiseConv2DDerFilterProgram(convInfo);return backend22.runWebGLProgram(program,[x,dy],"float32")}var depthwiseConv2dNativeBackpropFilterConfig2={kernelName:DepthwiseConv2dNativeBackpropFilter,backendName:"webgl",kernelFunc:depthwiseConv2dNativeBackpropFilter3};function depthwiseConv2dNativeBackpropInput3(args){let{inputs,backend:backend22,attrs}=args,{dy,filter}=inputs,{strides,dilations,pad:pad3,dimRoundingMode,inputShape}=attrs,convInfo=backend_util_exports.computeConv2DInfo(inputShape,filter.shape,strides,dilations,pad3,dimRoundingMode,!0),program=new DepthwiseConv2DDerInputProgram(convInfo);return backend22.runWebGLProgram(program,[dy,filter],"float32")}var depthwiseConv2dNativeBackpropInputConfig2={kernelName:DepthwiseConv2dNativeBackpropInput,backendName:"webgl",kernelFunc:depthwiseConv2dNativeBackpropInput3},DiagProgram=class{constructor(size){this.variableNames=["X"],this.outputShape=[size,size],this.userCode= `
2020-12-15 14:44:42 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec2 coords = getOutputCoords ( ) ;
float val = coords [ 0 ] == coords [ 1 ] ? getX ( coords [ 0 ] ) : 0.0 ;
setOutput ( val ) ;
}
2021-01-13 17:14:23 +01:00
` }};function diag3(args){let{inputs,backend:backend22}=args,{x}=inputs,outShape=[...x.shape,...x.shape],xSize=util_exports.sizeFromShape(x.shape),flat=reshape3({inputs:{x},backend:backend22,attrs:{shape:[xSize]}}),program=new DiagProgram(xSize),res=backend22.runWebGLProgram(program,[flat],flat.dtype),out=reshape3({inputs:{x:res},backend:backend22,attrs:{shape:outShape}});return backend22.disposeIntermediateTensorInfo(flat),backend22.disposeIntermediateTensorInfo(res),out}var diagConfig2={kernelName:Diag,backendName:"webgl",kernelFunc:diag3},Dilation2DProgram=class{constructor(convInfo){this.variableNames=["x","W"],this.outputShape=convInfo.outShape;let{inHeight,inWidth,padInfo,strideHeight,strideWidth,filterHeight,filterWidth,dilationHeight,dilationWidth}=convInfo,{top:padTop,left:padLeft}=padInfo;this.userCode= `
const ivec2 strides = ivec2 ( $ { strideHeight } , $ { strideWidth } ) ;
const ivec2 pads = ivec2 ( $ { padTop } , $ { padLeft } ) ;
2021-01-03 16:41:56 +01:00
const float neg _infinity = - 3.4 e38 ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int d1 = coords . w ;
ivec2 outTopLeftCorner =
coords . yz * strides - pads ;
int hBeg = outTopLeftCorner . x ;
int wBeg = outTopLeftCorner . y ;
float curVal = neg _infinity ;
2021-01-13 17:14:23 +01:00
for ( int h = 0 ; h < $ { filterHeight } ; h ++ ) {
int hIn = hBeg + h * $ { dilationHeight } ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
if ( hIn >= 0 && hIn < $ { inHeight } ) {
for ( int w = 0 ; w < $ { filterWidth } ; w ++ ) {
int wIn = wBeg + w * $ { dilationWidth } ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
if ( wIn >= 0 && wIn < $ { inWidth } ) {
2021-01-03 16:41:56 +01:00
float xVal = getX ( batch , hIn , wIn , d1 ) ;
float wVal = getW ( h , w , d1 ) ;
float val = xVal + wVal ;
if ( val > curVal ) {
curVal = val ;
}
}
}
}
}
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
float result = curVal ;
2020-12-16 20:49:14 +01:00
setOutput ( result ) ;
2020-12-15 14:44:42 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function dilation2D(args){let{inputs,backend:backend22,attrs}=args,{x,filter}=inputs,{strides,pad:pad3,dilations}=attrs,convInfo=backend_util_exports.computeDilation2DInfo(x.shape,filter.shape,strides,pad3,"NHWC",dilations),out,program=new Dilation2DProgram(convInfo);out=backend22.runWebGLProgram(program,[x,filter],"float32");let outReshaped=reshape3({inputs:{x:out},backend:backend22,attrs:{shape:convInfo.outShape}});return backend22.disposeIntermediateTensorInfo(out),outReshaped}var dilation2DConfig={kernelName:Dilation2D,backendName:"webgl",kernelFunc:dilation2D},ELU3="return (x >= 0.0) ? x : (exp(x) - 1.0);",ELU_PACKED= `
2021-01-03 16:41:56 +01:00
vec4 result ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
result . r = ( x . r >= 0.0 ) ? x . r : ( exp ( x . r ) - 1.0 ) ;
result . g = ( x . g >= 0.0 ) ? x . g : ( exp ( x . g ) - 1.0 ) ;
result . b = ( x . b >= 0.0 ) ? x . b : ( exp ( x . b ) - 1.0 ) ;
result . a = ( x . a >= 0.0 ) ? x . a : ( exp ( x . a ) - 1.0 ) ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
return result ;
2021-01-13 17:14:23 +01:00
` ,elu3=unaryKernelFunc2({opSnippet:ELU3,packedOpSnippet:ELU_PACKED}),eluConfig2={kernelName:Elu,backendName:"webgl",kernelFunc:elu3},ELU_DER="return (b >= 1.0) ? a : a * (b + 1.0);",ELU_DER_PACKED= `
2021-01-03 16:41:56 +01:00
vec4 bGTEZero = vec4 ( greaterThanEqual ( b , vec4 ( 0. ) ) ) ;
return ( bGTEZero * a ) + ( ( vec4 ( 1.0 ) - bGTEZero ) * ( a * ( b + vec4 ( 1.0 ) ) ) ) ;
2021-01-13 17:14:23 +01:00
` ,eluGrad2=args=>{let{inputs,backend:backend22}=args,{dy,y}=inputs,program=env().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new BinaryOpPackedProgram(ELU_DER_PACKED,dy.shape,y.shape):new BinaryOpProgram(ELU_DER,dy.shape,y.shape);return backend22.runWebGLProgram(program,[dy,y],dy.dtype)},eluGradConfig3={kernelName:EluGrad,backendName:"webgl",kernelFunc:eluGrad2},PACKED_EQUAL= `
2021-01-03 16:41:56 +01:00
return vec4 ( equal ( a , b ) ) ;
2021-01-13 17:14:23 +01:00
` ,EQUAL="return float(a == b);",equal3=binaryKernelFunc2({opSnippet:EQUAL,packedOpSnippet:PACKED_EQUAL,dtype:"bool"}),equalConfig2={kernelName:Equal,backendName:"webgl",kernelFunc:equal3},ERF= `
2021-01-03 16:41:56 +01:00
// Error function is calculated approximately with elementary function.
// See "Handbook of Mathematical Functions with Formulas,
// Graphs, and Mathematical Tables", Abramowitz and Stegun.
2021-01-13 17:14:23 +01:00
float p = $ { backend _util _exports . ERF _P } ;
float a1 = $ { backend _util _exports . ERF _A1 } ;
float a2 = $ { backend _util _exports . ERF _A2 } ;
float a3 = $ { backend _util _exports . ERF _A3 } ;
float a4 = $ { backend _util _exports . ERF _A4 } ;
float a5 = $ { backend _util _exports . ERF _A5 } ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
float sign = sign ( x ) ;
x = abs ( x ) ;
float t = 1.0 / ( 1.0 + p * x ) ;
return sign * ( 1.0 - ( ( ( ( ( a5 * t + a4 ) * t ) + a3 ) * t + a2 ) * t + a1 ) * t * exp ( - x * x ) ) ;
2021-01-13 17:14:23 +01:00
` ,erf3=unaryKernelFunc2({opSnippet:ERF}),erfConfig2={kernelName:Erf,backendName:"webgl",kernelFunc:erf3},EXP="return exp(x);",exp3=unaryKernelFunc2({opSnippet:EXP,packedOpSnippet:EXP,cpuKernelImpl:expImplCPU}),expConfig2={kernelName:Exp,backendName:"webgl",kernelFunc:exp3};function expandDims3(args){let{inputs,attrs,backend:backend22}=args,{dim}=attrs,{input:input2}=inputs,inputRank=input2.shape.length,newShape=input2.shape.slice(), $ dim=dim;return dim<0&&(util_exports.assert(-(inputRank+1)<=dim,()=> ` Axis must be in the interval [ $ { - ( inputRank + 1 ) } , $ { inputRank } ] ` ), $ dim=inputRank+dim+1),newShape.splice( $ dim,0,1),reshape3({inputs:{x:input2},backend:backend22,attrs:{shape:newShape}})}var expandDimsConfig2={kernelName:ExpandDims,backendName:"webgl",kernelFunc:expandDims3},EXPM1="return exp(x) - 1.0;",expm13=unaryKernelFunc2({opSnippet:EXPM1,packedOpSnippet:EXPM1,cpuKernelImpl:expm1ImplCPU}),expm1Config2={kernelName:Expm1,backendName:"webgl",kernelFunc:expm13},FFTProgram=class{constructor(component,inputShape,inverse){this.variableNames=["real","imag"];let innerDim=inputShape[1];this.outputShape=inputShape;let exponentMultiplierSnippet=inverse? ` 2.0 * $ { Math . PI } ` : ` - 2.0 * $ { Math . PI } ` ,resultDenominator=inverse? ` $ { innerDim } . 0 ` :"1.0",opString;if(component==="real")opString="return real * expR - imag * expI;";else if(component==="imag")opString="return real * expI + imag * expR;";else throw new Error( ` FFT component must be either "real" or "imag" , got $ { component } . ` );this.userCode= `
const float exponentMultiplier = $ { exponentMultiplierSnippet } ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
float unaryOpComplex ( float real , float expR , float imag , float expI ) {
2021-01-13 17:14:23 +01:00
$ { opString }
2021-01-03 16:41:56 +01:00
}
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
float mulMatDFT ( int batch , int index ) {
2021-01-13 17:14:23 +01:00
float indexRatio = float ( index ) / float ( $ { innerDim } ) ;
2021-01-03 16:41:56 +01:00
float exponentMultiplierTimesIndexRatio =
exponentMultiplier * indexRatio ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
float result = 0.0 ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
for ( int i = 0 ; i < $ { innerDim } ; i ++ ) {
2021-01-03 16:41:56 +01:00
// x = (-2|2 * PI / N) * index * i;
float x = exponentMultiplierTimesIndexRatio * float ( i ) ;
float expR = cos ( x ) ;
float expI = sin ( x ) ;
float real = getReal ( batch , i ) ;
float imag = getImag ( batch , i ) ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
result +=
2021-01-13 17:14:23 +01:00
unaryOpComplex ( real , expR , imag , expI ) / $ { resultDenominator } ;
2021-01-03 16:41:56 +01:00
}
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
return result ;
}
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
setOutput ( mulMatDFT ( coords [ 0 ] , coords [ 1 ] ) ) ;
}
2021-01-13 17:14:23 +01:00
` }};function fftImpl2(x,inverse,backend22){let xData=backend22.texData.get(x.dataId),inputSize=util_exports.sizeFromShape(x.shape),innerDimensionSize=x.shape[x.shape.length-1],batch=inputSize/innerDimensionSize,xShape=reshape3({inputs:{x},backend:backend22,attrs:{shape:[batch,innerDimensionSize]}}).shape,realProgram=new FFTProgram("real",xShape,inverse),imagProgram=new FFTProgram("imag",xShape,inverse),inputs=[{dataId:xData.complexTensorInfos.real.dataId,dtype:xData.complexTensorInfos.real.dtype,shape:xShape},{dataId:xData.complexTensorInfos.imag.dataId,dtype:xData.complexTensorInfos.imag.dtype,shape:xShape}],realPart=backend22.runWebGLProgram(realProgram,inputs,"float32"),imagPart=backend22.runWebGLProgram(imagProgram,inputs,"float32"),complexOutput=complex3({inputs:{real:realPart,imag:imagPart},backend:backend22});backend22.disposeIntermediateTensorInfo(realPart),backend22.disposeIntermediateTensorInfo(imagPart);let complexOutputReshaped=reshape3({inputs:{x:complexOutput},backend:backend22,attrs:{shape:x.shape}});return backend22.disposeIntermediateTensorInfo(complexOutputReshaped),complexOutputReshaped}function fft3(args){let{inputs,backend:backend22}=args,{input:input2}=inputs;return fftImpl2(input2,!1,backend22)}var fftConfig2={kernelName:FFT,backendName:"webgl",kernelFunc:fft3},FillProgram=class{constructor(shape,value){this.outputShape=[],this.variableNames=["x"],this.outputShape=shape,this.userCode= `
2021-01-03 16:41:56 +01:00
uniform float value ;
void main ( ) {
// Input can be obtained from uniform value.
setOutput ( value ) ;
}
2021-01-13 17:14:23 +01:00
` }getCustomSetupFunc(value){return(gpgpu,webGLProgram)=>{this.valueLoc==null&&(this.valueLoc=gpgpu.getUniformLocationNoThrow(webGLProgram,"value")),gpgpu.gl.uniform1f(this.valueLoc,value)}}};function fill3(args){let{backend:backend22,attrs}=args,{shape,value}=attrs,{dtype}=attrs;if(dtype=dtype||util_exports.inferDtype(value),dtype==="string"){let values=util_exports.getArrayFromDType(dtype,util_exports.sizeFromShape(shape));return values.fill(value),backend22.makeTensorInfo(shape,dtype,values)}else{let program=new FillProgram(shape,value),customSetup=program.getCustomSetupFunc(value);return backend22.runWebGLProgram(program,[],dtype,customSetup)}}var fillConfig2={kernelName:Fill,backendName:"webgl",kernelFunc:fill3},FlipLeftRightProgram=class{constructor(imageShape){this.variableNames=["Image"],this.outputShape=[];let imageWidth=imageShape[2];this.outputShape=imageShape,this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int x = coords [ 2 ] ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
int coordX = $ { imageWidth } - x ;
2021-01-03 16:41:56 +01:00
float outputValue ;
2021-01-13 17:14:23 +01:00
if ( coordX >= 0 && coordX < $ { imageWidth } ) {
2021-01-03 16:41:56 +01:00
outputValue = getImage ( coords [ 0 ] , coords [ 1 ] , coordX , coords [ 3 ] ) ;
} else {
outputValue = getImage ( coords [ 0 ] , coords [ 1 ] , coords [ 2 ] , coords [ 3 ] ) ;
}
setOutput ( outputValue ) ;
}
2021-01-13 17:14:23 +01:00
` }},flipLeftRightConfig2={kernelName:FlipLeftRight,backendName:"webgl",kernelFunc:({inputs,backend:backend22})=>{let{image:image3}=inputs,webglBackend=backend22,program=new FlipLeftRightProgram(image3.shape);return webglBackend.runWebGLProgram(program,[image3],image3.dtype)}},FLOOR="return floor(x);",floor3=unaryKernelFunc2({opSnippet:FLOOR,packedOpSnippet:FLOOR,cpuKernelImpl:floorImplCPU}),floorConfig2={kernelName:Floor,backendName:"webgl",kernelFunc:floor3},INT_DIV= `
2021-01-03 16:41:56 +01:00
float s = sign ( a ) * sign ( b ) ;
int ia = round ( a ) ;
int ib = round ( b ) ;
if ( ib != 0 ) {
// Windows (D3D) wants guaranteed non-zero int division at compile-time.
return float ( idiv ( ia , ib , s ) ) ;
} else {
return NAN ;
}
2021-01-13 17:14:23 +01:00
` ,INT_DIV_PACKED= `
2021-01-03 16:41:56 +01:00
ivec4 ia = round ( a ) ;
ivec4 ib = round ( b ) ;
bvec4 cond = notEqual ( ib , ivec4 ( 0 ) ) ;
ivec4 result = ivec4 ( 0 ) ;
vec4 s = sign ( a ) * sign ( b ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
// Windows (D3D) wants guaranteed non-zero int division at compile-time.
if ( cond [ 0 ] ) {
result [ 0 ] = idiv ( ia [ 0 ] , ib [ 0 ] , s [ 0 ] ) ;
}
if ( cond [ 1 ] ) {
result [ 1 ] = idiv ( ia [ 1 ] , ib [ 1 ] , s [ 1 ] ) ;
}
if ( cond [ 2 ] ) {
result [ 2 ] = idiv ( ia [ 2 ] , ib [ 2 ] , s [ 2 ] ) ;
}
if ( cond [ 3 ] ) {
result [ 3 ] = idiv ( ia [ 3 ] , ib [ 3 ] , s [ 3 ] ) ;
}
return vec4 ( result ) ;
2021-01-13 17:14:23 +01:00
` ,floorDiv3=binaryKernelFunc2({opSnippet:INT_DIV,packedOpSnippet:INT_DIV_PACKED,dtype:"int32"}),floorDivConfig2={kernelName:FloorDiv,backendName:"webgl",kernelFunc:floorDiv3},FromPixelsProgram=class{constructor(outputShape){this.variableNames=["A"];let glsl=getGlslDifferences(),[height,width]=outputShape;this.outputShape=outputShape,this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
int texR = coords [ 0 ] ;
int texC = coords [ 1 ] ;
int depth = coords [ 2 ] ;
2021-01-13 17:14:23 +01:00
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) / vec2 ( $ { width } . 0 , $ { height } . 0 ) ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
vec4 values = $ { glsl . texture2D } ( A , uv ) ;
2021-01-03 16:41:56 +01:00
float value ;
if ( depth == 0 ) {
value = values . r ;
} else if ( depth == 1 ) {
value = values . g ;
} else if ( depth == 2 ) {
value = values . b ;
} else if ( depth == 3 ) {
value = values . a ;
}
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
setOutput ( floor ( value * 255.0 + 0.5 ) ) ;
}
2021-01-13 17:14:23 +01:00
` }},FromPixelsPackedProgram=class{constructor(outputShape){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;let glsl=getGlslDifferences(),[height,width]=outputShape;this.outputShape=outputShape,this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
int texR = coords [ 0 ] ;
int texC = coords [ 1 ] ;
int depth = coords [ 2 ] ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
vec4 result = vec4 ( 0. ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
for ( int row = 0 ; row <= 1 ; row ++ ) {
for ( int col = 0 ; col <= 1 ; col ++ ) {
texC = coords [ 1 ] + row ;
depth = coords [ 2 ] + col ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
2021-01-13 17:14:23 +01:00
vec2 ( $ { width } . 0 , $ { height } . 0 ) ;
vec4 values = $ { glsl . texture2D } ( A , uv ) ;
2021-01-03 16:41:56 +01:00
float value ;
if ( depth == 0 ) {
value = values . r ;
} else if ( depth == 1 ) {
value = values . g ;
} else if ( depth == 2 ) {
value = values . b ;
} else if ( depth == 3 ) {
value = values . a ;
2020-12-15 14:44:42 +01:00
}
2021-01-03 16:41:56 +01:00
result [ row * 2 + col ] = floor ( value * 255.0 + 0.5 ) ;
2020-12-15 14:44:42 +01:00
}
}
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
$ { glsl . output } = result ;
2020-12-15 14:44:42 +01:00
}
2021-01-13 17:14:23 +01:00
` }},fromPixelsConfig={kernelName:FromPixels,backendName:"webgl",kernelFunc:fromPixels2},fromPixels2DContext2;function fromPixels2(args){let{inputs,backend:backend22,attrs}=args,{pixels}=inputs,{numChannels}=attrs,isVideo=typeof HTMLVideoElement!="undefined"&&pixels instanceof HTMLVideoElement,isImage=typeof HTMLImageElement!="undefined"&&pixels instanceof HTMLImageElement,isImageBitmap=typeof ImageBitmap!="undefined"&&pixels instanceof ImageBitmap,[width,height]=isVideo?[pixels.videoWidth,pixels.videoHeight]:[pixels.width,pixels.height],texShape=[height,width],outShape=[height,width,numChannels];(isImage||isVideo||isImageBitmap)&&(fromPixels2DContext2==null&&(fromPixels2DContext2=document.createElement("canvas").getContext("2d")),fromPixels2DContext2.canvas.width=width,fromPixels2DContext2.canvas.height=height,fromPixels2DContext2.drawImage(pixels,0,0,width,height),pixels=fromPixels2DContext2.canvas);let tempPixelHandle=backend22.makeTensorInfo(texShape,"int32");backend22.texData.get(tempPixelHandle.dataId).usage=TextureUsage.PIXELS,backend22.gpgpu.uploadPixelDataToTexture(backend22.getTexture(tempPixelHandle.dataId),pixels);let program=env().getBool("WEBGL_PACK")?new FromPixelsPackedProgram(outShape):new FromPixelsProgram(outShape),res=backend22.runWebGLProgram(program,[tempPixelHandle],"int32");return backend22.disposeData(tempPixelHandle.dataId),res}function fusedConv2d(args){let{inputs,backend:backend22,attrs}=args,{x,filter,bias,preluActivationWeights}=inputs,{strides,pad:pad3,dataFormat,dilations,dimRoundingMode,activation:activation2,leakyreluAlpha}=attrs, $ dataFormat=backend_util_exports.convertConv2DDataFormat(dataFormat),convInfo=backend_util_exports.computeConv2DInfo(x.shape,filter.shape,strides,dilations,pad3,dimRoundingMode,!1, $ dataFormat),out,intermediates=[];if(convInfo.filterHeight===1&&convInfo.filterWidth===1&&convInfo.dilationHeight===1&&convInfo.dilationWidth===1&&convInfo.strideHeight===1&&convInfo.strideWidth===1&&(convInfo.padInfo.type==="SAME"||convInfo.padInfo.type==="VALID"))out=conv2dByMatMul({x,filter,convInfo,backend:backend22,bias,activation:activation2,preluActivationWeights,leakyreluAlpha});else if(env().getBool("WEBGL_CONV_IM2COL")&&x.shape[0]===1)out=conv2dWithIm2Row({x,filter,convInfo,backend:backend22,bias,activation:activation2,preluActivationWeights,leakyreluAlpha});else{let hasBias=bias!=null,hasPreluActivationWeights=preluActivationWeights!=null,hasLeakyreluAlpha=activation2==="leakyrelu",fusedActivation=activation2?mapActivationToShaderProgram(activation2,!1):null,program=new Conv2DProgram(convInfo,hasBias,fusedActivation,hasPreluActivationWeights,hasLeakyreluAlpha),inputs2=[x,filter];if(bias&&inputs2.push(bias),preluActivationWeights&&inputs2.push(preluActivationWeights),hasLeakyreluAlpha){let $ leakyreluAlpha=backend22.makeTensorInfo([],"float32",util_exports.createScalarValue(leakyreluAlpha,"float32"));inputs2.push( $ leakyreluAlpha),intermediates.push( $ leakyreluAlpha)}out=backend22.runWebGLProgram(program,inputs2,"float32")}let outReshaped=reshape3({inputs:{x:out},backend:backend22,attrs:{shape:convInfo.outShape}});return intermediates.push(out),intermediates.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),outReshaped}var fusedConv2DConfig2={kernelName:FusedConv2D,backendName:"webgl",kernelFunc:fusedConv2d};function fusedDepthwiseConv2D2(args){let{inputs,backend:backend22,attrs}=args,{x,filter,bias,preluActivationWeights}=inputs,{strides,pad:pad3,dilations,dimRoundingMode,activation:activation2,leakyreluAlpha}=attrs,intermediates=[], $ dilations=dilations; $ dilations==null&&( $ dilations=[1,1]),util_exports.assert(backend_util_exports.eitherStridesOrDilationsAreOne(strides, $ dilations),()=> ` Error in depthwiseConv2d : Either strides or dilations must be 1. Got strides $ { strides } and dilations '${$dilations}' ` );let convInfo=backend_util_exports.computeConv2DInfo(x.shape,filter.shape,strides, $ dilations,pad3,dimRoundingMode,!0),shouldPackDepthwiseConv=env().getBool("WEBGL_PACK_DEPTHWISECONV")&&convInfo.strideWidth<=2&&convInfo.outChannels/convInfo.inChannels==1,fusedActivation=ac
$ { stridesType } strides = $ { stridesType } ( $ { this . strides } ) ;
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } coords = getOutputCoords ( ) ;
2021-01-03 16:41:56 +01:00
int flattenIndex = 0 ;
for ( int j = 0 ; j < $ { this . sliceDim } ; j ++ ) {
int index = round ( getIndices ( coords [ 0 ] , j ) ) ;
2021-01-13 17:14:23 +01:00
flattenIndex += index * $ { strideString } ;
2021-01-03 16:41:56 +01:00
}
setOutput ( getX ( flattenIndex , coords [ 1 ] ) ) ;
}
2021-01-13 17:14:23 +01:00
` }};function gatherNd2(args){let{inputs,backend:backend22}=args,{params,indices}=inputs,indicesShape=indices.shape,sliceRank=indicesShape[indicesShape.length-1],[resultShape,numSlices,sliceSize,strides]=backend_util_exports.prepareAndValidate(params,indices),flattenIndices=reshape3({inputs:{x:indices},backend:backend22,attrs:{shape:[numSlices,sliceRank]}}),flattenX=reshape3({inputs:{x:params},backend:backend22,attrs:{shape:[util_exports.sizeFromShape(params.shape)/sliceSize,sliceSize]}}),program=new GatherNDProgram(sliceRank,strides,[numSlices,sliceSize]),res=backend22.runWebGLProgram(program,[flattenX,flattenIndices],flattenX.dtype),reshaped=reshape3({inputs:{x:res},backend:backend22,attrs:{shape:resultShape}});return backend22.disposeIntermediateTensorInfo(flattenIndices),backend22.disposeIntermediateTensorInfo(flattenX),backend22.disposeIntermediateTensorInfo(res),reshaped}var gatherNdConfig2={kernelName:GatherNd,backendName:"webgl",kernelFunc:gatherNd2},GatherProgram=class{constructor(aShape,outputShape){this.variableNames=["A","indices"],this.outputShape=outputShape,this.rank=outputShape.length;let dtype=getCoordsDataType(this.rank),sourceCoords=getSourceCoords2(aShape,2);this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } resRC = getOutputCoords ( ) ;
setOutput ( getA ( $ { sourceCoords } ) ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function getSourceCoords2(aShape,axis){let currentCoords=["resRC.x","resRC.y","resRC.z","resRC.w"],sourceCoords=[];for(let i=0;i<aShape.length;i++)i===2?sourceCoords.push("int(getIndices(resRC.x, resRC.z))"):sourceCoords.push( ` $ { currentCoords [ i ] } ` );return sourceCoords.join()}function gatherV22(args){let{inputs,backend:backend22,attrs}=args,{x,indices}=inputs,{axis,batchDims}=attrs,parsedAxis=util_exports.parseAxisParam(axis,x.shape)[0],shapeInfo=backend_util_exports.segment_util.collectGatherOpShapeInfo(x,indices,parsedAxis,batchDims),indicesSize=util_exports.sizeFromShape(indices.shape),toDispose=[],flattenX=reshape3({inputs:{x},backend:backend22,attrs:{shape:[shapeInfo.batchSize,shapeInfo.outerSize,shapeInfo.dimSize,shapeInfo.sliceSize]}}),flattenIndex=reshape3({inputs:{x:indices},backend:backend22,attrs:{shape:[shapeInfo.batchSize,indicesSize/shapeInfo.batchSize]}});toDispose.push(flattenX),toDispose.push(flattenIndex);let flattenOutputShape=[shapeInfo.batchSize,shapeInfo.outerSize,indicesSize/shapeInfo.batchSize,shapeInfo.sliceSize];if(backend22.shouldExecuteOnCPU([x,indices])||x.dtype==="string"){let indicesBuf=backend22.bufferSync(flattenIndex),xBuf=backend22.bufferSync(flattenX),outBuf=gatherV2ImplCPU(xBuf,indicesBuf,flattenOutputShape);return toDispose.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),backend22.makeTensorInfo(shapeInfo.outputShape,outBuf.dtype,outBuf.values)}let program=new GatherProgram(flattenX.shape,flattenOutputShape),res=backend22.runWebGLProgram(program,[flattenX,flattenIndex],flattenX.dtype);toDispose.push(res);let reshaped=reshape3({inputs:{x:res},backend:backend22,attrs:{shape:shapeInfo.outputShape}});return toDispose.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),reshaped}var gatherV2Config2={kernelName:GatherV2,backendName:"webgl",kernelFunc:gatherV22},GREATER="return float(a > b);",GREATER_PACKED= `
2021-01-03 16:41:56 +01:00
return vec4 ( greaterThan ( a , b ) ) ;
2021-01-13 17:14:23 +01:00
` ,greater3=binaryKernelFunc2({opSnippet:GREATER,packedOpSnippet:GREATER_PACKED,cpuKernelImpl:greaterImplCPU,dtype:"bool"}),greaterConfig2={kernelName:Greater,backendName:"webgl",kernelFunc:greater3},GREATER_EQUAL="return float(a >= b);",GREATER_EQUAL_PACKED= `
2021-01-03 16:41:56 +01:00
return vec4 ( greaterThanEqual ( a , b ) ) ;
2021-01-13 17:14:23 +01:00
` ,greaterEqual3=binaryKernelFunc2({opSnippet:GREATER_EQUAL,packedOpSnippet:GREATER_EQUAL_PACKED,dtype:"bool"}),greaterEqualConfig2={kernelName:GreaterEqual,backendName:"webgl",kernelFunc:greaterEqual3};function ifft3(args){let{inputs,backend:backend22}=args,{input:input2}=inputs;return fftImpl2(input2,!0,backend22)}var ifftConfig2={kernelName:IFFT,backendName:"webgl",kernelFunc:ifft3},IS_FINITE="return float(!isnan(x) && !isinf(x));",isFinite4=unaryKernelFunc2({opSnippet:IS_FINITE,dtype:"bool"}),isFiniteConfig2={kernelName:IsFinite,backendName:"webgl",kernelFunc:isFinite4},IS_INF="return float(isinf(x));",isInf3=unaryKernelFunc2({opSnippet:IS_INF,dtype:"bool"}),isInfConfig2={kernelName:IsInf,backendName:"webgl",kernelFunc:isInf3},IS_NAN="return float(isnan(x));",isNaN4=unaryKernelFunc2({opSnippet:IS_NAN,dtype:"bool"}),isNaNConfig2={kernelName:IsNan,backendName:"webgl",kernelFunc:isNaN4},LESS="return float(a < b);",LESS_PACKED= `
2021-01-03 16:41:56 +01:00
return vec4 ( lessThan ( a , b ) ) ;
2021-01-13 17:14:23 +01:00
` ,less3=binaryKernelFunc2({opSnippet:LESS,packedOpSnippet:LESS_PACKED,cpuKernelImpl:lessImplCPU,dtype:"bool"}),lessConfig2={kernelName:Less,backendName:"webgl",kernelFunc:less3},LESS_EQUAL="return float(a <= b);",LESS_EQUAL_PACKED= `
2021-01-03 16:41:56 +01:00
return vec4 ( lessThanEqual ( a , b ) ) ;
2021-01-13 17:14:23 +01:00
` ,lessEqual3=binaryKernelFunc2({opSnippet:LESS_EQUAL,packedOpSnippet:LESS_EQUAL_PACKED,dtype:"bool"}),lessEqualConfig2={kernelName:LessEqual,backendName:"webgl",kernelFunc:lessEqual3};function linSpace2(args){let{backend:backend22,attrs}=args,{start,stop,num}=attrs,outVals=linSpaceImplCPU(start,stop,num);return backend22.makeTensorInfo([outVals.length],"float32",outVals)}var linSpaceConfig2={kernelName:LinSpace,backendName:"webgl",kernelFunc:linSpace2},LOG= ` if ( x < 0.0 ) return NAN ;
return log ( x ) ; ` ,LOG_PACKED= `
2021-01-03 16:41:56 +01:00
vec4 result = log ( x ) ;
vec4 isNaN = vec4 ( lessThan ( x , vec4 ( 0.0 ) ) ) ;
result . r = isNaN . r == 1.0 ? NAN : result . r ;
result . g = isNaN . g == 1.0 ? NAN : result . g ;
result . b = isNaN . b == 1.0 ? NAN : result . b ;
result . a = isNaN . a == 1.0 ? NAN : result . a ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
return result ;
2021-01-13 17:14:23 +01:00
` ,log4=unaryKernelFunc2({opSnippet:LOG,packedOpSnippet:LOG_PACKED,cpuKernelImpl:logImplCPU}),logConfig2={kernelName:Log,backendName:"webgl",kernelFunc:log4},LOG1P="return log(1.0 + x);",log1p3=unaryKernelFunc2({opSnippet:LOG1P}),log1pConfig2={kernelName:Log1p,backendName:"webgl",kernelFunc:log1p3},LOGICAL_AND="return float(a >= 1.0 && b >= 1.0);",LOGICAL_AND_PACKED= `
2021-01-03 16:41:56 +01:00
return vec4 (
vec4 ( greaterThanEqual ( a , vec4 ( 1.0 ) ) ) *
vec4 ( greaterThanEqual ( b , vec4 ( 1.0 ) ) ) ) ;
2021-01-13 17:14:23 +01:00
` ,logicalAnd3=binaryKernelFunc2({opSnippet:LOGICAL_AND,packedOpSnippet:LOGICAL_AND_PACKED,dtype:"bool"}),logicalAndConfig2={kernelName:LogicalAnd,backendName:"webgl",kernelFunc:logicalAnd3},LOGICAL_NOT="return float(!(x >= 1.0));",logicalNot3=unaryKernelFunc2({opSnippet:LOGICAL_NOT}),logicalNotConfig2={kernelName:LogicalNot,backendName:"webgl",kernelFunc:logicalNot3},LOGICAL_OR="return float(a >= 1.0 || b >= 1.0);",LOGICAL_OR_PACKED= `
2021-01-03 16:41:56 +01:00
return min (
vec4 ( greaterThanEqual ( a , vec4 ( 1.0 ) ) ) +
vec4 ( greaterThanEqual ( b , vec4 ( 1.0 ) ) ) ,
vec4 ( 1.0 ) ) ;
2021-01-13 17:14:23 +01:00
` ,logicalOr3=binaryKernelFunc2({opSnippet:LOGICAL_OR,packedOpSnippet:LOGICAL_OR_PACKED,dtype:"bool"}),logicalOrConfig2={kernelName:LogicalOr,backendName:"webgl",kernelFunc:logicalOr3},LRNProgram=class{constructor(xShape,radius,bias,alpha,beta){this.variableNames=["x"],this.outputShape=[];let rad=radius,maxD=xShape[3]-1;this.outputShape=xShape;let powOperator,basis= ` float ( $ { bias } ) + float ( $ { alpha } ) * sum ` ;beta===.5?powOperator= ` inversesqrt ( $ { basis } ) ` :beta===1?powOperator= ` 1.0 / ( $ { basis } ) ` :powOperator= ` exp ( log ( $ { basis } ) * float ( - $ { beta } ) ) ; ` ,this.userCode= `
2020-12-15 14:44:42 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
2021-01-03 16:41:56 +01:00
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
2020-12-16 20:49:14 +01:00
int d = coords [ 3 ] ;
2021-01-03 16:41:56 +01:00
float x = getX ( b , r , c , d ) ;
float sum = 0.0 ;
2021-01-13 17:14:23 +01:00
for ( int j = - $ { rad } ; j <= $ { rad } ; j ++ ) {
2021-01-03 16:41:56 +01:00
int idx = d + j ;
2021-01-13 17:14:23 +01:00
if ( idx >= 0 && idx <= $ { maxD } ) {
2021-01-03 16:41:56 +01:00
float z = getX ( b , r , c , idx ) ;
sum += z * z ;
}
}
2021-01-13 17:14:23 +01:00
float val = x * $ { powOperator } ;
2021-01-03 16:41:56 +01:00
setOutput ( val ) ;
}
2021-01-13 17:14:23 +01:00
` }},LRNPackedProgram=class{constructor(xShape,radius,bias,alpha,beta){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;let rad=radius,maxD=xShape[3]-1;this.outputShape=xShape;let powOperator,basis= ` float ( $ { bias } ) + float ( $ { alpha } ) * sum ` ;beta===.5?powOperator= ` inversesqrt ( $ { basis } ) ` :beta===1?powOperator= ` 1.0 / ( $ { basis } ) ` :powOperator= ` exp ( log ( $ { basis } ) * float ( - $ { beta } ) ) ; ` ,this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords . x ;
int r = coords . y ;
int c = coords . z ;
int d = coords . w ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
bool hasNextCol = d < $ { this . outputShape [ 3 ] } ;
bool hasNextRow = c < $ { this . outputShape [ 2 ] } ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
vec4 sum = vec4 ( 0. ) ;
vec4 xFragAtOutputCoords = getX ( b , r , c , d ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
vec4 xAtOutputCoords = vec4 (
getChannel ( xFragAtOutputCoords , vec2 ( c , d ) ) ,
hasNextCol ?
getChannel ( xFragAtOutputCoords , vec2 ( c , d + 1 ) ) : 0.0 ,
hasNextRow ?
getChannel ( xFragAtOutputCoords , vec2 ( c + 1 , d ) ) : 0.0 ,
( hasNextRow && hasNextCol ) ?
getChannel ( xFragAtOutputCoords , vec2 ( c + 1 , d + 1 ) ) : 0.0
) ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
int firstChannel = d - $ { rad } ;
2021-01-03 16:41:56 +01:00
vec2 cache = vec2 ( 0. ) ;
if ( firstChannel >= 0 ) {
vec4 firstChannelFrag = getX ( b , r , c , firstChannel ) ;
cache . x = getChannel ( firstChannelFrag , vec2 ( c , firstChannel ) ) ;
if ( hasNextRow ) {
cache . y = getChannel ( firstChannelFrag , vec2 ( c + 1 , firstChannel ) ) ;
}
}
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
ivec2 depth = ivec2 ( d , d + 1 ) ;
2021-01-13 17:14:23 +01:00
for ( int j = - $ { rad } ; j <= $ { rad } ; j ++ ) {
2021-01-03 16:41:56 +01:00
ivec2 idx = depth + j ;
bvec2 aboveLowerBound = greaterThanEqual ( idx , ivec2 ( 0 ) ) ;
2021-01-13 17:14:23 +01:00
bvec2 belowUpperBound = lessThanEqual ( idx , ivec2 ( $ { maxD } ) ) ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
bool depthInRange = aboveLowerBound . x && belowUpperBound . x ;
bool depthPlusOneInRange = aboveLowerBound . y && belowUpperBound . y ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
if ( depthInRange || depthPlusOneInRange ) {
vec4 z = vec4 ( 0. ) ;
vec4 xFragAtCurrentDepth ;
z . xz = cache . xy ;
if ( depthPlusOneInRange && hasNextCol ) {
xFragAtCurrentDepth = idx . y != d ?
getX ( b , r , c , idx . y ) : xFragAtOutputCoords ;
z . y = getChannel ( xFragAtCurrentDepth , vec2 ( c , idx . y ) ) ;
if ( hasNextRow ) {
z . w = getChannel ( xFragAtCurrentDepth , vec2 ( c + 1 , idx . y ) ) ;
}
}
cache . xy = z . yw ;
sum += z * z ;
}
}
2021-01-13 17:14:23 +01:00
vec4 result = xAtOutputCoords * $ { powOperator } ;
2021-01-03 16:41:56 +01:00
setOutput ( result ) ;
2020-12-15 14:44:42 +01:00
}
2021-01-13 17:14:23 +01:00
` }},lrn=args=>{let{inputs,backend:backend22,attrs}=args,{x}=inputs,{depthRadius,bias,alpha,beta}=attrs,program=env().getBool("WEBGL_PACK_NORMALIZATION")?new LRNPackedProgram(x.shape,depthRadius,bias,alpha,beta):new LRNProgram(x.shape,depthRadius,bias,alpha,beta);return backend22.runWebGLProgram(program,[x],x.dtype)},LRNConfig={kernelName:LRN,backendName:"webgl",kernelFunc:lrn},LRNGradProgram=class{constructor(inputShape,depthRadius,bias,alpha,beta){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=inputShape,this.depth=inputShape[3],this.depthRadius=depthRadius,this.bias=bias,this.alpha=alpha,this.beta=beta,this.userCode= `
2020-12-15 14:44:42 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
2021-01-03 16:41:56 +01:00
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
float result = 0.0 ;
for ( int d = 0 ; d < $ { this . depth } ; ++ d ) {
2021-01-13 17:14:23 +01:00
int depthBegin = int ( max ( 0.0 , float ( d - $ { depthRadius } ) ) ) ;
2021-01-03 16:41:56 +01:00
int depthEnd = int ( min ( float ( $ { this . depth } ) ,
2021-01-13 17:14:23 +01:00
float ( d + $ { depthRadius } + 1 ) ) ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
const int MIN _DEPTH _BEGIN = 0 ;
const int MAX _DEPTH _END = $ { this . depth } ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
float norm = 0.0 ;
for ( int k = MIN _DEPTH _BEGIN ; k < MAX _DEPTH _END ; ++ k ) {
if ( k < depthBegin ) {
continue ;
}
else if ( k >= depthBegin && k < depthEnd ) {
norm += getInputImage ( b , r , c , k ) * getInputImage ( b , r , c , k ) ;
}
else {
break ;
}
}
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
norm = float ( $ { alpha } ) * norm + float ( $ { bias } ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
for ( int k = MIN _DEPTH _BEGIN ; k < MAX _DEPTH _END ; ++ k ) {
if ( k < depthBegin ) {
continue ;
}
else if ( k >= depthBegin && k < depthEnd ) {
2021-01-13 17:14:23 +01:00
float dyi = - 2.0 * float ( $ { alpha } )
* float ( $ { beta } )
2021-01-03 16:41:56 +01:00
* getInputImage ( b , r , c , k ) * getOutputImage ( b , r , c , d )
/ n o r m ;
if ( k == d ) {
2021-01-13 17:14:23 +01:00
dyi += pow ( norm , - 1.0 * $ { beta } ) ;
2021-01-03 16:41:56 +01:00
}
if ( k == coords [ 3 ] ) {
dyi *= getDy ( b , r , c , d ) ;
result += dyi ;
}
}
else {
break ;
}
}
2020-12-16 20:49:14 +01:00
}
2021-01-03 16:41:56 +01:00
setOutput ( result ) ;
}
2021-01-13 17:14:23 +01:00
` }},lrnGrad=args=>{let{inputs,backend:backend22,attrs}=args,{x,y,dy}=inputs,{depthRadius,bias,alpha,beta}=attrs,program=new LRNGradProgram(x.shape,depthRadius,bias,alpha,beta);return backend22.runWebGLProgram(program,[x,y,dy],x.dtype)},LRNGradConfig={kernelName:LRNGrad,backendName:"webgl",kernelFunc:lrnGrad};function maxImpl2(x,reduceShape,outShape,backend22){let inSize=util_exports.sizeFromShape(reduceShape),batchSize=util_exports.sizeFromShape(x.shape)/inSize,reshapedInput=reshape3({inputs:{x},attrs:{shape:[batchSize,inSize]},backend:backend22}),reduced=reduce(reshapedInput,x.dtype,"max",backend22),reshapedOutput=reshape3({inputs:{x:reduced},attrs:{shape:outShape},backend:backend22});return backend22.disposeIntermediateTensorInfo(reshapedInput),backend22.disposeIntermediateTensorInfo(reduced),reshapedOutput}function max3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{reductionIndices,keepDims}=attrs,xRank=x.shape.length,origAxes=util_exports.parseAxisParam(reductionIndices,x.shape),axes=origAxes,permutedAxes=backend_util_exports.getAxesPermutation(axes,xRank),maxInputIsTransposed=permutedAxes!=null,shouldExecuteOnCPU=backend22.shouldExecuteOnCPU([x]),maxInput=x;if(maxInputIsTransposed){if(shouldExecuteOnCPU){let values=backend22.texData.get(maxInput.dataId).values,newShape=new Array(xRank);for(let i=0;i<newShape.length;i++)newShape[i]=x.shape[permutedAxes[i]];let maxInputValues=transposeImplCPU(values,x.shape,x.dtype,permutedAxes,newShape);maxInput=backend22.makeTensorInfo(newShape,x.dtype);let maxInputData=backend22.texData.get(maxInput.dataId);maxInputData.values=maxInputValues}else maxInput=transposeImpl2(x,permutedAxes,backend22);axes=backend_util_exports.getInnerMostAxes(axes.length,xRank)}backend_util_exports.assertAxesAreInnerMostDims("max",axes,xRank);let[maxOutShape,reduceShape]=backend_util_exports.computeOutAndReduceShapes(maxInput.shape,axes),outShape=maxOutShape;keepDims&&(outShape=backend_util_exports.expandShapeToKeepDim(maxOutShape,origAxes));let out;if(shouldExecuteOnCPU){let values=backend22.texData.get(maxInput.dataId).values,outValues=maxImplCPU(values,util_exports.sizeFromShape(reduceShape),outShape,x.dtype);out=backend22.makeTensorInfo(outShape,x.dtype);let outData=backend22.texData.get(out.dataId);outData.values=outValues}else out=maxImpl2(maxInput,reduceShape,outShape,backend22);return maxInputIsTransposed&&backend22.disposeIntermediateTensorInfo(maxInput),out}var maxConfig2={kernelName:Max,backendName:"webgl",kernelFunc:max3},MAXIMUM=CHECK_NAN_SNIPPET2+ `
2021-01-03 16:41:56 +01:00
return max ( a , b ) ;
2021-01-13 17:14:23 +01:00
` ,MAXIMUM_PACKED= `
2021-01-03 16:41:56 +01:00
vec4 result = vec4 ( max ( a , b ) ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
2021-01-13 17:14:23 +01:00
` +CHECK_NAN_SNIPPET3+ `
2021-01-03 16:41:56 +01:00
return result ;
2021-01-13 17:14:23 +01:00
` ,maximum3=binaryKernelFunc2({opSnippet:MAXIMUM,packedOpSnippet:MAXIMUM_PACKED,cpuKernelImpl:maximumImplCPU}),maximumConfig2={kernelName:Maximum,backendName:"webgl",kernelFunc:maximum3};function maxPool3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs;assertNotComplex2(x,"maxPool");let{filterSize,strides,pad:pad3,dimRoundingMode}=attrs,dilations=1;util_exports.assert(backend_util_exports.eitherStridesOrDilationsAreOne(strides,dilations),()=> ` Error in maxPool : Either strides or dilations must be 1. Got strides $ { strides } and dilations '${dilations}' ` );let convInfo=backend_util_exports.computePool2DInfo(x.shape,filterSize,strides,dilations,pad3,dimRoundingMode);if(convInfo.filterWidth===1&&convInfo.filterHeight===1&&util_exports.arraysEqual(convInfo.inShape,convInfo.outShape))return identity2({inputs:{x},backend:backend22});let maxPoolProgram=new Pool2DProgram(convInfo,"max",!1);return backend22.runWebGLProgram(maxPoolProgram,[x],x.dtype)}var maxPoolConfig2={kernelName:MaxPool,backendName:"webgl",kernelFunc:maxPool3};function maxPool3d2(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{filterSize,strides,pad:pad3,dataFormat,dimRoundingMode}=attrs,dilations=[1,1,1],convInfo=backend_util_exports.computePool3DInfo(x.shape,filterSize,strides,dilations,pad3,dimRoundingMode,dataFormat),maxPoolProgram=new Pool3DProgram(convInfo,"max",!1);return backend22.runWebGLProgram(maxPoolProgram,[x],x.dtype)}var maxPool3DConfig2={kernelName:MaxPool3D,backendName:"webgl",kernelFunc:maxPool3d2},MaxPool2DBackpropProgram=class{constructor(convInfo){this.variableNames=["dy","maxPos"],this.outputShape=convInfo.inShape;let strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,dilationHeight=convInfo.dilationHeight,effectiveFilterHeight=convInfo.effectiveFilterHeight,effectiveFilterWidth=convInfo.effectiveFilterWidth,padTop=effectiveFilterHeight-1-convInfo.padInfo.top,padLeft=effectiveFilterWidth-1-convInfo.padInfo.left,lastIndex=effectiveFilterHeight*effectiveFilterWidth-1;this.userCode= `
const ivec2 pads = ivec2 ( $ { padTop } , $ { padLeft } ) ;
2021-01-03 16:41:56 +01:00
2020-12-15 14:44:42 +01:00
void main ( ) {
2020-12-16 20:49:14 +01:00
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
ivec2 dyRCCorner = coords . yz - pads ;
int dyRCorner = dyRCCorner . x ;
int dyCCorner = dyRCCorner . y ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
// Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { effectiveFilterHeight } ;
wR += $ { dilationHeight } ) {
float dyR = float ( dyRCorner + wR ) / $ { strideHeight } . 0 ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
if ( dyR < 0.0 || dyR >= $ { convInfo . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
2021-01-03 16:41:56 +01:00
continue ;
}
int idyR = int ( dyR ) ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { effectiveFilterWidth } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { strideWidth } . 0 ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
if ( dyC < 0.0 || dyC >= $ { convInfo . outWidth } . 0 ||
2021-01-03 16:41:56 +01:00
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
float dyValue = getDy ( b , idyR , idyC , d ) ;
2021-01-13 17:14:23 +01:00
int maxPosValue = $ { lastIndex } - int ( getMaxPos ( b , idyR , idyC , d ) ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
// Get the current value, check it against the value from the
// position matrix.
2021-01-13 17:14:23 +01:00
int curPosValue = wR * $ { effectiveFilterWidth } + wC ;
2021-01-03 16:41:56 +01:00
float mask = float ( maxPosValue == curPosValue ? 1.0 : 0.0 ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
dotProd += dyValue * mask ;
}
}
setOutput ( dotProd ) ;
}
2021-01-13 17:14:23 +01:00
` }},MaxPool3DBackpropProgram=class{constructor(convInfo){this.variableNames=["dy","maxPos"],this.outputShape=convInfo.inShape;let strideDepth=convInfo.strideDepth,strideHeight=convInfo.strideHeight,strideWidth=convInfo.strideWidth,dilationDepth=convInfo.dilationDepth,dilationHeight=convInfo.dilationHeight,dilationWidth=convInfo.dilationWidth,effectiveFilterDepth=convInfo.effectiveFilterDepth,effectiveFilterHeight=convInfo.effectiveFilterHeight,effectiveFilterWidth=convInfo.effectiveFilterWidth,padFront=effectiveFilterDepth-1-convInfo.padInfo.front,padTop=effectiveFilterHeight-1-convInfo.padInfo.top,padLeft=effectiveFilterWidth-1-convInfo.padInfo.left,lastIndex=effectiveFilterDepth*effectiveFilterHeight*effectiveFilterWidth-1;this.userCode= `
const ivec3 pads = ivec3 ( $ { padFront } , $ { padTop } , $ { padLeft } ) ;
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
ivec3 dyCorner = ivec3 ( coords . y , coords . z , coords . w ) - pads ;
int dyDCorner = dyCorner . x ;
int dyRCorner = dyCorner . y ;
int dyCCorner = dyCorner . z ;
// Convolve dy(?, ?, ?, ch) with pos mask(:, :, :, d) to get
// dx(xD, xR, xC, ch).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
2021-01-13 17:14:23 +01:00
for ( int wD = 0 ; wD < $ { effectiveFilterDepth } ;
wD += $ { dilationDepth } ) {
float dyD = float ( dyDCorner + wD ) / $ { strideDepth } . 0 ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
if ( dyD < 0.0 || dyD >= $ { convInfo . outDepth } . 0 || fract ( dyD ) > 0.0 ) {
2020-12-15 14:44:42 +01:00
continue ;
}
2021-01-03 16:41:56 +01:00
int idyD = int ( dyD ) ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
for ( int wR = 0 ; wR < $ { effectiveFilterHeight } ;
wR += $ { dilationHeight } ) {
float dyR = float ( dyRCorner + wR ) / $ { strideHeight } . 0 ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
if ( dyR < 0.0 || dyR >= $ { convInfo . outHeight } . 0 ||
2021-01-03 16:41:56 +01:00
fract ( dyR ) > 0.0 ) {
2020-12-15 14:44:42 +01:00
continue ;
}
2021-01-03 16:41:56 +01:00
int idyR = int ( dyR ) ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
for ( int wC = 0 ; wC < $ { effectiveFilterWidth } ;
wC += $ { dilationWidth } ) {
float dyC = float ( dyCCorner + wC ) / $ { strideWidth } . 0 ;
2020-12-15 14:44:42 +01:00
2021-01-13 17:14:23 +01:00
if ( dyC < 0.0 || dyC >= $ { convInfo . outWidth } . 0 ||
2021-01-03 16:41:56 +01:00
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
float dyValue = getDy ( batch , idyD , idyR , idyC , ch ) ;
2021-01-13 17:14:23 +01:00
int maxPosValue = $ { lastIndex } -
2021-01-03 16:41:56 +01:00
int ( getMaxPos ( batch , idyD , idyR , idyC , ch ) ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
// Get the current value, check it against the value from the
// position matrix.
int curPosValue =
2021-01-13 17:14:23 +01:00
wD * $ { effectiveFilterHeight } * $ { effectiveFilterWidth } +
wR * $ { effectiveFilterWidth } + wC ;
2021-01-03 16:41:56 +01:00
float mask = float ( maxPosValue == curPosValue ? 1.0 : 0.0 ) ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
dotProd += dyValue * mask ;
2020-12-15 14:44:42 +01:00
}
}
}
2021-01-03 16:41:56 +01:00
setOutput ( dotProd ) ;
2020-12-15 14:44:42 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function maxPool3DGrad2(args){let{inputs,backend:backend22,attrs}=args,{dy,input:input2}=inputs,x=input2,{filterSize,strides,pad:pad3,dimRoundingMode}=attrs,dilations=[1,1,1],convInfo=backend_util_exports.computePool3DInfo(x.shape,filterSize,strides,dilations,pad3,dimRoundingMode),maxPool3dPositionsProgram=new Pool3DProgram(convInfo,"max",!0),maxPool3dPositions2=backend22.runWebGLProgram(maxPool3dPositionsProgram,[x],x.dtype),maxPoolBackpropProgram=new MaxPool3DBackpropProgram(convInfo),result=backend22.runWebGLProgram(maxPoolBackpropProgram,[dy,maxPool3dPositions2],x.dtype);return backend22.disposeIntermediateTensorInfo(maxPool3dPositions2),result}var maxPoolGrad3DConfig={kernelName:MaxPool3DGrad,backendName:"webgl",kernelFunc:maxPool3DGrad2};function maxPoolGrad3(args){let{inputs,backend:backend22,attrs}=args,{dy,input:input2,output}=inputs,x=input2;assertNotComplex2([input2,output],"maxPoolGrad");let{filterSize,strides,pad:pad3,dimRoundingMode}=attrs,convInfo=backend_util_exports.computePool2DInfo(x.shape,filterSize,strides,1,pad3,dimRoundingMode),getPositions=!0,maxPoolPositionsProgram=new Pool2DProgram(convInfo,"max",getPositions),maxPoolPositions2=backend22.runWebGLProgram(maxPoolPositionsProgram,[x],x.dtype),maxPoolBackPropProgram=new MaxPool2DBackpropProgram(convInfo),result=backend22.runWebGLProgram(maxPoolBackPropProgram,[dy,maxPoolPositions2],x.dtype);return backend22.disposeIntermediateTensorInfo(maxPoolPositions2),result}var maxPoolGradConfig3={kernelName:MaxPoolGrad,backendName:"webgl",kernelFunc:maxPoolGrad3};function maxPoolWithArgmaxImpl2(x,includeBatchInIndex,convInfo,backend22){let program=new Pool2DProgram(convInfo,"max",!1),poolOutput=backend22.runWebGLProgram(program,[x],"float32");program=new Pool2DProgram(convInfo,"max",!0,!0,includeBatchInIndex);let indexOutput=backend22.runWebGLProgram(program,[x],"float32");return[poolOutput,indexOutput]}var maxPoolWithArgmaxConfig2={kernelName:MaxPoolWithArgmax,backendName:"webgl",kernelFunc:({inputs,attrs,backend:backend22})=>{let{x}=inputs,{filterSize,strides,pad:pad3,includeBatchInIndex}=attrs,webglBackend=backend22;util_exports.assert(x.shape.length===4,()=> ` Error in maxPool : input must be rank 4 but got rank $ { x . shape . length } . ` );let dilations=[1,1];util_exports.assert(backend_util_exports.eitherStridesOrDilationsAreOne(strides,dilations),()=> ` Error in maxPool : Either strides or dilations must be 1. Got strides $ { strides } and dilations '${dilations}' ` );let convInfo=backend_util_exports.computePool2DInfo(x.shape,filterSize,strides,dilations,pad3),[result,indexes]=maxPoolWithArgmaxImpl2(x,includeBatchInIndex,convInfo,webglBackend);return[result,indexes]}};function meanImpl(x,reduceShape,outShape,backend22){let inSize=util_exports.sizeFromShape(reduceShape),batchSize=util_exports.sizeFromShape(x.shape)/inSize,reshapedInput=reshape3({inputs:{x},attrs:{shape:[batchSize,inSize]},backend:backend22}),reduced=reduce(reshapedInput,"float32","mean",backend22),reshapedOutput=reshape3({inputs:{x:reduced},attrs:{shape:outShape},backend:backend22});return backend22.disposeIntermediateTensorInfo(reshapedInput),backend22.disposeIntermediateTensorInfo(reduced),reshapedOutput}var meanConfig2={kernelName:Mean,backendName:"webgl",kernelFunc:({inputs,attrs,backend:backend22})=>{let{x}=inputs,{keepDims,axis}=attrs,webglBackend=backend22,xRank=x.shape.length,origAxes=util_exports.parseAxisParam(axis,x.shape),axes=origAxes,permutedAxes=backend_util_exports.getAxesPermutation(axes,xRank),meanInputIsTransposed=permutedAxes!=null,shouldExecuteOnCPU=webglBackend.shouldExecuteOnCPU([x]),intermediates=[],meanInput=x;if(meanInputIsTransposed){if(shouldExecuteOnCPU){let values=webglBackend.texData.get(meanInput.dataId).values,newShape=new Array(xRank);for(let i=0;i<newShape.length;i++)newShape[i]=x.shape[permutedAxes[i]];let meanInputValues=transposeImplCPU(values,x.shape,x.dtype,permutedAxes,newShape);meanInput=webglBackend.makeTensorInfo(newShape,x.dtype);let meanInputData=webglBackend.texData.get(meanInput.dataId);meanInputData.values=meanInputValues}else meanInput=transposeIm
2021-01-03 16:41:56 +01:00
return min ( a , b ) ;
2021-01-13 17:14:23 +01:00
` ,MINIMUM_PACKED= `
2021-01-03 16:41:56 +01:00
vec4 result = vec4 ( min ( a , b ) ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
2021-01-13 17:14:23 +01:00
` +CHECK_NAN_SNIPPET3+ `
2021-01-03 16:41:56 +01:00
return result ;
2021-01-13 17:14:23 +01:00
` ,minimum3=binaryKernelFunc2({opSnippet:MINIMUM,packedOpSnippet:MINIMUM_PACKED,cpuKernelImpl:minimumImplCPU}),minimumConfig2={kernelName:Minimum,backendName:"webgl",kernelFunc:minimum3},MirrorPadProgram=class{constructor(xShape,paddings,mode){this.variableNames=["x"],this.outputShape=paddings.map((p2,i)=>p2[0]+xShape[i]+p2[1]);let rank=xShape.length,dtype=getCoordsDataType(rank),start=paddings.map(p2=>p2[0]).join(","),end=paddings.map((p2,i)=>p2[0]+xShape[i]).join(","),unpackedCoords=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,rank),offset=mode==="reflect"?0:1;if(rank===1){this.userCode= `
int start = $ { start } ;
int end = $ { end } ;
2020-12-15 14:44:42 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
int outC = getOutputCoords ( ) ;
if ( outC < start ) {
2021-01-13 17:14:23 +01:00
outC = start * 2 - outC - $ { offset } ;
2021-01-03 16:41:56 +01:00
} else if ( outC >= end ) {
2021-01-13 17:14:23 +01:00
outC = ( end - 1 ) * 2 - outC + $ { offset } ;
2021-01-03 16:41:56 +01:00
}
setOutput ( getX ( outC - start ) ) ;
2020-12-15 14:44:42 +01:00
}
2021-01-03 16:41:56 +01:00
` ;return}this.userCode= `
2021-01-13 17:14:23 +01:00
$ { dtype } start = $ { dtype } ( $ { start } ) ;
$ { dtype } end = $ { dtype } ( $ { end } ) ;
2021-01-03 16:41:56 +01:00
2020-12-15 14:44:42 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } outC = getOutputCoords ( ) ;
for ( int i = 0 ; i < $ { rank } ; i ++ ) {
2021-01-03 16:41:56 +01:00
if ( outC [ i ] < start [ i ] ) {
2021-01-13 17:14:23 +01:00
outC [ i ] = start [ i ] * 2 - outC [ i ] - $ { offset } ;
2021-01-03 16:41:56 +01:00
} else if ( outC [ i ] >= end [ i ] ) {
2021-01-13 17:14:23 +01:00
outC [ i ] = ( end [ i ] - 1 ) * 2 - outC [ i ] + $ { offset } ;
2020-12-15 14:44:42 +01:00
}
}
2021-01-13 17:14:23 +01:00
$ { dtype } coords = outC - start ;
setOutput ( getX ( $ { unpackedCoords } ) ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }},MirrorPadPackedProgram=class{constructor(xShape,paddings,mode){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=paddings.map((p2,i)=>p2[0]+xShape[i]+p2[1]);let rank=xShape.length,dtype=getCoordsDataType(rank),start=paddings.map(p2=>p2[0]).join(","),end=paddings.map((p2,i)=>p2[0]+xShape[i]).join(","),coords2=getChannels("rc",rank),source=getChannels("source",rank),cLimit= ` $ { coords2 [ rank - 1 ] } < $ { this . outputShape [ rank - 1 ] } ` ,innerDims=rank===1?"source": ` vec2 ( $ { source . slice ( - 2 ) . join ( ) } ) ` ,offset=mode==="reflect"?0:1,mainLoop="";if(rank===1){let padSetup= `
$ { dtype } source = rc ;
2021-01-03 16:41:56 +01:00
if ( source < start ) {
2021-01-13 17:14:23 +01:00
source = start * 2 - source - $ { offset } ;
2021-01-03 16:41:56 +01:00
} else if ( source >= end ) {
2021-01-13 17:14:23 +01:00
source = ( end - 1 ) * 2 - source + $ { offset } ;
2020-12-15 14:44:42 +01:00
}
2021-01-03 16:41:56 +01:00
source -= start ;
2021-01-13 17:14:23 +01:00
` ;mainLoop= `
$ { dtype } rc = outputLoc ;
$ { padSetup }
result [ 0 ] = getChannel ( getX ( $ { source . join ( ) } ) , $ { innerDims } ) ;
$ { coords2 [ rank - 1 ] } += 1 ;
if ( $ { cLimit } ) {
$ { padSetup }
result [ 1 ] = getChannel ( getX ( $ { source . join ( ) } ) , $ { innerDims } ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }else{let padSetup= `
$ { dtype } source = rc ;
$ { dtype } lt = $ { dtype } ( lessThan ( source , start ) ) ;
$ { dtype } gte = $ { dtype } ( greaterThanEqual ( source , end ) ) ;
$ { dtype } orig = 1 - ( lt + gte ) ;
2021-01-03 16:41:56 +01:00
source = orig * source +
2021-01-13 17:14:23 +01:00
lt * ( start * 2 - source - $ { offset } ) +
gte * ( ( end - 1 ) * 2 - source + $ { offset } ) ;
2021-01-03 16:41:56 +01:00
source -= start ;
2021-01-13 17:14:23 +01:00
` ;mainLoop= `
$ { dtype } rc = outputLoc ;
$ { padSetup }
result [ 0 ] = getChannel ( getX ( $ { source . join ( ) } ) , $ { innerDims } ) ;
$ { coords2 [ rank - 1 ] } += 1 ;
if ( $ { cLimit } ) {
$ { padSetup }
result [ 1 ] = getChannel ( getX ( $ { source . join ( ) } ) , $ { innerDims } ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-03 16:41:56 +01:00
rc = outputLoc ;
2021-01-13 17:14:23 +01:00
$ { coords2 [ rank - 2 ] } += 1 ;
if ( $ { coords2 [ rank - 2 ] } < $ { this . outputShape [ rank - 2 ] } ) {
$ { padSetup }
result [ 2 ] = getChannel ( getX ( $ { source . join ( ) } ) , $ { innerDims } ) ;
$ { coords2 [ rank - 1 ] } += 1 ;
if ( $ { cLimit } ) {
$ { padSetup }
result [ 3 ] = getChannel ( getX ( $ { source . join ( ) } ) , $ { innerDims } ) ;
2021-01-03 16:41:56 +01:00
}
2020-11-16 21:51:46 +01:00
}
2021-01-03 16:41:56 +01:00
` }this.userCode= `
2021-01-13 17:14:23 +01:00
const $ { dtype } start = $ { dtype } ( $ { start } ) ;
const $ { dtype } end = $ { dtype } ( $ { end } ) ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } outputLoc = getOutputCoords ( ) ;
2021-01-03 16:41:56 +01:00
vec4 result = vec4 ( 0. ) ;
2021-01-13 17:14:23 +01:00
$ { mainLoop }
2021-01-03 16:41:56 +01:00
setOutput ( result ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
` }},mirrorPadKernelFunc=({inputs,backend:backend22,attrs})=>{let{x}=inputs,{paddings,mode}=attrs,program=env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new MirrorPadPackedProgram(x.shape,paddings,mode):new MirrorPadProgram(x.shape,paddings,mode);return backend22.runWebGLProgram(program,[x],x.dtype)},mirrorPadConfig2={kernelName:MirrorPad,backendName:"webgl",kernelFunc:mirrorPadKernelFunc},MOD= ` if ( b == 0.0 ) return NAN ;
return mod ( a , b ) ; ` ,MOD_PACKED= `
2021-01-03 16:41:56 +01:00
vec4 result = mod ( a , b ) ;
vec4 isNaN = vec4 ( equal ( b , vec4 ( 0.0 ) ) ) ;
2021-01-13 17:14:23 +01:00
` +CHECK_NAN_SNIPPET3+ `
2021-01-03 16:41:56 +01:00
return result ;
2021-01-13 17:14:23 +01:00
` ,mod3=binaryKernelFunc2({opSnippet:MOD,packedOpSnippet:MOD_PACKED}),modConfig2={kernelName:Mod,backendName:"webgl",kernelFunc:mod3},MultinomialProgram=class{constructor(batchSize,numOutcomes,numSamples){this.variableNames=["probs"],this.outputShape=[batchSize,numSamples],this.userCode= `
2021-01-03 16:41:56 +01:00
uniform float seed ;
2020-12-16 20:49:14 +01:00
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
2021-01-03 16:41:56 +01:00
float r = random ( seed ) ;
float cdf = 0.0 ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
for ( int i = 0 ; i < $ { numOutcomes - 1 } ; i ++ ) {
2021-01-03 16:41:56 +01:00
cdf += getProbs ( batch , i ) ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
if ( r < cdf ) {
setOutput ( float ( i ) ) ;
return ;
}
2020-12-16 20:49:14 +01:00
}
2021-01-03 16:41:56 +01:00
// If no other event happened, last event happened.
2021-01-13 17:14:23 +01:00
setOutput ( float ( $ { numOutcomes - 1 } ) ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }getCustomSetupFunc(seed){return(gpgpu,webGLProgram)=>{this.seedLoc==null&&(this.seedLoc=gpgpu.getUniformLocation(webGLProgram,"seed")),gpgpu.gl.uniform1f(this.seedLoc,seed)}}},DIV= `
2021-01-03 16:41:56 +01:00
if ( a == b ) {
return 1.0 ;
} ;
2021-01-13 17:14:23 +01:00
return a / b ; ` ,DIV_PACKED= `
2021-01-03 16:41:56 +01:00
// vec4 one = vec4(equal(a, b));
// return one + (vec4(1.0) - one) * a / b;
vec4 result = a / b ;
if ( a . x == b . x ) {
result . x = 1. ;
}
if ( a . y == b . y ) {
result . y = 1. ;
}
if ( a . z == b . z ) {
result . z = 1. ;
}
if ( a . w == b . w ) {
result . w = 1. ;
}
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
return result ;
2021-01-13 17:14:23 +01:00
` ,realDiv=binaryKernelFunc2({opSnippet:DIV,packedOpSnippet:DIV_PACKED,checkOutOfBounds:!0}),realDivConfig2={kernelName:RealDiv,backendName:"webgl",kernelFunc:realDiv},SUB="return a - b;",sub3=binaryKernelFunc2({opSnippet:SUB,packedOpSnippet:SUB,supportsComplex:!0,cpuKernelImpl:subImplCPU}),subConfig2={kernelName:Sub,backendName:"webgl",kernelFunc:sub3};function softmax3(args){let{inputs,backend:backend22,attrs}=args,{logits}=inputs,{dim}=attrs,axes=util_exports.parseAxisParam([dim],logits.shape),maxLogit=max3({inputs:{x:logits},backend:backend22,attrs:{reductionIndices:axes,keepDims:!1}}),expandedShape=backend_util_exports.expandShapeToKeepDim(maxLogit.shape,axes),maxLogitsReshaped=reshape3({inputs:{x:maxLogit},backend:backend22,attrs:{shape:expandedShape}}),a=sub3({inputs:{a:logits,b:maxLogitsReshaped},backend:backend22}),b=exp3({inputs:{x:a},backend:backend22}),sumExp=sum4({inputs:{x:b},backend:backend22,attrs:{axis:axes,keepDims:!1}}),sumExpReshaped=reshape3({inputs:{x:sumExp},backend:backend22,attrs:{shape:expandedShape}}),res=realDiv({inputs:{a:b,b:sumExpReshaped},backend:backend22});return backend22.disposeIntermediateTensorInfo(maxLogit),backend22.disposeIntermediateTensorInfo(maxLogitsReshaped),backend22.disposeIntermediateTensorInfo(a),backend22.disposeIntermediateTensorInfo(b),backend22.disposeIntermediateTensorInfo(sumExp),backend22.disposeIntermediateTensorInfo(sumExpReshaped),res}var softmaxConfig2={kernelName:Softmax,backendName:"webgl",kernelFunc:softmax3};function multinomial3(args){let{inputs,backend:backend22,attrs}=args,{logits}=inputs,{numSamples,seed,normalized}=attrs,probs=normalized?logits:softmax3({inputs:{logits},backend:backend22,attrs:{dim:logits.shape.length-1}}),batchSize=probs.shape[0],numOutcomes=probs.shape[1],program=new MultinomialProgram(batchSize,numOutcomes,numSamples),customSetup=program.getCustomSetupFunc(seed),res=backend22.runWebGLProgram(program,[probs],"int32",customSetup);return normalized||backend22.disposeIntermediateTensorInfo(probs),res}var multinomialConfig2={kernelName:Multinomial,backendName:"webgl",kernelFunc:multinomial3},NEG="return -x;";function neg3(args){let{inputs,backend:backend22}=args,{x}=inputs;if(backend22.shouldExecuteOnCPU([x])){let xData=backend22.texData.get(x.dataId),[outValues,newShape]=negImplCPU(xData.values,x.shape,x.dtype);return backend22.makeTensorInfo(newShape,x.dtype,outValues)}let program;return env().getBool("WEBGL_PACK_UNARY_OPERATIONS")?program=new UnaryOpPackedProgram(x.shape,NEG):program=new UnaryOpProgram(x.shape,NEG),backend22.runWebGLProgram(program,[x],x.dtype)}var negConfig2={kernelName:Neg,backendName:"webgl",kernelFunc:neg3},nonMaxSuppressionV3Impl3=kernel_impls_exports.nonMaxSuppressionV3Impl;function nonMaxSuppressionV32(args){backend_util_exports.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");let{inputs,backend:backend22,attrs}=args,{boxes,scores}=inputs,{maxOutputSize,iouThreshold,scoreThreshold}=attrs,boxesVals=backend22.readSync(boxes.dataId),scoresVals=backend22.readSync(scores.dataId),{selectedIndices}=nonMaxSuppressionV3Impl3(boxesVals,scoresVals,maxOutputSize,iouThreshold,scoreThreshold);return backend22.makeTensorInfo([selectedIndices.length],"int32",new Int32Array(selectedIndices))}var nonMaxSuppressionV3Config2={kernelName:NonMaxSuppressionV3,backendName:"webgl",kernelFunc:nonMaxSuppressionV32},nonMaxSuppressionV4Impl3=kernel_impls_exports.nonMaxSuppressionV4Impl;function nonMaxSuppressionV42(args){backend_util_exports.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");let{inputs,backend:backend22,attrs}=args,{boxes,scores}=inputs,{maxOutputSize,iouThreshold,scoreThreshold,padToMaxOutputSize}=attrs,boxesVals=backend22.readSync(boxes.dataId),scoresVals=backend22.readSync(scores.dataId),{selectedIndices,validOutputs}=nonMaxSuppressionV4Impl3(boxesVals,scoresVals,maxOutputSize,iouThreshold,scoreThreshold,padToMaxOutputSize);return[backend22.makeTensorInfo([selectedIndices.length],"int32",new Int32Array(selectedIndices
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int index = round ( getIndices ( coords . x ) ) ;
2021-01-13 17:14:23 +01:00
setOutput ( mix ( float ( $ { offValue } ) , float ( $ { onValue } ) ,
2021-01-03 16:41:56 +01:00
float ( index == coords . y ) ) ) ;
}
2021-01-13 17:14:23 +01:00
` }},oneHot3=args=>{let{inputs,backend:backend22,attrs}=args,{indices}=inputs,{depth,onValue,offValue}=attrs,indicesSize=util_exports.sizeFromShape(indices.shape),program=new OneHotProgram(indicesSize,depth,onValue,offValue),reshaped=reshape3({inputs:{x:indices},backend:backend22,attrs:{shape:[indicesSize]}}),result=backend22.runWebGLProgram(program,[reshaped],indices.dtype);backend22.disposeIntermediateTensorInfo(reshaped);let outShape=[...indices.shape,depth],out=reshape3({inputs:{x:result},backend:backend22,attrs:{shape:outShape}});return backend22.disposeIntermediateTensorInfo(result),out},oneHotConfig2={kernelName:OneHot,backendName:"webgl",kernelFunc:oneHot3};function zerosLike3(args){let{inputs,backend:backend22}=args,{x}=inputs;if(x.dtype==="complex64"){let realPart=real3({inputs:{input:x},backend:backend22}),r=zerosLike3({inputs:{x:realPart},backend:backend22}),imagPart=imag3({inputs:{input:x},backend:backend22}),i=zerosLike3({inputs:{x:imagPart},backend:backend22}),result=complex3({inputs:{real:r,imag:i},backend:backend22});return backend22.disposeIntermediateTensorInfo(realPart),backend22.disposeIntermediateTensorInfo(r),backend22.disposeIntermediateTensorInfo(imagPart),backend22.disposeIntermediateTensorInfo(i),result}else return fill3({attrs:{shape:x.shape,dtype:x.dtype,value:x.dtype==="string"?"":0},backend:backend22})}var zerosLikeConfig2={kernelName:ZerosLike,backendName:"webgl",kernelFunc:zerosLike3};function onesLike3(args){let{inputs,backend:backend22}=args,{x}=inputs;if(x.dtype==="string")throw new Error("onesLike is not supported under string dtype");if(x.dtype==="complex64"){let realPart=real3({inputs:{input:x},backend:backend22}),r=onesLike3({inputs:{x:realPart},backend:backend22}),imagPart=imag3({inputs:{input:x},backend:backend22}),i=zerosLike3({inputs:{x:imagPart},backend:backend22}),result=complex3({inputs:{real:r,imag:i},backend:backend22});return backend22.disposeIntermediateTensorInfo(realPart),backend22.disposeIntermediateTensorInfo(r),backend22.disposeIntermediateTensorInfo(imagPart),backend22.disposeIntermediateTensorInfo(i),result}else return fill3({attrs:{shape:x.shape,dtype:x.dtype,value:1},backend:backend22})}var onesLikeConfig2={kernelName:OnesLike,backendName:"webgl",kernelFunc:onesLike3};function pack2(args){let{inputs,backend:backend22,attrs}=args,{axis}=attrs;if(inputs.length===1)return expandDims3({inputs:{input:inputs[0]},backend:backend22,attrs:{dim:axis}});let shape=inputs[0].shape,dtype=inputs[0].dtype;inputs.forEach(t=>{util_exports.assertShapesMatch(shape,t.shape,"All tensors passed to stack must have matching shapes"),util_exports.assert(dtype===t.dtype,()=>"All tensors passed to stack must have matching dtypes")});let intermediateTensorInfos=[],expandedTensors=inputs.map(t=>{let expandedT=expandDims3({inputs:{input:t},backend:backend22,attrs:{dim:axis}});return intermediateTensorInfos.push(expandedT),expandedT}),result=concat3({inputs:expandedTensors,backend:backend22,attrs:{axis}});return intermediateTensorInfos.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),result}var packConfig2={kernelName:Pack,backendName:"webgl",kernelFunc:pack2},PadProgram=class{constructor(xShape,paddings,constantValue){this.variableNames=["x"],this.outputShape=paddings.map((p2,i)=>p2[0]+xShape[i]+p2[1]);let rank=xShape.length,type=getCoordsDataType(rank),start=paddings.map(p2=>p2[0]).join(","),end=paddings.map((p2,i)=>p2[0]+xShape[i]).join(","),unpackedCoords=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,rank);if(rank===1){this.userCode= `
int start = $ { start } ;
int end = $ { end } ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
void main ( ) {
int outC = getOutputCoords ( ) ;
if ( outC < start || outC >= end ) {
2021-01-13 17:14:23 +01:00
setOutput ( float ( $ { constantValue } ) ) ;
2021-01-03 16:41:56 +01:00
} else {
setOutput ( getX ( outC - start ) ) ;
}
2020-12-15 14:44:42 +01:00
}
2021-01-03 16:41:56 +01:00
` ;return}this.userCode= `
2021-01-13 17:14:23 +01:00
$ { type } start = $ { type } ( $ { start } ) ;
$ { type } end = $ { type } ( $ { end } ) ;
2021-01-03 16:41:56 +01:00
2020-12-15 14:44:42 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { type } outC = getOutputCoords ( ) ;
2021-01-03 16:41:56 +01:00
if ( any ( lessThan ( outC , start ) ) || any ( greaterThanEqual ( outC , end ) ) ) {
2021-01-13 17:14:23 +01:00
setOutput ( float ( $ { constantValue } ) ) ;
2020-12-15 14:44:42 +01:00
} else {
2021-01-13 17:14:23 +01:00
$ { type } coords = outC - start ;
setOutput ( getX ( $ { unpackedCoords } ) ) ;
2020-12-15 14:44:42 +01:00
}
}
2021-01-13 17:14:23 +01:00
` }},PadPackedProgram=class{constructor(xShape,paddings,constantValue){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=paddings.map((p2,i)=>p2[0]+xShape[i]+p2[1]);let rank=xShape.length,dtype=getCoordsDataType(rank),start=paddings.map(p2=>p2[0]).join(","),end=paddings.map((p2,i)=>p2[0]+xShape[i]).join(","),coords2=getChannels("rc",rank),source=getChannels("source",rank),cLimit= ` $ { coords2 [ rank - 1 ] } < $ { this . outputShape [ rank - 1 ] } ` ,innerDims=rank===1?"source": ` vec2 ( $ { source . slice ( - 2 ) . join ( ) } ) ` ,componentSetup=[ ` $ { dtype } rc = outputLoc ; ` , ` $ { coords2 [ rank - 1 ] } += 1 ;
if ( $ { cLimit } ) {
` ,rank===1?"": ` }
2021-01-03 16:41:56 +01:00
rc = outputLoc ;
2021-01-13 17:14:23 +01:00
$ { coords2 [ rank - 2 ] } += 1 ;
if ( $ { coords2 [ rank - 2 ] } < $ { this . outputShape [ rank - 2 ] } ) { ` ,rank===1?"": ` $ { coords2 [ rank - 1 ] } += 1 ;
if ( $ { cLimit } ) { ` ],paddingArea=rank===1?"rc < start || rc >= end":"any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))",mainLoop="";for(let i=0,j=rank===1?2:4;i<j;i++)mainLoop+= `
$ { componentSetup [ i ] }
if ( $ { paddingArea } ) {
result [ $ { i } ] = float ( $ { constantValue } ) ;
2021-01-03 16:41:56 +01:00
} else {
2021-01-13 17:14:23 +01:00
$ { dtype } source = rc - start ;
result [ $ { i } ] = getChannel ( getX ( $ { source . join ( ) } ) , $ { innerDims } ) ;
2020-12-15 14:44:42 +01:00
}
2021-01-13 17:14:23 +01:00
` ;mainLoop+=rank===1?"} ":"}}",this.userCode= `
const $ { dtype } start = $ { dtype } ( $ { start } ) ;
const $ { dtype } end = $ { dtype } ( $ { end } ) ;
2021-01-03 16:41:56 +01:00
2020-12-15 14:44:42 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } outputLoc = getOutputCoords ( ) ;
2020-12-15 14:44:42 +01:00
vec4 result = vec4 ( 0. ) ;
2021-01-13 17:14:23 +01:00
$ { mainLoop }
2020-12-15 14:44:42 +01:00
setOutput ( result ) ;
}
2021-01-13 17:14:23 +01:00
` }},padV22=args=>{let{inputs,backend:backend22,attrs}=args,{x}=inputs,{paddings,constantValue}=attrs,program=env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new PadPackedProgram(x.shape,paddings,constantValue):new PadProgram(x.shape,paddings,constantValue);return backend22.runWebGLProgram(program,[x],x.dtype)},padV2Config2={kernelName:PadV2,backendName:"webgl",kernelFunc:padV22},POW= `
2021-01-03 16:41:56 +01:00
if ( a < 0.0 && floor ( b ) < b ) {
return NAN ;
}
if ( b == 0.0 ) {
return 1.0 ;
}
return ( round ( mod ( b , 2.0 ) ) != 1 ) ?
pow ( abs ( a ) , b ) : sign ( a ) * pow ( abs ( a ) , b ) ;
2021-01-13 17:14:23 +01:00
` ,POW_PACKED= `
2021-01-03 16:41:56 +01:00
// isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise.
vec4 isModRound1 = vec4 ( equal ( round ( mod ( b , 2.0 ) ) , ivec4 ( 1 ) ) ) ;
vec4 multiplier = sign ( a ) * isModRound1 + ( vec4 ( 1.0 ) - isModRound1 ) ;
vec4 result = multiplier * pow ( abs ( a ) , b ) ;
// Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS
bvec4 isExpZero = equal ( b , vec4 ( 0.0 ) ) ;
result . r = isExpZero . r ? 1.0 : result . r ;
result . g = isExpZero . g ? 1.0 : result . g ;
result . b = isExpZero . b ? 1.0 : result . b ;
result . a = isExpZero . a ? 1.0 : result . a ;
vec4 isNaN = vec4 ( lessThan ( a , vec4 ( 0.0 ) ) ) * vec4 ( lessThan ( floor ( b ) , b ) ) ;
2021-01-13 17:14:23 +01:00
` +CHECK_NAN_SNIPPET3+ `
2021-01-03 16:41:56 +01:00
return result ;
2021-01-13 17:14:23 +01:00
` ,pow3=binaryKernelFunc2({opSnippet:POW,packedOpSnippet:POW_PACKED}),powConfig2={kernelName:Pow,backendName:"webgl",kernelFunc:pow3};function prod3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{axis,keepDims}=attrs,xRank=x.shape.length,toDispose=[],origAxes=util_exports.parseAxisParam(axis,x.shape),axes=origAxes,permutedAxes=backend_util_exports.getAxesPermutation(axes,xRank),permutedX=x;permutedAxes!=null&&(permutedX=transpose3({inputs:{x},backend:backend22,attrs:{perm:permutedAxes}}),axes=backend_util_exports.getInnerMostAxes(axes.length,xRank),toDispose.push(permutedX)),backend_util_exports.assertAxesAreInnerMostDims("prod",axes,xRank);let res;if(backend22.shouldExecuteOnCPU([permutedX])){let xVals=backend22.texData.get(permutedX.dataId).values,{outVals,outShape,outDtype}=prodImplCPU(permutedX.shape,permutedX.dtype,xVals,axes);res=backend22.makeTensorInfo(outShape,outDtype,outVals)}else{let[outShape,reduceShape]=backend_util_exports.computeOutAndReduceShapes(permutedX.shape,axes),inSize=util_exports.sizeFromShape(reduceShape),a2D=reshape3({inputs:{x:permutedX},backend:backend22,attrs:{shape:[-1,inSize]}}),outputDType=sumOutType(x.dtype),reduced=reduce(a2D,outputDType,"prod",backend22);res=reshape3({inputs:{x:reduced},backend:backend22,attrs:{shape:outShape}}),toDispose.push(a2D),toDispose.push(reduced)}if(keepDims){toDispose.push(res);let newShape=backend_util_exports.expandShapeToKeepDim(res.shape,origAxes);res=reshape3({inputs:{x:res},backend:backend22,attrs:{shape:newShape}})}return toDispose.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),res}var prodConfig2={kernelName:Prod,backendName:"webgl",kernelFunc:prod3},range3=args=>{let{backend:backend22,attrs}=args,{start,stop,step:step4,dtype}=attrs,values=rangeImplCPU(start,stop,step4,dtype);return backend22.makeTensorInfo([values.length],dtype,values)},rangeConfig2={kernelName:Range,backendName:"webgl",kernelFunc:range3},RECIPROCAL="return 1.0 / x;",reciprocal3=unaryKernelFunc2({opSnippet:RECIPROCAL}),reciprocalConfig2={kernelName:Reciprocal,backendName:"webgl",kernelFunc:reciprocal3},RELU3=CHECK_NAN_SNIPPET+ `
2021-01-03 16:41:56 +01:00
return ( x < 0.0 ) ? 0.0 : x ;
2021-01-13 17:14:23 +01:00
` ,RELU_PACKED= `
2021-01-03 16:41:56 +01:00
vec4 result = x * vec4 ( greaterThanEqual ( x , vec4 ( 0.0 ) ) ) ;
bvec4 isNaN = isnan ( x ) ;
result . r = isNaN . r ? x . r : result . r ;
result . g = isNaN . g ? x . g : result . g ;
result . b = isNaN . b ? x . b : result . b ;
result . a = isNaN . a ? x . a : result . a ;
return result ;
2021-01-13 17:14:23 +01:00
` ,relu3=unaryKernelFunc2({opSnippet:RELU3,packedOpSnippet:RELU_PACKED}),reluConfig2={kernelName:Relu,backendName:"webgl",kernelFunc:relu3},RELU63=CHECK_NAN_SNIPPET+ `
2021-01-03 16:41:56 +01:00
return ( x < 0.0 ) ? 0.0 : min ( 6.0 , x ) ;
2021-01-13 17:14:23 +01:00
` ,RELU6_PACKED= `
2021-01-03 16:41:56 +01:00
vec4 result = min ( x , vec4 ( 6. ) ) * vec4 ( greaterThanEqual ( x , vec4 ( 0.0 ) ) ) ;
bvec4 isNaN = isnan ( x ) ;
result . r = isNaN . r ? x . r : result . r ;
result . g = isNaN . g ? x . g : result . g ;
result . b = isNaN . b ? x . b : result . b ;
result . a = isNaN . a ? x . a : result . a ;
return result ;
2021-01-13 17:14:23 +01:00
` ,relu63=unaryKernelFunc2({opSnippet:RELU63,packedOpSnippet:RELU6_PACKED}),relu6Config2={kernelName:Relu6,backendName:"webgl",kernelFunc:relu63},ResizeBilinearProgram=class{constructor(inputShape,newHeight,newWidth,alignCorners,halfPixelCenters){this.variableNames=["A"],this.outputShape=[];let[batch,oldHeight,oldWidth,depth]=inputShape;this.outputShape=[batch,newHeight,newWidth,depth];let effectiveInSize=[alignCorners&&newHeight>1?oldHeight-1:oldHeight,alignCorners&&newWidth>1?oldWidth-1:oldWidth],effectiveOutSize=[alignCorners&&newHeight>1?newHeight-1:newHeight,alignCorners&&newWidth>1?newWidth-1:newWidth],sourceFracIndexRC;halfPixelCenters?sourceFracIndexRC="(vec2(yRC) + vec2(0.5)) * effectiveInputOverOutputRatioRC - vec2(0.5)":sourceFracIndexRC="vec2(yRC) * effectiveInputOverOutputRatioRC",this.userCode= `
2021-01-03 16:41:56 +01:00
const vec2 effectiveInputOverOutputRatioRC = vec2 (
2021-01-13 17:14:23 +01:00
$ { effectiveInSize [ 0 ] / effectiveOutSize [ 0 ] } ,
$ { effectiveInSize [ 1 ] / effectiveOutSize [ 1 ] } ) ;
const vec2 inputShapeRC = vec2 ( $ { oldHeight } . 0 , $ { oldWidth } . 0 ) ;
2020-12-16 20:49:14 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 yRC = coords . yz ;
// Fractional source index.
2021-01-13 17:14:23 +01:00
vec2 sourceFracIndexRC = $ { sourceFracIndexRC } ;
2021-01-03 16:41:56 +01:00
// Compute the four integer indices.
ivec2 sourceFloorRC = ivec2 ( max ( sourceFracIndexRC , vec2 ( 0.0 ) ) ) ;
ivec2 sourceCeilRC = ivec2 (
min ( inputShapeRC - 1.0 , ceil ( sourceFracIndexRC ) ) ) ;
float topLeft = getA ( b , sourceFloorRC . x , sourceFloorRC . y , d ) ;
float bottomLeft = getA ( b , sourceCeilRC . x , sourceFloorRC . y , d ) ;
float topRight = getA ( b , sourceFloorRC . x , sourceCeilRC . y , d ) ;
float bottomRight = getA ( b , sourceCeilRC . x , sourceCeilRC . y , d ) ;
vec2 fracRC = sourceFracIndexRC - vec2 ( sourceFloorRC ) ;
float top = topLeft + ( topRight - topLeft ) * fracRC . y ;
float bottom = bottomLeft + ( bottomRight - bottomLeft ) * fracRC . y ;
float newValue = top + ( bottom - top ) * fracRC . x ;
setOutput ( newValue ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
` }},ResizeBilinearPackedProgram=class{constructor(inputShape,newHeight,newWidth,alignCorners,halfPixelCenters){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];let[batch,oldHeight,oldWidth,depth]=inputShape;this.outputShape=[batch,newHeight,newWidth,depth];let effectiveInSize=[alignCorners&&newHeight>1?oldHeight-1:oldHeight,alignCorners&&newWidth>1?oldWidth-1:oldWidth],effectiveOutSize=[alignCorners&&newHeight>1?newHeight-1:newHeight,alignCorners&&newWidth>1?newWidth-1:newWidth],sourceFracIndexRC;halfPixelCenters?sourceFracIndexRC="(vec3(yRC) + vec3(0.5)) * effectiveInputOverOutputRatioRC - vec3(0.5)":sourceFracIndexRC="vec3(yRC) * effectiveInputOverOutputRatioRC",this.userCode= `
2021-01-03 16:41:56 +01:00
const vec3 effectiveInputOverOutputRatioRC = vec3 (
2021-01-13 17:14:23 +01:00
$ { effectiveInSize [ 0 ] / effectiveOutSize [ 0 ] } ,
$ { effectiveInSize [ 1 ] / effectiveOutSize [ 1 ] } ,
$ { effectiveInSize [ 1 ] / effectiveOutSize [ 1 ] } ) ;
const vec3 inputShapeRC = vec3 ( $ { oldHeight } . 0 , $ { oldWidth } . 0 ,
$ { oldWidth } . 0 ) ;
2021-01-03 16:41:56 +01:00
float getAValue ( int b , int r , int c , int d ) {
return getChannel ( getA ( b , r , c , d ) , vec2 ( c , d ) ) ;
2020-12-16 20:49:14 +01:00
}
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
// Calculate values for next column in yRC.z.
ivec3 yRC = coords . yzz + ivec3 ( 0 , 0 , 1 ) ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
// Fractional source index.
2021-01-13 17:14:23 +01:00
vec3 sourceFracIndexRC = $ { sourceFracIndexRC } ;
2021-01-03 16:41:56 +01:00
// Compute the four integer indices.
ivec3 sourceFloorRC = ivec3 ( max ( sourceFracIndexRC , vec3 ( 0.0 ) ) ) ;
ivec3 sourceCeilRC = ivec3 (
min ( inputShapeRC - 1.0 , ceil ( sourceFracIndexRC ) ) ) ;
// Should we calculate next column and row elements in 2x2 packed cell.
2021-01-13 17:14:23 +01:00
bool hasNextCol = d < $ { depth - 1 } ;
bool hasNextRow = coords . z < $ { newWidth - 1 } ;
2021-01-03 16:41:56 +01:00
// In parallel, construct four corners for all four components in
// packed 2x2 cell.
vec4 topLeft = vec4 (
getAValue ( b , sourceFloorRC . x , sourceFloorRC . y , d ) ,
hasNextCol ? getAValue ( b , sourceFloorRC . x , sourceFloorRC . y , d + 1 )
: 0.0 ,
hasNextRow ? getAValue ( b , sourceFloorRC . x , sourceFloorRC . z , d )
: 0.0 ,
( hasNextRow && hasNextCol ) ?
getAValue ( b , sourceFloorRC . x , sourceFloorRC . z , d + 1 ) : 0.0 ) ;
vec4 bottomLeft = vec4 (
getAValue ( b , sourceCeilRC . x , sourceFloorRC . y , d ) ,
hasNextCol ? getAValue ( b , sourceCeilRC . x , sourceFloorRC . y , d + 1 )
: 0.0 ,
hasNextRow ? getAValue ( b , sourceCeilRC . x , sourceFloorRC . z , d )
: 0.0 ,
( hasNextRow && hasNextCol ) ?
getAValue ( b , sourceCeilRC . x , sourceFloorRC . z , d + 1 ) : 0.0 ) ;
vec4 topRight = vec4 (
getAValue ( b , sourceFloorRC . x , sourceCeilRC . y , d ) ,
hasNextCol ? getAValue ( b , sourceFloorRC . x , sourceCeilRC . y , d + 1 )
: 0.0 ,
hasNextRow ? getAValue ( b , sourceFloorRC . x , sourceCeilRC . z , d )
: 0.0 ,
( hasNextRow && hasNextCol ) ?
getAValue ( b , sourceFloorRC . x , sourceCeilRC . z , d + 1 ) : 0.0 ) ;
vec4 bottomRight = vec4 (
getAValue ( b , sourceCeilRC . x , sourceCeilRC . y , d ) ,
hasNextCol ? getAValue ( b , sourceCeilRC . x , sourceCeilRC . y , d + 1 )
: 0.0 ,
hasNextRow ? getAValue ( b , sourceCeilRC . x , sourceCeilRC . z , d )
: 0.0 ,
( hasNextRow && hasNextCol ) ?
getAValue ( b , sourceCeilRC . x , sourceCeilRC . z , d + 1 ) : 0.0 ) ;
vec3 fracRC = sourceFracIndexRC - vec3 ( sourceFloorRC ) ;
vec4 top = mix ( topLeft , topRight , fracRC . yyzz ) ;
vec4 bottom = mix ( bottomLeft , bottomRight , fracRC . yyzz ) ;
vec4 newValue = mix ( top , bottom , fracRC . x ) ;
setOutput ( newValue ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function resizeBilinear3(args){let{inputs,backend:backend22,attrs}=args,{images}=inputs,{alignCorners,halfPixelCenters,size}=attrs,[newHeight,newWidth]=size,program=env().getBool("WEBGL_PACK_IMAGE_OPERATIONS")?new ResizeBilinearPackedProgram(images.shape,newHeight,newWidth,alignCorners,halfPixelCenters):new ResizeBilinearProgram(images.shape,newHeight,newWidth,alignCorners,halfPixelCenters);return backend22.runWebGLProgram(program,[images],"float32")}var resizeBilinearConfig2={kernelName:ResizeBilinear,backendName:"webgl",kernelFunc:resizeBilinear3},ResizeBilinearBackpropProgram=class{constructor(dyShape,inputShape,alignCorners){this.variableNames=["dy"],this.outputShape=[],this.outputShape=inputShape;let[,xHeight,xWidth]=inputShape,[,yHeight,yWidth]=dyShape,effectiveXSize=[alignCorners&&yHeight>1?xHeight-1:xHeight,alignCorners&&yWidth>1?xWidth-1:xWidth],effectiveYSize=[alignCorners&&yHeight>1?yHeight-1:yHeight,alignCorners&&yWidth>1?yWidth-1:yWidth],heightScale=effectiveXSize[0]/effectiveYSize[0],widthScale=effectiveXSize[1]/effectiveYSize[1],invHeightScale=1/heightScale,invWidthScale=1/widthScale,winHeight=Math.ceil(invHeightScale)*2+2,winWidth=Math.ceil(invWidthScale)*2+2;this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
float accumulator = 0.0 ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
const float heightScale = float ( $ { heightScale } ) ;
const float widthScale = float ( $ { widthScale } ) ;
2020-12-16 20:49:14 +01:00
2021-01-13 17:14:23 +01:00
const float invHeightScale = float ( $ { invHeightScale } ) ;
const float invWidthScale = float ( $ { invWidthScale } ) ;
2021-01-03 16:41:56 +01:00
2021-01-13 17:14:23 +01:00
const int winHeight = int ( $ { winHeight } ) ;
const int winWidth = int ( $ { winWidth } ) ;
2021-01-03 16:41:56 +01:00
// Compute bounds for where in dy we will look
float startRLerp = floor ( float ( r ) * invHeightScale ) ;
int startDyR = int ( startRLerp - float ( winHeight / 2 ) ) ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
float startCLerp = floor ( float ( c ) * invWidthScale ) ;
int startDyC = int ( startCLerp - float ( winWidth / 2 ) ) ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
// Loop over dy
for ( int dyROffset = 0 ; dyROffset < winHeight ; dyROffset ++ ) {
int dyR = dyROffset + startDyR ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
// Guard against the window exceeding the bounds of dy
2021-01-13 17:14:23 +01:00
if ( dyR < 0 || dyR >= $ { yHeight } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
for ( int dyCOffset = 0 ; dyCOffset < winWidth ; dyCOffset ++ ) {
int dyC = dyCOffset + startDyC ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
// Guard against the window exceeding the bounds of dy
2021-01-13 17:14:23 +01:00
if ( dyC < 0 || dyC >= $ { yWidth } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
float dxR = float ( dyR ) * heightScale ;
int topDxRIndex = int ( floor ( dxR ) ) ;
2021-01-13 17:14:23 +01:00
int bottomDxRIndex = int ( min ( ceil ( dxR ) , $ { xHeight - 1 } . 0 ) ) ;
2021-01-03 16:41:56 +01:00
float dxRLerp = dxR - float ( topDxRIndex ) ;
float inverseDxRLerp = 1.0 - dxRLerp ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
float dxC = float ( dyC ) * widthScale ;
int leftDxCIndex = int ( floor ( dxC ) ) ;
2021-01-13 17:14:23 +01:00
int rightDxCIndex = int ( min ( ceil ( dxC ) , $ { xWidth - 1 } . 0 ) ) ;
2021-01-03 16:41:56 +01:00
float dxCLerp = dxC - float ( leftDxCIndex ) ;
float inverseDxCLerp = 1.0 - dxCLerp ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
if ( r == topDxRIndex && c == leftDxCIndex ) {
// topLeft
accumulator +=
getDy ( b , dyR , dyC , d ) * inverseDxRLerp * inverseDxCLerp ;
}
2020-11-16 21:51:46 +01:00
2021-01-03 16:41:56 +01:00
if ( r == topDxRIndex && c == rightDxCIndex ) {
// topRight
accumulator += getDy ( b , dyR , dyC , d ) * inverseDxRLerp * dxCLerp ;
}
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
if ( r == bottomDxRIndex && c == leftDxCIndex ) {
// bottomLeft
accumulator += getDy ( b , dyR , dyC , d ) * dxRLerp * inverseDxCLerp ;
}
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
if ( r == bottomDxRIndex && c == rightDxCIndex ) {
// bottomRight
accumulator += getDy ( b , dyR , dyC , d ) * dxRLerp * dxCLerp ;
}
}
}
// End loop over dy
setOutput ( accumulator ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function resizeBilinearGrad2(args){let{inputs,backend:backend22,attrs}=args,{images,dy}=inputs,{alignCorners}=attrs,program=new ResizeBilinearBackpropProgram(dy.shape,images.shape,alignCorners);return backend22.runWebGLProgram(program,[dy],dy.dtype)}var resizeBilinearGradConfig3={kernelName:ResizeBilinearGrad,backendName:"webgl",kernelFunc:resizeBilinearGrad2},ResizeNearestNeighborProgram=class{constructor(inputShape,newHeight,newWidth,alignCorners,halfPixelCenters){this.variableNames=["A"],this.outputShape=[];let[batch,oldHeight,oldWidth,depth]=inputShape;this.outputShape=[batch,newHeight,newWidth,depth];let effectiveInSize=[alignCorners&&newHeight>1?oldHeight-1:oldHeight,alignCorners&&newWidth>1?oldWidth-1:oldWidth],effectiveOutSize=[alignCorners&&newHeight>1?newHeight-1:newHeight,alignCorners&&newWidth>1?newWidth-1:newWidth],roundBase=alignCorners?"0.5":"0.0",sourceFracIndexRC;halfPixelCenters?sourceFracIndexRC="max((vec2(yRC) + vec2(0.5)) * effectiveInputOverOutputRatioRC, vec2(0.0))":sourceFracIndexRC="vec2(yRC) * effectiveInputOverOutputRatioRC",this.userCode= `
2021-01-03 16:41:56 +01:00
const vec2 effectiveInputOverOutputRatioRC = vec2 (
2021-01-13 17:14:23 +01:00
$ { effectiveInSize [ 0 ] / effectiveOutSize [ 0 ] } ,
$ { effectiveInSize [ 1 ] / effectiveOutSize [ 1 ] } ) ;
const vec2 inputShapeRC = vec2 ( $ { oldHeight } . 0 , $ { oldWidth } . 0 ) ;
2021-01-03 16:41:56 +01:00
2020-11-16 21:51:46 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 yRC = coords . yz ;
// Fractional source index.
2021-01-13 17:14:23 +01:00
vec2 sourceFracIndexRC = $ { sourceFracIndexRC } ;
2021-01-03 16:41:56 +01:00
// Compute the coordinators of nearest neighbor point.
ivec2 sourceNearestRC = ivec2 (
2021-01-13 17:14:23 +01:00
min ( inputShapeRC - 1.0 , floor ( sourceFracIndexRC + $ { roundBase } ) ) ) ;
2021-01-03 16:41:56 +01:00
float newValue = getA ( b , sourceNearestRC . x , sourceNearestRC . y , d ) ;
setOutput ( newValue ) ;
2020-11-16 21:51:46 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function resizeNearestNeighbor3(args){let{inputs,backend:backend22,attrs}=args,{images}=inputs,{alignCorners,halfPixelCenters,size}=attrs,[newHeight,newWidth]=size,program=new ResizeNearestNeighborProgram(images.shape,newHeight,newWidth,alignCorners,halfPixelCenters);return backend22.runWebGLProgram(program,[images],images.dtype)}var resizeNearestNeighborConfig2={kernelName:ResizeNearestNeighbor,backendName:"webgl",kernelFunc:resizeNearestNeighbor3},ResizeNearestNeigborBackpropProgram=class{constructor(dyShape,inputShape,alignCorners){this.variableNames=["dy"],this.outputShape=[],this.outputShape=inputShape;let[,xHeight,xWidth]=inputShape,[,yHeight,yWidth]=dyShape,effectiveXSize=[alignCorners&&yHeight>1?xHeight-1:xHeight,alignCorners&&yWidth>1?xWidth-1:xWidth],effectiveYSize=[alignCorners&&yHeight>1?yHeight-1:yHeight,alignCorners&&yWidth>1?yWidth-1:yWidth],heightScale=effectiveXSize[0]/effectiveYSize[0],widthScale=effectiveXSize[1]/effectiveYSize[1],invHeightScale=1/heightScale,invWidthScale=1/widthScale,winHeight=Math.ceil(invHeightScale)*2+2,winWidth=Math.ceil(invWidthScale)*2+2;this.userCode= `
2020-11-16 21:51:46 +01:00
void main ( ) {
2021-01-03 16:41:56 +01:00
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
float accumulator = 0.0 ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
const float heightScale = float ( $ { heightScale } ) ;
const float widthScale = float ( $ { widthScale } ) ;
2020-11-16 21:51:46 +01:00
2021-01-13 17:14:23 +01:00
const float invHeightScale = float ( $ { invHeightScale } ) ;
const float invWidthScale = float ( $ { invWidthScale } ) ;
2020-11-10 02:13:38 +01:00
2021-01-13 17:14:23 +01:00
const int winHeight = int ( $ { winHeight } ) ;
const int winWidth = int ( $ { winWidth } ) ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
// Compute bounds for where in dy we will look
float startRLerp = floor ( float ( r ) * invHeightScale ) ;
int startDyR = int ( floor ( startRLerp - float ( winHeight / 2 ) ) ) ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
float startCLerp = floor ( float ( c ) * invWidthScale ) ;
int startDyC = int ( floor ( startCLerp - float ( winWidth / 2 ) ) ) ;
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
// Loop over dy
for ( int dyROffset = 0 ; dyROffset < winHeight ; dyROffset ++ ) {
int dyR = dyROffset + startDyR ;
2020-11-10 02:13:38 +01:00
2021-01-03 16:41:56 +01:00
// Guard against the window exceeding the bounds of dy
2021-01-13 17:14:23 +01:00
if ( dyR < 0 || dyR >= $ { yHeight } ) {
2021-01-03 16:41:56 +01:00
continue ;
}
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
for ( int dyCOffset = 0 ; dyCOffset < winWidth ; dyCOffset ++ ) {
int dyC = dyCOffset + startDyC ;
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
// Guard against the window exceeding the bounds of dy
2021-01-13 17:14:23 +01:00
if ( dyC < 0 || dyC >= $ { yWidth } ) {
2021-01-03 16:41:56 +01:00
continue ;
2020-12-16 20:49:14 +01:00
}
2020-12-15 14:44:42 +01:00
2021-01-03 16:41:56 +01:00
float sourceFracRow =
2021-01-13 17:14:23 +01:00
float ( $ { effectiveXSize [ 0 ] } ) *
( float ( dyR ) / float ( $ { effectiveYSize [ 0 ] } ) ) ;
2021-01-03 16:41:56 +01:00
float sourceFracCol =
2021-01-13 17:14:23 +01:00
float ( $ { effectiveXSize [ 1 ] } ) *
( float ( dyC ) / float ( $ { effectiveYSize [ 1 ] } ) ) ;
2021-01-03 16:41:56 +01:00
int sourceNearestRow = int ( min (
2021-01-13 17:14:23 +01:00
float ( int ( $ { xHeight } ) - 1 ) ,
$ { alignCorners } ? float ( round ( sourceFracRow ) ) :
2021-01-03 16:41:56 +01:00
float ( floor ( sourceFracRow ) ) ) ) ;
int sourceNearestCol = int ( min (
2021-01-13 17:14:23 +01:00
float ( int ( $ { xWidth } ) - 1 ) ,
$ { alignCorners } ? float ( round ( sourceFracCol ) ) :
2021-01-03 16:41:56 +01:00
float ( floor ( sourceFracCol ) ) ) ) ;
if ( r == sourceNearestRow && c == sourceNearestCol ) {
accumulator += getDy ( b , dyR , dyC , d ) ;
}
2020-12-16 20:49:14 +01:00
}
2020-12-15 14:44:42 +01:00
}
2021-01-03 16:41:56 +01:00
// End loop over dy
2020-12-16 20:49:14 +01:00
2021-01-03 16:41:56 +01:00
setOutput ( accumulator ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function resizeNearestNeighborGrad2(args){let{inputs,backend:backend22,attrs}=args,{images,dy}=inputs,{alignCorners}=attrs,program=new ResizeNearestNeigborBackpropProgram(dy.shape,images.shape,alignCorners);return backend22.runWebGLProgram(program,[dy],dy.dtype)}var resizeNearestNeighborGradConfig3={kernelName:ResizeNearestNeighborGrad,backendName:"webgl",kernelFunc:resizeNearestNeighborGrad2},ReverseProgram=class{constructor(xShape,axis){this.variableNames=["x"];let rank=xShape.length;if(rank>4)throw new Error( ` WebGL backend : Reverse of rank - $ { rank } tensor is not yet supported ` );if(this.outputShape=xShape,rank===1){this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
int coord = getOutputCoords ( ) ;
2021-01-13 17:14:23 +01:00
setOutput ( getX ( $ { xShape [ 0 ] } - coord - 1 ) ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
` ;return}let getInCoord=i=>axis.indexOf(i)!==-1&&xShape[i]!==1? ` $ { xShape [ i ] } - coords [ $ { i } ] - 1 ` : ` coords [ $ { i } ] ` ,inCoords=xShape.map((_,i)=>getInCoord(i)).join(","),type=getCoordsDataType(rank);this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { type } coords = getOutputCoords ( ) ;
setOutput ( getX ( $ { inCoords } ) ) ;
2020-12-16 20:49:14 +01:00
}
2021-01-13 17:14:23 +01:00
` }},ReversePackedProgram=class{constructor(xShape,axis){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;let rank=xShape.length;if(rank>4)throw new Error( ` WebGL backend : Reverse of rank - $ { rank } tensor is not yet supported ` );this.outputShape=xShape;let channels=getChannels("rc",rank),nextColumn= ` $ { channels [ rank - 1 ] } + 1 < $ { this . outputShape [ rank - 1 ] } ` ,nextRow= ` $ { channels [ rank - 2 ] } + 1 < $ { this . outputShape [ rank - 2 ] } ` ,type=getCoordsDataType(rank);rank===1?this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
int rc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
2021-01-13 17:14:23 +01:00
result . r = getChannel ( getX ( $ { xShape [ 0 ] } - rc - 1 ) ,
$ { xShape [ 0 ] } - rc - 1 ) ;
if ( $ { nextColumn } ) {
result . g = getChannel ( getX ( $ { xShape [ 0 ] } - ( rc + 1 ) - 1 ) ,
$ { xShape [ 0 ] } - ( rc + 1 ) - 1 ) ;
2021-01-03 16:41:56 +01:00
}
setOutput ( result ) ;
}
` :this.userCode= `
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { type } rc = getOutputCoords ( ) ;
2021-01-03 16:41:56 +01:00
vec4 result = vec4 ( 0. ) ;
2021-01-13 17:14:23 +01:00
result . r = $ { getR ( channels . slice ( ) ) } ;
if ( $ { nextColumn } ) {
result . g = $ { getG ( channels . slice ( ) ) } ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
if ( $ { nextRow } ) {
result . b = $ { getB ( channels . slice ( ) ) } ;
if ( $ { nextColumn } ) {
result . a = $ { getA ( channels . slice ( ) ) } ;
2021-01-03 16:41:56 +01:00
}
}
setOutput ( result ) ;
}
2021-01-13 17:14:23 +01:00
` ;function getR(channels2){return getChannel(channels2)}function getG(channels2){return channels2[rank-1]="("+channels2[rank-1]+" + 1)",getChannel(channels2)}function getB(channels2){return channels2[rank-2]="("+channels2[rank-2]+" + 1)",getChannel(channels2)}function getA(channels2){return channels2[rank-1]="("+channels2[rank-1]+" + 1)",channels2[rank-2]="("+channels2[rank-2]+" + 1)",getChannel(channels2)}function getChannel(channels2){let inCoordsArray=xShape.map((_,i)=>getInCoord(i,channels2)),inCoords=inCoordsArray.join(","),innerDims=inCoordsArray.slice(-2).join(",");return ` getChannel ( getX ( $ { inCoords } ) , vec2 ( $ { innerDims } ) ) ` }function getInCoord(i,channels1){return axis.indexOf(i)!==-1&&xShape[i]!==1? ` $ { xShape [ i ] } - $ { channels1 [ i ] } - 1 ` : ` $ { channels1 [ i ] } ` }}};function reverse3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{dims}=attrs,xRank=x.shape.length, $ dims=util_exports.parseAxisParam(dims,x.shape);if(xRank===0)return identity2({inputs:{x},backend:backend22});let program=env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new ReversePackedProgram(x.shape, $ dims):new ReverseProgram(x.shape, $ dims);return backend22.runWebGLProgram(program,[x],x.dtype)}var reverseConfig2={kernelName:Reverse,backendName:"webgl",kernelFunc:reverse3},RotateProgram=class{constructor(imageShape,radians,fillValue,center){this.variableNames=["Image"],this.outputShape=[];let imageHeight=imageShape[1],imageWidth=imageShape[2],sinFactor=Math.sin(radians).toFixed(3),cosFactor=Math.cos(radians).toFixed(3);this.outputShape=imageShape;let[centerX,centerY]=backend_util_exports.getImageCenter(center,imageHeight,imageWidth),centerXString=centerX.toFixed(3),centerYString=centerY.toFixed(3),fillSnippet="";typeof fillValue=="number"?fillSnippet= ` float outputValue = $ { fillValue . toFixed ( 2 ) } ; ` :fillSnippet= `
vec3 fill = vec3 ( $ { fillValue . join ( "," ) } ) ;
2020-12-16 20:49:14 +01:00
float outputValue = fill [ coords [ 3 ] ] ; ` ,this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int x = coords [ 2 ] ;
int y = coords [ 1 ] ;
2021-01-13 17:14:23 +01:00
float coordXFloat = ( float ( x ) - $ { centerXString } ) * $ { cosFactor } - ( float ( y ) - $ { centerYString } ) * $ { sinFactor } ;
float coordYFloat = ( float ( x ) - $ { centerXString } ) * $ { sinFactor } + ( float ( y ) - $ { centerYString } ) * $ { cosFactor } ;
int coordX = int ( round ( coordXFloat + $ { centerXString } ) ) ;
int coordY = int ( round ( coordYFloat + $ { centerYString } ) ) ;
$ { fillSnippet }
if ( coordX >= 0 && coordX < $ { imageWidth } && coordY >= 0 && coordY < $ { imageHeight } ) {
2020-12-16 20:49:14 +01:00
outputValue = getImage ( coords [ 0 ] , coordY , coordX , coords [ 3 ] ) ;
}
setOutput ( outputValue ) ;
}
2021-01-13 17:14:23 +01:00
` }},rotateWithOffsetConfig2={kernelName:RotateWithOffset,backendName:"webgl",kernelFunc:({inputs,attrs,backend:backend22})=>{let{image:image3}=inputs,{radians,fillValue,center}=attrs,webglBackend=backend22,program=new RotateProgram(image3.shape,radians,fillValue,center);return webglBackend.runWebGLProgram(program,[image3],image3.dtype)}},ROUND= `
2021-01-03 16:41:56 +01:00
// OpenGL ES does not support round function.
// The algorithm is based on banker's rounding.
float base = floor ( x ) ;
if ( ( x - base ) < 0.5 ) {
return floor ( x ) ;
} else if ( ( x - base ) > 0.5 ) {
return ceil ( x ) ;
} else {
if ( mod ( base , 2.0 ) == 0.0 ) {
return base ;
} else {
return base + 1.0 ;
}
}
2021-01-13 17:14:23 +01:00
` ,round4=unaryKernelFunc2({opSnippet:ROUND}),roundConfig2={kernelName:Round,backendName:"webgl",kernelFunc:round4},RSQRT="return inversesqrt(x);",rsqrt3=unaryKernelFunc2({opSnippet:RSQRT,cpuKernelImpl:rsqrtImplCPU}),rsqrtConfig2={kernelName:Rsqrt,backendName:"webgl",kernelFunc:rsqrt3},ScatterProgram=class{constructor(updateSize,sliceDim,indicesRank,updatesRank,strides,shape,summingDupeIndex=!0){this.variableNames=["updates","indices","defaultValue"],this.outputShape=shape;let stridesType=getCoordsDataType(strides.length),dtype=getCoordsDataType(shape.length),indicesString="";indicesRank===1?indicesString="i":indicesRank===2&&(indicesString="i, j");let indicesSnippet= ` getIndices ( $ { indicesString } ) ` ,updatesString="";updatesRank===1?updatesString="i":updatesRank===2&&(updatesString="i, coords[1]");let updatesSnippet= ` getUpdates ( $ { updatesString } ) ` ,strideString=sliceDim>1?"strides[j]":"strides";this.userCode= `
$ { stridesType } strides = $ { stridesType } ( $ { strides } ) ;
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } coords = getOutputCoords ( ) ;
2021-01-03 16:41:56 +01:00
float sum = 0.0 ;
bool found = false ;
2021-01-13 17:14:23 +01:00
for ( int i = 0 ; i < $ { updateSize } ; i ++ ) {
2021-01-03 16:41:56 +01:00
int flattenedIndex = 0 ;
2021-01-13 17:14:23 +01:00
for ( int j = 0 ; j < $ { sliceDim } ; j ++ ) {
int index = round ( $ { indicesSnippet } ) ;
flattenedIndex += index * $ { strideString } ;
2021-01-03 16:41:56 +01:00
}
if ( flattenedIndex == coords [ 0 ] ) {
2021-01-13 17:14:23 +01:00
sum += $ { updatesSnippet } ;
2021-01-03 16:41:56 +01:00
found = true ;
}
}
setOutput ( mix ( getDefaultValue ( ) , sum , float ( found ) ) ) ;
}
2021-01-13 17:14:23 +01:00
` }};function scatterNd2(args){let{inputs,backend:backend22,attrs}=args,{indices,updates}=inputs,{shape}=attrs,{sliceRank,numUpdates,sliceSize,strides,outputSize}=backend_util_exports.calculateShapes(updates,indices,shape),flattenShape=[outputSize/sliceSize,sliceSize];if(outputSize===0)return backend22.makeTensorInfo(shape,indices.dtype);let flattenIndices=reshape3({inputs:{x:indices},backend:backend22,attrs:{shape:[numUpdates,sliceRank]}}),flattenX=reshape3({inputs:{x:updates},backend:backend22,attrs:{shape:[numUpdates,sliceSize]}}),defaultValue=backend22.makeTensorInfo([],"float32",new Float32Array([0])),program=new ScatterProgram(numUpdates,sliceRank,flattenIndices.shape.length,flattenX.shape.length,strides,flattenShape),res=backend22.runWebGLProgram(program,[flattenX,flattenIndices,defaultValue],flattenX.dtype),reshaped=reshape3({inputs:{x:res},backend:backend22,attrs:{shape}});return backend22.disposeIntermediateTensorInfo(flattenIndices),backend22.disposeIntermediateTensorInfo(flattenX),backend22.disposeIntermediateTensorInfo(res),backend22.disposeIntermediateTensorInfo(defaultValue),reshaped}var scatterNdConfig2={kernelName:ScatterNd,backendName:"webgl",kernelFunc:scatterNd2},SelectProgram=class{constructor(cRank,shape,rank){this.variableNames=["c","a","b"],this.outputShape=shape;let cCoords,abCoords;if(rank>4)throw Error( ` Where for rank $ { rank } is not yet supported ` );if(rank===1)abCoords="resRC",cCoords="resRC";else{let currentCoords=["resRC.x","resRC.y","resRC.z","resRC.w"],cCoordVars=[],abCoordVars=[];for(let i=0;i<shape.length;i++)abCoordVars.push( ` $ { currentCoords [ i ] } ` ),i<cRank&&cCoordVars.push( ` $ { currentCoords [ i ] } ` );cCoords=cCoordVars.join(),abCoords=abCoordVars.join()}let dtype=getCoordsDataType(rank);this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } resRC = getOutputCoords ( ) ;
float cVal = getC ( $ { cCoords } ) ;
2021-01-03 16:41:56 +01:00
if ( cVal >= 1.0 ) {
2021-01-13 17:14:23 +01:00
setOutput ( getA ( $ { abCoords } ) ) ;
2021-01-03 16:41:56 +01:00
} else {
2021-01-13 17:14:23 +01:00
setOutput ( getB ( $ { abCoords } ) ) ;
2021-01-03 16:41:56 +01:00
}
}
2021-01-13 17:14:23 +01:00
` }};function select2(args){let{inputs,backend:backend22}=args,{condition,t,e}=inputs,program=new SelectProgram(condition.shape.length,t.shape,t.shape.length);return backend22.runWebGLProgram(program,[condition,t,e],upcastType(t.dtype,e.dtype))}var selectConfig2={kernelName:Select,backendName:"webgl",kernelFunc:select2},SELU= `
2021-01-03 16:41:56 +01:00
// Stable and Attracting Fixed Point (0, 1) for Normalized Weights.
// see: https://arxiv.org/abs/1706.02515
2021-01-13 17:14:23 +01:00
float scaleAlpha = $ { backend _util _exports . SELU _SCALEALPHA } ;
float scale = $ { backend _util _exports . SELU _SCALE } ;
2021-01-03 16:41:56 +01:00
return ( x >= 0.0 ) ? scale * x : scaleAlpha * ( exp ( x ) - 1.0 ) ;
2021-01-13 17:14:23 +01:00
` ,selu3=unaryKernelFunc2({opSnippet:SELU}),seluConfig2={kernelName:Selu,backendName:"webgl",kernelFunc:selu3},SIGMOID="return 1.0 / (1.0 + exp(-1.0 * x));",sigmoid3=unaryKernelFunc2({opSnippet:SIGMOID}),sigmoidConfig2={kernelName:Sigmoid,backendName:"webgl",kernelFunc:sigmoid3},SIGN= `
2021-01-03 16:41:56 +01:00
if ( isnan ( x ) ) { return 0.0 ; }
return sign ( x ) ;
2021-01-13 17:14:23 +01:00
` ,sign3=unaryKernelFunc2({opSnippet:SIGN}),signConfig2={kernelName:Sign,backendName:"webgl",kernelFunc:sign3},SIN=CHECK_NAN_SNIPPET_UNARY+ `
2020-12-16 20:49:14 +01:00
return sin ( x ) ;
2021-01-13 17:14:23 +01:00
` ,sin3=unaryKernelFunc2({opSnippet:SIN}),sinConfig2={kernelName:Sin,backendName:"webgl",kernelFunc:sin3},SINH= `
2021-01-03 16:41:56 +01:00
float e2x = exp ( x ) ;
return ( e2x - 1.0 / e2x ) / 2.0 ;
2021-01-13 17:14:23 +01:00
` ,sinh3=unaryKernelFunc2({opSnippet:SINH}),sinhConfig2={kernelName:Sinh,backendName:"webgl",kernelFunc:sinh3},SOFTPLUS= `
2021-01-03 16:41:56 +01:00
float epsilon = 1.1920928955078125 e - 7 ;
float threshold = log ( epsilon ) + 2.0 ;
bool too _large = x > - threshold ;
bool too _small = x < threshold ;
float result ;
float exp _x = exp ( x ) ;
if ( too _large ) {
result = x ;
}
else if ( too _small ) {
result = exp _x ;
}
else {
result = log ( exp _x + 1.0 ) ;
}
return result ;
2021-01-13 17:14:23 +01:00
` ,softplus3=unaryKernelFunc2({opSnippet:SOFTPLUS}),softplusConfig2={kernelName:Softplus,backendName:"webgl",kernelFunc:softplus3},spaceToBatchND3=args=>{let{inputs,backend:backend22,attrs}=args,{x}=inputs,{blockShape,paddings}=attrs;util_exports.assert(x.shape.length<=4,()=>"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet");let prod5=blockShape.reduce((a,b)=>a*b),completePaddings=[[0,0]];completePaddings.push(...paddings);for(let i=1+blockShape.length;i<x.shape.length;++i)completePaddings.push([0,0]);let toDispose=[],paddedX=padV22({inputs:{x},backend:backend22,attrs:{paddings:completePaddings,constantValue:0}}),reshapedPaddedShape=backend_util_exports.getReshaped(paddedX.shape,blockShape,prod5,!1),permutedReshapedPaddedPermutation=backend_util_exports.getPermuted(reshapedPaddedShape.length,blockShape.length,!1),flattenShape=backend_util_exports.getReshapedPermuted(paddedX.shape,blockShape,prod5,!1),reshapedPaddedX=reshape3({inputs:{x:paddedX},backend:backend22,attrs:{shape:reshapedPaddedShape}}),paddedXT=transpose3({inputs:{x:reshapedPaddedX},backend:backend22,attrs:{perm:permutedReshapedPaddedPermutation}}),result=reshape3({inputs:{x:paddedXT},backend:backend22,attrs:{shape:flattenShape}});return toDispose.push(paddedX),toDispose.push(reshapedPaddedX),toDispose.push(paddedXT),toDispose.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),result},spaceToBatchNDConfig2={kernelName:SpaceToBatchND,backendName:"webgl",kernelFunc:spaceToBatchND3};function sparseToDense3(args){let{inputs,backend:backend22,attrs}=args,{sparseIndices,sparseValues,defaultValue}=inputs,{outputShape}=attrs,{sliceRank,numUpdates,strides,outputSize}=backend_util_exports.calculateShapes(sparseValues,sparseIndices,outputShape),sumDupeIndices=!1,program=new ScatterProgram(numUpdates,sliceRank,sparseIndices.shape.length,sparseValues.shape.length,strides,[outputSize,1],sumDupeIndices),res=backend22.runWebGLProgram(program,[sparseValues,sparseIndices,defaultValue],sparseValues.dtype),reshaped=reshape3({inputs:{x:res},backend:backend22,attrs:{shape:outputShape}});return backend22.disposeIntermediateTensorInfo(res),reshaped}var sparseToDenseConfig2={kernelName:SparseToDense,backendName:"webgl",kernelFunc:sparseToDense3};function splitV2(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{numOrSizeSplits,axis}=attrs, $ axis=util_exports.parseAxisParam(axis,x.shape)[0],splitSizes=backend_util_exports.prepareSplitSize(x,numOrSizeSplits, $ axis),xRank=x.shape.length,begin=new Array(xRank).fill(0),size=x.shape.slice();return splitSizes.map(s=>{let sliceSize=[...size];sliceSize[ $ axis]=s;let sliceT=slice3({inputs:{x},backend:backend22,attrs:{begin,size:sliceSize}});return begin[ $ axis]+=s,sliceT})}var splitVConfig2={kernelName:SplitV,backendName:"webgl",kernelFunc:splitV2},SQRT="return sqrt(x);",sqrt3=unaryKernelFunc2({opSnippet:SQRT}),sqrtConfig2={kernelName:Sqrt,backendName:"webgl",kernelFunc:sqrt3},SQUARE="return x * x;",square2=unaryKernelFunc2({opSnippet:SQUARE}),squareConfig2={kernelName:Square,backendName:"webgl",kernelFunc:square2},SQUARED_DIFFERENCE="return (a - b) * (a - b);",squaredDifference3=binaryKernelFunc2({opSnippet:SQUARED_DIFFERENCE,packedOpSnippet:SQUARED_DIFFERENCE}),squaredDifferenceConfig2={kernelName:SquaredDifference,backendName:"webgl",kernelFunc:squaredDifference3};function step3({inputs,attrs,backend:backend22}){let{x}=inputs,opSnippet=CHECK_NAN_SNIPPET+ `
return x > 0.0 ? 1.0 : float ( $ { attrs . alpha } ) ;
` ,program=new UnaryOpProgram(x.shape,opSnippet);return backend22.runWebGLProgram(program,[x],x.dtype)}var stepConfig2={kernelName:Step,backendName:"webgl",kernelFunc:step3},StridedSliceProgram=class{constructor(begin,strides,size){this.variableNames=["x"],this.outputShape=size;let rank=size.length,inputDtype=getCoordsDataType(size.length),dtype=getCoordsDataType(size.length),newCoords="";if(rank===1)newCoords="coords * strides + begin";else{let outputAxis=0;newCoords=size.map((_,i)=>(outputAxis++,size.length===1? ` coords * strides [ $ { i } ] + begin [ $ { i } ] ` : ` coords [ $ { outputAxis - 1 } ] * strides [ $ { i } ] + begin [ $ { i } ] ` )).join(",")}this.userCode= `
$ { inputDtype } begin = $ { inputDtype } ( $ { begin } ) ;
$ { inputDtype } strides = $ { inputDtype } ( $ { strides } ) ;
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } coords = getOutputCoords ( ) ;
setOutput ( getX ( $ { newCoords } ) ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function stridedSlice3(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{begin,end,strides,beginMask,endMask,ellipsisMask,newAxisMask,shrinkAxisMask}=attrs,{nonStrided, $ begin, $ strides,size,newShape,outShape}=slice_util_exports.sliceInfo(x.shape,begin,end,strides,beginMask,endMask,ellipsisMask,newAxisMask,shrinkAxisMask), $ x=reshape3({inputs:{x},backend:backend22,attrs:{shape:newShape}}),result;if(nonStrided){let sliced=slice3({inputs:{x: $ x},backend:backend22,attrs:{begin: $ begin,size}});result=reshape3({inputs:{x:sliced},backend:backend22,attrs:{shape:outShape}}),backend22.disposeIntermediateTensorInfo(sliced)}else if(outShape.some(axis=>axis===0))result=backend22.makeTensorInfo(outShape,x.dtype,[]);else if(backend22.shouldExecuteOnCPU([ $ x])){let values=backend22.texData.get( $ x.dataId).values,xBuf=buffer( $ x.shape, $ x.dtype,values),resultValues=stridedSliceImplCPU(outShape,xBuf, $ strides, $ begin);result=backend22.makeTensorInfo(outShape, $ x.dtype,resultValues.values)}else{let program=new StridedSliceProgram( $ begin, $ strides,outShape);result=backend22.runWebGLProgram(program,[ $ x], $ x.dtype)}let resultReshaped=reshape3({inputs:{x:result},backend:backend22,attrs:{shape:outShape}});return backend22.disposeIntermediateTensorInfo( $ x),backend22.disposeIntermediateTensorInfo(result),resultReshaped}var stridedSliceConfig2={kernelName:StridedSlice,backendName:"webgl",kernelFunc:stridedSlice3},TAN="return tan(x);",tan3=unaryKernelFunc2({opSnippet:TAN}),tanConfig2={kernelName:Tan,backendName:"webgl",kernelFunc:tan3},TANH= `
2021-01-03 16:41:56 +01:00
float e2x = exp ( - 2.0 * abs ( x ) ) ;
return sign ( x ) * ( 1.0 - e2x ) / ( 1.0 + e2x ) ;
2021-01-13 17:14:23 +01:00
` ,tanh4=unaryKernelFunc2({opSnippet:TANH}),tanhConfig2={kernelName:Tanh,backendName:"webgl",kernelFunc:tanh4},TileProgram=class{constructor(aShape,reps){this.variableNames=["A"];let outputShape=new Array(aShape.length);for(let i=0;i<outputShape.length;i++)outputShape[i]=aShape[i]*reps[i];this.outputShape=outputShape,this.rank=outputShape.length;let dtype=getCoordsDataType(this.rank),sourceCoords=getSourceCoords3(aShape);this.userCode= `
2021-01-03 16:41:56 +01:00
void main ( ) {
2021-01-13 17:14:23 +01:00
$ { dtype } resRC = getOutputCoords ( ) ;
setOutput ( getA ( $ { sourceCoords } ) ) ;
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
` }};function getSourceCoords3(aShape){let rank=aShape.length;if(rank>5)throw Error( ` Tile for rank $ { rank } is not yet supported ` );if(rank===1)return ` imod ( resRC , $ { aShape [ 0 ] } ) ` ;let currentCoords=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],sourceCoords=[];for(let i=0;i<aShape.length;i++)sourceCoords.push( ` imod ( $ { currentCoords [ i ] } , $ { aShape [ i ] } ) ` );return sourceCoords.join()}function tile3(params){let{inputs,backend:backend22,attrs}=params,{x}=inputs,{reps}=attrs;if(x.dtype==="string"){let decodedData=backend22.readSync(x.dataId).map(d=>util_exports.decodeString(d)),buf=buffer(x.shape,x.dtype,decodedData),outBuf=tileImplCPU(buf,reps);return backend22.makeTensorInfo(outBuf.shape,outBuf.dtype,outBuf.values)}let program=new TileProgram(x.shape,reps);return backend22.runWebGLProgram(program,[x],x.dtype)}var tileConfig2={kernelName:Tile,backendName:"webgl",kernelFunc:tile3};function topK2(args){let{inputs,backend:backend22,attrs}=args,{x}=inputs,{k,sorted}=attrs,xVals=backend22.readSync(x.dataId),[allTopKVals,allTopKIndices]=topKImplCPU(xVals,x.shape,x.dtype,k,sorted);return[backend22.makeTensorInfo(allTopKVals.shape,allTopKVals.dtype,allTopKVals.values),backend22.makeTensorInfo(allTopKIndices.shape,allTopKIndices.dtype,allTopKIndices.values)]}var topKConfig2={kernelName:TopK,backendName:"webgl",kernelFunc:topK2};function unique3(args){let{inputs,attrs,backend:backend22}=args,{axis}=attrs,{x}=inputs;assertNotComplex2(x,"unique"),console.warn("WARNING: ","UI might be locked temporarily as data is being downloaded");let values=backend22.readSync(x.dataId),{outputValues,outputShape,indices}=uniqueImplCPU(values,axis,x.shape,x.dtype);return[backend22.makeTensorInfo(outputShape,x.dtype,outputValues),backend22.makeTensorInfo([indices.length],"int32",indices)]}var uniqueConfig2={kernelName:Unique,backendName:"webgl",kernelFunc:unique3};function unpack2(args){let{inputs,backend:backend22,attrs}=args,{value}=inputs,{axis}=attrs;axis<0&&(axis+=value.shape.length);let x=value,xRank=x.shape.length,num=value.shape[axis],outShape=new Array(xRank-1),outIndex=0;for(let i=0;i<xRank;i++)i!==axis&&(outShape[outIndex++]=x.shape[i]);let toDispose=[],begin=new Array(xRank).fill(0),size=x.shape.slice();size[axis]=1;let res=new Array(num);for(let i=0;i<res.length;i++){begin[axis]=i;let sliced=slice3({inputs:{x},backend:backend22,attrs:{begin,size}}),reshaped=reshape3({inputs:{x:sliced},backend:backend22,attrs:{shape:outShape}});res[i]=reshaped,toDispose.push(sliced)}return toDispose.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),res}var unpackConfig2={kernelName:Unpack,backendName:"webgl",kernelFunc:unpack2},SegmentOpProgram=class{constructor(segOpInfo,segOpType){this.variableNames=["x","segmentIds"];let windowSize=segOpInfo.windowSize,batchSize=segOpInfo.batchSize,inSize=segOpInfo.inSize,numSegments=segOpInfo.numSegments,outSize=numSegments*Math.ceil(inSize/windowSize);this.outputShape=[batchSize,outSize];let initializationValue="0.0",returnValue="sumValue",windowSizeNearestVec4=Math.floor(windowSize/4)*4,windowSizeVec4Remainder=windowSize%4,updateSnippet= `
2021-01-03 16:41:56 +01:00
sumValue += dot ( values , segFilter ) ;
2021-01-13 17:14:23 +01:00
` ,checkValueOutOfBounds="";inSize%windowSize>0&&(checkValueOutOfBounds= `
if ( inIdx < 0 || inIdx >= $ { inSize } ) {
2021-01-03 16:41:56 +01:00
return initializationValue ;
}
2021-01-13 17:14:23 +01:00
` );let checkSegmentIdOutOfBounds="";inSize%windowSize>0&&(checkSegmentIdOutOfBounds= `
if ( inIdx < 0 || inIdx >= $ { inSize } ) {
2021-01-03 16:41:56 +01:00
return - 1.0 ;
}
` ),this.userCode= `
2021-01-13 17:14:23 +01:00
const float initializationValue = $ { initializationValue } ;
2021-01-03 16:41:56 +01:00
float getValue ( int batch , int inIdx ) {
2021-01-13 17:14:23 +01:00
$ { checkValueOutOfBounds }
2021-01-03 16:41:56 +01:00
return getX ( batch , inIdx ) ;
}
float getSegmentIdAtIndex ( int inIdx ) {
2021-01-13 17:14:23 +01:00
$ { checkSegmentIdOutOfBounds }
2021-01-03 16:41:56 +01:00
return getSegmentIds ( inIdx ) ;
}
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
int inOffset = int ( floor ( float ( outIdx ) / float (
2021-01-13 17:14:23 +01:00
$ { numSegments } ) ) * float ( $ { windowSize } ) ) ;
int currentSeg = int ( mod ( float ( outIdx ) , float ( $ { numSegments } ) ) ) ;
2021-01-03 16:41:56 +01:00
float sumValue = 0.0 ;
2021-01-13 17:14:23 +01:00
for ( int i = 0 ; i < $ { windowSizeNearestVec4 } ; i += 4 ) {
2021-01-03 16:41:56 +01:00
int inIdx = inOffset + i ;
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
getValue ( batch , inIdx + 3 )
) ;
vec4 segFilter = vec4 (
int ( getSegmentIdAtIndex ( inIdx ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 1 ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 2 ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 3 ) ) == currentSeg ? 1 : 0
) ;
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
int inIdx = inOffset + $ { windowSizeNearestVec4 } ;
if ( $ { windowSizeVec4Remainder === 1 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
int inIdxSeg = int ( getSegmentIdAtIndex ( inIdx ) ) ;
vec4 segFilter = vec4 (
int ( getSegmentIdAtIndex ( inIdx ) ) == currentSeg ? 1 : 0 ,
0 ,
0 ,
0
) ;
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
} else if ( $ { windowSizeVec4Remainder === 2 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
initializationValue ,
initializationValue
) ;
vec4 segFilter = vec4 (
int ( getSegmentIdAtIndex ( inIdx ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 1 ) ) == currentSeg ? 1 : 0 ,
0 ,
0
) ;
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
} else if ( $ { windowSizeVec4Remainder === 3 } ) {
2021-01-03 16:41:56 +01:00
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
initializationValue
) ;
vec4 segFilter = vec4 (
int ( getSegmentIdAtIndex ( inIdx ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 1 ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 2 ) ) == currentSeg ? 1 : 0 ,
0
) ;
2021-01-13 17:14:23 +01:00
$ { updateSnippet }
2021-01-03 16:41:56 +01:00
}
2021-01-13 17:14:23 +01:00
setOutput ( $ { returnValue } ) ;
}
` }};function unsortedSegmentSum3(args){let{inputs,backend:backend22,attrs}=args,{x,segmentIds}=inputs,{numSegments}=attrs,xRank=x.shape.length,toDispose=[],axis=0,permutation=backend_util_exports.getAxesPermutation([axis],xRank),permutedX=x;permutation!=null&&(permutedX=transpose3({inputs:{x},backend:backend22,attrs:{perm:permutation}}),toDispose.push(permutedX),axis=backend_util_exports.getInnerMostAxes(1,xRank)[0]);let outShape=backend_util_exports.segment_util.computeOutShape(permutedX.shape,axis,numSegments),inSize=util_exports.sizeFromShape([permutedX.shape[axis]]),a2D=reshape3({inputs:{x:permutedX},backend:backend22,attrs:{shape:[-1,inSize]}});toDispose.push(a2D);let outputDType=sumOutType(x.dtype),segOpCompute=(x2,segOpType,segmentIds2,dtype,numSegments2)=>{let batchSize=x2.shape[0],inSize2=x2.shape[1],windowSize=backend_util_exports.segment_util.segOpComputeOptimalWindowSize(inSize2,numSegments2),segOpInfo={windowSize,inSize:inSize2,batchSize,numSegments:numSegments2},program=new SegmentOpProgram(segOpInfo,segOpType),output=backend22.compileAndRun(program,[x2,segmentIds2],dtype);if(toDispose.push(output),output.shape[1]===numSegments2)return output;let rangeInfo=range3({backend:backend22,attrs:{start:0,stop:numSegments2,step:1,dtype:"float32"}}),tileInfo=tile3({inputs:{x:rangeInfo},backend:backend22,attrs:{reps:[inSize2/windowSize]}});return toDispose.push(rangeInfo),toDispose.push(tileInfo),segOpCompute(output,segOpType,tileInfo,dtype,numSegments2)},segOpResult=segOpCompute(a2D,"unsortedSegmentSum",segmentIds,outputDType,numSegments),reshaped=reshape3({inputs:{x:segOpResult},backend:backend22,attrs:{shape:outShape}}),result=reshaped;if(permutation!=null){toDispose.push(reshaped);let perm=backend_util_exports.getUndoAxesPermutation(permutation);result=transpose3({inputs:{x:result},backend:backend22,attrs:{perm}})}return toDispose.forEach(t=>backend22.disposeIntermediateTensorInfo(t)),result}var unsortedSegmentSumConfig2={kernelName:UnsortedSegmentSum,backendName:"webgl",kernelFunc:unsortedSegmentSum3},kernelConfigs2=[LRNConfig,LRNGradConfig,_fusedMatMulConfig2,absConfig2,acosConfig2,acoshConfig2,addConfig2,addNConfig2,allConfig2,anyConfig2,argMaxConfig2,argMinConfig2,asinConfig2,asinhConfig2,atan2Config2,atanConfig2,atanhConfig2,avgPool3DConfig2,avgPoolConfig2,avgPoolGrad3DConfig,avgPoolGradConfig3,batchMatMulConfig2,batchNormConfig2,batchToSpaceNDConfig2,bincountConfig2,castConfig2,ceilConfig2,clipByValueConfig,complexAbsConfig2,complexConfig2,concatConfig2,conv2DBackpropFilterConfig2,conv2DBackpropInputConfig2,conv2DConfig2,conv3DBackpropFilterV2Config2,conv3DBackpropInputConfig,conv3DConfig2,cosConfig2,coshConfig2,cropAndResizeConfig2,cumsumConfig2,denseBincountConfig2,depthToSpaceConfig2,depthwiseConv2dNativeBackpropFilterConfig2,depthwiseConv2dNativeBackpropInputConfig2,depthwiseConv2dNativeConfig2,diagConfig2,dilation2DConfig,eluConfig2,eluGradConfig3,equalConfig2,erfConfig2,expConfig2,expandDimsConfig2,expm1Config2,fftConfig2,fillConfig2,flipLeftRightConfig2,floorConfig2,floorDivConfig2,fromPixelsConfig,fusedConv2DConfig2,fusedDepthwiseConv2DConfig2,gatherNdConfig2,gatherV2Config2,greaterConfig2,greaterEqualConfig2,identityConfig2,ifftConfig2,imagConfig2,isFiniteConfig2,isInfConfig2,isNaNConfig2,leakyReluConfig2,lessConfig2,lessEqualConfig2,linSpaceConfig2,log1pConfig2,logConfig2,logicalAndConfig2,logicalNotConfig2,logicalOrConfig2,maxConfig2,maxPool3DConfig2,maxPoolConfig2,maxPoolGrad3DConfig,maxPoolGradConfig3,maxPoolWithArgmaxConfig2,maximumConfig2,meanConfig2,minConfig2,minimumConfig2,mirrorPadConfig2,modConfig2,multinomialConfig2,multiplyConfig2,negConfig2,nonMaxSuppressionV3Config2,nonMaxSuppressionV4Config2,nonMaxSuppressionV5Config2,notEqualConfig2,oneHotConfig2,onesLikeConfig2,packConfig2,padV2Config2,powConfig2,preluConfig2,prodConfig2,rangeConfig2,realConfig2,realDivConfig2,reciprocalConfig2,relu6Config2,reluConfig2,reshapeConfig2,resizeBilinearConfig2,resizeBilinearGradConfig3,resizeNearestNeighborConfig2,resizeNearestNeighborGradConfig3,reverseConfig2,rotateWithOffsetConfig2,roundConfig2,
1. The $ { printableModuleName } is defined in Python , in which case it needs to be ported to TensorFlow . js or your JavaScript code .
2. The custom $ { printableModuleName } is defined in JavaScript , but is not registered properly with tf . serialization . registerClass ( ) . ` );return fn}else{let config2=identifier;if(config2.className==null||config2.config==null)throw new ValueError( ` $ { printableModuleName } : Improper config format : $ { JSON . stringify ( config2 ) } .
'className' and 'config' must set . ` );let className=config2.className,cls,fromConfig;if(className in customObjects?[cls,fromConfig]=customObjects[className]:className in _GLOBAL_CUSTOM_OBJECTS?[cls,fromConfig]=_GLOBAL_CUSTOM_OBJECTS.className:className in moduleObjects&&([cls,fromConfig]=moduleObjects[className]),cls==null)throw new ValueError( ` Unknown $ { printableModuleName } : $ { className } . This may be due to one of the following reasons :
1. The $ { printableModuleName } is defined in Python , in which case it needs to be ported to TensorFlow . js or your JavaScript code .
2. The custom $ { printableModuleName } is defined in JavaScript , but is not registered properly with tf . serialization . registerClass ( ) . ` );if(fromConfig!=null){let customObjectsCombined={};for(let key of Object.keys(_GLOBAL_CUSTOM_OBJECTS))customObjectsCombined[key]=_GLOBAL_CUSTOM_OBJECTS[key];for(let key of Object.keys(customObjects))customObjectsCombined[key]=customObjects[key];let nestedConfig=config2.config;nestedConfig.customObjects=customObjectsCombined;let backupCustomObjects=Object.assign({},_GLOBAL_CUSTOM_OBJECTS);for(let key of Object.keys(customObjects))_GLOBAL_CUSTOM_OBJECTS[key]=customObjects[key];convertNDArrayScalarsInConfig(config2.config);let returnObj=fromConfig(cls,config2.config,customObjects,fastWeightInit);return _GLOBAL_CUSTOM_OBJECTS=Object.assign({},backupCustomObjects),returnObj}else{let backupCustomObjects=Object.assign({},_GLOBAL_CUSTOM_OBJECTS);for(let key of Object.keys(customObjects))_GLOBAL_CUSTOM_OBJECTS[key]=customObjects[key];let returnObj=new cls(config2.config);return _GLOBAL_CUSTOM_OBJECTS=Object.assign({},backupCustomObjects),returnObj}}}function numberCompare(a,b){return a<b?-1:a>b?1:0}function reverseNumberCompare(a,b){return-1*numberCompare(a,b)}function unique4(xs){if(xs==null)return xs;let out=[];for(let x of xs)out.indexOf(x)===-1&&out.push(x);return out}function isObjectEmpty(obj){if(obj==null)throw new ValueError( ` Invalid value in obj : $ { JSON . stringify ( obj ) } ` );for(let key in obj)if(obj.hasOwnProperty(key))return!1;return!0}function checkStringTypeUnionValue(values,label,value){if(value!=null&&values.indexOf(value)<0)throw new ValueError( ` $ { value } is not a valid $ { label } . Valid values are $ { values } or null / undefined . ` )}function checkArrayTypeAndLength(x,expectedType,minLength=0,maxLength=Infinity){return assert2(minLength>=0),assert2(maxLength>=minLength),Array.isArray(x)&&x.length>=minLength&&x.length<=maxLength&&x.every(e=>typeof e===expectedType)}function assertPositiveInteger(value,name){Array.isArray(value)?(util_exports.assert(value.length>0,()=> ` $ { name } is unexpectedly an empty array . ` ),value.forEach((v,i)=>assertPositiveInteger(v, ` element $ { i + 1 } of $ { name } ` ))):util_exports.assert(Number.isInteger(value)&&value>0,()=> ` Expected $ { name } to be a positive integer , but got $ { formatAsFriendlyString ( value ) } . ` )}function formatAsFriendlyString(value){return value===null?"null":Array.isArray(value)?"["+value.map(v=>formatAsFriendlyString(v)).join(",")+"]":typeof value=="string"? ` "${value}" ` : ` $ { value } ` }function debounce(f,waitMs){let lastTime=util_exports.now(),lastResult;return(...args)=>{let now22=util_exports.now();return now22-lastTime<waitMs||(lastTime=now22,lastResult=f(...args)),lastResult}}function mapActivationToFusedKernel(activationName){return activationName==="relu"?"relu":activationName==="linear"?"linear":activationName==="elu"?"elu":null}function calcL2Norms(w,axis){return tidy(()=>sqrt(sum2(mul(w,w),axis,!0)))}var Constraint=class extends serialization_exports.Serializable{getConfig(){return{}}},MaxNorm=class extends Constraint{constructor(args){super();this.defaultMaxValue=2,this.defaultAxis=0,this.maxValue=args.maxValue!=null?args.maxValue:this.defaultMaxValue,this.axis=args.axis!=null?args.axis:this.defaultAxis}apply(w){return tidy(()=>{let norms=calcL2Norms(w,this.axis),desired=clipByValue(norms,0,this.maxValue);return mul(w,div(desired,add2(epsilon2(),norms)))})}getConfig(){return{maxValue:this.maxValue,axis:this.axis}}};MaxNorm.className="MaxNorm";serialization_exports.registerClass(MaxNorm);var UnitNorm=class extends Constraint{constructor(args){super();this.defaultAxis=0,this.axis=args.axis!=null?args.axis:this.defaultAxis}apply(w){return tidy(()=>div(w,add2(epsilon2(),calcL2Norms(w,this.axis))))}getConfig(){return{axis:this.axis}}};UnitNorm.className="UnitNorm";serialization_exports.registerClass(UnitNorm);var NonNeg=class extends Constraint{apply(w){return relu(w)}};NonNeg.className="NonNeg";serialization_exports.registerClass(NonNeg);var MinMaxNorm=class extends Constraint{constructor(args){super();this.defaultMinValue=0,this.defaultMaxValue=1,this.defau
because the value dtype is $ { tensor2 . dtype } , but TensorArray dtype is $ { this . dtype } . ` );if(this.size()===0&&(this.elementShape==null||this.elementShape.length===0)&&(this.elementShape=tensor2.shape),assertShapesMatchAllowUndefinedSize(this.elementShape,tensor2.shape, ` TensorArray $ { this . name } : Could not write to TensorArray index $ { index } . ` ),t.read)throw new Error( ` TensorArray $ { this . name } : Could not write to TensorArray index $ { index } , because it has already been read . ` );if(t.written)throw new Error( ` TensorArray $ { this . name } : Could not write to TensorArray index $ { index } , because it has already been written . ` );t.tensor=tensor2,keep(tensor2),t.written=!0,this.tensors[index]=t}writeMany(indices,tensors){if(indices.length!==tensors.length)throw new Error( ` TensorArray $ { this . name } : could not write multiple tensors , because the index size : $ { indices . length } is not the same as tensors size : $ { tensors . length } . ` );indices.forEach((i,index)=>this.write(i,tensors[index]))}gather(indices,dtype){if(!!dtype&&dtype!==this.dtype)throw new Error( ` TensorArray dtype is $ { this . dtype } but gather requested dtype $ { dtype } ` );if(indices)indices=indices.slice(0,this.size());else{indices=[];for(let i=0;i<this.size();i++)indices.push(i)}if(indices.length===0)return tensor([],[0].concat(this.elementShape));let tensors=this.readMany(indices);return assertShapesMatchAllowUndefinedSize(this.elementShape,tensors[0].shape,"TensorArray shape mismatch: "),stack(tensors,0)}concat(dtype){if(!!dtype&&dtype!==this.dtype)throw new Error( ` TensorArray dtype is $ { this . dtype } but concat requested dtype $ { dtype } ` );if(this.size()===0)return tensor([],[0].concat(this.elementShape));let indices=[];for(let i=0;i<this.size();i++)indices.push(i);let tensors=this.readMany(indices);return assertShapesMatchAllowUndefinedSize(this.elementShape,tensors[0].shape, ` TensorArray shape mismatch : tensor array shape ( $ { this . elementShape } ) vs first tensor shape ( $ { tensors [ 0 ] . shape } ) ` ),concat(tensors,0)}scatter(indices,tensor2){if(tensor2.dtype!==this.dtype)throw new Error( ` TensorArray dtype is $ { this . dtype } but tensor has dtype $ { tensor2 . dtype } ` );if(indices.length!==tensor2.shape[0])throw new Error( ` Expected len ( indices ) == tensor . shape [ 0 ] , but saw : $ { indices . length } vs . $ { tensor2 . shape [ 0 ] } ` );let maxIndex=Math.max(...indices);if(!this.dynamicSize&&maxIndex>=this.maxSize)throw new Error( ` Max index must be < array size ( $ { maxIndex } vs . $ { this . maxSize } ) ` );this.writeMany(indices,unstack(tensor2,0))}split(length,tensor2){if(tensor2.dtype!==this.dtype)throw new Error( ` TensorArray dtype is $ { this . dtype } but tensor has dtype $ { tensor2 . dtype } ` );let totalLength=0,cumulativeLengths=length.map(len=>(totalLength+=len,totalLength));if(totalLength!==tensor2.shape[0])throw new Error( ` Expected sum of lengths to be equal to
2020-12-13 00:34:30 +01:00
tensor . shape [ 0 ] , but sum of lengths is
2021-01-13 17:14:23 +01:00
$ { totalLength } , and tensor 's shape is: ${tensor2.shape}`);if(!this.dynamicSize&&length.length!==this.maxSize)throw new Error(`TensorArray' s size is not equal to the size of lengths ( $ { this . maxSize } vs . $ { length . length } ) , and the TensorArray is not marked as dynamically resizeable ` );let elementPerRow=totalLength===0?0:tensor2.size/totalLength,tensors=[];tidy(()=>{tensor2=reshape(tensor2,[1,totalLength,elementPerRow]);for(let i=0;i<length.length;++i){let previousLength=i===0?0:cumulativeLengths[i-1],indices2=[0,previousLength,0],sizes=[1,length[i],elementPerRow];tensors[i]=reshape(slice(tensor2,indices2,sizes),this.elementShape)}return tensors});let indices=[];for(let i=0;i<length.length;i++)indices[i]=i;this.writeMany(indices,tensors)}},TensorList=class{constructor(tensors,elementShape,elementDtype,maxNumElements=-1){this.tensors=tensors,this.elementShape=elementShape,this.elementDtype=elementDtype,tensors!=null&&tensors.forEach(tensor2=>{if(elementDtype!==tensor2.dtype)throw new Error( ` Invalid data types ; op elements $ { elementDtype } , but list elements $ { tensor2 . dtype } ` );assertShapesMatchAllowUndefinedSize(elementShape,tensor2.shape,"TensorList shape mismatch: "),keep(tensor2)}),this.idTensor=scalar(0),this.maxNumElements=maxNumElements,keep(this.idTensor)}get id(){return this.idTensor.id}copy(){return new TensorList([...this.tensors],this.elementShape,this.elementDtype)}clearAndClose(keepIds){this.tensors.forEach(tensor2=>{(keepIds==null||!keepIds.has(tensor2.id))&&tensor2.dispose()}),this.tensors.length=0,this.idTensor.dispose()}size(){return this.tensors.length}stack(elementShape,elementDtype,numElements=-1){if(elementDtype!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { elementDtype } , but list elements $ { this . elementDtype } ` );if(numElements!==-1&&this.tensors.length!==numElements)throw new Error( ` Operation expected a list with $ { numElements } elements but got a list with $ { this . tensors . length } elements . ` );return assertShapesMatchAllowUndefinedSize(elementShape,this.elementShape,"TensorList shape mismatch: "),tidy(()=>{let reshapedTensors=this.tensors.map(tensor2=>reshape(tensor2,elementShape));return stack(reshapedTensors,0)})}popBack(elementShape,elementDtype){if(elementDtype!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { elementDtype } , but list elements $ { this . elementDtype } ` );if(this.size()===0)throw new Error("Trying to pop from an empty list.");let tensor2=this.tensors.pop();return assertShapesMatchAllowUndefinedSize(tensor2.shape,elementShape,"TensorList shape mismatch: "),reshape(tensor2,elementShape)}pushBack(tensor2){if(tensor2.dtype!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { tensor2 . dtype } , but list elements $ { this . elementDtype } ` );if(assertShapesMatchAllowUndefinedSize(tensor2.shape,this.elementShape,"TensorList shape mismatch: "),this.maxNumElements===this.size())throw new Error("Trying to push element into a full list.");keep(tensor2),this.tensors.push(tensor2)}resize(size){if(size<0)throw new Error( ` TensorListResize expects size to be non - negative . Got : $ { size } ` );if(this.maxNumElements!==-1&&size>this.maxNumElements)throw new Error( ` TensorListResize input size $ { size } is greater maxNumElement $ { this . maxNumElements } . ` );this.tensors.length=size}getItem(elementIndex,elementShape,elementDtype){if(elementDtype!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { elementDtype } , but list elements $ { this . elementDtype } ` );if(elementIndex<0||elementIndex>this.tensors.length)throw new Error( ` Trying to access element $ { elementIndex } in a list with $ { this . tensors . length } elements . ` );if(this.tensors[elementIndex]==null)throw new Error( ` element at index $ { elementIndex } is null . ` );return assertShapesMatchAllowUndefinedSize(this.tensors[elementIndex].shape,elementShape,"TensorList shape mismatch: "),this.tensors[elementIndex]}setItem(elementIndex,tensor2){if(tensor2.dtype!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { tensor2 . dtype } , but list elements $ { this . elementDtype } ` );if(elementIndex<0||this.maxN
2020-12-13 00:34:30 +01:00
tensor . shape [ 0 ] , but sum of lengths is
2021-01-13 17:14:23 +01:00
$ { totalLength } , and tensor ' s shape is : $ { tensor2 . shape } ` );let elementPerRow=totalLength===0?0:tensor2.size/totalLength,tensors=tidy(()=>{let tensors2=[];tensor2=reshape(tensor2,[1,totalLength,elementPerRow]);for(let i=0;i<length.length;++i){let previousLength=i===0?0:cumulativeLengths[i-1],indices=[0,previousLength,0],sizes=[1,length[i],elementPerRow];tensors2[i]=reshape(slice(tensor2,indices,sizes),elementShape)}return tensor2.dispose(),tensors2}),list=new TensorList([],elementShape,tensor2.dtype,length.length);for(let i=0;i<tensors.length;i++)list.setItem(i,tensors[i]);return list}var executeOp3=async(node,tensorMap,context)=>{switch(node.op){case"If":case"StatelessIf":{let thenFunc=getParamValue("thenBranch",node,tensorMap,context),elseFunc=getParamValue("elseBranch",node,tensorMap,context),cond=getParamValue("cond",node,tensorMap,context),args=getParamValue("args",node,tensorMap,context);return(await cond.data())[0]?context.functionMap[thenFunc].executeFunctionAsync(args,context.tensorArrayMap,context.tensorListMap):context.functionMap[elseFunc].executeFunctionAsync(args,context.tensorArrayMap,context.tensorListMap)}case"While":case"StatelessWhile":{let bodyFunc=getParamValue("body",node,tensorMap,context),condFunc=getParamValue("cond",node,tensorMap,context),args=getParamValue("args",node,tensorMap,context),condResult=await context.functionMap[condFunc].executeFunctionAsync(args,context.tensorArrayMap,context.tensorListMap),argIds=args.map(tensor2=>tensor2.id),condValue=await condResult[0].data();condResult.forEach(tensor2=>{!tensor2.kept&&argIds.indexOf(tensor2.id)===-1&&tensor2.dispose()});let result=args;for(;condValue[0];){let origResult=result;result=await context.functionMap[bodyFunc].executeFunctionAsync(result,context.tensorArrayMap,context.tensorListMap);let resultIds=result.map(tensor2=>tensor2.id);origResult.forEach(tensor2=>{!tensor2.kept&&argIds.indexOf(tensor2.id)===-1&&resultIds.indexOf(tensor2.id)===-1&&tensor2.dispose()});let condResult2=await context.functionMap[condFunc].executeFunctionAsync(result,context.tensorArrayMap,context.tensorListMap);condValue=await condResult2[0].data(),condResult2.forEach(tensor2=>{!tensor2.kept&&argIds.indexOf(tensor2.id)===-1&&resultIds.indexOf(tensor2.id)===-1&&tensor2.dispose()})}return result}case"LoopCond":{let pred=getParamValue("pred",node,tensorMap,context);return[cloneTensor(pred)]}case"Switch":{let pred=getParamValue("pred",node,tensorMap,context),data2=getParamValue("data",node,tensorMap,context);return data2.kept||(data2=cloneTensor(data2)),(await pred.data())[0]?[void 0,data2]:[data2,void 0]}case"Merge":{let inputName=node.inputNames.find(name=>getTensor(name,tensorMap,context)!==void 0);if(inputName){let data2=getTensor(inputName,tensorMap,context);return[cloneTensor(data2)]}return}case"Enter":{let frameId=getParamValue("frameName",node,tensorMap,context),data2=getParamValue("tensor",node,tensorMap,context);return context.enterFrame(frameId),[cloneTensor(data2)]}case"Exit":{let data2=getParamValue("tensor",node,tensorMap,context);return context.exitFrame(),[cloneTensor(data2)]}case"NextIteration":{let data2=getParamValue("tensor",node,tensorMap,context);return context.nextIteration(),[cloneTensor(data2)]}case"TensorArrayV3":{let size=getParamValue("size",node,tensorMap,context),dtype=getParamValue("dtype",node,tensorMap,context),elementShape=getParamValue("elementShape",node,tensorMap,context),dynamicSize=getParamValue("dynamicSize",node,tensorMap,context),clearAfterRead=getParamValue("clearAfterRead",node,tensorMap,context),identicalElementShapes=getParamValue("identicalElementShapes",node,tensorMap,context),name=getParamValue("name",node,tensorMap,context),tensorArray=new TensorArray(name,dtype,size,elementShape,identicalElementShapes,dynamicSize,clearAfterRead);return context.addTensorArray(tensorArray),[tensorArray.idTensor,scalar(1)]}case"TensorArrayWriteV3":{let id=getParamValue("tensorArrayId",node,tensorMap,context),index=getParamValue("index",node,tensorMap,context),writeTensor=getParamValue("tensor",node,tensorMap,context),writeTensorA
$ { batchSize } ` );let size;return this.size===Infinity||this.size==null?size=this.size:smallLastBatch?size=Math.ceil(this.size/batchSize):size=Math.floor(this.size/batchSize),datasetFromIteratorFn(async()=>(await base2.iterator()).columnMajorBatch(batchSize,smallLastBatch,deepBatchConcat),size)}concatenate(dataset){let base2=this,size;return this.size===Infinity||dataset.size===Infinity?size=Infinity:this.size!=null&&dataset.size!=null?size=this.size+dataset.size:size=null,datasetFromIteratorFn(async()=>(await base2.iterator()).concatenate(await dataset.iterator()),size)}filter(predicate){let base2=this,size;return this.size===Infinity?size=Infinity:size=null,datasetFromIteratorFn(async()=>(await base2.iterator()).filter(x=>tidy(()=>predicate(x))),size)}async forEachAsync(f){return(await this.iterator()).forEachAsync(f)}map(transform){let base2=this;return datasetFromIteratorFn(async()=>(await base2.iterator()).map(x=>tidy(()=>transform(x))),this.size)}mapAsync(transform){let base2=this;return datasetFromIteratorFn(async()=>(await base2.iterator()).mapAsync(transform),this.size)}prefetch(bufferSize){if(bufferSize==null)throw new RangeError(" ` Dataset . prefetch ( ) ` requires bufferSize to be specified.");let base2=this;return datasetFromIteratorFn(async()=>(await base2.iterator()).prefetch(bufferSize),this.size)}repeat(count2){let base2=this,size;return this.size!=null&&count2>0?size=this.size*count2:count2===0?size=0:this.size!=null&&(count2===void 0||count2<0)?size=Infinity:size=null,datasetFromIteratorFn(async()=>{let iteratorIterator=iteratorFromFunction(async()=>({value:await base2.iterator(),done:!1}));return iteratorFromConcatenated(iteratorIterator.take(count2))},size)}skip(count2){let base2=this,size;return this.size!=null&&count2>=0&&this.size>=count2?size=this.size-count2:this.size!=null&&(this.size<count2||count2===void 0||count2<0)?size=0:size=null,datasetFromIteratorFn(async()=>(await base2.iterator()).skip(count2),size)}shuffle(bufferSize,seed,reshuffleEachIteration=!0){if(bufferSize==null||bufferSize<0)throw this.size==null?new RangeError(" ` Dataset . shuffle ( ) ` requires bufferSize to be specified."):new RangeError( ` \ ` Dataset.shuffle() \` requires bufferSize to be specified. If your data fits in main memory (for regular JS objects), and/or GPU memory (for \` tf.Tensor \` s), consider setting bufferSize to the dataset size ( ${ this . size } elements) ` ) ; let base2 = this , random = seedrandom4 . alea ( seed || util _exports . now ( ) . toString ( ) ) ; return datasetFromIteratorFn ( async ( ) => { let seed2 = random . int32 ( ) ; return reshuffleEachIteration && ( seed2 += random . int32 ( ) ) , ( await base2 . iterator ( ) ) . shuffle ( bufferSize , seed2 . toString ( ) ) } , this . size ) } take ( count2 ) { let base2 = this , size ; return this . size != null && this . size > count2 ? size = count2 : this . size != null && this . size <= count2 ? size = this . size : size = null , datasetFromIteratorFn ( async ( ) => ( await base2 . iterator ( ) ) . take ( count2 ) , size ) } async toArray ( ) { if ( this . size === Infinity ) throw new Error ( "Can not convert infinite data stream to array." ) ; return ( await this . iterator ( ) ) . toArray ( ) } async toArrayForTest ( ) { if ( this . size === Infinity ) throw new Error ( "Can not convert infinite data stream to array." ) ; return ( await this . iterator ( ) ) . toArrayForTest ( ) } } ; Dataset . MAX _BUFFER _SIZE = 1e4 ; function datasetFromIteratorFn ( iteratorFn , size = null ) { return new class extends Dataset { constructor ( ) { super ( ... arguments ) ; this . size = size } async iterator ( ) { return iteratorFn ( ) } } } function array ( items ) { return datasetFromIteratorFn ( async ( ) => iteratorFromItems ( items ) , items . length ) } function zip ( datasets ) { if ( ! isIterable2 ( datasets ) ) throw new Error ( "The argument to zip() must be an object or array." ) ; let size ; if ( Array . isArray ( datasets ) ) for ( let i = 0 ; i < datasets . length ; i ++ ) size = size == null ? datasets [ i ] . size : Math . min ( size , datasets [ i ] . size ) ; else if ( datasets instanceof Object ) for ( let ds in datasets ) size = size == null ? datasets [ ds ] . size : Math . min ( size , datasets [ ds ] . size ) ; return datasetFromIteratorFn ( async ( ) => { let streams = await deepMapAndAwaitAll ( datasets , d => { if ( d instanceof Dataset ) return { value : d . iterator ( ) , recurse : ! 1 } ; if ( isIterable2 ( d ) ) return { value : null , recurse : ! 0 } ; throw new Error ( " Leav
` ).map(line=>(line.endsWith(" \r ")&&(line=line.slice(0,-1)),line))}},CODE_QUOTE='"',STATE_OUT=Symbol("out"),STATE_FIELD=Symbol("field"),STATE_QUOTE=Symbol("quote"),STATE_QUOTE_AFTER_QUOTE=Symbol("quoteafterquote"),STATE_WITHIN_QUOTE_IN_QUOTE=Symbol("quoteinquote"),CSVDataset=class extends Dataset{constructor(input2,csvConfig){super();this.input=input2,this.hasHeader=!0,this.fullColumnNames=null,this.columnNamesValidated=!1,this.columnConfigs=null,this.configuredColumnsOnly=!1,this.delimiter=",",this.delimWhitespace=!1,this.base=new TextLineDataset(input2),csvConfig||(csvConfig={}),this.hasHeader=csvConfig.hasHeader!==!1,this.fullColumnNames=csvConfig.columnNames,this.columnConfigs=csvConfig.columnConfigs,this.configuredColumnsOnly=csvConfig.configuredColumnsOnly,csvConfig.delimWhitespace?(util_exports.assert(csvConfig.delimiter==null,()=>"Delimiter should not be provided when delimWhitespace is true."),this.delimWhitespace=!0,this.delimiter=" "):this.delimiter=csvConfig.delimiter?csvConfig.delimiter:","}async columnNames(){return this.columnNamesValidated||await this.setColumnNames(),this.configuredColumnsOnly?Object.keys(this.columnConfigs):this.fullColumnNames}async setColumnNames(){let columnNamesFromFile=await this.maybeReadHeaderLine();if(!this.fullColumnNames&&!columnNamesFromFile)throw new Error("Column names must be provided if there is no header line.");this.fullColumnNames&&columnNamesFromFile&&util_exports.assert(columnNamesFromFile.length===this.fullColumnNames.length,()=>"The length of provided columnNames ("+this.fullColumnNames.length.toString()+") does not match the length of the header line read from file ("+columnNamesFromFile.length.toString()+")."),this.fullColumnNames||(this.fullColumnNames=columnNamesFromFile);let counts=this.fullColumnNames.reduce((countAcc,name)=>(countAcc[name]=countAcc[name]+1||1,countAcc),{}),duplicateNames=Object.keys(counts).filter(name=>counts[name]>1);if(util_exports.assert(duplicateNames.length===0,()=>"Duplicate column names found: "+duplicateNames.toString()),this.columnConfigs){for(let key of Object.keys(this.columnConfigs))if(this.fullColumnNames.indexOf(key)===-1)throw new Error('The key "'+key+'" provided in columnConfigs does not match any of the column names ('+this.fullColumnNames.toString()+").")}this.columnNamesValidated=!0}async maybeReadHeaderLine(){if(this.hasHeader){let firstElement=await(await this.base.iterator()).next();if(firstElement.done)throw new Error("No data was found for CSV parsing.");let firstLine=firstElement.value;return this.parseRow(firstLine,!1)}else return null}async iterator(){this.columnNamesValidated||await this.setColumnNames();let lines=await this.base.iterator();return this.hasHeader&&(lines=lines.skip(1)),lines.map(x=>this.makeDataElement(x))}makeDataElement(line){let values=this.parseRow(line),features={},labels={};for(let i=0;i<this.fullColumnNames.length;i++){let key=this.fullColumnNames[i],config2=this.columnConfigs?this.columnConfigs[key]:null;if(!(this.configuredColumnsOnly&&!config2)){let value=values[i],parsedValue=null;if(value==="")if(config2&&config2.default!==void 0)parsedValue=config2.default;else{if(config2&&(config2.required||config2.isLabel))throw new Error( ` Required column $ { key } is empty in this line : $ { line } ` );parsedValue=void 0}else{let valueAsNum=Number(value);if(isNaN(valueAsNum))config2&&config2.dtype==="bool"?parsedValue=this.getBoolean(value):parsedValue=value;else if(!config2||!config2.dtype)parsedValue=valueAsNum;else switch(config2.dtype){case"float32":parsedValue=valueAsNum;break;case"int32":parsedValue=Math.floor(valueAsNum);break;case"bool":parsedValue=this.getBoolean(value);break;default:parsedValue=valueAsNum}}config2&&config2.isLabel?labels[key]=parsedValue:features[key]=parsedValue}}return Object.keys(labels).length===0?features:{xs:features,ys:labels}}getBoolean(value){return value==="1"||value.toLowerCase()==="true"?1:0}parseRow(line,validateElementCount=!0){let result=[],readOffset=0,readLength=line.length,currentState=STATE_OUT;for(let i=0;i<readLength;i++)switch(currentState){case STATE_OUT:sw
2020-12-08 15:58:30 +01:00
/ 9 j / 4 A A Q S k Z J R g A B A Q E A Y A B g A A D / 4 Q B o R X h p Z g A A T U 0 A K g A A A A g A B A E a A A U A A A A B A A A A P g E b A A U A
AAABAAAARgEoAAMAAAABAAIAAAExAAIAAAARAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQu
bmV0IDQuMi4xMwAA / 9 sAQwAGBAUGBQQGBgUGBwcGCAoQCgoJCQoUDg8MEBcUGBgXFBYWGh0lHxob
IxwWFiAsICMmJykqKRkfLTAtKDAlKCko / 9 sAQwEHBwcKCAoTCgoTKBoWGigoKCgoKCgoKCgoKCgo
KCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo / 8 AAEQgBAAEAAwEhAAIRAQMRAf / E
AB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC //EALUQAAIBAwMCBAMFBQQEAAABfQECAwAE
EQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZH
SElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1
tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fL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rVW6i8yFhkg + tJjRxGsWrxllkUMh9eK5uMz6bcebbnfG33kPcVkay2OntPKuo0
nhXI67c8qa7Lw3c + adjcEDGK1paSRhVV4s6A0or0jyRRQ1AHX0V553hRQBz + vNtt5z3xXzX8Qbdm
uic5YnOMdK3l8JnTXvlbwpYl + WySOgrp5YfLOOB9O1c62O7qQkc + 9 RsKChFPWp4DluOlSykaNruH
ArUgHShFNF2NT1qxGO3NBmyxGcE1N2560CFzjrUysO9JAPDDjFOVuKoQuSRTWouBkazbCa3cd8cV
wF7IISQccHBzUSWpV9C3o1x5b5GAjdQD1rs9DjC3kckbEhqKfxIzn8LOupRXqnkPccBSkUAzraK8
87 wooA5rxMSI3HqK8B8bQl9Q8sffY5b / AAraXwkUviNrw9pH2W1ViMMRTdRjw4HpWNtDti9TPc4P
FQs2M5qdyyMHLcfjV63HTAoBGtap0wK0YxigpsuRDtVhVYd6GQydVwwIqdRnqKCR23I5pCMUW6gD
YNKuetAEise9KTxQBWuFyhrznxNZkXjFeN3I + tTIZg2OqmzmxNF0PO3vXp / g2 + hukVl4zyPanTXv
JmVR + 60 dpThXpnlPceopWFAbnV0V553hSGgRynjC5FujOey14Ssp1HxNmTnc + a3kvcIpv37HoEYQ
QmMdVHSsnVbYJF5jVk0dsNzlruVIsl2wKxbjWrVHILjg1CRbZJb + ILHPzyhfStODWLQgFJFYd + el
UJM27HUIXxhga1Y5lLVLKLkMnoauxnPPrSEx7ShF + Y / n2qrc6xBbhizDAqkK1zJuvG9nbg8ZA681
ly / Ei052RO3uKAsZlx8QGd8xxvt9Aa1NH8dK7AXMcip64zigdkdrZX8F7EJLdwwNXMkrz1qRMRly
CK4TxmpidWI49felPYSOMmi80NIoOV6qRzXYeA5SskYPfirpfEjGr8LPWVHyD6U4CvQPL3ZItOYc
UDOoNFeed4Uhpks4H4iE / Z5MeleMeGULeLgjds10S + BGdL + Jc9OSBU2Huc5Nc74yvUtrcDBrJnZF
63 PJdXvLy / lKWw46bvQVz82jXhkLO5Y + 9 ZlsYthcRnbIjY9R3q3awTRkEM3WmJI6C0ea3dGRsr1x
XY6TqW9FLHnjrUs0izpLK5DDjofSta3ckH09KRUkZuuTvFGdvPauE1Y3U6Mqbssf / rUxHPTaJPK2
ZmJPbBqzY6DCZh5xJC9s9aBJHU6dpemJjfEmfetJtI0 + VPkUr / unFOxdiextHs33W07YHQHk11mk
Xb3KbZ1xIvcd6LEyWho4Nct41sTPYb16ipexCPPZN + wYGCvH1rrPAEJmvkPoc1VL4kZVvgZ6yFwK
cBXoHkkqinFaVyzo80GuE7WJRQSziPiGdthK5HQV4x4J / wBI8WPIewNdEvgRNL42emO / yj1UHNef
eNpRczbC + I17DvWT2OqJxc0sMK4TCisy41q0hfEkqj8aixdwTXNOlwvmqD9anS9tXH7uVG + hosO4
/ w C 0 o O h r R 0 + 6 G 4 Y N I E z s N E u C x A P N d j Z r u A 4 x x U m j I N S j U R k s O l c b q F y k b n j F A 1 s Y G o a s s a k n C q O 5
rl7rxhGm7yBnBxuJq0rkSlYpw + NLlsfd5P8AerVsvHEqSBHwPVgcgVpyMyVXU3rXxcHYETAk + hru
/ D W t i 6 Z S T y O K z Z q n d H a x v v U G q 2 r Q + d Y y q R 2 4 q W I 8 d v b r 7 L q D x y D A z X p v w 6 F v I x e P G S M 0 6 X x o y r / A
zviKFHNegeX1J41zUhXioGbuaSuM6wpCaBHG / EcA6HN / exxXjXw2jL67cv8A3Qa6H8CFR + NnoWpO
I4XI44rxLxrqjQzSEsQM1gdSPM9U1uR1YbmWIdXHf2rmpIb67YS28UrRlsLI3c / jW0VZGUpO5pW1
jfLNOjahawzwReYI5cjzMkDavHJ5 / SrVv9uhtPtVxCPLBwzxnlT9KGghLU3tKvvPjHzbl7EGuisJ
GRxWLOg7nRXJEbDjmvSNK + aFSfSoZr0KutRkphc4NcRrdkVjL9aVio7Hk3iqS8ubhrWzUlsZY9kG
cZNc5D4aee5MclzJIFTzHAO0MfatqSOWu7bFS1srDUZEis0vIZoUxPvfcC + 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ToQFwzjJqaGTFyfK5PQViyzUuFmuIdgGABya5u / vTaN5cnUHFUmLoZ
zyskwlgJweSK6zQdUEwVJeGr0aUrxPLxEfe0OrhPAqVjxWhznGRtUwatDK4jNxURbmkAm6jNABup
6 tQAFqhupNtu59qUnZFwV5JHnWsHdIx96w5lz15rzT2uhRmt85xWbcxMnUGmZlB0bdxmrNvFIcfM
350 mWjbs7YkDJY / jW5ZWW4jikWkdNp9mqYJFaJdEHHakUULu / VB1rLn1Ld / FgetMGYd / qWSQmSa0
/ A e m S 3 2 p f a 7 p i L e L k g 9 z 6 U m Q t z 0 W 7 u Q 2 c Z x 0 A 9 B V z R 7 c A e a 6 j 2 r P q X 0 L 9 9 K R a t 5 A 6 D k 1 w O o K Z 5 2 a
YfMORTYRLujiGWEq6 / NWza2yKQVHNdOHerRy4laJo6TTnbbtb8KuM3Fdh5z3OJjbmpt3FaMxAtUZ
agBN1GaQBzTwaAAms3VbjERUGsa07RsdeFpuUuY4jUjljWTKK4j02RE4IpJYFk6imQkVl0xWarsO
mAEcUi0bNnZBR0rWtoguMCkUi21wI161mXuocEKaYXMS4u + pY / hVCSWSY4HT0pEmlouiSahdpEBl
mOceleiwWcNjClvHgJH97Hc1EmVFFi3Czy7mwIl / WtJbjP7uLgd / apQ2VNVvtsBhiPzdK5S4nAuR
nqOCaTGi9pcytPlU + XpmumtWII44rah8ZjiNIXRuWeNvvViQ / LXpJWPJbu7nCRvVkNxVsxBmqJmo
EPiXca0YLMuOlJsuKuPlsSi5IrNuG8s4HWs5VEkbwoOTKsk + FJY4rC1K53k1xTk5O7PSpwVNWRzt
4 cms + WpKICtSLTETQj5q0YeBSGiys23pUguGxQMq3E59ayrm4x3yaAKiRtO2WPHcmhruKFxFajzZ
ScA44qRHoXhuMaLpxaUg6hcDLMf4F9KlhuDeXGASIl + 8 azZslYma68y48m1 + 7 nFW5rtbRNhb5z1p
iMKbUg0zuW4A4rPgb7VdKXOMmpA7HRbMS7nUYiUda0lkQOBngVrS + JGdbWLRt2bAx5BqeQ / LXpnj
PQ4GJ + ashuK0MhWaoWcA0AaOmASMK7jRNPWYBmHyiuepO2x10qfcv6vYxCzYqoGK4HVYVTJrmb5l
c6oaM5TUJ8EgGsG4kLNUHT0M64OaqMMikSRsuKbnFMRLG3zVehOaGNE445NNlnVFpDMu6uie9Vo1
8 z5mOAOST2pDK91cNN + 5 tsrH3PrW54a06KxT7fdrlh / q1Pc + tJ6IUdZGvHPLezMcnBOWbsPap5r3
ylFtbdT1xUWNWzU0 / Zbwlgfmx8zGsHWtRHmMqE59aAMyNifvHPc1f0gtPdqkY5JosJHeNci2tktY
2021-01-13 17:14:23 +01:00
euPnNY + oXWZEVJNrZ9aun8SIq / CzodHuriIokhDIR1ronbKZr0o6o8ipoz //2Q==`,body=`
2020-12-11 16:11:49 +01:00
/ 9 j / 4 A A Q S k Z J R g A B A Q A A A Q A B A A D / 2 w B D A A s I C A o I B w s K C Q o N D A s N E R w S E Q 8 P E S I Z G h Q c K S Q r K i g k
JyctMkA3LTA9MCcnOEw5PUNFSElIKzZPVU5GVEBHSEX / 2 wBDAQwNDREPESESEiFFLicuRUVFRUVF
RUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUX / wAARCASwBLADASIA
AhEBAxEB / 8 QAGwABAAIDAQEAAAAAAAAAAAAAAAEDAgQFBgf / xABDEAEAAgECBAMECQIDBgUFAQAA
AQIDBBEFEiExE0FRBiJhcRQjMkJSgZGhsWLBJDNyFSVTY3OSNEPR4fAHFjWCokT / xAAYAQEAAwEA
AAAAAAAAAAAAAAAAAQIDBP / EACARAQEBAQADAQEBAQEBAAAAAAABAhEDITFBEjJRIhP / 2 gAMAwEA
AhEDEQA / APqYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAKNTq8OkxzfNkisQC8eb1XtRNbzXT4q7eU2nu0MntRq / D8StMccvW29Zmdvgj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VOXJPq1sl5Q
Vbkz9 + rRy35rxHqzmZlVEe / Ez5LRlW5iyfR6zffaIjq1OSNZps2a21rZInafSPJhxGMl9LStLRWM
lorM / A4dkrWbYfLZC2W / 7 K6eubX6b4RzT + W76K8b7G6X62cu3Sten59nsm3j + OXz3 / 0 ANGIAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0OIYfpOHPijvNNo + fdvtXJO18k /
/ O w P F Y b z 2 l s 3 j x 8 V q W 6 x M d W P E d P 9 D 4 l k x / d t 7 9 f l L L H b k x T P w Y 6 n t 2 5 1 2 O R T R z E 2 x 4 / d p E 7 c v k m e
E4IrW3hRMxO8THRtU1FKWtvtvK2upx22rzRCtXkqzh2jtF7ZbT122b01ndnpuWuP3Z3 + Ky20qDVv
fauzVy3mejZzNK8dVjqi87KLRLYtXruqvXzkQp7Qoid88R6rcl + WGlW0 / Sa22mfhCZOq2x082ix6
jkm822pO8VrPdr4dNObVeDo8XW3uzMbzK + mvxT7szE27cvnu9j7PcNjSaXx8mOIzZevbrEeic5tN
+ SZnpt8J4fHD9HXHO3PPW0x / DeBtJxx29vaAJQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAKNRim9Z5e89Nl4DzXtVh5babURHrSf7f3ec1 + qnDorWrvvt5Pccb0n0zhmWk
Rvevv1 + cPE2rGTFNZU26PFfxwa5dVkjelI2772nZnX6bbrEUq3o0d678u8wmuDL2ittvVjXdneeK
cGv4jpJ6U56 + kS7 + j118 + GLXpakzHaWlp9NNY3tv + bbiYiNoQy1y30uyZJlrWmZnuym6q1iIJnop
yW2Te8bdWnnypQqz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fFp4
ZxLBPgTGK8xzXr5fOH0bFlpmxVyY7Rato3iYfNuG2x56Wrqa8s2jz + 7 Lu8O12bS6jkwzN6THNNI6
tvrN68Y4rxlx1vHa0bskAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAA4XtTTm0OKfTJ / aXdcL2pyRGjwU362yb7fkJz9eTxxyZJjyltRXzUZK7TFtl9Lbwy06YzrHwa +
fJFd / wCVt8m0bQ0eS2qzcm + 1 K / an + zNZFL5M1pjFXeI72ky48eGnPkvNp27 + TPU6nHpMfLXaIjpE
erk5dRMxOfN1mPeisfshW1ne1a1577Y6x5R3U0zze31FOWI6ze0byU098kRlzbxM9qrMlPDpyRMR
Md5Vt / Ihp5898mWZm1pjftE91uCt7fCI7dWeHDEW3t723l6rslqxWZnasR + SYhFbzhnfxJ2jyeq9
lcGXWZcmW0zWKxHLaI7794eJx5fpfEKabT8t8l5isddo3l9S4VjrwrRUwzSJt3tav3pdOL6Y6dXD
j8HFWm + / K s U 4 N R X P v t W a z H q u W V A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAa + fXYNP9u8b + kdZBsDkZOO135cWOZn4y5Wu4xqctbe9y19Kp4njt6vi + PDm8DFMWybbzPlV
5 PiGtz67UxbNbeKTtWIjaIXYpnwuaftT5tXJT3vmi1pMsrU5qIrG1V1a + 5 DCa7b9GFbRr5J6Wnbt
Cu + Wmk0m8956z8ZWZNorbfzcbX5rZslazPux3hUt41NTntktObJ13 + zX1bek01r4 / HzVm0bxPXy /
+ bNfDgjVa2uOY92kdfg6ufJOKvLXtttVVSqbcta2vM7zXtHp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pjfrPRWZ9rXXptUit6zO + 23 VyaRHEc05L1 /
w9J9ys / en1ljqdVbwYw452tlnl3jyjzbmmiMeKtYjpEbLeTXPUU8ee / + qjJpsV5rbkrFqzE1tEbT
DpYNbW21Mnu29fKWna0KbqTdjXXjld0cvQ63ltGHNPSfs2n + HUbS9c2s2UASqAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAOVxPWe99HpP8ArmP4b + r1EabT3yT3iOkesvMVtN7za07zad5l
XV5GmM9vVfEstvDx0jtaVVMlq + UJ18b5cMRvPeSuK87bUt + i2Z3PtG7zXpjkzXt6R + TXyTMzvM7t
ydHqZ + zhv1 + Cv / ZuqvPTHMfOYaTMil1a1K2vHSLTELq2v + KWzThGo84rH5rq8JzedqR + ZeI7WnOS
34 pYTafWXR / 2 Pln / AMyrKOCWnvmiPyR6O1y9585lhWJvl557Q6eo4T4dYiMvW3b3UanhldHpJtGX
e09unmjsT7eb1l4trI2t0hsZfrdNO0bzy + nzU20 / + NmkzO9esz + TZxWis9dttvPv + Tn21jjaW8zn
26 bTG3mp1M / Wzv3t0jyWXiKZJmsTERaZhXXDbNl8WaztWenxZLstPp5pau8frDtVrNMM5cfTfpMf
3 aunxxbes9d / R09Dp8ebJi09ptFr3jtt2WyrW9wy1Jx132mK + Xq9PotT0iIU19ntLtExa3T47T + q
6 nBaYvsZstZ + cT / LeMnUi0TXffo1s2m8Ws2 / OIMWk5Jib5L328rS2t94Sh5TV4ppklpW6PT6rh + P
NbebTHyas8E081mZy5P2W6OFhjxNTE / hr / LoRO0Kvo9dPqctKzMxEx1la5t3tdnjnMs4noievcrO
yZjeFF1OSnNV0OG62cn1GWffj7Mz5w05joovzY7xes7TE7w0xrjPeex6Ua + j1UarBFu1o6Wj0lsN
3 JfQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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lxXNOPSZfhWWpwO85OFzv57qrODkzeHntSe8Sn6Rv0a3EZ218
8 nXekfr1a0ZLVnqx19dWb6demXybOO7lYMvNMdW9S / VVLo0us7tPHdtUtEwJiZU3jq2Jhham8CVG
PNODNTJXvWd3qcWSubFXJWd4tG8PK3pPd1OB6veLaa89Y61 / u2xfxh5c / rsgNHOAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAANLimq + i6O0xPv392rdeZ4rq / pOqnlnelOkIt5F8Z7Wj27I2I6sb25YY
V1ImY3dbQ08LRc23vZp2j5OJG + XJWle9p2h6HHtbJXFT7OOIpX + 7 TxT31j5rycdTh + Dpz + XaG / sw
w18PHWseULN2trBE9UcrJKBhFU7JAQi0dEomegNDUYovM7x3jb5tO1ZvpbaTLtzRExWfWPJ08kbT
Ex5NXWYYyV5omYtHWJieyeDzuizfRs19Jn6TM7Ru1uMcJxZqTkw + 5 f4ebqa7SV1MR4tdrx2vEfy1
axqsNOTLjnLXytVXi3Xj8 + nmsxTLM16d5npPyUzpekTtSK + U7vS6vQ / SYmK1vWPS1HOn2dvvvvE /
tDO5XlcO + LbfHSd / W3o6 / BdDOXPTnj3Kz38rS6Wm4FNrRyRzTH3p6RH / AKvR8L4dXSzE3jmtHn5I
mbfqLV + m4dbLSsZInHjr3iI6zLpYaxS01rHuxHRHiT9mv6s67Vj1aqL6326MrWiYa + / Q 5 4 B x P a G e
XRZpj8MquB4 + Xg8zPnB7SX30to379GxpK1xcHiKz5IS8xr8PLPixH2bftLTy05o6dHYyVjLhy0t1
izjZa3pMVv3iO / qz1G2L + NbSajbNyW7xLsY8kTDz + fJXFqKZN4iZnafi6WHL0iYlStI7OO + 7 axW2
crFl7dW9jvE9ULN + J3ZbdFGOy + AYWpEqN7afNXLj + 1 Wd23KrJVMvCzseh0 + auow1yU7WhY4fCdV4
OadPefcvPuz6S7jol649Tl4AJVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAV581NPhtkvO0R + 4 NPi2
r8DB4dJ9 + / 7 Q 8 3 P o 2 N T q L a n N b L f v P a P S F D H V 6 6 s Z 5 E T 0 h R k n y W 2 l T t M y o u z 0 c 8 u s x 2 n 7 s 7 v S c K w x
zc1vu / y85p + maJh6Th + SOWeveXR4 / wDLm8v + nX5mUWa9bbrInolmu5jdTNkxYFk2Isr3TuCzeGMz
+ THdEyDDJO9Ja823rt2XWnya946pGvktDXta0ztWu / ybvLE9dkcoOf4GbJPWK1j49VmLh9JtE33v
Mevb9G7WsW8l1ccREISophiJ2jpDYpijbaOjOuOJ8ujOdqxsgVcsUjaETYvbaFFrgu5lVsm0yUtu
ryg43H5m + GIj1XcJzePoL4pnrWGtxmfchr8JvfHS1622if3QljzTTLes + qrNjrkiYtCzPMxnm095
YZJ6boS5teB49Tqscza97VtvWvlv8V / FOF34RrIxTM2xXjelp / eHoeA6XnzReY3ivX / 0 dfivDcfE
9 HbDbaLx1pb0lOs + jO7K8Lis3cN + 0 NKcd9PmthzV5clJ2mF9J9GHHVL108dm1SznYr / Ft0tuhLb8
mNohFbMhLWy0mJ3rPXvDvcO1karBG8 / WV6Wj + 7 kWrvDDBlvpdRGSnbzj1hpjX4z8mOx6UYYstc2O
uSk71tG7Ns5AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACZ2jeXneJ62dVl5KT9VTt8Z9W9xbWclPo + O
fft9qfSHEU1pv48ftYST23ZTDC / p0YtlVuvVjMbM5 + LCZjYGWGdrTPxiHY4ffaf3cjTxz1v6xMS6
Olty2iXVj / Dk8n + ndrkhnGRo1v8AFdW3RCrZ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kW + zvA / D21urr789cdZ8vi9KDb45rejl8Rry6iJ / FV1HP4vXbBTJEfYt1
+ UpiHM295bXsqrO9l8QkZ0lZEqqLeyBZHZLGvZkhIndADKJ3TMoqWQMZ6pjsxll2jsCLSrmU2lFY
36 gieyu0LJk3jbsga0wdqzK20QpyztQGprL / AFMrOE05NLkt6qdVWZxNrSe5o9vWBLiUjnzXn0vL
q555dHt8HOwV928 / 1 z / LpzXxbYccRvzTB + jucOwxh0dI22mY3ltIrHLWIjyjZKyoAAAAACJiJjaY
3 iXleM8InR5J1GniZw2n3oj7s / 8 Ao9Wi9a3rNbRE1mNpifNFnVs65XhcWTdt47bnFuF24dm8TFEz
p7T0 / pn0a + HJux1OOrOux08d1ndqY7tillVkzExLOk7yd4YxGwluViJhE45raL0na0dtlWO0 + bZr
1 TKi + 2 zptZGTamT3b / tLacvJjiY3XaTWdYxZZ6 / dtPm1zrv1z78fPcbwC7EAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABhkyV
xUm152iAZWtFazNp2iGhm1Vss8uP3aevnKrNntqLdelI7VRHRnrX / HRjx / tZREVjZXeybW6KbWZt
pCZ6S08tN7Nmbb7zCrJtyoS5145bSx5mWafelr3tsKmS / o08uXyhlly7RPV2 + AcBnPNdZrK + 53 pS
fP4ytnPVda4y4BwHxOXV6uvu96Unz + MvVxG0bQRG0bR2G0nHLb2gCUDX12LxtFmpHeazt82wT1gH
mMN4tWs + rcr2aEV8DU5sM / cvO3yb + O0csLUTSdrLphRE8tlkZI7Atr2ZMazDJVKTYSCawi7Ksq7z
1 QERvLK3ZGPrKbyCrbdnMcsbeaa18 / RhvvM7oGEwTG0JmYYTIML22a2e28xELM19oURPNO4lOem +
n3ZY5 + prVnMc2GYU4 / L4A0a15cNf6rz / AC6fC6 + NxCPOuOu / 5 tHJTbHj + F5 / l1 + BYumXJMd9o3 / d
MRXYASgAAAA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AAAA
AAAAAAAAAAAAAAAAAAAAAAo1Oprgr63ntAmTqdRqK4K9etp7Q5d7Wy2m953lNrWyWm953mVd77R0
Za1104xxlN9lV8qnJl2a9s3xUXX2ybsJyRDWtl3YWydEC + 2 VRkzeW6q + T4tbJm + KRdfK1cmWZnlr
vNp7RC / R6HU8SycmCk7ed57Q9ZwvgOn4fEXtHi5 / O9o7fJaZ6z1uRyOEezVstq6jiEbV71xevzer
rWtKxWsRFY6REeSRrJxz22gCUAAAAAANbX6aNVpL0npMRvWfSXlKamsRMVvXm + EvZXjmpaPWHzfL
oNRjzXicfWJ8phfPxFejx72x7xMzK + sXiNoiXlq + Pi6fWV / VfTNqfLJl / WTg9Pji8R70LqvMV1Gq
j / zcv6yz + lanzzZP1lWpelTET6S81Gp1P / Gyf90s412rjtnyfqql6asREdWM9 + jz9eJ6yP8Az7uh
odZqMt458tpB1JvEViI3 / RhzRt13 / R1MNaziiZiJn5K9ZNceKZiIiQcu / WekT + iYrWI3lzdTrs + 8
8 uW0fJzcur1Np / zsn6g79phVaIeetqNR / wAXJ / 3 SwnUaj / i5P + 6 UD0ldonum161h5mNRqP8Ai5P1
lNtRqJjacuT9Qd22WN5aGeZyZd / KHJy59RHbLf8AVq31Gp / 4 uT9ZEvS8Lr / vSs2npzRtL1z53wK +
oza / HW2XJNd99pmX0Rb8VAAAAAAAAAAAAAAcHj / C5yV + l4I9 + v24jzj1cLFk8nu5jeNpeW41wmdL
knU6ev1Vp96sfdn / ANFdTrXG + eq1q5F2LLtbZoY8m8d11bbSydErsYsm + zZrO / zcnBm226uhiyRK
EtrvCrJDOJTeu8A1MWX6Lqq5N / dnpb5O5ExMbx2cPNTeJb / DM / iYPDtPvY + nzhri / jDy5 / W6AuwA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAa2p1UYo5adbz + xbxMlvqJ1OqjDHLXree0ejmzNrWm953tPmTPWbWneZ7yoy5YhjrXXTjH8s75N
mtkyxt0VZM2 / m175N1V03yTKubMLXVXybeYLLX2VXy7eam + b0bOg4VquJW + rry4 / O9uyZOq3UjVm
9 r25axMzPaIdvhns1kzbZddM0p5Y47z8 / R2 + HcF03Doi1a8 + Xzvbv + TotJnjDXkt + K8ODHp8cY8N
IpSO0RCwF2YAAAAAAAAACvUZYw6fJkntWN3k8dfHz2vLucdz8mkjFE9bz1 + UOZosX1UzPm0nqI / W
MYo9FlcPNklfFGeH / NshLGun + Cz6PtHZtVZWlRLS + jxPkRpIn7rdoupHTdA5s6SI + 7 H6Mfo + 32 Y2
+ To3neSIiZ7A0IjPXpXLePlMotGW3272t85datKzHZjbTVnsDj + FG / 2 Y / RlGP4R + jo20u7H6N1Ql
o + H8I / REY957R + jpfReiK6eOYHLtj2tttH6KrY / 6 Y / R2c + kjeJiFVtLG24hxpw7 / AHY / RRkw9O37
O99Hrt1YX0tfOBLjcGp4XF8c + u8fs9c4dcVcGemSI61nd3IneN1orQAAAAAAAAAAAAABFqxes1tE
TE9JiUgPKcX4RbRXnNgiZwWnrH4XPi28PdXpW9JraImsxtMS8pxXhF9DecuGJtgmf + 1 TWW2N / la1
L7N7T5e3Vy6W3hsYcvLbqzbO9jvvCzvDR0 + XeO7crO6FmGSvRThy / RtVXJ92elvk2rRvDUzU7pl4
izsd2J3jeBpcNz + Lg5LT7 + Pp + Xk3W7js5eAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADs0NTrN96Yp6edkW8Wzm6 + LNTq4pvTHO9vOfRoWtt
1 mes95YWvs1s2fZldddOczLPLn2ju0MmebT3YZc2 / mpm3qqllN1drsbZIhr3yzvtHf4AsvlYYseb
V5Yx4KTe0 + UQ6nDvZ3UazbJqd8OKeu33peq0eh0 + hxcmnxxWPOfOfm0mP + steT / ji8N9mKY9suum
L37 + HHaPm9DSlaVitKxWsdohI0Y22gAgAAAAA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5K71tG0vHa / RX0GpmlutJ61t6wrY2xr8dXS5uesN + tt4ef0eaa223
2 dnHk3juyreM81OaFGiy / RtZET9jJ7s / 2 bdutd2jqKeic3iNTsd8a2h1H0jTVtP2o6W + bZbOO + gA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABje9cdJt
adohGTLXFTmvO0fy52bJfU23t0pHaqLeL5xdK9Rnvqb + cUjtCi94xxvK3JetKuHrdZvaa1ljb10y
cnIs1Wt3naJc ++ TmVWvMz1YWybfMGdsm3eWek0mo4jm8PT0mfW3lDf4V7P5tdMZdRviwfvZ6 / TaX
DpMMYsFIpWPTzXmf + steT8jn8L4Dp + HxF77Zc / 4 pjpHydYGjC3oAAAAAAAAAAAAAAAAADG9opS1p
7 RG7zszN6WtPe0zLua + 3 Joss / wBOzhzG2OsL5 + IrY09dsSyYRijbHEMvOChb7KjF0yS2LQ169Mso
S24noyrPVXWejNVKbTuw3T3REdQWU6LYlVvsyiUDPfqupPRr79VuOQX1lZEqoZxIMksd0gT2VT0l
bPZVbuCaW8i8bwr32WxbcGnkjaZa9p2ndv5qbw5 + aNugLItF6TEtvTX5sMb969HMpfazc0d9stqe
vVZDdAQAAAAAAAAAAAAAAAADV1 + iprtPOO / 2 u9bektoB4TJTJpNRbHkja1Z6uto8viVht + 0 HDvpG
H6Tjj6zHHvbecONw7Ltfkmeqmo6Ma69DXbbZTkr1mGWO3RneOaGbZRoM30fVzSelMnT83aef1FZ7
x3h1tBqfpGnjmn369LNc3sc3kzy9bQCzIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAa + q1dNNXr7157VhGp1Xh70x + 9 f9ocy283m1p5rz3mVbrjXHjt91lz
5 c9 + fJ1nyjyhdM8lZlOOIiqrUXikd + kMreunnI5XEdX4dZiZcG + XmtNl / F83PeeWWHDOGanieSKY
q + 5 H2rz2hMzWd1Iqx1yajJXHhrNrW6REeb1nCPZumn2z62Ivl7xTyr / 6 uhwzhGn4Zj2xxzZJ + 1 kn
vLoNJnjHW7TbbsAszAAAAAAAAAAAAAAAAAAAAaPFrbaSK / itEOXt0rDf4xb / ACa / GZacRvaF58Q2
IjasQnzPIhCU92tMbZGzHmotG10C6nZkwpPRmipIllEbMIZIE7solgmJBnCyk9VMM6z1BtVllEqK
z0WRILYlluriWcSDJVbusV27gwInaSWM9ECyZ3hqamnSWxFmOSOaqRx725bNnSZNs9J + OynVY + WZ
YYr7TE + nVaIr0Ais81Yn1hKAAAAAAAAAAAAAAAAAABExvG09peU4nov9n66L0j6q / WPg9Y1OJaON
ZpL0 + 9 HWs / EWzeVz9PbmrEtnyc3h9reHy26TWdnSr2YX6657ijLXpLX0 + onSamL / AHJ6W + Tbv2aW
ekTv16JzeI1Ox6KJiYiY7Slz + E6jxdN4dp3vj6fl5Og2clnKACAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACZ2jeQRMxEbzO0Q08uqtkma4ulfO3r8lefUePMxWf
cjy9WvlzVxV6T1Z61 / x0Y8f7Wc7Ur1lqVy + LqOWJ2hp6rXddon5rOF1tfmz5OkT0qzb8dWbxjp1c
biuuilJ5Z6r + IcQrixzEy8zl1E6rNt1tMztFY81sztU1eRucN4ffi2p5esRM72n0h7rS6XFo8FcO
CkVpX082nwXh3 + z9FWLxHi36328vg6TZyW9ABAAAAAAAAAAAAAAAAAAAAAADj8Unm1tK / hqppHvw
y1k8 / EMk + m0GOPeafiFpCZYwolnXspvHvLa9mF46gmnZmwozRUiUCBKYYsoBLOFbKAX0llEqqyzi
QXRLOJVRLOOwLIljZMEgrlhKyYYTAK5nZPN0RZjugUanHzVlz6xtLq361c + 9 eXItPpXX0dubTU + E
bL2lw2 ++ O1fSW6m / VYAISAAAAAAAAAAAAAAAAAp1GbwcfTreelYEydcuMcRrM / L9nnlsV6wqpi2r
tv133mfWVk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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAETETG0xukB4HVaeMHEtRi26RedvkyjBSfX9W77QYvC4xz7dMlYlrU7M929dWJLFc6aPK0q
7 YLxPS0S22FlP6q38Zac0yR92s / KVc3tHfFf8tpbcsLRvB / dR / 8 ALLVnU0r9uL1 + dZI1mnmdvGpv
6 TOy6ym + Oto2tWJ + cJ / tW + KLK5KW + zes / KU7tG + h01p64qx8Y6NXNo6Y + uPJlp8rLf0rfG7MXtHa
0x8 pZxqs9e2a8f8A7Oj7HaTHn0 + f6RWM23LETfr6vRW4PoL99NT8ui7F4 + vEdXXtnt + fVbXjGsr /
AOZE / OsPS29nuH27YrV + VpeV9pdPXhOtw49NG9Mld55 + vXcTPd42I47qo7xSfyWV9oM8d8VJ / VxM
d8l46xWF9cV7en6o / qLfxp2I9ob + eCv / AHMo9op89P8A / wBORGmyT5R + qfo2X8P7n9Q / jTsx7RR5
6 ef + 4 / 8 AuHftg / 8 A6cWcOSO9J / WEbWr3pY7Efzp2Lcfv5YK / 9 zWy8d1E / ZpSv5Oba1 / + Hb9lc + LP
bFt87I7E / wAabWbiurvEx4nL / pjZzc2bJkn372t85ZXx55 / BX85lucC0vPxnTxlnnjm32mOiZqUu
LJ2p4TwnVavNWaYbRTfre0bQ99pcH0bT0xb78vmtiIiNojaErMwAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAHnfarF7umzRHaZrLjYrdIen9ocPi8JyTt1xzF4eUw23rCm3R4r6bMy
wt6kdTaWLdjswmNoZontsCm0K5XWjopnuDC0dGpqG5bs08 / daKV672MjbSaif6oh6Z5f2LtvptRX
0 tEvUN3Jfo8f7cYve0eX4zV7B5z20xc / C8eSPuZIRficfXlcPaG7ino08HWI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Ta3Ph / BeYj5PoTxftFg8Hjk2iOmWkW / Psrr418V5WrWd2faFc
V2jdnEMXWxntupmN7NiYU27iWML6dVMVnddjgVqMsdHr + CW5uE6f4Rt + 7 yuSsTDv + zWXn0WTHP3L
/ t K + G H l + O 0 A 1 c 4 A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8Dn93W56 / wDM
t / L3z59qp24jn + OS38lnpr4r7ZxHQ2TEstt3PXUrt27K57rr1VT0BjKnJPRbMqMs7QlV2fYvHvrd
VknyrEfu9m8f7FZI8fVU85iJewbT45NfQBKo817W4eulzxHaZrL0rje09ItwqbfhtBVs3leai8RD
KLw1sduesL606dWFdsZT1jdhNeq6K9DlhCVUU6s4jZnt1YzAhnM71dH2bycmszY / K1d / 0 c6OzY4R
fwuK4p8rTstn6z8k7HrwGzkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHz3
Vxvr80 / 8 y38voTwGpj / F5 / 8 AqT / JfjTx / WVeyY6FPspc9dZPVXaOq2WEwIUTVRmjo2rNfLHRI3vZ
DJycXtX8dZh7t879nsnhcbwz23tt + r6I2nxyb + gCVBzuPY / E4PqI9K7ui19fTxNBnp60n + Aj5 / pJ
3 jZu1aOnnltMNussdfXbm + l3ZM9URHREdZVXTuT1Nk7boQiOkJw28PU47 / htEp5eivJPLMTCZ9Vv
x7mJ3iJ9UqNHk8XR4b + tIXuhxAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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v50c6nml
HMC / nOf4qOY5wX85zqOc5wbHOc7X5znBsc6edr85zg2ec52vzpi4NjmY5bROG + / b l l V z s N T k 5 d L l
n0pP8BHmMHWNmzt0aum8obm08vVjfrtnxztR0mXHzTvaZdjVRMTLkZo6yiFen9iZ2pqY / wBP93rN
3 kPY + / L f P X 1 r E / u 9 X z N 3 H f q z d O 6 v m T u I Z 7 m 7 H c 3 B n u 8 t 7 T R / v H B P 9 E / y 9 P u 8 3 7 S V 3 1 u m n + i f 5 R f i
/ j / 0 1 M M b 1 h j k r t K z B G 0 b M s m O Z Y 1 1 t O Y a m r 6 U n d 0 L U c 7 X T 7 u 3 r J P q L 8 e r 9 l c P h c F p b z y W m 3 9 v 7 O 0 0
+ FYvA4Zpsc94xxu227jv1IAgAAAAAAAAABKAAAASgASgBIgBIgBIgBIhIAAAAAAAAAAAAAAAAAAC
UACUJAAAAAAAAAAAABIAAAAAAAAAAAAAAAAAAAAg3AEbomQZbo3YzLGbAz3RNlc3YzcFs2YzdVN2
M2Bdzom6nmNwW86JurTAMuY3REJ2BB1ZRVMVBhsbSsiqeUFXLucq3lTygp5TlXcpygp5TlXcpygp
5 TlXcqOUFXKjlXcrGYBXysdlswiYBVMdUTCyY6sZBWxlnMMZgGLGZZSwkDdHMiWO4MuY5mEyjcFn
N1OdVzHMC3nTzqeY5gX85zqOZPMC + Lqdbk20eb / RKOZr8QybaK / XvtH7iZ9aGlp2luzT3fg19NHS
OjbmPcYX67XH1XSZ9XIzRvMuzrK7zLkZYmYnciunb9lZ5dTk + OP + 71 cXeP8AZnJ / ip2nf3J / l6iL
/ F u 5 L 9 b M W Z c z X i 6 Y u I b E W T z K I u y i w L t 3 n u O 2 5 u I 4 a / h x 7 / r L u c z g 8 T i c v F L b f d p E K 6 + N P H / p h h j o
stLGkctUWnoxrrU3j1cnWTzZq1jzl1clo5Zcu8c + txR63iP3Tn6pv4 + g4o5cVI9IiGe7CJ2iE7t3
GyN2O6dwSINwSISAlAAlACRAAlAAlACR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QPSW8KX2mas + NC2iv6xMNfJpMnLtEbuuxtMRCtzF55NR5rPps1N / ctP
y6uHreE6nXZ4pak48X3rT06fB7fNeI33cbX6mI32R / MWu7XF116aDSRhxbRERs8f499bkyZeeKae
kzE2mdon81 / tfxDLGOunwbzlzbx08oaHBvZHJlx48mrvaa94pu04y617576rNGLRRM0397JEd / lu
9 Dw / S3x4qxffo6mm4NjwUiKY4iI9Ib1dHFY6QIaNabbrYrLfrpJtaK1rMzPZb / s + 05 IpP59OyLeJ
k7eNfRaOc1ue32I7fGXYpi5Y77M8OGMeOKxHSFsU3Y29deZMzirl6dlVvhLatCjJHeYQv1rXnps1
8 k9 / VsW6qLVmZIi1rzitlvFKRvaZ2h6TSaenC9FFY + 3 brM + sqeG8Prp4 + kZ + lvuxPkr1mqm95nfp
DXM459676a2q1dsV7XietvNno78 + CJn1cjX6mOeIm0bR33dfRU5NJjidt9t5afjG / V6JZ7I2QMNh
nyo2BhsMuVG3wAhMSbbQRAMolnE + iuGUSCyJZRKuGUSCyJZK4llEgyZMYTuCUsYSCQASISAAAlCQ
AAAAAAEoASCASAAAAAAAAAAAAlACRACQAAAAAAAAAEgCEoASCAAAAAAAAAAAAAAAAAAAAAAABAAA
AAAAAAAISAIAAAAAAQAAACASgAAAQJAQAAhIDHZhln3do7z0WS18mWsajHjmes7pg3dNi5aRMNqO
yvDHTpPRaigHZhN4hHRlaVN59JY3zRENLUavaO + yq0iNVlitJ6vNcR1MVi0zO0era1 / Ea0rPvbz5
PM5MWp45qvo2GZrhmfrsnpHpHzTCseEcM / 2 vrr8Q1Eb4qzy44nziPN63HpYiIiI7LNHoqabBTFii
IpSNohuVxrKtWMEejPwY9G1FFmHB4mWJn7MdfnIM9JpIx15to5pbUaas / a6rqViI7MxPxqX0UT1r
O3wVzpbR2hviP5i03Y5s6a879FNtHljydhExCv8AMTPJXBnRZbz0iG5ptFjwe / l96zctMVamTJtE
yTMibu1VrdTzRMR0j0ed4lr64MVpm0RERvMz5NvX62uOJ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lNmWwCNjZICNhIDmcZredBecdpiY69FXCOLW + i
UiZidukulmxxlx2paN4mNng + K4 + I8Hy2yaTfl37TXetoCPfRxfp1qi3F48ofKMvtvxak8s6LDv61
rZji9rPaLUf5PC + bfttS0q8q3p9W / wBrRMdpUZuKdN99nzvFqPbTVz7nD8OKs + do2 / mW3h4D7Xaq
ZnPrtNpqz35aRaYOHY9Zk4pNt9rR + rl6zi + OnS + WN57Rv1lXp / YrNaYtruL6zNPnGO3hxP6O5w / 2
f0HDuun09Yv55Le9afznqcOvO4tBreMTHu30unnva0bWt8on + 70 nDuE4OHYYx4Kbesz3tPrMuhGO
IjpDOKrK9YVpsyiGUQnYGOyUgI2SlAIEmwMWMs9kTAMJYzDOYRMArmGErZhhMArlHmzmGMwDE3Ts
bAbs4swj5pgFkSziVcM4BZEsolXDKAZwyhjCYBkACQhIAAAAAAAJAAAAAAAAAAAAAAAAAAAShIAA
AAAAAAJAAAAAAAAAAAAAABAJEAAAAAAAAAAAAAAAIEoBKAAAAAAAAAAAAAAABAlAAAAAAAIAAAAA
BAkBAkBAkBAlACEgMZjdjbFW8bWrEx8YWANb6Fp + bfwab + vLDKMFK9qxH5L0bAr8OPRPKz2AY7J2
SbAjYZAI2E7AIEgIEgIEgMdkSy2NgY7MdlmyNoBXsxmFuyNgVTVjNV3KjlBRNTlXTVHKCrlIqt5T
lBhEMohlFerLlBjEMohMVTEARDKCITsAk2AEgAAAkAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAD /
2021-01-13 17:14:23 +01:00
2 Q == ` ;var version14="0.9.25";var now2=()=>typeof performance!="undefined"?performance.now():parseInt(Number(process.hrtime.bigint())/1e3/1e3);function mergeDeep(...objects){let isObject=obj=>obj&&typeof obj=="object";return objects.reduce((prev,obj)=>(Object.keys(obj||{}).forEach(key=>{let pVal=prev[key],oVal=obj[key];Array.isArray(pVal)&&Array.isArray(oVal)?prev[key]=pVal.concat(...oVal):isObject(pVal)&&isObject(oVal)?prev[key]=mergeDeep(pVal,oVal):prev[key]=oVal}),prev),{})}var Human=class{constructor(userConfig={}){this.tf=tfjs_esm_exports,this.version=version14,this.config=mergeDeep(config_default,userConfig),this.fx=null,this.state="idle",this.numTensors=0,this.analyzeMemoryLeaks=!1,this.checkSanity=!1,this.firstRun=!0,this.perf={},this.models={facemesh:null,posenet:null,handpose:null,iris:null,age:null,gender:null,emotion:null},this.facemesh=facemesh,this.age=age,this.gender=gender,this.emotion=emotion,this.body=posenet,this.hand=handpose}profile(){return this.config.profile?profile2.data:{}}analyze(...msg){if(!this.analyzeMemoryLeaks)return;let current=engine().state.numTensors,previous=this.numTensors;this.numTensors=current;let leaked=current-previous;leaked!==0&&log(...msg,leaked)}sanity(input2){if(!this.checkSanity)return null;if(!input2)return"input is not defined";if(ENV.flags.IS_NODE&&!(input2 instanceof Tensor))return"input must be a tensor";try{getBackend()}catch(e){return"backend not loaded"}return null}simmilarity(embedding1,embedding22){return this.config.face.embedding.enabled?embedding2.simmilarity(embedding1,embedding22):0}async load(userConfig){this.state="load";let timeStamp=now2();userConfig&&(this.config=mergeDeep(this.config,userConfig)),this.firstRun&&(log( ` version : $ { this . version } TensorFlow / JS version : $ { version6 } ` ),await this.checkBackend(!0),ENV.flags.IS_BROWSER&&(log("configuration:",this.config),log("tf flags:",ENV.flags))),this.config.async?[this.models.facemesh,this.models.age,this.models.gender,this.models.emotion,this.models.embedding,this.models.posenet,this.models.handpose]=await Promise.all([this.models.facemesh||(this.config.face.enabled?facemesh.load(this.config):null),this.models.age||(this.config.face.enabled&&this.config.face.age.enabled?age.load(this.config):null),this.models.gender||(this.config.face.enabled&&this.config.face.gender.enabled?gender.load(this.config):null),this.models.emotion||(this.config.face.enabled&&this.config.face.emotion.enabled?emotion.load(this.config):null),this.models.embedding||(this.config.face.enabled&&this.config.face.embedding.enabled?embedding2.load(this.config):null),this.models.posenet||(this.config.body.enabled?posenet.load(this.config):null),this.models.handpose||(this.config.hand.enabled?handpose.load(this.config):null)]):(this.config.face.enabled&&!this.models.facemesh&&(this.models.facemesh=await facemesh.load(this.config)),this.config.face.enabled&&this.config.face.age.enabled&&!this.models.age&&(this.models.age=await age.load(this.config)),this.config.face.enabled&&this.config.face.gender.enabled&&!this.models.gender&&(this.models.gender=await gender.load(this.config)),this.config.face.enabled&&this.config.face.emotion.enabled&&!this.models.emotion&&(this.models.emotion=await emotion.load(this.config)),this.config.face.enabled&&this.config.face.embedding.enabled&&!this.models.embedding&&(this.models.embedding=await embedding2.load(this.config)),this.config.body.enabled&&!this.models.posenet&&(this.models.posenet=await posenet.load(this.config)),this.config.hand.enabled&&!this.models.handpose&&(this.models.handpose=await handpose.load(this.config))),this.firstRun&&(log("tf engine state:",engine().state.numBytes,"bytes",engine().state.numTensors,"tensors"),this.firstRun=!1);let current=Math.trunc(now2()-timeStamp);current>(this.perf.load||0)&&(this.perf.load=current)}async checkBackend(force){if(this.config.backend&&this.config.backend!==""&&force||getBackend()!==this.config.backend){let timeStamp=now2();this.state="backend",log("setting backend:",this.config.backend),this.config.backend==="wasm"&&(log("settings wasm path:",this.confi
2020-11-08 18:32:31 +01:00
/ * *
* @ license
2020-11-16 21:51:46 +01:00
* Copyright 2017 Google LLC . All Rights Reserved .
2020-11-08 18:32:31 +01:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2020-11-16 21:51:46 +01:00
* Copyright 2018 Google LLC
2020-11-10 02:13:38 +01:00
*
2020-11-16 21:51:46 +01:00
* Use of this source code is governed by an MIT - style
* license that can be found in the LICENSE file or at
* https : //opensource.org/licenses/MIT.
2020-11-08 18:32:31 +01:00
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2020-11-16 21:51:46 +01:00
* Copyright 2018 Google LLC . All Rights Reserved .
2020-11-08 18:32:31 +01:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
2020-11-16 21:51:46 +01:00
*
2020-11-08 18:32:31 +01:00
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2020-11-16 21:51:46 +01:00
* Copyright 2018 Google LLC . All Rights Reserved .
2020-11-08 18:32:31 +01:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2020-11-16 21:51:46 +01:00
* Copyright 2019 Google LLC
2020-11-08 18:32:31 +01:00
*
2020-11-16 21:51:46 +01:00
* Use of this source code is governed by an MIT - style
* license that can be found in the LICENSE file or at
* https : //opensource.org/licenses/MIT.
2020-11-08 18:32:31 +01:00
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
* Copyright 2019 Google LLC . All Rights Reserved .
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
*
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2020-11-16 21:51:46 +01:00
* Copyright 2019 Google LLC . All Rights Reserved .
2020-11-08 18:32:31 +01:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2020-11-16 21:51:46 +01:00
* Copyright 2020 Google Inc . All Rights Reserved .
2020-11-08 18:32:31 +01:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2020-11-16 21:51:46 +01:00
* Copyright 2020 Google LLC
2020-11-10 02:13:38 +01:00
*
2020-11-16 21:51:46 +01:00
* Use of this source code is governed by an MIT - style
* license that can be found in the LICENSE file or at
* https : //opensource.org/licenses/MIT.
2020-11-08 18:32:31 +01:00
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
* Copyright 2020 Google LLC . All Rights Reserved .
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
* Copyright 2020 Google LLC . All Rights Reserved .
2020-11-16 21:51:46 +01:00
* Licensed under the Apache License , Version 2.0 ( the License ) ;
2020-11-08 18:32:31 +01:00
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
2020-11-16 21:51:46 +01:00
* http : //www.apache.org/licenses/LICENSE-2.0
2020-11-08 18:32:31 +01:00
*
* Unless required by applicable law or agreed to in writing , software
2020-11-16 21:51:46 +01:00
* distributed under the License is distributed on an AS IS BASIS ,
2020-11-08 18:32:31 +01:00
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
2021-01-11 15:02:02 +01:00
/ * *
* @ license
* Copyright 2021 Google LLC . All Rights Reserved .
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
2020-11-16 21:51:46 +01:00
/** @license See the LICENSE file. */
2020-10-12 01:22:43 +02:00
//# sourceMappingURL=human.esm.js.map