@huggingface/transformers 3.0.0-alpha.0 → 3.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,19 @@
1
- import*as e from"onnxruntime-node";import*as t from"sharp";var n={"./node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.wasm":
1
+ var e,t,n={"./node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.wasm":
2
2
  /*!****************************************************************************!*\
3
3
  !*** ./node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.wasm ***!
4
- \****************************************************************************/(e,t,n)=>{e.exports=n.p+"ort-wasm-simd-threaded.jsep.wasm"},"onnxruntime-node":
5
- /*!***********************************!*\
6
- !*** external "onnxruntime-node" ***!
7
- \***********************************/t=>{t.exports=e},sharp:
8
- /*!************************!*\
9
- !*** external "sharp" ***!
10
- \************************/e=>{e.exports=t},"?7a2c":
4
+ \****************************************************************************/(e,t,n)=>{e.exports=n.p+"ort-wasm-simd-threaded.jsep.wasm"},"?2ce3":
5
+ /*!**********************************!*\
6
+ !*** onnxruntime-node (ignored) ***!
7
+ \**********************************/()=>{},"?7a2c":
11
8
  /*!********************!*\
12
9
  !*** fs (ignored) ***!
13
10
  \********************/()=>{},"?a42a":
14
11
  /*!**********************!*\
15
12
  !*** path (ignored) ***!
16
- \**********************/()=>{},"?569f":
13
+ \**********************/()=>{},"?2b25":
14
+ /*!***********************!*\
15
+ !*** sharp (ignored) ***!
16
+ \***********************/()=>{},"?569f":
17
17
  /*!********************!*\
18
18
  !*** fs (ignored) ***!
19
19
  \********************/()=>{},"?3f59":
@@ -148,7 +148,7 @@ var r,i,a,s,o,l,u,d,c,p,h,f,m,g,_,w,y,b,v,x,M,T,k,$,C,S,P,E,F,A,I,z,O,B=Object.d
148
148
  */,"./src/backends/onnx.js":
149
149
  /*!******************************!*\
150
150
  !*** ./src/backends/onnx.js ***!
151
- \******************************/(e,t,n)=>{n.r(t),n.d(t,{Tensor:()=>s.Tensor,createInferenceSession:()=>h,deviceToExecutionProviders:()=>c,isONNXProxy:()=>g,isONNXTensor:()=>f});var r=n(/*! ../env.js */"./src/env.js"),i=n(/*! onnxruntime-node */"onnxruntime-node"),a=n(/*! onnxruntime-web/webgpu */"./node_modules/onnxruntime-web/dist/ort.webgpu.bundle.min.mjs"),s=n(/*! onnxruntime-common */"./node_modules/onnxruntime-common/dist/esm/index.js");const o=[];let l,u;r.apis.IS_NODE_ENV?(u=i.default??i,o.push("cpu"),l=["cpu"]):(u=a,r.apis.IS_WEBGPU_AVAILABLE&&o.push("webgpu"),o.push("wasm"),l=["wasm"]);const d=u.InferenceSession;function c(e){let t=l;if(e){if(!o.includes(e))throw new Error(`Unsupported device: "${e}". Should be one of: ${o.join(", ")}.`);t=[e]}return t}let p=null;async function h(e,t){p&&await p;const n=d.create(e,t);return p??=n,await n}function f(e){return e instanceof u.Tensor}const m=u?.env;if(m?.wasm){m.wasm.proxy=!r.apis.IS_WEBWORKER_ENV,"undefined"!=typeof crossOriginIsolated&&crossOriginIsolated||(m.wasm.numThreads=1);"undefined"!=typeof navigator&&/iP(hone|od|ad).+16_4.+AppleWebKit/.test(navigator.userAgent)&&(m.wasm.simd=!1)}function g(){return m?.wasm?.proxy}m?.webgpu&&(m.webgpu.powerPreference="high-performance"),r.env.backends.onnx=m},"./src/configs.js":
151
+ \******************************/(e,t,n)=>{var r;n.r(t),n.d(t,{Tensor:()=>o.Tensor,createInferenceSession:()=>f,deviceToExecutionProviders:()=>p,isONNXProxy:()=>_,isONNXTensor:()=>m});var i=n(/*! ../env.js */"./src/env.js"),a=n(/*! onnxruntime-node */"?2ce3"),s=n(/*! onnxruntime-web/webgpu */"./node_modules/onnxruntime-web/dist/ort.webgpu.bundle.min.mjs"),o=n(/*! onnxruntime-common */"./node_modules/onnxruntime-common/dist/esm/index.js");const l=[];let u,d;i.apis.IS_NODE_ENV?(d=a??(r||(r=n.t(a,2))),l.push("cpu"),u=["cpu"]):(d=s,i.apis.IS_WEBGPU_AVAILABLE&&l.push("webgpu"),l.push("wasm"),u=["wasm"]);const c=d.InferenceSession;function p(e){let t=u;if(e){if(!l.includes(e))throw new Error(`Unsupported device: "${e}". Should be one of: ${l.join(", ")}.`);t=[e]}return t}let h=null;async function f(e,t){h&&await h;const n=c.create(e,t);return h??=n,await n}function m(e){return e instanceof d.Tensor}const g=d?.env;if(g?.wasm){console.log(i.apis),console.log(import.meta.env),g.wasm.proxy=!i.apis.IS_WEBWORKER_ENV,"undefined"!=typeof crossOriginIsolated&&crossOriginIsolated||(g.wasm.numThreads=1);"undefined"!=typeof navigator&&/iP(hone|od|ad).+16_4.+AppleWebKit/.test(navigator.userAgent)&&(g.wasm.simd=!1)}function _(){return g?.wasm?.proxy}g?.webgpu&&(g.webgpu.powerPreference="high-performance"),i.env.backends.onnx=g},"./src/configs.js":
152
152
  /*!************************!*\
153
153
  !*** ./src/configs.js ***!
154
154
  \************************/(e,t,n)=>{n.r(t),n.d(t,{AutoConfig:()=>l,PretrainedConfig:()=>o,getKeyValueShapes:()=>s});var r=n(/*! ./utils/core.js */"./src/utils/core.js"),i=n(/*! ./utils/hub.js */"./src/utils/hub.js");function a(e){const t={};let n={};switch(e.model_type){case"llava":case"paligemma":case"florence2":n=a(e.text_config);break;case"moondream1":n=a(e.phi_config);break;case"musicgen":n=a(e.decoder);break;case"gpt2":case"gptj":case"codegen":case"gpt_bigcode":t.num_heads="n_head",t.num_layers="n_layer",t.hidden_size="n_embd";break;case"gpt_neox":case"stablelm":case"opt":case"phi":case"phi3":case"falcon":t.num_heads="num_attention_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size";break;case"llama":case"cohere":case"mistral":case"starcoder2":case"qwen2":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.hidden_size="hidden_size",t.num_attention_heads="num_attention_heads";break;case"gemma":case"gemma2":t.num_heads="num_key_value_heads",t.num_layers="num_hidden_layers",t.dim_kv="head_dim";break;case"openelm":t.num_heads="num_kv_heads",t.num_layers="num_transformer_layers",t.dim_kv="head_dim";break;case"gpt_neo":case"donut-swin":t.num_heads="num_heads",t.num_layers="num_layers",t.hidden_size="hidden_size";break;case"bloom":t.num_heads="n_head",t.num_layers="n_layer",t.hidden_size="hidden_size";break;case"mpt":t.num_heads="n_heads",t.num_layers="n_layers",t.hidden_size="d_model";break;case"t5":case"mt5":case"longt5":t.num_decoder_layers="num_decoder_layers",t.num_decoder_heads="num_heads",t.decoder_dim_kv="d_kv",t.num_encoder_layers="num_layers",t.num_encoder_heads="num_heads",t.encoder_dim_kv="d_kv";break;case"bart":case"mbart":case"marian":case"whisper":case"m2m_100":case"blenderbot":case"blenderbot-small":case"florence2_language":t.num_decoder_layers="decoder_layers",t.num_decoder_heads="decoder_attention_heads",t.decoder_hidden_size="d_model",t.num_encoder_layers="encoder_layers",t.num_encoder_heads="encoder_attention_heads",t.encoder_hidden_size="d_model";break;case"speecht5":t.num_decoder_layers="decoder_layers",t.num_decoder_heads="decoder_attention_heads",t.decoder_hidden_size="hidden_size",t.num_encoder_layers="encoder_layers",t.num_encoder_heads="encoder_attention_heads",t.encoder_hidden_size="hidden_size";break;case"trocr":t.num_encoder_layers=t.num_decoder_layers="decoder_layers",t.num_encoder_heads=t.num_decoder_heads="decoder_attention_heads",t.encoder_hidden_size=t.decoder_hidden_size="d_model";break;case"musicgen_decoder":t.num_encoder_layers=t.num_decoder_layers="num_hidden_layers",t.num_encoder_heads=t.num_decoder_heads="num_attention_heads",t.encoder_hidden_size=t.decoder_hidden_size="hidden_size";break;case"vision-encoder-decoder":const i=a(e.decoder),s="num_decoder_layers"in i,o=(0,r.pick)(e,["model_type","is_encoder_decoder"]);return s?(o.num_decoder_layers=i.num_decoder_layers,o.num_decoder_heads=i.num_decoder_heads,o.decoder_hidden_size=i.decoder_hidden_size,o.num_encoder_layers=i.num_encoder_layers,o.num_encoder_heads=i.num_encoder_heads,o.encoder_hidden_size=i.encoder_hidden_size):(o.num_layers=i.num_layers,o.num_heads=i.num_heads,o.hidden_size=i.hidden_size),o}const i={...n,...(0,r.pick)(e,["model_type","multi_query","is_encoder_decoder"])};for(const n in t)i[n]=e[t[n]];return i}function s(e,{prefix:t="past_key_values"}={}){const n={},r=e.normalized_config;if(r.is_encoder_decoder&&"num_encoder_heads"in r&&"num_decoder_heads"in r){const e=r.encoder_dim_kv??r.encoder_hidden_size/r.num_encoder_heads,i=r.decoder_dim_kv??r.decoder_hidden_size/r.num_decoder_heads,a=[1,r.num_encoder_heads,0,e],s=[1,r.num_decoder_heads,0,i];for(let e=0;e<r.num_decoder_layers;++e)n[`${t}.${e}.encoder.key`]=a,n[`${t}.${e}.encoder.value`]=a,n[`${t}.${e}.decoder.key`]=s,n[`${t}.${e}.decoder.value`]=s}else{const e=r.num_heads,i=r.num_layers,a=r.dim_kv??r.hidden_size/(r.num_attention_heads??e);if("falcon"===r.model_type){const r=[1*e,0,a];for(let e=0;e<i;++e)n[`${t}.${e}.key`]=r,n[`${t}.${e}.value`]=r}else if(r.multi_query){const r=[1*e,0,2*a];for(let e=0;e<i;++e)n[`${t}.${e}.key_value`]=r}else if("bloom"===r.model_type){const r=[1*e,a,0],s=[1*e,0,a];for(let e=0;e<i;++e)n[`${t}.${e}.key`]=r,n[`${t}.${e}.value`]=s}else if("openelm"===r.model_type)for(let r=0;r<i;++r){const i=[1,e[r],0,a];n[`${t}.${r}.key`]=i,n[`${t}.${r}.value`]=i}else{const r=[1,e,0,a];for(let e=0;e<i;++e)n[`${t}.${e}.key`]=r,n[`${t}.${e}.value`]=r}}return n}class o{max_position_embeddings;constructor(e){this.model_type=null,this.is_encoder_decoder=!1,Object.assign(this,e),this.normalized_config=a(this)}static async from_pretrained(e,{progress_callback:t=null,config:n=null,cache_dir:r=null,local_files_only:a=!1,revision:s="main"}={}){!n||n instanceof o||(n=new o(n));const l=n??await async function(e,t){return await(0,i.getModelJSON)(e,"config.json",!0,t)}(e,{progress_callback:t,config:n,cache_dir:r,local_files_only:a,revision:s});return new this(l)}}class l{static async from_pretrained(...e){return o.from_pretrained(...e)}}},"./src/env.js":
@@ -217,13 +217,13 @@ var r,i,a,s,o,l,u,d,c,p,h,f,m,g,_,w,y,b,v,x,M,T,k,$,C,S,P,E,F,A,I,z,O,B=Object.d
217
217
  \**************************/(e,t,n)=>{n.r(t),n.d(t,{getFile:()=>u,getModelFile:()=>p,getModelJSON:()=>h});var r=n(/*! fs */"?7a2c"),i=n(/*! path */"?a42a"),a=n(/*! ../env.js */"./src/env.js"),s=n(/*! ./core.js */"./src/utils/core.js");class o{_CONTENT_TYPE_MAP={txt:"text/plain",html:"text/html",css:"text/css",js:"text/javascript",json:"application/json",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif"};constructor(e){if(this.filePath=e,this.headers=new Headers,this.exists=r.existsSync(e),this.exists){this.status=200,this.statusText="OK";let t=r.statSync(e);this.headers.set("content-length",t.size.toString()),this.updateContentType();let n=this;this.body=new ReadableStream({start(e){n.arrayBuffer().then((t=>{e.enqueue(new Uint8Array(t)),e.close()}))}})}else this.status=404,this.statusText="Not Found",this.body=null}updateContentType(){const e=this.filePath.toString().split(".").pop().toLowerCase();this.headers.set("content-type",this._CONTENT_TYPE_MAP[e]??"application/octet-stream")}clone(){let e=new o(this.filePath);return e.exists=this.exists,e.status=this.status,e.statusText=this.statusText,e.headers=new Headers(this.headers),e}async arrayBuffer(){return(await r.promises.readFile(this.filePath)).buffer}async blob(){const e=await r.promises.readFile(this.filePath);return new Blob([e],{type:this.headers.get("content-type")})}async text(){return await r.promises.readFile(this.filePath,"utf8")}async json(){return JSON.parse(await this.text())}}function l(e,t=null,n=null){let r;try{r=new URL(e)}catch(e){return!1}return!(t&&!t.includes(r.protocol))&&!(n&&!n.includes(r.hostname))}async function u(e){if(a.env.useFS&&!l(e,["http:","https:","blob:"]))return new o(e);if("undefined"!=typeof process&&"node"===process?.release?.name){const t=!!process.env?.TESTING_REMOTELY,n=a.env.version,r=new Headers;r.set("User-Agent",`transformers.js/${n}; is_ci/${t};`);if(l(e,["http:","https:"],["huggingface.co","hf.co"])){const e=process.env?.HF_TOKEN??process.env?.HF_ACCESS_TOKEN;e&&r.set("Authorization",`Bearer ${e}`)}return fetch(e,{headers:r})}return fetch(e)}const d={400:"Bad request error occurred while trying to load file",401:"Unauthorized access to file",403:"Forbidden access to file",404:"Could not locate file",408:"Request timeout error occurred while trying to load file",500:"Internal server error error occurred while trying to load file",502:"Bad gateway error occurred while trying to load file",503:"Service unavailable error occurred while trying to load file",504:"Gateway timeout error occurred while trying to load file"};class c{constructor(e){this.path=e}async match(e){let t=i.join(this.path,e),n=new o(t);return n.exists?n:void 0}async put(e,t){const n=Buffer.from(await t.arrayBuffer());let a=i.join(this.path,e);try{await r.promises.mkdir(i.dirname(a),{recursive:!0}),await r.promises.writeFile(a,n)}catch(e){console.warn("An error occurred while writing the file to cache:",e)}}}async function p(e,t,n=!0,r={}){if(!a.env.allowLocalModels){if(r.local_files_only)throw Error("Invalid configuration detected: local models are disabled (`env.allowLocalModels=false`) but you have requested to only use local models (`local_files_only=true`).");if(!a.env.allowRemoteModels)throw Error("Invalid configuration detected: both local and remote models are disabled. Fix by setting `env.allowLocalModels` or `env.allowRemoteModels` to `true`.")}let i;if((0,s.dispatchCallback)(r.progress_callback,{status:"initiate",name:e,file:t}),!i&&a.env.useBrowserCache){if("undefined"==typeof caches)throw Error("Browser cache is not available in this environment.");try{i=await caches.open("transformers-cache")}catch(e){console.warn("An error occurred while opening the browser cache:",e)}}if(!i&&a.env.useFSCache&&(i=new c(r.cache_dir??a.env.cacheDir)),!i&&a.env.useCustomCache){if(!a.env.customCache)throw Error("`env.useCustomCache=true`, but `env.customCache` is not defined.");if(!a.env.customCache.match||!a.env.customCache.put)throw new Error("`env.customCache` must be an object which implements the `match` and `put` functions of the Web Cache API. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache");i=a.env.customCache}const o=r.revision??"main";let p,h,m=f(e,t),g=f(a.env.localModelPath,m),_=f(a.env.remoteHost,a.env.remotePathTemplate.replaceAll("{model}",e).replaceAll("{revision}",encodeURIComponent(o)),t),w="main"===o?m:f(e,o,t),y=i instanceof c?w:_,b=!1;i&&(h=await async function(e,...t){for(let n of t)try{let t=await e.match(n);if(t)return t}catch(e){continue}}(i,g,y));const v=void 0!==h;if(void 0===h){if(a.env.allowLocalModels){if(l(m,["http:","https:"])){if(r.local_files_only)throw new Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${m}.`);if(!a.env.allowRemoteModels)throw new Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${m}.`)}else try{h=await u(g),p=g}catch(e){console.warn(`Unable to load from local path "${g}": "${e}"`)}}if(void 0===h||404===h.status){if(r.local_files_only||!a.env.allowRemoteModels){if(n)throw Error(`\`local_files_only=true\` or \`env.allowRemoteModels=false\` and file was not found locally at "${g}".`);return null}if(h=await u(_),200!==h.status)return function(e,t,n){if(!n)return null;const r=d[e]??`Error (${e}) occurred while trying to load file`;throw Error(`${r}: "${t}".`)}(h.status,_,n);p=y}b=i&&"undefined"!=typeof Response&&h instanceof Response&&200===h.status}(0,s.dispatchCallback)(r.progress_callback,{status:"download",name:e,file:t});const x={status:"progress",name:e,file:t};let M;return r.progress_callback?v&&"undefined"!=typeof navigator&&/firefox/i.test(navigator.userAgent)?(M=new Uint8Array(await h.arrayBuffer()),(0,s.dispatchCallback)(r.progress_callback,{...x,progress:100,loaded:M.length,total:M.length})):M=await async function(e,t){const n=e.headers.get("Content-Length");null===n&&console.warn("Unable to determine content-length from response headers. Will expand buffer when needed.");let r=parseInt(n??"0"),i=new Uint8Array(r),a=0;const s=e.body.getReader();async function o(){const{done:e,value:n}=await s.read();if(e)return;let l=a+n.length;if(l>r){r=l;let e=new Uint8Array(r);e.set(i),i=e}i.set(n,a),a=l;return t({progress:a/r*100,loaded:a,total:r}),o()}return await o(),i}(h,(e=>{(0,s.dispatchCallback)(r.progress_callback,{...x,...e})})):M=new Uint8Array(await h.arrayBuffer()),b&&p&&void 0===await i.match(p)&&await i.put(p,new Response(M,{headers:h.headers})).catch((e=>{console.warn(`Unable to add response to browser cache: ${e}.`)})),(0,s.dispatchCallback)(r.progress_callback,{status:"done",name:e,file:t}),M}async function h(e,t,n=!0,r={}){let i=await p(e,t,n,r);if(null===i)return{};let a=new TextDecoder("utf-8").decode(i);return JSON.parse(a)}function f(...e){return(e=e.map(((t,n)=>(n&&(t=t.replace(new RegExp("^/"),"")),n!==e.length-1&&(t=t.replace(new RegExp("/$"),"")),t)))).join("/")}},"./src/utils/image.js":
218
218
  /*!****************************!*\
219
219
  !*** ./src/utils/image.js ***!
220
- \****************************/(e,t,n)=>{n.r(t),n.d(t,{RawImage:()=>f});var r=n(/*! ./hub.js */"./src/utils/hub.js"),i=n(/*! ../env.js */"./src/env.js"),a=n(/*! ./tensor.js */"./src/utils/tensor.js"),s=n(/*! sharp */"sharp");const o="undefined"!=typeof self,l=o&&"DedicatedWorkerGlobalScope"===self.constructor.name;let u,d,c;if(o)u=(e,t)=>{if(!self.OffscreenCanvas)throw new Error("OffscreenCanvas not supported by this browser.");return new self.OffscreenCanvas(e,t)},c=self.createImageBitmap,d=self.ImageData;else{if(!s.default)throw new Error("Unable to load image processing library.");c=async e=>{const t=(await e.metadata()).channels,{data:n,info:r}=await e.rotate().raw().toBuffer({resolveWithObject:!0}),i=new f(new Uint8ClampedArray(n),r.width,r.height,r.channels);return void 0!==t&&t!==r.channels&&i.convert(t),i}}const p={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"},h=new Map([["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"]]);class f{constructor(e,t,n,r){this.data=e,this.width=t,this.height=n,this.channels=r}get size(){return[this.width,this.height]}static async read(e){if(e instanceof f)return e;if("string"==typeof e||e instanceof URL)return await this.fromURL(e);throw new Error("Unsupported input type: "+typeof e)}static fromCanvas(e){if(!o)throw new Error("fromCanvas() is only supported in browser environments.");const t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;return new f(t,e.width,e.height,4)}static async fromURL(e){const t=await(0,r.getFile)(e);if(200!==t.status)throw new Error(`Unable to read image from "${e}" (${t.status} ${t.statusText})`);const n=await t.blob();return this.fromBlob(n)}static async fromBlob(e){if(o){const t=await c(e),n=u(t.width,t.height).getContext("2d");return n.drawImage(t,0,0),new this(n.getImageData(0,0,t.width,t.height).data,t.width,t.height,4)}{const t=(0,s.default)(await e.arrayBuffer());return await c(t)}}static fromTensor(e,t="CHW"){if(3!==e.dims.length)throw new Error(`Tensor should have 3 dimensions, but has ${e.dims.length} dimensions.`);if("CHW"===t)e=e.transpose(1,2,0);else if("HWC"!==t)throw new Error(`Unsupported channel format: ${t}`);if(!(e.data instanceof Uint8ClampedArray||e.data instanceof Uint8Array))throw new Error(`Unsupported tensor type: ${e.type}`);switch(e.dims[2]){case 1:case 2:case 3:case 4:return new f(e.data,e.dims[1],e.dims[0],e.dims[2]);default:throw new Error(`Unsupported number of channels: ${e.dims[2]}`)}}grayscale(){if(1===this.channels)return this;const e=new Uint8ClampedArray(this.width*this.height*1);switch(this.channels){case 3:case 4:for(let t=0,n=0;t<this.data.length;t+=this.channels){const r=this.data[t],i=this.data[t+1],a=this.data[t+2];e[n++]=Math.round(.2989*r+.587*i+.114*a)}break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,1)}rgb(){if(3===this.channels)return this;const e=new Uint8ClampedArray(this.width*this.height*3);switch(this.channels){case 1:for(let t=0,n=0;t<this.data.length;++t)e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=this.data[t];break;case 4:for(let t=0,n=0;t<this.data.length;t+=4)e[n++]=this.data[t],e[n++]=this.data[t+1],e[n++]=this.data[t+2];break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,3)}rgba(){if(4===this.channels)return this;const e=new Uint8ClampedArray(this.width*this.height*4);switch(this.channels){case 1:for(let t=0,n=0;t<this.data.length;++t)e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=255;break;case 3:for(let t=0,n=0;t<this.data.length;t+=3)e[n++]=this.data[t],e[n++]=this.data[t+1],e[n++]=this.data[t+2],e[n++]=255;break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,4)}async resize(e,t,{resample:n=2}={}){let r=p[n]??n;if(o){const n=this.channels,r=this.toCanvas(),i=u(e,t).getContext("2d");i.drawImage(r,0,0,e,t);return new f(i.getImageData(0,0,e,t).data,e,t,4).convert(n)}{let n=this.toSharp();switch(r){case"box":case"hamming":"box"!==r&&"hamming"!==r||(console.warn(`Resampling method ${r} is not yet supported. Using bilinear instead.`),r="bilinear");case"nearest":case"bilinear":case"bicubic":n=n.affine([e/this.width,0,0,t/this.height],{interpolator:r});break;case"lanczos":n=n.resize({width:e,height:t,fit:"fill",kernel:"lanczos3"});break;default:throw new Error(`Resampling method ${r} is not supported.`)}return await c(n)}}async pad([e,t,n,r]){if(e=Math.max(e,0),t=Math.max(t,0),n=Math.max(n,0),r=Math.max(r,0),0===e&&0===t&&0===n&&0===r)return this;if(o){const i=this.channels,a=this.toCanvas(),s=this.width+e+t,o=this.height+n+r,l=u(s,o).getContext("2d");l.drawImage(a,0,0,this.width,this.height,e,n,s,o);return new f(l.getImageData(0,0,s,o).data,s,o,4).convert(i)}{const i=this.toSharp().extend({left:e,right:t,top:n,bottom:r});return await c(i)}}async crop([e,t,n,r]){if(e=Math.max(e,0),t=Math.max(t,0),n=Math.min(n,this.width-1),r=Math.min(r,this.height-1),0===e&&0===t&&n===this.width-1&&r===this.height-1)return this;const i=n-e+1,a=r-t+1;if(o){const n=this.channels,r=this.toCanvas(),s=u(i,a).getContext("2d");s.drawImage(r,e,t,i,a,0,0,i,a);return new f(s.getImageData(0,0,i,a).data,i,a,4).convert(n)}{const n=this.toSharp().extract({left:e,top:t,width:i,height:a});return await c(n)}}async center_crop(e,t){if(this.width===e&&this.height===t)return this;const n=(this.width-e)/2,r=(this.height-t)/2;if(o){const i=this.channels,a=this.toCanvas(),s=u(e,t).getContext("2d");let o=0,l=0,d=0,c=0;n>=0?o=n:d=-n,r>=0?l=r:c=-r,s.drawImage(a,o,l,e,t,d,c,e,t);return new f(s.getImageData(0,0,e,t).data,e,t,4).convert(i)}{let i=this.toSharp();if(n>=0&&r>=0)i=i.extract({left:Math.floor(n),top:Math.floor(r),width:e,height:t});else if(n<=0&&r<=0){const a=Math.floor(-r),s=Math.floor(-n);i=i.extend({top:a,left:s,right:e-this.width-s,bottom:t-this.height-a})}else{let a=[0,0],s=0;r<0?(a[0]=Math.floor(-r),a[1]=t-this.height-a[0]):s=Math.floor(r);let o=[0,0],l=0;n<0?(o[0]=Math.floor(-n),o[1]=e-this.width-o[0]):l=Math.floor(n),i=i.extend({top:a[0],bottom:a[1],left:o[0],right:o[1]}).extract({left:l,top:s,width:e,height:t})}return await c(i)}}async toBlob(e="image/png",t=1){if(!o)throw new Error("toBlob() is only supported in browser environments.");const n=this.toCanvas();return await n.convertToBlob({type:e,quality:t})}toTensor(e="CHW"){let t=new a.Tensor("uint8",new Uint8Array(this.data),[this.height,this.width,this.channels]);if("HWC"===e);else{if("CHW"!==e)throw new Error(`Unsupported channel format: ${e}`);t=t.permute(2,0,1)}return t}toCanvas(){if(!o)throw new Error("toCanvas() is only supported in browser environments.");const e=this.clone().rgba(),t=u(e.width,e.height),n=new d(e.data,e.width,e.height);return t.getContext("2d").putImageData(n,0,0),t}_update(e,t,n,r=null){return this.data=e,this.width=t,this.height=n,null!==r&&(this.channels=r),this}clone(){return new f(this.data.slice(),this.width,this.height,this.channels)}convert(e){if(this.channels===e)return this;switch(e){case 1:this.grayscale();break;case 3:this.rgb();break;case 4:this.rgba();break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this}async save(e){if(!o){if(i.env.useFS){const t=this.toSharp();return await t.toFile(e)}throw new Error("Unable to save the image because filesystem is disabled in this environment.")}{if(l)throw new Error("Unable to save an image from a Web Worker.");const t=e.split(".").pop().toLowerCase(),n=h.get(t)??"image/png",r=await this.toBlob(n),i=URL.createObjectURL(r),a=document.createElement("a");a.href=i,a.download=e,a.click(),a.remove()}}toSharp(){if(o)throw new Error("toSharp() is only supported in server-side environments.");return(0,s.default)(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}}},"./src/utils/maths.js":
220
+ \****************************/(e,t,n)=>{n.r(t),n.d(t,{RawImage:()=>f});var r=n(/*! ./hub.js */"./src/utils/hub.js"),i=n(/*! ../env.js */"./src/env.js"),a=n(/*! ./tensor.js */"./src/utils/tensor.js"),s=n(/*! sharp */"?2b25");const o="undefined"!=typeof self,l=o&&"DedicatedWorkerGlobalScope"===self.constructor.name;let u,d,c;if(o)u=(e,t)=>{if(!self.OffscreenCanvas)throw new Error("OffscreenCanvas not supported by this browser.");return new self.OffscreenCanvas(e,t)},c=self.createImageBitmap,d=self.ImageData;else{if(!s)throw new Error("Unable to load image processing library.");c=async e=>{const t=(await e.metadata()).channels,{data:n,info:r}=await e.rotate().raw().toBuffer({resolveWithObject:!0}),i=new f(new Uint8ClampedArray(n),r.width,r.height,r.channels);return void 0!==t&&t!==r.channels&&i.convert(t),i}}const p={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"},h=new Map([["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"]]);class f{constructor(e,t,n,r){this.data=e,this.width=t,this.height=n,this.channels=r}get size(){return[this.width,this.height]}static async read(e){if(e instanceof f)return e;if("string"==typeof e||e instanceof URL)return await this.fromURL(e);throw new Error("Unsupported input type: "+typeof e)}static fromCanvas(e){if(!o)throw new Error("fromCanvas() is only supported in browser environments.");const t=e.getContext("2d").getImageData(0,0,e.width,e.height).data;return new f(t,e.width,e.height,4)}static async fromURL(e){const t=await(0,r.getFile)(e);if(200!==t.status)throw new Error(`Unable to read image from "${e}" (${t.status} ${t.statusText})`);const n=await t.blob();return this.fromBlob(n)}static async fromBlob(e){if(o){const t=await c(e),n=u(t.width,t.height).getContext("2d");return n.drawImage(t,0,0),new this(n.getImageData(0,0,t.width,t.height).data,t.width,t.height,4)}{const t=s(await e.arrayBuffer());return await c(t)}}static fromTensor(e,t="CHW"){if(3!==e.dims.length)throw new Error(`Tensor should have 3 dimensions, but has ${e.dims.length} dimensions.`);if("CHW"===t)e=e.transpose(1,2,0);else if("HWC"!==t)throw new Error(`Unsupported channel format: ${t}`);if(!(e.data instanceof Uint8ClampedArray||e.data instanceof Uint8Array))throw new Error(`Unsupported tensor type: ${e.type}`);switch(e.dims[2]){case 1:case 2:case 3:case 4:return new f(e.data,e.dims[1],e.dims[0],e.dims[2]);default:throw new Error(`Unsupported number of channels: ${e.dims[2]}`)}}grayscale(){if(1===this.channels)return this;const e=new Uint8ClampedArray(this.width*this.height*1);switch(this.channels){case 3:case 4:for(let t=0,n=0;t<this.data.length;t+=this.channels){const r=this.data[t],i=this.data[t+1],a=this.data[t+2];e[n++]=Math.round(.2989*r+.587*i+.114*a)}break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,1)}rgb(){if(3===this.channels)return this;const e=new Uint8ClampedArray(this.width*this.height*3);switch(this.channels){case 1:for(let t=0,n=0;t<this.data.length;++t)e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=this.data[t];break;case 4:for(let t=0,n=0;t<this.data.length;t+=4)e[n++]=this.data[t],e[n++]=this.data[t+1],e[n++]=this.data[t+2];break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,3)}rgba(){if(4===this.channels)return this;const e=new Uint8ClampedArray(this.width*this.height*4);switch(this.channels){case 1:for(let t=0,n=0;t<this.data.length;++t)e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=this.data[t],e[n++]=255;break;case 3:for(let t=0,n=0;t<this.data.length;t+=3)e[n++]=this.data[t],e[n++]=this.data[t+1],e[n++]=this.data[t+2],e[n++]=255;break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,4)}async resize(e,t,{resample:n=2}={}){let r=p[n]??n;if(o){const n=this.channels,r=this.toCanvas(),i=u(e,t).getContext("2d");i.drawImage(r,0,0,e,t);return new f(i.getImageData(0,0,e,t).data,e,t,4).convert(n)}{let n=this.toSharp();switch(r){case"box":case"hamming":"box"!==r&&"hamming"!==r||(console.warn(`Resampling method ${r} is not yet supported. Using bilinear instead.`),r="bilinear");case"nearest":case"bilinear":case"bicubic":n=n.affine([e/this.width,0,0,t/this.height],{interpolator:r});break;case"lanczos":n=n.resize({width:e,height:t,fit:"fill",kernel:"lanczos3"});break;default:throw new Error(`Resampling method ${r} is not supported.`)}return await c(n)}}async pad([e,t,n,r]){if(e=Math.max(e,0),t=Math.max(t,0),n=Math.max(n,0),r=Math.max(r,0),0===e&&0===t&&0===n&&0===r)return this;if(o){const i=this.channels,a=this.toCanvas(),s=this.width+e+t,o=this.height+n+r,l=u(s,o).getContext("2d");l.drawImage(a,0,0,this.width,this.height,e,n,s,o);return new f(l.getImageData(0,0,s,o).data,s,o,4).convert(i)}{const i=this.toSharp().extend({left:e,right:t,top:n,bottom:r});return await c(i)}}async crop([e,t,n,r]){if(e=Math.max(e,0),t=Math.max(t,0),n=Math.min(n,this.width-1),r=Math.min(r,this.height-1),0===e&&0===t&&n===this.width-1&&r===this.height-1)return this;const i=n-e+1,a=r-t+1;if(o){const n=this.channels,r=this.toCanvas(),s=u(i,a).getContext("2d");s.drawImage(r,e,t,i,a,0,0,i,a);return new f(s.getImageData(0,0,i,a).data,i,a,4).convert(n)}{const n=this.toSharp().extract({left:e,top:t,width:i,height:a});return await c(n)}}async center_crop(e,t){if(this.width===e&&this.height===t)return this;const n=(this.width-e)/2,r=(this.height-t)/2;if(o){const i=this.channels,a=this.toCanvas(),s=u(e,t).getContext("2d");let o=0,l=0,d=0,c=0;n>=0?o=n:d=-n,r>=0?l=r:c=-r,s.drawImage(a,o,l,e,t,d,c,e,t);return new f(s.getImageData(0,0,e,t).data,e,t,4).convert(i)}{let i=this.toSharp();if(n>=0&&r>=0)i=i.extract({left:Math.floor(n),top:Math.floor(r),width:e,height:t});else if(n<=0&&r<=0){const a=Math.floor(-r),s=Math.floor(-n);i=i.extend({top:a,left:s,right:e-this.width-s,bottom:t-this.height-a})}else{let a=[0,0],s=0;r<0?(a[0]=Math.floor(-r),a[1]=t-this.height-a[0]):s=Math.floor(r);let o=[0,0],l=0;n<0?(o[0]=Math.floor(-n),o[1]=e-this.width-o[0]):l=Math.floor(n),i=i.extend({top:a[0],bottom:a[1],left:o[0],right:o[1]}).extract({left:l,top:s,width:e,height:t})}return await c(i)}}async toBlob(e="image/png",t=1){if(!o)throw new Error("toBlob() is only supported in browser environments.");const n=this.toCanvas();return await n.convertToBlob({type:e,quality:t})}toTensor(e="CHW"){let t=new a.Tensor("uint8",new Uint8Array(this.data),[this.height,this.width,this.channels]);if("HWC"===e);else{if("CHW"!==e)throw new Error(`Unsupported channel format: ${e}`);t=t.permute(2,0,1)}return t}toCanvas(){if(!o)throw new Error("toCanvas() is only supported in browser environments.");const e=this.clone().rgba(),t=u(e.width,e.height),n=new d(e.data,e.width,e.height);return t.getContext("2d").putImageData(n,0,0),t}_update(e,t,n,r=null){return this.data=e,this.width=t,this.height=n,null!==r&&(this.channels=r),this}clone(){return new f(this.data.slice(),this.width,this.height,this.channels)}convert(e){if(this.channels===e)return this;switch(e){case 1:this.grayscale();break;case 3:this.rgb();break;case 4:this.rgba();break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this}async save(e){if(!o){if(i.env.useFS){const t=this.toSharp();return await t.toFile(e)}throw new Error("Unable to save the image because filesystem is disabled in this environment.")}{if(l)throw new Error("Unable to save an image from a Web Worker.");const t=e.split(".").pop().toLowerCase(),n=h.get(t)??"image/png",r=await this.toBlob(n),i=URL.createObjectURL(r),a=document.createElement("a");a.href=i,a.download=e,a.click(),a.remove()}}toSharp(){if(o)throw new Error("toSharp() is only supported in server-side environments.");return s(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}}},"./src/utils/maths.js":
221
221
  /*!****************************!*\
222
222
  !*** ./src/utils/maths.js ***!
223
223
  \****************************/(e,t,n)=>{function r(e,[t,n,r],[i,a],s="bilinear",o=!1){const l=a/r,u=i/n,d=new e.constructor(i*a*t),c=n*r,p=i*a;for(let s=0;s<i;++s)for(let i=0;i<a;++i){const o=s*a+i,h=(i+.5)/l-.5,f=(s+.5)/u-.5;let m=Math.floor(h),g=Math.floor(f);const _=Math.min(m+1,r-1),w=Math.min(g+1,n-1);m=Math.max(m,0),g=Math.max(g,0);const y=h-m,b=f-g,v=(1-y)*(1-b),x=y*(1-b),M=(1-y)*b,T=y*b,k=g*r,$=w*r,C=k+m,S=k+_,P=$+m,E=$+_;for(let n=0;n<t;++n){const t=n*c;d[n*p+o]=v*e[t+C]+x*e[t+S]+M*e[t+P]+T*e[t+E]}}return d}function i(e,t,n){const r=new Array(n.length),i=new Array(n.length);for(let e=n.length-1,a=1;e>=0;--e)i[e]=a,r[e]=t[n[e]],a*=r[e];const a=n.map(((e,t)=>i[n.indexOf(t)])),s=new e.constructor(e.length);for(let n=0;n<e.length;++n){let r=0;for(let e=t.length-1,i=n;e>=0;--e)r+=i%t[e]*a[e],i=Math.floor(i/t[e]);s[r]=e[n]}return[s,r]}function a(e){const t=c(e)[0],n=e.map((e=>Math.exp(e-t))),r=n.reduce(((e,t)=>e+t),0);return n.map((e=>e/r))}function s(e){return a(e).map((e=>Math.log(e)))}function o(e,t){let n=0;for(let r=0;r<e.length;++r)n+=e[r]*t[r];return n}function l(e,t){return o(e,t)/(u(e)*u(t))}function u(e){return Math.sqrt(e.reduce(((e,t)=>e+t*t),0))}function d(e){if(0===e.length)throw Error("Array must not be empty");let t=e[0],n=0;for(let r=1;r<e.length;++r)e[r]<t&&(t=e[r],n=r);return[t,n]}function c(e){if(0===e.length)throw Error("Array must not be empty");let t=e[0],n=0;for(let r=1;r<e.length;++r)e[r]>t&&(t=e[r],n=r);return[Number(t),n]}function p(e){return e>0&&0==(e&e-1)}n.r(t),n.d(t,{FFT:()=>m,bankers_round:()=>w,cos_sim:()=>l,dot:()=>o,dynamic_time_warping:()=>y,interpolate_data:()=>r,log_softmax:()=>s,magnitude:()=>u,max:()=>c,medianFilter:()=>g,min:()=>d,permute_data:()=>i,round:()=>_,softmax:()=>a});class h{constructor(e){if(this.size=0|e,this.size<=1||!p(this.size))throw new Error("FFT size must be a power of two larger than 1");this._csize=e<<1,this.table=new Float64Array(2*this.size);for(let e=0;e<this.table.length;e+=2){const t=Math.PI*e/this.size;this.table[e]=Math.cos(t),this.table[e+1]=-Math.sin(t)}let t=0;for(let e=1;this.size>e;e<<=1)++t;this._width=t%2==0?t-1:t,this._bitrev=new Int32Array(1<<this._width);for(let e=0;e<this._bitrev.length;++e){this._bitrev[e]=0;for(let t=0;t<this._width;t+=2){const n=this._width-t-2;this._bitrev[e]|=(e>>>t&3)<<n}}}createComplexArray(){return new Float64Array(this._csize)}fromComplexArray(e,t){const n=t||new Array(e.length>>>1);for(let t=0;t<e.length;t+=2)n[t>>>1]=e[t];return n}toComplexArray(e,t){const n=t||this.createComplexArray();for(let t=0;t<n.length;t+=2)n[t]=e[t>>>1],n[t+1]=0;return n}transform(e,t){if(e===t)throw new Error("Input and output buffers must be different");this._transform4(e,t,1)}realTransform(e,t){if(e===t)throw new Error("Input and output buffers must be different");this._realTransform4(e,t,1)}inverseTransform(e,t){if(e===t)throw new Error("Input and output buffers must be different");this._transform4(e,t,-1);for(let t=0;t<e.length;++t)e[t]/=this.size}_transform4(e,t,n){const r=this._csize;let i,a,s=1<<this._width,o=r/s<<1;const l=this._bitrev;if(4===o)for(i=0,a=0;i<r;i+=o,++a){const n=l[a];this._singleTransform2(t,e,i,n,s)}else for(i=0,a=0;i<r;i+=o,++a){const r=l[a];this._singleTransform4(t,e,i,r,s,n)}const u=this.table;for(s>>=2;s>=2;s>>=2){o=r/s<<1;const t=o>>>2;for(i=0;i<r;i+=o){const r=i+t-1;for(let a=i,o=0;a<r;a+=2,o+=s){const r=a,i=r+t,s=i+t,l=s+t,d=e[r],c=e[r+1],p=e[i],h=e[i+1],f=e[s],m=e[s+1],g=e[l],_=e[l+1],w=u[o],y=n*u[o+1],b=p*w-h*y,v=p*y+h*w,x=u[2*o],M=n*u[2*o+1],T=f*x-m*M,k=f*M+m*x,$=u[3*o],C=n*u[3*o+1],S=g*$-_*C,P=g*C+_*$,E=d+T,F=c+k,A=d-T,I=c-k,z=b+S,O=v+P,B=n*(b-S),L=n*(v-P);e[r]=E+z,e[r+1]=F+O,e[i]=A+L,e[i+1]=I-B,e[s]=E-z,e[s+1]=F-O,e[l]=A-L,e[l+1]=I+B}}}}_singleTransform2(e,t,n,r,i){const a=e[r],s=e[r+1],o=e[r+i],l=e[r+i+1];t[n]=a+o,t[n+1]=s+l,t[n+2]=a-o,t[n+3]=s-l}_singleTransform4(e,t,n,r,i,a){const s=2*i,o=3*i,l=e[r],u=e[r+1],d=e[r+i],c=e[r+i+1],p=e[r+s],h=e[r+s+1],f=e[r+o],m=e[r+o+1],g=l+p,_=u+h,w=l-p,y=u-h,b=d+f,v=c+m,x=a*(d-f),M=a*(c-m);t[n]=g+b,t[n+1]=_+v,t[n+2]=w+M,t[n+3]=y-x,t[n+4]=g-b,t[n+5]=_-v,t[n+6]=w-M,t[n+7]=y+x}_realTransform4(e,t,n){const r=this._csize;let i,a,s=1<<this._width,o=r/s<<1;const l=this._bitrev;if(4===o)for(i=0,a=0;i<r;i+=o,++a){const n=l[a];this._singleRealTransform2(t,e,i,n>>>1,s>>>1)}else for(i=0,a=0;i<r;i+=o,++a){const r=l[a];this._singleRealTransform4(t,e,i,r>>>1,s>>>1,n)}const u=this.table;for(s>>=2;s>=2;s>>=2){o=r/s<<1;const t=o>>>1,a=t>>>1,l=a>>>1;for(i=0;i<r;i+=o)for(let r=0,o=0;r<=l;r+=2,o+=s){const s=i+r,d=s+a,c=d+a,p=c+a,h=e[s],f=e[s+1],m=e[d],g=e[d+1],_=e[c],w=e[c+1],y=e[p],b=e[p+1],v=h,x=f,M=u[o],T=n*u[o+1],k=m*M-g*T,$=m*T+g*M,C=u[2*o],S=n*u[2*o+1],P=_*C-w*S,E=_*S+w*C,F=u[3*o],A=n*u[3*o+1],I=y*F-b*A,z=y*A+b*F,O=v+P,B=x+E,L=v-P,D=x-E,R=k+I,N=$+z,V=n*(k-I),j=n*($-z);if(e[s]=O+R,e[s+1]=B+N,e[d]=L+j,e[d+1]=D-V,0===r){e[c]=O-R,e[c+1]=B-N;continue}if(r===l)continue;const G=i+a-r,U=i+t-r;e[G]=L-n*j,e[G+1]=-D-n*V,e[U]=O-n*R,e[U+1]=n*N-B}}const d=r>>>1;for(let t=2;t<d;t+=2)e[r-t]=e[t],e[r-t+1]=-e[t+1]}_singleRealTransform2(e,t,n,r,i){const a=e[r],s=e[r+i];t[n]=a+s,t[n+1]=0,t[n+2]=a-s,t[n+3]=0}_singleRealTransform4(e,t,n,r,i,a){const s=2*i,o=3*i,l=e[r],u=e[r+i],d=e[r+s],c=e[r+o],p=l+d,h=l-d,f=u+c,m=a*(u-c);t[n]=p+f,t[n+1]=0,t[n+2]=h,t[n+3]=-m,t[n+4]=p-f,t[n+5]=0,t[n+6]=h,t[n+7]=m}}class f{constructor(e){const t=2*(e-1),n=2*(2*e-1),r=2**Math.ceil(Math.log2(n));this.bufferSize=r,this._a=t;const i=new Float64Array(n),a=new Float64Array(r);this._chirpBuffer=new Float64Array(r),this._buffer1=new Float64Array(r),this._buffer2=new Float64Array(r),this._outBuffer1=new Float64Array(r),this._outBuffer2=new Float64Array(r);const s=-2*Math.PI/e,o=Math.cos(s),l=Math.sin(s);for(let t=0;t<n>>1;++t){const n=(t+1-e)**2/2,r=Math.sqrt(o**2+l**2)**n,s=n*Math.atan2(l,o),u=2*t;i[u]=r*Math.cos(s),i[u+1]=r*Math.sin(s),a[u]=i[u],a[u+1]=-i[u+1]}this._slicedChirpBuffer=i.subarray(t,n),this._f=new h(r>>1),this._f.transform(this._chirpBuffer,a)}_transform(e,t,n){const r=this._buffer1,i=this._buffer2,a=this._outBuffer1,s=this._outBuffer2,o=this._chirpBuffer,l=this._slicedChirpBuffer,u=this._a;if(n)for(let e=0;e<l.length;e+=2){const n=e+1,i=t[e>>1];r[e]=i*l[e],r[n]=i*l[n]}else for(let e=0;e<l.length;e+=2){const n=e+1;r[e]=t[e]*l[e]-t[n]*l[n],r[n]=t[e]*l[n]+t[n]*l[e]}this._f.transform(a,r);for(let e=0;e<o.length;e+=2){const t=e+1;i[e]=a[e]*o[e]-a[t]*o[t],i[t]=a[e]*o[t]+a[t]*o[e]}this._f.inverseTransform(s,i);for(let t=0;t<s.length;t+=2){const n=s[t+u],r=s[t+u+1],i=l[t],a=l[t+1];e[t]=n*i-r*a,e[t+1]=n*a+r*i}}transform(e,t){this._transform(e,t,!1)}realTransform(e,t){this._transform(e,t,!0)}}class m{constructor(e){this.fft_length=e,this.isPowerOfTwo=p(e),this.isPowerOfTwo?(this.fft=new h(e),this.outputBufferSize=2*e):(this.fft=new f(e),this.outputBufferSize=this.fft.bufferSize)}realTransform(e,t){this.fft.realTransform(e,t)}transform(e,t){this.fft.transform(e,t)}}function g(e,t){if(t%2==0||t<=0)throw new Error("Window size must be a positive odd number");const n=new e.constructor(e.length),r=new e.constructor(t),i=Math.floor(t/2);for(let t=0;t<e.length;++t){let a=0;for(let n=-i;n<=i;++n){let i=t+n;i<0?i=Math.abs(i):i>=e.length&&(i=2*(e.length-1)-i),r[a++]=e[i]}r.sort(),n[t]=r[i]}return n}function _(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}function w(e){const t=Math.round(e);return Math.abs(e)%1==.5?t%2==0?t:t-1:t}function y(e){const t=e.length,n=e[0].length,r=[t+1,n+1],i=Array.from({length:r[0]},(()=>Array(r[1]).fill(1/0)));i[0][0]=0;const a=Array.from({length:r[0]},(()=>Array(r[1]).fill(-1)));for(let t=1;t<r[1];++t)for(let n=1;n<r[0];++n){const r=i[n-1][t-1],s=i[n-1][t],o=i[n][t-1];let l,u;r<s&&r<o?(l=r,u=0):s<r&&s<o?(l=s,u=1):(l=o,u=2),i[n][t]=e[n-1][t-1]+l,a[n][t]=u}for(let e=0;e<r[1];++e)a[0][e]=2;for(let e=0;e<r[0];++e)a[e][0]=1;let s=t,o=n,l=[],u=[];for(;s>0||o>0;)switch(l.push(s-1),u.push(o-1),a[s][o]){case 0:--s,--o;break;case 1:--s;break;case 2:--o;break;default:throw new Error(`Internal error in dynamic time warping. Unexpected trace[${s}, ${o}]. Please file a bug report.`)}return l.reverse(),u.reverse(),[l,u]}},"./src/utils/tensor.js":
224
224
  /*!*****************************!*\
225
225
  !*** ./src/utils/tensor.js ***!
226
- \*****************************/(e,t,n)=>{n.r(t),n.d(t,{Tensor:()=>o,cat:()=>y,full:()=>T,full_like:()=>k,interpolate:()=>u,interpolate_4d:()=>d,layer_norm:()=>m,matmul:()=>c,mean:()=>x,mean_pooling:()=>f,ones:()=>$,ones_like:()=>C,permute:()=>l,quantize_embeddings:()=>E,rfft:()=>p,stack:()=>b,std_mean:()=>v,topk:()=>h,zeros:()=>S,zeros_like:()=>P});var r=n(/*! ./maths.js */"./src/utils/maths.js"),i=n(/*! ../backends/onnx.js */"./src/backends/onnx.js"),a=n(/*! ../ops/registry.js */"./src/ops/registry.js");const s=Object.freeze({float32:Float32Array,float16:Uint16Array,float64:Float64Array,string:Array,int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,int64:BigInt64Array,uint64:BigUint64Array,bool:Uint8Array});class o{get dims(){return this.ort_tensor.dims}set dims(e){this.ort_tensor.dims=e}get type(){return this.ort_tensor.type}get data(){return this.ort_tensor.data}get size(){return this.ort_tensor.size}get location(){return this.ort_tensor.location}ort_tensor;constructor(...e){return(0,i.isONNXTensor)(e[0])?this.ort_tensor=e[0]:this.ort_tensor=new i.Tensor(e[0],e[1],e[2]),new Proxy(this,{get:(e,t)=>{if("string"==typeof t){let n=Number(t);if(Number.isInteger(n))return e._getitem(n)}return e[t]},set:(e,t,n)=>e[t]=n})}dispose(){this.ort_tensor.dispose()}*[Symbol.iterator](){const[e,...t]=this.dims;if(t.length>0){const n=t.reduce(((e,t)=>e*t));for(let r=0;r<e;++r)yield this._subarray(r,n,t)}else yield*this.data}_getitem(e){const[t,...n]=this.dims;if(e=w(e,t),n.length>0){const t=n.reduce(((e,t)=>e*t));return this._subarray(e,t,n)}return new o(this.type,[this.data[e]],n)}indexOf(e){const t=this.data;for(let n=0;n<t.length;++n)if(t[n]==e)return n;return-1}_subarray(e,t,n){const r=e*t,i=(e+1)*t,a="subarray"in this.data?this.data.subarray(r,i):this.data.slice(r,i);return new o(this.type,a,n)}item(){const e=this.data;if(1!==e.length)throw new Error(`a Tensor with ${e.length} elements cannot be converted to Scalar`);return e[0]}tolist(){return function(e,t){const n=e.length,r=t.reduce(((e,t)=>e*t));if(n!==r)throw Error(`cannot reshape array of size ${n} into shape (${t})`);let i=e;for(let e=t.length-1;e>=0;e--)i=i.reduce(((n,r)=>{let i=n[n.length-1];return i.length<t[e]?i.push(r):n.push([r]),n}),[[]]);return i[0]}(this.data,this.dims)}sigmoid(){return this.clone().sigmoid_()}sigmoid_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=1/(1+Math.exp(-e[t]));return this}mul(e){return this.clone().mul_(e)}mul_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]*=e;return this}div(e){return this.clone().div_(e)}div_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]/=e;return this}add(e){return this.clone().add_(e)}add_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]+=e;return this}clone(){return new o(this.type,this.data.slice(),this.dims.slice())}slice(...e){const t=[],n=[];for(let r=0;r<this.dims.length;++r){let i=e[r];if(null==i)n.push([0,this.dims[r]]),t.push(this.dims[r]);else if("number"==typeof i)i=w(i,this.dims[r],r),n.push([i,i+1]);else{if(!Array.isArray(i)||2!==i.length)throw new Error(`Invalid slice: ${i}`);{let[e,a]=i;if(e=null===e?0:w(e,this.dims[r],r,!1),a=null===a?this.dims[r]:w(a,this.dims[r],r,!1),e>a)throw new Error(`Invalid slice: ${i}`);const s=[Math.max(e,0),Math.min(a,this.dims[r])];n.push(s),t.push(s[1]-s[0])}}}const r=n.map((([e,t])=>t-e)),i=r.reduce(((e,t)=>e*t)),a=this.data,s=new a.constructor(i),l=this.stride();for(let e=0;e<i;++e){let t=0;for(let i=r.length-1,a=e;i>=0;--i){const e=r[i];t+=(a%e+n[i][0])*l[i],a=Math.floor(a/e)}s[e]=a[t]}return new o(this.type,s,t)}permute(...e){return l(this,e)}transpose(...e){return this.permute(...e)}sum(e=null,t=!1){return this.norm(1,e,t)}norm(e="fro",t=null,n=!1){if("fro"===e)e=2;else if("string"==typeof e)throw Error(`Unsupported norm: ${e}`);const r=this.data;if(null===t){let t=r.reduce(((t,n)=>t+n**e),0)**(1/e);return new o(this.type,[t],[])}t=w(t,this.dims.length);const i=this.dims.slice();i[t]=1;const a=new r.constructor(r.length/this.dims[t]);for(let n=0;n<r.length;++n){let s=0;for(let e=this.dims.length-1,r=n,a=1;e>=0;--e){const n=this.dims[e];if(e!==t){s+=r%n*a,a*=i[e]}r=Math.floor(r/n)}a[s]+=r[n]**e}if(1!==e)for(let t=0;t<a.length;++t)a[t]=a[t]**(1/e);return n||i.splice(t,1),new o(this.type,a,i)}normalize_(e=2,t=1){t=w(t,this.dims.length);const n=this.norm(e,t,!0),r=this.data,i=n.data;for(let e=0;e<r.length;++e){let n=0;for(let r=this.dims.length-1,i=e,a=1;r>=0;--r){const e=this.dims[r];if(r!==t){n+=i%e*a,a*=this.dims[r]}i=Math.floor(i/e)}r[e]/=i[n]}return this}normalize(e=2,t=1){return this.clone().normalize_(e,t)}stride(){return function(e){const t=new Array(e.length);for(let n=e.length-1,r=1;n>=0;--n)t[n]=r,r*=e[n];return t}(this.dims)}squeeze(e=null){return new o(this.type,this.data,g(this.dims,e))}squeeze_(e=null){return this.dims=g(this.dims,e),this}unsqueeze(e=null){return new o(this.type,this.data,_(this.dims,e))}unsqueeze_(e=null){return this.dims=_(this.dims,e),this}flatten_(e=0,t=-1){t=(t+this.dims.length)%this.dims.length;let n=this.dims.slice(0,e),r=this.dims.slice(e,t+1),i=this.dims.slice(t+1);return this.dims=[...n,r.reduce(((e,t)=>e*t),1),...i],this}flatten(e=0,t=-1){return this.clone().flatten_(e,t)}view(...e){let t=-1;for(let n=0;n<e.length;++n)if(-1===e[n]){if(-1!==t)throw new Error("Only one dimension can be inferred");t=n}const n=this.data;if(-1!==t){const r=e.reduce(((e,n,r)=>r!==t?e*n:e),1);e[t]=n.length/r}return new o(this.type,n,e)}neg_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=-e[t];return this}neg(){return this.clone().neg_()}clamp_(e,t){const n=this.data;for(let r=0;r<n.length;++r)n[r]=Math.min(Math.max(n[r],e),t);return this}clamp(e,t){return this.clone().clamp_(e,t)}round_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=Math.round(e[t]);return this}round(){return this.clone().round_()}mean(e=null,t=!1){return x(this,e,t)}to(e){if(this.type===e)return this;if(!s.hasOwnProperty(e))throw new Error(`Unsupported type: ${e}`);return new o(e,s[e].from(this.data),this.dims)}}function l(e,t){const[n,i]=(0,r.permute_data)(e.data,e.dims,t);return new o(e.type,n,i)}function u(e,[t,n],i="bilinear",a=!1){const s=e.dims.at(-3)??1,l=e.dims.at(-2),u=e.dims.at(-1);let d=(0,r.interpolate_data)(e.data,[s,l,u],[t,n],i,a);return new o(e.type,d,[s,t,n])}async function d(e,{size:t=null,mode:n="bilinear"}={}){if(4!==e.dims.length)throw new Error("`interpolate_4d` currently only supports 4D input.");if(!t)throw new Error("`interpolate_4d` requires a `size` argument.");let r,i;if(2===t.length)r=[...e.dims.slice(0,2),...t];else if(3===t.length)r=[e.dims[0],...t];else{if(4!==t.length)throw new Error("`size` must be of length 2, 3, or 4.");r=t}if("bilinear"===n)i=await a.TensorOpRegistry.bilinear_interpolate_4d;else{if("bicubic"!==n)throw new Error(`Unsupported mode: ${n}`);i=await a.TensorOpRegistry.bicubic_interpolate_4d}const s=new o("int64",new BigInt64Array(r.map(BigInt)),[r.length]);return await i({x:e,s})}async function c(e,t){const n=await a.TensorOpRegistry.matmul;return await n({a:e,b:t})}async function p(e,t){const n=await a.TensorOpRegistry.rfft;return await n({x:e,a:t})}async function h(e,t){const n=await a.TensorOpRegistry.top_k;return t=null===t?e.dims.at(-1):Math.min(t,e.dims.at(-1)),await n({x:e,k:new o("int64",[BigInt(t)],[1])})}function f(e,t){const n=e.data,r=t.data,i=[e.dims[0],e.dims[2]],a=new n.constructor(i[0]*i[1]),[s,l,u]=e.dims;let d=0;for(let e=0;e<s;++e){const t=e*u*l;for(let i=0;i<u;++i){let s=0,o=0;const c=e*l,p=t+i;for(let e=0;e<l;++e){const t=Number(r[c+e]);o+=t,s+=n[p+e*u]*t}const h=s/o;a[d++]=h}}return new o(e.type,a,i)}function m(e,t,{eps:n=1e-5}={}){if(2!==e.dims.length)throw new Error("`layer_norm` currently only supports 2D input.");const[r,i]=e.dims;if(1!==t.length&&t[0]!==i)throw new Error("`normalized_shape` must be a 1D array with shape `[input.dims[1]]`.");const[a,s]=v(e,1,0,!0),l=a.data,u=s.data,d=e.data,c=new d.constructor(d.length);for(let e=0;e<r;++e){const t=e*i;for(let r=0;r<i;++r){const i=t+r;c[i]=(d[i]-u[e])/(l[e]+n)}}return new o(e.type,c,e.dims)}function g(e,t){return e=e.slice(),null===t?e=e.filter((e=>1!==e)):"number"==typeof t?1===e[t]&&e.splice(t,1):Array.isArray(t)&&(e=e.filter(((e,n)=>1!==e||!t.includes(n)))),e}function _(e,t){return t=w(t,e.length+1),(e=e.slice()).splice(t,0,1),e}function w(e,t,n=null,r=!0){if(r&&(e<-t||e>=t))throw new Error(`IndexError: index ${e} is out of bounds for dimension${null===n?"":" "+n} with size ${t}`);return e<0&&(e=(e%t+t)%t),e}function y(e,t=0){t=w(t,e[0].dims.length);const n=e[0].dims.slice();n[t]=e.reduce(((e,n)=>e+n.dims[t]),0);const r=n.reduce(((e,t)=>e*t),1),i=new e[0].data.constructor(r),a=e[0].type;if(0===t){let t=0;for(const n of e){const e=n.data;i.set(e,t),t+=e.length}}else{let r=0;for(let a=0;a<e.length;++a){const{data:s,dims:o}=e[a];for(let e=0;e<s.length;++e){let a=0;for(let i=o.length-1,s=e,l=1;i>=0;--i){const e=o[i];let u=s%e;i===t&&(u+=r),a+=u*l,l*=n[i],s=Math.floor(s/e)}i[a]=s[e]}r+=o[t]}}return new o(a,i,n)}function b(e,t=0){return y(e.map((e=>e.unsqueeze(t))),t)}function v(e,t=null,n=1,r=!1){const i=e.data,a=e.dims;if(null===t){const t=i.reduce(((e,t)=>e+t),0)/i.length,r=Math.sqrt(i.reduce(((e,n)=>e+(n-t)**2),0)/(i.length-n)),a=new o(e.type,[t],[]);return[new o(e.type,[r],[]),a]}const s=x(e,t=w(t,a.length),r),l=s.data,u=a.slice();u[t]=1;const d=new i.constructor(i.length/a[t]);for(let e=0;e<i.length;++e){let n=0;for(let r=a.length-1,i=e,s=1;r>=0;--r){const e=a[r];if(r!==t){n+=i%e*s,s*=u[r]}i=Math.floor(i/e)}d[n]+=(i[e]-l[n])**2}for(let e=0;e<d.length;++e)d[e]=Math.sqrt(d[e]/(a[t]-n));r||u.splice(t,1);return[new o(e.type,d,u),s]}function x(e,t=null,n=!1){const r=e.data;if(null===t){const t=r.reduce(((e,t)=>e+t),0);return new o(e.type,[t/r.length],[])}const i=e.dims;t=w(t,i.length);const a=i.slice();a[t]=1;const s=new r.constructor(r.length/i[t]);for(let e=0;e<r.length;++e){let n=0;for(let r=i.length-1,s=e,o=1;r>=0;--r){const e=i[r];if(r!==t){n+=s%e*o,o*=a[r]}s=Math.floor(s/e)}s[n]+=r[e]}if(1!==i[t])for(let e=0;e<s.length;++e)s[e]=s[e]/i[t];return n||a.splice(t,1),new o(e.type,s,a)}function M(e,t,n,r){const i=e.reduce(((e,t)=>e*t),1);return new o(n,new r(i).fill(t),e)}function T(e,t){let n,r;if("number"==typeof t)n="float32",r=Float32Array;else{if("bigint"!=typeof t)throw new Error("Unsupported data type: "+typeof t);n="int64",r=BigInt64Array}return M(e,t,n,r)}function k(e,t){return T(e.dims,t)}function $(e){return M(e,1n,"int64",BigInt64Array)}function C(e){return $(e.dims)}function S(e){return M(e,0n,"int64",BigInt64Array)}function P(e){return S(e.dims)}function E(e,t){if(2!==e.dims.length)throw new Error("The tensor must have 2 dimensions");if(e.dims.at(-1)%8!=0)throw new Error("The last dimension of the tensor must be a multiple of 8");if(!["binary","ubinary"].includes(t))throw new Error("The precision must be either 'binary' or 'ubinary'");const n="binary"===t,r=n?"int8":"uint8",i=n?Int8Array:Uint8Array,a=e.data,s=new i(a.length/8);for(let e=0;e<a.length;++e){const t=a[e]>0?1:0,r=Math.floor(e/8),i=e%8;s[r]|=t<<7-i,n&&0===i&&(s[r]-=128)}return new o(r,s,[e.dims[0],e.dims[1]/8])}}},r={};function i(e){var t=r[e];if(void 0!==t)return t.exports;var a=r[e]={exports:{}};return n[e](a,a.exports,i),a.exports}i.d=(e,t)=>{for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;if("string"==typeof import.meta.url&&(e=import.meta.url),!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i.p=e})(),i.b=void 0;var a={};(()=>{
226
+ \*****************************/(e,t,n)=>{n.r(t),n.d(t,{Tensor:()=>o,cat:()=>y,full:()=>T,full_like:()=>k,interpolate:()=>u,interpolate_4d:()=>d,layer_norm:()=>m,matmul:()=>c,mean:()=>x,mean_pooling:()=>f,ones:()=>$,ones_like:()=>C,permute:()=>l,quantize_embeddings:()=>E,rfft:()=>p,stack:()=>b,std_mean:()=>v,topk:()=>h,zeros:()=>S,zeros_like:()=>P});var r=n(/*! ./maths.js */"./src/utils/maths.js"),i=n(/*! ../backends/onnx.js */"./src/backends/onnx.js"),a=n(/*! ../ops/registry.js */"./src/ops/registry.js");const s=Object.freeze({float32:Float32Array,float16:Uint16Array,float64:Float64Array,string:Array,int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,int64:BigInt64Array,uint64:BigUint64Array,bool:Uint8Array});class o{get dims(){return this.ort_tensor.dims}set dims(e){this.ort_tensor.dims=e}get type(){return this.ort_tensor.type}get data(){return this.ort_tensor.data}get size(){return this.ort_tensor.size}get location(){return this.ort_tensor.location}ort_tensor;constructor(...e){return(0,i.isONNXTensor)(e[0])?this.ort_tensor=e[0]:this.ort_tensor=new i.Tensor(e[0],e[1],e[2]),new Proxy(this,{get:(e,t)=>{if("string"==typeof t){let n=Number(t);if(Number.isInteger(n))return e._getitem(n)}return e[t]},set:(e,t,n)=>e[t]=n})}dispose(){this.ort_tensor.dispose()}*[Symbol.iterator](){const[e,...t]=this.dims;if(t.length>0){const n=t.reduce(((e,t)=>e*t));for(let r=0;r<e;++r)yield this._subarray(r,n,t)}else yield*this.data}_getitem(e){const[t,...n]=this.dims;if(e=w(e,t),n.length>0){const t=n.reduce(((e,t)=>e*t));return this._subarray(e,t,n)}return new o(this.type,[this.data[e]],n)}indexOf(e){const t=this.data;for(let n=0;n<t.length;++n)if(t[n]==e)return n;return-1}_subarray(e,t,n){const r=e*t,i=(e+1)*t,a="subarray"in this.data?this.data.subarray(r,i):this.data.slice(r,i);return new o(this.type,a,n)}item(){const e=this.data;if(1!==e.length)throw new Error(`a Tensor with ${e.length} elements cannot be converted to Scalar`);return e[0]}tolist(){return function(e,t){const n=e.length,r=t.reduce(((e,t)=>e*t));if(n!==r)throw Error(`cannot reshape array of size ${n} into shape (${t})`);let i=e;for(let e=t.length-1;e>=0;e--)i=i.reduce(((n,r)=>{let i=n[n.length-1];return i.length<t[e]?i.push(r):n.push([r]),n}),[[]]);return i[0]}(this.data,this.dims)}sigmoid(){return this.clone().sigmoid_()}sigmoid_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=1/(1+Math.exp(-e[t]));return this}mul(e){return this.clone().mul_(e)}mul_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]*=e;return this}div(e){return this.clone().div_(e)}div_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]/=e;return this}add(e){return this.clone().add_(e)}add_(e){const t=this.data;for(let n=0;n<t.length;++n)t[n]+=e;return this}clone(){return new o(this.type,this.data.slice(),this.dims.slice())}slice(...e){const t=[],n=[];for(let r=0;r<this.dims.length;++r){let i=e[r];if(null==i)n.push([0,this.dims[r]]),t.push(this.dims[r]);else if("number"==typeof i)i=w(i,this.dims[r],r),n.push([i,i+1]);else{if(!Array.isArray(i)||2!==i.length)throw new Error(`Invalid slice: ${i}`);{let[e,a]=i;if(e=null===e?0:w(e,this.dims[r],r,!1),a=null===a?this.dims[r]:w(a,this.dims[r],r,!1),e>a)throw new Error(`Invalid slice: ${i}`);const s=[Math.max(e,0),Math.min(a,this.dims[r])];n.push(s),t.push(s[1]-s[0])}}}const r=n.map((([e,t])=>t-e)),i=r.reduce(((e,t)=>e*t)),a=this.data,s=new a.constructor(i),l=this.stride();for(let e=0;e<i;++e){let t=0;for(let i=r.length-1,a=e;i>=0;--i){const e=r[i];t+=(a%e+n[i][0])*l[i],a=Math.floor(a/e)}s[e]=a[t]}return new o(this.type,s,t)}permute(...e){return l(this,e)}transpose(...e){return this.permute(...e)}sum(e=null,t=!1){return this.norm(1,e,t)}norm(e="fro",t=null,n=!1){if("fro"===e)e=2;else if("string"==typeof e)throw Error(`Unsupported norm: ${e}`);const r=this.data;if(null===t){let t=r.reduce(((t,n)=>t+n**e),0)**(1/e);return new o(this.type,[t],[])}t=w(t,this.dims.length);const i=this.dims.slice();i[t]=1;const a=new r.constructor(r.length/this.dims[t]);for(let n=0;n<r.length;++n){let s=0;for(let e=this.dims.length-1,r=n,a=1;e>=0;--e){const n=this.dims[e];if(e!==t){s+=r%n*a,a*=i[e]}r=Math.floor(r/n)}a[s]+=r[n]**e}if(1!==e)for(let t=0;t<a.length;++t)a[t]=a[t]**(1/e);return n||i.splice(t,1),new o(this.type,a,i)}normalize_(e=2,t=1){t=w(t,this.dims.length);const n=this.norm(e,t,!0),r=this.data,i=n.data;for(let e=0;e<r.length;++e){let n=0;for(let r=this.dims.length-1,i=e,a=1;r>=0;--r){const e=this.dims[r];if(r!==t){n+=i%e*a,a*=this.dims[r]}i=Math.floor(i/e)}r[e]/=i[n]}return this}normalize(e=2,t=1){return this.clone().normalize_(e,t)}stride(){return function(e){const t=new Array(e.length);for(let n=e.length-1,r=1;n>=0;--n)t[n]=r,r*=e[n];return t}(this.dims)}squeeze(e=null){return new o(this.type,this.data,g(this.dims,e))}squeeze_(e=null){return this.dims=g(this.dims,e),this}unsqueeze(e=null){return new o(this.type,this.data,_(this.dims,e))}unsqueeze_(e=null){return this.dims=_(this.dims,e),this}flatten_(e=0,t=-1){t=(t+this.dims.length)%this.dims.length;let n=this.dims.slice(0,e),r=this.dims.slice(e,t+1),i=this.dims.slice(t+1);return this.dims=[...n,r.reduce(((e,t)=>e*t),1),...i],this}flatten(e=0,t=-1){return this.clone().flatten_(e,t)}view(...e){let t=-1;for(let n=0;n<e.length;++n)if(-1===e[n]){if(-1!==t)throw new Error("Only one dimension can be inferred");t=n}const n=this.data;if(-1!==t){const r=e.reduce(((e,n,r)=>r!==t?e*n:e),1);e[t]=n.length/r}return new o(this.type,n,e)}neg_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=-e[t];return this}neg(){return this.clone().neg_()}clamp_(e,t){const n=this.data;for(let r=0;r<n.length;++r)n[r]=Math.min(Math.max(n[r],e),t);return this}clamp(e,t){return this.clone().clamp_(e,t)}round_(){const e=this.data;for(let t=0;t<e.length;++t)e[t]=Math.round(e[t]);return this}round(){return this.clone().round_()}mean(e=null,t=!1){return x(this,e,t)}to(e){if(this.type===e)return this;if(!s.hasOwnProperty(e))throw new Error(`Unsupported type: ${e}`);return new o(e,s[e].from(this.data),this.dims)}}function l(e,t){const[n,i]=(0,r.permute_data)(e.data,e.dims,t);return new o(e.type,n,i)}function u(e,[t,n],i="bilinear",a=!1){const s=e.dims.at(-3)??1,l=e.dims.at(-2),u=e.dims.at(-1);let d=(0,r.interpolate_data)(e.data,[s,l,u],[t,n],i,a);return new o(e.type,d,[s,t,n])}async function d(e,{size:t=null,mode:n="bilinear"}={}){if(4!==e.dims.length)throw new Error("`interpolate_4d` currently only supports 4D input.");if(!t)throw new Error("`interpolate_4d` requires a `size` argument.");let r,i;if(2===t.length)r=[...e.dims.slice(0,2),...t];else if(3===t.length)r=[e.dims[0],...t];else{if(4!==t.length)throw new Error("`size` must be of length 2, 3, or 4.");r=t}if("bilinear"===n)i=await a.TensorOpRegistry.bilinear_interpolate_4d;else{if("bicubic"!==n)throw new Error(`Unsupported mode: ${n}`);i=await a.TensorOpRegistry.bicubic_interpolate_4d}const s=new o("int64",new BigInt64Array(r.map(BigInt)),[r.length]);return await i({x:e,s})}async function c(e,t){const n=await a.TensorOpRegistry.matmul;return await n({a:e,b:t})}async function p(e,t){const n=await a.TensorOpRegistry.rfft;return await n({x:e,a:t})}async function h(e,t){const n=await a.TensorOpRegistry.top_k;return t=null===t?e.dims.at(-1):Math.min(t,e.dims.at(-1)),await n({x:e,k:new o("int64",[BigInt(t)],[1])})}function f(e,t){const n=e.data,r=t.data,i=[e.dims[0],e.dims[2]],a=new n.constructor(i[0]*i[1]),[s,l,u]=e.dims;let d=0;for(let e=0;e<s;++e){const t=e*u*l;for(let i=0;i<u;++i){let s=0,o=0;const c=e*l,p=t+i;for(let e=0;e<l;++e){const t=Number(r[c+e]);o+=t,s+=n[p+e*u]*t}const h=s/o;a[d++]=h}}return new o(e.type,a,i)}function m(e,t,{eps:n=1e-5}={}){if(2!==e.dims.length)throw new Error("`layer_norm` currently only supports 2D input.");const[r,i]=e.dims;if(1!==t.length&&t[0]!==i)throw new Error("`normalized_shape` must be a 1D array with shape `[input.dims[1]]`.");const[a,s]=v(e,1,0,!0),l=a.data,u=s.data,d=e.data,c=new d.constructor(d.length);for(let e=0;e<r;++e){const t=e*i;for(let r=0;r<i;++r){const i=t+r;c[i]=(d[i]-u[e])/(l[e]+n)}}return new o(e.type,c,e.dims)}function g(e,t){return e=e.slice(),null===t?e=e.filter((e=>1!==e)):"number"==typeof t?1===e[t]&&e.splice(t,1):Array.isArray(t)&&(e=e.filter(((e,n)=>1!==e||!t.includes(n)))),e}function _(e,t){return t=w(t,e.length+1),(e=e.slice()).splice(t,0,1),e}function w(e,t,n=null,r=!0){if(r&&(e<-t||e>=t))throw new Error(`IndexError: index ${e} is out of bounds for dimension${null===n?"":" "+n} with size ${t}`);return e<0&&(e=(e%t+t)%t),e}function y(e,t=0){t=w(t,e[0].dims.length);const n=e[0].dims.slice();n[t]=e.reduce(((e,n)=>e+n.dims[t]),0);const r=n.reduce(((e,t)=>e*t),1),i=new e[0].data.constructor(r),a=e[0].type;if(0===t){let t=0;for(const n of e){const e=n.data;i.set(e,t),t+=e.length}}else{let r=0;for(let a=0;a<e.length;++a){const{data:s,dims:o}=e[a];for(let e=0;e<s.length;++e){let a=0;for(let i=o.length-1,s=e,l=1;i>=0;--i){const e=o[i];let u=s%e;i===t&&(u+=r),a+=u*l,l*=n[i],s=Math.floor(s/e)}i[a]=s[e]}r+=o[t]}}return new o(a,i,n)}function b(e,t=0){return y(e.map((e=>e.unsqueeze(t))),t)}function v(e,t=null,n=1,r=!1){const i=e.data,a=e.dims;if(null===t){const t=i.reduce(((e,t)=>e+t),0)/i.length,r=Math.sqrt(i.reduce(((e,n)=>e+(n-t)**2),0)/(i.length-n)),a=new o(e.type,[t],[]);return[new o(e.type,[r],[]),a]}const s=x(e,t=w(t,a.length),r),l=s.data,u=a.slice();u[t]=1;const d=new i.constructor(i.length/a[t]);for(let e=0;e<i.length;++e){let n=0;for(let r=a.length-1,i=e,s=1;r>=0;--r){const e=a[r];if(r!==t){n+=i%e*s,s*=u[r]}i=Math.floor(i/e)}d[n]+=(i[e]-l[n])**2}for(let e=0;e<d.length;++e)d[e]=Math.sqrt(d[e]/(a[t]-n));r||u.splice(t,1);return[new o(e.type,d,u),s]}function x(e,t=null,n=!1){const r=e.data;if(null===t){const t=r.reduce(((e,t)=>e+t),0);return new o(e.type,[t/r.length],[])}const i=e.dims;t=w(t,i.length);const a=i.slice();a[t]=1;const s=new r.constructor(r.length/i[t]);for(let e=0;e<r.length;++e){let n=0;for(let r=i.length-1,s=e,o=1;r>=0;--r){const e=i[r];if(r!==t){n+=s%e*o,o*=a[r]}s=Math.floor(s/e)}s[n]+=r[e]}if(1!==i[t])for(let e=0;e<s.length;++e)s[e]=s[e]/i[t];return n||a.splice(t,1),new o(e.type,s,a)}function M(e,t,n,r){const i=e.reduce(((e,t)=>e*t),1);return new o(n,new r(i).fill(t),e)}function T(e,t){let n,r;if("number"==typeof t)n="float32",r=Float32Array;else{if("bigint"!=typeof t)throw new Error("Unsupported data type: "+typeof t);n="int64",r=BigInt64Array}return M(e,t,n,r)}function k(e,t){return T(e.dims,t)}function $(e){return M(e,1n,"int64",BigInt64Array)}function C(e){return $(e.dims)}function S(e){return M(e,0n,"int64",BigInt64Array)}function P(e){return S(e.dims)}function E(e,t){if(2!==e.dims.length)throw new Error("The tensor must have 2 dimensions");if(e.dims.at(-1)%8!=0)throw new Error("The last dimension of the tensor must be a multiple of 8");if(!["binary","ubinary"].includes(t))throw new Error("The precision must be either 'binary' or 'ubinary'");const n="binary"===t,r=n?"int8":"uint8",i=n?Int8Array:Uint8Array,a=e.data,s=new i(a.length/8);for(let e=0;e<a.length;++e){const t=a[e]>0?1:0,r=Math.floor(e/8),i=e%8;s[r]|=t<<7-i,n&&0===i&&(s[r]-=128)}return new o(r,s,[e.dims[0],e.dims[1]/8])}}},r={};function i(e){var t=r[e];if(void 0!==t)return t.exports;var a=r[e]={exports:{}};return n[e](a,a.exports,i),a.exports}t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,i.t=function(n,r){if(1&r&&(n=this(n)),8&r)return n;if("object"==typeof n&&n){if(4&r&&n.__esModule)return n;if(16&r&&"function"==typeof n.then)return n}var a=Object.create(null);i.r(a);var s={};e=e||[null,t({}),t([]),t(t)];for(var o=2&r&&n;"object"==typeof o&&!~e.indexOf(o);o=t(o))Object.getOwnPropertyNames(o).forEach((e=>s[e]=()=>n[e]));return s.default=()=>n,i.d(a,s),a},i.d=(e,t)=>{for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;if("string"==typeof import.meta.url&&(e=import.meta.url),!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i.p=e})(),i.b=void 0;var a={};(()=>{
227
227
  /*!*****************************!*\
228
228
  !*** ./src/transformers.js ***!
229
229
  \*****************************/