2020-08-21 15:01:04 +02:00
var faceapi = ( ( ) => { var Yu = Object . defineProperty , WO = Object . prototype . hasOwnProperty , $s = ( e , t ) => ( ) => ( t || ( t = { exports : { } } , e ( t . exports , t ) ) , t . exports ) , Jx = e => Yu ( e , "__esModule" , { value : ! 0 } ) , Re = ( e , t ) => { Jx ( e ) ; for ( var s in t ) Yu ( e , s , { get : t [ s ] , enumerable : ! 0 } ) } , zO = ( e , t ) => { if ( Jx ( e ) , typeof t == "object" || typeof t == "function" ) for ( let s in t ) ! WO . call ( e , s ) && s !== "default" && Yu ( e , s , { get : ( ) => t [ s ] , enumerable : ! 0 } ) ; return e } , nl = e => e && e . _ _esModule ? e : zO ( Yu ( { } , "default" , { value : e , enumerable : ! 0 } ) , e ) ; var Qx = $s ( ( Zx , Qf ) => { ( function ( e , t , s ) { function n ( a ) { var l = this , c = o ( ) ; l . next = function ( ) { var p = 2091639 * l . s0 + l . c * 23283064365386963e-26 ; return l . s0 = l . s1 , l . s1 = l . s2 , l . s2 = p - ( l . c = p | 0 ) } , l . c = 1 , l . s0 = c ( " " ) , l . s1 = c ( " " ) , l . s2 = c ( " " ) , l . s0 -= c ( a ) , l . s0 < 0 && ( l . s0 += 1 ) , l . s1 -= c ( a ) , l . s1 < 0 && ( l . s1 += 1 ) , l . s2 -= c ( a ) , l . s2 < 0 && ( l . s2 += 1 ) , c = null } function i ( a , l ) { return l . c = a . c , l . s0 = a . s0 , l . s1 = a . s1 , l . s2 = a . s2 , l } function r ( a , l ) { var c = new n ( a ) , p = l && l . state , u = c . next ; return u . int32 = function ( ) { return c . next ( ) * 4294967296 | 0 } , u . double = function ( ) { return u ( ) + ( u ( ) * 2097152 | 0 ) * 11102230246251565e-32 } , u . quick = u , p && ( typeof p == "object" && i ( p , c ) , u . state = function ( ) { return i ( c , { } ) } ) , u } function o ( ) { var a = 4022871197 , l = function ( c ) { c = c . toString ( ) ; for ( var p = 0 ; p < c . length ; p ++ ) { a += c . charCodeAt ( p ) ; var u = . 02519603282416938 * a ; a = u >>> 0 , u -= a , u *= a , a = u >>> 0 , u -= a , a += u * 4294967296 } return ( a >>> 0 ) * 23283064365386963e-26 } ; return l } t && t . exports ? t . exports = r : s && s . amd ? s ( function ( ) { return r } ) : this . alea = r } ) ( Zx , typeof Qf == "object" && Qf , typeof define == "function" && define ) } ) ; var tL = $s ( ( eL , eg ) => { ( function ( e , t , s ) { function n ( o ) { var a = this , l = "" ; a . x = 0 , a . y = 0 , a . z = 0 , a . w = 0 , a . next = function ( ) { var p = a . x ^ a . x << 11 ; return a . x = a . y , a . y = a . z , a . z = a . w , a . w ^= a . w >>> 19 ^ p ^ p >>> 8 } , o === ( o | 0 ) ? a . x = o : l += o ; for ( var c = 0 ; c < l . length + 64 ; c ++ ) a . x ^= l . charCodeAt ( c ) | 0 , a . next ( ) } function i ( o , a ) { return a . x = o . x , a . y = o . y , a . z = o . z , a . w = o . w , a } function r ( o , a ) { var l = new n ( o ) , c = a && a . state , p = function ( ) { return ( l . next ( ) >>> 0 ) / 4294967296 } ; return p . double = function ( ) { do var u = l . next ( ) >>> 11 , h = ( l . next ( ) >>> 0 ) / 4294967296 , d = ( u + h ) / ( 1 << 21 ) ; while ( d === 0 ) ; return d } , p . int32 = l . next , p . quick = p , c && ( typeof c == "object" && i ( c , l ) , p . state = function ( ) { return i ( l , { } ) } ) , p } t && t . exports ? t . exports = r : s && s . amd ? s ( function ( ) { return r } ) : this . xor128 = r } ) ( eL , typeof eg == "object" && eg , typeof define == "function" && define ) } ) ; var nL = $s ( ( sL , tg ) => { ( function ( e , t , s ) { function n ( o ) { var a = this , l = "" ; a . next = function ( ) { var p = a . x ^ a . x >>> 2 ; return a . x = a . y , a . y = a . z , a . z = a . w , a . w = a . v , ( a . d = a . d + 362437 | 0 ) + ( a . v = a . v ^ a . v << 4 ^ ( p ^ p << 1 ) ) | 0 } , a . x = 0 , a . y = 0 , a . z = 0 , a . w = 0 , a . v = 0 , o === ( o | 0 ) ? a . x = o : l += o ; for ( var c = 0 ; c < l . length + 64 ; c ++ ) a . x ^= l . charCodeAt ( c ) | 0 , c == l . length && ( a . d = a . x << 10 ^ a . x >>> 4 ) , a . next ( ) } function i ( o , a ) { return a . x = o . x , a . y = o . y , a . z = o . z , a . w = o . w , a . v = o . v , a . d = o . d , a } function r ( o , a ) { var l = new n ( o ) , c = a && a . state , p = function ( ) { return ( l . next ( ) >>> 0 ) / 4294967296 } ; return p . double = function ( ) { do var u = l . next ( ) >>> 11 , h = ( l . next ( ) >>> 0 ) / 4294967296 , d = ( u + h ) / ( 1 << 21 ) ; while ( d === 0 ) ; return d } , p . int32 = l . next , p . quick = p , c && ( typeof c == "object" && i ( c , l ) , p . state = function ( ) { return i ( l , { } ) } ) , p } t && t . exports ? t . exports = r : s && s . amd ? s ( function ( ) { return r } ) : this . xorwow = r } ) ( sL , typeof tg == "object" && tg , typeof define == "function" && define ) } ) ; var rL = $s ( ( iL , sg ) => { ( function ( e , t , s ) { function n ( o ) { var a = this ; a . next = function ( ) { var c = a . x , p = a . i , u , h , d ; return u = c [ p ] , u ^= u >>> 7 , h = u ^ u << 24 , u = c [ p + 1 & 7 ] , h ^= u ^ u >>> 10 , u = c [ p + 3 & 7 ] , h ^= u ^ u >>> 3 , u = c [ p + 4 & 7 ] , h ^= u ^ u << 7 , u = c [ p + 7 & 7 ] , u = u ^ u << 13 , h ^= u ^ u << 9 , c [ p ] = h , a . i = p + 1 & 7 , h } ; function l ( c , p ) { var u , h , d = [ ] ; if ( p === ( p | 0 ) ) h = d [ 0 ] = p ; else for ( p = "" + p , u = 0 ; u < p . length ; ++ u ) d [ u & 7 ] = d [ u & 7 ] << 15 ^ p . charCodeAt ( u ) + d [ u + 1 & 7 ] << 13 ; for ( ; d . length < 8 ; ) d . push ( 0 ) ; for ( u = 0 ; u < 8 && d [ u ] === 0 ; ++ u ) ; for ( u == 8 ? h = d [ 7 ] = - 1 : h = d [ u ] , c . x = d , c . i = 0 , u = 256 ; u > 0 ; -- u ) c . next ( ) } l ( a , o ) } function i ( o , a ) { return a . x = o . x . slice ( ) , a . i = o . i , a } function r ( o , a ) { o == null && ( o = + new Date ( ) ) ; var l = new n ( o ) , c = a && a . state , p = function ( ) { return ( l . next ( ) >>> 0 ) / 4294967296 } ; return p . double = function ( ) { do var u = l . next ( ) >>> 11 , h = ( l . next ( ) >>> 0 ) / 4294967296 , d = ( u + h ) / ( 1 << 21 ) ; while ( d === 0 ) ; return d } , p . int32 = l . next , p . quick = p , c && ( c . x && i ( c , l ) , p . state = function ( ) { return i ( l , { } ) } ) , p } t && t . exports ? t . exports = r : s && s . amd ? s ( function ( ) { return r } ) : this . xorshift7 = r } ) ( iL , typeof sg == "object" && sg , typeof define == "function" && define ) } ) ; var aL = $s ( ( oL
` )),l.join( `
` )}function x1(e,t,s,n){const i=We(t),r=n[n.length-1],o=new Array(r).fill(0),a=t.length,l=s==="complex64"?ep(e):e;if(a>1)for(let c=0;c<i/r;c++){const p=c*r;for(let u=0;u<r;u++)o[u]=Math.max(o[u],Qc(l[p+u],0,s).length)}return o}function Qc(e,t,s){let n;return Array.isArray(e)?n= ` $ { parseFloat ( e [ 0 ] . toFixed ( py ) ) } + $ { parseFloat ( e [ 1 ] . toFixed ( py ) ) } j ` :vn(e)?n= ` '${e}' ` :s==="bool"?n=rS(e):n=parseFloat(e.toFixed(py)).toString(),zr(n,t)}function rS(e){return e===0?"false":"true"}function Eh(e,t,s,n,i,r=!0){const o=s==="complex64"?2:1,a=t[0],l=t.length;if(l===0){if(s==="complex64"){const f=ep(e);return[Qc(f[0],0,s)]}return s==="bool"?[rS(e[0])]:[e[0].toString()]}if(l===1){if(a>nS){const y=Zc*o;let b=Array.from(e.slice(0,y)),S=Array.from(e.slice((a-Zc)*o,a*o));return s==="complex64"&&(b=ep(b),S=ep(S)),["["+b.map((x,I)=>Qc(x,i[I],s)).join(", ")+", ..., "+S.map((x,I)=>Qc(x,i[a-Zc+I],s)).join(", ")+"]"]}const f=s==="complex64"?ep(e):Array.from(e);return["["+f.map((y,b)=>Qc(y,i[b],s)).join(", ")+"]"]}const c=t.slice(1),p=n.slice(1),u=n[0]*o,h=[];if(a>nS){for(let f=0;f<Zc;f++){const y=f*u,b=y+u;h.push(...Eh(e.slice(y,b),c,s,p,i,!1))}h.push("...");for(let f=a-Zc;f<a;f++){const y=f*u,b=y+u;h.push(...Eh(e.slice(y,b),c,s,p,i,f===a-1))}}else for(let f=0;f<a;f++){const y=f*u,b=y+u;h.push(...Eh(e.slice(y,b),c,s,p,i,f===a-1))}const d=l===2?",":"";h[0]="["+h[0]+d;for(let f=1;f<h.length-1;f++)h[f]=" "+h[f]+d;let m= ` ,
` ;for(let f=2;f<l;f++)m+= `
` ;return h[h.length-1]=" "+h[h.length-1]+"]"+(r?"":m),h}function ep(e){const t=[];for(let s=0;s<e.length;s+=2)t.push([e[s],e[s+1]]);return t}class fi{constructor(e,t,s){if(this.dtype=t,this.shape=e.slice(),this.size=We(e),s!=null){const n=s.length;v(n===this.size,()=> ` Length of values '${n}' 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=s||iy(t,this.size),this.strides=qn(e)}set(e,...t){t.length===0&&(t=[0]),v(t.length===this.rank,()=> ` The number of provided coordinates ( $ { t . length } ) must match the rank ( $ { this . rank } ) ` );const s=this.locToIndex(t);this.values[s]=e}get(...e){e.length===0&&(e=[0]);let t=0;for(const n of e){if(n<0||n>=this.shape[t]){const i= ` Requested out of range element at $ { e } . Buffer shape = $ { this . shape } ` ;throw new Error(i)}t++}let s=e[e.length-1];for(let n=0;n<e.length-1;++n)s+=this.strides[n]*e[n];return this.values[s]}locToIndex(e){if(this.rank===0)return 0;if(this.rank===1)return e[0];let t=e[e.length-1];for(let s=0;s<e.length-1;++s)t+=this.strides[s]*e[s];return t}indexToLoc(e){if(this.rank===0)return[];if(this.rank===1)return[e];const t=new Array(this.shape.length);for(let s=0;s<t.length-1;++s)t[s]=Math.floor(e/this.strides[s]),e-=t[s]*this.strides[s];return t[t.length-1]=e,t}get rank(){return this.shape.length}toTensor(){return Kn().makeTensor(this.values,this.shape,this.dtype)}}let Kn=null,aa=null,L1=null;function oS(e){Kn=e}function aS(e){aa=e}function lS(e){L1=e}class ue{constructor(e,t,s,n){this.kept=!1,this.isDisposedInternal=!1,this.shape=e.slice(),this.dtype=t||"float32",this.size=We(e),this.strides=qn(e),this.dataId=s,this.id=n,this.rankType=this.rank<5?this.rank.toString():"higher"}get rank(){return this.shape.length}async buffer(){const e=await this.data();return aa.buffer(this.shape,this.dtype,e)}bufferSync(){return aa.buffer(this.shape,this.dtype,this.dataSync())}async array(){const e=await this.data();return Br(this.shape,e)}arraySync(){return Br(this.shape,this.dataSync())}async data(){this.throwIfDisposed();const e=Kn().read(this.dataId);if(this.dtype==="string"){const t=await e;try{return t.map(s=>Oh(s))}catch(s){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();const e=Kn().readSync(this.dataId);if(this.dtype==="string")try{return e.map(t=>Oh(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();const e=await Kn().read(this.dataId);return this.dtype==="string"?e:new Uint8Array(e.buffer)}dispose(){if(this.isDisposed)return;Kn().disposeTensor(this),this.isDisposedInternal=!0}get isDisposed(){return this.isDisposedInternal}throwIfDisposed(){if(this.isDisposed)throw new Error("Tensor is disposed.")}print(e=!1){return aa.print(this,e)}clone(){return this.throwIfDisposed(),aa.clone(this)}toString(e=!1){const t=this.dataSync();return iS(t,this.shape,this.dtype,e)}cast(e){return this.throwIfDisposed(),aa.cast(this,e)}variable(e=!0,t,s){return this.throwIfDisposed(),Kn().makeVariable(this,e,t,s)}}Object.defineProperty(ue,Symbol.hasInstance,{value:e=>!!e&&e.dataId!=null&&e.shape!=null&&e.dtype!=null});class Xn extends ue{constructor(e,t,s,n){super(e.shape,e.dtype,e.dataId,n);this.trainable=t,this.name=s}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(!It(e.shape,this.shape))throw new Error( ` shape of the new value ( $ { e . shape } ) and previous value ( $ { this . shape } ) must match ` );Kn().disposeTensor(this),this.dataId=e.dataId,Kn().incRef(this,null)}dispose(){Kn().disposeVariable(this),this.isDisposedInternal=!0}}Object.defineProperty(Xn,Symbol.hasInstance,{value:e=>e instanceof ue&&e.assign!=null&&e.assign instanceof Function});var uy;(function(e){e.R0="R0",e.R1="R1",e.
with dtype $ { c . dtype } . ` )});const n=Te(t,s[0].shape)[0],i=Ty(s.map(c=>c.shape),n);if(We(i)===0)return ze([],i);if(s=s.filter(c=>c.size>0),s.length===1)return s[0];const r=s.map(c=>c.shape);vy(r,n);const o=(c,p)=>{const u=c.concat(s,n);return p(s),u},a=s,l={axis:t};return T.runKernelFunc(o,a,null,El,l)}const ge=L({concat_:dE});function mE(e,t,s=!1,n=!1){let i=g(e,"a","matMul"),r=g(t,"b","matMul");[i,r]=Ne(i,r),v(i.rank>=2&&r.rank>=2&&i.rank===r.rank,()=> ` Error in matMul : inputs must have the same rank of at least 2 , got ranks $ { i . rank } and $ { r . rank } . ` );const o=s?i.shape[i.rank-2]:i.shape[i.rank-1],a=n?r.shape[r.rank-1]:r.shape[r.rank-2],l=s?i.shape[i.rank-1]:i.shape[i.rank-2],c=n?r.shape[r.rank-2]:r.shape[r.rank-1],p=i.shape.slice(0,-2),u=r.shape.slice(0,-2),h=We(p),d=We(u);v(It(p,u),()=> ` Error in matMul : outer dimensions ( $ { p } ) and ( $ { u } ) of Tensors with shapes $ { i . shape } and $ { r . shape } must match . ` ),v(o===a,()=> ` Error in matMul : inner shapes ( $ { o } ) and ( $ { a } ) of Tensors with shapes $ { i . shape } and $ { r . shape } and transposeA = $ { s } and transposeB = $ { n } must match . ` );const m=i.shape.slice(0,-2).concat([l,c]),f=s?O(i,[h,o,l]):O(i,[h,l,o]),y=n?O(r,[d,c,a]):O(r,[d,a,c]),b=(A,k)=>(k([f,y]),A.batchMatMul(f,y,s,n)),S={a:f,b:y},x={transposeA:s,transposeB:n},I=T.runKernelFunc(b,S,null,Al,x);return O(I,m)}const Le=L({matMul_:mE});function fE(e,t){let s=g(e,"a","mul"),n=g(t,"b","mul");[s,n]=Ne(s,n);const i=(o,a)=>{const l=o.multiply(s,n);return a([s,n]),l},r={a:s,b:n};return T.runKernelFunc(i,r,null,lc)}const C=L({mul_:fE});function gE(e){const t=g(e,"x","sigmoid"),s={x:t};return T.runKernelFunc((n,i)=>{const r=n.sigmoid(t);return i([r]),r},s,null,Ec)}const Ss=L({sigmoid_:gE});const Jn={};Re(Jn,{assertParamsValid:()=>Iy,computeFlatOffset:()=>bE,computeOutShape:()=>Ay,isSliceContinous:()=>yE,maskToAxes:()=>mp,parseSliceParams:()=>fp,startForAxis:()=>Ey,startIndicesWithElidedDims:()=>Cy,stopForAxis:()=>ky,stopIndicesWithElidedDims:()=>Ry,stridesForAxis:()=>Oy,stridesWithElidedDims:()=>Ny});function Iy(e,t,s){v(e.rank===t.length,()=> ` Error in slice$ { e . rank } D : Length of begin $ { t } must match the rank of the array ( $ { e . rank } ) . ` ),v(e.rank===s.length,()=> ` Error in slice$ { e . rank } D : Length of size $ { s } must match the rank of the array ( $ { e . rank } ) . ` );for(let n=0;n<e.rank;++n)v(t[n]+s[n]<=e.shape[n],()=> ` Error in slice$ { e . rank } D : begin [ $ { n } ] + size [ $ { n } ] ( $ { t [ n ] + s [ n ] } ) would overflow input . shape [ $ { n } ] ( $ { e . shape [ n ] } ) ` )}function mp(e){const t=[];let s=0;for(;e>0;)e&1&&t.push(s),e/=2,s++;return t}function Ay(e,t,s){const n=[];for(let i=0;i<e.length;i++)n[i]=Math.ceil((t[i]-e[i])/s[i]);return n}function Ny(e,t,s,n){const i=[...e];for(let r=i.length;r<n.length;r++)i.push(1);for(let r=0;r<s;r++)r===0?i[t]=1:(i.splice(t,0,1),i.pop());return i}function fS(e,t,s){return s<=e?s:s-(t-1)}function gS(e,t){const s=[];for(let n=0;n<e;n++)s.push(t+n);return s}function Cy(e,t,s,n,i){const r=[...i],o=gS(s,t);for(let a=0;a<r.length;a++)if(o.indexOf(a)>-1)r[a]=0;else{const l=fS(t,s,a);let c=n[l];e&1<<l&&(c=0),r[a]=c}return r}function Ry(e,t,s,n,i){const r=[...i],o=gS(s,t);for(let a=0;a<r.length;a++)if(o.indexOf(a)>-1)r[a]=Number.MAX_SAFE_INTEGER;else{const l=fS(t,s,a);let c=n[l];e&1<<l&&(c=Number.MAX_SAFE_INTEGER),r[a]=c}for(let a=0;a<r.length;a++){const l=i[a];r[a]<0&&(r[a]+=l),r[a]=na(0,r[a],i[a])}return r}function Oy(e,t,s){let n=e[t];return(s&1<<t||n==null)&&(n=1),n}function Ey(e,t,s,n,i,r){let o=t[i];const a=s[i]||1;(e&1<<i||r&1<<i||o==null)&&(a>0?o=Number.MIN_SAFE_INTEGER:o=Number.MAX_SAFE_INTEGER);const l=n[i];return o<0&&(o+=l),o=na(0,o,l-1),o}function ky(e,t,s,n,i,r){let o=t[i];const a=s[i]||1;(e&1<<i||r&1<<i||o==null)&&(a>0?o=Number.MAX_SAFE_INTEGER:o=Number.MIN_SAFE_INTEGER);const l=n[i];return o<0&&(o+=l),a>0?o=na(0,o,l):o=na(-1,o,l-1),o}function yE(e,t,s){let n=s.length;for(let i=0;i<s.length;i++)if(s[i]>1){n=i;break}for(let i=n+1;i<s.length;i++)if(t[i]>0||s[i]!==e[i])return!1;return!0}function bE(e,t){let s=e.length>0?e[e.length-1]:1;for(let n=0;n<e.length-1;n++)s+=e[n]*t[n];return s}function fp(e,t,s){let n;typeof t=="number"?n=[t,...new Ar
$ { i } and $ { t } for depthToSpace with input shape
$ { n . shape } ` ),v(r*t>=0,()=> ` Negative dimension size caused by overflow when multiplying
$ { r } and $ { t } for depthToSpace with input shape
$ { n . shape } ` ),v(o%(t*t)===0,()=> ` Dimension size must be evenly divisible by $ { t * t } but is $ { o } for depthToSpace with input shape $ { n . shape } ` );const a=p=>p.depthToSpace(n,t,s),l={x:n},c={blockSize:t,dataFormat:s};return T.runKernelFunc(a,l,null,vg,c)}const Tp=L({depthToSpace_:HE});function qE(e,t,s,n,i="NHWC",r=[1,1],o){const a=g(e,"x","depthwiseConv2d"),l=g(t,"filter","depthwiseConv2d");let c=a,p=!1;a.rank===3&&(p=!0,c=O(a,[1,a.shape[0],a.shape[1],a.shape[2]])),v(c.rank===4,()=> ` Error in depthwiseConv2d : input must be rank 4 , but got rank $ { c . rank } . ` ),v(l.rank===4,()=> ` Error in depthwiseConv2d : filter must be rank 4 , but got rank $ { l . rank } . ` ),v(c.shape[3]===l.shape[2],()=> ` Error in depthwiseConv2d : number of input channels ( $ { c . shape [ 3 ] } ) must match the inChannels dimension in filter $ { l . shape [ 2 ] } . ` ),o!=null&&v(De(n),()=> ` Error in depthwiseConv2d : pad must be an integer when using , dimRoundingMode $ { o } but got pad $ { n } . ` );const u=(f,y)=>{r==null&&(r=[1,1]),v(et(s,r),()=> ` Error in depthwiseConv2d : Either strides or dilations must be 1. Got strides $ { s } and dilations '${r}' ` );const b=is(c.shape,l.shape,s,r,n,o,!0),S=f.depthwiseConv2D(c,l,b);return y([c,l]),S},h={x:c,filter:l},d={strides:s,pad:n,dataFormat:i,dilations:r,dimRoundingMode:o},m=T.runKernelFunc(u,h,null, $ l,d);return p?O(m,[m.shape[1],m.shape[2],m.shape[3]]):m}const In=L({depthwiseConv2d_:qE});function YE(e){const t=g(e,"x","diag"),s=i=>{const r=O(t,[t.size]),o=i.diag(r),a=[...e.shape,...e.shape];return O(o,a)},n={x:t};return T.runKernelFunc(s,n,null,Ag)}const Fy=L({diag_:YE});function KE(e,t,s,n,i=[1,1],r="NHWC"){const o=g(e,"x","dilation2d"),a=g(t,"filter","dilation2d");v(o.rank===3||o.rank===4,()=> ` Error in dilation2d : input must be rank 3 or 4 , but got rank $ { o . rank } . ` ),v(a.rank===3,()=> ` Error in dilation2d : filter must be rank 3 , but got rank $ { a . rank } . ` ),v(r==="NHWC",()=> ` Error in dilation2d : Only NHWC is currently supported , but got dataFormat of $ { r } ` );let l=o,c=!1;o.rank===3&&(l=O(o,[1,o.shape[0],o.shape[1],o.shape[2]]),c=!0);const p={x:l,filter:a},u={strides:s,pad:n,dilations:i},h=T.runKernel(_r,p,u);return c?O(h,[h.shape[1],h.shape[2],h.shape[3]]):h}const Ip=L({dilation2d_:KE});function XE(e,t){let s=g(e,"a","floorDiv"),n=g(t,"b","floorDiv");[s,n]=Ne(s,n);const i=(o,a)=>{const l=o.floorDiv(s,n);return a([s,n]),l},r={a:s,b:n};return T.runKernelFunc(i,r,null,Vl)}const Jr=L({floorDiv_:XE});function JE(e,t){let s=g(e,"a","div"),n=g(t,"b","div");if([s,n]=Ne(s,n),s.dtype==="int32"&&n.dtype==="int32")return Jr(s,n);const i=(a,l)=>{const c=a.realDivide(s,n);return l([s,n]),c},r={a:s,b:n},o={};return T.runKernelFunc(i,r,null,ui,o)}const J=L({div_:JE});function ZE(e,t){const s=e.length,n=[];for(let i=0;i<s;i++){const r=s-1-i,o=e[r]||1,a=t[t.length-1-i]||1;a>1&&o===1&&n.unshift(r)}return n}function Ke(e,t){const s=[];for(let n=0;n<t.length;n++){const i=e[e.length-n-1],r=t.length-n-1,o=t[r];(i==null||i===1&&o>1)&&s.unshift(r)}return s}function Se(e,t){const s=[],n=Math.max(e.length,t.length);for(let i=0;i<n;i++){let r=e[e.length-i-1];r==null&&(r=1);let o=t[t.length-i-1];if(o==null&&(o=1),r===1)s.unshift(o);else if(o===1)s.unshift(r);else if(r!==o){const a= ` Operands could not be broadcast together with shapes $ { e } and $ { t } . ` ;throw Error(a)}else s.unshift(r)}return s}function QE(e,t){let s=g(e,"a","equal"),n=g(t,"b","equal");[s,n]=Ne(s,n),Se(s.shape,n.shape);const i=o=>o.equal(s,n),r={a:s,b:n};return T.runKernelFunc(i,r,null,Cg)}const Qt=L({equal_:QE});function ek(e,t,s){const n=g(t,"a","where"),i=g(s,"b","where"),r=g(e,"condition","where","bool"),o=Se(n.shape,i.shape),a=or(n,o),l=or(i,o);r.rank===1&&v(r.shape[0]===n.shape[0],()=>"The first dimension of ` a ` must match the size of ` condition ` ."),r.rank!==1&&xe(r.shape,l.shape,"Error in where: ");const c=(u,h)=>{const d=u.select(r,a,l);return h([r]),d},p={condition:r,t:a,e:l};return T.runKernelFunc(c,p,null,Ic)}const at=L({where_:ek});function tk(e){const t=g(e,"x","zerosLike"),s={x:t};return T.runKernelFunc(n=>n.zerosLike(t),s,null,Vc)}const ne=L({zerosLike_:tk});function sk(e,t){let s=g(e,"a","div"),n=g(t,"b
rank $ { r . rank } . ` ),v(De(t),()=> ` Error in localResponseNormalization : depthRadius must be an integer but got depthRadius $ { t } . ` );let o=r,a=!1;r.rank===3&&(a=!0,o=O(r,[1,r.shape[0],r.shape[1],r.shape[2]]));const l=(h,d)=>{const m=h.localResponseNormalization4D(o,t,s,n,i);return d([o,m]),m},c={x:o},p={depthRadius:t,bias:s,alpha:n,beta:i},u=T.runKernelFunc(l,c,null,tc,p);return a?O(u,[u.shape[1],u.shape[2],u.shape[3]]):u}const Op=L({localResponseNormalization_:Ek});function kk(e){const t=g(e,"x","log"),s={x:t};return T.runKernelFunc((n,i)=>{const r=n.log(t);return i([t]),r},s,null,Zl)}const Mt=L({log_:kk});function _k(e){const t=g(e,"x","log1p"),s={x:t};return T.runKernelFunc((n,i)=>{const r=n.log1p(t);return i([t]),r},s,null,Ql)}const eo=L({log1p_:_k});function Dk(e){return v(Hn(e),()=>"The f passed in grad(f) must be a function"),(t,s)=>{const n=g(t,"x","tf.grad",null),i=s!=null?g(s,"dy","tf.grad"):null;return T.tidy(()=>{const{value:r,grads:o}=T.gradients(()=>e(n),[n],i);return i!=null&&xe(r.shape,i.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),Mh(o),o[0]})}}function Fk(e){return v(Hn(e),()=>"The f passed in grads(f) must be a function"),(t,s)=>{v(Array.isArray(t),()=>"The args passed in grads(f)(args) must be an array of ` Tensor ` s or ` TensorLike ` s");const n=yi(t,"args","tf.grads",null),i=s!=null?g(s,"dy","tf.grads"):null;return T.tidy(()=>{const{value:r,grads:o}=T.gradients(()=>e(...n),n,i);return i!=null&&xe(r.shape,i.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Mh(o),o})}}function Mk(e){return v(Hn(e),()=>"The f passed in valueAndGrad(f) must be a function"),(t,s)=>{v(t instanceof ue,()=>"The x passed in valueAndGrad(f)(x) must be a tensor"),v(s==null||s instanceof ue,()=>"The dy passed in valueAndGrad(f)(x, dy) must be a tensor");const{grads:n,value:i}=T.gradients(()=>e(t),[t],s);return Mh(n),{grad:n[0],value:i}}}function Uk(e){return v(Hn(e),()=>"The f passed in valueAndGrads(f) must be a function"),(t,s)=>{v(Array.isArray(t)&&t.every(i=>i instanceof ue),()=>"The args passed in valueAndGrads(f)(args) must be array of tensors"),v(s==null||s instanceof ue,()=>"The dy passed in valueAndGrads(f)(args, dy) must be a tensor");const n=T.gradients(()=>e(...t),t,s);return s!=null&&xe(n.value.shape,s.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),Mh(n.grads),n}}function Uh(e,t){v(Hn(e),()=>"The f passed in variableGrads(f) must be a function"),v(t==null||Array.isArray(t)&&t.every(c=>c instanceof Xn),()=>"The varList passed in variableGrads(f, varList) must be an array of variables");const s=t!=null;if(!s){t=[];for(const c in T.registeredVariables)t.push(T.registeredVariables[c])}const n=s?t.filter(c=>!c.trainable):null,i=t.length;t=t.filter(c=>c.trainable),v(t.length>0,()=> ` variableGrads ( ) expects at least one of the input variables to be trainable , but none of the $ { i } variables is trainable . ` );const r=!0,{value:o,grads:a}=T.gradients(e,t,null,r);v(a.some(c=>c!=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()."),v(o.rank===0,()=> ` The f passed in variableGrads ( f ) must return a scalar , but it returned a rank - $ { o . rank } tensor ` );const l={};return t.forEach((c,p)=>{a[p]!=null&&(l[c.name]=a[p])}),n!=null&&n.forEach(c=>l[c.name]=null),{value:o,grads:l}}function ms(e){return T.customGrad(e)}function Mh(e){const t=e.filter(s=>s==null).length;if(t>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 $ k(e){const t=g(e,"x","neg"),s={x:t};return T.runKernelFunc(n=>n.neg(t),s,null,cc)}const Oe=L({neg_: $ k});function Wk(e){const t=g(e,"x","softplus"),s={x:t};return T.runKernelFunc((n,i)=>{const r=n.softplus(t);return i([t]),r},s,null,kc)}const Rn=L({softplus_:Wk});function zk(e){const t=g(e,"x","logSigmoid"),s=ms(n=>{const i=Oe(Rn(Oe(n))),r=o=>{const a=C(o,Ss(Oe(n)));return a};return{value:i,gradFunc:r}});return s(t)}const By=L({logSigmoid_:zk});function Bk(e,t=null,s=!1){const n=g(e,"x","max"),i=(a,l)=>{const c=Te(t,n.shape);let p=c;const u=ut(p,n.rank);let h=n;u!=null&&(h=se(n,u),p=Gt(p.length,h.rank));const d=a.max(h,p);u!=null&&h.dispose();let m=d;if(s){const f=ft(m.shape,Te(t,n.shape));m=O(m,f),d.dispose()}return l([n,m]),m},r={x:n},o={reductionIndices:t,keepDims:s};return T.runKernelFunc(i,r,null,hi,o)}const st=L({max_:Bk});function Pk(e,t){let s=g(e,"a","sub"),n=g(t,"b","sub");[s,n]=Ne(s,n);const i=(o,a)=>{const l=o.subtract(s,n);return a([s,n]),l},r={a:s,b:n};return T.runKernelFunc(i,r,null, $ c)}const X=L({sub_:Pk});function jk(e,t=null,s=!1){let n=g(e,"x","sum");n.dtype==="bool"&&(n=K(n,"int32"));const i=(a,l)=>{l([n]);const c=Te(t,n.shape),p=ut(c,n.rank);let u=c,h=n;p!=null&&(h=se(n,p),u=Gt(u.length,n.rank));let d=a.sum(h,u);if(s){const m=ft(d.shape,c);d=O(d,m)}return d},r={x:n},o={axis:t,keepDims:s};return T.runKernelFunc(i,r,null,Dc,o)}const te=L({sum_:jk});function Vk(e,t=-1){const s=g(e,"logits","logSoftmax");if(t===-1&&(t=s.rank-1),t!==s.rank-1)throw Error( ` Log Softmax along a non - last dimension is not yet supported . Logits was rank $ { s . rank } and axis was $ { t } ` );const n=(o,a)=>{const l=!0,c=st(e,t,!0),p=X(e,c),u=X(K(p,"float32"),Mt(te(At(p),t,l)));return a([u]),u},i={logits:s},r={axis:t};return T.runKernelFunc(n,i,null,ec,r)}const to=L({logSoftmax_:Vk});function Gk(e,t=null,s=!1){const n=g(e,"x","logSumExp"),i=Te(t,n.shape),r=st(n,i,!0),o=X(n,r),a=At(o),l=te(a,i),c=Mt(l),p=W(O(r,c.shape),c);if(s){const u=ft(p.shape,i);return O(p,u)}return p}const Ep=L({logSumExp_:Gk});function Hk(e,t){const s=g(e,"a","logicalAnd","bool"),n=g(t,"b","logicalAnd","bool");Se(s.shape,n.shape);const i={a:s,b:n};return T.runKernelFunc(r=>r.logicalAnd(s,n),i,null, $ g)}const zt=L({logicalAnd_:Hk});function qk(e){const t=g(e,"x","logicalNot","bool"),s={x:t};return T.runKernelFunc(n=>n.logicalNot(t),s,null,Wg)}const vi=L({logicalNot_:qk});function Yk(e,t){const s=g(e,"a","logicalOr","bool"),n=g(t,"b","logicalOr","bool");Se(s.shape,n.shape);const i={a:s,b:n};return T.runKernelFunc(r=>r.logicalOr(s,n),i,null,zg)}const so=L({logicalOr_:Yk});function Kk(e,t){const s=g(e,"a","logicalXor","bool"),n=g(t,"b","logicalXor","bool");return Se(s.shape,n.shape),zt(so(e,t),vi(zt(e,t)))}const Py=L({logicalXor_:Kk});function Xk(e,t,s,n,i){const r=g(e,"x","maxPool"),o=1;let a=r,l=!1;r.rank===3&&(l=!0,a=O(r,[1,r.shape[0],r.shape[1],r.shape[2]])),v(a.rank===4,()=> ` Error in maxPool : input must be rank 4 but got rank $ { a . rank } . ` ),v(et(s,o),()=> ` Error in maxPool : Either strides or dilations must be 1. Got strides $ { s } and dilations '${o}' ` ),i!=null&&v(De(n),()=> ` Error in maxPool : pad must be an integer when using , dimRoundingMode $ { i } but got pad $ { n } . ` );const c=(d,m)=>{const f=Tn(a.shape,t,s,1,n,i);let y;return f.filterWidth===1&&f.filterHeight===1&&It(f.inShape,f.outShape)?y=a.clone():y=d.maxPool(a,f),m([a,y]),y},p={x:a},u={filterSize:t,strides:s,pad:n,dimRoundingMode:i},h=T.runKernelFunc(c,p,null,nc,u);return l?O(h,[h.shape[1],h.shape[2],h.shape[3]]):h}const lt=L({maxPool_:Xk});function Jk(e,t=[1,1,1],s,n,i,r="NDHWC",o){o==null?o=[1,1,1]:xt("dilations is deprecated, this field will be gone in v3.0.0.");const a=g(e,"x","maxPool3d");let l=a,c=!1;a.rank===4&&(c=!0,l=O(a,[1,a.shape[0],a.shape[1],a.shape[2],a.shape[3]])),v(l.rank===5,()=> ` Error in maxPool3d : x must be rank 5 but got rank $ { l . rank } . ` ),v(r==="NDHWC",()=> ` Error in maxPool3d : Only NDHWC is currently supported , but got dataFormat of $ { r } ` ),v(et(s,o),()=> ` Error in maxPool3d : Either strides or dilations must be 1. Got stri
Actual : $ { i } .
Expected : $ { r } . ` );for(let o=0;o<r.length;++o){const a=i[o],l=r[o];if(!s(a,l))throw new Error( ` Arrays differ : actual [ $ { o } ] = $ { a } , expected [ $ { o } ] = $ { l } .
Actual : $ { i } .
Expected : $ { r } . ` )}}function A_(e,t){e().then(()=>t.fail(),()=>t())}function N_(e,t){const s=typeof t=="string"||typeof t=="number"||typeof t=="boolean"?[t]:t;return vn(e)||vn(e[0])||vn(t)||vn(t[0])?Qy(e,s,(n,i)=>n==i):Qy(e,t,(n,i)=>eb(n,i,0))}function C_(e,t,s){if(s==null&&(s=Zy()),!eb(e,t,s))throw new Error( ` Numbers differ : actual === $ { e } , expected === $ { t } ` )}function eb(e,t,s){return!isFinite(e)&&!isFinite(t)?!0:!(isNaN(e)||isNaN(t)||Math.abs(e-t)>s)}function R_(e,t,s){for(let n=0;n<e.length;n++)if(e[n]<t||e[n]>s)throw new Error( ` Value out of range : $ { e [ n ] } low : $ { t } , high : $ { s } ` )}function O_(e,t){expect(new Float32Array(e)).toEqual(new Float32Array(t))}const $ h=nl(il());class Dp{constructor(e,t,s,n,i){this.mean=e,this.stdDev=t,this.dtype=s,this.nextVal=NaN,this.truncated=n,this.truncated&&(this.upper=this.mean+this.stdDev*2,this.lower=this.mean-this.stdDev*2);const r=i||Math.random();this.random= $ h.alea(r.toString())}nextValue(){if(!isNaN(this.nextVal)){const n=this.nextVal;return this.nextVal=NaN,n}let e,t,s=!1;for(;!s;){let n,i,r;do n=2*this.random()-1,i=2*this.random()-1,r=n*n+i*i;while(r>=1||r===0);const o=Math.sqrt(-2*Math.log(r)/r);e=this.mean+this.stdDev*n*o,t=this.mean+this.stdDev*i*o,(!this.truncated||this.isValidTruncated(e))&&(s=!0)}return(!this.truncated||this.isValidTruncated(t))&&(this.nextVal=this.convertValue(t)),this.convertValue(e)}convertValue(e){return this.dtype==null||this.dtype==="float32"?e:Math.round(e)}isValidTruncated(e){return e<=this.upper&&e>=this.lower}}class LS{constructor(e,t,s,n){this.alpha=e,this.beta=1/t,this.dtype=s;const i=n||Math.random();this.randu= $ h.alea(i.toString()),this.randn=new Dp(0,1,s,!1,this.randu()),e<1?this.d=e+2/3:this.d=e-1/3,this.c=1/Math.sqrt(9*this.d)}nextValue(){let e,t,s,n,i,r;for(;;){do n=this.randn.nextValue(),r=1+this.c*n;while(r<=0);if(r*=r*r,e=n*n,t=1-.331*e*e,s=.5*e+this.d*(1-r+Math.log(r)),i=this.randu(),i<t||Math.log(i)<s)break}return r=1/this.beta*this.d*r,this.alpha<1&&(r*=Math.pow(this.randu(),1/this.alpha)),this.convertValue(r)}convertValue(e){return this.dtype==="float32"?e:Math.round(e)}}class SS{constructor(e=0,t=1,s,n){if(this.canReturnFloat=()=>this.dtype==null||this.dtype==="float32",this.min=e,this.range=t-e,this.dtype=s,n==null&&(n=Math.random()),typeof n=="number"&&(n=n.toString()),!this.canReturnFloat()&&this.range<=1)throw new Error( ` The difference between $ { e } - $ { t } <= 1 and dtype is not float ` );this.random= $ h.alea(n)}convertValue(e){return this.canReturnFloat()?e:Math.round(e)}nextValue(){return this.convertValue(this.min+this.range*this.random())}}function E_(e,t,s=1,n="float32",i){if(s==null&&(s=1),n==null&&(n="float32"),n!=="float32"&&n!=="int32")throw new Error( ` Unsupported data type $ { n } ` );const r=new LS(t,s,n,i),o=le(e,n);for(let a=0;a<o.values.length;a++)o.values[a]=r.nextValue();return o.toTensor()}const tb=L({randomGamma_:E_});function k_(e,t=0,s=1,n,i){if(n!=null&&n==="bool")throw new Error( ` Unsupported data type $ { n } ` );const r=new Dp(t,s,n,!1,i),o=le(e,n);for(let a=0;a<o.values.length;a++)o.values[a]=r.nextValue();return o.toTensor()}const ha=L({randomNormal_:k_});function __(e,t=0,s=1,n="float32",i){const r=le(e,n),o=new SS(t,s,null,i);for(let a=0;a<r.values.length;a++)r.values[a]=o.nextValue();return r.toTensor()}const Gs=L({randomUniform_:__});function Fe(e,t){zs(e);const s=Zt(e,t);if(s.length!==1)throw new Error("tensor1d() requires values to be a flat/TypedArray");const n=null;return ds(e,n,s,t)}function ei(e,t,s=1,n="float32"){if(s===0)throw new Error("Cannot have a step of zero");const i=()=>{const o=e===t,a=e<t&&s<0,l=t<e&&s>1;if(o||a||l)return Ie([0],n);const c=Math.abs(Math.ceil((t-e)/s)),p=Yn(c,n);t<e&&s===1&&(s=-1),p[0]=e;for(let u=1;u<p.length;u++)p[u]=p[u-1]+s;return Fe(p,n)},r={start:e,stop:t,step:s,dtype:n};return T.runKernelFunc(i,{},null,Hg,r)}function D_(e){const t=g(e,"x","reciprocal"),s={x:t};return T.runKernelFunc((n,i)=>{const r=n.reciprocal(t);return i([t]),r},s,null,gc)}const Fp=L({reciprocal_:D_});function F_(e){const t=g(e,"x","relu"),s=(i,r)=>(r([t]),t.dtype==="bool"?K(t,"int32"):i.relu(t)),n={x
Manifest JSON has weights with names : $ { a . join ( ", " ) } . ` )}const l=i.reduce((d,m,f)=>(m&&d.push(f),d),[]),c=[];l.forEach(d=>{t[d].paths.forEach(m=>{const f=s+(s.endsWith("/")?"":"/")+m;c.push(f)})});const p=await e(c),u={};let h=0;return l.forEach(d=>{const m=t[d].paths.length;let f=0;for(let I=0;I<m;I++)f+=p[h+I].byteLength;const y=new ArrayBuffer(f),b=new Uint8Array(y);let S=0;for(let I=0;I<m;I++){const A=new Uint8Array(p[h+I]);b.set(A,S),S+=A.byteLength}const x=r[d];x.forEach(I=>{const A=y.slice(I.groupOffset,I.groupOffset+I.sizeBytes),k=hb(A,[I.manifestEntry]);for(const R in k)u[R]=k[R]}),h+=m}),u}}const GF="application/octet-stream",HF="application/json";class gb{constructor(e,t){if(this.DEFAULT_METHOD="POST",t==null&&(t={}),this.weightPathPrefix=t.weightPathPrefix,this.onProgress=t.onProgress,t.fetchFunc!=null?(v(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= $ ().platform.fetch,v(e!=null&&e.length>0,()=>"URL path for http must not be null, undefined or empty."),Array.isArray(e)&&v(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.");const t=Object.assign({method:this.DEFAULT_METHOD},this.requestInit);t.body=new FormData();const s=[{paths:["./model.weights.bin"],weights:e.weightSpecs}],n={modelTopology:e.modelTopology,format:e.format,generatedBy:e.generatedBy,convertedBy:e.convertedBy,userDefinedMetadata:e.userDefinedMetadata,weightsManifest:s};t.body.append("model.json",new Blob([JSON.stringify(n)],{type:HF}),"model.json"),e.weightData!=null&&t.body.append("model.weights.bin",new Blob([e.weightData],{type:GF}),"model.weights.bin");const i=await this.fetch(this.path,t);if(i.ok)return{modelArtifactsInfo:Yp(e),responses:[i]};throw new Error( ` BrowserHTTPRequest . save ( ) failed due to HTTP response status $ { i . status } . ` )}async load(){const 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(p){let u= ` Failed to parse model JSON of response from $ { this . path } . ` ;throw this.path.endsWith(".pb")?u+=" 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.":u+=" Please make sure the server is serving valid JSON for this request.",new Error(u)}const s=t.modelTopology,n=t.weightsManifest,i=t.generatedBy,r=t.convertedBy,o=t.format,a=t.userDefinedMetadata;if(s==null&&n==null)throw new Error( ` The JSON from HTTP path $ { this . path } contains neither model topology or manifest for weights . ` );let l,c;if(n!=null){const p=await this.loadWeights(n);[l,c]=p}return{modelTopology:s,weightSpecs:l,weightData:c,userDefinedMetadata:a,generatedBy:i,convertedBy:r,format:o}}async loadWeights(e){const t=Array.isArray(this.path)?this.path[1]:this.path,[s,n]=qF(t),i=this.weightPathPrefix||s,r=[];for(const l of e)r.push(...l.weights);const o=[];e.forEach(l=>{l.paths.forEach(c=>{o.push(i+c+n)})});const a=await fb(o,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress});return[r,qp(a)]}}gb.URL_SCHEME_REGEX=/^https?: \/ \/ /;function qF(e){const t=e.lastIndexOf("/"),s=e.lastIndexOf("?"),n=e.substring(0,t),i=s>t?e.substring(s):"";return[n+"/",i]}function yb(e){return e.match(gb.URL_SCHEME_REGEX)!=null}const Ov=(e,t)=>{if(typeof fetch=="undefined"&&(t==null||t.fe
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 o}else{const r=e;if(r.className==null||r.config==null)throw new _( ` $ { n } : Improper config format : $ { JSON . stringify ( r ) } .
'className' and 'config' must set . ` );const o=r.className;let a,l;if(o in s?[a,l]=s[o]:o in un?[a,l]=un.className:o in t&&([a,l]=t[o]),a==null)throw new _( ` Unknown $ { n } : $ { o } . 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){const c={};for(const d of Object.keys(un))c[d]=un[d];for(const d of Object.keys(s))c[d]=s[d];const p=r.config;p.customObjects=c;const u=Object.assign({},un);for(const d of Object.keys(s))un[d]=s[d];Eb(r.config);const h=l(a,r.config,s,i);return un=Object.assign({},u),h}else{const c=Object.assign({},un);for(const u of Object.keys(s))un[u]=s[u];const p=new a(r.config);return un=Object.assign({},c),p}}}function zM(e,t){return e<t?-1:e>t?1:0}function Zp(e,t){return-1*zM(e,t)}function hn(e){if(e==null)return e;const t=[];for(const s of e)t.indexOf(s)===-1&&t.push(s);return t}function NI(e){if(e==null)throw new _( ` Invalid value in obj : $ { JSON . stringify ( e ) } ` );for(const t in e)if(e.hasOwnProperty(t))return!1;return!0}function _i(e,t,s){if(s==null)return;if(e.indexOf(s)<0)throw new _( ` $ { s } is not a valid $ { t } . Valid values are $ { e } or null / undefined . ` )}function sd(e,t,s=0,n=Infinity){return qs(s>=0),qs(n>=s),Array.isArray(e)&&e.length>=s&&e.length<=n&&e.every(i=>typeof i===t)}function jt(e,t){Array.isArray(e)?(E.assert(e.length>0,()=> ` $ { t } is unexpectedly an empty array . ` ),e.forEach((s,n)=>jt(s, ` element $ { n + 1 } of $ { t } ` ))):E.assert(Number.isInteger(e)&&e>0,()=> ` Expected $ { t } to be a positive integer , but got $ { CI ( e ) } . ` )}function CI(e){return e===null?"null":Array.isArray(e)?"["+e.map(t=>CI(t)).join(",")+"]":typeof e=="string"? ` "${e}" ` : ` $ { e } ` }function RI(e,t){let s=E.now(),n;const i=(...r)=>{const o=E.now();return o-s<t||(s=o,n=e(...r)),n};return i}function nd(e){return e==="relu"?"relu":e==="linear"?"linear":e==="elu"?"elu":null}function kb(e,t){return N(()=>He(te(C(e,e),t,!0)))}class Qp extends P.Serializable{getConfig(){return{}}}class id extends Qp{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 N(()=>{const t=kb(e,this.axis),s=Dt(t,0,this.maxValue);return C(e,J(s,W(vt(),t)))})}getConfig(){return{maxValue:this.maxValue,axis:this.axis}}}id.className="MaxNorm";P.registerClass(id);class rd extends Qp{constructor(e){super();this.defaultAxis=0,this.axis=e.axis!=null?e.axis:this.defaultAxis}apply(e){return N(()=>J(e,W(vt(),kb(e,this.axis))))}getConfig(){return{axis:this.axis}}}rd.className="UnitNorm";P.registerClass(rd);class od extends Qp{apply(e){return ke(e)}}od.className="NonNeg";P.registerClass(od);class ad extends Qp{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 N(()=>{const t=kb(e,this.axis),s=W(C(this.rate,Dt(t,this.minValue,this.maxValue)),C(1-this.rate,t));return C(e,J(s,W(vt(),t)))})}getConfig(){return{minValue:this.minValue,maxValue:this.maxValue,rate:this.rate,axis:this.axis}}}ad.className="MinMaxNorm";P.registerClass(ad);const OI={maxNorm:"MaxNorm",minMaxNorm:"MinMaxNorm",nonNeg:"NonNeg",unitNorm:"UnitNorm"};function Be(e){return La(e)}function EI(e,t={}){return si(e,P.SerializationMap.getMap().classNameMap,t,"constraint")}function it(e){if(e==null)return null;if(typeof e=="string"){const t=e in OI?OI[e]:e,s={className:t,config:{}};return EI(s)}else return e instanceof Qp?e:EI(e)}const _b={};Re(_b,{maxNorm:()=>BM,minMaxNorm:()=>VM,nonNeg:()=>jM,unitNorm:()=>PM});function BM(e){return new id(e)}function PM(e){return new rd(e)}function jM(){return new od()}function VM(e){return new ad(e)}const kI=["channelsFirst","channelsLast"],_I=["valid","same","causal"],DI=["max","avg"],FI=["sum","mul","concat","ave"];const Sa=new Map();function dt(e){_i(kI,"DataFormat",e)}function _s(e){_i(_I,"PaddingMode",e)}function Db(e){_i(DI,"PoolMode",e)}const eu=[],MI="/";function Dn(e,t){eu.push(e);try{const s=t();return eu.pop(),s}catch(s){throw eu.pop(),s}}function GM(){return eu.l
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),Ds(this.elementShape,t.shape, ` TensorArray $ { this . name } : Could not write to TensorArray index $ { e } . ` ),s.read)throw new Error( ` TensorArray $ { this . name } : Could not write to TensorArray index $ { e } , because it has already been read . ` );if(s.written)throw new Error( ` TensorArray $ { this . name } : Could not write to TensorArray index $ { e } , because it has already been written . ` );s.tensor=t,gt(t),s.written=!0,this.tensors[e]=s}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((s,n)=>this.write(s,t[n]))}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 n=0;n<this.size();n++)e.push(n)}if(e.length===0)return ze([],[0].concat(this.elementShape));const s=this.readMany(e);return Ds(this.elementShape,s[0].shape,"TensorArray shape mismatch: "),Xe(s,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 ze([],[0].concat(this.elementShape));const t=[];for(let n=0;n<this.size();n++)t.push(n);const s=this.readMany(t);return Ds(this.elementShape,s[0].shape, ` TensorArray shape mismatch : tensor array shape ( $ { this . elementShape } ) vs first tensor shape ( $ { s [ 0 ] . shape } ) ` ),ge(s,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 ] } ` );const s=Math.max(...e);if(!this.dynamicSize&&s>=this.maxSize)throw new Error( ` Max index must be < array size ( $ { s } vs . $ { this . maxSize } ) ` );this.writeMany(e,nt(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 s=0;const n=e.map(a=>(s+=a,s));if(s!==t.shape[0])throw new Error( ` Expected sum of lengths to be equal to
tensor . shape [ 0 ] , but sum of lengths is
$ { s } , 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 ` );const i=s===0?0:t.size/s,r=[];N(()=>{t=t.reshape([1,s,i]);for(let a=0;a<e.length;++a){const l=a===0?0:n[a-1],c=[0,l,0],p=[1,e[a],i];r[a]=he(t,c,p).reshape(this.elementShape)}return r});const o=[];for(let a=0;a<e.length;a++)o[a]=a;this.writeMany(o,r)}}class Ru{constructor(e,t,s,n=-1){this.tensors=e,this.elementShape=t,this.elementDtype=s,e!=null&&e.forEach(i=>{if(s!==i.dtype)throw new Error( ` Invalid data types ; op elements $ { s } , but list elements $ { i . dtype } ` );Ds(t,i.shape,"TensorList shape mismatch: "),gt(i)}),this.idTensor=j(0),this.maxNumElements=n,gt(this.idTensor)}get id(){return this.idTensor.id}copy(){return new Ru([...this.tensors],this.elementShape,this.elementDtype)}clearAndClose(){this.tensors.forEach(e=>e.dispose()),this.tensors.length=0,this.idTensor.dispose()}size(){return this.tensors.length}stack(e,t,s=-1){if(t!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { t } , but list elements $ { this . elementDtype } ` );if(s!==-1&&this.tensors.length!==s)throw new Error( ` Operation expected a list with $ { s } elements but got a list with $ { this . tensors . length } elements . ` );return Ds(e,this.elementShape,"TensorList shape mismatch: "),N(()=>{const n=this.tensors.map(i=>i.reshape(e));return Xe(n,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.");const s=this.tensors.pop();return Ds(s.shape,e,"TensorList shape mismatch: "),s.reshape(e)}pushBack(e){if(e.dtype!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { e . dtype } , but list elements $ { this . elementDtype } ` );if(Ds(e.shape,this.elementShape,"TensorList shape mismatch: "),this.maxNumElements===this.size())throw new Error("Trying to push element into a full list.");gt(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,s){if(s!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { s } , 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 . ` );return Ds(this.tensors[e].shape,t,"TensorList shape mismatch: "),this.tensors[e]}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 . ` );Ds(this.elementShape,t.shape,"TensorList shape mismatch: "),gt(t),this.tensors[e]=t}gather(e,t,s){if(t!==this.elementDtype)throw new Error( ` Invalid data types ; op elements $ { t } , but list elements $ { this . elementDtype } ` );return Ds(this.elementShape,s,"TensorList shape mismatch: "),e=e.slice(0,this.size()),e.length===0?ze([],[0].concat(this.elementShape)):N(()=>{const n=e.map(i=>this.tensors[i].reshape(s));return Xe(n,0)})}concat(e,t){if(!!e&&e!==this.elementDtype)throw new Error( ` TensorList dtype is $ { this . elementDtype } but concat requested dtype $ { e } ` );return Ds(this.elementShape,t,"TensorList shape mismatch: "),this.size()===0?ze([],[0].concat(this.elementShape)):N(()=>{const s=this.tensors.map(n=>n.reshape(t));return ge(s,0)})}}function hN(e,t,s){const n=e.dtype;if(e.shape.length<1)throw new Error( ` Tensor must be at least a vector , but saw shape : $ { e . shape } ` );if(e.dtype!==s)throw new Error( ` Invalid data types ; op elements $ { e . dtype } , but list elements $ { s } ` );const i=
tensor . shape [ 0 ] , but sum of lengths is
$ { n } , and tensor ' s shape is : $ { e . shape } ` );const r=n===0?0:e.size/n,o=N(()=>{const l=[];e=e.reshape([1,n,r]);for(let c=0;c<t.length;++c){const p=c===0?0:i[c-1],u=[0,p,0],h=[1,t[c],r];l[c]=he(e,u,h).reshape(s)}return e.dispose(),l}),a=new Ru([],s,e.dtype,t.length);for(let l=0;l<o.length;l++)a.setItem(l,o[l]);return a}const gN=async(e,t,s)=>{switch(e.op){case"If":case"StatelessIf":{const n=w("thenBranch",e,t,s),i=w("elseBranch",e,t,s),r=w("cond",e,t,s),o=w("args",e,t,s),a=await r.data();return a[0]?s.functionMap[n].executeFunctionAsync(o,s.tensorArrayMap,s.tensorListMap):s.functionMap[i].executeFunctionAsync(o,s.tensorArrayMap,s.tensorListMap)}case"While":case"StatelessWhile":{const n=w("body",e,t,s),i=w("cond",e,t,s),r=w("args",e,t,s),o=await s.functionMap[i].executeFunctionAsync(r,s.tensorArrayMap,s.tensorListMap),a=r.map(p=>p.id);let l=await o[0].data();o.forEach(p=>{!p.kept&&a.indexOf(p.id)===-1&&p.dispose()});let c=r;for(;l[0];){const p=c;c=await s.functionMap[n].executeFunctionAsync(c,s.tensorArrayMap,s.tensorListMap);const u=c.map(d=>d.id);p.forEach(d=>{!d.kept&&a.indexOf(d.id)===-1&&u.indexOf(d.id)===-1&&d.dispose()});const h=await s.functionMap[i].executeFunctionAsync(c,s.tensorArrayMap,s.tensorListMap);l=await h[0].data(),h.forEach(d=>{!d.kept&&a.indexOf(d.id)===-1&&u.indexOf(d.id)===-1&&d.dispose()})}return c}case"LoopCond":{const n=w("pred",e,t,s);return[Wn(n)]}case"Switch":{const n=w("pred",e,t,s);let i=w("data",e,t,s);return i.kept||(i=Wn(i)),(await n.data())[0]?[void 0,i]:[i,void 0]}case"Merge":{const n=e.inputNames.find(i=>Vt(i,t,s)!==void 0);if(n){const i=Vt(n,t,s);return[Wn(i)]}return}case"Enter":{const n=w("frameName",e,t,s),i=w("tensor",e,t,s);return s.enterFrame(n),[Wn(i)]}case"Exit":{const n=w("tensor",e,t,s);return s.exitFrame(),[Wn(n)]}case"NextIteration":{const n=w("tensor",e,t,s);return s.nextIteration(),[Wn(n)]}case"TensorArrayV3":{const n=w("size",e,t,s),i=w("dtype",e,t,s),r=w("elementShape",e,t,s),o=w("dynamicSize",e,t,s),a=w("clearAfterRead",e,t,s),l=w("identicalElementShapes",e,t,s),c=w("name",e,t,s),p=new uN(c,i,n,r,l,o,a);return s.addTensorArray(p),[p.idTensor,j(1)]}case"TensorArrayWriteV3":{const n=w("tensorArrayId",e,t,s),i=w("index",e,t,s),r=w("tensor",e,t,s),o=s.getTensorArray(n.id);return o.write(i,r),[o.idTensor]}case"TensorArrayReadV3":{const n=w("tensorArrayId",e,t,s),i=w("index",e,t,s),r=s.getTensorArray(n.id);return[r.read(i)]}case"TensorArrayGatherV3":{const n=w("tensorArrayId",e,t,s),i=w("indices",e,t,s),r=w("dtype",e,t,s),o=s.getTensorArray(n.id);return[o.gather(i,r)]}case"TensorArrayScatterV3":{const n=w("tensorArrayId",e,t,s),i=w("indices",e,t,s),r=w("tensor",e,t,s),o=s.getTensorArray(n.id);return o.scatter(i,r),[o.idTensor]}case"TensorArrayConcatV3":{const n=w("tensorArrayId",e,t,s),i=s.getTensorArray(n.id),r=w("dtype",e,t,s);return[i.concat(r)]}case"TensorArraySplitV3":{const n=w("tensorArrayId",e,t,s),i=w("tensor",e,t,s),r=w("lengths",e,t,s),o=s.getTensorArray(n.id);return o.split(r,i),[o.idTensor]}case"TensorArraySizeV3":{const n=w("tensorArrayId",e,t,s),i=s.getTensorArray(n.id);return[j(i.size(),"int32")]}case"TensorArrayCloseV3":{const n=w("tensorArrayId",e,t,s),i=s.getTensorArray(n.id);return i.clearAndClose(),[i.idTensor]}case"TensorListSetItem":{const n=w("tensorListId",e,t,s),i=w("index",e,t,s),r=w("tensor",e,t,s),o=s.getTensorList(n.id);return o.setItem(i,r),[o.idTensor]}case"TensorListGetItem":{const n=w("tensorListId",e,t,s),i=w("index",e,t,s),r=w("elementShape",e,t,s),o=w("elementDType",e,t,s),a=s.getTensorList(n.id);return[a.getItem(i,r,o)]}case"TensorListScatterV2":case"TensorListScatter":{const n=w("indices",e,t,s),i=w("tensor",e,t,s),r=w("elementShape",e,t,s),o=w("numElements",e,t,s),a=mN(i,n,r,o);return s.addTensorList(a),[a.idTensor]}case"TensorListReserve":{const n=w("elementShape",e,t,s),i=w("elementDType",e,t,s),r=w("numElements",e,t,s),o=dN(n,i,r);return s.addTensorList(o),[o.idTensor]}case"TensorListGather":{const n=w("tensorListId",e,t,s),i=w("indices",e,t,s),r=w("elementShape",e,t,s),o=w("elementDType",e,t,s),a=s.getTensorList(n.id);return[a
$ { e } ` );let n;return this.size===Infinity||this.size==null?n=this.size:t?n=Math.ceil(this.size/e):n=Math.floor(this.size/e),Ns(async()=>(await s.iterator()).columnMajorBatch(e,t,Sz),n)}concatenate(e){const t=this;let s;return this.size===Infinity||e.size===Infinity?s=Infinity:this.size!=null&&e.size!=null?s=this.size+e.size:s=null,Ns(async()=>(await t.iterator()).concatenate(await e.iterator()),s)}filter(e){const t=this;let s;return this.size===Infinity?s=Infinity:s=null,Ns(async()=>(await t.iterator()).filter(n=>N(()=>e(n))),s)}async forEachAsync(e){return(await this.iterator()).forEachAsync(e)}map(e){const t=this;return Ns(async()=>(await t.iterator()).map(s=>N(()=>e(s))),this.size)}mapAsync(e){const t=this;return Ns(async()=>(await t.iterator()).mapAsync(e),this.size)}prefetch(e){if(e==null)throw new RangeError(" ` Dataset . prefetch ( ) ` requires bufferSize to be specified.");const t=this;return Ns(async()=>(await t.iterator()).prefetch(e),this.size)}repeat(e){const t=this;let s;return this.size!=null&&e>0?s=this.size*e:e===0?s=0:this.size!=null&&(e===void 0||e<0)?s=Infinity:s=null,Ns(async()=>{const n=Ou(async()=>({value:await t.iterator(),done:!1}));return zN(n.take(e))},s)}skip(e){const t=this;let s;return this.size!=null&&e>=0&&this.size>=e?s=this.size-e:this.size!=null&&(this.size<e||e===void 0||e<0)?s=0:s=null,Ns(async()=>(await t.iterator()).skip(e),s)}shuffle(e,t,s=!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) ` ) ; const n = this , i = VN . alea ( t || E . now ( ) . toString ( ) ) ; return Ns ( async ( ) => { let r = i . int32 ( ) ; return s && ( r += i . int32 ( ) ) , ( await n . iterator ( ) ) . shuffle ( e , r . toString ( ) ) } , this . size ) } take ( e ) { const t = this ; let s ; return this . size != null && this . size > e ? s = e : this . size != null && this . size <= e ? s = this . size : s = null , Ns ( async ( ) => ( await t . iterator ( ) ) . take ( e ) , s ) } async toArray ( ) { if ( this . size === Infinity ) throw new Error ( "Can not convert infinite data stream to array." ) ; return ( await this . iterator ( ) ) . toArray ( ) } async toArrayForTest ( ) { if ( this . size === Infinity ) throw new Error ( "Can not convert infinite data stream to array." ) ; return ( await this . iterator ( ) ) . toArrayForTest ( ) } } Bi . MAX _BUFFER _SIZE = 1e4 ; function Ns ( e , t = null ) { return new class extends Bi { constructor ( ) { super ( ... arguments ) ; this . size = t } async iterator ( ) { return e ( ) } } ( ) } function GN ( e ) { return Ns ( async ( ) => Mw ( e ) , e . length ) } function HN ( e ) { if ( ! br ( e ) ) throw new Error ( "The argument to zip() must be an object or array." ) ; let t ; if ( Array . isArray ( e ) ) for ( let s = 0 ; s < e . length ; s ++ ) t = t == null ? e [ s ] . size : Math . min ( t , e [ s ] . size ) ; else if ( e instanceof Object ) for ( const s in e ) t = t == null ? e [ s ] . size : Math . min ( t , e [ s ] . size ) ; return Ns ( async ( ) => { const s = await ef ( e , n => { if ( n instanceof Bi ) return { value : n . iterator ( ) , recurse : ! 1 } ; if ( br ( n ) ) return { value : null , recurse : ! 0 } ; throw new Error ( "Leaves of the structure passed to zip() must be Datasets, not primitives." ) } ) ; return BN ( s , zi . SHORTEST ) } , t ) } function Sz ( e ) { if ( e === null ) return null ; const t = e [ 0 ] ; if ( MN ( t ) ) { const s = vz ( e ) ; return { value : s , recurse : ! 1 } } return { value : null , recurse : ! 0 } } function vz ( e ) { if ( e . length === 0 ) throw new Error ( "Can't make a batch of zero elements." ) ; return e [ 0 ] instanceof ue ? Xe ( e ) : ze ( e ) } class nf extends Bi { constructor ( e ) { super ( ) ; this . input = e } async iterator ( ) { const e = await this . input . iterator ( ) , t = e . decodeUTF8 ( ) , s = t . split ( `
` ).map(n=>(n.endsWith(" \r ")&&(n=n.slice(0,-1)),n));return s}}const rf='"',ku=Symbol("out"),qN=Symbol("field"),of=Symbol("quote"),Uw=Symbol("quoteafterquote"),YN=Symbol("quoteinquote");class af extends Bi{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 nf(e),t||(t={}),this.hasHeader=!(t.hasHeader===!1),this.fullColumnNames=t.columnNames,this.columnConfigs=t.columnConfigs,this.configuredColumnsOnly=t.configuredColumnsOnly,t.delimWhitespace?(E.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(){const 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&&E.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);const t=this.fullColumnNames.reduce((n,i)=>(n[i]=n[i]+1||1,n),{}),s=Object.keys(t).filter(n=>t[n]>1);if(E.assert(s.length===0,()=>"Duplicate column names found: "+s.toString()),this.columnConfigs)for(const n of Object.keys(this.columnConfigs)){const i=this.fullColumnNames.indexOf(n);if(i===-1)throw new Error('The key "'+n+'" provided in columnConfigs does not match any of the column names ('+this.fullColumnNames.toString()+").")}this.columnNamesValidated=!0}async maybeReadHeaderLine(){if(this.hasHeader){const e=await this.base.iterator(),t=await e.next();if(t.done)throw new Error("No data was found for CSV parsing.");const s=t.value,n=this.parseRow(s,!1);return n}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){const t=this.parseRow(e),s={},n={};for(let i=0;i<this.fullColumnNames.length;i++){const r=this.fullColumnNames[i],o=this.columnConfigs?this.columnConfigs[r]:null;if(this.configuredColumnsOnly&&!o)continue;{const a=t[i];let l=null;if(a==="")if(o&&o.default!==void 0)l=o.default;else{if(o&&(o.required||o.isLabel))throw new Error( ` Required column $ { r } is empty in this line : $ { e } ` );l=void 0}else{const c=Number(a);if(isNaN(c))o&&o.dtype==="bool"?l=this.getBoolean(a):l=a;else if(!o||!o.dtype)l=c;else switch(o.dtype){case"float32":l=c;break;case"int32":l=Math.floor(c);break;case"bool":l=this.getBoolean(a);break;default:l=c}}o&&o.isLabel?n[r]=l:s[r]=l}}return Object.keys(n).length===0?s:{xs:s,ys:n}}getBoolean(e){return e==="1"||e.toLowerCase()==="true"?1:0}parseRow(e,t=!0){const s=[];let n=0;const i=e.length;let r=ku;for(let o=0;o<i;o++)switch(r){case ku:switch(e.charAt(o)){case rf:n=o+1,r=of;break;case this.delimiter:if(n=o+1,this.delimiter===" "&&this.delimWhitespace)break;s.push(""),r=ku;break;default:r=qN,n=o;break}break;case qN:switch(e.charAt(o)){case this.delimiter:s.push(e.substring(n,o)),r=ku,n=o+1;break;default:}break;case of:switch(e.charAt(o)){case rf:r=Uw;break;default:}break;case Uw:switch(e.charAt(o)){case this.delimiter:s.push(e.substring(n,o-1)),r=ku,n=o+1;break;case rf:r=of;break;default:r=YN;break}break;case YN:switch(e.charAt(o)){case rf:r=of;break;default:}break;default:}if(r===Uw?s.push(e.substring(n,i-1)):s.push(e.substring(n)),t&&s.length!==this.fullColumnNames.length)throw new Error( ` Invalid row in csv file . Should have $ { this . fullColumnNames . length } elements in a row , but got $ { s } ` );return s}}class $ w extends Tt{constructor(e){super();this.microphoneConfig=e,this.isClosed=!1,this.fftSize=e.fftSize||1024;const t=Math.log2(this.fftSize);if
=== === === === === === === === === =
Hi there 👋 . 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.
=== === === === === === === === === = ` ));const n={};return this.data.set(n,{values:e,dtype:s}),n}move(e,t,s,n){this.data.set(e,{values:t,dtype:n})}numDataIds(){return this.data.numDataIds()}async read(e){return this.readSync(e)}readSync(e){const{dtype:t,complexTensors:s}=this.data.get(e);if(t==="complex64"){const n=this.readSync(s.real.dataId),i=this.readSync(s.imag.dataId);return U.mergeRealAndImagArrays(n,i)}return this.data.get(e).values}bufferSync(e){const t=this.readSync(e.dataId);let s=t;if(e.dtype==="string")try{s=t.map(n=>E.decodeString(n))}catch(n){throw new Error("Failed to decode encoded string bytes into utf-8")}return le(e.shape,e.dtype,s)}makeOutput(e,t,s){const n=this.write(e,t,s);return os().makeTensorFromDataId(n,t,s,this)}disposeData(e){if(this.data.has(e)){const{complexTensors:t}=this.data.get(e);t!=null&&(t.real.dispose(),t.imag.dispose()),this.data.delete(e)}}async time(e){const t=E.now();e();const s=E.now()-t;return{kernelMs:s}}memory(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}}complex(e,t){const s=this.makeOutput(null,e.shape,"complex64"),n=this.data.get(s.dataId);return n.complexTensors={real:os().keep(e.clone()),imag:os().keep(t.clone())},s}real(e){const t=this.data.get(e.dataId);return t.complexTensors.real.clone()}imag(e){const t=this.data.get(e.dataId);return t.complexTensors.imag.clone()}slice(e,t,s){H(e,"slice");const n=Jn.isSliceContinous(e.shape,t,s);if(n){const o=Jn.computeFlatOffset(t,e.strides),a=E.sizeFromShape(s),l=this.readSync(e.dataId);return ze(l.subarray(o,o+a),s,e.dtype)}const i=le(s,e.dtype),r=this.bufferSync(e);for(let o=0;o<i.size;++o){const a=i.indexToLoc(o),l=a.map((c,p)=>c+t[p]);i.values[o]=r.get(...l)}return i.toTensor()}stridedSlice(e,t,s,n){H(e,"stridedSlice");const i=Jn.computeOutShape(t,s,n);if(i.some(a=>a===0))return ze([],i);const r=le(i,e.dtype),o=this.bufferSync(e);for(let a=0;a<r.size;a++){const l=r.indexToLoc(a),c=new Array(l.length);for(let p=0;p<c.length;p++)c[p]=l[p]*n[p]+t[p];r.set(o.get(...c),...l)}return r.toTensor()}diag(e){const t=this.readSync(e.dataId),s=le([e.size,e.size],e.dtype),n=s.values;for(let i=0;i<t.length;i++)n[i*e.size+i]=t[i];return s.toTensor()}unstack(e,t){const s=e.shape[t],n=new Array(e.rank-1);let i=0;for(let l=0;l<e.rank;l++)l!==t&&(n[i++]=e.shape[l]);const r=new Array(e.rank).fill(0),o=e.shape.slice();o[t]=1;const a=new Array(s);for(let l=0;l<a.length;l++)r[t]=l,a[l]=this.slice(e,r,o).reshape(n);return a}reverse(e,t){H(e,"reverse");const s=le(e.shape,e.dtype),n=this.bufferSync(e);for(let i=0;i<s.size;i++){const r=s.indexToLoc(i),o=r.slice();t.forEach(a=>o[a]=e.shape[a]-1-o[a]),s.set(n.get(...o),...r)}return s.toTensor()}concat(e,t){if(e[0].dtype==="complex64"){const o=e.map(l=> $ t(l)),a=e.map(l=>Ht(l));return Ze(this.concat(o,t),this.concat(a,t))}const s=e.map(o=>{const a=E.sizeFromShape(o.shape.slice(t));return o.as2D(-1,a)}),n=U.computeOutShape(s.map(o=>o.shape),1),i=le(n,e[0].dtype).values;if(s[0].shape[0]===1){let o=0;s.forEach(a=>{i.set(this.readSync(a.dataId),o),o+=a.size})}else{let o=0;s.forEach(a=>{const l=this.readSync(a.dataId);let c=0;for(let p=0;p<a.shape[0];++p){const u=p*n[1]+o;for(let h=0;h<a.shape[1];++h)i[u+h]=l[c++]}o+=a.shape[1]})}const r=U.computeOutShape(e.map(o=>o.shape),t);return ze(i,r,e[0].dtype)}neg(e){return H(e,"neg"),this.multiply(j(-1),e)}add(e,t){return e.dtype==="complex64"||t.dtype==="complex64"?this.broadcastedBinaryComplexOp(e.cast("complex64"),t.cast("complex64"),(s,n,i,r)=>({real:s+i,imag:n+r})):this.broadcastedBinaryOp(e,t,wt(e.dtype,t.dtype),(s,n)=>s+n)}addN(e){H(e,"addN");const t=e.map(i=>this.readSync(i.dataId)),s=le(e[0].shape,e[0].dtype),n=s.values;for(let i=0;i<e.length;i++){const r=t[i];for(let o=0;o<n.length;o++)n[o]+=r[o]}return s.toTensor()}softmax(e,t){const s=E.parseAxisParam([t],e.shape),n=st(e,s),i=U.expandShapeToKeepDim(n.shape,s),r=this.subtract(e,n.reshape(i)),o=this.exp(r),a=this.sum(o,s).reshape(i);return J(o,a)}subtract(e,t){return e.dtype==="complex64"||t.dtype==="complex64"?this
` ),r=i.length.toString().length+2,o=i.map((u,h)=>E.rightPad((h+1).toString(),r)+u);let a=0;for(let u=0;u<o.length;u++)a=Math.max(o[u].length,a);const l=o.slice(0,n-1),c=o.slice(n-1,n),p=o.slice(n);console.log(l.join( `
` )),console.log(t.split( `
` )[0]),console.log( ` % c $ { E . rightPad ( c [ 0 ] , a ) } ` ,"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(p.join( `
` ))}function vC(e){return Pi(e,()=>e.createProgram(),"Unable to create WebGLProgram.")}function TC(e,t){if(oe(e,()=>e.linkProgram(t)),e.getProgramParameter(t,e.LINK_STATUS)===!1)throw console.log(e.getProgramInfoLog(t)),new Error("Failed to link vertex and fragment shaders.")}function bf(e,t){if(oe(e,()=>e.validateProgram(t)),e.getProgramParameter(t,e.VALIDATE_STATUS)===!1)throw console.log(e.getProgramInfoLog(t)),new Error("Shader program validation failed.")}function IC(e,t){const s=Pi(e,()=>e.createBuffer(),"Unable to create WebGLBuffer");return oe(e,()=>e.bindBuffer(e.ARRAY_BUFFER,s)),oe(e,()=>e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW)),s}function AC(e,t){const s=Pi(e,()=>e.createBuffer(),"Unable to create WebGLBuffer");return oe(e,()=>e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,s)),oe(e,()=>e.bufferData(e.ELEMENT_ARRAY_BUFFER,t,e.STATIC_DRAW)),s}function NC(e){return Pi(e,()=>e.createTexture(),"Unable to create WebGLTexture.")}function CC(e,t){const s= $ ().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(e<=0||t<=0){const n= ` [ $ { e } x$ { t } ] ` ;throw new Error("Requested texture size "+n+" is invalid.")}if(e>s||t>s){const n= ` [ $ { e } x$ { t } ] ` ,i= ` [ $ { s } x$ { s } ] ` ;throw new Error("Requested texture size "+n+" greater than WebGL maximum on this browser / GPU "+i+".")}}function RC(e){return Pi(e,()=>e.createFramebuffer(),"Unable to create WebGLFramebuffer.")}function Yw(e,t,s,n,i,r,o){const a=e.getAttribLocation(t,s);return a===-1?!1:(oe(e,()=>e.bindBuffer(e.ARRAY_BUFFER,n)),oe(e,()=>e.vertexAttribPointer(a,i,e.FLOAT,!1,r,o)),oe(e,()=>e.enableVertexAttribArray(a)),!0)}function qz(e,t,s){Hz(e,s),oe(e,()=>e.activeTexture(e.TEXTURE0+s)),oe(e,()=>e.bindTexture(e.TEXTURE_2D,t))}function OC(e,t,s){return Pi(e,()=>e.getUniformLocation(t,s),'uniform "'+s+'" not present in program.')}function EC(e,t,s){return e.getUniformLocation(t,s)}function kC(e,t,s,n){oe(e,()=>qz(e,t,n)),oe(e,()=>e.uniform1i(s,n))}function wf(e,t,s){oe(e,()=>e.bindFramebuffer(e.FRAMEBUFFER,s)),oe(e,()=>e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t,0))}function Kw(e,t){oe(e,()=>e.bindFramebuffer(e.FRAMEBUFFER,t)),oe(e,()=>e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,null,0))}function Mu(e){const t=e.checkFramebufferStatus(e.FRAMEBUFFER);if(t!==e.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+Yz(e,t))}function Yz(e,t){switch(t){case e.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case e.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case e.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case e.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return ` unknown error $ { t } ` }}function Pi(e,t,s){const n=oe(e,()=>t());if(n==null)throw new Error(s);return n}function Hz(e,t){const s=e.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,n=t+e.TEXTURE0;if(n<e.TEXTURE0||n>s){const i= ` [ gl . TEXTURE0 , gl . TEXTURE$ { s } ] ` ;throw new Error( ` textureUnit must be in $ { i } . ` )}}function Lr(e,t=2){return E.sizeFromShape(e.slice(0,e.length-t))}function Sr(e){if(e.length===0)throw Error("Cannot get rows and columns of an empty shape array.");return[e.length>1?e[e.length-2]:1,e[e.length-1]]}function xf(e){let t=[1,1,1];const s=e.length===0||e.length===1&&e[0]===1;return s||(t=[Lr(e),...Sr(e)]),t}function _C(e,t=!1){let s= $ ().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(t&&(s=s*2,e=e.map((i,r)=>r>=e.length-2?E.nearestLargerEven(e[r]):e[r]),e.length===1&&(e=[2,e[0]])),e.length!==2){const i=E.squeezeShape(e);e=i.newShape}let n=E.sizeFromShape(e);if(e.length<=1&&n<=s)return[1,n];if(e.length===2&&e[0]<=s&&e[1]<=s)return e;if(e.length===3&&e[0]*e[1]<=s&&e[2]<=s)return[e[0]*e[1],e[2]];if(e.length===3&&e[0]<=s&&e[1]*e[2]<=s)return[e[0],e[1]*e[2]];if(e.length===4&&e[0]*e[1]*e[2]<=s&&e[3]<=s)return[e[0]*e[1]*e[2],e[3]];if(e.length===4&&e[0]<=s&&e[1]*e[2]*e[3]<=s)return[e[0],e[1]*e[2]*e[3]];if(t){const i=Lr(e);let r=2,o=2;return e.length&&([r,o]=Sr(e)),n=i*(r/2)*(o/2),E.sizeToSquarishShape(n).map(a=>a*2)}return E.sizeToSquarishShape(n)}function Lf(e){return e%2===0}functio
void main ( ) {
$ { s . join ( `
` )}
float result = $ { n } ;
setOutput ( result ) ;
}
` }}class BC{constructor(e,t){this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.variableNames=t.map((i,r)=> ` T$ { r } ` );const s=[];this.variableNames.forEach(i=>{s.push( ` vec4 v$ { i } = get$ { i } AtOutCoords ( ) ; ` )});const n=this.variableNames.map(i=> ` v$ { i } ` ).join(" + ");this.userCode= `
void main ( ) {
$ { s . join ( `
` )}
vec4 result = $ { n } ;
setOutput ( result ) ;
}
` }}class PC{constructor(e,t,s){this.variableNames=["A"];const n=e.windowSize,i=e.batchSize,r=e.inSize,o=Math.ceil(r/n);s||this.variableNames.push("bestIndicesA"),this.outputShape=[i,o];const a=t==="max"?">":"<",l=s?"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 * $ { n } ;
int bestIndex = inOffset ;
float bestValue = getA ( batch , bestIndex ) ;
for ( int i = 0 ; i < $ { n } ; i ++ ) {
int inIdx = $ { l } ;
float candidate = getA ( batch , inIdx ) ;
if ( candidate $ { a } bestValue ) {
bestValue = candidate ;
bestIndex = inIdx ;
}
}
setOutput ( float ( bestIndex ) ) ;
}
` }}function ex(e,t){return["x","y","z","w","u","v"].slice(0,t).map(s=> ` $ { e } . $ { s } ` )}function Et(e,t){return t===1?[e]:ex(e,t)}function jC(e,t){if(e===1)return"rc";let s="";for(let n=0;n<e;n++)s+=t[n],n<e-1&&(s+=",");return s}function ot(){let e,t,s,n,i,r,o,a,l,c;return $ ().getNumber("WEBGL_VERSION")===2?(e="#version 300 es",t="in",s="out",n="in",i="texture",r="outputColor",o="out vec4 outputColor;",a= `
bool isnan _custom ( float val ) {
return ( val > 0.0 || val < 0.0 ) ? false : val != 0.0 ;
}
bvec4 isnan _custom ( vec4 val ) {
return bvec4 ( isnan _custom ( val . x ) ,
isnan _custom ( val . y ) , isnan _custom ( val . z ) , isnan _custom ( val . w ) ) ;
}
# define isnan ( value ) isnan _custom ( value )
` ,l="",c= `
# define round ( value ) newRound ( value )
int newRound ( float value ) {
return int ( floor ( value + 0.5 ) ) ;
}
ivec4 newRound ( vec4 value ) {
return ivec4 ( floor ( value + vec4 ( 0.5 ) ) ) ;
}
` ):(e="",t="attribute",s="varying",n="varying",i="texture2D",r="gl_FragColor",o="",a= `
# define isnan ( value ) isnan _custom ( value )
bool isnan _custom ( float val ) {
return ( val > 0. || val < 1. || val == 0. ) ? false : true ;
}
bvec4 isnan _custom ( vec4 val ) {
return bvec4 ( isnan ( val . x ) , isnan ( val . y ) , isnan ( val . z ) , isnan ( val . w ) ) ;
}
` ,l= `
uniform float INFINITY ;
bool isinf ( float val ) {
return abs ( val ) == INFINITY ;
}
bvec4 isinf ( vec4 val ) {
return equal ( abs ( val ) , vec4 ( INFINITY ) ) ;
}
` ,c= `
int round ( float value ) {
return int ( floor ( value + 0.5 ) ) ;
}
ivec4 round ( vec4 value ) {
return ivec4 ( floor ( value + vec4 ( 0.5 ) ) ) ;
}
` ),{version:e,attribute:t,varyingVs:s,varyingFs:n,texture2D:i,output:r,defineOutput:o,defineSpecialNaN:a,defineSpecialInf:l,defineRound:c}}function zn(e,t,s="index"){const n=E.computeStrides(t);return n.map((i,r)=>{const o= ` int $ { e [ r ] } = $ { s } / $ { i } ` ,a=r===n.length-1? ` int $ { e [ r + 1 ] } = $ { s } - $ { e [ r ] } * $ { i } ` : ` index -= $ { e [ r ] } * $ { i } ` ;return ` $ { o } ; $ { a } ; ` }).join("")}function Ua(e){const t=E.computeStrides(e).map(s=>s.toString());return `
int getFlatIndex ( ivec3 coords ) {
return coords . x * $ { t [ 0 ] } + coords . y * $ { t [ 1 ] } + coords . z ;
}
` }const Sf= `
const float FLOAT _MAX = 1.70141184 e38 ;
const float FLOAT _MIN = 1.17549435 e - 38 ;
lowp vec4 encode _float ( highp float v ) {
if ( isnan ( v ) ) {
return vec4 ( 255 , 255 , 255 , 255 ) ;
}
highp float av = abs ( v ) ;
if ( av < FLOAT _MIN ) {
return vec4 ( 0.0 , 0.0 , 0.0 , 0.0 ) ;
} else if ( v > FLOAT _MAX ) {
return vec4 ( 0.0 , 0.0 , 128.0 , 127.0 ) / 255.0 ;
} else if ( v < - FLOAT _MAX ) {
return vec4 ( 0.0 , 0.0 , 128.0 , 255.0 ) / 255.0 ;
}
highp vec4 c = vec4 ( 0 , 0 , 0 , 0 ) ;
highp float e = floor ( log2 ( av ) ) ;
highp float m = exp2 ( fract ( log2 ( av ) ) ) - 1.0 ;
c [ 2 ] = floor ( 128.0 * m ) ;
m -= c [ 2 ] / 128.0 ;
c [ 1 ] = floor ( 32768.0 * m ) ;
m -= c [ 1 ] / 32768.0 ;
c [ 0 ] = floor ( 8388608.0 * m ) ;
highp float ebias = e + 127.0 ;
c [ 3 ] = floor ( ebias / 2.0 ) ;
ebias -= c [ 3 ] * 2.0 ;
c [ 2 ] += floor ( ebias ) * 128.0 ;
c [ 3 ] += 128.0 * step ( 0.0 , - v ) ;
return c / 255.0 ;
}
` ;const{getBroadcastDims:VC}=U;function GC(e,t,s,n){const i=[];e.forEach(m=>{const f=E.sizeFromShape(m.shapeInfo.logicalShape);m.shapeInfo.isUniform?i.push( ` uniform float $ { m . name } $ { f > 1 ? ` [ ${ f } ] ` : "" } ; ` ):(i.push( ` uniform sampler2D $ { m . name } ; ` ),i.push( ` uniform int offset$ { m . name } ; ` ))});const r=i.join( `
` ),o=e.map(m=>Xz(m,t,n)).join( `
` ),a=t.texShape,l=ot(),c=Qz(l);let p,u,h=sB(l);t.isPacked?(p=Jz(t.logicalShape,a),u=tB(l)):(p=Zz(t.logicalShape,a),u=eB(l)),n&&(h+=nB);const d=[h,c,u,r,p,o,s].join( `
` );return d}function $ a(e){const t=e.shapeInfo.logicalShape;switch(t.length){case 0:return iB(e);case 1:return rB(e);case 2:return oB(e);case 3:return aB(e);case 4:return lB(e);case 5:return cB(e);case 6:return pB(e);default:throw new Error( ` $ { t . length } - D input sampling is not yet supported ` )}}function HC(e){const t=e.shapeInfo.logicalShape;switch(t.length){case 0:return uB(e);case 1:return hB(e);case 2:return dB(e);case 3:return mB(e);default:return fB(e)}}function Xz(e,t,s=!1){let n="";s?n+=HC(e):n+= $ a(e);const i=e.shapeInfo.logicalShape,r=t.logicalShape;return i.length<=r.length&&(s?n+=gB(e,t):n+=yB(e,t)),n}function Jz(e,t){switch(e.length){case 0:return qC();case 1:return bB(e,t);case 2:return LB(e,t);case 3:return wB(e,t);default:return xB(e,t)}}function Zz(e,t){switch(e.length){case 0:return qC();case 1:return SB(e,t);case 2:return NB(e,t);case 3:return vB(e,t);case 4:return TB(e,t);case 5:return IB(e,t);case 6:return AB(e,t);default:throw new Error( ` $ { e . length } - D output sampling is not yet supported ` )}}function Qz(e){return `
float sampleTexture ( sampler2D textureSampler , vec2 uv ) {
return $ { e . texture2D } ( textureSampler , uv ) . r ;
}
` }function eB(e){return `
void setOutput ( float val ) {
$ { e . output } = vec4 ( val , 0 , 0 , 0 ) ;
}
` }function tB(e){return `
void setOutput ( vec4 val ) {
$ { e . output } = val ;
}
` }function sB(e){const t= ` $ { e . version }
precision highp float ;
precision highp int ;
precision highp sampler2D ;
$ { e . varyingFs } vec2 resultUV ;
$ { e . defineOutput }
const vec2 halfCR = vec2 ( 0.5 , 0.5 ) ;
struct ivec5
{
int x ;
int y ;
int z ;
int w ;
int u ;
} ;
struct ivec6
{
int x ;
int y ;
int z ;
int w ;
int u ;
int v ;
} ;
uniform float NAN ;
$ { e . defineSpecialNaN }
$ { e . defineSpecialInf }
$ { e . 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 ;
}
return res ;
}
//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 ) ;
}
$ { CB }
$ { RB }
$ { OB }
` ;return t}const CB= `
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 ) ;
}
` ,RB= `
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 ) ;
}
` ,OB= `
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 ) ;
}
` ,nB= `
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 qC(){return `
int getOutputCoords ( ) {
return 0 ;
}
` }function bB(e,t){const s=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)];return s[0]===1? `
int getOutputCoords ( ) {
return 2 * int ( resultUV . x * $ { s [ 1 ] } . 0 ) ;
}
` :s[1]===1? `
int getOutputCoords ( ) {
return 2 * int ( resultUV . y * $ { s [ 0 ] } . 0 ) ;
}
` : `
int getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { s [ 0 ] } , $ { s [ 1 ] } ) ) ;
return 2 * ( resTexRC . x * $ { s [ 1 ] } + resTexRC . y ) ;
}
` }function SB(e,t){return t[0]===1? `
int getOutputCoords ( ) {
return int ( resultUV . x * $ { t [ 1 ] } . 0 ) ;
}
` :t[1]===1? `
int getOutputCoords ( ) {
return int ( resultUV . y * $ { t [ 0 ] } . 0 ) ;
}
` : `
int getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { t [ 0 ] } , $ { t [ 1 ] } ) ) ;
return resTexRC . x * $ { t [ 1 ] } + resTexRC . y ;
}
` }function wB(e,t){const s=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)],n=Math.ceil(e[2]/2),i=n*Math.ceil(e[1]/2);return `
ivec3 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { s [ 0 ] } , $ { s [ 1 ] } ) ) ;
int index = resTexRC . x * $ { s [ 1 ] } + resTexRC . y ;
int b = index / $ { i } ;
index -= b * $ { i } ;
int r = 2 * ( index / $ { n } ) ;
int c = imod ( index , $ { n } ) * 2 ;
return ivec3 ( b , r , c ) ;
}
` }function vB(e,t){const s=zn(["r","c","d"],e);return `
ivec3 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { t [ 0 ] } , $ { t [ 1 ] } ) ) ;
int index = resTexRC . x * $ { t [ 1 ] } + resTexRC . y ;
$ { s }
return ivec3 ( r , c , d ) ;
}
` }function xB(e,t){const s=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)],n=Math.ceil(e[e.length-1]/2),i=n*Math.ceil(e[e.length-2]/2);let r=i,o="",a="b, r, c";for(let l=2;l<e.length-1;l++)r*=e[e.length-l-1],o= `
int b$ { l } = index / $ { r } ;
index -= b$ { l } * $ { r } ;
` +o,a= ` b$ { l } , ` +a;return `
ivec$ { e . length } getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { s [ 0 ] } , $ { s [ 1 ] } ) ) ;
int index = resTexRC . x * $ { s [ 1 ] } + resTexRC . y ;
$ { o }
int b = index / $ { i } ;
index -= b * $ { i } ;
int r = 2 * ( index / $ { n } ) ;
int c = imod ( index , $ { n } ) * 2 ;
return ivec$ { e . length } ( $ { a } ) ;
}
` }function TB(e,t){const s=zn(["r","c","d","d2"],e);return `
ivec4 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { t [ 0 ] } , $ { t [ 1 ] } ) ) ;
int index = resTexRC . x * $ { t [ 1 ] } + resTexRC . y ;
$ { s }
return ivec4 ( r , c , d , d2 ) ;
}
` }function IB(e,t){const s=zn(["r","c","d","d2","d3"],e);return `
ivec5 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx * vec2 ( $ { t [ 0 ] } ,
$ { t [ 1 ] } ) ) ;
int index = resTexRC . x * $ { t [ 1 ] } + resTexRC . y ;
$ { s }
ivec5 outShape = ivec5 ( r , c , d , d2 , d3 ) ;
return outShape ;
}
` }function AB(e,t){const s=zn(["r","c","d","d2","d3","d4"],e);return `
ivec6 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { t [ 0 ] } , $ { t [ 1 ] } ) ) ;
int index = resTexRC . x * $ { t [ 1 ] } + resTexRC . y ;
$ { s }
ivec6 result = ivec6 ( r , c , d , d2 , d3 , d4 ) ;
return result ;
}
` }function LB(e,t){const s=[Math.ceil(t[0]/2),Math.ceil(t[1]/2)];if(E.arraysEqual(e,t))return `
ivec2 getOutputCoords ( ) {
return 2 * ivec2 ( resultUV . yx * vec2 ( $ { s [ 0 ] } , $ { s [ 1 ] } ) ) ;
}
` ;const n=Math.ceil(e[1]/2);return `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { s [ 0 ] } , $ { s [ 1 ] } ) ) ;
int index = resTexRC . x * $ { s [ 1 ] } + resTexRC . y ;
int r = 2 * ( index / $ { n } ) ;
int c = imod ( index , $ { n } ) * 2 ;
return ivec2 ( r , c ) ;
}
` }function NB(e,t){return E.arraysEqual(e,t)? `
ivec2 getOutputCoords ( ) {
return ivec2 ( resultUV . yx * vec2 ( $ { t [ 0 ] } , $ { t [ 1 ] } ) ) ;
}
` :e[1]===1? `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { t [ 0 ] } , $ { t [ 1 ] } ) ) ;
int index = resTexRC . x * $ { t [ 1 ] } + resTexRC . y ;
return ivec2 ( index , 0 ) ;
}
` :e[0]===1? `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { t [ 0 ] } , $ { t [ 1 ] } ) ) ;
int index = resTexRC . x * $ { t [ 1 ] } + resTexRC . y ;
return ivec2 ( 0 , index ) ;
}
` : `
ivec2 getOutputCoords ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { t [ 0 ] } , $ { t [ 1 ] } ) ) ;
int index = resTexRC . x * $ { t [ 1 ] } + resTexRC . y ;
int r = index / $ { e [ 1 ] } ;
int c = index - r * $ { e [ 1 ] } ;
return ivec2 ( r , c ) ;
}
` }function Do(e){return ` offset$ { e } ` }function uB(e){const t=e.name,s="get"+t.charAt(0).toUpperCase()+t.slice(1),n=ot();return `
vec4 $ { s } ( ) {
return $ { n . texture2D } ( $ { t } , halfCR ) ;
}
` }function iB(e){const t=e.name,s="get"+t.charAt(0).toUpperCase()+t.slice(1);if(e.shapeInfo.isUniform)return ` float $ { s } ( ) { return $ { t } ; } ` ;const[n,i]=e.shapeInfo.texShape;if(n===1&&i===1)return `
float $ { s } ( ) {
return sampleTexture ( $ { t } , halfCR ) ;
}
` ;const[r,o]=e.shapeInfo.texShape,a=Do(t);return `
float $ { s } ( ) {
vec2 uv = uvFromFlat ( $ { r } , $ { o } , $ { a } ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` }function hB(e){const t=e.name,s="get"+t.charAt(0).toUpperCase()+t.slice(1),n=e.shapeInfo.texShape,i=[Math.ceil(n[0]/2),Math.ceil(n[1]/2)],r=ot();return `
vec4 $ { s } ( int index ) {
vec2 uv = packedUVfrom1D (
$ { i [ 0 ] } , $ { i [ 1 ] } , index ) ;
return $ { r . texture2D } ( $ { t } , uv ) ;
}
` }function rB(e){const t=e.name,s="get"+t.charAt(0).toUpperCase()+t.slice(1);if(e.shapeInfo.isUniform)return `
float $ { s } ( int index ) {
$ { Wa ( e ) }
}
` ;const n=e.shapeInfo.texShape,i=n[0],r=n[1];if(r===1&&i===1)return `
float $ { s } ( int index ) {
return sampleTexture ( $ { t } , halfCR ) ;
}
` ;const o=Do(t);return r===1? `
float $ { s } ( int index ) {
vec2 uv = vec2 ( 0.5 , ( float ( index + $ { o } ) + 0.5 ) / $ { i } . 0 ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` :i===1? `
float $ { s } ( int index ) {
vec2 uv = vec2 ( ( float ( index + $ { o } ) + 0.5 ) / $ { r } . 0 , 0.5 ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` : `
float $ { s } ( int index ) {
vec2 uv = uvFromFlat ( $ { i } , $ { r } , index + $ { o } ) ;
return sampleTexture ( $ { t } , uv ) ;
}
` }function dB(e){const t=e.shapeInfo.logicalShape,s=e.name,n="get"+s.charAt(0).toUpperCase()+s.slice(1),i=e.shapeInfo.texShape,r=i[0],o=i[1],a=ot();if(i!=null&&E.arraysEqual(t,i))return `
vec4 $ { n } ( int row , int col ) {
vec2 uv = ( vec2 ( col , row ) + halfCR ) / vec2 ( $ { o } . 0 , $ { r } . 0 ) ;
return $ { a . texture2D } ( $ { s } , uv ) ;
}
` ;const l=[Math.ceil(i[0]/2),Math.ceil(i[1]/2)],c=Math.ceil(t[1]/2);return `
vec4 $ { n } ( int row , int col ) {
vec2 uv = packedUVfrom2D ( $ { c } , $ { l [ 0 ] } , $ { l [ 1 ] } , row , col ) ;
return $ { a . texture2D } ( $ { s } , uv ) ;
}
` }function oB(e){const t=e.shapeInfo.logicalShape,s=e.name,n="get"+s.charAt(0).toUpperCase()+s.slice(1),i=e.shapeInfo.texShape;if(i!=null&&E.arraysEqual(t,i)){const u=i[0],h=i[1];return `
float $ { n } ( int row , int col ) {
vec2 uv = ( vec2 ( col , row ) + halfCR ) / vec2 ( $ { h } . 0 , $ { u } . 0 ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` }const{newShape:r,keptDims:o}=E.squeezeShape(t),a=r;if(a.length<t.length){const u=za(e,a),h=["row","col"];return `
$ { $a ( u ) }
float $ { n } ( int row , int col ) {
return $ { n } ( $ { Ba ( h , o ) } ) ;
}
` }if(e.shapeInfo.isUniform)return `
float $ { n } ( int row , int col ) {
int index = round ( dot ( vec2 ( row , col ) , vec2 ( $ { t [ 1 ] } , 1 ) ) ) ;
$ { Wa ( e ) }
}
` ;const l=i[0],c=i[1],p=Do(s);return c===1? `
float $ { n } ( int row , int col ) {
float index = dot ( vec3 ( row , col , $ { p } ) , vec3 ( $ { t [ 1 ] } , 1 , 1 ) ) ;
vec2 uv = vec2 ( 0.5 , ( index + 0.5 ) / $ { l } . 0 ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` :l===1? `
float $ { n } ( 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 ( $ { s } , uv ) ;
}
` : `
float $ { n } ( int row , int col ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * $ { t [ 1 ] } + col + $ { p } ;
vec2 uv = uvFromFlat ( $ { l } , $ { c } , index ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` }function mB(e){const t=e.shapeInfo.logicalShape,s=e.name,n="get"+s.charAt(0).toUpperCase()+s.slice(1),i=e.shapeInfo.texShape,r=[Math.ceil(i[0]/2),Math.ceil(i[1]/2)];if(t[0]===1){const u=t.slice(1),h=[1,2],d=za(e,u),m=["b","row","col"];return `
$ { HC ( d ) }
vec4 $ { n } ( int b , int row , int col ) {
return $ { n } ( $ { Ba ( m , h ) } ) ;
}
` }const o=r[0],a=r[1],l=Math.ceil(t[2]/2),c=l*Math.ceil(t[1]/2),p=ot();return `
vec4 $ { n } ( int b , int row , int col ) {
vec2 uv = packedUVfrom3D (
$ { o } , $ { a } , $ { c } , $ { l } , b , row , col ) ;
return $ { p . texture2D } ( $ { s } , uv ) ;
}
` }function aB(e){const t=e.shapeInfo.logicalShape,s=e.name,n="get"+s.charAt(0).toUpperCase()+s.slice(1),i=t[1]*t[2],r=t[2],{newShape:o,keptDims:a}=E.squeezeShape(t),l=o;if(l.length<t.length){const m=za(e,l),f=["row","col","depth"];return `
$ { $a ( m ) }
float $ { n } ( int row , int col , int depth ) {
return $ { n } ( $ { Ba ( f , a ) } ) ;
}
` }if(e.shapeInfo.isUniform)return `
float $ { n } ( int row , int col , int depth ) {
int index = round ( dot ( vec3 ( row , col , depth ) ,
vec3 ( $ { i } , $ { r } , 1 ) ) ) ;
$ { Wa ( e ) }
}
` ;const c=e.shapeInfo.texShape,p=c[0],u=c[1],h=e.shapeInfo.flatOffset;if(u===i&&h==null)return `
float $ { n } ( int row , int col , int depth ) {
float texR = float ( row ) ;
float texC = dot ( vec2 ( col , depth ) , vec2 ( $ { r } , 1 ) ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { u } . 0 , $ { p } . 0 ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` ;if(u===r&&h==null)return `
float $ { n } ( 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 ( $ { u } . 0 , $ { p } . 0 ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` ;const d=Do(s);return `
float $ { n } ( int row , int col , int depth ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * $ { i } + col * $ { r } + depth + $ { d } ;
vec2 uv = uvFromFlat ( $ { p } , $ { u } , index ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` }function fB(e){const t=e.shapeInfo.logicalShape,s=t.length,n=e.name,i="get"+n.charAt(0).toUpperCase()+n.slice(1),r=e.shapeInfo.texShape,o=[Math.ceil(r[0]/2),Math.ceil(r[1]/2)],a=o[0],l=o[1],c=Math.ceil(t[s-1]/2);let p=c*Math.ceil(t[s-2]/2),u="int b, int row, int col",h= ` b * $ { p } + ( row / 2 ) * $ { c } + ( col / 2 ) ` ;for(let m=2;m<s-1;m++)u= ` int b$ { m } , ` +u,p*=t[s-m-1],h= ` b$ { m } * $ { p } + ` +h;const d=ot();return `
vec4 $ { i } ( $ { u } ) {
int index = $ { h } ;
int texR = index / $ { l } ;
int texC = index - texR * $ { l } ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) / vec2 ( $ { l } , $ { a } ) ;
return $ { d . texture2D } ( $ { n } , uv ) ;
}
` }function lB(e){const t=e.shapeInfo.logicalShape,s=e.name,n="get"+s.charAt(0).toUpperCase()+s.slice(1),i=t[3],r=t[2]*i,o=t[1]*r,{newShape:a,keptDims:l}=E.squeezeShape(t);if(a.length<t.length){const m=za(e,a),f=["row","col","depth","depth2"];return `
$ { $a ( m ) }
float $ { n } ( int row , int col , int depth , int depth2 ) {
return $ { n } ( $ { Ba ( f , l ) } ) ;
}
` }if(e.shapeInfo.isUniform)return `
float $ { n } ( int row , int col , int depth , int depth2 ) {
int index = round ( dot ( vec4 ( row , col , depth , depth2 ) ,
vec4 ( $ { o } , $ { r } , $ { i } , 1 ) ) ) ;
$ { Wa ( e ) }
}
` ;const c=e.shapeInfo.flatOffset,p=e.shapeInfo.texShape,u=p[0],h=p[1];if(h===o&&c==null)return `
float $ { n } ( int row , int col , int depth , int depth2 ) {
float texR = float ( row ) ;
float texC =
dot ( vec3 ( col , depth , depth2 ) ,
vec3 ( $ { r } , $ { i } , 1 ) ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { h } . 0 , $ { u } . 0 ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` ;if(h===i&&c==null)return `
float $ { n } ( 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 ( $ { h } . 0 , $ { u } . 0 ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` ;const d=Do(s);return `
float $ { n } ( int row , int col , int depth , int depth2 ) {
// Explicitly use integer operations as dot() only works on floats.
int index = row * $ { o } + col * $ { r } +
depth * $ { i } + depth2 ;
vec2 uv = uvFromFlat ( $ { u } , $ { h } , index + $ { d } ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` }function cB(e){const t=e.shapeInfo.logicalShape,s=e.name,n="get"+s.charAt(0).toUpperCase()+s.slice(1),i=t[4],r=t[3]*i,o=t[2]*r,a=t[1]*o,{newShape:l,keptDims:c}=E.squeezeShape(t);if(l.length<t.length){const f=za(e,l),y=["row","col","depth","depth2","depth3"];return `
$ { $a ( f ) }
float $ { n } ( int row , int col , int depth , int depth2 , int depth3 ) {
return $ { n } ( $ { Ba ( y , c ) } ) ;
}
` }if(e.shapeInfo.isUniform)return `
float $ { n } ( int row , int col , int depth , int depth2 , int depth3 ) {
float index = dot (
vec4 ( row , col , depth , depth2 ) ,
vec4 ( $ { a } , $ { o } , $ { r } , $ { i } ) ) +
depth3 ;
$ { Wa ( e ) }
}
` ;const p=e.shapeInfo.flatOffset,u=e.shapeInfo.texShape,h=u[0],d=u[1];if(d===a&&p==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 ( $ { o } , $ { r } , $ { i } , 1 ) ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { d } . 0 , $ { h } . 0 ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` ;if(d===i&&p==null)return `
float $ { n } ( int row , int col , int depth , int depth2 , int depth3 ) {
float texR = dot (
vec4 ( row , col , depth , depth2 ) ,
vec4 ( $ { t [ 1 ] * t [ 2 ] * t [ 3 ] } ,
$ { t [ 2 ] * t [ 3 ] } , $ { t [ 3 ] } , 1 ) ) ;
int texC = depth3 ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { d } . 0 , $ { h } . 0 ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` ;const m=Do(s);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 * $ { a } + col * $ { o } + depth * $ { r } +
depth2 * $ { i } + depth3 + $ { m } ;
vec2 uv = uvFromFlat ( $ { h } , $ { d } , index ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` }function pB(e){const t=e.shapeInfo.logicalShape,s=e.name,n="get"+s.charAt(0).toUpperCase()+s.slice(1),{newShape:i,keptDims:r}=E.squeezeShape(t);if(i.length<t.length){const y=za(e,i),b=["row","col","depth","depth2","depth3","depth4"];return `
$ { $a ( y ) }
float $ { n } ( int row , int col , int depth ,
int depth2 , int depth3 , int depth4 ) {
return $ { n } ( $ { Ba ( b , r ) } ) ;
}
` }const o=t[5],a=t[4]*o,l=t[3]*a,c=t[2]*l,p=t[1]*c;if(e.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 ( $ { p } , $ { c } , $ { l } , $ { a } ) ) +
dot (
vec2 ( depth3 , depth4 ) ,
vec2 ( $ { o } , 1 ) ) ) ;
$ { Wa ( e ) }
}
` ;const u=e.shapeInfo.flatOffset,h=e.shapeInfo.texShape,d=h[0],m=h[1];if(m===p&&u==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 ( $ { c } , $ { l } , $ { a } , $ { o } ) ) +
float ( depth4 ) ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { m } . 0 , $ { d } . 0 ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` ;if(m===o&&u==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 ( $ { t [ 1 ] * t [ 2 ] * t [ 3 ] * t [ 4 ] } ,
$ { t [ 2 ] * t [ 3 ] * t [ 4 ] } ,
$ { t [ 3 ] * t [ 4 ] } ,
$ { t [ 4 ] } ) ) + float ( depth3 ) ;
int texC = depth4 ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { m } . 0 , $ { d } . 0 ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` ;const f=Do(s);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 * $ { p } + col * $ { c } + depth * $ { l } +
depth2 * $ { a } + depth3 * $ { o } + depth4 + $ { f } ;
vec2 uv = uvFromFlat ( $ { d } , $ { m } , index ) ;
return sampleTexture ( $ { s } , uv ) ;
}
` }function Wa(e){const t=e.name,s=E.sizeFromShape(e.shapeInfo.logicalShape);return s<2? ` return $ { t } ; ` : `
for ( int i = 0 ; i < $ { s } ; i ++ ) {
if ( i == index ) {
return $ { t } [ i ] ;
}
}
` }function gB(e,t){const s=e.name,n=s.charAt(0).toUpperCase()+s.slice(1),i="get"+n+"AtOutCoords",r=e.shapeInfo.logicalShape.length,o=t.logicalShape.length,a=VC(e.shapeInfo.logicalShape,t.logicalShape),l=Ce(o),c=o-r;let p;const u=["x","y","z","w","u","v"];r===0?p="":o<2&&a.length>=1?p="coords = 0;":p=a.map(S=> ` coords . $ { u [ S + c ] } = 0 ; ` ).join( `
` );let h="";o<2&&r>0?h="coords":h=e.shapeInfo.logicalShape.map((S,x)=> ` coords . $ { u [ x + c ] } ` ).join(", ");let d="return outputValue;";const m=E.sizeFromShape(e.shapeInfo.logicalShape),f=m===1,y=E.sizeFromShape(t.logicalShape),b=y===1;if(r===1&&!f&&!b)d= `
return vec4 ( outputValue . xy , outputValue . xy ) ;
` ;else if(f&&!b)o===1?d= `
return vec4 ( outputValue . x , outputValue . x , 0. , 0. ) ;
` :d= `
return vec4 ( outputValue . x ) ;
` ;else if(a.length){const S=r-2,x=r-1;a.indexOf(S)>-1&&a.indexOf(x)>-1?d="return vec4(outputValue.x);":a.indexOf(S)>-1?d="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":a.indexOf(x)>-1&&(d="return vec4(outputValue.xx, outputValue.zz);")}return `
vec4 $ { i } ( ) {
$ { l } coords = getOutputCoords ( ) ;
$ { p }
vec4 outputValue = get$ { n } ( $ { h } ) ;
$ { d }
}
` }function yB(e,t){const s=e.name,n=s.charAt(0).toUpperCase()+s.slice(1),i="get"+n+"AtOutCoords",r=t.texShape,o=e.shapeInfo.texShape,a=e.shapeInfo.logicalShape.length,l=t.logicalShape.length;if(!e.shapeInfo.isUniform&&a===l&&e.shapeInfo.flatOffset==null&&E.arraysEqual(o,r))return `
float $ { i } ( ) {
return sampleTexture ( $ { s } , resultUV ) ;
}
` ;const c=Ce(l),p=VC(e.shapeInfo.logicalShape,t.logicalShape),u=l-a;let h;const d=["x","y","z","w","u","v"];a===0?h="":l<2&&p.length>=1?h="coords = 0;":h=p.map(f=> ` coords . $ { d [ f + u ] } = 0 ; ` ).join( `
` );let m="";return l<2&&a>0?m="coords":m=e.shapeInfo.logicalShape.map((f,y)=> ` coords . $ { d [ y + u ] } ` ).join(", "), `
float $ { i } ( ) {
$ { c } coords = getOutputCoords ( ) ;
$ { h }
return get$ { n } ( $ { m } ) ;
}
` }function Ce(e){if(e<=1)return"int";if(e===2)return"ivec2";if(e===3)return"ivec3";if(e===4)return"ivec4";if(e===5)return"ivec5";if(e===6)return"ivec6";throw Error( ` GPU for rank $ { e } is not yet supported ` )}function za(e,t){const s=JSON.parse(JSON.stringify(e));return s.shapeInfo.logicalShape=t,s}function Ba(e,t){return t.map(s=>e[s]).join(", ")}class YC{constructor(e,t,s,n){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,E.assert(e.length>2,()=> ` Packed arg$ { s . charAt ( 0 ) . toUpperCase ( ) + s . slice ( 1 ) } supports only inputs with rank above 2. ` );const i=e[e.length-1],r=Math.ceil(i/t);this.outputShape=e.slice(0,-1),r>1&&this.outputShape.push(r),n||this.variableNames.push("bestIndicesA");const o=this.outputShape,a=o.length,l=Ce(a),c=Et("coords",a);let p,u;if(r===1){u=a+1;const R=Ce(u);p= `
$ { R } sourceLocR = $ { R } ( $ { c . join ( ) } , 0 ) ;
++ $ { c [ a - 1 ] } ;
$ { R } sourceLocG = $ { R } ( $ { c . join ( ) } , 0 ) ;
++ $ { c [ a - 2 ] } ;
$ { R } sourceLocA = $ { R } ( $ { c . join ( ) } , 0 ) ;
-- $ { c [ a - 1 ] } ;
$ { R } sourceLocB = $ { R } ( $ { c . join ( ) } , 0 ) ;
-- $ { c [ a - 2 ] } ; ` }else u=a,p= `
$ { l } sourceLocR = coords ;
++ $ { c [ a - 1 ] } ;
$ { l } sourceLocG = coords ;
++ $ { c [ a - 2 ] } ;
$ { l } sourceLocA = coords ;
-- $ { c [ a - 1 ] } ;
$ { l } sourceLocB = coords ;
-- $ { c [ a - 2 ] } ; ` ;const h=["x","y","z","w","u","v"].slice(0,u),d="."+h[u-1],m=h.map(R=>"int "+R),f=Et("sourceLocR",u-1).concat("inIdx.r"),y=Et("sourceLocG",u-1).concat("inIdx.g"),b=Et("sourceLocB",u-1).concat("inIdx.b"),S=Et("sourceLocA",u-1).concat("inIdx.a"),x=s==="max"?"greaterThan":"lessThan",I=n?"": `
inIdx = round ( vec4 ( getBestIndicesAChannel ( $ { f . join ( ) } ) ,
getBestIndicesAChannel ( $ { y . join ( ) } ) ,
getBestIndicesAChannel ( $ { b . join ( ) } ) ,
getBestIndicesAChannel ( $ { S . join ( ) } ) ) ) ; ` ,A= ` vec4 (
getAChannel ( $ { f . join ( ) } ) ,
hasNextCol ? getAChannel ( $ { y . join ( ) } ) : 0. ,
hasNextRow ? getAChannel ( $ { b . join ( ) } ) : 0. ,
hasNextRow && hasNextCol ? getAChannel ( $ { S . join ( ) } ) : 0. ) ` ,k=n?"": `
float getBestIndicesAChannel ( $ { m . join ( ) } ) {
return getChannel ( getBestIndicesA ( $ { h . join ( ) } ) ,
vec2 ( $ { h . slice ( - 2 ) . join ( ) } ) ) ;
} ` ;this.userCode= `
float getAChannel ( $ { m . join ( ) } ) {
return getChannel ( getA ( $ { h . join ( ) } ) ,
vec2 ( $ { h . slice ( - 2 ) . join ( ) } ) ) ;
}
$ { k }
void main ( ) {
$ { l } coords = getOutputCoords ( ) ;
bool hasNextCol = $ { c [ a - 1 ] } < $ { o [ a - 1 ] - 1 } ;
bool hasNextRow = $ { c [ a - 2 ] } < $ { o [ a - 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 ;
$ { I }
vec4 candidate = $ { A } ;
bvec4 nan = isnan ( candidate ) ;
bvec4 replace = bvec4 (
vec4 ( $ { x } ( candidate , bestValue ) ) * ( vec4 ( 1.0 ) - vec4 ( nan ) ) ) ;
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 ) ;
}
` }}class KC{constructor(e){this.variableNames=["dy"],this.outputShape=e.inShape;const t=e.filterHeight,s=e.filterWidth,n=e.strideHeight,i=e.strideWidth,r=e.dilationHeight,o=e.dilationWidth,a=e.effectiveFilterHeight,l=e.effectiveFilterWidth,c=a-1-e.padInfo.top,p=l-1-e.padInfo.left,u=1/(t*s);this.userCode= `
const ivec2 pads = ivec2 ( $ { c } , $ { p } ) ;
const float avgMultiplier = float ( $ { u } ) ;
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 ;
for ( int wR = 0 ; wR < $ { a } ;
wR += $ { r } ) {
float dyR = float ( dyRCorner + wR ) / $ { n } . 0 ;
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
for ( int wC = 0 ; wC < $ { l } ;
wC += $ { o } ) {
float dyC = float ( dyCCorner + wC ) / $ { i } . 0 ;
if ( dyC < 0.0 || dyC >= $ { e . outWidth } . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
float dyValue = getDy ( b , idyR , idyC , d ) ;
dotProd += dyValue * avgMultiplier ;
}
}
setOutput ( dotProd ) ;
}
` }}class XC{constructor(e){this.variableNames=["dy"],this.outputShape=e.inShape;const t=e.filterDepth,s=e.filterHeight,n=e.filterWidth,i=e.strideDepth,r=e.strideHeight,o=e.strideWidth,a=e.dilationDepth,l=e.dilationHeight,c=e.dilationWidth,p=e.effectiveFilterDepth,u=e.effectiveFilterHeight,h=e.effectiveFilterWidth,d=p-1-e.padInfo.front,m=u-1-e.padInfo.top,f=h-1-e.padInfo.left,y=1/(t*s*n);this.userCode= `
const ivec3 pads = ivec3 ( $ { d } , $ { m } , $ { f } ) ;
const float avgMultiplier = float ( $ { y } ) ;
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
ivec3 dyCorner = ivec3 ( coords . y , coords . z , coords . w ) - pads ;
int dyDCorner = dyCorner . x ;
int dyRCorner = dyCorner . y ;
int dyCCorner = dyCorner . z ;
// Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get
// dx(xD, xR, xC, ch).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
for ( int wD = 0 ; wD < $ { p } ;
wD += $ { a } ) {
float dyD = float ( dyDCorner + wD ) / $ { i } . 0 ;
if ( dyD < 0.0 || dyD >= $ { e . outDepth } . 0 || fract ( dyD ) > 0.0 ) {
continue ;
}
int idyD = int ( dyD ) ;
for ( int wR = 0 ; wR < $ { u } ;
wR += $ { l } ) {
float dyR = float ( dyRCorner + wR ) / $ { r } . 0 ;
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 ||
fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
for ( int wC = 0 ; wC < $ { h } ;
wC += $ { c } ) {
float dyC = float ( dyCCorner + wC ) / $ { o } . 0 ;
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 ) ;
dotProd += dyValue * avgMultiplier ;
}
}
}
setOutput ( dotProd ) ;
}
` }}class JC{constructor(e,t,s,n,i,r){this.outputShape=[],this.variableNames=["x","mean","variance"],U.assertAndGetBroadcastShape(e,t),U.assertAndGetBroadcastShape(e,s);let o="0.0";n!=null&&(U.assertAndGetBroadcastShape(e,n),this.variableNames.push("offset"),o="getOffsetAtOutCoords()");let a="1.0";i!=null&&(U.assertAndGetBroadcastShape(e,i),this.variableNames.push("scale"),a="getScaleAtOutCoords()"),this.outputShape=e,this.userCode= `
void main ( ) {
float x = getXAtOutCoords ( ) ;
float mean = getMeanAtOutCoords ( ) ;
float variance = getVarianceAtOutCoords ( ) ;
float offset = $ { o } ;
float scale = $ { a } ;
float inv = scale * inversesqrt ( variance + float ( $ { r } ) ) ;
setOutput ( dot ( vec3 ( x , - mean , offset ) , vec3 ( inv , inv , 1 ) ) ) ;
}
` }}class ZC{constructor(e,t,s,n,i,r){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],U.assertAndGetBroadcastShape(e,t),U.assertAndGetBroadcastShape(e,s);let o="vec4(0.0)";n!=null&&(U.assertAndGetBroadcastShape(e,n),this.variableNames.push("offset"),o="getOffsetAtOutCoords()");let a="vec4(1.0)";i!=null&&(U.assertAndGetBroadcastShape(e,i),this.variableNames.push("scale"),a="getScaleAtOutCoords()"),this.outputShape=e,this.userCode= `
void main ( ) {
vec4 offset = $ { o } ;
vec4 scale = $ { a } ;
vec4 x = getXAtOutCoords ( ) ;
vec4 mean = getMeanAtOutCoords ( ) ;
vec4 variance = getVarianceAtOutCoords ( ) ;
vec4 inv = scale * inversesqrt ( variance + vec4 ( $ { r } ) ) ;
setOutput ( ( x - mean ) * inv + offset ) ;
}
` }}const tx={REAL:"return areal * breal - aimag * bimag;",IMAG:"return areal * bimag + aimag * breal;"};class sx{constructor(e,t,s){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=U.assertAndGetBroadcastShape(t,s),this.userCode= `
float binaryOpComplex (
float areal , float aimag , float breal , float bimag ) {
$ { e }
}
void main ( ) {
float areal = getARealAtOutCoords ( ) ;
float aimag = getAImagAtOutCoords ( ) ;
float breal = getBRealAtOutCoords ( ) ;
float bimag = getBImagAtOutCoords ( ) ;
setOutput ( binaryOpComplex ( areal , aimag , breal , bimag ) ) ;
}
` }}const nx= `
if ( isnan ( a ) ) return a ;
if ( isnan ( b ) ) return b ;
` ,vf="return a + b;",Tf="return a - b;",ix="return a * b;",QC= `
if ( a == b ) {
return 1.0 ;
} ;
return a / b ; ` ,e0= `
float s = sign ( a ) * sign ( b ) ;
int ia = round ( a ) ;
int ib = round ( b ) ;
if ( ib != 0 ) {
// Windows (D3D) wants guaranteed non-zero int division at compile-time.
return float ( idiv ( ia , ib , s ) ) ;
} else {
return NAN ;
}
` ,t0= `
if ( a < 0.0 && floor ( b ) < b ) {
return NAN ;
}
if ( b == 0.0 ) {
return 1.0 ;
}
return ( round ( mod ( b , 2.0 ) ) != 1 ) ?
pow ( abs ( a ) , b ) : sign ( a ) * pow ( abs ( a ) , b ) ;
` ,s0="return float(a == b);",n0="return float(a != b);",i0="return float(a < b);",r0="return float(a <= b);",o0="return float(a > b);",a0="return float(a >= b);",l0="return float(a >= 1.0 && b >= 1.0);",c0="return float(a >= 1.0 || b >= 1.0);",p0=nx+ `
return max ( a , b ) ;
` ,u0=nx+ `
return min ( a , b ) ;
` ,h0= ` if ( b == 0.0 ) return NAN ;
return mod ( a , b ) ; ` ,d0=nx+ `
return atan ( a , b ) ;
` ,m0="return (b >= 1.0) ? a : a * (b + 1.0);",rx="return (a < 0.) ? b * a : a;";class mt{constructor(e,t,s){this.variableNames=["A","B"],this.outputShape=U.assertAndGetBroadcastShape(t,s),this.userCode= `
float binaryOperation ( float a , float b ) {
$ { e }
}
void main ( ) {
float a = getAAtOutCoords ( ) ;
float b = getBAtOutCoords ( ) ;
setOutput ( binaryOperation ( a , b ) ) ;
}
` }}const Uu= `
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 ;
` ,f0= `
// vec4 one = vec4(equal(a, b));
// return one + (vec4(1.0) - one) * a / b;
vec4 result = a / b ;
if ( a . x == b . x ) {
result . x = 1. ;
}
if ( a . y == b . y ) {
result . y = 1. ;
}
if ( a . z == b . z ) {
result . z = 1. ;
}
if ( a . w == b . w ) {
result . w = 1. ;
}
return result ;
` ,g0= `
ivec4 ia = round ( a ) ;
ivec4 ib = round ( b ) ;
bvec4 cond = notEqual ( ib , ivec4 ( 0 ) ) ;
ivec4 result = ivec4 ( 0 ) ;
vec4 s = sign ( a ) * sign ( b ) ;
// 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 ) ;
` ,y0= `
// isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise.
vec4 isModRound1 = vec4 ( equal ( round ( mod ( b , 2.0 ) ) , ivec4 ( 1 ) ) ) ;
vec4 multiplier = sign ( a ) * isModRound1 + ( vec4 ( 1.0 ) - isModRound1 ) ;
vec4 result = multiplier * pow ( abs ( a ) , b ) ;
// Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS
bvec4 isExpZero = equal ( b , vec4 ( 0.0 ) ) ;
result . r = isExpZero . r ? 1.0 : result . r ;
result . g = isExpZero . g ? 1.0 : result . g ;
result . b = isExpZero . b ? 1.0 : result . b ;
result . a = isExpZero . a ? 1.0 : result . a ;
vec4 isNaN = vec4 ( lessThan ( a , vec4 ( 0.0 ) ) ) * vec4 ( lessThan ( floor ( b ) , b ) ) ;
` +Uu+ `
return result ;
` ,ox= `
vec4 aLessThanZero = vec4 ( lessThan ( a , vec4 ( 0. ) ) ) ;
return ( aLessThanZero * ( b * a ) ) + ( ( vec4 ( 1.0 ) - aLessThanZero ) * a ) ;
` ,b0= `
vec4 bGTEZero = vec4 ( greaterThanEqual ( b , vec4 ( 0. ) ) ) ;
return ( bGTEZero * a ) + ( ( vec4 ( 1.0 ) - bGTEZero ) * ( a * ( b + vec4 ( 1.0 ) ) ) ) ;
` ,w0= `
vec4 result = atan ( a , b ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
` +Uu+ `
return result ;
` ,x0= `
return vec4 ( equal ( a , b ) ) ;
` ,L0= `
return vec4 ( notEqual ( a , b ) ) ;
` ,S0= `
return vec4 ( lessThan ( a , b ) ) ;
` ,v0= `
return vec4 ( lessThanEqual ( a , b ) ) ;
` ,T0= `
return vec4 ( greaterThan ( a , b ) ) ;
` ,I0= `
return vec4 ( greaterThanEqual ( a , b ) ) ;
` ,A0= `
return vec4 (
vec4 ( greaterThanEqual ( a , vec4 ( 1.0 ) ) ) *
vec4 ( greaterThanEqual ( b , vec4 ( 1.0 ) ) ) ) ;
` ,N0= `
return min (
vec4 ( greaterThanEqual ( a , vec4 ( 1.0 ) ) ) +
vec4 ( greaterThanEqual ( b , vec4 ( 1.0 ) ) ) ,
vec4 ( 1.0 ) ) ;
` ,C0= `
vec4 result = vec4 ( max ( a , b ) ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
` +Uu+ `
return result ;
` ,R0= `
vec4 result = vec4 ( min ( a , b ) ) ;
vec4 isNaN = min ( vec4 ( isnan ( a ) ) + vec4 ( isnan ( b ) ) , vec4 ( 1.0 ) ) ;
` +Uu+ `
return result ;
` ,O0= `
vec4 result = mod ( a , b ) ;
vec4 isNaN = vec4 ( equal ( b , vec4 ( 0.0 ) ) ) ;
` +Uu+ `
return result ;
` ;class Qs{constructor(e,t,s,n=!1){this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.packedInputs=!0,this.packedOutput=!0,this.outputShape=U.assertAndGetBroadcastShape(t,s);const i=this.outputShape.length;let r="";if(n)if(i===0||E.sizeFromShape(this.outputShape)===1)r= `
result . y = 0. ;
result . z = 0. ;
result . w = 0. ;
` ;else{const o=Ce(i);if(r= `
$ { o } coords = getOutputCoords ( ) ;
` ,i===1)r+= `
result . y = ( coords + 1 ) >= $ { this . outputShape [ 0 ] } ? 0. : result . y ;
result . z = 0. ;
result . w = 0. ;
` ;else{const a=Et("coords",i);r+= `
bool nextRowOutOfBounds =
( $ { a [ i - 2 ] } + 1 ) >= $ { this . outputShape [ i - 2 ] } ;
bool nextColOutOfBounds =
( $ { a [ i - 1 ] } + 1 ) >= $ { this . outputShape [ i - 1 ] } ;
result . y = nextColOutOfBounds ? 0. : result . y ;
result . z = nextRowOutOfBounds ? 0. : result . z ;
result . w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result . w ;
` }}this.userCode= `
vec4 binaryOperation ( vec4 a , vec4 b ) {
$ { e }
}
void main ( ) {
vec4 a = getAAtOutCoords ( ) ;
vec4 b = getBAtOutCoords ( ) ;
vec4 result = binaryOperation ( a , b ) ;
$ { r }
setOutput ( result ) ;
}
` }}class E0{constructor(e){this.variableNames=["A"],this.outputShape=e,this.userCode= `
uniform float minVal ;
uniform float maxVal ;
void main ( ) {
float value = getAAtOutCoords ( ) ;
if ( isnan ( value ) ) {
setOutput ( value ) ;
return ;
}
setOutput ( clamp ( value , minVal , maxVal ) ) ;
}
` }getCustomSetupFunc(e,t){return(s,n)=>{this.minLoc==null&&(this.minLoc=s.getUniformLocationNoThrow(n,"minVal"),this.maxLoc=s.getUniformLocationNoThrow(n,"maxVal")),s.gl.uniform1f(this.minLoc,e),s.gl.uniform1f(this.maxLoc,t)}}}class k0{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.userCode= `
uniform float minVal ;
uniform float maxVal ;
void main ( ) {
vec4 value = getAAtOutCoords ( ) ;
if ( any ( isnan ( value ) ) ) {
setOutput ( value ) ;
return ;
}
setOutput ( clamp ( value , vec4 ( minVal ) , vec4 ( maxVal ) ) ) ;
}
` }getCustomSetupFunc(e,t){return(s,n)=>{this.minLoc==null&&(this.minLoc=s.getUniformLocationNoThrow(n,"minVal"),this.maxLoc=s.getUniformLocationNoThrow(n,"maxVal")),s.gl.uniform1f(this.minLoc,e),s.gl.uniform1f(this.maxLoc,t)}}}class _0{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 ) ;
// 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 ) )
) ;
}
` }}class D0{constructor(e){this.outputShape=[],this.outputShape=U.computeOutShape(e,1),this.variableNames=e.map((r,o)=> ` T$ { o } ` );const t=new Array(e.length-1);t[0]=e[0][1];for(let r=1;r<t.length;r++)t[r]=t[r-1]+e[r][1];const s=[ ` if ( yC < $ { t [ 0 ] } ) setOutput ( getT0 ( yR , yC ) ) ; ` ];for(let r=1;r<t.length;r++){const o=t[r-1];s.push( ` else if ( yC < $ { t [ r ] } ) setOutput ( getT$ { r } ( yR , yC - $ { o } ) ) ; ` )}const n=t.length,i=t[t.length-1];s.push( ` else setOutput ( getT$ { n } ( yR , yC - $ { i } ) ) ; ` ),this.userCode= `
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int yR = coords . x ;
int yC = coords . y ;
$ { s . join ( `
` )}
}
` }}class F0{constructor(e,t){this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[],this.outputShape=U.computeOutShape(e,t);const s=this.outputShape,n=s.length,i=Ce(n),r=Et("coords",n),o=["x","y","z","w","u","v"].slice(0,n);this.variableNames=e.map((m,f)=> ` T$ { f } ` );const a=new Array(e.length-1);a[0]=e[0][t];for(let m=1;m<a.length;m++)a[m]=a[m-1]+e[m][t];const l=o[t],c=o.slice(-2),p=o.join();let u= ` if ( $ { l } < $ { a [ 0 ] } ) {
return getChannel (
getT0 ( $ { p } ) , vec2 ( $ { c . join ( ) } ) ) ;
} ` ;for(let m=1;m<a.length;m++){const f=a[m-1];u+= `
if ( $ { l } < $ { a [ m ] } && $ { l } >= $ { a [ m - 1 ] } ) {
return getChannel (
getT$ { m } ( $ { If ( o , l , f ) } ) ,
vec2 ( $ { If ( c , l , f ) } ) ) ;
} ` }const h=a.length,d=a[a.length-1];u+= `
return getChannel (
getT$ { h } ( $ { If ( o , l , d ) } ) ,
vec2 ( $ { If ( c , l , d ) } ) ) ; ` ,this.userCode= `
float getValue ( $ { o . map ( m => "int " + m ) } ) {
$ { u }
}
void main ( ) {
$ { i } coords = getOutputCoords ( ) ;
vec4 result = vec4 ( getValue ( $ { r } ) , 0. , 0. , 0. ) ;
$ { r [ n - 1 ] } = $ { r [ n - 1 ] } + 1 ;
if ( $ { r [ n - 1 ] } < $ { s [ n - 1 ] } ) {
result . g = getValue ( $ { r } ) ;
}
$ { r [ n - 2 ] } = $ { r [ n - 2 ] } + 1 ;
if ( $ { r [ n - 2 ] } < $ { s [ n - 2 ] } ) {
result . a = getValue ( $ { r } ) ;
}
$ { r [ n - 1 ] } = $ { r [ n - 1 ] } - 1 ;
if ( $ { r [ n - 2 ] } < $ { s [ n - 2 ] } &&
$ { r [ n - 1 ] } < $ { s [ n - 1 ] } ) {
result . b = getValue ( $ { r } ) ;
}
setOutput ( result ) ;
}
` }}function If(e,t,s){const n=e.indexOf(t),i=e.map((r,o)=>o===n? ` $ { r } - $ { s } ` :r);return i.join()}class M0{constructor(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;const t=e.strideHeight,s=e.strideWidth,n=e.padInfo.top,i=e.padInfo.left,r=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 ;
// 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 ;
for ( int b = 0 ; b < $ { e . batchSize } ; b ++ ) {
for ( int yR = 0 ; yR < $ { e . outHeight } ; yR ++ ) {
int xR = wR + yR * $ { t } - $ { n } ;
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
for ( int yC = 0 ; yC < $ { e . outWidth } ; yC ++ ) {
int xC = wC + yC * $ { s } - $ { i } ;
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
if ( $ { r } ) {
float dyValue = getDy ( b , yR , yC , d2 ) ;
float xValue = getX ( b , xR , xC , d1 ) ;
dotProd += ( xValue * dyValue ) ;
} else {
float dyValue = getDy ( b , d2 , yR , yC ) ;
float xValue = getX ( b , d1 , xR , xC ) ;
dotProd += ( xValue * dyValue ) ;
}
}
}
}
setOutput ( dotProd ) ;
}
` }}class U0{constructor(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;const t=e.filterHeight,s=e.filterWidth,n=e.strideHeight,i=e.strideWidth,r=e.dataFormat==="channelsLast",o=t-1-e.padInfo.top,a=s-1-e.padInfo.left,l=r?1:2,c=r?2:3,p=r?3:1;this.userCode= `
const ivec2 pads = ivec2 ( $ { o } , $ { a } ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int d1 = coords [ $ { p } ] ;
ivec2 dyCorner = ivec2 ( coords [ $ { l } ] , coords [ $ { c } ] ) - pads ;
int dyRCorner = dyCorner . x ;
int dyCCorner = dyCorner . y ;
// 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 ) / $ { n } . 0 ;
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
int wRPerm = $ { t } - 1 - wR ;
for ( int wC = 0 ; wC < $ { s } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { i } . 0 ;
if ( dyC < 0.0 || dyC >= $ { e . outWidth } . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
int wCPerm = $ { s } - 1 - wC ;
for ( int d2 = 0 ; d2 < $ { e . outChannels } ; d2 ++ ) {
if ( $ { r } ) {
float xValue = getDy ( batch , idyR , idyC , d2 ) ;
float wValue = getW ( wRPerm , wCPerm , d1 , d2 ) ;
dotProd += xValue * wValue ;
} else {
float xValue = getDy ( batch , d2 , idyR , idyC ) ;
float wValue = getW ( wRPerm , wCPerm , d1 , d2 ) ;
dotProd += xValue * wValue ;
}
}
}
}
setOutput ( dotProd ) ;
}
` }}class $ 0{constructor(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;const t=e.strideDepth,s=e.strideHeight,n=e.strideWidth,i=e.padInfo.front,r=e.padInfo.top,o=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 ;
float dotProd = 0.0 ;
for ( int b = 0 ; b < $ { e . batchSize } ; b ++ ) {
for ( int yF = 0 ; yF < $ { e . outDepth } ; yF ++ ) {
int xF = wF + yF * $ { t } - $ { i } ;
if ( xF < 0 || xF >= $ { e . inDepth } ) {
continue ;
}
for ( int yR = 0 ; yR < $ { e . outHeight } ; yR ++ ) {
int xR = wR + yR * $ { s } - $ { r } ;
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
for ( int yC = 0 ; yC < $ { e . outWidth } ; yC ++ ) {
int xC = wC + yC * $ { n } - $ { o } ;
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
float dyValue = getDy ( b , yF , yR , yC , d2 ) ;
float xValue = getX ( b , xF , xR , xC , d1 ) ;
dotProd += ( xValue * dyValue ) ;
}
}
}
}
setOutput ( dotProd ) ;
}
` }}class W0{constructor(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;const t=e.filterDepth,s=e.filterHeight,n=e.filterWidth,i=e.strideDepth,r=e.strideHeight,o=e.strideWidth,a=t-1-e.padInfo.front,l=s-1-e.padInfo.top,c=n-1-e.padInfo.left;this.userCode= `
const ivec3 pads = ivec3 ( $ { a } , $ { l } , $ { c } ) ;
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int d1 = coords . u ;
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 ) / $ { i } . 0 ;
if ( dyF < 0.0 || dyF >= $ { e . outDepth } . 0 || fract ( dyF ) > 0.0 ) {
continue ;
}
int idyF = int ( dyF ) ;
int wFPerm = $ { t } - 1 - wF ;
for ( int wR = 0 ; wR < $ { s } ; wR ++ ) {
float dyR = float ( dyRCorner + wR ) / $ { r } . 0 ;
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 ||
fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
int wRPerm = $ { s } - 1 - wR ;
for ( int wC = 0 ; wC < $ { n } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { o } . 0 ;
if ( dyC < 0.0 || dyC >= $ { e . outWidth } . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
int wCPerm = $ { n } - 1 - wC ;
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 ;
}
}
}
}
setOutput ( dotProd ) ;
}
` }}class z0{constructor(e){this.variableNames=["x","dy"],this.outputShape=e.filterShape;const t=e.strideHeight,s=e.strideWidth,n=e.padInfo.top,i=e.padInfo.left,r=e.outChannels/e.inChannels;this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int wR = coords . x ;
int wC = coords . y ;
int d1 = coords . z ;
int dm = coords . w ;
int d2 = d1 * $ { r } + dm ;
float dotProd = 0.0 ;
// 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 } - $ { n } ;
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
for ( int yC = 0 ; yC < $ { e . outWidth } ; yC ++ ) {
int xC = wC + yC * $ { s } - $ { i } ;
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
float dyValue = getDy ( b , yR , yC , d2 ) ;
float xValue = getX ( b , xR , xC , d1 ) ;
dotProd += ( xValue * dyValue ) ;
}
}
}
setOutput ( dotProd ) ;
}
` }}class B0{constructor(e){this.variableNames=["dy","W"],this.outputShape=e.inShape;const t=e.filterHeight,s=e.filterWidth,n=e.strideHeight,i=e.strideWidth,r=t-1-e.padInfo.top,o=s-1-e.padInfo.left,a=e.outChannels/e.inChannels;this.userCode= `
const ivec2 pads = ivec2 ( $ { r } , $ { o } ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int d1 = coords [ 3 ] ;
ivec2 dyCorner = coords . yz - pads ;
int dyRCorner = dyCorner . x ;
int dyCCorner = dyCorner . y ;
float dotProd = 0.0 ;
for ( int wR = 0 ; wR < $ { t } ; wR ++ ) {
float dyR = float ( dyRCorner + wR ) / $ { n } . 0 ;
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
int wRPerm = $ { t } - 1 - wR ;
for ( int wC = 0 ; wC < $ { s } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { i } . 0 ;
if ( dyC < 0.0 || dyC >= $ { e . outWidth } . 0 ||
fract ( dyC ) > 0.0 ) {
continue ;
}
int idyC = int ( dyC ) ;
int wCPerm = $ { s } - 1 - wC ;
// TO DO: Vec4 over the channelMul
for ( int dm = 0 ; dm < $ { a } ; dm ++ ) {
int d2 = d1 * $ { a } + dm ;
float xValue = getDy ( batch , idyR , idyC , d2 ) ;
float wValue = getW ( wRPerm , wCPerm , d1 , dm ) ;
dotProd += xValue * wValue ;
}
}
}
setOutput ( dotProd ) ;
}
` }}class ax{constructor(e,t=!1,s=null,n=!1){this.variableNames=["x","W"],this.outputShape=e.outShape;const i=e.padInfo.top,r=e.padInfo.left,o=e.strideHeight,a=e.strideWidth,l=e.dilationHeight,c=e.dilationWidth,p=e.filterHeight,u=e.filterWidth,h=Math.floor(e.inChannels/4)*4,d=e.inChannels%4,m=e.dataFormat==="channelsLast",f=m?1:2,y=m?2:3,b=m?3:1;let S="",x="";s&&(n?S= ` float activation ( float a ) {
float b = getPreluActivationWeightsAtOutCoords ( ) ;
$ { s }
} ` :S= `
float activation ( float x ) {
$ { s }
}
` ,x="result = activation(result);");const I=t?"result += getBiasAtOutCoords();":"";t&&this.variableNames.push("bias"),n&&this.variableNames.push("preluActivationWeights"),this.userCode= `
$ { S }
const ivec2 strides = ivec2 ( $ { o } , $ { a } ) ;
const ivec2 pads = ivec2 ( $ { i } , $ { r } ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int d2 = coords [ $ { b } ] ;
ivec2 xRCCorner =
ivec2 ( coords [ $ { f } ] , coords [ $ { y } ] ) * strides - pads ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
// 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 < $ { p } ; wR ++ ) {
int xR = xRCorner + wR * $ { l } ;
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
for ( int wC = 0 ; wC < $ { u } ; wC ++ ) {
int xC = xCCorner + wC * $ { c } ;
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
for ( int d1 = 0 ; d1 < $ { h } ; d1 += 4 ) {
vec4 wValues = vec4 (
getW ( wR , wC , d1 , d2 ) ,
getW ( wR , wC , d1 + 1 , d2 ) ,
getW ( wR , wC , d1 + 2 , d2 ) ,
getW ( wR , wC , d1 + 3 , d2 )
) ;
if ( $ { m } ) {
vec4 xValues = vec4 (
getX ( batch , xR , xC , d1 ) ,
getX ( batch , xR , xC , d1 + 1 ) ,
getX ( batch , xR , xC , d1 + 2 ) ,
getX ( batch , xR , xC , d1 + 3 )
) ;
dotProd += dot ( xValues , wValues ) ;
} else {
vec4 xValues = vec4 (
getX ( batch , d1 , xR , xC ) ,
getX ( batch , d1 + 1 , xR , xC ) ,
getX ( batch , d1 + 2 , xR , xC ) ,
getX ( batch , d1 + 3 , xR , xC )
) ;
dotProd += dot ( xValues , wValues ) ;
}
}
if ( $ { d === 1 } ) {
if ( $ { m } ) {
dotProd +=
getX ( batch , xR , xC , $ { h } ) *
getW ( wR , wC , $ { h } , d2 ) ;
} else {
dotProd +=
getX ( batch , $ { h } , xR , xC ) *
getW ( wR , wC , $ { h } , d2 ) ;
}
} else if ( $ { d === 2 } ) {
vec2 wValues = vec2 (
getW ( wR , wC , $ { h } , d2 ) ,
getW ( wR , wC , $ { h } + 1 , d2 )
) ;
if ( $ { m } ) {
vec2 xValues = vec2 (
getX ( batch , xR , xC , $ { h } ) ,
getX ( batch , xR , xC , $ { h } + 1 )
) ;
dotProd += dot ( xValues , wValues ) ;
} else {
vec2 xValues = vec2 (
getX ( batch , $ { h } , xR , xC ) ,
getX ( batch , $ { h } + 1 , xR , xC )
) ;
dotProd += dot ( xValues , wValues ) ;
}
} else if ( $ { d === 3 } ) {
vec3 wValues = vec3 (
getW ( wR , wC , $ { h } , d2 ) ,
getW ( wR , wC , $ { h } + 1 , d2 ) ,
getW ( wR , wC , $ { h } + 2 , d2 )
) ;
if ( $ { m } ) {
vec3 xValues = vec3 (
getX ( batch , xR , xC , $ { h } ) ,
getX ( batch , xR , xC , $ { h } + 1 ) ,
getX ( batch , xR , xC , $ { h } + 2 )
) ;
dotProd += dot ( xValues , wValues ) ;
} else {
vec3 xValues = vec3 (
getX ( batch , $ { h } , xR , xC ) ,
getX ( batch , $ { h } + 1 , xR , xC ) ,
getX ( batch , $ { h } + 2 , xR , xC )
) ;
dotProd += dot ( xValues , wValues ) ;
}
}
}
}
float result = dotProd ;
$ { I }
$ { x }
setOutput ( result ) ;
}
` }}class P0{constructor(e){this.variableNames=["x","W"],this.outputShape=e.outShape;const t=e.padInfo.front,s=e.padInfo.top,n=e.padInfo.left,i=e.strideDepth,r=e.strideHeight,o=e.strideWidth,a=e.dilationDepth,l=e.dilationHeight,c=e.dilationWidth,p=e.filterDepth,u=e.filterHeight,h=e.filterWidth,d=Math.floor(e.inChannels/4)*4,m=e.inChannels%4;this.userCode= `
const ivec3 strides = ivec3 ( $ { i } , $ { r } , $ { o } ) ;
const ivec3 pads = ivec3 ( $ { t } , $ { s } , $ { n } ) ;
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int d2 = coords . u ;
ivec3 xFRCCorner = ivec3 ( coords . y , coords . z , coords . w ) * strides - pads ;
int xFCorner = xFRCCorner . x ;
int xRCorner = xFRCCorner . y ;
int xCCorner = xFRCCorner . z ;
// 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 * $ { a } ;
if ( xF < 0 || xF >= $ { e . inDepth } ) {
continue ;
}
for ( int wR = 0 ; wR < $ { u } ; wR ++ ) {
int xR = xRCorner + wR * $ { l } ;
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
for ( int wC = 0 ; wC < $ { h } ; wC ++ ) {
int xC = xCCorner + wC * $ { c } ;
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
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 )
) ;
dotProd += dot ( xValues , wValues ) ;
}
if ( $ { m === 1 } ) {
dotProd +=
getX ( batch , xF , xR , xC , $ { d } ) *
getW ( wF , wR , wC , $ { d } , d2 ) ;
} else if ( $ { m === 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 ( $ { m === 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 ) ;
}
` }}class lx{constructor(e,t=!1,s=null,n=!1){this.variableNames=["x","W"],this.outputShape=e.outShape;const i=e.inHeight,r=e.inWidth,o=e.padInfo.top,a=e.padInfo.left,l=e.strideHeight,c=e.strideWidth,p=e.dilationHeight,u=e.dilationWidth,h=e.filterHeight,d=e.filterWidth,m=e.outChannels/e.inChannels;let f="",y="";s&&(n?f= ` float activation ( float a ) {
float b = getPreluActivationWeightsAtOutCoords ( ) ;
$ { s }
} ` :f= `
float activation ( float x ) {
$ { s }
}
` ,y="result = activation(result);");const b=t?"result += getBiasAtOutCoords();":"";t&&this.variableNames.push("bias"),n&&this.variableNames.push("preluActivationWeights"),this.userCode= `
$ { f }
const ivec2 strides = ivec2 ( $ { l } , $ { c } ) ;
const ivec2 pads = ivec2 ( $ { o } , $ { a } ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords . x ;
ivec2 xRCCorner = coords . yz * strides - pads ;
int d2 = coords . w ;
int d1 = d2 / $ { m } ;
int q = d2 - d1 * $ { m } ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
// 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 < $ { h } ; wR ++ ) {
int xR = xRCorner + wR * $ { p } ;
if ( xR < 0 || xR >= $ { i } ) {
continue ;
}
for ( int wC = 0 ; wC < $ { d } ; wC ++ ) {
int xC = xCCorner + wC * $ { u } ;
if ( xC < 0 || xC >= $ { r } ) {
continue ;
}
float xVal = getX ( batch , xR , xC , d1 ) ;
float wVal = getW ( wR , wC , d1 , q ) ;
dotProd += xVal * wVal ;
}
}
float result = dotProd ;
$ { b }
$ { y }
setOutput ( result ) ;
}
` }}class cx{constructor(e,t=!1,s=null,n=!1){this.variableNames=["x","W"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e.outShape;const i=e.inHeight,r=e.inWidth,o=e.padInfo.top,a=e.padInfo.left,l=e.strideHeight,c=e.strideWidth,p=e.dilationHeight,u=e.dilationWidth,h=e.filterHeight,d=e.filterWidth,m=d;let f="int xR; int xC; int xCOffset;";for(let x=0;x<h;x++)for(let I=0;I<d;I++)f+= `
vec4 xTexelR$ { x } C$ { I * 2 } = vec4 ( 0. ) ;
vec4 wR$ { x } C$ { I } = vec4 ( 0. ) ;
vec4 xR$ { x } C$ { I } = vec4 ( 0. ) ; ` ;for(let x=0;x<h;x++)for(let I=0;I<m;I++){const A=I*2;if(f+= `
xR = xRCorner + $ { x * p } ;
xC = xCCorner + $ { A * u } ;
` ,c===1){if(A<d&&(a%2===1?f+= `
xCOffset = xC + 1 ;
if ( xR >= 0 && xR < $ { i } && xCOffset >= 0 && xCOffset < $ { r } ) {
xTexelR$ { x } C$ { A } = getX ( batch , xR , xCOffset , d1 ) ;
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if ( xCOffset + 1 >= $ { r } ) {
xTexelR$ { x } C$ { A } . zw = vec2 ( 0. ) ;
}
} else {
xTexelR$ { x } C$ { A } = vec4 ( 0. ) ;
}
xCOffset = xC + 1 - 2 ;
if ( xR >= 0 && xR < $ { i } && xCOffset >= 0 && xCOffset < $ { r } ) {
vec4 previous = getX ( batch , xR , xCOffset , d1 ) ;
// Need to manually clear unused channels in case
// we're reading from recycled texture.
if ( xCOffset + 1 >= $ { r } ) {
previous . zw = vec2 ( 0. ) ;
}
xR$ { x } C$ { A } = vec4 ( previous . zw , xTexelR$ { x } C$ { A } . xy ) ;
} else {
xR$ { x } C$ { A } = vec4 ( 0 , 0 , xTexelR$ { x } C$ { A } . xy ) ;
}
` :f+= `
if ( xR >= 0 && xR < $ { i } && xC >= 0 && xC < $ { r } ) {
xTexelR$ { x } C$ { A } = getX ( batch , xR , xC , d1 ) ;
} else {
xTexelR$ { x } C$ { A } = vec4 ( 0. ) ;
}
xR$ { x } C$ { A } = xTexelR$ { x } C$ { A } ;
` ,A+1<d)){const k=a%2===0?E.nearestLargerEven(u):u;u%2===0&&a%2===1||u%2!==0&&a%2!==1?(f+= `
xCOffset = xC + $ { a % 2 } + $ { k } ;
if ( xR >= 0 && xR < $ { i } &&
xCOffset >= 0 && xCOffset < $ { r } ) {
xTexelR$ { x } C$ { A + 2 } = getX ( batch , xR , xCOffset , d1 ) ;
}
` ,u>1&&(f+= `
xCOffset -= 2 ;
if ( xR >= 0 && xR < $ { i } &&
xCOffset >= 0 && xCOffset < $ { r } ) {
xTexelR$ { x } C$ { A } = getX ( batch , xR , xCOffset , d1 ) ;
} else {
xTexelR$ { x } C$ { A } = vec4 ( 0. ) ;
}
` ),f+= `
xR$ { x } C$ { A + 1 } = vec4 (
xTexelR$ { x } C$ { A } . zw , xTexelR$ { x } C$ { A + 2 } . xy ) ;
` ):f+= `
xCOffset = xC + $ { k } ;
if ( xR >= 0 && xR < $ { i } &&
xCOffset >= 0 && xCOffset < $ { r } ) {
xTexelR$ { x } C$ { A + 2 } = getX ( batch , xR , xCOffset , d1 ) ;
}
xR$ { x } C$ { A + 1 } = xTexelR$ { x } C$ { A + 2 } ;
` }}else A<d&&(f+= `
if ( xR >= 0 && xR < $ { i } ) {
` ,a%2===1?(f+= `
xCOffset = xC + 1 - $ { c } ;
if ( xCOffset >= 0 && xCOffset < $ { r } ) {
xTexelR$ { x } C$ { A } = getX ( batch , xR , xCOffset , d1 ) ;
} else {
xTexelR$ { x } C$ { A } = vec4 ( 0. ) ;
}
if ( xC + 1 >= 0 && xC + 1 < $ { r } ) {
xTexelR$ { x } C$ { A + 2 } = getX ( batch , xR , xC + 1 , d1 ) ;
} else {
xTexelR$ { x } C$ { A + 2 } = vec4 ( 0. ) ;
}
xR$ { x } C$ { A } = vec4 (
xTexelR$ { x } C$ { A } . zw , xTexelR$ { x } C$ { A + 2 } . zw ) ;
` ,A+1<d&&(f+= `
vec4 final = vec4 ( 0. ) ;
xCOffset = xC + 1 + $ { c } ;
if ( xCOffset >= 0 && xCOffset < $ { r } ) {
final = getX ( batch , xR , xCOffset , d1 ) ;
}
xR$ { x } C$ { A + 1 } = vec4 ( xTexelR$ { x } C$ { A + 2 } . xy , final . xy ) ;
` )):(f+= `
if ( xC >= 0 && xC < $ { r } ) {
xTexelR$ { x } C$ { A } = getX ( batch , xR , xC , d1 ) ;
} else {
xTexelR$ { x } C$ { A } = vec4 ( 0. ) ;
}
xCOffset = xC + $ { c } ;
if ( xCOffset >= 0 && xCOffset < $ { r } ) {
xTexelR$ { x } C$ { A + 2 } = getX ( batch , xR , xCOffset , d1 ) ;
} else {
xTexelR$ { x } C$ { A + 2 } = vec4 ( 0. ) ;
}
xR$ { x } C$ { A } = vec4 (
xTexelR$ { x } C$ { A } . xy , xTexelR$ { x } C$ { A + 2 } . xy ) ;
` ,A+1<d&&(f+= `
xR$ { x } C$ { A + 1 } = vec4 (
xTexelR$ { x } C$ { A } . zw , xTexelR$ { x } C$ { A + 2 } . zw ) ;
` )),f+="}");A<d&&(f+= `
vec4 wTexelR$ { x } C$ { A } = getW ( $ { x } , $ { A } , d1 , q ) ;
wR$ { x } C$ { A } = vec4 ( wTexelR$ { x } C$ { A } . xz , wTexelR$ { x } C$ { A } . xz ) ;
` ,A+1<d&&(f+= `
vec4 wTexelR$ { x } C$ { A + 1 } = getW ( $ { x } , $ { A + 1 } , d1 , q ) ;
wR$ { x } C$ { A + 1 } =
vec4 ( wTexelR$ { x } C$ { A + 1 } . xz , wTexelR$ { x } C$ { A + 1 } . xz ) ; ` ))}for(let x=0;x<h;x++)for(let I=0;I<d;I++)f+= ` dotProd += xR$ { x } C$ { I } * wR$ { x } C$ { I } ; ` ;let y="",b="";s&&(n?y= ` vec4 activation ( vec4 a ) {
vec4 b = getPreluActivationWeightsAtOutCoords ( ) ;
$ { s }
} ` :y= ` vec4 activation ( vec4 x ) {
$ { s }
} ` ,b="result = activation(result);");const S=t?"result += getBiasAtOutCoords();":"";t&&this.variableNames.push("bias"),n&&this.variableNames.push("preluActivationWeights"),this.userCode= `
$ { y }
const ivec2 strides = ivec2 ( $ { l } , $ { c } ) ;
const ivec2 pads = ivec2 ( $ { o } , $ { a } ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords . x ;
ivec2 xRCCorner = coords . yz * strides - pads ;
int d2 = coords . w ;
int d1 = d2 ;
int q = 0 ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
vec4 dotProd = vec4 ( 0. ) ;
$ { f }
vec4 result = dotProd ;
$ { S }
$ { b }
setOutput ( result ) ;
}
` }}class j0{constructor(e,t,s,n,i){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];const[r,o,a,l]=e,[c]=t,[p,u]=s;this.outputShape=[c,p,u,l];const h=n==="bilinear"?1:0,[d,m]=[ ` $ { o - 1 } . 0 ` , ` $ { a - 1 } . 0 ` ],[f,y,b]=p>1?[ ` $ { ( o - 1 ) / ( p - 1 ) } ` ,"(y2-y1) * height_ratio", ` y1 * $ { d } + float ( y ) * ( height _scale ) ` ]:["0.0","0.0", ` 0.5 * ( y1 + y2 ) * $ { d } ` ],[S,x,I]=u>1?[ ` $ { ( a - 1 ) / ( u - 1 ) } ` ,"(x2-x1) * width_ratio", ` x1 * $ { m } + float ( x ) * ( width _scale ) ` ]:["0.0","0.0", ` 0.5 * ( x1 + x2 ) * $ { m } ` ];this.userCode= `
const float height _ratio = float ( $ { f } ) ;
const float width _ratio = float ( $ { S } ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int y = coords [ 1 ] ;
int x = coords [ 2 ] ;
int d = coords [ 3 ] ;
// get box vals
float y1 = getBoxes ( b , 0 ) ;
float x1 = getBoxes ( b , 1 ) ;
float y2 = getBoxes ( b , 2 ) ;
float x2 = getBoxes ( b , 3 ) ;
// get image in batch index
int bInd = round ( getBoxInd ( b ) ) ;
if ( bInd < 0 || bInd >= $ { r } ) {
return ;
}
float height _scale = $ { y } ;
float width _scale = $ { x } ;
float in _y = $ { b } ;
if ( in _y < 0.0 || in _y > $ { d } ) {
setOutput ( float ( $ { i } ) ) ;
return ;
}
float in _x = $ { I } ;
if ( in _x < 0.0 || in _x > $ { m } ) {
setOutput ( float ( $ { i } ) ) ;
return ;
}
vec2 sourceFracIndexCR = vec2 ( in _x , in _y ) ;
if ( $ { h } == 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 ) ;
}
}
` }}class px{constructor(e,t,s){this.variableNames=["x"],this.outputShape=e;const n=e.length,i=t?"0.0": ` getX ( $ { V0 ( n , "coords" ) } ) ` ,r=e[e.length-1];let o="",a="";t?(o=s? ` end != $ { r - 1 } ` :"end != 0",a=s?"end + 1":"end - 1"):(o=s? ` end + pow2 < $ { r } ` :"end >= pow2",a=s?"end + pow2":"end - pow2"),this.userCode= `
uniform float index ;
void main ( ) {
$ { Ce ( n ) } coords = getOutputCoords ( ) ;
int end = $ { G0 ( n , "coords" ) } ;
float val = $ { i } ;
int pow2 = int ( pow ( 2.0 , index ) ) ;
if ( $ { o } ) {
int idx = $ { a } ;
$ { G0 ( n , "coords" ) } = idx ;
val += getX ( $ { V0 ( n , "coords" ) } ) ;
}
setOutput ( val ) ;
}
` }getCustomSetupFunc(e){return(t,s)=>{this.index==null&&(this.index=t.getUniformLocation(s,"index")),t.gl.uniform1f(this.index,e)}}}function V0(e,t){if(e===1)return ` $ { t } ` ;if(e===2)return ` $ { t } . x , $ { t } . y ` ;if(e===3)return ` $ { t } . x , $ { t } . y , $ { t } . z ` ;if(e===4)return ` $ { t } . x , $ { t } . y , $ { t } . z , $ { t } . w ` ;throw Error( ` Cumulative sum for rank $ { e } is not yet supported ` )}function G0(e,t){if(e===1)return ` $ { t } ` ;if(e===2)return ` $ { t } . y ` ;if(e===3)return ` $ { t } . z ` ;if(e===4)return ` $ { t } . w ` ;throw Error( ` Cumulative sum for rank $ { e } is not yet supported ` )}class H0{constructor(e){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outPackingScheme=wr.DENSE;const t=xr(e),s=ot();this.outputShape=e,this.userCode= `
ivec3 outCoordsFromFlatIndex ( int index ) {
$ { zn ( [ "r" , "c" , "d" ] , e ) }
return ivec3 ( r , c , d ) ;
}
void main ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { t [ 0 ] } , $ { t [ 1 ] } ) ) ;
int index = 4 * ( resTexRC . x * $ { t [ 1 ] } + resTexRC . y ) ;
vec4 result = vec4 ( 0. ) ;
for ( int i = 0 ; i < 4 ; i ++ ) {
int flatIndex = index + i ;
ivec3 rc = outCoordsFromFlatIndex ( flatIndex ) ;
result [ i ] = getA ( rc . x , rc . y , rc . z ) ;
}
$ { s . output } = result ;
}
` }}class q0{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=wr.DENSE;const t=xr(e),s=ot();this.outputShape=e,this.userCode= `
ivec3 outCoordsFromFlatIndex ( int index ) {
$ { zn ( [ "r" , "c" , "d" ] , e ) }
return ivec3 ( r , c , d ) ;
}
void main ( ) {
ivec2 resTexRC = ivec2 ( resultUV . yx *
vec2 ( $ { t [ 0 ] } , $ { t [ 1 ] } ) ) ;
int index = 4 * ( resTexRC . x * $ { t [ 1 ] } + resTexRC . y ) ;
vec4 result = vec4 ( 0. ) ;
for ( int i = 0 ; i < 4 ; i ++ ) {
int flatIndex = index + i ;
ivec3 rc = outCoordsFromFlatIndex ( flatIndex ) ;
result [ i ] = getChannel ( getA ( rc . x , rc . y , rc . z ) , vec2 ( rc . y , rc . z ) ) ;
}
$ { s . output } = result ;
}
` }}class Y0{constructor(e,t,s){this.variableNames=["x"],this.outputShape=[],this.outputShape=e,this.blockSize=t,this.dataFormat=s,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 ;
float result = $ { this . getInputSamplingString ( ) } ;
setOutput ( result ) ;
}
` }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)"}}class K0{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 ) ;
}
` }}class X0{constructor(e){this.variableNames=["A"],this.outTexUsage=ns.DOWNLOAD;const t=ot();this.outputShape=e,this.userCode= `
$ { Sf }
void main ( ) {
float x = getAAtOutCoords ( ) ;
$ { t . output } = encode _float ( x ) ;
}
` }}class J0{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=ns.DOWNLOAD;const t=ot();this.outputShape=e,this.userCode= `
$ { Sf }
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
float x = getChannel ( getAAtOutCoords ( ) , vec2 ( coords . y , coords . z ) ) ;
$ { t . output } = encode _float ( x ) ;
}
` }}class Z0{constructor(e,t,s=!1){this.variableNames=["A"];const n=ot(),[i,r]=t;this.outputShape=e;let o="result";s&&(o="floor(result * 255. + 0.5)"),this.userCode= `
$ { Ua ( e ) }
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
int flatIndex = getFlatIndex ( coords ) ;
int offset = imod ( flatIndex , 4 ) ;
flatIndex = idiv ( flatIndex , 4 , 1. ) ;
int r = flatIndex / $ { r } ;
int c = imod ( flatIndex , $ { r } ) ;
vec2 uv = ( vec2 ( c , r ) + halfCR ) / vec2 ( $ { r } . 0 , $ { i } . 0 ) ;
vec4 values = $ { n . texture2D } ( A , uv ) ;
float result ;
if ( offset == 0 ) {
result = values [ 0 ] ;
} else if ( offset == 1 ) {
result = values [ 1 ] ;
} else if ( offset == 2 ) {
result = values [ 2 ] ;
} else {
result = values [ 3 ] ;
}
$ { n . output } = vec4 ( $ { o } , 0. , 0. , 0. ) ;
}
` }}class Q0{constructor(e,t,s=!1){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;const n=ot(),[i,r]=t;this.outputShape=e;let o="",a="result";s&&(a="floor(result * 255. + 0.5)");for(let l=0;l<=1;l++)for(let c=0;c<=1;c++){const p=l*2+c;o+= `
localCoords = coords ;
if ( localCoords [ 2 ] + $ { c } < $ { e [ 2 ] } ) {
localCoords [ 2 ] += $ { c } ;
if ( localCoords [ 1 ] + $ { l } < $ { e [ 1 ] } ) {
localCoords [ 1 ] += $ { l } ;
flatIndex = getFlatIndex ( localCoords ) ;
offset = imod ( flatIndex , 4 ) ;
flatIndex = idiv ( flatIndex , 4 , 1. ) ;
r = flatIndex / $ { r } ;
c = imod ( flatIndex , $ { r } ) ;
uv = ( vec2 ( c , r ) + halfCR ) / vec2 ( $ { r } . 0 , $ { i } . 0 ) ;
values = $ { n . texture2D } ( A , uv ) ;
if ( offset == 0 ) {
result [ $ { p } ] = values [ 0 ] ;
} else if ( offset == 1 ) {
result [ $ { p } ] = values [ 1 ] ;
} else if ( offset == 2 ) {
result [ $ { p } ] = values [ 2 ] ;
} else {
result [ $ { p } ] = values [ 3 ] ;
}
}
}
` }this.userCode= `
$ { Ua ( e ) }
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
int flatIndex , r , c , offset ;
ivec3 localCoords ;
vec2 uv ;
vec4 values ;
$ { o }
$ { n . output } = $ { a } ;
}
` }}const ux={REAL:"return real * expR - imag * expI;",IMAG:"return real * expI + imag * expR;"};class hx{constructor(e,t,s){this.variableNames=["real","imag"];const n=t[1];this.outputShape=t;const i=s? ` 2.0 * $ { Math . PI } ` : ` - 2.0 * $ { Math . PI } ` ,r=s? ` $ { n } . 0 ` :"1.0";this.userCode= `
const float exponentMultiplier = $ { i } ;
float unaryOpComplex ( float real , float expR , float imag , float expI ) {
$ { e }
}
float mulMatDFT ( int batch , int index ) {
float indexRatio = float ( index ) / float ( $ { n } ) ;
float exponentMultiplierTimesIndexRatio =
exponentMultiplier * indexRatio ;
float result = 0.0 ;
for ( int i = 0 ; i < $ { n } ; i ++ ) {
// x = (-2|2 * PI / N) * index * i;
float x = exponentMultiplierTimesIndexRatio * float ( i ) ;
float expR = cos ( x ) ;
float expI = sin ( x ) ;
float real = getReal ( batch , i ) ;
float imag = getImag ( batch , i ) ;
result +=
unaryOpComplex ( real , expR , imag , expI ) / $ { r } ;
}
return result ;
}
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
setOutput ( mulMatDFT ( coords [ 0 ] , coords [ 1 ] ) ) ;
}
` }}class eR{constructor(e,t){this.outputShape=[],this.variableNames=["x"],this.outputShape=e,this.userCode= `
uniform float value ;
void main ( ) {
// Input can be obtained from uniform value.
setOutput ( value ) ;
}
` }getCustomSetupFunc(e){return(t,s)=>{this.valueLoc==null&&(this.valueLoc=t.getUniformLocationNoThrow(s,"value")),t.gl.uniform1f(this.valueLoc,e)}}}class tR{constructor(e,t,s){this.variableNames=["A","indices"];const n=e.slice();n[s]=t,this.outputShape=n,this.rank=n.length;const i=Ce(this.rank),r=EB(e,s);this.userCode= `
void main ( ) {
$ { i } resRC = getOutputCoords ( ) ;
setOutput ( getA ( $ { r } ) ) ;
}
` }}function EB(e,t){const s=e.length;if(s>4)throw Error( ` Gather for rank $ { s } is not yet supported ` );if(s===1)return"int(getIndices(resRC))";const n=["resRC.x","resRC.y","resRC.z","resRC.w"],i=[];for(let r=0;r<e.length;r++)r===t?i.push( ` int ( getIndices ( $ { n [ r ] } ) ) ` ):i.push( ` $ { n [ r ] } ` );return i.join()}class sR{constructor(e,t,s){this.sliceDim=e,this.strides=t,this.variableNames=["x","indices"],this.outputShape=s;const n=Ce(t.length),i=Ce(s.length),r=this.sliceDim>1?"strides[j]":"strides";this.userCode= `
$ { n } strides = $ { n } ( $ { this . strides } ) ;
void main ( ) {
$ { i } coords = getOutputCoords ( ) ;
int flattenIndex = 0 ;
for ( int j = 0 ; j < $ { this . sliceDim } ; j ++ ) {
int index = round ( getIndices ( coords [ 0 ] , j ) ) ;
flattenIndex += index * $ { r } ;
}
setOutput ( getX ( flattenIndex , coords [ 1 ] ) ) ;
}
` }}function nR(e){const t=ot(),s= ` $ { t . version }
precision highp float ;
$ { t . attribute } vec3 clipSpacePos ;
$ { t . attribute } vec2 uv ;
$ { t . varyingVs } vec2 resultUV ;
void main ( ) {
gl _Position = vec4 ( clipSpacePos , 1 ) ;
resultUV = uv ;
} ` ;return LC(e,s)}function iR(e){const t=new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]);return IC(e,t)}function rR(e){const t=new Uint16Array([0,1,2,2,1,3]);return AC(e,t)}function $ u(e,t,s,n,i,r){CC(t,s);const o=NC(e),a=e.TEXTURE_2D;return oe(e,()=>e.bindTexture(a,o)),oe(e,()=>e.texParameteri(a,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE)),oe(e,()=>e.texParameteri(a,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)),oe(e,()=>e.texParameteri(a,e.TEXTURE_MIN_FILTER,e.NEAREST)),oe(e,()=>e.texParameteri(a,e.TEXTURE_MAG_FILTER,e.NEAREST)),oe(e,()=>e.texImage2D(a,0,n,t,s,0,i,r,null)),oe(e,()=>e.bindTexture(e.TEXTURE_2D,null)),o}function dx(e){return e.internalFormatFloat}function oR(e,t,s,n){const[i,r]=_o(t,s);return $ u(e,i,r,dx(n),n.textureFormatFloat,e.FLOAT)}function mx(e){return e.internalFormatHalfFloat}function aR(e,t,s,n){const[i,r]=_o(t,s);return $ u(e,i,r,mx(n),n.textureFormatFloat,n.textureTypeHalfFloat)}function fx(e){return e.downloadTextureFormat}function lR(e,t,s,n){const[i,r]=_o(t,s);return $ u(e,i,r,fx(n),e.RGBA,e.UNSIGNED_BYTE)}function gx(e){return e.internalFormatPackedFloat}function cR(e,t,s,n){const[i,r]=oi(t,s);return $ u(e,i,r,gx(n),e.RGBA,e.FLOAT)}function yx(e){return e.internalFormatPackedHalfFloat}function pR(e,t,s,n){const[i,r]=oi(t,s);return $ u(e,i,r,yx(n),e.RGBA,n.textureTypeHalfFloat)}function uR(e,t,s){const n=0,i=3*4,r=3*4+2*4;oe(e,()=>e.bindBuffer(e.ARRAY_BUFFER,s));const o=Yw(e,t,"clipSpacePos",s,3,r,n);return o&&Yw(e,t,"uv",s,2,r,i)}function hR(e,t,s,n,i,r){oe(e,()=>e.bindTexture(e.TEXTURE_2D,t));let o,a,l;i instanceof Uint8Array?(o=new Uint8Array(s*n*4),a=e.UNSIGNED_BYTE,l=e.RGBA):(o=new Float32Array(s*n*4),a=e.FLOAT,l=r.internalFormatPackedFloat),o.set(i),oe(e,()=>e.texImage2D(e.TEXTURE_2D,0,l,s,n,0,e.RGBA,a,o)),oe(e,()=>e.bindTexture(e.TEXTURE_2D,null))}function dR(e,t,s){oe(e,()=>e.bindTexture(e.TEXTURE_2D,t)),s.data instanceof Uint8Array?oe(e,()=>e.texImage2D(e.TEXTURE_2D,0,e.RGBA,s.width,s.height,0,e.RGBA,e.UNSIGNED_BYTE,s.data)):oe(e,()=>e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,s)),oe(e,()=>e.bindTexture(e.TEXTURE_2D,null))}function mR(e,t,s,n){const i=e.createBuffer();oe(e,()=>e.bindBuffer(e.PIXEL_PACK_BUFFER,i));const r=4,o=4,a=r*o*t*s;return oe(e,()=>e.bufferData(e.PIXEL_PACK_BUFFER,a,e.STREAM_READ)),oe(e,()=>e.readPixels(0,0,s,t,e.RGBA,e.FLOAT,0)),oe(e,()=>e.bindBuffer(e.PIXEL_PACK_BUFFER,null)),i}function fR(e,t,s){const n=e,i=new Float32Array(s);return n.bindBuffer(n.PIXEL_PACK_BUFFER,t),n.getBufferSubData(n.PIXEL_PACK_BUFFER,0,i),n.bindBuffer(n.PIXEL_PACK_BUFFER,null),i}function gR(e,t,s,n){const[i,r]=_o(t,s),o=4,a=new Uint8Array(bC(t*s,o));return oe(e,()=>e.readPixels(0,0,i,r,n.downloadTextureFormat,e.UNSIGNED_BYTE,a)),new Float32Array(a.buffer)}function yR(e,t,s,n,i,r,o,a){const l=e,c=new Float32Array(wC(r,o));return l.bindBuffer(l.PIXEL_PACK_BUFFER,t),l.getBufferSubData(l.PIXEL_PACK_BUFFER,0,c),l.bindBuffer(l.PIXEL_PACK_BUFFER,null),c}function bR(e,t,s){const n=new Float32Array(t*s*4);return oe(e,()=>e.readPixels(0,0,s,t,e.RGBA,e.FLOAT,n)),n}class bx{constructor(e){this.outputTexture=null,this.program=null,this.disposed=!1,this.vertexAttrsAreBound=!1,this.itemsToPoll=[];const t= $ ().getNumber("WEBGL_VERSION");e!=null?(this.gl=e,qw(t,e)):this.gl=Js(t);let s="WEBGL_color_buffer_float";const n="EXT_color_buffer_half_float";if( $ ().getNumber("WEBGL_VERSION")===1){const i="OES_texture_float",r="OES_texture_half_float";if(this.textureFloatExtension=Fu(this.gl,i),Zs(this.gl,r))this.textureHalfFloatExtension=Fu(this.gl,r);else if( $ ().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(s),Zs(this.gl,n))this.colorBufferHalfFloatExtension=Fu(this.gl,n);else if( $ ().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(s="EXT_color_buffer_float",Zs(this.gl,s))this.colorBufferFloatExtensi
blockIndex = rc . y + $ { A } ;
pos = rc . x + $ { I } ;
if ( blockIndex < $ { e [ 1 ] } && pos < $ { e [ 0 ] } ) {
offsetY = int ( blockIndex / ( $ { l } ) ) * $ { o } - $ { d } ;
d0 = offsetY + $ { p } * ( pos / $ { m } ) ;
if ( d0 < $ { t [ b ] } && d0 >= 0 ) {
offsetX = int ( mod ( float ( blockIndex ) , $ { l } . ) * $ { r } . - $ { h } . ) ;
d1 = offsetX + $ { c } * ( int ( mod ( float ( pos ) , $ { m } . ) / $ { i } . ) ) ;
if ( d1 < $ { t [ S ] } && d1 >= 0 ) {
ch = int ( mod ( float ( pos ) , $ { i } . ) ) ;
if ( $ { y } ) {
innerDims = vec2 ( d1 , ch ) ;
result [ $ { I * 2 + A } ] = getChannel (
getA ( d0 , int ( innerDims . x ) ,
int ( innerDims . y ) ) , innerDims ) ;
} else {
innerDims = vec2 ( d0 , d1 ) ;
result [ $ { I * 2 + A } ] = getChannel (
getA ( ch , int ( innerDims . x ) ,
int ( innerDims . y ) ) , innerDims ) ;
}
}
}
}
` ;this.userCode= `
void main ( ) {
ivec2 rc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0 ) ;
int blockIndex , pos , offsetY , d0 , offsetX , d1 , ch ;
vec2 innerDims ;
$ { x }
$ { f . output } = result ;
}
` }}class TR{constructor(e,t,s,n,i){this.variableNames=["x"],this.outputShape=[];const r=t,o=e[3]-1;this.outputShape=e;let a;const l= ` float ( $ { s } ) + float ( $ { n } ) * sum ` ;i===.5?a= ` inversesqrt ( $ { l } ) ` :i===1?a= ` 1.0 / ( $ { l } ) ` :a= ` exp ( log ( $ { l } ) * float ( - $ { i } ) ) ; ` ,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 = - $ { r } ; j <= $ { r } ; j ++ ) {
int idx = d + j ;
if ( idx >= 0 && idx <= $ { o } ) {
float z = getX ( b , r , c , idx ) ;
sum += z * z ;
}
}
float val = x * $ { a } ;
setOutput ( val ) ;
}
` }}class IR{constructor(e,t,s,n,i){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=e,this.depth=e[3],this.depthRadius=t,this.bias=s,this.alpha=n,this.beta=i,this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int r = coords [ 1 ] ;
int c = coords [ 2 ] ;
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 ;
}
}
norm = float ( $ { n } ) * norm + float ( $ { s } ) ;
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 ( $ { n } )
* float ( $ { i } )
* getInputImage ( b , r , c , k ) * getOutputImage ( b , r , c , d )
/ n o r m ;
if ( k == d ) {
dyi += pow ( norm , - 1.0 * $ { i } ) ;
}
if ( k == coords [ 3 ] ) {
dyi *= getDy ( b , r , c , d ) ;
result += dyi ;
}
}
else {
break ;
}
}
}
setOutput ( result ) ;
}
` }}class AR{constructor(e,t,s,n,i){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;const r=t,o=e[3]-1;this.outputShape=e;let a;const l= ` float ( $ { s } ) + float ( $ { n } ) * sum ` ;i===.5?a= ` inversesqrt ( $ { l } ) ` :i===1?a= ` 1.0 / ( $ { l } ) ` :a= ` exp ( log ( $ { l } ) * float ( - $ { i } ) ) ; ` ,this.userCode= `
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords . x ;
int r = coords . y ;
int c = coords . z ;
int d = coords . w ;
bool hasNextCol = d < $ { this . outputShape [ 3 ] } ;
bool hasNextRow = c < $ { this . outputShape [ 2 ] } ;
vec4 sum = vec4 ( 0. ) ;
vec4 xFragAtOutputCoords = getX ( b , r , c , d ) ;
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
) ;
int firstChannel = d - $ { r } ;
vec2 cache = vec2 ( 0. ) ;
if ( firstChannel >= 0 ) {
vec4 firstChannelFrag = getX ( b , r , c , firstChannel ) ;
cache . x = getChannel ( firstChannelFrag , vec2 ( c , firstChannel ) ) ;
if ( hasNextRow ) {
cache . y = getChannel ( firstChannelFrag , vec2 ( c + 1 , firstChannel ) ) ;
}
}
ivec2 depth = ivec2 ( d , d + 1 ) ;
for ( int j = - $ { r } ; j <= $ { r } ; j ++ ) {
ivec2 idx = depth + j ;
bvec2 aboveLowerBound = greaterThanEqual ( idx , ivec2 ( 0 ) ) ;
bvec2 belowUpperBound = lessThanEqual ( idx , ivec2 ( $ { o } ) ) ;
bool depthInRange = aboveLowerBound . x && belowUpperBound . x ;
bool depthPlusOneInRange = aboveLowerBound . y && belowUpperBound . y ;
if ( depthInRange || depthPlusOneInRange ) {
vec4 z = vec4 ( 0. ) ;
vec4 xFragAtCurrentDepth ;
z . xz = cache . xy ;
if ( depthPlusOneInRange && hasNextCol ) {
xFragAtCurrentDepth = idx . y != d ?
getX ( b , r , c , idx . y ) : xFragAtOutputCoords ;
z . y = getChannel ( xFragAtCurrentDepth , vec2 ( c , idx . y ) ) ;
if ( hasNextRow ) {
z . w = getChannel ( xFragAtCurrentDepth , vec2 ( c + 1 , idx . y ) ) ;
}
}
cache . xy = z . yw ;
sum += z * z ;
}
}
vec4 result = xAtOutputCoords * $ { a } ;
setOutput ( result ) ;
}
` }}class NR{constructor(e){this.variableNames=["dy","maxPos"],this.outputShape=e.inShape;const t=e.strideHeight,s=e.strideWidth,n=e.dilationHeight,i=e.effectiveFilterHeight,r=e.effectiveFilterWidth,o=i-1-e.padInfo.top,a=r-1-e.padInfo.left,l=i*r-1;this.userCode= `
const ivec2 pads = ivec2 ( $ { o } , $ { a } ) ;
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 ;
for ( int wR = 0 ; wR < $ { i } ;
wR += $ { n } ) {
float dyR = float ( dyRCorner + wR ) / $ { t } . 0 ;
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 || fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
for ( int wC = 0 ; wC < $ { r } ; wC ++ ) {
float dyC = float ( dyCCorner + wC ) / $ { s } . 0 ;
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 = $ { l } - int ( getMaxPos ( b , idyR , idyC , d ) ) ;
// Get the current value, check it against the value from the
// position matrix.
int curPosValue = wR * $ { r } + wC ;
float mask = float ( maxPosValue == curPosValue ? 1.0 : 0.0 ) ;
dotProd += dyValue * mask ;
}
}
setOutput ( dotProd ) ;
}
` }}class CR{constructor(e){this.variableNames=["dy","maxPos"],this.outputShape=e.inShape;const t=e.strideDepth,s=e.strideHeight,n=e.strideWidth,i=e.dilationDepth,r=e.dilationHeight,o=e.dilationWidth,a=e.effectiveFilterDepth,l=e.effectiveFilterHeight,c=e.effectiveFilterWidth,p=a-1-e.padInfo.front,u=l-1-e.padInfo.top,h=c-1-e.padInfo.left,d=a*l*c-1;this.userCode= `
const ivec3 pads = ivec3 ( $ { p } , $ { u } , $ { h } ) ;
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
ivec3 dyCorner = ivec3 ( coords . y , coords . z , coords . w ) - pads ;
int dyDCorner = dyCorner . x ;
int dyRCorner = dyCorner . y ;
int dyCCorner = dyCorner . z ;
// Convolve dy(?, ?, ?, ch) with pos mask(:, :, :, d) to get
// dx(xD, xR, xC, ch).
// ? = to be determined. : = across all values in that axis.
float dotProd = 0.0 ;
for ( int wD = 0 ; wD < $ { a } ;
wD += $ { i } ) {
float dyD = float ( dyDCorner + wD ) / $ { t } . 0 ;
if ( dyD < 0.0 || dyD >= $ { e . outDepth } . 0 || fract ( dyD ) > 0.0 ) {
continue ;
}
int idyD = int ( dyD ) ;
for ( int wR = 0 ; wR < $ { l } ;
wR += $ { r } ) {
float dyR = float ( dyRCorner + wR ) / $ { s } . 0 ;
if ( dyR < 0.0 || dyR >= $ { e . outHeight } . 0 ||
fract ( dyR ) > 0.0 ) {
continue ;
}
int idyR = int ( dyR ) ;
for ( int wC = 0 ; wC < $ { c } ;
wC += $ { o } ) {
float dyC = float ( dyCCorner + wC ) / $ { n } . 0 ;
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 * $ { l } * $ { c } +
wR * $ { c } + wC ;
float mask = float ( maxPosValue == curPosValue ? 1.0 : 0.0 ) ;
dotProd += dyValue * mask ;
}
}
}
setOutput ( dotProd ) ;
}
` }}class Af{constructor(e,t,s=!1,n=!1,i=!1,r=null,o=!1){this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t;const a=s?e[1]:e[2],l=Math.ceil(a/2),c=s?"i * 2, rc.y":"rc.y, i * 2",p=n?"rc.z, i * 2":"i * 2, rc.z",u=s?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],h=n?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"];let d="",m="";r&&(o?d= ` vec4 activation ( vec4 a ) {
vec4 b = getPreluActivationWeightsAtOutCoords ( ) ;
$ { r }
} ` :d= ` vec4 activation ( vec4 x ) {
$ { r }
} ` ,m="result = activation(result);");const f=i?"result += getBiasAtOutCoords();":"";i&&this.variableNames.push("bias"),o&&this.variableNames.push("preluActivationWeights"),this.userCode= `
$ { d }
const float sharedDimension = $ { l } . 0 ;
vec4 dot2x2ARowBCol ( ivec3 rc ) {
vec4 result = vec4 ( 0 ) ;
for ( int i = 0 ; i < $ { l } ; i ++ ) {
vec4 a = getMatrixA ( rc . x , $ { c } ) ;
vec4 b = getMatrixB ( rc . x , $ { p } ) ;
// These swizzled products need to be separately added.
// See: https://github.com/tensorflow/tfjs/issues/1735
result += ( $ { u [ 0 ] } * $ { h [ 0 ] } ) ;
result += ( $ { u [ 1 ] } * $ { h [ 1 ] } ) ;
}
return result ;
}
void main ( ) {
ivec3 rc = getOutputCoords ( ) ;
vec4 result = dot2x2ARowBCol ( rc ) ;
$ { f }
$ { m }
setOutput ( result ) ;
}
` }}class RR{constructor(e,t,s){this.variableNames=["probs"],this.outputShape=[e,s],this.userCode= `
uniform float seed ;
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
float r = random ( seed ) ;
float cdf = 0.0 ;
for ( int i = 0 ; i < $ { t - 1 } ; i ++ ) {
cdf += getProbs ( batch , i ) ;
if ( r < cdf ) {
setOutput ( float ( i ) ) ;
return ;
}
}
// If no other event happened, last event happened.
setOutput ( float ( $ { t - 1 } ) ) ;
}
` }getCustomSetupFunc(e){return(t,s)=>{this.seedLoc==null&&(this.seedLoc=t.getUniformLocation(s,"seed")),t.gl.uniform1f(this.seedLoc,e)}}}class OR{constructor(e,t,s,n){this.variableNames=["indices"],this.outputShape=[e,t],this.userCode= `
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int index = round ( getIndices ( coords . x ) ) ;
setOutput ( mix ( float ( $ { n } ) , float ( $ { s } ) ,
float ( index == coords . y ) ) ) ;
}
` }}class ER{constructor(e){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outputShape=e;const t=e.length;if(t===0)this.userCode= `
void main ( ) {
setOutput ( vec4 ( getA ( ) , 0. , 0. , 0. ) ) ;
}
` ;else{const s=Et("rc",t),n=Ce(t),i=_B(t,e,s),r=DB(t,e[e.length-1],e[e.length-2],s),o=FB(e,s);this.userCode= `
void main ( ) {
$ { n } rc = getOutputCoords ( ) ;
if ( $ { i } ) {
setOutput ( vec4 ( 0 ) ) ;
} else {
$ { r }
setOutput ( vec4 ( $ { o } ) ) ;
}
}
` }}}function MB(e,t){const s=[];for(let n=0;n<=1;n++)for(let i=0;i<=1;i++){let r= ` $ { n === 0 ? "r" : "rp1" } , $ { i === 0 ? "c" : "cp1" } ` ;for(let o=2;o<e;o++)r= ` $ { t [ t . length - 1 - o ] } , ` +r;s.push(r)}return s}function _B(e,t,s){if(e===1)return ` rc > $ { t [ 0 ] } ` ;let n="";for(let i=e-2;i<e;i++)n+= ` $ { s [ i ] } >= $ { t [ i ] } ` ,i<e-1&&(n+="||");return n}function DB(e,t,s,n){if(e===1)return"";const i=n.slice(-2);return `
int r = $ { i [ 0 ] } ;
int c = $ { i [ 1 ] } ;
int rp1 = r + 1 ;
int cp1 = c + 1 ;
bool cEdge = cp1 >= $ { t } ;
bool rEdge = rp1 >= $ { s } ;
` }function FB(e,t){const s=e.length,n=MB(s,t);return s===1? ` getA ( rc ) ,
rc + 1 >= $ { e [ 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 ] } ) ` }class kR{constructor(e,t,s){this.variableNames=["x"],this.outputShape=t.map((l,c)=>l[0]+e[c]+l[1]);const n=e.length,i=Ce(n),r=t.map(l=>l[0]).join(","),o=t.map((l,c)=>l[0]+e[c]).join(","),a=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,n);if(n===1){this.userCode= `
int start = $ { r } ;
int end = $ { o } ;
void main ( ) {
int outC = getOutputCoords ( ) ;
if ( outC < start || outC >= end ) {
setOutput ( float ( $ { s } ) ) ;
} else {
setOutput ( getX ( outC - start ) ) ;
}
}
` ;return}this.userCode= `
$ { i } start = $ { i } ( $ { r } ) ;
$ { i } end = $ { i } ( $ { o } ) ;
void main ( ) {
$ { i } outC = getOutputCoords ( ) ;
if ( any ( lessThan ( outC , start ) ) || any ( greaterThanEqual ( outC , end ) ) ) {
setOutput ( float ( $ { s } ) ) ;
} else {
$ { i } coords = outC - start ;
setOutput ( getX ( $ { a } ) ) ;
}
}
` }}class _R{constructor(e,t,s){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t.map((m,f)=>m[0]+e[f]+m[1]);const n=e.length,i=Ce(n),r=t.map(m=>m[0]).join(","),o=t.map((m,f)=>m[0]+e[f]).join(","),a=Et("rc",n),l=Et("source",n),c= ` $ { a [ n - 1 ] } < $ { this . outputShape [ n - 1 ] } ` ,p=n===1?"source": ` vec2 ( $ { l . slice ( - 2 ) . join ( ) } ) ` ,u=[ ` $ { i } rc = outputLoc ; ` , ` $ { a [ n - 1 ] } += 1 ;
if ( $ { c } ) {
` ,n===1?"": ` }
rc = outputLoc ;
$ { a [ n - 2 ] } += 1 ;
if ( $ { a [ n - 2 ] } < $ { this . outputShape [ n - 2 ] } ) { ` ,n===1?"": ` $ { a [ n - 1 ] } += 1 ;
if ( $ { c } ) { ` ],h=n===1?"rc < start || rc >= end":"any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))";let d="";for(let m=0,f=n===1?2:4;m<f;m++)d+= `
$ { u [ m ] }
if ( $ { h } ) {
result [ $ { m } ] = float ( $ { s } ) ;
} else {
$ { i } source = rc - start ;
result [ $ { m } ] = getChannel ( getX ( $ { l . join ( ) } ) , $ { p } ) ;
}
` ;d+=n===1?"} ":"}}",this.userCode= `
const $ { i } start = $ { i } ( $ { r } ) ;
const $ { i } end = $ { i } ( $ { o } ) ;
void main ( ) {
$ { i } outputLoc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
$ { d }
setOutput ( result ) ;
}
` }}class Fo{constructor(e,t,s,n=!1,i=!1){if(this.variableNames=["x"],t==="avg"&&s)throw new Error("Cannot compute positions for average pool.");const r=e.filterWidth,o=e.strideHeight,a=e.strideWidth,l=e.dilationHeight,c=e.dilationWidth,p=e.effectiveFilterHeight,u=e.effectiveFilterWidth,h=e.padInfo.top,d=e.padInfo.left;this.outputShape=e.outShape;const m=t==="avg",f= ` ( ( batch * $ { e . inHeight } + xR ) * $ { e . inWidth } + xC ) * $ { e . inChannels } + d ` ,y= ` ( xR * $ { e . inWidth } + xC ) * $ { e . inChannels } + d ` ;let b="0.0";if(m||(b="-1.0 / 1e-20"),s){const R=">=";this.userCode= `
const ivec2 strides = ivec2 ( $ { o } , $ { a } ) ;
const ivec2 pads = ivec2 ( $ { h } , $ { d } ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 xRCCorner = coords . yz * strides - pads ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
float minMaxValue = 0.0 ;
float minMaxValueFound = 0.0 ;
int minMaxPosition = 0 ;
float avgValue = 0.0 ;
for ( int wR = 0 ; wR < $ { p } ;
wR += $ { l } ) {
int xR = xRCorner + wR ;
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
for ( int wC = 0 ; wC < $ { u } ;
wC += $ { c } ) {
int xC = xCCorner + wC ;
if ( xC < 0 || xC >= $ { e . inWidth } ) {
continue ;
}
float value = getX ( batch , xR , xC , d ) ;
// 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 = $ { n ? i ? f : y : ` wR * ${ u } + wC ` } ;
}
}
}
setOutput ( float ( minMaxPosition ) ) ;
}
` ;return}const S="max";let x= ` $ { t } ( $ { t } ( $ { t } ( minMaxValue [ 0 ] , minMaxValue [ 1 ] ) , minMaxValue [ 2 ] ) , minMaxValue [ 3 ] ) ` ;t==="avg"&&(x="avgValue / count");const I=Math.floor(r/4)*4,A=r%4,k= `
if ( $ { m } ) {
avgValue += dot ( values , ones ) ;
} else {
minMaxValue = $ { S } ( values , minMaxValue ) ;
}
` ;this.userCode= `
const ivec2 strides = ivec2 ( $ { o } , $ { a } ) ;
const ivec2 pads = ivec2 ( $ { h } , $ { d } ) ;
const float initializationValue = $ { b } ;
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
float count = 0.0 ;
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 ) ;
}
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 xRCCorner = coords . yz * strides - pads ;
int xRCorner = xRCCorner . x ;
int xCCorner = xRCCorner . y ;
// max/min x(?, ?, d) to get y(yR, yC, d).
// ? = to be determined
vec4 minMaxValue = vec4 ( $ { b } ) ;
float avgValue = 0.0 ;
count = 0.0 ;
for ( int wR = 0 ; wR < $ { p } ;
wR += $ { l } ) {
int xR = xRCorner + wR ;
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
for ( int wC = 0 ; wC < $ { I } ; wC += 4 ) {
int xC = xCCorner + wC * $ { c } ;
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 )
) ;
$ { k }
}
int xC = xCCorner + $ { I } ;
if ( $ { A === 1 } ) {
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
$ { k }
} else if ( $ { A === 2 } ) {
vec4 values = vec4 (
getValue ( batch , xR , xC , d ) ,
getValue ( batch , xR , xC + $ { c } , d ) ,
initializationValue ,
initializationValue
) ;
$ { k }
} 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
) ;
$ { k }
}
}
setOutput ( $ { x } ) ;
}
` }}class Nf{constructor(e,t,s,n=!1,i=!1){if(this.variableNames=["x"],t==="avg"&&s)throw new Error("Cannot compute positions for average pool.");const r=e.filterWidth,o=e.strideDepth,a=e.strideHeight,l=e.strideWidth,c=e.dilationDepth,p=e.dilationHeight,u=e.dilationWidth,h=e.effectiveFilterDepth,d=e.effectiveFilterHeight,m=e.effectiveFilterWidth,f=e.padInfo.front,y=e.padInfo.top,b=e.padInfo.left;this.outputShape=e.outShape;const S=t==="avg";let x="0.0";if(S||(x="-1.0 / 1e-20"),s){const F=">=";this.userCode= `
const ivec3 strides =
ivec3 ( $ { o } , $ { a } , $ { l } ) ;
const ivec3 pads = ivec3 ( $ { f } , $ { y } , $ { b } ) ;
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
ivec3 xCorner = ivec3 ( coords . y , coords . z , coords . w ) * strides - pads ;
int xDCorner = xCorner . x ;
int xRCorner = xCorner . y ;
int xCCorner = xCorner . z ;
// max/min x(?, ?, ?, ch) to get y(yD, yR, yC, ch).
// ? = to be determined
float minMaxValue = 0.0 ;
float minMaxValueFound = 0.0 ;
int minMaxPosition = 0 ;
for ( int wD = 0 ; wD < $ { h } ;
wD += $ { c } ) {
int xD = xDCorner + wD ;
if ( xD < 0 || xD >= $ { e . inDepth } ) {
continue ;
}
for ( int wR = 0 ; wR < $ { d } ;
wR += $ { p } ) {
int xR = xRCorner + wR ;
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
for ( int wC = 0 ; wC < $ { m } ;
wC += $ { u } ) {
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 $ { F } currMinMaxValue ) {
minMaxValue = value ;
minMaxValueFound = 1.0 ;
minMaxPosition = $ { n ? i ? ` (((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 } * ${ m } +
wR * $ { m } + wC ` };
}
}
}
}
setOutput ( float ( minMaxPosition ) ) ;
}
` ;return}const I="max";let A= ` $ { t } ( $ { t } ( $ { t } ( minMaxValue [ 0 ] , minMaxValue [ 1 ] ) , minMaxValue [ 2 ] ) , minMaxValue [ 3 ] ) ` ;t==="avg"&&(A="avgValue / count");const k=Math.floor(r/4)*4,R=r%4,D= `
if ( $ { S } ) {
avgValue += dot ( values , ones ) ;
} else {
minMaxValue = $ { I } ( values , minMaxValue ) ;
}
` ;this.userCode= `
const ivec3 strides =
ivec3 ( $ { o } , $ { a } , $ { l } ) ;
const ivec3 pads = ivec3 ( $ { f } , $ { y } , $ { b } ) ;
const float initializationValue = $ { x } ;
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
float count = 0.0 ;
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 ) ;
}
void main ( ) {
ivec5 coords = getOutputCoords ( ) ;
int batch = coords . x ;
int ch = coords . u ;
ivec3 xCorner = ivec3 ( coords . y , coords . z , coords . w ) * strides - pads ;
int xDCorner = xCorner . x ;
int xRCorner = xCorner . y ;
int xCCorner = xCorner . z ;
// max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).
// ? = to be determined
vec4 minMaxValue = vec4 ( $ { x } ) ;
float avgValue = 0.0 ;
count = 0.0 ;
for ( int wD = 0 ; wD < $ { h } ;
wD += $ { c } ) {
int xD = xDCorner + wD ;
if ( xD < 0 || xD >= $ { e . inDepth } ) {
continue ;
}
for ( int wR = 0 ; wR < $ { d } ;
wR += $ { p } ) {
int xR = xRCorner + wR ;
if ( xR < 0 || xR >= $ { e . inHeight } ) {
continue ;
}
for ( int wC = 0 ; wC < $ { k } ; wC += 4 ) {
int xC = xCCorner + wC * $ { u } ;
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
getValue ( batch , xD , xR , xC + $ { u } , ch ) ,
getValue ( batch , xD , xR , xC + 2 * $ { u } , ch ) ,
getValue ( batch , xD , xR , xC + 3 * $ { u } , ch )
) ;
$ { D }
}
int xC = xCCorner + $ { k } ;
if ( $ { R === 1 } ) {
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
$ { D }
} else if ( $ { R === 2 } ) {
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
getValue ( batch , xD , xR , xC + $ { u } , ch ) ,
initializationValue ,
initializationValue
) ;
$ { D }
} else if ( $ { R === 3 } ) {
vec4 values = vec4 (
getValue ( batch , xD , xR , xC , ch ) ,
getValue ( batch , xD , xR , xC + $ { u } , ch ) ,
getValue ( batch , xD , xR , xC + 2 * $ { u } , ch ) ,
initializationValue
) ;
$ { D }
}
}
setOutput ( $ { A } ) ;
}
}
` }}class Cf{constructor(e,t){this.variableNames=["x"];const s=e.windowSize,n=e.batchSize,i=e.inSize,r=Math.ceil(i/s);this.outputShape=[n,r];let o="0.0",a="";t==="prod"?o="1.0":t==="min"?(o="1.0 / 1e-20",a="min"):t==="max"&&(o="-1.0 / 1e-20",a="max");let l= ` $ { t } ( $ { t } ( $ { t } ( minMaxValue [ 0 ] , minMaxValue [ 1 ] ) , minMaxValue [ 2 ] ) , minMaxValue [ 3 ] ) ` ;t==="sum"?l="sumValue":t==="prod"?l="prodValue":t==="all"?l="allValue":t==="any"&&(l="anyValue");const c=Math.floor(s/4)*4,p=s%4;let u= `
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 = $ { a } ( values , minMaxValue ) ;
}
` ,h="vec4";t==="all"?(o="1.0",u= `
bool reducedAllValue = all ( values ) ;
float floatedReducedAllValue = float ( reducedAllValue ) ;
allValue = float ( allValue >= 1.0 && floatedReducedAllValue >= 1.0 ) ;
` ,h="bvec4"):t==="any"&&(o="0.0",u= `
bool reducedAnyValue = any ( values ) ;
float floatedReducedAnyValue = float ( reducedAnyValue ) ;
anyValue = float ( anyValue >= 1.0 || floatedReducedAnyValue >= 1.0 ) ;
` ,h="bvec4");let d="";i%s>0&&(d= `
if ( inIdx < 0 || inIdx >= $ { i } ) {
return initializationValue ;
}
` ),this.userCode= `
const float initializationValue = $ { o } ;
const vec4 ones = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
float getValue ( int batch , int inIdx ) {
$ { d }
return getX ( batch , inIdx ) ;
}
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
int inOffset = outIdx * $ { s } ;
vec4 minMaxValue = vec4 ( $ { o } ) ;
float prodValue = 1.0 ;
float sumValue = 0.0 ;
float allValue = 1.0 ;
float anyValue = 0.0 ;
for ( int i = 0 ; i < $ { c } ; i += 4 ) {
int inIdx = inOffset + i ;
$ { h } values = $ { h } (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
getValue ( batch , inIdx + 3 )
) ;
$ { u }
}
int inIdx = inOffset + $ { c } ;
if ( $ { p === 1 } ) {
$ { h } values = $ { h } (
getValue ( batch , inIdx ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
$ { u }
} else if ( $ { p === 2 } ) {
$ { h } values = $ { h } (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
initializationValue ,
initializationValue
) ;
$ { u }
} else if ( $ { p === 3 } ) {
$ { h } values = $ { h } (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
initializationValue
) ;
$ { u }
}
setOutput ( $ { l } ) ;
}
` }}class Rf{constructor(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e;let s="";for(let n=0;n<4;n++){let i="thisRC = rc;";n%2===1&&(i+="thisRC.z += 1;"),n>1&&(i+="thisRC.y += 1;"),s+= `
$ { i }
$ { n > 0 ? "if(thisRC.y < rows && thisRC.z < cols){" : "" }
int flatIndex = getFlatIndex ( thisRC ) ;
ivec3 inputRC = inputCoordsFromReshapedOutCoords ( flatIndex ) ;
vec2 inputRCInnerDims = vec2 ( float ( inputRC . y ) , float ( inputRC . z ) ) ;
result [ $ { n } ] =
getChannel ( getA ( inputRC . x , inputRC . y , inputRC . z ) , inputRCInnerDims ) ;
$ { n > 0 ? "}" : "" }
` }this.userCode= `
$ { UB ( t ) }
$ { Ua ( e ) }
void main ( ) {
ivec3 rc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
ivec3 thisRC ;
int rows = $ { e [ 1 ] } ;
int cols = $ { e [ 2 ] } ;
$ { s }
setOutput ( result ) ;
}
` }}function UB(e){const t=zn(["r","c","d"],e);return `
ivec3 inputCoordsFromReshapedOutCoords ( int index ) {
$ { t }
return ivec3 ( r , c , d ) ;
}
` }class DR{constructor(e,t,s){this.variableNames=["dy"],this.outputShape=[],this.outputShape=t.shape;const[,n,i]=t.shape,[,r,o]=e.shape,a=[s&&r>1?n-1:n,s&&o>1?i-1:i],l=[s&&r>1?r-1:r,s&&o>1?o-1:o],c=a[0]/l[0],p=a[1]/l[1],u=1/c,h=1/p,d=Math.ceil(u)*2+2,m=Math.ceil(h)*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 ] ;
float accumulator = 0.0 ;
const float heightScale = float ( $ { c } ) ;
const float widthScale = float ( $ { p } ) ;
const float invHeightScale = float ( $ { u } ) ;
const float invWidthScale = float ( $ { h } ) ;
const int winHeight = int ( $ { d } ) ;
const int winWidth = int ( $ { m } ) ;
// Compute bounds for where in dy we will look
float startRLerp = floor ( float ( r ) * invHeightScale ) ;
int startDyR = int ( startRLerp - float ( winHeight / 2 ) ) ;
float startCLerp = floor ( float ( c ) * invWidthScale ) ;
int startDyC = int ( startCLerp - float ( winWidth / 2 ) ) ;
// Loop over dy
for ( int dyROffset = 0 ; dyROffset < winHeight ; dyROffset ++ ) {
int dyR = dyROffset + startDyR ;
// Guard against the window exceeding the bounds of dy
if ( dyR < 0 || dyR >= $ { r } ) {
continue ;
}
for ( int dyCOffset = 0 ; dyCOffset < winWidth ; dyCOffset ++ ) {
int dyC = dyCOffset + startDyC ;
// Guard against the window exceeding the bounds of dy
if ( dyC < 0 || dyC >= $ { o } ) {
continue ;
}
float dxR = float ( dyR ) * heightScale ;
int topDxRIndex = int ( floor ( dxR ) ) ;
int bottomDxRIndex = int ( min ( ceil ( dxR ) , $ { n - 1 } . 0 ) ) ;
float dxRLerp = dxR - float ( topDxRIndex ) ;
float inverseDxRLerp = 1.0 - dxRLerp ;
float dxC = float ( dyC ) * widthScale ;
int leftDxCIndex = int ( floor ( dxC ) ) ;
int rightDxCIndex = int ( min ( ceil ( dxC ) , $ { i - 1 } . 0 ) ) ;
float dxCLerp = dxC - float ( leftDxCIndex ) ;
float inverseDxCLerp = 1.0 - dxCLerp ;
if ( r == topDxRIndex && c == leftDxCIndex ) {
// topLeft
accumulator +=
getDy ( b , dyR , dyC , d ) * inverseDxRLerp * inverseDxCLerp ;
}
if ( r == topDxRIndex && c == rightDxCIndex ) {
// topRight
accumulator += getDy ( b , dyR , dyC , d ) * inverseDxRLerp * dxCLerp ;
}
if ( r == bottomDxRIndex && c == leftDxCIndex ) {
// bottomLeft
accumulator += getDy ( b , dyR , dyC , d ) * dxRLerp * inverseDxCLerp ;
}
if ( r == bottomDxRIndex && c == rightDxCIndex ) {
// bottomRight
accumulator += getDy ( b , dyR , dyC , d ) * dxRLerp * dxCLerp ;
}
}
}
// End loop over dy
setOutput ( accumulator ) ;
}
` }}class FR{constructor(e,t,s,n){this.variableNames=["A"],this.outputShape=[];const[i,r,o,a]=e;this.outputShape=[i,t,s,a];const l=[n&&t>1?r-1:r,n&&s>1?o-1:o],c=[n&&t>1?t-1:t,n&&s>1?s-1:s];this.userCode= `
const vec2 effectiveInputOverOutputRatioRC = vec2 (
$ { l [ 0 ] / c [ 0 ] } ,
$ { l [ 1 ] / c [ 1 ] } ) ;
const vec2 inputShapeRC = vec2 ( $ { r } . 0 , $ { o } . 0 ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 yRC = coords . yz ;
// Fractional source index.
vec2 sourceFracIndexRC = vec2 ( yRC ) * effectiveInputOverOutputRatioRC ;
// Compute the four integer indices.
ivec2 sourceFloorRC = ivec2 ( sourceFracIndexRC ) ;
ivec2 sourceCeilRC = ivec2 (
min ( inputShapeRC - 1.0 , ceil ( sourceFracIndexRC ) ) ) ;
float topLeft = getA ( b , sourceFloorRC . x , sourceFloorRC . y , d ) ;
float bottomLeft = getA ( b , sourceCeilRC . x , sourceFloorRC . y , d ) ;
float topRight = getA ( b , sourceFloorRC . x , sourceCeilRC . y , d ) ;
float bottomRight = getA ( b , sourceCeilRC . x , sourceCeilRC . y , d ) ;
vec2 fracRC = sourceFracIndexRC - vec2 ( sourceFloorRC ) ;
float top = topLeft + ( topRight - topLeft ) * fracRC . y ;
float bottom = bottomLeft + ( bottomRight - bottomLeft ) * fracRC . y ;
float newValue = top + ( bottom - top ) * fracRC . x ;
setOutput ( newValue ) ;
}
` }}class MR{constructor(e,t,s,n){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];const[i,r,o,a]=e;this.outputShape=[i,t,s,a];const l=[n&&t>1?r-1:r,n&&s>1?o-1:o],c=[n&&t>1?t-1:t,n&&s>1?s-1:s];this.userCode= `
const vec3 effectiveInputOverOutputRatioRC = vec3 (
$ { l [ 0 ] / c [ 0 ] } ,
$ { l [ 1 ] / c [ 1 ] } ,
$ { l [ 1 ] / c [ 1 ] } ) ;
const vec3 inputShapeRC = vec3 ( $ { r } . 0 , $ { o } . 0 ,
$ { o } . 0 ) ;
float getAValue ( int b , int r , int c , int d ) {
return getChannel ( getA ( b , r , c , d ) , vec2 ( c , d ) ) ;
}
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 ) ;
// Fractional source index.
vec3 sourceFracIndexRC = vec3 ( yRC ) * effectiveInputOverOutputRatioRC ;
// Compute the four integer indices.
ivec3 sourceFloorRC = ivec3 ( sourceFracIndexRC ) ;
ivec3 sourceCeilRC = ivec3 (
min ( inputShapeRC - 1.0 , ceil ( sourceFracIndexRC ) ) ) ;
// Should we calculate next column and row elements in 2x2 packed cell.
bool hasNextCol = d < $ { a - 1 } ;
bool hasNextRow = coords . z < $ { s - 1 } ;
// In parallel, construct four corners for all four components in
// packed 2x2 cell.
vec4 topLeft = vec4 (
getAValue ( b , sourceFloorRC . x , sourceFloorRC . y , d ) ,
hasNextCol ? getAValue ( b , sourceFloorRC . x , sourceFloorRC . y , d + 1 )
: 0.0 ,
hasNextRow ? getAValue ( b , sourceFloorRC . x , sourceFloorRC . z , d )
: 0.0 ,
( hasNextRow && hasNextCol ) ?
getAValue ( b , sourceFloorRC . x , sourceFloorRC . z , d + 1 ) : 0.0 ) ;
vec4 bottomLeft = vec4 (
getAValue ( b , sourceCeilRC . x , sourceFloorRC . y , d ) ,
hasNextCol ? getAValue ( b , sourceCeilRC . x , sourceFloorRC . y , d + 1 )
: 0.0 ,
hasNextRow ? getAValue ( b , sourceCeilRC . x , sourceFloorRC . z , d )
: 0.0 ,
( hasNextRow && hasNextCol ) ?
getAValue ( b , sourceCeilRC . x , sourceFloorRC . z , d + 1 ) : 0.0 ) ;
vec4 topRight = vec4 (
getAValue ( b , sourceFloorRC . x , sourceCeilRC . y , d ) ,
hasNextCol ? getAValue ( b , sourceFloorRC . x , sourceCeilRC . y , d + 1 )
: 0.0 ,
hasNextRow ? getAValue ( b , sourceFloorRC . x , sourceCeilRC . z , d )
: 0.0 ,
( hasNextRow && hasNextCol ) ?
getAValue ( b , sourceFloorRC . x , sourceCeilRC . z , d + 1 ) : 0.0 ) ;
vec4 bottomRight = vec4 (
getAValue ( b , sourceCeilRC . x , sourceCeilRC . y , d ) ,
hasNextCol ? getAValue ( b , sourceCeilRC . x , sourceCeilRC . y , d + 1 )
: 0.0 ,
hasNextRow ? getAValue ( b , sourceCeilRC . x , sourceCeilRC . z , d )
: 0.0 ,
( hasNextRow && hasNextCol ) ?
getAValue ( b , sourceCeilRC . x , sourceCeilRC . z , d + 1 ) : 0.0 ) ;
vec3 fracRC = sourceFracIndexRC - vec3 ( sourceFloorRC ) ;
vec4 top = mix ( topLeft , topRight , fracRC . yyzz ) ;
vec4 bottom = mix ( bottomLeft , bottomRight , fracRC . yyzz ) ;
vec4 newValue = mix ( top , bottom , fracRC . x ) ;
setOutput ( newValue ) ;
}
` }}class UR{constructor(e,t,s){this.variableNames=["dy"],this.outputShape=[],this.outputShape=t.shape;const[,n,i]=t.shape,[,r,o]=e.shape,a=[s&&r>1?n-1:n,s&&o>1?i-1:i],l=[s&&r>1?r-1:r,s&&o>1?o-1:o],c=a[0]/l[0],p=a[1]/l[1],u=1/c,h=1/p,d=Math.ceil(u)*2+2,m=Math.ceil(h)*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 ] ;
float accumulator = 0.0 ;
const float heightScale = float ( $ { c } ) ;
const float widthScale = float ( $ { p } ) ;
const float invHeightScale = float ( $ { u } ) ;
const float invWidthScale = float ( $ { h } ) ;
const int winHeight = int ( $ { d } ) ;
const int winWidth = int ( $ { m } ) ;
// Compute bounds for where in dy we will look
float startRLerp = floor ( float ( r ) * invHeightScale ) ;
int startDyR = int ( floor ( startRLerp - float ( winHeight / 2 ) ) ) ;
float startCLerp = floor ( float ( c ) * invWidthScale ) ;
int startDyC = int ( floor ( startCLerp - float ( winWidth / 2 ) ) ) ;
// Loop over dy
for ( int dyROffset = 0 ; dyROffset < winHeight ; dyROffset ++ ) {
int dyR = dyROffset + startDyR ;
// Guard against the window exceeding the bounds of dy
if ( dyR < 0 || dyR >= $ { r } ) {
continue ;
}
for ( int dyCOffset = 0 ; dyCOffset < winWidth ; dyCOffset ++ ) {
int dyC = dyCOffset + startDyC ;
// Guard against the window exceeding the bounds of dy
if ( dyC < 0 || dyC >= $ { o } ) {
continue ;
}
float sourceFracRow =
float ( $ { a [ 0 ] } ) *
( float ( dyR ) / float ( $ { l [ 0 ] } ) ) ;
float sourceFracCol =
float ( $ { a [ 1 ] } ) *
( float ( dyC ) / float ( $ { l [ 1 ] } ) ) ;
int sourceNearestRow = int ( min (
float ( int ( $ { n } ) - 1 ) ,
$ { s } ? float ( round ( sourceFracRow ) ) :
float ( floor ( sourceFracRow ) ) ) ) ;
int sourceNearestCol = int ( min (
float ( int ( $ { i } ) - 1 ) ,
$ { s } ? float ( round ( sourceFracCol ) ) :
float ( floor ( sourceFracCol ) ) ) ) ;
if ( r == sourceNearestRow && c == sourceNearestCol ) {
accumulator += getDy ( b , dyR , dyC , d ) ;
}
}
}
// End loop over dy
setOutput ( accumulator ) ;
}
` }}class $ R{constructor(e,t,s,n){this.variableNames=["A"],this.outputShape=[];const[i,r,o,a]=e;this.outputShape=[i,t,s,a];const l=[n&&t>1?r-1:r,n&&s>1?o-1:o],c=[n&&t>1?t-1:t,n&&s>1?s-1:s],p=n?"0.5":"0.0";this.userCode= `
const vec2 effectiveInputOverOutputRatioRC = vec2 (
$ { l [ 0 ] / c [ 0 ] } ,
$ { l [ 1 ] / c [ 1 ] } ) ;
const vec2 inputShapeRC = vec2 ( $ { r } . 0 , $ { o } . 0 ) ;
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int b = coords [ 0 ] ;
int d = coords [ 3 ] ;
ivec2 yRC = coords . yz ;
// Fractional source index.
vec2 sourceFracIndexRC = vec2 ( yRC ) * effectiveInputOverOutputRatioRC ;
// Compute the coordinators of nearest neighbor point.
ivec2 sourceNearestRC = ivec2 (
min ( inputShapeRC - 1.0 , floor ( sourceFracIndexRC + $ { p } ) ) ) ;
float newValue = getA ( b , sourceNearestRC . x , sourceNearestRC . y , d ) ;
setOutput ( newValue ) ;
}
` }}class WR{constructor(e,t){this.variableNames=["x"];const s=e.length;if(s>4)throw new Error( ` WebGL backend : Reverse of rank - $ { s } tensor is not yet supported ` );if(this.outputShape=e,s===1){this.userCode= `
void main ( ) {
int coord = getOutputCoords ( ) ;
setOutput ( getX ( $ { e [ 0 ] } - coord - 1 ) ) ;
}
` ;return}const n=o=>t.indexOf(o)!==-1&&e[o]!==1? ` $ { e [ o ] } - coords [ $ { o } ] - 1 ` : ` coords [ $ { o } ] ` ,i=e.map((o,a)=>n(a)).join(","),r=Ce(s);this.userCode= `
void main ( ) {
$ { r } coords = getOutputCoords ( ) ;
setOutput ( getX ( $ { i } ) ) ;
}
` }}class zR{constructor(e,t){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;const s=e.length;if(s>4)throw new Error( ` WebGL backend : Reverse of rank - $ { s } tensor is not yet supported ` );this.outputShape=e;const n=Et("rc",s),i= ` $ { n [ s - 1 ] } + 1 < $ { this . outputShape [ s - 1 ] } ` ,r= ` $ { n [ s - 2 ] } + 1 < $ { this . outputShape [ s - 2 ] } ` ,o=Ce(s);s===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 ( $ { i } ) {
result . g = getChannel ( getX ( $ { e [ 0 ] } - ( rc + 1 ) - 1 ) ,
$ { e [ 0 ] } - ( rc + 1 ) - 1 ) ;
}
setOutput ( result ) ;
}
` :this.userCode= `
void main ( ) {
$ { o } rc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
result . r = $ { a ( n . slice ( ) ) } ;
if ( $ { i } ) {
result . g = $ { l ( n . slice ( ) ) } ;
}
if ( $ { r } ) {
result . b = $ { c ( n . slice ( ) ) } ;
if ( $ { i } ) {
result . a = $ { p ( n . slice ( ) ) } ;
}
}
setOutput ( result ) ;
}
` ;function a(d){return u(d)}function l(d){return d[s-1]="("+d[s-1]+" + 1)",u(d)}function c(d){return d[s-2]="("+d[s-2]+" + 1)",u(d)}function p(d){return d[s-1]="("+d[s-1]+" + 1)",d[s-2]="("+d[s-2]+" + 1)",u(d)}function u(d){const m=e.map((b,S)=>h(S,d)),f=m.join(","),y=m.slice(-2).join(",");return ` getChannel ( getX ( $ { f } ) , vec2 ( $ { y } ) ) ` }function h(d,m){return t.indexOf(d)!==-1&&e[d]!==1? ` $ { e [ d ] } - $ { m [ d ] } - 1 ` : ` $ { m [ d ] } ` }}}class wx{constructor(e,t,s,n,i,r,o=!0){this.variableNames=["updates","indices","defaultValue"],this.outputShape=r;const a=Ce(i.length),l=Ce(r.length);let c="";s===1?c="i":s===2&&(c="i, j");const p= ` getIndices ( $ { c } ) ` ;let u="";n===1?u="i":n===2&&(u="i, coords[1]");const h= ` getUpdates ( $ { u } ) ` ,d=t>1?"strides[j]":"strides";this.userCode= `
$ { a } strides = $ { a } ( $ { i } ) ;
void main ( ) {
$ { l } 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 += $ { h } ;
found = true ;
}
}
setOutput ( mix ( getDefaultValue ( ) , sum , float ( found ) ) ) ;
}
` }}class BR{constructor(e,t){this.variableNames=["x","segmentIds"];const s=e.windowSize,n=e.batchSize,i=e.inSize,r=e.numSegments,o=r*Math.ceil(i/s);this.outputShape=[n,o];const a="0.0",l="sumValue",c=Math.floor(s/4)*4,p=s%4,u= `
sumValue += dot ( values , segFilter ) ;
` ;let h="";i%s>0&&(h= `
if ( inIdx < 0 || inIdx >= $ { i } ) {
return initializationValue ;
}
` );let d="";i%s>0&&(d= `
if ( inIdx < 0 || inIdx >= $ { i } ) {
return - 1.0 ;
}
` ),this.userCode= `
const float initializationValue = $ { a } ;
float getValue ( int batch , int inIdx ) {
$ { h }
return getX ( batch , inIdx ) ;
}
float getSegmentIdAtIndex ( int inIdx ) {
$ { d }
return getSegmentIds ( inIdx ) ;
}
void main ( ) {
ivec2 coords = getOutputCoords ( ) ;
int batch = coords [ 0 ] ;
int outIdx = coords [ 1 ] ;
int inOffset = int ( floor ( float ( outIdx ) / float (
$ { r } ) ) * float ( $ { s } ) ) ;
int currentSeg = int ( mod ( float ( outIdx ) , float ( $ { r } ) ) ) ;
float sumValue = 0.0 ;
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 )
) ;
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
) ;
$ { u }
}
int inIdx = inOffset + $ { c } ;
if ( $ { p === 1 } ) {
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
initializationValue ,
initializationValue ,
initializationValue
) ;
int inIdxSeg = int ( getSegmentIdAtIndex ( inIdx ) ) ;
vec4 segFilter = vec4 (
int ( getSegmentIdAtIndex ( inIdx ) ) == currentSeg ? 1 : 0 ,
0 ,
0 ,
0
) ;
$ { u }
} else if ( $ { p === 2 } ) {
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
initializationValue ,
initializationValue
) ;
vec4 segFilter = vec4 (
int ( getSegmentIdAtIndex ( inIdx ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 1 ) ) == currentSeg ? 1 : 0 ,
0 ,
0
) ;
$ { u }
} else if ( $ { p === 3 } ) {
vec4 values = vec4 (
getValue ( batch , inIdx ) ,
getValue ( batch , inIdx + 1 ) ,
getValue ( batch , inIdx + 2 ) ,
initializationValue
) ;
vec4 segFilter = vec4 (
int ( getSegmentIdAtIndex ( inIdx ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 1 ) ) == currentSeg ? 1 : 0 ,
int ( getSegmentIdAtIndex ( inIdx + 2 ) ) == currentSeg ? 1 : 0 ,
0
) ;
$ { u }
}
setOutput ( $ { l } ) ;
}
` }}class PR{constructor(e,t,s){this.variableNames=["c","a","b"],this.outputShape=t;let n,i;if(s>4)throw Error( ` Where for rank $ { s } is not yet supported ` );if(s===1)i="resRC",n="resRC";else{const o=["resRC.x","resRC.y","resRC.z","resRC.w"],a=[],l=[];for(let c=0;c<t.length;c++)l.push( ` $ { o [ c ] } ` ),c<e&&a.push( ` $ { o [ c ] } ` );n=a.join(),i=l.join()}const r=Ce(s);this.userCode= `
void main ( ) {
$ { r } resRC = getOutputCoords ( ) ;
float cVal = getC ( $ { n } ) ;
if ( cVal >= 1.0 ) {
setOutput ( getA ( $ { i } ) ) ;
} else {
setOutput ( getB ( $ { i } ) ) ;
}
}
` }}class jR{constructor(e){this.variableNames=["source"],this.outputShape=e,this.rank=e.length;const t=Ce(this.rank),s= ` uniform int start [ $ { this . rank } ] ; ` ,n= $ B(this.rank);let i;const r=e.map((o,a)=> ` sourceLoc . $ { xx [ a ] } = start [ $ { a } ] + coords . $ { xx [ a ] } ; ` );i= `
$ { t } sourceLoc ;
$ { t } coords = getOutputCoords ( ) ;
$ { r . join ( `
` )}
` ,this.userCode= `
$ { s }
void main ( ) {
$ { i }
setOutput ( getSource ( $ { n } ) ) ;
}
` }getCustomSetupFunc(e){if(e.length!==this.rank)throw Error( ` The rank ( $ { this . rank } ) of the program must match the length of start ( $ { e . length } ) ` );return(t,s)=>{if(this.startLoc==null&&(this.startLoc=t.getUniformLocationNoThrow(s,"start"),this.startLoc==null))return;t.gl.uniform1iv(this.startLoc,e)}}}const xx=["x","y","z","w","u","v"];function $ B(e){if(e===1)return"sourceLoc";if(e<=6)return xx.slice(0,e).map(t=>"sourceLoc."+t).join(",");throw Error( ` Slicing for rank $ { e } is not yet supported ` )}class VR{constructor(e){this.variableNames=["source"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.rank=e.length;const t=Ce(this.rank),s=Et("coords",this.rank),n=Et("sourceLoc",this.rank),i=this.rank===1?"sourceLoc": ` vec2 ( $ { n . slice ( - 2 ) . join ( ) } ) ` ,r= ` getChannel ( getSource ( $ { n . join ( ) } ) , $ { i } ) ` ,o= `
result . x = $ { r } ;
if ( ++ $ { s [ this . rank - 1 ] } < $ { e [ this . rank - 1 ] } ) {
++ $ { n [ this . rank - 1 ] } ;
result . y = $ { r } ;
-- $ { n [ this . rank - 1 ] } ;
}
` ,a=this.rank===1?"": `
-- $ { s [ this . rank - 1 ] } ;
if ( ++ $ { s [ this . rank - 2 ] } < $ { e [ this . rank - 2 ] } ) {
++ $ { n [ this . rank - 2 ] } ;
result . z = $ { r } ;
if ( ++ $ { s [ this . rank - 1 ] } < $ { e [ this . rank - 1 ] } ) {
++ $ { n [ this . rank - 1 ] } ;
result . w = $ { r } ;
}
}
` ,l=this.rank<=4? ` sourceLoc = coords +
$ { t } ( $ { e . map ( ( c , p ) => ` start[ ${ p } ] ` ) . join ( ) } ) ; ` :e.map((c,p)=> ` $ { n [ p ] } = $ { s [ p ] } + start [ $ { p } ] ; ` ).join( `
` );this.userCode= `
uniform int start [ $ { this . rank } ] ;
void main ( ) {
$ { t } coords = getOutputCoords ( ) ;
$ { t } sourceLoc ;
$ { l }
vec4 result = vec4 ( 0. ) ;
$ { o }
$ { a }
setOutput ( result ) ;
}
` }getCustomSetupFunc(e){if(e.length!==this.rank)throw Error( ` The rank ( $ { this . rank } ) of the program must match the length of start ( $ { e . length } ) ` );return(t,s)=>{if(this.startLoc==null&&(this.startLoc=t.getUniformLocationNoThrow(s,"start"),this.startLoc==null))return;t.gl.uniform1iv(this.startLoc,e)}}}class GR{constructor(e,t,s){this.variableNames=["x"],this.outputShape=s;const n=s.length,i=Ce(s.length),r=Ce(s.length);let o="";if(n===1)o="coords * strides + begin";else{let a=0;o=s.map((l,c)=>(a++,s.length===1? ` coords * strides [ $ { c } ] + begin [ $ { c } ] ` : ` coords [ $ { a - 1 } ] * strides [ $ { c } ] + begin [ $ { c } ] ` )).join(",")}this.userCode= `
$ { i } begin = $ { i } ( $ { e } ) ;
$ { i } strides = $ { i } ( $ { t } ) ;
void main ( ) {
$ { r } coords = getOutputCoords ( ) ;
setOutput ( getX ( $ { o } ) ) ;
}
` }}class KR{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,s){const n=qR(t,s),i=YR(e,n,s);i in this.freeTextures||(this.freeTextures[i]=[]),i in this.usedTextures||(this.usedTextures[i]=[]);const r=HR(e,n,this.gpgpu.gl,this.gpgpu.textureConfig,s);if(this.freeTextures[i].length>0){this.numFreeTextures--,this.numUsedTextures++,this._numBytesFree-=r,this.log();const a=this.freeTextures[i].shift();return this.usedTextures[i].push(a),a}let o;return n===Kt.PACKED_2X2_FLOAT32?o=this.gpgpu.createPackedMatrixTexture(e[0],e[1]):n===Kt.PACKED_2X2_FLOAT16?o=this.gpgpu.createFloat16PackedMatrixTexture(e[0],e[1]):n===Kt.UNPACKED_FLOAT32?o=this.gpgpu.createFloat32MatrixTexture(e[0],e[1]):n===Kt.UNPACKED_FLOAT16?o=this.gpgpu.createFloat16MatrixTexture(e[0],e[1]):n===Kt.PACKED_4X1_UNSIGNED_BYTE&&(o=this.gpgpu.createUnsignedBytesMatrixTexture(e[0],e[1])),this.usedTextures[i].push(o),this.numUsedTextures++,this._numBytesAllocated+=r,this.log(),o}releaseTexture(e,t,s,n){if(this.freeTextures==null)return;const i=qR(s,n),r=YR(t,i,n);r in this.freeTextures||(this.freeTextures[r]=[]);const o=HR(t,i,this.gpgpu.gl,this.gpgpu.textureConfig,n),a= $ ().get("WEBGL_DELETE_TEXTURE_THRESHOLD");a!==-1&&this._numBytesAllocated>a?(this.gpgpu.deleteMatrixTexture(e),this._numBytesAllocated-=o):(this.freeTextures[r].push(e),this.numFreeTextures++,this._numBytesFree+=o),this.numUsedTextures--;const l=this.usedTextures[r],c=l.indexOf(e);if(c<0)throw new Error("Cannot release a texture that was never provided by this texture manager");l.splice(c,1),this.log()}log(){if(!this.logEnabled)return;const e=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used", ` $ { this . numFreeTextures } / $ { this . numUsedTextures } ` , ` ( $ { e } ) ` );const 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)return;for(const e in this.freeTextures)this.freeTextures[e].forEach(t=>{this.gpgpu.deleteMatrixTexture(t)});for(const 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 WB(e,t){const s=e;if(t===s.R32F)return 4;if(t===s.R16F)return 2;if(t===s.RGBA32F)return 16;if(t===e.RGBA)return 16;if(t===s.RGBA16F)return 8;throw new Error( ` Unknown internal format $ { t } ` )}function HR(e,t,s,n,i){const r=zB(t,n);let o;if(i){const[l,c]=oi(e[0],e[1]);o=l*c}else{const[l,c]=_o(e[0],e[1]);o=l*c}const a=WB(s,r);return o*a}function zB(e,t){switch(e){case Kt.PACKED_2X2_FLOAT32:return gx(t);case Kt.PACKED_2X2_FLOAT16:return yx(t);case Kt.UNPACKED_FLOAT32:return dx(t);case Kt.UNPACKED_FLOAT16:return mx(t);case Kt.PACKED_4X1_UNSIGNED_BYTE:return fx(t);default:throw new Error( ` Unknown physical texture type $ { e } ` )}}function BB(e){return $ ().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?e?Kt.PACKED_2X2_FLOAT32:Kt.UNPACKED_FLOAT32:e?Kt.PACKED_2X2_FLOAT16:Kt.UNPACKED_FLOAT16}function qR(e,t){if(e===ns.UPLOAD)return Kt.PACKED_2X2_FLOAT32;if(e===ns.RENDER||e==null)return BB(t);if(e===ns.DOWNLOAD||e===ns.PIXELS)return Kt.PACKED_4X1_UNSIGNED_BYTE;throw new Error( ` Unknown logical texture type $ { e } ` )}function YR(e,t,s){return ` $ { e [ 0 ] } _$ { e [ 1 ] } _$ { t } _$ { s } ` }class XR{constructor(e,t){this.variableNames=["A"];const s=new Array(e.length);for(let r=0;r<s.length;r++)s[r]=e[r]*t[r];this.outputShape=s,this.rank=s.length;const n=Ce(this.rank),i=PB(e);this.userCode= `
void main ( ) {
$ { n } resRC = getOutputCoords ( ) ;
setOutput ( getA ( $ { i } ) ) ;
}
` }}function PB(e){const t=e.length;if(t>5)throw Error( ` Tile for rank $ { t } is not yet supported ` );if(t===1)return ` imod ( resRC , $ { e [ 0 ] } ) ` ;const s=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],n=[];for(let i=0;i<e.length;i++)n.push( ` imod ( $ { s [ i ] } , $ { e [ i ] } ) ` );return n.join()}class _e{constructor(e,t){this.variableNames=["A"],this.outputShape=e,this.userCode= `
float unaryOperation ( float x ) {
$ { t }
}
void main ( ) {
float x = getAAtOutCoords ( ) ;
float y = unaryOperation ( x ) ;
setOutput ( y ) ;
}
` }}const Bn="if (isnan(x)) return x;",JR="return x;",Lx="return abs(x);",Sx=Bn+ `
return ( x < 0.0 ) ? 0.0 : x ;
` ,vx=Bn+ `
return ( x < 0.0 ) ? 0.0 : min ( 6.0 , x ) ;
` ,Tx="return (x >= 0.0) ? x : (exp(x) - 1.0);",ZR= `
// Stable and Attracting Fixed Point (0, 1) for Normalized Weights.
// see: https://arxiv.org/abs/1706.02515
float scaleAlpha = $ { U . SELU _SCALEALPHA } ;
float scale = $ { U . SELU _SCALE } ;
return ( x >= 0.0 ) ? scale * x : scaleAlpha * ( exp ( x ) - 1.0 ) ;
` ;function QR(e=0){return Bn+ `
return x > 0.0 ? 1.0 : float ( $ { e } ) ;
` }const Ix="return -x;",Ax="return ceil(x);",Nx="return floor(x);",e2= `
if ( isnan ( x ) ) { return 0.0 ; }
return sign ( x ) ;
` ,t2="return float(isnan(x));",s2="return float(isinf(x));",n2="return float(!isnan(x) && !isinf(x));",i2= `
// 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 ;
}
}
` ,Cx="return exp(x);",Rx="return exp(x) - 1.0;",r2= ` if ( x < 0.0 ) return NAN ;
return log ( x ) ; ` ,o2="return log(1.0 + x);",a2="return sqrt(x);",l2="return inversesqrt(x);",c2="return 1.0 / (1.0 + exp(-1.0 * x));",p2= `
float epsilon = 1.1920928955078125 e - 7 ;
float threshold = log ( epsilon ) + 2.0 ;
bool too _large = x > - threshold ;
bool too _small = x < threshold ;
float result ;
float exp _x = exp ( x ) ;
if ( too _large ) {
result = x ;
}
else if ( too _small ) {
result = exp _x ;
}
else {
result = log ( exp _x + 1.0 ) ;
}
return result ;
` ,u2=Bn+ `
return sin ( x ) ;
` ,h2=Bn+ `
return cos ( x ) ;
` ,d2="return tan(x);",m2=Bn+ `
if ( abs ( x ) > 1. ) {
return NAN ;
}
return asin ( x ) ;
` ,f2=Bn+ `
if ( abs ( x ) > 1. ) {
return NAN ;
}
return acos ( x ) ;
` ,g2=Bn+ `
return atan ( x ) ;
` ,y2= `
float e2x = exp ( x ) ;
return ( e2x - 1.0 / e2x ) / 2.0 ;
` ,b2= `
float e2x = exp ( - x ) ;
return ( e2x + 1.0 / e2x ) / 2.0 ;
` ,w2= `
float e2x = exp ( - 2.0 * abs ( x ) ) ;
return sign ( x ) * ( 1.0 - e2x ) / ( 1.0 + e2x ) ;
` ,x2=Bn+"return log(x + sqrt(x * x + 1.0));",L2=Bn+ `
if ( x < 1.0 ) return NAN ;
return log ( x + sqrt ( x * x - 1.0 ) ) ; ` ,S2=Bn+ `
if ( ( x < - 1.0 ) || ( x > 1.0 ) ) return NAN ;
return ( log ( 1.0 + x ) - log ( 1.0 - x ) ) / 2.0 ; ` ,v2= `
// Error function is calculated approximately with elementary function.
// See "Handbook of Mathematical Functions with Formulas,
// Graphs, and Mathematical Tables", Abramowitz and Stegun.
float p = $ { U . ERF _P } ;
float a1 = $ { U . ERF _A1 } ;
float a2 = $ { U . ERF _A2 } ;
float a3 = $ { U . ERF _A3 } ;
float a4 = $ { U . ERF _A4 } ;
float a5 = $ { U . ERF _A5 } ;
float sign = sign ( x ) ;
x = abs ( x ) ;
float t = 1.0 / ( 1.0 + p * x ) ;
return sign * ( 1.0 - ( ( ( ( ( a5 * t + a4 ) * t ) + a3 ) * t + a2 ) * t + a1 ) * t * exp ( - x * x ) ) ;
` ,T2="return x * x;",I2="return 1.0 / x;",A2="return float(!(x >= 1.0));",N2="return float(int(x));",Wu="return x;";const C2="return x;",R2= `
vec4 result = log ( x ) ;
vec4 isNaN = vec4 ( lessThan ( x , vec4 ( 0.0 ) ) ) ;
result . r = isNaN . r == 1.0 ? NAN : result . r ;
result . g = isNaN . g == 1.0 ? NAN : result . g ;
result . b = isNaN . b == 1.0 ? NAN : result . b ;
result . a = isNaN . a == 1.0 ? NAN : result . a ;
return result ;
` ,Ox= `
vec4 result = x * vec4 ( greaterThanEqual ( x , vec4 ( 0.0 ) ) ) ;
bvec4 isNaN = isnan ( x ) ;
result . r = isNaN . r ? x . r : result . r ;
result . g = isNaN . g ? x . g : result . g ;
result . b = isNaN . b ? x . b : result . b ;
result . a = isNaN . a ? x . a : result . a ;
return result ;
` ,Ex= `
vec4 result = min ( x , vec4 ( 6. ) ) * vec4 ( greaterThanEqual ( x , vec4 ( 0.0 ) ) ) ;
bvec4 isNaN = isnan ( x ) ;
result . r = isNaN . r ? x . r : result . r ;
result . g = isNaN . g ? x . g : result . g ;
result . b = isNaN . b ? x . b : result . b ;
result . a = isNaN . a ? x . a : result . a ;
return result ;
` ,kx= `
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 ;
` ;class Pa{constructor(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e,this.userCode= `
vec4 unaryOperation ( vec4 x ) {
$ { t }
}
void main ( ) {
vec4 x = getAAtOutCoords ( ) ;
vec4 y = unaryOperation ( x ) ;
setOutput ( y ) ;
}
` }}class O2{constructor(e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outputShape=e;const t=e.length,s=Et("rc",t),n=Ce(t),i=jC(t,s),r=s.slice(-2),o=t<=1?"rc": ` vec2 ( $ { r . join ( "," ) } ) ` ;this.userCode= `
void main ( ) {
$ { n } rc = getOutputCoords ( ) ;
vec4 packedInput = getA ( $ { i } ) ;
setOutput ( getChannel ( packedInput , $ { o } ) ) ;
}
` }}const{segment_util:E2}=U,jB=St.split,VB=St.tile,GB=St.topkImpl,HB=St.whereImpl,qB=1e-7,YB=1e-4,Of={};function KB(e){return e in Of||(Of[e]={}),Of[e]}function Ef(e,t=!1){if(e==="linear")return t?C2:JR;if(e==="relu")return t?Ox:Sx;if(e==="elu")return t?kx:Tx;if(e==="relu6")return t?Ex:vx;if(e==="prelu")return t?ox:rx;throw new Error( ` Activation $ { e } has not been implemented for the WebGL backend . ` )}const XB=128,JB=600;function ZB(){return $ ().global.screen==null?1024: $ ().global.screen.height* $ ().global.screen.width*window.devicePixelRatio*JB/1024/1024}const k2=1e3;class _x extends Jp{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.warnedAboutMemory=!1,this.warnedAboutCPUBackend=!1,this.pendingDeletes=0,this.disposed=!1,! $ ().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(e==null){const t=Js( $ ().getNumber("WEBGL_VERSION"));this.binaryCache=KB( $ ().getNumber("WEBGL_VERSION")),this.gpgpu=new bx(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 KR(this.gpgpu),this.numMBBeforeWarning=ZB(),this.texData=new Xp(this,os())}numDataIds(){return this.texData.numDataIds()+(this.cpuBackend?this.cpuBackend.numDataIds():0)-this.pendingDeletes}write(e,t,s){if(( $ ().getBool("WEBGL_CHECK_NUMERICAL_PROBLEMS")|| $ ().getBool("DEBUG"))&&this.checkNumericalProblems(e),s==="complex64"&&e!=null)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");const n={};return this.texData.set(n,{shape:t,dtype:s,values:e,usage:ns.UPLOAD}),n}move(e,t,s,n){if( $ ().getBool("DEBUG")&&this.checkNumericalProblems(t),n==="complex64")throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(e,{shape:s,dtype:n,values:t,usage:ns.UPLOAD})}readSync(e){const t=this.texData.get(e),{values:s,dtype:n,complexTensors:i,slice:r,shape:o,isPacked:a}=t;if(r!=null){let u;a?u=new Pa(o,Wu):u=new _e(o,Wu);const h=this.runWebGLProgram(u,[{dataId:e,shape:o,dtype:n}],n),d=this.readSync(h.dataId);return this.disposeData(h.dataId),d}if(s!=null)return this.convertAndCacheOnCPU(e);if(n==="string")return s;const l=this.activeTimers!=null;let c;l&&(c=E.now());let p;if(n==="complex64"){const u=i.real.dataSync(),h=i.imag.dataSync();p=U.mergeRealAndImagArrays(u,h)}else p=this.getValuesFromTexture(e);return l&&(this.downloadWaitMs+=E.now()-c),this.convertAndCacheOnCPU(e,p)}async read(e){if(this.pendingRead.has(e)){const d=this.pendingRead.get(e);return new Promise(m=>d.push(m))}const t=this.texData.get(e),{values:s,shape:n,slice:i,dtype:r,complexTensors:o,isPacked:a}=t;if(i!=null){let d;a?d=new Pa(n,Wu):d=new _e(n,Wu);const m=this.runWebGLProgram(d,[{dataId:e,shape:n,dtype:r}],r),f=this.read(m.dataId);return this.disposeData(m.dataId),f}if(s!=null)return this.convertAndCacheOnCPU(e);if(! $ ().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&& $ ().getNumber("WEBGL_VERSION")===2)throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");let l=null,c;if(r!=="complex64"&& $ ().get("WEBGL_BUFFER_SUPPORTED")){c=this.decode(e);const d=this.texData.get(c.dataId);l=this.gpgpu.createBufferFromTexture(d.texture,...xr(n))}this.pendingRead.set(e,[]),r!=="complex64"&&await this.gpgpu.createAndWaitForFence();let p;if(r==="complex64"){const d=await Promise.all([o.real.data(),o.imag.data()]),m=d[0],f=d[1];p=U.mergeRealAndImagArrays(m,f)}else if(l==null)p=this.getValuesFromTexture(e);else{const d=E.sizeFromShape(n);p=this.gpgpu.downloadFloat32MatrixFromBuffer(l,d)}c!=null&&this.disposeData(c.dataId);const u=this.convertAndCacheOnCPU(e,p),h=this.pendingRead.get(e);return this.pendingRead.delete(e),h.forEach(d=>d(u)),this.pendingDisposal.has(e)&&(this.pendingDisposal.delete(e),this.disposeData(e),this.pendingDeletes--),u}checkNumericalProblems(e){if(e==null)return;for(let t=0;t<e.length;t++){const s=e[t];if
void main ( ) {
ivec4 coords = getOutputCoords ( ) ;
int x = coords [ 2 ] ;
int coordX = $ { t } - x ;
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 ) ;
}
` }}const U2={kernelName:Dr,backendName:"webgl",kernelFunc:({inputs:e,backend:t})=>{const{image:s}=e,n=t,i=new M2(s.shape),r=n.runWebGLProgram(i,[s],s.dtype);return r}};class $ 2{constructor(e){this.variableNames=["A"];const t=ot(),[s,n]=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 ( $ { n } . 0 , $ { s } . 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 ) ) ;
}
` }}class W2{constructor(e){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;const t=ot(),[s,n]=e;this.outputShape=e,this.userCode= `
void main ( ) {
ivec3 coords = getOutputCoords ( ) ;
int texR = coords [ 0 ] ;
int texC = coords [ 1 ] ;
int depth = coords [ 2 ] ;
vec4 result = vec4 ( 0. ) ;
for ( int row = 0 ; row <= 1 ; row ++ ) {
for ( int col = 0 ; col <= 1 ; col ++ ) {
texC = coords [ 1 ] + row ;
depth = coords [ 2 ] + col ;
vec2 uv = ( vec2 ( texC , texR ) + halfCR ) /
vec2 ( $ { n } . 0 , $ { s } . 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 ;
}
result [ row * 2 + col ] = floor ( value * 255.0 + 0.5 ) ;
}
}
$ { t . output } = result ;
}
` }}const z2={kernelName:ta,backendName:"webgl",kernelFunc:eP};let ja;function eP(e){const{inputs:t,backend:s,attrs:n}=e;let{pixels:i}=t;const{numChannels:r}=n,o=typeof HTMLVideoElement!="undefined"&&i instanceof HTMLVideoElement,a=typeof HTMLImageElement!="undefined"&&i instanceof HTMLImageElement,[l,c]=o?[i.videoWidth,i.videoHeight]:[i.width,i.height],p=[c,l],u=[c,l,r];(a||o)&&(ja==null&&(ja=document.createElement("canvas").getContext("2d")),ja.canvas.width=l,ja.canvas.height=c,ja.drawImage(i,0,0,l,c),i=ja.canvas);const h=s.makeTensorInfo(p,"int32");s.texData.get(h.dataId).usage=ns.PIXELS,s.gpgpu.uploadPixelDataToTexture(s.getTexture(h.dataId),i);const d= $ ().getBool("WEBGL_PACK")?new W2(u):new $ 2(u),m=s.runWebGLProgram(d,[h],"int32");return s.disposeData(h.dataId),m}const{maxImpl:B2,transposeImpl:kf}=Vw;function Fx(e,t,s,n){const[i,r]=e.shape,o=U.computeOptimalWindowSize(r),a={windowSize:o,inSize:r,batchSize:i},l=new Cf(a,s),c=n.runWebGLProgram(l,[e],t);return c.shape[1]===1?c:Fx(c,t,s,n)}function tP(e,t,s){const n=[Lr(e.shape),...Sr(e.shape)],i={dtype:e.dtype,shape:n,dataId:e.dataId},r=[Lr(t),...Sr(t)],o=new Rf(r,n),a=!0,l=s.runWebGLProgram(o,[i],e.dtype,null,a);return{dataId:l.dataId,shape:t,dtype:l.dtype}}function Mx(e,t,s){const n=s.texData.get(e.dataId);return n.isPacked&&!vr(e.shape,t)&&!(n.texture!==null&&vr(n.shape,t))?tP(e,t,s):{dataId:e.dataId,shape:t,dtype:e.dtype}}function P2(e,t,s,n){const i=E.sizeFromShape(t),r=E.sizeFromShape(e.shape),o=r/i,a=Mx(e,[o,i],n),l=Fx(a,e.dtype,"max",n);return a.dataId!==e.dataId&&n.disposeData(a.dataId),Mx(l,s,n)}class j2{constructor(e,t){this.variableNames=["A"];const s=new Array(e.length);for(let r=0;r<s.length;r++)s[r]=e[t[r]];this.outputShape=s,this.rank=s.length;const n=Ce(this.rank),i=sP(t);this.userCode= `
void main ( ) {
$ { n } resRC = getOutputCoords ( ) ;
setOutput ( getA ( $ { i } ) ) ;
}
` }}function sP(e){const t=e.length;if(t>6)throw Error( ` Transpose for rank $ { t } is not yet supported ` );const s=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],n=new Array(t);for(let i=0;i<e.length;i++)n[e[i]]=s[i];return n.join()}class V2{constructor(e,t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0;const s=new Array(e.length);for(let c=0;c<s.length;c++)s[c]=e[t[c]];if(this.outputShape=s,this.rank=s.length,this.rank>6)throw Error( ` Packed transpose for rank $ { this . rank } is not yet supported . ` );const n=Ce(this.rank),i=ex("rc",this.rank),r=new Array(this.rank);for(let c=0;c<t.length;c++)r[t[c]]=i[c];const o= ` vec2 ( $ { r . slice ( - 2 ) . join ( ) } ) ` ,a= ` ++ $ { i [ this . rank - 1 ] } < $ { s [ this . rank - 1 ] } ` ,l= ` getChannel ( getA ( $ { r . join ( ) } ) , $ { o } ) ` ;this.userCode= `
void main ( ) {
$ { n } rc = getOutputCoords ( ) ;
vec4 result = vec4 ( 0. ) ;
result [ 0 ] = $ { l } ;
if ( $ { a } ) {
result [ 1 ] = $ { l } ;
}
-- $ { i [ this . rank - 1 ] } ;
if ( ++ $ { i [ this . rank - 2 ] } < $ { s [ this . rank - 2 ] } ) {
result [ 2 ] = $ { l } ;
if ( $ { a } ) {
result [ 3 ] = $ { l } ;
}
}
setOutput ( result ) ;
}
` }}function _f(e,t,s){const n= $ ().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new V2(e.shape,t):new j2(e.shape,t);return s.runWebGLProgram(n,[e],e.dtype)}const G2={kernelName:hi,backendName:"webgl",kernelFunc:({inputs:e,attrs:t,backend:s})=>{const{x:n}=e,{reductionIndices:i,keepDims:r}=t,o=s,a=n.shape.length,l=E.parseAxisParam(i,n.shape);let c=l;const p=U.getAxesPermutation(c,a),u=p!=null,h=o.shouldExecuteOnCPU([n]);let d=n;if(u){if(h){const S=o.texData.get(d.dataId),x=S.values,I=new Array(a);for(let R=0;R<I.length;R++)I[R]=n.shape[p[R]];const A=kf(x,n.shape,n.dtype,p,I);d=o.makeTensorInfo(I,n.dtype);const k=o.texData.get(d.dataId);k.values=A}else d=_f(n,p,o);c=U.getInnerMostAxes(c.length,a)}U.assertAxesAreInnerMostDims("max",c,a);const[m,f]=U.computeOutAndReduceShapes(d.shape,c);let y=m;r&&(y=U.expandShapeToKeepDim(m,l));let b;if(h){const S=o.texData.get(d.dataId),x=S.values,I=B2(x,E.sizeFromShape(f),y,n.dtype);b=o.makeTensorInfo(y,n.dtype);const A=o.texData.get(b.dataId);A.values=I}else b=P2(d,f,y,o);return u&&o.disposeData(d.dataId),b}};function H2(e,t,s,n){let i=new Fo(s,"max",!1);const r=n.runWebGLProgram(i,[e],"float32");i=new Fo(s,"max",!0,!0,t);const o=n.runWebGLProgram(i,[e],"float32");return[r,o]}const q2={kernelName:Fr,backendName:"webgl",kernelFunc:({inputs:e,attrs:t,backend:s})=>{const{x:n}=e,{filterSize:i,strides:r,pad:o,includeBatchInIndex:a}=t,l=s;E.assert(n.shape.length===4,()=> ` Error in maxPool : input must be rank 4 but got rank $ { n . shape . length } . ` );const c=[1,1];E.assert(U.eitherStridesOrDilationsAreOne(r,c),()=> ` Error in maxPool : Either strides or dilations must be 1. Got strides $ { r } and dilations '${c}' ` );const p=U.computePool2DInfo(n.shape,i,r,c,o),[u,h]=H2(n,a,p,l);return[u,h]}};const Y2={kernelName:pc,backendName:"webgl",kernelFunc:({inputs:e,backend:t,attrs:s})=>{U.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");const{boxes:n,scores:i}=e,{maxOutputSize:r,iouThreshold:o,scoreThreshold:a}=s,l=t,c=l.readSync(n.dataId),p=l.readSync(i.dataId),u=r,h=o,d=a;return St.nonMaxSuppressionV3Impl(c,p,u,h,d)}};const nP=St.nonMaxSuppressionV4Impl,K2={kernelName:Mr,backendName:"webgl",kernelFunc:({inputs:e,backend:t,attrs:s})=>{U.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");const{boxes:n,scores:i}=e,{maxOutputSize:r,iouThreshold:o,scoreThreshold:a,padToMaxOutputSize:l}=s,c=t,p=c.readSync(n.dataId),u=c.readSync(i.dataId),{selectedIndices:h,validOutputs:d}=nP(p,u,r,o,a,l);return[h,d]}};const iP=St.nonMaxSuppressionV5Impl,X2={kernelName:Ur,backendName:"webgl",kernelFunc:({inputs:e,backend:t,attrs:s})=>{U.warn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");const{boxes:n,scores:i}=e,{maxOutputSize:r,iouThreshold:o,scoreThreshold:a,softNmsSigma:l}=s,c=t,p=c.readSync(n.dataId),u=c.readSync(i.dataId),h=r,d=o,m=a,f=l,{selectedIndices:y,selectedScores:b}=iP(p,u,h,d,m,f);return[y,b]}};class J2{constructor(e,t,s,n){this.variableNames=["Image"],this.outputShape=[];const i=e[1],r=e[2],o=Math.sin(t).toFixed(3),a=Math.cos(t).toFixed(3);this.outputShape=e;const[l,c]=U.getImageCenter(n,i,r),p=l.toFixed(3),u=c.toFixed(3);let h="";typeof s=="number"?h= ` float outputValue = $ { s . toFixed ( 2 ) } ; ` :h= `
vec3 fill = vec3 ( $ { s . 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 ) - $ { p } ) * $ { a } - ( float ( y ) - $ { u } ) * $ { o } ;
float coordYFloat = ( float ( x ) - $ { p } ) * $ { o } + ( float ( y ) - $ { u } ) * $ { a } ;
int coordX = int ( round ( coordXFloat + $ { p } ) ) ;
int coordY = int ( round ( coordYFloat + $ { u } ) ) ;
$ { h }
if ( coordX >= 0 && coordX < $ { r } && coordY >= 0 && coordY < $ { i } ) {
outputValue = getImage ( coords [ 0 ] , coordY , coordX , coords [ 3 ] ) ;
}
setOutput ( outputValue ) ;
}
` }}const Z2={kernelName:Wr,backendName:"webgl",kernelFunc:({inputs:e,attrs:t,backend:s})=>{const{image:n}=e,{radians:i,fillValue:r,center:o}=t,a=s,l=new J2(n.shape,i,r,o),c=a.runWebGLProgram(l,[n],n.dtype);return c}};const Q2={kernelName: $ r,backendName:"webgl",kernelFunc:({inputs:e,backend:t})=>{const{x:s}=e,n=t,i=new _e(s.shape,T2);return n.runWebGLProgram(i,[s],s.dtype)}};const eO={kernelName:di,backendName:"webgl",kernelFunc:({inputs:e,backend:t})=>{const{a:s,b:n}=e,i="return (a - b) * (a - b);",r=t,o= $ ().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Qs(i,s.shape,n.shape):new mt(i,s.shape,n.shape);return r.compileAndRun(o,[s,n])}};const tO={kernelName:mi,backendName:"webgl",kernelFunc:({inputs:e,attrs:t,backend:s})=>{const{x:n}=e,{perm:i}=t,r=s,o=n.shape.length,a=new Array(o);for(let c=0;c<a.length;c++)a[c]=n.shape[i[c]];let l;if(r.shouldExecuteOnCPU([n])){const c=r.texData.get(n.dataId),p=c.values,u=kf(p,n.shape,n.dtype,i,a);l=r.makeTensorInfo(a,n.dtype);const h=r.texData.get(l.dataId);h.values=u}else l=_f(n,i,r);return l}};const rP=[G2,U2,z2,F2,q2,Y2,K2,X2,Z2,Q2,eO,tO];for(const e of rP)Yc(e);const sO="2.3.0";const Xu={};Re(Xu,{Abs:()=>dl,Acos:()=>ml,Acosh:()=>fl,AdadeltaOptimizer:()=>bo,AdagradOptimizer:()=>wo,AdamOptimizer:()=>xo,AdamaxOptimizer:()=>Lo,Add:()=>Er,AddN:()=>gl,All:()=>mg,Any:()=>fg,ArgMax:()=>yl,ArgMin:()=>bl,Asin:()=>wl,Asinh:()=>xl,Atan:()=>Ll,Atan2:()=>vl,Atanh:()=>Sl,AvgPool:()=>Tl,AvgPool3D:()=>Il,AvgPool3DBackprop:()=>yg,AvgPoolBackprop:()=>gg,BatchMatMul:()=>Al,BatchToSpaceND:()=>Nl,BroadcastTo:()=>Cl,Callback:()=>lw,CallbackList:()=>zb,Cast:()=>kr,Ceil:()=>Rl,ClipByValue:()=>Ol,Complex:()=>bg,Concat:()=>El,Conv2D:()=>kl,Conv2DBackpropFilter:()=>wg,Conv2DBackpropInput:()=>_l,Conv3D:()=>Dl,Conv3DBackpropFilterV2:()=>xg,Conv3DBackpropInputV2:()=>Lg,Cos:()=>Fl,Cosh:()=>Ml,CropAndResize:()=>Sg,Cumsum:()=>Ul,CustomCallback:()=>Pb,DataStorage:()=>Xp,DepthToSpace:()=>vg,DepthwiseConv2dNative:()=> $ l,DepthwiseConv2dNativeBackpropFilter:()=>Tg,DepthwiseConv2dNativeBackpropInput:()=>Ig,Diag:()=>Ag,Dilation2D:()=>_r,Dilation2DBackpropFilter:()=>ea,Dilation2DBackpropInput:()=>Qo,Div:()=>ui,ENV:()=>pg,EarlyStopping:()=>cw,Elu:()=>Wl,EluGrad:()=>Ng,Environment:()=>cg,Equal:()=>Cg,Erf:()=>zl,Exp:()=>Bl,Expm1:()=>Pl,FFT:()=>Rg,Fill:()=>Og,FlipLeftRight:()=>Dr,Floor:()=>jl,FloorDiv:()=>Vl,FromPixels:()=>ta,FusedBatchNorm:()=>Gl,FusedConv2D:()=>Ih,FusedDepthwiseConv2D:()=>Ah,GatherNd:()=>Eg,GatherV2:()=>Hl,GraphModel:()=>Dw,Greater:()=>kg,GreaterEqual:()=>ql,History:()=>Bb,IFFT:()=>_g,Identity:()=>Yl,Imag:()=>Dg,InputSpec:()=>rt,IsFinite:()=>Kl,IsInf:()=>Xl,IsNan:()=>Jl,KernelBackend:()=>Jp,LRN:()=>tc,LRNBackprop:()=>Bg,LayerVariable:()=>Td,LayersModel:()=>gn,Less:()=>Fg,LessEqual:()=>Mg,LinSpace:()=>Ug,Log:()=>Zl,Log1p:()=>Ql,LogSoftmax:()=>ec,LogicalAnd:()=> $ g,LogicalNot:()=>Wg,LogicalOr:()=>zg,Max:()=>hi,MaxPool:()=>nc,MaxPool3D:()=>ic,MaxPool3DBackprop:()=>jg,MaxPoolBackprop:()=>Pg,MaxPoolWithArgmax:()=>Fr,Maximum:()=>sc,Mean:()=>e1,Min:()=>rc,Minimum:()=>oc,Mod:()=>ac,MomentumOptimizer:()=>So,Multiply:()=>lc,Negate:()=>cc,NonMaxSuppressionV3:()=>pc,NonMaxSuppressionV4:()=>Mr,NonMaxSuppressionV5:()=>Ur,NotEqual:()=>Vg,OneHot:()=>hc,OnesLike:()=>uc,Optimizer:()=>fs,PadV2:()=>dc,Pool:()=>t1,Pow:()=>mc,Prelu:()=>fc,Prod:()=>Gg,RMSPropOptimizer:()=>vo,RNN:()=>ri,Range:()=>Hg,Rank:()=>uy,Real:()=>qg,Reciprocal:()=>gc,Reduction:()=>ht,Relu:()=>yc,Relu6:()=>Lc,Reshape:()=>bc,ResizeBilinear:()=>xc,ResizeBilinearGrad:()=>Kg,ResizeNearestNeighbor:()=>wc,ResizeNearestNeighborGrad:()=>Yg,Reverse:()=>Sc,RotateWithOffset:()=>Wr,Round:()=>vc,Rsqrt:()=>Tc,SGDOptimizer:()=>Ei,ScatterNd:()=>Xg,SelectV2:()=>Ic,Selu:()=>Ac,Sequential:()=>yr,Sigmoid:()=>Ec,Sign:()=>Oc,Sin:()=>Cc,Sinh:()=>Rc,Slice:()=>Nc,Softmax:()=>Uc,Softplus:()=>kc,SpaceToBatchND:()=>Fc,SparseToDense:()=>Jg,SplitV:()=>Mc,Sqrt:()=>_c,Square:()=> $ r,SquaredDifference:()=>di,Step:()=>Gc,StridedSlice:()=>Zg,Sub:()=> $ c,Sum:()=>Dc,SymbolicTensor:()=>bs,Tan:()=>Wc,Tanh:()=>zc,Tensor:()=>ue,TensorBuffer:()=>fi,Tile:()=>Bc,TopK:()=>Qg,Transpose:()=>mi,Unpack:()=>Pc,
2020-08-18 14:04:15 +02:00
/ * *
* @ license
* Copyright 2017 Google LLC . All Rights Reserved .
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
2020-08-21 15:01:04 +02:00
/ * *
* @ license
* Copyright 2018 Google LLC
*
* Use of this source code is governed by an MIT - style
* license that can be found in the LICENSE file or at
* https : //opensource.org/licenses/MIT.
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
* Copyright 2018 Google LLC . All Rights Reserved .
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
*
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
2020-08-18 14:04:15 +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 .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
2020-08-21 15:01:04 +02:00
/ * *
* @ license
* Copyright 2019 Google LLC
*
* Use of this source code is governed by an MIT - style
* license that can be found in the LICENSE file or at
* https : //opensource.org/licenses/MIT.
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
* Copyright 2019 Google LLC . All Rights Reserved .
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
*
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
2020-08-18 14:04:15 +02:00
/ * *
* @ license
* Copyright 2019 Google LLC . All Rights Reserved .
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
* Copyright 2020 Google Inc . All Rights Reserved .
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/ * *
* @ license
* Copyright 2020 Google LLC . All Rights Reserved .
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === === === === === === ==
* /
/** @license See the LICENSE file. */
//# sourceMappingURL=face-api.min.js.map