2021-09-11 03:21:29 +02:00
/ *
Human
homepage : < https : //github.com/vladmandic/human>
author : < https : //github.com/vladmandic>'
* /
2021-10-22 22:09:52 +02:00
var sW = Object . create ; var Sg = Object . defineProperty ; var iW = Object . getOwnPropertyDescriptor ; var aW = Object . getOwnPropertyNames ; var lW = Object . getPrototypeOf , uW = Object . prototype . hasOwnProperty ; var XS = r => Sg ( r , "__esModule" , { value : ! 0 } ) ; var Lc = ( r => typeof require != "undefined" ? require : typeof Proxy != "undefined" ? new Proxy ( r , { get : ( e , t ) => ( typeof require != "undefined" ? require : e ) [ t ] } ) : r ) ( function ( r ) { if ( typeof require != "undefined" ) return require . apply ( this , arguments ) ; throw new Error ( 'Dynamic require of "' + r + '" is not supported' ) } ) ; var qt = ( r , e ) => ( ) => ( e || r ( ( e = { exports : { } } ) . exports , e ) , e . exports ) , qe = ( r , e ) => { XS ( r ) ; for ( var t in e ) Sg ( r , t , { get : e [ t ] , enumerable : ! 0 } ) } , cW = ( r , e , t ) => { if ( e && typeof e == "object" || typeof e == "function" ) for ( let n of aW ( e ) ) ! uW . call ( r , n ) && n !== "default" && Sg ( r , n , { get : ( ) => e [ n ] , enumerable : ! ( t = iW ( e , n ) ) || t . enumerable } ) ; return r } , ou = r => cW ( XS ( Sg ( r != null ? sW ( lW ( r ) ) : { } , "default" , r && r . _ _esModule && "default" in r ? { get : ( ) => r . default , enumerable : ! 0 } : { value : r , enumerable : ! 0 } ) ) , r ) ; var hN = qt ( ( Cse , dN ) => { dN . exports = Wt ; var oo = null ; try { oo = new WebAssembly . Instance ( new WebAssembly . Module ( new Uint8Array ( [ 0 , 97 , 115 , 109 , 1 , 0 , 0 , 0 , 1 , 13 , 2 , 96 , 0 , 1 , 127 , 96 , 4 , 127 , 127 , 127 , 127 , 1 , 127 , 3 , 7 , 6 , 0 , 1 , 1 , 1 , 1 , 1 , 6 , 6 , 1 , 127 , 1 , 65 , 0 , 11 , 7 , 50 , 6 , 3 , 109 , 117 , 108 , 0 , 1 , 5 , 100 , 105 , 118 , 95 , 115 , 0 , 2 , 5 , 100 , 105 , 118 , 95 , 117 , 0 , 3 , 5 , 114 , 101 , 109 , 95 , 115 , 0 , 4 , 5 , 114 , 101 , 109 , 95 , 117 , 0 , 5 , 8 , 103 , 101 , 116 , 95 , 104 , 105 , 103 , 104 , 0 , 0 , 10 , 191 , 1 , 6 , 4 , 0 , 35 , 0 , 11 , 36 , 1 , 1 , 126 , 32 , 0 , 173 , 32 , 1 , 173 , 66 , 32 , 134 , 132 , 32 , 2 , 173 , 32 , 3 , 173 , 66 , 32 , 134 , 132 , 126 , 34 , 4 , 66 , 32 , 135 , 167 , 36 , 0 , 32 , 4 , 167 , 11 , 36 , 1 , 1 , 126 , 32 , 0 , 173 , 32 , 1 , 173 , 66 , 32 , 134 , 132 , 32 , 2 , 173 , 32 , 3 , 173 , 66 , 32 , 134 , 132 , 127 , 34 , 4 , 66 , 32 , 135 , 167 , 36 , 0 , 32 , 4 , 167 , 11 , 36 , 1 , 1 , 126 , 32 , 0 , 173 , 32 , 1 , 173 , 66 , 32 , 134 , 132 , 32 , 2 , 173 , 32 , 3 , 173 , 66 , 32 , 134 , 132 , 128 , 34 , 4 , 66 , 32 , 135 , 167 , 36 , 0 , 32 , 4 , 167 , 11 , 36 , 1 , 1 , 126 , 32 , 0 , 173 , 32 , 1 , 173 , 66 , 32 , 134 , 132 , 32 , 2 , 173 , 32 , 3 , 173 , 66 , 32 , 134 , 132 , 129 , 34 , 4 , 66 , 32 , 135 , 167 , 36 , 0 , 32 , 4 , 167 , 11 , 36 , 1 , 1 , 126 , 32 , 0 , 173 , 32 , 1 , 173 , 66 , 32 , 134 , 132 , 32 , 2 , 173 , 32 , 3 , 173 , 66 , 32 , 134 , 132 , 130 , 34 , 4 , 66 , 32 , 135 , 167 , 36 , 0 , 32 , 4 , 167 , 11 ] ) ) , { } ) . exports } catch ( r ) { } function Wt ( r , e , t ) { this . low = r | 0 , this . high = e | 0 , this . unsigned = ! ! t } Wt . prototype . _ _isLong _ _ ; Object . defineProperty ( Wt . prototype , "__isLong__" , { value : ! 0 } ) ; function Fn ( r ) { return ( r && r . _ _isLong _ _ ) === ! 0 } Wt . isLong = Fn ; var sN = { } , iN = { } ; function cu ( r , e ) { var t , n , o ; return e ? ( r >>>= 0 , ( o = 0 <= r && r < 256 ) && ( n = iN [ r ] , n ) ? n : ( t = Ut ( r , ( r | 0 ) < 0 ? - 1 : 0 , ! 0 ) , o && ( iN [ r ] = t ) , t ) ) : ( r |= 0 , ( o = - 128 <= r && r < 128 ) && ( n = sN [ r ] , n ) ? n : ( t = Ut ( r , r < 0 ? - 1 : 0 , ! 1 ) , o && ( sN [ r ] = t ) , t ) ) } Wt . fromInt = cu ; function so ( r , e ) { if ( isNaN ( r ) ) return e ? pu : io ; if ( e ) { if ( r < 0 ) return pu ; if ( r >= lN ) return fN } else { if ( r <= - uN ) return On ; if ( r + 1 >= uN ) return mN } return r < 0 ? so ( - r , e ) . neg ( ) : Ut ( r % Ip | 0 , r / Ip | 0 , e ) } Wt . fromNumber = so ; function Ut ( r , e , t ) { return new Wt ( r , e , t ) } Wt . fromBits = Ut ; var Dg = Math . pow ; function e _ ( r , e , t ) { if ( r . length === 0 ) throw Error ( "empty string" ) ; if ( r === "NaN" || r === "Infinity" || r === "+Infinity" || r === "-Infinity" ) return io ; if ( typeof e == "number" ? ( t = e , e = ! 1 ) : e = ! ! e , t = t || 10 , t < 2 || 36 < t ) throw RangeError ( "radix" ) ; var n ; if ( ( n = r . indexOf ( "-" ) ) > 0 ) throw Error ( "interior hyphen" ) ; if ( n === 0 ) return e _ ( r . substring ( 1 ) , e , t ) . neg ( ) ; for ( var o = so ( Dg ( t , 8 ) ) , s = io , a = 0 ; a < r . length ; a += 8 ) { var i = Math . min ( 8 , r . length - a ) , l = parseInt ( r . substring ( a , a + i ) , t ) ; if ( i < 8 ) { var u = so ( Dg ( t , i ) ) ; s = s . mul ( u ) . add ( so ( l ) ) } else s = s . mul ( o ) , s = s . add ( so ( l ) ) } return s . unsigned = e , s } Wt . fromString = e _ ; function Ss ( r , e ) { return typeof r == "number" ? so ( r , e ) : typeof r == "string" ? e _ ( r , e ) : Ut ( r . low , r . high , typeof e == "boolean" ? e : r . unsigned ) } Wt . fromValue = Ss ; var aN = 1 << 16 , RW = 1 << 24 , Ip = aN * aN , lN = Ip * Ip , uN = lN / 2 , cN = cu ( RW ) , io = cu ( 0 ) ; Wt . ZERO = io ; var pu = cu ( 0 , ! 0 ) ; Wt . UZERO = pu ; var Sp = cu ( 1 ) ; Wt . ONE = Sp ; var pN = cu ( 1 , ! 0 ) ; Wt . UONE = pN ; var t _ = cu ( - 1 ) ; Wt . NEG _ONE = t _ ; var mN = Ut ( 4294967295 | 0 , 2147483647 | 0 , ! 1 ) ; Wt . MAX _VALUE = mN ; var fN = Ut ( 4294967295 | 0 , 4294967295 | 0 , ! 0 ) ; Wt . MAX _UNSIGNED _VALUE = fN ; var On = Ut ( 0 , 2147483648 | 0 , ! 1 ) ; Wt . MIN _VALUE = On ; var we = Wt . prototype ; we . toInt = function ( ) { return this . unsigned ? this . low >>> 0 : this . low } ; we . toNumber = function ( ) { return this . unsigned ? ( this . high >>> 0 ) * Ip + ( this . low >>> 0 ) : this . high * Ip + ( this . low >>> 0 ) } ; we . toString = function ( e ) { if ( e = e || 10 , e < 2 || 36 < e ) throw RangeError ( "radix" ) ; if ( this . isZero ( ) ) return "0" ; if ( this . isNegative ( ) ) if ( this . eq ( On ) ) { var t = so ( e ) , n = this . div ( t ) , o = n . mul ( t ) . sub ( this ) ; return
` )),l.join( `
` )}function WW(r,e,t,n){let o=st(e),s=n[n.length-1],a=new Array(s).fill(0),i=e.length,l=t==="complex64"?cf(r):r;if(i>1)for(let u=0;u<o/s;u++){let c=u*s;for(let p=0;p<s;p++)a[p]=Math.max(a[p],uf(l[c+p],0,t).length)}return a}function uf(r,e,t){let n;return Array.isArray(r)?n= ` $ { parseFloat ( r [ 0 ] . toFixed ( o _ ) ) } + $ { parseFloat ( r [ 1 ] . toFixed ( o _ ) ) } j ` :Do(r)?n= ` '${r}' ` :t==="bool"?n=IN(r):n=parseFloat(r.toFixed(o_)).toString(),su(n,e)}function IN(r){return r===0?"false":"true"}function Rg(r,e,t,n,o,s=!0){let a=t==="complex64"?2:1,i=e[0],l=e.length;if(l===0){if(t==="complex64"){let h=cf(r);return[uf(h[0],0,t)]}return t==="bool"?[IN(r[0])]:[r[0].toString()]}if(l===1){if(i>vN){let g=lf*a,x=Array.from(r.slice(0,g)),y=Array.from(r.slice((i-lf)*a,i*a));return t==="complex64"&&(x=cf(x),y=cf(y)),["["+x.map((w,_)=>uf(w,o[_],t)).join(", ")+", ..., "+y.map((w,_)=>uf(w,o[i-lf+_],t)).join(", ")+"]"]}let h=t==="complex64"?cf(r):Array.from(r);return["["+h.map((g,x)=>uf(g,o[x],t)).join(", ")+"]"]}let u=e.slice(1),c=n.slice(1),p=n[0]*a,m=[];if(i>vN){for(let h=0;h<lf;h++){let g=h*p,x=g+p;m.push(...Rg(r.slice(g,x),u,t,c,o,!1))}m.push("...");for(let h=i-lf;h<i;h++){let g=h*p,x=g+p;m.push(...Rg(r.slice(g,x),u,t,c,o,h===i-1))}}else for(let h=0;h<i;h++){let g=h*p,x=g+p;m.push(...Rg(r.slice(g,x),u,t,c,o,h===i-1))}let f=l===2?",":"";m[0]="["+m[0]+f;for(let h=1;h<m.length-1;h++)m[h]=" "+m[h]+f;let d= ` ,
` ;for(let h=2;h<l;h++)d+= `
` ;return m[m.length-1]=" "+m[m.length-1]+"]"+(s?"":d),m}function cf(r){let e=[];for(let t=0;t<r.length;t+=2)e.push([r[t],r[t+1]]);return e}var mt=class{constructor(e,t,n){if(this.dtype=t,this.shape=e.slice(),this.size=st(e),n!=null){let o=n.length;E(o===this.size,()=> ` Length of values '${o}' does not match the size inferred by the shape '${this.size}' . ` )}if(t==="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=n||jw(t,this.size),this.strides=ei(e)}set(e,...t){t.length===0&&(t=[0]),E(t.length===this.rank,()=> ` The number of provided coordinates ( $ { t . length } ) must match the rank ( $ { this . rank } ) ` );let n=this.locToIndex(t);this.values[n]=e}get(...e){e.length===0&&(e=[0]);let t=0;for(let o of e){if(o<0||o>=this.shape[t]){let s= ` Requested out of range element at $ { e } . Buffer shape = $ { this . shape } ` ;throw new Error(s)}t++}let n=e[e.length-1];for(let o=0;o<e.length-1;++o)n+=this.strides[o]*e[o];return this.values[n]}locToIndex(e){if(this.rank===0)return 0;if(this.rank===1)return e[0];let t=e[e.length-1];for(let n=0;n<e.length-1;++n)t+=this.strides[n]*e[n];return t}indexToLoc(e){if(this.rank===0)return[];if(this.rank===1)return[e];let t=new Array(this.shape.length);for(let n=0;n<t.length-1;++n)t[n]=Math.floor(e/this.strides[n]),e-=t[n]*this.strides[n];return t[t.length-1]=e,t}get rank(){return this.shape.length}toTensor(){return bi().makeTensor(this.values,this.shape,this.dtype)}},bi=null,Ep=null,UW=null;function SN(r){bi=r}function NN(r){Ep=r}function TN(r){UW=r}var Le=class{constructor(e,t,n,o){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=st(e),this.strides=ei(e),this.dataId=n,this.id=o,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){let e=await this.data();return Ep.buffer(this.shape,this.dtype,e)}bufferSync(){return Ep.buffer(this.shape,this.dtype,this.dataSync())}async array(){let e=await this.data();return iu(this.shape,e,this.dtype==="complex64")}arraySync(){return iu(this.shape,this.dataSync(),this.dtype==="complex64")}async data(){this.throwIfDisposed();let e=bi().read(this.dataId);if(this.dtype==="string"){let t=await e;try{return t.map(n=>Tp(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}dataSync(){this.throwIfDisposed();let e=bi().readSync(this.dataId);if(this.dtype==="string")try{return e.map(t=>Tp(t))}catch(t){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return e}async bytes(){this.throwIfDisposed();let e=await bi().read(this.dataId);return this.dtype==="string"?e:new Uint8Array(e.buffer)}dispose(){this.isDisposed||(bi().disposeTensor(this),this.isDisposedInternal=!0)}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=!1){return Ep.print(this,e)}clone(){return this.throwIfDisposed(),Ep.clone(this)}toString(e=!1){let t=this.dataSync();return CN(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),Ep.cast(this,e)}variable(e=!0,t,n){return this.throwIfDisposed(),bi().makeVariable(this,e,t,n)}};Object.defineProperty(Le,Symbol.hasInstance,{value:r=>!!r&&r.data!=null&&r.dataSync!=null&&r.throwIfDisposed!=null});function M(){return ef("Tensor",()=>Le)}M();var Sl=class extends Le{constructor(e,t,n,o){super(e.shape,e.dtype,e.dataId,o);this.trainable=t,this.name=n}assign(e){if(e.dtype!==this.dtype)throw new Error( ` dtype of the new value ( $ { e . dtype } ) and previous value ( $ { this . dtype } ) must match ` );if(!Qr(e.shape,this.shape))throw new Error( ` shape of the new value ( $ { e . shape } ) and previous value ( $ { this . shape } ) must match ` );bi().disposeTensor(this),this.dataId=e.dataId,bi().incRef(this,null)}dispose(){bi().disposeVariable(this),this.isDisposedInternal=!0}};Object.defineProperty(Sl,Symbol.hasInstance,{value:r=>r instanceof Le&&r.assi
Manifest JSON has weights with names : $ { i . join ( ", " ) } . ` )}let l=o.reduce((f,d,h)=>(d&&f.push(h),f),[]),u=[];l.forEach(f=>{e[f].paths.forEach(d=>{let h=t+(t.endsWith("/")?"":"/")+d;u.push(h)})});let c=await r(u),p={},m=0;return l.forEach(f=>{let d=e[f].paths.length,h=0;for(let _=0;_<d;_++)h+=c[m+_].byteLength;let g=new ArrayBuffer(h),x=new Uint8Array(g),y=0;for(let _=0;_<d;_++){let C=new Uint8Array(c[m+_]);x.set(C,y),y+=C.byteLength}s[f].forEach(_=>{let C=g.slice(_.groupOffset,_.groupOffset+_.sizeBytes),A=Og(C,[_.manifestEntry]);for(let D in A)p[D]=A[D]}),m+=d}),p}}var v4="application/octet-stream",C4="application/json",Lg=class{constructor(e,t){if(this.DEFAULT_METHOD="POST",t==null&&(t={}),this.weightPathPrefix=t.weightPathPrefix,this.onProgress=t.onProgress,this.weightUrlConverter=t.weightUrlConverter,t.fetchFunc!=null?(E(typeof t.fetchFunc=="function",()=>"Must pass a function that matches the signature of ` fetch ` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"),this.fetch=t.fetchFunc):this.fetch=U().platform.fetch,E(e!=null&&e.length>0,()=>"URL path for http must not be null, undefined or empty."),Array.isArray(e)&&E(e.length===2,()=> ` URL paths for http must have a length of 2 , ( actual length is $ { e . length } ) . ` ),this.path=e,t.requestInit!=null&&t.requestInit.body!=null)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=t.requestInit||{}}async save(e){if(e.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");let t=Object.assign({method:this.DEFAULT_METHOD},this.requestInit);t.body=new FormData;let n=[{paths:["./model.weights.bin"],weights:e.weightSpecs}],o=Pg(e,n);t.body.append("model.json",new Blob([JSON.stringify(o)],{type:C4}),"model.json"),e.weightData!=null&&t.body.append("model.weights.bin",new Blob([e.weightData],{type:v4}),"model.weights.bin");let s=await this.fetch(this.path,t);if(s.ok)return{modelArtifactsInfo:wi(e),responses:[s]};throw new Error( ` BrowserHTTPRequest . save ( ) failed due to HTTP response status $ { s . status } . ` )}async load(){let e=await this.fetch(this.path,this.requestInit);if(!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 . ` );let t;try{t=await e.json()}catch(s){let a= ` Failed to parse model JSON of response from $ { this . path } . ` ;throw this.path.endsWith(".pb")?a+=" 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.":a+=" Please make sure the server is serving valid JSON for this request.",new Error(a)}let n=t.modelTopology,o=t.weightsManifest;if(n==null&&o==null)throw new Error( ` The JSON from HTTP path $ { this . path } contains neither model topology or manifest for weights . ` );return Dp(t,s=>this.loadWeights(s))}async loadWeights(e){let t=Array.isArray(this.path)?this.path[1]:this.path,[n,o]=I4(t),s=this.weightPathPrefix||n,a=[];for(let c of e)a.push(...c.weights);let i=[],l=[];for(let c of e)for(let p of c.paths)this.weightUrlConverter!=null?l.push(this.weightUrlConverter(p)):i.push(s+p+o);this.weightUrlConverter&&i.push(...await Promise.all(l));let u=await S_(i,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress});return[a,Ap(u)]}};Lg.URL_SCHEME_REGEX=/^https?: \/ \/ /;function I4(r){let e=r.lastIndexOf("/"),t=r.lastIndexOf("?"),n=r.substring(0,e),o=t>e?r.substring(t):"";return[n+"/",o]}function zg(r){return r.match(Lg.URL_SCHEME_REGEX)!=null}var s1=(r,e)=>{if(typeof fetch=="undefined"&&(e==null||e.fetchFunc==null))return null;{let t=!0;if(Array.isArray(r)?t=r.every(n=>zg(n)):t=zg(r),t)return Bg(r,e)}return null};Et.registerSaveRouter(s1);Et.registerLoadRouter(s1);function Bg(r,e){return new Lg(r,e)}function i1(r,e){return Bg(r,e)}var Vg=class{
Actual : $ { o } .
Expected : $ { s } . ` );for(let a=0;a<s.length;++a){let i=o[a],l=s[a];if(!t(i,l))throw new Error( ` Arrays differ : actual [ $ { a } ] = $ { i } , expected [ $ { a } ] = $ { l } .
Actual : $ { o } .
Expected : $ { s } . ` )}}function W4(r,e){r().then(()=>e.fail(),()=>e())}function U4(r,e){let t=typeof e=="string"||typeof e=="number"||typeof e=="boolean"?[e]:e;return Do(r)||Do(r[0])||Do(e)||Do(e[0])?D_(r,t,(n,o)=>n==o):D_(r,e,(n,o)=> $ _(n,o,0))}function S1(r,e,t){if(t==null&&(t=Kg()),! $ _(r,e,t))throw new Error( ` Numbers differ : actual === $ { r } , expected === $ { e } ` )}function $ _(r,e,t){return!isFinite(r)&&!isFinite(e)?!0:!(isNaN(r)||isNaN(e)||Math.abs(r-e)>t)}function j4(r,e,t){for(let n=0;n<r.length;n++)if(r[n]<e||r[n]>t)throw new Error( ` Value out of range : $ { r [ n ] } low : $ { e } , high : $ { t } ` )}function H4(r,e){expect(new Float32Array(r)).toEqual(new Float32Array(e))}function N1(r){for(let e=0;e<r.length;e++){let t=r[e];Array.isArray(t)?N1(t):r[e]=Il(t)}return r}var E1="3.10.0";function nue(){U().set("PROD",!0)}function oue(){U().set("DEBUG",!0)}function sue(){U().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")}function R_(r){U().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(r+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}TN(R_);function iue(){T.disposeVariables()}function Es(){return T}function ff(){return T.memory()}function aue(r){return T.profile(r)}function V(r,e){return T.tidy(r,e)}function De(r){pf(r).forEach(t=>t.dispose())}function Ft(r){return T.keep(r)}function lue(r){return T.time(r)}function q4(r){return T.setBackend(r)}function uue(){return T.ready()}function cue(){return T.backendName}function pue(r){T.removeBackend(r)}function mue(r){return T.findBackend(r)}function fue(r){return T.findBackendFactory(r)}function Op(r,e,t=1){return T.registerBackend(r,e,t)}function A1(){return T.backend}function due(r,e){U().setPlatform(r,e)}function K4(r,e){let t=k(r,"a","add"),n=k(e,"b","add");[t,n]=je(t,n);let o={a:t,b:n};return T.runKernel(jn,o)}var Z=N({add_:K4});function X4(r,e){let t=k(r,"a","floorDiv"),n=k(e,"b","floorDiv");[t,n]=je(t,n);let o={a:t,b:n};return T.runKernel(qo,o)}var bu=N({floorDiv_:X4});function Y4(r,e){let t=k(r,"a","div"),n=k(e,"b","div");if([t,n]=je(t,n),t.dtype==="int32"&&n.dtype==="int32")return bu(t,n);let o={a:t,b:n},s={};return T.runKernel(Wo,o,s)}var ce=N({div_:Y4});function Z4(r,e){let t=k(r,"a","mul"),n=k(e,"b","mul");[t,n]=je(t,n);let o={a:t,b:n};return T.runKernel(ss,o)}var O=N({mul_:Z4});function J4(r){let e=k(r,"x","abs");if(e.dtype==="complex64"){let t={x:e};return T.runKernel(dl,t)}else{let t={x:e};return T.runKernel(ti,t)}}var Ct=N({abs_:J4});function Q4(r){let t={x:k(r,"x","acos")};return T.runKernel(Mi,t)}var df=N({acos_:Q4});function eU(r){let t={x:k(r,"x","acosh")};return T.runKernel(Li,t)}var hf=N({acosh_:eU});function tU(r){E(Array.isArray(r),()=>"The argument passed to tf.addN() must be a list of tensors"),E(r.length>=1,()=> ` Must pass at least one tensor to tf . addN ( ) , but got $ { r . length } ` );let e=r.map((o,s)=>k(o, ` tensors$ { s } ` ,"addN")),t=e[0];e.forEach(o=>{if(o.dtype!==t.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),e.forEach(o=>{if(!Qr(o.shape,t.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});let n=e;return T.runKernel( $ o,n)}var F_=N({addN_:tU});function rU(r,e=null,t=!1){let o={x:k(r,"x","all","bool")},s={axis:e,keepDims:t};return T.runKernel(zi,o,s)}var wu=N({all_:rU});function nU(r,e=null,t=!1){let o={x:k(r,"x","any","bool")},s={axis:e,keepDims:t};return T.runKernel(Bi,o,s)}var El=N({any_:nU});function oU(r,e=0){let n={x:k(r,"x","argMax")},o={axis:e};return T.runKernel(Ro,n,o)}var As=N({argMax_:oU});function sU(r,e=0){let n={x:k(r,"x","argMin")},o={axis:e};return T.runKernel(ml,n,o)}var gf=N({argMin_:sU});function iU(r){let t={x:k(r,"x","asin")};return T.runKernel(Vi,t)}var xf=N({asin_:iU});function aU(r){let t={x:k(r,"x","asinh")};return T.runKernel(Gi,t)}var yf=N({asinh_:aU});function lU(r){let t={x:k(r,"x","atan")};return T.runKernel(Wi,t)}var bf=N({atan_:lU});function uU(r,e){let t=k(r,"a","atan2"),n=k(e,"b","atan2");[t,n]=je(t,n);let o={a:t,b:n};return T.runKernel(ji,o)}var wf=N({atan2_:uU});function cU(r
with dtype $ { s . dtype } . ` )}),t.length===1)return wn(t[0]);let n=t,o={axis:e};return T.runKernel(ni,n,o)}var tt=N({concat_:wU});function _U(r){let t={x:k(r,"x","sigmoid","float32")};return T.runKernel(xs,t)}var zr=N({sigmoid_:_U});function kU(r,e,t){let n=k(r,"x","slice","string_or_numeric");if(n.rank===0)throw new Error("Slicing scalar is not possible");let o={x:n},s={begin:e,size:t};return T.runKernel(pi,o,s)}var Oe=N({slice_:kU});function vU(r){let t={x:k(r,"x","tanh","float32")};return T.runKernel(Cs,t)}var Ds=N({tanh_:vU});function CU(r,e,t,n,o,s){let a=k(r,"forgetBias","basicLSTMCell"),i=k(e,"lstmKernel","basicLSTMCell"),l=k(t,"lstmBias","basicLSTMCell"),u=k(n,"data","basicLSTMCell"),c=k(o,"c","basicLSTMCell"),p=k(s,"h","basicLSTMCell"),m=tt([u,p],1),f=ze(m,i),d=Z(f,l),h=d.shape[0],g=d.shape[1]/4,x=[h,g],y=Oe(d,[0,0],x),w=Oe(d,[0,g],x),_=Oe(d,[0,g*2],x),C=Oe(d,[0,g*3],x),A=Z(O(zr(y),Ds(w)),O(c,zr(Z(a,_)))),D=O(Ds(A),zr(C));return[A,D]}var IU=N({basicLSTMCell_:CU});function SU(r,e,t){let n=k(r,"x","batchToSpaceND"),o=e.reduce((i,l)=>i*l);E(n.rank>=1+e.length,()=> ` input rank is $ { n . rank } but should be > than blockShape . length $ { e . length } ` ),E(t.length===e.length,()=> ` crops . length is $ { t . length } but should be equal to blockShape . length $ { e . length } ` ),E(n.shape[0]%o==0,()=> ` input tensor batch is $ { n . shape [ 0 ] } but is not divisible by the product of the elements of blockShape $ { e . join ( " * " ) } === $ { o } ` );let s={x:n},a={blockShape:e,crops:t};return T.runKernel(ri,s,a)}var Ea=N({batchToSpaceND_:SU});function R1(r){let e;return r.rank===0||r.rank===1?e=F(r,[1,1,1,r.size]):r.rank===2?e=F(r,[1,1,r.shape[0],r.shape[1]]):r.rank===3?e=F(r,[1,r.shape[0],r.shape[1],r.shape[2]]):e=r,e}function NU(r,e,t,n,o,s){s==null&&(s=.001);let a=k(r,"x","batchNorm"),i=k(e,"mean","batchNorm"),l=k(t,"variance","batchNorm"),u;o!=null&&(u=k(o,"scale","batchNorm"));let c;n!=null&&(c=k(n,"offset","batchNorm")),E(i.rank===l.rank,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),E(c==null||i.rank===c.rank,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),E(u==null||i.rank===u.rank,()=>"Batch normalization gradient requires mean and scale to have equal ranks.");let m={x:R1(a),scale:u,offset:c,mean:i,variance:l},f={varianceEpsilon:s},d=T.runKernel(Ko,m,f);return F(d,a.shape)}var lo=N({batchNorm_:NU});function TU(r,e,t,n,o,s){let a=k(r,"x","batchNorm"),i=k(e,"mean","batchNorm"),l=k(t,"variance","batchNorm"),u;o!=null&&(u=k(o,"scale","batchNorm"));let c;return n!=null&&(c=k(n,"offset","batchNorm")),E(a.rank===2,()=> ` Error in batchNorm2D : x must be rank 2 but got rank $ { a . rank } . ` ),E(i.rank===2||i.rank===1,()=> ` Error in batchNorm2D : mean must be rank 2 or rank 1 but got rank $ { i . rank } . ` ),E(l.rank===2||l.rank===1,()=> ` Error in batchNorm2D : variance must be rank 2 or rank 1 but got rank $ { l . rank } . ` ),u!=null&&E(u.rank===2||u.rank===1,()=> ` Error in batchNorm2D : scale must be rank 2 or rank 1 but got rank $ { u . rank } . ` ),c!=null&&E(c.rank===2||c.rank===1,()=> ` Error in batchNorm2D : offset must be rank 2 or rank 1 but got rank $ { c . rank } . ` ),lo(a,i,l,c,u,s)}var L_=N({batchNorm2d_:TU});function EU(r,e,t,n,o,s){let a=k(r,"x","batchNorm"),i=k(e,"mean","batchNorm"),l=k(t,"variance","batchNorm"),u;o!=null&&(u=k(o,"scale","batchNorm"));let c;return n!=null&&(c=k(n,"offset","batchNorm")),E(a.rank===3,()=> ` Error in batchNorm3D : x must be rank 3 but got rank $ { a . rank } . ` ),E(i.rank===3||i.rank===1,()=> ` Error in batchNorm3D : mean must be rank 3 or rank 1 but got rank $ { i . rank } . ` ),E(l.rank===3||l.rank===1,()=> ` Error in batchNorm3D : variance must be rank 3 or rank 1 but got rank $ { l . rank } . ` ),u!=null&&E(u.rank===3||u.rank===1,()=> ` Error in batchNorm3D : scale must be rank 3 or rank 1 but got rank $ { u . rank } . ` ),c!=null&&E(c.rank===3||c.rank===1,()=> ` Error in batchNorm3D : offset must be rank 3 or rank 1 but got rank $ { c . rank } . ` ),lo(a,i,l,c,u,s)}var z_=N({batchNorm3d_:EU});function AU(r,e,t,n,o,s){let a=k(r,"x","batchNorm"),i=k(e,"mean","batchNorm"),l=k(t,"variance","batchNorm"),u;o!=null&&(u=k(o,"scale","batchNorm"))
$ { o } and $ { e } for depthToSpace with input shape
$ { n . shape } ` ),E(s*e>=0,()=> ` Negative dimension size caused by overflow when multiplying
$ { s } and $ { e } for depthToSpace with input shape
$ { n . shape } ` ),E(a%(e*e)==0,()=> ` Dimension size must be evenly divisible by $ { e * e } but is $ { a } for depthToSpace with input shape $ { n . shape } ` );let i={x:n},l={blockSize:e,dataFormat:t};return T.runKernel(qi,i,l)}var Sf=N({depthToSpace_:ZU});function JU(r,e,t,n,o="NHWC",s=[1,1],a){let i=k(r,"x","depthwiseConv2d","float32"),l=k(e,"filter","depthwiseConv2d","float32"),u=i,c=!1;i.rank===3&&(c=!0,u=F(i,[1,i.shape[0],i.shape[1],i.shape[2]])),E(u.rank===4,()=> ` Error in depthwiseConv2d : input must be rank 4 , but got rank $ { u . rank } . ` ),E(l.rank===4,()=> ` Error in depthwiseConv2d : filter must be rank 4 , but got rank $ { l . rank } . ` ),E(u.shape[3]===l.shape[2],()=> ` Error in depthwiseConv2d : number of input channels ( $ { u . shape [ 3 ] } ) must match the inChannels dimension in filter $ { l . shape [ 2 ] } . ` ),a!=null&&E(it(n),()=> ` Error in depthwiseConv2d : pad must be an integer when using , dimRoundingMode $ { a } but got pad $ { n } . ` );let p={x:u,filter:l},m={strides:t,pad:n,dataFormat:o,dilations:s,dimRoundingMode:a},f=T.runKernel(Go,p,m);return c?F(f,[f.shape[1],f.shape[2],f.shape[3]]):f}var $ s=N({depthwiseConv2d_:JU});function QU(r){let t={x:k(r,"x","diag")};return T.runKernel(ep,t)}var ej=N({diag_:QU});function tj(r,e,t,n,o=[1,1],s="NHWC"){let a=k(r,"x","dilation2d"),i=k(e,"filter","dilation2d");E(a.rank===3||a.rank===4,()=> ` Error in dilation2d : input must be rank 3 or 4 , but got rank $ { a . rank } . ` ),E(i.rank===3,()=> ` Error in dilation2d : filter must be rank 3 , but got rank $ { i . rank } . ` ),E(s==="NHWC",()=> ` Error in dilation2d : Only NHWC is currently supported , but got dataFormat of $ { s } ` );let l=a,u=!1;a.rank===3&&(l=F(a,[1,a.shape[0],a.shape[1],a.shape[2]]),u=!0);let c={x:l,filter:i},p={strides:t,pad:n,dilations:o},m=T.runKernel(gl,c,p);return u?F(m,[m.shape[1],m.shape[2],m.shape[3]]):m}var Nf=N({dilation2d_:tj});function rj(r,e){let t=r.length,n=[];for(let o=0;o<t;o++){let s=t-1-o,a=r[s]||1;(e[e.length-1-o]||1)>1&&a===1&&n.unshift(s)}return n}function It(r,e){let t=[];for(let n=0;n<e.length;n++){let o=r[r.length-n-1],s=e.length-n-1,a=e[s];(o==null||o===1&&a>1)&&t.unshift(s)}return t}function We(r,e){let t=[],n=Math.max(r.length,e.length);for(let o=0;o<n;o++){let s=r[r.length-o-1];s==null&&(s=1);let a=e[e.length-o-1];if(a==null&&(a=1),s===1)t.unshift(a);else if(a===1)t.unshift(s);else if(s!==a){let i= ` Operands could not be broadcast together with shapes $ { r } and $ { e } . ` ;throw Error(i)}else t.unshift(s)}return t}function nj(r,e){let t=k(r,"a","equal","string_or_numeric"),n=k(e,"b","equal","string_or_numeric");[t,n]=je(t,n),We(t.shape,n.shape);let o={a:t,b:n};return T.runKernel(Xi,o)}var kr=N({equal_:nj});function oj(r,e,t){let n=k(e,"a","where"),o=k(t,"b","where"),s=k(r,"condition","where","bool"),a=We(We(s.shape,n.shape),o.shape),i=Aa(s,a),l=Aa(n,a),u=Aa(o,a),c={condition:i,t:l,e:u};return T.runKernel(ci,c)}var St=N({where_:oj});function sj(r){let t={x:k(r,"x","zerosLike")};return T.runKernel(hi,t)}var Se=N({zerosLike_:sj});function ij(r,e){let t=k(r,"a","div"),n=k(e,"b","div");[t,n]=je(t,n);let o=ce(t,n),s=Se(o),a=kr(n,s);return St(a,s,o)}var Tf=N({divNoNan_:ij});function aj(r,e){let t=k(r,"t1","dot"),n=k(e,"t2","dot");E((t.rank===1||t.rank===2)&&(n.rank===1||n.rank===2),()=> ` Error in dot : inputs must all be rank 1 or 2 , but got ranks $ { t . rank } and $ { n . rank } . ` );let o=t.rank===1?t.size:t.shape[1],s=n.rank===1?n.size:n.shape[0];if(E(o===s,()=> ` Error in dot : inner dimensions of inputs must match , but got $ { o } and $ { s } . ` ),t.rank===1&&n.rank===1){let a=F(t,[1,-1]),i=F(n,[-1,1]),l=ze(a,i);return F(l,[])}else if(t.rank===1&&n.rank===2){let a=F(t,[1,-1]),i=F(n,[n.shape[0],n.shape[1]]),l=ze(a,i);return F(l,[l.size])}else if(t.rank===2&&n.rank===1){let a=F(n,[-1,1]),i=ze(t,a);return F(i,[i.size])}else{let a=F(n,[n.shape[0],n.shape[1]]);return ze(t,a)}}var K_=N({dot_:aj});function lj(r,...e){let t=e.map((o,s)=>k(o, ` tensors$ { s } ` ,"einsum")),n={equation:r};return T.runKernel(tp,t,n)}var X_=N({einsum_:lj});function uj(r){let t={x:k(r,"x","elu","float32")};return T.runKernel(Uo,t)}var Rs=N({elu_:uj});function cj(r){let e=k(r,"x","erf");E(e.dtype==="int32"||e.dtype==="floa
rank $ { s . rank } . ` ),E(it(e),()=> ` Error in localResponseNormalization : depthRadius must be an integer but got depthRadius $ { e } . ` );let a=s,i=!1;s.rank===3&&(i=!0,a=F(s,[1,s.shape[0],s.shape[1],s.shape[2]]));let l={x:a},u={depthRadius:e,bias:t,alpha:n,beta:o},c=T.runKernel(yl,l,u);return i?F(c,[c.shape[1],c.shape[2],c.shape[3]]):c}var $ f=N({localResponseNormalization_:Nj});function Tj(r){let t={x:k(r,"x","log","float32")};return T.runKernel(Zo,t)}var xr=N({log_:Tj});function Ej(r){let t={x:k(r,"x","log1p")};return T.runKernel(sa,t)}var Ra=N({log1p_:Ej});function Aj(r){return E(Qs(r),()=>"The f passed in grad(f) must be a function"),(e,t)=>{let n=k(e,"x","tf.grad","string_or_numeric"),o=t!=null?k(t,"dy","tf.grad"):null;return T.tidy(()=>{let{value:s,grads:a}=T.gradients(()=>r(n),[n],o);return o!=null&&Rt(s.shape,o.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),Jg(a),a[0]})}}function Dj(r){return E(Qs(r),()=>"The f passed in grads(f) must be a function"),(e,t)=>{E(Array.isArray(e),()=>"The args passed in grads(f)(args) must be an array of ` Tensor ` s or ` TensorLike ` s");let n=va(e,"args","tf.grads","string_or_numeric"),o=t!=null?k(t,"dy","tf.grads"):null;return T.tidy(()=>{let{value:s,grads:a}=T.gradients(()=>r(...n),n,o);return o!=null&&Rt(s.shape,o.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Jg(a),a})}}function $ j(r){return E(Qs(r),()=>"The f passed in valueAndGrad(f) must be a function"),(e,t)=>{E(e instanceof Le,()=>"The x passed in valueAndGrad(f)(x) must be a tensor"),E(t==null||t instanceof Le,()=>"The dy passed in valueAndGrad(f)(x, dy) must be a tensor");let{grads:n,value:o}=T.gradients(()=>r(e),[e],t);return Jg(n),{grad:n[0],value:o}}}function Rj(r){return E(Qs(r),()=>"The f passed in valueAndGrads(f) must be a function"),(e,t)=>{E(Array.isArray(e)&&e.every(o=>o instanceof Le),()=>"The args passed in valueAndGrads(f)(args) must be array of tensors"),E(t==null||t instanceof Le,()=>"The dy passed in valueAndGrads(f)(args, dy) must be a tensor");let n=T.gradients(()=>r(...e),e,t);return t!=null&&Rt(n.value.shape,t.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Jg(n.grads),n}}function Zg(r,e){E(Qs(r),()=>"The f passed in variableGrads(f) must be a function"),E(e==null||Array.isArray(e)&&e.every(u=>u instanceof Sl),()=>"The varList passed in variableGrads(f, varList) must be an array of variables");let t=e!=null;if(!t){e=[];for(let u in T.registeredVariables)e.push(T.registeredVariables[u])}let n=t?e.filter(u=>!u.trainable):null,o=e.length;e=e.filter(u=>u.trainable),E(e.length>0,()=> ` variableGrads ( ) expects at least one of the input variables to be trainable , but none of the $ { o } variables is trainable . ` );let s=!0,{value:a,grads:i}=T.gradients(r,e,null,s);E(i.some(u=>u!=null),()=>"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."),E(a.rank===0,()=> ` The f passed in variableGrads ( f ) must return a scalar , but it returned a rank - $ { a . rank } tensor ` );let l={};return e.forEach((u,c)=>{i[c]!=null&&(l[u.name]=i[c])}),n!=null&&n.forEach(u=>l[u.name]=null),{value:a,grads:l}}function on(r){return T.customGrad(r)}function Jg(r){if(r.filter(t=>t==null).length>0)throw new Error( ` Cannot compute gradient of y = f ( x ) with respect to x . Make sure that
the f you passed encloses all operations that lead from x to y . ` )}function Fj(r){let t={x:k(r,"x","neg")};return T.runKernel(ii,t)}var He=N({neg_:Fj});function Oj(r){let t={x:k(r,"x","softplus")};return T.runKernel(ya,t)}var co=N({softplus_:Oj});function Pj(r){let e=k(r,"x","logSigmoid");return on(n=>({value:He(co(He(n))),gradFunc:a=>O(a,zr(He(n)))}))(e)}var Q_=N({logSigmoid_:Pj});function Mj(r,e=null,t=!1){let o={x:k(r,"x","max")},s={reductionIndices:e,keepDims:t};return T.runKernel(Jo,o,s)}var Rr=N({max_:Mj});function Lj(r,e){let t=k(r,"a","sub"),n=k(e,"b","sub");[t,n]=je(t,n);let o={a:t,b:n};return T.runKernel(ks,o)}var le=N({sub_:Lj});function zj(r,e=null,t=!1){let n=k(r,"x","sum");n.dtype==="bool"&&(n=Y(n,"int32"));let o={x:n},s={axis:e,keepDims:t};return T.runKernel(bs,o,s)}var me=N({sum_:zj});function Bj(r,e=-1){let t=k(r,"logits","logSoftmax");if(e===-1&&(e=t.rank-1),e!==t.rank-1)throw Error( ` Log Softmax along a non - last dimension is not yet supported . Logits was rank $ { t . rank } and axis was $ { e } ` );return on((o,s)=>{let a=!0,i=Rr(o,e,!0),l=le(o,i),u=le(Y(l,"float32"),xr(me(Kt(l),e,a)));return s([u]),{value:u,gradFunc:(p,m)=>{let[f]=m,d=!0,h=Kt(f);return le(p,O(me(p,e,d),h))}}})(t)}var Eu=N({logSoftmax_:Bj});function ek(r,e){for(let t=0;t<r.length;++t)if(r[r.length-t-1]!==e-1-t)return!1;return!0}function F1(r,e,t){let n=r.length+e.length,o=[],s=0,a=0;for(let i=0;i<n;i++)t.indexOf(i)===-1?o.push(r[s++]):o.push(e[a++]);return o}function tk(r,e){let t=[],n=r.length;for(let s=0;s<n;s++)e.indexOf(s)===-1&&t.push(r[s]);let o=e.map(s=>r[s]);return[t,o]}function po(r,e){let t=e.map(n=>1);return F1(r,t,e)}function Vj(r,e,t){E(ek(e,t),()=> ` $ { r } supports only inner - most axes for now . Got axes $ { e } and rank - $ { t } input . ` )}function rk(r,e){if(ek(r,e))return null;let t=[];for(let n=0;n<e;++n)r.indexOf(n)===-1&&t.push(n);return r.forEach(n=>t.push(n)),t}function Rf(r){return r.map((e,t)=>[t,e]).sort((e,t)=>e[1]-t[1]).map(e=>e[0])}function Gj(r,e){let t=[];for(let n=e-r;n<e;++n)t.push(n);return t}function Wj(r,e=null,t=!1){let n=k(r,"x","logSumExp"),o=cr(e,n.shape),s=Rr(n,o,!0),a=le(n,s),i=Kt(a),l=me(i,o),u=xr(l),c=Z(F(s,u.shape),u);if(t){let p=po(c.shape,o);return F(c,p)}return c}var Ff=N({logSumExp_:Wj});function Uj(r,e){let t=k(r,"a","logicalAnd","bool"),n=k(e,"b","logicalAnd","bool");We(t.shape,n.shape);let o={a:t,b:n};return T.runKernel(ia,o)}var Cr=N({logicalAnd_:Uj});function jj(r){let t={x:k(r,"x","logicalNot","bool")};return T.runKernel(au,t)}var Fa=N({logicalNot_:jj});function Hj(r,e){let t=k(r,"a","logicalOr","bool"),n=k(e,"b","logicalOr","bool");We(t.shape,n.shape);let o={a:t,b:n};return T.runKernel(lu,o)}var Au=N({logicalOr_:Hj});function qj(r,e){let t=k(r,"a","logicalXor","bool"),n=k(e,"b","logicalXor","bool");return We(t.shape,n.shape),Cr(Au(r,e),Fa(Cr(r,e)))}var nk=N({logicalXor_:qj});function Kj(r,e,t,n,o){let s=k(r,"x","maxPool"),a=1,i=s,l=!1;s.rank===3&&(l=!0,i=F(s,[1,s.shape[0],s.shape[1],s.shape[2]])),E(i.rank===4,()=> ` Error in maxPool : input must be rank 4 but got rank $ { i . rank } . ` ),E( $ r(t,a),()=> ` Error in maxPool : Either strides or dilations must be 1. Got strides $ { t } and dilations '${a}' ` ),o!=null&&E(it(n),()=> ` Error in maxPool : pad must be an integer when using , dimRoundingMode $ { o } but got pad $ { n } . ` );let u={x:i},c={filterSize:e,strides:t,pad:n,dimRoundingMode:o},p=T.runKernel(es,u,c);return l?F(p,[p.shape[1],p.shape[2],p.shape[3]]):p}var Oa=N({maxPool_:Kj});function Xj(r,e=[1,1,1],t,n,o,s="NDHWC"){let a=k(r,"x","maxPool3d"),i=a,l=!1;a.rank===4&&(l=!0,i=F(a,[1,a.shape[0],a.shape[1],a.shape[2],a.shape[3]])),E(i.rank===5,()=> ` Error in maxPool3d : x must be rank 5 but got rank $ { i . rank } . ` ),E(s==="NDHWC",()=> ` Error in maxPool3d : Only NDHWC is currently supported , but got dataFormat of $ { s } ` ),o!=null&&E(it(n),()=> ` Error in maxPool3d : pad must be an integer when using , dimRoundingMode $ { o } but got pad $ { n } . ` );let u={x:i},c={filterSize:e,strides:t,pad:n,dimRoundingMode:o,dataFormat:s},p=T.runKernel(bl,u,c);return l?F(p,[p.shape[1],p.shape[2],p.shape[3],p.shape[4]]):p}var Of=N({maxPool3d_:Xj});function Yj(r,e,
$ { o . shape } ` );if(s.rank!==1)throw new Error( ` Values should be Tensor1D but received shape $ { s . shape } ` );if(a.rank!==1)throw new Error( ` Dense shape should be Tensor1D but received shape $ { a . shape } ` );if(i.rank!==0)throw new Error( ` Default value should be a scalar but received shape $ { i . shape } ` );let l={indices:o,values:s,denseShape:a,defaultValue:i},u=T.runKernel(hp,l);return{outputIndices:u[0],outputValues:u[1],emptyRowIndicator:u[2],reverseIndexMap:u[3]}}var RT=N({sparseFillEmptyRows_: $ K});function RK(r,e,t){let n=k(r,"inputIndices","sparseReshape"),o=k(e,"inputShape","sparseReshape"),s=k(t,"newShape","sparseReshape");if(n.rank!==2)throw new Error( ` Input indices should be Tensor2D but received shape
$ { n . shape } ` );if(o.rank!==1)throw new Error( ` Input shape should be Tensor1D but received shape $ { o . shape } ` );if(s.rank!==1)throw new Error( ` New shape should be Tensor1D but received shape $ { s . shape } ` );let a={inputIndices:n,inputShape:o,newShape:s},i=T.runKernel(gp,a);return{outputIndices:i[0],outputShape:i[1]}}var FT=N({sparseReshape_:RK});function FK(r,e,t){let n=k(r,"data","sparseSegmentMean"),o=k(e,"indices","sparseSegmentMean"),s=k(t,"segmentIds","sparseSegmentMean");if(n.rank<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(o.rank!==1)throw new Error( ` Indices should be Tensor1D but received shape
$ { o . shape } ` );if(s.rank!==1)throw new Error( ` Segment ids should be Tensor1D but received shape
$ { s . shape } ` );let a={data:n,indices:o,segmentIds:s};return T.runKernel(xp,a)}var OT=N({sparseSegmentMean_:FK});function OK(r,e,t){let n=k(r,"data","sparseSegmentSum"),o=k(e,"indices","sparseSegmentSum"),s=k(t,"segmentIds","sparseSegmentSum");if(n.rank<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(o.rank!==1)throw new Error( ` Indices should be Tensor1D but received shape
$ { o . shape } ` );if(s.rank!==1)throw new Error( ` Segment ids should be Tensor1D but received shape
$ { s . shape } ` );let a={data:n,indices:o,segmentIds:s};return T.runKernel(yp,a)}var PT=N({sparseSegmentSum_:OK});function PK(r,e,t,n,o,s,a,i){let l=k(r,"data","stringNGrams","string");if(l.dtype!=="string")throw new Error("Data must be of datatype string");if(l.shape.length!==1)throw new Error( ` Data must be a vector , saw : $ { l . shape } ` );let u=k(e,"dataSplits","stringNGrams");if(u.dtype!=="int32")throw new Error("Data splits must be of datatype int32");let c={separator:t,nGramWidths:n,leftPad:o,rightPad:s,padWidth:a,preserveShortSequences:i},p={data:l,dataSplits:u},m=T.runKernel(wp,p,c);return{nGrams:m[0],nGramsSplits:m[1]}}var MT=N({stringNGrams_:PK});function MK(r,e,t=!0){let n=k(r,"input","stringSplit","string"),o=k(e,"delimiter","stringSplit","string");if(n.rank!==1)throw new Error( ` Input should be Tensor1D but received shape $ { n . shape } ` );if(o.rank!==0)throw new Error( ` Delimiter should be a scalar but received shape $ { o . shape } ` );let s={skipEmpty:t},a={input:n,delimiter:o},i=T.runKernel(_p,a,s);return{indices:i[0],values:i[1],shape:i[2]}}var LT=N({stringSplit_:MK});function LK(r,e){let t=k(r,"input","stringToHashBucketFast","string"),n={numBuckets:e};if(e<=0)throw new Error("Number of buckets must be at least 1");let o={input:t};return T.runKernel(kp,o,n)}var zT=N({stringToHashBucketFast_:LK});var SRe={fft:Ba,ifft:_i,rfft:Va,irfft:zu},DRe={hammingWindow:sT,hannWindow:lx,frame:ux,stft:iT},Cn={flipLeftRight:lT,grayscaleToRGB:uT,resizeNearestNeighbor:dx,resizeBilinear:fx,rotateWithOffset:cT,cropAndResize:aT,nonMaxSuppression:pT,nonMaxSuppressionAsync:dT,nonMaxSuppressionWithScore:hT,nonMaxSuppressionWithScoreAsync:gT,nonMaxSuppressionPadded:xT,nonMaxSuppressionPaddedAsync:yT,threshold:bT,transform:wT},BT={bandPart:_T,gramSchmidt:kT,qr:CT},oFe={absoluteDifference:IT,computeWeightedLoss:Vr,cosineDistance:ST,hingeLoss:NT,huberLoss:TT,logLoss:ET,meanSquaredError:AT,sigmoidCrossEntropy:DT,softmaxCrossEntropy: $ T},Kf={sparseFillEmptyRows:RT,sparseReshape:FT,sparseSegmentMean:OT,sparseSegmentSum:PT},hx={stringNGrams:MT,stringSplit:LT,stringToHashBucketFast:zT};var qr=class extends qg{minimize(e,t=!1,n){let{value:o,grads:s}=this.computeGradients(e,n);if(n!=null){let a=n.map(i=>({name:i.name,tensor:s[i.name]}));this.applyGradients(a)}else this.applyGradients(s);return De(s),t?o:(o.dispose(),null)}get iterations(){return this.iterations_==null&&(this.iterations_=0),this.iterations_}incrementIterations(){this.iterations_=this.iterations+1}computeGradients(e,t){return Zg(e,t)}dispose(){this.iterations_!=null&&De(this.iterations_)}async saveIterations(){return this.iterations_==null&&(this.iterations_=0),{name:"iter",tensor:pe(this.iterations_,"int32")}}async getWeights(){throw new Error("getWeights() is not implemented for this optimizer yet.")}async setWeights(e){throw new Error( ` setWeights ( ) is not implemented for this optimizer class $ { this . getClassName ( ) } ` )}async extractIterations(e){return this.iterations_=(await e[0].tensor.data())[0],e.slice(1)}};Object.defineProperty(qr,Symbol.hasInstance,{value:r=>r.minimize!=null&&r.computeGradients!=null&&r.applyGradients!=null});var Hu=class extends qr{constructor(e,t,n=null){super();this.learningRate=e,this.rho=t,this.epsilon=n,this.accumulatedGrads=[],this.accumulatedUpdates=[],n==null&&(this.epsilon=T.backend.epsilon())}applyGradients(e){(Array.isArray(e)?e.map(n=>n.name):Object.keys(e)).forEach((n,o)=>{let s=T.registeredVariables[n],a=!1;this.accumulatedGrads[o]==null&&(this.accumulatedGrads[o]={originalName: ` $ { n } / accum _grad ` ,variable:V(()=>Se(s).variable(a))}),this.accumulatedUpdates[o]==null&&(this.accumulatedUpdates[o]={originalName: ` $ { n } / accum _var ` ,variable:V(()=>Se(s).variable(a))});let i=Array.isArray(e)?e[o].tensor:e[n];if(i==null)return;let l=this.accumulatedGrads[o].variable,u=this.accumulatedUpdates[o].variable;V(()=>{let c=Z(O(l,this.rho),O(Ve(i),1-this.rho)),p=O(ce(bt(Z(u,this.epsilon)),bt(Z(l,this.epsilon))),i),m=Z(O(u,this.rho),O(Ve(p),1-this.rho));l.assign(c),u.assign(m);let f=Z(O(p,-this.learningRate),s);s.assign(f)})}),this.incrementIterations()}dispose(){this.accu
$ { s } ) . ` );if(t<n)throw new Error( ` batchDims ( $ { n } ) must be less than or equal to axis ( $ { t } ) . ` );for(let p=0;p<n;++p)if(r.shape[p]!==e.shape[p])throw new Error( ` x . shape [ $ { p } ] : $ { r . shape [ p ] } should be equal to indices . shape [ $ { p } ] : $ { e . shape [ p ] } . ` );let a=r.shape[t],i=[],l=1,u=1,c=1;for(let p=0;p<n;++p)i.push(r.shape[p]),l*=r.shape[p];for(let p=n;p<t;p++)i.push(r.shape[p]),u*=r.shape[p];for(let p=n;p<o;p++)i.push(e.shape[p]);for(let p=t+1;p<s;p++)i.push(r.shape[p]),c*=r.shape[p];return{batchSize:l,sliceSize:c,outerSize:u,dimSize:a,outputShape:i}}function w6(r){try{return r.map(e=>Tp(e))}catch(e){throw new Error( ` Failed to decode encoded string bytes into utf - 8 , error : $ { e } ` )}}function _6(r){return r.map(e=>Il(e))}var Gr={};qe(Gr,{nonMaxSuppressionV3Impl:()=>cx,nonMaxSuppressionV4Impl:()=>px,nonMaxSuppressionV5Impl:()=>mx,whereImpl:()=>nx});var xx={kernelName:ti,inputsToSave:["x"],gradFunc:(r,e)=>{let[t]=e;return{x:()=>O(r,Ls(Y(t,"float32"),-1))}}};var WT={kernelName:Mi,inputsToSave:["x"],gradFunc:(r,e)=>{let[t]=e;return{x:()=>{let n=Ve(Y(t,"float32")),o=bt(le(pe(1),n));return He(ce(r,o))}}}};var UT={kernelName:Li,inputsToSave:["x"],gradFunc:(r,e)=>{let[t]=e;return{x:()=>{let n=bt(le(Ve(Y(t,"float32")),1));return ce(r,n)}}}};var jT={kernelName:jn,inputsToSave:["a","b"],gradFunc:(r,e)=>{let[t,n]=e,o=We(t.shape,n.shape);return{a:()=>{let i=r,l=It(t.shape,o);return l.length>0&&(i=me(i,l)),F(i,t.shape)},b:()=>{let i=r,l=It(n.shape,o);return l.length>0&&(i=me(i,l)),F(i,n.shape)}}}};var HT={kernelName: $ o,saveAllInputs:!0,gradFunc:(r,e)=>{let t={};return e.forEach((n,o)=>{t[o]=()=>r.clone()}),t}};var qT={kernelName:Ro,inputsToSave:["x"],gradFunc:(r,e)=>{let[t]=e;return{x:()=>Se(t)}}};var KT={kernelName:ml,inputsToSave:["x"],gradFunc:(r,e)=>{let[t]=e;return{x:()=>Se(t)}}};var XT={kernelName:Vi,inputsToSave:["x"],gradFunc:(r,e)=>{let[t]=e;return{x:()=>ce(r,bt(le(pe(1),Ve(Y(t,"float32")))))}}};var YT={kernelName:Gi,inputsToSave:["x"],gradFunc:(r,e)=>{let[t]=e;return{x:()=>{let n=bt(Z(pe(1),Ve(Y(t,"float32"))));return ce(r,n)}}}};var ZT={kernelName:ji,inputsToSave:["a","b"],gradFunc:(r,e)=>{let[t,n]=e,o=We(t.shape,n.shape);return{a:()=>{let i=Z(Ve(t),Ve(n)),l=O(r,ce(n,i)),u=It(t.shape,o);return u.length>0&&(l=me(l,u)),F(l,t.shape)},b:()=>{let i=Z(Ve(t),Ve(n)),l=He(O(r,ce(t,i))),u=It(n.shape,o);return u.length>0&&(l=me(l,u)),F(l,n.shape)}}}};var JT={kernelName:Wi,inputsToSave:["x"],gradFunc:(r,e)=>{let[t]=e;return{x:()=>ce(r,Z(Ve(Y(t,"float32")),1))}}};var QT={kernelName:Ui,inputsToSave:["x"],gradFunc:(r,e)=>{let[t]=e;return{x:()=>ce(r,le(pe(1),Ve(Y(t,"float32"))))}}};function k6(r,e,t,n,o,s){let a=k(r,"dy","avgPool3dGrad"),i=k(e,"input","avgPool3dGrad"),l=a,u=i,c=!1;i.rank===4&&(c=!0,l=F(a,[1,a.shape[0],a.shape[1],a.shape[2],a.shape[3]]),u=F(i,[1,i.shape[0],i.shape[1],i.shape[2],i.shape[3]])),E(l.rank===5,()=> ` Error in avgPool3dGrad : dy must be rank 5 but got rank $ { l . rank } . ` ),E(u.rank===5,()=> ` Error in avgPool3dGrad : input must be rank 5 but got rank $ { u . rank } . ` ),s!=null&&E(it(o),()=> ` Error in avgPool3dGrad : pad must be an integer when using , dimRoundingMode $ { s } but got pad $ { o } . ` );let p={dy:l,input:u},m={filterSize:t,strides:n,pad:o,dimRoundingMode:s},f=T.runKernel(Uc,p,m);return c?F(f,[f.shape[1],f.shape[2],f.shape[3],f.shape[4]]):f}var eE=N({avgPool3dGrad_:k6});var tE={kernelName:fl,inputsToSave:["x"],gradFunc:(r,e,t)=>{let[n]=e,{filterSize:o,strides:s,pad:a,dimRoundingMode:i}=t;return{x:()=>eE(r,n,o,s,a,i)}}};function v6(r,e,t,n,o){let s=k(r,"dy","avgPoolGrad"),a=k(e,"input","avgPoolGrad");E(a.rank===s.rank,()=> ` Rank of input ( $ { a . rank } ) does not match rank of dy ( $ { s . rank } ) ` );let i=a,l=s,u=!1;a.rank===3&&(u=!0,i=F(a,[1,a.shape[0],a.shape[1],a.shape[2]]),l=F(s,[1,s.shape[0],s.shape[1],s.shape[2]])),E(l.rank===4,()=> ` Error in avgPoolGrad : dy must be rank 4 but got rank $ { l . rank } . ` ),E(i.rank===4,()=> ` Error in avgPoolGrad : input must be rank 4 but got rank $ { i . rank } . ` );let c={dy:l,input:i},p={filterSize:t,strides:n,pad:o},m=T.runKernel(Wc,c,p);return u?F(m,[m.shape[1],m.shape[2],m.shape[3]]):m}var rE=N({avgPoolGrad_:v6});var nE={
1. The $ { n } is defined in Python , in which case it needs to be ported to TensorFlow . js or your JavaScript code .
2. The custom $ { n } is defined in JavaScript , but is not registered properly with tf . serialization . registerClass ( ) . ` );return a}else{let s=r;if(s.className==null||s.config==null)throw new z( ` $ { n } : Improper config format : $ { JSON . stringify ( s ) } .
'className' and 'config' must set . ` );let a=s.className,i,l;if(a in t?[i,l]=t[a]:a in yo?[i,l]=yo.className:a in e&&([i,l]=e[a]),i==null)throw new z( ` Unknown $ { n } : $ { a } . This may be due to one of the following reasons :
1. The $ { n } is defined in Python , in which case it needs to be ported to TensorFlow . js or your JavaScript code .
2. The custom $ { n } is defined in JavaScript , but is not registered properly with tf . serialization . registerClass ( ) . ` );if(l!=null){let u={};for(let f of Object.keys(yo))u[f]=yo[f];for(let f of Object.keys(t))u[f]=t[f];let c=s.config;c.customObjects=u;let p=Object.assign({},yo);for(let f of Object.keys(t))yo[f]=t[f];Dk(s.config);let m=l(i,s.config,t,o);return yo=Object.assign({},p),m}else{let u=Object.assign({},yo);for(let p of Object.keys(t))yo[p]=t[p];let c=new i(s.config);return yo=Object.assign({},u),c}}}function A6(r,e){return r<e?-1:r>e?1:0}function Yf(r,e){return-1*A6(r,e)}function bo(r){if(r==null)return r;let e=[];for(let t of r)e.indexOf(t)===-1&&e.push(t);return e}function L2(r){if(r==null)throw new z( ` Invalid value in obj : $ { JSON . stringify ( r ) } ` );for(let e in r)if(r.hasOwnProperty(e))return!1;return!0}function Ci(r,e,t){if(t!=null&&r.indexOf(t)<0)throw new z( ` $ { t } is not a valid $ { e } . Valid values are $ { r } or null / undefined . ` )}function bx(r,e,t=0,n=1/0){return Kn(t>=0),Kn(n>=t),Array.isArray(r)&&r.length>=t&&r.length<=n&&r.every(o=>typeof o===e)}function Zt(r,e){Array.isArray(r)?(b.assert(r.length>0,()=> ` $ { e } is unexpectedly an empty array . ` ),r.forEach((t,n)=>Zt(t, ` element $ { n + 1 } of $ { e } ` ))):b.assert(Number.isInteger(r)&&r>0,()=> ` Expected $ { e } to be a positive integer , but got $ { z2 ( r ) } . ` )}function z2(r){return r===null?"null":Array.isArray(r)?"["+r.map(e=>z2(e)).join(",")+"]":typeof r=="string"? ` "${r}" ` : ` $ { r } ` }function B2(r,e,t){let n=t!=null?t():b.now(),o;return(...a)=>{let i=t!=null?t():b.now();return i-n<e||(n=i,o=r(...a)),o}}function wx(r){return r==="relu"?"relu":r==="linear"?"linear":r==="elu"?"elu":null}function $ k(r,e){return V(()=>bt(me(O(r,r),e,!0)))}var Hp=class extends ee.Serializable{getConfig(){return{}}},Zf=class extends Hp{constructor(e){super();this.defaultMaxValue=2,this.defaultAxis=0,this.maxValue=e.maxValue!=null?e.maxValue:this.defaultMaxValue,this.axis=e.axis!=null?e.axis:this.defaultAxis}apply(e){return V(()=>{let t= $ k(e,this.axis),n=gr(t,0,this.maxValue);return O(e,ce(n,Z(ir(),t)))})}getConfig(){return{maxValue:this.maxValue,axis:this.axis}}};Zf.className="MaxNorm";ee.registerClass(Zf);var Jf=class extends Hp{constructor(e){super();this.defaultAxis=0,this.axis=e.axis!=null?e.axis:this.defaultAxis}apply(e){return V(()=>ce(e,Z(ir(), $ k(e,this.axis))))}getConfig(){return{axis:this.axis}}};Jf.className="UnitNorm";ee.registerClass(Jf);var Qf=class extends Hp{apply(e){return Ir(e)}};Qf.className="NonNeg";ee.registerClass(Qf);var ed=class extends Hp{constructor(e){super();this.defaultMinValue=0,this.defaultMaxValue=1,this.defaultRate=1,this.defaultAxis=0,this.minValue=e.minValue!=null?e.minValue:this.defaultMinValue,this.maxValue=e.maxValue!=null?e.maxValue:this.defaultMaxValue,this.rate=e.rate!=null?e.rate:this.defaultRate,this.axis=e.axis!=null?e.axis:this.defaultAxis}apply(e){return V(()=>{let t= $ k(e,this.axis),n=Z(O(this.rate,gr(t,this.minValue,this.maxValue)),O(1-this.rate,t));return O(e,ce(n,Z(ir(),t)))})}getConfig(){return{minValue:this.minValue,maxValue:this.maxValue,rate:this.rate,axis:this.axis}}};ed.className="MinMaxNorm";ee.registerClass(ed);var V2={maxNorm:"MaxNorm",minMaxNorm:"MinMaxNorm",nonNeg:"NonNeg",unitNorm:"UnitNorm"};function Bt(r){return jp(r)}function G2(r,e={}){return vi(r,ee.SerializationMap.getMap().classNameMap,e,"constraint")}function Vt(r){if(r==null)return null;if(typeof r=="string"){let t={className:r in V2?V2[r]:r,config:{}};return G2(t)}else return r instanceof Hp?r:G2(r)}function D6(r){return new Zf(r)}function $ 6(r){return new Jf(r)}function R6(){return new Qf}function F6(r){return new ed(r)}var uA={};qe(uA,{constant:()=>G6,glorotNormal:()=>X6,glorotUniform:()=>K6,heNormal:()=>Y6,heUniform:()=>Z6,identity:()=>H6,leCunNormal:()=>J6,leCunUniform:()=>Q6,ones:()=>V6,orthogonal:()=>e5,randomNormal:()=>U6,randomUniform:()=>W6,truncatedNormal:()=>j6,varianceScaling:()=>q6,zeros:()=>B6});var U2=["channelsFirst","channelsLast"],j2=["nearest","bilinear"],H2=["valid","same","causal"],q2=["max","avg"],K2=["sum","mul","concat","ave"];var qp=new Map;function Ot(r){Ci(U2,"Da
because the value dtype is $ { t . dtype } , but TensorArray dtype is $ { this . dtype } . ` );if(this.size()===0&&(this.elementShape==null||this.elementShape.length===0)&&(this.elementShape=t.shape),zn(this.elementShape,t.shape, ` TensorArray $ { this . name } : Could not write to TensorArray index $ { e } . ` ),n.read)throw new Error( ` TensorArray $ { this . name } : Could not write to TensorArray index $ { e } , because it has already been read . ` );if(n.written)throw new Error( ` TensorArray $ { this . name } : Could not write to TensorArray index $ { e } , because it has already been written . ` );n.tensor=t,Ft(t),n.written=!0,this.tensors[e]=n}writeMany(e,t){if(e.length!==t.length)throw new Error( ` TensorArray $ { this . name } : could not write multiple tensors , because the index size : $ { e . length } is not the same as tensors size : $ { t . length } . ` );e.forEach((n,o)=>this.write(n,t[o]))}gather(e,t){if(!!t&&t!==this.dtype)throw new Error( ` TensorArray dtype is $ { this . dtype } but gather requested dtype $ { t } ` );if(e)e=e.slice(0,this.size());else{e=[];for(let o=0;o<this.size();o++)e.push(o)}if(e.length===0)return Dr([],[0].concat(this.elementShape));let n=this.readMany(e);return zn(this.elementShape,n[0].shape,"TensorArray shape mismatch: "),Xt(n,0)}concat(e){if(!!e&&e!==this.dtype)throw new Error( ` TensorArray dtype is $ { this . dtype } but concat requested dtype $ { e } ` );if(this.size()===0)return Dr([],[0].concat(this.elementShape));let t=[];for(let o=0;o<this.size();o++)t.push(o);let n=this.readMany(t);return zn(this.elementShape,n[0].shape, ` TensorArray shape mismatch : tensor array shape ( $ { this . elementShape } ) vs first tensor shape ( $ { n [ 0 ] . shape } ) ` ),tt(n,0)}scatter(e,t){if(t.dtype!==this.dtype)throw new Error( ` TensorArray dtype is $ { this . dtype } but tensor has dtype $ { t . dtype } ` );if(e.length!==t.shape[0])throw new Error( ` Expected len ( indices ) == tensor . shape [ 0 ] , but saw : $ { e . length } vs . $ { t . shape [ 0 ] } ` );let n=Math.max(...e);if(!this.dynamicSize&&n>=this.maxSize)throw new Error( ` Max index must be < array size ( $ { n } vs . $ { this . maxSize } ) ` );this.writeMany(e,yr(t,0))}split(e,t){if(t.dtype!==this.dtype)throw new Error( ` TensorArray dtype is $ { this . dtype } but tensor has dtype $ { t . dtype } ` );let n=0,o=e.map(l=>(n+=l,n));if(n!==t.shape[0])throw new Error( ` Expected sum of lengths to be equal to
tensor . shape [ 0 ] , but sum of lengths is
$ { n } , and tensor 's shape is: ${t.shape}`);if(!this.dynamicSize&&e.length!==this.maxSize)throw new Error(`TensorArray' s size is not equal to the size of lengths ( $ { this . maxSize } vs . $ { e . length } ) , and the TensorArray is not marked as dynamically resizeable ` );let s=n===0?0:t.size/n,a=[];V(()=>{t=F(t,[1,n,s]);for(let l=0;l<e.length;++l){let u=l===0?0:o[l-1],c=[0,u,0],p=[1,e[l],s];a[l]=F(Oe(t,c,p),this.elementShape)}return a});let i=[];for(let l=0;l<e.length;l++)i[l]=l;this.writeMany(i,a)}};var uc=class{constructor(e,t,n,o=-1){this.tensors=e,this.elementShape=t,this.elementDtype=n,e!=null&&e.forEach(s=>{if(n!==s.dtype)throw new Error( ` Invalid data types ; op elements $ { n } , but list elements $ { s . dtype } ` );zn(t,s.shape,"TensorList shape mismatch: "),Ft(s)}),this.idTensor=pe(0),this.maxNumElements=o,Ft(this.idTensor)}get id(){return this.idTensor.id}copy(){return new uc([...this.tensors],this.elementShape,this.elementDtype)}clearAndClose(e){this.tensors.forEach(t=>{(e==null||!e.has(t.id))&&t.dispose()}),this.tensors.length=0,this.idTensor.dispose()}size(){return this.tensors.length}stack(e,t,n=-1){if(t!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { t } , but list elements $ { this . elementDtype } ` );if(n!==-1&&this.tensors.length!==n)throw new Error( ` Operation expected a list with $ { n } elements but got a list with $ { this . tensors . length } elements . ` );zn(e,this.elementShape,"TensorList shape mismatch: ");let o=gm(this.elementShape,this.tensors,e);return V(()=>{let s=this.tensors.map(a=>F(a,o));return Xt(s,0)})}popBack(e,t){if(t!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { t } , but list elements $ { this . elementDtype } ` );if(this.size()===0)throw new Error("Trying to pop from an empty list.");let n=gm(this.elementShape,this.tensors,e),o=this.tensors.pop();return zn(o.shape,e,"TensorList shape mismatch: "),F(o,n)}pushBack(e){if(e.dtype!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { e . dtype } , but list elements $ { this . elementDtype } ` );if(zn(e.shape,this.elementShape,"TensorList shape mismatch: "),this.maxNumElements===this.size())throw new Error("Trying to push element into a full list.");Ft(e),this.tensors.push(e)}resize(e){if(e<0)throw new Error( ` TensorListResize expects size to be non - negative . Got : $ { e } ` );if(this.maxNumElements!==-1&&e>this.maxNumElements)throw new Error( ` TensorListResize input size $ { e } is greater maxNumElement $ { this . maxNumElements } . ` );this.tensors.length=e}getItem(e,t,n){if(n!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { n } , but list elements $ { this . elementDtype } ` );if(e<0||e>this.tensors.length)throw new Error( ` Trying to access element $ { e } in a list with $ { this . tensors . length } elements . ` );if(this.tensors[e]==null)throw new Error( ` element at index $ { e } is null . ` );zn(this.tensors[e].shape,t,"TensorList shape mismatch: ");let o=gm(this.elementShape,this.tensors,t);return F(this.tensors[e],o)}setItem(e,t){if(t.dtype!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { t . dtype } , but list elements $ { this . elementDtype } ` );if(e<0||this.maxNumElements!==-1&&e>=this.maxNumElements)throw new Error( ` Trying to set element $ { e } in a list with max $ { this . maxNumElements } elements . ` );zn(this.elementShape,t.shape,"TensorList shape mismatch: "),Ft(t),this.tensors[e]=t}gather(e,t,n){if(t!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { t } , but list elements $ { this . elementDtype } ` );zn(this.elementShape,n,"TensorList shape mismatch: "),e=e.slice(0,this.size());let o=gm(this.elementShape,this.tensors,n);return e.length===0?Dr([],[0].concat(o)):V(()=>{let s=e.map(a=>F(this.tensors[a],o));return Xt(s,0)})}concat(e,t){if(!!e&&e!==this.elementDtype)throw new Error( ` TensorList dtype is $ { this . elementDtype } but concat requested dtype $ { e } ` );zn(this.elementShape,t,"TensorList shape mismatch: ");let n=gm(this.elementShape,this.tensors,t);return this.size()===0?Dr([],[0].concat(n)):V(()=>{let o=this.tensors.map(s=>F(s,n));return tt(o,0)})}};function nD(r,e,t){let n=r.dtype;if(r.shape.length<1)throw new Error( ` Tens
tensor . shape [ 0 ] , but sum of lengths is
$ { n } , and tensor ' s shape is : $ { r . shape } ` );let s=r.shape.slice(1),a=iy(s,t),i=n===0?0:r.size/n,l=V(()=>{let c=[];r=F(r,[1,n,i]);for(let p=0;p<e.length;++p){let m=p===0?0:o[p-1],f=[0,m,0],d=[1,e[p],i];c[p]=F(Oe(r,f,d),a)}return r.dispose(),c}),u=new uc([],t,r.dtype,e.length);for(let c=0;c<l.length;c++)u.setItem(c,l[c]);return u}var aD=async(r,e,t)=>{switch(r.op){case"If":case"StatelessIf":{let n=v("thenBranch",r,e,t),o=v("elseBranch",r,e,t),s=v("cond",r,e,t),a=v("args",r,e,t);return(await s.data())[0]?t.functionMap[n].executeFunctionAsync(a,t.tensorArrayMap,t.tensorListMap):t.functionMap[o].executeFunctionAsync(a,t.tensorArrayMap,t.tensorListMap)}case"While":case"StatelessWhile":{let n=v("body",r,e,t),o=v("cond",r,e,t),s=v("args",r,e,t),a=await t.functionMap[o].executeFunctionAsync(s,t.tensorArrayMap,t.tensorListMap),i=s.map(c=>c.id),l=await a[0].data();a.forEach(c=>{!c.kept&&i.indexOf(c.id)===-1&&c.dispose()});let u=s;for(;l[0];){let c=u;u=await t.functionMap[n].executeFunctionAsync(u,t.tensorArrayMap,t.tensorListMap);let p=u.map(f=>f.id);c.forEach(f=>{!f.kept&&i.indexOf(f.id)===-1&&p.indexOf(f.id)===-1&&f.dispose()});let m=await t.functionMap[o].executeFunctionAsync(u,t.tensorArrayMap,t.tensorListMap);l=await m[0].data(),m.forEach(f=>{!f.kept&&i.indexOf(f.id)===-1&&p.indexOf(f.id)===-1&&f.dispose()})}return u}case"LoopCond":{let n=v("pred",r,e,t);return[Hs(n)]}case"Switch":{let n=v("pred",r,e,t),o=v("data",r,e,t);return o.kept||(o=Hs(o)),(await n.data())[0]?[void 0,o]:[o,void 0]}case"Merge":{let n=r.inputNames.find(o=>br(o,e,t)!==void 0);if(n){let o=br(n,e,t);return[Hs(o)]}return}case"Enter":{let n=v("frameName",r,e,t),o=v("tensor",r,e,t);return t.enterFrame(n),[Hs(o)]}case"Exit":{let n=v("tensor",r,e,t);return t.exitFrame(),[Hs(n)]}case"NextIteration":{let n=v("tensor",r,e,t);return t.nextIteration(),[Hs(n)]}case"TensorArrayV3":{let n=v("size",r,e,t),o=v("dtype",r,e,t),s=v("elementShape",r,e,t),a=v("dynamicSize",r,e,t),i=v("clearAfterRead",r,e,t),l=v("identicalElementShapes",r,e,t),u=v("name",r,e,t),c=new Yv(u,o,n,s,l,a,i);return t.addTensorArray(c),[c.idTensor,pe(1)]}case"TensorArrayWriteV3":{let n=v("tensorArrayId",r,e,t),o=v("index",r,e,t),s=v("tensor",r,e,t),a=t.getTensorArray(n.id);return a.write(o,s),[a.idTensor]}case"TensorArrayReadV3":{let n=v("tensorArrayId",r,e,t),o=v("index",r,e,t);return[t.getTensorArray(n.id).read(o)]}case"TensorArrayGatherV3":{let n=v("tensorArrayId",r,e,t),o=v("indices",r,e,t),s=v("dtype",r,e,t);return[t.getTensorArray(n.id).gather(o,s)]}case"TensorArrayScatterV3":{let n=v("tensorArrayId",r,e,t),o=v("indices",r,e,t),s=v("tensor",r,e,t),a=t.getTensorArray(n.id);return a.scatter(o,s),[a.idTensor]}case"TensorArrayConcatV3":{let n=v("tensorArrayId",r,e,t),o=t.getTensorArray(n.id),s=v("dtype",r,e,t);return[o.concat(s)]}case"TensorArraySplitV3":{let n=v("tensorArrayId",r,e,t),o=v("tensor",r,e,t),s=v("lengths",r,e,t),a=t.getTensorArray(n.id);return a.split(s,o),[a.idTensor]}case"TensorArraySizeV3":{let n=v("tensorArrayId",r,e,t),o=t.getTensorArray(n.id);return[pe(o.size(),"int32")]}case"TensorArrayCloseV3":{let n=v("tensorArrayId",r,e,t),o=t.getTensorArray(n.id);return o.clearAndClose(),[o.idTensor]}case"TensorListSetItem":{let n=v("tensorListId",r,e,t),o=v("index",r,e,t),s=v("tensor",r,e,t),a=t.getTensorList(n.id);return a.setItem(o,s),[a.idTensor]}case"TensorListGetItem":{let n=v("tensorListId",r,e,t),o=v("index",r,e,t),s=v("elementShape",r,e,t),a=v("elementDType",r,e,t);return[t.getTensorList(n.id).getItem(o,s,a)]}case"TensorListScatterV2":case"TensorListScatter":{let n=v("indices",r,e,t),o=v("tensor",r,e,t),s=v("elementShape",r,e,t),a=v("numElements",r,e,t),i=sD(o,n,s,a);return t.addTensorList(i),[i.idTensor]}case"TensorListReserve":case"EmptyTensorList":{let n=v("elementShape",r,e,t),o=v("elementDType",r,e,t),s;r.op==="TensorListReserve"?s="numElements":s="maxNumElements";let a=v(s,r,e,t),i=oD(n,o,a);return t.addTensorList(i),[i.idTensor]}case"TensorListGather":{let n=v("tensorListId",r,e,t),o=v("indices",r,e,t),s=v("elementShape",r,e,t),a=v("elementDType",r,e,t);return[t.getTensor
$ { e } ` );let o;return this.size===1/0||this.size==null?o=this.size:t?o=Math.ceil(this.size/e):o=Math.floor(this.size/e),Tn(async()=>(await n.iterator()).columnMajorBatch(e,t,_7),o)}concatenate(e){let t=this,n;return this.size===1/0||e.size===1/0?n=1/0:this.size!=null&&e.size!=null?n=this.size+e.size:n=null,Tn(async()=>(await t.iterator()).concatenate(await e.iterator()),n)}filter(e){let t=this,n;return this.size===1/0?n=1/0:n=null,Tn(async()=>(await t.iterator()).filter(o=>V(()=>e(o))),n)}async forEachAsync(e){return(await this.iterator()).forEachAsync(e)}map(e){let t=this;return Tn(async()=>(await t.iterator()).map(n=>V(()=>e(n))),this.size)}mapAsync(e){let t=this;return Tn(async()=>(await t.iterator()).mapAsync(e),this.size)}prefetch(e){if(e==null)throw new RangeError(" ` Dataset . prefetch ( ) ` requires bufferSize to be specified.");let t=this;return Tn(async()=>(await t.iterator()).prefetch(e),this.size)}repeat(e){let t=this,n;return this.size!=null&&e>0?n=this.size*e:e===0?n=0:this.size!=null&&(e===void 0||e<0)?n=1/0:n=null,Tn(async()=>{let o=wh(async()=>({value:await t.iterator(),done:!1}));return KD(o.take(e))},n)}skip(e){let t=this,n;return this.size!=null&&e>=0&&this.size>=e?n=this.size-e:this.size!=null&&(this.size<e||e===void 0||e<0)?n=0:n=null,Tn(async()=>(await t.iterator()).skip(e),n)}shuffle(e,t,n=!0){if(e==null||e<0)throw this.size==null?new RangeError(" ` Dataset . shuffle ( ) ` requires bufferSize to be specified."):new RangeError( ` \ ` Dataset.shuffle() \` requires bufferSize to be specified. If your data fits in main memory (for regular JS objects), and/or GPU memory (for \` tf.Tensor \` s), consider setting bufferSize to the dataset size ( ${ this . size } elements) ` ) ; let o = this , s = l$ . alea ( t || b . now ( ) . toString ( ) ) ; return Tn ( async ( ) => { let a = s . int32 ( ) ; return n && ( a += s . int32 ( ) ) , ( await o . iterator ( ) ) . shuffle ( e , a . toString ( ) ) } , this . size ) } take ( e ) { let t = this , n ; return this . size != null && this . size > e ? n = e : this . size != null && this . size <= e ? n = this . size : n = null , Tn ( async ( ) => ( await t . iterator ( ) ) . take ( e ) , n ) } async toArray ( ) { if ( this . size === 1 / 0 ) throw new Error ( "Can not convert infinite data stream to array." ) ; return ( await this . iterator ( ) ) . toArray ( ) } async toArrayForTest ( ) { if ( this . size === 1 / 0 ) throw new Error ( "Can not convert infinite data stream to array." ) ; return ( await this . iterator ( ) ) . toArrayForTest ( ) } } ; Ti . MAX _BUFFER _SIZE = 1e4 ; function Tn ( r , e = null ) { return new class extends Ti { constructor ( ) { super ( ... arguments ) ; this . size = e } async iterator ( ) { return r ( ) } } } function u$ ( r ) { return Tn ( async ( ) => m0 ( r ) , r . length ) } function c$ ( r ) { if ( ! Ul ( r ) ) throw new Error ( "The argument to zip() must be an object or array." ) ; let e ; if ( Array . isArray ( r ) ) for ( let t = 0 ; t < r . length ; t ++ ) e = e == null ? r [ t ] . size : Math . min ( e , r [ t ] . size ) ; else if ( r instanceof Object ) for ( let t in r ) e = e == null ? r [ t ] . size : Math . min ( e , r [ t ] . size ) ; return Tn ( async ( ) => { let t = await py ( r , n => { if ( n instanceof Ti ) return { value : n . iterator ( ) , recurse : ! 1 } ; if ( Ul ( n ) ) return { value : null , recurse : ! 0 } ; throw new Error ( "Leaves of the structure passed to zip() must be Datasets, not primitives." ) } ) ; return XD ( t , Xa . SHORTEST ) } , e ) } function _7 ( r ) { if ( r === null ) return null ; let e = r [ 0 ] ; return jD ( e ) ? { value : k7 ( r ) , recurse : ! 1 } : { value : null , recurse : ! 0 } } function k7 ( r ) { if ( r . length === 0 ) throw new Error ( "Can't make a batch of zero elements." ) ; return r [ 0 ] instanceof Le ? Xt ( r ) : Dr ( r ) } var _h = class extends Ti { constructor ( e ) { super ( ) ; this . input = e } async iterator ( ) { return ( await this . input . iterator ( ) ) . decodeUTF8 ( ) . split ( `
` ).map(o=>(o.endsWith(" \r ")&&(o=o.slice(0,-1)),o))}};var my='"',kh=Symbol("out"),p $ =Symbol("field"),fy=Symbol("quote"),g0=Symbol("quoteafterquote"),m $ =Symbol("quoteinquote"),vh=class extends Ti{constructor(e,t){super();this.input=e,this.hasHeader=!0,this.fullColumnNames=null,this.columnNamesValidated=!1,this.columnConfigs=null,this.configuredColumnsOnly=!1,this.delimiter=",",this.delimWhitespace=!1,this.base=new _h(e),t||(t={}),this.hasHeader=t.hasHeader!==!1,this.fullColumnNames=t.columnNames,this.columnConfigs=t.columnConfigs,this.configuredColumnsOnly=t.configuredColumnsOnly,t.delimWhitespace?(b.assert(t.delimiter==null,()=>"Delimiter should not be provided when delimWhitespace is true."),this.delimWhitespace=!0,this.delimiter=" "):this.delimiter=t.delimiter?t.delimiter:","}async columnNames(){return this.columnNamesValidated||await this.setColumnNames(),this.configuredColumnsOnly?Object.keys(this.columnConfigs):this.fullColumnNames}async setColumnNames(){let e=await this.maybeReadHeaderLine();if(!this.fullColumnNames&&!e)throw new Error("Column names must be provided if there is no header line.");this.fullColumnNames&&e&&b.assert(e.length===this.fullColumnNames.length,()=>"The length of provided columnNames ("+this.fullColumnNames.length.toString()+") does not match the length of the header line read from file ("+e.length.toString()+")."),this.fullColumnNames||(this.fullColumnNames=e);let t=this.fullColumnNames.reduce((o,s)=>(o[s]=o[s]+1||1,o),{}),n=Object.keys(t).filter(o=>t[o]>1);if(b.assert(n.length===0,()=>"Duplicate column names found: "+n.toString()),this.columnConfigs){for(let o of Object.keys(this.columnConfigs))if(this.fullColumnNames.indexOf(o)===-1)throw new Error('The key "'+o+'" provided in columnConfigs does not match any of the column names ('+this.fullColumnNames.toString()+").")}this.columnNamesValidated=!0}async maybeReadHeaderLine(){if(this.hasHeader){let t=await(await this.base.iterator()).next();if(t.done)throw new Error("No data was found for CSV parsing.");let n=t.value;return this.parseRow(n,!1)}else return null}async iterator(){this.columnNamesValidated||await this.setColumnNames();let e=await this.base.iterator();return this.hasHeader&&(e=e.skip(1)),e.map(t=>this.makeDataElement(t))}makeDataElement(e){let t=this.parseRow(e),n={},o={};for(let s=0;s<this.fullColumnNames.length;s++){let a=this.fullColumnNames[s],i=this.columnConfigs?this.columnConfigs[a]:null;if(!(this.configuredColumnsOnly&&!i)){let l=t[s],u=null;if(l==="")if(i&&i.default!==void 0)u=i.default;else{if(i&&(i.required||i.isLabel))throw new Error( ` Required column $ { a } is empty in this line : $ { e } ` );u=void 0}else{let c=Number(l);if(isNaN(c))i&&i.dtype==="bool"?u=this.getBoolean(l):u=l;else if(!i||!i.dtype)u=c;else switch(i.dtype){case"float32":u=c;break;case"int32":u=Math.floor(c);break;case"bool":u=this.getBoolean(l);break;default:u=c}}i&&i.isLabel?o[a]=u:n[a]=u}}return Object.keys(o).length===0?n:{xs:n,ys:o}}getBoolean(e){return e==="1"||e.toLowerCase()==="true"?1:0}parseRow(e,t=!0){let n=[],o=0,s=e.length,a=kh;for(let i=0;i<s;i++)switch(a){case kh:switch(e.charAt(i)){case my:o=i+1,a=fy;break;case this.delimiter:if(o=i+1,this.delimiter===" "&&this.delimWhitespace)break;n.push(""),a=kh;break;default:a=p $ ,o=i;break}break;case p $ :switch(e.charAt(i)){case this.delimiter:n.push(e.substring(o,i)),a=kh,o=i+1;break;default:}break;case fy:switch(e.charAt(i)){case my:a=g0;break;default:}break;case g0:switch(e.charAt(i)){case this.delimiter:n.push(e.substring(o,i-1)),a=kh,o=i+1;break;case my:a=fy;break;default:a=m $ ;break}break;case m $ :switch(e.charAt(i)){case my:a=fy;break;default:}break;default:}if(a===g0?n.push(e.substring(o,s-1)):n.push(e.substring(o)),t&&n.length!==this.fullColumnNames.length)throw new Error( ` Invalid row in csv file . Should have $ { this . fullColumnNames . length } elements in a row , but got $ { n } ` );return n}};var Ch=class extends tr{constructor(e){super();this.microphoneConfig=e,this.isClosed=!1,this.fftSize=e.fftSize||1024;let t=Math.log2(this.fftSize);if(this.fftSize<0||t<4||t>14||!Number.isInteger(t))throw new Error( ` Inval
=== === === === === === === === === =
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.
=== === === === === === === === === = ` ));let o={id:this.nextDataId()};return this.data.set(o,{values:e,dtype:n,refCount:1}),o}makeTensorInfo(e,t,n){let o;if(t==="string"&&n!=null&&n.length>0&&b.isString(n[0])){let s=n.map(a=>b.encodeString(a));o=this.write(s,e,t)}else o=this.write(n,e,t);return{dataId:o,shape:e,dtype:t}}refCount(e){return this.data.has(e)?this.data.get(e).refCount:0}incRef(e){let t=this.data.get(e);t.refCount++}decRef(e){if(this.data.has(e)){let t=this.data.get(e);t.refCount--}}move(e,t,n,o,s){this.data.set(e,{values:t,dtype:o,refCount:s})}numDataIds(){return this.data.numDataIds()}async read(e){return this.readSync(e)}readSync(e){let{dtype:t,complexTensorInfos:n}=this.data.get(e);if(t==="complex64"){let o=this.readSync(n.real.dataId),s=this.readSync(n.imag.dataId);return I.mergeRealAndImagArrays(o,s)}return this.data.get(e).values}bufferSync(e){let t=this.readSync(e.dataId),n=t;if(e.dtype==="string")try{n=t.map(o=>b.decodeString(o))}catch(o){throw new Error("Failed to decode encoded string bytes into utf-8")}return Ie(e.shape,e.dtype,n)}makeOutput(e,t,n){let o=this.write(e,t,n);return Es().makeTensorFromDataId(o,t,n,this)}disposeData(e,t=!1){if(this.data.has(e)){if(this.data.get(e).refCount--,!t&&this.data.get(e).refCount>0)return!1;let{complexTensorInfos:n}=this.data.get(e);n!=null&&(this.disposeData(n.real.dataId,!0),this.disposeData(n.imag.dataId,!0)),this.data.delete(e)}return!0}disposeIntermediateTensorInfo(e){this.disposeData(e.dataId)}async time(e){let t=b.now();return e(),{kernelMs:b.now()-t}}memory(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}}where(e){te([e],"where");let t=this.readSync(e.dataId);return C7(e.shape,t)}dispose(){}floatPrecision(){return 32}epsilon(){return super.epsilon()}};pc.nextDataId=0;var Ay={};qe(Ay,{addImpl:()=>w0,bincountImpl:()=>km,bincountReduceImpl:()=>gy,ceilImpl:()=>_0,concatImpl:()=>mc,equalImpl:()=>k0,expImpl:()=>C0,expm1Impl:()=>S0,floorImpl:()=>N0,gatherNdImpl:()=>xy,gatherV2Impl:()=>yy,greaterEqualImpl:()=>E0,greaterImpl:()=>T0,lessEqualImpl:()=>D0,lessImpl:()=>A0,linSpaceImpl:()=>by,logImpl:()=> $ 0,maxImpl:()=>wy,maximumImpl:()=>R0,minimumImpl:()=>F0,multiplyImpl:()=>Ah,negImpl:()=>O0,notEqualImpl:()=>P0,prodImpl:()=>M0,rangeImpl:()=>dc,rsqrtImpl:()=>L0,sigmoidImpl:()=>K $ ,simpleAbsImpl:()=>b0,sliceImpl:()=>hc,sparseFillEmptyRowsImpl:()=>_y,sparseReshapeImpl:()=>ky,sparseSegmentReductionImpl:()=>Cm,sqrtImpl:()=>Z $ ,squaredDifferenceImpl:()=>B0,stridedSliceImpl:()=>vy,stringNGramsImpl:()=>Cy,stringSplitImpl:()=>Iy,stringToHashBucketFastImpl:()=>Sy,subImpl:()=>V0,tileImpl:()=>Ny,topKImpl:()=>Ty,transposeImpl:()=>vm,uniqueImpl:()=>Ey});function b0(r){let e=new Float32Array(r.length);for(let t=0;t<r.length;++t)e[t]=Math.abs(r[t]);return e}var I7=r=>{let{x:e}=r.inputs,t=r.backend;te(e,"abs");let n=new Float32Array(b.sizeFromShape(e.shape)),o=t.data.get(e.dataId).values;return n=b0(o),t.makeOutput(n,e.shape,e.dtype)},C $ ={kernelName:ti,backendName:"cpu",kernelFunc:I7};function Ze(r){return(e,t,n,o,s)=>{let a=I.assertAndGetBroadcastShape(e,t),i=a.length,l=b.computeStrides(a),u=b.sizeFromShape(a),c=b.getTypedArrayFromDType(s,u),p=e.length,m=t.length,f=b.computeStrides(e),d=b.computeStrides(t),h=I.getBroadcastDims(e,a),g=I.getBroadcastDims(t,a);if(h.length+g.length===0)for(let x=0;x<c.length;++x)c[x]=r(n[x%n.length],o[x%o.length]);else for(let x=0;x<c.length;++x){let y=b.indexToLoc(x,i,l),w=y.slice(-p);h.forEach(D=>w[D]=0);let _=b.locToIndex(w,p,f),C=y.slice(-m);g.forEach(D=>C[D]=0);let A=b.locToIndex(C,m,d);c[x]=r(n[_],o[A])}return[c,a]}}function wr(r){let{inputs:e,backend:t}=r,{real:n,imag:o}=e,s=t.data.get(n.dataId).values,a=t.data.get(o.dataId).values,i=t.makeTensorInfo(n.shape,"complex64"),l=t.data.get(i.dataId);return l.complexTensorInfos={real:t.makeTensorInfo(n.shape,"float32",s),imag:t.makeTensorInfo(o.shape,"float32",a)},i}var I $ ={kernelName:qc,backendName:"cpu",kernelFunc:wr};function wm(r,e,t="float32"){if(t==="complex64"){let o=wm(r,e,"float32"),s=wm(r,e,"float32")
indices . shape [ 0 ] = $ { i } ` );let g=b.getArrayFromDType(t,0),x=b.getArrayFromDType(o,0);return[g,[0,p],x,u,c]}let m=!0,f=0,d=new Array(l).fill(0);for(let g=0;g<i;++g){let x=r[g*p];if(x<0)throw new Error( ` indices ( $ { g } , 0 ) is invalid : $ { x } < 0 ` );if(x>=l)throw new Error( ` indices ( $ { g } , 0 ) is invalid : $ { x } >= $ { l } ` );++d[x],m=m&&x>=f,f=x}let h=!0;for(let g=0;g<l;++g){let x=d[g]===0;u[g]=x,h=h&&!x,d[g]=Math.max(d[g],1),g>0&&(d[g]+=d[g-1])}if(h&&m){let g=r,x=n;for(let y=0;y<i;++y)c[y]=y;return[g,[i,p],x,u,c]}else{let g=d[l-1],x=b.getArrayFromDType(t,g*p),y=b.getArrayFromDType(o,g),w=new Array(l).fill(0);for(let _=0;_<i;++_){let C=r[_*p],A=w[C],D=(C===0?0:d[C-1])+A;w[C]++;for(let R=0;R<p;++R)x[D*p+R]=r[_*p+R];y[D]=n[_],c[_]=D}for(let _=0;_<l;++_)if(w[_]===0){let A=_===0?0:d[_-1];x[A*p+0]=_;for(let D=1;D<p;++D)x[A*p+D]=0;y[A]=a}return[x,[g,p],y,u,c]}}function ky(r,e,t,n,o){let s=b.sizeFromShape(n),a=e[0],i=o.length,l=[],u=1,c=-1;for(let g=0;g<i;++g){let x=o[g];if(x===-1){if(c!==-1)throw new Error( ` only one output dimension may be - 1 , not both $ { c } and $ { g } ` );c=g,l.push(1)}else{if(x<0)throw new Error( ` size $ { g } must be non - negative , not $ { x } ` );u*=x,l.push(x)}}if(c!==-1){if(u<=0)throw new Error("reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero");let g=Math.trunc(s/u);if(u*g!==s)throw new Error( ` Input to reshape is a SparseTensor with $ { s }
dense values , but the requested shape requires a multiple of $ { u } . inputShape = $ { n } outputShape = $ { l } ` );l[c]=g}let p=b.sizeFromShape(l);if(p!==s)throw new Error( ` Input to reshape is a tensor with $ { s } dense values , but the requested shape has $ { p } . inputShape = $ { n } outputShape = $ { l } ` );let m=n.length,f=[];if(m>0){f[m-1]=1;for(let g=m-2;g>=0;--g)f[g]=f[g+1]*n[g+1]}let d=[];if(i>0){d[i-1]=1;for(let g=i-2;g>=0;--g)d[g]=d[g+1]*l[g+1]}let h=b.getArrayFromDType(t,a*i);for(let g=0;g<a;++g){let x=0;for(let y=0;y<m;++y)x+=r[g*m+y]*f[y];for(let y=0;y<i;++y)h[g*i+y]=Math.trunc(x/d[y]),x%=d[y]}return[h,[a,i],l]}function Cm(r,e,t,n,o,s=!1,a=0){let i=n.length;if(i!==o.length)throw new Error("segmentIds and indices should have same size.");let l=[e[0],r.length/e[0]],u=l[1],p=i>0?o[i-1]+1:0;if(p<0)throw new Error("segment ids must be >= 0");let m=e.slice();m[0]=p;let f=m.reduce((w,_)=>w*_,1),d=b.getArrayFromDType(t,f);if(i===0)return p>0&&d.fill(a),[d,m];if(p<=0)throw new Error("segment ids must be >= 0");let h=0,g=1,x=0,y=o[h];for(;;){let w=0;if(g<i){if(w=o[g],y===w){++g;continue}if(y>=w)throw new Error("segment ids are not increasing")}if(y<0||y>=p)throw new Error( ` Segment id $ { y } out of range [ 0 , $ { p } ) , possibly because segmentIds input is not sorted . ` );y>x&&d.fill(a,x*u,y*u);for(let _=h;_<g;++_){let C=n[_];if(C<0||C>=l[0])throw new Error( ` Bad : indices [ $ { _ } ] == $ { n [ _ ] } out of range [ 0 , $ { l [ 0 ] } ) ` );for(let A=0;A<u;A++)d[y*u+A]+=r[C*u+A]}if(s)for(let _=0;_<u;_++)d[y*u+_]/=g-h;if(h=g,++g,x=y+1,y=w,g>i)break}return x<p&&d.fill(a,x*u,p*u),[d,m]}var Z $ =dn(r=>Math.sqrt(r)),G7= $ e(ys,r=>Math.sqrt(r)),J $ ={kernelName:ys,backendName:"cpu",kernelFunc:G7};var B0=Ze((r,e)=>{let t=r-e;return t*t}),W7=rt(_s,B0),Q $ ={kernelName:_s,backendName:"cpu",kernelFunc:W7};function vy(r,e,t,n){let o=Ie(r,e.dtype);for(let s=0;s<o.size;s++){let a=o.indexToLoc(s),i=new Array(a.length);for(let l=0;l<i.length;l++)i[l]=a[l]*t[l]+n[l];o.set(e.get(...i),...a)}return o}var eR=class{constructor(e,t,n,o,s,a){this.separator=b.encodeString(e),this.nGramWidths=t,this.leftPad=b.encodeString(n),this.rightPad=b.encodeString(o),this.padWidth=s,this.preserveShort=a}getPadWidth(e){return Math.min(this.padWidth<0?e-1:this.padWidth,e-1)}getNumNGrams(e,t){let n=this.getPadWidth(t);return Math.max(0,e+2*n-t+1)}createNGrams(e,t,n,o,s,a){for(let i=0;i<s;++i){let l=this.getPadWidth(a),u=Math.max(0,l-i),c=Math.max(0,l-(s-(i+1))),p=a-(u+c),m=t+(u>0?0:i-l),f=0;f+=u*this.leftPad.length;for(let y=0;y<p;++y)f+=e[m+y].length;f+=c*this.rightPad.length,f+=(u+c+p-1)*this.separator.length,n[o+i]=new Uint8Array(f);let h=n[o+i],g=0,x=y=>y.forEach(w=>h[g++]=w);for(let y=0;y<u;++y)x(this.leftPad),x(this.separator);for(let y=0;y<p-1;++y)x(e[m+y]),x(this.separator);if(p>0){x(e[m+p-1]);for(let y=0;y<c;++y)x(this.separator),x(this.rightPad)}else{for(let y=0;y<c-1;++y)x(this.rightPad),x(this.separator);x(this.rightPad)}}}compute(e,t){let n=e.length,o=t.length;if(o>0){let l=t[0];if(l!==0)throw new Error( ` First split value must be 0 , got $ { l } ` );for(let u=1;u<o;++u){let c=t[u]>=l;if(c=c&&t[u]<=n,!c)throw new Error( ` Invalid split value $ { t [ u ] } , must be in [ $ { l } , $ { n } ] ` );l=t[u]}if(l!==n)throw new Error( ` Last split value must be data size . Expected $ { n } , got $ { l } ` )}let s=o-1,a=b.getArrayFromDType("int32",o);if(n===0||o===0){let l=new Array(n);for(let u=0;u<=s;++u)a[u]=0;return[l,a]}a[0]=0;for(let l=1;l<=s;++l){let u=t[l]-t[l-1],c=0;this.nGramWidths.forEach(p=>{c+=this.getNumNGrams(u,p)}),this.preserveShort&&u>0&&c===0&&(c=1),a[l]=a[l-1]+c}let i=new Array(a[s]);for(let l=0;l<s;++l){let u=t[l],c=a[l];if(this.nGramWidths.forEach(p=>{let m=t[l+1]-t[l],f=this.getNumNGrams(m,p);this.createNGrams(e,u,i,c,f,p),c+=f}),this.preserveShort&&c===a[l]){let p=t[l+1]-t[l];if(p===0)continue;let m=p+2*this.padWidth,f=1;this.createNGrams(e,u,i,c,f,m)}}return[i,a]}};function Cy(r,e,t,n,o,s,a,i){return new eR(t,n,o,s,a,i).compute(r,e)}function U7(r,e,t,n){if(!r.length)return;if(e.length===0){for(let s=0;s<r.length;++s)n.push(r.subarray(s,s+1));return}if(e.length===1){let s=e[0],a=r.indexOf(s);for(;a!==-1;){let i=r.subarray(0,a);
$ { s . shape } ` );if(n.shape.length!==2)throw new Error( ` Indices must be a matrix , saw :
$ { n . shape } ` );if(o.shape.length!==1)throw new Error( ` Values must be a vector , saw :
$ { o . shape } ` );if(a.shape.length!==0)throw new Error( ` Default value must be a scalar , saw :
$ { a . shape } ` );let i=t.data.get(n.dataId).values,l=t.data.get(o.dataId).values,u=t.data.get(s.dataId).values,c=t.data.get(a.dataId).values[0],[p,m,f,d,h]=_y(i,n.shape,n.dtype,l,o.dtype,u,c);return[t.makeTensorInfo(m,n.dtype,p),t.makeTensorInfo([m[0]],o.dtype,f),t.makeTensorInfo([d.length],"bool",new Uint8Array(d.map(g=>Number(g)))),t.makeTensorInfo([h.length],n.dtype,new Int32Array(h))]}var mO={kernelName:hp,backendName:"cpu",kernelFunc:Z9};function J9(r){let{inputs:e,backend:t}=r,{inputIndices:n,inputShape:o,newShape:s}=e;if(n.shape.length!==2)throw new Error( ` Input indices should be a matrix but received shape
$ { n . shape } ` );if(o.shape.length!==1)throw new Error( ` Input shape should be a vector but received shape
$ { o . shape } ` );if(s.shape.length!==1)throw new Error( ` Target shape should be a vector but received shape $ { s . shape } ` );let a=Array.from(t.data.get(o.dataId).values),i=t.data.get(n.dataId).values,l=Array.from(t.data.get(s.dataId).values),[u,c,p]=ky(i,n.shape,n.dtype,a,l);return[t.makeTensorInfo(c,n.dtype,u),t.makeTensorInfo([p.length],s.dtype,new Int32Array(p))]}var fO={kernelName:gp,backendName:"cpu",kernelFunc:J9};function Q9(r){let{inputs:e,backend:t}=r,{data:n,indices:o,segmentIds:s}=e;if(n.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(o.shape.length!==1)throw new Error( ` Indices should be a vector but received shape
$ { o . shape } ` );if(s.shape.length!==1)throw new Error( ` Segment ids should be a vector but received shape
$ { s . shape } ` );let a=t.data.get(n.dataId).values,i=t.data.get(o.dataId).values,l=t.data.get(s.dataId).values,[u,c]=Cm(a,n.shape,n.dtype,i,l,!0);return t.makeTensorInfo(c,n.dtype,u)}var dO={kernelName:xp,backendName:"cpu",kernelFunc:Q9};function eZ(r){let{inputs:e,backend:t}=r,{data:n,indices:o,segmentIds:s}=e;if(n.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(o.shape.length!==1)throw new Error( ` Indices should be a vector but received shape
$ { o . shape } ` );if(s.shape.length!==1)throw new Error( ` Segment ids should be a vector but received shape
$ { s . shape } ` );let a=t.data.get(n.dataId).values,i=t.data.get(o.dataId).values,l=t.data.get(s.dataId).values,[u,c]=Cm(a,n.shape,n.dtype,i,l);return t.makeTensorInfo(c,n.dtype,u)}var hO={kernelName:yp,backendName:"cpu",kernelFunc:eZ};function tZ(r){let{inputs:e,backend:t,attrs:n}=r,{sparseIndices:o,sparseValues:s,defaultValue:a}=e,{outputShape:i}=n,{sliceRank:l,numUpdates:u,sliceSize:c,strides:p,outputSize:m}=I.calculateShapes(s,o,i),f=!1,d=t.bufferSync(o),h=t.bufferSync(s),g=t.data.get(a.dataId).values[0],x=Oy(d,h,i,m,c,u,l,p,g,f);return t.makeTensorInfo(i,x.dtype,x.values)}var gO={kernelName:bp,backendName:"cpu",kernelFunc:tZ};function rZ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{numOrSizeSplits:s,axis:a}=n,i=b.parseAxisParam(a,o.shape)[0],l=I.prepareSplitSize(o,s,i),u=new Array(o.shape.length).fill(0),c=o.shape.slice();return l.map(p=>{let m=[...c];m[i]=p;let f=So({inputs:{x:o},backend:t,attrs:{begin:u,size:m}});return u[i]+=p,f})}var xO={kernelName:fi,backendName:"cpu",kernelFunc:rZ};var yO={kernelName:kl,backendName:"cpu",kernelFunc:({inputs:r,backend:e})=>{let{x:t}=r,n=e;te(t,"square");let o=n.data.get(t.dataId).values,s=new Float32Array(o.length);for(let i=0;i<o.length;++i){let l=o[i];s[i]=l*l}return{dataId:n.write(s,t.shape,t.dtype),shape:t.shape,dtype:t.dtype}}};var nZ= $ e(no,(r,e)=>{let t=e;return isNaN(r)?NaN:r>0?1:t.alpha}),bO={kernelName:no,backendName:"cpu",kernelFunc:nZ};function oZ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{begin:s,end:a,strides:i,beginMask:l,endMask:u,ellipsisMask:c,newAxisMask:p,shrinkAxisMask:m}=n;te(o,"stridedSlice");let{nonStrided:f, $ begin:d, $ strides:h,size:g,newShape:x,outShape:y}=pr.sliceInfo(o.shape,s,a,i,l,u,c,p,m),w=Je({inputs:{x:o},backend:t,attrs:{shape:x}}),_;if(f){let A=So({inputs:{x:w},backend:t,attrs:{begin:d,size:g}});_=Je({inputs:{x:A},backend:t,attrs:{shape:y}}),t.disposeIntermediateTensorInfo(A)}else if(y.some(A=>A===0))_=t.makeTensorInfo(y,o.dtype,[]);else{let A=t.bufferSync(w),D=vy(y,A,h,d);_=t.makeTensorInfo(D.shape,D.dtype,D.values)}let C=Je({inputs:{x:_},backend:t,attrs:{shape:y}});return t.disposeIntermediateTensorInfo(w),t.disposeIntermediateTensorInfo(_),C}var wO={kernelName:ba,backendName:"cpu",kernelFunc:oZ};function sZ(r){let{inputs:e,backend:t,attrs:n}=r,{separator:o,nGramWidths:s,leftPad:a,rightPad:i,padWidth:l,preserveShortSequences:u}=n,{data:c,dataSplits:p}=e,m=t.data.get(c.dataId).values,f=t.data.get(p.dataId).values,[d,h]=Cy(m,f,o,s,a,i,l,u);return[t.makeTensorInfo([d.length],"string",d),t.makeTensorInfo(p.shape,"int32",h)]}var _O={kernelName:wp,backendName:"cpu",kernelFunc:sZ};function iZ(r){let{inputs:e,backend:t,attrs:n}=r,{skipEmpty:o}=n,{input:s,delimiter:a}=e;if(s.dtype!=="string")throw new Error("Input must be of datatype string");if(s.shape.length!==1)throw new Error( ` Input must be a vector , got shape : $ { s . shape } ` );if(a.shape.length!==0)throw new Error( ` Delimiter must be a scalar , got shape : $ { a . shape } ` );let i=t.data.get(s.dataId).values,l=t.data.get(a.dataId).values[0],[u,c,p]=Iy(i,l,o),m=c.length;return[t.makeTensorInfo([m,2],"int32",u),t.makeTensorInfo([m],"string",c),t.makeTensorInfo([2],"int32",new Int32Array(p))]}var kO={kernelName:_p,backendName:"cpu",kernelFunc:iZ};function aZ(r){let{inputs:e,backend:t,attrs:n}=r,{numBuckets:o}=n,{input:s}=e;if(s.dtype!=="string")throw new Error("Input must be of datatype string");if(o<=0)throw new Error("Number of buckets must be at least 1");let a=t.data.get(s.dataId).values,i=Sy(a,o);return t.makeTensorInfo(s.shape,"int32",i)}var vO={kernelName:kp,backendName:"cpu",kernelFunc:aZ};var lZ= $ e(vs,r=>Math.tan(r)),CO={kernelName:vs,backendName:"cpu",kernelFunc:lZ};var uZ= $ e(Cs,r=>Math.tanh(r)),IO={kernelName:Cs,backendName:"cpu",kernelFunc:uZ};function cZ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{reps:s}=n;te(o,"tile");let a=Ny(t.bufferSync(o),s);return t.makeTensorInfo(a.shape,a.dtype,a.values)}var SO={kernelName:Hn,backendName:"cpu",kernelFunc:cZ};function pZ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{k:s,sorted:a}=n;te(o,"topk");let i=t.data.get(o.dataId).values,[l,u]=Ty(i,o.shape,o
` ),s=o.length.toString().length+2,a=o.map((p,m)=>b.rightPad((m+1).toString(),s)+p),i=0;for(let p=0;p<a.length;p++)i=Math.max(a[p].length,i);let l=a.slice(0,n-1),u=a.slice(n-1,n),c=a.slice(n);console.log(l.join( `
` )),console.log(e.split( `
` )[0]),console.log( ` % c $ { b . rightPad ( u [ 0 ] , i ) } ` ,"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(c.join( `
` ))}function sC(r){return Ja(r,()=>r.createProgram(),"Unable to create WebGLProgram.")}function iC(r,e){if(ke(r,()=>r.linkProgram(e)),r.getProgramParameter(e,r.LINK_STATUS)===!1)throw console.log(r.getProgramInfoLog(e)),new Error("Failed to link vertex and fragment shaders.")}function Bh(r,e){if(ke(r,()=>r.validateProgram(e)),r.getProgramParameter(e,r.VALIDATE_STATUS)===!1)throw console.log(r.getProgramInfoLog(e)),new Error("Shader program validation failed.")}function aC(r,e){let t=Ja(r,()=>r.createBuffer(),"Unable to create WebGLBuffer");return ke(r,()=>r.bindBuffer(r.ARRAY_BUFFER,t)),ke(r,()=>r.bufferData(r.ARRAY_BUFFER,e,r.STATIC_DRAW)),t}function lC(r,e){let t=Ja(r,()=>r.createBuffer(),"Unable to create WebGLBuffer");return ke(r,()=>r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,t)),ke(r,()=>r.bufferData(r.ELEMENT_ARRAY_BUFFER,e,r.STATIC_DRAW)),t}function AZ(){return U().getNumber("WEBGL_VERSION")===2?1:4}function uC(r){return Ja(r,()=>r.createTexture(),"Unable to create WebGLTexture.")}function cC(r,e){let t=U().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(r<=0||e<=0){let n= ` [ $ { r } x$ { e } ] ` ;throw new Error("Requested texture size "+n+" is invalid.")}if(r>t||e>t){let n= ` [ $ { r } x$ { e } ] ` ,o= ` [ $ { t } x$ { t } ] ` ;throw new Error("Requested texture size "+n+" greater than WebGL maximum on this browser / GPU "+o+".")}}function pC(r){return Ja(r,()=>r.createFramebuffer(),"Unable to create WebGLFramebuffer.")}function Py(r,e,t,n,o,s,a){let i=r.getAttribLocation(e,t);return i===-1?!1:(ke(r,()=>r.bindBuffer(r.ARRAY_BUFFER,n)),ke(r,()=>r.vertexAttribPointer(i,o,r.FLOAT,!1,s,a)),ke(r,()=>r.enableVertexAttribArray(i)),!0)}function PO(r,e,t){LO(r,t),ke(r,()=>r.activeTexture(r.TEXTURE0+t)),ke(r,()=>r.bindTexture(r.TEXTURE_2D,e))}function DZ(r,e){LO(r,e),ke(r,()=>r.activeTexture(r.TEXTURE0+e)),ke(r,()=>r.bindTexture(r.TEXTURE_2D,null))}function mC(r,e,t){return Ja(r,()=>r.getUniformLocation(e,t),'uniform "'+t+'" not present in program.')}function fC(r,e,t){return r.getUniformLocation(e,t)}function dC(r,e,t,n){ke(r,()=>PO(r,e,n)),ke(r,()=>r.uniform1i(t,n))}function $ Z(r){ke(r,()=>r.bindFramebuffer(r.FRAMEBUFFER,null)),ke(r,()=>r.viewport(0,0,r.canvas.width,r.canvas.height)),ke(r,()=>r.scissor(0,0,r.canvas.width,r.canvas.height))}function Vh(r,e,t){ke(r,()=>r.bindFramebuffer(r.FRAMEBUFFER,t)),ke(r,()=>r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,e,0))}function My(r,e){ke(r,()=>r.bindFramebuffer(r.FRAMEBUFFER,e)),ke(r,()=>r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,null,0))}function Em(r){let e=r.checkFramebufferStatus(r.FRAMEBUFFER);if(e!==r.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+MO(r,e))}function MO(r,e){switch(e){case r.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case r.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return ` unknown error $ { e } ` }}function Ja(r,e,t){let n=ke(r,()=>e());if(n==null)throw new Error(t);return n}function LO(r,e){let t=r.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,n=e+r.TEXTURE0;if(n<r.TEXTURE0||n>t){let o= ` [ gl . TEXTURE0 , gl . TEXTURE$ { t } ] ` ;throw new Error( ` textureUnit must be in $ { o } . ` )}}function Qa(r,e=2){return b.sizeFromShape(r.slice(0,r.length-e))}function el(r){if(r.length===0)throw Error("Cannot get rows and columns of an empty shape array.");return[r.length>1?r[r.length-2]:1,r[r.length-1]]}function Gh(r){let e=[1,1,1];return r.length===0||r.length===1&&r[0]===1||(e=[Qa(r),...el(r)]),e}function hC(r,e=!1){let t=U().getNumber("WEBGL_MAX_TEXTURE_SIZE");e&&(t=t*2,r=r.map((o,s)=>s>=r.length-2?b.nearestLargerEven(r[s]):r[s]),r.length===1&&(r=[2,r[0]])),r.length!==2&&(r=b.squeezeShape(r).newShape);let n=b.sizeFromShape(r);if(r.length<=1&&n<=t)return[1,n];if(r.length===2&&r[0]<=t&&r[1]<=t)return r;if(r.length===3&&r[0]*r[1]<=t&&r[2]<=t)return[r[0]*r[1],r[2]];if(r.length===3&&r[0]<=t&&r[1]*r[2]<=t)return[r[0],r[1]*r[2]];if(r.length===4&&r[0]*r[1]
bool isnan _custom ( float val ) {
return ( val > 0.0 || val < 0.0 ) ? false : val != 0.0 ;
2021-06-07 02:47:59 +02:00
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
bvec4 isnan _custom ( vec4 val ) {
return bvec4 ( isnan _custom ( val . x ) ,
isnan _custom ( val . y ) , isnan _custom ( val . z ) , isnan _custom ( val . w ) ) ;
2021-06-07 01:00:34 +02:00
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
# define isnan ( value ) isnan _custom ( value )
` ,l="",u= `
# define round ( value ) newRound ( value )
int newRound ( float value ) {
return int ( floor ( value + 0.5 ) ) ;
2021-06-05 19:02:01 +02:00
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec4 newRound ( vec4 value ) {
return ivec4 ( floor ( value + vec4 ( 0.5 ) ) ) ;
2021-06-07 02:47:59 +02:00
}
2021-10-22 22:09:52 +02:00
` ):(r="",e="attribute",t="varying",n="varying",o="texture2D",s="gl_FragColor",a="",i= `
# define isnan ( value ) isnan _custom ( value )
bool isnan _custom ( float val ) {
return ( val > 0. || val < 1. || val == 0. ) ? false : true ;
2021-06-07 02:47:59 +02:00
}
2021-10-22 22:09:52 +02:00
bvec4 isnan _custom ( vec4 val ) {
return bvec4 ( isnan ( val . x ) , isnan ( val . y ) , isnan ( val . z ) , isnan ( val . w ) ) ;
2021-06-07 02:47:59 +02:00
}
2021-10-22 22:09:52 +02:00
` ,l= `
uniform float INFINITY ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
bool isinf ( float val ) {
return abs ( val ) == INFINITY ;
2021-06-05 22:13:41 +02:00
}
2021-10-22 22:09:52 +02:00
bvec4 isinf ( vec4 val ) {
return equal ( abs ( val ) , vec4 ( INFINITY ) ) ;
2021-06-07 02:34:29 +02:00
}
2021-10-22 22:09:52 +02:00
` ,u= `
int round ( float value ) {
return int ( floor ( value + 0.5 ) ) ;
2021-06-07 02:34:29 +02:00
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec4 round ( vec4 value ) {
return ivec4 ( floor ( value + vec4 ( 0.5 ) ) ) ;
2021-06-05 22:13:41 +02:00
}
2021-10-22 22:09:52 +02:00
` ),{version:r,attribute:e,varyingVs:t,varyingFs:n,texture2D:o,output:s,defineOutput:a,defineSpecialNaN:i,defineSpecialInf:l,defineRound:u}}function Ks(r,e,t="index"){let n=b.computeStrides(e);return n.map((o,s)=>{let a= ` int $ { r [ s ] } = $ { t } / $ { o } ` ,i=s===n.length-1? ` int $ { r [ s + 1 ] } = $ { t } - $ { r [ s ] } * $ { o } ` : ` index -= $ { r [ s ] } * $ { o } ` ;return ` $ { a } ; $ { i } ; ` }).join("")}function yc(r,e,t="index"){let n=b.computeStrides(e);return n.map((o,s)=>{let a= ` int $ { r [ s ] } = $ { t } / outShapeStrides [ $ { s } ] ` ,i=s===n.length-1? ` int $ { r [ s + 1 ] } = $ { t } - $ { r [ s ] } * outShapeStrides [ $ { s } ] ` : ` index -= $ { r [ s ] } * outShapeStrides [ $ { s } ] ` ;return ` $ { a } ; $ { i } ; ` }).join("")}function PZ(r,e){let t=r.length,n=r.map(s=> ` $ { e } [ $ { s } ] ` ),o=new Array(t-1);o[t-2]=n[t-1];for(let s=t-3;s>=0;--s)o[s]= ` ( $ { o [ s + 1 ] } * $ { n [ s + 1 ] } ) ` ;return o}function BO(r,e,t="index"){let n=r.map((s,a)=>a),o=PZ(n,e);return o.map((s,a)=>{let i= ` int $ { r [ a ] } = $ { t } / $ { o [ a ] } ` ,l=a===o.length-1? ` int $ { r [ a + 1 ] } = $ { t } - $ { r [ a ] } * $ { o [ a ] } ` : ` index -= $ { r [ a ] } * $ { o [ a ] } ` ;return ` $ { i } ; $ { l } ; ` }).join("")}function Am(r){let e=b.computeStrides(r).map(t=>t.toString());return `
int getFlatIndex ( ivec3 coords ) {
return coords . x * $ { e [ 0 ] } + coords . y * $ { e [ 1 ] } + coords . z ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }function Dm(){return `
int getFlatIndex ( ivec3 coords ) {
return coords . x * outShapeStrides [ 0 ] + coords . y * outShapeStrides [ 1 ] + coords . z ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }var Gy= `
const float FLOAT _MAX = 1.70141184 e38 ;
const float FLOAT _MIN = 1.17549435 e - 38 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
lowp vec4 encode _float ( highp float v ) {
if ( isnan ( v ) ) {
return vec4 ( 255 , 255 , 255 , 255 ) ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
highp float av = abs ( v ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
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 ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
highp vec4 c = vec4 ( 0 , 0 , 0 , 0 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
highp float e = floor ( log2 ( av ) ) ;
highp float m = exp2 ( fract ( log2 ( av ) ) ) - 1.0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
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 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
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 ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` ;var{getBroadcastDims:VO}=I;function GO(r,e,t){let n=[];if(r.forEach(f=>{let d=b.sizeFromShape(f.shapeInfo.logicalShape);if(f.shapeInfo.isUniform?n.push( ` uniform float $ { f . name } $ { d > 1 ? ` [ ${ d } ] ` : "" } ; ` ):(n.push( ` uniform sampler2D $ { f . name } ; ` ),n.push( ` uniform int offset$ { f . name } ; ` )),t.enableShapeUniforms){let{uniformShape:h}=Wy(t.packedInputs,f.shapeInfo.logicalShape,f.shapeInfo.texShape);switch(h.length){case 1:n.push( ` uniform int $ { f . name } Shape ; ` );break;case 2:n.push( ` uniform ivec2 $ { f . name } Shape ; ` );break;case 3:n.push( ` uniform ivec3 $ { f . name } Shape ; ` );break;case 4:n.push( ` uniform ivec4 $ { f . name } Shape ; ` );break;default:break}n.push( ` uniform ivec2 $ { f . name } TexShape ; ` )}}),t.enableShapeUniforms){switch(e.logicalShape.length){case 1:n.push("uniform int outShape;");break;case 2:n.push("uniform ivec2 outShape;"),n.push("uniform int outShapeStrides;");break;case 3:n.push("uniform ivec3 outShape;"),n.push("uniform ivec2 outShapeStrides;");break;case 4:n.push("uniform ivec4 outShape;"),n.push("uniform ivec3 outShapeStrides;");break;default:break}n.push("uniform ivec2 outTexShape;")}t.customUniforms&&t.customUniforms.forEach(f=>{n.push( ` uniform $ { f . type } $ { f . name } $ { f . arrayIndex ? ` [ ${ f . arrayIndex } ] ` : "" } ; ` )});let o=n.join( `
` ),s=r.map(f=>MZ(f,e,t.packedInputs,t.enableShapeUniforms)).join( `
` ),a=e.texShape,i=Gt(),l=BZ(i),u,c,p=WZ(i);return e.isPacked?(u=LZ(e.logicalShape,a,t.enableShapeUniforms),c=GZ(i)):(u=zZ(e.logicalShape,a,t.enableShapeUniforms),c=VZ(i)),t.packedInputs&&(p+=qZ),[p,l,c,o,u,s,t.userCode].join( `
` )}function $ m(r,e=!1){let t=r.shapeInfo.logicalShape;switch(t.length){case 0:return sJ(r,e);case 1:return aJ(r,e);case 2:return uJ(r,e);case 3:return pJ(r,e);case 4:return fJ(r,e);case 5:return dJ(r);case 6:return hJ(r);default:throw new Error( ` $ { t . length } - D input sampling is not yet supported ` )}}function WO(r,e){switch(r.shapeInfo.logicalShape.length){case 0:return oJ(r);case 1:return iJ(r,e);case 2:return lJ(r,e);case 3:return cJ(r,e);default:return mJ(r,e)}}function MZ(r,e,t=!1,n){let o="";t?o+=WO(r,n):o+= $ m(r,n);let s=r.shapeInfo.logicalShape,a=e.logicalShape;return s.length<=a.length&&(t?o+=gJ(r,e):o+=xJ(r,e)),o}function LZ(r,e,t){switch(r.length){case 0:return UO();case 1:return KZ(r,e,t);case 2:return rJ(r,e,t);case 3:return YZ(r,e,t);default:return JZ(r,e,t)}}function zZ(r,e,t){switch(r.length){case 0:return UO();case 1:return XZ(r,e,t);case 2:return nJ(r,e,t);case 3:return ZZ(r,e,t);case 4:return QZ(r,e,t);case 5:return eJ(r,e);case 6:return tJ(r,e);default:throw new Error( ` $ { r . length } - D output sampling is not yet supported ` )}}function BZ(r){return `
float sampleTexture ( sampler2D textureSampler , vec2 uv ) {
return $ { r . texture2D } ( textureSampler , uv ) . r ;
}
` }function VZ(r){return `
void setOutput ( float val ) {
$ { r . output } = vec4 ( val , 0 , 0 , 0 ) ;
}
` }function GZ(r){return `
void setOutput ( vec4 val ) {
$ { r . output } = val ;
}
` }function WZ(r){return ` $ { r . version }
precision highp float ;
precision highp int ;
precision highp sampler2D ;
$ { r . varyingFs } vec2 resultUV ;
$ { r . defineOutput }
const vec2 halfCR = vec2 ( 0.5 , 0.5 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
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 ;
$ { r . defineSpecialNaN }
$ { r . defineSpecialInf }
$ { r . defineRound }
int imod ( int x , int y ) {
return x - y * ( x / y ) ;
}
int idiv ( int a , int b , float sign ) {
int res = a / b ;
int mod = imod ( a , b ) ;
if ( sign < 0. && mod != 0 ) {
res -= 1 ;
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
return res ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02: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 ) ;
}
$ { UZ }
$ { jZ }
$ { HZ }
` }var UZ= `
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 ) ;
}
` ,jZ= `
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 ) ;
}
` ,HZ= `
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 ) ;
}
` ,qZ= `
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 ) ;
}
float getChannel ( vec4 frag , int dim ) {
float modCoord = mod ( float ( dim ) , 2. ) ;
return modCoord == 0. ? frag . r : frag . g ;
}
` ;function UO(){return `
int getOutputCoords ( ) {
return 0 ;
}
` }function KZ(r,e,t){let n=[Math.ceil(e[0]/2),Math.ceil(e[1]/2)];return n[0]===1?t? `
int getOutputCoords ( ) {
return 2 * int ( resultUV . x * ceil ( float ( outTexShape [ 1 ] ) / 2.0 ) ) ;
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
` : `
int getOutputCoords ( ) {
return 2 * int ( resultUV . x * $ { n [ 1 ] } . 0 ) ;
2021-06-07 02:47:59 +02:00
}
2021-10-22 22:09:52 +02:00
` :n[1]===1?t? `
int getOutputCoords ( ) {
return 2 * int ( resultUV . y * ceil ( float ( outTexShape [ 0 ] ) / 2.0 ) ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` : `
int getOutputCoords ( ) {
return 2 * int ( resultUV . y * $ { n [ 0 ] } . 0 ) ;
2021-06-07 02:47:59 +02:00
}
2021-10-22 22:09:52 +02:00
` :t? `
int getOutputCoords ( ) {
ivec2 packedTexShape = ivec2 ( ceil ( float ( outTexShape [ 0 ] ) / 2.0 ) , ceil ( float ( outTexShape [ 1 ] ) / 2.0 ) ) ;
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( packedTexShape [ 0 ] , packedTexShape [ 1 ] ) ) ;
return 2 * ( resTexRC . x * packedTexShape [ 1 ] + resTexRC . y ) ;
}
` : `
int getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { n [ 0 ] } , $ { n [ 1 ] } ) ) ;
return 2 * ( resTexRC . x * $ { n [ 1 ] } + resTexRC . y ) ;
}
` }function XZ(r,e,t){return e[0]===1?t? `
int getOutputCoords ( ) {
return int ( resultUV . x * float ( outTexShape [ 1 ] ) ) ;
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
` : `
int getOutputCoords ( ) {
return int ( resultUV . x * $ { e [ 1 ] } . 0 ) ;
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
` :e[1]===1?t? `
int getOutputCoords ( ) {
return int ( resultUV . y * float ( outTexShape [ 0 ] ) ) ;
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
` : `
int getOutputCoords ( ) {
return int ( resultUV . y * $ { e [ 0 ] } . 0 ) ;
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
` :t? `
int getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( outTexShape [ 0 ] , outTexShape [ 1 ] ) ) ;
return resTexRC . x * outTexShape [ 1 ] + resTexRC . y ;
}
` : `
int getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { e [ 0 ] } , $ { e [ 1 ] } ) ) ;
return resTexRC . x * $ { e [ 1 ] } + resTexRC . y ;
}
` }function YZ(r,e,t){if(t)return `
ivec3 getOutputCoords ( ) {
ivec2 packedTexShape = ivec2 ( ceil ( float ( outTexShape [ 0 ] ) / 2.0 ) , ceil ( float ( outTexShape [ 1 ] ) / 2.0 ) ) ;
int texelsInLogicalRow = int ( ceil ( float ( outShape [ 2 ] ) / 2.0 ) ) ;
int texelsInBatch = texelsInLogicalRow * int ( ceil ( float ( outShape [ 1 ] ) / 2.0 ) ) ;
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( packedTexShape [ 0 ] , packedTexShape [ 1 ] ) ) ;
int index = resTexRC . x * packedTexShape [ 1 ] + resTexRC . y ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int b = index / texelsInBatch ;
index -= b * texelsInBatch ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
int r = 2 * ( index / texelsInLogicalRow ) ;
int c = imod ( index , texelsInLogicalRow ) * 2 ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
return ivec3 ( b , r , c ) ;
}
` ;let n=[Math.ceil(e[0]/2),Math.ceil(e[1]/2)],o=Math.ceil(r[2]/2),s=o*Math.ceil(r[1]/2);return `
ivec3 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { n [ 0 ] } , $ { n [ 1 ] } ) ) ;
int index = resTexRC . x * $ { n [ 1 ] } + resTexRC . y ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
int b = index / $ { s } ;
index -= b * $ { s } ;
int r = 2 * ( index / $ { o } ) ;
int c = imod ( index , $ { o } ) * 2 ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
return ivec3 ( b , r , c ) ;
}
` }function ZZ(r,e,t){if(t)return `
ivec3 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( outTexShape [ 0 ] , outTexShape [ 1 ] ) ) ;
int index = resTexRC . x * outTexShape [ 1 ] + resTexRC . y ;
$ { yc ( [ "r" , "c" , "d" ] , r ) }
return ivec3 ( r , c , d ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` ;let n=Ks(["r","c","d"],r);return `
ivec3 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { e [ 0 ] } , $ { e [ 1 ] } ) ) ;
int index = resTexRC . x * $ { e [ 1 ] } + resTexRC . y ;
$ { n }
return ivec3 ( r , c , d ) ;
}
` }function JZ(r,e,t){if(t)return `
ivec4 getOutputCoords ( ) {
ivec2 packedTexShape = ivec2 ( ceil ( float ( outTexShape [ 0 ] ) / 2.0 ) , ceil ( float ( outTexShape [ 1 ] ) / 2.0 ) ) ;
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( packedTexShape [ 0 ] , packedTexShape [ 1 ] ) ) ;
int index = resTexRC . x * packedTexShape [ 1 ] + resTexRC . y ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int texelsInLogicalRow = int ( ceil ( float ( outShape [ 3 ] ) / 2.0 ) ) ;
int texelsInBatch = texelsInLogicalRow * int ( ceil ( float ( outShape [ 2 ] ) / 2.0 ) ) ;
int texelsInBatchN = texelsInBatch * outShape [ 1 ] ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int b2 = index / texelsInBatchN ;
index -= b2 * texelsInBatchN ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int b = index / texelsInBatch ;
index -= b * texelsInBatch ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int r = 2 * ( index / texelsInLogicalRow ) ;
int c = imod ( index , texelsInLogicalRow ) * 2 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
return ivec4 ( b2 , b , r , c ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` ;let n=[Math.ceil(e[0]/2),Math.ceil(e[1]/2)],o=Math.ceil(r[r.length-1]/2),s=o*Math.ceil(r[r.length-2]/2),a=s,i="",l="b, r, c";for(let u=2;u<r.length-1;u++)a*=r[r.length-u-1],i= `
int b$ { u } = index / $ { a } ;
index -= b$ { u } * $ { a } ;
` +i,l= ` b$ { u } , ` +l;return `
ivec$ { r . length } getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { n [ 0 ] } , $ { n [ 1 ] } ) ) ;
int index = resTexRC . x * $ { n [ 1 ] } + resTexRC . y ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { i }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int b = index / $ { s } ;
index -= b * $ { s } ;
int r = 2 * ( index / $ { o } ) ;
int c = imod ( index , $ { o } ) * 2 ;
return ivec$ { r . length } ( $ { l } ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }function QZ(r,e,t){if(t)return `
ivec4 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( outTexShape [ 0 ] , outTexShape [ 1 ] ) ) ;
int index = resTexRC . x * outTexShape [ 1 ] + resTexRC . y ;
$ { yc ( [ "r" , "c" , "d" , "d2" ] , r ) }
return ivec4 ( r , c , d , d2 ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` ;let n=Ks(["r","c","d","d2"],r);return `
ivec4 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { e [ 0 ] } , $ { e [ 1 ] } ) ) ;
int index = resTexRC . x * $ { e [ 1 ] } + resTexRC . y ;
$ { n }
return ivec4 ( r , c , d , d2 ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }function eJ(r,e){let t=Ks(["r","c","d","d2","d3"],r);return `
ivec5 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx * vec2 ( $ { e [ 0 ] } ,
$ { e [ 1 ] } ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int index = resTexRC . x * $ { e [ 1 ] } + resTexRC . y ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { t }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec5 outShape = ivec5 ( r , c , d , d2 , d3 ) ;
return outShape ;
}
` }function tJ(r,e){let t=Ks(["r","c","d","d2","d3","d4"],r);return `
ivec6 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { e [ 0 ] } , $ { e [ 1 ] } ) ) ;
int index = resTexRC . x * $ { e [ 1 ] } + resTexRC . y ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { t }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec6 result = ivec6 ( r , c , d , d2 , d3 , d4 ) ;
return result ;
}
` }function rJ(r,e,t){let n=[Math.ceil(e[0]/2),Math.ceil(e[1]/2)];if(b.arraysEqual(r,e))return t? `
ivec2 getOutputCoords ( ) {
ivec2 packedTexShape = ivec2 ( ceil ( float ( outTexShape [ 0 ] ) / 2.0 ) , ceil ( float ( outTexShape [ 1 ] ) / 2.0 ) ) ;
return 2 * ivec2 ( resultUV . yx * vec2 ( packedTexShape [ 0 ] , packedTexShape [ 1 ] ) ) ;
}
` : `
ivec2 getOutputCoords ( ) {
return 2 * ivec2 ( resultUV . yx * vec2 ( $ { n [ 0 ] } , $ { n [ 1 ] } ) ) ;
}
` ;let o=Math.ceil(r[1]/2);return t? `
ivec2 getOutputCoords ( ) {
ivec2 packedTexShape = ivec2 ( ceil ( float ( outTexShape [ 0 ] ) / 2.0 ) , ceil ( float ( outTexShape [ 1 ] ) / 2.0 ) ) ;
int texelsInLogicalRow = int ( ceil ( float ( outShape [ 1 ] ) / 2.0 ) ) ;
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( packedTexShape [ 0 ] , packedTexShape [ 1 ] ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int index = resTexRC . x * packedTexShape [ 1 ] + resTexRC . y ;
int r = 2 * ( index / texelsInLogicalRow ) ;
int c = imod ( index , texelsInLogicalRow ) * 2 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
return ivec2 ( r , c ) ;
}
` : `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { n [ 0 ] } , $ { n [ 1 ] } ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int index = resTexRC . x * $ { n [ 1 ] } + resTexRC . y ;
int r = 2 * ( index / $ { o } ) ;
int c = imod ( index , $ { o } ) * 2 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
return ivec2 ( r , c ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }function nJ(r,e,t){return b.arraysEqual(r,e)?t? `
ivec2 getOutputCoords ( ) {
return ivec2 ( resultUV . yx * vec2 ( outTexShape [ 0 ] , outTexShape [ 1 ] ) ) ;
}
` : `
ivec2 getOutputCoords ( ) {
return ivec2 ( resultUV . yx * vec2 ( $ { e [ 0 ] } , $ { e [ 1 ] } ) ) ;
}
` :r[1]===1?t? `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( outTexShape [ 0 ] , outTexShape [ 1 ] ) ) ;
int index = resTexRC . x * outTexShape [ 1 ] + resTexRC . y ;
return ivec2 ( index , 0 ) ;
}
` : `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { e [ 0 ] } , $ { e [ 1 ] } ) ) ;
int index = resTexRC . x * $ { e [ 1 ] } + resTexRC . y ;
return ivec2 ( index , 0 ) ;
}
` :r[0]===1?t? `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( outTexShape [ 0 ] , outTexShape [ 1 ] ) ) ;
int index = resTexRC . x * outTexShape [ 1 ] + resTexRC . y ;
return ivec2 ( 0 , index ) ;
}
` : `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { e [ 0 ] } , $ { e [ 1 ] } ) ) ;
int index = resTexRC . x * $ { e [ 1 ] } + resTexRC . y ;
return ivec2 ( 0 , index ) ;
}
` :t? `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( outTexShape [ 0 ] , outTexShape [ 1 ] ) ) ;
int index = resTexRC . x * outTexShape [ 1 ] + resTexRC . y ;
int r = index / outShape [ 1 ] ;
int c = index - r * outShape [ 1 ] ;
return ivec2 ( r , c ) ;
2021-10-22 15:48:27 +02:00
}
2021-10-22 22:09:52 +02:00
` : `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { e [ 0 ] } , $ { e [ 1 ] } ) ) ;
int index = resTexRC . x * $ { e [ 1 ] } + resTexRC . y ;
int r = index / $ { r [ 1 ] } ;
int c = index - r * $ { r [ 1 ] } ;
return ivec2 ( r , c ) ;
}
` }function bc(r){return ` offset$ { r } ` }function oJ(r){let e=r.name,t="get"+e.charAt(0).toUpperCase()+e.slice(1),n=Gt();return `
vec4 $ { t } ( ) {
return $ { n . texture2D } ( $ { e } , halfCR ) ;
}
` }function sJ(r,e){let t=r.name,n="get"+t.charAt(0).toUpperCase()+t.slice(1);if(r.shapeInfo.isUniform)return ` float $ { n } ( ) { return $ { t } ; } ` ;let[o,s]=r.shapeInfo.texShape;if(o===1&&s===1)return `
float $ { n } ( ) {
return sampleTexture ( $ { t } , halfCR ) ;
}
` ;let a=bc(t);if(e)return `
float $ { n } ( ) {
vec2 uv = uvFromFlat ( $ { t } TexShape [ 0 ] , $ { t } TexShape [ 1 ] , $ { a } ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` ;let[i,l]=r.shapeInfo.texShape;return `
float $ { n } ( ) {
vec2 uv = uvFromFlat ( $ { i } , $ { l } , $ { a } ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` }function iJ(r,e){let t=r.name,n="get"+t.charAt(0).toUpperCase()+t.slice(1),o=r.shapeInfo.texShape,s=Gt();if(e)return `
vec4 $ { n } ( int index ) {
ivec2 packedTexShape = ivec2 ( ceil ( float ( $ { t } TexShape [ 0 ] ) / 2.0 ) , ceil ( float ( $ { t } TexShape [ 1 ] ) / 2.0 ) ) ;
vec2 uv = packedUVfrom1D (
packedTexShape [ 0 ] , packedTexShape [ 1 ] , index ) ;
return $ { s . texture2D } ( $ { t } , uv ) ;
}
` ;let a=[Math.ceil(o[0]/2),Math.ceil(o[1]/2)];return `
vec4 $ { n } ( int index ) {
vec2 uv = packedUVfrom1D (
$ { a [ 0 ] } , $ { a [ 1 ] } , index ) ;
return $ { s . texture2D } ( $ { t } , uv ) ;
}
` }function aJ(r,e){let t=r.name,n="get"+t.charAt(0).toUpperCase()+t.slice(1);if(r.shapeInfo.isUniform)return `
float $ { n } ( int index ) {
$ { Rm ( r ) }
}
` ;let o=r.shapeInfo.texShape,s=o[0],a=o[1];if(a===1&&s===1)return `
float $ { n } ( int index ) {
return sampleTexture ( $ { t } , halfCR ) ;
}
` ;let i=bc(t);return a===1?e? `
float $ { n } ( int index ) {
vec2 uv = vec2 ( 0.5 , ( float ( index + $ { i } ) + 0.5 ) / float ( $ { t } TexShape [ 0 ] ) ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` : `
float $ { n } ( int index ) {
vec2 uv = vec2 ( 0.5 , ( float ( index + $ { i } ) + 0.5 ) / $ { s } . 0 ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` :s===1?e? `
float $ { n } ( int index ) {
vec2 uv = vec2 ( ( float ( index + $ { i } ) + 0.5 ) / float ( $ { t } TexShape [ 1 ] ) , 0.5 ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` : `
float $ { n } ( int index ) {
vec2 uv = vec2 ( ( float ( index + $ { i } ) + 0.5 ) / $ { a } . 0 , 0.5 ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` :e? `
float $ { n } ( int index ) {
vec2 uv = uvFromFlat ( $ { t } TexShape [ 0 ] , $ { t } TexShape [ 1 ] , index + $ { i } ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` : `
float $ { n } ( int index ) {
vec2 uv = uvFromFlat ( $ { s } , $ { a } , index + $ { i } ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` }function lJ(r,e){let t=r.shapeInfo.logicalShape,n=r.name,o="get"+n.charAt(0).toUpperCase()+n.slice(1),s=r.shapeInfo.texShape,a=s[0],i=s[1],l=Gt();if(s!=null&&b.arraysEqual(t,s))return e? `
vec4 $ { o } ( int row , int col ) {
vec2 uv = ( vec2 ( col , row ) + halfCR ) / vec2 ( $ { n } TexShape [ 1 ] , $ { n } TexShape [ 0 ] ) ;
return $ { l . texture2D } ( $ { n } , uv ) ;
}
` : `
vec4 $ { o } ( int row , int col ) {
vec2 uv = ( vec2 ( col , row ) + halfCR ) / vec2 ( $ { i } . 0 , $ { a } . 0 ) ;
return $ { l . texture2D } ( $ { n } , uv ) ;
}
` ;if(e)return `
vec4 $ { o } ( int row , int col ) {
ivec2 packedTexShape = ivec2 ( ceil ( float ( $ { n } TexShape [ 0 ] ) / 2.0 ) , ceil ( float ( $ { n } TexShape [ 1 ] ) / 2.0 ) ) ;
int valuesPerRow = int ( ceil ( float ( $ { n } Shape [ 1 ] ) / 2.0 ) ) ;
vec2 uv = packedUVfrom2D ( valuesPerRow , packedTexShape [ 0 ] , packedTexShape [ 1 ] , row , col ) ;
return $ { l . texture2D } ( $ { n } , uv ) ;
}
` ;let u=[Math.ceil(s[0]/2),Math.ceil(s[1]/2)],c=Math.ceil(t[1]/2);return `
vec4 $ { o } ( int row , int col ) {
vec2 uv = packedUVfrom2D ( $ { c } , $ { u [ 0 ] } , $ { u [ 1 ] } , row , col ) ;
return $ { l . texture2D } ( $ { n } , uv ) ;
}
` }function uJ(r,e){let t=r.shapeInfo.logicalShape,n=r.name,o="get"+n.charAt(0).toUpperCase()+n.slice(1),s=r.shapeInfo.texShape;if(s!=null&&b.arraysEqual(t,s)){if(e)return `
float $ { o } ( int row , int col ) {
vec2 uv = ( vec2 ( col , row ) + halfCR ) / vec2 ( $ { n } TexShape [ 1 ] , $ { n } TexShape [ 0 ] ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` ;let m=s[0],f=s[1];return `
float $ { o } ( int row , int col ) {
vec2 uv = ( vec2 ( col , row ) + halfCR ) / vec2 ( $ { f } . 0 , $ { m } . 0 ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` }let{newShape:a,keptDims:i}=b.squeezeShape(t),l=a;if(l.length<t.length){let m=Fm(r,l),f=["row","col"];return `
$ { $m ( m , e ) }
float $ { o } ( int row , int col ) {
return $ { o } ( $ { Om ( f , i ) } ) ;
}
` }if(r.shapeInfo.isUniform)return `
float $ { o } ( int row , int col ) {
int index = round ( dot ( vec2 ( row , col ) , vec2 ( $ { t [ 1 ] } , 1 ) ) ) ;
$ { Rm ( r ) }
}
` ;let u=s[0],c=s[1],p=bc(n);return c===1?e? `
float $ { o } ( int row , int col ) {
float index = dot ( vec3 ( row , col , $ { p } ) , vec3 ( $ { n } Shape [ 1 ] , 1 , 1 ) ) ;
vec2 uv = vec2 ( 0.5 , ( index + 0.5 ) / float ( $ { n } TexShape [ 0 ] ) ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` : `
float $ { o } ( int row , int col ) {
float index = dot ( vec3 ( row , col , $ { p } ) , vec3 ( $ { t [ 1 ] } , 1 , 1 ) ) ;
vec2 uv = vec2 ( 0.5 , ( index + 0.5 ) / $ { u } . 0 ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` :u===1?e? `
float $ { o } ( int row , int col ) {
float index = dot ( vec3 ( row , col , $ { p } ) , vec3 ( $ { n } Shape [ 1 ] , 1 , 1 ) ) ;
vec2 uv = vec2 ( ( index + 0.5 ) / float ( $ { n } TexShape [ 1 ] ) , 0.5 ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` : `
float $ { o } ( int row , int col ) {
float index = dot ( vec3 ( row , col , $ { p } ) , vec3 ( $ { t [ 1 ] } , 1 , 1 ) ) ;
vec2 uv = vec2 ( ( index + 0.5 ) / $ { c } . 0 , 0.5 ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` :e? `
float $ { o } ( int row , int col ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * $ { n } Shape [ 1 ] + col + $ { p } ;
vec2 uv = uvFromFlat ( $ { n } TexShape [ 0 ] , $ { n } TexShape [ 1 ] , index ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` : `
float $ { o } ( int row , int col ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * $ { t [ 1 ] } + col + $ { p } ;
vec2 uv = uvFromFlat ( $ { u } , $ { c } , index ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` }function cJ(r,e){let t=r.shapeInfo.logicalShape,n=r.name,o="get"+n.charAt(0).toUpperCase()+n.slice(1),s=r.shapeInfo.texShape,a=[Math.ceil(s[0]/2),Math.ceil(s[1]/2)];if(t[0]===1){let m=t.slice(1),f=[1,2],d=Fm(r,m),h=["b","row","col"];return `
$ { WO ( d , e ) }
vec4 $ { o } ( int b , int row , int col ) {
return $ { o } ( $ { Om ( h , f ) } ) ;
}
` }let i=Gt();if(e)return `
vec4 $ { o } ( int b , int row , int col ) {
ivec2 packedTexShape = ivec2 ( ceil ( float ( $ { n } TexShape [ 0 ] ) / 2.0 ) , ceil ( float ( $ { n } TexShape [ 1 ] ) / 2.0 ) ) ;
int valuesPerRow = int ( ceil ( float ( $ { n } Shape [ 2 ] ) / 2.0 ) ) ;
int texelsInBatch = valuesPerRow * int ( ceil ( float ( $ { n } Shape [ 1 ] ) / 2.0 ) ) ;
vec2 uv = packedUVfrom3D (
packedTexShape [ 0 ] , packedTexShape [ 1 ] , texelsInBatch , valuesPerRow , b , row , col ) ;
return $ { i . texture2D } ( $ { n } , uv ) ;
}
` ;let l=a[0],u=a[1],c=Math.ceil(t[2]/2),p=c*Math.ceil(t[1]/2);return `
vec4 $ { o } ( int b , int row , int col ) {
vec2 uv = packedUVfrom3D (
$ { l } , $ { u } , $ { p } , $ { c } , b , row , col ) ;
return $ { i . texture2D } ( $ { n } , uv ) ;
}
` }function pJ(r,e){let t=r.shapeInfo.logicalShape,n=r.name,o="get"+n.charAt(0).toUpperCase()+n.slice(1),s=t[1]*t[2],a=t[2],{newShape:i,keptDims:l}=b.squeezeShape(t),u=i;if(u.length<t.length){let h=Fm(r,u),g=["row","col","depth"];return `
$ { $m ( h , e ) }
float $ { o } ( int row , int col , int depth ) {
return $ { o } ( $ { Om ( g , l ) } ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }if(r.shapeInfo.isUniform)return `
float $ { o } ( int row , int col , int depth ) {
int index = round ( dot ( vec3 ( row , col , depth ) ,
vec3 ( $ { s } , $ { a } , 1 ) ) ) ;
$ { Rm ( r ) }
}
` ;let c=r.shapeInfo.texShape,p=c[0],m=c[1],f=r.shapeInfo.flatOffset;if(m===s&&f==null)return e? `
float $ { o } ( int row , int col , int depth ) {
int stride1 = $ { n } Shape [ 2 ] ;
float texR = float ( row ) ;
float texC = dot ( vec2 ( col , depth ) , vec2 ( stride1 , 1 ) ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { n } TexShape [ 1 ] , $ { n } TexShape [ 0 ] ) ;
return sampleTexture ( $ { n } , uv ) ;
2021-10-22 15:48:27 +02:00
}
2021-10-22 22:09:52 +02:00
` : `
float $ { o } ( int row , int col , int depth ) {
float texR = float ( row ) ;
float texC = dot ( vec2 ( col , depth ) , vec2 ( $ { a } , 1 ) ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { m } . 0 , $ { p } . 0 ) ;
return sampleTexture ( $ { n } , uv ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` ;if(m===a&&f==null)return e? `
float $ { o } ( int row , int col , int depth ) {
float texR = dot ( vec2 ( row , col ) , vec2 ( $ { n } Shape [ 1 ] , 1 ) ) ;
float texC = float ( depth ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) / vec2 ( $ { n } TexShape [ 1 ] , $ { n } TexShape [ 0 ] ) ;
return sampleTexture ( $ { n } , uv ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` : `
float $ { o } ( int row , int col , int depth ) {
float texR = dot ( vec2 ( row , col ) , vec2 ( $ { t [ 1 ] } , 1 ) ) ;
float texC = float ( depth ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) / vec2 ( $ { m } . 0 , $ { p } . 0 ) ;
return sampleTexture ( $ { n } , uv ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` ;let d=bc(n);return e? `
float $ { o } ( int row , int col , int depth ) {
// Explicitly use integer operations as dot() only works on floats.
int stride0 = $ { n } Shape [ 1 ] * $ { n } Shape [ 2 ] ;
int stride1 = $ { n } Shape [ 2 ] ;
int index = row * $ { s } + col * $ { a } + depth + $ { d } ;
vec2 uv = uvFromFlat ( $ { n } TexShape [ 0 ] , $ { n } TexShape [ 1 ] , index ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` : `
float $ { o } ( int row , int col , int depth ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * $ { s } + col * $ { a } + depth + $ { d } ;
vec2 uv = uvFromFlat ( $ { p } , $ { m } , index ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` }function mJ(r,e){let t=r.name,n="get"+t.charAt(0).toUpperCase()+t.slice(1),o=Gt();if(e)return `
vec4 $ { n } ( int b2 , int b , int row , int col ) {
int valuesPerRow = int ( ceil ( float ( $ { t } Shape [ 3 ] ) / 2.0 ) ) ;
int texelsInBatch = valuesPerRow * int ( ceil ( float ( $ { t } Shape [ 2 ] ) / 2.0 ) ) ;
int index = b * texelsInBatch + ( row / 2 ) * valuesPerRow + ( col / 2 ) ;
texelsInBatch *= $ { t } Shape [ 1 ] ;
index = b2 * texelsInBatch + index ;
ivec2 packedTexShape = ivec2 ( ceil ( float ( $ { t } TexShape [ 0 ] ) / 2.0 ) , ceil ( float ( $ { t } TexShape [ 1 ] ) / 2.0 ) ) ;
int texR = index / packedTexShape [ 1 ] ;
int texC = index - texR * packedTexShape [ 1 ] ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) / vec2 ( packedTexShape [ 1 ] , packedTexShape [ 0 ] ) ; return $ { o . texture2D } ( $ { t } , uv ) ;
}
` ;let s=r.shapeInfo.logicalShape,a=s.length,i=r.shapeInfo.texShape,l=[Math.ceil(i[0]/2),Math.ceil(i[1]/2)],u=l[0],c=l[1],p=Math.ceil(s[a-1]/2),m=p*Math.ceil(s[a-2]/2),f="int b, int row, int col",d= ` b * $ { m } + ( row / 2 ) * $ { p } + ( col / 2 ) ` ;for(let h=2;h<a-1;h++)f= ` int b$ { h } , ` +f,m*=s[a-h-1],d= ` b$ { h } * $ { m } + ` +d;return `
vec4 $ { n } ( $ { f } ) {
int index = $ { d } ;
int texR = index / $ { c } ;
int texC = index - texR * $ { c } ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) / vec2 ( $ { c } , $ { u } ) ;
return $ { o . texture2D } ( $ { t } , uv ) ;
}
` }function fJ(r,e){let t=r.shapeInfo.logicalShape,n=r.name,o="get"+n.charAt(0).toUpperCase()+n.slice(1),s=t[3],a=t[2]*s,i=t[1]*a,{newShape:l,keptDims:u}=b.squeezeShape(t);if(l.length<t.length){let y=Fm(r,l),w=["row","col","depth","depth2"];return `
$ { $m ( y , e ) }
float $ { o } ( int row , int col , int depth , int depth2 ) {
return $ { o } ( $ { Om ( w , u ) } ) ;
}
` }if(r.shapeInfo.isUniform)return `
float $ { o } ( int row , int col , int depth , int depth2 ) {
int index = round ( dot ( vec4 ( row , col , depth , depth2 ) ,
vec4 ( $ { i } , $ { a } , $ { s } , 1 ) ) ) ;
$ { Rm ( r ) }
2021-10-22 15:48:27 +02:00
}
2021-10-22 22:09:52 +02:00
` ;let c=r.shapeInfo.flatOffset,p=r.shapeInfo.texShape,m=p[0],f=p[1],d= ` int stride2 = $ { n } Shape [ 3 ] ; ` ,h= ` int stride1 = $ { n } Shape [ 2 ] * stride2 ; ` ,g= ` int stride0 = $ { n } Shape [ 1 ] * stride1 ; ` ;if(f===i&&c==null)return e? `
float $ { o } ( int row , int col , int depth , int depth2 ) {
$ { d }
$ { h }
float texR = float ( row ) ;
float texC =
dot ( vec3 ( col , depth , depth2 ) ,
vec3 ( stride1 , stride2 , 1 ) ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { n } TexShape [ 1 ] , $ { n } TexShape [ 0 ] ) ;
return sampleTexture ( $ { n } , uv ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` : `
float $ { o } ( int row , int col , int depth , int depth2 ) {
float texR = float ( row ) ;
float texC =
dot ( vec3 ( col , depth , depth2 ) ,
vec3 ( $ { a } , $ { s } , 1 ) ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { f } . 0 , $ { m } . 0 ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` ;if(f===s&&c==null)return e? `
float $ { o } ( int row , int col , int depth , int depth2 ) {
float texR = dot ( vec3 ( row , col , depth ) ,
vec3 ( $ { n } Shape [ 1 ] * $ { n } Shape [ 2 ] , $ { n } Shape [ 2 ] , 1 ) ) ;
float texC = float ( depth2 ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { n } TexShape [ 1 ] , $ { n } TexShape [ 0 ] ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` : `
float $ { o } ( int row , int col , int depth , int depth2 ) {
float texR = dot ( vec3 ( row , col , depth ) ,
vec3 ( $ { t [ 1 ] * t [ 2 ] } , $ { t [ 2 ] } , 1 ) ) ;
float texC = float ( depth2 ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { f } . 0 , $ { m } . 0 ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` ;let x=bc(n);return e? `
float $ { o } ( int row , int col , int depth , int depth2 ) {
// Explicitly use integer operations as dot() only works on floats.
$ { d }
$ { h }
$ { g }
int index = row * stride0 + col * stride1 +
depth * stride2 + depth2 ;
vec2 uv = uvFromFlat ( $ { n } TexShape [ 0 ] , $ { n } TexShape [ 1 ] , index + $ { x } ) ;
return sampleTexture ( $ { n } , uv ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` : `
float $ { o } ( int row , int col , int depth , int depth2 ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * $ { i } + col * $ { a } +
depth * $ { s } + depth2 ;
vec2 uv = uvFromFlat ( $ { m } , $ { f } , index + $ { x } ) ;
return sampleTexture ( $ { n } , uv ) ;
}
` }function dJ(r){let e=r.shapeInfo.logicalShape,t=r.name,n="get"+t.charAt(0).toUpperCase()+t.slice(1),o=e[4],s=e[3]*o,a=e[2]*s,i=e[1]*a,{newShape:l,keptDims:u}=b.squeezeShape(e);if(l.length<e.length){let h=Fm(r,l),g=["row","col","depth","depth2","depth3"];return `
$ { $m ( h ) }
float $ { n } ( int row , int col , int depth , int depth2 , int depth3 ) {
return $ { n } ( $ { Om ( g , u ) } ) ;
}
` }if(r.shapeInfo.isUniform)return `
float $ { n } ( int row , int col , int depth , int depth2 , int depth3 ) {
float index = dot (
vec4 ( row , col , depth , depth2 ) ,
vec4 ( $ { i } , $ { a } , $ { s } , $ { o } ) ) +
depth3 ;
$ { Rm ( r ) }
}
` ;let c=r.shapeInfo.flatOffset,p=r.shapeInfo.texShape,m=p[0],f=p[1];if(f===i&&c==null)return `
float $ { n } ( int row , int col , int depth , int depth2 , int depth3 ) {
int texR = row ;
float texC = dot ( vec4 ( col , depth , depth2 , depth3 ) ,
vec4 ( $ { a } , $ { s } , $ { o } , 1 ) ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { f } . 0 , $ { m } . 0 ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` ;if(f===o&&c==null)return `
float $ { n } ( int row , int col , int depth , int depth2 , int depth3 ) {
float texR = dot (
vec4 ( row , col , depth , depth2 ) ,
vec4 ( $ { e [ 1 ] * e [ 2 ] * e [ 3 ] } ,
$ { e [ 2 ] * e [ 3 ] } , $ { e [ 3 ] } , 1 ) ) ;
int texC = depth3 ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { f } . 0 , $ { m } . 0 ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` ;let d=bc(t);return `
float $ { n } ( int row , int col , int depth , int depth2 , int depth3 ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * $ { i } + col * $ { a } + depth * $ { s } +
depth2 * $ { o } + depth3 + $ { d } ;
vec2 uv = uvFromFlat ( $ { m } , $ { f } , index ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` }function hJ(r){let e=r.shapeInfo.logicalShape,t=r.name,n="get"+t.charAt(0).toUpperCase()+t.slice(1),{newShape:o,keptDims:s}=b.squeezeShape(e);if(o.length<e.length){let g=Fm(r,o),x=["row","col","depth","depth2","depth3","depth4"];return `
$ { $m ( g ) }
float $ { n } ( int row , int col , int depth ,
int depth2 , int depth3 , int depth4 ) {
return $ { n } ( $ { Om ( x , s ) } ) ;
}
` }let a=e[5],i=e[4]*a,l=e[3]*i,u=e[2]*l,c=e[1]*u;if(r.shapeInfo.isUniform)return `
float $ { n } ( int row , int col , int depth ,
int depth2 , int depth3 , int depth4 ) {
int index = round ( dot (
vec4 ( row , col , depth , depth2 ) ,
vec4 ( $ { c } , $ { u } , $ { l } , $ { i } ) ) +
dot (
vec2 ( depth3 , depth4 ) ,
vec2 ( $ { a } , 1 ) ) ) ;
$ { Rm ( r ) }
}
` ;let p=r.shapeInfo.flatOffset,m=r.shapeInfo.texShape,f=m[0],d=m[1];if(d===c&&p==null)return `
float $ { n } ( int row , int col , int depth ,
int depth2 , int depth3 , int depth4 ) {
int texR = row ;
float texC = dot ( vec4 ( col , depth , depth2 , depth3 ) ,
vec4 ( $ { u } , $ { l } , $ { i } , $ { a } ) ) +
float ( depth4 ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { d } . 0 , $ { f } . 0 ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` ;if(d===a&&p==null)return `
float $ { n } ( int row , int col , int depth ,
int depth2 , int depth3 , int depth4 ) {
float texR = dot ( vec4 ( row , col , depth , depth2 ) ,
vec4 ( $ { e [ 1 ] * e [ 2 ] * e [ 3 ] * e [ 4 ] } ,
$ { e [ 2 ] * e [ 3 ] * e [ 4 ] } ,
$ { e [ 3 ] * e [ 4 ] } ,
$ { e [ 4 ] } ) ) + float ( depth3 ) ;
int texC = depth4 ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { d } . 0 , $ { f } . 0 ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` ;let h=bc(t);return `
float $ { n } ( 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 * $ { c } + col * $ { u } + depth * $ { l } +
depth2 * $ { i } + depth3 * $ { a } + depth4 + $ { h } ;
vec2 uv = uvFromFlat ( $ { f } , $ { d } , index ) ;
return sampleTexture ( $ { t } , uv ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }function Rm(r){let e=r.name,t=b.sizeFromShape(r.shapeInfo.logicalShape);return t<2? ` return $ { e } ; ` : `
for ( int i = 0 ; i < $ { t } ; i ++ ) {
if ( i == index ) {
return $ { e } [ i ] ;
}
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }function gJ(r,e){let t=r.name,n=t.charAt(0).toUpperCase()+t.slice(1),o="get"+n+"AtOutCoords",s=r.shapeInfo.logicalShape.length,a=e.logicalShape.length,i=VO(r.shapeInfo.logicalShape,e.logicalShape),l=Ue(a),u=a-s,c,p=["x","y","z","w","u","v"];s===0?c="":a<2&&i.length>=1?c="coords = 0;":c=i.map(y=> ` coords . $ { p [ y + u ] } = 0 ; ` ).join( `
` );let m="";a<2&&s>0?m="coords":m=r.shapeInfo.logicalShape.map((y,w)=> ` coords . $ { p [ w + u ] } ` ).join(", ");let f="return outputValue;",h=b.sizeFromShape(r.shapeInfo.logicalShape)===1,x=b.sizeFromShape(e.logicalShape)===1;if(s===1&&!h&&!x)f= `
return vec4 ( outputValue . xy , outputValue . xy ) ;
` ;else if(h&&!x)a===1?f= `
return vec4 ( outputValue . x , outputValue . x , 0. , 0. ) ;
` :f= `
return vec4 ( outputValue . x ) ;
` ;else if(i.length){let y=s-2,w=s-1;i.indexOf(y)>-1&&i.indexOf(w)>-1?f="return vec4(outputValue.x);":i.indexOf(y)>-1?f="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":i.indexOf(w)>-1&&(f="return vec4(outputValue.xx, outputValue.zz);")}return `
vec4 $ { o } ( ) {
$ { l } coords = getOutputCoords ( ) ;
$ { c }
vec4 outputValue = get$ { n } ( $ { m } ) ;
$ { f }
}
` }function xJ(r,e){let t=r.name,n=t.charAt(0).toUpperCase()+t.slice(1),o="get"+n+"AtOutCoords",s=e.texShape,a=r.shapeInfo.texShape,i=r.shapeInfo.logicalShape.length,l=e.logicalShape.length;if(!r.shapeInfo.isUniform&&i===l&&r.shapeInfo.flatOffset==null&&b.arraysEqual(a,s))return `
float $ { o } ( ) {
return sampleTexture ( $ { t } , resultUV ) ;
}
` ;let u=Ue(l),c=VO(r.shapeInfo.logicalShape,e.logicalShape),p=l-i,m,f=["x","y","z","w","u","v"];i===0?m="":l<2&&c.length>=1?m="coords = 0;":m=c.map(h=> ` coords . $ { f [ h + p ] } = 0 ; ` ).join( `
` );let d="";return l<2&&i>0?d="coords":d=r.shapeInfo.logicalShape.map((h,g)=> ` coords . $ { f [ g + p ] } ` ).join(", "), `
float $ { o } ( ) {
$ { u } coords = getOutputCoords ( ) ;
$ { m }
return get$ { n } ( $ { d } ) ;
}
` }function Ue(r){if(r<=1)return"int";if(r===2)return"ivec2";if(r===3)return"ivec3";if(r===4)return"ivec4";if(r===5)return"ivec5";if(r===6)return"ivec6";throw Error( ` GPU for rank $ { r } is not yet supported ` )}function Wy(r,e,t){let{newShape:n,keptDims:o}=b.squeezeShape(e),s=e.length,a=r&&s===3&&e[0]===1,i=a?e.slice(1):n,l=!r&&s>1&&!b.arraysEqual(e,t)&&n.length<s||a;return{useSqueezeShape:l,uniformShape:l?i:e,keptDims:o}}function Fm(r,e){let t=JSON.parse(JSON.stringify(r));return t.shapeInfo.logicalShape=e,t}function Om(r,e){return e.map(t=>r[t]).join(", ")}function jO(r,e,t,n){let o=t.map((w,_)=>{let C={logicalShape:w.shape,texShape:w.isUniform?null:w.texData.texShape,isUniform:w.isUniform,isPacked:w.isUniform?!1:w.texData.isPacked,flatOffset:null};return w.texData!=null&&w.texData.slice!=null&&w.texData.slice.flatOffset>0&&(C.flatOffset=w.texData.slice.flatOffset),{name:e.variableNames[_],shapeInfo:C}}),s=o.map(w=>w.shapeInfo),a={logicalShape:n.shape,texShape:n.texData.texShape,isUniform:!1,isPacked:n.texData.isPacked,flatOffset:null},i=GO(o,a,e),l=r.createProgram(i),u=null,c=r.getUniformLocation(l,"NAN",!1);U().getNumber("WEBGL_VERSION")===1&&(u=r.getUniformLocation(l,"INFINITY",!1));let p=!1,m={},f={},d={};for(let w=0;w<e.variableNames.length;w++){let _=e.variableNames[w];m[_]=r.getUniformLocation(l,_,p),m[ ` offset$ { _ } ` ]=r.getUniformLocation(l, ` offset$ { _ } ` ,p),e.enableShapeUniforms&&(f[ ` $ { _ } Shape ` ]=r.getUniformLocation(l, ` $ { _ } Shape ` ,p),d[ ` $ { _ } TexShape ` ]=r.getUniformLocation(l, ` $ { _ } TexShape ` ,p))}let h,g,x;e.enableShapeUniforms&&(h=r.getUniformLocation(l,"outShape",p),x=r.getUniformLocation(l,"outShapeStrides",p),g=r.getUniformLocation(l,"outTexShape",p));let y=[];return e.customUniforms&&e.customUniforms.forEach((w,_)=>{y[_]=r.getUniformLocation(l,w.name,p)}),{program:e,source:i,webGLProgram:l,uniformLocations:m,customUniformLocations:y,inShapeInfos:s,outShapeInfo:a,infLoc:u,nanLoc:c,inShapesLocations:f,inTexShapesLocations:d,outShapeLocation:h,outShapeStridesLocation:x,outTexShapeLocation:g}}function HO(r,e){if(r.length!==e.length)throw Error( ` Binary was compiled with $ { r . length } inputs , but was executed with $ { e . length } inputs ` );r.forEach((t,n)=>{let o=t.logicalShape,s=e[n],a=s.shape;if(!b.arraysEqual(o,a))throw Error( ` Binary was compiled with different shapes than the current args . Shapes $ { o } and $ { a } must match ` );if(t.isUniform&&s.isUniform)return;let i=t.texShape,l=s.isUniform?null:s.texData.texShape;if(!b.arraysEqual(i,l))throw Error( ` Binary was compiled with different texture shapes than the current args . Shape $ { i } and $ { l } must match ` )})}function qO(r,e,t,n,o){e.program.enableShapeUniforms||(HO(e.inShapeInfos,t),HO([e.outShapeInfo],[n]));let s=n.texData.texture,a=n.texData.texShape;n.texData.isPacked?r.setOutputPackedMatrixTexture(s,a[0],a[1]):r.setOutputMatrixTexture(s,a[0],a[1]),r.setProgram(e.webGLProgram),U().getNumber("WEBGL_VERSION")===1&&e.infLoc!==null&&r.gl.uniform1f(e.infLoc,1/0),e.nanLoc!==null&&r.gl.uniform1f(e.nanLoc,NaN),t.forEach((l,u)=>{let c=e.program.variableNames[u],p=e.uniformLocations[c],m=e.uniformLocations[ ` offset$ { c } ` ],f=e.inShapesLocations[ ` $ { c } Shape ` ],d=e.inTexShapesLocations[ ` $ { c } TexShape ` ];if(f){let{uniformShape:h}=Wy(e.program.packedInputs,l.shape,l.texData.texShape);switch(h.length){case 1:r.gl.uniform1iv(f,new Int32Array(h));break;case 2:r.gl.uniform2iv(f,new Int32Array(h));break;case 3:r.gl.uniform3iv(f,new Int32Array(h));break;case 4:r.gl.uniform4iv(f,new Int32Array(h));break;default:break}}if(d&&r.gl.uniform2i(d,l.texData.texShape[0],l.texData.texShape[1]),p!=null){if(l.isUniform){if(b.sizeFromShape(l.shape)<2)r.gl.uniform1f(p,l.uniformValues[0]);else{let h=l.uniformValues;h instanceof Float32Array||(h=new Float32Array(h)),r.gl.uniform1fv(p,h)}return}l.texData.slice!=null&&m!=null&&r.gl.uniform1i(m,l.texData.slice.flatOffset),r.setInputMatrixTexture(l.texData.texture,p,u)}});let i=e.outShapeLocation;if(i)switch(n.shape.length){case 1:r.gl.uniform1iv(i,new Int32Array(n.shape));break;case 2:r.gl.uniform2iv(i,new Int32Array(n.shape));break;case 3:r.gl.uniform3iv(i,new Int32Array(n
ivec3 outCoordsFromFlatIndex ( int index ) {
$ { this . enableShapeUniforms ? yc ( [ "r" , "c" , "d" ] , e ) : Ks ( [ "r" , "c" , "d" ] , e ) }
return ivec3 ( r , c , d ) ;
}
2021-09-11 17:17:13 +02:00
void main ( ) {
2021-10-22 22:09:52 +02:00
ivec2 resTexRC = ivec2 ( resultUV . yx * vec2 ( texShape [ 0 ] , texShape [ 1 ] ) ) ;
int index = 4 * ( resTexRC . x * texShape [ 1 ] + resTexRC . y ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 result = vec4 ( 0. ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02: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 ) ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { t . output } = result ;
}
` }};var CC=class{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=Hl.DENSE,this.customUniforms=[{name:"texShape",type:"ivec2"}];let t=Gt();this.outputShape=e,this.enableShapeUniforms=jt(this.outputShape.length),this.userCode= `
ivec3 outCoordsFromFlatIndex ( int index ) {
$ { this . enableShapeUniforms ? yc ( [ "r" , "c" , "d" ] , e ) : Ks ( [ "r" , "c" , "d" ] , e ) }
return ivec3 ( r , c , d ) ;
2021-09-11 17:17:13 +02:00
}
void main ( ) {
2021-10-22 22:09:52 +02:00
ivec2 resTexRC = ivec2 ( resultUV . yx * vec2 ( texShape [ 0 ] , texShape [ 1 ] ) ) ;
int index = 4 * ( resTexRC . x * texShape [ 1 ] + resTexRC . y ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 result = vec4 ( 0. ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int i = 0 ; i < 4 ; i ++ ) {
int flatIndex = index + i ;
ivec3 rc = outCoordsFromFlatIndex ( flatIndex ) ;
result [ i ] = getChannel ( getA ( rc . x , rc . y , rc . z ) , vec2 ( rc . y , rc . z ) ) ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { t . output } = result ;
}
` }};var IC=class{constructor(e){this.variableNames=["A"],this.outTexUsage=Ur.DOWNLOAD;let t=Gt();this.outputShape=e,this.userCode= `
$ { Gy }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
float x = getAAtOutCoords ( ) ;
$ { t . output } = encode _float ( x ) ;
}
` }};var SC=class{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=Ur.DOWNLOAD;let t=Gt();this.outputShape=e,this.userCode= `
$ { Gy }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
float x = getChannel ( getAAtOutCoords ( ) , vec2 ( coords . y , coords . z ) ) ;
$ { t . output } = encode _float ( x ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }};var NC=class{constructor(e,t=!1){this.variableNames=["A"],this.customUniforms=[{name:"texShape",type:"ivec2"}];let n=Gt();this.outputShape=e,this.enableShapeUniforms=jt(this.outputShape.length);let o="result";t&&(o="floor(result * 255. + 0.5)"),this.userCode= `
$ { this . enableShapeUniforms ? Dm ( ) : Am ( e ) }
2021-09-11 17:17:13 +02:00
void main ( ) {
2021-10-22 22:09:52 +02:00
ivec3 coords = getOutputCoords ( ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int flatIndex = getFlatIndex ( coords ) ;
int offset = imod ( flatIndex , 4 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
flatIndex = idiv ( flatIndex , 4 , 1. ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int r = flatIndex / texShape [ 1 ] ;
int c = imod ( flatIndex , texShape [ 1 ] ) ;
vec2 uv = ( vec2 ( c , r ) + halfCR ) / vec2 ( texShape [ 1 ] , texShape [ 0 ] ) ;
vec4 values = $ { n . texture2D } ( A , uv ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float result ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02: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 ] ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { n . output } = vec4 ( $ { o } , 0. , 0. , 0. ) ;
}
` }};var TC=class{constructor(e,t=!1){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.customUniforms=[{name:"texShape",type:"ivec2"}];let n=Gt();this.outputShape=e,this.enableShapeUniforms=jt(this.outputShape.length);let o="",s="result";t&&(s="floor(result * 255. + 0.5)");for(let a=0;a<=1;a++)for(let i=0;i<=1;i++){let l=a*2+i;o+= `
localCoords = coords ;
if ( localCoords [ 2 ] + $ { i } < $ { this . enableShapeUniforms ? "outShape[2]" : ` ${ e [ 2 ] } ` } ) {
localCoords [ 2 ] += $ { i } ;
if ( localCoords [ 1 ] + $ { a } < $ { this . enableShapeUniforms ? "outShape[1]" : ` ${ e [ 1 ] } ` } ) {
localCoords [ 1 ] += $ { a } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
flatIndex = getFlatIndex ( localCoords ) ;
offset = imod ( flatIndex , 4 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
flatIndex = idiv ( flatIndex , 4 , 1. ) ;
int r = flatIndex / texShape [ 1 ] ;
int c = imod ( flatIndex , texShape [ 1 ] ) ;
vec2 uv = ( vec2 ( c , r ) + halfCR ) / vec2 ( texShape [ 1 ] , texShape [ 0 ] ) ;
values = $ { n . texture2D } ( A , uv ) ;
if ( offset == 0 ) {
result [ $ { l } ] = values [ 0 ] ;
} else if ( offset == 1 ) {
result [ $ { l } ] = values [ 1 ] ;
} else if ( offset == 2 ) {
result [ $ { l } ] = values [ 2 ] ;
} else {
result [ $ { l } ] = values [ 3 ] ;
2021-09-11 17:17:13 +02:00
}
}
}
2021-10-22 22:09:52 +02:00
` }this.userCode= `
$ { this . enableShapeUniforms ? Dm ( ) : Am ( e ) }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 result = vec4 ( 0. ) ;
int flatIndex , r , c , offset ;
ivec3 localCoords ;
vec2 uv ;
vec4 values ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { o }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { n . output } = $ { s } ;
}
` }};var XO={};qe(XO,{bindVertexProgramAttributeStreams:()=>MC,createBufferFromOutputTexture:()=>BC,createFloat16MatrixTexture:()=>RC,createFloat16PackedMatrixTexture:()=>PC,createFloat32MatrixTexture:()=> $ C,createIndexBuffer:()=>DC,createPackedMatrixTexture:()=>OC,createUnsignedBytesMatrixTexture:()=>FC,createVertexBuffer:()=>AC,createVertexShader:()=>EC,downloadByteEncodedFloatMatrixFromOutputTexture:()=>GC,downloadFloat32MatrixFromBuffer:()=>VC,downloadMatrixFromPackedOutputTexture:()=>UC,downloadPackedMatrixFromBuffer:()=>WC,getInternalFormatForFloat16MatrixTexture:()=>jy,getInternalFormatForFloat16PackedMatrixTexture:()=>Ky,getInternalFormatForFloat32MatrixTexture:()=>Uy,getInternalFormatForPackedMatrixTexture:()=>qy,getInternalFormatForUnsignedBytesMatrixTexture:()=>Hy,uploadDenseMatrixToTexture:()=>LC,uploadPixelDataToTexture:()=>zC});function EC(r){let e=Gt(),t= ` $ { e . version }
precision highp float ;
$ { e . attribute } vec3 clipSpacePos ;
$ { e . attribute } vec2 uv ;
$ { e . varyingVs } vec2 resultUV ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
gl _Position = vec4 ( clipSpacePos , 1 ) ;
resultUV = uv ;
} ` ;return nC(r,t)}function AC(r){let e=new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]);return aC(r,e)}function DC(r){let e=new Uint16Array([0,1,2,2,1,3]);return lC(r,e)}function Wh(r,e,t,n,o,s){cC(e,t);let a=uC(r),i=r.TEXTURE_2D;return ke(r,()=>r.bindTexture(i,a)),ke(r,()=>r.texParameteri(i,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE)),ke(r,()=>r.texParameteri(i,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE)),ke(r,()=>r.texParameteri(i,r.TEXTURE_MIN_FILTER,r.NEAREST)),ke(r,()=>r.texParameteri(i,r.TEXTURE_MAG_FILTER,r.NEAREST)),ke(r,()=>r.texImage2D(i,0,n,e,t,0,o,s,null)),ke(r,()=>r.bindTexture(r.TEXTURE_2D,null)),a}function Uy(r){return r.internalFormatFloat}function $ C(r,e,t,n){let[o,s]=xc(e,t);return Wh(r,o,s,Uy(n),n.textureFormatFloat,r.FLOAT)}function jy(r){return r.internalFormatHalfFloat}function RC(r,e,t,n){let[o,s]=xc(e,t);return Wh(r,o,s,jy(n),n.textureFormatFloat,n.textureTypeHalfFloat)}function Hy(r){return r.downloadTextureFormat}function FC(r,e,t,n){let[o,s]=xc(e,t);return Wh(r,o,s,Hy(n),r.RGBA,r.UNSIGNED_BYTE)}function qy(r){return r.internalFormatPackedFloat}function OC(r,e,t,n){let[o,s]=Ai(e,t);return Wh(r,o,s,qy(n),r.RGBA,r.FLOAT)}function Ky(r){return r.internalFormatPackedHalfFloat}function PC(r,e,t,n){let[o,s]=Ai(e,t);return Wh(r,o,s,Ky(n),r.RGBA,n.textureTypeHalfFloat)}function MC(r,e,t){let n=0,o=3*4,s=3*4+2*4;return ke(r,()=>r.bindBuffer(r.ARRAY_BUFFER,t)),Py(r,e,"clipSpacePos",t,3,s,n)&&Py(r,e,"uv",t,2,s,o)}function LC(r,e,t,n,o,s){ke(r,()=>r.bindTexture(r.TEXTURE_2D,e));let a,i,l;o instanceof Uint8Array?(a=new Uint8Array(t*n*4),i=r.UNSIGNED_BYTE,l=r.RGBA):(a=new Float32Array(t*n*4),i=r.FLOAT,l=s.internalFormatPackedFloat),a.set(o),ke(r,()=>r.texImage2D(r.TEXTURE_2D,0,l,t,n,0,r.RGBA,i,a)),ke(r,()=>r.bindTexture(r.TEXTURE_2D,null))}function zC(r,e,t){ke(r,()=>r.bindTexture(r.TEXTURE_2D,e)),t.data instanceof Uint8Array?ke(r,()=>r.texImage2D(r.TEXTURE_2D,0,r.RGBA,t.width,t.height,0,r.RGBA,r.UNSIGNED_BYTE,t.data)):ke(r,()=>r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t)),ke(r,()=>r.bindTexture(r.TEXTURE_2D,null))}function BC(r,e,t,n){let o=r.createBuffer();ke(r,()=>r.bindBuffer(r.PIXEL_PACK_BUFFER,o));let i=4*4*e*t;return ke(r,()=>r.bufferData(r.PIXEL_PACK_BUFFER,i,r.STREAM_READ)),ke(r,()=>r.readPixels(0,0,t,e,r.RGBA,r.FLOAT,0)),ke(r,()=>r.bindBuffer(r.PIXEL_PACK_BUFFER,null)),o}function VC(r,e,t){let n=r,o=new Float32Array(t);return n.bindBuffer(n.PIXEL_PACK_BUFFER,e),n.getBufferSubData(n.PIXEL_PACK_BUFFER,0,o),n.bindBuffer(n.PIXEL_PACK_BUFFER,null),o}function GC(r,e,t,n){let[o,s]=xc(e,t),a=4,i=new Uint8Array(RO(e*t,a));return ke(r,()=>r.readPixels(0,0,o,s,n.downloadTextureFormat,r.UNSIGNED_BYTE,i)),new Float32Array(i.buffer)}function WC(r,e,t,n,o,s,a,i){let l=r,u=new Float32Array(FO(s,a));return l.bindBuffer(l.PIXEL_PACK_BUFFER,e),l.getBufferSubData(l.PIXEL_PACK_BUFFER,0,u),l.bindBuffer(l.PIXEL_PACK_BUFFER,null),u}function UC(r,e,t){let n=new Float32Array(e*t*4);return ke(r,()=>r.readPixels(0,0,t,e,r.RGBA,r.FLOAT,n)),n}var Xy=class{constructor(e){this.outputTexture=null,this.program=null,this.disposed=!1,this.vertexAttrsAreBound=!1,this.itemsToPoll=[];let t=U().getNumber("WEBGL_VERSION");e!=null?(this.gl=e,tC(t,e)):this.gl=Zn(t);let n="WEBGL_color_buffer_float",o="EXT_color_buffer_half_float";if(U().getNumber("WEBGL_VERSION")===1){let s="OES_texture_float",a="OES_texture_half_float";if(this.textureFloatExtension=Tm(this.gl,s),Bn(this.gl,a))this.textureHalfFloatExtension=Tm(this.gl,a);else if(U().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");if(this.colorBufferFloatExtension=this.gl.getExtension(n),Bn(this.gl,o))this.colorBufferHalfFloatExtension=Tm(this.gl,o);else if(U().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support color renderable half floats, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.")}else if(n="EXT_color_buffer_float",Bn(this.gl,n))this.colorBufferFloatExtension=this.gl.getExtension(n);else if(Bn(this.gl,o))this.
void main ( ) {
setOutput ( vec4 ( getA ( ) , 0. , 0. , 0. ) ) ;
}
` ;else{let n=Jt("rc",t),o=Ue(t),s=wJ(t,e,n),a=_J(t,e[e.length-1],e[e.length-2],n),i=kJ(e,n);this.userCode= `
void main ( ) {
$ { o } rc = getOutputCoords ( ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( $ { s } ) {
setOutput ( vec4 ( 0 ) ) ;
} else {
$ { a }
setOutput ( vec4 ( $ { i } ) ) ;
}
}
` }}};function bJ(r,e){let t=[];for(let n=0;n<=1;n++)for(let o=0;o<=1;o++){let s= ` $ { n === 0 ? "r" : "rp1" } , $ { o === 0 ? "c" : "cp1" } ` ;for(let a=2;a<r;a++)s= ` $ { e [ e . length - 1 - a ] } , ` +s;t.push(s)}return t}function wJ(r,e,t){if(r===1)return ` rc > $ { e [ 0 ] } ` ;let n="";for(let o=r-2;o<r;o++)n+= ` $ { t [ o ] } >= $ { e [ o ] } ` ,o<r-1&&(n+="||");return n}function _J(r,e,t,n){if(r===1)return"";let o=n.slice(-2);return `
int r = $ { o [ 0 ] } ;
int c = $ { o [ 1 ] } ;
int rp1 = r + 1 ;
int cp1 = c + 1 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
bool cEdge = cp1 >= $ { e } ;
bool rEdge = rp1 >= $ { t } ;
` }function kJ(r,e){let t=r.length,n=bJ(t,e);return t===1? ` getA ( rc ) ,
rc + 1 >= $ { r [ 0 ] } ? 0. : getA ( rc + 1 ) ,
0 , 0 ` : ` getA ( $ { n [ 0 ] } ) ,
cEdge ? 0. : getA ( $ { n [ 1 ] } ) ,
rEdge ? 0. : getA ( $ { n [ 2 ] } ) ,
rEdge || cEdge ? 0. : getA ( $ { n [ 3 ] } ) ` }var Uh=class{constructor(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.customUniforms=[{name:"inputShape",type:"ivec3"}],this.outputShape=e,this.enableShapeUniforms=jt(this.outputShape.length);let n="";for(let o=0;o<4;o++){let s="thisRC = rc;";o%2==1&&(s+="thisRC.z += 1;"),o>1&&(s+="thisRC.y += 1;"),n+= `
$ { s }
$ { o > 0 ? "if(thisRC.y < rows && thisRC.z < cols){" : "" }
int flatIndex = getFlatIndex ( thisRC ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec3 inputRC = inputCoordsFromReshapedOutCoords ( flatIndex ) ;
vec2 inputRCInnerDims = vec2 ( float ( inputRC . y ) , float ( inputRC . z ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
result [ $ { o } ] =
getChannel ( getA ( inputRC . x , inputRC . y , inputRC . z ) , inputRCInnerDims ) ;
$ { o > 0 ? "}" : "" }
` }this.userCode= `
$ { vJ ( t , this . enableShapeUniforms ) }
$ { this . enableShapeUniforms ? Dm ( ) : Am ( e ) }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec3 rc = getOutputCoords ( ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 result = vec4 ( 0. ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec3 thisRC ;
int rows = $ { this . enableShapeUniforms ? "outShape[1]" : e [ 1 ] } ;
int cols = $ { this . enableShapeUniforms ? "outShape[2]" : e [ 2 ] } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { n }
setOutput ( result ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }};function vJ(r,e){return `
ivec3 inputCoordsFromReshapedOutCoords ( int index ) {
$ { e ? BO ( [ "r" , "c" , "d" ] , "inputShape" ) : Ks ( [ "r" , "c" , "d" ] , r ) }
return ivec3 ( r , c , d ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }var qC=class{constructor(e){this.gpgpu=e,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}acquireTexture(e,t,n){let o=PP(t,n),s=MP(e,o,n);s in this.freeTextures||(this.freeTextures[s]=[]),s in this.usedTextures||(this.usedTextures[s]=[]);let a=OP(e,o,this.gpgpu.gl,this.gpgpu.textureConfig,n);if(this.freeTextures[s].length>0){this.numFreeTextures--,this.numUsedTextures++,this._numBytesFree-=a,this.log();let l=this.freeTextures[s].shift();return this.usedTextures[s].push(l),l}let i;return o===Fr.PACKED_2X2_FLOAT32?i=this.gpgpu.createPackedMatrixTexture(e[0],e[1]):o===Fr.PACKED_2X2_FLOAT16?i=this.gpgpu.createFloat16PackedMatrixTexture(e[0],e[1]):o===Fr.UNPACKED_FLOAT32?i=this.gpgpu.createFloat32MatrixTexture(e[0],e[1]):o===Fr.UNPACKED_FLOAT16?i=this.gpgpu.createFloat16MatrixTexture(e[0],e[1]):o===Fr.PACKED_4X1_UNSIGNED_BYTE&&(i=this.gpgpu.createUnsignedBytesMatrixTexture(e[0],e[1])),this.usedTextures[s].push(i),this.numUsedTextures++,this._numBytesAllocated+=a,this.log(),i}releaseTexture(e,t,n,o){if(this.freeTextures==null)return;let s=PP(n,o),a=MP(t,s,o);a in this.freeTextures||(this.freeTextures[a]=[]);let i=OP(t,s,this.gpgpu.gl,this.gpgpu.textureConfig,o),l=U().get("WEBGL_DELETE_TEXTURE_THRESHOLD");l!==-1&&this._numBytesAllocated>l?(this.gpgpu.deleteMatrixTexture(e),this._numBytesAllocated-=i):(this.freeTextures[a].push(e),this.numFreeTextures++,this._numBytesFree+=i),this.numUsedTextures--;let u=this.usedTextures[a],c=u.indexOf(e);if(c<0)throw new Error("Cannot release a texture that was never provided by this texture manager");u.splice(c,1),this.log()}log(){if(!this.logEnabled)return;let e=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used", ` $ { this . numFreeTextures } / $ { this . numUsedTextures } ` , ` ( $ { e } ) ` );let t=this._numBytesFree/this._numBytesAllocated;console.log( ` Bytes allocated : $ { this . _numBytesAllocated } ` ),console.log( ` Bytes unused : $ { this . _numBytesFree } ( $ { Math . round ( 100 * t ) } % ) ` )}get numBytesAllocated(){return this._numBytesAllocated}get numBytesFree(){return this._numBytesFree}getNumUsedTextures(){return this.numUsedTextures}getNumFreeTextures(){return this.numFreeTextures}dispose(){if(this.freeTextures!=null){for(let e in this.freeTextures)this.freeTextures[e].forEach(t=>{this.gpgpu.deleteMatrixTexture(t)});for(let e in this.usedTextures)this.usedTextures[e].forEach(t=>{this.gpgpu.deleteMatrixTexture(t)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0,this._numBytesAllocated=0,this._numBytesFree=0}}};function CJ(r,e){let t=r;if(e===t.R32F)return 4;if(e===t.R16F)return 2;if(e===t.RGBA32F)return 16;if(e===r.RGBA)return 16;if(e===t.RGBA16F)return 8;throw new Error( ` Unknown internal format $ { e } ` )}function OP(r,e,t,n,o){let s=IJ(e,n),a;if(o){let[l,u]=Ai(r[0],r[1]);a=l*u}else{let[l,u]=xc(r[0],r[1]);a=l*u}let i=CJ(t,s);return a*i}function IJ(r,e){switch(r){case Fr.PACKED_2X2_FLOAT32:return qy(e);case Fr.PACKED_2X2_FLOAT16:return Ky(e);case Fr.UNPACKED_FLOAT32:return Uy(e);case Fr.UNPACKED_FLOAT16:return jy(e);case Fr.PACKED_4X1_UNSIGNED_BYTE:return Hy(e);default:throw new Error( ` Unknown physical texture type $ { r } ` )}}function SJ(r){return U().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?r?Fr.PACKED_2X2_FLOAT32:Fr.UNPACKED_FLOAT32:r?Fr.PACKED_2X2_FLOAT16:Fr.UNPACKED_FLOAT16}function PP(r,e){if(r===Ur.UPLOAD)return Fr.PACKED_2X2_FLOAT32;if(r===Ur.RENDER||r==null)return SJ(e);if(r===Ur.DOWNLOAD||r===Ur.PIXELS)return Fr.PACKED_4X1_UNSIGNED_BYTE;throw new Error( ` Unknown logical texture type $ { r } ` )}function MP(r,e,t){return ` $ { r [ 0 ] } _$ { r [ 1 ] } _$ { e } _$ { t } ` }var En=class{constructor(e,t){this.variableNames=["A"],this.outputShape=e,this.enableShapeUniforms=jt(this.outputShape.length),this.userCode= `
float unaryOperation ( float x ) {
$ { t }
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
void main ( ) {
float x = getAAtOutCoords ( ) ;
float y = unaryOperation ( x ) ;
setOutput ( y ) ;
}
` }},Nr="if (isnan(x)) return x;",LP="return x;",KC="return abs(x);";var zP="return (x >= 0.0) ? x : (exp(x) - 1.0);",BP=Nr+ `
return ( x < 0.0 ) ? 0.0 : x ;
` ,VP=Nr+ `
return ( x < 0.0 ) ? 0.0 : min ( 6.0 , x ) ;
` ,jh="return x;",GP="return 1.0 / (1.0 + exp(-1.0 * x));";var WP="return x;",UP= `
2021-09-11 17:17:13 +02:00
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 ;
2021-10-22 22:09:52 +02:00
` ,jP= `
vec4 result = x * vec4 ( greaterThanEqual ( x , vec4 ( 0.0 ) ) ) ;
bvec4 isNaN = isnan ( x ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
result . r = isNaN . r ? x . r : result . r ;
result . g = isNaN . g ? x . g : result . g ;
result . b = isNaN . b ? x . b : result . b ;
result . a = isNaN . a ? x . a : result . a ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
return result ;
` ,HP= `
vec4 result = min ( x , vec4 ( 6. ) ) * vec4 ( greaterThanEqual ( x , vec4 ( 0.0 ) ) ) ;
bvec4 isNaN = isnan ( x ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
result . r = isNaN . r ? x . r : result . r ;
result . g = isNaN . g ? x . g : result . g ;
result . b = isNaN . b ? x . b : result . b ;
result . a = isNaN . a ? x . a : result . a ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
return result ;
` ,qP="return 1.0 / (1.0 + exp(-1.0 * x));",Xs=class{constructor(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.enableShapeUniforms=jt(this.outputShape.length),this.userCode= `
vec4 unaryOperation ( vec4 x ) {
$ { t }
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
vec4 x = getAAtOutCoords ( ) ;
vec4 y = unaryOperation ( x ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( y ) ;
}
` }};var XC=class{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outputShape=e;let t=e.length,n=Jt("rc",t),o=Ue(t),s=FP(t,n),a=n.slice(-2),i=t<=1?"rc": ` vec2 ( $ { a . join ( "," ) } ) ` ;this.userCode= `
void main ( ) {
$ { o } rc = getOutputCoords ( ) ;
vec4 packedInput = getA ( $ { s } ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( getChannel ( packedInput , $ { i } ) ) ;
}
` }};var NJ=Gr.whereImpl,TJ=1e-7,EJ=1e-4,Qy={};function AJ(r){return r in Qy||(Qy[r]={}),Qy[r]}var DJ=U().getNumber("CPU_HANDOFF_SIZE_THRESHOLD"), $ J=600;function RJ(){return U().global.screen==null?1024:U().global.screen.height*U().global.screen.width*window.devicePixelRatio* $ J/1024/1024}var _c=class extends Js{constructor(e){super();if(this.pendingRead=new WeakMap,this.pendingDisposal=new WeakSet,this.dataRefCount=new WeakMap,this.numBytesInGPU=0,this.uploadWaitMs=0,this.downloadWaitMs=0,this.lastGlFlushTime=0,this.warnedAboutMemory=!1,this.pendingDeletes=0,this.disposed=!1,!U().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(e==null){let t=Zn(U().getNumber("WEBGL_VERSION"));this.binaryCache=AJ(U().getNumber("WEBGL_VERSION")),this.gpgpu=new Xy(t),this.canvas=t.canvas,this.gpgpuCreatedLocally=!0}else this.gpgpu=e,this.binaryCache={},this.gpgpuCreatedLocally=!1,this.canvas=e.gl.canvas;this.textureManager=new qC(this.gpgpu),this.numMBBeforeWarning=RJ(),this.texData=new pl(this,Es())}nextDataId(){return _c.nextDataId++}numDataIds(){return this.texData.numDataIds()-this.pendingDeletes}write(e,t,n){if((U().getBool("WEBGL_CHECK_NUMERICAL_PROBLEMS")||U().getBool("DEBUG"))&&this.checkNumericalProblems(e),n==="complex64"&&e!=null)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");let o={id:this.nextDataId()};return this.texData.set(o,{shape:t,dtype:n,values:e,usage:Ur.UPLOAD,refCount:1}),o}refCount(e){return this.texData.has(e)?this.texData.get(e).refCount:0}incRef(e){let t=this.texData.get(e);t.refCount++}decRef(e){if(this.texData.has(e)){let t=this.texData.get(e);t.refCount--}}move(e,t,n,o,s){if(U().getBool("DEBUG")&&this.checkNumericalProblems(t),o==="complex64")throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(e,{shape:n,dtype:o,values:t,usage:Ur.UPLOAD,refCount:s})}disposeIntermediateTensorInfo(e){this.disposeData(e.dataId)}readSync(e){let t=this.texData.get(e),{values:n,dtype:o,complexTensorInfos:s,slice:a,shape:i,isPacked:l}=t;if(a!=null){let m;l?m=new Xs(i,jh):m=new En(i,jh);let f=this.runWebGLProgram(m,[{dataId:e,shape:i,dtype:o}],o),d=this.readSync(f.dataId);return this.disposeIntermediateTensorInfo(f),d}if(n!=null)return this.convertAndCacheOnCPU(e);if(o==="string")return n;let u=this.activeTimers!=null,c;u&&(c=b.now());let p;if(o==="complex64"){let m=this.readSync(s.real.dataId),f=this.readSync(s.imag.dataId);p=I.mergeRealAndImagArrays(m,f)}else p=this.getValuesFromTexture(e);return u&&(this.downloadWaitMs+=b.now()-c),this.convertAndCacheOnCPU(e,p)}async read(e){if(this.pendingRead.has(e)){let d=this.pendingRead.get(e);return new Promise(h=>d.push(h))}let t=this.texData.get(e),{values:n,shape:o,slice:s,dtype:a,complexTensorInfos:i,isPacked:l}=t;if(s!=null){let d;l?d=new Xs(o,jh):d=new En(o,jh);let h=this.runWebGLProgram(d,[{dataId:e,shape:o,dtype:a}],a),g=this.read(h.dataId);return this.disposeIntermediateTensorInfo(h),g}if(n!=null)return this.convertAndCacheOnCPU(e);if(!U().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&&U().getNumber("WEBGL_VERSION")===2)throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");let u=null,c;if(a!=="complex64"&&U().get("WEBGL_BUFFER_SUPPORTED")){c=this.decode(e);let d=this.texData.get(c.dataId);u=this.gpgpu.createBufferFromTexture(d.texture,...Lh(o))}this.pendingRead.set(e,[]),a!=="complex64"&&await this.gpgpu.createAndWaitForFence();let p;if(a==="complex64"){let d=await Promise.all([this.read(i.real.dataId),this.read(i.imag.dataId)]),h=d[0],g=d[1];p=I.mergeRealAndImagArrays(h,g)}else if(u==null)p=this.getValuesFromTexture(e);else{let d=b.sizeFromShape(o);p=this.gpgpu.downloadFloat32MatrixFromBuffer(u,d)}if(c!=null&&this.disposeIntermediateTensorInfo(c),u!=null){let d=this.gpgpu.gl;ke(d,()=>d.deleteBuffer(u))}let m=this.convertAndCacheOnCPU(e,p),f=this.pendingRead.get(e);return this.pendingRead.delete(e),f.forEach(d=>d(m)),this.pendingDisposal.has(e)&&(this.pendingDisposal.delete(e),this.disposeData(e)&&Es().
if ( isnan ( a ) ) return a ;
if ( isnan ( b ) ) return b ;
` ;var No=class{constructor(e,t,n){this.variableNames=["A","B"],this.outputShape=I.assertAndGetBroadcastShape(t,n),this.enableShapeUniforms=jt(this.outputShape.length),this.userCode= `
float binaryOperation ( float a , float b ) {
$ { e }
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
float a = getAAtOutCoords ( ) ;
float b = getBAtOutCoords ( ) ;
setOutput ( binaryOperation ( a , b ) ) ;
}
` }};var Kl= `
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 ;
` ;var Ys=class{constructor(e,t,n,o=!1){this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.packedInputs=!0,this.packedOutput=!0,this.outputShape=I.assertAndGetBroadcastShape(t,n);let s=this.outputShape.length;this.enableShapeUniforms=jt(s);let a="";if(o)if(s===0||b.sizeFromShape(this.outputShape)===1)a= `
result . y = 0. ;
result . z = 0. ;
result . w = 0. ;
` ;else if(a= `
$ { Ue ( s ) } coords = getOutputCoords ( ) ;
` ,s===1)this.enableShapeUniforms?a+= `
result . y = ( coords + 1 ) >= outShape ? 0. : result . y ;
result . z = 0. ;
result . w = 0. ;
` :a+= `
result . y = ( coords + 1 ) >= $ { this . outputShape [ 0 ] } ? 0. : result . y ;
result . z = 0. ;
result . w = 0. ;
` ;else{let l=Jt("coords",s);this.enableShapeUniforms?a+= `
bool nextRowOutOfBounds =
( $ { l [ s - 2 ] } + 1 ) >= outShape [ $ { s } - 2 ] ;
bool nextColOutOfBounds =
( $ { l [ s - 1 ] } + 1 ) >= outShape [ $ { s } - 1 ] ;
result . y = nextColOutOfBounds ? 0. : result . y ;
result . z = nextRowOutOfBounds ? 0. : result . z ;
result . w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result . w ;
` :a+= `
bool nextRowOutOfBounds =
( $ { l [ s - 2 ] } + 1 ) >= $ { this . outputShape [ s - 2 ] } ;
bool nextColOutOfBounds =
( $ { l [ s - 1 ] } + 1 ) >= $ { this . outputShape [ s - 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 ) {
$ { e }
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
void main ( ) {
vec4 a = getAAtOutCoords ( ) ;
vec4 b = getBAtOutCoords ( ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 result = binaryOperation ( a , b ) ;
$ { a }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( result ) ;
}
` }};function Qt(r){let{inputs:e,backend:t}=r,{x:n}=e;return t.incRef(n.dataId),{dataId:n.dataId,shape:n.shape,dtype:n.dtype}}var YP={kernelName:ro,backendName:"webgl",kernelFunc:Qt};function An(r){let{inputs:e,backend:t}=r,{real:n,imag:o}=e,s=t.makeTensorInfo(n.shape,"complex64"),a=t.texData.get(s.dataId),i=Qt({inputs:{x:n},backend:t}),l=Qt({inputs:{x:o},backend:t});return a.complexTensorInfos={real:i,imag:l},s}var ZP={kernelName:qc,backendName:"webgl",kernelFunc:An};var YC="return (a < 0.) ? b * a : a;",ZC= `
vec4 aLessThanZero = vec4 ( lessThan ( a , vec4 ( 0. ) ) ) ;
return ( aLessThanZero * ( b * a ) ) + ( ( vec4 ( 1.0 ) - aLessThanZero ) * a ) ;
` ;function OJ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{alpha:s}=n,a=t.makeTensorInfo([],"float32",b.createScalarValue(s,"float32")),i=U().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Ys(ZC,o.shape,a.shape):new No(YC,o.shape,a.shape),l=t.runWebGLProgram(i,[o,a],"float32");return t.disposeIntermediateTensorInfo(a),l}var JP={kernelName:Yo,backendName:"webgl",kernelFunc:OJ};var JC="return (a < 0.) ? b * a : a;",QC= `
vec4 aLessThanZero = vec4 ( lessThan ( a , vec4 ( 0. ) ) ) ;
return ( aLessThanZero * ( b * a ) ) + ( ( vec4 ( 1.0 ) - aLessThanZero ) * a ) ;
` ;function PJ(r){let{inputs:e,backend:t}=r,{x:n,alpha:o}=e,s=U().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Ys(QC,n.shape,o.shape):new No(JC,n.shape,o.shape);return t.runWebGLProgram(s,[n,o],"float32")}var QP={kernelName:us,backendName:"webgl",kernelFunc:PJ};var tb="if (isnan(x)) return x;",eM= `
if ( isnan ( a ) ) return a ;
if ( isnan ( b ) ) return b ;
` ,tM= `
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 ;
` ;function ve({opSnippet:r,packedOpSnippet:e,cpuKernelImpl:t,dtype:n}){return({inputs:o,backend:s})=>{let{x:a}=o,i=s,l=n||a.dtype;if(i.shouldExecuteOnCPU([a])&&t!=null){let p=i.texData.get(a.dataId),m=t(p.values,l);return i.makeTensorInfo(a.shape,l,m)}let u=U().getBool("WEBGL_PACK_UNARY_OPERATIONS")&&e!=null,c;return u?c=new Xs(a.shape,e):c=new En(a.shape,r),i.runWebGLProgram(c,[a],l)}}function at({opSnippet:r,packedOpSnippet:e,checkOutOfBounds:t=!1,supportsComplex:n=!1,cpuKernelImpl:o,dtype:s}){return({inputs:a,backend:i})=>{let{a:l,b:u}=a,c=i;if(n&&l.dtype==="complex64"){let d=c.texData.get(l.dataId),h=c.texData.get(u.dataId),[g,x]=[[d.complexTensorInfos.real,h.complexTensorInfos.real],[d.complexTensorInfos.imag,h.complexTensorInfos.imag]].map(w=>{let[_,C]=w,A={dataId:_.dataId,dtype:_.dtype,shape:l.shape},D={dataId:C.dataId,dtype:C.dtype,shape:u.shape},R=new No(r,l.shape,u.shape);return c.runWebGLProgram(R,[A,D],hr(_.dtype,C.dtype))}),y=An({inputs:{real:g,imag:x},backend:c});return c.disposeIntermediateTensorInfo(g),c.disposeIntermediateTensorInfo(x),y}let p=s||hr(l.dtype,u.dtype);if((l.dtype==="string"||u.dtype==="string"||c.shouldExecuteOnCPU([l,u]))&&o!=null){let d=c.texData.get(l.dataId).values,h=c.texData.get(u.dataId).values,g=l.dtype==="string"?I.fromUint8ToStringArray(d):d,x=l.dtype==="string"?I.fromUint8ToStringArray(h):h,[y,w]=o(l.shape,u.shape,g,x,p),_=c.makeTensorInfo(w,p),C=c.texData.get(_.dataId);return C.values=y,_}let m=U().getBool("WEBGL_PACK_BINARY_OPERATIONS")&&e!=null,f;return m?f=new Ys(e,l.shape,u.shape,t):f=new No(r,l.shape,u.shape),c.runWebGLProgram(f,[l,u],p)}}function Xl(r,e=!1){if(r==="linear")return e?WP:LP;if(r==="relu")return e?jP:BP;if(r==="elu")return e?UP:zP;if(r==="relu6")return e?HP:VP;if(r==="prelu")return e?QC:JC;if(r==="leakyrelu")return e?ZC:YC;if(r==="sigmoid")return e?qP:GP;throw new Error( ` Activation $ { r } has not been implemented for the WebGL backend . ` )}var Hh=class{constructor(e,t,n,o=!1,s=!1,a=!1,i=null,l=!1,u=!1){this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=n,this.enableShapeUniforms=jt(this.outputShape.length);let c=o?e[1]:e[2],p=Math.ceil(c/2),m=o?"i * 2, rc.y":"rc.y, i * 2",f=s?"rc.z, i * 2":"i * 2, rc.z",d=o?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],h=s?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],g="",x="";i&&(l?g= ` vec4 activation ( vec4 a ) {
vec4 b = getPreluActivationWeightsAtOutCoords ( ) ;
$ { i }
} ` :u?g= ` vec4 activation ( vec4 a ) {
vec4 b = getLeakyreluAlphaAtOutCoords ( ) ;
$ { i }
} ` :g= ` vec4 activation ( vec4 x ) {
$ { i }
} ` ,x="result = activation(result);");let y=a?"result += getBiasAtOutCoords();":"";a&&this.variableNames.push("bias"),l&&this.variableNames.push("preluActivationWeights"),u&&this.variableNames.push("leakyreluAlpha");let w="rc.x",_="rc.x";e[0]<t[0]?w= ` int ( min ( float ( rc . x ) , $ { e [ 0 ] - 1 } . ) ) ` :t[0]<e[0]&&(_= ` int ( min ( float ( rc . x ) , $ { t [ 0 ] - 1 } . ) ) ` ),this.userCode= `
$ { g }
// Don't use uniform for sharedDimensionPacked for performance.
const float sharedDimension = $ { p } . 0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 dot2x2ARowBCol ( ivec3 rc ) {
vec4 result = vec4 ( 0 ) ;
for ( int i = 0 ; i < $ { p } ; i ++ ) {
int batchA = $ { w } ;
int batchB = $ { _ } ;
vec4 a = getMatrixA ( batchA , $ { m } ) ;
vec4 b = getMatrixB ( batchB , $ { f } ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// These swizzled products need to be separately added.
// See: https://github.com/tensorflow/tfjs/issues/1735
result += ( $ { d [ 0 ] } * $ { h [ 0 ] } ) ;
result += ( $ { d [ 1 ] } * $ { h [ 1 ] } ) ;
}
2021-09-11 17:17:13 +02:00
return result ;
}
void main ( ) {
2021-10-22 22:09:52 +02:00
ivec3 rc = getOutputCoords ( ) ;
vec4 result = dot2x2ARowBCol ( rc ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { y }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { x }
setOutput ( result ) ;
}
` }};var eI={REAL:"return areal * breal - aimag * bimag;",IMAG:"return areal * bimag + aimag * breal;"},rb=class{constructor(e,t,n){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=I.assertAndGetBroadcastShape(t,n),this.userCode= `
float binaryOpComplex (
float areal , float aimag , float breal , float bimag ) {
$ { e }
}
2021-09-11 17:17:13 +02:00
void main ( ) {
2021-10-22 22:09:52 +02:00
float areal = getARealAtOutCoords ( ) ;
float aimag = getAImagAtOutCoords ( ) ;
float breal = getBRealAtOutCoords ( ) ;
float bimag = getBImagAtOutCoords ( ) ;
setOutput ( binaryOpComplex ( areal , aimag , breal , bimag ) ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }};var rM="return a * b;";function qh(r){let{inputs:e,backend:t}=r,{a:n,b:o}=e,s=I.upcastType(n.dtype,o.dtype);if(n.dtype==="complex64"){let i=t.texData.get(n.dataId),l=t.texData.get(o.dataId),u=new rb(eI.REAL,n.shape,o.shape),c=new rb(eI.IMAG,n.shape,o.shape),p=[{dataId:i.complexTensorInfos.real.dataId,dtype:i.complexTensorInfos.real.dtype,shape:n.shape},{dataId:i.complexTensorInfos.imag.dataId,dtype:i.complexTensorInfos.imag.dtype,shape:n.shape},{dataId:l.complexTensorInfos.real.dataId,dtype:l.complexTensorInfos.real.dtype,shape:o.shape},{dataId:l.complexTensorInfos.imag.dataId,dtype:l.complexTensorInfos.imag.dtype,shape:o.shape}],m=t.runWebGLProgram(u,p,"float32"),f=t.runWebGLProgram(c,p,"float32"),d=An({inputs:{real:m,imag:f},backend:t});return t.disposeIntermediateTensorInfo(m),t.disposeIntermediateTensorInfo(f),d}if(t.shouldExecuteOnCPU([n,o])){let i=t.texData.get(n.dataId),l=t.texData.get(o.dataId),[u,c]=hP(n.shape,o.shape,i.values,l.values,s),p=t.makeTensorInfo(c,s),m=t.texData.get(p.dataId);return m.values=u,p}let a;return U().getBool("WEBGL_PACK_BINARY_OPERATIONS")?a=new Ys(rM,n.shape,o.shape):a=new No(rM,n.shape,o.shape),t.runWebGLProgram(a,[n,o],s)}var nM={kernelName:ss,backendName:"webgl",kernelFunc:qh};function oM(r,e,t){let n=[Qa(r.shape),...el(r.shape)],o={dtype:r.dtype,shape:n,dataId:r.dataId},s=[Qa(e),...el(e)],a=new Uh(s,n),i=!0,l=[n],u=t.runWebGLProgram(a,[o],r.dtype,l,i);return{dataId:u.dataId,shape:e,dtype:u.dtype}}function ue(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{shape:s}=n,a=t,i=b.sizeFromShape(o.shape),l=b.inferFromImplicitShape(s,i),u=b.sizeFromShape(l);b.assert(i===u,()=> ` The new shape ( $ { l } ) has $ { u } elements and the old shape ( $ { o . shape } ) has $ { i } elements . The new shape and old shape must have the same number of elements . ` );let c=a.texData.get(o.dataId);return c.isPacked&&!ql(o.shape,l)&&!(c.texture!==null&&ql(c.shape,l))?oM(o,l,a):(a.incRef(o.dataId),{dataId:o.dataId,shape:l,dtype:o.dtype})}var sM={kernelName:ui,backendName:"webgl",kernelFunc:ue};var nb=class{constructor(e,t){this.variableNames=["x"];let{windowSize:n,batchSize:o,inSize:s,outSize:a}=e;this.outputShape=[o,a];let i=Math.floor(n/4)*4,l=n%4,u="sumValue += dot(values, ones);";if(t!=null){let p=1/t;u= ` sumValue += dot ( values * $ { b . isInt ( p ) ? p . toPrecision ( 2 ) : p } , ones ) ; ` }let c="";s%n>0&&(c= `
if ( inIdx < 0 || inIdx >= $ { s } ) {
return 0.0 ;
}
` ),this.userCode= `
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float getValue ( int batch , int inIdx ) {
$ { c }
return getX ( batch , inIdx ) ;
}
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
int inOffset = outIdx * $ { n } ;
float sumValue = 0.0 ;
for ( int i = 0 ; i < $ { i } ; i += 4 ) {
int inIdx = inOffset + i ;
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
getValue ( batch , inIdx + 3 )
) ;
$ { u }
}
int inIdx = inOffset + $ { i } ;
if ( $ { l === 1 } ) {
vec4 values = vec4 ( getValue ( batch , inIdx ) , 0.0 , 0.0 , 0.0 ) ;
$ { u }
} else if ( $ { l === 2 } ) {
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) , 0.0 , 0.0 ) ;
$ { u }
} else if ( $ { l === 3 } ) {
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) , 0.0 ) ;
$ { u }
}
setOutput ( sumValue ) ;
}
` }};var tI=class{constructor(e,t){this.variableNames=["x"];let{windowSize:n,batchSize:o,inSize:s,outSize:a}=e;this.outputShape=[o,a];let i="0.0",l="";t==="prod"?i="1.0":t==="min"?(i="1.0 / 1e-20",l="min"):t==="max"&&(i="-1.0 / 1e-20",l="max");let u= ` $ { t } ( $ { t } ( $ { t } ( minMaxValue [ 0 ] , minMaxValue [ 1 ] ) , minMaxValue [ 2 ] ) , minMaxValue [ 3 ] ) ` ;t==="sum"?u="sumValue":t==="prod"?u="prodValue":t==="all"?u="allValue":t==="any"&&(u="anyValue");let c=Math.floor(n/4)*4,p=n%4,m= `
if ( $ { t === "sum" } ) {
sumValue += dot ( values , ones ) ;
} else if ( $ { t === "prod" } ) {
vec2 tmp = vec2 ( values [ 0 ] , values [ 1 ] ) * vec2 ( values [ 2 ] , values [ 3 ] ) ;
prodValue *= tmp [ 0 ] * tmp [ 1 ] ;
} else {
minMaxValue = $ { l } ( values , minMaxValue ) ;
if ( $ { t === "min" } || $ { t === "max" } ) {
minMaxValue = $ { l } ( values , minMaxValue ) ;
bvec4 isNaN = isnan ( values ) ;
if ( isNaN . r || isNaN . g || isNaN . b || isNaN . a ) {
minMaxValue = vec4 ( NAN ) ;
}
}
}
` ,f="vec4";t==="all"?(i="1.0",m= `
bool reducedAllValue = all ( values ) ;
float floatedReducedAllValue = float ( reducedAllValue ) ;
allValue = float ( allValue >= 1.0 && floatedReducedAllValue >= 1.0 ) ;
` ,f="bvec4"):t==="any"&&(i="0.0",m= `
bool reducedAnyValue = any ( values ) ;
float floatedReducedAnyValue = float ( reducedAnyValue ) ;
anyValue = float ( anyValue >= 1.0 || floatedReducedAnyValue >= 1.0 ) ;
` ,f="bvec4");let d="";s%n>0&&(d= `
if ( inIdx < 0 || inIdx >= $ { s } ) {
return initializationValue ;
}
` ),this.userCode= `
const float initializationValue = $ { i } ;
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float getValue ( int batch , int inIdx ) {
$ { d }
return getX ( batch , inIdx ) ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
int inOffset = outIdx * $ { n } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 minMaxValue = vec4 ( $ { i } ) ;
float prodValue = 1.0 ;
float sumValue = 0.0 ;
float allValue = 1.0 ;
float anyValue = 0.0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int i = 0 ; i < $ { c } ; i += 4 ) {
int inIdx = inOffset + i ;
$ { f } values = $ { f } (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
getValue ( batch , inIdx + 3 )
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { m }
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int inIdx = inOffset + $ { c } ;
if ( $ { p === 1 } ) {
$ { f } values = $ { f } (
getValue ( batch , inIdx ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { m }
} else if ( $ { p === 2 } ) {
$ { f } values = $ { f } (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
initializationValue ,
initializationValue
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { m }
} else if ( $ { p === 3 } ) {
$ { f } values = $ { f } (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
initializationValue
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { m }
}
setOutput ( $ { u } ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }};function MJ(r){let e=[];for(;e.length===0||e[e.length-1].outSize!==1;){let t=e.length?e[e.length-1].outSize:r[1],n=I.computeOptimalWindowSize(t);e.push({inSize:t,windowSize:n,outSize:Math.ceil(t/n)})}return e}function Vn(r,e,t,n){let o=MJ(r.shape),s=r;for(let a=0;a<o.length;a++){let{inSize:i,windowSize:l,outSize:u}=o[a],c,p;t==="mean"?c=a===0?new nb({windowSize:l,inSize:i,batchSize:r.shape[0],outSize:u},i):new nb({windowSize:l,inSize:i,batchSize:r.shape[0],outSize:u}):c=new tI({windowSize:l,inSize:i,batchSize:r.shape[0],outSize:u},t),p=s,s=n.runWebGLProgram(c,[s],e),p.dataId!==r.dataId&&n.disposeIntermediateTensorInfo(p)}return s}var rI=class{constructor(e,t){this.variableNames=["A"];let n=new Array(e.length);for(let a=0;a<n.length;a++)n[a]=e[t[a]];this.outputShape=n,this.rank=n.length;let o=Ue(this.rank),s=LJ(t);this.userCode= `
void main ( ) {
$ { o } resRC = getOutputCoords ( ) ;
setOutput ( getA ( $ { s } ) ) ;
}
` }};function LJ(r){let e=r.length;if(e>6)throw Error( ` Transpose for rank $ { e } is not yet supported ` );let t=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],n=new Array(e);for(let o=0;o<r.length;o++)n[r[o]]=t[o];return n.join()}var nI=class{constructor(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0;let n=new Array(e.length);for(let c=0;c<n.length;c++)n[c]=e[t[c]];if(this.outputShape=n,this.rank=n.length,this.rank>6)throw Error( ` Packed transpose for rank $ { this . rank } is not yet supported . ` );let o=Ue(this.rank),s=jC("rc",this.rank),a=new Array(this.rank);for(let c=0;c<t.length;c++)a[t[c]]=s[c];let i= ` vec2 ( $ { a . slice ( - 2 ) . join ( ) } ) ` ,l= ` ++ $ { s [ this . rank - 1 ] } < $ { n [ this . rank - 1 ] } ` ,u= ` getChannel ( getA ( $ { a . join ( ) } ) , $ { i } ) ` ;this.userCode= `
void main ( ) {
$ { o } rc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
result [ 0 ] = $ { u } ;
if ( $ { l } ) {
result [ 1 ] = $ { u } ;
}
-- $ { s [ this . rank - 1 ] } ;
if ( ++ $ { s [ this . rank - 2 ] } < $ { n [ this . rank - 2 ] } ) {
result [ 2 ] = $ { u } ;
if ( $ { l } ) {
result [ 3 ] = $ { u } ;
}
}
setOutput ( result ) ;
}
` }};function Yl(r,e,t){let n=U().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new nI(r.shape,e):new rI(r.shape,e);return t.runWebGLProgram(n,[r],r.dtype)}function iM(r,e,t,n){let o=e,s=r.shape.length,a=b.parseAxisParam(o,r.shape),i=a,l=I.getAxesPermutation(i,s),u=l!=null,c=r;u&&(c=Yl(r,l,n),i=I.getInnerMostAxes(i.length,s)),I.assertAxesAreInnerMostDims("sum",i,s);let[p,m]=I.computeOutAndReduceShapes(c.shape,i),f=p;t&&(f=I.expandShapeToKeepDim(p,a));let d=b.sizeFromShape(m),g=b.sizeFromShape(r.shape)/d,x=ue({inputs:{x:c},attrs:{shape:[g,d]},backend:n}),y=hu(r.dtype),w=Vn(x,y,"sum",n),_=ue({inputs:{x:w},attrs:{shape:f},backend:n});return n.disposeIntermediateTensorInfo(x),n.disposeIntermediateTensorInfo(w),u&&n.disposeIntermediateTensorInfo(c),_}function kc(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{axis:s,keepDims:a}=n;return iM(o,s,a,t)}var aM={kernelName:bs,backendName:"webgl",kernelFunc:kc};function Pt(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{perm:s}=n,a=t,i=o.shape.length,l=new Array(i);for(let c=0;c<l.length;c++)l[c]=o.shape[s[c]];let u;if(a.shouldExecuteOnCPU([o])){let p=a.texData.get(o.dataId).values,m=wc(p,o.shape,o.dtype,s,l);u=a.makeTensorInfo(l,o.dtype);let f=a.texData.get(u.dataId);f.values=m}else u=Yl(o,s,a);return u}var lM={kernelName:Is,backendName:"webgl",kernelFunc:Pt};var oI=1e3;function vc({a:r,b:e,transposeA:t,transposeB:n,backend:o,bias:s=null,preluActivationWeights:a=null,leakyreluAlpha:i=0,activation:l=null}){let u=r.shape.length,c=e.shape.length,p=t?r.shape[u-2]:r.shape[u-1],m=n?e.shape[c-1]:e.shape[c-2],f=t?r.shape[u-1]:r.shape[u-2],d=n?e.shape[c-2]:e.shape[c-1],h=r.shape.slice(0,-2),g=e.shape.slice(0,-2),x=b.sizeFromShape(h),y=b.sizeFromShape(g),w=x===y||x===1||y===1;b.assert(u>=2&&c>=2&&w,()=> ` Error in matMul : the input batch dimensions must either be the same or at least one input batch dimension must be 1. Got input batch dimensions of ( $ { h } ) and ( $ { g } ) . ` );let C=(x>y?r.shape.slice(0,-2):e.shape.slice(0,-2)).concat([f,d]);b.assert(p===m,()=> ` Error in matMul : inner shapes ( $ { p } ) and ( $ { m } ) of Tensors with shapes $ { r . shape } and $ { e . shape } and transposeA = $ { t } and transposeB = $ { n } must match . ` );let A=t?[x,p,f]:[x,f,p],D=n?[y,d,m]:[y,m,d],R=ue({inputs:{x:r},backend:o,attrs:{shape:A}}),P=ue({inputs:{x:e},backend:o,attrs:{shape:D}}),L=[R,P],G=Math.max(x,y),W=t?R.shape[1]:R.shape[2],j=s!=null,H=a!=null,q=l==="leakyrelu",X=l!=null?Xl(l,!0):null,re=j||H||q||X!=null,J;if((f===1||d===1)&&W>oI&&re===!1){let se=R,ne=P;t&&(se=Pt({inputs:{x:R},backend:o,attrs:{perm:[0,2,1]}}),L.push(se)),n&&(ne=Pt({inputs:{x:P},backend:o,attrs:{perm:[0,2,1]}}),L.push(ne));let fe=d!==1,ae=d===1,ge=se;fe&&(ge=ue({inputs:{x:se},backend:o,attrs:{shape:[G,W,1]}}),L.push(ge));let de=d===1?2:1,ye=ne;ae&&(ye=ue({inputs:{x:ne},backend:o,attrs:{shape:[G,1,W]}}),L.push(ye));let _e=qh({inputs:{a:ge,b:ye},backend:o});J=kc({inputs:{x:_e},backend:o,attrs:{axis:de,keepDims:!0}}),L.push(_e)}else{let se=hr(r.dtype,e.dtype),ne=new Hh(A,D,[G,f,d],t,n,j,X,H,q),fe=[R,P];if(s!=null&&fe.push(s),H&&fe.push(a),q){let ae=o.makeTensorInfo([],"float32",b.createScalarValue(i,"float32"));fe.push(ae),L.push(ae)}J=o.runWebGLProgram(ne,fe,se)}let oe=ue({inputs:{x:J},backend:o,attrs:{shape:C}});L.push(J);for(let se of L)o.disposeIntermediateTensorInfo(se);return oe}function zJ(r){let{inputs:e,backend:t,attrs:n}=r,{a:o,b:s,bias:a,preluActivationWeights:i}=e,{transposeA:l,transposeB:u,activation:c,leakyreluAlpha:p}=n;return vc({a:o,b:s,transposeA:l,transposeB:u,backend:t,bias:a,preluActivationWeights:i,leakyreluAlpha:p,activation:c})}var uM={kernelName:gi,backendName:"webgl",kernelFunc:zJ};var cM="return abs(x);";function BJ(r){let{inputs:e,backend:t}=r,{x:n}=e;if(t.shouldExecuteOnCPU([n])&&n.dtype!=="complex64"){let s=t.texData.get(n.dataId),a=Zy(s.values);return t.makeTensorInfo(n.shape,n.dtype,a)}let o;return U().getBool("WEBGL_PACK_UNARY_OPERATIONS")?o=new Xs(n.shape,cM):o=new En(n.shape,cM),t.runWebGLProgram(o,[n],n.dtype)}var pM={kernelName:ti,backendName:"webgl",kernelFunc:BJ};var VJ=Nr+ `
if ( abs ( x ) > 1. ) {
return NAN ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
return acos ( x ) ;
` ,GJ=ve({opSnippet:VJ}),mM={kernelName:Mi,backendName:"webgl",kernelFunc:GJ};var WJ=Nr+ `
if ( x < 1.0 ) return NAN ;
return log ( x + sqrt ( x * x - 1.0 ) ) ; ` ,UJ=ve({opSnippet:WJ}),fM={kernelName:Li,backendName:"webgl",kernelFunc:UJ};var dM="return a + b;",jJ=at({opSnippet:dM,packedOpSnippet:dM,supportsComplex:!0,cpuKernelImpl:YO}),hM={kernelName:jn,backendName:"webgl",kernelFunc:jJ};var sI=class{constructor(e,t){this.outputShape=[],this.outputShape=e,this.variableNames=t.map((s,a)=> ` T$ { a } ` );let n=[];this.variableNames.forEach(s=>{n.push( ` float v$ { s } = get$ { s } AtOutCoords ( ) ; ` )});let o=this.variableNames.map(s=> ` v$ { s } ` ).join(" + ");this.userCode= `
2021-09-11 17:17:13 +02:00
void main ( ) {
2021-10-22 22:09:52 +02:00
$ { n . join ( `
` )}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float result = $ { o } ;
setOutput ( result ) ;
}
` }};var iI=class{constructor(e,t){this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.variableNames=t.map((s,a)=> ` T$ { a } ` );let n=[];this.variableNames.forEach(s=>{n.push( ` vec4 v$ { s } = get$ { s } AtOutCoords ( ) ; ` )});let o=this.variableNames.map(s=> ` v$ { s } ` ).join(" + ");this.userCode= `
void main ( ) {
$ { n . join ( `
` )}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 result = $ { o } ;
setOutput ( result ) ;
}
` }};function ob(r){let{inputs:e,backend:t}=r,n=e;if(n.length===1)return Qt({inputs:{x:n[0]},backend:t});if(n.length>U().get("WEBGL_MAX_TEXTURES_IN_SHADER")){let l=Math.floor(n.length/2),u=ob({inputs:n.slice(0,l),backend:t}),c=ob({inputs:n.slice(l),backend:t});return ob({inputs:[u,c],backend:t})}let o=n.map(l=>l.dtype).reduce((l,u)=>hr(l,u)),s=n.map(l=>l.shape),i=U().getBool("WEBGL_PACK")?new iI(n[0].shape,s):new sI(n[0].shape,s);return t.runWebGLProgram(i,n,o)}var gM={kernelName: $ o,backendName:"webgl",kernelFunc:ob};function HJ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{axis:s,keepDims:a}=n,i=o.shape.length,l=b.parseAxisParam(s,o.shape),u=l,c=I.getAxesPermutation(u,i),p=o;c!=null&&(p=Pt({inputs:{x:o},backend:t,attrs:{perm:c}}),u=I.getInnerMostAxes(u.length,i)),I.assertAxesAreInnerMostDims("all",u,i);let[m,f]=I.computeOutAndReduceShapes(p.shape,u),d=b.sizeFromShape(f),h=ue({inputs:{x:p},backend:t,attrs:{shape:[-1,d]}}),g=Vn(h,h.dtype,"all",t),x;if(a){let y=I.expandShapeToKeepDim(m,l);x=ue({inputs:{x:g},backend:t,attrs:{shape:y}})}else x=ue({inputs:{x:g},backend:t,attrs:{shape:m}});return t.disposeIntermediateTensorInfo(h),t.disposeIntermediateTensorInfo(g),c!=null&&t.disposeIntermediateTensorInfo(p),x}var xM={kernelName:zi,backendName:"webgl",kernelFunc:HJ};function qJ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{axis:s,keepDims:a}=n,i=o.shape.length,l=b.parseAxisParam(s,o.shape),u=l,c=I.getAxesPermutation(u,i),p=o;c!=null&&(p=Pt({inputs:{x:o},backend:t,attrs:{perm:c}}),u=I.getInnerMostAxes(u.length,i)),I.assertAxesAreInnerMostDims("any",u,i);let[m,f]=I.computeOutAndReduceShapes(p.shape,u),d=b.sizeFromShape(f),h=ue({inputs:{x:p},backend:t,attrs:{shape:[-1,d]}}),g=Vn(h,h.dtype,"any",t),x;if(a){let y=I.expandShapeToKeepDim(m,l);x=ue({inputs:{x:g},backend:t,attrs:{shape:y}})}else x=ue({inputs:{x:g},backend:t,attrs:{shape:m}});return t.disposeIntermediateTensorInfo(h),t.disposeIntermediateTensorInfo(g),c!=null&&t.disposeIntermediateTensorInfo(p),x}var yM={kernelName:Bi,backendName:"webgl",kernelFunc:qJ};var aI=class{constructor(e,t,n){this.variableNames=["A"];let{windowSize:o,batchSize:s,outSize:a}=e;n||this.variableNames.push("bestIndicesA"),this.outputShape=[s,a];let i=t==="max"?">":"<",l=n?"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 * $ { o } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int bestIndex = inOffset ;
float bestValue = getA ( batch , bestIndex ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int i = 0 ; i < $ { o } ; i ++ ) {
int inIdx = $ { l } ;
float candidate = getA ( batch , inIdx ) ;
if ( candidate $ { i } bestValue ) {
bestValue = candidate ;
bestIndex = inIdx ;
2021-09-11 17:17:13 +02:00
}
}
2021-10-22 22:09:52 +02:00
setOutput ( float ( bestIndex ) ) ;
}
` }};var lI=class{constructor(e,t,n,o){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,b.assert(e.length>2,()=> ` Packed arg$ { n . charAt ( 0 ) . toUpperCase ( ) + n . slice ( 1 ) } supports only inputs with rank above 2. ` );let s=e[e.length-1],a=Math.ceil(s/t);this.outputShape=e.slice(0,-1),a>1&&this.outputShape.push(a),o||this.variableNames.push("bestIndicesA");let i=this.outputShape,l=i.length,u=Ue(l),c=Jt("coords",l),p,m;if(a===1){m=l+1;let R=Ue(m);p= `
$ { R } sourceLocR = $ { R } ( $ { c . join ( ) } , 0 ) ;
++ $ { c [ l - 1 ] } ;
$ { R } sourceLocG = $ { R } ( $ { c . join ( ) } , 0 ) ;
++ $ { c [ l - 2 ] } ;
$ { R } sourceLocA = $ { R } ( $ { c . join ( ) } , 0 ) ;
-- $ { c [ l - 1 ] } ;
$ { R } sourceLocB = $ { R } ( $ { c . join ( ) } , 0 ) ;
-- $ { c [ l - 2 ] } ; ` }else m=l,p= `
$ { u } sourceLocR = coords ;
++ $ { c [ l - 1 ] } ;
$ { u } sourceLocG = coords ;
++ $ { c [ l - 2 ] } ;
$ { u } sourceLocA = coords ;
-- $ { c [ l - 1 ] } ;
$ { u } sourceLocB = coords ;
-- $ { c [ l - 2 ] } ; ` ;let f=["x","y","z","w","u","v"].slice(0,m),d="."+f[m-1],h=f.map(R=>"int "+R),g=Jt("sourceLocR",m-1).concat("inIdx.r"),x=Jt("sourceLocG",m-1).concat("inIdx.g"),y=Jt("sourceLocB",m-1).concat("inIdx.b"),w=Jt("sourceLocA",m-1).concat("inIdx.a"),_=n==="max"?"greaterThan":"lessThan",C=o?"": `
inIdx = round ( vec4 ( getBestIndicesAChannel ( $ { g . join ( ) } ) ,
getBestIndicesAChannel ( $ { x . join ( ) } ) ,
getBestIndicesAChannel ( $ { y . join ( ) } ) ,
getBestIndicesAChannel ( $ { w . join ( ) } ) ) ) ; ` ,A= ` vec4 (
getAChannel ( $ { g . join ( ) } ) ,
hasNextCol ? getAChannel ( $ { x . join ( ) } ) : 0. ,
hasNextRow ? getAChannel ( $ { y . join ( ) } ) : 0. ,
hasNextRow && hasNextCol ? getAChannel ( $ { w . join ( ) } ) : 0. ) ` ,D=o?"": `
float getBestIndicesAChannel ( $ { h . join ( ) } ) {
return getChannel ( getBestIndicesA ( $ { f . join ( ) } ) ,
vec2 ( $ { f . slice ( - 2 ) . join ( ) } ) ) ;
} ` ;this.userCode= `
float getAChannel ( $ { h . join ( ) } ) {
return getChannel ( getA ( $ { f . join ( ) } ) ,
vec2 ( $ { f . slice ( - 2 ) . join ( ) } ) ) ;
}
$ { D }
void main ( ) {
$ { u } coords = getOutputCoords ( ) ;
bool hasNextCol = $ { c [ l - 1 ] } < $ { i [ l - 1 ] - 1 } ;
bool hasNextRow = $ { c [ l - 2 ] } < $ { i [ l - 2 ] - 1 } ;
$ { p }
ivec4 srcIdx = ivec4 ( sourceLocR$ { d } , sourceLocG$ { d } ,
sourceLocB$ { d } , sourceLocA$ { d } ) * $ { t } ;
ivec4 inIdx = srcIdx ;
vec4 bestIndex = vec4 ( inIdx ) ;
vec4 bestValue = $ { A } ;
for ( int i = 0 ; i < $ { t } ; i ++ ) {
inIdx = srcIdx ;
$ { C }
vec4 candidate = $ { A } ;
bvec4 nan = isnan ( candidate ) ;
bvec4 replace = bvec4 (
vec4 ( $ { _ } ( candidate , bestValue ) ) * ( vec4 ( 1.0 ) - vec4 ( nan ) ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
bestValue = vec4 ( replace . x ? candidate . x : bestValue . x ,
replace . y ? candidate . y : bestValue . y ,
replace . z ? candidate . z : bestValue . z ,
replace . w ? candidate . w : bestValue . w ) ;
bestIndex = mix ( bestIndex , vec4 ( inIdx ) , vec4 ( replace ) ) ;
srcIdx ++ ;
}
setOutput ( bestIndex ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }};function bM(r,e,t,n=null){let o=e.shape[0],s=e.shape[1];n!=null&&(o=n.shape[0],s=n.shape[1]);let a=I.computeOptimalWindowSize(s),i={windowSize:a,inSize:s,batchSize:o,outSize:Math.ceil(s/a)},l=new aI(i,t,n==null),u=[e];n!=null&&u.push(n);let c=r.runWebGLProgram(l,u,"int32");if(c.shape[1]===1)return c;let p=bM(r,e,t,c);return r.disposeIntermediateTensorInfo(c),p}function wM(r,e,t,n=null){let o=n!=null?n.shape:e.shape,s=o[o.length-1],a=I.computeOptimalWindowSize(s),i=new lI(o,a,t,n==null),l=n==null?[e]:[e,n],u=r.runWebGLProgram(i,l,"int32");if(u.shape.length===e.shape.length){let c=wM(r,e,t,u);return r.disposeIntermediateTensorInfo(u),c}return u}function sb(r,e,t,n){let o=[t];if(I.assertAxesAreInnerMostDims("arg"+n.charAt(0).toUpperCase()+n.slice(1),o,e.shape.length),!U().getBool("WEBGL_PACK_REDUCE")||e.shape.length<=2){let s=[],a=r.texData.get(e.dataId),i=a!==null&&a.isPacked,l=e;i&&(l=r.unpackTensor(e),s.push(l));let[u,c]=I.computeOutAndReduceShapes(l.shape,o),p=b.sizeFromShape(c),m=ue({inputs:{x:l},backend:r,attrs:{shape:[-1,p]}});s.push(m);let f=bM(r,m,n);s.push(f);let d=ue({inputs:{x:f},backend:r,attrs:{shape:u}});return s.forEach(h=>r.disposeIntermediateTensorInfo(h)),d}return wM(r,e,n)}function KJ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{axis:s}=n,a=b.parseAxisParam(s,o.shape),i=I.getAxesPermutation(a,o.shape.length),l=o,u=[];i!=null&&(l=Pt({inputs:{x:o},backend:t,attrs:{perm:i}}),u.push(l),a=I.getInnerMostAxes(a.length,l.shape.length)),I.assertAxesAreInnerMostDims("argMax",[a[0]],l.shape.length);let c=sb(t,l,a[0],"max");return u.forEach(p=>t.disposeIntermediateTensorInfo(p)),c}var _M={kernelName:Ro,backendName:"webgl",kernelFunc:KJ};function XJ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{axis:s}=n,a=b.parseAxisParam(s,o.shape),i=I.getAxesPermutation(a,o.shape.length),l=o,u=[];i!=null&&(l=Pt({inputs:{x:o},backend:t,attrs:{perm:i}}),u.push(l),a=I.getInnerMostAxes(a.length,l.shape.length)),I.assertAxesAreInnerMostDims("argMin",[a[0]],l.shape.length);let c=sb(t,l,a[0],"min");return u.forEach(p=>t.disposeIntermediateTensorInfo(p)),c}var kM={kernelName:ml,backendName:"webgl",kernelFunc:XJ};var YJ=Nr+ `
if ( abs ( x ) > 1. ) {
return NAN ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
return asin ( x ) ;
` ,ZJ=ve({opSnippet:YJ}),vM={kernelName:Vi,backendName:"webgl",kernelFunc:ZJ};var JJ=Nr+"return log(x + sqrt(x * x + 1.0));",QJ=ve({opSnippet:JJ}),CM={kernelName:Gi,backendName:"webgl",kernelFunc:QJ};var eQ=Nr+ `
return atan ( x ) ;
` ,tQ=ve({opSnippet:eQ}),IM={kernelName:Wi,backendName:"webgl",kernelFunc:tQ};var rQ=eM+ `
return atan ( a , b ) ;
` ,nQ= `
vec4 result = atan ( a , b ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
` +tM+ `
return result ;
` ,oQ=at({opSnippet:rQ,packedOpSnippet:nQ}),SM={kernelName:ji,backendName:"webgl",kernelFunc:oQ};var sQ=Nr+ `
if ( ( x < - 1.0 ) || ( x > 1.0 ) ) return NAN ;
return ( log ( 1.0 + x ) - log ( 1.0 - x ) ) / 2.0 ; ` ,iQ=ve({opSnippet:sQ}),NM={kernelName:Ui,backendName:"webgl",kernelFunc:iQ};var Di=class{constructor(e,t,n,o=!1,s=!1){if(this.variableNames=["x"],t==="avg"&&n)throw new Error("Cannot compute positions for average pool.");let a=e.filterWidth,i=e.strideHeight,l=e.strideWidth,u=e.dilationHeight,c=e.dilationWidth,p=e.effectiveFilterHeight,m=e.effectiveFilterWidth,f=e.padInfo.top,d=e.padInfo.left;this.outputShape=e.outShape;let h=t==="avg",g= ` ( ( batch * $ { e . inHeight } + xR ) * $ { e . inWidth } + xC ) * $ { e . inChannels } + d ` ,x= ` ( xR * $ { e . inWidth } + xC ) * $ { e . inChannels } + d ` ,y="0.0";if(h||(y="-1.0 / 1e-20"),n){let R=">=";this.userCode= `
const ivec2 strides = ivec2 ( $ { i } , $ { l } ) ;
const ivec2 pads = ivec2 ( $ { f } , $ { d } ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int d = coords [ 3 ] ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec2 xRCCorner = coords . yz * strides - pads ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
float minMaxValue = 0.0 ;
float minMaxValueFound = 0.0 ;
int minMaxPosition = 0 ;
float avgValue = 0.0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int wR = 0 ; wR < $ { p } ;
wR += $ { u } ) {
int xR = xRCorner + wR ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { m } ;
wC += $ { c } ) {
int xC = xCCorner + wC ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float value = getX ( batch , xR , xC , d ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02: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 = $ { o ? s ? g : x : ` wR * ${ m } + wC ` } ;
}
}
}
setOutput ( float ( minMaxPosition ) ) ;
}
` ;return}let w="max",_= ` $ { t } ( $ { t } ( $ { t } ( minMaxValue [ 0 ] , minMaxValue [ 1 ] ) , minMaxValue [ 2 ] ) , minMaxValue [ 3 ] ) ` ;t==="avg"&&(_="avgValue / count");let C=Math.floor(a/4)*4,A=a%4,D= `
if ( $ { h } ) {
avgValue += dot ( values , ones ) ;
} else {
minMaxValue = $ { w } ( values , minMaxValue ) ;
}
` ;this.userCode= `
const ivec2 strides = ivec2 ( $ { i } , $ { l } ) ;
const ivec2 pads = ivec2 ( $ { f } , $ { d } ) ;
const float initializationValue = $ { y } ;
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float count = 0.0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float getValue ( int batch , int xR , int xC , int d ) {
if ( xC < 0 || xC >= $ { e . inWidth } ) {
return initializationValue ;
}
count += 1.0 ;
return getX ( batch , xR , xC , d ) ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int d = coords [ 3 ] ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec2 xRCCorner = coords . yz * strides - pads ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
vec4 minMaxValue = vec4 ( $ { y } ) ;
float avgValue = 0.0 ;
count = 0.0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int wR = 0 ; wR < $ { p } ;
wR += $ { u } ) {
int xR = xRCorner + wR ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { C } ; wC += 4 ) {
int xC = xCCorner + wC * $ { c } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
getValue ( batch , xR , xC + $ { c } , d ) ,
getValue ( batch , xR , xC + 2 * $ { c } , d ) ,
getValue ( batch , xR , xC + 3 * $ { c } , d )
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { D }
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int xC = xCCorner + $ { C } ;
if ( $ { A === 1 } ) {
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { D }
} else if ( $ { A === 2 } ) {
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
getValue ( batch , xR , xC + $ { c } , d ) ,
initializationValue ,
initializationValue
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { D }
} else if ( $ { A === 3 } ) {
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
getValue ( batch , xR , xC + $ { c } , d ) ,
getValue ( batch , xR , xC + 2 * $ { c } , d ) ,
initializationValue
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { D }
2021-09-11 17:17:13 +02:00
}
}
2021-10-22 22:09:52 +02:00
setOutput ( $ { _ } ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }},Cc=class{constructor(e,t,n,o=!1,s=!1){if(this.variableNames=["x"],t==="avg"&&n)throw new Error("Cannot compute positions for average pool.");let a=e.filterWidth,i=e.strideDepth,l=e.strideHeight,u=e.strideWidth,c=e.dilationDepth,p=e.dilationHeight,m=e.dilationWidth,f=e.effectiveFilterDepth,d=e.effectiveFilterHeight,h=e.effectiveFilterWidth,g=e.padInfo.front,x=e.padInfo.top,y=e.padInfo.left;this.outputShape=e.outShape;let w=t==="avg",_="0.0";if(w||(_="-1.0 / 1e-20"),n){let L=">=";this.userCode= `
const ivec3 strides =
ivec3 ( $ { i } , $ { l } , $ { u } ) ;
const ivec3 pads = ivec3 ( $ { g } , $ { x } , $ { y } ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec3 xCorner = ivec3 ( coords . y , coords . z , coords . w ) * strides - pads ;
int xDCorner = xCorner . x ;
int xRCorner = xCorner . y ;
int xCCorner = xCorner . z ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// max/min x(?, ?, ?, ch) to get y(yD, yR, yC, ch).
// ? = to be determined
float minMaxValue = 0.0 ;
float minMaxValueFound = 0.0 ;
int minMaxPosition = 0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int wD = 0 ; wD < $ { f } ;
wD += $ { c } ) {
int xD = xDCorner + wD ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xD < 0 || xD >= $ { e . inDepth } ) {
continue ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
for ( int wR = 0 ; wR < $ { d } ;
wR += $ { p } ) {
int xR = xRCorner + wR ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { h } ;
wC += $ { m } ) {
int xC = xCCorner + wC ;
if ( xC < 0 || xC >= $ { e . 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 $ { L } currMinMaxValue ) {
minMaxValue = value ;
minMaxValueFound = 1.0 ;
minMaxPosition = $ { o ? s ? ` (((batch * ${ e . inDepth } + xD) * ${ e . inHeight } + xR) * ${ e . inWidth } + xC) * ${ e . inChannels } + ch ` : ` ((xD * ${ e . inHeight } + xR) * ${ e . inWidth } + xC) * ${ e . inChannels } + ch ` : ` wD * ${ d } * ${ h } +
wR * $ { h } + wC ` };
}
2021-09-11 17:17:13 +02:00
}
}
}
2021-10-22 22:09:52 +02:00
setOutput ( float ( minMaxPosition ) ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` ;return}let C="max",A= ` $ { t } ( $ { t } ( $ { t } ( minMaxValue [ 0 ] , minMaxValue [ 1 ] ) , minMaxValue [ 2 ] ) , minMaxValue [ 3 ] ) ` ;t==="avg"&&(A="avgValue / count");let D=Math.floor(a/4)*4,R=a%4,P= `
if ( $ { w } ) {
avgValue += dot ( values , ones ) ;
} else {
minMaxValue = $ { C } ( values , minMaxValue ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` ;this.userCode= `
const ivec3 strides =
ivec3 ( $ { i } , $ { l } , $ { u } ) ;
const ivec3 pads = ivec3 ( $ { g } , $ { x } , $ { y } ) ;
const float initializationValue = $ { _ } ;
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float count = 0.0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float getValue ( int batch , int xD , int xR , int xC , int ch ) {
if ( xC < 0 || xC >= $ { e . inWidth } ) {
return initializationValue ;
}
count += 1.0 ;
return getX ( batch , xD , xR , xC , ch ) ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec3 xCorner = ivec3 ( coords . y , coords . z , coords . w ) * strides - pads ;
int xDCorner = xCorner . x ;
int xRCorner = xCorner . y ;
int xCCorner = xCorner . z ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).
// ? = to be determined
vec4 minMaxValue = vec4 ( $ { _ } ) ;
float avgValue = 0.0 ;
count = 0.0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int wD = 0 ; wD < $ { f } ;
wD += $ { c } ) {
int xD = xDCorner + wD ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xD < 0 || xD >= $ { e . inDepth } ) {
continue ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
for ( int wR = 0 ; wR < $ { d } ;
wR += $ { p } ) {
int xR = xRCorner + wR ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { D } ; wC += 4 ) {
int xC = xCCorner + wC * $ { m } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
getValue ( batch , xD , xR , xC + $ { m } , ch ) ,
getValue ( batch , xD , xR , xC + 2 * $ { m } , ch ) ,
getValue ( batch , xD , xR , xC + 3 * $ { m } , ch )
) ;
$ { P }
}
int xC = xCCorner + $ { D } ;
if ( $ { R === 1 } ) {
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
$ { P }
} else if ( $ { R === 2 } ) {
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
getValue ( batch , xD , xR , xC + $ { m } , ch ) ,
initializationValue ,
initializationValue
) ;
$ { P }
} else if ( $ { R === 3 } ) {
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
getValue ( batch , xD , xR , xC + $ { m } , ch ) ,
getValue ( batch , xD , xR , xC + 2 * $ { m } , ch ) ,
initializationValue
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { P }
}
}
setOutput ( $ { A } ) ;
}
}
` }};function aQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e;qs(o,"avgPool");let{filterSize:s,strides:a,pad:i,dimRoundingMode:l}=n,u=1;b.assert(I.eitherStridesOrDilationsAreOne(a,u),()=> ` Error in avgPool : Either strides or dilations must be 1. Got strides $ { a } and dilations '${u}' ` );let c=I.computePool2DInfo(o.shape,s,a,u,i,l);if(c.filterWidth===1&&c.filterHeight===1&&b.arraysEqual(c.inShape,c.outShape))return Qt({inputs:{x:o},backend:t});let p=new Di(c,"avg",!1);return t.runWebGLProgram(p,[o],"float32")}var TM={kernelName:Fo,backendName:"webgl",kernelFunc:aQ};function lQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{filterSize:s,strides:a,pad:i,dimRoundingMode:l,dataFormat:u}=n,c=[1,1,1],p=I.computePool3DInfo(o.shape,s,a,c,i,l,u),m=new Cc(p,"avg",!1);return t.runWebGLProgram(m,[o],"float32")}var EM={kernelName:fl,backendName:"webgl",kernelFunc:lQ};var uI=class{constructor(e){this.variableNames=["dy"],this.outputShape=e.inShape;let t=e.filterHeight,n=e.filterWidth,o=e.strideHeight,s=e.strideWidth,a=e.dilationHeight,i=e.dilationWidth,l=e.effectiveFilterHeight,u=e.effectiveFilterWidth,c=l-1-e.padInfo.top,p=u-1-e.padInfo.left,m=1/(t*n);this.userCode= `
const ivec2 pads = ivec2 ( $ { c } , $ { p } ) ;
const float avgMultiplier = float ( $ { m } ) ;
2021-09-11 17:17:13 +02:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 dyRCCorner = coords . yz - pads ;
int dyRCorner = dyRCCorner . x ;
int dyCCorner = dyRCCorner . y ;
// Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
2021-10-22 22:09:52 +02:00
for ( int wR = 0 ; wR < $ { l } ;
wR += $ { a } ) {
float dyR = float ( dyRCorner + wR ) / $ { o } . 0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
2021-09-11 17:17:13 +02:00
continue ;
}
int idyR = int ( dyR ) ;
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { u } ;
wC += $ { i } ) {
float dyC = float ( dyCCorner + wC ) / $ { s } . 0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( dyC < 0.0 || dyC >= $ { e . outWidth } . 0 ||
2021-09-11 17:17:13 +02:00
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
float dyValue = getDy ( b , idyR , idyC , d ) ;
2021-10-22 22:09:52 +02:00
dotProd += dyValue * avgMultiplier ;
2021-09-11 17:17:13 +02:00
}
}
setOutput ( dotProd ) ;
}
2021-10-22 22:09:52 +02:00
` }},cI=class{constructor(e){this.variableNames=["dy"],this.outputShape=e.inShape;let t=e.filterDepth,n=e.filterHeight,o=e.filterWidth,s=e.strideDepth,a=e.strideHeight,i=e.strideWidth,l=e.dilationDepth,u=e.dilationHeight,c=e.dilationWidth,p=e.effectiveFilterDepth,m=e.effectiveFilterHeight,f=e.effectiveFilterWidth,d=p-1-e.padInfo.front,h=m-1-e.padInfo.top,g=f-1-e.padInfo.left,x=1/(t*n*o);this.userCode= `
const ivec3 pads = ivec3 ( $ { d } , $ { h } , $ { g } ) ;
const float avgMultiplier = float ( $ { x } ) ;
2021-06-07 02:47:59 +02:00
2021-09-11 17:17:13 +02:00
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
ivec3 dyCorner = ivec3 ( coords . y , coords . z , coords . w ) - pads ;
int dyDCorner = dyCorner . x ;
int dyRCorner = dyCorner . y ;
int dyCCorner = dyCorner . z ;
2021-10-22 22:09:52 +02:00
// Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get
2021-09-11 17:17:13 +02:00
// dx(xD, xR, xC, ch).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
2021-10-22 22:09:52 +02:00
for ( int wD = 0 ; wD < $ { p } ;
wD += $ { l } ) {
float dyD = float ( dyDCorner + wD ) / $ { s } . 0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( dyD < 0.0 || dyD >= $ { e . outDepth } . 0 || fract ( dyD ) > 0.0 ) {
2021-09-11 17:17:13 +02:00
continue ;
}
int idyD = int ( dyD ) ;
2021-10-22 22:09:52 +02:00
for ( int wR = 0 ; wR < $ { m } ;
wR += $ { u } ) {
float dyR = float ( dyRCorner + wR ) / $ { a } . 0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 ||
2021-09-11 17:17:13 +02:00
fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { f } ;
wC += $ { c } ) {
float dyC = float ( dyCCorner + wC ) / $ { i } . 0 ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( dyC < 0.0 || dyC >= $ { e . outWidth } . 0 ||
2021-09-11 16:29:31 +02:00
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2021-06-07 02:47:59 +02:00
2021-09-11 17:17:13 +02:00
float dyValue = getDy ( batch , idyD , idyR , idyC , ch ) ;
2021-10-22 22:09:52 +02:00
dotProd += dyValue * avgMultiplier ;
2021-09-11 17:17:13 +02:00
}
}
}
setOutput ( dotProd ) ;
}
2021-10-22 22:09:52 +02:00
` }};function uQ(r){let{inputs:e,backend:t,attrs:n}=r,{dy:o,input:s}=e,a=s,{filterSize:i,strides:l,pad:u,dimRoundingMode:c}=n,p=[1,1,1],m=I.computePool3DInfo(a.shape,i,l,p,u,c),f=new cI(m);return t.runWebGLProgram(f,[o],a.dtype)}var AM={kernelName:Uc,backendName:"webgl",kernelFunc:uQ};function cQ(r){let{inputs:e,backend:t,attrs:n}=r,{dy:o,input:s}=e,a=s;qs([o,s],"avgPoolGrad");let{filterSize:i,strides:l,pad:u}=n,c=I.computePool2DInfo(a.shape,i,l,1,u),p=new uI(c);return t.runWebGLProgram(p,[o],a.dtype)}var DM={kernelName:Wc,backendName:"webgl",kernelFunc:cQ};function pQ(r){let{inputs:e,backend:t,attrs:n}=r,{a:o,b:s}=e,{transposeA:a,transposeB:i}=n;return vc({a:o,b:s,transposeA:a,transposeB:i,backend:t})}var $ M={kernelName:Oo,backendName:"webgl",kernelFunc:pQ};var pI=class{constructor(e,t,n,o,s,a){this.outputShape=[],this.variableNames=["x","mean","variance"],I.assertAndGetBroadcastShape(e,t),I.assertAndGetBroadcastShape(e,n);let i="0.0";o!=null&&(I.assertAndGetBroadcastShape(e,o),this.variableNames.push("offset"),i="getOffsetAtOutCoords()");let l="1.0";s!=null&&(I.assertAndGetBroadcastShape(e,s),this.variableNames.push("scale"),l="getScaleAtOutCoords()"),this.outputShape=e,this.userCode= `
void main ( ) {
float x = getXAtOutCoords ( ) ;
float mean = getMeanAtOutCoords ( ) ;
float variance = getVarianceAtOutCoords ( ) ;
float offset = $ { i } ;
float scale = $ { l } ;
float inv = scale * inversesqrt ( variance + float ( $ { a } ) ) ;
setOutput ( dot ( vec3 ( x , - mean , offset ) , vec3 ( inv , inv , 1 ) ) ) ;
}
` }};var mI=class{constructor(e,t,n,o,s,a){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],I.assertAndGetBroadcastShape(e,t),I.assertAndGetBroadcastShape(e,n);let i="vec4(0.0)";o!=null&&(I.assertAndGetBroadcastShape(e,o),this.variableNames.push("offset"),i="getOffsetAtOutCoords()");let l="vec4(1.0)";s!=null&&(I.assertAndGetBroadcastShape(e,s),this.variableNames.push("scale"),l="getScaleAtOutCoords()"),this.outputShape=e,this.userCode= `
void main ( ) {
vec4 offset = $ { i } ;
vec4 scale = $ { l } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 x = getXAtOutCoords ( ) ;
vec4 mean = getMeanAtOutCoords ( ) ;
vec4 variance = getVarianceAtOutCoords ( ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 inv = scale * inversesqrt ( variance + vec4 ( $ { a } ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( ( x - mean ) * inv + offset ) ;
}
` }};var mQ=({inputs:r,backend:e,attrs:t})=>{let{x:n,mean:o,variance:s,offset:a,scale:i}=r;b.assert(o.shape.length===s.shape.length,()=>"Batch normalization gradient requires mean and variance to have equal ranks."),b.assert(a==null||o.shape.length===a.shape.length,()=>"Batch normalization gradient requires mean and offset to have equal ranks."),b.assert(i==null||o.shape.length===i.shape.length,()=>"Batch normalization gradient requires mean and scale to have equal ranks.");let{varianceEpsilon:l}=t;l==null&&(l=.001);let u=[n,o,s],c=null;a!=null&&(c=a.shape,u.push(a));let p=null;i!=null&&(p=i.shape,u.push(i));let m=U().getBool("WEBGL_PACK_NORMALIZATION")?new mI(n.shape,o.shape,s.shape,c,p,l):new pI(n.shape,o.shape,s.shape,c,p,l);return e.runWebGLProgram(m,u,u[0].dtype)},RM={kernelName:Ko,backendName:"webgl",kernelFunc:mQ};var fI=class{constructor(e){this.variableNames=["source"],this.outputShape=e,this.rank=e.length;let t=Ue(this.rank);this.customUniforms=[{name:"start",arrayIndex:this.rank,type:"int"}];let n=fQ(this.rank),o,s=e.map((a,i)=> ` sourceLoc . $ { dI [ i ] } = start [ $ { i } ] + coords . $ { dI [ i ] } ; ` );o= `
$ { t } sourceLoc ;
$ { t } coords = getOutputCoords ( ) ;
$ { s . join ( `
` )}
` ,this.userCode= `
void main ( ) {
$ { o }
setOutput ( getSource ( $ { n } ) ) ;
}
` }},dI=["x","y","z","w","u","v"];function fQ(r){if(r===1)return"sourceLoc";if(r<=6)return dI.slice(0,r).map(e=>"sourceLoc."+e).join(",");throw Error( ` Slicing for rank $ { r } is not yet supported ` )}var hI=class{constructor(e){this.variableNames=["source"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.rank=e.length,this.customUniforms=[{name:"start",arrayIndex:this.rank,type:"int"}];let t=Ue(this.rank),n=Jt("coords",this.rank),o=Jt("sourceLoc",this.rank),s=this.rank===1?"sourceLoc": ` vec2 ( $ { o . slice ( - 2 ) . join ( ) } ) ` ,a= ` getChannel ( getSource ( $ { o . join ( ) } ) , $ { s } ) ` ,i= `
result . x = $ { a } ;
if ( ++ $ { n [ this . rank - 1 ] } < $ { e [ this . rank - 1 ] } ) {
++ $ { o [ this . rank - 1 ] } ;
result . y = $ { a } ;
-- $ { o [ this . rank - 1 ] } ;
}
` ,l=this.rank===1?"": `
-- $ { n [ this . rank - 1 ] } ;
if ( ++ $ { n [ this . rank - 2 ] } < $ { e [ this . rank - 2 ] } ) {
++ $ { o [ this . rank - 2 ] } ;
result . z = $ { a } ;
if ( ++ $ { n [ this . rank - 1 ] } < $ { e [ this . rank - 1 ] } ) {
++ $ { o [ this . rank - 1 ] } ;
result . w = $ { a } ;
}
}
` ,u=this.rank<=4? ` sourceLoc = coords +
$ { t } ( $ { e . map ( ( c , p ) => ` start[ ${ p } ] ` ) . join ( ) } ) ; ` :e.map((c,p)=> ` $ { o [ p ] } = $ { n [ p ] } + start [ $ { p } ] ; ` ).join( `
` );this.userCode= `
void main ( ) {
$ { t } coords = getOutputCoords ( ) ;
$ { t } sourceLoc ;
$ { u }
vec4 result = vec4 ( 0. ) ;
$ { i }
$ { l }
setOutput ( result ) ;
}
` }};function dQ(r,e,t,n){let o=n.texData.get(r.dataId),s=n.makeTensorInfo(t,r.dtype),a=n.texData.get(s.dataId);Object.assign(a,o),a.refCount=1,a.shape=t,a.dtype=r.dtype;let i=pr.computeFlatOffset(e,b.computeStrides(r.shape));o.slice&&(i+=o.slice.flatOffset),a.slice={flatOffset:i,origDataId:o.slice&&o.slice.origDataId||r.dataId};let l=n.dataRefCount.get(a.slice.origDataId)||1;return n.dataRefCount.set(a.slice.origDataId,l+1),s}function Zs(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{begin:s,size:a}=n,[i,l]=pr.parseSliceParams(o,s,a);if(pr.assertParamsValid(o,i,l),b.sizeFromShape(l)===0)return t.makeTensorInfo(l,o.dtype,[]);if(t.shouldExecuteOnCPU([o])||o.dtype==="string"){let p=t.texData.get(o.dataId),m=kP(p.values,i,l,o.shape,o.dtype);return t.makeTensorInfo(l,o.dtype,m)}let{isPacked:u}=t.texData.get(o.dataId),c=pr.isSliceContinous(o.shape,i,l);if(u||!c){let p=U().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new hI(l):new fI(l),m=[i];return t.runWebGLProgram(p,[o],o.dtype,m)}return t.uploadToGPU(o.dataId),dQ(o,i,l,t)}var FM={kernelName:pi,backendName:"webgl",kernelFunc:Zs};var hQ=r=>{let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{blockShape:s,crops:a}=n;b.assert(o.shape.length<=4,()=>"batchToSpaceND for rank > 4 with a WebGL backend not implemented yet");let i=s.reduce((y,w)=>y*w),l=I.getReshaped(o.shape,s,i),u=I.getPermuted(l.length,s.length),c=I.getReshapedPermuted(o.shape,s,i),p=I.getSliceBeginCoords(a,s.length),m=I.getSliceSize(c,a,s.length),f=[],d=ue({inputs:{x:o},backend:t,attrs:{shape:l}}),h=Pt({inputs:{x:d},backend:t,attrs:{perm:u}}),g=ue({inputs:{x:h},backend:t,attrs:{shape:c}}),x=Zs({inputs:{x:g},backend:t,attrs:{begin:p,size:m}});return f.push(d),f.push(h),f.push(g),f.forEach(y=>t.disposeIntermediateTensorInfo(y)),x},OM={kernelName:ri,backendName:"webgl",kernelFunc:hQ};function gQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,weights:s}=e,{size:a}=n,i=t.readSync(o.dataId),l=t.readSync(s.dataId),u=Yy(i,l,s.dtype,s.shape,a);return t.makeTensorInfo([a],s.dtype,u)}var PM={kernelName:jc,backendName:"webgl",kernelFunc:gQ};function xQ(r){let{inputs:e,backend:t}=r,{s0:n,s1:o}=e,s=t.readSync(n.dataId),a=t.readSync(o.dataId),i=I.assertAndGetBroadcastShape(Array.from(s),Array.from(a));return t.makeTensorInfo([i.length],"int32",Int32Array.from(i))}var MM={kernelName:Hc,backendName:"webgl",kernelFunc:xQ};var yQ="return float(a != b);",gI=at({opSnippet:yQ,cpuKernelImpl:xP,dtype:"bool"}),LM={kernelName:la,backendName:"webgl",kernelFunc:gI};function tl(r){let{inputs:e,backend:t}=r,{input:n}=e,o=t.texData.get(n.dataId);return Qt({inputs:{x:o.complexTensorInfos.real},backend:t})}var zM={kernelName:mp,backendName:"webgl",kernelFunc:tl};var bQ="return float(int(x));";function BM(r,e){let t=new En(r.shape,bQ),n=e.runWebGLProgram(t,[r],"int32");return{dataId:n.dataId,shape:n.shape,dtype:n.dtype}}function xI(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{dtype:s}=n;if(s==="complex64"){if(o.dtype==="complex64")return Qt({inputs:{x:o},backend:t});let a=yt(o.shape),i=xI({inputs:{x:o},backend:t,attrs:{dtype:"float32"}}),l=An({inputs:{real:i,imag:a},backend:t});return a.dispose(),t.disposeIntermediateTensorInfo(i),l}if(o.dtype==="complex64"){let a=tl({inputs:{input:o},backend:t}),i=xI({inputs:{x:a},backend:t,attrs:{dtype:s}});return t.disposeIntermediateTensorInfo(a),i}if(!b.hasEncodingLoss(o.dtype,s)){let a=Qt({inputs:{x:o},backend:t});return{dataId:a.dataId,shape:a.shape,dtype:s}}if(s==="int32")return BM(o,t);if(s==="bool"){let a=t.makeTensorInfo([],"bool",b.getTypedArrayFromDType("bool",1)),l=gI({inputs:{a:o,b:a},backend:t});return t.disposeIntermediateTensorInfo(a),l}throw new Error( ` Error in Cast : failed to cast $ { o . dtype } to $ { s } ` )}var VM={kernelName:eo,backendName:"webgl",kernelFunc:xI};var GM="return ceil(x);",wQ=ve({opSnippet:GM,packedOpSnippet:GM,cpuKernelImpl:JO}),WM={kernelName:Po,backendName:"webgl",kernelFunc:wQ};var yI=class{constructor(e){this.variableNames=["A"],this.customUniforms=[{name:"minVal",type:"float"},{name:"maxVal",type:"float"}],this.outputShape=e,this.userCode= `
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
float value = getAAtOutCoords ( ) ;
if ( isnan ( value ) ) {
setOutput ( value ) ;
return ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( clamp ( value , minVal , maxVal ) ) ;
}
` }};var bI=class{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.customUniforms=[{name:"minVal",type:"float"},{name:"maxVal",type:"float"}],this.outputShape=e,this.userCode= `
void main ( ) {
vec4 value = getAAtOutCoords ( ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( any ( isnan ( value ) ) ) {
setOutput ( value ) ;
return ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
setOutput ( clamp ( value , vec4 ( minVal ) , vec4 ( maxVal ) ) ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }};function _Q(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{clipValueMin:s,clipValueMax:a}=n,i;U().getBool("WEBGL_PACK_CLIP")?i=new bI(o.shape):i=new yI(o.shape);let l=[[s],[a]];return t.runWebGLProgram(i,[o],o.dtype,l)}var UM={kernelName:to,backendName:"webgl",kernelFunc:_Q};var wI=class{constructor(e){this.variableNames=["real","imag"],this.outputShape=e,this.userCode= `
void main ( ) {
float re = abs ( getRealAtOutCoords ( ) ) ;
float im = abs ( getImagAtOutCoords ( ) ) ;
float mx = max ( re , im ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// sadly the length function in glsl is not underflow-safe
// (at least not on Intel GPUs). So the safe solution is
// to ensure underflow-safety in all cases.
setOutput (
mx == 0.0 ? 0.0 : mx * length ( vec2 ( 1 , min ( re , im ) / mx ) )
) ;
}
` }};function jM(r,e){return{dataId:e.dataId,dtype:e.dtype,shape:r.shape}}function kQ(r){let{inputs:e,backend:t}=r,{x:n}=e,o=t.texData.get(n.dataId),s=new wI(n.shape),a=[jM(n,o.complexTensorInfos.real),jM(n,o.complexTensorInfos.imag)];return t.runWebGLProgram(s,a,a[0].dtype)}var HM={kernelName:dl,backendName:"webgl",kernelFunc:kQ};var _I=class{constructor(e){this.outputShape=[],this.outputShape=I.computeOutShape(e,1),this.variableNames=e.map((a,i)=> ` T$ { i } ` );let t=new Array(e.length-1);t[0]=e[0][1];for(let a=1;a<t.length;a++)t[a]=t[a-1]+e[a][1];let n=[ ` if ( yC < $ { t [ 0 ] } ) setOutput ( getT0 ( yR , yC ) ) ; ` ];for(let a=1;a<t.length;a++){let i=t[a-1];n.push( ` else if ( yC < $ { t [ a ] } ) setOutput ( getT$ { a } ( yR , yC - $ { i } ) ) ; ` )}let o=t.length,s=t[t.length-1];n.push( ` else setOutput ( getT$ { o } ( yR , yC - $ { s } ) ) ; ` ),this.userCode= `
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int yR = coords . x ;
int yC = coords . y ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { n . join ( `
` )}
}
` }};var kI=class{constructor(e,t){this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[],this.outputShape=I.computeOutShape(e,t);let n=this.outputShape,o=n.length,s=Ue(o),a=Jt("coords",o),i=["x","y","z","w","u","v"].slice(0,o);this.variableNames=e.map((h,g)=> ` T$ { g } ` );let l=new Array(e.length-1);l[0]=e[0][t];for(let h=1;h<l.length;h++)l[h]=l[h-1]+e[h][t];let u=i[t],c=i.slice(-2),p=i.join(),m= ` if ( $ { u } < $ { l [ 0 ] } ) {
return getChannel (
getT0 ( $ { p } ) , vec2 ( $ { c . join ( ) } ) ) ;
} ` ;for(let h=1;h<l.length;h++){let g=l[h-1];m+= `
if ( $ { u } < $ { l [ h ] } && $ { u } >= $ { l [ h - 1 ] } ) {
return getChannel (
getT$ { h } ( $ { ib ( i , u , g ) } ) ,
vec2 ( $ { ib ( c , u , g ) } ) ) ;
} ` }let f=l.length,d=l[l.length-1];m+= `
return getChannel (
getT$ { f } ( $ { ib ( i , u , d ) } ) ,
vec2 ( $ { ib ( c , u , d ) } ) ) ; ` ,this.userCode= `
float getValue ( $ { i . map ( h => "int " + h ) } ) {
$ { m }
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
$ { s } coords = getOutputCoords ( ) ;
vec4 result = vec4 ( getValue ( $ { a } ) , 0. , 0. , 0. ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { a [ o - 1 ] } = $ { a [ o - 1 ] } + 1 ;
if ( $ { a [ o - 1 ] } < $ { n [ o - 1 ] } ) {
result . g = getValue ( $ { a } ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
$ { a [ o - 2 ] } = $ { a [ o - 2 ] } + 1 ;
if ( $ { a [ o - 2 ] } < $ { n [ o - 2 ] } ) {
result . a = getValue ( $ { a } ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
$ { a [ o - 1 ] } = $ { a [ o - 1 ] } - 1 ;
if ( $ { a [ o - 2 ] } < $ { n [ o - 2 ] } &&
$ { a [ o - 1 ] } < $ { n [ o - 1 ] } ) {
result . b = getValue ( $ { a } ) ;
2021-09-11 17:17:13 +02:00
}
setOutput ( result ) ;
}
2021-10-22 22:09:52 +02:00
` }};function ib(r,e,t){let n=r.indexOf(e);return r.map((s,a)=>a===n? ` $ { s } - $ { t } ` :s).join()}function Ic(r){let{inputs:e,backend:t}=r,{input:n}=e,o=t.texData.get(n.dataId);return Qt({inputs:{x:o.complexTensorInfos.imag},backend:t})}var qM={kernelName:sp,backendName:"webgl",kernelFunc:Ic};function Sc(r,e,t){let n=r[0].dtype;if(n==="complex64"){let c=r.map(h=>tl({inputs:{input:h},backend:t})),p=r.map(h=>Ic({inputs:{input:h},backend:t})),m=Sc(c,e,t),f=Sc(p,e,t),d=An({inputs:{real:m,imag:f},backend:t});return c.forEach(h=>t.disposeIntermediateTensorInfo(h)),p.forEach(h=>t.disposeIntermediateTensorInfo(h)),t.disposeIntermediateTensorInfo(m),t.disposeIntermediateTensorInfo(f),d}let o=t.shouldExecuteOnCPU(r);if(n==="string"&&(o=!0),o){let c=r.map(x=>{let y=b.sizeFromShape(x.shape.slice(e));return ue({inputs:{x},backend:t,attrs:{shape:[-1,y]}})}),p=c.map(x=>({vals:t.readSync(x.dataId),shape:x.shape})),m=I.computeOutShape(c.map(x=>x.shape),1),f=c[0].shape[0]===1,d=QO(p,m,n,f),h=I.computeOutShape(r.map(x=>x.shape),e),g=t.makeTensorInfo(h,n,d);return c.forEach(x=>t.disposeIntermediateTensorInfo(x)),g}if(r.length>U().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){let c=Math.floor(r.length/2),p=Sc(r.slice(0,c),e,t),m=Sc(r.slice(c),e,t),f=Sc([p,m],e,t);return t.disposeIntermediateTensorInfo(p),t.disposeIntermediateTensorInfo(m),f}if(U().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&r[0].shape.length>1){let c=new kI(r.map(p=>p.shape),e);return t.runWebGLProgram(c,r,n)}let{tensors2D:s,outShape:a}=vQ(r,e,t),i=new _I(s.map(c=>c.shape)),l=t.runWebGLProgram(i,s,n);s.forEach(c=>t.disposeIntermediateTensorInfo(c));let u=ue({inputs:{x:l},attrs:{shape:a},backend:t});return t.disposeIntermediateTensorInfo(l),u}function vQ(r,e,t){let n=I.computeOutShape(r.map(s=>s.shape),e);return{tensors2D:r.map(s=>ue({inputs:{x:s},attrs:{shape:[-1,b.sizeFromShape(s.shape.slice(e))]},backend:t})),outShape:n}}function vI(r){let{inputs:e,backend:t,attrs:n}=r,{axis:o}=n,s=b.parseAxisParam(o,e[0].shape)[0],a=I.computeOutShape(e.map(u=>u.shape),s);if(b.sizeFromShape(a)===0)return t.makeTensorInfo(a,e[0].dtype,[]);let i=e.filter(u=>b.sizeFromShape(u.shape)>0);if(i.length===1)return Qt({inputs:{x:i[0]},backend:t});let l=i.map(u=>u.shape);return I.assertParamsConsistent(l,s),Sc(i,s,t)}var KM={kernelName:ni,backendName:"webgl",kernelFunc:vI};var Kh=class{constructor(e,t=!1,n=null,o=!1,s=!1){this.variableNames=["x","W"],this.outputShape=e.outShape;let a=e.padInfo.top,i=e.padInfo.left,l=e.strideHeight,u=e.strideWidth,c=e.dilationHeight,p=e.dilationWidth,m=e.filterHeight,f=e.filterWidth,d=Math.floor(e.inChannels/4)*4,h=e.inChannels%4,g=e.dataFormat==="channelsLast",x=g?1:2,y=g?2:3,w=g?3:1,_="",C="";n&&(o?_= ` float activation ( float a ) {
float b = getPreluActivationWeightsAtOutCoords ( ) ;
$ { n }
} ` :s?_= ` float activation ( float a ) {
float b = getLeakyreluAlphaAtOutCoords ( ) ;
$ { n }
} ` :_= `
float activation ( float x ) {
$ { n }
}
` ,C="result = activation(result);");let A=t?"result += getBiasAtOutCoords();":"";t&&this.variableNames.push("bias"),o&&this.variableNames.push("preluActivationWeights"),s&&this.variableNames.push("leakyreluAlpha"),this.userCode= `
$ { _ }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
const ivec2 strides = ivec2 ( $ { l } , $ { u } ) ;
const ivec2 pads = ivec2 ( $ { a } , $ { i } ) ;
2021-09-11 17:17:13 +02:00
void main ( ) {
2021-10-22 22:09:52 +02:00
ivec4 coords = getOutputCoords ( ) ;
2021-09-11 17:17:13 +02:00
int batch = coords [ 0 ] ;
2021-10-22 22:09:52 +02:00
int d2 = coords [ $ { w } ] ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec2 xRCCorner =
ivec2 ( coords [ $ { x } ] , coords [ $ { y } ] ) * strides - pads ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02: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 < $ { m } ; wR ++ ) {
int xR = xRCorner + wR * $ { c } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { f } ; wC ++ ) {
int xC = xCCorner + wC * $ { p } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int d1 = 0 ; d1 < $ { d } ; 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 )
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( $ { g } ) {
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 ) ;
}
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( $ { h === 1 } ) {
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( $ { g } ) {
dotProd +=
getX ( batch , xR , xC , $ { d } ) *
getW ( wR , wC , $ { d } , d2 ) ;
} else {
dotProd +=
getX ( batch , $ { d } , xR , xC ) *
getW ( wR , wC , $ { d } , d2 ) ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
} else if ( $ { h === 2 } ) {
vec2 wValues = vec2 (
getW ( wR , wC , $ { d } , d2 ) ,
getW ( wR , wC , $ { d } + 1 , d2 )
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( $ { g } ) {
vec2 xValues = vec2 (
getX ( batch , xR , xC , $ { d } ) ,
getX ( batch , xR , xC , $ { d } + 1 )
) ;
dotProd += dot ( xValues , wValues ) ;
} else {
vec2 xValues = vec2 (
getX ( batch , $ { d } , xR , xC ) ,
getX ( batch , $ { d } + 1 , xR , xC )
) ;
dotProd += dot ( xValues , wValues ) ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
} else if ( $ { h === 3 } ) {
vec3 wValues = vec3 (
getW ( wR , wC , $ { d } , d2 ) ,
getW ( wR , wC , $ { d } + 1 , d2 ) ,
getW ( wR , wC , $ { d } + 2 , d2 )
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( $ { g } ) {
vec3 xValues = vec3 (
getX ( batch , xR , xC , $ { d } ) ,
getX ( batch , xR , xC , $ { d } + 1 ) ,
getX ( batch , xR , xC , $ { d } + 2 )
) ;
dotProd += dot ( xValues , wValues ) ;
} else {
vec3 xValues = vec3 (
getX ( batch , $ { d } , xR , xC ) ,
getX ( batch , $ { d } + 1 , xR , xC ) ,
getX ( batch , $ { d } + 2 , xR , xC )
) ;
dotProd += dot ( xValues , wValues ) ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
}
2021-09-11 17:17:13 +02:00
}
}
2021-10-22 22:09:52 +02:00
float result = dotProd ;
$ { A }
$ { C }
setOutput ( result ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }},CI=class{constructor(e){this.variableNames=["x","W"],this.outputShape=e.outShape;let t=e.padInfo.front,n=e.padInfo.top,o=e.padInfo.left,s=e.strideDepth,a=e.strideHeight,i=e.strideWidth,l=e.dilationDepth,u=e.dilationHeight,c=e.dilationWidth,p=e.filterDepth,m=e.filterHeight,f=e.filterWidth,d=Math.floor(e.inChannels/4)*4,h=e.inChannels%4;this.userCode= `
const ivec3 strides = ivec3 ( $ { s } , $ { a } , $ { i } ) ;
const ivec3 pads = ivec3 ( $ { t } , $ { n } , $ { o } ) ;
2021-09-11 17:17:13 +02:00
void main ( ) {
2021-10-22 22:09:52 +02:00
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int d2 = coords . u ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ivec3 xFRCCorner = ivec3 ( coords . y , coords . z , coords . w ) * strides - pads ;
int xFCorner = xFRCCorner . x ;
int xRCorner = xFRCCorner . y ;
int xCCorner = xFRCCorner . z ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02: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 < $ { p } ; wF ++ ) {
int xF = xFCorner + wF * $ { l } ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( xF < 0 || xF >= $ { e . inDepth } ) {
continue ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
for ( int wR = 0 ; wR < $ { m } ; wR ++ ) {
int xR = xRCorner + wR * $ { u } ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { f } ; wC ++ ) {
int xC = xCCorner + wC * $ { c } ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
for ( int d1 = 0 ; d1 < $ { d } ; 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 )
) ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
dotProd += dot ( xValues , wValues ) ;
}
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
if ( $ { h === 1 } ) {
dotProd +=
getX ( batch , xF , xR , xC , $ { d } ) *
getW ( wF , wR , wC , $ { d } , d2 ) ;
} else if ( $ { h === 2 } ) {
vec2 xValues = vec2 (
getX ( batch , xF , xR , xC , $ { d } ) ,
getX ( batch , xF , xR , xC , $ { d } + 1 )
) ;
vec2 wValues = vec2 (
getW ( wF , wR , wC , $ { d } , d2 ) ,
getW ( wF , wR , wC , $ { d } + 1 , d2 )
) ;
dotProd += dot ( xValues , wValues ) ;
} else if ( $ { h === 3 } ) {
vec3 xValues = vec3 (
getX ( batch , xF , xR , xC , $ { d } ) ,
getX ( batch , xF , xR , xC , $ { d } + 1 ) ,
getX ( batch , xF , xR , xC , $ { d } + 2 )
) ;
vec3 wValues = vec3 (
getW ( wF , wR , wC , $ { d } , d2 ) ,
getW ( wF , wR , wC , $ { d } + 1 , d2 ) ,
getW ( wF , wR , wC , $ { d } + 2 , d2 )
) ;
dotProd += dot ( xValues , wValues ) ;
}
}
}
}
setOutput ( dotProd ) ;
}
` }};var II=class{constructor(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.customUniforms=[{name:"inputShape",type:"ivec3"},{name:"pad",type:"ivec2"},{name:"stride",type:"ivec2"},{name:"dilation",type:"ivec2"},{name:"inChannels",type:"int"},{name:"itemsPerBlockRow",type:"int"},{name:"outWidth",type:"int"}],this.outputShape=e,this.enableShapeUniforms=jt(this.outputShape.length);let{dataFormat:n}=t,o=Gt(),s=n==="channelsLast",a=s?0:1,i=s?1:2,l=this.enableShapeUniforms?"if(blockIndex < outShape[1] && pos < outShape[0]) {": ` if ( blockIndex < $ { e [ 1 ] } && pos < $ { e [ 0 ] } ) { ` ,u="";for(let c=0;c<=1;c++)for(let p=0;p<=1;p++)u+= `
blockIndex = rc . y + $ { p } ;
pos = rc . x + $ { c } ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
$ { l }
offsetY = int ( blockIndex / outWidth ) * stride [ 0 ] - pad [ 0 ] ;
d0 = offsetY + dilation [ 0 ] * ( pos / itemsPerBlockRow ) ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
if ( d0 < inputShape [ $ { a } ] && d0 >= 0 ) {
// Use custom imod instead mod. On Intel GPU, mod may generate
// unexpected value.
// https://github.com/tensorflow/tfjs/issues/5447
offsetX = imod ( blockIndex , outWidth ) * stride [ 1 ] - pad [ 1 ] ;
d1 = offsetX + dilation [ 1 ] * ( imod ( pos , itemsPerBlockRow ) /
inChannels ) ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
if ( d1 < inputShape [ $ { i } ] && d1 >= 0 ) {
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
ch = imod ( pos , inChannels ) ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
if ( $ { s } ) {
innerDims = vec2 ( d1 , ch ) ;
result [ $ { c * 2 + p } ] = getChannel (
getA ( d0 , int ( innerDims . x ) ,
int ( innerDims . y ) ) , innerDims ) ;
} else {
innerDims = vec2 ( d0 , d1 ) ;
result [ $ { c * 2 + p } ] = getChannel (
getA ( ch , int ( innerDims . x ) ,
int ( innerDims . y ) ) , innerDims ) ;
}
}
}
}
` ;this.userCode= `
2021-09-11 16:29:31 +02:00
void main ( ) {
2021-10-22 22:09:52 +02:00
ivec2 rc = getOutputCoords ( ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
vec4 result = vec4 ( 0 ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
int blockIndex , pos , offsetY , d0 , offsetX , d1 , ch ;
vec2 innerDims ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
$ { u }
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
$ { o . output } = result ;
}
` }};function ab({x:r,filter:e,convInfo:t,backend:n,bias:o=null,preluActivationWeights:s=null,leakyreluAlpha:a=0,activation:i=null}){let l=r.shape,u=n.texData.get(r.dataId),c=t.inChannels,p=l[0]*l[1]*l[2],m=t.outChannels,f=t.dataFormat==="channelsLast",d=!1,h=!1,g,x=[];if(!((p===1||m===1)&&c>oI)&&u.isPacked&&f&&u.texture!=null&&l[2]%2!=0&&b.arraysEqual(u.shape.slice(-3),l.slice(-3))){let _=l[0]*l[1]*(l[2]+1),C={dataId:r.dataId,shape:[1,_,t.inChannels],dtype:r.dtype},A=u.shape;u.shape=u.shape.slice(),u.shape[u.shape.length-2]++,b.assert(ql(u.shape,C.shape),()=> ` packed reshape $ { u . shape } to $ { C . shape } isn ' t free ` );let D=ue({inputs:{x:e},backend:n,attrs:{shape:[1,t.inChannels,t.outChannels]}});x.push(D);let R=vc({a:C,b:D,backend:n,transposeA:d,transposeB:h,bias:o,activation:i,preluActivationWeights:s,leakyreluAlpha:a}),P=n.texData.get(R.dataId);b.assert(P.isPacked,()=>"batchMatMul result is expected to be packed"),u.shape=A,P.shape=t.outShape,g=Qt({inputs:{x:R},backend:n}),g.shape=t.outShape,x.push(R)}else{let _=f?l[0]*l[1]*l[2]:l[0]*l[2]*l[3],C=ue({inputs:{x:r},backend:n,attrs:{shape:[1,_,t.inChannels]}}),A=ue({inputs:{x:e},backend:n,attrs:{shape:[1,t.inChannels,t.outChannels]}}),D=vc({a:C,b:A,transposeA:d,transposeB:h,backend:n,bias:o,activation:i,preluActivationWeights:s,leakyreluAlpha:a});g=ue({inputs:{x:D},backend:n,attrs:{shape:t.outShape}}),x.push(C),x.push(A),x.push(D)}for(let _ of x)n.disposeIntermediateTensorInfo(_);return g}function lb({x:r,filter:e,convInfo:t,backend:n,bias:o=null,preluActivationWeights:s=null,leakyreluAlpha:a=0,activation:i=null}){let{filterWidth:l,filterHeight:u,inChannels:c,outWidth:p,outHeight:m,dataFormat:f}=t,d=f==="channelsLast",h=l*u*c,g=m*p,x=[h,g],y=!0,w=!1,_=[],C=ue({inputs:{x:r},backend:n,attrs:{shape:r.shape.slice(1)}}),A=ue({inputs:{x:e},backend:n,attrs:{shape:[1,h,b.sizeFromShape(e.shape)/h]}});_.push(C),_.push(A);let D=new II(x,t),R=[C.shape,[t.padInfo.top,t.padInfo.left],[t.strideHeight,t.strideWidth],[t.dilationHeight,t.dilationWidth],[t.inChannels],[t.filterWidth*t.inChannels],[t.outWidth]],P=n.runWebGLProgram(D,[C],"float32",R),L=ue({inputs:{x:P},backend:n,attrs:{shape:[1,x[0],x[1]]}});_.push(P),_.push(L);let G=o!=null,W=s!=null,j=i==="leakyrelu",H=i?Xl(i,!0):null,q=new Hh(L.shape,A.shape,[1,g,t.outChannels],y,w,G,H,W,j),X=[L,A];if(o&&X.push(o),W&&X.push(s),j){let se=n.makeTensorInfo([],"float32",b.createScalarValue(a,"float32"));X.push(se),_.push(se)}let re=n.runWebGLProgram(q,X,"float32"),J=d?[1,m,p,t.outChannels]:[1,t.outChannels,m,p],oe=ue({inputs:{x:re},backend:n,attrs:{shape:J}});_.push(re);for(let se of _)n.disposeIntermediateTensorInfo(se);return oe}function CQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,filter:s}=e,{strides:a,pad:i,dataFormat:l,dilations:u,dimRoundingMode:c}=n,p=I.convertConv2DDataFormat(l),m=I.computeConv2DInfo(o.shape,s.shape,a,u,i,c,!1,p),f;if(m.filterHeight===1&&m.filterWidth===1&&m.dilationHeight===1&&m.dilationWidth===1&&m.strideHeight===1&&m.strideWidth===1&&(m.padInfo.type==="SAME"||m.padInfo.type==="VALID"))f=ab({x:o,filter:s,convInfo:m,backend:t});else if(U().getBool("WEBGL_CONV_IM2COL")&&o.shape[0]===1)f=lb({x:o,filter:s,convInfo:m,backend:t});else{let h=new Kh(m);f=t.runWebGLProgram(h,[o,s],"float32")}let d=ue({inputs:{x:f},backend:t,attrs:{shape:m.outShape}});return t.disposeIntermediateTensorInfo(f),d}var XM={kernelName:Mo,backendName:"webgl",kernelFunc:CQ};var SI=class{constructor(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;let t=e.strideHeight,n=e.strideWidth,o=e.padInfo.top,s=e.padInfo.left,a=e.dataFormat==="channelsLast";this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int wR = coords . x ;
int wC = coords . y ;
int d1 = coords . z ;
int d2 = coords . w ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02: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 ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
for ( int b = 0 ; b < $ { e . batchSize } ; b ++ ) {
for ( int yR = 0 ; yR < $ { e . outHeight } ; yR ++ ) {
int xR = wR + yR * $ { t } - $ { o } ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
for ( int yC = 0 ; yC < $ { e . outWidth } ; yC ++ ) {
int xC = wC + yC * $ { n } - $ { s } ;
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
if ( $ { a } ) {
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 ) ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
}
}
}
setOutput ( dotProd ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }},NI=class{constructor(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;let t=e.filterHeight,n=e.filterWidth,o=e.strideHeight,s=e.strideWidth,a=e.dataFormat==="channelsLast",i=t-1-e.padInfo.top,l=n-1-e.padInfo.left,u=a?1:2,c=a?2:3,p=a?3:1;this.userCode= `
const ivec2 pads = ivec2 ( $ { i } , $ { l } ) ;
2021-06-07 02:47:59 +02:00
2021-09-11 17:17:13 +02:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
2021-10-22 22:09:52 +02:00
int batch = coords [ 0 ] ;
int d1 = coords [ $ { p } ] ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
ivec2 dyCorner = ivec2 ( coords [ $ { u } ] , coords [ $ { c } ] ) - pads ;
int dyRCorner = dyCorner . x ;
int dyCCorner = dyCorner . y ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
// Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
for ( int wR = 0 ; wR < $ { t } ; wR ++ ) {
float dyR = float ( dyRCorner + wR ) / $ { o } . 0 ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
int wRPerm = $ { t } - 1 - wR ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { n } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { s } . 0 ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( dyC < 0.0 || dyC >= $ { e . outWidth } . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
int wCPerm = $ { n } - 1 - wC ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
for ( int d2 = 0 ; d2 < $ { e . outChannels } ; d2 ++ ) {
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( $ { a } ) {
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 ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
}
}
}
setOutput ( dotProd ) ;
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
` }},TI=class{constructor(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;let t=e.strideDepth,n=e.strideHeight,o=e.strideWidth,s=e.padInfo.front,a=e.padInfo.top,i=e.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 ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
float dotProd = 0.0 ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
for ( int b = 0 ; b < $ { e . batchSize } ; b ++ ) {
for ( int yF = 0 ; yF < $ { e . outDepth } ; yF ++ ) {
int xF = wF + yF * $ { t } - $ { s } ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( xF < 0 || xF >= $ { e . inDepth } ) {
continue ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
for ( int yR = 0 ; yR < $ { e . outHeight } ; yR ++ ) {
int xR = wR + yR * $ { n } - $ { a } ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
for ( int yC = 0 ; yC < $ { e . outWidth } ; yC ++ ) {
int xC = wC + yC * $ { o } - $ { i } ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
float dyValue = getDy ( b , yF , yR , yC , d2 ) ;
float xValue = getX ( b , xF , xR , xC , d1 ) ;
dotProd += ( xValue * dyValue ) ;
}
}
}
}
setOutput ( dotProd ) ;
}
` }},EI=class{constructor(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;let t=e.filterDepth,n=e.filterHeight,o=e.filterWidth,s=e.strideDepth,a=e.strideHeight,i=e.strideWidth,l=t-1-e.padInfo.front,u=n-1-e.padInfo.top,c=o-1-e.padInfo.left;this.userCode= `
const ivec3 pads = ivec3 ( $ { l } , $ { u } , $ { c } ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int d1 = coords . u ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
ivec3 dyCorner = ivec3 ( coords . y , coords . z , coords . w ) - pads ;
int dyFCorner = dyCorner . x ;
int dyRCorner = dyCorner . y ;
int dyCCorner = dyCorner . z ;
float dotProd = 0.0 ;
for ( int wF = 0 ; wF < $ { t } ; wF ++ ) {
float dyF = float ( dyFCorner + wF ) / $ { s } . 0 ;
if ( dyF < 0.0 || dyF >= $ { e . outDepth } . 0 || fract ( dyF ) > 0.0 ) {
2021-09-11 16:29:31 +02:00
continue ;
}
2021-10-22 22:09:52 +02:00
int idyF = int ( dyF ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
int wFPerm = $ { t } - 1 - wF ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
for ( int wR = 0 ; wR < $ { n } ; wR ++ ) {
float dyR = float ( dyRCorner + wR ) / $ { a } . 0 ;
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 ||
fract ( dyR ) > 0.0 ) {
2021-09-11 16:29:31 +02:00
continue ;
2021-06-07 02:34:29 +02:00
}
2021-10-22 22:09:52 +02:00
int idyR = int ( dyR ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
int wRPerm = $ { n } - 1 - wR ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { o } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { i } . 0 ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
if ( dyC < 0.0 || dyC >= $ { e . outWidth } . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
int wCPerm = $ { o } - 1 - wC ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
for ( int d2 = 0 ; d2 < $ { e . outChannels } ; d2 ++ ) {
float xValue = getDy ( batch , idyF , idyR , idyC , d2 ) ;
float wValue = getW ( wFPerm , wRPerm , wCPerm , d1 , d2 ) ;
dotProd += xValue * wValue ;
}
2021-09-11 16:29:31 +02:00
}
}
2021-06-07 02:47:59 +02:00
}
2021-10-22 22:09:52 +02:00
setOutput ( dotProd ) ;
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
` }};function IQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,dy:s}=e,{strides:a,pad:i,dataFormat:l,dimRoundingMode:u,filterShape:c}=n,p=I.convertConv2DDataFormat(l),m=I.computeConv2DInfo(o.shape,c,a,1,i,u,!1,p),f=new SI(m);return t.runWebGLProgram(f,[o,s],"float32")}var YM={kernelName:Kc,backendName:"webgl",kernelFunc:IQ};function SQ(r){let{inputs:e,backend:t,attrs:n}=r,{dy:o,filter:s}=e,{inputShape:a,strides:i,pad:l,dataFormat:u,dimRoundingMode:c}=n,p=I.convertConv2DDataFormat(u),m=I.computeConv2DInfo(a,s.shape,i,1,l,c,!1,p),f=new NI(m);return t.runWebGLProgram(f,[o,s],"float32")}var ZM={kernelName:Lo,backendName:"webgl",kernelFunc:SQ};function NQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,filter:s}=e,{strides:a,pad:i,dilations:l}=n,u=I.computeConv3DInfo(o.shape,s.shape,a,l,i),c=new CI(u);return t.runWebGLProgram(c,[o,s],"float32")}var JM={kernelName:hl,backendName:"webgl",kernelFunc:NQ};function TQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,dy:s}=e,{strides:a,pad:i,filterShape:l}=n,u=I.computeConv3DInfo(o.shape,l,a,1,i),c=new TI(u);return t.runWebGLProgram(c,[o,s],"float32")}var QM={kernelName:Xc,backendName:"webgl",kernelFunc:TQ};function EQ(r){let{inputs:e,backend:t,attrs:n}=r,{dy:o,filter:s}=e,{pad:a,strides:i,inputShape:l}=n,u=I.computeConv3DInfo(l,s.shape,i,1,a),c=new EI(u);return t.runWebGLProgram(c,[o,s],"float32")}var eL={kernelName:Yc,backendName:"webgl",kernelFunc:EQ};var AQ=tb+ `
return cos ( x ) ;
` ,DQ=ve({opSnippet:AQ}),tL={kernelName:zo,backendName:"webgl",kernelFunc:DQ};var $ Q= `
float e2x = exp ( - x ) ;
return ( e2x + 1.0 / e2x ) / 2.0 ;
` ,RQ=ve({opSnippet: $ Q}),rL={kernelName:Bo,backendName:"webgl",kernelFunc:RQ};var AI=class{constructor(e,t,n,o,s){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];let[a,i,l,u]=e,[c]=t,[p,m]=n;this.outputShape=[c,p,m,u];let f=o==="bilinear"?1:0,[d,h]=[ ` $ { i - 1 } . 0 ` , ` $ { l - 1 } . 0 ` ],[g,x,y]=p>1?[ ` $ { ( i - 1 ) / ( p - 1 ) } ` ,"(y2-y1) * height_ratio", ` y1 * $ { d } + float ( y ) * ( height _scale ) ` ]:["0.0","0.0", ` 0.5 * ( y1 + y2 ) * $ { d } ` ],[w,_,C]=m>1?[ ` $ { ( l - 1 ) / ( m - 1 ) } ` ,"(x2-x1) * width_ratio", ` x1 * $ { h } + float ( x ) * ( width _scale ) ` ]:["0.0","0.0", ` 0.5 * ( x1 + x2 ) * $ { h } ` ];this.userCode= `
const float height _ratio = float ( $ { g } ) ;
const float width _ratio = float ( $ { w } ) ;
2021-09-11 17:17:13 +02:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
2021-10-22 22:09:52 +02:00
int y = coords [ 1 ] ;
int x = coords [ 2 ] ;
2021-09-11 17:17:13 +02:00
int d = coords [ 3 ] ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
// get box vals
float y1 = getBoxes ( b , 0 ) ;
float x1 = getBoxes ( b , 1 ) ;
float y2 = getBoxes ( b , 2 ) ;
float x2 = getBoxes ( b , 3 ) ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
// get image in batch index
int bInd = round ( getBoxInd ( b ) ) ;
if ( bInd < 0 || bInd >= $ { a } ) {
return ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
float height _scale = $ { x } ;
float width _scale = $ { _ } ;
float in _y = $ { y } ;
if ( in _y < 0.0 || in _y > $ { d } ) {
setOutput ( float ( $ { s } ) ) ;
return ;
}
float in _x = $ { C } ;
if ( in _x < 0.0 || in _x > $ { h } ) {
setOutput ( float ( $ { s } ) ) ;
return ;
}
vec2 sourceFracIndexCR = vec2 ( in _x , in _y ) ;
if ( $ { f } == 1 ) {
// Compute the four integer indices.
ivec2 sourceFloorCR = ivec2 ( sourceFracIndexCR ) ;
ivec2 sourceCeilCR = ivec2 ( ceil ( sourceFracIndexCR ) ) ;
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 ) ;
vec2 fracCR = sourceFracIndexCR - vec2 ( sourceFloorCR ) ;
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 ) ;
}
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
` }};var FQ=r=>{let{inputs:e,backend:t,attrs:n}=r,{image:o,boxes:s,boxInd:a}=e,{cropSize:i,method:l,extrapolationValue:u}=n,c=new AI(o.shape,s.shape,i,l,u);return t.runWebGLProgram(c,[o,s,a],"float32")},nL={kernelName:Hi,backendName:"webgl",kernelFunc:FQ};var ub=class{constructor(e,t,n){this.variableNames=["x"],this.customUniforms=[{name:"index",type:"float"}],this.outputShape=e;let o=e.length,s=t?"0.0": ` getX ( $ { oL ( o , "coords" ) } ) ` ,a=e[e.length-1],i="",l="";t?(i=n? ` end != $ { a - 1 } ` :"end != 0",l=n?"end + 1":"end - 1"):(i=n? ` end + pow2 < $ { a } ` :"end >= pow2",l=n?"end + pow2":"end - pow2"),this.userCode= `
void main ( ) {
$ { Ue ( o ) } coords = getOutputCoords ( ) ;
int end = $ { sL ( o , "coords" ) } ;
float val = $ { s } ;
int pow2 = int ( pow ( 2.0 , index ) ) ;
if ( $ { i } ) {
int idx = $ { l } ;
$ { sL ( o , "coords" ) } = idx ;
val += getX ( $ { oL ( o , "coords" ) } ) ;
}
setOutput ( val ) ;
}
` }};function oL(r,e){if(r===1)return ` $ { e } ` ;if(r===2)return ` $ { e } . x , $ { e } . y ` ;if(r===3)return ` $ { e } . x , $ { e } . y , $ { e } . z ` ;if(r===4)return ` $ { e } . x , $ { e } . y , $ { e } . z , $ { e } . w ` ;throw Error( ` Cumulative sum for rank $ { r } is not yet supported ` )}function sL(r,e){if(r===1)return ` $ { e } ` ;if(r===2)return ` $ { e } . y ` ;if(r===3)return ` $ { e } . z ` ;if(r===4)return ` $ { e } . w ` ;throw Error( ` Cumulative sum for rank $ { r } is not yet supported ` )}function OQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{axis:s,exclusive:a,reverse:i}=n,l=o.shape.length,u=I.getAxesPermutation([s],l),c=o;u!=null&&(c=Pt({inputs:{x:o},backend:t,attrs:{perm:u}}));let p=I.getInnerMostAxes(1,l)[0];if(p!==l-1)throw new Error( ` WebGL cumsum shader expects an inner - most axis = $ { o . shape . length - 1 } but got axis = $ { s } ` );let m=c.shape[p],f=Qt({inputs:{x:c},backend:t});for(let d=0;d<=Math.ceil(Math.log2(m))-1;d++){let h=new ub(c.shape,!1,i),g=[[d]],x=f;f=t.runWebGLProgram(h,[f],f.dtype,g),t.disposeIntermediateTensorInfo(x)}if(a){let d=new ub(c.shape,a,i),h=f;f=t.runWebGLProgram(d,[f],f.dtype),t.disposeIntermediateTensorInfo(h)}if(u!=null){let d=I.getUndoAxesPermutation(u),h=Pt({inputs:{x:f},backend:t,attrs:{perm:d}});return t.disposeIntermediateTensorInfo(f),t.disposeIntermediateTensorInfo(c),h}return f}var iL={kernelName:Vo,backendName:"webgl",kernelFunc:OQ};function PQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,weights:s}=e,{size:a,binaryOutput:i}=n;if(o.shape.length===1){let l=t.readSync(o.dataId),u=t.readSync(s.dataId),c=Yy(l,u,s.dtype,s.shape,a);return t.makeTensorInfo([a],s.dtype,c)}else if(o.shape.length===2){let l=t.bufferSync(o),u=t.bufferSync(s),c=ZO(l,u,a,i);return t.makeTensorInfo(c.shape,s.dtype,c.values)}throw new Error( ` Error in denseBincount : input must be at most rank 2 , but got rank$ { o . shape . length } . ` )}var aL={kernelName:Zc,backendName:"webgl",kernelFunc:PQ};var DI=class{constructor(e,t,n){this.variableNames=["x"],this.outputShape=[],this.outputShape=e,this.blockSize=t,this.dataFormat=n,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 / $ { t } ;
int offset _h = imod ( h , $ { t } ) ;
int in _w = w / $ { t } ;
int offset _w = imod ( w , $ { t } ) ;
int offset _d = ( offset _h * $ { t } + offset _w ) *
$ { this . getOutputDepthSize ( ) } ;
int in _d = d + offset _d ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
float result = $ { this . getInputSamplingString ( ) } ;
setOutput ( result ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }getHeightCoordString(){return this.dataFormat==="NHWC"?"coords[1]":"coords[2]"}getWidthCoordString(){return this.dataFormat==="NHWC"?"coords[2]":"coords[3]"}getDepthCoordString(){return this.dataFormat==="NHWC"?"coords[3]":"coords[1]"}getOutputDepthSize(){return this.dataFormat==="NHWC"?this.outputShape[3]:this.outputShape[1]}getInputSamplingString(){return this.dataFormat==="NHWC"?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"}};function MQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{blockSize:s,dataFormat:a}=n,i=o.shape[0],l=a==="NHWC"?o.shape[1]:o.shape[2],u=a==="NHWC"?o.shape[2]:o.shape[3],c=a==="NHWC"?o.shape[3]:o.shape[1],p=l*s,m=u*s,f=c/(s*s),d=a==="NHWC"?[i,p,m,f]:[i,f,p,m],h=new DI(d,s,a);return t.runWebGLProgram(h,[o],o.dtype)}var lL={kernelName:qi,backendName:"webgl",kernelFunc:MQ};var Xh=class{constructor(e,t=!1,n=null,o=!1,s=!1){this.variableNames=["x","W"],this.customUniforms=[{name:"pads",type:"ivec2"},{name:"strides",type:"ivec2"},{name:"dilations",type:"ivec2"},{name:"inDims",type:"ivec2"}],this.outputShape=e.outShape,this.enableShapeUniforms=jt(this.outputShape.length);let a=e.filterHeight,i=e.filterWidth,l=e.outChannels/e.inChannels,u="",c="";n&&(o?u= ` float activation ( float a ) {
float b = getPreluActivationWeightsAtOutCoords ( ) ;
$ { n }
} ` :s?u= ` float activation ( float a ) {
float b = getLeakyreluAlphaAtOutCoords ( ) ;
$ { n }
} ` :u= `
float activation ( float x ) {
$ { n }
}
` ,c="result = activation(result);");let p=t?"result += getBiasAtOutCoords();":"";t&&this.variableNames.push("bias"),o&&this.variableNames.push("preluActivationWeights"),s&&this.variableNames.push("leakyreluAlpha"),this.userCode= `
$ { u }
2021-09-11 17:17:13 +02:00
2021-09-11 16:29:31 +02:00
void main ( ) {
2021-09-11 17:17:13 +02:00
ivec4 coords = getOutputCoords ( ) ;
2021-10-22 22:09:52 +02:00
int batch = coords . x ;
ivec2 xRCCorner = coords . yz * strides - pads ;
int d2 = coords . w ;
int d1 = d2 / $ { l } ;
int q = d2 - d1 * $ { l } ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02: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 < $ { a } ; wR ++ ) {
int xR = xRCorner + wR * dilations [ 0 ] ;
2021-06-05 19:02:01 +02:00
2021-10-22 22:09:52 +02:00
if ( xR < 0 || xR >= inDims [ 0 ] ) {
continue ;
}
2021-06-05 19:02:01 +02:00
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { i } ; wC ++ ) {
int xC = xCCorner + wC * dilations [ 1 ] ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xC < 0 || xC >= inDims [ 1 ] ) {
continue ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float xVal = getX ( batch , xR , xC , d1 ) ;
float wVal = getW ( wR , wC , d1 , q ) ;
dotProd += xVal * wVal ;
}
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float result = dotProd ;
$ { p }
$ { c }
setOutput ( result ) ;
}
` }};var Yh=class{constructor(e,t=!1,n=null,o=!1,s=!1){this.variableNames=["x","W"],this.packedInputs=!0,this.packedOutput=!0,this.customUniforms=[{name:"pads",type:"ivec2"},{name:"strides",type:"ivec2"},{name:"dilations",type:"ivec2"},{name:"inDims",type:"ivec2"}],this.outputShape=e.outShape,this.enableShapeUniforms=jt(this.outputShape.length);let a=e.outChannels/e.inChannels,i=e.padInfo.left,l=e.strideWidth,u=e.dilationWidth,c=e.filterHeight,p=e.filterWidth,m=p,f= `
int xR ; int xC ; int xCOffset ;
vec4 wTexel ; vec4 previous ; vec4 final ; ` ;for(let x=0;x<p;x++)f+= `
vec4 xTexelC$ { x * 2 } ;
int xTexelC$ { x * 2 } Ready ;
vec4 xTexelC$ { x * 2 + 1 } ;
int xTexelC$ { x * 2 + 1 } Ready ;
vec4 xC$ { x } ; ` ;f+= `
for ( int r = 0 ; r < $ { c } ; r ++ ) {
` ;for(let x=0;x<p;x++)f+= `
xTexelC$ { x * 2 } = vec4 ( 0.0 ) ;
xTexelC$ { x * 2 } Ready = 0 ;
xTexelC$ { x * 2 + 1 } = vec4 ( 0.0 ) ;
xTexelC$ { x * 2 + 1 } Ready = 0 ;
xC$ { x } = vec4 ( 0.0 ) ; ` ;f+= `
xR = xRCorner + r * dilations [ 0 ] ;
if ( xR >= 0 && xR < inDims [ 0 ] ) {
` ;for(let x=0;x<(m+1)/2;x++){let y=x*2;if(f+= `
xC = xCCorner + $ { y * u } ;
` ,l===1){if(y<p&&(i%2==1?(f+= `
xCOffset = xC + 1 ;
if ( xCOffset >= 0 && xCOffset < inDims [ 1 ] && xTexelC$ { y } Ready == 0 ) {
xTexelC$ { y } = getX ( batch , xR , xCOffset , d1 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if ( xCOffset + 1 >= inDims [ 1 ] ) {
xTexelC$ { y } . zw = vec2 ( 0.0 ) ;
}
xTexelC$ { y } Ready = 1 ;
}
` ,u===1&&y>0?f+= `
xC$ { y } = vec4 ( xTexelC$ { y - 2 } . zw , xTexelC$ { y } . xy ) ;
` :f+= `
xCOffset = xC + 1 - 2 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xCOffset >= 0 && xCOffset < inDims [ 1 ] ) {
previous = getX ( batch , xR , xCOffset , d1 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if ( xCOffset + 1 >= inDims [ 1 ] ) {
previous . zw = vec2 ( 0.0 ) ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
xC$ { y } = vec4 ( previous . zw , xTexelC$ { y } . xy ) ;
} else {
xC$ { y } = vec4 ( 0.0 , 0.0 , xTexelC$ { y } . xy ) ;
}
` ):f+= `
if ( xC >= 0 && xC < inDims [ 1 ] && xTexelC$ { y } Ready == 0 ) {
xTexelC$ { y } = getX ( batch , xR , xC , d1 ) ;
if ( xC + 1 >= inDims [ 1 ] ) {
xTexelC$ { y } . zw = vec2 ( 0.0 ) ;
}
xTexelC$ { y } Ready = 1 ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
xC$ { y } = xTexelC$ { y } ;
` ,y+1<p)){let w=i%2==0?b.nearestLargerEven(u):u;u%2==0&&i%2==1||u%2!=0&&i%2!=1?(f+= `
xCOffset = xC + imod ( pads [ 1 ] , 2 ) + $ { w } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xCOffset >= 0 && xCOffset < inDims [ 1 ] && xTexelC$ { y + 1 } Ready == 0 ) {
xTexelC$ { y + 1 } = getX ( batch , xR , xCOffset , d1 ) ;
2021-06-05 19:02:01 +02:00
2021-10-22 22:09:52 +02:00
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if ( xCOffset + 1 >= inDims [ 1 ] ) {
xTexelC$ { y + 1 } . zw = vec2 ( 0.0 ) ;
}
xTexelC$ { y + 1 } Ready = 1 ;
}
` ,u>1&&(f+= `
xCOffset -= 2 ;
if ( xCOffset >= 0 && xCOffset < inDims [ 1 ] && xTexelC$ { y } Ready == 0 ) {
xTexelC$ { y } = getX ( batch , xR , xCOffset , d1 ) ;
xTexelC$ { y } Ready = 1 ;
}
` ),f+= `
xC$ { y + 1 } = vec4 ( xTexelC$ { y } . zw , xTexelC$ { y + 1 } . xy ) ;
` ):w===1?f+= `
xC$ { y + 1 } = xTexelC$ { y } ;
` :f+= `
xCOffset = xC + $ { w } ;
if ( xCOffset >= 0 && xCOffset < inDims [ 1 ] && xTexelC$ { y + 1 } Ready == 0 ) {
xTexelC$ { y + 1 } = getX ( batch , xR , xCOffset , d1 ) ;
if ( xCOffset + 1 >= inDims [ 1 ] ) {
xTexelC$ { y + 1 } . zw = vec2 ( 0.0 ) ;
}
xTexelC$ { y + 1 } Ready = 1 ;
}
2021-06-05 19:02:01 +02:00
2021-10-22 22:09:52 +02:00
xC$ { y + 1 } = xTexelC$ { y + 1 } ;
` }}else y<p&&(i%2==1?(f+= `
xCOffset = xC + 1 - strides [ 1 ] ;
if ( xCOffset >= 0 && xCOffset < inDims [ 1 ] && xTexelC$ { y } Ready == 0 ) {
xTexelC$ { y } = getX ( batch , xR , xCOffset , d1 ) ;
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if ( xCOffset + 1 >= inDims [ 1 ] ) {
xTexelC$ { y } . zw = vec2 ( 0.0 ) ;
}
xTexelC$ { y } Ready = 1 ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( xC + 1 >= 0 && xC + 1 < inDims [ 1 ] && xTexelC$ { y + 1 } Ready == 0 ) {
xTexelC$ { y + 1 } = getX ( batch , xR , xC + 1 , d1 ) ;
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if ( xC + 2 >= inDims [ 1 ] ) {
xTexelC$ { y + 1 } . zw = vec2 ( 0.0 ) ;
}
xTexelC$ { y + 1 } Ready = 1 ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
xC$ { y } = vec4 ( xTexelC$ { y } . zw , xTexelC$ { y + 1 } . zw ) ;
` ,y+1<p&&(f+= `
final = vec4 ( 0.0 ) ;
xCOffset = xC + 1 + strides [ 1 ] ;
if ( xCOffset >= 0 && xCOffset < inDims [ 1 ] ) {
final = getX ( batch , xR , xCOffset , d1 ) ;
}
xC$ { y + 1 } = vec4 ( xTexelC$ { y + 1 } . xy , final . xy ) ;
` )):(f+= `
if ( xC >= 0 && xC < inDims [ 1 ] && xTexelC$ { y } Ready == 0 ) {
xTexelC$ { y } = getX ( batch , xR , xC , d1 ) ;
if ( xC + 1 >= inDims [ 1 ] ) {
xTexelC$ { y } . zw = vec2 ( 0.0 ) ;
}
xTexelC$ { y } Ready = 1 ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
xCOffset = xC + strides [ 1 ] ;
if ( xCOffset >= 0 && xCOffset < inDims [ 1 ] && xTexelC$ { y + 1 } Ready == 0 ) {
xTexelC$ { y + 1 } = getX ( batch , xR , xCOffset , d1 ) ;
if ( xCOffset + 1 >= inDims [ 1 ] ) {
xTexelC$ { y + 1 } . zw = vec2 ( 0. ) ;
}
xTexelC$ { y + 1 } Ready = 1 ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
xC$ { y } = vec4 (
xTexelC$ { y } . xy , xTexelC$ { y + 1 } . xy ) ;
` ,y+1<p&&(f+= `
xC$ { y + 1 } = vec4 ( xTexelC$ { y } . zw , xTexelC$ { y + 1 } . zw ) ;
` )));y<p&&(f+= `
wTexel = getW ( r , $ { y } , d1 , q ) ;
dotProd += xC$ { y } * vec4 ( wTexel . xz , wTexel . xz ) ;
` ,y+1<p&&(f+= `
wTexel = getW ( r , $ { y + 1 } , d1 , q ) ;
dotProd += xC$ { y + 1 } * vec4 ( wTexel . xz , wTexel . xz ) ;
` ))}f+= `
}
` ,f+= `
}
` ;let d="",h="";n&&(o?d= ` vec4 activation ( vec4 a ) {
vec4 b = getPreluActivationWeightsAtOutCoords ( ) ;
$ { n }
} ` :s?d= ` vec4 activation ( vec4 a ) {
vec4 b = getLeakyreluAlphaAtOutCoords ( ) ;
$ { n }
} ` :d= ` vec4 activation ( vec4 x ) {
$ { n }
} ` ,h="result = activation(result);");let g=t?"result += getBiasAtOutCoords();":"";t&&this.variableNames.push("bias"),o&&this.variableNames.push("preluActivationWeights"),s&&this.variableNames.push("leakyreluAlpha"),this.userCode= `
$ { d }
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords . x ;
ivec2 xRCCorner = coords . yz * strides - pads ;
int d2 = coords . w ;
int d1 = d2 / $ { a } ;
int q = d2 - d1 * $ { a } ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
//intialize dotProd with a small epsilon seems to reduce GPU accuracy loss.
vec4 dotProd = vec4 ( 0.000000000000001 ) ;
2021-06-07 02:34:29 +02:00
2021-10-22 22:09:52 +02:00
$ { f }
2021-06-05 19:02:01 +02:00
2021-10-22 22:09:52 +02:00
vec4 result = dotProd - vec4 ( 0.000000000000001 ) ;
$ { g }
$ { h }
setOutput ( result ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }};function LQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,filter:s}=e,{strides:a,pad:i,dilations:l,dimRoundingMode:u}=n,c=l;c==null&&(c=[1,1]),b.assert(I.eitherStridesOrDilationsAreOne(a,c),()=> ` Error in depthwiseConv2d : Either strides or dilations must be 1. Got strides $ { a } and dilations '${c}' ` );let p=I.computeConv2DInfo(o.shape,s.shape,a,c,i,u,!0),m;U().getBool("WEBGL_PACK_DEPTHWISECONV")&&p.strideWidth<=2&&p.outChannels/p.inChannels==1?m=new Yh(p):m=new Xh(p);let f=[[p.padInfo.top,p.padInfo.left],[p.strideHeight,p.strideWidth],[p.dilationHeight,p.dilationWidth],[p.inHeight,p.inWidth]];return t.runWebGLProgram(m,[o,s],"float32",f)}var uL={kernelName:Go,backendName:"webgl",kernelFunc:LQ};var $ I=class{constructor(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;let t=e.strideHeight,n=e.strideWidth,o=e.padInfo.top,s=e.padInfo.left,a=e.outChannels/e.inChannels;this.userCode= `
2021-09-11 17:17:13 +02:00
void main ( ) {
2021-10-22 22:09:52 +02:00
ivec4 coords = getOutputCoords ( ) ;
int wR = coords . x ;
int wC = coords . y ;
int d1 = coords . z ;
int dm = coords . w ;
int d2 = d1 * $ { a } + dm ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float dotProd = 0.0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// TO DO: Vec4 over the batch size
for ( int b = 0 ; b < $ { e . batchSize } ; b ++ ) {
for ( int yR = 0 ; yR < $ { e . outHeight } ; yR ++ ) {
int xR = wR + yR * $ { t } - $ { o } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
for ( int yC = 0 ; yC < $ { e . outWidth } ; yC ++ ) {
int xC = wC + yC * $ { n } - $ { s } ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
2021-06-05 19:02:01 +02:00
2021-10-22 22:09:52 +02:00
float dyValue = getDy ( b , yR , yC , d2 ) ;
float xValue = getX ( b , xR , xC , d1 ) ;
dotProd += ( xValue * dyValue ) ;
2021-09-11 16:29:31 +02:00
}
}
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
setOutput ( dotProd ) ;
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
` }},RI=class{constructor(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;let t=e.filterHeight,n=e.filterWidth,o=e.strideHeight,s=e.strideWidth,a=t-1-e.padInfo.top,i=n-1-e.padInfo.left,l=e.outChannels/e.inChannels;this.userCode= `
const ivec2 pads = ivec2 ( $ { a } , $ { i } ) ;
2021-06-07 02:47:59 +02:00
void main ( ) {
2021-10-22 22:09:52 +02: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 ;
2021-07-29 15:53:13 +02:00
2021-10-22 22:09:52 +02:00
float dotProd = 0.0 ;
2021-07-29 15:53:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int wR = 0 ; wR < $ { t } ; wR ++ ) {
float dyR = float ( dyRCorner + wR ) / $ { o } . 0 ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
int wRPerm = $ { t } - 1 - wR ;
2021-07-29 15:53:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { n } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { s } . 0 ;
2021-07-29 15:53:13 +02:00
2021-10-22 22:09:52 +02:00
if ( dyC < 0.0 || dyC >= $ { e . outWidth } . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
2021-07-29 15:53:13 +02:00
2021-10-22 22:09:52 +02:00
int wCPerm = $ { n } - 1 - wC ;
2021-07-29 15:53:13 +02:00
2021-10-22 22:09:52 +02:00
// 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 ) ;
}
` }};function zQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,dy:s}=e,{strides:a,dilations:i,pad:l,dimRoundingMode:u,filterShape:c}=n,p=I.computeConv2DInfo(o.shape,c,a,i,l,u,!0),m=new $ I(p);return t.runWebGLProgram(m,[o,s],"float32")}var cL={kernelName:Jc,backendName:"webgl",kernelFunc:zQ};function BQ(r){let{inputs:e,backend:t,attrs:n}=r,{dy:o,filter:s}=e,{strides:a,dilations:i,pad:l,dimRoundingMode:u,inputShape:c}=n,p=I.computeConv2DInfo(c,s.shape,a,i,l,u,!0),m=new RI(p);return t.runWebGLProgram(m,[o,s],"float32")}var pL={kernelName:Qc,backendName:"webgl",kernelFunc:BQ};var FI=class{constructor(e){this.variableNames=["X"],this.outputShape=[e,e],this.userCode= `
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
float val = coords [ 0 ] == coords [ 1 ] ? getX ( coords [ 0 ] ) : 0.0 ;
setOutput ( val ) ;
}
` }};function VQ(r){let{inputs:e,backend:t}=r,{x:n}=e,o=[...n.shape,...n.shape],s=b.sizeFromShape(n.shape),a=ue({inputs:{x:n},backend:t,attrs:{shape:[s]}}),i=new FI(s),l=t.runWebGLProgram(i,[a],a.dtype),u=ue({inputs:{x:l},backend:t,attrs:{shape:o}});return t.disposeIntermediateTensorInfo(a),t.disposeIntermediateTensorInfo(l),u}var mL={kernelName:ep,backendName:"webgl",kernelFunc:VQ};var OI=class{constructor(e){this.variableNames=["x","W"],this.outputShape=e.outShape;let{inHeight:t,inWidth:n,padInfo:o,strideHeight:s,strideWidth:a,filterHeight:i,filterWidth:l,dilationHeight:u,dilationWidth:c}=e,{top:p,left:m}=o;this.userCode= `
const ivec2 strides = ivec2 ( $ { s } , $ { a } ) ;
const ivec2 pads = ivec2 ( $ { p } , $ { m } ) ;
const float neg _infinity = - 3.4 e38 ;
2021-07-29 15:53:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int d1 = coords . w ;
ivec2 outTopLeftCorner =
coords . yz * strides - pads ;
int hBeg = outTopLeftCorner . x ;
int wBeg = outTopLeftCorner . y ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
float curVal = neg _infinity ;
for ( int h = 0 ; h < $ { i } ; h ++ ) {
int hIn = hBeg + h * $ { u } ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
if ( hIn >= 0 && hIn < $ { t } ) {
for ( int w = 0 ; w < $ { l } ; w ++ ) {
int wIn = wBeg + w * $ { c } ;
2021-06-07 02:34:29 +02:00
2021-10-22 22:09:52 +02:00
if ( wIn >= 0 && wIn < $ { n } ) {
float xVal = getX ( batch , hIn , wIn , d1 ) ;
float wVal = getW ( h , w , d1 ) ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
float val = xVal + wVal ;
if ( val > curVal ) {
curVal = val ;
}
}
}
}
}
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
float result = curVal ;
setOutput ( result ) ;
}
` }};function GQ(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,filter:s}=e,{strides:a,pad:i,dilations:l}=n,u=I.computeDilation2DInfo(o.shape,s.shape,a,i,"NHWC",l),c,p=new OI(u);c=t.runWebGLProgram(p,[o,s],"float32");let m=ue({inputs:{x:c},backend:t,attrs:{shape:u.outShape}});return t.disposeIntermediateTensorInfo(c),m}var fL={kernelName:gl,backendName:"webgl",kernelFunc:GQ};function WQ(r){let{inputs:e,backend:t,attrs:n}=r,{equation:o}=n,s=e,{allDims:a,summedDims:i,idDims:l}=I.decodeEinsumEquation(o,s.length);I.checkEinsumDimSizes(a.length,l,s);let{path:u,steps:c}=I.getEinsumComputePath(i,l),p=c.length,m=null,f=a.length,d=[];for(let h=0;h<p;++h){for(let g of c[h]){let{permutationIndices:x,expandDims:y}=I.getEinsumPermutation(f,l[g]),w;I.isIdentityPermutation(x)?w=s[g]:(w=Pt({inputs:{x:s[g]},backend:t,attrs:{perm:x}}),d.push(w));let _=w.shape.slice();for(let C=0;C<y.length;++C)_.splice(y[C],0,1);b.arraysEqual(w.shape,_)||(w=ue({inputs:{x:w},backend:t,attrs:{shape:_}}),d.push(w)),m===null?m=w:(m=qh({inputs:{a:w,b:m},backend:t}),d.push(m))}h<p-1&&(u[h]>=0&&(m=kc({inputs:{x:m},backend:t,attrs:{axis:u[h]-(a.length-f),keepDims:!1}}),d.push(m)),f--)}for(let h of d)h!==m&&t.disposeIntermediateTensorInfo(h);return m}var dL={kernelName:tp,backendName:"webgl",kernelFunc:WQ};var UQ="return (x >= 0.0) ? x : (exp(x) - 1.0);",jQ= `
vec4 result ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
result . r = ( x . r >= 0.0 ) ? x . r : ( exp ( x . r ) - 1.0 ) ;
result . g = ( x . g >= 0.0 ) ? x . g : ( exp ( x . g ) - 1.0 ) ;
result . b = ( x . b >= 0.0 ) ? x . b : ( exp ( x . b ) - 1.0 ) ;
result . a = ( x . a >= 0.0 ) ? x . a : ( exp ( x . a ) - 1.0 ) ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
return result ;
` ,HQ=ve({opSnippet:UQ,packedOpSnippet:jQ}),hL={kernelName:Uo,backendName:"webgl",kernelFunc:HQ};var qQ="return (b >= 1.0) ? a : a * (b + 1.0);",KQ= `
vec4 bGTEZero = vec4 ( greaterThanEqual ( b , vec4 ( 0. ) ) ) ;
return ( bGTEZero * a ) + ( ( vec4 ( 1.0 ) - bGTEZero ) * ( a * ( b + vec4 ( 1.0 ) ) ) ) ;
` ,XQ=r=>{let{inputs:e,backend:t}=r,{dy:n,y:o}=e,s=U().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Ys(KQ,n.shape,o.shape):new No(qQ,n.shape,o.shape);return t.runWebGLProgram(s,[n,o],n.dtype)},gL={kernelName:rp,backendName:"webgl",kernelFunc:XQ};var YQ= `
return vec4 ( equal ( a , b ) ) ;
` ,ZQ="return float(a == b);",JQ=at({opSnippet:ZQ,packedOpSnippet:YQ,dtype:"bool",cpuKernelImpl:eP}),xL={kernelName:Xi,backendName:"webgl",kernelFunc:JQ};var QQ= `
// 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 . ERF _P } ;
float a1 = $ { I . ERF _A1 } ;
float a2 = $ { I . ERF _A2 } ;
float a3 = $ { I . ERF _A3 } ;
float a4 = $ { I . ERF _A4 } ;
float a5 = $ { I . ERF _A5 } ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
float sign = sign ( x ) ;
x = abs ( x ) ;
float t = 1.0 / ( 1.0 + p * x ) ;
return sign * ( 1.0 - ( ( ( ( ( a5 * t + a4 ) * t ) + a3 ) * t + a2 ) * t + a1 ) * t * exp ( - x * x ) ) ;
` ,eee=ve({opSnippet:QQ}),yL={kernelName:Ki,backendName:"webgl",kernelFunc:eee};var bL="return exp(x);",PI=ve({opSnippet:bL,packedOpSnippet:bL,cpuKernelImpl:tP,dtype:"float32"}),wL={kernelName:jo,backendName:"webgl",kernelFunc:PI};function cb(r){let{inputs:e,attrs:t,backend:n}=r,{dim:o}=t,{input:s}=e,a=s.shape.length,i=s.shape.slice(),l=o;return o<0&&(b.assert(-(a+1)<=o,()=> ` Axis must be in the interval [ $ { - ( a + 1 ) } , $ { a } ] ` ),l=a+o+1),i.splice(l,0,1),ue({inputs:{x:s},backend:n,attrs:{shape:i}})}var _L={kernelName:oi,backendName:"webgl",kernelFunc:cb};var kL="return exp(x) - 1.0;",tee=ve({opSnippet:kL,packedOpSnippet:kL,cpuKernelImpl:rP}),vL={kernelName:Yi,backendName:"webgl",kernelFunc:tee};var pb=class{constructor(e,t,n){this.variableNames=["real","imag"];let o=t[1];this.outputShape=t;let s=n? ` 2.0 * $ { Math . PI } ` : ` - 2.0 * $ { Math . PI } ` ,a=n? ` $ { o } . 0 ` :"1.0",i;if(e==="real")i="return real * expR - imag * expI;";else if(e==="imag")i="return real * expI + imag * expR;";else throw new Error( ` FFT component must be either "real" or "imag" , got $ { e } . ` );this.userCode= `
const float exponentMultiplier = $ { s } ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
float unaryOpComplex ( float real , float expR , float imag , float expI ) {
$ { i }
}
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
float mulMatDFT ( int batch , int index ) {
float indexRatio = float ( index ) / float ( $ { o } ) ;
float exponentMultiplierTimesIndexRatio =
exponentMultiplier * indexRatio ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
float result = 0.0 ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
for ( int i = 0 ; i < $ { o } ; 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 ) ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
result +=
unaryOpComplex ( real , expR , imag , expI ) / $ { a } ;
}
return result ;
}
2021-06-07 02:47:59 +02:00
2021-09-11 17:17:13 +02:00
void main ( ) {
2021-10-22 22:09:52 +02:00
ivec2 coords = getOutputCoords ( ) ;
setOutput ( mulMatDFT ( coords [ 0 ] , coords [ 1 ] ) ) ;
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
` }};function mb(r,e,t){let n=t.texData.get(r.dataId),o=b.sizeFromShape(r.shape),s=r.shape[r.shape.length-1],a=o/s,i=ue({inputs:{x:r},backend:t,attrs:{shape:[a,s]}}),l=i.shape,u=new pb("real",l,e),c=new pb("imag",l,e),p=[{dataId:n.complexTensorInfos.real.dataId,dtype:n.complexTensorInfos.real.dtype,shape:l},{dataId:n.complexTensorInfos.imag.dataId,dtype:n.complexTensorInfos.imag.dtype,shape:l}],m=t.runWebGLProgram(u,p,"float32"),f=t.runWebGLProgram(c,p,"float32"),d=An({inputs:{real:m,imag:f},backend:t});t.disposeIntermediateTensorInfo(m),t.disposeIntermediateTensorInfo(f);let h=ue({inputs:{x:d},backend:t,attrs:{shape:r.shape}});return t.disposeIntermediateTensorInfo(i),t.disposeIntermediateTensorInfo(d),h}function ree(r){let{inputs:e,backend:t}=r,{input:n}=e;return mb(n,!1,t)}var CL={kernelName:np,backendName:"webgl",kernelFunc:ree};var MI=class{constructor(e,t){this.outputShape=[],this.customUniforms=[{name:"value",type:"float"}],this.variableNames=["x"],this.outputShape=e,this.userCode= `
void main ( ) {
// Input can be obtained from uniform value.
setOutput ( value ) ;
}
` }};function rl(r){let{backend:e,attrs:t}=r,{shape:n,value:o}=t,{dtype:s}=t;if(s=s||b.inferDtype(o),s==="string"){let a=b.getArrayFromDType(s,b.sizeFromShape(n));return a.fill(o),e.makeTensorInfo(n,s,a)}else{let a=new MI(n,o),i=[[o]];return e.runWebGLProgram(a,[],s,i)}}var IL={kernelName:xl,backendName:"webgl",kernelFunc:rl};var LI=class{constructor(e){this.variableNames=["Image"],this.outputShape=[];let t=e[2];this.outputShape=e,this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int x = coords [ 2 ] ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int coordX = $ { t } - x - 1 ;
float outputValue ;
if ( coordX >= 0 && coordX < $ { t } ) {
outputValue = getImage ( coords [ 0 ] , coords [ 1 ] , coordX , coords [ 3 ] ) ;
} else {
outputValue = getImage ( coords [ 0 ] , coords [ 1 ] , coords [ 2 ] , coords [ 3 ] ) ;
}
setOutput ( outputValue ) ;
}
` }};var SL={kernelName:Zi,backendName:"webgl",kernelFunc:({inputs:r,backend:e})=>{let{image:t}=r,n=e,o=new LI(t.shape);return n.runWebGLProgram(o,[t],t.dtype)}};var NL="return floor(x);",nee=ve({opSnippet:NL,packedOpSnippet:NL,cpuKernelImpl:nP}),TL={kernelName:Ho,backendName:"webgl",kernelFunc:nee};var oee= `
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 ) ) ;
2021-09-11 17:17:13 +02:00
} else {
2021-10-22 22:09:52 +02:00
return NAN ;
2021-06-07 02:47:59 +02:00
}
2021-10-22 22:09:52 +02:00
` ,see= `
ivec4 ia = round ( a ) ;
ivec4 ib = round ( b ) ;
bvec4 cond = notEqual ( ib , ivec4 ( 0 ) ) ;
ivec4 result = ivec4 ( 0 ) ;
vec4 s = sign ( a ) * sign ( b ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02: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 ) ;
` ,iee=at({opSnippet:oee,packedOpSnippet:see,dtype:"int32"}),EL={kernelName:qo,backendName:"webgl",kernelFunc:iee};var zI=class{constructor(e){this.variableNames=["A"];let t=Gt(),[n,o]=e;this.outputShape=e,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 ( $ { o } . 0 , $ { n } . 0 ) ;
vec4 values = $ { t . 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 ;
}
setOutput ( floor ( value * 255.0 + 0.5 ) ) ;
}
` }};var BI=class{constructor(e){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;let t=Gt(),[n,o]=e;this.outputShape=e,this.userCode= `
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
int texR = coords [ 0 ] ;
int texC = coords [ 1 ] ;
int depth = coords [ 2 ] ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 result = vec4 ( 0. ) ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
for ( int row = 0 ; row <= 1 ; row ++ ) {
for ( int col = 0 ; col <= 1 ; col ++ ) {
texC = coords [ 1 ] + row ;
depth = coords [ 2 ] + col ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { o } . 0 , $ { n } . 0 ) ;
vec4 values = $ { t . 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 ;
}
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
result [ row * 2 + col ] = floor ( value * 255.0 + 0.5 ) ;
}
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
$ { t . output } = result ;
}
` }};var AL={kernelName:nf,backendName:"webgl",kernelFunc:aee},Pm;function aee(r){let{inputs:e,backend:t,attrs:n}=r,{pixels:o}=e,{numChannels:s}=n,a=typeof HTMLVideoElement!="undefined"&&o instanceof HTMLVideoElement,i=typeof HTMLImageElement!="undefined"&&o instanceof HTMLImageElement,[l,u]=a?[o.videoWidth,o.videoHeight]:[o.width,o.height],c=[u,l],p=[u,l,s];(i||a)&&(Pm==null&&(Pm=document.createElement("canvas").getContext("2d")),Pm.canvas.width=l,Pm.canvas.height=u,Pm.drawImage(o,0,0,l,u),o=Pm.canvas);let m=t.makeTensorInfo(c,"int32");t.texData.get(m.dataId).usage=Ur.PIXELS,t.gpgpu.uploadPixelDataToTexture(t.getTexture(m.dataId),o);let f=U().getBool("WEBGL_PACK")?new BI(p):new zI(p),d=t.runWebGLProgram(f,[m],"int32");return t.disposeData(m.dataId),d}function lee(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,filter:s,bias:a,preluActivationWeights:i}=e,{strides:l,pad:u,dataFormat:c,dilations:p,dimRoundingMode:m,activation:f,leakyreluAlpha:d}=n,h=I.convertConv2DDataFormat(c),g=I.computeConv2DInfo(o.shape,s.shape,l,p,u,m,!1,h),x,y=[];if(g.filterHeight===1&&g.filterWidth===1&&g.dilationHeight===1&&g.dilationWidth===1&&g.strideHeight===1&&g.strideWidth===1&&(g.padInfo.type==="SAME"||g.padInfo.type==="VALID"))x=ab({x:o,filter:s,convInfo:g,backend:t,bias:a,activation:f,preluActivationWeights:i,leakyreluAlpha:d});else if(U().getBool("WEBGL_CONV_IM2COL")&&o.shape[0]===1)x=lb({x:o,filter:s,convInfo:g,backend:t,bias:a,activation:f,preluActivationWeights:i,leakyreluAlpha:d});else{let _=a!=null,C=i!=null,A=f==="leakyrelu",D=f?Xl(f,!1):null,R=new Kh(g,_,D,C,A),P=[o,s];if(a&&P.push(a),i&&P.push(i),A){let L=t.makeTensorInfo([],"float32",b.createScalarValue(d,"float32"));P.push(L),y.push(L)}x=t.runWebGLProgram(R,P,"float32")}let w=ue({inputs:{x},backend:t,attrs:{shape:g.outShape}});return y.push(x),y.forEach(_=>t.disposeIntermediateTensorInfo(_)),w}var DL={kernelName:xi,backendName:"webgl",kernelFunc:lee};function uee(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,filter:s,bias:a,preluActivationWeights:i}=e,{strides:l,pad:u,dilations:c,dimRoundingMode:p,activation:m,leakyreluAlpha:f}=n,d=[],h=c;h==null&&(h=[1,1]),b.assert(I.eitherStridesOrDilationsAreOne(l,h),()=> ` Error in depthwiseConv2d : Either strides or dilations must be 1. Got strides $ { l } and dilations '${h}' ` );let g=I.computeConv2DInfo(o.shape,s.shape,l,h,u,p,!0),x=U().getBool("WEBGL_PACK_DEPTHWISECONV")&&g.strideWidth<=2&&g.outChannels/g.inChannels==1,y=m?Xl(m,x):null,w=[o,s],_=a!=null,C=i!=null,A=m==="leakyrelu";if(_&&w.push(a),C&&w.push(i),A){let L=t.makeTensorInfo([],"float32",b.createScalarValue(f,"float32"));w.push(L),d.push(L)}let D;x?D=new Yh(g,_,y,C,A):D=new Xh(g,_,y,C,A);let R=[[g.padInfo.top,g.padInfo.left],[g.strideHeight,g.strideWidth],[g.dilationHeight,g.dilationWidth],[g.inHeight,g.inWidth]],P=t.runWebGLProgram(D,w,"float32",R);return d.forEach(L=>t.disposeIntermediateTensorInfo(L)),P}var $ L={kernelName:yi,backendName:"webgl",kernelFunc:uee};var VI=class{constructor(e,t,n){this.sliceDim=e,this.strides=t,this.variableNames=["x","indices"],this.outputShape=n;let o=Ue(t.length),s=Ue(n.length),a=this.sliceDim>1?"strides[j]":"strides";this.userCode= `
$ { o } strides = $ { o } ( $ { this . strides } ) ;
void main ( ) {
$ { s } coords = getOutputCoords ( ) ;
int flattenIndex = 0 ;
for ( int j = 0 ; j < $ { this . sliceDim } ; j ++ ) {
int index = round ( getIndices ( coords [ 0 ] , j ) ) ;
flattenIndex += index * $ { a } ;
}
setOutput ( getX ( flattenIndex , coords [ 1 ] ) ) ;
}
` }};function cee(r){let{inputs:e,backend:t}=r,{params:n,indices:o}=e,s=o.shape,a=s[s.length-1],i=b.sizeFromShape(n.shape),[l,u,c,p]=I.prepareAndValidate(n,o),m=ue({inputs:{x:o},backend:t,attrs:{shape:[u,a]}}),f=ue({inputs:{x:n},backend:t,attrs:{shape:[b.sizeFromShape(n.shape)/c,c]}});if(t.shouldExecuteOnCPU([n,o])||n.dtype==="string"){let x=t.readSync(o.dataId),y=t.bufferSync(n),w=oP(x,y,n.dtype,u,a,c,p,n.shape,i);return t.makeTensorInfo(l,n.dtype,w.values)}let d=new VI(a,p,[u,c]),h=t.runWebGLProgram(d,[f,m],f.dtype),g=ue({inputs:{x:h},backend:t,attrs:{shape:l}});return t.disposeIntermediateTensorInfo(m),t.disposeIntermediateTensorInfo(f),t.disposeIntermediateTensorInfo(h),g}var RL={kernelName:Ji,backendName:"webgl",kernelFunc:cee};var GI=class{constructor(e,t){this.variableNames=["A","indices"],this.outputShape=t,this.rank=t.length;let n=Ue(this.rank),o=pee(e,2);this.userCode= `
2021-09-11 16:29:31 +02:00
void main ( ) {
2021-10-22 22:09:52 +02:00
$ { n } resRC = getOutputCoords ( ) ;
setOutput ( getA ( $ { o } ) ) ;
2021-06-07 02:34:29 +02:00
}
2021-10-22 22:09:52 +02:00
` }};function pee(r,e){let t=["resRC.x","resRC.y","resRC.z","resRC.w"],n=[];for(let o=0;o<r.length;o++)o===2?n.push("int(getIndices(resRC.x, resRC.z))"):n.push( ` $ { t [ o ] } ` );return n.join()}function WI(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,indices:s}=e,{axis:a,batchDims:i}=n,l=b.parseAxisParam(a,o.shape)[0],u=t.readSync(s.dataId),c=o.shape[l];for(let _=0;_<u.length;++_){let C=u[_];b.assert(C<=c-1&&C>=0,()=> ` GatherV2 : the index value $ { C } is not in [ 0 , $ { c - 1 } ] ` )}let p=I.segment_util.collectGatherOpShapeInfo(o,s,l,i),m=b.sizeFromShape(s.shape),f=[],d=ue({inputs:{x:o},backend:t,attrs:{shape:[p.batchSize,p.outerSize,p.dimSize,p.sliceSize]}}),h=ue({inputs:{x:s},backend:t,attrs:{shape:[p.batchSize,m/p.batchSize]}});f.push(d),f.push(h);let g=[p.batchSize,p.outerSize,m/p.batchSize,p.sliceSize];if(t.shouldExecuteOnCPU([o,s])||o.dtype==="string"){let _=t.bufferSync(h),C=t.bufferSync(d),A=sP(C,_,g);return f.forEach(D=>t.disposeIntermediateTensorInfo(D)),t.makeTensorInfo(p.outputShape,A.dtype,A.values)}let x=new GI(d.shape,g),y=t.runWebGLProgram(x,[d,h],d.dtype);f.push(y);let w=ue({inputs:{x:y},backend:t,attrs:{shape:p.outputShape}});return f.forEach(_=>t.disposeIntermediateTensorInfo(_)),w}var FL={kernelName:si,backendName:"webgl",kernelFunc:WI};var mee="return float(a > b);",fee= `
return vec4 ( greaterThan ( a , b ) ) ;
` ,dee=at({opSnippet:mee,packedOpSnippet:fee,cpuKernelImpl:iP,dtype:"bool"}),OL={kernelName:Qi,backendName:"webgl",kernelFunc:dee};var hee="return float(a >= b);",gee= `
return vec4 ( greaterThanEqual ( a , b ) ) ;
` ,xee=at({opSnippet:hee,packedOpSnippet:gee,dtype:"bool",cpuKernelImpl:aP}),PL={kernelName:Xo,backendName:"webgl",kernelFunc:xee};function yee(r){let{inputs:e,backend:t}=r,{input:n}=e;return mb(n,!0,t)}var ML={kernelName:op,backendName:"webgl",kernelFunc:yee};var bee="return float(!isnan(x) && !isinf(x));",wee=ve({opSnippet:bee,dtype:"bool"}),LL={kernelName:ea,backendName:"webgl",kernelFunc:wee};var _ee="return float(isinf(x));",kee=ve({opSnippet:_ee,dtype:"bool"}),zL={kernelName:ta,backendName:"webgl",kernelFunc:kee};var vee="return float(isnan(x));",Cee=ve({opSnippet:vee,dtype:"bool"}),BL={kernelName:ra,backendName:"webgl",kernelFunc:Cee};var Iee="return float(a < b);",See= `
return vec4 ( lessThan ( a , b ) ) ;
` ,Nee=at({opSnippet:Iee,packedOpSnippet:See,cpuKernelImpl:lP,dtype:"bool"}),VL={kernelName:na,backendName:"webgl",kernelFunc:Nee};var Tee="return float(a <= b);",Eee= `
return vec4 ( lessThanEqual ( a , b ) ) ;
` ,Aee=at({opSnippet:Tee,packedOpSnippet:Eee,cpuKernelImpl:uP,dtype:"bool"}),GL={kernelName:oa,backendName:"webgl",kernelFunc:Aee};function Dee(r){let{backend:e,attrs:t}=r,{start:n,stop:o,num:s}=t,a=cP(n,o,s);return e.makeTensorInfo([a.length],"float32",a)}var WL={kernelName:ip,backendName:"webgl",kernelFunc:Dee};var $ ee= ` if ( x < 0.0 ) return NAN ;
return log ( x ) ; ` ,Ree= `
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 ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
return result ;
` ,Fee=ve({opSnippet: $ ee,packedOpSnippet:Ree,cpuKernelImpl:pP}),UL={kernelName:Zo,backendName:"webgl",kernelFunc:Fee};var Oee="return log(1.0 + x);",Pee=ve({opSnippet:Oee}),jL={kernelName:sa,backendName:"webgl",kernelFunc:Pee};var Mee="return float(a >= 1.0 && b >= 1.0);",Lee= `
return vec4 (
vec4 ( greaterThanEqual ( a , vec4 ( 1.0 ) ) ) *
vec4 ( greaterThanEqual ( b , vec4 ( 1.0 ) ) ) ) ;
` ,zee=at({opSnippet:Mee,packedOpSnippet:Lee,dtype:"bool"}),HL={kernelName:ia,backendName:"webgl",kernelFunc:zee};var Bee="return float(!(x >= 1.0));",Vee=ve({opSnippet:Bee}),qL={kernelName:au,backendName:"webgl",kernelFunc:Vee};var Gee="return float(a >= 1.0 || b >= 1.0);",Wee= `
return min (
vec4 ( greaterThanEqual ( a , vec4 ( 1.0 ) ) ) +
vec4 ( greaterThanEqual ( b , vec4 ( 1.0 ) ) ) ,
vec4 ( 1.0 ) ) ;
` ,Uee=at({opSnippet:Gee,packedOpSnippet:Wee,dtype:"bool"}),KL={kernelName:lu,backendName:"webgl",kernelFunc:Uee};var UI=class{constructor(e,t,n,o,s){this.variableNames=["x"],this.outputShape=[];let a=t,i=e[3]-1;this.outputShape=e;let l,u= ` float ( $ { n } ) + float ( $ { o } ) * sum ` ;s===.5?l= ` inversesqrt ( $ { u } ) ` :s===1?l= ` 1.0 / ( $ { u } ) ` :l= ` exp ( log ( $ { u } ) * float ( - $ { s } ) ) ; ` ,this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
int d = coords [ 3 ] ;
float x = getX ( b , r , c , d ) ;
float sum = 0.0 ;
for ( int j = - $ { a } ; j <= $ { a } ; j ++ ) {
int idx = d + j ;
if ( idx >= 0 && idx <= $ { i } ) {
float z = getX ( b , r , c , idx ) ;
sum += z * z ;
}
}
float val = x * $ { l } ;
setOutput ( val ) ;
}
` }};var jI=class{constructor(e,t,n,o,s){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;let a=t,i=e[3]-1;this.outputShape=e;let l,u= ` float ( $ { n } ) + float ( $ { o } ) * sum ` ;s===.5?l= ` inversesqrt ( $ { u } ) ` :s===1?l= ` 1.0 / ( $ { u } ) ` :l= ` exp ( log ( $ { u } ) * float ( - $ { s } ) ) ; ` ,this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords . x ;
int r = coords . y ;
int c = coords . z ;
int d = coords . w ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
bool hasNextCol = d < $ { this . outputShape [ 3 ] } ;
bool hasNextRow = c < $ { this . outputShape [ 2 ] } ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
vec4 sum = vec4 ( 0. ) ;
vec4 xFragAtOutputCoords = getX ( b , r , c , d ) ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02: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
) ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
int firstChannel = d - $ { a } ;
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 ) ) ;
}
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
ivec2 depth = ivec2 ( d , d + 1 ) ;
for ( int j = - $ { a } ; j <= $ { a } ; j ++ ) {
ivec2 idx = depth + j ;
bvec2 aboveLowerBound = greaterThanEqual ( idx , ivec2 ( 0 ) ) ;
bvec2 belowUpperBound = lessThanEqual ( idx , ivec2 ( $ { i } ) ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
bool depthInRange = aboveLowerBound . x && belowUpperBound . x ;
bool depthPlusOneInRange = aboveLowerBound . y && belowUpperBound . y ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
if ( depthInRange || depthPlusOneInRange ) {
vec4 z = vec4 ( 0. ) ;
vec4 xFragAtCurrentDepth ;
z . xz = cache . xy ;
if ( depthPlusOneInRange && hasNextCol ) {
xFragAtCurrentDepth = idx . y != d ?
getX ( b , r , c , idx . y ) : xFragAtOutputCoords ;
z . y = getChannel ( xFragAtCurrentDepth , vec2 ( c , idx . y ) ) ;
if ( hasNextRow ) {
z . w = getChannel ( xFragAtCurrentDepth , vec2 ( c + 1 , idx . y ) ) ;
2021-09-11 17:17:13 +02:00
}
}
2021-10-22 22:09:52 +02:00
cache . xy = z . yw ;
sum += z * z ;
}
}
vec4 result = xAtOutputCoords * $ { l } ;
setOutput ( result ) ;
}
` }};var jee=r=>{let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{depthRadius:s,bias:a,alpha:i,beta:l}=n,u=U().getBool("WEBGL_PACK_NORMALIZATION")?new jI(o.shape,s,a,i,l):new UI(o.shape,s,a,i,l);return t.runWebGLProgram(u,[o],o.dtype)},XL={kernelName:yl,backendName:"webgl",kernelFunc:jee};var HI=class{constructor(e,t,n,o,s){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=e,this.depth=e[3],this.depthRadius=t,this.bias=n,this.alpha=o,this.beta=s,this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
float result = 0.0 ;
for ( int d = 0 ; d < $ { this . depth } ; ++ d ) {
int depthBegin = int ( max ( 0.0 , float ( d - $ { t } ) ) ) ;
int depthEnd = int ( min ( float ( $ { this . depth } ) ,
float ( d + $ { t } + 1 ) ) ) ;
const int MIN _DEPTH _BEGIN = 0 ;
const int MAX _DEPTH _END = $ { this . depth } ;
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 ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
}
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
norm = float ( $ { o } ) * norm + float ( $ { n } ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
for ( int k = MIN _DEPTH _BEGIN ; k < MAX _DEPTH _END ; ++ k ) {
if ( k < depthBegin ) {
continue ;
}
else if ( k >= depthBegin && k < depthEnd ) {
float dyi = - 2.0 * float ( $ { o } )
* float ( $ { s } )
* getInputImage ( b , r , c , k ) * getOutputImage ( b , r , c , d )
/ n o r m ;
if ( k == d ) {
dyi += pow ( norm , - 1.0 * $ { s } ) ;
}
if ( k == coords [ 3 ] ) {
dyi *= getDy ( b , r , c , d ) ;
result += dyi ;
2021-09-11 17:17:13 +02:00
}
}
2021-10-22 22:09:52 +02:00
else {
break ;
}
}
}
setOutput ( result ) ;
}
` }};var Hee=r=>{let{inputs:e,backend:t,attrs:n}=r,{x:o,y:s,dy:a}=e,{depthRadius:i,bias:l,alpha:u,beta:c}=n,p=new HI(o.shape,i,l,u,c);return t.runWebGLProgram(p,[o,s,a],o.dtype)},YL={kernelName:ap,backendName:"webgl",kernelFunc:Hee};function ZL(r,e,t,n){let o=b.sizeFromShape(e),a=b.sizeFromShape(r.shape)/o,i=ue({inputs:{x:r},attrs:{shape:[a,o]},backend:n}),l=Vn(i,r.dtype,"max",n),u=ue({inputs:{x:l},attrs:{shape:t},backend:n});return n.disposeIntermediateTensorInfo(i),n.disposeIntermediateTensorInfo(l),u}function qI(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{reductionIndices:s,keepDims:a}=n,i=o.shape.length,l=b.parseAxisParam(s,o.shape),u=l,c=I.getAxesPermutation(u,i),p=c!=null,m=t.shouldExecuteOnCPU([o]),f=o;if(p){if(m){let w=t.texData.get(f.dataId).values,_=new Array(i);for(let D=0;D<_.length;D++)_[D]=o.shape[c[D]];let C=wc(w,o.shape,o.dtype,c,_);f=t.makeTensorInfo(_,o.dtype);let A=t.texData.get(f.dataId);A.values=C}else f=Yl(o,c,t);u=I.getInnerMostAxes(u.length,i)}I.assertAxesAreInnerMostDims("max",u,i);let[d,h]=I.computeOutAndReduceShapes(f.shape,u),g=d;a&&(g=I.expandShapeToKeepDim(d,l));let x;if(m){let w=t.texData.get(f.dataId).values,_=mP(w,b.sizeFromShape(h),g,o.dtype);x=t.makeTensorInfo(g,o.dtype);let C=t.texData.get(x.dataId);C.values=_}else x=ZL(f,h,g,t);return p&&t.disposeIntermediateTensorInfo(f),x}var JL={kernelName:Jo,backendName:"webgl",kernelFunc:qI};var qee=eb+ `
return max ( a , b ) ;
` ,Kee= `
vec4 result = vec4 ( max ( a , b ) ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
` +Kl+ `
return result ;
` ,Xee=at({opSnippet:qee,packedOpSnippet:Kee,cpuKernelImpl:fP}),QL={kernelName:Qo,backendName:"webgl",kernelFunc:Xee};function Yee(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e;qs(o,"maxPool");let{filterSize:s,strides:a,pad:i,dimRoundingMode:l}=n,u=1;b.assert(I.eitherStridesOrDilationsAreOne(a,u),()=> ` Error in maxPool : Either strides or dilations must be 1. Got strides $ { a } and dilations '${u}' ` );let c=I.computePool2DInfo(o.shape,s,a,u,i,l);if(c.filterWidth===1&&c.filterHeight===1&&b.arraysEqual(c.inShape,c.outShape))return Qt({inputs:{x:o},backend:t});let p=new Di(c,"max",!1);return t.runWebGLProgram(p,[o],o.dtype)}var ez={kernelName:es,backendName:"webgl",kernelFunc:Yee};function Zee(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{filterSize:s,strides:a,pad:i,dataFormat:l,dimRoundingMode:u}=n,c=[1,1,1],p=I.computePool3DInfo(o.shape,s,a,c,i,u,l),m=new Cc(p,"max",!1);return t.runWebGLProgram(m,[o],o.dtype)}var tz={kernelName:bl,backendName:"webgl",kernelFunc:Zee};var KI=class{constructor(e){this.variableNames=["dy","maxPos"],this.outputShape=e.inShape;let t=e.strideHeight,n=e.strideWidth,o=e.dilationHeight,s=e.effectiveFilterHeight,a=e.effectiveFilterWidth,i=s-1-e.padInfo.top,l=a-1-e.padInfo.left,u=s*a-1;this.userCode= `
const ivec2 pads = ivec2 ( $ { i } , $ { l } ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
2021-06-05 21:10:28 +02:00
2021-10-22 22:09:52 +02:00
ivec2 dyRCCorner = coords . yz - pads ;
int dyRCorner = dyRCCorner . x ;
int dyCCorner = dyRCCorner . y ;
2021-06-05 21:10:28 +02:00
2021-10-22 22:09:52 +02: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 < $ { s } ;
wR += $ { o } ) {
float dyR = float ( dyRCorner + wR ) / $ { t } . 0 ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { a } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { n } . 0 ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
if ( dyC < 0.0 || dyC >= $ { e . outWidth } . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
float dyValue = getDy ( b , idyR , idyC , d ) ;
int maxPosValue = $ { u } - int ( getMaxPos ( b , idyR , idyC , d ) ) ;
// Get the current value, check it against the value from the
// position matrix.
int curPosValue = wR * $ { a } + wC ;
float mask = float ( maxPosValue == curPosValue ? 1.0 : 0.0 ) ;
dotProd += dyValue * mask ;
}
}
setOutput ( dotProd ) ;
2021-09-11 16:29:31 +02:00
}
2021-10-22 22:09:52 +02:00
` }},XI=class{constructor(e){this.variableNames=["dy","maxPos"],this.outputShape=e.inShape;let t=e.strideDepth,n=e.strideHeight,o=e.strideWidth,s=e.dilationDepth,a=e.dilationHeight,i=e.dilationWidth,l=e.effectiveFilterDepth,u=e.effectiveFilterHeight,c=e.effectiveFilterWidth,p=l-1-e.padInfo.front,m=u-1-e.padInfo.top,f=c-1-e.padInfo.left,d=l*u*c-1;this.userCode= `
const ivec3 pads = ivec3 ( $ { p } , $ { m } , $ { f } ) ;
2021-06-05 21:10:28 +02:00
2021-09-11 17:17:13 +02:00
void main ( ) {
2021-10-22 22:09:52 +02:00
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
2021-06-05 21:10:28 +02:00
2021-10-22 22:09:52 +02:00
ivec3 dyCorner = ivec3 ( coords . y , coords . z , coords . w ) - pads ;
int dyDCorner = dyCorner . x ;
int dyRCorner = dyCorner . y ;
int dyCCorner = dyCorner . z ;
2021-06-05 21:10:28 +02:00
2021-10-22 22:09:52 +02: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 ;
2021-06-05 21:10:28 +02:00
2021-10-22 22:09:52 +02:00
for ( int wD = 0 ; wD < $ { l } ;
wD += $ { s } ) {
float dyD = float ( dyDCorner + wD ) / $ { t } . 0 ;
2021-06-05 21:10:28 +02:00
2021-10-22 22:09:52 +02:00
if ( dyD < 0.0 || dyD >= $ { e . outDepth } . 0 || fract ( dyD ) > 0.0 ) {
continue ;
}
int idyD = int ( dyD ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
for ( int wR = 0 ; wR < $ { u } ;
wR += $ { a } ) {
float dyR = float ( dyRCorner + wR ) / $ { n } . 0 ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 ||
fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
2021-07-29 15:53:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int wC = 0 ; wC < $ { c } ;
wC += $ { i } ) {
float dyC = float ( dyCCorner + wC ) / $ { o } . 0 ;
2021-07-29 15:53:13 +02:00
2021-10-22 22:09:52 +02:00
if ( dyC < 0.0 || dyC >= $ { e . outWidth } . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
float dyValue = getDy ( batch , idyD , idyR , idyC , ch ) ;
int maxPosValue = $ { d } -
int ( getMaxPos ( batch , idyD , idyR , idyC , ch ) ) ;
// Get the current value, check it against the value from the
// position matrix.
int curPosValue =
wD * $ { u } * $ { c } +
wR * $ { c } + wC ;
float mask = float ( maxPosValue == curPosValue ? 1.0 : 0.0 ) ;
dotProd += dyValue * mask ;
}
}
}
setOutput ( dotProd ) ;
}
` }};function Jee(r){let{inputs:e,backend:t,attrs:n}=r,{dy:o,input:s}=e,a=s,{filterSize:i,strides:l,pad:u,dimRoundingMode:c}=n,p=[1,1,1],m=I.computePool3DInfo(a.shape,i,l,p,u,c),f=new Cc(m,"max",!0),d=t.runWebGLProgram(f,[a],a.dtype),h=new XI(m),g=t.runWebGLProgram(h,[o,d],a.dtype);return t.disposeIntermediateTensorInfo(d),g}var rz={kernelName:up,backendName:"webgl",kernelFunc:Jee};function Qee(r){let{inputs:e,backend:t,attrs:n}=r,{dy:o,input:s,output:a}=e,i=s;qs([s,a],"maxPoolGrad");let{filterSize:l,strides:u,pad:c,dimRoundingMode:p}=n,m=I.computePool2DInfo(i.shape,l,u,1,c,p),f=!0,d=new Di(m,"max",f),h=t.runWebGLProgram(d,[i],i.dtype),g=new KI(m),x=t.runWebGLProgram(g,[o,h],i.dtype);return t.disposeIntermediateTensorInfo(h),x}var nz={kernelName:lp,backendName:"webgl",kernelFunc:Qee};function oz(r,e,t,n){let o=new Di(t,"max",!1),s=n.runWebGLProgram(o,[r],"float32");o=new Di(t,"max",!0,!0,e);let a=n.runWebGLProgram(o,[r],"float32");return[s,a]}var sz={kernelName:cp,backendName:"webgl",kernelFunc:({inputs:r,attrs:e,backend:t})=>{let{x:n}=r,{filterSize:o,strides:s,pad:a,includeBatchInIndex:i}=e,l=t;b.assert(n.shape.length===4,()=> ` Error in maxPool : input must be rank 4 but got rank $ { n . shape . length } . ` );let u=[1,1];b.assert(I.eitherStridesOrDilationsAreOne(s,u),()=> ` Error in maxPool : Either strides or dilations must be 1. Got strides $ { s } and dilations '${u}' ` );let c=I.computePool2DInfo(n.shape,o,s,u,a),[p,m]=oz(n,i,c,l);return[p,m]}};function iz(r,e,t,n){let o=b.sizeFromShape(e),a=b.sizeFromShape(r.shape)/o,i=ue({inputs:{x:r},attrs:{shape:[a,o]},backend:n}),l=Vn(i,"float32","mean",n),u=ue({inputs:{x:l},attrs:{shape:t},backend:n});return n.disposeIntermediateTensorInfo(i),n.disposeIntermediateTensorInfo(l),u}var az={kernelName:ts,backendName:"webgl",kernelFunc:({inputs:r,attrs:e,backend:t})=>{let{x:n}=r,{keepDims:o,axis:s}=e,a=t,i=n.shape.length,l=b.parseAxisParam(s,n.shape),u=l,c=I.getAxesPermutation(u,i),p=c!=null,m=a.shouldExecuteOnCPU([n]),f=[],d=n;if(p){if(m){let _=a.texData.get(d.dataId).values,C=new Array(i);for(let R=0;R<C.length;R++)C[R]=n.shape[c[R]];let A=wc(_,n.shape,n.dtype,c,C);d=a.makeTensorInfo(C,n.dtype);let D=a.texData.get(d.dataId);D.values=A}else d=Yl(n,c,a);f.push(d),u=I.getInnerMostAxes(u.length,i)}I.assertAxesAreInnerMostDims("sum",u,i);let[h,g]=I.computeOutAndReduceShapes(d.shape,u),x=h;o&&(x=I.expandShapeToKeepDim(h,l));let y=iz(d,g,x,a);for(let w of f)a.disposeIntermediateTensorInfo(w);return y}};function ete(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{axis:s,keepDims:a}=n,i=o.shape.length,l=b.parseAxisParam(s,o.shape),u=l,c=I.getAxesPermutation(u,i),p=o;c!=null&&(p=Pt({inputs:{x:o},backend:t,attrs:{perm:c}}),u=I.getInnerMostAxes(u.length,o.shape.length)),I.assertAxesAreInnerMostDims("min",u,i);let[m,f]=I.computeOutAndReduceShapes(p.shape,u),d=b.sizeFromShape(f),h=ue({inputs:{x:p},backend:t,attrs:{shape:[-1,d]}}),g=Vn(h,h.dtype,"min",t),x;if(a){let y=I.expandShapeToKeepDim(m,l);x=ue({inputs:{x:g},backend:t,attrs:{shape:y}})}else x=ue({inputs:{x:g},backend:t,attrs:{shape:m}});return t.disposeIntermediateTensorInfo(h),t.disposeIntermediateTensorInfo(g),c!=null&&t.disposeIntermediateTensorInfo(p),x}var lz={kernelName:rs,backendName:"webgl",kernelFunc:ete};var tte=eb+ `
return min ( a , b ) ;
` ,rte= `
vec4 result = vec4 ( min ( a , b ) ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
` +Kl+ `
return result ;
` ,nte=at({opSnippet:tte,packedOpSnippet:rte,cpuKernelImpl:dP}),uz={kernelName:ns,backendName:"webgl",kernelFunc:nte};var YI=class{constructor(e,t,n){this.variableNames=["x"],this.outputShape=t.map((c,p)=>c[0]+e[p]+c[1]);let o=e.length,s=Ue(o),a=t.map(c=>c[0]).join(","),i=t.map((c,p)=>c[0]+e[p]).join(","),l=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,o),u=n==="reflect"?0:1;if(o===1){this.userCode= `
int start = $ { a } ;
int end = $ { i } ;
void main ( ) {
int outC = getOutputCoords ( ) ;
if ( outC < start ) {
outC = start * 2 - outC - $ { u } ;
} else if ( outC >= end ) {
outC = ( end - 1 ) * 2 - outC + $ { u } ;
}
setOutput ( getX ( outC - start ) ) ;
}
` ;return}this.userCode= `
$ { s } start = $ { s } ( $ { a } ) ;
$ { s } end = $ { s } ( $ { i } ) ;
void main ( ) {
$ { s } outC = getOutputCoords ( ) ;
for ( int i = 0 ; i < $ { o } ; i ++ ) {
if ( outC [ i ] < start [ i ] ) {
outC [ i ] = start [ i ] * 2 - outC [ i ] - $ { u } ;
} else if ( outC [ i ] >= end [ i ] ) {
outC [ i ] = ( end [ i ] - 1 ) * 2 - outC [ i ] + $ { u } ;
}
}
$ { s } coords = outC - start ;
setOutput ( getX ( $ { l } ) ) ;
}
` }};var ZI=class{constructor(e,t,n){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t.map((d,h)=>d[0]+e[h]+d[1]);let o=e.length,s=Ue(o),a=t.map(d=>d[0]).join(","),i=t.map((d,h)=>d[0]+e[h]).join(","),l=Jt("rc",o),u=Jt("source",o),c= ` $ { l [ o - 1 ] } < $ { this . outputShape [ o - 1 ] } ` ,p=o===1?"source": ` vec2 ( $ { u . slice ( - 2 ) . join ( ) } ) ` ,m=n==="reflect"?0:1,f="";if(o===1){let d= `
$ { s } source = rc ;
if ( source < start ) {
source = start * 2 - source - $ { m } ;
} else if ( source >= end ) {
source = ( end - 1 ) * 2 - source + $ { m } ;
}
source -= start ;
` ;f= `
$ { s } rc = outputLoc ;
$ { d }
result [ 0 ] = getChannel ( getX ( $ { u . join ( ) } ) , $ { p } ) ;
$ { l [ o - 1 ] } += 1 ;
if ( $ { c } ) {
$ { d }
result [ 1 ] = getChannel ( getX ( $ { u . join ( ) } ) , $ { p } ) ;
}
` }else{let d= `
$ { s } source = rc ;
$ { s } lt = $ { s } ( lessThan ( source , start ) ) ;
$ { s } gte = $ { s } ( greaterThanEqual ( source , end ) ) ;
$ { s } orig = 1 - ( lt + gte ) ;
source = orig * source +
lt * ( start * 2 - source - $ { m } ) +
gte * ( ( end - 1 ) * 2 - source + $ { m } ) ;
source -= start ;
` ;f= `
$ { s } rc = outputLoc ;
$ { d }
result [ 0 ] = getChannel ( getX ( $ { u . join ( ) } ) , $ { p } ) ;
$ { l [ o - 1 ] } += 1 ;
if ( $ { c } ) {
$ { d }
result [ 1 ] = getChannel ( getX ( $ { u . join ( ) } ) , $ { p } ) ;
}
rc = outputLoc ;
$ { l [ o - 2 ] } += 1 ;
if ( $ { l [ o - 2 ] } < $ { this . outputShape [ o - 2 ] } ) {
$ { d }
result [ 2 ] = getChannel ( getX ( $ { u . join ( ) } ) , $ { p } ) ;
$ { l [ o - 1 ] } += 1 ;
if ( $ { c } ) {
$ { d }
result [ 3 ] = getChannel ( getX ( $ { u . join ( ) } ) , $ { p } ) ;
}
}
` }this.userCode= `
const $ { s } start = $ { s } ( $ { a } ) ;
const $ { s } end = $ { s } ( $ { i } ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
$ { s } outputLoc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
$ { f }
setOutput ( result ) ;
}
` }};var ote=({inputs:r,backend:e,attrs:t})=>{let{x:n}=r,{paddings:o,mode:s}=t,a=U().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new ZI(n.shape,o,s):new YI(n.shape,o,s);return e.runWebGLProgram(a,[n],n.dtype)},cz={kernelName:os,backendName:"webgl",kernelFunc:ote};var ste= ` if ( b == 0.0 ) return NAN ;
return mod ( a , b ) ; ` ,ite= `
vec4 result = mod ( a , b ) ;
vec4 isNaN = vec4 ( equal ( b , vec4 ( 0.0 ) ) ) ;
` +Kl+ `
return result ;
` ,ate=at({opSnippet:ste,packedOpSnippet:ite}),pz={kernelName:aa,backendName:"webgl",kernelFunc:ate};var JI=class{constructor(e,t,n){this.variableNames=["probs"],this.customUniforms=[{name:"seed",type:"float"}],this.outputShape=[e,n],this.userCode= `
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
float r = random ( seed ) ;
float cdf = 0.0 ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
for ( int i = 0 ; i < $ { t - 1 } ; i ++ ) {
cdf += getProbs ( batch , i ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
if ( r < cdf ) {
setOutput ( float ( i ) ) ;
return ;
}
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
// If no other event happened, last event happened.
setOutput ( float ( $ { t - 1 } ) ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
` }};var lte= `
if ( a == b ) {
return 1.0 ;
2021-09-11 17:17:13 +02:00
} ;
2021-10-22 22:09:52 +02:00
return a / b ; ` ,ute= `
// 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. ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
if ( a . y == b . y ) {
result . y = 1. ;
}
if ( a . z == b . z ) {
result . z = 1. ;
}
if ( a . w == b . w ) {
result . w = 1. ;
2021-09-11 17:17:13 +02:00
}
2021-06-05 21:10:28 +02:00
2021-10-22 22:09:52 +02:00
return result ;
` ,QI=at({opSnippet:lte,packedOpSnippet:ute,checkOutOfBounds:!0}),mz={kernelName:Wo,backendName:"webgl",kernelFunc:QI};var fz="return a - b;",eS=at({opSnippet:fz,packedOpSnippet:fz,supportsComplex:!0,cpuKernelImpl:AP}),dz={kernelName:ks,backendName:"webgl",kernelFunc:eS};function tS(r){let{inputs:e,backend:t,attrs:n}=r,{logits:o}=e,{dim:s}=n,a=b.parseAxisParam([s],o.shape),i=qI({inputs:{x:o},backend:t,attrs:{reductionIndices:a,keepDims:!1}}),l=I.expandShapeToKeepDim(i.shape,a),u=ue({inputs:{x:i},backend:t,attrs:{shape:l}}),c=eS({inputs:{a:o,b:u},backend:t}),p=PI({inputs:{x:c},backend:t}),m=kc({inputs:{x:p},backend:t,attrs:{axis:a,keepDims:!1}}),f=ue({inputs:{x:m},backend:t,attrs:{shape:l}}),d=QI({inputs:{a:p,b:f},backend:t});return t.disposeIntermediateTensorInfo(i),t.disposeIntermediateTensorInfo(u),t.disposeIntermediateTensorInfo(c),t.disposeIntermediateTensorInfo(p),t.disposeIntermediateTensorInfo(m),t.disposeIntermediateTensorInfo(f),d}var hz={kernelName:ws,backendName:"webgl",kernelFunc:tS};function cte(r){let{inputs:e,backend:t,attrs:n}=r,{logits:o}=e,{numSamples:s,seed:a,normalized:i}=n,l=i?o:tS({inputs:{logits:o},backend:t,attrs:{dim:o.shape.length-1}}),u=l.shape[0],c=l.shape[1],p=new JI(u,c,s),m=[[a]],f=t.runWebGLProgram(p,[l],"int32",m);return i||t.disposeIntermediateTensorInfo(l),f}var gz={kernelName:pp,backendName:"webgl",kernelFunc:cte};var xz="return -x;";function pte(r){let{inputs:e,backend:t}=r,{x:n}=e;if(t.shouldExecuteOnCPU([n])){let s=t.texData.get(n.dataId),[a,i]=gP(s.values,n.shape,n.dtype);return t.makeTensorInfo(i,n.dtype,a)}let o;return U().getBool("WEBGL_PACK_UNARY_OPERATIONS")?o=new Xs(n.shape,xz):o=new En(n.shape,xz),t.runWebGLProgram(o,[n],n.dtype)}var yz={kernelName:ii,backendName:"webgl",kernelFunc:pte};var mte=Gr.nonMaxSuppressionV3Impl;function fte(r){I.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");let{inputs:e,backend:t,attrs:n}=r,{boxes:o,scores:s}=e,{maxOutputSize:a,iouThreshold:i,scoreThreshold:l}=n,u=t.readSync(o.dataId),c=t.readSync(s.dataId),{selectedIndices:p}=mte(u,c,a,i,l);return t.makeTensorInfo([p.length],"int32",new Int32Array(p))}var bz={kernelName:ua,backendName:"webgl",kernelFunc:fte};var dte=Gr.nonMaxSuppressionV4Impl;function hte(r){I.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");let{inputs:e,backend:t,attrs:n}=r,{boxes:o,scores:s}=e,{maxOutputSize:a,iouThreshold:i,scoreThreshold:l,padToMaxOutputSize:u}=n,c=t.readSync(o.dataId),p=t.readSync(s.dataId),{selectedIndices:m,validOutputs:f}=dte(c,p,a,i,l,u);return[t.makeTensorInfo([m.length],"int32",new Int32Array(m)),t.makeTensorInfo([],"int32",new Int32Array([f]))]}var wz={kernelName:ca,backendName:"webgl",kernelFunc:hte};var gte=Gr.nonMaxSuppressionV5Impl;function xte(r){I.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");let{inputs:e,backend:t,attrs:n}=r,{boxes:o,scores:s}=e,{maxOutputSize:a,iouThreshold:i,scoreThreshold:l,softNmsSigma:u}=n,c=t.readSync(o.dataId),p=t.readSync(s.dataId),m=a,f=i,d=l,h=u,{selectedIndices:g,selectedScores:x}=gte(c,p,m,f,d,h);return[t.makeTensorInfo([g.length],"int32",new Int32Array(g)),t.makeTensorInfo([x.length],"float32",new Float32Array(x))]}var _z={kernelName:pa,backendName:"webgl",kernelFunc:xte};var rS=class{constructor(e,t,n,o){this.variableNames=["indices"],this.outputShape=[e,t],this.userCode= `
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int index = round ( getIndices ( coords . x ) ) ;
setOutput ( mix ( float ( $ { o } ) , float ( $ { n } ) ,
float ( index == coords . y ) ) ) ;
}
` }};var yte=r=>{let{inputs:e,backend:t,attrs:n}=r,{indices:o}=e,{depth:s,onValue:a,offValue:i}=n,l=b.sizeFromShape(o.shape),u=new rS(l,s,a,i),c=ue({inputs:{x:o},backend:t,attrs:{shape:[l]}}),p=t.runWebGLProgram(u,[c],o.dtype);t.disposeIntermediateTensorInfo(c);let m=[...o.shape,s],f=ue({inputs:{x:p},backend:t,attrs:{shape:m}});return t.disposeIntermediateTensorInfo(p),f},kz={kernelName:is,backendName:"webgl",kernelFunc:yte};function Zh(r){let{inputs:e,backend:t}=r,{x:n}=e;if(n.dtype==="complex64"){let o=tl({inputs:{input:n},backend:t}),s=Zh({inputs:{x:o},backend:t}),a=Ic({inputs:{input:n},backend:t}),i=Zh({inputs:{x:a},backend:t}),l=An({inputs:{real:s,imag:i},backend:t});return t.disposeIntermediateTensorInfo(o),t.disposeIntermediateTensorInfo(s),t.disposeIntermediateTensorInfo(a),t.disposeIntermediateTensorInfo(i),l}else return rl({attrs:{shape:n.shape,dtype:n.dtype,value:n.dtype==="string"?"":0},backend:t})}var vz={kernelName:hi,backendName:"webgl",kernelFunc:Zh};function Cz(r){let{inputs:e,backend:t}=r,{x:n}=e;if(n.dtype==="string")throw new Error("onesLike is not supported under string dtype");if(n.dtype==="complex64"){let o=tl({inputs:{input:n},backend:t}),s=Cz({inputs:{x:o},backend:t}),a=Ic({inputs:{input:n},backend:t}),i=Zh({inputs:{x:a},backend:t}),l=An({inputs:{real:s,imag:i},backend:t});return t.disposeIntermediateTensorInfo(o),t.disposeIntermediateTensorInfo(s),t.disposeIntermediateTensorInfo(a),t.disposeIntermediateTensorInfo(i),l}else return rl({attrs:{shape:n.shape,dtype:n.dtype,value:1},backend:t})}var Iz={kernelName:ai,backendName:"webgl",kernelFunc:Cz};function bte(r){let{inputs:e,backend:t,attrs:n}=r,{axis:o}=n;if(e.length===1)return cb({inputs:{input:e[0]},backend:t,attrs:{dim:o}});let s=e[0].shape,a=e[0].dtype;e.forEach(c=>{b.assertShapesMatch(s,c.shape,"All tensors passed to stack must have matching shapes"),b.assert(a===c.dtype,()=>"All tensors passed to stack must have matching dtypes")});let i=[],l=e.map(c=>{let p=cb({inputs:{input:c},backend:t,attrs:{dim:o}});return i.push(p),p}),u=vI({inputs:l,backend:t,attrs:{axis:o}});return i.forEach(c=>t.disposeIntermediateTensorInfo(c)),u}var Sz={kernelName:li,backendName:"webgl",kernelFunc:bte};var nS=class{constructor(e,t,n){this.variableNames=["x"],this.customUniforms=[{name:"value",type:"float"}],this.outputShape=t.map((u,c)=>u[0]+e[c]+u[1]);let o=e.length,s=Ue(o),a=t.map(u=>u[0]).join(","),i=t.map((u,c)=>u[0]+e[c]).join(","),l=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,o);if(o===1){this.userCode= `
int start = $ { a } ;
int end = $ { i } ;
2021-06-05 21:10:28 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
int outC = getOutputCoords ( ) ;
if ( outC < start || outC >= end ) {
setOutput ( value ) ;
} else {
setOutput ( getX ( outC - start ) ) ;
}
}
` ;return}this.userCode= `
$ { s } start = $ { s } ( $ { a } ) ;
$ { s } end = $ { s } ( $ { i } ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
$ { s } outC = getOutputCoords ( ) ;
if ( any ( lessThan ( outC , start ) ) || any ( greaterThanEqual ( outC , end ) ) ) {
setOutput ( value ) ;
} else {
$ { s } coords = outC - start ;
setOutput ( getX ( $ { l } ) ) ;
}
}
` }};var oS=class{constructor(e,t,n){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.customUniforms=[{name:"value",type:"float"}],this.outputShape=t.map((h,g)=>h[0]+e[g]+h[1]);let o=e.length,s=Ue(o),a=t.map(h=>h[0]).join(","),i=t.map((h,g)=>h[0]+e[g]).join(","),l=Jt("rc",o),u=Jt("source",o),c= ` $ { l [ o - 1 ] } < $ { this . outputShape [ o - 1 ] } ` ,p=o===1?"source": ` vec2 ( $ { u . slice ( - 2 ) . join ( ) } ) ` ,m=[ ` $ { s } rc = outputLoc ; ` , ` $ { l [ o - 1 ] } += 1 ;
if ( $ { c } ) {
` ,o===1?"": ` }
rc = outputLoc ;
$ { l [ o - 2 ] } += 1 ;
if ( $ { l [ o - 2 ] } < $ { this . outputShape [ o - 2 ] } ) { ` ,o===1?"": ` $ { l [ o - 1 ] } += 1 ;
if ( $ { c } ) { ` ],f=o===1?"rc < start || rc >= end":"any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))",d="";for(let h=0,g=o===1?2:4;h<g;h++)d+= `
$ { m [ h ] }
if ( $ { f } ) {
result [ $ { h } ] = float ( value ) ;
} else {
$ { s } source = rc - start ;
result [ $ { h } ] = getChannel ( getX ( $ { u . join ( ) } ) , $ { p } ) ;
}
` ;d+=o===1?"} ":"}}",this.userCode= `
const $ { s } start = $ { s } ( $ { a } ) ;
const $ { s } end = $ { s } ( $ { i } ) ;
2021-06-05 21:10:28 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
$ { s } outputLoc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
$ { d }
setOutput ( result ) ;
}
` }};var sS=r=>{let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{paddings:s,constantValue:a}=n;if(b.sizeFromShape(o.shape)===0){let u=s.map((c,p)=>c[0]+o.shape[p]+c[1]);return rl({backend:t,attrs:{shape:u,value:a,dtype:o.dtype}})}let i=U().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new oS(o.shape,s,a):new nS(o.shape,s,a),l=[[a]];return t.runWebGLProgram(i,[o],o.dtype,l)},Nz={kernelName:as,backendName:"webgl",kernelFunc:sS};var wte= `
if ( a < 0.0 && floor ( b ) < b ) {
return NAN ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
if ( b == 0.0 ) {
return 1.0 ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
return ( round ( mod ( b , 2.0 ) ) != 1 ) ?
pow ( abs ( a ) , b ) : sign ( a ) * pow ( abs ( a ) , b ) ;
` ,_te= `
// 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 ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02: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 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 isNaN = vec4 ( lessThan ( a , vec4 ( 0.0 ) ) ) * vec4 ( lessThan ( floor ( b ) , b ) ) ;
` +Kl+ `
return result ;
` ,kte=at({opSnippet:wte,packedOpSnippet:_te}),Tz={kernelName:ls,backendName:"webgl",kernelFunc:kte};function vte(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{axis:s,keepDims:a}=n,i=o.shape.length,l=[],u=b.parseAxisParam(s,o.shape),c=u,p=I.getAxesPermutation(c,i),m=o;p!=null&&(m=Pt({inputs:{x:o},backend:t,attrs:{perm:p}}),c=I.getInnerMostAxes(c.length,i),l.push(m)),I.assertAxesAreInnerMostDims("prod",c,i);let f;if(t.shouldExecuteOnCPU([m])){let d=t.texData.get(m.dataId).values,{outVals:h,outShape:g,outDtype:x}=yP(m.shape,m.dtype,d,c);f=t.makeTensorInfo(g,x,h)}else{let[d,h]=I.computeOutAndReduceShapes(m.shape,c),g=b.sizeFromShape(h),x=ue({inputs:{x:m},backend:t,attrs:{shape:[-1,g]}}),y=hu(o.dtype),w=Vn(x,y,"prod",t);f=ue({inputs:{x:w},backend:t,attrs:{shape:d}}),l.push(x),l.push(w)}if(a){l.push(f);let d=I.expandShapeToKeepDim(f.shape,u);f=ue({inputs:{x:f},backend:t,attrs:{shape:d}})}return l.forEach(d=>t.disposeIntermediateTensorInfo(d)),f}var Ez={kernelName:ma,backendName:"webgl",kernelFunc:vte};var iS=r=>{let{backend:e,attrs:t}=r,{start:n,stop:o,step:s,dtype:a}=t,i=bP(n,o,s,a);return e.makeTensorInfo([i.length],a,i)},Az={kernelName:wl,backendName:"webgl",kernelFunc:iS};var Cte="return 1.0 / x;",Ite=ve({opSnippet:Cte}),Dz={kernelName:fa,backendName:"webgl",kernelFunc:Ite};var Ste=Nr+ `
return ( x < 0.0 ) ? 0.0 : x ;
` ,Nte= `
vec4 result = x * vec4 ( greaterThanEqual ( x , vec4 ( 0.0 ) ) ) ;
bvec4 isNaN = isnan ( x ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
result . r = isNaN . r ? x . r : result . r ;
result . g = isNaN . g ? x . g : result . g ;
result . b = isNaN . b ? x . b : result . b ;
result . a = isNaN . a ? x . a : result . a ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
return result ;
` ,Tte=ve({opSnippet:Ste,packedOpSnippet:Nte}), $ z={kernelName:cs,backendName:"webgl",kernelFunc:Tte};var Ete=Nr+ `
return ( x < 0.0 ) ? 0.0 : min ( 6.0 , x ) ;
` ,Ate= `
vec4 result = min ( x , vec4 ( 6. ) ) * vec4 ( greaterThanEqual ( x , vec4 ( 0.0 ) ) ) ;
bvec4 isNaN = isnan ( x ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
result . r = isNaN . r ? x . r : result . r ;
result . g = isNaN . g ? x . g : result . g ;
result . b = isNaN . b ? x . b : result . b ;
result . a = isNaN . a ? x . a : result . a ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
return result ;
` ,Dte=ve({opSnippet:Ete,packedOpSnippet:Ate}),Rz={kernelName:ms,backendName:"webgl",kernelFunc:Dte};var aS=class{constructor(e,t,n,o,s){this.variableNames=["A"],this.outputShape=[];let[a,i,l,u]=e;this.outputShape=[a,t,n,u];let c=[o&&t>1?i-1:i,o&&n>1?l-1:l],p=[o&&t>1?t-1:t,o&&n>1?n-1:n],m;s?m="(vec2(yRC) + vec2(0.5)) * effectiveInputOverOutputRatioRC - vec2(0.5)":m="vec2(yRC) * effectiveInputOverOutputRatioRC",this.userCode= `
const vec2 effectiveInputOverOutputRatioRC = vec2 (
$ { c [ 0 ] / p [ 0 ] } ,
$ { c [ 1 ] / p [ 1 ] } ) ;
const vec2 inputShapeRC = vec2 ( $ { i } . 0 , $ { l } . 0 ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 yRC = coords . yz ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
// Fractional source index.
vec2 sourceFracIndexRC = $ { m } ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
// Compute the four integer indices.
ivec2 sourceFloorRC = ivec2 ( max ( sourceFracIndexRC , vec2 ( 0.0 ) ) ) ;
ivec2 sourceCeilRC = ivec2 (
min ( inputShapeRC - 1.0 , ceil ( sourceFracIndexRC ) ) ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02: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 ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
vec2 fracRC = sourceFracIndexRC - vec2 ( sourceFloorRC ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
float top = topLeft + ( topRight - topLeft ) * fracRC . y ;
float bottom = bottomLeft + ( bottomRight - bottomLeft ) * fracRC . y ;
float newValue = top + ( bottom - top ) * fracRC . x ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( newValue ) ;
}
` }};var lS=class{constructor(e,t,n,o,s){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];let[a,i,l,u]=e;this.outputShape=[a,t,n,u];let c=[o&&t>1?i-1:i,o&&n>1?l-1:l],p=[o&&t>1?t-1:t,o&&n>1?n-1:n],m;s?m="(vec3(yRC) + vec3(0.5)) * effectiveInputOverOutputRatioRC - vec3(0.5)":m="vec3(yRC) * effectiveInputOverOutputRatioRC",this.userCode= `
const vec3 effectiveInputOverOutputRatioRC = vec3 (
$ { c [ 0 ] / p [ 0 ] } ,
$ { c [ 1 ] / p [ 1 ] } ,
$ { c [ 1 ] / p [ 1 ] } ) ;
const vec3 inputShapeRC = vec3 ( $ { i } . 0 , $ { l } . 0 ,
$ { l } . 0 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float getAValue ( int b , int r , int c , int d ) {
return getChannel ( getA ( b , r , c , d ) , vec2 ( c , d ) ) ;
2021-09-11 16:29:31 +02:00
}
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
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 ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
// Fractional source index.
vec3 sourceFracIndexRC = $ { m } ;
// Compute the four integer indices.
ivec3 sourceFloorRC = ivec3 ( max ( sourceFracIndexRC , vec3 ( 0.0 ) ) ) ;
ivec3 sourceCeilRC = ivec3 (
min ( inputShapeRC - 1.0 , ceil ( sourceFracIndexRC ) ) ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
// Should we calculate next column and row elements in 2x2 packed cell.
bool hasNextCol = d < $ { u - 1 } ;
bool hasNextRow = coords . z < $ { n - 1 } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02: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 ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02: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 ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02: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 ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02: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 ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
vec3 fracRC = sourceFracIndexRC - vec3 ( sourceFloorRC ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 top = mix ( topLeft , topRight , fracRC . yyzz ) ;
vec4 bottom = mix ( bottomLeft , bottomRight , fracRC . yyzz ) ;
vec4 newValue = mix ( top , bottom , fracRC . x ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( newValue ) ;
}
` }};function $ te(r){let{inputs:e,backend:t,attrs:n}=r,{images:o}=e,{alignCorners:s,halfPixelCenters:a,size:i}=n,[l,u]=i,c=U().getBool("WEBGL_PACK_IMAGE_OPERATIONS")?new lS(o.shape,l,u,s,a):new aS(o.shape,l,u,s,a);return t.runWebGLProgram(c,[o],"float32")}var Fz={kernelName:ps,backendName:"webgl",kernelFunc: $ te};var uS=class{constructor(e,t,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=t;let[,o,s]=t,[,a,i]=e,l=[n&&a>1?o-1:o,n&&i>1?s-1:s],u=[n&&a>1?a-1:a,n&&i>1?i-1:i],c=l[0]/u[0],p=l[1]/u[1],m=1/c,f=1/p,d=Math.ceil(m)*2+2,h=Math.ceil(f)*2+2;this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
float accumulator = 0.0 ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
const float heightScale = float ( $ { c } ) ;
const float widthScale = float ( $ { p } ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
const float invHeightScale = float ( $ { m } ) ;
const float invWidthScale = float ( $ { f } ) ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
const int winHeight = int ( $ { d } ) ;
const int winWidth = int ( $ { h } ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// Compute bounds for where in dy we will look
float startRLerp = floor ( float ( r ) * invHeightScale ) ;
int startDyR = int ( startRLerp - float ( winHeight / 2 ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float startCLerp = floor ( float ( c ) * invWidthScale ) ;
int startDyC = int ( startCLerp - float ( winWidth / 2 ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// Loop over dy
for ( int dyROffset = 0 ; dyROffset < winHeight ; dyROffset ++ ) {
int dyR = dyROffset + startDyR ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
// Guard against the window exceeding the bounds of dy
if ( dyR < 0 || dyR >= $ { a } ) {
continue ;
}
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
for ( int dyCOffset = 0 ; dyCOffset < winWidth ; dyCOffset ++ ) {
int dyC = dyCOffset + startDyC ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
// Guard against the window exceeding the bounds of dy
if ( dyC < 0 || dyC >= $ { i } ) {
continue ;
}
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
float dxR = float ( dyR ) * heightScale ;
int topDxRIndex = int ( floor ( dxR ) ) ;
int bottomDxRIndex = int ( min ( ceil ( dxR ) , $ { o - 1 } . 0 ) ) ;
float dxRLerp = dxR - float ( topDxRIndex ) ;
float inverseDxRLerp = 1.0 - dxRLerp ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
float dxC = float ( dyC ) * widthScale ;
int leftDxCIndex = int ( floor ( dxC ) ) ;
int rightDxCIndex = int ( min ( ceil ( dxC ) , $ { s - 1 } . 0 ) ) ;
float dxCLerp = dxC - float ( leftDxCIndex ) ;
float inverseDxCLerp = 1.0 - dxCLerp ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( r == topDxRIndex && c == leftDxCIndex ) {
// topLeft
accumulator +=
getDy ( b , dyR , dyC , d ) * inverseDxRLerp * inverseDxCLerp ;
}
2021-06-05 19:02:01 +02:00
2021-10-22 22:09:52 +02:00
if ( r == topDxRIndex && c == rightDxCIndex ) {
// topRight
accumulator += getDy ( b , dyR , dyC , d ) * inverseDxRLerp * dxCLerp ;
}
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
if ( r == bottomDxRIndex && c == leftDxCIndex ) {
// bottomLeft
accumulator += getDy ( b , dyR , dyC , d ) * dxRLerp * inverseDxCLerp ;
}
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
if ( r == bottomDxRIndex && c == rightDxCIndex ) {
// bottomRight
accumulator += getDy ( b , dyR , dyC , d ) * dxRLerp * dxCLerp ;
}
}
}
// End loop over dy
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( accumulator ) ;
}
` }};function Rte(r){let{inputs:e,backend:t,attrs:n}=r,{images:o,dy:s}=e,{alignCorners:a}=n,i=new uS(s.shape,o.shape,a);return t.runWebGLProgram(i,[s],s.dtype)}var Oz={kernelName:dp,backendName:"webgl",kernelFunc:Rte};var cS=class{constructor(e,t,n,o,s){this.variableNames=["A"],this.outputShape=[];let[a,i,l,u]=e;this.outputShape=[a,t,n,u];let c=[o&&t>1?i-1:i,o&&n>1?l-1:l],p=[o&&t>1?t-1:t,o&&n>1?n-1:n],m=o?"0.5":"0.0",f;s?f="max((vec2(yRC) + vec2(0.5)) * effectiveInputOverOutputRatioRC, vec2(0.0))":f="vec2(yRC) * effectiveInputOverOutputRatioRC",this.userCode= `
const vec2 effectiveInputOverOutputRatioRC = vec2 (
$ { c [ 0 ] / p [ 0 ] } ,
$ { c [ 1 ] / p [ 1 ] } ) ;
const vec2 inputShapeRC = vec2 ( $ { i } . 0 , $ { l } . 0 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 yRC = coords . yz ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// Fractional source index.
vec2 sourceFracIndexRC = $ { f } ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// Compute the coordinators of nearest neighbor point.
ivec2 sourceNearestRC = ivec2 (
min ( inputShapeRC - 1.0 , floor ( sourceFracIndexRC + $ { m } ) ) ) ;
float newValue = getA ( b , sourceNearestRC . x , sourceNearestRC . y , d ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( newValue ) ;
}
` }};var pS=class{constructor(e,t,n,o,s){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];let[a,i,l,u]=e;this.outputShape=[a,t,n,u];let c=[o&&t>1?i-1:i,o&&n>1?l-1:l],p=[o&&t>1?t-1:t,o&&n>1?n-1:n],m=o?"0.5":"0.0",f;s?f="max((vec3(yRC) + vec3(0.5)) * effectiveInputOverOutputRatioRC, vec3(0.0))":f="vec3(yRC) * effectiveInputOverOutputRatioRC",this.userCode= `
const vec3 effectiveInputOverOutputRatioRC = vec3 (
$ { c [ 0 ] / p [ 0 ] } ,
$ { c [ 1 ] / p [ 1 ] } ,
$ { c [ 1 ] / p [ 1 ] } ) ;
const vec3 inputShapeRC = vec3 ( $ { i } . 0 , $ { l } . 0 ,
$ { l } . 0 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float getAValue ( int b , int r , int c , int d ) {
return getChannel ( getA ( b , r , c , d ) , vec2 ( c , d ) ) ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
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 ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// Fractional source index.
vec3 sourceFracIndexRC = $ { f } ;
2021-06-07 02:34:29 +02:00
2021-10-22 22:09:52 +02:00
// Compute the coordinators of nearest neighbor point.
ivec3 sourceNearestRC = ivec3 (
min ( inputShapeRC - 1.0 , floor ( sourceFracIndexRC + $ { m } ) ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// Should we calculate next column and row elements in 2x2 packed cell.
bool hasNextCol = d < $ { u - 1 } ;
bool hasNextRow = coords . z < $ { n - 1 } ;
2021-04-28 14:58:21 +02:00
2021-10-22 22:09:52 +02:00
vec4 newValue = vec4 (
getAValue ( b , sourceNearestRC . x , sourceNearestRC . y , d ) ,
hasNextCol ? getAValue ( b , sourceNearestRC . x , sourceNearestRC . y , d + 1 )
: 0.0 ,
hasNextRow ? getAValue ( b , sourceNearestRC . x , sourceNearestRC . z , d )
: 0.0 ,
( hasNextRow && hasNextCol ) ?
getAValue ( b , sourceNearestRC . x , sourceNearestRC . z , d + 1 ) : 0.0 ) ;
2021-06-04 15:20:59 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( newValue ) ;
}
` }};function Fte(r){let{inputs:e,backend:t,attrs:n}=r,{images:o}=e,{alignCorners:s,halfPixelCenters:a,size:i}=n,[l,u]=i,c=U().getBool("WEBGL_PACK_IMAGE_OPERATIONS")?new pS(o.shape,l,u,s,a):new cS(o.shape,l,u,s,a);return t.runWebGLProgram(c,[o],o.dtype)}var Pz={kernelName:_l,backendName:"webgl",kernelFunc:Fte};var mS=class{constructor(e,t,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=t;let[,o,s]=t,[,a,i]=e,l=[n&&a>1?o-1:o,n&&i>1?s-1:s],u=[n&&a>1?a-1:a,n&&i>1?i-1:i],c=l[0]/u[0],p=l[1]/u[1],m=1/c,f=1/p,d=Math.ceil(m)*2+2,h=Math.ceil(f)*2+2;this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
2021-06-04 15:20:59 +02:00
2021-10-22 22:09:52 +02:00
float accumulator = 0.0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
const float heightScale = float ( $ { c } ) ;
const float widthScale = float ( $ { p } ) ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
const float invHeightScale = float ( $ { m } ) ;
const float invWidthScale = float ( $ { f } ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
const int winHeight = int ( $ { d } ) ;
const int winWidth = int ( $ { h } ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// Compute bounds for where in dy we will look
float startRLerp = floor ( float ( r ) * invHeightScale ) ;
int startDyR = int ( floor ( startRLerp - float ( winHeight / 2 ) ) ) ;
2021-06-04 19:52:40 +02:00
2021-10-22 22:09:52 +02:00
float startCLerp = floor ( float ( c ) * invWidthScale ) ;
int startDyC = int ( floor ( startCLerp - float ( winWidth / 2 ) ) ) ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
// Loop over dy
for ( int dyROffset = 0 ; dyROffset < winHeight ; dyROffset ++ ) {
int dyR = dyROffset + startDyR ;
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
// Guard against the window exceeding the bounds of dy
if ( dyR < 0 || dyR >= $ { a } ) {
continue ;
}
2021-09-11 16:29:31 +02:00
2021-10-22 22:09:52 +02:00
for ( int dyCOffset = 0 ; dyCOffset < winWidth ; dyCOffset ++ ) {
int dyC = dyCOffset + startDyC ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// Guard against the window exceeding the bounds of dy
if ( dyC < 0 || dyC >= $ { i } ) {
continue ;
}
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float sourceFracRow =
float ( $ { l [ 0 ] } ) *
( float ( dyR ) / float ( $ { u [ 0 ] } ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float sourceFracCol =
float ( $ { l [ 1 ] } ) *
( float ( dyC ) / float ( $ { u [ 1 ] } ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int sourceNearestRow = int ( min (
float ( int ( $ { o } ) - 1 ) ,
$ { n } ? float ( round ( sourceFracRow ) ) :
float ( floor ( sourceFracRow ) ) ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int sourceNearestCol = int ( min (
float ( int ( $ { s } ) - 1 ) ,
$ { n } ? float ( round ( sourceFracCol ) ) :
float ( floor ( sourceFracCol ) ) ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( r == sourceNearestRow && c == sourceNearestCol ) {
accumulator += getDy ( b , dyR , dyC , d ) ;
}
}
}
// End loop over dy
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( accumulator ) ;
}
` }};function Ote(r){let{inputs:e,backend:t,attrs:n}=r,{images:o,dy:s}=e,{alignCorners:a}=n,i=new mS(s.shape,o.shape,a);return t.runWebGLProgram(i,[s],s.dtype)}var Mz={kernelName:fp,backendName:"webgl",kernelFunc:Ote};var fS=class{constructor(e,t){this.variableNames=["x"];let n=e.length;if(n>4)throw new Error( ` WebGL backend : Reverse of rank - $ { n } tensor is not yet supported ` );if(this.outputShape=e,n===1){this.userCode= `
void main ( ) {
int coord = getOutputCoords ( ) ;
setOutput ( getX ( $ { e [ 0 ] } - coord - 1 ) ) ;
}
` ;return}let o=i=>t.indexOf(i)!==-1&&e[i]!==1? ` $ { e [ i ] } - coords [ $ { i } ] - 1 ` : ` coords [ $ { i } ] ` ,s=e.map((i,l)=>o(l)).join(","),a=Ue(n);this.userCode= `
void main ( ) {
$ { a } coords = getOutputCoords ( ) ;
setOutput ( getX ( $ { s } ) ) ;
}
` }};var dS=class{constructor(e,t){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;let n=e.length;if(n>4)throw new Error( ` WebGL backend : Reverse of rank - $ { n } tensor is not yet supported ` );this.outputShape=e;let o=Jt("rc",n),s= ` $ { o [ n - 1 ] } + 1 < $ { this . outputShape [ n - 1 ] } ` ,a= ` $ { o [ n - 2 ] } + 1 < $ { this . outputShape [ n - 2 ] } ` ,i=Ue(n);n===1?this.userCode= `
void main ( ) {
int rc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
result . r = getChannel ( getX ( $ { e [ 0 ] } - rc - 1 ) ,
$ { e [ 0 ] } - rc - 1 ) ;
if ( $ { s } ) {
result . g = getChannel ( getX ( $ { e [ 0 ] } - ( rc + 1 ) - 1 ) ,
$ { e [ 0 ] } - ( rc + 1 ) - 1 ) ;
}
setOutput ( result ) ;
}
` :this.userCode= `
void main ( ) {
$ { i } rc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
result . r = $ { l ( o . slice ( ) ) } ;
if ( $ { s } ) {
result . g = $ { u ( o . slice ( ) ) } ;
}
if ( $ { a } ) {
result . b = $ { c ( o . slice ( ) ) } ;
if ( $ { s } ) {
result . a = $ { p ( o . slice ( ) ) } ;
}
}
setOutput ( result ) ;
}
` ;function l(d){return m(d)}function u(d){return d[n-1]="("+d[n-1]+" + 1)",m(d)}function c(d){return d[n-2]="("+d[n-2]+" + 1)",m(d)}function p(d){return d[n-1]="("+d[n-1]+" + 1)",d[n-2]="("+d[n-2]+" + 1)",m(d)}function m(d){let h=e.map((y,w)=>f(w,d)),g=h.join(","),x=h.slice(-2).join(",");return ` getChannel ( getX ( $ { g } ) , vec2 ( $ { x } ) ) ` }function f(d,h){return t.indexOf(d)!==-1&&e[d]!==1? ` $ { e [ d ] } - $ { h [ d ] } - 1 ` : ` $ { h [ d ] } ` }}};function Pte(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{dims:s}=n,a=o.shape.length,i=b.parseAxisParam(s,o.shape);if(a===0)return Qt({inputs:{x:o},backend:t});let l=U().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new dS(o.shape,i):new fS(o.shape,i);return t.runWebGLProgram(l,[o],o.dtype)}var Lz={kernelName:fs,backendName:"webgl",kernelFunc:Pte};var hS=class{constructor(e,t){this.variableNames=["Image"],this.outputShape=[],this.customUniforms=[{name:"params",type:"vec4"}];let n=e[1],o=e[2];this.outputShape=e;let s="";typeof t=="number"?s= ` float outputValue = $ { t . toFixed ( 2 ) } ; ` :s= `
vec3 fill = vec3 ( $ { t . 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 ) - params [ 0 ] ) * params [ 3 ] -
( float ( y ) - params [ 1 ] ) * params [ 2 ] ;
float coordYFloat = ( float ( x ) - params [ 0 ] ) * params [ 2 ] +
( float ( y ) - params [ 1 ] ) * params [ 3 ] ;
int coordX = int ( round ( coordXFloat + params [ 0 ] ) ) ;
int coordY = int ( round ( coordYFloat + params [ 1 ] ) ) ;
$ { s }
if ( coordX >= 0 && coordX < $ { o } && coordY >= 0 && coordY < $ { n } ) {
outputValue = getImage ( coords [ 0 ] , coordY , coordX , coords [ 3 ] ) ;
}
setOutput ( outputValue ) ;
}
` }};var zz={kernelName:ka,backendName:"webgl",kernelFunc:({inputs:r,attrs:e,backend:t})=>{let{image:n}=r,{radians:o,fillValue:s,center:a}=e,i=t,l=new hS(n.shape,s),[u,c]=I.getImageCenter(a,n.shape[1],n.shape[2]),p=[[u,c,Math.sin(o),Math.cos(o)]];return i.runWebGLProgram(l,[n],n.dtype,p)}};var Mte= `
// OpenGL ES does not support round function.
// The algorithm is based on banker's rounding.
float base = floor ( x ) ;
if ( ( x - base ) < 0.5 ) {
return floor ( x ) ;
} else if ( ( x - base ) > 0.5 ) {
return ceil ( x ) ;
} else {
if ( mod ( base , 2.0 ) == 0.0 ) {
return base ;
} else {
return base + 1.0 ;
2021-09-11 17:17:13 +02:00
}
}
2021-10-22 22:09:52 +02:00
` ,Lte=ve({opSnippet:Mte}),Bz={kernelName:ds,backendName:"webgl",kernelFunc:Lte};var zte="return inversesqrt(x);",Bte=ve({opSnippet:zte,cpuKernelImpl:wP}),Vz={kernelName:hs,backendName:"webgl",kernelFunc:Bte};var Jh=class{constructor(e,t,n,o,s,a,i=!0){this.variableNames=["updates","indices","defaultValue"],this.outputShape=a;let l=Ue(s.length),u=Ue(a.length),c="";n===1?c="i":n===2&&(c="i, j");let p= ` getIndices ( $ { c } ) ` ,m="";o===1?m="i":o===2&&(m="i, coords[1]");let f= ` getUpdates ( $ { m } ) ` ,d=t>1?"strides[j]":"strides";this.userCode= `
$ { l } strides = $ { l } ( $ { s } ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
$ { u } coords = getOutputCoords ( ) ;
float sum = 0.0 ;
bool found = false ;
for ( int i = 0 ; i < $ { e } ; i ++ ) {
int flattenedIndex = 0 ;
for ( int j = 0 ; j < $ { t } ; j ++ ) {
int index = round ( $ { p } ) ;
flattenedIndex += index * $ { d } ;
}
if ( flattenedIndex == coords [ 0 ] ) {
sum += $ { f } ;
found = true ;
}
}
setOutput ( mix ( getDefaultValue ( ) , sum , float ( found ) ) ) ;
}
` }};function Vte(r){let{inputs:e,backend:t,attrs:n}=r,{indices:o,updates:s}=e,{shape:a}=n,{sliceRank:i,numUpdates:l,sliceSize:u,strides:c,outputSize:p}=I.calculateShapes(s,o,a),m=[p/u,u];if(p===0)return t.makeTensorInfo(a,o.dtype);let f=ue({inputs:{x:o},backend:t,attrs:{shape:[l,i]}}),d=ue({inputs:{x:s},backend:t,attrs:{shape:[l,u]}}),h=t.makeTensorInfo([],"float32",new Float32Array([0])),g=new Jh(l,i,f.shape.length,d.shape.length,c,m),x=t.runWebGLProgram(g,[d,f,h],d.dtype),y=ue({inputs:{x},backend:t,attrs:{shape:a}});return t.disposeIntermediateTensorInfo(f),t.disposeIntermediateTensorInfo(d),t.disposeIntermediateTensorInfo(x),t.disposeIntermediateTensorInfo(h),y}var Gz={kernelName:da,backendName:"webgl",kernelFunc:Vte};var gS=class{constructor(e,t,n){this.variableNames=["c","a","b"],this.outputShape=t;let o,s;if(n>4)throw Error( ` Where for rank $ { n } is not yet supported ` );if(n===1)s="resRC",o="resRC";else{let i=["resRC.x","resRC.y","resRC.z","resRC.w"],l=[],u=[];for(let c=0;c<t.length;c++)u.push( ` $ { i [ c ] } ` ),c<e&&l.push( ` $ { i [ c ] } ` );o=l.join(),s=u.join()}let a=Ue(n);this.userCode= `
void main ( ) {
$ { a } resRC = getOutputCoords ( ) ;
float cVal = getC ( $ { o } ) ;
if ( cVal >= 1.0 ) {
setOutput ( getA ( $ { s } ) ) ;
} else {
setOutput ( getB ( $ { s } ) ) ;
}
}
` }};function Gte(r){let{inputs:e,backend:t}=r,{condition:n,t:o,e:s}=e,a=new gS(n.shape.length,o.shape,o.shape.length);return t.runWebGLProgram(a,[n,o,s],hr(o.dtype,s.dtype))}var Wz={kernelName:ci,backendName:"webgl",kernelFunc:Gte};var Wte= `
// Stable and Attracting Fixed Point (0, 1) for Normalized Weights.
// see: https://arxiv.org/abs/1706.02515
float scaleAlpha = $ { I . SELU _SCALEALPHA } ;
float scale = $ { I . SELU _SCALE } ;
return ( x >= 0.0 ) ? scale * x : scaleAlpha * ( exp ( x ) - 1.0 ) ;
` ,Ute=ve({opSnippet:Wte}),Uz={kernelName:ha,backendName:"webgl",kernelFunc:Ute};var jz="return 1.0 / (1.0 + exp(-1.0 * x));",jte=ve({opSnippet:jz,packedOpSnippet:jz,cpuKernelImpl:_P}),Hz={kernelName:xs,backendName:"webgl",kernelFunc:jte};var Hte= `
if ( isnan ( x ) ) { return 0.0 ; }
return sign ( x ) ;
` ,qte=ve({opSnippet:Hte}),qz={kernelName:xa,backendName:"webgl",kernelFunc:qte};var Kte=tb+ `
return sin ( x ) ;
` ,Xte=ve({opSnippet:Kte}),Kz={kernelName:gs,backendName:"webgl",kernelFunc:Xte};var Yte= `
float e2x = exp ( x ) ;
return ( e2x - 1.0 / e2x ) / 2.0 ;
` ,Zte=ve({opSnippet:Yte}),Xz={kernelName:ga,backendName:"webgl",kernelFunc:Zte};var Jte= `
float epsilon = 1.1920928955078125 e - 7 ;
float threshold = log ( epsilon ) + 2.0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
bool too _large = x > - threshold ;
bool too _small = x < threshold ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
float result ;
float exp _x = exp ( x ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
if ( too _large ) {
result = x ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
else if ( too _small ) {
result = exp _x ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
else {
result = log ( exp _x + 1.0 ) ;
2021-09-11 17:17:13 +02:00
}
2021-10-22 22:09:52 +02:00
return result ;
` ,Qte=ve({opSnippet:Jte}),Yz={kernelName:ya,backendName:"webgl",kernelFunc:Qte};var ere=r=>{let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{blockShape:s,paddings:a}=n;b.assert(o.shape.length<=4,()=>"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet");let i=s.reduce((x,y)=>x*y),l=[[0,0]];l.push(...a);for(let x=1+s.length;x<o.shape.length;++x)l.push([0,0]);let u=[],c=sS({inputs:{x:o},backend:t,attrs:{paddings:l,constantValue:0}}),p=I.getReshaped(c.shape,s,i,!1),m=I.getPermuted(p.length,s.length,!1),f=I.getReshapedPermuted(c.shape,s,i,!1),d=ue({inputs:{x:c},backend:t,attrs:{shape:p}}),h=Pt({inputs:{x:d},backend:t,attrs:{perm:m}}),g=ue({inputs:{x:h},backend:t,attrs:{shape:f}});return u.push(c),u.push(d),u.push(h),u.forEach(x=>t.disposeIntermediateTensorInfo(x)),g},Zz={kernelName:mi,backendName:"webgl",kernelFunc:ere};function tre(r){let{inputs:e,backend:t}=r,{indices:n,values:o,denseShape:s,defaultValue:a}=e;if(s.shape.length!==1)throw new Error( ` Dense shape must be a vector , saw :
$ { s . shape } ` );if(n.shape.length!==2)throw new Error( ` Indices must be a matrix , saw :
$ { n . shape } ` );if(o.shape.length!==1)throw new Error( ` Values must be a vector , saw :
$ { o . shape } ` );if(a.shape.length!==0)throw new Error( ` Default value must be a scalar , saw :
$ { a . shape } ` );let i=t.readSync(n.dataId),l=t.readSync(o.dataId),u=t.readSync(s.dataId),c=t.readSync(a.dataId)[0],[p,m,f,d,h]=vP(i,n.shape,n.dtype,l,o.dtype,u,c);return[t.makeTensorInfo(m,n.dtype,p),t.makeTensorInfo([m[0]],o.dtype,f),t.makeTensorInfo([d.length],"bool",new Uint8Array(d.map(g=>Number(g)))),t.makeTensorInfo([h.length],n.dtype,new Int32Array(h))]}var Jz={kernelName:hp,backendName:"webgl",kernelFunc:tre};function rre(r){let{inputs:e,backend:t}=r,{inputIndices:n,inputShape:o,newShape:s}=e;if(n.shape.length!==2)throw new Error( ` Input indices should be a matrix but received shape $ { n . shape } ` );if(o.shape.length!==1)throw new Error( ` Input shape should be a vector but received shape $ { o . shape } ` );if(s.shape.length!==1)throw new Error( ` Target shape should be a vector but received shape $ { s . shape } ` );let a=Array.from(t.readSync(o.dataId)),i=t.readSync(n.dataId),l=Array.from(t.readSync(s.dataId)),[u,c,p]=CP(i,n.shape,n.dtype,a,l);return[t.makeTensorInfo(c,n.dtype,u),t.makeTensorInfo([p.length],s.dtype,new Int32Array(p))]}var Qz={kernelName:gp,backendName:"webgl",kernelFunc:rre};function nre(r){let{inputs:e,backend:t}=r,{data:n,indices:o,segmentIds:s}=e;if(n.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(o.shape.length!==1)throw new Error( ` Indices should be a vector but received shape
$ { o . shape } ` );if(s.shape.length!==1)throw new Error( ` Segment ids should be a vector but received shape
$ { s . shape } ` );let a=t.readSync(n.dataId),i=t.readSync(o.dataId),l=t.readSync(s.dataId),[u,c]=Jy(a,n.shape,n.dtype,i,l,!0);return t.makeTensorInfo(c,n.dtype,u)}var e3={kernelName:xp,backendName:"webgl",kernelFunc:nre};function ore(r){let{inputs:e,backend:t}=r,{data:n,indices:o,segmentIds:s}=e;if(n.shape.length<1)throw new Error("Data should be at least 1 dimensional but received scalar");if(o.shape.length!==1)throw new Error( ` Indices should be a vector but received shape
$ { o . shape } ` );if(s.shape.length!==1)throw new Error( ` Segment ids should be a vector but received shape
$ { s . shape } ` );let a=t.readSync(n.dataId),i=t.readSync(o.dataId),l=t.readSync(s.dataId),[u,c]=Jy(a,n.shape,n.dtype,i,l);return t.makeTensorInfo(c,n.dtype,u)}var t3={kernelName:yp,backendName:"webgl",kernelFunc:ore};function sre(r){let{inputs:e,backend:t,attrs:n}=r,{sparseIndices:o,sparseValues:s,defaultValue:a}=e,{outputShape:i}=n,{sliceRank:l,numUpdates:u,strides:c,outputSize:p}=I.calculateShapes(s,o,i),m=!1,f=new Jh(u,l,o.shape.length,s.shape.length,c,[p,1],m),d=t.runWebGLProgram(f,[s,o,a],s.dtype),h=ue({inputs:{x:d},backend:t,attrs:{shape:i}});return t.disposeIntermediateTensorInfo(d),h}var r3={kernelName:bp,backendName:"webgl",kernelFunc:sre};function ire(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{numOrSizeSplits:s,axis:a}=n,i=b.parseAxisParam(a,o.shape)[0],l=I.prepareSplitSize(o,s,i),u=o.shape.length,c=new Array(u).fill(0),p=o.shape.slice();return l.map(m=>{let f=[...p];f[i]=m;let d=Zs({inputs:{x:o},backend:t,attrs:{begin:c,size:f}});return c[i]+=m,d})}var n3={kernelName:fi,backendName:"webgl",kernelFunc:ire};var o3="return sqrt(x);",are=ve({opSnippet:o3,packedOpSnippet:o3,cpuKernelImpl:IP}),s3={kernelName:ys,backendName:"webgl",kernelFunc:are};var lre="return x * x;",ure=ve({opSnippet:lre}),i3={kernelName:kl,backendName:"webgl",kernelFunc:ure};var a3="return (a - b) * (a - b);",cre=at({opSnippet:a3,packedOpSnippet:a3}),l3={kernelName:_s,backendName:"webgl",kernelFunc:cre};function pre({inputs:r,attrs:e,backend:t}){let{x:n}=r,o=Nr+ `
return x > 0.0 ? 1.0 : float ( $ { e . alpha } ) ;
` ,s=new En(n.shape,o);return t.runWebGLProgram(s,[n],n.dtype)}var u3={kernelName:no,backendName:"webgl",kernelFunc:pre};var xS=class{constructor(e,t,n){this.variableNames=["x"],this.outputShape=n;let o=n.length,s=Ue(n.length),a=Ue(n.length),i="";if(o===1)i="coords * strides + begin";else{let l=0;i=n.map((u,c)=>(l++,n.length===1? ` coords * strides [ $ { c } ] + begin [ $ { c } ] ` : ` coords [ $ { l - 1 } ] * strides [ $ { c } ] + begin [ $ { c } ] ` )).join(",")}this.userCode= `
$ { s } begin = $ { s } ( $ { e } ) ;
$ { s } strides = $ { s } ( $ { t } ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
$ { a } coords = getOutputCoords ( ) ;
setOutput ( getX ( $ { i } ) ) ;
}
` }};function mre(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{begin:s,end:a,strides:i,beginMask:l,endMask:u,ellipsisMask:c,newAxisMask:p,shrinkAxisMask:m}=n,{nonStrided:f, $ begin:d, $ strides:h,size:g,newShape:x,outShape:y}=pr.sliceInfo(o.shape,s,a,i,l,u,c,p,m),w=ue({inputs:{x:o},backend:t,attrs:{shape:x}}),_;if(f){let A=Zs({inputs:{x:w},backend:t,attrs:{begin:d,size:g}});_=ue({inputs:{x:A},backend:t,attrs:{shape:y}}),t.disposeIntermediateTensorInfo(A)}else if(y.some(A=>A===0))_=t.makeTensorInfo(y,o.dtype,[]);else if(t.shouldExecuteOnCPU([w])){let R=t.texData.get(w.dataId).values,P=Ie(w.shape,w.dtype,R),L=SP(y,P,h,d);_=t.makeTensorInfo(y,w.dtype,L.values)}else{let D=new xS(d,h,y);_=t.runWebGLProgram(D,[w],w.dtype)}let C=ue({inputs:{x:_},backend:t,attrs:{shape:y}});return t.disposeIntermediateTensorInfo(w),t.disposeIntermediateTensorInfo(_),C}var c3={kernelName:ba,backendName:"webgl",kernelFunc:mre};function fre(r){let{inputs:e,backend:t,attrs:n}=r,{separator:o,nGramWidths:s,leftPad:a,rightPad:i,padWidth:l,preserveShortSequences:u}=n,{data:c,dataSplits:p}=e,m=t.readSync(c.dataId),f=t.readSync(p.dataId),[d,h]=NP(m,f,o,s,a,i,l,u);return[t.makeTensorInfo([d.length],"string",d),t.makeTensorInfo(p.shape,"int32",h)]}var p3={kernelName:wp,backendName:"webgl",kernelFunc:fre};function dre(r){let{inputs:e,backend:t,attrs:n}=r,{skipEmpty:o}=n,{input:s,delimiter:a}=e;if(s.dtype!=="string")throw new Error("Input must be of datatype string");if(s.shape.length!==1)throw new Error( ` Input must be a vector , got shape : $ { s . shape } ` );if(a.shape.length!==0)throw new Error( ` Delimiter must be a scalar , got shape : $ { a . shape } ` );let i=t.readSync(s.dataId),l=t.readSync(a.dataId)[0],[u,c,p]=TP(i,l,o),m=c.length;return[t.makeTensorInfo([m,2],"int32",u),t.makeTensorInfo([m],"string",c),t.makeTensorInfo([2],"int32",new Int32Array(p))]}var m3={kernelName:_p,backendName:"webgl",kernelFunc:dre};function hre(r){let{inputs:e,backend:t,attrs:n}=r,{numBuckets:o}=n,{input:s}=e;if(s.dtype!=="string")throw new Error("Input must be of datatype string");if(o<=0)throw new Error("Number of buckets must be at least 1");let a=t.readSync(s.dataId),i=EP(a,o);return t.makeTensorInfo(s.shape,"int32",i)}var f3={kernelName:kp,backendName:"webgl",kernelFunc:hre};var gre="return tan(x);",xre=ve({opSnippet:gre}),d3={kernelName:vs,backendName:"webgl",kernelFunc:xre};var yre= `
float e2x = exp ( - 2.0 * abs ( x ) ) ;
return sign ( x ) * ( 1.0 - e2x ) / ( 1.0 + e2x ) ;
` ,bre=ve({opSnippet:yre}),h3={kernelName:Cs,backendName:"webgl",kernelFunc:bre};var yS=class{constructor(e,t){this.variableNames=["A"];let n=new Array(e.length);for(let a=0;a<n.length;a++)n[a]=e[a]*t[a];this.outputShape=n,this.rank=n.length;let o=Ue(this.rank),s=wre(e);this.userCode= `
void main ( ) {
$ { o } resRC = getOutputCoords ( ) ;
setOutput ( getA ( $ { s } ) ) ;
}
` }};function wre(r){let e=r.length;if(e>5)throw Error( ` Tile for rank $ { e } is not yet supported ` );if(e===1)return ` imod ( resRC , $ { r [ 0 ] } ) ` ;let t=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],n=[];for(let o=0;o<r.length;o++)n.push( ` imod ( $ { t [ o ] } , $ { r [ o ] } ) ` );return n.join()}function bS(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{reps:s}=n;if(o.dtype==="string"||o.shape.length>5){let l=t.readSync(o.dataId),u=o.dtype==="string"?l.map(m=>b.decodeString(m)):l,c=Ie(o.shape,o.dtype,u),p=DP(c,s);return t.makeTensorInfo(p.shape,p.dtype,p.values)}let a=new yS(o.shape,s);return t.runWebGLProgram(a,[o],o.dtype)}var g3={kernelName:Hn,backendName:"webgl",kernelFunc:bS};var wS=class{constructor(e){this.variableNames=["x","indices"],this.customUniforms=[{name:"n",type:"int"},{name:"firstPass",type:"int"},{name:"negativeInf",type:"float"},{name:"dir",type:"int"},{name:"inc",type:"int"}],this.outputShape=e,this.userCode= `
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int elemIdx = coords [ 1 ] ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// We compare elements pair-wise within a group of size 2 * inc.
// The comparing rule for each group alternates between ascending
// and descending. Within each group, we compare each pair at
// positions i and i+inc. To decide whether an element at position i
// is x0 or x1, we mod it by 2 * inc, if the result is smaller than
// inc, it is in the first half of the group, we denote it as x0,
// otherwise we denote it as x1.
// For example, as shown in the Bitonic top K paper referenced above,
// Figure5(a) shows that element[1] is in the
// second half of the group when group size is 2, but it is in the
// first half of the group when group size is 4.
2021-07-29 15:53:13 +02:00
2021-10-22 22:09:52 +02:00
bool isFirstInPair = imod ( elemIdx , 2 * inc ) < inc ;
int i = isFirstInPair ? elemIdx : elemIdx - inc ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
int i0 = firstPass == 1 ? i : int ( getIndices ( batch , i ) ) ;
int i1 = firstPass == 1 ? i + inc : int ( getIndices ( batch , i + inc ) ) ;
float x0 = i0 < n ? getX ( batch , i0 ) : negativeInf ;
float x1 = i1 < n ? getX ( batch , i1 ) : negativeInf ;
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
// Denotes which direction indices are in (ascending or descending).
bool reverse = imod ( elemIdx , 2 * dir ) >= dir ;
bool isGreater = x0 > x1 || ( x0 == x1 && i1 > i0 ) ;
if ( reverse == isGreater ) { // Elements in opposite order of direction
int iTemp = i0 ;
i0 = i1 ;
i1 = iTemp ;
}
if ( isFirstInPair ) {
setOutput ( float ( i0 ) ) ;
} else {
setOutput ( float ( i1 ) ) ;
}
}
` }},_S=class{constructor(e){this.variableNames=["x","indices"],this.customUniforms=[{name:"n",type:"int"},{name:"firstPass",type:"int"},{name:"k",type:"int"}],this.outputShape=e,this.userCode= `
void main ( ) {
// Takes max of indices (0, k), (1, k + 1), (2, k + 2) ...
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int elemIdx = coords [ 1 ] ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
// The output size is half of the previous size.
// If the previous sequence is | | | | _ _ _ _ | | | | _ _ _ _ (k=4),
// we only need to output the indices at positions |, the indices at
// positions _ can be thrown away, see Figure5(b) After Phase 2
// (Merge phase) in the Bitonic Top K paper referenced above.
// For example, the paper shows we only need to output the orange bars.
// The output sequence should look like this | | | | | | | |.
// Because the sequence is halved, to map the output index back
// to the previous sequence to find the corresponding value,
// we need to double the index. When we double the index,
// we basically interpolate a position, so 2i looks like
// | _ | _ | _ | _ | _ | _ | _. We move the | to the first k position
// of each 2k positions by - elemIdx % k. E.g. for output at
// index 4,5,6,7, we want to get the corresponding element at
// original index 8,9,10,11, for output at index 8,9,10,11,
// we want to get the corresponding element at original index
// 16,17,18,19, so on and so forth.
2021-06-05 22:13:41 +02:00
2021-10-22 22:09:52 +02:00
int i = elemIdx < k ? elemIdx : ( elemIdx * 2 - imod ( elemIdx , k ) ) ;
int i0 = firstPass == 1 ? i : int ( getIndices ( batch , i ) ) ;
int i1 = firstPass == 1 ? i + k : int ( getIndices ( batch , i + k ) ) ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
float x0 = getX ( batch , i0 ) ;
float x1 = i1 < n ? getX ( batch , i1 ) : x0 ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
setOutput ( x0 >= x1 ? float ( i0 ) : float ( i1 ) ) ;
}
` }};function Nc(r,e){e!==null&&r.disposeIntermediateTensorInfo(e)}function x3(r){let e=1;for(;e<r;)e*=2;return e}function _re(r){let{inputs:e,backend:t,attrs:n}=r,{x:o}=e,{k:s,sorted:a}=n,i=U().getNumber("TOPK_LAST_DIM_CPU_HANDOFF_SIZE_THRESHOLD"),l=U().getNumber("TOPK_K_CPU_HANDOFF_THRESHOLD"),u=o.shape,c=u[u.length-1];if(t.shouldExecuteOnCPU([o])||c<i||s>l){let L=t.readSync(o.dataId),[G,W]= $ P(L,u,o.dtype,s,a);return[t.makeTensorInfo(G.shape,G.dtype,G.values),t.makeTensorInfo(W.shape,W.dtype,W.values)]}if(s===0)return u[u.length-1]=0,[t.makeTensorInfo(u,o.dtype,[]),t.makeTensorInfo(u,"int32",[])];if(c===1)return[o,rl({attrs:{shape:u,dtype:"int32",value:0},backend:t})];let p=t.texData.get(o.dataId),m=p!==null&&p.isPacked,f=m?t.unpackTensor(o):o,h=b.sizeFromShape(u)/c,g=ue({inputs:{x:f},attrs:{shape:[h,c]},backend:t});m&&Nc(t,f);let x=x3(s),y=x3(c),w=null,_=()=>w===null?[g,g]:[g,w],C=(L,G,W)=>{let j=_(),H=new wS(W),X=[[c],[w===null?1:0],[Number.NEGATIVE_INFINITY],[L],[G]],re=w;w=t.runWebGLProgram(H,j,"int32",X),Nc(t,re)};for(let L=1;L<x;L*=2){let G=L*2;for(let W=L;W>=1;W/=2)C(G,W,[h,y])}for(let L=y;L>x;L/=2){let G=_(),W=new _S([h,L/2]),H=[[c],[w===null?1:0],[x]],q=w;w=t.runWebGLProgram(W,G,"int32",H),Nc(t,q);let X=x/2,re=X*2;for(let J=X;J>=1;J/=2)C(re,J,w.shape)}let A=w;w=Zs({inputs:{x:w},backend:t,attrs:{begin:0,size:[h,s]}}),Nc(t,A);let D=WI({inputs:{x:g,indices:w},backend:t,attrs:{axis:1,batchDims:1}});Nc(t,g);let R=u.slice(0,-1);R.push(s),A=w,w=ue({inputs:{x:w},attrs:{shape:R},backend:t}),Nc(t,A);let P=D;return D=ue({inputs:{x:D},attrs:{shape:R},backend:t}),Nc(t,P),[D,w]}var y3={kernelName:wa,backendName:"webgl",kernelFunc:_re};var kS=class{constructor(e,t,n,o,s,a){this.variableNames=["Image","Transforms"],this.outputShape=a;let i=n==="nearest"?1:2,l;switch(o){case"constant":l=1;break;case"reflect":l=2;break;case"wrap":l=3;break;case"nearest":l=4;break;default:l=1;break}this.userCode= `
float mapCoord ( float outCoord , float len ) {
float inCoord = outCoord ;
if ( $ { l } == 2 ) {
if ( inCoord < 0.0 ) {
if ( len <= 1.0 ) {
inCoord = 0.0 ;
} else {
float sz2 = 2.0 * len ;
if ( inCoord < sz2 ) {
inCoord = sz2 * float ( int ( float ( - inCoord / sz2 ) ) ) +
inCoord ;
}
inCoord = inCoord < - len ? inCoord + sz2 : - inCoord - 1.0 ;
}
} else if ( inCoord > len - 1.0 ) {
if ( len <= 1.0 ) {
inCoord = 0.0 ;
} else {
float sz2 = 2.0 * len ;
inCoord -= sz2 * float ( int ( float ( inCoord / sz2 ) ) ) ;
if ( inCoord >= len ) {
inCoord = sz2 - inCoord - 1.0 ;
}
}
}
return clamp ( inCoord , 0.0 , len - 1.0 ) ;
} else if ( $ { l } == 3 ) {
if ( inCoord < 0.0 ) {
if ( len <= 1.0 ) {
inCoord = 0.0 ;
} else {
float sz = len - 1.0 ;
inCoord += len * ( float ( int ( float ( - inCoord / sz ) ) ) + 1.0 ) ;
}
} else if ( inCoord > len - 1.0 ) {
if ( len <= 1.0 ) {
inCoord = 0.0 ;
} else {
float sz = len - 1.0 ;
inCoord -= len * float ( int ( float ( inCoord / sz ) ) ) ;
}
}
return clamp ( inCoord , 0.0 , len - 1.0 ) ;
} else if ( $ { l } == 4 ) {
return clamp ( outCoord , 0.0 , len - 1.0 ) ;
} else {
return outCoord ;
}
}
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
float readWithFillValue ( int batch , int coordY , int coordX ,
int channel ) {
float outputValue ;
if ( 0 <= coordY && coordY < $ { e } && 0 <= coordX && coordX < $ { t } ) {
outputValue = getImage ( batch , coordY , coordX , channel ) ;
} else {
outputValue = float ( $ { s } ) ;
}
return outputValue ;
}
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
float outputValue ;
int batch = coords [ 0 ] ;
int x = coords [ 2 ] ;
int y = coords [ 1 ] ;
int channel = coords [ 3 ] ;
float xf = float ( x ) ;
float yf = float ( y ) ;
float a1 = getTransforms ( batch , 0 ) ;
float a2 = getTransforms ( batch , 1 ) ;
float a3 = getTransforms ( batch , 2 ) ;
float b1 = getTransforms ( batch , 3 ) ;
float b2 = getTransforms ( batch , 4 ) ;
float b3 = getTransforms ( batch , 5 ) ;
float c1 = getTransforms ( batch , 6 ) ;
float c2 = getTransforms ( batch , 7 ) ;
float projection = c1 * xf + c2 * yf + 1.0 ;
if ( projection == 0.0 ) {
outputValue = float ( $ { s } ) ;
} else {
float inX = ( a1 * xf + a2 * yf + a3 ) / projection ;
float inY = ( b1 * xf + b2 * yf + b3 ) / projection ;
float mapX = mapCoord ( inX , float ( $ { t } ) ) ;
float mapY = mapCoord ( inY , float ( $ { e } ) ) ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
if ( $ { i } == 1 ) {
int coordY = int ( round ( mapY ) ) ;
int coordX = int ( round ( mapX ) ) ;
outputValue = readWithFillValue ( batch , coordY , coordX ,
channel ) ;
} else {
float yFloor = floor ( mapY ) ;
float xFloor = floor ( mapX ) ;
float yCeil = yFloor + 1.0 ;
float xCeil = xFloor + 1.0 ;
float valueYFloor = ( xCeil - mapX ) *
readWithFillValue ( batch , int ( yFloor ) , int ( xFloor ) , channel ) +
( mapX - xFloor ) *
readWithFillValue ( batch , int ( yFloor ) , int ( xCeil ) , channel ) ;
float valueYCeil = ( xCeil - mapX ) *
readWithFillValue ( batch , int ( yCeil ) , int ( xFloor ) , channel ) +
( mapX - xFloor ) *
readWithFillValue ( batch , int ( yCeil ) , int ( xCeil ) , channel ) ;
outputValue = ( yCeil - mapY ) * valueYFloor +
( mapY - yFloor ) * valueYCeil ;
}
}
setOutput ( outputValue ) ;
}
` }};function kre(r){let{inputs:e,backend:t,attrs:n}=r,{image:o,transforms:s}=e,{interpolation:a,fillMode:i,fillValue:l,outputShape:u}=n,[c,p,m,f]=o.shape,[d,h]=u!=null?u:[p,m],g=[c,d,h,f],x=new kS(p,m,a,i,l,g);return t.runWebGLProgram(x,[o,s],"float32")}var b3={kernelName:_a,backendName:"webgl",kernelFunc:kre};function vre(r){let{inputs:e,attrs:t,backend:n}=r,{axis:o}=t,{x:s}=e;qs(s,"unique"),console.warn("WARNING: ","UI might be locked temporarily as data is being downloaded");let a=n.readSync(s.dataId),{outputValues:i,outputShape:l,indices:u}=RP(a,o,s.shape,s.dtype);return[n.makeTensorInfo(l,s.dtype,i),n.makeTensorInfo([u.length],"int32",u)]}var w3={kernelName:vp,backendName:"webgl",kernelFunc:vre};function Cre(r){let{inputs:e,backend:t,attrs:n}=r,{value:o}=e,{axis:s}=n;s<0&&(s+=o.shape.length);let a=o,i=a.shape.length,l=o.shape[s],u=new Array(i-1),c=0;for(let h=0;h<i;h++)h!==s&&(u[c++]=a.shape[h]);let p=[],m=new Array(i).fill(0),f=a.shape.slice();f[s]=1;let d=new Array(l);for(let h=0;h<d.length;h++){m[s]=h;let g=Zs({inputs:{x:a},backend:t,attrs:{begin:m,size:f}}),x=ue({inputs:{x:g},backend:t,attrs:{shape:u}});d[h]=x,p.push(g)}return p.forEach(h=>t.disposeIntermediateTensorInfo(h)),d}var _3={kernelName:di,backendName:"webgl",kernelFunc:Cre};var vS=class{constructor(e,t){this.variableNames=["x","segmentIds"];let n=e.windowSize,o=e.batchSize,s=e.inSize,a=e.numSegments,i=a*Math.ceil(s/n);this.outputShape=[o,i];let l="0.0",u="sumValue",c=Math.floor(n/4)*4,p=n%4,m= `
sumValue += dot ( values , segFilter ) ;
` ,f="";s%n>0&&(f= `
if ( inIdx < 0 || inIdx >= $ { s } ) {
return initializationValue ;
}
` );let d="";s%n>0&&(d= `
if ( inIdx < 0 || inIdx >= $ { s } ) {
return - 1.0 ;
}
` ),this.userCode= `
const float initializationValue = $ { l } ;
2021-06-07 01:00:34 +02:00
2021-10-22 22:09:52 +02:00
float getValue ( int batch , int inIdx ) {
$ { f }
return getX ( batch , inIdx ) ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
float getSegmentIdAtIndex ( int inIdx ) {
$ { d }
return getSegmentIds ( inIdx ) ;
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
int inOffset = int ( floor ( float ( outIdx ) / float (
$ { a } ) ) * float ( $ { n } ) ) ;
int currentSeg = int ( mod ( float ( outIdx ) , float ( $ { a } ) ) ) ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
float sumValue = 0.0 ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
for ( int i = 0 ; i < $ { c } ; i += 4 ) {
int inIdx = inOffset + i ;
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
getValue ( batch , inIdx + 3 )
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02: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
) ;
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
$ { m }
}
2021-06-07 02:47:59 +02:00
2021-10-22 22:09:52 +02:00
int inIdx = inOffset + $ { c } ;
if ( $ { p === 1 } ) {
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
int inIdxSeg = int ( getSegmentIdAtIndex ( inIdx ) ) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 segFilter = vec4 (
int ( getSegmentIdAtIndex ( inIdx ) ) == currentSeg ? 1 : 0 ,
0 ,
0 ,
0
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { m }
} else if ( $ { p === 2 } ) {
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
initializationValue ,
initializationValue
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
vec4 segFilter = vec4 (
int ( getSegmentIdAtIndex ( inIdx ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 1 ) ) == currentSeg ? 1 : 0 ,
0 ,
0
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { m }
} else if ( $ { p === 3 } ) {
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
initializationValue
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02: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
) ;
2021-09-11 17:17:13 +02:00
2021-10-22 22:09:52 +02:00
$ { m }
}
setOutput ( $ { u } ) ;
2021-06-07 01:00:34 +02:00
}
2021-10-22 22:09:52 +02:00
` }};function Ire(r){let{inputs:e,backend:t,attrs:n}=r,{x:o,segmentIds:s}=e,{numSegments:a}=n,i=o.shape.length,l=[],u=0,c=I.getAxesPermutation([u],i),p=o;c!=null&&(p=Pt({inputs:{x:o},backend:t,attrs:{perm:c}}),l.push(p),u=I.getInnerMostAxes(1,i)[0]);let m=I.segment_util.computeOutShape(p.shape,u,a),f=b.sizeFromShape([p.shape[u]]),d=ue({inputs:{x:p},backend:t,attrs:{shape:[-1,f]}});l.push(d);let h=hu(o.dtype),g=(_,C,A,D,R)=>{let P=_.shape[0],L=_.shape[1],G=I.segment_util.segOpComputeOptimalWindowSize(L,R),W={windowSize:G,inSize:L,batchSize:P,numSegments:R},j=new vS(W,C),H=t.compileAndRun(j,[_,A],D);if(l.push(H),H.shape[1]===R)return H;let q=iS({backend:t,attrs:{start:0,stop:R,step:1,dtype:"float32"}}),X=bS({inputs:{x:q},backend:t,attrs:{reps:[L/G]}});return l.push(q),l.push(X),g(H,C,X,D,R)},x=g(d,"unsortedSegmentSum",s,h,a),y=ue({inputs:{x},backend:t,attrs:{shape:m}}),w=y;if(c!=null){l.push(y);let _=I.getUndoAxesPermutation(c);w=Pt({inputs:{x:w},backend:t,attrs:{perm:_}})}return l.forEach(_=>t.disposeIntermediateTensorInfo(_)),w}var k3={kernelName:vl,backendName:"webgl",kernelFunc:Ire};var Sre=[XL,YL,uM,pM,mM,fM,hM,gM,xM,yM,_M,kM,vM,CM,SM,IM,NM,EM,TM,AM,DM, $ M,RM,OM,PM,MM,VM,WM,UM,HM,ZP,KM,YM,ZM,XM,QM,eL,JM,tL,rL,nL,iL,aL,lL,cL,pL,uL,mL,fL,dL,hL,gL,xL,yL,wL,_L,vL,CL,IL,SL,TL,EL,AL,DL, $ L,RL,FL,OL,PL,YP,ML,qM,LL,zL,BL,JP,VL,GL,WL,jL,UL,HL,qL,KL,JL,tz,ez,rz,nz,sz,QL,az,lz,uz,cz,pz,gz,nM,yz,bz,wz,_z,LM,kz,Iz,Sz,Nz,Tz,QP,Ez,Az,zM,mz,Dz,Rz, $ z,sM,Fz,Oz,Pz,Mz,Lz,zz,Bz,Vz,Gz,Wz,Uz,Hz,qz,Kz,Xz,FM,hz,Yz,Zz,Jz,Qz,e3,t3,r3,n3,s3,i3,l3,u3,c3,p3,m3,f3,dz,aM,d3,h3,g3,y3,b3,lM,w3,_3,k3,vz];for(let r of Sre)uu(r);var et;(function(r){r[r.float32=0]="float32",r[r.int32=1]="int32",r[r.bool=2]="bool",r[r.string=3]="string",r[r.complex64=4]="complex64"})(et||(et={}));var Zl;(function(r){r[r.linear=0]="linear",r[r.relu=1]="relu",r[r.relu6=2]="relu6",r[r.prelu=3]="prelu",r[r.leakyrelu=4]="leakyrelu",r[r.sigmoid=5]="sigmoid",r[r.elu=6]="elu"})(Zl||(Zl={}));var v3;function Nre(r){v3=r.wasm.cwrap(gi,null,["number","array","number","number","array","number","number","number","number","number","number","number","number"])}function Tre(r){let{inputs:e,backend:t,attrs:n}=r,{a:o,b:s,bias:a,preluActivationWeights:i}=e;if(o.dtype!=="float32"||s.dtype!=="float32")throw new Error("_FusedMatMul for non non-float32 tensors not yet supported.");let{transposeA:l,transposeB:u,activation:c,leakyreluAlpha:p}=n,m=t.dataIdMap.get(o.dataId).id,f=t.dataIdMap.get(s.dataId).id,d=0;if(a!=null){let R=t.dataIdMap.get(a.dataId);if(R.shape.length!==1)throw new Error( ` _FusedMatMul only supports rank - 1 bias but got rank $ { R . shape . length } . ` );d=R.id}let h=i==null?0:t.dataIdMap.get(i.dataId).id,g=Zl[c];if(g==null)throw new Error( ` $ { c } activation not yet supported for FusedConv2D in the wasm backend . ` );let x=l?o.shape[2]:o.shape[1],y=u?s.shape[1]:s.shape[2],w=o.shape[0],_=t.makeOutput([w,x,y],o.dtype),C=t.dataIdMap.get(_.dataId).id,A=new Uint8Array(new Int32Array(o.shape).buffer),D=new Uint8Array(new Int32Array(s.shape).buffer);return v3(m,A,o.shape.length,f,D,s.shape.length,l,u,g,d,h,p||0,C),_}var C3={kernelName:gi,backendName:"wasm",setupFunc:Nre,kernelFunc:Tre};function lt(r,e){let t;function n(s){t=s.wasm.cwrap(r,null,["number","number","number"])}function o(s){let{backend:a,inputs:{x:i}}=s,l=a.dataIdMap.get(i.dataId).id,u=a.makeOutput(i.shape,e||i.dtype),c=a.dataIdMap.get(u.dataId).id;return b.sizeFromShape(u.shape)===0||t(l,et[i.dtype],c),u}return{kernelName:r,backendName:"wasm",setupFunc:n,kernelFunc:o}}var I3=lt(ti);function kt(r,e,t){let n;function o(a){n=a.wasm.cwrap(r,null,["number","array","number","number","array","number","number","number"])}function s(a){let{backend:i,inputs:l}=a,{a:u,b:c}=l,p=i.dataIdMap.get(u.dataId).id,m=i.dataIdMap.get(c.dataId).id,f=t!=null?t:u.dtype,d=I.assertAndGetBroadcastShape(u.shape,c.shape),h=i.makeOutput(d,f);if(b.sizeFromShape(d)===0)return h;let g=new Uint8Array(new Int32Array(u.shape).buffer),x=new Uint8Array(new Int32Array(c.shape).buffer),y=i.dataIdMap.get(h.dataId).id,w=()=>n(p,g,u.shape.length,m,x,c.shape.length,et[u.dtype],y);
2021-02-21 19:34:26 +01:00
/ * *
* @ license
2021-04-28 14:58:21 +02:00
* Copyright 2017 Google LLC . All Rights Reserved .
2021-02-21 19:34:26 +01:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2021-04-28 14:58:21 +02:00
* Copyright 2018 Google LLC
2021-02-21 19:34:26 +01:00
*
2021-04-28 14:58:21 +02:00
* Use of this source code is governed by an MIT - style
* license that can be found in the LICENSE file or at
* https : //opensource.org/licenses/MIT.
2021-02-21 19:34:26 +01:00
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ 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
2021-04-28 14:58:21 +02:00
* Copyright 2019 Google LLC
2021-02-21 19:34:26 +01:00
*
2021-04-28 14:58:21 +02:00
* Use of this source code is governed by an MIT - style
* license that can be found in the LICENSE file or at
* https : //opensource.org/licenses/MIT.
2021-02-21 19:34:26 +01:00
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2021-04-28 14:58:21 +02:00
* Copyright 2019 Google LLC . All Rights Reserved .
2021-02-21 19:34:26 +01:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
*
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2021-04-28 14:58:21 +02:00
* Copyright 2019 Google LLC . All Rights Reserved .
2021-02-21 19:34:26 +01:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2021-04-28 14:58:21 +02:00
* Copyright 2020 Google Inc . All Rights Reserved .
2021-02-21 19:34:26 +01:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2021-04-28 14:58:21 +02:00
* Copyright 2020 Google LLC
2021-02-21 19:34:26 +01:00
*
2021-04-28 14:58:21 +02:00
* Use of this source code is governed by an MIT - style
* license that can be found in the LICENSE file or at
* https : //opensource.org/licenses/MIT.
2021-02-21 19:34:26 +01:00
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2021-04-28 14:58:21 +02:00
* Copyright 2020 Google LLC . All Rights Reserved .
2021-02-21 19:34:26 +01:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2021-04-28 14:58:21 +02:00
* Copyright 2020 Google LLC . All Rights Reserved .
* Licensed under the Apache License , Version 2.0 ( the License ) ;
2021-02-21 19:34:26 +01:00
* 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
2021-04-28 14:58:21 +02:00
* distributed under the License is distributed on an AS IS BASIS ,
2021-02-21 19:34:26 +01:00
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
2021-04-28 14:58:21 +02:00
* Copyright 2021 Google LLC . All Rights Reserved .
2021-02-21 19:34:26 +01:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
2021-04-30 17:55:04 +02:00
/ * *
* @ license
* Copyright 2021 Google LLC . All Rights Reserved .
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* 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 .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
2021-08-31 19:00:06 +02:00
/ * *
* @ 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 .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
2021-04-28 14:58:21 +02:00
/** @license See the LICENSE file. */
2021-09-11 17:17:13 +02:00
//# sourceMappingURL=tfjs.esm.js.map