2020-11-07 17:25:03 +01:00
var ff = Object . defineProperty , tg = N => ff ( N , "__esModule" , { value : ! 0 } ) , Or = ( N , i ) => ( ) => ( i || ( i = { exports : { } } , N ( i . exports , i ) ) , i . exports ) , Zh = ( N , i ) => { tg ( N ) ; for ( var we in i ) ff ( N , we , { get : i [ we ] , enumerable : ! 0 } ) } , rg = Or ( ( ) => { } ) , ng = Or ( ( ) => { } ) , Bp = Or ( ( ) => { } ) , ml = Or ( N => { "use strict" ; Object . defineProperty ( N , "__esModule" , { value : ! 0 } ) ; var i = function ( t , e ) { return i = Object . setPrototypeOf || { _ _proto _ _ : [ ] } instanceof Array && function ( n , a ) { n . _ _proto _ _ = a } || function ( n , a ) { for ( var c in a ) a . hasOwnProperty ( c ) && ( n [ c ] = a [ c ] ) } , i ( t , e ) } ; function we ( t , e ) { i ( t , e ) ; function n ( ) { this . constructor = t } t . prototype = e === null ? Object . create ( e ) : ( n . prototype = e . prototype , new n ) } function M ( t , e , n , a ) { return new ( n || ( n = Promise ) ) ( function ( c , d ) { function y ( C ) { try { _ ( a . next ( C ) ) } catch ( F ) { d ( F ) } } function v ( C ) { try { _ ( a . throw ( C ) ) } catch ( F ) { d ( F ) } } function _ ( C ) { C . done ? c ( C . value ) : new n ( function ( F ) { F ( C . value ) } ) . then ( y , v ) } _ ( ( a = a . apply ( t , e || [ ] ) ) . next ( ) ) } ) } function V ( t , e ) { var n = { label : 0 , sent : function ( ) { if ( d [ 0 ] & 1 ) throw d [ 1 ] ; return d [ 1 ] } , trys : [ ] , ops : [ ] } , a , c , d , y ; return y = { next : v ( 0 ) , throw : v ( 1 ) , return : v ( 2 ) } , typeof Symbol == "function" && ( y [ Symbol . iterator ] = function ( ) { return this } ) , y ; function v ( C ) { return function ( F ) { return _ ( [ C , F ] ) } } function _ ( C ) { if ( a ) throw new TypeError ( "Generator is already executing." ) ; for ( ; n ; ) try { if ( a = 1 , c && ( d = C [ 0 ] & 2 ? c . return : C [ 0 ] ? c . throw || ( ( d = c . return ) && d . call ( c ) , 0 ) : c . next ) && ! ( d = d . call ( c , C [ 1 ] ) ) . done ) return d ; ( c = 0 , d ) && ( C = [ C [ 0 ] & 2 , d . value ] ) ; switch ( C [ 0 ] ) { case 0 : case 1 : d = C ; break ; case 4 : return n . label ++ , { value : C [ 1 ] , done : ! 1 } ; case 5 : n . label ++ , c = C [ 1 ] , C = [ 0 ] ; continue ; case 7 : C = n . ops . pop ( ) , n . trys . pop ( ) ; continue ; default : if ( ! ( d = n . trys , d = d . length > 0 && d [ d . length - 1 ] ) && ( C [ 0 ] === 6 || C [ 0 ] === 2 ) ) { n = 0 ; continue } if ( C [ 0 ] === 3 && ( ! d || C [ 1 ] > d [ 0 ] && C [ 1 ] < d [ 3 ] ) ) { n . label = C [ 1 ] ; break } if ( C [ 0 ] === 6 && n . label < d [ 1 ] ) { n . label = d [ 1 ] , d = C ; break } if ( d && n . label < d [ 2 ] ) { n . label = d [ 2 ] , n . ops . push ( C ) ; break } d [ 2 ] && n . ops . pop ( ) , n . trys . pop ( ) ; continue } C = e . call ( t , n ) } catch ( F ) { C = [ 6 , F ] , c = 0 } finally { a = d = 0 } if ( C [ 0 ] & 5 ) throw C [ 1 ] ; return { value : C [ 0 ] ? C [ 1 ] : void 0 , done : ! 0 } } } var oe = 1e-7 , de = 1e-4 , X = function ( ) { function t ( e , n ) { this . backend = e , this . dataMover = n , this . data = new WeakMap , this . dataIdsCount = 0 } return t . prototype . get = function ( e ) { return this . data . has ( e ) || this . dataMover . moveData ( this . backend , e ) , this . data . get ( e ) } , t . prototype . set = function ( e , n ) { this . dataIdsCount ++ , this . data . set ( e , n ) } , t . prototype . has = function ( e ) { return this . data . has ( e ) } , t . prototype . delete = function ( e ) { return this . dataIdsCount -- , this . data . delete ( e ) } , t . prototype . numDataIds = function ( ) { return this . dataIdsCount } , t } ( ) , Te = function ( ) { function t ( ) { } return t . prototype . time = function ( e ) { return z ( "time" ) } , t . prototype . read = function ( e ) { return z ( "read" ) } , t . prototype . readSync = function ( e ) { return z ( "readSync" ) } , t . prototype . numDataIds = function ( ) { return z ( "numDataIds" ) } , t . prototype . disposeData = function ( e ) { return z ( "disposeData" ) } , t . prototype . write = function ( e , n , a ) { return z ( "write" ) } , t . prototype . move = function ( e , n , a , c ) { return z ( "move" ) } , t . prototype . memory = function ( ) { return z ( "memory" ) } , t . prototype . floatPrecision = function ( ) { return z ( "floatPrecision" ) } , t . prototype . epsilon = function ( ) { return this . floatPrecision ( ) === 32 ? oe : de } , t . prototype . batchMatMul = function ( e , n , a , c ) { return z ( "batchMatMul" ) } , t . prototype . fusedBatchMatMul = function ( e ) { var n = e . a , a = e . b , c = e . transposeA , d = e . transposeB , y = e . bias , v = e . activation , _ = e . preluActivationWeights ; return z ( "fusedBatchMatMul" ) } , t . prototype . slice = function ( e , n , a ) { return z ( "slice" ) } , t . prototype . stridedSlice = function ( e , n , a , c ) { return z ( "stridedSlice" ) } , t . prototype . unstack = function ( e , n ) { return z ( "unstack" ) } , t . prototype . reverse = function ( e , n ) { return z ( "reverse" ) } , t . prototype . concat = function ( e , n ) { return z ( "concat" ) } , t . prototype . neg = function ( e ) { return z ( "neg" ) } , t . prototype . add = function ( e , n ) { return z ( "add" ) } , t . prototype . addN = function ( e ) { return z ( "addN" ) } , t . prototype . subtract = function ( e , n ) { return z ( "subtract" ) } , t . prototype . multiply = function ( e , n ) { return z ( "multiply" ) } , t . prototype . realDivide = function ( e , n ) { return z ( "realDivide" ) } , t . prototype . floorDiv = function ( e , n ) { return z ( "floorDiv" ) } , t . prototype . sum = function ( e , n ) { return z ( "sum" ) } , t . prototype . prod = function ( e , n ) { return z ( "prod" ) } , t . prototype . unsortedSegmentSum = function ( e , n , a ) { return z (
2020-11-07 16:37:19 +01:00
` )),_.join( `
2020-11-07 17:25:03 +01:00
` )}function fe(t,e,n,a){var c=It(e),d=a[a.length-1],y=new Array(d).fill(0),v=e.length,_=n==="complex64"?Oe(t):t;if(v>1)for(var C=0;C<c/d;C++)for(var F=C*d,B=0;B<d;B++)y[B]=Math.max(y[B],ve(_[F+B],0,n).length);return y}function ve(t,e,n){var a;return Array.isArray(t)?a=parseFloat(t[0].toFixed(_e))+" + "+(parseFloat(t[1].toFixed(_e))+"j"):ta(t)?a="'"+t+"'":n==="bool"?a=ge(t):a=parseFloat(t.toFixed(_e)).toString(),et(a,e)}function ge(t){return t===0?"false":"true"}function Ae(t,e,n,a,c,d){d===void 0&&(d=!0);var y=n==="complex64"?2:1,v=e[0],_=e.length;if(_===0){if(n==="complex64"){var C=Oe(t);return[ve(C[0],0,n)]}return n==="bool"?[ge(t[0])]:[t[0].toString()]}if(_===1){if(v>se){var F=te*y,B=Array.from(t.slice(0,F)),U=Array.from(t.slice((v-te)*y,v*y));return n==="complex64"&&(B=Oe(B),U=Oe(U)),["["+B.map(function(nr,yr){return ve(nr,c[yr],n)}).join(", ")+", ..., "+U.map(function(nr,yr){return ve(nr,c[v-te+yr],n)}).join(", ")+"]"]}var J=n==="complex64"?Oe(t):Array.from(t);return["["+J.map(function(nr,yr){return ve(nr,c[yr],n)}).join(", ")+"]"]}var me=e.slice(1),Le=a.slice(1),Me=a[0]*y,He=[];if(v>se){for(var lt=0;lt<te;lt++){var Nt=lt*Me,Ct=Nt+Me;He.push.apply(He,Ae(t.slice(Nt,Ct),me,n,Le,c,!1))}He.push("...");for(var lt=v-te;lt<v;lt++){var Nt=lt*Me,Ct=Nt+Me;He.push.apply(He,Ae(t.slice(Nt,Ct),me,n,Le,c,lt===v-1))}}else for(var lt=0;lt<v;lt++){var Nt=lt*Me,Ct=Nt+Me;He.push.apply(He,Ae(t.slice(Nt,Ct),me,n,Le,c,lt===v-1))}var Bt=_===2?",":"";He[0]="["+He[0]+Bt;for(var lt=1;lt<He.length-1;lt++)He[lt]=" "+He[lt]+Bt;for(var ur= ` ,
` ,lt=2;lt<_;lt++)ur+= `
` ;return He[He.length-1]=" "+He[He.length-1]+"]"+(d?"":ur),He}function Oe(t){for(var e=[],n=0;n<t.length;n+=2)e.push([t[n],t[n+1]]);return e}var De=function(){function t(e,n,a){var c=this;if(this.dtype=n,this.shape=e.slice(),this.size=It(e),a!=null){var d=a.length;W(d===this.size,function(){return"Length of values '"+d+"' does not match the size "+("inferred by the shape '"+c.size+"'.")})}if(n==="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=a||_r(n,this.size),this.strides=za(e)}return t.prototype.set=function(e){for(var n=this,a=[],c=1;c<arguments.length;c++)a[c-1]=arguments[c];a.length===0&&(a=[0]),W(a.length===this.rank,function(){return"The number of provided coordinates ("+a.length+") must "+("match the rank ("+n.rank+")")});var d=this.locToIndex(a);this.values[d]=e},t.prototype.get=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];e.length===0&&(e=[0]);for(var a=0,c=0,d=e;c<d.length;c++){var y=d[c];if(y<0||y>=this.shape[a]){var v="Requested out of range element at "+e+". "+(" Buffer shape="+this.shape);throw new Error(v)}a++}for(var _=e[e.length-1],C=0;C<e.length-1;++C)_+=this.strides[C]*e[C];return this.values[_]},t.prototype.locToIndex=function(e){if(this.rank===0)return 0;if(this.rank===1)return e[0];for(var n=e[e.length-1],a=0;a<e.length-1;++a)n+=this.strides[a]*e[a];return n},t.prototype.indexToLoc=function(e){if(this.rank===0)return[];if(this.rank===1)return[e];for(var n=new Array(this.shape.length),a=0;a<n.length-1;++a)n[a]=Math.floor(e/this.strides[a]),e-=n[a]*this.strides[a];return n[n.length-1]=e,n},Object.defineProperty(t.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),t.prototype.toTensor=function(){return Ve().makeTensor(this.values,this.shape,this.dtype)},t}(),Ve=null,Xe=null;function at(t){Ve=t}function it(t){Xe=t}var $ =function(){function t(e,n,a,c){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=n||"float32",this.size=It(e),this.strides=za(e),this.dataId=a,this.id=c,this.rankType=this.rank<5?this.rank.toString():"higher"}return Object.defineProperty(t.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),t.prototype.buffer=function(){return M(this,void 0,void 0,function(){var e;return V(this,function(n){switch(n.label){case 0:return[4,this.data()];case 1:return e=n.sent(),[2,Xe.buffer(this.shape,this.dtype,e)]}})})},t.prototype.bufferSync=function(){return Xe.buffer(this.shape,this.dtype,this.dataSync())},t.prototype.array=function(){return M(this,void 0,void 0,function(){var e;return V(this,function(n){switch(n.label){case 0:return[4,this.data()];case 1:return e=n.sent(),[2,Gn(this.shape,e)]}})})},t.prototype.arraySync=function(){return Gn(this.shape,this.dataSync())},t.prototype.data=function(){return M(this,void 0,void 0,function(){var e,n;return V(this,function(a){switch(a.label){case 0:return this.throwIfDisposed(),e=Ve().read(this.dataId),this.dtype==="string"?[4,e]:[3,2];case 1:n=a.sent();try{return[2,n.map(function(c){return ns(c)})]}catch(c){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}a.label=2;case 2:return[2,e]}})})},t.prototype.dataSync=function(){this.throwIfDisposed();var e=Ve().readSync(this.dataId);if(this.dtype==="string")try{return e.map(function(n){return ns(n)})}catch(n){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return e},t.prototype.bytes=function(){return M(this,void 0,void 0,function(){var e;return V(this,function(n){switch(n.label){case 0:return this.throwIfDisposed(),[4,Ve().read(this.dataId)];case 1:return e=n.sent(),this.dtype==="string"?[2,e]:[2,new Uint8Array(e.buffer)]}})})},t.prototype.dispose=function(){if(this.isDisposed)return;Ve().disposeTensor(this),this.isDisposedInternal=!0},Object.defineProperty(t.prototype,"isDisposed",{get:function(){return this.isDi
` )+"Manifest JSON has weights with names: "+(_.join(", ")+"."));return F=d.reduce(function(Me,He,lt){return He&&Me.push(lt),Me},[]),B=[],F.forEach(function(Me){n[Me].paths.forEach(function(He){var lt=a+(a.endsWith("/")?"":"/")+He;B.push(lt)})}),[4,t(B)];case 1:return U=Le.sent(),J={},me=0,F.forEach(function(Me){for(var He=n[Me].paths.length,lt=0,Nt=0;Nt<He;Nt++)lt+=U[me+Nt].byteLength;for(var Ct=new ArrayBuffer(lt),Bt=new Uint8Array(Ct),ur=0,nr=0;nr<He;nr++){var yr=new Uint8Array(U[me+nr]);Bt.set(yr,ur),ur+=yr.byteLength}var Gr=y[Me];Gr.forEach(function(en){var Zr=Ct.slice(en.groupOffset,en.groupOffset+en.sizeBytes),Qr=xa(Zr,[en.manifestEntry]);for(var Kr in Qr)J[Kr]=Qr[Kr]}),me+=He}),[2,J]}})})}}var Hs="application/octet-stream",fo="application/json",Mu=function(){function t(e,n){if(this.DEFAULT_METHOD="POST",n==null&&(n={}),this.weightPathPrefix=n.weightPathPrefix,this.onProgress=n.onProgress,this.weightUrlConverter=n.weightUrlConverter,n.fetchFunc!=null?(W(typeof n.fetchFunc=="function",function(){return"Must pass a function that matches the signature of ` fetch ` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"}),this.fetch=n.fetchFunc):this.fetch=Rr().platform.fetch,W(e!=null&&e.length>0,function(){return"URL path for http must not be null, undefined or empty."}),Array.isArray(e)&&W(e.length===2,function(){return"URL paths for http must have a length of 2, "+("(actual length is "+e.length+").")}),this.path=e,n.requestInit!=null&&n.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=n.requestInit||{}}return t.prototype.save=function(e){return M(this,void 0,void 0,function(){var n,a,c,d;return V(this,function(y){switch(y.label){case 0:if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");return n=Object.assign({method:this.DEFAULT_METHOD},this.requestInit),n.body=new FormData,a=[{paths:["./model.weights.bin"],weights:e.weightSpecs}],c={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,userDefinedMetadata:e.userDefinedMetadata,weightsManifest:a},n.body.append("model.json",new Blob([JSON.stringify(c)],{type:fo}),"model.json"),e.weightData!=null&&n.body.append("model.weights.bin",new Blob([e.weightData],{type:Hs}),"model.weights.bin"),[4,this.fetch(this.path,n)];case 1:if(d=y.sent(),d.ok)return[2,{modelArtifactsInfo:dn(e),responses:[d]}];throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+(d.status+"."))}})})},t.prototype.load=function(){return M(this,void 0,void 0,function(){var e,n,a,c,d,y,v,_,C,F,B,U,J,me,Le;return V(this,function(Me){switch(Me.label){case 0:return[4,this.fetch(this.path,this.requestInit)];case 1:if(e=Me.sent(),!e.ok)throw new Error("Request to "+this.path+" failed with status code "+(e.status+". Please verify this URL points to ")+"the model JSON of the model to load.");Me.label=2;case 2:return Me.trys.push([2,4,,5]),[4,e.json()];case 3:return n=Me.sent(),[3,5];case 4:throw a=Me.sent(),c="Failed to parse model JSON of response from "+this.path+".",this.path.endsWith(".pb")?c+=" Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository.":c+=" Please make sure the server is serving valid JSON for this request.",new Error(c);case 5:if(d=n.modelTopology,y=n.weightsManifest,v=n.generatedBy,_=n.convertedBy,C=n.format,F=n.userDefinedMetadata,d==null&&y==null)throw new Error("The JSON from HTTP path "+this.path+" contains neither model topology or manifest for weights.");return y!=null?[4,this.loadWeights(y)]:[3,7];case 6:J=Me.sent(),B=J[0],U=J[1],Me.label=7;case 7:return me={modelTopology:d,weightSpecs:B,weightData:U,userDefinedMetadata:F,generatedBy:v,convertedBy:_,format:C},Le=n.mo
2020-11-07 16:37:19 +01:00
` )+("Actual: "+_+ ` .
` )+("Expected: "+C+"."));for(var F=0;F<C.length;++F){var B=_[F],U=C[F];if(!n(B,U))throw new Error("Arrays differ: actual["+F+"] = "+B+", expected["+F+"] = "+U+ ` .
` +("Actual: "+_+ ` .
2020-11-07 17:25:03 +01:00
` )+("Expected: "+C+"."))}}function El(t,e){t().then(function(){return e.fail()},function(){return e()})}function Rl(t,e){var n=typeof e=="string"||typeof e=="number"||typeof e=="boolean"?[e]:e;return ta(t)||ta(t[0])||ta(e)||ta(e[0])?Gu(t,n,function(a,c){return a==c}):Gu(t,e,function(a,c){return js(a,c,0)})}function Al(t,e,n){if(n==null&&(n=vu()),!js(t,e,n))throw new Error("Numbers differ: actual === "+t+", expected === "+e)}function js(t,e,n){return!isFinite(t)&&!isFinite(e)?!0:!(isNaN(t)||isNaN(e)||Math.abs(t-e)>n)}function ju(t,e,n){for(var a=0;a<t.length;a++)if(t[a]<e||t[a]>n)throw new Error("Value out of range:"+t[a]+" low: "+e+", high: "+n)}function Fl(t,e){expect(new Float32Array(t)).toEqual(new Float32Array(e))}var Dl={__proto__:null,TEST_EPSILON_FLOAT16:Hu,expectArraysClose:Tl,testEpsilon:vu,expectPromiseToFail:El,expectArraysEqual:Rl,expectNumbersClose:Al,expectValuesInRange:ju,expectArrayBuffersEqual:Fl},qu="2.7.0";function Ol(){Rr().set("PROD",!0)}function Ml(){Rr().set("DEBUG",!0)}function Ku(){Rr().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")}function Ea(t){Rr().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(t+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}function zl(){Ie.disposeVariables()}function Ll(){return Ie}function Pl(){return Ie.memory()}function Zc(t){return Ie.profile(t)}function la(t,e){return Ie.tidy(t,e)}function Ua(t){var e=Ot(t);e.forEach(function(n){return n.dispose()})}function gu(t){return Ie.keep(t)}function Qc(t){return Ie.time(t)}function Bl(t){return Ie.setBackend(t)}function Wl(){return Ie.ready()}function Ul(){return Ie.backendName}function Vl(t){Ie.removeBackend(t)}function Hl(t){return Ie.findBackend(t)}function Gl(t){return Ie.findBackendFactory(t)}function jl(t,e,n){return n===void 0&&(n=1),Ie.registerBackend(t,e,n)}function ql(){return Ie.backend}function Kl(t,e){Rr().setPlatform(t,e)}function Xl(t,e){var n,a=ie(t,"a","add"),c=ie(e,"b","add");n=Tt(a,c),a=n[0],c=n[1];var d=function(v,_){var C=v.add(a,c);return _([a,c]),C},y={a,b:c};return Ie.runKernelFunc(d,y,null,ma)}var Cr=Re({add_:Xl});function Yl(t,e){var n,a=ie(t,"a","floorDiv"),c=ie(e,"b","floorDiv");n=Tt(a,c),a=n[0],c=n[1];var d=function(v,_){var C=v.floorDiv(a,c);return _([a,c]),C},y={a,b:c};return Ie.runKernelFunc(d,y,null,k)}var Xu=Re({floorDiv_:Yl});function Zl(t,e){var n,a=ie(t,"a","div"),c=ie(e,"b","div");if(n=Tt(a,c),a=n[0],c=n[1],a.dtype==="int32"&&c.dtype==="int32")return Xu(a,c);var d=function(_,C){var F=_.realDivide(a,c);return C([a,c]),F},y={a,b:c},v={};return Ie.runKernelFunc(d,y,null,Vr,v)}var Wr=Re({div_:Zl});function Jc(t,e){var n,a=ie(t,"a","mul"),c=ie(e,"b","mul");n=Tt(a,c),a=n[0],c=n[1];var d=function(v,_){var C=v.multiply(a,c);return _([a,c]),C},y={a,b:c};return Ie.runKernelFunc(d,y,null,qr)}var bt=Re({mul_:Jc});function Ql(t){var e=ie(t,"x","abs"),n={x:e};return Ie.runKernelFunc(function(a,c){return c([e]),e.dtype==="complex64"?a.complexAbs(e):a.abs(e)},n,null,jn)}var ci=Re({abs_:Ql});function Jl(t){var e=ie(t,"x","acos"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.acos(e);return c([e]),d},n,null,ni)}var $ c=Re({acos_:Jl});function $ l(t){var e=ie(t,"x","acosh"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.acosh(e);return c([e]),d},n,null,pi)}var el=Re({acosh_: $ l});function eh(t){W(Array.isArray(t),function(){return"The argument passed to tf.addN() must be a list of tensors"}),W(t.length>=1,function(){return"Must pass at least one tensor to tf.addN(), but got "+(""+t.length)});var e=t.map(function(d,y){return ie(d,"tensors"+y,"addN")}),n=e[0];e.forEach(function(d){if(d.dtype!==n.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),e.forEach(function(d){if(!mt(d.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});var a=function(d,y){var v=d.addN(e);return y(e),v},c=e;return Ie.runKernelFunc(a,c,null,di)}var th=Re({addN_:eh});function Yu(t,e){for(var n=0;n<t.length;++n)if(t[t.length-n-1]!==e-1-n)return!1;return!0
with dtype ` +y.dtype+". ")});var a=function(y,v){var _=jt(e,n[0].shape)[0],C=Ir(n.map(function(U){return U.shape}),_);if(It(C)===0)return An([],C);if(n=n.filter(function(U){return U.size>0}),n.length===1)return n[0];var F=n.map(function(U){return U.shape});hr(F,_);var B=y.concat(n,_);return v(n),B},c=n,d={axis:e};return Ie.runKernelFunc(a,c,null,Ue,d)}var kr=Re({concat_:zr});function Sr(t){var e=ie(t,"x","sigmoid"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.sigmoid(e);return c([d]),d},n,null,As)}var mn=Re({sigmoid_:Sr});function Xr(t,e,n){var a=ie(t,"x","slice");if(a.rank===0)throw new Error("Slicing scalar is not possible");var c=function(v,_){var C=Vu(a,e,n),F=C[0],B=C[1];return Bc(a,F,B),_([a]),v.slice(a,F,B)},d={x:a},y={begin:e,size:n};return Ie.runKernelFunc(c,d,null,To,y)}var er=Re({slice_:Xr});function Dn(t){var e=ie(t,"x","tanh"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.tanh(e);return c([d]),d},n,null,Os)}var Cn=Re({tanh_:Dn});function bn(t,e,n,a,c,d){var y=ie(t,"forgetBias","basicLSTMCell"),v=ie(e,"lstmKernel","basicLSTMCell"),_=ie(n,"lstmBias","basicLSTMCell"),C=ie(a,"data","basicLSTMCell"),F=ie(c,"c","basicLSTMCell"),B=ie(d,"h","basicLSTMCell"),U=kr([C,B],1),J=sn(U,v),me=Cr(J,_),Le=me.shape[0],Me=me.shape[1]/4,He=[Le,Me],lt=er(me,[0,0],He),Nt=er(me,[0,Me],He),Ct=er(me,[0,Me*2],He),Bt=er(me,[0,Me*3],He),ur=Cr(bt(mn(lt),Cn(Nt)),bt(F,mn(Cr(y,Ct)))),nr=bt(Cn(ur),mn(Bt));return[ur,nr]}var un=Re({basicLSTMCell_:bn});function On(t,e,n){var a=ie(t,"x","batchToSpaceND"),c=e.reduce(function(_,C){return _*C});W(a.rank>=1+e.length,function(){return"input rank is "+a.rank+" but should be > than blockShape.length "+e.length}),W(n.length===e.length,function(){return"crops.length is "+n.length+" but should be equal to blockShape.length "+e.length}),W(a.shape[0]%c===0,function(){return"input tensor batch is "+a.shape[0]+" but is not divisible by the product of "+("the elements of blockShape "+e.join(" * ")+" === "+c)});var d=function(_){return _.batchToSpaceND(a,e,n)},y={x:a},v={blockShape:e,crops:n};return Ie.runKernelFunc(d,y,null,Oi,v)}var Hr=Re({batchToSpaceND_:On});function ha(t){var e;return t.rank===0||t.rank===1?e=Ke(t,[1,1,1,t.size]):t.rank===2?e=Ke(t,[1,1,t.shape[0],t.shape[1]]):t.rank===3?e=Ke(t,[1,t.shape[0],t.shape[1],t.shape[2]]):e=t,e}function Ni(t,e,n,a,c,d){d==null&&(d=.001);var y=ie(t,"x","batchNorm"),v=ie(e,"mean","batchNorm"),_=ie(n,"variance","batchNorm"),C;c!=null&&(C=ie(c,"scale","batchNorm"));var F;a!=null&&(F=ie(a,"offset","batchNorm")),W(v.rank===_.rank,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),W(F==null||v.rank===F.rank,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),W(C==null||v.rank===C.rank,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."});var B=ha(y),U=function(Me,He){return He([B,v,_,C]),Me.batchNorm(B,Wi(v),Wi(_),Wi(F),Wi(C),d)},J={x:B,scale:C,offset:F,mean:v,variance:_},me={varianceEpsilon:d},Le=Ie.runKernelFunc(U,J,null,K,me);return Ke(Le,y.shape)}function Wi(t){return t==null?null:t.rank===0?Ke(t,[t.size]):t.rank===1?t:t.rank===2?Ke(t,[1,1,t.shape[0],t.shape[1]]):t.rank===3?Ke(t,[1,t.shape[0],t.shape[1],t.shape[2]]):t}var Kn=Re({batchNorm_:Ni});function eo(t,e,n,a,c,d){var y=ie(t,"x","batchNorm"),v=ie(e,"mean","batchNorm"),_=ie(n,"variance","batchNorm"),C;c!=null&&(C=ie(c,"scale","batchNorm"));var F;return a!=null&&(F=ie(a,"offset","batchNorm")),W(y.rank===2,function(){return"Error in batchNorm2D: x must be rank 2 but got rank "+(y.rank+".")}),W(v.rank===2||v.rank===1,function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but "+("got rank "+v.rank+".")}),W(_.rank===2||_.rank===1,function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 "+("but got rank "+_.rank+".")}),C!=null&&W(C.rank===2||C.rank===1,function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 "+("but got rank "+C.rank+".")}),F!=null&&W(F.rank===2||F.rank===1,function(){return"Error in batchNorm2D: off
2020-11-07 16:37:19 +01:00
` +c+" and "+e+ ` for depthToSpace with input shape
` +a.shape}),W(d*e>=0,function(){return ` Negative dimension size caused by overflow when multiplying
` +d+" and "+e+ ` for depthToSpace with input shape
2020-11-07 17:25:03 +01:00
` +a.shape}),W(y%(e*e)===0,function(){return"Dimension size must be evenly divisible by "+e*e+" but is "+y+" for depthToSpace with input shape "+a.shape});var v=function(F){return F.depthToSpace(a,e,n)},_={x:a},C={blockSize:e,dataFormat:n};return Ie.runKernelFunc(v,_,null,va,C)}var Yp=Re({depthToSpace_:Tf});function Ef(t,e,n,a,c,d,y){c===void 0&&(c="NHWC"),d===void 0&&(d=[1,1]);var v=ie(t,"x","depthwiseConv2d"),_=ie(e,"filter","depthwiseConv2d"),C=v,F=!1;v.rank===3&&(F=!0,C=Ke(v,[1,v.shape[0],v.shape[1],v.shape[2]])),W(C.rank===4,function(){return"Error in depthwiseConv2d: input must be rank 4, but got "+("rank "+C.rank+".")}),W(_.rank===4,function(){return"Error in depthwiseConv2d: filter must be rank 4, but got rank "+(_.rank+".")}),W(C.shape[3]===_.shape[2],function(){return"Error in depthwiseConv2d: number of input channels "+("("+C.shape[3]+") must match the inChannels dimension in ")+("filter "+_.shape[2]+".")}),y!=null&&W(yt(a),function(){return"Error in depthwiseConv2d: pad must be an integer when using, "+("dimRoundingMode "+y+" but got pad "+a+".")});var B=function(Le,Me){d==null&&(d=[1,1]),W(dt(n,d),function(){return"Error in depthwiseConv2d: Either strides or dilations must be "+("1. Got strides "+n+" and dilations '"+d+"'")});var He=T(C.shape,_.shape,n,d,a,y,!0),lt=Le.depthwiseConv2D(C,_,He);return Me([C,_]),lt},U={x:C,filter:_},J={strides:n,pad:a,dataFormat:c,dilations:d,dimRoundingMode:y},me=Ie.runKernelFunc(B,U,null,ia,J);return F?Ke(me,[me.shape[1],me.shape[2],me.shape[3]]):me}var lh=Re({depthwiseConv2d_:Ef});function Rf(t){var e=ie(t,"x","diag"),n=function(c){var d=Ke(e,[e.size]),y=c.diag(d),v=t.shape.concat(t.shape);return Ke(y,v)},a={x:e};return Ie.runKernelFunc(n,a,null,rn)}var Af=Re({diag_:Rf});function Ff(t,e,n,a,c,d){c===void 0&&(c=[1,1]),d===void 0&&(d="NHWC");var y=ie(t,"x","dilation2d"),v=ie(e,"filter","dilation2d");W(y.rank===3||y.rank===4,function(){return"Error in dilation2d: input must be rank 3 or 4, but got rank "+(y.rank+".")}),W(v.rank===3,function(){return"Error in dilation2d: filter must be rank 3, but got rank "+(v.rank+".")}),W(d==="NHWC",function(){return"Error in dilation2d: Only NHWC is currently supported, "+("but got dataFormat of "+d)});var _=y,C=!1;y.rank===3&&(_=Ke(y,[1,y.shape[0],y.shape[1],y.shape[2]]),C=!0);var F={x:_,filter:v},B={strides:n,pad:a,dilations:c},U=Ie.runKernel(hn,F,B);return C?Ke(U,[U.shape[1],U.shape[2],U.shape[3]]):U}var Zp=Re({dilation2d_:Ff});function Df(t,e){for(var n=t.length,a=[],c=0;c<n;c++){var d=n-1-c,y=t[d]||1,v=e[e.length-1-c]||1;v>1&&y===1&&a.unshift(d)}return a}function ti(t,e){for(var n=[],a=0;a<e.length;a++){var c=t[t.length-a-1],d=e.length-a-1,y=e[d];(c==null||c===1&&y>1)&&n.unshift(d)}return n}function pa(t,e){for(var n=[],a=Math.max(t.length,e.length),c=0;c<a;c++){var d=t[t.length-c-1];d==null&&(d=1);var y=e[e.length-c-1];if(y==null&&(y=1),d===1)n.unshift(y);else if(y===1)n.unshift(d);else if(d!==y){var v="Operands could not be broadcast together with shapes "+(t+" and "+e+".");throw Error(v)}else n.unshift(d)}return n}function Of(t,e){var n,a=ie(t,"a","equal"),c=ie(e,"b","equal");n=Tt(a,c),a=n[0],c=n[1],pa(a.shape,c.shape);var d=function(v){return v.equal(a,c)},y={a,b:c};return Ie.runKernelFunc(d,y,null,qn)}var hh=Re({equal_:Of});function Mf(t,e,n){var a=ie(e,"a","where"),c=ie(n,"b","where"),d=ie(t,"condition","where","bool"),y=pa(a.shape,c.shape),v=Qu(a,y),_=Qu(c,y);d.rank===1&&W(d.shape[0]===a.shape[0],function(){return"The first dimension of ` a ` must match the size of ` condition ` ."}),d.rank!==1&&st(d.shape,_.shape,"Error in where: ");var C=function(B,U){var J=B.select(d,v,_);return U([d]),J},F={condition:d,t:v,e:_};return Ie.runKernelFunc(C,F,null,Da)}var ls=Re({where_:Mf});function zf(t){var e=ie(t,"x","zerosLike"),n={x:e};return Ie.runKernelFunc(function(a){return a.zerosLike(e)},n,null,zs)}var gn=Re({zerosLike_:zf});function Lf(t,e){var n,a=ie(t,"a","div"),c=ie(e,"b","div");n=Tt(a,c),a=n[0],c=n[1];var d=Wr(a,c),y=gn(d),v=hh(c,y);return ls(v,y,d)}var Qp=Re({divNoNan_:Lf});function Pf(t,e){var n=ie(t,"t1","dot"),a=ie(e,"t2","d
2020-11-07 16:37:19 +01:00
rank ` +d.rank+"."}),W(yt(e),function(){return"Error in localResponseNormalization: depthRadius must be an "+("integer but got depthRadius "+e+".")});var y=d,v=!1;d.rank===3&&(v=!0,y=Ke(d,[1,d.shape[0],d.shape[1],d.shape[2]]));var _=function(U,J){var me=U.localResponseNormalization4D(y,e,n,a,c);return J([y,me]),me},C={x:y},F={depthRadius:e,bias:n,alpha:a,beta:c},B=Ie.runKernelFunc(_,C,null,Sn,F);return v?Ke(B,[B.shape[1],B.shape[2],B.shape[3]]):B}var sd=Re({localResponseNormalization_:c1});function l1(t){var e=ie(t,"x","log"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.log(e);return c([e]),d},n,null,xr)}var ec=Re({log_:l1});function h1(t){var e=ie(t,"x","log1p"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.log1p(e);return c([e]),d},n,null,kn)}var hp=Re({log1p_:h1});function p1(t){return W(ra(t),function(){return"The f passed in grad(f) must be a function"}),function(e,n){var a=ie(e,"x","tf.grad",null),c=n!=null?ie(n,"dy","tf.grad"):null;return Ie.tidy(function(){var d=Ie.gradients(function(){return t(a)},[a],c),y=d.value,v=d.grads;return c!=null&&st(y.shape,c.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),Dh(v),v[0]})}}function d1(t){return W(ra(t),function(){return"The f passed in grads(f) must be a function"}),function(e,n){W(Array.isArray(e),function(){return"The args passed in grads(f)(args) must be an array of ` Tensor ` s or ` TensorLike ` s"});var a=In(e,"args","tf.grads",null),c=n!=null?ie(n,"dy","tf.grads"):null;return Ie.tidy(function(){var d=Ie.gradients(function(){return t.apply(void 0,a)},a,c),y=d.value,v=d.grads;return c!=null&&st(y.shape,c.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Dh(v),v})}}function f1(t){return W(ra(t),function(){return"The f passed in valueAndGrad(f) must be a function"}),function(e,n){W(e instanceof $ ,function(){return"The x passed in valueAndGrad(f)(x) must be a tensor"}),W(n==null||n instanceof $ ,function(){return"The dy passed in valueAndGrad(f)(x, dy) must be a tensor"});var a=Ie.gradients(function(){return t(e)},[e],n),c=a.grads,d=a.value;return Dh(c),{grad:c[0],value:d}}}function m1(t){return W(ra(t),function(){return"The f passed in valueAndGrads(f) must be a function"}),function(e,n){W(Array.isArray(e)&&e.every(function(c){return c instanceof $ }),function(){return"The args passed in valueAndGrads(f)(args) must be array of tensors"}),W(n==null||n instanceof $ ,function(){return"The dy passed in valueAndGrads(f)(args, dy) must be a tensor"});var a=Ie.gradients(function(){return t.apply(void 0,e)},e,n);return n!=null&&st(a.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Dh(a.grads),a}}function ud(t,e){W(ra(t),function(){return"The f passed in variableGrads(f) must be a function"}),W(e==null||Array.isArray(e)&&e.every(function(B){return B instanceof rt}),function(){return"The varList passed in variableGrads(f, varList) must be an array of variables"});var n=e!=null;if(!n){e=[];for(var a in Ie.registeredVariables)e.push(Ie.registeredVariables[a])}var c=n?e.filter(function(B){return!B.trainable}):null,d=e.length;e=e.filter(function(B){return B.trainable}),W(e.length>0,function(){return"variableGrads() expects at least one of the input variables to "+("be trainable, but none of the "+d+" variables is ")+"trainable."});var y=!0,v=Ie.gradients(t,e,null,y),_=v.value,C=v.grads;W(C.some(function(B){return B!=null}),function(){return"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()."}),W(_.rank===0,function(){return"The f passed in variableGrads(f) must return a scalar, but it "+("returned a rank-"+_.rank+" tensor")});var F={};return e.forEach(function(B,U){C[U]!=null&&(F[B.name]=C[U])}),c!=null&&c.forEach(function(B){return F[B.name]=null}),{value:_,grads:F}}function Ts(t){return Ie.customGrad(t)}function Dh(t){var e=t.filter(function(n){return n==nul
2020-11-07 17:25:03 +01:00
the f you passed encloses all operations that lead from x to y . ` )}function y1(t){var e=ie(t,"x","neg"),n={x:e};return Ie.runKernelFunc(function(a){return a.neg(e)},n,null,Io)}var ri=Re({neg_:y1});function v1(t){var e=ie(t,"x","softplus"),n={x:e};return Ie.runKernelFunc(function(a,c){var d=a.softplus(e);return c([e]),d},n,null,Zo)}var pp=Re({softplus_:v1});function g1(t){var e=ie(t,"x","logSigmoid"),n=Ts(function(a){var c=ri(pp(ri(a))),d=function(y){var v=bt(y,mn(ri(a)));return v};return{value:c,gradFunc:d}});return n(e)}var cd=Re({logSigmoid_:g1});function x1(t,e,n){e===void 0&&(e=null),n===void 0&&(n=!1);var a=ie(t,"x","max"),c=function(v,_){var C=jt(e,a.shape),F=C,B= $ i(F,a.rank),U=a;B!=null&&(U= $ n(a,B),F=p(F.length,U.rank));var J=v.max(U,F);B!=null&&U.dispose();var me=J;if(n){var Le=li(me.shape,jt(e,a.shape));me=Ke(me,Le),J.dispose()}return _([a,me]),me},d={x:a},y={reductionIndices:e,keepDims:n};return Ie.runKernelFunc(c,d,null, $ r,y)}var tc=Re({max_:x1});function _1(t,e){var n,a=ie(t,"a","sub"),c=ie(e,"b","sub");n=Tt(a,c),a=n[0],c=n[1];var d=function(v,_){var C=v.subtract(a,c);return _([a,c]),C},y={a,b:c};return Ie.runKernelFunc(d,y,null,ds)}var Lr=Re({sub_:_1});function w1(t,e,n){e===void 0&&(e=null),n===void 0&&(n=!1);var a=ie(t,"x","sum");a.dtype==="bool"&&(a=dr(a,"int32"));var c=function(v,_){_([a]);var C=jt(e,a.shape),F= $ i(C,a.rank),B=C,U=a;F!=null&&(U= $ n(a,F),B=p(B.length,a.rank));var J=v.sum(U,B);if(n){var me=li(J.shape,C);J=Ke(J,me)}return J},d={x:a},y={axis:e,keepDims:n};return Ie.runKernelFunc(c,d,null,Qo,y)}var Yr=Re({sum_:w1});function b1(t,e){e===void 0&&(e=-1);var n=ie(t,"logits","logSoftmax");if(e===-1&&(e=n.rank-1),e!==n.rank-1)throw Error("Log Softmax along a non-last dimension is not yet supported. "+("Logits was rank "+n.rank+" and axis was "+e));var a=function(y,v){var _=!0,C=tc(t,e,!0),F=Lr(t,C),B=Lr(dr(F,"float32"),ec(Yr(hs(F),e,_)));return v([B]),B},c={logits:n},d={axis:e};return Ie.runKernelFunc(a,c,null,Na,d)}var ld=Re({logSoftmax_:b1});function k1(t,e,n){e===void 0&&(e=null),n===void 0&&(n=!1);var a=ie(t,"x","logSumExp"),c=jt(e,a.shape),d=tc(a,c,!0),y=Lr(a,d),v=hs(y),_=Yr(v,c),C=ec(_),F=Cr(Ke(d,C.shape),C);if(n){var B=li(F.shape,c);return Ke(F,B)}return F}var dp=Re({logSumExp_:k1});function S1(t,e){var n=ie(t,"a","logicalAnd","bool"),a=ie(e,"b","logicalAnd","bool");pa(n.shape,a.shape);var c={a:n,b:a};return Ie.runKernelFunc(function(d){return d.logicalAnd(n,a)},c,null,pn)}var rc=Re({logicalAnd_:S1});function I1(t){var e=ie(t,"x","logicalNot","bool"),n={x:e};return Ie.runKernelFunc(function(a){return a.logicalNot(e)},n,null,zn)}var Oh=Re({logicalNot_:I1});function N1(t,e){var n=ie(t,"a","logicalOr","bool"),a=ie(e,"b","logicalOr","bool");pa(n.shape,a.shape);var c={a:n,b:a};return Ie.runKernelFunc(function(d){return d.logicalOr(n,a)},c,null,Dr)}var fp=Re({logicalOr_:N1});function C1(t,e){var n=ie(t,"a","logicalXor","bool"),a=ie(e,"b","logicalXor","bool");return pa(n.shape,a.shape),rc(fp(t,e),Oh(rc(t,e)))}var hd=Re({logicalXor_:C1});function T1(t,e,n,a,c){var d=ie(t,"x","maxPool"),y=1,v=d,_=!1;d.rank===3&&(_=!0,v=Ke(d,[1,d.shape[0],d.shape[1],d.shape[2]])),W(v.rank===4,function(){return"Error in maxPool: input must be rank 4 but got rank "+v.rank+"."}),W(dt(n,y),function(){return"Error in maxPool: Either strides or dilations must be 1. "+("Got strides "+n+" and dilations '"+y+"'")}),c!=null&&W(yt(a),function(){return"Error in maxPool: pad must be an integer when using, "+("dimRoundingMode "+c+" but got pad "+a+".")});var C=function(J,me){var Le=h(v.shape,e,n,1,a,c),Me;return Le.filterWidth===1&&Le.filterHeight===1&&mt(Le.inShape,Le.outShape)?Me=v.clone():Me=J.maxPool(v,Le),me([v,Me]),Me},F={x:v},B={filterSize:e,strides:n,pad:a,dimRoundingMode:c},U=Ie.runKernelFunc(C,F,null,mi,B);return _?Ke(U,[U.shape[1],U.shape[2],U.shape[3]]):U}var mp=Re({maxPool_:T1});function E1(t,e,n,a,c,d,y){e===void 0&&(e=[1,1,1]),d===void 0&&(d="NDHWC"),y==null?y=[1,1,1]:Ea("dilations is deprecated, this field will be gone in v3.0.0.");var v=ie(t,"x","maxPool3d"),_=v,C=!1;v.rank===4&&(C=!0,_=Ke(v,[1,v.shape[0],v.shape
2020-11-07 16:37:19 +01:00
` +("1. The "+o+" is defined in Python, in which ")+ ` case it needs to be ported to TensorFlow . js or your JavaScript code .
` +("2. The custom "+o+" is defined in JavaScript, ")+"but is not registered properly with tf.serialization.registerClass().");return Z}else{var le=s;if(le.className==null||le.config==null)throw new w(o+": Improper config format: "+(JSON.stringify(le)+ ` .
` )+"'className' and 'config' must set.");var Ne=le.className,Be=void 0,je=void 0;if(Ne in r?(b=r[Ne],Be=b[0],je=b[1]):Ne in $ e?(T= $ e.className,Be=T[0],je=T[1]):Ne in u&&(O=u[Ne],Be=O[0],je=O[1]),Be==null)throw new w("Unknown "+o+": "+Ne+ ` . This may be due to one of the following reasons :
` +("1. The "+o+" is defined in Python, in which ")+ ` case it needs to be ported to TensorFlow . js or your JavaScript code .
2020-11-07 17:25:03 +01:00
` +("2. The custom "+o+" is defined in JavaScript, ")+"but is not registered properly with tf.serialization.registerClass().");if(je!=null){for(var qe={},vt=0,pt=Object.keys( $ e);vt<pt.length;vt++){var ct=pt[vt];qe[ct]= $ e[ct]}for(var dt=0,Ft=Object.keys(r);dt<Ft.length;dt++){var ct=Ft[dt];qe[ct]=r[ct]}var sr=le.config;sr.customObjects=qe;for(var Yt=V({}, $ e), $ t=0,vr=Object.keys(r); $ t<vr.length; $ t++){var ct=vr[ $ t]; $ e[ct]=r[ct]}nt(le.config);var hr=je(Be,le.config,r,h);return $ e=V({},Yt),hr}else{for(var Yt=V({}, $ e),Ir=0,zr=Object.keys(r);Ir<zr.length;Ir++){var ct=zr[Ir]; $ e[ct]=r[ct]}var hr=new Be(le.config);return $ e=V({},Yt),hr}}}function Qt(s,u){return s<u?-1:s>u?1:0}function rr(s,u){return-1*Qt(s,u)}function jt(s){if(s==null)return s;for(var u=[],r=0,o=s;r<o.length;r++){var h=o[r];u.indexOf(h)===-1&&u.push(h)}return u}function jr(s){if(s==null)throw new w("Invalid value in obj: "+JSON.stringify(s));for(var u in s)if(s.hasOwnProperty(u))return!1;return!0}function Pr(s,u,r){if(r==null)return;if(s.indexOf(r)<0)throw new w(r+" is not a valid "+u+". Valid values are "+s+" or null/undefined.")}function _r(s,u,r,o){return r===void 0&&(r=0),o===void 0&&(o=Infinity),ut(r>=0),ut(o>=r),Array.isArray(s)&&s.length>=r&&s.length<=o&&s.every(function(h){return typeof h===u})}function ar(s,u){Array.isArray(s)?(i.util.assert(s.length>0,function(){return u+" is unexpectedly an empty array."}),s.forEach(function(r,o){return ar(r,"element "+(o+1)+" of "+u)})):i.util.assert(Number.isInteger(s)&&s>0,function(){return"Expected "+u+" to be a positive integer, but got "+(da(s)+".")})}function da(s){return s===null?"null":Array.isArray(s)?"["+s.map(function(u){return da(u)}).join(",")+"]":typeof s=="string"?'"'+s+'"':""+s}function Ha(s,u){var r=i.util.now(),o,h=function(){for(var b=[],T=0;T<arguments.length;T++)b[T]=arguments[T];var O=i.util.now();return O-r<u||(r=O,o=s.apply(void 0,b)),o};return h}function Tn(s){return s==="relu"?"relu":s==="linear"?"linear":s==="elu"?"elu":null}function ba(s,u){return i.tidy(function(){return i.sqrt(i.sum(i.mul(s,s),u,!0))})}var ka=function(s){M(u,s);function u(){return s!==null&&s.apply(this,arguments)||this}return u.prototype.getConfig=function(){return{}},u}(i.serialization.Serializable),ta=function(s){M(u,s);function u(r){var o=s.call(this)||this;return o.defaultMaxValue=2,o.defaultAxis=0,o.maxValue=r.maxValue!=null?r.maxValue:o.defaultMaxValue,o.axis=r.axis!=null?r.axis:o.defaultAxis,o}return u.prototype.apply=function(r){var o=this;return i.tidy(function(){var h=ba(r,o.axis),b=i.clipByValue(h,0,o.maxValue);return i.mul(r,i.div(b,i.add(z(),h)))})},u.prototype.getConfig=function(){return{maxValue:this.maxValue,axis:this.axis}},u.className="MaxNorm",u}(ka);i.serialization.registerClass(ta);var Ma=function(s){M(u,s);function u(r){var o=s.call(this)||this;return o.defaultAxis=0,o.axis=r.axis!=null?r.axis:o.defaultAxis,o}return u.prototype.apply=function(r){var o=this;return i.tidy(function(){return i.div(r,i.add(z(),ba(r,o.axis)))})},u.prototype.getConfig=function(){return{axis:this.axis}},u.className="UnitNorm",u}(ka);i.serialization.registerClass(Ma);var Ti=function(s){M(u,s);function u(){return s!==null&&s.apply(this,arguments)||this}return u.prototype.apply=function(r){return i.relu(r)},u.className="NonNeg",u}(ka);i.serialization.registerClass(Ti);var Bn=function(s){M(u,s);function u(r){var o=s.call(this)||this;return o.defaultMinValue=0,o.defaultMaxValue=1,o.defaultRate=1,o.defaultAxis=0,o.minValue=r.minValue!=null?r.minValue:o.defaultMinValue,o.maxValue=r.maxValue!=null?r.maxValue:o.defaultMaxValue,o.rate=r.rate!=null?r.rate:o.defaultRate,o.axis=r.axis!=null?r.axis:o.defaultAxis,o}return u.prototype.apply=function(r){var o=this;return i.tidy(function(){var h=ba(r,o.axis),b=i.add(i.mul(o.rate,i.clipByValue(h,o.minValue,o.maxValue)),i.mul(1-o.rate,h));return i.mul(r,i.div(b,i.add(z(),h)))})},u.prototype.getConfig=function(){return{minValue:this.minValue,maxValue:this.maxValue,rate:this.rate,axis:this.axis}},u.className="MinMaxNorm",u}(ka);i.serialization.registerClass(Bn);var ra={maxNorm:"MaxNorm",minMaxNor
2020-11-07 16:37:19 +01:00
because the value dtype is ` +k.dtype+", but TensorArray dtype is "+this.dtype+".");if(this.size()===0&&(this.elementShape==null||this.elementShape.length===0)&&(this.elementShape=k.shape),ln(this.elementShape,k.shape,"TensorArray "+this.name+": Could not write to TensorArray index "+x+"."),K.read)throw new Error("TensorArray "+this.name+": Could not write to TensorArray index "+x+", because it has already been read.");if(K.written)throw new Error("TensorArray "+this.name+": Could not write to TensorArray index "+x+", because it has already been written.");K.tensor=k,i.keep(k),K.written=!0,this.tensors[x]=K},S.prototype.writeMany=function(x,k){var K=this;if(x.length!==k.length)throw new Error("TensorArray "+this.name+": could not write multiple tensors,"+("because the index size: "+x.length+" is not the same as tensors size: "+k.length+"."));x.forEach(function(Se,be){return K.write(Se,k[be])})},S.prototype.gather=function(x,k){if(!!k&&k!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but gather requested dtype "+k);if(x)x=x.slice(0,this.size());else{x=[];for(var K=0;K<this.size();K++)x.push(K)}if(x.length===0)return i.tensor([],[0].concat(this.elementShape));var Se=this.readMany(x);return ln(this.elementShape,Se[0].shape,"TensorArray shape mismatch: "),i.stack(Se,0)},S.prototype.concat=function(x){if(!!x&&x!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but concat requested dtype "+x);if(this.size()===0)return i.tensor([],[0].concat(this.elementShape));for(var k=[],K=0;K<this.size();K++)k.push(K);var Se=this.readMany(k);return ln(this.elementShape,Se[0].shape,"TensorArray shape mismatch: tensor array shape ("+this.elementShape+") vs first tensor shape ("+Se[0].shape+")"),i.concat(Se,0)},S.prototype.scatter=function(x,k){if(k.dtype!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but tensor has dtype "+k.dtype);if(x.length!==k.shape[0])throw new Error("Expected len(indices) == tensor.shape[0], but saw: "+x.length+" vs. "+k.shape[0]);var K=Math.max.apply(Math,de(x));if(!this.dynamicSize&&K>=this.maxSize)throw new Error("Max index must be < array size ("+K+" vs. "+this.maxSize+")");this.writeMany(x,i.unstack(k,0))},S.prototype.split=function(x,k){var K=this;if(k.dtype!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but tensor has dtype "+k.dtype);var Se=0,be=x.map(function(Lt){return Se+=Lt,Se});if(Se!==k.shape[0])throw new Error( ` Expected sum of lengths to be equal to
tensor . shape [ 0 ] , but sum of lengths is
` +Se+", and tensor's shape is: "+k.shape);if(!this.dynamicSize&&x.length!==this.maxSize)throw new Error("TensorArray's size is not equal to the size of lengths ("+this.maxSize+" vs. "+x.length+"), and the TensorArray is not marked as dynamically resizeable");var Je=Se===0?0:k.size/Se,Pe=[];i.tidy(function(){k=i.reshape(k,[1,Se,Je]);for(var Lt=0;Lt<x.length;++Lt){var Wt=Lt===0?0:be[Lt-1],Gt=[0,Wt,0],Jt=[1,x[Lt],Je];Pe[Lt]=i.reshape(i.slice(k,Gt,Jt),K.elementShape)}return Pe});for(var gt=[],ft=0;ft<x.length;ft++)gt[ft]=ft;this.writeMany(gt,Pe)},S}(),Ai=function(){function S(x,k,K,Se){Se===void 0&&(Se=-1),this.tensors=x,this.elementShape=k,this.elementDtype=K,x!=null&&x.forEach(function(be){if(K!==be.dtype)throw new Error("Invalid data types; op elements "+K+", but list elements "+be.dtype);ln(k,be.shape,"TensorList shape mismatch: "),i.keep(be)}),this.idTensor=i.scalar(0),this.maxNumElements=Se,i.keep(this.idTensor)}return Object.defineProperty(S.prototype,"id",{get:function(){return this.idTensor.id},enumerable:!0,configurable:!0}),S.prototype.copy=function(){return new S(de(this.tensors),this.elementShape,this.elementDtype)},S.prototype.clearAndClose=function(x){this.tensors.forEach(function(k){(x==null||!x.has(k.id))&&k.dispose()}),this.tensors.length=0,this.idTensor.dispose()},S.prototype.size=function(){return this.tensors.length},S.prototype.stack=function(x,k,K){var Se=this;if(K===void 0&&(K=-1),k!==this.elementDtype)throw new Error("Invalid data types; op elements "+k+", but list elements "+this.elementDtype);if(K!==-1&&this.tensors.length!==K)throw new Error("Operation expected a list with "+K+" elements but got a list with "+this.tensors.length+" elements.");return ln(x,this.elementShape,"TensorList shape mismatch: "),i.tidy(function(){var be=Se.tensors.map(function(Je){return i.reshape(Je,x)});return i.stack(be,0)})},S.prototype.popBack=function(x,k){if(k!==this.elementDtype)throw new Error("Invalid data types; op elements "+k+", but list elements "+this.elementDtype);if(this.size()===0)throw new Error("Trying to pop from an empty list.");var K=this.tensors.pop();return ln(K.shape,x,"TensorList shape mismatch: "),i.reshape(K,x)},S.prototype.pushBack=function(x){if(x.dtype!==this.elementDtype)throw new Error("Invalid data types; op elements "+x.dtype+", but list elements "+this.elementDtype);if(ln(x.shape,this.elementShape,"TensorList shape mismatch: "),this.maxNumElements===this.size())throw new Error("Trying to push element into a full list.");i.keep(x),this.tensors.push(x)},S.prototype.resize=function(x){if(x<0)throw new Error("TensorListResize expects size to be non-negative. Got: "+x);if(this.maxNumElements!==-1&&x>this.maxNumElements)throw new Error("TensorListResize input size "+x+" is greater maxNumElement "+this.maxNumElements+".");this.tensors.length=x},S.prototype.getItem=function(x,k,K){if(K!==this.elementDtype)throw new Error("Invalid data types; op elements "+K+", but list elements "+this.elementDtype);if(x<0||x>this.tensors.length)throw new Error("Trying to access element "+x+" in a list with "+this.tensors.length+" elements.");if(this.tensors[x]==null)throw new Error("element at index "+x+" is null.");return ln(this.tensors[x].shape,k,"TensorList shape mismatch: "),this.tensors[x]},S.prototype.setItem=function(x,k){if(k.dtype!==this.elementDtype)throw new Error("Invalid data types; op elements "+k.dtype+", but list elements "+this.elementDtype);if(x<0||this.maxNumElements!==-1&&x>=this.maxNumElements)throw new Error("Trying to set element "+x+" in a list with max "+this.maxNumElements+" elements.");ln(this.elementShape,k.shape,"TensorList shape mismatch: "),i.keep(k),this.tensors[x]=k},S.prototype.gather=function(x,k,K){var Se=this;if(k!==this.elementDtype)throw new Error("Invalid data types; op elements "+k+", but list elements "+this.elementDtype);return ln(this.elementShape,K,"TensorList shape mismatch: "),x=x.slice(0,this.size()),x.length===0?i.tensor([],[0].concat(this.elementShape)):i.tidy(function(){var be=x.map(function(Je){return i.reshape(Se.tensors[Je],K)});return i.stack(be,0)
tensor . shape [ 0 ] , but sum of lengths is
2020-11-07 17:25:03 +01:00
` +K+", and tensor's shape is: "+S.shape);for(var be=K===0?0:S.size/K,Je=i.tidy(function(){var ft=[];S=i.reshape(S,[1,K,be]);for(var Lt=0;Lt<x.length;++Lt){var Wt=Lt===0?0:Se[Lt-1],Gt=[0,Wt,0],Jt=[1,x[Lt],be];ft[Lt]=i.reshape(i.slice(S,Gt,Jt),k)}return S.dispose(),ft}),Pe=new Ai([],k,S.dtype,x.length),gt=0;gt<Je.length;gt++)Pe.setItem(gt,Je[gt]);return Pe}var Fi=void 0,qi=function(S,x,k){return M(Fi,void 0,void 0,function(){var K,Se,be,Je,Pe,gt,ft,Lt,Pe,Wt,Gt,gt,Jt,wr,Ar,Ar,Zt,xr,Zt,kn,Zt,Zt,Zt,pn,zn,Dr,Na,Sn,cr, $ r,Fa,mi,Ka,Xa,ii,zi,Rn,Ca,Ki,yi,oi,qr,Io,nn,Ya,Ba,Xi,si,Li,ao,mo,Za,io,Yo,No,Co,oo,ua,Ka,Xa,Br,ua,Rn,Dr,ca,Br,nn,Ya,Dr,Qa,Br,Dr,Zn,Qa,Br,Ki,yi,Dr,Zn,Br,ua,Dr,Zn,Qa,Br,so,Dr,Zn,Br,Xi,Br,Li,Dr,ua,Xa,Br,ua,Dr,ca,Br,mo,Dr,Za,Br;return V(this,function(Ta){switch(Ta.label){case 0:K=S.op;switch(K){case"If":return[3,1];case"StatelessIf":return[3,1];case"While":return[3,3];case"StatelessWhile":return[3,3];case"LoopCond":return[3,9];case"Switch":return[3,10];case"Merge":return[3,12];case"Enter":return[3,13];case"Exit":return[3,14];case"NextIteration":return[3,15];case"TensorArrayV3":return[3,16];case"TensorArrayWriteV3":return[3,17];case"TensorArrayReadV3":return[3,18];case"TensorArrayGatherV3":return[3,19];case"TensorArrayScatterV3":return[3,20];case"TensorArrayConcatV3":return[3,21];case"TensorArraySplitV3":return[3,22];case"TensorArraySizeV3":return[3,23];case"TensorArrayCloseV3":return[3,24];case"TensorListSetItem":return[3,25];case"TensorListGetItem":return[3,26];case"TensorListScatterV2":return[3,27];case"TensorListScatter":return[3,27];case"TensorListReserve":return[3,28];case"TensorListGather":return[3,29];case"TensorListStack":return[3,30];case"TensorListFromTensor":return[3,31];case"TensorListConcat":return[3,32];case"TensorListPushBack":return[3,33];case"TensorListPopBack":return[3,34];case"TensorListSplit":return[3,35]}return[3,36];case 1:return Se=w("thenBranch",S,x,k),be=w("elseBranch",S,x,k),Je=w("cond",S,x,k),Pe=w("args",S,x,k),[4,Je.data()];case 2:return gt=Ta.sent(),gt[0]?[2,k.functionMap[Se].executeFunctionAsync(Pe,k.tensorArrayMap,k.tensorListMap)]:[2,k.functionMap[be].executeFunctionAsync(Pe,k.tensorArrayMap,k.tensorListMap)];case 3:return ft=w("body",S,x,k),Lt=w("cond",S,x,k),Pe=w("args",S,x,k),[4,k.functionMap[Lt].executeFunctionAsync(Pe,k.tensorArrayMap,k.tensorListMap)];case 4:return Wt=Ta.sent(),Gt=Pe.map(function(vn){return vn.id}),[4,Wt[0].data()];case 5:gt=Ta.sent(),Wt.forEach(function(vn){!vn.kept&&Gt.indexOf(vn.id)===-1&&vn.dispose()}),Jt=Pe,wr=function(){var vn,Pi,yo;return V(this,function(vo){switch(vo.label){case 0:return vn=Jt,[4,k.functionMap[ft].executeFunctionAsync(Jt,k.tensorArrayMap,k.tensorListMap)];case 1:return Jt=vo.sent(),Pi=Jt.map(function(Da){return Da.id}),vn.forEach(function(Da){!Da.kept&&Gt.indexOf(Da.id)===-1&&Pi.indexOf(Da.id)===-1&&Da.dispose()}),[4,k.functionMap[Lt].executeFunctionAsync(Jt,k.tensorArrayMap,k.tensorListMap)];case 2:return yo=vo.sent(),[4,yo[0].data()];case 3:return gt=vo.sent(),yo.forEach(function(Da){!Da.kept&&Gt.indexOf(Da.id)===-1&&Pi.indexOf(Da.id)===-1&&Da.dispose()}),[2]}})},Ta.label=6;case 6:return gt[0]?[5,wr()]:[3,8];case 7:return Ta.sent(),[3,6];case 8:return[2,Jt];case 9:return Ar=w("pred",S,x,k),[2,[It(Ar)]];case 10:return Ar=w("pred",S,x,k),Zt=w("data",S,x,k),Zt.kept||(Zt=It(Zt)),[4,Ar.data()];case 11:return[2,Ta.sent()[0]?[void 0,Zt]:[Zt,void 0]];case 12:return xr=S.inputNames.find(function(vn){return xe(vn,x,k)!==void 0}),xr?(Zt=xe(xr,x,k),[2,[It(Zt)]]):[2,void 0];case 13:return kn=w("frameName",S,x,k),Zt=w("tensor",S,x,k),k.enterFrame(kn),[2,[It(Zt)]];case 14:return Zt=w("tensor",S,x,k),k.exitFrame(),[2,[It(Zt)]];case 15:return Zt=w("tensor",S,x,k),k.nextIteration(),[2,[It(Zt)]];case 16:return pn=w("size",S,x,k),zn=w("dtype",S,x,k),Dr=w("elementShape",S,x,k),Na=w("dynamicSize",S,x,k),Sn=w("clearAfterRead",S,x,k),cr=w("identicalElementShapes",S,x,k), $ r=w("name",S,x,k),Fa=new gr( $ r,zn,pn,Dr,cr,Na,Sn),k.addTensorArray(Fa),[2,[Fa.idTensor,i.scalar(1)]];case 17:return mi=w("tensorArrayId",S,x,k),Ka=w("index",S,x,k),Xa=w("tensor",S,x,k
2020-11-07 16:37:19 +01:00
` +Y});var Ue;return this.size===Infinity||this.size==null?Ue=this.size:j?Ue=Math.ceil(this.size/Y):Ue=Math.floor(this.size/Y),Wn(function(){return V(ne,void 0,void 0,function(){return oe(this,function(kt){switch(kt.label){case 0:return[4,re.iterator()];case 1:return[2,kt.sent().columnMajorBatch(Y,j,hi)]}})})},Ue)},pe.prototype.concatenate=function(Y){var j=this,ne=this,re;return this.size===Infinity||Y.size===Infinity?re=Infinity:this.size!=null&&Y.size!=null?re=this.size+Y.size:re=null,Wn(function(){return V(j,void 0,void 0,function(){var Ue,kt;return oe(this,function(tt){switch(tt.label){case 0:return[4,ne.iterator()];case 1:return kt=(Ue=tt.sent()).concatenate,[4,Y.iterator()];case 2:return[2,kt.apply(Ue,[tt.sent()])]}})})},re)},pe.prototype.filter=function(Y){var j=this,ne=this,re;return this.size===Infinity?re=Infinity:re=null,Wn(function(){return V(j,void 0,void 0,function(){return oe(this,function(Ue){switch(Ue.label){case 0:return[4,ne.iterator()];case 1:return[2,Ue.sent().filter(function(kt){return i.tidy(function(){return Y(kt)})})]}})})},re)},pe.prototype.forEachAsync=function(Y){return V(this,void 0,void 0,function(){return oe(this,function(j){switch(j.label){case 0:return[4,this.iterator()];case 1:return[2,j.sent().forEachAsync(Y)]}})})},pe.prototype.map=function(Y){var j=this,ne=this;return Wn(function(){return V(j,void 0,void 0,function(){return oe(this,function(re){switch(re.label){case 0:return[4,ne.iterator()];case 1:return[2,re.sent().map(function(Ue){return i.tidy(function(){return Y(Ue)})})]}})})},this.size)},pe.prototype.mapAsync=function(Y){var j=this,ne=this;return Wn(function(){return V(j,void 0,void 0,function(){return oe(this,function(re){switch(re.label){case 0:return[4,ne.iterator()];case 1:return[2,re.sent().mapAsync(Y)]}})})},this.size)},pe.prototype.prefetch=function(Y){var j=this;if(Y==null)throw new RangeError(" ` Dataset . prefetch ( ) ` requires bufferSize to be specified.");var ne=this;return Wn(function(){return V(j,void 0,void 0,function(){return oe(this,function(re){switch(re.label){case 0:return[4,ne.iterator()];case 1:return[2,re.sent().prefetch(Y)]}})})},this.size)},pe.prototype.repeat=function(Y){var j=this,ne=this,re;return this.size!=null&&Y>0?re=this.size*Y:Y===0?re=0:this.size!=null&&(Y===void 0||Y<0)?re=Infinity:re=null,Wn(function(){return V(j,void 0,void 0,function(){var Ue,kt=this;return oe(this,function(tt){return Ue=jr(function(){return V(kt,void 0,void 0,function(){var ze;return oe(this,function(Ye){switch(Ye.label){case 0:return ze={},[4,ne.iterator()];case 1:return[2,(ze.value=Ye.sent(),ze.done=!1,ze)]}})})}),[2,Pr(Ue.take(Y))]})})},re)},pe.prototype.skip=function(Y){var j=this,ne=this,re;return this.size!=null&&Y>=0&&this.size>=Y?re=this.size-Y:this.size!=null&&(this.size<Y||Y===void 0||Y<0)?re=0:re=null,Wn(function(){return V(j,void 0,void 0,function(){return oe(this,function(Ue){switch(Ue.label){case 0:return[4,ne.iterator()];case 1:return[2,Ue.sent().skip(Y)]}})})},re)},pe.prototype.shuffle=function(Y,j,ne){var re=this;if(ne===void 0&&(ne=!0),Y==null||Y<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)"));var Ue=this,kt=W(j||i.util.now().toString());return Wn(function(){return V(re,void 0,void 0,function(){var tt;return oe(this,function(ze){switch(ze.label){case 0:return tt=kt.int32(),ne&&(tt+=kt.int32()),[4,Ue.iterator()];case 1:return[2,ze.sent().shuffle(Y,tt.toString())]}})})},this.size)},pe.prototype.take=function(Y){var j=this,ne=this,re;return this.size!=null&&this.size>Y?re=Y:this.size!=null&&this.size<=Y?re=this.size:re=null,Wn(function(){return V(j,void 0,void 0,function(){return oe(this,function(Ue){switch(Ue.label){case 0:return[4,ne.iterator()];case 1:return[2,Ue.sent().take(Y)]}})})},re)},pe.prototype.toArray=function(){return V(this,void 0,void 0,function(
2020-11-07 17:25:03 +01:00
` ).map(function(kt){return kt.endsWith(" \r ")&&(kt=kt.slice(0,-1)),kt}),[2,re]}})})},Y}(Yn),xn='"',Ia=Symbol("out"),Rr=Symbol("field"),Pa=Symbol("quote"),na=Symbol("quoteafterquote"),Ei=Symbol("quoteinquote"),Gi=function(pe){M(Y,pe);function Y(j,ne){var re=pe.call(this)||this;return re.input=j,re.hasHeader=!0,re.fullColumnNames=null,re.columnNamesValidated=!1,re.columnConfigs=null,re.configuredColumnsOnly=!1,re.delimiter=",",re.delimWhitespace=!1,re.base=new on(j),ne||(ne={}),re.hasHeader=!(ne.hasHeader===!1),re.fullColumnNames=ne.columnNames,re.columnConfigs=ne.columnConfigs,re.configuredColumnsOnly=ne.configuredColumnsOnly,ne.delimWhitespace?(i.util.assert(ne.delimiter==null,function(){return"Delimiter should not be provided when delimWhitespace is true."}),re.delimWhitespace=!0,re.delimiter=" "):re.delimiter=ne.delimiter?ne.delimiter:",",re}return Y.prototype.columnNames=function(){return V(this,void 0,void 0,function(){return oe(this,function(j){switch(j.label){case 0:return this.columnNamesValidated?[3,2]:[4,this.setColumnNames()];case 1:j.sent(),j.label=2;case 2:return[2,this.configuredColumnsOnly?Object.keys(this.columnConfigs):this.fullColumnNames]}})})},Y.prototype.setColumnNames=function(){return V(this,void 0,void 0,function(){var j,ne,re,Ue,kt,tt,ze,Ye=this;return oe(this,function(Dt){switch(Dt.label){case 0:return[4,this.maybeReadHeaderLine()];case 1:if(j=Dt.sent(),!this.fullColumnNames&&!j)throw new Error("Column names must be provided if there is no header line.");if(this.fullColumnNames&&j&&i.util.assert(j.length===this.fullColumnNames.length,function(){return"The length of provided columnNames ("+Ye.fullColumnNames.length.toString()+") does not match the length of the header line read from file ("+j.length.toString()+")."}),this.fullColumnNames||(this.fullColumnNames=j),ne=this.fullColumnNames.reduce(function(St,Mt){return St[Mt]=St[Mt]+1||1,St},{}),re=Object.keys(ne).filter(function(St){return ne[St]>1}),i.util.assert(re.length===0,function(){return"Duplicate column names found: "+re.toString()}),this.columnConfigs){for(Ue=0,kt=Object.keys(this.columnConfigs);Ue<kt.length;Ue++)if(tt=kt[Ue],ze=this.fullColumnNames.indexOf(tt),ze===-1)throw new Error('The key "'+tt+'" provided in columnConfigs does not match any of the column names ('+this.fullColumnNames.toString()+").")}return this.columnNamesValidated=!0,[2]}})})},Y.prototype.maybeReadHeaderLine=function(){return V(this,void 0,void 0,function(){var j,ne,re,Ue;return oe(this,function(kt){switch(kt.label){case 0:return this.hasHeader?[4,this.base.iterator()]:[3,3];case 1:return j=kt.sent(),[4,j.next()];case 2:if(ne=kt.sent(),ne.done)throw new Error("No data was found for CSV parsing.");return re=ne.value,Ue=this.parseRow(re,!1),[2,Ue];case 3:return[2,null]}})})},Y.prototype.iterator=function(){return V(this,void 0,void 0,function(){var j,ne=this;return oe(this,function(re){switch(re.label){case 0:return this.columnNamesValidated?[3,2]:[4,this.setColumnNames()];case 1:re.sent(),re.label=2;case 2:return[4,this.base.iterator()];case 3:return j=re.sent(),this.hasHeader&&(j=j.skip(1)),[2,j.map(function(Ue){return ne.makeDataElement(Ue)})]}})})},Y.prototype.makeDataElement=function(j){for(var ne=this.parseRow(j),re={},Ue={},kt=0;kt<this.fullColumnNames.length;kt++){var tt=this.fullColumnNames[kt],ze=this.columnConfigs?this.columnConfigs[tt]:null;if(this.configuredColumnsOnly&&!ze)continue;var Ye=ne[kt],Dt=null;if(Ye==="")if(ze&&ze.default!==void 0)Dt=ze.default;else{if(ze&&(ze.required||ze.isLabel))throw new Error("Required column "+tt+" is empty in this line: "+j);Dt=void 0}else{var St=Number(Ye);if(isNaN(St))ze&&ze.dtype==="bool"?Dt=this.getBoolean(Ye):Dt=Ye;else if(!ze||!ze.dtype)Dt=St;else switch(ze.dtype){case"float32":Dt=St;break;case"int32":Dt=Math.floor(St);break;case"bool":Dt=this.getBoolean(Ye);break;default:Dt=St}}ze&&ze.isLabel?Ue[tt]=Dt:re[tt]=Dt}return Object.keys(Ue).length===0?re:{xs:re,ys:Ue}},Y.prototype.getBoolean=function(j){return j==="1"||j.toLowerCase()==="true"?1:0},Y.prototype.parseRow=function(j,ne){ne===void 0&&(ne=!0);for(var re=[],
2020-11-07 16:37:19 +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.
2020-11-07 17:25:03 +01:00
=== === === === === === === === === = ` ));var H={};return this.data.set(H,{values:E,dtype:A,refCount:1}),H},ue.prototype.makeTensorInfo=function(E,D,A){var H;if(D==="string"&&A!=null&&A.length>0&&i.util.isString(A[0])){var se=A.map(function(te){return i.util.encodeString(te)});H=this.write(se,E,D)}else H=this.write(A,E,D);return{dataId:H,shape:E,dtype:D}},ue.prototype.incRef=function(E){var D=this.data.get(E);D.refCount++},ue.prototype.decRef=function(E){if(this.data.has(E)){var D=this.data.get(E);D.refCount--}},ue.prototype.move=function(E,D,A,H){this.data.set(E,{values:D,dtype:H,refCount:1})},ue.prototype.numDataIds=function(){return this.data.numDataIds()},ue.prototype.read=function(E){return oe(this,void 0,void 0,function(){return de(this,function(D){return[2,this.readSync(E)]})})},ue.prototype.readSync=function(E){var D=this.data.get(E),A=D.dtype,H=D.complexTensorInfos;if(A==="complex64"){var se=this.readSync(H.real.dataId),te=this.readSync(H.imag.dataId);return i.backend_util.mergeRealAndImagArrays(se,te)}return this.data.get(E).values},ue.prototype.bufferSync=function(E){var D=this.readSync(E.dataId),A=D;if(E.dtype==="string")try{A=D.map(function(H){return i.util.decodeString(H)})}catch(H){throw new Error("Failed to decode encoded string bytes into utf-8")}return i.buffer(E.shape,E.dtype,A)},ue.prototype.makeOutput=function(E,D,A){var H=this.write(E,D,A);return i.engine().makeTensorFromDataId(H,D,A,this)},ue.prototype.disposeData=function(E){if(this.data.has(E)){var D=this.data.get(E).complexTensorInfos;D!=null&&(this.disposeData(D.real.dataId),this.disposeData(D.imag.dataId)),this.data.delete(E)}},ue.prototype.disposeIntermediateTensorInfo=function(E){var D=E.dataId;if(this.data.has(D)){var A=this.data.get(D);A.refCount--,A.refCount<1&&this.disposeData(D)}},ue.prototype.time=function(E){return oe(this,void 0,void 0,function(){var D,A;return de(this,function(H){return D=i.util.now(),E(),A=i.util.now()-D,[2,{kernelMs:A}]})})},ue.prototype.memory=function(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}},ue.prototype.stridedSlice=function(E,D,A,H){X(E,"stridedSlice");var se=i.slice_util.computeOutShape(D,A,H);if(se.some(function(Ae){return Ae===0}))return i.tensor([],se);for(var te=i.buffer(se,E.dtype),_e=this.bufferSync(E),ce=0;ce<te.size;ce++){for(var fe=te.indexToLoc(ce),ve=new Array(fe.length),ge=0;ge<ve.length;ge++)ve[ge]=fe[ge]*H[ge]+D[ge];te.set.apply(te,[_e.get.apply(_e,ve)].concat(fe))}return te.toTensor()},ue.prototype.diag=function(E){for(var D=this.readSync(E.dataId),A=i.buffer([E.size,E.size],E.dtype),H=A.values,se=0;se<D.length;se++)H[se*E.size+se]=D[se];return A.toTensor()},ue.prototype.unstack=function(E,D){for(var A=E.shape[D],H=new Array(E.rank-1),se=0,te=0;te<E.rank;te++)te!==D&&(H[se++]=E.shape[te]);var _e=new Array(E.rank).fill(0),ce=E.shape.slice();ce[D]=1;for(var fe=new Array(A),te=0;te<fe.length;te++)_e[D]=te,fe[te]=i.slice(E,_e,ce).reshape(H);return fe},ue.prototype.reverse=function(E,D){X(E,"reverse");for(var A=i.buffer(E.shape,E.dtype),H=this.bufferSync(E),se=function(_e){var ce=A.indexToLoc(_e),fe=ce.slice();D.forEach(function(ve){return fe[ve]=E.shape[ve]-1-fe[ve]}),A.set.apply(A,[H.get.apply(H,fe)].concat(ce))},te=0;te<A.size;te++)se(te);return A.toTensor()},ue.prototype.neg=function(E){return X(E,"neg"),i.mul(i.scalar(-1),E)},ue.prototype.addN=function(E){var D=this;X(E,"addN");for(var A=E.map(function(fe){return D.readSync(fe.dataId)}),H=i.buffer(E[0].shape,E[0].dtype),se=H.values,te=0;te<E.length;te++)for(var _e=A[te],ce=0;ce<se.length;ce++)se[ce]+=_e[ce];return H.toTensor()},ue.prototype.softmax=function(E,D){var A=i.util.parseAxisParam([D],E.shape),H=i.max(E,A),se=i.backend_util.expandShapeToKeepDim(H.shape,A),te=i.sub(E,H.reshape(se)),_e=i.exp(te),ce=this.sum(_e,A).reshape(se);return i.div(_e,ce)},ue.prototype.pow=function(E,D){return X([E,D],"pow"),this.broadcastedBinaryOp(E,D,E.dtype,function(A,H){return Math.pow(A,H)})},ue.prototype.floorDiv=function(E,D){X([E,D],"floorDiv");var A=funct
2020-11-07 16:37:19 +01:00
` ),I=g.length.toString().length+2,R=g.map(function(Ce,Fe){return i.util.rightPad((Fe+1).toString(),I)+Ce}),P=0,L=0;L<R.length;L++)P=Math.max(R[L].length,P);var G=R.slice(0,m-1),Q=R.slice(m-1,m),ke=R.slice(m);console.log(G.join( `
` )),console.log(p.split( `
` )[0]),console.log("%c "+i.util.rightPad(Q[0],P),"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(ke.join( `
` ))}function Pr(f){return Yn(f,function(){return f.createProgram()},"Unable to create WebGLProgram.")}function _r(f,p){if(Ze(f,function(){return f.linkProgram(p)}),f.getProgramParameter(p,f.LINK_STATUS)===!1)throw console.log(f.getProgramInfoLog(p)),new Error("Failed to link vertex and fragment shaders.")}function ar(f,p){if(Ze(f,function(){return f.validateProgram(p)}),f.getProgramParameter(p,f.VALIDATE_STATUS)===!1)throw console.log(f.getProgramInfoLog(p)),new Error("Shader program validation failed.")}function da(f,p){var l=Yn(f,function(){return f.createBuffer()},"Unable to create WebGLBuffer");return Ze(f,function(){return f.bindBuffer(f.ARRAY_BUFFER,l)}),Ze(f,function(){return f.bufferData(f.ARRAY_BUFFER,p,f.STATIC_DRAW)}),l}function Ha(f,p){var l=Yn(f,function(){return f.createBuffer()},"Unable to create WebGLBuffer");return Ze(f,function(){return f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,l)}),Ze(f,function(){return f.bufferData(f.ELEMENT_ARRAY_BUFFER,p,f.STATIC_DRAW)}),l}function Tn(){return i.env().getNumber("WEBGL_VERSION")===2?1:4}function ba(f){return Yn(f,function(){return f.createTexture()},"Unable to create WebGLTexture.")}function ka(f,p){var l=i.env().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(f<=0||p<=0){var m="["+f+"x"+p+"]";throw new Error("Requested texture size "+m+" is invalid.")}if(f>l||p>l){var m="["+f+"x"+p+"]",g="["+l+"x"+l+"]";throw new Error("Requested texture size "+m+" greater than WebGL maximum on this browser / GPU "+g+".")}}function ta(f){return Yn(f,function(){return f.createFramebuffer()},"Unable to create WebGLFramebuffer.")}function Ma(f,p,l,m,g,I,R){var P=f.getAttribLocation(p,l);return P===-1?!1:(Ze(f,function(){return f.bindBuffer(f.ARRAY_BUFFER,m)}),Ze(f,function(){return f.vertexAttribPointer(P,g,f.FLOAT,!1,I,R)}),Ze(f,function(){return f.enableVertexAttribArray(P)}),!0)}function Ti(f,p,l){Wn(f,l),Ze(f,function(){return f.activeTexture(f.TEXTURE0+l)}),Ze(f,function(){return f.bindTexture(f.TEXTURE_2D,p)})}function Bn(f,p){Wn(f,p),Ze(f,function(){return f.activeTexture(f.TEXTURE0+p)}),Ze(f,function(){return f.bindTexture(f.TEXTURE_2D,null)})}function ra(f,p,l){return Yn(f,function(){return f.getUniformLocation(p,l)},'uniform "'+l+'" not present in program.')}function cn(f,p,l){return f.getUniformLocation(p,l)}function za(f,p,l,m){Ze(f,function(){return Ti(f,p,m)}),Ze(f,function(){return f.uniform1i(l,m)})}function fn(f){Ze(f,function(){return f.bindFramebuffer(f.FRAMEBUFFER,null)}),Ze(f,function(){return f.viewport(0,0,f.canvas.width,f.canvas.height)}),Ze(f,function(){return f.scissor(0,0,f.canvas.width,f.canvas.height)})}function Gn(f,p,l){Ze(f,function(){return f.bindFramebuffer(f.FRAMEBUFFER,l)}),Ze(f,function(){return f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0,f.TEXTURE_2D,p,0)})}function _i(f,p){Ze(f,function(){return f.bindFramebuffer(f.FRAMEBUFFER,p)}),Ze(f,function(){return f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0,f.TEXTURE_2D,null,0)})}function fa(f){var p=f.checkFramebufferStatus(f.FRAMEBUFFER);if(p!==f.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+Hi(f,p))}function Hi(f,p){switch(p){case f.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case f.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case f.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case f.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return"unknown error "+p}}function Yn(f,p,l){var m=Ze(f,function(){return p()});if(m==null)throw new Error(l);return m}function Wn(f,p){var l=f.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,m=p+f.TEXTURE0;if(m<f.TEXTURE0||m>l){var g="[gl.TEXTURE0, gl.TEXTURE"+l+"]";throw new Error("textureUnit must be in "+g+".")}}function Ga(f,p){return p===void 0&&(p=2),i.util.sizeFromShape(f.slice(0,f.length-p))}function Sa(f){if(f.length===0)throw Error("Cannot get rows and columns of an empty shape array.");return[f.length>1?f[f.length-2]:1,f[f.length-1]]}function hi(f){var p=[1,1,1],l=f.length===0||f.length===1&&f[0]===1;return l||(p=[Ga(f)]
void main ( ) {
` +m.join( `
` )+ `
float result = ` +g+ ` ;
setOutput ( result ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),hn=function(){function f(p,l){this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=p,this.variableNames=l.map(function(I,R){return"T"+R});var m=[];this.variableNames.forEach(function(I){m.push("vec4 v"+I+" = get"+I+"AtOutCoords();")});var g=this.variableNames.map(function(I){return"v"+I}).join(" + ");this.userCode= `
void main ( ) {
` +m.join( `
` )+ `
vec4 result = ` +g+ ` ;
setOutput ( result ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),oa=function(){function f(p,l,m){this.variableNames=["A"];var g=p.windowSize,I=p.batchSize,R=p.outSize;m||this.variableNames.push("bestIndicesA"),this.outputShape=[I,R];var P=l==="max"?">":"<",L=m?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode= `
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
int inOffset = outIdx * ` +g+ ` ;
int bestIndex = inOffset ;
float bestValue = getA ( batch , bestIndex ) ;
for ( int i = 0 ; i < ` +g+ ` ; i ++ ) {
int inIdx = ` +L+ ` ;
float candidate = getA ( batch , inIdx ) ;
if ( candidate ` +P+ ` bestValue ) {
bestValue = candidate ;
bestIndex = inIdx ;
2020-11-04 17:57:44 +01:00
}
}
2020-11-07 16:37:19 +01:00
setOutput ( float ( bestIndex ) ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}();function Jr(f,p){return["x","y","z","w","u","v"].slice(0,p).map(function(l){return f+"."+l})}function Vr(f,p){return p===1?[f]:Jr(f,p)}function Jn(f,p){if(f===1)return"rc";for(var l="",m=0;m<f;m++)l+=p[m],m<f-1&&(l+=",");return l}function tn(){var f,p,l,m,g,I,R,P,L,G;return i.env().getNumber("WEBGL_VERSION")===2?(f="#version 300 es",p="in",l="out",m="in",g="texture",I="outputColor",R="out vec4 outputColor;",P= `
bool isnan _custom ( float val ) {
return ( val > 0.0 || val < 0.0 ) ? false : val != 0.0 ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
bvec4 isnan _custom ( vec4 val ) {
return bvec4 ( isnan _custom ( val . x ) ,
isnan _custom ( val . y ) , isnan _custom ( val . z ) , isnan _custom ( val . w ) ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
# define isnan ( value ) isnan _custom ( value )
` ,L="",G= `
# define round ( value ) newRound ( value )
int newRound ( float value ) {
return int ( floor ( value + 0.5 ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
ivec4 newRound ( vec4 value ) {
return ivec4 ( floor ( value + vec4 ( 0.5 ) ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ):(f="",p="attribute",l="varying",m="varying",g="texture2D",I="gl_FragColor",R="",P= `
# define isnan ( value ) isnan _custom ( value )
bool isnan _custom ( float val ) {
return ( val > 0. || val < 1. || val == 0. ) ? false : true ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
bvec4 isnan _custom ( vec4 val ) {
return bvec4 ( isnan ( val . x ) , isnan ( val . y ) , isnan ( val . z ) , isnan ( val . w ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ,L= `
uniform float INFINITY ;
bool isinf ( float val ) {
return abs ( val ) == INFINITY ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
bvec4 isinf ( vec4 val ) {
return equal ( abs ( val ) , vec4 ( INFINITY ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ,G= `
int round ( float value ) {
return int ( floor ( value + 0.5 ) ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
ivec4 round ( vec4 value ) {
return ivec4 ( floor ( value + vec4 ( 0.5 ) ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ),{version:f,attribute:p,varyingVs:l,varyingFs:m,texture2D:g,output:I,defineOutput:R,defineSpecialNaN:P,defineSpecialInf:L,defineRound:G}}function En(f,p,l){l===void 0&&(l="index");var m=i.util.computeStrides(p);return m.map(function(g,I){var R="int "+f[I]+" = "+l+" / "+g,P=I===m.length-1?"int "+f[I+1]+" = "+l+" - "+f[I]+" * "+g:"index -= "+f[I]+" * "+g;return R+"; "+P+";"}).join("")}function qn(f){var p=i.util.computeStrides(f).map(function(l){return l.toString()});return `
int getFlatIndex ( ivec3 coords ) {
return coords . x * ` +p[0]+" + coords.y * "+p[1]+ ` + coords . z ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }var sa= `
const float FLOAT _MAX = 1.70141184 e38 ;
const float FLOAT _MIN = 1.17549435 e - 38 ;
lowp vec4 encode _float ( highp float v ) {
if ( isnan ( v ) ) {
return vec4 ( 255 , 255 , 255 , 255 ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +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-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +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-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` ,ga=i.backend_util.getBroadcastDims;function Mi(f,p,l,m){var g=[];f.forEach(function(Ee){var Ge=i.util.sizeFromShape(Ee.shapeInfo.logicalShape);Ee.shapeInfo.isUniform?g.push("uniform float "+Ee.name+(Ge>1?"["+Ge+"]":"")+";"):(g.push("uniform sampler2D "+Ee.name+";"),g.push("uniform int offset"+Ee.name+";"))});var I=g.join( `
` ),R=f.map(function(Ee){return x(Ee,p,m)}).join( `
` ),P=p.texShape,L=tn(),G=Se(L),Q,ke,Ce=Pe(L);p.isPacked?(Q=k(p.logicalShape,P),ke=Je(L)):(Q=K(p.logicalShape,P),ke=be(L)),m&&(Ce+=Wt);var Fe=[Ce,G,ke,I,Q,R,l].join( `
` );return Fe}function Aa(f){var p=f.shapeInfo.logicalShape;switch(p.length){case 0:return $ r(f);case 1:return mi(f);case 2:return Xa(f);case 3:return zi(f);case 4:return Ca(f);case 5:return Ki(f);case 6:return yi(f);default:throw new Error(p.length+"-D input sampling is not yet supported")}}function S(f){var p=f.shapeInfo.logicalShape;switch(p.length){case 0:return cr(f);case 1:return Fa(f);case 2:return Ka(f);case 3:return ii(f);default:return Rn(f)}}function x(f,p,l){l===void 0&&(l=!1);var m="";l?m+=S(f):m+=Aa(f);var g=f.shapeInfo.logicalShape,I=p.logicalShape;return g.length<=I.length&&(l?m+=qr(f,p):m+=Io(f,p)),m}function k(f,p){switch(f.length){case 0:return Gt();case 1:return Jt(f,p);case 2:return Dr(f,p);case 3:return Ar(f,p);default:return xr(f,p)}}function K(f,p){switch(f.length){case 0:return Gt();case 1:return wr(f,p);case 2:return Na(f,p);case 3:return Zt(f,p);case 4:return kn(f,p);case 5:return pn(f,p);case 6:return zn(f,p);default:throw new Error(f.length+"-D output sampling is not yet supported")}}function Se(f){return `
float sampleTexture ( sampler2D textureSampler , vec2 uv ) {
return ` +f.texture2D+ ` ( textureSampler , uv ) . r ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function be(f){return `
void setOutput ( float val ) {
` +f.output+ ` = vec4 ( val , 0 , 0 , 0 ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function Je(f){return `
void setOutput ( vec4 val ) {
` +f.output+ ` = val ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function Pe(f){var p=f.version+ `
precision highp float ;
precision highp int ;
precision highp sampler2D ;
` +f.varyingFs+ ` vec2 resultUV ;
` +f.defineOutput+ `
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 ;
` +f.defineSpecialNaN+ `
` +f.defineSpecialInf+ `
` +f.defineRound+ `
int imod ( int x , int y ) {
return x - y * ( x / y ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +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 ;
}
return res ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +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-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` +gt+ `
` +ft+ `
` +Lt+ `
` ;return p}var gt= `
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 ) ;
}
` ,ft= `
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 ) ;
}
` ,Lt= `
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 ) ;
}
` ,Wt= `
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-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
float getChannel ( vec4 frag , int dim ) {
float modCoord = mod ( float ( dim ) , 2. ) ;
return modCoord == 0. ? frag . r : frag . g ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ;function Gt(){return `
int getOutputCoords ( ) {
return 0 ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function Jt(f,p){var l=[Math.ceil(p[0]/2),Math.ceil(p[1]/2)];return l[0]===1? `
int getOutputCoords ( ) {
return 2 * int ( resultUV . x * ` +l[1]+ ` . 0 ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` :l[1]===1? `
int getOutputCoords ( ) {
return 2 * int ( resultUV . y * ` +l[0]+ ` . 0 ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` : `
int getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +l[0]+", "+l[1]+ ` ) ) ;
return 2 * ( resTexRC . x * ` +l[1]+ ` + resTexRC . y ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` }function wr(f,p){return p[0]===1? `
int getOutputCoords ( ) {
return int ( resultUV . x * ` +p[1]+ ` . 0 ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` :p[1]===1? `
int getOutputCoords ( ) {
return int ( resultUV . y * ` +p[0]+ ` . 0 ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` : `
int getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +p[0]+", "+p[1]+ ` ) ) ;
return resTexRC . x * ` +p[1]+ ` + resTexRC . y ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function Ar(f,p){var l=[Math.ceil(p[0]/2),Math.ceil(p[1]/2)],m=Math.ceil(f[2]/2),g=m*Math.ceil(f[1]/2);return `
ivec3 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +l[0]+", "+l[1]+ ` ) ) ;
int index = resTexRC . x * ` +l[1]+ ` + resTexRC . y ;
int b = index / ` +g+ ` ;
index -= b * ` +g+ ` ;
int r = 2 * ( index / ` +m+ ` ) ;
int c = imod ( index , ` +m+ ` ) * 2 ;
return ivec3 ( b , r , c ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` }function Zt(f,p){var l=En(["r","c","d"],f);return `
ivec3 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +p[0]+", "+p[1]+ ` ) ) ;
int index = resTexRC . x * ` +p[1]+ ` + resTexRC . y ;
` +l+ `
return ivec3 ( r , c , d ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function xr(f,p){for(var l=[Math.ceil(p[0]/2),Math.ceil(p[1]/2)],m=Math.ceil(f[f.length-1]/2),g=m*Math.ceil(f[f.length-2]/2),I=g,R="",P="b, r, c",L=2;L<f.length-1;L++)I*=f[f.length-L-1],R= `
int b ` +L+" = index / "+I+ ` ;
index -= b ` +L+" * "+I+ ` ;
` +R,P="b"+L+", "+P;return `
ivec ` +f.length+ ` getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +l[0]+", "+l[1]+ ` ) ) ;
int index = resTexRC . x * ` +l[1]+ ` + resTexRC . y ;
` +R+ `
int b = index / ` +g+ ` ;
index -= b * ` +g+ ` ;
int r = 2 * ( index / ` +m+ ` ) ;
int c = imod ( index , ` +m+ ` ) * 2 ;
return ivec ` +f.length+"("+P+ ` ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` }function kn(f,p){var l=En(["r","c","d","d2"],f);return `
ivec4 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +p[0]+", "+p[1]+ ` ) ) ;
int index = resTexRC . x * ` +p[1]+ ` + resTexRC . y ;
` +l+ `
return ivec4 ( r , c , d , d2 ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function pn(f,p){var l=En(["r","c","d","d2","d3"],f);return `
ivec5 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx * vec2 ( ` +p[0]+ ` ,
` +p[1]+ ` ) ) ;
int index = resTexRC . x * ` +p[1]+ ` + resTexRC . y ;
` +l+ `
ivec5 outShape = ivec5 ( r , c , d , d2 , d3 ) ;
return outShape ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` }function zn(f,p){var l=En(["r","c","d","d2","d3","d4"],f);return `
ivec6 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +p[0]+", "+p[1]+ ` ) ) ;
int index = resTexRC . x * ` +p[1]+ ` + resTexRC . y ;
` +l+ `
ivec6 result = ivec6 ( r , c , d , d2 , d3 , d4 ) ;
return result ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function Dr(f,p){var l=[Math.ceil(p[0]/2),Math.ceil(p[1]/2)];if(i.util.arraysEqual(f,p))return `
ivec2 getOutputCoords ( ) {
return 2 * ivec2 ( resultUV . yx * vec2 ( ` +l[0]+", "+l[1]+ ` ) ) ;
}
` ;var m=Math.ceil(f[1]/2);return `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +l[0]+", "+l[1]+ ` ) ) ;
int index = resTexRC . x * ` +l[1]+ ` + resTexRC . y ;
int r = 2 * ( index / ` +m+ ` ) ;
int c = imod ( index , ` +m+ ` ) * 2 ;
return ivec2 ( r , c ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function Na(f,p){return i.util.arraysEqual(f,p)? `
ivec2 getOutputCoords ( ) {
return ivec2 ( resultUV . yx * vec2 ( ` +p[0]+", "+p[1]+ ` ) ) ;
}
` :f[1]===1? `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +p[0]+", "+p[1]+ ` ) ) ;
int index = resTexRC . x * ` +p[1]+ ` + resTexRC . y ;
return ivec2 ( index , 0 ) ;
}
` :f[0]===1? `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +p[0]+", "+p[1]+ ` ) ) ;
int index = resTexRC . x * ` +p[1]+ ` + resTexRC . y ;
return ivec2 ( 0 , index ) ;
}
` : `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +p[0]+", "+p[1]+ ` ) ) ;
int index = resTexRC . x * ` +p[1]+ ` + resTexRC . y ;
int r = index / ` +f[1]+ ` ;
int c = index - r * ` +f[1]+ ` ;
return ivec2 ( r , c ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` }function Sn(f){return"offset"+f}function cr(f){var p=f.name,l="get"+p.charAt(0).toUpperCase()+p.slice(1),m=tn();return `
vec4 ` +l+ ` ( ) {
return ` +m.texture2D+"("+p+ ` , halfCR ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function $ r(f){var p=f.name,l="get"+p.charAt(0).toUpperCase()+p.slice(1);if(f.shapeInfo.isUniform)return"float "+l+"() {return "+p+";}";var m=f.shapeInfo.texShape,g=m[0],I=m[1];if(g===1&&I===1)return `
float ` +l+ ` ( ) {
return sampleTexture ( ` +p+ ` , halfCR ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` ;var R=f.shapeInfo.texShape,P=R[0],L=R[1],G=Sn(p);return `
float ` +l+ ` ( ) {
vec2 uv = uvFromFlat ( ` +P+", "+L+", "+G+ ` ) ;
return sampleTexture ( ` +p+ ` , uv ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` }function Fa(f){var p=f.name,l="get"+p.charAt(0).toUpperCase()+p.slice(1),m=f.shapeInfo.texShape,g=[Math.ceil(m[0]/2),Math.ceil(m[1]/2)],I=tn();return `
vec4 ` +l+ ` ( int index ) {
vec2 uv = packedUVfrom1D (
` +g[0]+", "+g[1]+ ` , index ) ;
return ` +I.texture2D+"("+p+ ` , uv ) ;
}
` }function mi(f){var p=f.name,l="get"+p.charAt(0).toUpperCase()+p.slice(1);if(f.shapeInfo.isUniform)return `
float ` +l+ ` ( int index ) {
` +oi(f)+ `
}
` ;var m=f.shapeInfo.texShape,g=m[0],I=m[1];if(I===1&&g===1)return `
float ` +l+ ` ( int index ) {
return sampleTexture ( ` +p+ ` , halfCR ) ;
}
` ;var R=Sn(p);return I===1? `
float ` +l+ ` ( int index ) {
vec2 uv = vec2 ( 0.5 , ( float ( index + ` +R+") + 0.5) / "+g+ ` . 0 ) ;
return sampleTexture ( ` +p+ ` , uv ) ;
}
` :g===1? `
float ` +l+ ` ( int index ) {
vec2 uv = vec2 ( ( float ( index + ` +R+") + 0.5) / "+I+ ` . 0 , 0.5 ) ;
return sampleTexture ( ` +p+ ` , uv ) ;
}
` : `
float ` +l+ ` ( int index ) {
vec2 uv = uvFromFlat ( ` +g+", "+I+", index + "+R+ ` ) ;
return sampleTexture ( ` +p+ ` , uv ) ;
}
` }function Ka(f){var p=f.shapeInfo.logicalShape,l=f.name,m="get"+l.charAt(0).toUpperCase()+l.slice(1),g=f.shapeInfo.texShape,I=g[0],R=g[1],P=tn();if(g!=null&&i.util.arraysEqual(p,g))return `
vec4 ` +m+ ` ( int row , int col ) {
vec2 uv = ( vec2 ( col , row ) + halfCR ) / vec2 ( ` +R+".0, "+I+ ` . 0 ) ;
return ` +P.texture2D+"("+l+ ` , uv ) ;
}
` ;var L=[Math.ceil(g[0]/2),Math.ceil(g[1]/2)],G=Math.ceil(p[1]/2);return `
vec4 ` +m+ ` ( int row , int col ) {
vec2 uv = packedUVfrom2D ( ` +G+", "+L[0]+", "+L[1]+ ` , row , col ) ;
return ` +P.texture2D+"("+l+ ` , uv ) ;
}
` }function Xa(f){var p=f.shapeInfo.logicalShape,l=f.name,m="get"+l.charAt(0).toUpperCase()+l.slice(1),g=f.shapeInfo.texShape;if(g!=null&&i.util.arraysEqual(p,g)){var I=g[0],R=g[1];return `
float ` +m+ ` ( int row , int col ) {
vec2 uv = ( vec2 ( col , row ) + halfCR ) / vec2 ( ` +R+".0, "+I+ ` . 0 ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
}
` }var P=i.util.squeezeShape(p),L=P.newShape,G=P.keptDims,Q=L;if(Q.length<p.length){var ke=Ya(f,Q),Ce=["row","col"];return `
` +Aa(ke)+ `
float ` +m+ ` ( int row , int col ) {
return ` +m+"("+Ba(Ce,G)+ ` ) ;
}
` }if(f.shapeInfo.isUniform)return `
float ` +m+ ` ( int row , int col ) {
int index = round ( dot ( vec2 ( row , col ) , vec2 ( ` +p[1]+ ` , 1 ) ) ) ;
` +oi(f)+ `
}
` ;var Fe=g[0],Ee=g[1],Ge=Sn(l);return Ee===1? `
float ` +m+ ` ( int row , int col ) {
float index = dot ( vec3 ( row , col , ` +Ge+"), vec3("+p[1]+ ` , 1 , 1 ) ) ;
vec2 uv = vec2 ( 0.5 , ( index + 0.5 ) / ` +Fe+ ` . 0 ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
}
` :Fe===1? `
float ` +m+ ` ( int row , int col ) {
float index = dot ( vec3 ( row , col , ` +Ge+"), vec3("+p[1]+ ` , 1 , 1 ) ) ;
vec2 uv = vec2 ( ( index + 0.5 ) / ` +Ee+ ` . 0 , 0.5 ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
}
` : `
float ` +m+ ` ( int row , int col ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * ` +p[1]+" + col + "+Ge+ ` ;
vec2 uv = uvFromFlat ( ` +Fe+", "+Ee+ ` , index ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function ii(f){var p=f.shapeInfo.logicalShape,l=f.name,m="get"+l.charAt(0).toUpperCase()+l.slice(1),g=f.shapeInfo.texShape,I=[Math.ceil(g[0]/2),Math.ceil(g[1]/2)];if(p[0]===1){var R=p.slice(1),P=[1,2],L=Ya(f,R),G=["b","row","col"];return `
` +S(L)+ `
vec4 ` +m+ ` ( int b , int row , int col ) {
return ` +m+"("+Ba(G,P)+ ` ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
` }var Q=I[0],ke=I[1],Ce=Math.ceil(p[2]/2),Fe=Ce*Math.ceil(p[1]/2),Ee=tn();return `
vec4 ` +m+ ` ( int b , int row , int col ) {
vec2 uv = packedUVfrom3D (
` +Q+", "+ke+", "+Fe+", "+Ce+ ` , b , row , col ) ;
return ` +Ee.texture2D+"("+l+ ` , uv ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function zi(f){var p=f.shapeInfo.logicalShape,l=f.name,m="get"+l.charAt(0).toUpperCase()+l.slice(1),g=p[1]*p[2],I=p[2],R=i.util.squeezeShape(p),P=R.newShape,L=R.keptDims,G=P;if(G.length<p.length){var Q=Ya(f,G),ke=["row","col","depth"];return `
` +Aa(Q)+ `
float ` +m+ ` ( int row , int col , int depth ) {
return ` +m+"("+Ba(ke,L)+ ` ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }if(f.shapeInfo.isUniform)return `
float ` +m+ ` ( int row , int col , int depth ) {
int index = round ( dot ( vec3 ( row , col , depth ) ,
vec3 ( ` +g+", "+I+ ` , 1 ) ) ) ;
` +oi(f)+ `
}
` ;var Ce=f.shapeInfo.texShape,Fe=Ce[0],Ee=Ce[1],Ge=f.shapeInfo.flatOffset;if(Ee===g&&Ge==null)return `
float ` +m+ ` ( int row , int col , int depth ) {
float texR = float ( row ) ;
float texC = dot ( vec2 ( col , depth ) , vec2 ( ` +I+ ` , 1 ) ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( ` +Ee+".0, "+Fe+ ` . 0 ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
}
` ;if(Ee===I&&Ge==null)return `
float ` +m+ ` ( int row , int col , int depth ) {
float texR = dot ( vec2 ( row , col ) , vec2 ( ` +p[1]+ ` , 1 ) ) ;
float texC = float ( depth ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) / vec2 ( ` +Ee+".0, "+Fe+ ` . 0 ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ;var Qe=Sn(l);return `
float ` +m+ ` ( int row , int col , int depth ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * ` +g+" + col * "+I+" + depth + "+Qe+ ` ;
vec2 uv = uvFromFlat ( ` +Fe+", "+Ee+ ` , index ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
}
` }function Rn(f){for(var p=f.shapeInfo.logicalShape,l=p.length,m=f.name,g="get"+m.charAt(0).toUpperCase()+m.slice(1),I=f.shapeInfo.texShape,R=[Math.ceil(I[0]/2),Math.ceil(I[1]/2)],P=R[0],L=R[1],G=Math.ceil(p[l-1]/2),Q=G*Math.ceil(p[l-2]/2),ke="int b, int row, int col",Ce="b * "+Q+" + (row / 2) * "+G+" + (col / 2)",Fe=2;Fe<l-1;Fe++)ke="int b"+Fe+", "+ke,Q*=p[l-Fe-1],Ce="b"+Fe+" * "+Q+" + "+Ce;var Ee=tn();return `
vec4 ` +g+"("+ke+ ` ) {
int index = ` +Ce+ ` ;
int texR = index / ` +L+ ` ;
int texC = index - texR * ` +L+ ` ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) / vec2 ( ` +L+", "+P+ ` ) ;
return ` +Ee.texture2D+"("+m+ ` , uv ) ;
}
` }function Ca(f){var p=f.shapeInfo.logicalShape,l=f.name,m="get"+l.charAt(0).toUpperCase()+l.slice(1),g=p[3],I=p[2]*g,R=p[1]*I,P=i.util.squeezeShape(p),L=P.newShape,G=P.keptDims;if(L.length<p.length){var Q=Ya(f,L),ke=["row","col","depth","depth2"];return `
` +Aa(Q)+ `
float ` +m+ ` ( int row , int col , int depth , int depth2 ) {
return ` +m+"("+Ba(ke,G)+ ` ) ;
}
` }if(f.shapeInfo.isUniform)return `
float ` +m+ ` ( int row , int col , int depth , int depth2 ) {
int index = round ( dot ( vec4 ( row , col , depth , depth2 ) ,
vec4 ( ` +R+", "+I+", "+g+ ` , 1 ) ) ) ;
` +oi(f)+ `
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ;var Ce=f.shapeInfo.flatOffset,Fe=f.shapeInfo.texShape,Ee=Fe[0],Ge=Fe[1];if(Ge===R&&Ce==null)return `
float ` +m+ ` ( int row , int col , int depth , int depth2 ) {
float texR = float ( row ) ;
float texC =
dot ( vec3 ( col , depth , depth2 ) ,
vec3 ( ` +I+", "+g+ ` , 1 ) ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( ` +Ge+".0, "+Ee+ ` . 0 ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ;if(Ge===g&&Ce==null)return `
float ` +m+ ` ( int row , int col , int depth , int depth2 ) {
float texR = dot ( vec3 ( row , col , depth ) ,
vec3 ( ` +p[1]*p[2]+", "+p[2]+ ` , 1 ) ) ;
float texC = float ( depth2 ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( ` +Ge+".0, "+Ee+ ` . 0 ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` ;var Qe=Sn(l);return `
float ` +m+ ` ( int row , int col , int depth , int depth2 ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * ` +R+" + col * "+I+ ` +
depth * ` +g+ ` + depth2 ;
vec2 uv = uvFromFlat ( ` +Ee+", "+Ge+", index + "+Qe+ ` ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
}
` }function Ki(f){var p=f.shapeInfo.logicalShape,l=f.name,m="get"+l.charAt(0).toUpperCase()+l.slice(1),g=p[4],I=p[3]*g,R=p[2]*I,P=p[1]*R,L=i.util.squeezeShape(p),G=L.newShape,Q=L.keptDims;if(G.length<p.length){var ke=Ya(f,G),Ce=["row","col","depth","depth2","depth3"];return `
` +Aa(ke)+ `
float ` +m+ ` ( int row , int col , int depth , int depth2 , int depth3 ) {
return ` +m+"("+Ba(Ce,Q)+ ` ) ;
}
` }if(f.shapeInfo.isUniform)return `
float ` +m+ ` ( int row , int col , int depth , int depth2 , int depth3 ) {
float index = dot (
vec4 ( row , col , depth , depth2 ) ,
vec4 ( ` +P+", "+R+", "+I+", "+g+ ` ) ) +
depth3 ;
` +oi(f)+ `
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` ;var Fe=f.shapeInfo.flatOffset,Ee=f.shapeInfo.texShape,Ge=Ee[0],Qe=Ee[1];if(Qe===P&&Fe==null)return `
float ` +m+ ` ( int row , int col , int depth , int depth2 , int depth3 ) {
int texR = row ;
float texC = dot ( vec4 ( col , depth , depth2 , depth3 ) ,
vec4 ( ` +R+", "+I+", "+g+ ` , 1 ) ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( ` +Qe+".0, "+Ge+ ` . 0 ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ;if(Qe===g&&Fe==null)return `
float ` +m+ ` ( int row , int col , int depth , int depth2 , int depth3 ) {
float texR = dot (
vec4 ( row , col , depth , depth2 ) ,
vec4 ( ` +p[1]*p[2]*p[3]+ ` ,
` +p[2]*p[3]+", "+p[3]+ ` , 1 ) ) ;
int texC = depth3 ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( ` +Qe+".0, "+Ge+ ` . 0 ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` ;var s=Sn(l);return `
float ` +m+ ` ( int row , int col , int depth , int depth2 , int depth3 ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * ` +P+" + col * "+R+" + depth * "+I+ ` +
depth2 * ` +g+" + depth3 + "+s+ ` ;
vec2 uv = uvFromFlat ( ` +Ge+", "+Qe+ ` , index ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
}
` }function yi(f){var p=f.shapeInfo.logicalShape,l=f.name,m="get"+l.charAt(0).toUpperCase()+l.slice(1),g=i.util.squeezeShape(p),I=g.newShape,R=g.keptDims;if(I.length<p.length){var P=Ya(f,I),L=["row","col","depth","depth2","depth3","depth4"];return `
` +Aa(P)+ `
float ` +m+ ` ( int row , int col , int depth ,
int depth2 , int depth3 , int depth4 ) {
return ` +m+"("+Ba(L,R)+ ` ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }var G=p[5],Q=p[4]*G,ke=p[3]*Q,Ce=p[2]*ke,Fe=p[1]*Ce;if(f.shapeInfo.isUniform)return `
float ` +m+ ` ( int row , int col , int depth ,
int depth2 , int depth3 , int depth4 ) {
int index = round ( dot (
vec4 ( row , col , depth , depth2 ) ,
vec4 ( ` +Fe+", "+Ce+", "+ke+", "+Q+ ` ) ) +
dot (
vec2 ( depth3 , depth4 ) ,
vec2 ( ` +G+ ` , 1 ) ) ) ;
` +oi(f)+ `
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` ;var Ee=f.shapeInfo.flatOffset,Ge=f.shapeInfo.texShape,Qe=Ge[0],s=Ge[1];if(s===Fe&&Ee==null)return `
float ` +m+ ` ( int row , int col , int depth ,
int depth2 , int depth3 , int depth4 ) {
int texR = row ;
float texC = dot ( vec4 ( col , depth , depth2 , depth3 ) ,
vec4 ( ` +Ce+", "+ke+", "+Q+", "+G+ ` ) ) +
float ( depth4 ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( ` +s+".0, "+Qe+ ` . 0 ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
}
` ;if(s===G&&Ee==null)return `
float ` +m+ ` ( int row , int col , int depth ,
int depth2 , int depth3 , int depth4 ) {
float texR = dot ( vec4 ( row , col , depth , depth2 ) ,
vec4 ( ` +p[1]*p[2]*p[3]*p[4]+ ` ,
` +p[2]*p[3]*p[4]+ ` ,
` +p[3]*p[4]+ ` ,
` +p[4]+ ` ) ) + float ( depth3 ) ;
int texC = depth4 ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( ` +s+".0, "+Qe+ ` . 0 ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
}
` ;var u=Sn(l);return `
float ` +m+ ` ( int row , int col , int depth ,
int depth2 , int depth3 , int depth4 ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * ` +Fe+" + col * "+Ce+" + depth * "+ke+ ` +
depth2 * ` +Q+" + depth3 * "+G+" + depth4 + "+u+ ` ;
vec2 uv = uvFromFlat ( ` +Qe+", "+s+ ` , index ) ;
return sampleTexture ( ` +l+ ` , uv ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }function oi(f){var p=f.name,l=i.util.sizeFromShape(f.shapeInfo.logicalShape);return l<2?"return "+p+";": `
for ( int i = 0 ; i < ` +l+ ` ; i ++ ) {
if ( i == index ) {
return ` +p+ ` [ i ] ;
2020-11-06 22:21:20 +01:00
}
}
2020-11-07 16:37:19 +01:00
` }function qr(f,p){var l=f.name,m=l.charAt(0).toUpperCase()+l.slice(1),g="get"+m+"AtOutCoords",I=f.shapeInfo.logicalShape.length,R=p.logicalShape.length,P=ga(f.shapeInfo.logicalShape,p.logicalShape),L=nn(R),G=R-I,Q,ke=["x","y","z","w","u","v"];I===0?Q="":R<2&&P.length>=1?Q="coords = 0;":Q=P.map(function(o){return"coords."+ke[o+G]+" = 0;"}).join( `
` );var Ce="";R<2&&I>0?Ce="coords":Ce=f.shapeInfo.logicalShape.map(function(o,h){return"coords."+ke[h+G]}).join(", ");var Fe="return outputValue;",Ee=i.util.sizeFromShape(f.shapeInfo.logicalShape),Ge=Ee===1,Qe=i.util.sizeFromShape(p.logicalShape),s=Qe===1;if(I===1&&!Ge&&!s)Fe= `
return vec4 ( outputValue . xy , outputValue . xy ) ;
` ;else if(Ge&&!s)R===1?Fe= `
return vec4 ( outputValue . x , outputValue . x , 0. , 0. ) ;
` :Fe= `
return vec4 ( outputValue . x ) ;
` ;else if(P.length){var u=I-2,r=I-1;P.indexOf(u)>-1&&P.indexOf(r)>-1?Fe="return vec4(outputValue.x);":P.indexOf(u)>-1?Fe="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":P.indexOf(r)>-1&&(Fe="return vec4(outputValue.xx, outputValue.zz);")}return `
vec4 ` +g+ ` ( ) {
` +L+ ` coords = getOutputCoords ( ) ;
` +Q+ `
vec4 outputValue = get ` +m+"("+Ce+ ` ) ;
` +Fe+ `
}
` }function Io(f,p){var l=f.name,m=l.charAt(0).toUpperCase()+l.slice(1),g="get"+m+"AtOutCoords",I=p.texShape,R=f.shapeInfo.texShape,P=f.shapeInfo.logicalShape.length,L=p.logicalShape.length;if(!f.shapeInfo.isUniform&&P===L&&f.shapeInfo.flatOffset==null&&i.util.arraysEqual(R,I))return `
float ` +g+ ` ( ) {
return sampleTexture ( ` +l+ ` , resultUV ) ;
}
` ;var G=nn(L),Q=ga(f.shapeInfo.logicalShape,p.logicalShape),ke=L-P,Ce,Fe=["x","y","z","w","u","v"];P===0?Ce="":L<2&&Q.length>=1?Ce="coords = 0;":Ce=Q.map(function(Ge){return"coords."+Fe[Ge+ke]+" = 0;"}).join( `
` );var Ee="";return L<2&&P>0?Ee="coords":Ee=f.shapeInfo.logicalShape.map(function(Ge,Qe){return"coords."+Fe[Qe+ke]}).join(", "), `
float ` +g+ ` ( ) {
` +G+ ` coords = getOutputCoords ( ) ;
` +Ce+ `
return get ` +m+"("+Ee+ ` ) ;
}
` }function nn(f){if(f<=1)return"int";if(f===2)return"ivec2";if(f===3)return"ivec3";if(f===4)return"ivec4";if(f===5)return"ivec5";if(f===6)return"ivec6";throw Error("GPU for rank "+f+" is not yet supported")}function Ya(f,p){var l=JSON.parse(JSON.stringify(f));return l.shapeInfo.logicalShape=p,l}function Ba(f,p){return p.map(function(l){return f[l]}).join(", ")}var Xi=function(){function f(p,l,m,g){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,i.util.assert(p.length>2,function(){return"Packed arg"+(m.charAt(0).toUpperCase()+m.slice(1))+" supports only inputs with rank above 2."});var I=p[p.length-1],R=Math.ceil(I/l);this.outputShape=p.slice(0,-1),R>1&&this.outputShape.push(R),g||this.variableNames.push("bestIndicesA");var P=this.outputShape,L=P.length,G=nn(L),Q=Vr("coords",L),ke,Ce;if(R===1){Ce=L+1;var Fe=nn(Ce);ke= `
` +Fe+" sourceLocR = "+Fe+"("+Q.join()+ ` , 0 ) ;
++ ` +Q[L-1]+ ` ;
` +Fe+" sourceLocG = "+Fe+"("+Q.join()+ ` , 0 ) ;
++ ` +Q[L-2]+ ` ;
` +Fe+" sourceLocA = "+Fe+"("+Q.join()+ ` , 0 ) ;
-- ` +Q[L-1]+ ` ;
` +Fe+" sourceLocB = "+Fe+"("+Q.join()+ ` , 0 ) ;
-- ` +Q[L-2]+";"}else Ce=L,ke= `
` +G+ ` sourceLocR = coords ;
++ ` +Q[L-1]+ ` ;
` +G+ ` sourceLocG = coords ;
++ ` +Q[L-2]+ ` ;
` +G+ ` sourceLocA = coords ;
-- ` +Q[L-1]+ ` ;
` +G+ ` sourceLocB = coords ;
-- ` +Q[L-2]+";";var Ee=["x","y","z","w","u","v"].slice(0,Ce),Ge="."+Ee[Ce-1],Qe=Ee.map(function(q){return"int "+q}),s=Vr("sourceLocR",Ce-1).concat("inIdx.r"),u=Vr("sourceLocG",Ce-1).concat("inIdx.g"),r=Vr("sourceLocB",Ce-1).concat("inIdx.b"),o=Vr("sourceLocA",Ce-1).concat("inIdx.a"),h=m==="max"?"greaterThan":"lessThan",b=g?"": `
inIdx = round ( vec4 ( getBestIndicesAChannel ( ` +s.join()+ ` ) ,
getBestIndicesAChannel ( ` +u.join()+ ` ) ,
getBestIndicesAChannel ( ` +r.join()+ ` ) ,
getBestIndicesAChannel ( ` +o.join()+")));",T= ` vec4 (
getAChannel ( ` +s.join()+ ` ) ,
hasNextCol ? getAChannel ( ` +u.join()+ ` ) : 0. ,
hasNextRow ? getAChannel ( ` +r.join()+ ` ) : 0. ,
hasNextRow && hasNextCol ? getAChannel ( ` +o.join()+") : 0.)",O=g?"": `
float getBestIndicesAChannel ( ` +Qe.join()+ ` ) {
return getChannel ( getBestIndicesA ( ` +Ee.join()+ ` ) ,
vec2 ( ` +Ee.slice(-2).join()+ ` ) ) ;
} ` ;this.userCode= `
float getAChannel ( ` +Qe.join()+ ` ) {
return getChannel ( getA ( ` +Ee.join()+ ` ) ,
vec2 ( ` +Ee.slice(-2).join()+ ` ) ) ;
}
` +O+ `
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
` +G+ ` coords = getOutputCoords ( ) ;
bool hasNextCol = ` +Q[L-1]+" < "+(P[L-1]-1)+ ` ;
bool hasNextRow = ` +Q[L-2]+" < "+(P[L-2]-1)+ ` ;
` +ke+ `
ivec4 srcIdx = ivec4 ( sourceLocR ` +Ge+", sourceLocG"+Ge+ ` ,
sourceLocB ` +Ge+", sourceLocA"+Ge+") * "+l+ ` ;
ivec4 inIdx = srcIdx ;
vec4 bestIndex = vec4 ( inIdx ) ;
vec4 bestValue = ` +T+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int i = 0 ; i < ` +l+ ` ; i ++ ) {
inIdx = srcIdx ;
` +b+ `
vec4 candidate = ` +T+ ` ;
bvec4 nan = isnan ( candidate ) ;
bvec4 replace = bvec4 (
vec4 ( ` +h+ ` ( candidate , bestValue ) ) * ( vec4 ( 1.0 ) - vec4 ( nan ) ) ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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 ++ ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
setOutput ( bestIndex ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),si=function(){function f(p){this.variableNames=["dy"],this.outputShape=p.inShape;var l=p.filterHeight,m=p.filterWidth,g=p.strideHeight,I=p.strideWidth,R=p.dilationHeight,P=p.dilationWidth,L=p.effectiveFilterHeight,G=p.effectiveFilterWidth,Q=L-1-p.padInfo.top,ke=G-1-p.padInfo.left,Ce=1/(l*m);this.userCode= `
const ivec2 pads = ivec2 ( ` +Q+", "+ke+ ` ) ;
const float avgMultiplier = float ( ` +Ce+ ` ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
ivec2 dyRCCorner = coords . yz - pads ;
int dyRCorner = dyRCCorner . x ;
int dyCCorner = dyRCCorner . y ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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 ;
for ( int wR = 0 ; wR < ` +L+ ` ;
wR += ` +R+ ` ) {
float dyR = float ( dyRCorner + wR ) / ` +g+ ` . 0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( dyR < 0.0 || dyR >= ` +p.outHeight+ ` . 0 || fract ( dyR ) > 0.0 ) {
continue ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
int idyR = int ( dyR ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wC = 0 ; wC < ` +G+ ` ;
wC += ` +P+ ` ) {
float dyC = float ( dyCCorner + wC ) / ` +I+ ` . 0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( dyC < 0.0 || dyC >= ` +p.outWidth+ ` . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float dyValue = getDy ( b , idyR , idyC , d ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
dotProd += dyValue * avgMultiplier ;
2020-11-06 19:50:16 +01:00
}
}
2020-11-07 16:37:19 +01:00
setOutput ( dotProd ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Li=function(){function f(p){this.variableNames=["dy"],this.outputShape=p.inShape;var l=p.filterDepth,m=p.filterHeight,g=p.filterWidth,I=p.strideDepth,R=p.strideHeight,P=p.strideWidth,L=p.dilationDepth,G=p.dilationHeight,Q=p.dilationWidth,ke=p.effectiveFilterDepth,Ce=p.effectiveFilterHeight,Fe=p.effectiveFilterWidth,Ee=ke-1-p.padInfo.front,Ge=Ce-1-p.padInfo.top,Qe=Fe-1-p.padInfo.left,s=1/(l*m*g);this.userCode= `
const ivec3 pads = ivec3 ( ` +Ee+", "+Ge+", "+Qe+ ` ) ;
const float avgMultiplier = float ( ` +s+ ` ) ;
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 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get
// dx(xD, xR, xC, ch).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wD = 0 ; wD < ` +ke+ ` ;
wD += ` +L+ ` ) {
float dyD = float ( dyDCorner + wD ) / ` +I+ ` . 0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( dyD < 0.0 || dyD >= ` +p.outDepth+ ` . 0 || fract ( dyD ) > 0.0 ) {
continue ;
}
int idyD = int ( dyD ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wR = 0 ; wR < ` +Ce+ ` ;
wR += ` +G+ ` ) {
float dyR = float ( dyRCorner + wR ) / ` +R+ ` . 0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( dyR < 0.0 || dyR >= ` +p.outHeight+ ` . 0 ||
fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wC = 0 ; wC < ` +Fe+ ` ;
wC += ` +Q+ ` ) {
float dyC = float ( dyCCorner + wC ) / ` +P+ ` . 0 ;
if ( dyC < 0.0 || dyC >= ` +p.outWidth+ ` . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
int idyC = int ( dyC ) ;
float dyValue = getDy ( batch , idyD , idyR , idyC , ch ) ;
dotProd += dyValue * avgMultiplier ;
2020-11-06 19:50:16 +01:00
}
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
}
setOutput ( dotProd ) ;
}
` }return f}(),ao= `
if ( isnan ( a ) ) return a ;
if ( isnan ( b ) ) return b ;
` ,mo= `
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 ;
}
` ,Za= `
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 ) ;
` ,io="return float(a == b);",Yo="return float(a < b);",No="return float(a <= b);",Co="return float(a > b);",oo="return float(a >= b);",ua="return float(a >= 1.0 && b >= 1.0);",Br="return float(a >= 1.0 || b >= 1.0);",ca=ao+ `
return max ( a , b ) ;
` ,Qa=ao+ `
return min ( a , b ) ;
` ,Zn= ` if ( b == 0.0 ) return NAN ;
return mod ( a , b ) ; ` ,so="return (b >= 1.0) ? a : a * (b + 1.0);",Ta="return (a < 0.) ? b * a : a;",vn=function(){function f(p,l,m){this.variableNames=["A","B"],this.outputShape=i.backend_util.assertAndGetBroadcastShape(l,m),this.userCode= `
float binaryOperation ( float a , float b ) {
` +p+ `
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
float a = getAAtOutCoords ( ) ;
float b = getBAtOutCoords ( ) ;
setOutput ( binaryOperation ( a , b ) ) ;
}
` }return f}(),Pi= `
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 ;
` ,yo= `
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-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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 ) ;
` ,vo= `
// 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 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// 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 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 isNaN = vec4 ( lessThan ( a , vec4 ( 0.0 ) ) ) * vec4 ( lessThan ( floor ( b ) , b ) ) ;
` +Pi+ `
return result ;
` ,Da= `
vec4 aLessThanZero = vec4 ( lessThan ( a , vec4 ( 0. ) ) ) ;
return ( aLessThanZero * ( b * a ) ) + ( ( vec4 ( 1.0 ) - aLessThanZero ) * a ) ;
` ,go= `
vec4 bGTEZero = vec4 ( greaterThanEqual ( b , vec4 ( 0. ) ) ) ;
return ( bGTEZero * a ) + ( ( vec4 ( 1.0 ) - bGTEZero ) * ( a * ( b + vec4 ( 1.0 ) ) ) ) ;
` ,To= `
return vec4 ( equal ( a , b ) ) ;
` ,Es= `
return vec4 ( lessThan ( a , b ) ) ;
` ,Eo= `
return vec4 ( lessThanEqual ( a , b ) ) ;
` ,Rs= `
return vec4 ( greaterThan ( a , b ) ) ;
` ,As= `
return vec4 ( greaterThanEqual ( a , b ) ) ;
` ,Zo= `
return vec4 (
vec4 ( greaterThanEqual ( a , vec4 ( 1.0 ) ) ) *
vec4 ( greaterThanEqual ( b , vec4 ( 1.0 ) ) ) ) ;
` ,Ro= `
return min (
vec4 ( greaterThanEqual ( a , vec4 ( 1.0 ) ) ) +
vec4 ( greaterThanEqual ( b , vec4 ( 1.0 ) ) ) ,
vec4 ( 1.0 ) ) ;
` ,Qo= `
vec4 result = vec4 ( max ( a , b ) ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
` +Pi+ `
return result ;
` ,Ao= `
vec4 result = vec4 ( min ( a , b ) ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
` +Pi+ `
return result ;
` ,Jo= `
vec4 result = mod ( a , b ) ;
vec4 isNaN = vec4 ( equal ( b , vec4 ( 0.0 ) ) ) ;
` +Pi+ `
return result ;
` ,vi=function(){function f(p,l,m,g){g===void 0&&(g=!1),this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.packedInputs=!0,this.packedOutput=!0,this.outputShape=i.backend_util.assertAndGetBroadcastShape(l,m);var I=this.outputShape.length,R="";if(g)if(I===0||i.util.sizeFromShape(this.outputShape)===1)R= `
result . y = 0. ;
result . z = 0. ;
result . w = 0. ;
` ;else{var P=nn(I);if(R= `
` +P+ ` coords = getOutputCoords ( ) ;
` ,I===1)R+= `
result . y = ( coords + 1 ) >= ` +this.outputShape[0]+ ` ? 0. : result . y ;
result . z = 0. ;
result . w = 0. ;
` ;else{var L=Vr("coords",I);R+= `
bool nextRowOutOfBounds =
( ` +L[I-2]+" + 1) >= "+this.outputShape[I-2]+ ` ;
bool nextColOutOfBounds =
( ` +L[I-1]+" + 1) >= "+this.outputShape[I-1]+ ` ;
result . y = nextColOutOfBounds ? 0. : result . y ;
result . z = nextRowOutOfBounds ? 0. : result . z ;
result . w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result . w ;
` }}this.userCode= `
vec4 binaryOperation ( vec4 a , vec4 b ) {
` +p+ `
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
vec4 a = getAAtOutCoords ( ) ;
vec4 b = getBAtOutCoords ( ) ;
vec4 result = binaryOperation ( a , b ) ;
` +R+ `
setOutput ( result ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Fs=function(){function f(p){this.variableNames=["A"],this.outputShape=p,this.userCode= `
uniform float minVal ;
uniform float maxVal ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
float value = getAAtOutCoords ( ) ;
if ( isnan ( value ) ) {
setOutput ( value ) ;
return ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
setOutput ( clamp ( value , minVal , maxVal ) ) ;
}
` }return f.prototype.getCustomSetupFunc=function(p,l){var m=this;return function(g,I){m.minLoc==null&&(m.minLoc=g.getUniformLocationNoThrow(I,"minVal"),m.maxLoc=g.getUniformLocationNoThrow(I,"maxVal")),g.gl.uniform1f(m.minLoc,p),g.gl.uniform1f(m.maxLoc,l)}},f}(),eu=function(){function f(p){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=p,this.userCode= `
uniform float minVal ;
uniform float maxVal ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
vec4 value = getAAtOutCoords ( ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( any ( isnan ( value ) ) ) {
setOutput ( value ) ;
return ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
setOutput ( clamp ( value , vec4 ( minVal ) , vec4 ( maxVal ) ) ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f.prototype.getCustomSetupFunc=function(p,l){var m=this;return function(g,I){m.minLoc==null&&(m.minLoc=g.getUniformLocationNoThrow(I,"minVal"),m.maxLoc=g.getUniformLocationNoThrow(I,"maxVal")),g.gl.uniform1f(m.minLoc,p),g.gl.uniform1f(m.maxLoc,l)}},f}(),ds=function(){function f(p){this.variableNames=["real","imag"],this.outputShape=p,this.userCode= `
void main ( ) {
float re = abs ( getRealAtOutCoords ( ) ) ;
float im = abs ( getImagAtOutCoords ( ) ) ;
float mx = max ( re , im ) ;
// 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 ) )
) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),tu=function(){function f(p){this.variableNames=["x","dy"],this.outputShape=p.filterShape;var l=p.strideHeight,m=p.strideWidth,g=p.padInfo.top,I=p.padInfo.left,R=p.dataFormat==="channelsLast";this.userCode= `
2020-11-06 22:21:20 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
2020-11-07 16:37:19 +01:00
int wR = coords . x ;
int wC = coords . y ;
int d1 = coords . z ;
int d2 = coords . w ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int b = 0 ; b < ` +p.batchSize+ ` ; b ++ ) {
for ( int yR = 0 ; yR < ` +p.outHeight+ ` ; yR ++ ) {
int xR = wR + yR * ` +l+" - "+g+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xR < 0 || xR >= ` +p.inHeight+ ` ) {
continue ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
for ( int yC = 0 ; yC < ` +p.outWidth+ ` ; yC ++ ) {
int xC = wC + yC * ` +m+" - "+I+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xC < 0 || xC >= ` +p.inWidth+ ` ) {
continue ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( ` +R+ ` ) {
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-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
2020-11-06 22:21:20 +01:00
}
}
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
setOutput ( dotProd ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Ds=function(){function f(p){this.variableNames=["dy","W"],this.outputShape=p.inShape;var l=p.filterHeight,m=p.filterWidth,g=p.strideHeight,I=p.strideWidth,R=p.dataFormat==="channelsLast",P=l-1-p.padInfo.top,L=m-1-p.padInfo.left,G=R?1:2,Q=R?2:3,ke=R?3:1;this.userCode= `
const ivec2 pads = ivec2 ( ` +P+", "+L+ ` ) ;
2020-11-06 22:21:20 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
2020-11-07 16:37:19 +01:00
int batch = coords [ 0 ] ;
int d1 = coords [ ` +ke+ ` ] ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
ivec2 dyCorner = ivec2 ( coords [ ` +G+"], coords["+Q+ ` ] ) - pads ;
int dyRCorner = dyCorner . x ;
int dyCCorner = dyCorner . y ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).
2020-11-06 22:21:20 +01:00
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
2020-11-07 16:37:19 +01:00
for ( int wR = 0 ; wR < ` +l+ ` ; wR ++ ) {
float dyR = float ( dyRCorner + wR ) / ` +g+ ` . 0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( dyR < 0.0 || dyR >= ` +p.outHeight+ ` . 0 || fract ( dyR ) > 0.0 ) {
2020-11-06 22:21:20 +01:00
continue ;
}
int idyR = int ( dyR ) ;
2020-11-07 16:37:19 +01:00
int wRPerm = ` +l+ ` - 1 - wR ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wC = 0 ; wC < ` +m+ ` ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / ` +I+ ` . 0 ;
if ( dyC < 0.0 || dyC >= ` +p.outWidth+ ` . 0 ||
2020-11-06 22:21:20 +01:00
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2020-11-07 16:37:19 +01:00
int wCPerm = ` +m+ ` - 1 - wC ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int d2 = 0 ; d2 < ` +p.outChannels+ ` ; d2 ++ ) {
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( ` +R+ ` ) {
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-11-06 19:50:16 +01:00
}
}
2020-11-06 22:21:20 +01:00
setOutput ( dotProd ) ;
}
2020-11-07 16:37:19 +01:00
` }return f}(),fs=function(){function f(p){this.variableNames=["x","dy"],this.outputShape=p.filterShape;var l=p.strideDepth,m=p.strideHeight,g=p.strideWidth,I=p.padInfo.front,R=p.padInfo.top,P=p.padInfo.left;this.userCode= `
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int wF = coords . x ;
int wR = coords . y ;
int wC = coords . z ;
int d1 = coords . w ;
int d2 = coords . u ;
float dotProd = 0.0 ;
for ( int b = 0 ; b < ` +p.batchSize+ ` ; b ++ ) {
for ( int yF = 0 ; yF < ` +p.outDepth+ ` ; yF ++ ) {
int xF = wF + yF * ` +l+" - "+I+ ` ;
if ( xF < 0 || xF >= ` +p.inDepth+ ` ) {
continue ;
}
for ( int yR = 0 ; yR < ` +p.outHeight+ ` ; yR ++ ) {
int xR = wR + yR * ` +m+" - "+R+ ` ;
if ( xR < 0 || xR >= ` +p.inHeight+ ` ) {
continue ;
}
for ( int yC = 0 ; yC < ` +p.outWidth+ ` ; yC ++ ) {
int xC = wC + yC * ` +g+" - "+P+ ` ;
if ( xC < 0 || xC >= ` +p.inWidth+ ` ) {
continue ;
}
float dyValue = getDy ( b , yF , yR , yC , d2 ) ;
float xValue = getX ( b , xF , xR , xC , d1 ) ;
dotProd += ( xValue * dyValue ) ;
}
}
}
}
setOutput ( dotProd ) ;
}
` }return f}(),Os=function(){function f(p){this.variableNames=["dy","W"],this.outputShape=p.inShape;var l=p.filterDepth,m=p.filterHeight,g=p.filterWidth,I=p.strideDepth,R=p.strideHeight,P=p.strideWidth,L=l-1-p.padInfo.front,G=m-1-p.padInfo.top,Q=g-1-p.padInfo.left;this.userCode= `
const ivec3 pads = ivec3 ( ` +L+", "+G+", "+Q+ ` ) ;
2020-11-06 22:21:20 +01:00
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
2020-11-07 16:37:19 +01:00
int d1 = coords . u ;
2020-11-06 22:21:20 +01:00
ivec3 dyCorner = ivec3 ( coords . y , coords . z , coords . w ) - pads ;
2020-11-07 16:37:19 +01:00
int dyFCorner = dyCorner . x ;
2020-11-06 22:21:20 +01:00
int dyRCorner = dyCorner . y ;
int dyCCorner = dyCorner . z ;
float dotProd = 0.0 ;
2020-11-07 16:37:19 +01:00
for ( int wF = 0 ; wF < ` +l+ ` ; wF ++ ) {
float dyF = float ( dyFCorner + wF ) / ` +I+ ` . 0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( dyF < 0.0 || dyF >= ` +p.outDepth+ ` . 0 || fract ( dyF ) > 0.0 ) {
2020-11-06 22:21:20 +01:00
continue ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
int idyF = int ( dyF ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
int wFPerm = ` +l+ ` - 1 - wF ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wR = 0 ; wR < ` +m+ ` ; wR ++ ) {
float dyR = float ( dyRCorner + wR ) / ` +R+ ` . 0 ;
if ( dyR < 0.0 || dyR >= ` +p.outHeight+ ` . 0 ||
fract ( dyR ) > 0.0 ) {
2020-11-06 22:21:20 +01:00
continue ;
}
int idyR = int ( dyR ) ;
2020-11-07 16:37:19 +01:00
int wRPerm = ` +m+ ` - 1 - wR ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wC = 0 ; wC < ` +g+ ` ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / ` +P+ ` . 0 ;
if ( dyC < 0.0 || dyC >= ` +p.outWidth+ ` . 0 ||
2020-11-06 22:21:20 +01:00
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2020-11-07 16:37:19 +01:00
int wCPerm = ` +g+ ` - 1 - wC ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int d2 = 0 ; d2 < ` +p.outChannels+ ` ; d2 ++ ) {
float xValue = getDy ( batch , idyF , idyR , idyC , d2 ) ;
float wValue = getW ( wFPerm , wRPerm , wCPerm , d1 , d2 ) ;
dotProd += xValue * wValue ;
}
2020-11-06 22:21:20 +01:00
}
2020-11-06 19:50:16 +01:00
}
}
2020-11-06 22:21:20 +01:00
setOutput ( dotProd ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Ms=function(){function f(p){this.variableNames=["x","dy"],this.outputShape=p.filterShape;var l=p.strideHeight,m=p.strideWidth,g=p.padInfo.top,I=p.padInfo.left,R=p.outChannels/p.inChannels;this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int wR = coords . x ;
int wC = coords . y ;
int d1 = coords . z ;
int dm = coords . w ;
int d2 = d1 * ` +R+ ` + dm ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float dotProd = 0.0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// TO DO: Vec4 over the batch size
for ( int b = 0 ; b < ` +p.batchSize+ ` ; b ++ ) {
for ( int yR = 0 ; yR < ` +p.outHeight+ ` ; yR ++ ) {
int xR = wR + yR * ` +l+" - "+g+ ` ;
if ( xR < 0 || xR >= ` +p.inHeight+ ` ) {
continue ;
}
for ( int yC = 0 ; yC < ` +p.outWidth+ ` ; yC ++ ) {
int xC = wC + yC * ` +m+" - "+I+ ` ;
if ( xC < 0 || xC >= ` +p.inWidth+ ` ) {
continue ;
}
float dyValue = getDy ( b , yR , yC , d2 ) ;
float xValue = getX ( b , xR , xC , d1 ) ;
dotProd += ( xValue * dyValue ) ;
}
}
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
setOutput ( dotProd ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),ru=function(){function f(p){this.variableNames=["dy","W"],this.outputShape=p.inShape;var l=p.filterHeight,m=p.filterWidth,g=p.strideHeight,I=p.strideWidth,R=l-1-p.padInfo.top,P=m-1-p.padInfo.left,L=p.outChannels/p.inChannels;this.userCode= `
const ivec2 pads = ivec2 ( ` +R+", "+P+ ` ) ;
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec4 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int d1 = coords [ 3 ] ;
ivec2 dyCorner = coords . yz - pads ;
int dyRCorner = dyCorner . x ;
int dyCCorner = dyCorner . y ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float dotProd = 0.0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wR = 0 ; wR < ` +l+ ` ; wR ++ ) {
float dyR = float ( dyRCorner + wR ) / ` +g+ ` . 0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( dyR < 0.0 || dyR >= ` +p.outHeight+ ` . 0 || fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
int wRPerm = ` +l+ ` - 1 - wR ;
for ( int wC = 0 ; wC < ` +m+ ` ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / ` +I+ ` . 0 ;
if ( dyC < 0.0 || dyC >= ` +p.outWidth+ ` . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
int wCPerm = ` +m+ ` - 1 - wC ;
// TO DO: Vec4 over the channelMul
for ( int dm = 0 ; dm < ` +L+ ` ; dm ++ ) {
int d2 = d1 * ` +L+ ` + dm ;
float xValue = getDy ( batch , idyR , idyC , d2 ) ;
float wValue = getW ( wRPerm , wCPerm , d1 , dm ) ;
dotProd += xValue * wValue ;
}
}
}
setOutput ( dotProd ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),ms=function(){function f(p,l,m,g){l===void 0&&(l=!1),m===void 0&&(m=null),g===void 0&&(g=!1),this.variableNames=["x","W"],this.outputShape=p.outShape;var I=p.padInfo.top,R=p.padInfo.left,P=p.strideHeight,L=p.strideWidth,G=p.dilationHeight,Q=p.dilationWidth,ke=p.filterHeight,Ce=p.filterWidth,Fe=Math.floor(p.inChannels/4)*4,Ee=p.inChannels%4,Ge=p.dataFormat==="channelsLast",Qe=Ge?1:2,s=Ge?2:3,u=Ge?3:1,r="",o="";m&&(g?r= ` float activation ( float a ) {
float b = getPreluActivationWeightsAtOutCoords ( ) ;
` +m+ `
} ` :r= `
float activation ( float x ) {
` +m+ `
}
` ,o="result = activation(result);");var h=l?"result += getBiasAtOutCoords();":"";l&&this.variableNames.push("bias"),g&&this.variableNames.push("preluActivationWeights"),this.userCode= `
` +r+ `
const ivec2 strides = ivec2 ( ` +P+", "+L+ ` ) ;
const ivec2 pads = ivec2 ( ` +I+", "+R+ ` ) ;
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec4 coords = getOutputCoords ( ) ;
2020-11-06 22:21:20 +01:00
int batch = coords [ 0 ] ;
2020-11-07 16:37:19 +01:00
int d2 = coords [ ` +u+ ` ] ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
ivec2 xRCCorner =
ivec2 ( coords [ ` +Qe+"], coords["+s+ ` ] ) * strides - pads ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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 ;
for ( int wR = 0 ; wR < ` +ke+ ` ; wR ++ ) {
int xR = xRCorner + wR * ` +G+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xR < 0 || xR >= ` +p.inHeight+ ` ) {
continue ;
2020-11-06 19:50:16 +01:00
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wC = 0 ; wC < ` +Ce+ ` ; wC ++ ) {
int xC = xCCorner + wC * ` +Q+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xC < 0 || xC >= ` +p.inWidth+ ` ) {
continue ;
}
for ( int d1 = 0 ; d1 < ` +Fe+ ` ; d1 += 4 ) {
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 )
) ;
if ( ` +Ge+ ` ) {
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 ) ;
}
}
if ( ` +(Ee===1)+ ` ) {
if ( ` +Ge+ ` ) {
dotProd +=
getX ( batch , xR , xC , ` +Fe+ ` ) *
getW ( wR , wC , ` +Fe+ ` , d2 ) ;
} else {
dotProd +=
getX ( batch , ` +Fe+ ` , xR , xC ) *
getW ( wR , wC , ` +Fe+ ` , d2 ) ;
}
} else if ( ` +(Ee===2)+ ` ) {
vec2 wValues = vec2 (
getW ( wR , wC , ` +Fe+ ` , d2 ) ,
getW ( wR , wC , ` +Fe+ ` + 1 , d2 )
) ;
if ( ` +Ge+ ` ) {
vec2 xValues = vec2 (
getX ( batch , xR , xC , ` +Fe+ ` ) ,
getX ( batch , xR , xC , ` +Fe+ ` + 1 )
) ;
dotProd += dot ( xValues , wValues ) ;
} else {
vec2 xValues = vec2 (
getX ( batch , ` +Fe+ ` , xR , xC ) ,
getX ( batch , ` +Fe+ ` + 1 , xR , xC )
) ;
dotProd += dot ( xValues , wValues ) ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
} else if ( ` +(Ee===3)+ ` ) {
vec3 wValues = vec3 (
getW ( wR , wC , ` +Fe+ ` , d2 ) ,
getW ( wR , wC , ` +Fe+ ` + 1 , d2 ) ,
getW ( wR , wC , ` +Fe+ ` + 2 , d2 )
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( ` +Ge+ ` ) {
vec3 xValues = vec3 (
getX ( batch , xR , xC , ` +Fe+ ` ) ,
getX ( batch , xR , xC , ` +Fe+ ` + 1 ) ,
getX ( batch , xR , xC , ` +Fe+ ` + 2 )
) ;
dotProd += dot ( xValues , wValues ) ;
} else {
vec3 xValues = vec3 (
getX ( batch , ` +Fe+ ` , xR , xC ) ,
getX ( batch , ` +Fe+ ` + 1 , xR , xC ) ,
getX ( batch , ` +Fe+ ` + 2 , xR , xC )
) ;
dotProd += dot ( xValues , wValues ) ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
}
2020-11-06 22:21:20 +01:00
}
2020-11-06 19:50:16 +01:00
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float result = dotProd ;
` +h+ `
` +o+ `
setOutput ( result ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),nu=function(){function f(p){this.variableNames=["x","W"],this.outputShape=p.outShape;var l=p.padInfo.front,m=p.padInfo.top,g=p.padInfo.left,I=p.strideDepth,R=p.strideHeight,P=p.strideWidth,L=p.dilationDepth,G=p.dilationHeight,Q=p.dilationWidth,ke=p.filterDepth,Ce=p.filterHeight,Fe=p.filterWidth,Ee=Math.floor(p.inChannels/4)*4,Ge=p.inChannels%4;this.userCode= `
const ivec3 strides = ivec3 ( ` +I+", "+R+", "+P+ ` ) ;
const ivec3 pads = ivec3 ( ` +l+", "+m+", "+g+ ` ) ;
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int d2 = coords . u ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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-06 22:21:20 +01:00
2020-11-07 16:37:19 +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 ;
for ( int wF = 0 ; wF < ` +ke+ ` ; wF ++ ) {
int xF = xFCorner + wF * ` +L+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xF < 0 || xF >= ` +p.inDepth+ ` ) {
continue ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wR = 0 ; wR < ` +Ce+ ` ; wR ++ ) {
int xR = xRCorner + wR * ` +G+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xR < 0 || xR >= ` +p.inHeight+ ` ) {
2020-11-06 22:21:20 +01:00
continue ;
}
2020-11-07 16:37:19 +01:00
for ( int wC = 0 ; wC < ` +Fe+ ` ; wC ++ ) {
int xC = xCCorner + wC * ` +Q+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xC < 0 || xC >= ` +p.inWidth+ ` ) {
2020-11-06 22:21:20 +01:00
continue ;
}
2020-11-07 16:37:19 +01:00
for ( int d1 = 0 ; d1 < ` +Ee+ ` ; d1 += 4 ) {
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-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
dotProd += dot ( xValues , wValues ) ;
}
if ( ` +(Ge===1)+ ` ) {
dotProd +=
getX ( batch , xF , xR , xC , ` +Ee+ ` ) *
getW ( wF , wR , wC , ` +Ee+ ` , d2 ) ;
} else if ( ` +(Ge===2)+ ` ) {
vec2 xValues = vec2 (
getX ( batch , xF , xR , xC , ` +Ee+ ` ) ,
getX ( batch , xF , xR , xC , ` +Ee+ ` + 1 )
) ;
vec2 wValues = vec2 (
getW ( wF , wR , wC , ` +Ee+ ` , d2 ) ,
getW ( wF , wR , wC , ` +Ee+ ` + 1 , d2 )
) ;
dotProd += dot ( xValues , wValues ) ;
} else if ( ` +(Ge===3)+ ` ) {
vec3 xValues = vec3 (
getX ( batch , xF , xR , xC , ` +Ee+ ` ) ,
getX ( batch , xF , xR , xC , ` +Ee+ ` + 1 ) ,
getX ( batch , xF , xR , xC , ` +Ee+ ` + 2 )
) ;
vec3 wValues = vec3 (
getW ( wF , wR , wC , ` +Ee+ ` , d2 ) ,
getW ( wF , wR , wC , ` +Ee+ ` + 1 , d2 ) ,
getW ( wF , wR , wC , ` +Ee+ ` + 2 , d2 )
) ;
dotProd += dot ( xValues , wValues ) ;
2020-11-06 22:21:20 +01:00
}
}
}
}
2020-11-07 16:37:19 +01:00
setOutput ( dotProd ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),ys=function(){function f(p,l,m,g){l===void 0&&(l=!1),m===void 0&&(m=null),g===void 0&&(g=!1),this.variableNames=["x","W"],this.outputShape=p.outShape;var I=p.inHeight,R=p.inWidth,P=p.padInfo.top,L=p.padInfo.left,G=p.strideHeight,Q=p.strideWidth,ke=p.dilationHeight,Ce=p.dilationWidth,Fe=p.filterHeight,Ee=p.filterWidth,Ge=p.outChannels/p.inChannels,Qe="",s="";m&&(g?Qe= ` float activation ( float a ) {
float b = getPreluActivationWeightsAtOutCoords ( ) ;
` +m+ `
} ` :Qe= `
float activation ( float x ) {
` +m+ `
}
` ,s="result = activation(result);");var u=l?"result += getBiasAtOutCoords();":"";l&&this.variableNames.push("bias"),g&&this.variableNames.push("preluActivationWeights"),this.userCode= `
` +Qe+ `
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
const ivec2 strides = ivec2 ( ` +G+", "+Q+ ` ) ;
const ivec2 pads = ivec2 ( ` +P+", "+L+ ` ) ;
2020-11-06 22:21:20 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
2020-11-07 16:37:19 +01:00
int batch = coords . x ;
2020-11-06 22:21:20 +01:00
ivec2 xRCCorner = coords . yz * strides - pads ;
2020-11-07 16:37:19 +01:00
int d2 = coords . w ;
int d1 = d2 / ` +Ge+ ` ;
int q = d2 - d1 * ` +Ge+ ` ;
2020-11-06 22:21:20 +01:00
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2020-11-07 16:37:19 +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.
for ( int wR = 0 ; wR < ` +Fe+ ` ; wR ++ ) {
int xR = xRCorner + wR * ` +ke+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xR < 0 || xR >= ` +I+ ` ) {
2020-11-06 22:21:20 +01:00
continue ;
}
2020-11-07 16:37:19 +01:00
for ( int wC = 0 ; wC < ` +Ee+ ` ; wC ++ ) {
int xC = xCCorner + wC * ` +Ce+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xC < 0 || xC >= ` +R+ ` ) {
continue ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float xVal = getX ( batch , xR , xC , d1 ) ;
float wVal = getW ( wR , wC , d1 , q ) ;
dotProd += xVal * wVal ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float result = dotProd ;
` +u+ `
` +s+ `
setOutput ( result ) ;
}
` }return f}(),Fo=function(){function f(p,l,m,g){l===void 0&&(l=!1),m===void 0&&(m=null),g===void 0&&(g=!1),this.variableNames=["x","W"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=p.outShape;for(var I=p.inHeight,R=p.inWidth,P=p.padInfo.top,L=p.padInfo.left,G=p.strideHeight,Q=p.strideWidth,ke=p.dilationHeight,Ce=p.dilationWidth,Fe=p.filterHeight,Ee=p.filterWidth,Ge=Ee,Qe="int xR; int xC; int xCOffset;",s=0;s<Fe;s++)for(var u=0;u<Ee;u++)Qe+= `
vec4 xTexelR ` +s+"C"+u*2+ ` = vec4 ( 0. ) ;
vec4 wR ` +s+"C"+u+ ` = vec4 ( 0. ) ;
vec4 xR ` +s+"C"+u+" = vec4(0.);";for(var s=0;s<Fe;s++)for(var r=0;r<Ge;r++){var u=r*2;if(Qe+= `
xR = xRCorner + ` +s*ke+ ` ;
xC = xCCorner + ` +u*Ce+ ` ;
` ,Q===1){if(u<Ee&&(L%2===1?Qe+= `
xCOffset = xC + 1 ;
if ( xR >= 0 && xR < ` +I+" && xCOffset >= 0 && xCOffset < "+R+ ` ) {
xTexelR ` +s+"C"+u+ ` = getX ( batch , xR , xCOffset , d1 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if ( xCOffset + 1 >= ` +R+ ` ) {
xTexelR ` +s+"C"+u+ ` . zw = vec2 ( 0. ) ;
}
} else {
xTexelR ` +s+"C"+u+ ` = vec4 ( 0. ) ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
xCOffset = xC + 1 - 2 ;
if ( xR >= 0 && xR < ` +I+" && xCOffset >= 0 && xCOffset < "+R+ ` ) {
vec4 previous = getX ( batch , xR , xCOffset , d1 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if ( xCOffset + 1 >= ` +R+ ` ) {
previous . zw = vec2 ( 0. ) ;
}
xR ` +s+"C"+u+" = vec4(previous.zw, xTexelR"+s+"C"+u+ ` . xy ) ;
} else {
xR ` +s+"C"+u+" = vec4(0, 0, xTexelR"+s+"C"+u+ ` . xy ) ;
}
` :Qe+= `
if ( xR >= 0 && xR < ` +I+" && xC >= 0 && xC < "+R+ ` ) {
xTexelR ` +s+"C"+u+ ` = getX ( batch , xR , xC , d1 ) ;
} else {
xTexelR ` +s+"C"+u+ ` = vec4 ( 0. ) ;
}
xR ` +s+"C"+u+" = xTexelR"+s+"C"+u+ ` ;
` ,u+1<Ee)){var o=L%2===0?i.util.nearestLargerEven(Ce):Ce;Ce%2===0&&L%2===1||Ce%2!==0&&L%2!==1?(Qe+= `
xCOffset = xC + ` +L%2+" + "+o+ ` ;
if ( xR >= 0 && xR < ` +I+ ` &&
xCOffset >= 0 && xCOffset < ` +R+ ` ) {
xTexelR ` +s+"C"+(u+2)+ ` = getX ( batch , xR , xCOffset , d1 ) ;
}
` ,Ce>1&&(Qe+= `
xCOffset -= 2 ;
if ( xR >= 0 && xR < ` +I+ ` &&
xCOffset >= 0 && xCOffset < ` +R+ ` ) {
xTexelR ` +s+"C"+u+ ` = getX ( batch , xR , xCOffset , d1 ) ;
} else {
xTexelR ` +s+"C"+u+ ` = vec4 ( 0. ) ;
}
` ),Qe+= `
xR ` +s+"C"+(u+1)+ ` = vec4 (
xTexelR ` +s+"C"+u+".zw, xTexelR"+s+"C"+(u+2)+ ` . xy ) ;
` ):Qe+= `
xCOffset = xC + ` +o+ ` ;
if ( xR >= 0 && xR < ` +I+ ` &&
xCOffset >= 0 && xCOffset < ` +R+ ` ) {
xTexelR ` +s+"C"+(u+2)+ ` = getX ( batch , xR , xCOffset , d1 ) ;
}
xR ` +s+"C"+(u+1)+" = xTexelR"+s+"C"+(u+2)+ ` ;
` }}else u<Ee&&(Qe+= `
if ( xR >= 0 && xR < ` +I+ ` ) {
` ,L%2===1?(Qe+= `
xCOffset = xC + 1 - ` +Q+ ` ;
if ( xCOffset >= 0 && xCOffset < ` +R+ ` ) {
xTexelR ` +s+"C"+u+ ` = getX ( batch , xR , xCOffset , d1 ) ;
} else {
xTexelR ` +s+"C"+u+ ` = vec4 ( 0. ) ;
}
if ( xC + 1 >= 0 && xC + 1 < ` +R+ ` ) {
xTexelR ` +s+"C"+(u+2)+ ` = getX ( batch , xR , xC + 1 , d1 ) ;
} else {
xTexelR ` +s+"C"+(u+2)+ ` = vec4 ( 0. ) ;
}
xR ` +s+"C"+u+ ` = vec4 (
xTexelR ` +s+"C"+u+".zw, xTexelR"+s+"C"+(u+2)+ ` . zw ) ;
` ,u+1<Ee&&(Qe+= `
vec4 final = vec4 ( 0. ) ;
xCOffset = xC + 1 + ` +Q+ ` ;
if ( xCOffset >= 0 && xCOffset < ` +R+ ` ) {
final = getX ( batch , xR , xCOffset , d1 ) ;
}
xR ` +s+"C"+(u+1)+" = vec4(xTexelR"+s+"C"+(u+2)+ ` . xy , final . xy ) ;
` )):(Qe+= `
if ( xC >= 0 && xC < ` +R+ ` ) {
xTexelR ` +s+"C"+u+ ` = getX ( batch , xR , xC , d1 ) ;
} else {
xTexelR ` +s+"C"+u+ ` = vec4 ( 0. ) ;
}
xCOffset = xC + ` +Q+ ` ;
if ( xCOffset >= 0 && xCOffset < ` +R+ ` ) {
xTexelR ` +s+"C"+(u+2)+ ` = getX ( batch , xR , xCOffset , d1 ) ;
} else {
xTexelR ` +s+"C"+(u+2)+ ` = vec4 ( 0. ) ;
}
xR ` +s+"C"+u+ ` = vec4 (
xTexelR ` +s+"C"+u+".xy, xTexelR"+s+"C"+(u+2)+ ` . xy ) ;
` ,u+1<Ee&&(Qe+= `
xR ` +s+"C"+(u+1)+ ` = vec4 (
xTexelR ` +s+"C"+u+".zw, xTexelR"+s+"C"+(u+2)+ ` . zw ) ;
` )),Qe+="}");u<Ee&&(Qe+= `
vec4 wTexelR ` +s+"C"+u+" = getW("+s+", "+u+ ` , d1 , q ) ;
wR ` +s+"C"+u+" = vec4(wTexelR"+s+"C"+u+".xz, wTexelR"+s+"C"+u+ ` . xz ) ;
` ,u+1<Ee&&(Qe+= `
vec4 wTexelR ` +s+"C"+(u+1)+" = getW("+s+", "+(u+1)+ ` , d1 , q ) ;
wR ` +s+"C"+(u+1)+ ` =
vec4 ( wTexelR ` +s+"C"+(u+1)+".xz, wTexelR"+s+"C"+(u+1)+".xz);"))}for(var s=0;s<Fe;s++)for(var u=0;u<Ee;u++)Qe+="dotProd += xR"+s+"C"+u+" * wR"+s+"C"+u+";";var h="",b="";m&&(g?h= ` vec4 activation ( vec4 a ) {
vec4 b = getPreluActivationWeightsAtOutCoords ( ) ;
` +m+ `
} ` :h= ` vec4 activation ( vec4 x ) {
` +m+ `
} ` ,b="result = activation(result);");var T=l?"result += getBiasAtOutCoords();":"";l&&this.variableNames.push("bias"),g&&this.variableNames.push("preluActivationWeights"),this.userCode= `
` +h+ `
const ivec2 strides = ivec2 ( ` +G+", "+Q+ ` ) ;
const ivec2 pads = ivec2 ( ` +P+", "+L+ ` ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords . x ;
ivec2 xRCCorner = coords . yz * strides - pads ;
int d2 = coords . w ;
int d1 = d2 ;
int q = 0 ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
vec4 dotProd = vec4 ( 0. ) ;
` +Qe+ `
vec4 result = dotProd ;
` +T+ `
` +b+ `
setOutput ( result ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),zs=function(){function f(p,l,m,g,I){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];var R=p[0],P=p[1],L=p[2],G=p[3],Q=l[0],ke=m[0],Ce=m[1];this.outputShape=[Q,ke,Ce,G];var Fe=g==="bilinear"?1:0,Ee=[P-1+".0",L-1+".0"],Ge=Ee[0],Qe=Ee[1],s=ke>1?[""+(P-1)/(ke-1),"(y2-y1) * height_ratio","y1*"+Ge+" + float(y)*(height_scale)"]:["0.0","0.0","0.5 * (y1+y2) * "+Ge],u=s[0],r=s[1],o=s[2],h=Ce>1?[""+(L-1)/(Ce-1),"(x2-x1) * width_ratio","x1*"+Qe+" + float(x)*(width_scale)"]:["0.0","0.0","0.5 * (x1+x2) * "+Qe],b=h[0],T=h[1],O=h[2];this.userCode= `
const float height _ratio = float ( ` +u+ ` ) ;
const float width _ratio = float ( ` +b+ ` ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int y = coords [ 1 ] ;
int x = coords [ 2 ] ;
int d = coords [ 3 ] ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// get image in batch index
int bInd = round ( getBoxInd ( b ) ) ;
if ( bInd < 0 || bInd >= ` +R+ ` ) {
return ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float height _scale = ` +r+ ` ;
float width _scale = ` +T+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float in _y = ` +o+ ` ;
if ( in _y < 0.0 || in _y > ` +Ge+ ` ) {
setOutput ( float ( ` +I+ ` ) ) ;
return ;
}
float in _x = ` +O+ ` ;
if ( in _x < 0.0 || in _x > ` +Qe+ ` ) {
setOutput ( float ( ` +I+ ` ) ) ;
return ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec2 sourceFracIndexCR = vec2 ( in _x , in _y ) ;
if ( ` +Fe+ ` == 1 ) {
// Compute the four integer indices.
ivec2 sourceFloorCR = ivec2 ( sourceFracIndexCR ) ;
ivec2 sourceCeilCR = ivec2 ( ceil ( sourceFracIndexCR ) ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec2 fracCR = sourceFracIndexCR - vec2 ( sourceFloorCR ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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 ) ;
} else {
// 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 ) ;
}
}
` }return f}(), $ o=function(){function f(p,l,m){this.variableNames=["x"],this.outputShape=p;var g=p.length,I=l?"0.0":"getX("+xo(g,"coords")+")",R=p[p.length-1],P="",L="";l?(P=m?"end != "+(R-1):"end != 0",L=m?"end + 1":"end - 1"):(P=m?"end + pow2 < "+R:"end >= pow2",L=m?"end + pow2":"end - pow2"),this.userCode= `
uniform float index ;
void main ( ) {
` +nn(g)+ ` coords = getOutputCoords ( ) ;
int end = ` +vs(g,"coords")+ ` ;
float val = ` +I+ ` ;
int pow2 = int ( pow ( 2.0 , index ) ) ;
if ( ` +P+ ` ) {
int idx = ` +L+ ` ;
` +vs(g,"coords")+ ` = idx ;
val += getX ( ` +xo(g,"coords")+ ` ) ;
}
setOutput ( val ) ;
}
` }return f.prototype.getCustomSetupFunc=function(p){var l=this;return function(m,g){l.index==null&&(l.index=m.getUniformLocation(g,"index")),m.gl.uniform1f(l.index,p)}},f}();function xo(f,p){if(f===1)return""+p;if(f===2)return p+".x, "+p+".y";if(f===3)return p+".x, "+p+".y, "+p+".z";if(f===4)return p+".x, "+p+".y, "+p+".z, "+p+".w";throw Error("Cumulative sum for rank "+f+" is not yet supported")}function vs(f,p){if(f===1)return""+p;if(f===2)return p+".y";if(f===3)return p+".z";if(f===4)return p+".w";throw Error("Cumulative sum for rank "+f+" is not yet supported")}var Do=function(){function f(p){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outPackingScheme=ee.DENSE;var l=st(p),m=tn();this.outputShape=p,this.userCode= `
ivec3 outCoordsFromFlatIndex ( int index ) {
` +En(["r","c","d"],p)+ `
return ivec3 ( r , c , d ) ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +l[0]+", "+l[1]+ ` ) ) ;
int index = 4 * ( resTexRC . x * ` +l[1]+ ` + resTexRC . y ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 result = vec4 ( 0. ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int i = 0 ; i < 4 ; i ++ ) {
int flatIndex = index + i ;
ivec3 rc = outCoordsFromFlatIndex ( flatIndex ) ;
result [ i ] = getA ( rc . x , rc . y , rc . z ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` +m.output+ ` = result ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Ls=function(){function f(p){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=ee.DENSE;var l=st(p),m=tn();this.outputShape=p,this.userCode= `
ivec3 outCoordsFromFlatIndex ( int index ) {
` +En(["r","c","d"],p)+ `
return ivec3 ( r , c , d ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
void main ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( ` +l[0]+", "+l[1]+ ` ) ) ;
int index = 4 * ( resTexRC . x * ` +l[1]+ ` + resTexRC . y ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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 ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` +m.output+ ` = result ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),es=function(){function f(p,l,m){this.variableNames=["x"],this.outputShape=[],this.outputShape=p,this.blockSize=l,this.dataFormat=m,this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int h = ` +this.getHeightCoordString()+ ` ;
int w = ` +this.getWidthCoordString()+ ` ;
int d = ` +this.getDepthCoordString()+ ` ;
int in _h = h / ` +l+ ` ;
int offset _h = imod ( h , ` +l+ ` ) ;
int in _w = w / ` +l+ ` ;
int offset _w = imod ( w , ` +l+ ` ) ;
int offset _d = ( offset _h * ` +l+ ` + offset _w ) *
` +this.getOutputDepthSize()+ ` ;
int in _d = d + offset _d ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float result = ` +this.getInputSamplingString()+ ` ;
setOutput ( result ) ;
}
` }return f.prototype.getHeightCoordString=function(){return this.dataFormat==="NHWC"?"coords[1]":"coords[2]"},f.prototype.getWidthCoordString=function(){return this.dataFormat==="NHWC"?"coords[2]":"coords[3]"},f.prototype.getDepthCoordString=function(){return this.dataFormat==="NHWC"?"coords[3]":"coords[1]"},f.prototype.getOutputDepthSize=function(){return this.dataFormat==="NHWC"?this.outputShape[3]:this.outputShape[1]},f.prototype.getInputSamplingString=function(){return this.dataFormat==="NHWC"?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"},f}(),_o=function(){function f(p){this.variableNames=["X"],this.outputShape=[p,p],this.userCode= `
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec2 coords = getOutputCoords ( ) ;
float val = coords [ 0 ] == coords [ 1 ] ? getX ( coords [ 0 ] ) : 0.0 ;
setOutput ( val ) ;
}
` }return f}(),wo=function(){function f(p){this.variableNames=["A"],this.outTexUsage=w.DOWNLOAD;var l=tn();this.outputShape=p,this.userCode= `
` +sa+ `
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
float x = getAAtOutCoords ( ) ;
` +l.output+ ` = encode _float ( x ) ;
}
` }return f}(),Ps=function(){function f(p){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=w.DOWNLOAD;var l=tn();this.outputShape=p,this.userCode= `
` +sa+ `
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
float x = getChannel ( getAAtOutCoords ( ) , vec2 ( coords . y , coords . z ) ) ;
` +l.output+ ` = encode _float ( x ) ;
}
` }return f}(),Bs=function(){function f(p,l,m){m===void 0&&(m=!1),this.variableNames=["A"];var g=tn(),I=l[0],R=l[1];this.outputShape=p;var P="result";m&&(P="floor(result * 255. + 0.5)"),this.userCode= `
` +qn(p)+ `
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
int flatIndex = getFlatIndex ( coords ) ;
int offset = imod ( flatIndex , 4 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
flatIndex = idiv ( flatIndex , 4 , 1. ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
int r = flatIndex / ` +R+ ` ;
int c = imod ( flatIndex , ` +R+ ` ) ;
vec2 uv = ( vec2 ( c , r ) + halfCR ) / vec2 ( ` +R+".0, "+I+ ` . 0 ) ;
vec4 values = ` +g.texture2D+ ` ( A , uv ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float result ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( offset == 0 ) {
result = values [ 0 ] ;
} else if ( offset == 1 ) {
result = values [ 1 ] ;
} else if ( offset == 2 ) {
result = values [ 2 ] ;
} else {
result = values [ 3 ] ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +g.output+" = vec4("+P+ ` , 0. , 0. , 0. ) ;
}
` }return f}(),gs=function(){function f(p,l,m){m===void 0&&(m=!1),this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var g=tn(),I=l[0],R=l[1];this.outputShape=p;var P="",L="result";m&&(L="floor(result * 255. + 0.5)");for(var G=0;G<=1;G++)for(var Q=0;Q<=1;Q++){var ke=G*2+Q;P+= `
localCoords = coords ;
if ( localCoords [ 2 ] + ` +Q+" < "+p[2]+ ` ) {
localCoords [ 2 ] += ` +Q+ ` ;
if ( localCoords [ 1 ] + ` +G+" < "+p[1]+ ` ) {
localCoords [ 1 ] += ` +G+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
flatIndex = getFlatIndex ( localCoords ) ;
offset = imod ( flatIndex , 4 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
flatIndex = idiv ( flatIndex , 4 , 1. ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
r = flatIndex / ` +R+ ` ;
c = imod ( flatIndex , ` +R+ ` ) ;
uv = ( vec2 ( c , r ) + halfCR ) / vec2 ( ` +R+".0, "+I+ ` . 0 ) ;
values = ` +g.texture2D+ ` ( A , uv ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( offset == 0 ) {
result [ ` +ke+ ` ] = values [ 0 ] ;
} else if ( offset == 1 ) {
result [ ` +ke+ ` ] = values [ 1 ] ;
} else if ( offset == 2 ) {
result [ ` +ke+ ` ] = values [ 2 ] ;
} else {
result [ ` +ke+ ` ] = values [ 3 ] ;
}
2020-11-06 22:21:20 +01:00
}
}
2020-11-07 16:37:19 +01:00
` }this.userCode= `
` +qn(p)+ `
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec3 coords = getOutputCoords ( ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 result = vec4 ( 0. ) ;
int flatIndex , r , c , offset ;
ivec3 localCoords ;
vec2 uv ;
vec4 values ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +P+ `
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +g.output+" = "+L+ ` ;
}
` }return f}(),ts=function(){function f(p,l){this.outputShape=[],this.variableNames=["x"],this.outputShape=p,this.userCode= `
uniform float value ;
void main ( ) {
// Input can be obtained from uniform value.
setOutput ( value ) ;
}
` }return f.prototype.getCustomSetupFunc=function(p){var l=this;return function(m,g){l.valueLoc==null&&(l.valueLoc=m.getUniformLocationNoThrow(g,"value")),m.gl.uniform1f(l.valueLoc,p)}},f}(),au=function(){function f(p,l,m){this.variableNames=["A","indices"];var g=p.slice();g[m]=l,this.outputShape=g,this.rank=g.length;var I=nn(this.rank),R=bu(p,m);this.userCode= `
void main ( ) {
` +I+ ` resRC = getOutputCoords ( ) ;
setOutput ( getA ( ` +R+ ` ) ) ;
}
` }return f}();function bu(f,p){var l=f.length;if(l>4)throw Error("Gather for rank "+l+" is not yet supported");if(l===1)return"int(getIndices(resRC))";for(var m=["resRC.x","resRC.y","resRC.z","resRC.w"],g=[],I=0;I<f.length;I++)I===p?g.push("int(getIndices("+m[I]+"))"):g.push(""+m[I]);return g.join()}var iu=function(){function f(p,l,m){this.sliceDim=p,this.strides=l,this.variableNames=["x","indices"],this.outputShape=m;var g=nn(l.length),I=nn(m.length),R=this.sliceDim>1?"strides[j]":"strides";this.userCode= `
` +g+" strides = "+g+"("+this.strides+ ` ) ;
void main ( ) {
` +I+ ` coords = getOutputCoords ( ) ;
int flattenIndex = 0 ;
for ( int j = 0 ; j < ` +this.sliceDim+ ` ; j ++ ) {
int index = round ( getIndices ( coords [ 0 ] , j ) ) ;
flattenIndex += index * ` +R+ ` ;
}
setOutput ( getX ( flattenIndex , coords [ 1 ] ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}();function Oo(f){var p=tn(),l=p.version+ `
precision highp float ;
` +p.attribute+ ` vec3 clipSpacePos ;
` +p.attribute+ ` vec2 uv ;
` +p.varyingVs+ ` vec2 resultUV ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
gl _Position = vec4 ( clipSpacePos , 1 ) ;
resultUV = uv ;
2020-11-07 17:25:03 +01:00
} ` ;return Qt(f,l)}function Mo(f){var p=new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]);return da(f,p)}function xs(f){var p=new Uint16Array([0,1,2,2,1,3]);return Ha(f,p)}function rs(f,p,l,m,g,I){ka(p,l);var R=ba(f),P=f.TEXTURE_2D;return Ze(f,function(){return f.bindTexture(P,R)}),Ze(f,function(){return f.texParameteri(P,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE)}),Ze(f,function(){return f.texParameteri(P,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE)}),Ze(f,function(){return f.texParameteri(P,f.TEXTURE_MIN_FILTER,f.NEAREST)}),Ze(f,function(){return f.texParameteri(P,f.TEXTURE_MAG_FILTER,f.NEAREST)}),Ze(f,function(){return f.texImage2D(P,0,m,p,l,0,g,I,null)}),Ze(f,function(){return f.bindTexture(f.TEXTURE_2D,null)}),R}function ki(f){return f.internalFormatFloat}function zo(f,p,l,m){var g=We(p,l),I=g[0],R=g[1];return rs(f,I,R,ki(m),m.textureFormatFloat,f.FLOAT)}function Lo(f){return f.internalFormatHalfFloat}function Yi(f,p,l,m){var g=We(p,l),I=g[0],R=g[1];return rs(f,I,R,Lo(m),m.textureFormatFloat,m.textureTypeHalfFloat)}function ns(f){return f.downloadTextureFormat}function ae(f,p,l,m){var g=We(p,l),I=g[0],R=g[1];return rs(f,I,R,ns(m),f.RGBA,f.UNSIGNED_BYTE)}function ue(f){return f.internalFormatPackedFloat}function E(f,p,l,m){var g=ut(p,l),I=g[0],R=g[1];return rs(f,I,R,ue(m),f.RGBA,f.FLOAT)}function D(f){return f.internalFormatPackedHalfFloat}function A(f,p,l,m){var g=ut(p,l),I=g[0],R=g[1];return rs(f,I,R,D(m),f.RGBA,m.textureTypeHalfFloat)}function H(f,p,l){var m=0,g=3*4,I=3*4+2*4;Ze(f,function(){return f.bindBuffer(f.ARRAY_BUFFER,l)});var R=Ma(f,p,"clipSpacePos",l,3,I,m);return R&&Ma(f,p,"uv",l,2,I,g)}function se(f,p,l,m,g,I){Ze(f,function(){return f.bindTexture(f.TEXTURE_2D,p)});var R,P,L;g instanceof Uint8Array?(R=new Uint8Array(l*m*4),P=f.UNSIGNED_BYTE,L=f.RGBA):(R=new Float32Array(l*m*4),P=f.FLOAT,L=I.internalFormatPackedFloat),R.set(g),Ze(f,function(){return f.texImage2D(f.TEXTURE_2D,0,L,l,m,0,f.RGBA,P,R)}),Ze(f,function(){return f.bindTexture(f.TEXTURE_2D,null)})}function te(f,p,l){Ze(f,function(){return f.bindTexture(f.TEXTURE_2D,p)}),l.data instanceof Uint8Array?Ze(f,function(){return f.texImage2D(f.TEXTURE_2D,0,f.RGBA,l.width,l.height,0,f.RGBA,f.UNSIGNED_BYTE,l.data)}):Ze(f,function(){return f.texImage2D(f.TEXTURE_2D,0,f.RGBA,f.RGBA,f.UNSIGNED_BYTE,l)}),Ze(f,function(){return f.bindTexture(f.TEXTURE_2D,null)})}function _e(f,p,l,m){var g=f.createBuffer();Ze(f,function(){return f.bindBuffer(f.PIXEL_PACK_BUFFER,g)});var I=4,R=4,P=I*R*p*l;return Ze(f,function(){return f.bufferData(f.PIXEL_PACK_BUFFER,P,f.STREAM_READ)}),Ze(f,function(){return f.readPixels(0,0,l,p,f.RGBA,f.FLOAT,0)}),Ze(f,function(){return f.bindBuffer(f.PIXEL_PACK_BUFFER,null)}),g}function ce(f,p,l){var m=f,g=new Float32Array(l);return m.bindBuffer(m.PIXEL_PACK_BUFFER,p),m.getBufferSubData(m.PIXEL_PACK_BUFFER,0,g),m.bindBuffer(m.PIXEL_PACK_BUFFER,null),g}function fe(f,p,l,m){var g=We(p,l),I=g[0],R=g[1],P=4,L=new Uint8Array(W(p*l,P));return Ze(f,function(){return f.readPixels(0,0,I,R,m.downloadTextureFormat,f.UNSIGNED_BYTE,L)}),new Float32Array(L.buffer)}function ve(f,p,l,m,g,I,R,P){var L=f,G=new Float32Array(Kt(I,R));return L.bindBuffer(L.PIXEL_PACK_BUFFER,p),L.getBufferSubData(L.PIXEL_PACK_BUFFER,0,G),L.bindBuffer(L.PIXEL_PACK_BUFFER,null),G}function ge(f,p,l){var m=new Float32Array(p*l*4);return Ze(f,function(){return f.readPixels(0,0,l,p,f.RGBA,f.FLOAT,m)}),m}var Ae={__proto__:null,createVertexShader:Oo,createVertexBuffer:Mo,createIndexBuffer:xs,getInternalFormatForFloat32MatrixTexture:ki,createFloat32MatrixTexture:zo,getInternalFormatForFloat16MatrixTexture:Lo,createFloat16MatrixTexture:Yi,getInternalFormatForUnsignedBytesMatrixTexture:ns,createUnsignedBytesMatrixTexture:ae,getInternalFormatForPackedMatrixTexture:ue,createPackedMatrixTexture:E,getInternalFormatForFloat16PackedMatrixTexture:D,createFloat16PackedMatrixTexture:A,bindVertexProgramAttributeStreams:H,uploadDenseMatrixToTexture:se,uploadPixelDataToTexture:te,createBufferFromOutputTexture:_e,downloadFloat32MatrixFromBuffer:ce,downloadByteEncodedFloatMatrixFromOutputTexture:fe,downloadPa
2020-11-07 16:37:19 +01:00
blockIndex = rc . y + ` +b+ ` ;
pos = rc . x + ` +h+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( blockIndex < ` +p[1]+" && pos < "+p[0]+ ` ) {
offsetY = int ( blockIndex / ( ` +G+")) * "+P+" - "+Ee+ ` ;
d0 = offsetY + ` +ke+" * (pos / "+Ge+ ` ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( d0 < ` +l[u]+ ` && d0 >= 0 ) {
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
offsetX = int ( mod ( float ( blockIndex ) , ` +G+".) * "+R+". - "+Fe+ ` . ) ;
d1 = offsetX + ` +Q+" * (int(mod(float(pos), "+Ge+".) / "+I+ ` . ) ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( d1 < ` +l[r]+ ` && d1 >= 0 ) {
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
ch = int ( mod ( float ( pos ) , ` +I+ ` . ) ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( ` +s+ ` ) {
innerDims = vec2 ( d1 , ch ) ;
result [ ` +(h*2+b)+ ` ] = getChannel (
getA ( d0 , int ( innerDims . x ) ,
int ( innerDims . y ) ) , innerDims ) ;
} else {
innerDims = vec2 ( d0 , d1 ) ;
result [ ` +(h*2+b)+ ` ] = getChannel (
getA ( ch , int ( innerDims . x ) ,
int ( innerDims . y ) ) , innerDims ) ;
}
}
}
}
` ;this.userCode= `
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec2 rc = getOutputCoords ( ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 result = vec4 ( 0 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
int blockIndex , pos , offsetY , d0 , offsetX , d1 , ch ;
vec2 innerDims ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +o+ `
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +Qe.output+ ` = result ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),rt=function(){function f(p,l,m,g,I){this.variableNames=["x"],this.outputShape=[];var R=l,P=p[3]-1;this.outputShape=p;var L,G="float("+m+") + float("+g+") * sum";I===.5?L="inversesqrt("+G+")":I===1?L="1.0/("+G+")":L="exp(log("+G+") * float(-"+I+"));",this.userCode= `
2020-11-06 22:21:20 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
2020-11-07 16:37:19 +01:00
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
2020-11-06 22:21:20 +01:00
int d = coords [ 3 ] ;
2020-11-07 16:37:19 +01:00
float x = getX ( b , r , c , d ) ;
float sum = 0.0 ;
for ( int j = - ` +R+"; j <= "+R+ ` ; j ++ ) {
int idx = d + j ;
if ( idx >= 0 && idx <= ` +P+ ` ) {
float z = getX ( b , r , c , idx ) ;
sum += z * z ;
}
}
float val = x * ` +L+ ` ;
setOutput ( val ) ;
}
` }return f}(),xt=function(){function f(p,l,m,g,I){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=p,this.depth=p[3],this.depthRadius=l,this.bias=m,this.alpha=g,this.beta=I,this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
2020-11-06 22:21:20 +01:00
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
2020-11-07 16:37:19 +01:00
float result = 0.0 ;
for ( int d = 0 ; d < ` +this.depth+ ` ; ++ d ) {
int depthBegin = int ( max ( 0.0 , float ( d - ` +l+ ` ) ) ) ;
int depthEnd = int ( min ( float ( ` +this.depth+ ` ) ,
float ( d + ` +l+ ` + 1 ) ) ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
const int MIN _DEPTH _BEGIN = 0 ;
const int MAX _DEPTH _END = ` +this.depth+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
norm = float ( ` +g+") * norm + float("+m+ ` ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int k = MIN _DEPTH _BEGIN ; k < MAX _DEPTH _END ; ++ k ) {
if ( k < depthBegin ) {
2020-11-06 22:21:20 +01:00
continue ;
}
2020-11-07 16:37:19 +01:00
else if ( k >= depthBegin && k < depthEnd ) {
float dyi = - 2.0 * float ( ` +g+ ` )
* float ( ` +I+ ` )
* getInputImage ( b , r , c , k ) * getOutputImage ( b , r , c , d )
/ n o r m ;
if ( k == d ) {
dyi += pow ( norm , - 1.0 * ` +I+ ` ) ;
}
if ( k == coords [ 3 ] ) {
dyi *= getDy ( b , r , c , d ) ;
result += dyi ;
}
}
else {
break ;
}
}
}
setOutput ( result ) ;
}
2020-11-07 17:25:03 +01:00
` }return f}(),ht=function(){function f(p,l,m,g,I){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;var R=l,P=p[3]-1;this.outputShape=p;var L,G="float("+m+") + float("+g+") * sum";I===.5?L="inversesqrt("+G+")":I===1?L="1.0/("+G+")":L="exp(log("+G+") * float(-"+I+"));",this.userCode= `
2020-11-07 16:37:19 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords . x ;
int r = coords . y ;
int c = coords . z ;
int d = coords . w ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
bool hasNextCol = d < ` +this.outputShape[3]+ ` ;
bool hasNextRow = c < ` +this.outputShape[2]+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 sum = vec4 ( 0. ) ;
vec4 xFragAtOutputCoords = getX ( b , r , c , d ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
int firstChannel = d - ` +R+ ` ;
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-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
ivec2 depth = ivec2 ( d , d + 1 ) ;
for ( int j = - ` +R+"; j <= "+R+ ` ; j ++ ) {
ivec2 idx = depth + j ;
bvec2 aboveLowerBound = greaterThanEqual ( idx , ivec2 ( 0 ) ) ;
bvec2 belowUpperBound = lessThanEqual ( idx , ivec2 ( ` +P+ ` ) ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
bool depthInRange = aboveLowerBound . x && belowUpperBound . x ;
bool depthPlusOneInRange = aboveLowerBound . y && belowUpperBound . y ;
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 ) ) ;
}
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
cache . xy = z . yw ;
sum += z * z ;
2020-11-06 22:21:20 +01:00
}
}
2020-11-07 16:37:19 +01:00
vec4 result = xAtOutputCoords * ` +L+ ` ;
setOutput ( result ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),_t=function(){function f(p){this.variableNames=["dy","maxPos"],this.outputShape=p.inShape;var l=p.strideHeight,m=p.strideWidth,g=p.dilationHeight,I=p.effectiveFilterHeight,R=p.effectiveFilterWidth,P=I-1-p.padInfo.top,L=R-1-p.padInfo.left,G=I*R-1;this.userCode= `
const ivec2 pads = ivec2 ( ` +P+", "+L+ ` ) ;
2020-11-06 22:21:20 +01:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
2020-11-07 16:37:19 +01:00
ivec2 dyRCCorner = coords . yz - pads ;
int dyRCorner = dyRCCorner . x ;
int dyCCorner = dyRCCorner . y ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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 ;
for ( int wR = 0 ; wR < ` +I+ ` ;
wR += ` +g+ ` ) {
float dyR = float ( dyRCorner + wR ) / ` +l+ ` . 0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( dyR < 0.0 || dyR >= ` +p.outHeight+ ` . 0 || fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wC = 0 ; wC < ` +R+ ` ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / ` +m+ ` . 0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( dyC < 0.0 || dyC >= ` +p.outWidth+ ` . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float dyValue = getDy ( b , idyR , idyC , d ) ;
int maxPosValue = ` +G+ ` - int ( getMaxPos ( b , idyR , idyC , d ) ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Get the current value, check it against the value from the
// position matrix.
int curPosValue = wR * ` +R+ ` + wC ;
float mask = float ( maxPosValue == curPosValue ? 1.0 : 0.0 ) ;
dotProd += dyValue * mask ;
}
}
setOutput ( dotProd ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),At=function(){function f(p){this.variableNames=["dy","maxPos"],this.outputShape=p.inShape;var l=p.strideDepth,m=p.strideHeight,g=p.strideWidth,I=p.dilationDepth,R=p.dilationHeight,P=p.dilationWidth,L=p.effectiveFilterDepth,G=p.effectiveFilterHeight,Q=p.effectiveFilterWidth,ke=L-1-p.padInfo.front,Ce=G-1-p.padInfo.top,Fe=Q-1-p.padInfo.left,Ee=L*G*Q-1;this.userCode= `
const ivec3 pads = ivec3 ( ` +ke+", "+Ce+", "+Fe+ ` ) ;
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// 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 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wD = 0 ; wD < ` +L+ ` ;
wD += ` +I+ ` ) {
float dyD = float ( dyDCorner + wD ) / ` +l+ ` . 0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( dyD < 0.0 || dyD >= ` +p.outDepth+ ` . 0 || fract ( dyD ) > 0.0 ) {
continue ;
}
int idyD = int ( dyD ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wR = 0 ; wR < ` +G+ ` ;
wR += ` +R+ ` ) {
float dyR = float ( dyRCorner + wR ) / ` +m+ ` . 0 ;
if ( dyR < 0.0 || dyR >= ` +p.outHeight+ ` . 0 ||
fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
for ( int wC = 0 ; wC < ` +Q+ ` ;
wC += ` +P+ ` ) {
float dyC = float ( dyCCorner + wC ) / ` +g+ ` . 0 ;
if ( dyC < 0.0 || dyC >= ` +p.outWidth+ ` . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
float dyValue = getDy ( batch , idyD , idyR , idyC , ch ) ;
int maxPosValue = ` +Ee+ ` -
int ( getMaxPos ( batch , idyD , idyR , idyC , ch ) ) ;
// Get the current value, check it against the value from the
// position matrix.
int curPosValue =
wD * ` +G+" * "+Q+ ` +
wR * ` +Q+ ` + wC ;
float mask = float ( maxPosValue == curPosValue ? 1.0 : 0.0 ) ;
dotProd += dyValue * mask ;
}
}
}
setOutput ( dotProd ) ;
}
` }return f}(),zt=function(){function f(p,l,m,g,I,R,P,L){g===void 0&&(g=!1),I===void 0&&(I=!1),R===void 0&&(R=!1),P===void 0&&(P=null),L===void 0&&(L=!1),this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=m;var G=g?p[1]:p[2],Q=Math.ceil(G/2),ke=g?"i * 2, rc.y":"rc.y, i * 2",Ce=I?"rc.z, i * 2":"i * 2, rc.z",Fe=g?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],Ee=I?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],Ge="",Qe="";P&&(L?Ge= ` vec4 activation ( vec4 a ) {
vec4 b = getPreluActivationWeightsAtOutCoords ( ) ;
` +P+ `
} ` :Ge= ` vec4 activation ( vec4 x ) {
` +P+ `
} ` ,Qe="result = activation(result);");var s=R?"result += getBiasAtOutCoords();":"";R&&this.variableNames.push("bias"),L&&this.variableNames.push("preluActivationWeights");var u="rc.x",r="rc.x";p[0]<l[0]?u="int(min(float(rc.x), "+(p[0]-1)+".))":l[0]<p[0]&&(r="int(min(float(rc.x), "+(l[0]-1)+".))"),this.userCode= `
` +Ge+ `
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
const float sharedDimension = ` +Q+ ` . 0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 dot2x2ARowBCol ( ivec3 rc ) {
vec4 result = vec4 ( 0 ) ;
for ( int i = 0 ; i < ` +Q+ ` ; i ++ ) {
int batchA = ` +u+ ` ;
int batchB = ` +r+ ` ;
vec4 a = getMatrixA ( batchA , ` +ke+ ` ) ;
vec4 b = getMatrixB ( batchB , ` +Ce+ ` ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// These swizzled products need to be separately added.
// See: https://github.com/tensorflow/tfjs/issues/1735
result += ( ` +Fe[0]+" * "+Ee[0]+ ` ) ;
result += ( ` +Fe[1]+" * "+Ee[1]+ ` ) ;
}
return result ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
ivec3 rc = getOutputCoords ( ) ;
vec4 result = dot2x2ARowBCol ( rc ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +s+ `
` +Qe+ `
setOutput ( result ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Pt=function(){function f(p,l,m){this.variableNames=["probs"],this.outputShape=[p,m],this.userCode= `
uniform float seed ;
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float r = random ( seed ) ;
float cdf = 0.0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int i = 0 ; i < ` +(l-1)+ ` ; i ++ ) {
cdf += getProbs ( batch , i ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( r < cdf ) {
setOutput ( float ( i ) ) ;
return ;
}
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// If no other event happened, last event happened.
setOutput ( float ( ` +(l-1)+ ` ) ) ;
}
` }return f.prototype.getCustomSetupFunc=function(p){var l=this;return function(m,g){l.seedLoc==null&&(l.seedLoc=m.getUniformLocation(g,"seed")),m.gl.uniform1f(l.seedLoc,p)}},f}(),Ut=function(){function f(p,l,m,g){this.variableNames=["indices"],this.outputShape=[p,l],this.userCode= `
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int index = round ( getIndices ( coords . x ) ) ;
setOutput ( mix ( float ( ` +g+"), float("+m+ ` ) ,
float ( index == coords . y ) ) ) ;
}
` }return f}(),Tt=function(){function f(p){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outputShape=p;var l=p.length;if(l===0)this.userCode= `
void main ( ) {
setOutput ( vec4 ( getA ( ) , 0. , 0. , 0. ) ) ;
}
` ;else{var m=Vr("rc",l),g=nn(l),I=Ht(l,p,m),R=Ot(l,p[p.length-1],p[p.length-2],m),P=Rt(p,m);this.userCode= `
void main ( ) {
` +g+ ` rc = getOutputCoords ( ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( ` +I+ ` ) {
setOutput ( vec4 ( 0 ) ) ;
} else {
` +R+ `
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
setOutput ( vec4 ( ` +P+ ` ) ) ;
}
}
` }}return f}();function Xt(f,p){for(var l=[],m=0;m<=1;m++)for(var g=0;g<=1;g++){for(var I=(m===0?"r":"rp1")+", "+(g===0?"c":"cp1"),R=2;R<f;R++)I=p[p.length-1-R]+","+I;l.push(I)}return l}function Ht(f,p,l){if(f===1)return"rc > "+p[0];for(var m="",g=f-2;g<f;g++)m+=l[g]+" >= "+p[g],g<f-1&&(m+="||");return m}function Ot(f,p,l,m){if(f===1)return"";var g=m.slice(-2);return `
int r = ` +g[0]+ ` ;
int c = ` +g[1]+ ` ;
int rp1 = r + 1 ;
int cp1 = c + 1 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
bool cEdge = cp1 >= ` +p+ ` ;
bool rEdge = rp1 >= ` +l+ ` ;
` }function Rt(f,p){var l=f.length,m=Xt(l,p);return l===1? ` getA ( rc ) ,
rc + 1 >= ` +f[0]+ ` ? 0. : getA ( rc + 1 ) ,
0 , 0 ` :"getA("+m[0]+ ` ) ,
cEdge ? 0. : getA ( ` +m[1]+ ` ) ,
rEdge ? 0. : getA ( ` +m[2]+ ` ) ,
rEdge || cEdge ? 0. : getA ( ` +m[3]+")"}var wt=function(){function f(p,l,m){this.variableNames=["x"],this.outputShape=l.map(function(G,Q){return G[0]+p[Q]+G[1]});var g=p.length,I=nn(g),R=l.map(function(G){return G[0]}).join(","),P=l.map(function(G,Q){return G[0]+p[Q]}).join(","),L=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,g);if(g===1){this.userCode= `
int start = ` +R+ ` ;
int end = ` +P+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
int outC = getOutputCoords ( ) ;
if ( outC < start || outC >= end ) {
setOutput ( float ( ` +m+ ` ) ) ;
} else {
setOutput ( getX ( outC - start ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
}
` ;return}this.userCode= `
` +I+" start = "+I+"("+R+ ` ) ;
` +I+" end = "+I+"("+P+ ` ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
` +I+ ` outC = getOutputCoords ( ) ;
if ( any ( lessThan ( outC , start ) ) || any ( greaterThanEqual ( outC , end ) ) ) {
setOutput ( float ( ` +m+ ` ) ) ;
} else {
` +I+ ` coords = outC - start ;
setOutput ( getX ( ` +L+ ` ) ) ;
}
}
` }return f}(),Et=function(){function f(p,l,m){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=l.map(function(s,u){return s[0]+p[u]+s[1]});for(var g=p.length,I=nn(g),R=l.map(function(s){return s[0]}).join(","),P=l.map(function(s,u){return s[0]+p[u]}).join(","),L=Vr("rc",g),G=Vr("source",g),Q=L[g-1]+" < "+this.outputShape[g-1],ke=g===1?"source":"vec2("+G.slice(-2).join()+")",Ce=[I+" rc = outputLoc;",L[g-1]+ ` += 1 ;
if ( ` +Q+ ` ) {
` ,g===1?"": ` }
rc = outputLoc ;
` +L[g-2]+ ` += 1 ;
if ( ` +L[g-2]+" < "+this.outputShape[g-2]+") {",g===1?"":" "+L[g-1]+ ` += 1 ;
if ( ` +Q+") {"],Fe=g===1?"rc < start || rc >= end":"any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))",Ee="",Ge=0,Qe=g===1?2:4;Ge<Qe;Ge++)Ee+= `
` +Ce[Ge]+ `
if ( ` +Fe+ ` ) {
result [ ` +Ge+"] = float("+m+ ` ) ;
} else {
` +I+ ` source = rc - start ;
result [ ` +Ge+"] = getChannel(getX("+G.join()+"), "+ke+ ` ) ;
}
` ;Ee+=g===1?"} ":"}}",this.userCode= `
const ` +I+" start = "+I+"("+R+ ` ) ;
const ` +I+" end = "+I+"("+P+ ` ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
` +I+ ` outputLoc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
` +Ee+ `
setOutput ( result ) ;
}
` }return f}(),Vt=function(){function f(p,l,m,g,I){if(g===void 0&&(g=!1),I===void 0&&(I=!1),this.variableNames=["x"],l==="avg"&&m)throw new Error("Cannot compute positions for average pool.");var R=p.filterWidth,P=p.strideHeight,L=p.strideWidth,G=p.dilationHeight,Q=p.dilationWidth,ke=p.effectiveFilterHeight,Ce=p.effectiveFilterWidth,Fe=p.padInfo.top,Ee=p.padInfo.left;this.outputShape=p.outShape;var Ge=l==="avg",Qe="((batch * "+p.inHeight+" + xR) * "+p.inWidth+" + xC) * "+p.inChannels+" + d",s="(xR * "+p.inWidth+" + xC) * "+p.inChannels+" + d",u="0.0";if(Ge||(u="-1.0 / 1e-20"),m){var r=">=";this.userCode= `
const ivec2 strides = ivec2 ( ` +P+", "+L+ ` ) ;
const ivec2 pads = ivec2 ( ` +Fe+", "+Ee+ ` ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 xRCCorner = coords . yz * strides - pads ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
// 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 ;
for ( int wR = 0 ; wR < ` +ke+ ` ;
wR += ` +G+ ` ) {
int xR = xRCorner + wR ;
if ( xR < 0 || xR >= ` +p.inHeight+ ` ) {
2020-11-06 22:21:20 +01:00
continue ;
}
2020-11-07 16:37:19 +01:00
for ( int wC = 0 ; wC < ` +Ce+ ` ;
wC += ` +Q+ ` ) {
int xC = xCCorner + wC ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xC < 0 || xC >= ` +p.inWidth+ ` ) {
continue ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float value = getX ( batch , xR , xC , d ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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 ) ;
if ( value ` +r+ ` currMinMaxValue ) {
minMaxValue = value ;
minMaxValueFound = 1.0 ;
minMaxPosition = ` +(g?I?Qe:s:"wR * "+Ce+" + wC")+ ` ;
}
2020-11-06 22:21:20 +01:00
}
}
2020-11-07 16:37:19 +01:00
setOutput ( float ( minMaxPosition ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ;return}var o="max",h=l+"("+l+"("+l+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";l==="avg"&&(h="avgValue / count");var b=Math.floor(R/4)*4,T=R%4,O= `
if ( ` +Ge+ ` ) {
avgValue += dot ( values , ones ) ;
} else {
minMaxValue = ` +o+ ` ( values , minMaxValue ) ;
}
` ;this.userCode= `
const ivec2 strides = ivec2 ( ` +P+", "+L+ ` ) ;
const ivec2 pads = ivec2 ( ` +Fe+", "+Ee+ ` ) ;
const float initializationValue = ` +u+ ` ;
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float count = 0.0 ;
float getValue ( int batch , int xR , int xC , int d ) {
if ( xC < 0 || xC >= ` +p.inWidth+ ` ) {
return initializationValue ;
}
count += 1.0 ;
return getX ( batch , xR , xC , d ) ;
2020-11-06 22:21:20 +01:00
}
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
2020-11-07 16:37:19 +01:00
int batch = coords [ 0 ] ;
2020-11-06 22:21:20 +01:00
int d = coords [ 3 ] ;
2020-11-07 16:37:19 +01:00
ivec2 xRCCorner = coords . yz * strides - pads ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
vec4 minMaxValue = vec4 ( ` +u+ ` ) ;
float avgValue = 0.0 ;
count = 0.0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wR = 0 ; wR < ` +ke+ ` ;
wR += ` +G+ ` ) {
int xR = xRCorner + wR ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xR < 0 || xR >= ` +p.inHeight+ ` ) {
continue ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
for ( int wC = 0 ; wC < ` +b+ ` ; wC += 4 ) {
int xC = xCCorner + wC * ` +Q+ ` ;
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
getValue ( batch , xR , xC + ` +Q+ ` , d ) ,
getValue ( batch , xR , xC + 2 * ` +Q+ ` , d ) ,
getValue ( batch , xR , xC + 3 * ` +Q+ ` , d )
) ;
` +O+ `
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
int xC = xCCorner + ` +b+ ` ;
if ( ` +(T===1)+ ` ) {
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
` +O+ `
} else if ( ` +(T===2)+ ` ) {
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
getValue ( batch , xR , xC + ` +Q+ ` , d ) ,
initializationValue ,
initializationValue
) ;
` +O+ `
} else if ( ` +(T===3)+ ` ) {
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
getValue ( batch , xR , xC + ` +Q+ ` , d ) ,
getValue ( batch , xR , xC + 2 * ` +Q+ ` , d ) ,
initializationValue
) ;
` +O+ `
2020-11-06 22:21:20 +01:00
}
}
2020-11-07 16:37:19 +01:00
setOutput ( ` +h+ ` ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),qt=function(){function f(p,l,m,g,I){if(g===void 0&&(g=!1),I===void 0&&(I=!1),this.variableNames=["x"],l==="avg"&&m)throw new Error("Cannot compute positions for average pool.");var R=p.filterWidth,P=p.strideDepth,L=p.strideHeight,G=p.strideWidth,Q=p.dilationDepth,ke=p.dilationHeight,Ce=p.dilationWidth,Fe=p.effectiveFilterDepth,Ee=p.effectiveFilterHeight,Ge=p.effectiveFilterWidth,Qe=p.padInfo.front,s=p.padInfo.top,u=p.padInfo.left;this.outputShape=p.outShape;var r=l==="avg",o="0.0";if(r||(o="-1.0 / 1e-20"),m){var h=">=";this.userCode= `
const ivec3 strides =
ivec3 ( ` +P+", "+L+", "+G+ ` ) ;
const ivec3 pads = ivec3 ( ` +Qe+", "+s+", "+u+ ` ) ;
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
ivec3 xCorner = ivec3 ( coords . y , coords . z , coords . w ) * strides - pads ;
int xDCorner = xCorner . x ;
int xRCorner = xCorner . y ;
int xCCorner = xCorner . z ;
// 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 ;
for ( int wD = 0 ; wD < ` +Fe+ ` ;
wD += ` +Q+ ` ) {
int xD = xDCorner + wD ;
if ( xD < 0 || xD >= ` +p.inDepth+ ` ) {
continue ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
for ( int wR = 0 ; wR < ` +Ee+ ` ;
wR += ` +ke+ ` ) {
int xR = xRCorner + wR ;
if ( xR < 0 || xR >= ` +p.inHeight+ ` ) {
continue ;
}
for ( int wC = 0 ; wC < ` +Ge+ ` ;
wC += ` +Ce+ ` ) {
int xC = xCCorner + wC ;
if ( xC < 0 || xC >= ` +p.inWidth+ ` ) {
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 ) ;
if ( value ` +h+ ` currMinMaxValue ) {
minMaxValue = value ;
minMaxValueFound = 1.0 ;
minMaxPosition = ` +(g?I?"(((batch * "+p.inDepth+" + xD) * "+p.inHeight+" + xR) * "+p.inWidth+" + xC) * "+p.inChannels+" + ch":"((xD * "+p.inHeight+" + xR) * "+p.inWidth+" + xC) * "+p.inChannels+" + ch":"wD * "+Ee+" * "+Ge+ ` +
wR * ` +Ge+" + wC")+ ` ;
}
}
2020-11-06 22:21:20 +01:00
}
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
setOutput ( float ( minMaxPosition ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ;return}var b="max",T=l+"("+l+"("+l+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";l==="avg"&&(T="avgValue / count");var O=Math.floor(R/4)*4,q=R%4,Z= `
if ( ` +r+ ` ) {
avgValue += dot ( values , ones ) ;
} else {
minMaxValue = ` +b+ ` ( values , minMaxValue ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` ;this.userCode= `
const ivec3 strides =
ivec3 ( ` +P+", "+L+", "+G+ ` ) ;
const ivec3 pads = ivec3 ( ` +Qe+", "+s+", "+u+ ` ) ;
const float initializationValue = ` +o+ ` ;
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float count = 0.0 ;
float getValue ( int batch , int xD , int xR , int xC , int ch ) {
if ( xC < 0 || xC >= ` +p.inWidth+ ` ) {
return initializationValue ;
}
count += 1.0 ;
return getX ( batch , xD , xR , xC , ch ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).
// ? = to be determined
vec4 minMaxValue = vec4 ( ` +o+ ` ) ;
float avgValue = 0.0 ;
count = 0.0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wD = 0 ; wD < ` +Fe+ ` ;
wD += ` +Q+ ` ) {
int xD = xDCorner + wD ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xD < 0 || xD >= ` +p.inDepth+ ` ) {
continue ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wR = 0 ; wR < ` +Ee+ ` ;
wR += ` +ke+ ` ) {
int xR = xRCorner + wR ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
if ( xR < 0 || xR >= ` +p.inHeight+ ` ) {
continue ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int wC = 0 ; wC < ` +O+ ` ; wC += 4 ) {
int xC = xCCorner + wC * ` +Ce+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
getValue ( batch , xD , xR , xC + ` +Ce+ ` , ch ) ,
getValue ( batch , xD , xR , xC + 2 * ` +Ce+ ` , ch ) ,
getValue ( batch , xD , xR , xC + 3 * ` +Ce+ ` , ch )
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +Z+ `
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
int xC = xCCorner + ` +O+ ` ;
if ( ` +(q===1)+ ` ) {
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +Z+ `
} else if ( ` +(q===2)+ ` ) {
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
getValue ( batch , xD , xR , xC + ` +Ce+ ` , ch ) ,
initializationValue ,
initializationValue
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +Z+ `
} else if ( ` +(q===3)+ ` ) {
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
getValue ( batch , xD , xR , xC + ` +Ce+ ` , ch ) ,
getValue ( batch , xD , xR , xC + 2 * ` +Ce+ ` , ch ) ,
initializationValue
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +Z+ `
}
}
setOutput ( ` +T+ ` ) ;
}
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),lr=function(){function f(p,l){this.variableNames=["x"];var m=p.windowSize,g=p.batchSize,I=p.inSize,R=p.outSize;this.outputShape=[g,R];var P="0.0",L="";l==="prod"?P="1.0":l==="min"?(P="1.0 / 1e-20",L="min"):l==="max"&&(P="-1.0 / 1e-20",L="max");var G=l+"("+l+"("+l+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";l==="sum"?G="sumValue":l==="prod"?G="prodValue":l==="all"?G="allValue":l==="any"&&(G="anyValue");var Q=Math.floor(m/4)*4,ke=m%4,Ce= `
if ( ` +(l==="sum")+ ` ) {
sumValue += dot ( values , ones ) ;
} else if ( ` +(l==="prod")+ ` ) {
vec2 tmp = vec2 ( values [ 0 ] , values [ 1 ] ) * vec2 ( values [ 2 ] , values [ 3 ] ) ;
prodValue *= tmp [ 0 ] * tmp [ 1 ] ;
} else {
minMaxValue = ` +L+ ` ( values , minMaxValue ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` ,Fe="vec4";l==="all"?(P="1.0",Ce= `
bool reducedAllValue = all ( values ) ;
float floatedReducedAllValue = float ( reducedAllValue ) ;
allValue = float ( allValue >= 1.0 && floatedReducedAllValue >= 1.0 ) ;
` ,Fe="bvec4"):l==="any"&&(P="0.0",Ce= `
bool reducedAnyValue = any ( values ) ;
float floatedReducedAnyValue = float ( reducedAnyValue ) ;
anyValue = float ( anyValue >= 1.0 || floatedReducedAnyValue >= 1.0 ) ;
` ,Fe="bvec4");var Ee="";I%m>0&&(Ee= `
if ( inIdx < 0 || inIdx >= ` +I+ ` ) {
return initializationValue ;
}
` ),this.userCode= `
const float initializationValue = ` +P+ ` ;
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float getValue ( int batch , int inIdx ) {
` +Ee+ `
return getX ( batch , inIdx ) ;
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
int inOffset = outIdx * ` +m+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 minMaxValue = vec4 ( ` +P+ ` ) ;
float prodValue = 1.0 ;
float sumValue = 0.0 ;
float allValue = 1.0 ;
float anyValue = 0.0 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int i = 0 ; i < ` +Q+ ` ; i += 4 ) {
int inIdx = inOffset + i ;
` +Fe+" values = "+Fe+ ` (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
getValue ( batch , inIdx + 3 )
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +Ce+ `
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
int inIdx = inOffset + ` +Q+ ` ;
if ( ` +(ke===1)+ ` ) {
` +Fe+" values = "+Fe+ ` (
getValue ( batch , inIdx ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +Ce+ `
} else if ( ` +(ke===2)+ ` ) {
` +Fe+" values = "+Fe+ ` (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
initializationValue ,
initializationValue
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +Ce+ `
} else if ( ` +(ke===3)+ ` ) {
` +Fe+" values = "+Fe+ ` (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
initializationValue
) ;
` +Ce+ `
}
setOutput ( ` +G+ ` ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),ir=function(){function f(p,l){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=p;for(var m="",g=0;g<4;g++){var I="thisRC = rc;";g%2===1&&(I+="thisRC.z += 1;"),g>1&&(I+="thisRC.y += 1;"),m+= `
` +I+ `
` +(g>0?"if(thisRC.y < rows && thisRC.z < cols){":"")+ `
int flatIndex = getFlatIndex ( thisRC ) ;
ivec3 inputRC = inputCoordsFromReshapedOutCoords ( flatIndex ) ;
vec2 inputRCInnerDims = vec2 ( float ( inputRC . y ) , float ( inputRC . z ) ) ;
result [ ` +g+ ` ] =
getChannel ( getA ( inputRC . x , inputRC . y , inputRC . z ) , inputRCInnerDims ) ;
` +(g>0?"}":"")+ `
` }this.userCode= `
` +Ie(l)+ `
` +qn(p)+ `
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec3 rc = getOutputCoords ( ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 result = vec4 ( 0. ) ;
ivec3 thisRC ;
int rows = ` +p[1]+ ` ;
int cols = ` +p[2]+ ` ;
` +m+ `
setOutput ( result ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}();function Ie(f){var p=En(["r","c","d"],f);return `
ivec3 inputCoordsFromReshapedOutCoords ( int index ) {
` +p+ `
return ivec3 ( r , c , d ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }var br=function(){function f(p,l,m){this.variableNames=["dy"],this.outputShape=[],this.outputShape=l.shape;var g=l.shape,I=g[1],R=g[2],P=p.shape,L=P[1],G=P[2],Q=[m&&L>1?I-1:I,m&&G>1?R-1:R],ke=[m&&L>1?L-1:L,m&&G>1?G-1:G],Ce=Q[0]/ke[0],Fe=Q[1]/ke[1],Ee=1/Ce,Ge=1/Fe,Qe=Math.ceil(Ee)*2+2,s=Math.ceil(Ge)*2+2;this.userCode= `
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float accumulator = 0.0 ;
const float heightScale = float ( ` +Ce+ ` ) ;
const float widthScale = float ( ` +Fe+ ` ) ;
const float invHeightScale = float ( ` +Ee+ ` ) ;
const float invWidthScale = float ( ` +Ge+ ` ) ;
const int winHeight = int ( ` +Qe+ ` ) ;
const int winWidth = int ( ` +s+ ` ) ;
// Compute bounds for where in dy we will look
float startRLerp = floor ( float ( r ) * invHeightScale ) ;
int startDyR = int ( startRLerp - float ( winHeight / 2 ) ) ;
float startCLerp = floor ( float ( c ) * invWidthScale ) ;
int startDyC = int ( startCLerp - float ( winWidth / 2 ) ) ;
// Loop over dy
for ( int dyROffset = 0 ; dyROffset < winHeight ; dyROffset ++ ) {
int dyR = dyROffset + startDyR ;
// Guard against the window exceeding the bounds of dy
if ( dyR < 0 || dyR >= ` +L+ ` ) {
continue ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
for ( int dyCOffset = 0 ; dyCOffset < winWidth ; dyCOffset ++ ) {
int dyC = dyCOffset + startDyC ;
// Guard against the window exceeding the bounds of dy
if ( dyC < 0 || dyC >= ` +G+ ` ) {
continue ;
}
float dxR = float ( dyR ) * heightScale ;
int topDxRIndex = int ( floor ( dxR ) ) ;
int bottomDxRIndex = int ( min ( ceil ( dxR ) , ` +(I-1)+ ` . 0 ) ) ;
float dxRLerp = dxR - float ( topDxRIndex ) ;
float inverseDxRLerp = 1.0 - dxRLerp ;
float dxC = float ( dyC ) * widthScale ;
int leftDxCIndex = int ( floor ( dxC ) ) ;
int rightDxCIndex = int ( min ( ceil ( dxC ) , ` +(R-1)+ ` . 0 ) ) ;
float dxCLerp = dxC - float ( leftDxCIndex ) ;
float inverseDxCLerp = 1.0 - dxCLerp ;
if ( r == topDxRIndex && c == leftDxCIndex ) {
// topLeft
accumulator +=
getDy ( b , dyR , dyC , d ) * inverseDxRLerp * inverseDxCLerp ;
}
if ( r == topDxRIndex && c == rightDxCIndex ) {
// topRight
accumulator += getDy ( b , dyR , dyC , d ) * inverseDxRLerp * dxCLerp ;
}
if ( r == bottomDxRIndex && c == leftDxCIndex ) {
// bottomLeft
accumulator += getDy ( b , dyR , dyC , d ) * dxRLerp * inverseDxCLerp ;
}
if ( r == bottomDxRIndex && c == rightDxCIndex ) {
// bottomRight
accumulator += getDy ( b , dyR , dyC , d ) * dxRLerp * dxCLerp ;
}
2020-11-06 22:21:20 +01:00
}
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
// End loop over dy
setOutput ( accumulator ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Nr=function(){function f(p,l,m,g){this.variableNames=["A"],this.outputShape=[];var I=p[0],R=p[1],P=p[2],L=p[3];this.outputShape=[I,l,m,L];var G=[g&&l>1?R-1:R,g&&m>1?P-1:P],Q=[g&&l>1?l-1:l,g&&m>1?m-1:m];this.userCode= `
const vec2 effectiveInputOverOutputRatioRC = vec2 (
` +G[0]/Q[0]+ ` ,
` +G[1]/Q[1]+ ` ) ;
const vec2 inputShapeRC = vec2 ( ` +R+".0, "+P+ ` . 0 ) ;
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 yRC = coords . yz ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Fractional source index.
vec2 sourceFracIndexRC = vec2 ( yRC ) * effectiveInputOverOutputRatioRC ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Compute the four integer indices.
ivec2 sourceFloorRC = ivec2 ( sourceFracIndexRC ) ;
ivec2 sourceCeilRC = ivec2 (
min ( inputShapeRC - 1.0 , ceil ( sourceFracIndexRC ) ) ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
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 ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
setOutput ( newValue ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Tr=function(){function f(p,l,m,g){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];var I=p[0],R=p[1],P=p[2],L=p[3];this.outputShape=[I,l,m,L];var G=[g&&l>1?R-1:R,g&&m>1?P-1:P],Q=[g&&l>1?l-1:l,g&&m>1?m-1:m];this.userCode= `
const vec3 effectiveInputOverOutputRatioRC = vec3 (
` +G[0]/Q[0]+ ` ,
` +G[1]/Q[1]+ ` ,
` +G[1]/Q[1]+ ` ) ;
const vec3 inputShapeRC = vec3 ( ` +R+".0, "+P+ ` . 0 ,
` +P+ ` . 0 ) ;
float getAValue ( int b , int r , int c , int d ) {
return getChannel ( getA ( b , r , c , d ) , vec2 ( c , d ) ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +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-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Fractional source index.
vec3 sourceFracIndexRC = vec3 ( yRC ) * effectiveInputOverOutputRatioRC ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Compute the four integer indices.
ivec3 sourceFloorRC = ivec3 ( sourceFracIndexRC ) ;
ivec3 sourceCeilRC = ivec3 (
min ( inputShapeRC - 1.0 , ceil ( sourceFracIndexRC ) ) ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Should we calculate next column and row elements in 2x2 packed cell.
bool hasNextCol = d < ` +(L-1)+ ` ;
bool hasNextRow = coords . z < ` +(m-1)+ ` ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +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 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
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 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
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 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
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 ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec3 fracRC = sourceFracIndexRC - vec3 ( sourceFloorRC ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 top = mix ( topLeft , topRight , fracRC . yyzz ) ;
vec4 bottom = mix ( bottomLeft , bottomRight , fracRC . yyzz ) ;
vec4 newValue = mix ( top , bottom , fracRC . x ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
setOutput ( newValue ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),pr=function(){function f(p,l,m){this.variableNames=["dy"],this.outputShape=[],this.outputShape=l.shape;var g=l.shape,I=g[1],R=g[2],P=p.shape,L=P[1],G=P[2],Q=[m&&L>1?I-1:I,m&&G>1?R-1:R],ke=[m&&L>1?L-1:L,m&&G>1?G-1:G],Ce=Q[0]/ke[0],Fe=Q[1]/ke[1],Ee=1/Ce,Ge=1/Fe,Qe=Math.ceil(Ee)*2+2,s=Math.ceil(Ge)*2+2;this.userCode= `
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float accumulator = 0.0 ;
const float heightScale = float ( ` +Ce+ ` ) ;
const float widthScale = float ( ` +Fe+ ` ) ;
const float invHeightScale = float ( ` +Ee+ ` ) ;
const float invWidthScale = float ( ` +Ge+ ` ) ;
const int winHeight = int ( ` +Qe+ ` ) ;
const int winWidth = int ( ` +s+ ` ) ;
// Compute bounds for where in dy we will look
float startRLerp = floor ( float ( r ) * invHeightScale ) ;
int startDyR = int ( floor ( startRLerp - float ( winHeight / 2 ) ) ) ;
float startCLerp = floor ( float ( c ) * invWidthScale ) ;
int startDyC = int ( floor ( startCLerp - float ( winWidth / 2 ) ) ) ;
// Loop over dy
for ( int dyROffset = 0 ; dyROffset < winHeight ; dyROffset ++ ) {
int dyR = dyROffset + startDyR ;
// Guard against the window exceeding the bounds of dy
if ( dyR < 0 || dyR >= ` +L+ ` ) {
continue ;
2020-11-06 19:50:16 +01:00
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
for ( int dyCOffset = 0 ; dyCOffset < winWidth ; dyCOffset ++ ) {
int dyC = dyCOffset + startDyC ;
// Guard against the window exceeding the bounds of dy
if ( dyC < 0 || dyC >= ` +G+ ` ) {
continue ;
}
float sourceFracRow =
float ( ` +Q[0]+ ` ) *
( float ( dyR ) / float ( ` +ke[0]+ ` ) ) ;
float sourceFracCol =
float ( ` +Q[1]+ ` ) *
( float ( dyC ) / float ( ` +ke[1]+ ` ) ) ;
int sourceNearestRow = int ( min (
float ( int ( ` +I+ ` ) - 1 ) ,
` +m+ ` ? float ( round ( sourceFracRow ) ) :
float ( floor ( sourceFracRow ) ) ) ) ;
int sourceNearestCol = int ( min (
float ( int ( ` +R+ ` ) - 1 ) ,
` +m+ ` ? float ( round ( sourceFracCol ) ) :
float ( floor ( sourceFracCol ) ) ) ) ;
if ( r == sourceNearestRow && c == sourceNearestCol ) {
accumulator += getDy ( b , dyR , dyC , d ) ;
}
}
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
// End loop over dy
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
setOutput ( accumulator ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Fr=function(){function f(p,l,m,g){this.variableNames=["A"],this.outputShape=[];var I=p[0],R=p[1],P=p[2],L=p[3];this.outputShape=[I,l,m,L];var G=[g&&l>1?R-1:R,g&&m>1?P-1:P],Q=[g&&l>1?l-1:l,g&&m>1?m-1:m],ke=g?"0.5":"0.0";this.userCode= `
const vec2 effectiveInputOverOutputRatioRC = vec2 (
` +G[0]/Q[0]+ ` ,
` +G[1]/Q[1]+ ` ) ;
const vec2 inputShapeRC = vec2 ( ` +R+".0, "+P+ ` . 0 ) ;
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 yRC = coords . yz ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Fractional source index.
vec2 sourceFracIndexRC = vec2 ( yRC ) * effectiveInputOverOutputRatioRC ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
// Compute the coordinators of nearest neighbor point.
ivec2 sourceNearestRC = ivec2 (
min ( inputShapeRC - 1.0 , floor ( sourceFracIndexRC + ` +ke+ ` ) ) ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float newValue = getA ( b , sourceNearestRC . x , sourceNearestRC . y , d ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
setOutput ( newValue ) ;
}
` }return f}(),mr=function(){function f(p,l){this.variableNames=["x"];var m=p.length;if(m>4)throw new Error("WebGL backend: Reverse of rank-"+m+" tensor is not yet supported");if(this.outputShape=p,m===1){this.userCode= `
void main ( ) {
int coord = getOutputCoords ( ) ;
setOutput ( getX ( ` +p[0]+ ` - coord - 1 ) ) ;
}
` ;return}var g=function(P){return l.indexOf(P)!==-1&&p[P]!==1?p[P]+" - coords["+P+"] - 1":"coords["+P+"]"},I=p.map(function(P,L){return g(L)}).join(","),R=nn(m);this.userCode= `
void main ( ) {
` +R+ ` coords = getOutputCoords ( ) ;
setOutput ( getX ( ` +I+ ` ) ) ;
}
` }return f}(),Er=function(){function f(p,l){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;var m=p.length;if(m>4)throw new Error("WebGL backend: Reverse of rank-"+m+" tensor is not yet supported");this.outputShape=p;var g=Vr("rc",m),I=g[m-1]+" + 1 < "+this.outputShape[m-1],R=g[m-2]+" + 1 < "+this.outputShape[m-2],P=nn(m);m===1?this.userCode= `
void main ( ) {
int rc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
result . r = getChannel ( getX ( ` +p[0]+ ` - rc - 1 ) ,
` +p[0]+ ` - rc - 1 ) ;
if ( ` +I+ ` ) {
result . g = getChannel ( getX ( ` +p[0]+ ` - ( rc + 1 ) - 1 ) ,
` +p[0]+ ` - ( rc + 1 ) - 1 ) ;
}
setOutput ( result ) ;
}
` :this.userCode= `
void main ( ) {
` +P+ ` rc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
result . r = ` +L(g.slice())+ ` ;
if ( ` +I+ ` ) {
result . g = ` +G(g.slice())+ ` ;
}
if ( ` +R+ ` ) {
result . b = ` +Q(g.slice())+ ` ;
if ( ` +I+ ` ) {
result . a = ` +ke(g.slice())+ ` ;
}
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
setOutput ( result ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` ;function L(Ee){return Ce(Ee)}function G(Ee){return Ee[m-1]="("+Ee[m-1]+" + 1)",Ce(Ee)}function Q(Ee){return Ee[m-2]="("+Ee[m-2]+" + 1)",Ce(Ee)}function ke(Ee){return Ee[m-1]="("+Ee[m-1]+" + 1)",Ee[m-2]="("+Ee[m-2]+" + 1)",Ce(Ee)}function Ce(Ee){var Ge=p.map(function(u,r){return Fe(r,Ee)}),Qe=Ge.join(","),s=Ge.slice(-2).join(",");return"getChannel(getX("+Qe+"), vec2("+s+"))"}function Fe(Ee,Ge){return l.indexOf(Ee)!==-1&&p[Ee]!==1?p[Ee]+" - "+Ge[Ee]+" - 1":""+Ge[Ee]}}return f}(),an=function(){function f(p,l,m,g,I,R,P){this.variableNames=["updates","indices","defaultValue"],this.outputShape=R;var L=nn(I.length),G=nn(R.length),Q="";m===1?Q="i":m===2&&(Q="i, j");var ke="getIndices("+Q+")",Ce="";g===1?Ce="i":g===2&&(Ce="i, coords[1]");var Fe="getUpdates("+Ce+")",Ee=l>1?"strides[j]":"strides";this.userCode= `
` +L+" strides = "+L+"("+I+ ` ) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
void main ( ) {
` +G+ ` coords = getOutputCoords ( ) ;
float sum = 0.0 ;
bool found = false ;
for ( int i = 0 ; i < ` +p+ ` ; i ++ ) {
int flattenedIndex = 0 ;
for ( int j = 0 ; j < ` +l+ ` ; j ++ ) {
int index = round ( ` +ke+ ` ) ;
flattenedIndex += index * ` +Ee+ ` ;
}
if ( flattenedIndex == coords [ 0 ] ) {
sum += ` +Fe+ ` ;
found = true ;
}
}
setOutput ( mix ( getDefaultValue ( ) , sum , float ( found ) ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),_n=function(){function f(p,l){this.variableNames=["x","segmentIds"];var m=p.windowSize,g=p.batchSize,I=p.inSize,R=p.numSegments,P=R*Math.ceil(I/m);this.outputShape=[g,P];var L="0.0",G="sumValue",Q=Math.floor(m/4)*4,ke=m%4,Ce= `
sumValue += dot ( values , segFilter ) ;
` ,Fe="";I%m>0&&(Fe= `
if ( inIdx < 0 || inIdx >= ` +I+ ` ) {
return initializationValue ;
}
` );var Ee="";I%m>0&&(Ee= `
if ( inIdx < 0 || inIdx >= ` +I+ ` ) {
return - 1.0 ;
}
` ),this.userCode= `
const float initializationValue = ` +L+ ` ;
2020-11-06 22:21:20 +01:00
float getValue ( int batch , int inIdx ) {
2020-11-07 16:37:19 +01:00
` +Fe+ `
2020-11-06 22:21:20 +01:00
return getX ( batch , inIdx ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
float getSegmentIdAtIndex ( int inIdx ) {
` +Ee+ `
return getSegmentIds ( inIdx ) ;
}
2020-11-06 22:21:20 +01:00
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
2020-11-07 16:37:19 +01:00
int inOffset = int ( floor ( float ( outIdx ) / float (
` +R+")) * float("+m+ ` ) ) ;
int currentSeg = int ( mod ( float ( outIdx ) , float ( ` +R+ ` ) ) ) ;
2020-11-06 22:21:20 +01:00
float sumValue = 0.0 ;
2020-11-07 16:37:19 +01:00
for ( int i = 0 ; i < ` +Q+ ` ; i += 4 ) {
2020-11-06 22:21:20 +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-07 16:37:19 +01:00
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
) ;
` +Ce+ `
2020-11-06 19:50:16 +01:00
}
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
int inIdx = inOffset + ` +Q+ ` ;
if ( ` +(ke===1)+ ` ) {
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
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +Ce+ `
} else if ( ` +(ke===2)+ ` ) {
2020-11-06 22:21:20 +01:00
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
2020-11-07 16:37:19 +01:00
getValue ( batch , inIdx + 1 ) ,
initializationValue ,
initializationValue
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 segFilter = vec4 (
int ( getSegmentIdAtIndex ( inIdx ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 1 ) ) == currentSeg ? 1 : 0 ,
0 ,
0
) ;
` +Ce+ `
} else if ( ` +(ke===3)+ ` ) {
2020-11-06 22:21:20 +01:00
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
2020-11-07 16:37:19 +01:00
getValue ( batch , inIdx + 2 ) ,
initializationValue
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
vec4 segFilter = vec4 (
int ( getSegmentIdAtIndex ( inIdx ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 1 ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 2 ) ) == currentSeg ? 1 : 0 ,
0
) ;
2020-11-06 22:21:20 +01:00
2020-11-07 16:37:19 +01:00
` +Ce+ `
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
setOutput ( ` +G+ ` ) ;
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),ie=function(){function f(p,l,m){this.variableNames=["c","a","b"],this.outputShape=l;var g,I;if(m>4)throw Error("Where for rank "+m+" is not yet supported");if(m===1)I="resRC",g="resRC";else{for(var R=["resRC.x","resRC.y","resRC.z","resRC.w"],P=[],L=[],G=0;G<l.length;G++)L.push(""+R[G]),G<p&&P.push(""+R[G]);g=P.join(),I=L.join()}var Q=nn(m);this.userCode= `
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
` +Q+ ` resRC = getOutputCoords ( ) ;
float cVal = getC ( ` +g+ ` ) ;
if ( cVal >= 1.0 ) {
setOutput ( getA ( ` +I+ ` ) ) ;
} else {
setOutput ( getB ( ` +I+ ` ) ) ;
2020-11-06 22:21:20 +01:00
}
}
2020-11-07 16:37:19 +01:00
` }return f}(),In=function(){function f(p){this.variableNames=["source"],this.outputShape=p,this.rank=p.length;var l=nn(this.rank),m="uniform int start["+this.rank+"];",g=Re(this.rank),I,R=p.map(function(P,L){return"sourceLoc."+wn[L]+" = start["+L+"] + coords."+wn[L]+";"});I= `
` +l+ ` sourceLoc ;
` +l+ ` coords = getOutputCoords ( ) ;
` +R.join( `
` )+ `
` ,this.userCode= `
` +m+ `
void main ( ) {
` +I+ `
setOutput ( getSource ( ` +g+ ` ) ) ;
}
` }return f.prototype.getCustomSetupFunc=function(p){var l=this;if(p.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the "+("length of start ("+p.length+")"));return function(m,g){if(l.startLoc==null&&(l.startLoc=m.getUniformLocationNoThrow(g,"start"),l.startLoc==null))return;m.gl.uniform1iv(l.startLoc,p)}},f}(),wn=["x","y","z","w","u","v"];function Re(f){if(f===1)return"sourceLoc";if(f<=6)return wn.slice(0,f).map(function(p){return"sourceLoc."+p}).join(",");throw Error("Slicing for rank "+f+" is not yet supported")}var Un=function(){function f(p){this.variableNames=["source"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=p,this.rank=p.length;var l=nn(this.rank),m=Vr("coords",this.rank),g=Vr("sourceLoc",this.rank),I=this.rank===1?"sourceLoc":"vec2("+g.slice(-2).join()+")",R="getChannel(getSource("+g.join()+"), "+I+")",P= `
result . x = ` +R+ ` ;
if ( ++ ` +m[this.rank-1]+" < "+p[this.rank-1]+ ` ) {
++ ` +g[this.rank-1]+ ` ;
result . y = ` +R+ ` ;
-- ` +g[this.rank-1]+ ` ;
}
` ,L=this.rank===1?"": `
-- ` +m[this.rank-1]+ ` ;
if ( ++ ` +m[this.rank-2]+" < "+p[this.rank-2]+ ` ) {
++ ` +g[this.rank-2]+ ` ;
result . z = ` +R+ ` ;
if ( ++ ` +m[this.rank-1]+" < "+p[this.rank-1]+ ` ) {
++ ` +g[this.rank-1]+ ` ;
result . w = ` +R+ ` ;
}
}
` ,G=this.rank<=4? ` sourceLoc = coords +
` +l+"("+p.map(function(Q,ke){return"start["+ke+"]"}).join()+");":p.map(function(Q,ke){return g[ke]+" = "+m[ke]+" + start["+ke+"];"}).join( `
` );this.userCode= `
uniform int start [ ` +this.rank+ ` ] ;
2020-11-06 22:21:20 +01:00
void main ( ) {
2020-11-07 16:37:19 +01:00
` +l+ ` coords = getOutputCoords ( ) ;
` +l+ ` sourceLoc ;
` +G+ `
2020-11-06 22:21:20 +01:00
vec4 result = vec4 ( 0. ) ;
2020-11-07 16:37:19 +01:00
` +P+ `
` +L+ `
2020-11-06 22:21:20 +01:00
setOutput ( result ) ;
}
2020-11-07 16:37:19 +01:00
` }return f.prototype.getCustomSetupFunc=function(p){var l=this;if(p.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the "+("length of start ("+p.length+")"));return function(m,g){if(l.startLoc==null&&(l.startLoc=m.getUniformLocationNoThrow(g,"start"),l.startLoc==null))return;m.gl.uniform1iv(l.startLoc,p)}},f}(),Ln=function(){function f(p,l,m){this.variableNames=["x"],this.outputShape=m;var g=m.length,I=nn(m.length),R=nn(m.length),P="";if(g===1)P="coords * strides + begin";else{var L=0;P=m.map(function(G,Q){return L++,m.length===1?"coords * strides["+Q+"] + begin["+Q+"]":"coords["+(L-1)+"] * strides["+Q+"] + begin["+Q+"]"}).join(",")}this.userCode= `
` +I+" begin = "+I+"("+p+ ` ) ;
` +I+" strides = "+I+"("+l+ ` ) ;
void main ( ) {
` +R+ ` coords = getOutputCoords ( ) ;
setOutput ( getX ( ` +P+ ` ) ) ;
}
2020-11-07 17:25:03 +01:00
` }return f}(),Oa=function(){function f(p){this.gpgpu=p,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}return f.prototype.acquireTexture=function(p,l,m){var g=xa(l,m),I=_a(p,g,m);I in this.freeTextures||(this.freeTextures[I]=[]),I in this.usedTextures||(this.usedTextures[I]=[]);var R=Ja(p,g,this.gpgpu.gl,this.gpgpu.textureConfig,m);if(this.freeTextures[I].length>0){this.numFreeTextures--,this.numUsedTextures++,this._numBytesFree-=R,this.log();var P=this.freeTextures[I].shift();return this.usedTextures[I].push(P),P}var L;return g===xe.PACKED_2X2_FLOAT32?L=this.gpgpu.createPackedMatrixTexture(p[0],p[1]):g===xe.PACKED_2X2_FLOAT16?L=this.gpgpu.createFloat16PackedMatrixTexture(p[0],p[1]):g===xe.UNPACKED_FLOAT32?L=this.gpgpu.createFloat32MatrixTexture(p[0],p[1]):g===xe.UNPACKED_FLOAT16?L=this.gpgpu.createFloat16MatrixTexture(p[0],p[1]):g===xe.PACKED_4X1_UNSIGNED_BYTE&&(L=this.gpgpu.createUnsignedBytesMatrixTexture(p[0],p[1])),this.usedTextures[I].push(L),this.numUsedTextures++,this._numBytesAllocated+=R,this.log(),L},f.prototype.releaseTexture=function(p,l,m,g){if(this.freeTextures==null)return;var I=xa(m,g),R=_a(l,I,g);R in this.freeTextures||(this.freeTextures[R]=[]);var P=Ja(l,I,this.gpgpu.gl,this.gpgpu.textureConfig,g),L=i.env().get("WEBGL_DELETE_TEXTURE_THRESHOLD");L!==-1&&this._numBytesAllocated>L?(this.gpgpu.deleteMatrixTexture(p),this._numBytesAllocated-=P):(this.freeTextures[R].push(p),this.numFreeTextures++,this._numBytesFree+=P),this.numUsedTextures--;var G=this.usedTextures[R],Q=G.indexOf(p);if(Q<0)throw new Error("Cannot release a texture that was never provided by this texture manager");G.splice(Q,1),this.log()},f.prototype.log=function(){if(!this.logEnabled)return;var p=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",this.numFreeTextures+" / "+this.numUsedTextures,"("+p+")");var l=this._numBytesFree/this._numBytesAllocated;console.log("Bytes allocated: "+this._numBytesAllocated),console.log("Bytes unused: "+this._numBytesFree+" ("+Math.round(100*l)+"%)")},Object.defineProperty(f.prototype,"numBytesAllocated",{get:function(){return this._numBytesAllocated},enumerable:!0,configurable:!0}),Object.defineProperty(f.prototype,"numBytesFree",{get:function(){return this._numBytesFree},enumerable:!0,configurable:!0}),f.prototype.getNumUsedTextures=function(){return this.numUsedTextures},f.prototype.getNumFreeTextures=function(){return this.numFreeTextures},f.prototype.dispose=function(){var p=this;if(this.freeTextures==null)return;for(var l in this.freeTextures)this.freeTextures[l].forEach(function(m){p.gpgpu.deleteMatrixTexture(m)});for(var l in this.usedTextures)this.usedTextures[l].forEach(function(g){p.gpgpu.deleteMatrixTexture(g)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0},f}();function An(f,p){var l=f;if(p===l.R32F)return 4;if(p===l.R16F)return 2;if(p===l.RGBA32F)return 16;if(p===f.RGBA)return 16;if(p===l.RGBA16F)return 8;throw new Error("Unknown internal format "+p)}function Ja(f,p,l,m,g){var I=Wa(p,m),R;if(g){var P=ut(f[0],f[1]),L=P[0],G=P[1];R=L*G}else{var Q=We(f[0],f[1]),ke=Q[0],Ce=Q[1];R=ke*Ce}var Fe=An(l,I);return R*Fe}function Wa(f,p){switch(f){case xe.PACKED_2X2_FLOAT32:return ue(p);case xe.PACKED_2X2_FLOAT16:return D(p);case xe.UNPACKED_FLOAT32:return ki(p);case xe.UNPACKED_FLOAT16:return Lo(p);case xe.PACKED_4X1_UNSIGNED_BYTE:return ns(p);default:throw new Error("Unknown physical texture type "+f)}}function $ a(f){return i.env().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?f?xe.PACKED_2X2_FLOAT32:xe.UNPACKED_FLOAT32:f?xe.PACKED_2X2_FLOAT16:xe.UNPACKED_FLOAT16}function xa(f,p){if(f===w.UPLOAD)return xe.PACKED_2X2_FLOAT32;if(f===w.RENDER||f==null)return $ a(p);if(f===w.DOWNLOAD||f===w.PIXELS)return xe.PACKED_4X1_UNSIGNED_BYTE;throw new Error("Unknown logical texture type "+f)}function _a(f,p,l){return f[0]+"_"+f[1]+"_"+p+"_"+l}var Zi=function(){function f(p,l){this.variableNames=["A"];for(va
2020-11-07 16:37:19 +01:00
void main ( ) {
` +I+ ` resRC = getOutputCoords ( ) ;
setOutput ( getA ( ` +R+ ` ) ) ;
}
` }return f}();function Bi(f){var p=f.length;if(p>5)throw Error("Tile for rank "+p+" is not yet supported");if(p===1)return"imod(resRC, "+f[0]+")";for(var l=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],m=[],g=0;g<f.length;g++)m.push("imod("+l[g]+", "+f[g]+")");return m.join()}var Mr=function(){function f(p,l){this.variableNames=["A"],this.outputShape=p,this.userCode= `
float unaryOperation ( float x ) {
` +l+ `
2020-11-06 22:21:20 +01:00
}
void main ( ) {
2020-11-07 16:37:19 +01:00
float x = getAAtOutCoords ( ) ;
float y = unaryOperation ( x ) ;
setOutput ( y ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),ei="if (isnan(x)) return x;",as="return x;",Po="return abs(x);",dn=ei+ `
return ( x < 0.0 ) ? 0.0 : x ;
` ,Bo=ei+ `
return ( x < 0.0 ) ? 0.0 : min ( 6.0 , x ) ;
` ,Fn="return (x >= 0.0) ? x : (exp(x) - 1.0);",ou= `
// Stable and Attracting Fixed Point (0, 1) for Normalized Weights.
// see: https://arxiv.org/abs/1706.02515
float scaleAlpha = ` +i.backend_util.SELU_SCALEALPHA+ ` ;
float scale = ` +i.backend_util.SELU_SCALE+ ` ;
return ( x >= 0.0 ) ? scale * x : scaleAlpha * ( exp ( x ) - 1.0 ) ;
` ;function cc(f){return f===void 0&&(f=0),ei+( `
return x > 0.0 ? 1.0 : float ( ` +f+ ` ) ;
` )}var ui="return -x;",ku="return ceil(x);",Su="return floor(x);",lc= `
if ( isnan ( x ) ) { return 0.0 ; }
return sign ( x ) ;
` ,_s="return float(isnan(x));",Si="return float(isinf(x));",ws="return float(!isnan(x) && !isinf(x));",bo= `
// 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 ;
2020-11-06 22:21:20 +01:00
}
}
2020-11-07 16:37:19 +01:00
` ,uo="return exp(x);",Iu="return exp(x) - 1.0;",su= ` if ( x < 0.0 ) return NAN ;
return log ( x ) ; ` ,bs="return log(1.0 + x);",Nu="return sqrt(x);",uu="return inversesqrt(x);",Cu="return 1.0 / (1.0 + exp(-1.0 * x));",hc= `
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 ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
else if ( too _small ) {
result = exp _x ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
else {
result = log ( exp _x + 1.0 ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
return result ;
` ,co=ei+ `
if ( abs ( x ) > 1. ) {
return NAN ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
return asin ( x ) ;
` ,ks=ei+ `
if ( abs ( x ) > 1. ) {
return NAN ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
return acos ( x ) ;
` ,Tu=ei+ `
return atan ( x ) ;
` ,pc= `
float e2x = exp ( x ) ;
return ( e2x - 1.0 / e2x ) / 2.0 ;
` ,dc= `
float e2x = exp ( - x ) ;
return ( e2x + 1.0 / e2x ) / 2.0 ;
` ,fc= `
float e2x = exp ( - 2.0 * abs ( x ) ) ;
return sign ( x ) * ( 1.0 - e2x ) / ( 1.0 + e2x ) ;
` ,vl=ei+"return log(x + sqrt(x * x + 1.0));",Eu=ei+ `
if ( x < 1.0 ) return NAN ;
return log ( x + sqrt ( x * x - 1.0 ) ) ; ` ,mc=ei+ `
if ( ( x < - 1.0 ) || ( x > 1.0 ) ) return NAN ;
return ( log ( 1.0 + x ) - log ( 1.0 - x ) ) / 2.0 ; ` ,yc= `
// Error function is calculated approximately with elementary function.
// See "Handbook of Mathematical Functions with Formulas,
// Graphs, and Mathematical Tables", Abramowitz and Stegun.
float p = ` +i.backend_util.ERF_P+ ` ;
float a1 = ` +i.backend_util.ERF_A1+ ` ;
float a2 = ` +i.backend_util.ERF_A2+ ` ;
float a3 = ` +i.backend_util.ERF_A3+ ` ;
float a4 = ` +i.backend_util.ERF_A4+ ` ;
float a5 = ` +i.backend_util.ERF_A5+ ` ;
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 ) ) ;
` ,Ii="return 1.0 / x;",is="return float(!(x >= 1.0));",Ss="return x;",vc="return x;",Wo= `
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 ;
return result ;
` ,lo= `
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 ;
` ,Uo= `
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 ;
` ,cu= `
vec4 result ;
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 ) ;
return result ;
` ,os=function(){function f(p,l){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=p,this.userCode= `
vec4 unaryOperation ( vec4 x ) {
` +l+ `
}
void main ( ) {
vec4 x = getAAtOutCoords ( ) ;
vec4 y = unaryOperation ( x ) ;
setOutput ( y ) ;
}
` }return f}(),Vo=function(){function f(p){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outputShape=p;var l=p.length,m=Vr("rc",l),g=nn(l),I=Jn(l,m),R=m.slice(-2),P=l<=1?"rc":"vec2("+R.join(",")+")";this.userCode= `
void main ( ) {
` +g+ ` rc = getOutputCoords ( ) ;
vec4 packedInput = getA ( ` +I+ ` ) ;
setOutput ( getChannel ( packedInput , ` +P+ ` ) ) ;
}
2020-11-07 17:25:03 +01:00
` }return f}(),gl=i.backend_util.segment_util,xl=i.kernel_impls.split,Ru=i.kernel_impls.tile,gc=i.kernel_impls.topkImpl,Ws=i.kernel_impls.whereImpl,xc=1e-7,Qi=1e-4,lu={};function dr(f){return f in lu||(lu[f]={}),lu[f]}function Us(f,p){if(p===void 0&&(p=!1),f==="linear")return p?vc:as;if(f==="relu")return p?lo:dn;if(f==="elu")return p?cu:Fn;if(f==="relu6")return p?Uo:Bo;if(f==="prelu")return p?Da:Ta;throw new Error("Activation "+f+" has not been implemented for the WebGL backend.")}var Ho=128,Au=600;function _c(){return i.env().global.screen==null?1024:i.env().global.screen.height*i.env().global.screen.width*window.devicePixelRatio*Au/1024/1024}var Fu=1e3,Go=function(f){M(p,f);function p(l){var m=f.call(this)||this;if(m.pendingRead=new WeakMap,m.pendingDisposal=new WeakSet,m.dataRefCount=new WeakMap,m.numBytesInGPU=0,m.uploadWaitMs=0,m.downloadWaitMs=0,m.warnedAboutMemory=!1,m.warnedAboutCPUBackend=!1,m.pendingDeletes=0,m.disposed=!1,!i.env().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(l==null){var g=z(i.env().getNumber("WEBGL_VERSION"));m.binaryCache=dr(i.env().getNumber("WEBGL_VERSION")),m.gpgpu=new Oe(g),m.canvas=g.canvas,m.gpgpuCreatedLocally=!0}else m.gpgpu=l,m.binaryCache={},m.gpgpuCreatedLocally=!1,m.canvas=l.gl.canvas;return m.textureManager=new Oa(m.gpgpu),m.numMBBeforeWarning=_c(),m.texData=new i.DataStorage(m,i.engine()),m}return p.prototype.numDataIds=function(){return this.texData.numDataIds()+(this.cpuBackend?this.cpuBackend.numDataIds():0)-this.pendingDeletes},p.prototype.write=function(l,m,g){if((i.env().getBool("WEBGL_CHECK_NUMERICAL_PROBLEMS")||i.env().getBool("DEBUG"))&&this.checkNumericalProblems(l),g==="complex64"&&l!=null)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");var I={};return this.texData.set(I,{shape:m,dtype:g,values:l,usage:w.UPLOAD,refCount:1,complexParentRefCount:0}),I},p.prototype.incRef=function(l){var m=this.texData.get(l);m.refCount++},p.prototype.decRef=function(l){if(this.texData.has(l)){var m=this.texData.get(l);m.refCount--}},p.prototype.move=function(l,m,g,I){if(i.env().getBool("DEBUG")&&this.checkNumericalProblems(m),I==="complex64")throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(l,{shape:g,dtype:I,values:m,usage:w.UPLOAD,refCount:1,complexParentRefCount:0})},p.prototype.disposeIntermediateTensorInfo=function(l){var m=l.dataId;if(this.texData.has(m)){var g=this.texData.get(m);g.refCount--,g.refCount<1&&this.disposeData(m)}},p.prototype.readSync=function(l){var m=this.texData.get(l),g=m.values,I=m.dtype,R=m.complexTensorInfos,P=m.slice,L=m.shape,G=m.isPacked;if(P!=null){var Q=void 0;G?Q=new os(L,Ss):Q=new Mr(L,Ss);var ke=this.runWebGLProgram(Q,[{dataId:l,shape:L,dtype:I}],I),Ce=this.readSync(ke.dataId);return this.disposeIntermediateTensorInfo(ke),Ce}if(g!=null)return this.convertAndCacheOnCPU(l);if(I==="string")return g;var Fe=this.activeTimers!=null,Ee;Fe&&(Ee=i.util.now());var Ge;if(I==="complex64"){var Qe=this.readSync(R.real.dataId),s=this.readSync(R.imag.dataId);Ge=i.backend_util.mergeRealAndImagArrays(Qe,s)}else Ge=this.getValuesFromTexture(l);return Fe&&(this.downloadWaitMs+=i.util.now()-Ee),this.convertAndCacheOnCPU(l,Ge)},p.prototype.read=function(l){return V(this,void 0,void 0,function(){var m,g,I,R,P,L,G,Q,ke,Ce,Fe,Ee,Ge,Qe,s,u,r,o,h,b,T,O;return oe(this,function(q){switch(q.label){case 0:if(this.pendingRead.has(l))return m=this.pendingRead.get(l),[2,new Promise(function(Z){return m.push(Z)})];if(g=this.texData.get(l),I=g.values,R=g.shape,P=g.slice,L=g.dtype,G=g.complexTensorInfos,Q=g.isPacked,P!=null)return ke=void 0,Q?ke=new os(R,Ss):ke=new Mr(R,Ss),Ce=this.runWebGLProgram(ke,[{dataId:l,shape:R,dtype:L}],L),Fe=this.read(Ce.dataId),this.disposeIntermediateTensorInfo(Ce),[2,Fe];if(I!=null)return[2,this.convertAndCacheOnCPU(l)];if(!i.env().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&&i.env().getNumber("WEBGL_VERSION")===2)throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");re
2020-11-07 16:37:19 +01:00
if ( isnan ( a ) ) return a ;
if ( isnan ( b ) ) return b ;
` ,Ou= `
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 ;
2020-11-07 17:25:03 +01:00
` ;function Hs(f){return function(p){var l=p.inputs,m=p.backend,g=l.x,I=m,R=new Mr(g.shape,f);return I.runWebGLProgram(R,[g],g.dtype)}}function fo(f){var p=f.opSnippet,l=f.packedOpSnippet,m=f.checkOutOfBounds,g=m===void 0?!1:m,I=f.supportsComplex,R=I===void 0?!1:I,P=f.cpuKernelImpl,L=f.dtype;return function(G){var Q=G.inputs,ke=G.backend,Ce=Q,Fe=Ce.a,Ee=Ce.b,Ge=ke;if(R&&Fe.dtype==="complex64"){var Qe=Ge.texData.get(Fe.dataId),s=Ge.texData.get(Ee.dataId),u=[[Qe.complexTensorInfos.real,s.complexTensorInfos.real],[Qe.complexTensorInfos.imag,s.complexTensorInfos.imag]].map(function(je){var qe=je[0],vt=je[1],pt={dataId:qe.dataId,dtype:qe.dtype,shape:Fe.shape},ct={dataId:vt.dataId,dtype:vt.dtype,shape:Ee.shape},dt=new vn(p,Fe.shape,Ee.shape);return Ge.runWebGLProgram(dt,[pt,ct],i.upcastType(qe.dtype,vt.dtype))}),r=u[0],o=u[1],h=po({inputs:{real:r,imag:o},backend:Ge});return Ge.disposeIntermediateTensorInfo(r),Ge.disposeIntermediateTensorInfo(o),h}var b=L||i.upcastType(Fe.dtype,Ee.dtype);if(Ge.shouldExecuteOnCPU([Fe,Ee])&&P!=null){var Qe=Ge.texData.get(Fe.dataId),s=Ge.texData.get(Ee.dataId),T=P(Fe.shape,Ee.shape,Qe.values,s.values,b),O=T[0],q=T[1],Z=Ge.makeTensorInfo(q,b),le=Ge.texData.get(Z.dataId);return le.values=O,Z}var Ne=i.env().getBool("WEBGL_PACK_BINARY_OPERATIONS")&&l!=null,Be;return Ne?Be=new vi(l,Fe.shape,Ee.shape,g):Be=new vn(p,Fe.shape,Ee.shape),Ge.runWebGLProgram(Be,[Fe,Ee],b)}}var Mu="return a + b;",_l=fo({opSnippet:Mu,packedOpSnippet:Mu,supportsComplex:!0,cpuKernelImpl:tt}),zu={kernelName:i.Add,backendName:"webgl",kernelFunc:_l},Lu=Ic+ `
2020-11-07 16:37:19 +01:00
return atan ( a , b ) ;
` ,pu= `
vec4 result = atan ( a , b ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
` +Ou+ `
return result ;
` ,wl=fo({opSnippet:Lu,packedOpSnippet:pu}),du={kernelName:i.Atan2,backendName:"webgl",kernelFunc:wl};function fu(f){var p=f.inputs,l=f.backend,m=f.attrs,g=p.x;ln(g,"avgPool");var I=m.filterSize,R=m.strides,P=m.pad,L=m.dimRoundingMode,G=1;i.util.assert(i.backend_util.eitherStridesOrDilationsAreOne(R,G),function(){return"Error in avgPool: Either strides or dilations must be 1. "+("Got strides "+R+" and dilations '"+G+"'")});var Q=i.backend_util.computePool2DInfo(g.shape,I,R,G,P,L);if(Q.filterWidth===1&&Q.filterHeight===1&&i.util.arraysEqual(Q.inShape,Q.outShape))return ho({inputs:{x:g},backend:l});var ke=new Vt(Q,"avg",!1);return l.runWebGLProgram(ke,[g],"float32")}var Nc={kernelName:i.AvgPool,backendName:"webgl",kernelFunc:fu};function Cc(f){var p=f.inputs,l=f.backend,m=f.attrs,g=p.dy,I=p.input,R=I;ln([g,I],"avgPoolBackprop");var P=m.filterSize,L=m.strides,G=m.pad,Q=i.backend_util.computePool2DInfo(R.shape,P,L,1,G),ke=new si(Q);return l.runWebGLProgram(ke,[g],R.dtype)}var Tc={kernelName:i.AvgPoolBackprop,backendName:"webgl",kernelFunc:Cc},Ec=function(){function f(p,l,m,g,I,R){this.outputShape=[],this.variableNames=["x","mean","variance"],i.backend_util.assertAndGetBroadcastShape(p,l),i.backend_util.assertAndGetBroadcastShape(p,m);var P="0.0";g!=null&&(i.backend_util.assertAndGetBroadcastShape(p,g),this.variableNames.push("offset"),P="getOffsetAtOutCoords()");var L="1.0";I!=null&&(i.backend_util.assertAndGetBroadcastShape(p,I),this.variableNames.push("scale"),L="getScaleAtOutCoords()"),this.outputShape=p,this.userCode= `
void main ( ) {
float x = getXAtOutCoords ( ) ;
float mean = getMeanAtOutCoords ( ) ;
float variance = getVarianceAtOutCoords ( ) ;
float offset = ` +P+ ` ;
float scale = ` +L+ ` ;
float inv = scale * inversesqrt ( variance + float ( ` +R+ ` ) ) ;
setOutput ( dot ( vec3 ( x , - mean , offset ) , vec3 ( inv , inv , 1 ) ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Ke=function(){function f(p,l,m,g,I,R){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],i.backend_util.assertAndGetBroadcastShape(p,l),i.backend_util.assertAndGetBroadcastShape(p,m);var P="vec4(0.0)";g!=null&&(i.backend_util.assertAndGetBroadcastShape(p,g),this.variableNames.push("offset"),P="getOffsetAtOutCoords()");var L="vec4(1.0)";I!=null&&(i.backend_util.assertAndGetBroadcastShape(p,I),this.variableNames.push("scale"),L="getScaleAtOutCoords()"),this.outputShape=p,this.userCode= `
void main ( ) {
vec4 offset = ` +P+ ` ;
vec4 scale = ` +L+ ` ;
vec4 x = getXAtOutCoords ( ) ;
vec4 mean = getMeanAtOutCoords ( ) ;
vec4 variance = getVarianceAtOutCoords ( ) ;
vec4 inv = scale * inversesqrt ( variance + vec4 ( ` +R+ ` ) ) ;
setOutput ( ( x - mean ) * inv + offset ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Rc=function(f){var p=f.inputs,l=f.backend,m=f.attrs,g=p.x,I=p.mean,R=p.variance,P=p.offset,L=p.scale;i.util.assert(I.shape.length===R.shape.length,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),i.util.assert(P==null||I.shape.length===P.shape.length,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),i.util.assert(L==null||I.shape.length===L.shape.length,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."});var G=m.varianceEpsilon;G==null&&(G=.001);var Q=[g,I,R],ke=null;P!=null&&(ke=P.shape,Q.push(P));var Ce=null;L!=null&&(Ce=L.shape,Q.push(L));var Fe=i.env().getBool("WEBGL_PACK_NORMALIZATION")?new Ke(g.shape,I.shape,R.shape,ke,Ce,G):new Ec(g.shape,I.shape,R.shape,ke,Ce,G),Ee=l.runWebGLProgram(Fe,Q,Q[0].dtype);return Ee},sn={kernelName:i.FusedBatchNorm,backendName:"webgl",kernelFunc:Rc},Ac="return float(a != b);",Is=fo({opSnippet:Ac,dtype:"bool"}),Fc={kernelName:i.NotEqual,backendName:"webgl",kernelFunc:Is};function $ n(f){var p=f.inputs,l=f.backend,m=p.input,g=l.texData.get(m.dataId);return ho({inputs:{x:g.complexTensorInfos.real},backend:l})}var Dc={kernelName:i.Real,backendName:"webgl",kernelFunc: $ n},Oc="return float(int(x));";function Mc(f,p){var l=new Mr(f.shape,Oc),m=p.runWebGLProgram(l,[f],"int32");return{dataId:m.dataId,shape:m.shape,dtype:m.dtype}}function Gs(f){var p=f.inputs,l=f.backend,m=f.attrs,g=p.x,I=m.dtype;if(I==="complex64"){if(g.dtype==="complex64")return ho({inputs:{x:g},backend:l});var R=i.zeros(g.shape),P=Gs({inputs:{x:g},backend:l,attrs:{dtype:"float32"}}),L=po({inputs:{real:P,imag:R},backend:l});return R.dispose(),l.disposeIntermediateTensorInfo(P),L}if(g.dtype==="complex64"){var G= $ n({inputs:{input:g},backend:l}),L=Gs({inputs:{x:G},backend:l,attrs:{dtype:I}});return l.disposeIntermediateTensorInfo(G),L}if(!i.util.hasEncodingLoss(g.dtype,I)){var L=ho({inputs:{x:g},backend:l});return{dataId:L.dataId,shape:L.shape,dtype:I}}if(I==="int32")return Mc(g,l);if(I==="bool"){var Q=l.makeTensorInfo([],"bool",i.util.getTypedArrayFromDType("bool",1)),ke={a:g,b:Q},L=Is({inputs:ke,backend:l});return l.disposeIntermediateTensorInfo(Q),L}throw new Error("Error in Cast: failed to cast "+g.dtype+" to "+I)}var ss={kernelName:i.Cast,backendName:"webgl",kernelFunc:Gs},zc=function(){function f(p){this.outputShape=[],this.outputShape=i.backend_util.computeOutShape(p,1),this.variableNames=p.map(function(L,G){return"T"+G});var l=new Array(p.length-1);l[0]=p[0][1];for(var m=1;m<l.length;m++)l[m]=l[m-1]+p[m][1];for(var g=["if (yC < "+l[0]+") setOutput(getT0(yR, yC));"],m=1;m<l.length;m++){var I=l[m-1];g.push("else if (yC < "+l[m]+") "+("setOutput(getT"+m+"(yR, yC-"+I+"));"))}var R=l.length,P=l[l.length-1];g.push("else setOutput(getT"+R+"(yR, yC-"+P+"));"),this.userCode= `
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int yR = coords . x ;
int yC = coords . y ;
` +g.join( `
` )+ `
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Lc=function(){function f(p,l){this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[],this.outputShape=i.backend_util.computeOutShape(p,l);var m=this.outputShape,g=m.length,I=nn(g),R=Vr("coords",g),P=["x","y","z","w","u","v"].slice(0,g);this.variableNames=p.map(function(s,u){return"T"+u});var L=new Array(p.length-1);L[0]=p[0][l];for(var G=1;G<L.length;G++)L[G]=L[G-1]+p[G][l];for(var Q=P[l],ke=P.slice(-2),Ce=P.join(),Fe="if ("+Q+" < "+L[0]+ ` ) {
return getChannel (
getT0 ( ` +Ce+"), vec2("+ke.join()+ ` ) ) ;
} ` ,G=1;G<L.length;G++){var Ee=L[G-1];Fe+= `
if ( ` +Q+" < "+L[G]+" && "+Q+" >= "+L[G-1]+ ` ) {
return getChannel (
getT ` +G+"("+mu(P,Q,Ee)+ ` ) ,
vec2 ( ` +mu(ke,Q,Ee)+ ` ) ) ;
} ` }var Ge=L.length,Qe=L[L.length-1];Fe+= `
return getChannel (
getT ` +Ge+"("+mu(P,Q,Qe)+ ` ) ,
vec2 ( ` +mu(ke,Q,Qe)+"));",this.userCode= `
float getValue ( ` +P.map(function(s){return"int "+s})+ ` ) {
` +Fe+ `
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
void main ( ) {
` +I+ ` coords = getOutputCoords ( ) ;
vec4 result = vec4 ( getValue ( ` +R+ ` ) , 0. , 0. , 0. ) ;
` +R[g-1]+" = "+R[g-1]+ ` + 1 ;
if ( ` +R[g-1]+" < "+m[g-1]+ ` ) {
result . g = getValue ( ` +R+ ` ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` +R[g-2]+" = "+R[g-2]+ ` + 1 ;
if ( ` +R[g-2]+" < "+m[g-2]+ ` ) {
result . a = getValue ( ` +R+ ` ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` +R[g-1]+" = "+R[g-1]+ ` - 1 ;
if ( ` +R[g-2]+" < "+m[g-2]+ ` &&
` +R[g-1]+" < "+m[g-1]+ ` ) {
result . b = getValue ( ` +R+ ` ) ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
setOutput ( result ) ;
2020-11-06 17:39:39 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}();function mu(f,p,l){var m=f.indexOf(p),g=f.map(function(I,R){return R===m?I+" - "+l:I});return g.join()}function Pc(f){var p=f.inputs,l=f.backend,m=p.input,g=l.texData.get(m.dataId);return ho({inputs:{x:g.complexTensorInfos.imag},backend:l})}var Pu={kernelName:i.Imag,backendName:"webgl",kernelFunc:Pc};function bl(f,p,l){var m=[Ga(f.shape)].concat(Sa(f.shape)),g={dtype:f.dtype,shape:m,dataId:f.dataId},I=[Ga(p)].concat(Sa(p)),R=new ir(I,m),P=!0,L=l.runWebGLProgram(R,[g],f.dtype,null,P);return{dataId:L.dataId,shape:p,dtype:L.dtype}}function Ji(f){var p=f.inputs,l=f.backend,m=f.attrs,g=p.x,I=m.shape,R=l,P=i.util.sizeFromShape(g.shape),L=i.util.inferFromImplicitShape(I,P),G=i.util.sizeFromShape(L);i.util.assert(P===G,function(){return"The new shape ("+L+") has "+G+" elements and the old "+("shape ("+g.shape+") has "+P+" elements. The new shape and old ")+"shape must have the same number of elements."});var Q=R.texData.get(g.dataId);return Q.isPacked&&!xn(g.shape,L)&&!(Q.texture!==null&&xn(Q.shape,L))?bl(g,L,R):(R.incRef(g.dataId),{dataId:g.dataId,shape:L,dtype:g.dtype})}var Bu={kernelName:i.Reshape,backendName:"webgl",kernelFunc:Ji};function us(f,p,l){var m=f[0].dtype;if(m==="complex64"){var g=f.map(function(r){return $ n({inputs:{input:r},backend:l})}),I=f.map(function(r){return Pc({inputs:{input:r},backend:l})}),R=us(g,p,l),P=us(I,p,l),L=po({inputs:{real:R,imag:P},backend:l});return g.forEach(function(r){return l.disposeIntermediateTensorInfo(r)}),I.forEach(function(r){return l.disposeIntermediateTensorInfo(r)}),l.disposeIntermediateTensorInfo(R),l.disposeIntermediateTensorInfo(P),L}if(f.length>i.env().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){var G=Math.floor(f.length/2),Q=us(f.slice(0,G),p,l),ke=us(f.slice(G),p,l),Ce=us([Q,ke],p,l);return l.disposeIntermediateTensorInfo(Q),l.disposeIntermediateTensorInfo(ke),Ce}if(i.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&f[0].shape.length>1){var Fe=new Lc(f.map(function(r){return r.shape}),p);return l.runWebGLProgram(Fe,f,m)}var Ee=i.backend_util.computeOutShape(f.map(function(r){return r.shape}),p),Ge=f.map(function(r){return Ji({inputs:{x:r},attrs:{shape:[-1,i.util.sizeFromShape(r.shape.slice(p))]},backend:l})}),Qe=new zc(Ge.map(function(r){return r.shape})),s=l.runWebGLProgram(Qe,Ge,m);Ge.forEach(function(r){return l.disposeIntermediateTensorInfo(r)});var u=Ji({inputs:{x:s},attrs:{shape:Ee},backend:l});return l.disposeIntermediateTensorInfo(s),u}function kl(f){var p=f.inputs,l=f.backend,m=f.attrs,g=m.axis,I=i.util.parseAxisParam(g,p[0].shape)[0],R=i.backend_util.computeOutShape(p.map(function(G){return G.shape}),I);if(i.util.sizeFromShape(R)===0)return l.makeTensorInfo(R,p[0].dtype,[]);var P=p.filter(function(G){return i.util.sizeFromShape(G.shape)>0});if(P.length===1)return P[0];var L=P.map(function(G){return G.shape});return i.backend_util.assertParamsConsistent(L,I),us(P,I,l)}var Bc={kernelName:i.Concat,backendName:"webgl",kernelFunc:kl},yu=hu+ `
return cos ( x ) ;
` ,Wc=Hs(yu),Uc={kernelName:i.Cos,backendName:"webgl",kernelFunc:Wc},Vc= `
if ( a == b ) {
return 1.0 ;
} ;
return a / b ; ` ,Hc= `
// 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. ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
if ( a . y == b . y ) {
result . y = 1. ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
if ( a . z == b . z ) {
result . z = 1. ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
if ( a . w == b . w ) {
result . w = 1. ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
return result ;
` ,Gc=fo({opSnippet:Vc,packedOpSnippet:Hc,checkOutOfBounds:!0}),jc={kernelName:i.Div,backendName:"webgl",kernelFunc:Gc},Wu=function(){function f(p,l,m){this.variableNames=["real","imag"];var g=l[1];this.outputShape=l;var I=m?"2.0 * "+Math.PI:"-2.0 * "+Math.PI,R=m?g+".0":"1.0",P;if(p==="real")P="return real * expR - imag * expI;";else if(p==="imag")P="return real * expI + imag * expR;";else throw new Error('FFT component must be either "real" or "imag", got '+p+".");this.userCode= `
const float exponentMultiplier = ` +I+ ` ;
float unaryOpComplex ( float real , float expR , float imag , float expI ) {
` +P+ `
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
float mulMatDFT ( int batch , int index ) {
float indexRatio = float ( index ) / float ( ` +g+ ` ) ;
float exponentMultiplierTimesIndexRatio =
exponentMultiplier * indexRatio ;
float result = 0.0 ;
for ( int i = 0 ; i < ` +g+ ` ; i ++ ) {
// 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 ) ;
result +=
unaryOpComplex ( real , expR , imag , expI ) / ` +R+ ` ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
return result ;
2020-11-04 17:57:44 +01:00
}
2020-11-07 16:37:19 +01:00
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
setOutput ( mulMatDFT ( coords [ 0 ] , coords [ 1 ] ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}();function Uu(f,p,l){var m=l.texData.get(f.dataId),g=i.util.sizeFromShape(f.shape),I=f.shape[f.shape.length-1],R=g/I,P=Ji({inputs:{x:f},backend:l,attrs:{shape:[R,I]}}),L=P.shape,G=new Wu("real",L,p),Q=new Wu("imag",L,p),ke=[{dataId:m.complexTensorInfos.real.dataId,dtype:m.complexTensorInfos.real.dtype,shape:L},{dataId:m.complexTensorInfos.imag.dataId,dtype:m.complexTensorInfos.imag.dtype,shape:L}],Ce=l.runWebGLProgram(G,ke,"float32"),Fe=l.runWebGLProgram(Q,ke,"float32"),Ee=po({inputs:{real:Ce,imag:Fe},backend:l});l.disposeIntermediateTensorInfo(Ce),l.disposeIntermediateTensorInfo(Fe);var Ge=Ji({inputs:{x:Ee},backend:l,attrs:{shape:f.shape}});return l.disposeIntermediateTensorInfo(Ge),Ge}function qc(f){var p=f.inputs,l=f.backend,m=p.input;return Uu(m,!1,l)}var Kc={kernelName:i.FFT,backendName:"webgl",kernelFunc:qc},Sl=function(){function f(p){this.variableNames=["Image"],this.outputShape=[];var l=p[2];this.outputShape=p,this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int x = coords [ 2 ] ;
int coordX = ` +l+ ` - x ;
float outputValue ;
if ( coordX >= 0 && coordX < ` +l+ ` ) {
outputValue = getImage ( coords [ 0 ] , coords [ 1 ] , coordX , coords [ 3 ] ) ;
} else {
outputValue = getImage ( coords [ 0 ] , coords [ 1 ] , coords [ 2 ] , coords [ 3 ] ) ;
}
setOutput ( outputValue ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Il={kernelName:i.FlipLeftRight,backendName:"webgl",kernelFunc:function(f){var p=f.inputs,l=f.backend,m=p.image,g=l,I=new Sl(m.shape),R=g.runWebGLProgram(I,[m],m.dtype);return R}},Vu=function(){function f(p){this.variableNames=["A"];var l=tn(),m=p[0],g=p[1];this.outputShape=p,this.userCode= `
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
int texR = coords [ 0 ] ;
int texC = coords [ 1 ] ;
int depth = coords [ 2 ] ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) / vec2 ( ` +g+".0, "+m+ ` . 0 ) ;
vec4 values = ` +l.texture2D+ ` ( A , uv ) ;
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-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
setOutput ( floor ( value * 255.0 + 0.5 ) ) ;
2020-11-04 17:43:51 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Xc=function(){function f(p){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var l=tn(),m=p[0],g=p[1];this.outputShape=p,this.userCode= `
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
int texR = coords [ 0 ] ;
int texC = coords [ 1 ] ;
int depth = coords [ 2 ] ;
vec4 result = vec4 ( 0. ) ;
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 ) /
vec2 ( ` +g+".0, "+m+ ` . 0 ) ;
vec4 values = ` +l.texture2D+ ` ( A , uv ) ;
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 ;
}
result [ row * 2 + col ] = floor ( value * 255.0 + 0.5 ) ;
}
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` +l.output+ ` = result ;
2020-11-04 20:59:30 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Yc={kernelName:i.FromPixels,backendName:"webgl",kernelFunc:jo},cs;function jo(f){var p=f.inputs,l=f.backend,m=f.attrs,g=p.pixels,I=m.numChannels,R=typeof HTMLVideoElement!="undefined"&&g instanceof HTMLVideoElement,P=typeof HTMLImageElement!="undefined"&&g instanceof HTMLImageElement,L=R?[g.videoWidth,g.videoHeight]:[g.width,g.height],G=L[0],Q=L[1],ke=[Q,G],Ce=[Q,G,I];(P||R)&&(cs==null&&(cs=document.createElement("canvas").getContext("2d")),cs.canvas.width=G,cs.canvas.height=Q,cs.drawImage(g,0,0,G,Q),g=cs.canvas);var Fe=l.makeTensorInfo(ke,"int32");l.texData.get(Fe.dataId).usage=w.PIXELS,l.gpgpu.uploadPixelDataToTexture(l.getTexture(Fe.dataId),g);var Ee=i.env().getBool("WEBGL_PACK")?new Xc(Ce):new Vu(Ce),Ge=l.runWebGLProgram(Ee,[Fe],"int32");return l.disposeData(Fe.dataId),Ge}function Nl(f){var p=f.inputs,l=f.backend,m=p.input;return Uu(m,!0,l)}var Cl={kernelName:i.IFFT,backendName:"webgl",kernelFunc:Nl},Hu=function(){function f(p,l){this.variableNames=["x"];var m=p.windowSize,g=p.batchSize,I=p.inSize,R=p.outSize;this.outputShape=[g,R];var P=Math.floor(m/4)*4,L=m%4,G="sumValue += dot(values, ones);";if(l!=null){var Q=1/l;G="sumValue += dot(values * "+(i.util.isInt(Q)?Q.toPrecision(2):Q)+", ones);"}var ke="";I%m>0&&(ke= `
if ( inIdx < 0 || inIdx >= ` +I+ ` ) {
return 0.0 ;
}
` ),this.userCode= `
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
float getValue ( int batch , int inIdx ) {
` +ke+ `
return getX ( batch , inIdx ) ;
2020-11-04 17:43:51 +01:00
}
2020-11-07 16:37:19 +01:00
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
int inOffset = outIdx * ` +m+ ` ;
float sumValue = 0.0 ;
for ( int i = 0 ; i < ` +P+ ` ; i += 4 ) {
int inIdx = inOffset + i ;
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
getValue ( batch , inIdx + 3 )
) ;
` +G+ `
}
int inIdx = inOffset + ` +P+ ` ;
if ( ` +(L===1)+ ` ) {
vec4 values = vec4 ( getValue ( batch , inIdx ) , 0.0 , 0.0 , 0.0 ) ;
` +G+ `
} else if ( ` +(L===2)+ ` ) {
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) , 0.0 , 0.0 ) ;
` +G+ `
} else if ( ` +(L===3)+ ` ) {
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) , 0.0 ) ;
` +G+ `
}
setOutput ( sumValue ) ;
2020-11-04 20:59:30 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}();function Tl(f){for(var p=[];p.length===0||p[p.length-1].outSize!==1;){var l=p.length?p[p.length-1].outSize:f[1],m=i.backend_util.computeOptimalWindowSize(l);p.push({inSize:l,windowSize:m,outSize:Math.ceil(l/m)})}return p}function vu(f,p,l,m){for(var g=Tl(f.shape),I=f,R=0;R<g.length;R++){var P=g[R],L=P.inSize,G=P.windowSize,Q=P.outSize,ke=void 0,Ce=void 0;l==="mean"?ke=R===0?new Hu({windowSize:G,inSize:L,batchSize:f.shape[0],outSize:Q},L):new Hu({windowSize:G,inSize:L,batchSize:f.shape[0],outSize:Q}):ke=new lr({windowSize:G,inSize:L,batchSize:f.shape[0],outSize:Q},l),Ce=I,I=m.runWebGLProgram(ke,[I],p),Ce.dataId!==f.dataId&&m.disposeIntermediateTensorInfo(Ce)}return I}function Gu(f,p,l,m){var g=i.util.sizeFromShape(p),I=i.util.sizeFromShape(f.shape),R=I/g,P=Ji({inputs:{x:f},attrs:{shape:[R,g]},backend:m}),L=vu(P,f.dtype,"max",m),G=Ji({inputs:{x:L},attrs:{shape:l},backend:m});return m.disposeIntermediateTensorInfo(P),m.disposeIntermediateTensorInfo(L),G}var El=function(){function f(p,l){this.variableNames=["A"];for(var m=new Array(p.length),g=0;g<m.length;g++)m[g]=p[l[g]];this.outputShape=m,this.rank=m.length;var I=nn(this.rank),R=Rl(l);this.userCode= `
void main ( ) {
` +I+ ` resRC = getOutputCoords ( ) ;
setOutput ( getA ( ` +R+ ` ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}();function Rl(f){var p=f.length;if(p>6)throw Error("Transpose for rank "+p+" is not yet supported");for(var l=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],m=new Array(p),g=0;g<f.length;g++)m[f[g]]=l[g];return m.join()}var Al=function(){function f(p,l){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0;for(var m=new Array(p.length),g=0;g<m.length;g++)m[g]=p[l[g]];if(this.outputShape=m,this.rank=m.length,this.rank>6)throw Error("Packed transpose for rank "+this.rank+" is not yet supported.");for(var I=nn(this.rank),R=Jr("rc",this.rank),P=new Array(this.rank),g=0;g<l.length;g++)P[l[g]]=R[g];var L="vec2("+P.slice(-2).join()+")",G="++"+R[this.rank-1]+" < "+m[this.rank-1],Q="getChannel(getA("+P.join()+"), "+L+")";this.userCode= `
void main ( ) {
` +I+ ` rc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
result [ 0 ] = ` +Q+ ` ;
if ( ` +G+ ` ) {
result [ 1 ] = ` +Q+ ` ;
}
-- ` +R[this.rank-1]+ ` ;
if ( ++ ` +R[this.rank-2]+" < "+m[this.rank-2]+ ` ) {
result [ 2 ] = ` +Q+ ` ;
if ( ` +G+ ` ) {
result [ 3 ] = ` +Q+ ` ;
}
2020-11-06 19:50:16 +01:00
}
2020-11-07 16:37:19 +01:00
setOutput ( result ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}();function js(f,p,l){var m=i.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new Al(f.shape,p):new El(f.shape,p);return l.runWebGLProgram(m,[f],f.dtype)}var ju={kernelName:i.Max,backendName:"webgl",kernelFunc:function(f){var p=f.inputs,l=f.attrs,m=f.backend,g=p.x,I=l,R=I.reductionIndices,P=I.keepDims,L=m,G=g.shape.length,Q=i.util.parseAxisParam(R,g.shape),ke=Q,Ce=i.backend_util.getAxesPermutation(ke,G),Fe=Ce!=null,Ee=L.shouldExecuteOnCPU([g]),Ge=g;if(Fe){if(Ee){for(var Qe=L.texData.get(Ge.dataId),s=Qe.values,u=new Array(G),r=0;r<u.length;r++)u[r]=g.shape[Ce[r]];var o=qa(s,g.shape,g.dtype,Ce,u);Ge=L.makeTensorInfo(u,g.dtype);var h=L.texData.get(Ge.dataId);h.values=o}else Ge=js(g,Ce,L);ke=i.backend_util.getInnerMostAxes(ke.length,G)}i.backend_util.assertAxesAreInnerMostDims("max",ke,G);var b=i.backend_util.computeOutAndReduceShapes(Ge.shape,ke),T=b[0],O=b[1],q=T;P&&(q=i.backend_util.expandShapeToKeepDim(T,Q));var Z;if(Ee){var Qe=L.texData.get(Ge.dataId),s=Qe.values,le=fr(s,i.util.sizeFromShape(O),q,g.dtype);Z=L.makeTensorInfo(q,g.dtype);var Ne=L.texData.get(Z.dataId);Ne.values=le}else Z=Gu(Ge,O,q,L);return Fe&&L.disposeIntermediateTensorInfo(Ge),Z}};function Fl(f){var p=f.inputs,l=f.backend,m=f.attrs,g=p.x;ln(g,"maxPool");var I=m.filterSize,R=m.strides,P=m.pad,L=m.dimRoundingMode,G=1;i.util.assert(i.backend_util.eitherStridesOrDilationsAreOne(R,G),function(){return"Error in maxPool: Either strides or dilations must be 1. "+("Got strides "+R+" and dilations '"+G+"'")});var Q=i.backend_util.computePool2DInfo(g.shape,I,R,G,P,L);if(Q.filterWidth===1&&Q.filterHeight===1&&i.util.arraysEqual(Q.inShape,Q.outShape))return ho({inputs:{x:g},backend:l});var ke=new Vt(Q,"max",!1);return l.runWebGLProgram(ke,[g],g.dtype)}var Dl={kernelName:i.MaxPool,backendName:"webgl",kernelFunc:Fl};function qu(f){var p=f.inputs,l=f.backend,m=f.attrs,g=p.dy,I=p.input,R=p.output,P=I;ln([I,R],"maxPoolBackprop");var L=m.filterSize,G=m.strides,Q=m.pad,ke=m.dimRoundingMode,Ce=i.backend_util.computePool2DInfo(P.shape,L,G,1,Q,ke),Fe=!0,Ee=new Vt(Ce,"max",Fe),Ge=l.runWebGLProgram(Ee,[P],P.dtype),Qe=new _t(Ce),s=l.runWebGLProgram(Qe,[g,Ge],P.dtype);return l.disposeIntermediateTensorInfo(Ge),s}var Ol={kernelName:i.MaxPoolBackprop,backendName:"webgl",kernelFunc:qu};function Ml(f,p,l,m){var g=new Vt(l,"max",!1),I=m.runWebGLProgram(g,[f],"float32");g=new Vt(l,"max",!0,!0,p);var R=m.runWebGLProgram(g,[f],"float32");return[I,R]}var Ku={kernelName:i.MaxPoolWithArgmax,backendName:"webgl",kernelFunc:function(f){var p=f.inputs,l=f.attrs,m=f.backend,g=p.x,I=l,R=I.filterSize,P=I.strides,L=I.pad,G=I.includeBatchInIndex,Q=m;i.util.assert(g.shape.length===4,function(){return"Error in maxPool: input must be rank 4 but got rank "+g.shape.length+"."});var ke=[1,1];i.util.assert(i.backend_util.eitherStridesOrDilationsAreOne(P,ke),function(){return"Error in maxPool: Either strides or dilations must be 1. "+("Got strides "+P+" and dilations '"+ke+"'")});var Ce=i.backend_util.computePool2DInfo(g.shape,R,P,ke,L),Fe=Ml(g,G,Ce,Q),Ee=Fe[0],Ge=Fe[1];return[Ee,Ge]}};function Ea(f,p,l,m){var g=i.util.sizeFromShape(p),I=i.util.sizeFromShape(f.shape),R=I/g,P=Ji({inputs:{x:f},attrs:{shape:[R,g]},backend:m}),L=vu(P,"float32","mean",m),G=Ji({inputs:{x:L},attrs:{shape:l},backend:m});return m.disposeIntermediateTensorInfo(P),m.disposeIntermediateTensorInfo(L),G}var zl={kernelName:i.Mean,backendName:"webgl",kernelFunc:function(f){var p=f.inputs,l=f.attrs,m=f.backend,g=p.x,I=l,R=I.keepDims,P=I.axis,L=m,G=g.shape.length,Q=i.util.parseAxisParam(P,g.shape),ke=Q,Ce=i.backend_util.getAxesPermutation(ke,G),Fe=Ce!=null,Ee=L.shouldExecuteOnCPU([g]),Ge=[],Qe=g;if(Fe){if(Ee){for(var s=L.texData.get(Qe.dataId),u=s.values,r=new Array(G),o=0;o<r.length;o++)r[o]=g.shape[Ce[o]];var h=qa(u,g.shape,g.dtype,Ce,r);Qe=L.makeTensorInfo(r,g.dtype);var b=L.texData.get(Qe.dataId);b.values=h}else Qe=js(g,Ce,L);Ge.push(Qe),ke=i.backend_util.getInnerMostAxes(ke.length,G)}i.backend_util.assertAxesAreInnerMostDims("sum",ke,G);var T=i.backend_util.computeOutAndReduceShapes(Qe.shape,ke),O=T[0],q=T[1],Z=O;R&&(Z=i.ba
int start = ` +R+ ` ;
int end = ` +P+ ` ;
void main ( ) {
int outC = getOutputCoords ( ) ;
if ( outC < start ) {
outC = start * 2 - outC - ` +G+ ` ;
} else if ( outC >= end ) {
outC = ( end - 1 ) * 2 - outC + ` +G+ ` ;
}
setOutput ( getX ( outC - start ) ) ;
}
` ;return}this.userCode= `
` +I+" start = "+I+"("+R+ ` ) ;
` +I+" end = "+I+"("+P+ ` ) ;
void main ( ) {
` +I+ ` outC = getOutputCoords ( ) ;
for ( int i = 0 ; i < ` +g+ ` ; i ++ ) {
if ( outC [ i ] < start [ i ] ) {
outC [ i ] = start [ i ] * 2 - outC [ i ] - ` +G+ ` ;
} else if ( outC [ i ] >= end [ i ] ) {
outC [ i ] = ( end [ i ] - 1 ) * 2 - outC [ i ] + ` +G+ ` ;
}
}
` +I+ ` coords = outC - start ;
setOutput ( getX ( ` +L+ ` ) ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Pl=function(){function f(p,l,m){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=l.map(function(Ge,Qe){return Ge[0]+p[Qe]+Ge[1]});var g=p.length,I=nn(g),R=l.map(function(Ge){return Ge[0]}).join(","),P=l.map(function(Ge,Qe){return Ge[0]+p[Qe]}).join(","),L=Vr("rc",g),G=Vr("source",g),Q=L[g-1]+" < "+this.outputShape[g-1],ke=g===1?"source":"vec2("+G.slice(-2).join()+")",Ce=m==="reflect"?0:1,Fe="";if(g===1){var Ee= `
` +I+ ` source = rc ;
if ( source < start ) {
source = start * 2 - source - ` +Ce+ ` ;
} else if ( source >= end ) {
source = ( end - 1 ) * 2 - source + ` +Ce+ ` ;
}
source -= start ;
` ;Fe= `
` +I+ ` rc = outputLoc ;
` +Ee+ `
result [ 0 ] = getChannel ( getX ( ` +G.join()+"), "+ke+ ` ) ;
` +L[g-1]+ ` += 1 ;
if ( ` +Q+ ` ) {
` +Ee+ `
result [ 1 ] = getChannel ( getX ( ` +G.join()+"), "+ke+ ` ) ;
}
` }else{var Ee= `
` +I+ ` source = rc ;
` +I+" lt = "+I+ ` ( lessThan ( source , start ) ) ;
` +I+" gte = "+I+ ` ( greaterThanEqual ( source , end ) ) ;
` +I+ ` orig = 1 - ( lt + gte ) ;
source = orig * source +
lt * ( start * 2 - source - ` +Ce+ ` ) +
gte * ( ( end - 1 ) * 2 - source + ` +Ce+ ` ) ;
source -= start ;
` ;Fe= `
` +I+ ` rc = outputLoc ;
` +Ee+ `
result [ 0 ] = getChannel ( getX ( ` +G.join()+"), "+ke+ ` ) ;
` +L[g-1]+ ` += 1 ;
if ( ` +Q+ ` ) {
` +Ee+ `
result [ 1 ] = getChannel ( getX ( ` +G.join()+"), "+ke+ ` ) ;
}
rc = outputLoc ;
` +L[g-2]+ ` += 1 ;
if ( ` +L[g-2]+" < "+this.outputShape[g-2]+ ` ) {
` +Ee+ `
result [ 2 ] = getChannel ( getX ( ` +G.join()+"), "+ke+ ` ) ;
` +L[g-1]+ ` += 1 ;
if ( ` +Q+ ` ) {
` +Ee+ `
result [ 3 ] = getChannel ( getX ( ` +G.join()+"), "+ke+ ` ) ;
}
}
` }this.userCode= `
const ` +I+" start = "+I+"("+R+ ` ) ;
const ` +I+" end = "+I+"("+P+ ` ) ;
void main ( ) {
` +I+ ` outputLoc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
` +Fe+ `
setOutput ( result ) ;
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Zc=function(f){var p=f.inputs,l=f.backend,m=f.attrs,g=p.x,I=m.paddings,R=m.mode,P=i.env().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new Pl(g.shape,I,R):new Ll(g.shape,I,R),L=l.runWebGLProgram(P,[g],g.dtype);return L},la={kernelName:i.MirrorPad,backendName:"webgl",kernelFunc:Zc},Ua={REAL:"return areal * breal - aimag * bimag;",IMAG:"return areal * bimag + aimag * breal;"},gu=function(){function f(p,l,m){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=i.backend_util.assertAndGetBroadcastShape(l,m),this.userCode= `
float binaryOpComplex (
float areal , float aimag , float breal , float bimag ) {
` +p+ `
2020-11-06 22:21:20 +01:00
}
2020-11-07 16:37:19 +01:00
void main ( ) {
float areal = getARealAtOutCoords ( ) ;
float aimag = getAImagAtOutCoords ( ) ;
float breal = getBRealAtOutCoords ( ) ;
float bimag = getBImagAtOutCoords ( ) ;
setOutput ( binaryOpComplex ( areal , aimag , breal , bimag ) ) ;
2020-11-06 17:39:39 +01:00
}
2020-11-07 16:37:19 +01:00
` }return f}(),Qc="return a * b;";function Bl(f){var p=f.inputs,l=f.backend,m=p.a,g=p.b,I=i.backend_util.upcastType(m.dtype,g.dtype);if(m.dtype==="complex64"){var R=l.texData.get(m.dataId),P=l.texData.get(g.dataId),L=new gu(Ua.REAL,m.shape,g.shape),G=new gu(Ua.IMAG,m.shape,g.shape),Q=[{dataId:R.complexTensorInfos.real.dataId,dtype:R.complexTensorInfos.real.dtype,shape:m.shape},{dataId:R.complexTensorInfos.imag.dataId,dtype:R.complexTensorInfos.imag.dtype,shape:m.shape},{dataId:P.complexTensorInfos.real.dataId,dtype:P.complexTensorInfos.real.dtype,shape:g.shape},{dataId:P.complexTensorInfos.imag.dataId,dtype:P.complexTensorInfos.imag.dtype,shape:g.shape}],ke=l.runWebGLProgram(L,Q,"float32"),Ce=l.runWebGLProgram(G,Q,"float32"),Fe=po({inputs:{real:ke,imag:Ce},backend:l});return l.disposeIntermediateTensorInfo(ke),l.disposeIntermediateTensorInfo(Ce),Fe}if(l.shouldExecuteOnCPU([m,g])){var R=l.texData.get(m.dataId),P=l.texData.get(g.dataId),Ee=or(m.shape,g.shape,R.values,P.values,I),Ge=Ee[0],Qe=Ee[1],s=l.makeTensorInfo(Qe,I),u=l.texData.get(s.dataId);return u.values=Ge,s}var r;return i.env().getBool("WEBGL_PACK_BINARY_OPERATIONS")?r=new vi(Qc,m.shape,g.shape):r=new vn(Qc,m.shape,g.shape),l.runWebGLProgram(r,[m,g],I)}var Wl={kernelName:i.Multiply,backendName:"webgl",kernelFunc:Bl},Ul={kernelName:i.NonMaxSuppressionV3,backendName:"webgl",kernelFunc:function(f){var p=f.inputs,l=f.backend,m=f.attrs;i.backend_util.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");var g=p,I=g.boxes,R=g.scores,P=m,L=P.maxOutputSize,G=P.iouThreshold,Q=P.scoreThreshold,ke=l,Ce=ke.readSync(I.dataId),Fe=ke.readSync(R.dataId),Ee=L,Ge=G,Qe=Q;return i.kernel_impls.nonMaxSuppressionV3Impl(Ce,Fe,Ee,Ge,Qe)}},Vl=i.kernel_impls.nonMaxSuppressionV4Impl,Hl={kernelName:i.NonMaxSuppressionV4,backendName:"webgl",kernelFunc:function(f){var p=f.inputs,l=f.backend,m=f.attrs;i.backend_util.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");var g=p,I=g.boxes,R=g.scores,P=m,L=P.maxOutputSize,G=P.iouThreshold,Q=P.scoreThreshold,ke=P.padToMaxOutputSize,Ce=l,Fe=Ce.readSync(I.dataId),Ee=Ce.readSync(R.dataId),Ge=Vl(Fe,Ee,L,G,Q,ke),Qe=Ge.selectedIndices,s=Ge.validOutputs;return[Qe,s]}},Gl=i.kernel_impls.nonMaxSuppressionV5Impl,jl={kernelName:i.NonMaxSuppressionV5,backendName:"webgl",kernelFunc:function(f){var p=f.inputs,l=f.backend,m=f.attrs;i.backend_util.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");var g=p,I=g.boxes,R=g.scores,P=m,L=P.maxOutputSize,G=P.iouThreshold,Q=P.scoreThreshold,ke=P.softNmsSigma,Ce=l,Fe=Ce.readSync(I.dataId),Ee=Ce.readSync(R.dataId),Ge=L,Qe=G,s=Q,u=ke,r=Gl(Fe,Ee,Ge,Qe,s,u),o=r.selectedIndices,h=r.selectedScores;return[o,h]}},ql=function(){function f(p,l,m,g){this.variableNames=["Image"],this.outputShape=[];var I=p[1],R=p[2],P=Math.sin(l).toFixed(3),L=Math.cos(l).toFixed(3);this.outputShape=p;var G=i.backend_util.getImageCenter(g,I,R),Q=G[0],ke=G[1],Ce=Q.toFixed(3),Fe=ke.toFixed(3),Ee="";typeof m=="number"?Ee="float outputValue = "+m.toFixed(2)+";":Ee= `
vec3 fill = vec3 ( ` +m.join(",")+ ` ) ;
float outputValue = fill [ coords [ 3 ] ] ; ` ,this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int x = coords [ 2 ] ;
int y = coords [ 1 ] ;
float coordXFloat = ( float ( x ) - ` +Ce+") * "+L+" - (float(y) - "+Fe+") * "+P+ ` ;
float coordYFloat = ( float ( x ) - ` +Ce+") * "+P+" + (float(y) - "+Fe+") * "+L+ ` ;
int coordX = int ( round ( coordXFloat + ` +Ce+ ` ) ) ;
int coordY = int ( round ( coordYFloat + ` +Fe+ ` ) ) ;
` +Ee+ `
if ( coordX >= 0 && coordX < ` +R+" && coordY >= 0 && coordY < "+I+ ` ) {
outputValue = getImage ( coords [ 0 ] , coordY , coordX , coords [ 3 ] ) ;
}
setOutput ( outputValue ) ;
}
` }return f}(),Kl={kernelName:i.RotateWithOffset,backendName:"webgl",kernelFunc:function(f){var p=f.inputs,l=f.attrs,m=f.backend,g=p.image,I=l,R=I.radians,P=I.fillValue,L=I.center,G=m,Q=new ql(g.shape,R,P,L),ke=G.runWebGLProgram(Q,[g],g.dtype);return ke}},Xl=hu+ `
return sin ( x ) ;
2020-11-07 17:34:09 +01:00
` ,Cr=Hs(Xl),Yl={kernelName:i.Sin,backendName:"webgl",kernelFunc:Cr},Xu="return x * x;",Zl=Hs(Xu),Wr={kernelName:i.Square,backendName:"webgl",kernelFunc:Zl},Jc="return (a - b) * (a - b);",bt=fo({opSnippet:Jc,packedOpSnippet:Jc}),Ql={kernelName:i.SquaredDifference,backendName:"webgl",kernelFunc:bt},ci="return a - b;",Jl=fo({opSnippet:ci,packedOpSnippet:ci,supportsComplex:!0,cpuKernelImpl:ia}), $ c={kernelName:i.Sub,backendName:"webgl",kernelFunc:Jl}, $ l="return tan(x);",el=Hs( $ l),eh={kernelName:i.Tan,backendName:"webgl",kernelFunc:el},th={kernelName:i.Transpose,backendName:"webgl",kernelFunc:function(f){for(var p=f.inputs,l=f.attrs,m=f.backend,g=p.x,I=l.perm,R=m,P=g.shape.length,L=new Array(P),G=0;G<L.length;G++)L[G]=g.shape[I[G]];var Q;if(R.shouldExecuteOnCPU([g])){var ke=R.texData.get(g.dataId),Ce=ke.values,Fe=qa(Ce,g.shape,g.dtype,I,L);Q=R.makeTensorInfo(L,g.dtype);var Ee=R.texData.get(Q.dataId);Ee.values=Fe}else Q=js(g,I,R);return Q}};function Yu(f){var p=f.inputs,l=f.attrs,m=f.backend,g=l.axis,I=p.x;ln(I,"unique"),console.warn("WARNING: ","UI might be locked temporarily as data is being downloaded");var R=m.readSync(I.dataId),P=bi(R,g,I.shape,I.dtype),L=P.outputValues,G=P.outputShape,Q=P.indices;return[m.makeTensorInfo(G,I.dtype,L),m.makeTensorInfo([Q.length],"int32",Q)]}for(var tl={kernelName:i.Unique,backendName:"webgl",kernelFunc:Yu},rl=[zu,du,Nc,Tc,sn,ss,Sc,Bc,Uc,jc,Kc,Il,Yc,kc,Cl,Pu,ju,Dl,Ol,Ku,zl,la,Wl,Ul,Hl,jl,Fc,Dc,Bu,Kl,Yl,Wr, $ c,Ql,eh,th,tl],li=0,nl=rl;li<nl.length;li++){var $ i=nl[li];i.registerKernel( $ i)}N.GPGPUContext=Oe,N.MathBackendWebGL=Go,N.forceHalfFloat=Vs,N.gpgpu_util=Ae,N.setWebGLContext=Te,N.version_webgl=Du,N.webgl=bc,N.webgl_util=ai}),Vi=Or(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});var i=ml(),we=ag(),M=ig(),V=sg(),oe=yg(),de=vg(),X="2.7.0",Te={"tfjs-core":i.version_core,"tfjs-backend-cpu":oe.version_cpu,"tfjs-backend-webgl":de.version_webgl,"tfjs-data":V.version_data,"tfjs-layers":we.version_layers,"tfjs-converter":M.version_converter,tfjs:X};Object.keys(i).forEach(function(z){z!=="default"&&Object.defineProperty(N,z,{enumerable:!0,get:function(){return i[z]}})}),Object.keys(we).forEach(function(z){z!=="default"&&Object.defineProperty(N,z,{enumerable:!0,get:function(){return we[z]}})}),Object.keys(M).forEach(function(z){z!=="default"&&Object.defineProperty(N,z,{enumerable:!0,get:function(){return M[z]}})}),N.data=V,N.version=Te}),gg=Or(N=>{const i=Vi(),we=6;function M(ye){const ee={strides:[ye/16,ye/8],anchors:[2,6]},w=[];for(let xe=0;xe<ee.strides.length;xe++){const We=ee.strides[xe],W=Math.floor((ye+We-1)/We),st=Math.floor((ye+We-1)/We),ut=ee.anchors[xe];for(let Kt=0;Kt<W;Kt++){const It=We*(Kt+.5);for(let Ze=0;Ze<st;Ze++){const mt=We*(Ze+.5);for(let yt=0;yt<ut;yt++)w.push([mt,It])}}}return w}const V=ye=>{ye.startEndTensor.dispose(),ye.startPoint.dispose(),ye.endPoint.dispose()},oe=ye=>({startEndTensor:ye,startPoint:i.slice(ye,[0,0],[-1,2]),endPoint:i.slice(ye,[0,2],[-1,2])}),de=(ye,ee)=>{const w=i.mul(ye.startPoint,ee),xe=i.mul(ye.endPoint,ee),We=i.concat2d([w,xe],1);return oe(We)};function X(ye,ee,w){const xe=i.slice(ye,[0,1],[-1,2]),We=i.add(xe,ee),W=i.slice(ye,[0,3],[-1,2]),st=i.div(W,w),ut=i.div(We,w),Kt=i.div(st,2),It=i.sub(ut,Kt),Ze=i.add(ut,Kt),mt=i.mul(It,w),yt=i.mul(Ze,w), $ e=1;return i.concat2d([mt,yt], $ e)}function Te(ye,ee){return i.tidy(()=>{const w=ye.box?ye.box:ye;return de(w,ee).startEndTensor.squeeze()})}class z{constructor(ye,ee){this.blazeFaceModel=ye,this.width=ee.detector.inputSize,this.height=ee.detector.inputSize,this.anchorsData=M(ee.detector.inputSize),this.anchors=i.tensor2d(this.anchorsData),this.inputSize=i.tensor1d([this.width,this.height]),this.config=ee,this.scaleFaces=.8}async getBoundingBoxes(ye){if(!ye||ye.isDisposedInternal||ye.shape.length!==4||ye.shape[1]<1||ye.shape[2]<1)return null;const[ee,w,xe]=i.tidy(()=>{const It=ye.resizeBilinear([this.width,this.height]),Ze=i.sub(It.div(127.5),1),mt=this.blazeFaceModel.predict(Ze);let yt;if(Array.isArray(mt)){const et=mt.sort((jr,Pr)=>jr.size-Pr.size),Qt=i.concat([et[0],et[2]],2),rr=i.concat([et[1
2020-11-07 16:37:19 +01:00
` ),yt.FRAGMENT_IDENTITY=["precision highp float;","varying vec2 vUv;","uniform sampler2D texture;","void main(void) {","gl_FragColor = texture2D(texture, vUv);","}"].join( `
` );let $ e={}; $ e.colorMatrix=function(ot){const nt=new Float32Array(ot);nt[4]/=255,nt[9]/=255,nt[14]/=255,nt[19]/=255;const et=nt[18]===1&&nt[3]===0&&nt[8]===0&&nt[13]===0&&nt[15]===0&&nt[16]===0&&nt[17]===0&&nt[19]===0? $ e.colorMatrix.SHADER.WITHOUT_ALPHA: $ e.colorMatrix.SHADER.WITH_ALPHA,Qt=Ze(et);W.uniform1fv(Qt.uniform.m,nt),It()}, $ e.colorMatrix.SHADER={}, $ e.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( `
` ), $ e.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( `
` ), $ e.brightness=function(ot){const nt=(ot||0)+1; $ e.colorMatrix([nt,0,0,0,0,0,nt,0,0,0,0,0,nt,0,0,0,0,0,1,0])}, $ e.saturation=function(ot){const nt=(ot||0)*2/3+1,et=(nt-1)*-.5; $ e.colorMatrix([nt,et,et,0,0,et,nt,et,0,0,et,et,nt,0,0,0,0,0,1,0])}, $ e.desaturate=function(){ $ e.saturation(-1)}, $ e.contrast=function(ot){const nt=(ot||0)+1,et=-128*(nt-1); $ e.colorMatrix([nt,0,0,0,et,0,nt,0,0,et,0,0,nt,0,et,0,0,0,1,0])}, $ e.negative=function(){ $ e.contrast(-2)}, $ e.hue=function(ot){ot=(ot||0)/180*Math.PI;const nt=Math.cos(ot),et=Math.sin(ot),Qt=.213,rr=.715,jt=.072; $ e.colorMatrix([Qt+nt*(1-Qt)+et*-Qt,rr+nt*-rr+et*-rr,jt+nt*-jt+et*(1-jt),0,0,Qt+nt*-Qt+et*.143,rr+nt*(1-rr)+et*.14,jt+nt*-jt+et*-.283,0,0,Qt+nt*-Qt+et*-(1-Qt),rr+nt*-rr+et*rr,jt+nt*(1-jt)+et*jt,0,0,0,0,0,1,0])}, $ e.desaturateLuminance=function(){ $ e.colorMatrix([.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,.2764723,.929708,.0938197,0,-37.1,0,0,0,1,0])}, $ e.sepia=function(){ $ e.colorMatrix([.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0])}, $ e.brownie=function(){ $ e.colorMatrix([.5997023498159715,.34553243048391263,-.2708298674538042,0,47.43192855600873,-.037703249837783157,.8609577587992641,.15059552388459913,0,-36.96841498319127,.24113635128153335,-.07441037908422492,.44972182064877153,0,-7.562075277591283,0,0,0,1,0])}, $ e.vintagePinhole=function(){ $ e.colorMatrix([.6279345635605994,.3202183420819367,-.03965408211312453,0,9.651285835294123,.02578397704808868,.6441188644374771,.03259127616149294,0,7.462829176470591,.0466055556782719,-.0851232987247891,.5241648018700465,0,5.159190588235296,0,0,0,1,0])}, $ e.kodachrome=function(){ $ e.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])}, $ e.technicolor=function(){ $ e.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])}, $ e.polaroid=function(){ $ e.colorMatrix([1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0])}, $ e.shiftToBGR=function(){ $ e.colorMatrix([0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0])}, $ e.convolution=function(ot){const nt=new Float32Array(ot),et=1/he,Qt=1/ye,rr=Ze( $ e.convolution.SHADER);W.uniform1fv(rr.uniform.m,nt),W.uniform2f(rr.uniform.px,et,Qt),It()}, $ e.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( `
` ), $ e.detectEdges=function(){ $ e.convolution.call(this,[0,1,0,1,-4,1,0,1,0])}, $ e.sobelX=function(){ $ e.convolution.call(this,[-1,0,1,-2,0,2,-1,0,1])}, $ e.sobelY=function(){ $ e.convolution.call(this,[-1,-2,-1,0,0,0,1,2,1])}, $ e.sharpen=function(ot){const nt=ot||1; $ e.convolution.call(this,[0,-1*nt,0,-1*nt,1+4*nt,-1*nt,0,-1*nt,0])}, $ e.emboss=function(ot){const nt=ot||1; $ e.convolution.call(this,[-2*nt,-1*nt,0,-1*nt,1,1*nt,0,1*nt,2*nt])}, $ e.blur=function(ot){const nt=ot/7/he,et=ot/7/ye,Qt=Ze( $ e.blur.SHADER);W.uniform2f(Qt.uniform.px,0,et),It(mt.INTERMEDIATE),W.uniform2f(Qt.uniform.px,nt,0),It()}, $ e.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( `
` ), $ e.pixelate=function(ot){const nt=ot/he,et=ot/ye,Qt=Ze( $ e.pixelate.SHADER);W.uniform2f(Qt.uniform.size,nt,et),It()}, $ e.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( `
2020-11-07 17:25:03 +01:00
` )};N.Canvas=we}),Ug=Or(N=>{const i=Vi(),we=Wg();let M=null,V=null;function oe(de,X){let Te;if(de instanceof i.Tensor)Te=i.clone(de);else{const z=de.naturalWidth||de.videoWidth||de.width||de.shape&&de.shape[1]>0,he=de.naturalHeight||de.videoHeight||de.height||de.shape&&de.shape[2]>0;let ye=z,ee=he;X.filter.width>0?ye=X.filter.width:X.filter.height>0&&(ye=z*(X.filter.height/he)),X.filter.height>0?ee=X.filter.height:X.filter.width>0&&(ee=he*(X.filter.width/z)),(!M||M.width!==ye||M.height!==ee)&&(M=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(ye,ee):document.createElement("canvas"),M.width!==ye&&(M.width=ye),M.height!==ee&&(M.height=ee));const w=M.getContext("2d");de instanceof ImageData?w.putImageData(de,0,0):w.drawImage(de,0,0,z,he,0,0,M.width,M.height),X.filter.enabled&&((!this.fx||!V||M.width!==V.width||M.height!==V.height)&&(V=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(M.width,M.height):document.createElement("canvas"),V.width!==M.width&&(V.width=M.width),V.height!==M.height&&(V.height=M.height),this.fx=i.ENV.flags.IS_BROWSER?new we.Canvas({canvas:V}):null),this.fx.reset(),this.fx.addFilter("brightness",X.filter.brightness),X.filter.contrast!==0&&this.fx.addFilter("contrast",X.filter.contrast),X.filter.sharpness!==0&&this.fx.addFilter("sharpen",X.filter.sharpness),X.filter.blur!==0&&this.fx.addFilter("blur",X.filter.blur),X.filter.saturation!==0&&this.fx.addFilter("saturation",X.filter.saturation),X.filter.hue!==0&&this.fx.addFilter("hue",X.filter.hue),X.filter.negative&&this.fx.addFilter("negative"),X.filter.sepia&&this.fx.addFilter("sepia"),X.filter.vintage&&this.fx.addFilter("brownie"),X.filter.sepia&&this.fx.addFilter("sepia"),X.filter.kodachrome&&this.fx.addFilter("kodachrome"),X.filter.technicolor&&this.fx.addFilter("technicolor"),X.filter.polaroid&&this.fx.addFilter("polaroid"),X.filter.pixelate!==0&&this.fx.addFilter("pixelate",X.filter.pixelate),this.fx.apply(M)),V||(V=M);let xe;if(X.backend==="webgl"||V instanceof ImageData)xe=i.browser.fromPixels(V);else{const W=typeof OffscreenCanvas!="undefined"?new OffscreenCanvas(ye,ee):document.createElement("canvas");W.width=ye,W.height=ee;const st=W.getContext("2d");st.drawImage(V,0,0);const ut=st.getImageData(0,0,ye,ee);xe=i.browser.fromPixels(ut)}const We=xe.toFloat();Te=We.expandDims(0),xe.dispose(),We.dispose()}return{tensor:Te,canvas:X.filter.return?V:null}}N.process=oe}),Vg=Or(N=>{Zh(N,{default:()=>i});var i={backend:"webgl",console:!0,async:!0,profile:!1,deallocate:!1,scoped:!1,videoOptimized:!0,filter:{enabled:!0,width:0,height:0,return:!0,brightness:0,contrast:0,sharpness:0,blur:0,saturation:0,hue:0,negative:!1,sepia:!1,vintage:!1,kodachrome:!1,technicolor:!1,polaroid:!1,pixelate:0},gesture:{enabled:!0},face:{enabled:!0,detector:{modelPath:"../models/blazeface-back.json",inputSize:256,maxFaces:10,skipFrames:15,minConfidence:.1,iouThreshold:.1,scoreThreshold:.2},mesh:{enabled:!0,modelPath:"../models/facemesh.json",inputSize:192},iris:{enabled:!0,modelPath:"../models/iris.json",enlargeFactor:2.3,inputSize:64},age:{enabled:!0,modelPath:"../models/age-ssrnet-imdb.json",inputSize:64,skipFrames:15},gender:{enabled:!0,minConfidence:.1,modelPath:"../models/gender-ssrnet-imdb.json",inputSize:64,skipFrames:15},emotion:{enabled:!0,inputSize:64,minConfidence:.2,skipFrames:15,modelPath:"../models/emotion-large.json"}},body:{enabled:!0,modelPath:"../models/posenet.json",inputResolution:257,outputStride:16,maxDetections:10,scoreThreshold:.8,nmsRadius:20},hand:{enabled:!0,inputSize:256,skipFrames:15,minConfidence:.5,iouThreshold:.2,scoreThreshold:.5,enlargeFactor:1.65,maxHands:10,detector:{modelPath:"../models/handdetect.json"},skeleton:{modelPath:"../models/handskeleton.json"}}}}),Hg=Or((N,i)=>{i.exports={name:"@vladmandic/human",version:"0.7.6",description:"human: 3D Face Detection, Body Pose, Hand & Finger Tracking, Iris Tracking, Age & Gender Prediction, Emotion Prediction & Gesture Recognition",sideEffects:!1,main:"dist/human.node.js",module:"dist/human.esm.js",browser:"dist/human.esm.js",author:"Vladimir Mandic <mandic00@live.com>",bugs:{url:"h
2020-11-07 17:34:09 +01:00
: root { -- rounded : 0.2 rem ; }
2020-11-07 16:37:19 +01:00
. menu { position : absolute ; top : 0 rem ; right : 0 ; width : fit - content ; padding : 0 0.8 rem 0 0.8 rem ; line - height : 1.8 rem ; z - index : 10 ; max - height : calc ( 100 % - 4 rem ) ;
2020-11-07 17:34:09 +01:00
box - shadow : 0 0 8 px dimgrey ; background : $ { Ra . background } ; border - radius : var ( -- rounded ) ; border - color : black ; border - style : solid ; border - width : thin ; }
2020-11-07 16:37:19 +01:00
. menu : hover { box - shadow : 0 0 8 px $ { Ra . hover } ; }
. menu - container { display : block ; max - height : 100 vh ; }
. menu - container - fadeout { max - height : 0 ; overflow : hidden ; transition : max - height , 0.5 s ease ; }
. menu - container - fadein { max - height : 100 vh ; overflow : hidden ; transition : max - height , 0.5 s ease ; }
. menu - item { display : flex ; white - space : nowrap ; padding : 0.2 rem ; width : max - content ; cursor : default ; }
. menu - title { text - align : right ; cursor : pointer ; }
. menu - hr { margin : 0.2 rem ; border : 1 px solid rgba ( 0 , 0 , 0 , 0.5 ) }
. menu - label { padding : 0 ; }
. menu - list { margin - right : 0.8 rem ; }
select : focus { outline : none ; }
2020-11-07 17:34:09 +01:00
. menu - list - item { background : $ { Ra . itemBackground } ; color : $ { Ra . itemColor } ; border : none ; padding : 0.2 rem ; font - family : inherit ; font - variant : inherit ; border - radius : var ( -- rounded ) ; font - weight : 800 ; }
2020-11-07 16:37:19 +01:00
. menu - chart - title { padding : 0 ; font - size : 0.8 rem ; font - weight : 800 ; align - items : center }
. menu - chart - canvas { background : transparent ; margin : 0.2 rem 0 0.2 rem 0.6 rem ; }
2020-11-07 17:25:03 +01:00
. menu - button { border : 0 ; background : $ { Ra . buttonBackground } ; width : - webkit - fill - available ; padding : 8 px ; margin : 8 px 0 8 px 0 ; cursor : pointer ; box - shadow : 4 px 4 px 4 px 0 dimgrey ;
2020-11-07 17:34:09 +01:00
border - radius : var ( -- rounded ) ; justify - content : center ; font - family : inherit ; font - variant : inherit ; font - size : 1 rem ; font - weight : 800 ; }
2020-11-07 16:37:19 +01:00
. menu - button : hover { background : $ { Ra . buttonHover } ; box - shadow : 4 px 4 px 4 px 0 black ; }
. menu - button : focus { outline : none ; }
2020-11-07 17:34:09 +01:00
. menu - checkbox { width : 2.8 rem ; height : 1 rem ; background : $ { Ra . itemBackground } ; margin : 0.5 rem 0.8 rem 0 0 ; position : relative ; border - radius : var ( -- rounded ) ; }
2020-11-07 16:37:19 +01:00
. menu - checkbox : after { content : 'OFF' ; color : $ { Ra . checkboxOff } ; position : absolute ; right : 0.2 rem ; top : - 0.4 rem ; font - weight : 800 ; font - size : 0.5 rem ; }
. menu - checkbox : before { content : 'ON' ; color : $ { Ra . checkboxOn } ; position : absolute ; left : 0.3 rem ; top : - 0.4 rem ; font - weight : 800 ; font - size : 0.5 rem ; }
2020-11-07 17:34:09 +01:00
. menu - checkbox - label { width : 1.3 rem ; height : 0.8 rem ; cursor : pointer ; position : absolute ; top : 0.1 rem ; left : 0.1 rem ; z - index : 1 ; background : $ { Ra . checkboxOff } ; border - radius : var ( -- rounded ) ; transition : left 0.6 s ease ; }
2020-11-07 16:37:19 +01:00
input [ type = checkbox ] { visibility : hidden ; }
input [ type = checkbox ] : checked + label { left : 1.4 rem ; background : $ { Ra . checkboxOn } ; }
. menu - range { margin : 0 0.8 rem 0 0 ; width : 5 rem ; background : transparent ; color : $ { Ra . rangeBackground } ; }
. menu - range : before { content : attr ( value ) ; color : $ { Ra . rangeLabel } ; margin : 0 0.4 rem 0 0 ; font - weight : 800 ; font - size : 0.6 rem ; position : relative ; top : 0.3 rem ; }
input [ type = range ] { - webkit - appearance : none ; }
2020-11-07 17:34:09 +01:00
input [ type = range ] : : - webkit - slider - runnable - track { width : 100 % ; height : 1 rem ; cursor : pointer ; background : $ { Ra . itemBackground } ; border - radius : var ( -- rounded ) ; border : 1 px ; }
input [ type = range ] : : - webkit - slider - thumb { border : 1 px solid # 000000 ; margin - top : 0.05 rem ; height : 0.9 rem ; width : 1.5 rem ; border - radius : var ( -- rounded ) ; background : $ { Ra . rangeBackground } ; cursor : pointer ; - webkit - appearance : none ; }
2020-11-07 16:37:19 +01:00
` ,i=document.createElement("style");i.innerHTML=N,document.getElementsByTagName("head")[0].appendChild(i),bf=!0}class tx{constructor(N,i,we,M){M&&(Ra={...Ra,...M}),ex(),this.createMenu(N,i,we),this.id=0,this.instance=wh,wh++,this._maxFPS=0,this.hidden=0}createMenu(N,i="",we={top:null,left:null,bottom:null,right:null}){if(this.menu=document.createElement("div"),this.menu.id= ` menu - $ { wh } ` ,this.menu.className="menu",we&&(we.top&&(this.menu.style.top=we.top),we.bottom&&(this.menu.style.bottom=we.bottom),we.left&&(this.menu.style.left=we.left),we.right&&(this.menu.style.right=we.right)),this.container=document.createElement("div"),this.container.id= ` menu - container - $ { wh } ` ,this.container.className="menu-container menu-container-fadein",i!==""){const M=document.createElement("div");M.className="menu-title",M.id= ` menu - title - $ { wh } ` ,M.innerHTML=i,this.menu.appendChild(M),M.addEventListener("click",()=>{this.container.classList.toggle("menu-container-fadeout"),this.container.classList.toggle("menu-container-fadein"),this.menu.style.borderStyle=this.container.classList.contains("menu-container-fadeout")?"none":"solid"})}this.menu.appendChild(this.container),typeof N=="object"?N.appendChild(this.menu):document.getElementById(N).appendChild(this.menu)}get newID(){return this.id++, ` menu - $ { this . instance } - $ { this . id } ` }get ID(){return ` menu - $ { this . instance } - $ { this . id } ` }get width(){return this.menu.offsetWidth}get height(){return this.menu.offsetHeight}hide(){this.container.classList.contains("menu-container-fadein")&&(this.container.classList.toggle("menu-container-fadeout"),this.container.classList.toggle("menu-container-fadein"))}visible(){return this.container.classList.contains("menu-container-fadein")}toggle(N){if(this.container.classList.toggle("menu-container-fadeout"),this.container.classList.toggle("menu-container-fadein"),this.container.classList.contains("menu-container-fadein")&&N){const i=N.x||(N.touches&&N.touches[0]?N.touches[0].pageX:null),we=N.y||(N.touches&&N.touches[0]?N.touches[0].pageY:null);i&&(this.menu.style.left= ` $ { i - 105 } px ` ),we&&(this.menu.style.top="5.5rem"),this.menu.offsetLeft<0&&(this.menu.style.left=0),this.menu.offsetLeft+this.menu.offsetWidth>window.innerWidth&&(this.menu.style.left=null,this.menu.style.right=0),this.menu.style.borderStyle="solid"}else this.menu.style.borderStyle="none"}addTitle(N){const i=document.createElement("div");return i.className="menu-title",i.id=this.newID,i.innerHTML=N,this.menu.appendChild(i),i.addEventListener("click",()=>{this.hidden=!this.hidden;const we=document.getElementsByClassName("menu");for(const M of we)M.style.display=this.hidden?"none":"block"}),i}addLabel(N){const i=document.createElement("div");return i.className="menu-item menu-label",i.id=this.newID,i.innerHTML=N,this.container.appendChild(i),i}addBool(N,i,we,M){const V=document.createElement("div");return V.className="menu-item",V.innerHTML= ` < div class = "menu-checkbox" > < input class = "menu-checkbox" type = "checkbox" id = "${this.newID}" $ { i [ we ] ? "checked" : "" } / > < label class = "menu-checkbox-label" for = "${this.ID}" > < / l a b e l > < / d i v > $ { N } ` , t h i s . c o n t a i n e r . a p p e n d C h i l d ( V ) , V . a d d E v e n t L i s t e n e r ( " c h a n g e " , o e = > { i [ w e ] = o e . t a r g e t . c h e c k e d , M & & M ( o e . t a r g e t . c h e c k e d ) } ) , V } a s y n c a d d L i s t ( N , i , w e , M ) { c o n s t V = d o c u m e n t . c r e a t e E l e m e n t ( " d i v " ) ; V . c l a s s N a m e = " m e n u - i t e m " ; l e t o e = " " ; f o r ( c o n s t d e o f i ) { c o n s t X = d e = = = w e ? " s e l e c t e d " : " " ; o e + = ` < o p t i o n v a l u e = " $ { d e } " $ { X } > $ { d e } < / o p t i o n > ` } r e t u r n V . i n n e r H T M L = ` < d i v c l a s s = " m e n u - l i s t " > < s e l e c t n a m e = " $ { t h i s . I D } " c l a s s = " m e n u - l i s t - i t e m " > $ { o e } < / s e l e c t > < l a b e l f o r = " $ { t h i s . I D } " > < / l a b e l > < / d i v > $ { N } ` , V . s t y l e . f o n t F a m i l y = d o c u m e n t . b o d y . s t y l e . f o n t F a m i l y , V . s t y l e . f o n t S i z e = d o c u m e n t . b o d y . s t y l e . f o n t S i z e , V . s t y l e . f o n t V a r i a n t = d o c u m e n t . b o d y . s t y l e . f o n t V a r i a n t , t h i s . c o n t a i n e r . a p p e n d C h i l d ( V ) , V . a d d E v e n t L i s t e n e r ( " c h a n g e " , d e = > { M & & M ( i [ d e . t a r g e t . s e l e c t e d I n d e x ] ) } ) , V } a d d R a n g e ( N , i , w e , M , V , o e , d e ) { c o n s t X = d o c u m e n t . c r e a t e E l e m e n t ( " d i v " ) ; r e t u r n X . c l a s s N a m e = " m e n u - i t e m " , X . i n n e r H T M L = ` < i n p u t c l a s s = " m e n u - r a n g e " t y p e = " r a n g e " i d = " $ { t h i s . n e w I D } " m i n = " $ { M } " m a x = " $ { V } " s t e p = " $ { o e } " v a l u e = " $ { i [ w e ] } " > $ { N } ` , t h i s . c o n t a i n e r . a p p e n d C h i l d ( X ) , X . a d d E v e n t L i s t e n e r ( " c h a n g e " , T e = > { i [ w e ] = p a r s e I
video : $ { bh . name } | facing : $ { bh . facing } | resolution : $ { bh . width } x $ { bh . height } $ { X }
backend : $ { tr . tf . getBackend ( ) } | $ { de }
performance : $ { rx ( i . performance ) } FPS : $ { Te }
` }async function Xp(){if(Nn.busy)return null;Nn.busy=!0;const N=document.getElementById("video"),i=document.getElementById("canvas"),we=document.getElementById("log"),M=N.srcObject?N.srcObject.getVideoTracks()[0].readyState==="live"&&N.readyState>2&&!N.paused:!1;let V="";if(Xo("setting up camera"),!navigator.mediaDevices)return V="camera access not supported",we.innerText+= `
$ { V } ` ,Ko(V),Xo(V),null;let oe;const de={audio:!1,video:{facingMode:Nn.facing?"user":"environment",resizeMode:"none",width:{ideal:window.innerWidth},height:{ideal:window.innerHeight}}};try{oe=await navigator.mediaDevices.getUserMedia(de)}catch(z){z.name==="PermissionDeniedError"?V="camera permission denied":z.name==="SourceUnavailableError"?V="camera not available":V="camera error",we.innerText+= `
2020-11-07 17:25:03 +01:00
$ { V } ` ,Xo(V),Ko(z)}if(oe)N.srcObject=oe;else return null;const X=oe.getVideoTracks()[0],Te=X.getSettings();return Ko("camera constraints:",de,"window:",{width:window.innerWidth,height:window.innerHeight},"settings:",Te,"track:",X),bh={name:X.label,width:Te.width,height:Te.height,facing:Te.facingMode==="user"?"front":"back"},new Promise(z=>{N.onloadeddata=async()=>{N.width=N.videoWidth,N.height=N.videoHeight,i.width=N.width,i.height=N.height,i.style.width=i.width>i.height?"100vw":"",i.style.height=i.width>i.height?"":"100vh";const he=14+6*i.width/window.innerWidth;Nn.baseFont=Nn.baseFontProto.replace(/{size}/, ` $ { he } px ` ),M&&N.play(),Nn.busy=!1,Xo(""),z(N)}})}function nx(N,i,we){uc||(Ko("creating worker thread"),uc=new Worker(Nn.worker,{type:"module"}),uc.warned=!1,uc.addEventListener("message",M=>{uc.warned||(Ko("warning: cannot transfer canvas from worked thread"),Ko("warning: image will not show filter effects"),uc.warned=!0),Kp(N,M.data.result,we)})),uc.postMessage({image:i.data.buffer,width:we.width,height:we.height},[i.data.buffer])}function qp(N,i){var M;jp=performance.now();const we=N.srcObject&&N.srcObject.getVideoTracks()[0].readyState==="live"&&N.readyState>2&&!N.paused;if(!we&&N.srcObject){N.srcObject.getVideoTracks()[0].readyState==="live"&&N.readyState<=2?setTimeout(()=>qp(N,i),500):Ko( ` camera not ready : track state : $ { ( M = N . srcObject ) == null ? void 0 : M . getVideoTracks ( ) [ 0 ] . readyState } stream state : $ { N . readyState } ` );return}if(Xo(""),Nn.useWorker){const V=new OffscreenCanvas(i.width,i.height),oe=V.getContext("2d");oe.drawImage(N,0,0,N.width,N.height,0,0,i.width,i.height);const de=oe.getImageData(0,0,i.width,i.height);nx(N,de,i)}else tr.detect(N).then(V=>{V.error?Ko(V.error):Kp(N,V,i),tr.config.profile&&Ko("profile data:",tr.profile())})}async function ax(N){return jp=performance.now(),new Promise(i=>{const we=new Image;we.onload=async()=>{Ko("Processing image:",we.src);const M=document.getElementById("canvas");we.width=we.naturalWidth,we.height=we.naturalHeight,M.width=tr.config.filter.width&&tr.config.filter.width>0?tr.config.filter.width:we.naturalWidth,M.height=tr.config.filter.height&&tr.config.filter.height>0?tr.config.filter.height:we.naturalHeight;const V=await tr.detect(we);Kp(we,V,M);const oe=document.createElement("canvas");oe.className="thumbnail",oe.width=window.innerWidth/(Nn.columns+.1),oe.height=M.height/(window.innerWidth/oe.width);const de=oe.getContext("2d");de.drawImage(M,0,0,M.width,M.height,0,0,oe.width,oe.height),document.getElementById("samples-container").appendChild(oe),we.src="",i(!0)},we.src=N})}async function ix(){tr.config.videoOptimized=!0,document.getElementById("samples-container").style.display="none",document.getElementById("canvas").style.display="block";const N=document.getElementById("video"),i=document.getElementById("canvas");Nn.baseLineHeight=Nn.baseLineHeightProto,N.srcObject!==null&&!N.paused?(document.getElementById("play").style.display="block",Xo("paused"),N.pause()):(await Xp(),document.getElementById("play").style.display="none",Xo(""),N.play()),qp(N,i)}async function ox(){document.getElementById("play").style.display="none",tr.config.videoOptimized=!1;const N=12+Math.trunc(12*Nn.columns*window.innerWidth/document.body.clientWidth);Nn.baseFont=Nn.baseFontProto.replace(/{size}/, ` $ { N } px ` ),Nn.baseLineHeight=Nn.baseLineHeightProto*Nn.columns,document.getElementById("canvas").style.display="none",document.getElementById("samples-container").style.display="block",Ko("Running detection of sample images"),Xo("processing images"),document.getElementById("samples-container").innerHTML="";for(const i of Nn.samples)await ax(i);Xo("")}function sx(){Pn=new Gp(document.body,"...",{top:"1rem",right:"1rem"});const N=Pn.addButton("start video","pause video",()=>ix());Pn.addButton("process images","process images",()=>ox()),document.getElementById("play").addEventListener("click",()=>N.click()),Pn.addHTML('<hr style="min-width: 200px; border-style: inset; border-color: dimgray">'),Pn.addList("Backend",["cpu","webgl","wasm","webgpu"],tr.config.backend,i=>tr.config.backend=i),Pn.addBool("A
2020-11-06 22:21:20 +01:00
/ * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Copyright ( c ) Microsoft Corporation . 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
THIS CODE IS PROVIDED ON AN * AS IS * BASIS , WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND , EITHER EXPRESS OR IMPLIED , INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE , FITNESS FOR A PARTICULAR PURPOSE ,
MERCHANTABLITY OR NON - INFRINGEMENT .
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/ * *
* @ license
* Copyright 2017 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 2018 Google LLC
*
* 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.
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
* Copyright 2018 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 2018 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 2019 Google LLC
*
* 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.
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ 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
* 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
* Copyright 2020 Google Inc . 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
*
* 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.
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ 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 .
* 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
*
* https : //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 .
* 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 2018 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 See the LICENSE file. */
2020-11-04 17:43:51 +01:00
//# sourceMappingURL=demo-browser-index.js.map