@genai-fi/nanogpt 0.10.2 → 0.11.0

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.
Files changed (262) hide show
  1. package/dist/Generator.d.ts +10 -5
  2. package/dist/Generator.js +11760 -146
  3. package/dist/{RealDiv-zz7FpkKX.js → RealDiv-Ds-jvL09.js} +28 -30
  4. package/dist/Reshape-Cd6e-Otn.js +14 -0
  5. package/dist/{Reshape-CHdUjC72.js → Reshape-Ct266DEk.js} +21 -23
  6. package/dist/TeachableLLM.d.ts +4 -3
  7. package/dist/TeachableLLM.js +15 -16
  8. package/dist/Trainer.d.ts +2 -2
  9. package/dist/Trainer.js +6 -6
  10. package/dist/{axis_util-BsIr9ZNu.js → axis_util-DofAuy0p.js} +1 -1
  11. package/dist/backend.js +2 -2
  12. package/dist/{backend_util-B1XRLuq9.js → backend_util-C7NWHpv7.js} +72 -73
  13. package/dist/{backend_webgpu-CqpfEImu.js → backend_webgpu-B0Vls736.js} +52 -54
  14. package/dist/broadcast_to-DDaNMbX7.js +28 -0
  15. package/dist/checks/appendCache.js +2 -2
  16. package/dist/checks/attentionMask.js +3 -3
  17. package/dist/checks/gelu.js +2 -2
  18. package/dist/checks/matMulGelu.js +7 -11
  19. package/dist/checks/normRMS.js +9 -9
  20. package/dist/checks/normRMSGrad.js +3 -3
  21. package/dist/checks/packUnpack.js +2 -2
  22. package/dist/checks/qkv.js +11 -12
  23. package/dist/checks/rope.js +2 -2
  24. package/dist/clip_by_value-Dn5tzexi.js +12 -0
  25. package/dist/complex-DClmWqJt.js +11 -0
  26. package/dist/concat-C6X3AAlQ.js +17 -0
  27. package/dist/{concat_util-iBYIyuQe.js → concat_util-CHsJFZJJ.js} +1 -1
  28. package/dist/{dataset-D2P7rHAw.js → dataset-DcjWqUVQ.js} +135 -137
  29. package/dist/dropout-OxuaJz6z.js +92 -0
  30. package/dist/expand_dims-BzfJK2uc.js +11 -0
  31. package/dist/{exports_initializers-CZSUJoVE.js → exports_initializers-eS9QJ6ut.js} +1 -1
  32. package/dist/floor-DIb-lN_u.js +9 -0
  33. package/dist/gather-BcO5UQNJ.js +9 -0
  34. package/dist/{gelu-Bmhopi0J.js → gelu-DqTbCx5x.js} +10 -11
  35. package/dist/{gpgpu_math-DsCcikas.js → gpgpu_math-CJcbnKPC.js} +841 -1015
  36. package/dist/index-D0RBWjq8.js +3520 -0
  37. package/dist/{index-DRyE072i.js → index-Dj5TkmPY.js} +330 -331
  38. package/dist/{kernel_funcs_utils-CWfOAPGO.js → kernel_funcs_utils-CSaumNDs.js} +132 -134
  39. package/dist/layers/BaseLayer.js +15 -16
  40. package/dist/layers/CausalSelfAttention.js +6 -6
  41. package/dist/layers/MLP.js +4 -4
  42. package/dist/layers/PositionEmbedding.js +7 -7
  43. package/dist/layers/RMSNorm.js +3 -3
  44. package/dist/layers/RoPECache.js +9 -9
  45. package/dist/layers/TiedEmbedding.js +6 -6
  46. package/dist/layers/TransformerBlock.js +1 -1
  47. package/dist/loader/loadTransformers.js +1 -1
  48. package/dist/loader/oldZipLoad.js +21 -22
  49. package/dist/log_sum_exp-VLZgbFAH.js +39 -0
  50. package/dist/main.d.ts +1 -1
  51. package/dist/main.js +49 -50
  52. package/dist/{matMul16-fEAJ4smh.js → matMul16-cDxwemKj.js} +14 -15
  53. package/dist/matMulGelu-B2s_80-H.js +163 -0
  54. package/dist/mat_mul-DxpNTCRz.js +11 -0
  55. package/dist/mod-PrOKlFxH.js +11 -0
  56. package/dist/models/NanoGPTV1.js +2 -2
  57. package/dist/models/model.js +13 -14
  58. package/dist/ones-BX_wEgzB.js +14 -0
  59. package/dist/ops/adamAdjust.js +1 -1
  60. package/dist/ops/adamMoments.js +1 -1
  61. package/dist/ops/add16.js +1 -1
  62. package/dist/ops/appendCache.js +3 -3
  63. package/dist/ops/attentionMask.js +1 -1
  64. package/dist/ops/concat16.js +2 -2
  65. package/dist/ops/cpu/adamAdjust.js +12 -13
  66. package/dist/ops/cpu/adamMoments.js +6 -7
  67. package/dist/ops/cpu/appendCache.js +7 -8
  68. package/dist/ops/cpu/attentionMask.js +11 -11
  69. package/dist/ops/cpu/fusedSoftmax.js +10 -11
  70. package/dist/ops/cpu/gatherSub.js +10 -11
  71. package/dist/ops/cpu/gelu.js +14 -15
  72. package/dist/ops/cpu/matMul16.js +6 -7
  73. package/dist/ops/cpu/matMulGelu.js +5 -6
  74. package/dist/ops/cpu/matMulMul.js +3 -4
  75. package/dist/ops/cpu/mulDropout.js +3 -4
  76. package/dist/ops/cpu/normRMS.js +11 -12
  77. package/dist/ops/cpu/qkv.js +8 -9
  78. package/dist/ops/cpu/rope.js +9 -10
  79. package/dist/ops/cpu/scatterSub.js +14 -16
  80. package/dist/ops/dot16.js +2 -2
  81. package/dist/ops/gatherSub.js +1 -1
  82. package/dist/ops/gelu.js +2 -2
  83. package/dist/ops/grads/add16.js +10 -11
  84. package/dist/ops/grads/attentionMask.js +5 -6
  85. package/dist/ops/grads/gelu.js +3 -4
  86. package/dist/ops/grads/matMul16.js +4 -5
  87. package/dist/ops/grads/matMulGelu.js +8 -9
  88. package/dist/ops/grads/normRMS.js +9 -10
  89. package/dist/ops/grads/pack16.js +4 -5
  90. package/dist/ops/grads/qkv.js +17 -19
  91. package/dist/ops/grads/rope.js +3 -5
  92. package/dist/ops/grads/softmax16.js +3 -4
  93. package/dist/ops/grads/unpack16.js +3 -4
  94. package/dist/ops/grads/utils.d.ts +1 -0
  95. package/dist/ops/grads/utils.js +8 -4
  96. package/dist/ops/matMul16.js +3 -3
  97. package/dist/ops/matMulGelu.js +2 -2
  98. package/dist/ops/matMulMul.js +1 -1
  99. package/dist/ops/mul16.js +1 -1
  100. package/dist/ops/mulDrop.js +1 -1
  101. package/dist/ops/normRMS.js +1 -1
  102. package/dist/ops/pack16.js +3 -4
  103. package/dist/ops/qkv.js +4 -8
  104. package/dist/ops/reshape16.js +16 -18
  105. package/dist/ops/rope.d.ts +1 -1
  106. package/dist/ops/rope.js +3 -8
  107. package/dist/ops/scatterSub.js +1 -1
  108. package/dist/ops/slice16.js +2 -2
  109. package/dist/ops/softmax16.js +5 -8
  110. package/dist/ops/sub16.js +1 -1
  111. package/dist/ops/sum16.js +2 -2
  112. package/dist/ops/transpose16.js +23 -24
  113. package/dist/ops/unpack16.js +2 -2
  114. package/dist/ops/webgl/adamAdjust.js +2 -3
  115. package/dist/ops/webgl/adamMoments.js +1 -2
  116. package/dist/ops/webgl/appendCache.js +1 -2
  117. package/dist/ops/webgl/attentionMask.js +5 -6
  118. package/dist/ops/webgl/fusedSoftmax.js +6 -8
  119. package/dist/ops/webgl/gatherSub.js +6 -7
  120. package/dist/ops/webgl/gelu.js +2 -3
  121. package/dist/ops/webgl/log.js +11 -12
  122. package/dist/ops/webgl/matMul16.js +15 -16
  123. package/dist/ops/webgl/matMulGelu.js +7 -111
  124. package/dist/ops/webgl/matMulMul.js +14 -15
  125. package/dist/ops/webgl/mulDropout.js +8 -9
  126. package/dist/ops/webgl/normRMS.js +7 -8
  127. package/dist/ops/webgl/qkv.js +5 -6
  128. package/dist/ops/webgl/rope.js +7 -8
  129. package/dist/ops/webgl/scatterSub.js +5 -6
  130. package/dist/ops/webgpu/adamAdjust.js +10 -12
  131. package/dist/ops/webgpu/adamMoments.js +8 -10
  132. package/dist/ops/webgpu/add16.js +8 -9
  133. package/dist/ops/webgpu/appendCache.js +23 -25
  134. package/dist/ops/webgpu/attentionMask.js +10 -12
  135. package/dist/ops/webgpu/attentionMask32_program.js +2 -2
  136. package/dist/ops/webgpu/concat16.js +12 -14
  137. package/dist/ops/webgpu/gatherSub.js +9 -11
  138. package/dist/ops/webgpu/gelu.js +28 -29
  139. package/dist/ops/webgpu/matMul16.js +26 -28
  140. package/dist/ops/webgpu/matMul16_program.js +4 -5
  141. package/dist/ops/webgpu/mul16.js +7 -8
  142. package/dist/ops/webgpu/normRMS.js +17 -19
  143. package/dist/ops/webgpu/normRMSGrad.js +21 -28
  144. package/dist/ops/webgpu/pack16.js +12 -13
  145. package/dist/ops/webgpu/pack16_program.js +2 -2
  146. package/dist/ops/webgpu/qkv.js +13 -15
  147. package/dist/ops/webgpu/rope.js +25 -27
  148. package/dist/ops/webgpu/scatterSub.js +7 -9
  149. package/dist/ops/webgpu/slice16.js +21 -23
  150. package/dist/ops/webgpu/softmax16.js +17 -19
  151. package/dist/ops/webgpu/softmax16_program.js +2 -2
  152. package/dist/ops/webgpu/softmax16_subgroup_program.js +2 -2
  153. package/dist/ops/webgpu/softmax16grad.js +7 -8
  154. package/dist/ops/webgpu/sub16.js +8 -9
  155. package/dist/ops/webgpu/sum16.js +19 -21
  156. package/dist/ops/webgpu/transpose16.js +19 -20
  157. package/dist/ops/webgpu/transpose16_program.js +2 -2
  158. package/dist/ops/webgpu/transpose16_shared_program.js +11 -12
  159. package/dist/ops/webgpu/unpack16.js +3 -4
  160. package/dist/ops/webgpu/utils/binary_op.js +7 -8
  161. package/dist/ops/webgpu/utils/reductions.js +14 -22
  162. package/dist/ops-FJapAPfm.js +476 -0
  163. package/dist/pack16-k4jq6aMX.js +39 -0
  164. package/dist/patches/webgpu_backend.js +19 -20
  165. package/dist/patches/webgpu_base.js +1 -1
  166. package/dist/patches/webgpu_program.js +15 -16
  167. package/dist/{random_width-BVV9HveY.js → random_width-UGQn4OWb.js} +2506 -2761
  168. package/dist/range-CuGvVN2c.js +10 -0
  169. package/dist/relu-Cf80uA2p.js +9 -0
  170. package/dist/reshape-CkjKPPqB.js +9 -0
  171. package/dist/resize_nearest_neighbor-DB8k9KN_.js +175 -0
  172. package/dist/rope-BmZmp9uP.js +24 -0
  173. package/dist/{scatter_nd_util-C7zXRT_h.js → scatter_nd_util-BY22Cc-C.js} +1 -1
  174. package/dist/selu_util-BuLbmbrl.js +44 -0
  175. package/dist/{shared-CHhxz-O5.js → shared-B7USJZgw.js} +1 -1
  176. package/dist/{shared-D2NP_CpY.js → shared-BQboIImQ.js} +379 -381
  177. package/dist/slice-Aqy7KbJh.js +12 -0
  178. package/dist/{slice_util-DyjSAD0u.js → slice_util-D8CQRenR.js} +7 -7
  179. package/dist/{softmax-C9JQEtnO.js → softmax-faLoUZVT.js} +4 -5
  180. package/dist/split-BNz5jcGc.js +9 -0
  181. package/dist/squeeze--YMgaAAf.js +10 -0
  182. package/dist/stack-WJK22CFn.js +11 -0
  183. package/dist/step-dXR33iOg.js +261 -0
  184. package/dist/sum-BdplSvq_.js +11 -0
  185. package/dist/{tensor-0r5yOo2R.js → tensor-BQqrDvpx.js} +1 -1
  186. package/dist/tensor1d-LxP9asMm.js +11 -0
  187. package/dist/{tensor2d-CSB4KOb0.js → tensor2d-BN1sSfQO.js} +6 -7
  188. package/dist/{tensor4d-D7bLqGqz.js → tensor4d-DVwr7pLF.js} +6 -7
  189. package/dist/{tfjs_backend-CNkSTL0c.js → tfjs_backend-Vi4JfLzT.js} +256 -265
  190. package/dist/tile-CvN_LyVr.js +11 -0
  191. package/dist/tokeniser/BaseTokeniser.d.ts +27 -0
  192. package/dist/tokeniser/BaseTokeniser.js +94 -0
  193. package/dist/tokeniser/CharTokeniser.d.ts +4 -3
  194. package/dist/tokeniser/CharTokeniser.js +46 -32
  195. package/dist/tokeniser/bpe.d.ts +4 -3
  196. package/dist/tokeniser/bpe.js +60 -45
  197. package/dist/tokeniser/type.d.ts +11 -0
  198. package/dist/training/Adam.js +2 -2
  199. package/dist/training/AdamExt.js +1 -1
  200. package/dist/training/DatasetBuilder.d.ts +2 -2
  201. package/dist/training/DatasetBuilder.js +32 -36
  202. package/dist/training/FullTrainer.js +1 -1
  203. package/dist/training/Trainer.d.ts +3 -3
  204. package/dist/training/Trainer.js +2 -2
  205. package/dist/training/sparseCrossEntropy.js +5 -5
  206. package/dist/transpose-JawVKyZy.js +36 -0
  207. package/dist/unsorted_segment_sum-LAbmE9G4.js +277 -0
  208. package/dist/utilities/dummy.js +3 -3
  209. package/dist/utilities/multinomialCPU.js +2 -2
  210. package/dist/utilities/packed.d.ts +1 -4
  211. package/dist/utilities/packed.js +10 -745
  212. package/dist/utilities/performance.js +1 -1
  213. package/dist/utilities/profile.js +1 -1
  214. package/dist/utilities/safetensors.js +2 -2
  215. package/dist/utilities/sentences.js +5 -5
  216. package/dist/utilities/weights.js +2 -2
  217. package/dist/{variable-DzfrwYuP.js → variable-DQ9yYgEU.js} +1 -1
  218. package/dist/{webgpu_program-DzaQiqel.js → webgpu_program-CAE4RICo.js} +177 -171
  219. package/dist/{webgpu_util-0_ubCEHJ.js → webgpu_util-BdovYhXr.js} +34 -35
  220. package/dist/zeros-DeiE2zTa.js +13 -0
  221. package/dist/zeros_like-BAz3iKru.js +721 -0
  222. package/package.json +4 -2
  223. package/dist/Reshape-CDVLyVfz.js +0 -16
  224. package/dist/broadcast_to-B0ChcDaz.js +0 -30
  225. package/dist/complex-BBiRlsVq.js +0 -13
  226. package/dist/concat-DmBLPVGC.js +0 -19
  227. package/dist/dropout-B1x1kYMa.js +0 -99
  228. package/dist/expand_dims-ouvfxQ1n.js +0 -13
  229. package/dist/gather-CH9sdacz.js +0 -10
  230. package/dist/index-D6Q1lPZO.js +0 -2157
  231. package/dist/log_sum_exp-D3ftBNY5.js +0 -41
  232. package/dist/mat_mul-C59XWcJd.js +0 -12
  233. package/dist/mod-DESSvHIU.js +0 -12
  234. package/dist/mulmat_packed_gpu-Coh6qbJk.js +0 -55
  235. package/dist/ones-jU9jlQvM.js +0 -15
  236. package/dist/ops-BFDtP6th.js +0 -645
  237. package/dist/pack16-CmVZs6af.js +0 -41
  238. package/dist/patches/PackedTensor.d.ts +0 -12
  239. package/dist/patches/PackedTensor.js +0 -11
  240. package/dist/patches/engine.d.ts +0 -261
  241. package/dist/patches/engine.js +0 -12
  242. package/dist/patches/tape.d.ts +0 -12
  243. package/dist/patches/tape.js +0 -5
  244. package/dist/range-ZZZD60Fx.js +0 -11
  245. package/dist/reciprocal-CrYlsAGD.js +0 -10
  246. package/dist/register_all_kernels-nvj2k7OC.js +0 -12307
  247. package/dist/relu-BYDneVPn.js +0 -10
  248. package/dist/reshape-CaPQzFvz.js +0 -10
  249. package/dist/rope-s4W2XO9B.js +0 -32
  250. package/dist/selu_util-BGPXmd4B.js +0 -303
  251. package/dist/sin-Djs4aQiu.js +0 -16
  252. package/dist/slice-DvovR5wq.js +0 -13
  253. package/dist/split-DBck65sX.js +0 -10
  254. package/dist/squeeze-C00Ipm_7.js +0 -11
  255. package/dist/stack-ChnHwRpX.js +0 -13
  256. package/dist/sum-ywRJj3Zr.js +0 -12
  257. package/dist/tensor-CzmOBsdf.js +0 -909
  258. package/dist/tensor1d-BlUT89BP.js +0 -12
  259. package/dist/tensor_util-DfwaWayG.js +0 -523
  260. package/dist/tile-CR074jmp.js +0 -13
  261. package/dist/transpose-DH4gmHvu.js +0 -38
  262. package/dist/zeros-DBFVbpv5.js +0 -14
@@ -1,182 +1,386 @@
1
- import { K as z, L as oe, M as ie, N as ae, P as me, Q as J, h as $e } from "./index-D6Q1lPZO.js";
2
- import { e as v, a as F, i as B, h as I, b as T, s as E, I as H, J as Te, F as Y } from "./tensor-CzmOBsdf.js";
3
- import "./index-Cp39cXWe.js";
4
- import { b as Se } from "./backend_util-B1XRLuq9.js";
5
- const Re = "model", Ee = ".json", Ce = ".weights.bin";
6
- function K(e) {
7
- return new Promise((t) => setTimeout(t)).then(e);
8
- }
9
- class N {
10
- constructor(t) {
11
- if (!v().getBool("IS_BROWSER"))
12
- throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");
13
- t.startsWith(N.URL_SCHEME) && (t = t.slice(N.URL_SCHEME.length)), (t == null || t.length === 0) && (t = Re), this.modelJsonFileName = t + Ee, this.weightDataFileName = t + Ce;
14
- }
15
- async save(t) {
16
- if (typeof document > "u")
17
- throw new Error("Browser downloads are not supported in this environment since `document` is not present");
18
- const n = oe.join(t.weightData), r = window.URL.createObjectURL(new Blob([n], { type: "application/octet-stream" }));
19
- if (t.modelTopology instanceof ArrayBuffer)
20
- throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");
21
- {
22
- const o = [{
23
- paths: ["./" + this.weightDataFileName],
24
- weights: t.weightSpecs
25
- }], i = ie(t, o), a = window.URL.createObjectURL(new Blob([JSON.stringify(i)], { type: "application/json" })), s = this.modelJsonAnchor == null ? document.createElement("a") : this.modelJsonAnchor;
26
- if (s.download = this.modelJsonFileName, s.href = a, await K(() => s.dispatchEvent(new MouseEvent("click"))), t.weightData != null) {
27
- const c = this.weightDataAnchor == null ? document.createElement("a") : this.weightDataAnchor;
28
- c.download = this.weightDataFileName, c.href = r, await K(() => c.dispatchEvent(new MouseEvent("click")));
29
- }
30
- return { modelArtifactsInfo: ae(t) };
31
- }
1
+ import { ab as $, V as E, aN as X, ac as T, aO as ae, L as N, aP as G, y as ie, a9 as k, ad as ce } from "./index-D0RBWjq8.js";
2
+ import { b as se } from "./backend_util-C7NWHpv7.js";
3
+ const w = {}, M = {
4
+ alpha: !1,
5
+ antialias: !1,
6
+ premultipliedAlpha: !1,
7
+ preserveDrawingBuffer: !1,
8
+ depth: !1,
9
+ stencil: !1,
10
+ failIfMajorPerformanceCaveat: !0
11
+ };
12
+ function ut(e, t) {
13
+ w[e] = t;
14
+ }
15
+ function A(e, t) {
16
+ if (!(e in w) || t != null) {
17
+ const r = le(e, t);
18
+ if (r !== null)
19
+ w[e] = r;
20
+ else
21
+ return console.log("Could not get context for WebGL version", e), null;
32
22
  }
23
+ const n = w[e];
24
+ return n == null || n.isContextLost() ? (delete w[e], A(e)) : (n.disable(n.DEPTH_TEST), n.disable(n.STENCIL_TEST), n.disable(n.BLEND), n.disable(n.DITHER), n.disable(n.POLYGON_OFFSET_FILL), n.disable(n.SAMPLE_COVERAGE), n.enable(n.SCISSOR_TEST), n.enable(n.CULL_FACE), n.cullFace(n.BACK), w[e]);
33
25
  }
34
- N.URL_SCHEME = "downloads://";
35
- const we = (e) => v().getBool("IS_BROWSER") && !Array.isArray(e) && e.startsWith(N.URL_SCHEME) ? Fe(e.slice(N.URL_SCHEME.length)) : null;
36
- z.registerSaveRouter(we);
37
- function Fe(e = "model") {
38
- return new N(e);
39
- }
40
- function Z(e, t, n, r) {
41
- a(e), n = n ?? 0, r = r ?? 1, s(n, r);
42
- let o = 0;
43
- const i = (c) => (c.then((u) => {
44
- const l = n + ++o / e.length * (r - n);
45
- return t(l), u;
46
- }), c);
47
- function a(c) {
48
- F(c != null && Array.isArray(c) && c.length > 0, () => "promises must be a none empty array");
26
+ function ue(e) {
27
+ if (!$().getBool("IS_SAFARI") && typeof OffscreenCanvas < "u" && e === 2)
28
+ return new OffscreenCanvas(300, 150);
29
+ if (typeof document < "u")
30
+ return document.createElement("canvas");
31
+ throw new Error("Cannot create a canvas in this context");
32
+ }
33
+ function le(e, t) {
34
+ if (e !== 1 && e !== 2)
35
+ throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");
36
+ const n = t ?? ue(e);
37
+ return n.addEventListener("webglcontextlost", (r) => {
38
+ r.preventDefault(), delete w[e];
39
+ }, !1), $().getBool("SOFTWARE_WEBGL_ENABLED") && (M.failIfMajorPerformanceCaveat = !1), e === 1 ? (
40
+ // tslint:disable-next-line
41
+ n.getContext("webgl", M) || n.getContext("experimental-webgl", M)
42
+ ) : n.getContext("webgl2", M);
43
+ }
44
+ var H;
45
+ (function(e) {
46
+ e[e.DENSE = 0] = "DENSE", e[e.SHARED_BATCH = 1] = "SHARED_BATCH";
47
+ })(H || (H = {}));
48
+ var q;
49
+ (function(e) {
50
+ e[e.RENDER = 0] = "RENDER", e[e.UPLOAD = 1] = "UPLOAD", e[e.PIXELS = 2] = "PIXELS", e[e.DOWNLOAD = 3] = "DOWNLOAD";
51
+ })(q || (q = {}));
52
+ var j;
53
+ (function(e) {
54
+ e[e.UNPACKED_FLOAT16 = 0] = "UNPACKED_FLOAT16", e[e.UNPACKED_FLOAT32 = 1] = "UNPACKED_FLOAT32", e[e.PACKED_4X1_UNSIGNED_BYTE = 2] = "PACKED_4X1_UNSIGNED_BYTE", e[e.PACKED_2X2_FLOAT32 = 3] = "PACKED_2X2_FLOAT32", e[e.PACKED_2X2_FLOAT16 = 4] = "PACKED_2X2_FLOAT16";
55
+ })(j || (j = {}));
56
+ function lt(e, t) {
57
+ return [t, e];
58
+ }
59
+ function ft(e, t) {
60
+ return e * t;
61
+ }
62
+ function xt(e) {
63
+ const t = E(e), n = Math.ceil(t / 4);
64
+ return X(n);
65
+ }
66
+ function fe(e, t) {
67
+ return [
68
+ Math.max(1, Math.ceil(t / 2)),
69
+ Math.max(1, Math.ceil(e / 2))
70
+ ];
71
+ }
72
+ function dt(e, t) {
73
+ const [n, r] = fe(e, t);
74
+ return n * r * 4;
75
+ }
76
+ function K(e, t) {
77
+ const n = e;
78
+ let r, o, a, i, c, s, l, u, f, d;
79
+ return $().getNumber("WEBGL_VERSION") === 2 ? (r = n.R32F, o = n.R16F, a = n.RGBA16F, i = n.RGBA32F, c = n.RED, l = 4, u = 1, f = n.HALF_FLOAT, d = n.FLOAT, s = n.RGBA8) : (r = e.RGBA, o = e.RGBA, a = e.RGBA, i = n.RGBA, c = e.RGBA, l = 4, u = 4, f = t != null ? t.HALF_FLOAT_OES : null, d = e.FLOAT, s = e.RGBA), {
80
+ internalFormatFloat: r,
81
+ internalFormatHalfFloat: o,
82
+ internalFormatPackedHalfFloat: a,
83
+ internalFormatPackedFloat: i,
84
+ textureFormatFloat: c,
85
+ downloadTextureFormat: s,
86
+ downloadUnpackNumChannels: l,
87
+ defaultNumChannels: u,
88
+ textureTypeHalfFloat: f,
89
+ textureTypeFloat: d
90
+ };
91
+ }
92
+ function v(e, t) {
93
+ const n = t();
94
+ return $().getBool("DEBUG") && xe(e), n;
95
+ }
96
+ function xe(e) {
97
+ const t = e.getError();
98
+ if (t !== e.NO_ERROR)
99
+ throw new Error("WebGL Error: " + pe(e, t));
100
+ }
101
+ const de = 596e-10, he = 65504;
102
+ function ht(e) {
103
+ return !!($().getBool("WEBGL_RENDER_FLOAT32_ENABLED") || e === 0 || de < Math.abs(e) && Math.abs(e) < he);
104
+ }
105
+ function pe(e, t) {
106
+ switch (t) {
107
+ case e.NO_ERROR:
108
+ return "NO_ERROR";
109
+ case e.INVALID_ENUM:
110
+ return "INVALID_ENUM";
111
+ case e.INVALID_VALUE:
112
+ return "INVALID_VALUE";
113
+ case e.INVALID_OPERATION:
114
+ return "INVALID_OPERATION";
115
+ case e.INVALID_FRAMEBUFFER_OPERATION:
116
+ return "INVALID_FRAMEBUFFER_OPERATION";
117
+ case e.OUT_OF_MEMORY:
118
+ return "OUT_OF_MEMORY";
119
+ case e.CONTEXT_LOST_WEBGL:
120
+ return "CONTEXT_LOST_WEBGL";
121
+ default:
122
+ return `Unknown error code ${t}`;
49
123
  }
50
- function s(c, u) {
51
- F(c >= 0 && c <= 1, () => `Progress fraction must be in range [0, 1], but got startFraction ${c}`), F(u >= 0 && u <= 1, () => `Progress fraction must be in range [0, 1], but got endFraction ${u}`), F(u >= c, () => `startFraction must be no more than endFraction, but got startFraction ${c} and endFraction ${u}`);
124
+ }
125
+ function pt(e, t) {
126
+ return C(e, () => e.getExtension(t), 'Extension "' + t + '" not supported on this browser.');
127
+ }
128
+ function vt(e, t) {
129
+ const n = C(e, () => e.createShader(e.VERTEX_SHADER), "Unable to create vertex WebGLShader.");
130
+ if (v(e, () => e.shaderSource(n, t)), v(e, () => e.compileShader(n)), e.getShaderParameter(n, e.COMPILE_STATUS) === !1)
131
+ throw console.log(e.getShaderInfoLog(n)), new Error("Failed to compile vertex shader.");
132
+ return n;
133
+ }
134
+ function ve(e, t) {
135
+ const n = C(e, () => e.createShader(e.FRAGMENT_SHADER), "Unable to create fragment WebGLShader.");
136
+ if (v(e, () => e.shaderSource(n, t)), v(e, () => e.compileShader(n)), $().get("ENGINE_COMPILE_ONLY"))
137
+ return n;
138
+ if (e.getShaderParameter(n, e.COMPILE_STATUS) === !1)
139
+ throw me(t, e.getShaderInfoLog(n)), new Error("Failed to compile fragment shader.");
140
+ return n;
141
+ }
142
+ const $e = /ERROR: [0-9]+:([0-9]+):/g;
143
+ function me(e, t) {
144
+ const n = $e.exec(t);
145
+ if (n == null) {
146
+ console.log(`Couldn't parse line number in error: ${t}`), console.log(e);
147
+ return;
52
148
  }
53
- return Promise.all(e.map(i));
54
- }
55
- async function ge(e, t) {
56
- t == null && (t = {});
57
- const n = t.fetchFunc == null ? v().platform.fetch : t.fetchFunc, r = e.map((f) => n(f, t.requestInit, { isBinary: !0 })), s = (t.onProgress == null ? await Promise.all(r) : await Z(r, t.onProgress, 0, 0.5)).map((f) => f.arrayBuffer());
58
- return t.onProgress == null ? await Promise.all(s) : await Z(s, t.onProgress, 0.5, 1);
59
- }
60
- function _e(e, t) {
61
- var n;
62
- const r = t.fetchFunc == null ? v().platform.fetch : t.fetchFunc;
63
- let o = 0, i;
64
- return (n = t.onProgress) === null || n === void 0 || n.call(t, 0), new ReadableStream({
65
- pull: async (a) => {
66
- for (var s; o < e.length; ) {
67
- i || (i = (await r(e[o], t.requestInit, { isBinary: !0 })).body.getReader());
68
- const { done: c, value: u } = await i.read();
69
- if (c) {
70
- o++, i = void 0, (s = t.onProgress) === null || s === void 0 || s.call(t, o / e.length);
71
- continue;
72
- }
73
- a.enqueue(u);
74
- return;
75
- }
76
- a.close();
77
- }
78
- });
149
+ const r = +n[1], o = e.split(`
150
+ `), a = o.length.toString().length + 2, i = o.map((f, d) => G((d + 1).toString(), a) + f);
151
+ let c = 0;
152
+ for (let f = 0; f < i.length; f++)
153
+ c = Math.max(i[f].length, c);
154
+ const s = i.slice(0, r - 1), l = i.slice(r - 1, r), u = i.slice(r);
155
+ console.log(s.join(`
156
+ `)), console.log(t.split(`
157
+ `)[0]), console.log(`%c ${G(l[0], c)}`, "border:1px solid red; background-color:#e3d2d2; color:#a61717"), console.log(u.join(`
158
+ `));
159
+ }
160
+ function $t(e) {
161
+ return C(e, () => e.createProgram(), "Unable to create WebGLProgram.");
162
+ }
163
+ function mt(e, t) {
164
+ if (v(e, () => e.linkProgram(t)), !$().get("ENGINE_COMPILE_ONLY") && e.getProgramParameter(t, e.LINK_STATUS) === !1)
165
+ throw console.log(e.getProgramInfoLog(t)), new Error("Failed to link vertex and fragment shaders.");
166
+ }
167
+ function Tt(e, t) {
168
+ if (v(e, () => e.validateProgram(t)), e.getProgramParameter(t, e.VALIDATE_STATUS) === !1)
169
+ throw console.log(e.getProgramInfoLog(t)), new Error("Shader program validation failed.");
79
170
  }
80
- const Ae = "application/octet-stream", Ne = "application/json";
81
- class q {
82
- constructor(t, n) {
83
- if (this.DEFAULT_METHOD = "POST", n == null && (n = {}), this.weightPathPrefix = n.weightPathPrefix, this.weightUrlConverter = n.weightUrlConverter, n.fetchFunc != null ? (F(typeof n.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 = n.fetchFunc) : this.fetch = v().platform.fetch, F(t != null && t.length > 0, () => "URL path for http must not be null, undefined or empty."), Array.isArray(t) && F(t.length === 2, () => `URL paths for http must have a length of 2, (actual length is ${t.length}).`), this.path = t, n.requestInit != null && n.requestInit.body != null)
84
- throw new Error("requestInit is expected to have no pre-existing body, but has one.");
85
- this.requestInit = n.requestInit || {}, this.loadOptions = n;
171
+ function St(e, t) {
172
+ const n = C(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
173
+ return v(e, () => e.bindBuffer(e.ARRAY_BUFFER, n)), v(e, () => e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
174
+ }
175
+ function Rt(e, t) {
176
+ const n = C(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
177
+ return v(e, () => e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, n)), v(e, () => e.bufferData(e.ELEMENT_ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
178
+ }
179
+ function Et(e) {
180
+ return C(e, () => e.createTexture(), "Unable to create WebGLTexture.");
181
+ }
182
+ function Ct(e, t) {
183
+ const n = $().getNumber("WEBGL_MAX_TEXTURE_SIZE");
184
+ if (e <= 0 || t <= 0) {
185
+ const r = `[${e}x${t}]`;
186
+ throw new Error("Requested texture size " + r + " is invalid.");
86
187
  }
87
- async save(t) {
88
- if (t.modelTopology instanceof ArrayBuffer)
89
- throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");
90
- const n = Object.assign({ method: this.DEFAULT_METHOD }, this.requestInit);
91
- n.body = new FormData();
92
- const r = [{
93
- paths: ["./model.weights.bin"],
94
- weights: t.weightSpecs
95
- }], o = ie(t, r);
96
- if (n.body.append("model.json", new Blob([JSON.stringify(o)], { type: Ne }), "model.json"), t.weightData != null) {
97
- const a = oe.join(t.weightData);
98
- n.body.append("model.weights.bin", new Blob([a], { type: Ae }), "model.weights.bin");
99
- }
100
- const i = await this.fetch(this.path, n);
101
- if (i.ok)
102
- return {
103
- modelArtifactsInfo: ae(t),
104
- responses: [i]
105
- };
106
- throw new Error(`BrowserHTTPRequest.save() failed due to HTTP response status ${i.status}.`);
188
+ if (e > n || t > n) {
189
+ const r = `[${e}x${t}]`, o = `[${n}x${n}]`;
190
+ throw new Error("Requested texture size " + r + " greater than WebGL maximum on this browser / GPU " + o + ".");
107
191
  }
108
- async loadModelJSON() {
109
- const t = await this.fetch(this.path, this.requestInit);
110
- if (!t.ok)
111
- throw new Error(`Request to ${this.path} failed with status code ${t.status}. Please verify this URL points to the model JSON of the model to load.`);
112
- let n;
113
- try {
114
- n = await t.json();
115
- } catch {
116
- let a = `Failed to parse model JSON of response from ${this.path}.`;
117
- throw this.path.endsWith(".pb") ? a += " Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository." : a += " Please make sure the server is serving valid JSON for this request.", new Error(a);
118
- }
119
- const r = n.modelTopology, o = n.weightsManifest;
120
- if (r == null && o == null)
121
- throw new Error(`The JSON from HTTP path ${this.path} contains neither model topology or manifest for weights.`);
122
- return n;
192
+ }
193
+ function Ft(e) {
194
+ return C(e, () => e.createFramebuffer(), "Unable to create WebGLFramebuffer.");
195
+ }
196
+ function _t(e, t, n, r, o, a, i) {
197
+ const c = e.getAttribLocation(t, n);
198
+ return c === -1 ? !1 : (v(e, () => e.bindBuffer(e.ARRAY_BUFFER, r)), v(e, () => e.vertexAttribPointer(c, o, e.FLOAT, !1, a, i)), v(e, () => e.enableVertexAttribArray(c)), !0);
199
+ }
200
+ function Te(e, t, n) {
201
+ Re(e, n), v(e, () => e.activeTexture(e.TEXTURE0 + n)), v(e, () => e.bindTexture(e.TEXTURE_2D, t));
202
+ }
203
+ function At(e, t, n) {
204
+ return C(e, () => e.getUniformLocation(t, n), 'uniform "' + n + '" not present in program.');
205
+ }
206
+ function wt(e, t, n) {
207
+ return e.getUniformLocation(t, n);
208
+ }
209
+ function Nt(e, t, n, r) {
210
+ v(e, () => Te(e, t, r)), v(e, () => e.uniform1i(n, r));
211
+ }
212
+ function Ot(e, t, n) {
213
+ v(e, () => e.bindFramebuffer(e.FRAMEBUFFER, n)), v(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, t, 0));
214
+ }
215
+ function It(e, t) {
216
+ v(e, () => e.bindFramebuffer(e.FRAMEBUFFER, t)), v(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, null, 0));
217
+ }
218
+ function Lt(e) {
219
+ const t = e.checkFramebufferStatus(e.FRAMEBUFFER);
220
+ if (t !== e.FRAMEBUFFER_COMPLETE)
221
+ throw new Error("Error binding framebuffer: " + Se(e, t));
222
+ }
223
+ function Se(e, t) {
224
+ switch (t) {
225
+ case e.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
226
+ return "FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
227
+ case e.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
228
+ return "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
229
+ case e.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
230
+ return "FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
231
+ case e.FRAMEBUFFER_UNSUPPORTED:
232
+ return "FRAMEBUFFER_UNSUPPORTED";
233
+ default:
234
+ return `unknown error ${t}`;
123
235
  }
124
- /**
125
- * Load model artifacts via HTTP request(s).
126
- *
127
- * See the documentation to `tf.io.http` for details on the saved
128
- * artifacts.
129
- *
130
- * @returns The loaded model artifacts (if loading succeeds).
131
- */
132
- async load() {
133
- if (this.loadOptions.streamWeights)
134
- return this.loadStream();
135
- const t = await this.loadModelJSON();
136
- return me(t, (n) => this.loadWeights(n));
236
+ }
237
+ function C(e, t, n) {
238
+ const r = v(e, () => t());
239
+ if (r == null)
240
+ throw new Error(n);
241
+ return r;
242
+ }
243
+ function Re(e, t) {
244
+ const n = e.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1, r = t + e.TEXTURE0;
245
+ if (r < e.TEXTURE0 || r > n) {
246
+ const o = `[gl.TEXTURE0, gl.TEXTURE${n}]`;
247
+ throw new Error(`textureUnit must be in ${o}.`);
137
248
  }
138
- async loadStream() {
139
- const t = await this.loadModelJSON(), n = await this.getWeightUrls(t.weightsManifest), r = J(t.weightsManifest), o = () => _e(n, this.loadOptions);
140
- return Object.assign(Object.assign({}, t), { weightSpecs: r, getWeightStream: o });
249
+ }
250
+ function Z(e, t = 2) {
251
+ return E(e.slice(0, e.length - t));
252
+ }
253
+ function J(e) {
254
+ if (e.length === 0)
255
+ throw Error("Cannot get rows and columns of an empty shape array.");
256
+ return [
257
+ e.length > 1 ? e[e.length - 2] : 1,
258
+ e[e.length - 1]
259
+ ];
260
+ }
261
+ function Ut(e) {
262
+ let t = [1, 1, 1];
263
+ return e.length === 0 || e.length === 1 && e[0] === 1 || (t = [Z(e), ...J(e)]), t;
264
+ }
265
+ function Dt(e, t = !1) {
266
+ let n = $().getNumber("WEBGL_MAX_TEXTURE_SIZE"), r = $().getNumber("WEBGL_MAX_SIZE_FOR_NARROW_TEXTURE");
267
+ r === 1 / 0 && $().getBool("WEBGL_AUTO_SQUARIFY_NARROW_TEXTURE_SHAPE") && (r = n / 2), t && (n = n * 2, r = r * 2, e = e.map((c, s) => s >= e.length - 2 ? ae(e[s]) : e[s]), e.length === 1 && (e = [2, e[0]])), e.length !== 2 && (e = N(e).newShape);
268
+ let o = E(e), a = null;
269
+ e.length <= 1 && o <= n ? a = [1, o] : e.length === 2 && e[0] <= n && e[1] <= n ? a = e : e.length === 3 && e[0] * e[1] <= n && e[2] <= n ? a = [e[0] * e[1], e[2]] : e.length === 3 && e[0] <= n && e[1] * e[2] <= n ? a = [e[0], e[1] * e[2]] : e.length === 4 && e[0] * e[1] * e[2] <= n && e[3] <= n ? a = [e[0] * e[1] * e[2], e[3]] : e.length === 4 && e[0] <= n && e[1] * e[2] * e[3] <= n && (a = [e[0], e[1] * e[2] * e[3]]);
270
+ const i = a != null && Math.max(...a) > r && Math.min(...a) <= (t ? 2 : 1) && Math.min(...a) > 0;
271
+ if (a == null || i)
272
+ if (t) {
273
+ const c = Z(e);
274
+ let s = 2, l = 2;
275
+ e.length && ([s, l] = J(e)), o = c * (s / 2) * (l / 2), a = X(o).map((u) => u * 2);
276
+ } else
277
+ a = X(o);
278
+ return a;
279
+ }
280
+ function B(e) {
281
+ return e % 2 === 0;
282
+ }
283
+ function gt(e, t) {
284
+ if (e = e.slice(-2), t = t.slice(-2), T(e, t) || !e.length || !t.length || e[0] === 0 || e[1] === 0 || t[0] === 0 || t[1] === 0)
285
+ return !0;
286
+ if (e.length !== t.length) {
287
+ const n = e[e.length - 1], r = t[t.length - 1];
288
+ if (n === r || B(n) && B(r) && (e[0] === 1 || t[0] === 1))
289
+ return !0;
141
290
  }
142
- async getWeightUrls(t) {
143
- const n = Array.isArray(this.path) ? this.path[1] : this.path, [r, o] = Ie(n), i = this.weightPathPrefix || r, a = [], s = [];
144
- for (const c of t)
145
- for (const u of c.paths)
146
- this.weightUrlConverter != null ? s.push(this.weightUrlConverter(u)) : a.push(i + u + o);
147
- return this.weightUrlConverter && a.push(...await Promise.all(s)), a;
291
+ return e[1] === t[1] && B(e[0]) && B(t[0]);
292
+ }
293
+ let P, V;
294
+ function bt(e) {
295
+ if (P == null) {
296
+ const t = A(e);
297
+ P = t.getParameter(t.MAX_TEXTURE_SIZE);
148
298
  }
149
- async loadWeights(t) {
150
- const n = await this.getWeightUrls(t), r = J(t), o = await ge(n, this.loadOptions);
151
- return [r, o];
299
+ return P;
300
+ }
301
+ function kt(e) {
302
+ if (V == null) {
303
+ const t = A(e);
304
+ V = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);
152
305
  }
306
+ return Math.min(16, V);
153
307
  }
154
- q.URL_SCHEME_REGEX = /^https?:\/\//;
155
- function Ie(e) {
156
- const t = e.lastIndexOf("/"), n = e.lastIndexOf("?"), r = e.substring(0, t), o = n > t ? e.substring(n) : "";
157
- return [r + "/", o];
158
- }
159
- function Q(e) {
160
- return e.match(q.URL_SCHEME_REGEX) != null;
161
- }
162
- const ce = (e, t) => {
163
- if (typeof fetch > "u" && (t == null || t.fetchFunc == null))
164
- return null;
165
- {
166
- let n = !0;
167
- if (Array.isArray(e) ? n = e.every((r) => Q(r)) : n = Q(e), n)
168
- return Ue(e, t);
308
+ function Mt(e) {
309
+ if (e === 0)
310
+ return 0;
311
+ let t;
312
+ const n = A(e);
313
+ return _(n, "EXT_disjoint_timer_query_webgl2") && e === 2 ? t = 2 : _(n, "EXT_disjoint_timer_query") ? t = 1 : t = 0, t;
314
+ }
315
+ function _(e, t) {
316
+ return e.getExtension(t) != null;
317
+ }
318
+ function Bt(e) {
319
+ try {
320
+ if (A(e) != null)
321
+ return !0;
322
+ } catch (t) {
323
+ return console.log("Error when getting WebGL context: ", t), !1;
169
324
  }
170
- return null;
171
- };
172
- z.registerSaveRouter(ce);
173
- z.registerLoadRouter(ce);
174
- function Ue(e, t) {
175
- return new q(e, t);
325
+ return !1;
326
+ }
327
+ function yt(e) {
328
+ if (e === 0)
329
+ return !1;
330
+ const t = A(e);
331
+ if (e === 1) {
332
+ if (!_(t, "OES_texture_float"))
333
+ return !1;
334
+ } else if (!_(t, "EXT_color_buffer_float"))
335
+ return !1;
336
+ return W(t);
337
+ }
338
+ function Pt(e) {
339
+ if (e === 0)
340
+ return !1;
341
+ const t = A(e);
342
+ if (e === 1) {
343
+ if (!_(t, "OES_texture_float") || !_(t, "WEBGL_color_buffer_float"))
344
+ return !1;
345
+ } else {
346
+ if (_(t, "EXT_color_buffer_float"))
347
+ return W(t);
348
+ const r = "EXT_color_buffer_half_float";
349
+ if (_(t, r)) {
350
+ const o = t.getExtension(r);
351
+ return Ee(t, o);
352
+ }
353
+ return !1;
354
+ }
355
+ return W(t);
356
+ }
357
+ function W(e) {
358
+ const t = K(e), n = e.createTexture();
359
+ e.bindTexture(e.TEXTURE_2D, n), e.texImage2D(e.TEXTURE_2D, 0, t.internalFormatFloat, 1, 1, 0, t.textureFormatFloat, t.textureTypeFloat, null);
360
+ const a = e.createFramebuffer();
361
+ e.bindFramebuffer(e.FRAMEBUFFER, a), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, n, 0);
362
+ const i = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
363
+ return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(n), e.deleteFramebuffer(a), i;
364
+ }
365
+ function Ee(e, t) {
366
+ const n = K(e, t), r = e.createTexture();
367
+ e.bindTexture(e.TEXTURE_2D, r), e.texImage2D(e.TEXTURE_2D, 0, n.internalFormatHalfFloat, 1, 1, 0, n.textureFormatFloat, n.textureTypeHalfFloat, null);
368
+ const i = e.createFramebuffer();
369
+ e.bindFramebuffer(e.FRAMEBUFFER, i), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, r, 0);
370
+ const c = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
371
+ return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(r), e.deleteFramebuffer(i), c;
372
+ }
373
+ function Vt(e) {
374
+ return e !== 2 ? !1 : A(e).fenceSync != null;
375
+ }
376
+ function Xt(e, t) {
377
+ Array.isArray(e) || (e = [e]), e.forEach((n) => {
378
+ n != null && ie(n.dtype !== "complex64", () => `${t} does not support complex64 tensors in the WebGL backend.`);
379
+ });
176
380
  }
177
381
  function L() {
178
- let e, t, n, r, o, i, a, s, c, u;
179
- return v().getNumber("WEBGL_VERSION") === 2 ? (e = "#version 300 es", t = "in", n = "out", r = "in", o = "texture", i = "outputColor", a = "out vec4 outputColor;", s = v().getBool("WEBGL2_ISNAN_CUSTOM") ? `
382
+ let e, t, n, r, o, a, i, c, s, l;
383
+ return $().getNumber("WEBGL_VERSION") === 2 ? (e = "#version 300 es", t = "in", n = "out", r = "in", o = "texture", a = "outputColor", i = "out vec4 outputColor;", c = $().getBool("WEBGL2_ISNAN_CUSTOM") ? `
180
384
  bool isnan_custom(float val) {
181
385
  uint floatToUint = floatBitsToUint(val);
182
386
  return (floatToUint & 0x7fffffffu) > 0x7f800000u;
@@ -188,7 +392,7 @@ function L() {
188
392
  }
189
393
 
190
394
  #define isnan(value) isnan_custom(value)
191
- ` : "", c = "", u = `
395
+ ` : "", s = "", l = `
192
396
  #define round(value) newRound(value)
193
397
  int newRound(float value) {
194
398
  return int(floor(value + 0.5));
@@ -197,7 +401,7 @@ function L() {
197
401
  ivec4 newRound(vec4 value) {
198
402
  return ivec4(floor(value + vec4(0.5)));
199
403
  }
200
- `) : (e = "", t = "attribute", n = "varying", r = "varying", o = "texture2D", i = "gl_FragColor", a = "", s = `
404
+ `) : (e = "", t = "attribute", n = "varying", r = "varying", o = "texture2D", a = "gl_FragColor", i = "", c = `
201
405
  #define isnan(value) isnan_custom(value)
202
406
  bool isnan_custom(float val) {
203
407
  return (val > 0. || val < 1. || val == 0.) ? false : true;
@@ -205,7 +409,7 @@ function L() {
205
409
  bvec4 isnan_custom(vec4 val) {
206
410
  return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));
207
411
  }
208
- `, c = `
412
+ `, s = `
209
413
  uniform float INFINITY;
210
414
 
211
415
  bool isinf(float val) {
@@ -214,7 +418,7 @@ function L() {
214
418
  bvec4 isinf(vec4 val) {
215
419
  return equal(abs(val), vec4(INFINITY));
216
420
  }
217
- `, u = `
421
+ `, l = `
218
422
  int round(float value) {
219
423
  return int(floor(value + 0.5));
220
424
  }
@@ -228,57 +432,57 @@ function L() {
228
432
  varyingVs: n,
229
433
  varyingFs: r,
230
434
  texture2D: o,
231
- output: i,
232
- defineOutput: a,
233
- defineSpecialNaN: s,
234
- defineSpecialInf: c,
235
- defineRound: u
435
+ output: a,
436
+ defineOutput: i,
437
+ defineSpecialNaN: c,
438
+ defineSpecialInf: s,
439
+ defineRound: l
236
440
  };
237
441
  }
238
- function V(e, t, n = "index") {
239
- const r = B(t);
240
- return r.map((o, i) => {
241
- const a = `int ${e[i]} = ${n} / ${o}`, s = i === r.length - 1 ? `int ${e[i + 1]} = ${n} - ${e[i]} * ${o}` : `index -= ${e[i]} * ${o}`;
242
- return `${a}; ${s};`;
442
+ function y(e, t, n = "index") {
443
+ const r = k(t);
444
+ return r.map((o, a) => {
445
+ const i = `int ${e[a]} = ${n} / ${o}`, c = a === r.length - 1 ? `int ${e[a + 1]} = ${n} - ${e[a]} * ${o}` : `index -= ${e[a]} * ${o}`;
446
+ return `${i}; ${c};`;
243
447
  }).join("");
244
448
  }
245
- function se(e, t, n = "index") {
246
- const r = B(t);
247
- return r.map((o, i) => {
248
- const a = `int ${e[i]} = ${n} / outShapeStrides[${i}]`, s = i === r.length - 1 ? `int ${e[i + 1]} = ${n} - ${e[i]} * outShapeStrides[${i}]` : `index -= ${e[i]} * outShapeStrides[${i}]`;
249
- return `${a}; ${s};`;
449
+ function Q(e, t, n = "index") {
450
+ const r = k(t);
451
+ return r.map((o, a) => {
452
+ const i = `int ${e[a]} = ${n} / outShapeStrides[${a}]`, c = a === r.length - 1 ? `int ${e[a + 1]} = ${n} - ${e[a]} * outShapeStrides[${a}]` : `index -= ${e[a]} * outShapeStrides[${a}]`;
453
+ return `${i}; ${c};`;
250
454
  }).join("");
251
455
  }
252
- function Oe(e, t) {
253
- const n = e.length, r = e.map((i) => `${t}[${i}]`), o = new Array(n - 1);
456
+ function Ce(e, t) {
457
+ const n = e.length, r = e.map((a) => `${t}[${a}]`), o = new Array(n - 1);
254
458
  o[n - 2] = r[n - 1];
255
- for (let i = n - 3; i >= 0; --i)
256
- o[i] = `(${o[i + 1]} * ${r[i + 1]})`;
459
+ for (let a = n - 3; a >= 0; --a)
460
+ o[a] = `(${o[a + 1]} * ${r[a + 1]})`;
257
461
  return o;
258
462
  }
259
- function bt(e, t, n = "index") {
260
- const r = e.map((i, a) => a), o = Oe(r, t);
261
- return o.map((i, a) => {
262
- const s = `int ${e[a]} = ${n} / ${o[a]}`, c = a === o.length - 1 ? `int ${e[a + 1]} = ${n} - ${e[a]} * ${o[a]}` : `index -= ${e[a]} * ${o[a]}`;
263
- return `${s}; ${c};`;
463
+ function Wt(e, t, n = "index") {
464
+ const r = e.map((a, i) => i), o = Ce(r, t);
465
+ return o.map((a, i) => {
466
+ const c = `int ${e[i]} = ${n} / ${o[i]}`, s = i === o.length - 1 ? `int ${e[i + 1]} = ${n} - ${e[i]} * ${o[i]}` : `index -= ${e[i]} * ${o[i]}`;
467
+ return `${c}; ${s};`;
264
468
  }).join("");
265
469
  }
266
- function Dt(e) {
267
- const t = B(e).map((n) => n.toString());
470
+ function zt(e) {
471
+ const t = k(e).map((n) => n.toString());
268
472
  return `
269
473
  int getFlatIndex(ivec3 coords) {
270
474
  return coords.x * ${t[0]} + coords.y * ${t[1]} + coords.z;
271
475
  }
272
476
  `;
273
477
  }
274
- function yt() {
478
+ function Gt() {
275
479
  return `
276
480
  int getFlatIndex(ivec3 coords) {
277
481
  return coords.x * outShapeStrides[0] + coords.y * outShapeStrides[1] + coords.z;
278
482
  }
279
483
  `;
280
484
  }
281
- const Mt = `
485
+ const Ht = `
282
486
  const float FLOAT_MAX = 1.70141184e38;
283
487
  const float FLOAT_MIN = 1.17549435e-38;
284
488
 
@@ -318,28 +522,28 @@ const Mt = `
318
522
  return c / 255.0;
319
523
  }
320
524
  `;
321
- const { getBroadcastDims: ue } = Se;
322
- function Le(e, t, n) {
525
+ const { getBroadcastDims: ee } = se;
526
+ function Fe(e, t, n) {
323
527
  const r = [];
324
- if (e.forEach((h) => {
325
- const x = E(h.shapeInfo.logicalShape);
326
- if (h.shapeInfo.isUniform ? r.push(`uniform float ${h.name}${x > 1 ? `[${x}]` : ""};`) : (r.push(`uniform sampler2D ${h.name};`), r.push(`uniform int offset${h.name};`)), n.enableShapeUniforms) {
327
- const { uniformShape: p } = j(n.packedInputs, h.shapeInfo.logicalShape, h.shapeInfo.texShape);
528
+ if (e.forEach((x) => {
529
+ const h = E(x.shapeInfo.logicalShape);
530
+ if (x.shapeInfo.isUniform ? r.push(`uniform float ${x.name}${h > 1 ? `[${h}]` : ""};`) : (r.push(`uniform sampler2D ${x.name};`), r.push(`uniform int offset${x.name};`)), n.enableShapeUniforms) {
531
+ const { uniformShape: p } = z(n.packedInputs, x.shapeInfo.logicalShape, x.shapeInfo.texShape);
328
532
  switch (p.length) {
329
533
  case 1:
330
- r.push(`uniform int ${h.name}Shape;`);
534
+ r.push(`uniform int ${x.name}Shape;`);
331
535
  break;
332
536
  case 2:
333
- r.push(`uniform ivec2 ${h.name}Shape;`);
537
+ r.push(`uniform ivec2 ${x.name}Shape;`);
334
538
  break;
335
539
  case 3:
336
- r.push(`uniform ivec3 ${h.name}Shape;`);
540
+ r.push(`uniform ivec3 ${x.name}Shape;`);
337
541
  break;
338
542
  case 4:
339
- r.push(`uniform ivec4 ${h.name}Shape;`);
543
+ r.push(`uniform ivec4 ${x.name}Shape;`);
340
544
  break;
341
545
  }
342
- r.push(`uniform ivec2 ${h.name}TexShape;`);
546
+ r.push(`uniform ivec2 ${x.name}TexShape;`);
343
547
  }
344
548
  }), n.enableShapeUniforms) {
345
549
  switch (t.logicalShape.length) {
@@ -358,121 +562,121 @@ function Le(e, t, n) {
358
562
  }
359
563
  r.push("uniform ivec2 outTexShape;");
360
564
  }
361
- n.customUniforms && n.customUniforms.forEach((h) => {
362
- r.push(`uniform ${h.type} ${h.name}${h.arrayIndex ? `[${h.arrayIndex}]` : ""};`);
565
+ n.customUniforms && n.customUniforms.forEach((x) => {
566
+ r.push(`uniform ${x.type} ${x.name}${x.arrayIndex ? `[${x.arrayIndex}]` : ""};`);
363
567
  });
364
568
  const o = r.join(`
365
- `), i = e.map((h) => be(h, t, n.packedInputs, n.enableShapeUniforms)).join(`
366
- `), a = t.texShape, s = L(), c = Me(s);
367
- let u, l, f = Pe(s);
368
- return t.isPacked ? (u = De(t.logicalShape, a, n.enableShapeUniforms), l = ke(s)) : (u = ye(t.logicalShape, a, n.enableShapeUniforms), l = Be(s)), n.packedInputs && (f += He), [
569
+ `), a = e.map((x) => _e(x, t, n.packedInputs, n.enableShapeUniforms)).join(`
570
+ `), i = t.texShape, c = L(), s = Ne(c);
571
+ let l, u, f = Le(c);
572
+ return t.isPacked ? (l = Ae(t.logicalShape, i, n.enableShapeUniforms), u = Ie(c)) : (l = we(t.logicalShape, i, n.enableShapeUniforms), u = Oe(c)), n.packedInputs && (f += be), [
369
573
  f,
370
- c,
371
- l,
372
- o,
574
+ s,
373
575
  u,
374
- i,
576
+ o,
577
+ l,
578
+ a,
375
579
  n.userCode
376
580
  ].join(`
377
581
  `);
378
582
  }
379
- function b(e, t = !1) {
583
+ function U(e, t = !1) {
380
584
  const n = e.shapeInfo.logicalShape;
381
585
  switch (n.length) {
382
586
  case 0:
383
- return nt(e, t);
587
+ return qe(e, t);
384
588
  case 1:
385
- return ot(e, t);
589
+ return Ye(e, t);
386
590
  case 2:
387
- return at(e, t);
591
+ return Ze(e, t);
388
592
  case 3:
389
- return st(e, t);
593
+ return Qe(e, t);
390
594
  case 4:
391
- return lt(e, t);
595
+ return tt(e, t);
392
596
  case 5:
393
- return ft(e);
597
+ return nt(e);
394
598
  case 6:
395
- return ht(e);
599
+ return rt(e);
396
600
  default:
397
601
  throw new Error(`${n.length}-D input sampling is not yet supported`);
398
602
  }
399
603
  }
400
- function le(e, t) {
604
+ function te(e, t) {
401
605
  switch (e.shapeInfo.logicalShape.length) {
402
606
  case 0:
403
- return tt(e);
607
+ return He(e);
404
608
  case 1:
405
- return rt(e, t);
609
+ return je(e, t);
406
610
  case 2:
407
- return it(e, t);
611
+ return Ke(e, t);
408
612
  case 3:
409
- return ct(e, t);
613
+ return Je(e, t);
410
614
  default:
411
- return ut(e, t);
615
+ return et(e, t);
412
616
  }
413
617
  }
414
- function be(e, t, n = !1, r) {
618
+ function _e(e, t, n = !1, r) {
415
619
  let o = "";
416
- n ? o += le(e, r) : o += b(e, r);
417
- const i = e.shapeInfo.logicalShape, a = t.logicalShape;
418
- return i.length <= a.length && (n ? o += dt(e, t) : o += xt(e, t)), o;
620
+ n ? o += te(e, r) : o += U(e, r);
621
+ const a = e.shapeInfo.logicalShape, i = t.logicalShape;
622
+ return a.length <= i.length && (n ? o += ot(e, t) : o += at(e, t)), o;
419
623
  }
420
- function De(e, t, n) {
624
+ function Ae(e, t, n) {
421
625
  switch (e.length) {
422
626
  case 0:
423
- return fe();
627
+ return ne();
424
628
  case 1:
425
- return Ge(e, t, n);
629
+ return ke(e, t, n);
426
630
  case 2:
427
- return Qe(e, t, n);
631
+ return ze(e, t, n);
428
632
  case 3:
429
- return qe(e, t, n);
633
+ return Be(e, t, n);
430
634
  default:
431
- return Je(e, t, n);
635
+ return Pe(e, t, n);
432
636
  }
433
637
  }
434
- function ye(e, t, n) {
638
+ function we(e, t, n) {
435
639
  switch (e.length) {
436
640
  case 0:
437
- return fe();
641
+ return ne();
438
642
  case 1:
439
- return ze(e, t, n);
643
+ return Me(e, t, n);
440
644
  case 2:
441
- return et(e, t, n);
645
+ return Ge(e, t, n);
442
646
  case 3:
443
- return je(e, t, n);
647
+ return ye(e, t, n);
444
648
  case 4:
445
- return Ye(e, t, n);
649
+ return Ve(e, t, n);
446
650
  case 5:
447
- return Ke(e, t);
651
+ return Xe(e, t);
448
652
  case 6:
449
- return Ze(e, t);
653
+ return We(e, t);
450
654
  default:
451
655
  throw new Error(`${e.length}-D output sampling is not yet supported`);
452
656
  }
453
657
  }
454
- function Me(e) {
658
+ function Ne(e) {
455
659
  return `
456
660
  float sampleTexture(sampler2D textureSampler, vec2 uv) {
457
661
  return ${e.texture2D}(textureSampler, uv).r;
458
662
  }
459
663
  `;
460
664
  }
461
- function Be(e) {
665
+ function Oe(e) {
462
666
  return `
463
667
  void setOutput(float val) {
464
668
  ${e.output} = vec4(val, 0, 0, 0);
465
669
  }
466
670
  `;
467
671
  }
468
- function ke(e) {
672
+ function Ie(e) {
469
673
  return `
470
674
  void setOutput(vec4 val) {
471
675
  ${e.output} = val;
472
676
  }
473
677
  `;
474
678
  }
475
- function Pe(e) {
679
+ function Le(e) {
476
680
  return `${e.version}
477
681
  precision highp float;
478
682
  precision highp int;
@@ -528,12 +732,12 @@ function Pe(e) {
528
732
  return fract((p3.x + p3.y) * p3.z);
529
733
  }
530
734
 
531
- ${Ve}
532
- ${We}
533
- ${Xe}
735
+ ${Ue}
736
+ ${De}
737
+ ${ge}
534
738
  `;
535
739
  }
536
- const Ve = `
740
+ const Ue = `
537
741
  vec2 uvFromFlat(int texNumR, int texNumC, int index) {
538
742
  int texR = index / texNumC;
539
743
  int texC = index - texR * texNumC;
@@ -545,7 +749,7 @@ vec2 packedUVfrom1D(int texNumR, int texNumC, int index) {
545
749
  int texC = texelIndex - texR * texNumC;
546
750
  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
547
751
  }
548
- `, We = `
752
+ `, De = `
549
753
  vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
550
754
  int texNumC, int row, int col) {
551
755
  int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);
@@ -553,7 +757,7 @@ vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
553
757
  int texC = texelIndex - texR * texNumC;
554
758
  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
555
759
  }
556
- `, Xe = `
760
+ `, ge = `
557
761
  vec2 packedUVfrom3D(int texNumR, int texNumC,
558
762
  int texelsInBatch, int texelsInLogicalRow, int b,
559
763
  int row, int col) {
@@ -562,7 +766,7 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
562
766
  int texC = index - texR * texNumC;
563
767
  return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
564
768
  }
565
- `, He = `
769
+ `, be = `
566
770
  float getChannel(vec4 frag, vec2 innerDims) {
567
771
  vec2 modCoord = mod(innerDims, 2.);
568
772
  return modCoord.x == 0. ?
@@ -574,14 +778,14 @@ vec2 packedUVfrom3D(int texNumR, int texNumC,
574
778
  return modCoord == 0. ? frag.r : frag.g;
575
779
  }
576
780
  `;
577
- function fe() {
781
+ function ne() {
578
782
  return `
579
783
  int getOutputCoords() {
580
784
  return 0;
581
785
  }
582
786
  `;
583
787
  }
584
- function Ge(e, t, n) {
788
+ function ke(e, t, n) {
585
789
  const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
586
790
  return r[0] === 1 ? n ? `
587
791
  int getOutputCoords() {
@@ -614,7 +818,7 @@ function Ge(e, t, n) {
614
818
  }
615
819
  `;
616
820
  }
617
- function ze(e, t, n) {
821
+ function Me(e, t, n) {
618
822
  return t[0] === 1 ? n ? `
619
823
  int getOutputCoords() {
620
824
  return int(resultUV.x * float(outTexShape[1]));
@@ -645,7 +849,7 @@ function ze(e, t, n) {
645
849
  }
646
850
  `;
647
851
  }
648
- function qe(e, t, n) {
852
+ function Be(e, t, n) {
649
853
  if (n)
650
854
  return `
651
855
  ivec3 getOutputCoords() {
@@ -665,15 +869,15 @@ function qe(e, t, n) {
665
869
  return ivec3(b, r, c);
666
870
  }
667
871
  `;
668
- const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], o = Math.ceil(e[2] / 2), i = o * Math.ceil(e[1] / 2);
872
+ const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], o = Math.ceil(e[2] / 2), a = o * Math.ceil(e[1] / 2);
669
873
  return `
670
874
  ivec3 getOutputCoords() {
671
875
  ivec2 resTexRC = ivec2(resultUV.yx *
672
876
  vec2(${r[0]}, ${r[1]}));
673
877
  int index = resTexRC.x * ${r[1]} + resTexRC.y;
674
878
 
675
- int b = index / ${i};
676
- index -= b * ${i};
879
+ int b = index / ${a};
880
+ index -= b * ${a};
677
881
 
678
882
  int r = 2 * (index / ${o});
679
883
  int c = imod(index, ${o}) * 2;
@@ -682,18 +886,18 @@ function qe(e, t, n) {
682
886
  }
683
887
  `;
684
888
  }
685
- function je(e, t, n) {
889
+ function ye(e, t, n) {
686
890
  if (n)
687
891
  return `
688
892
  ivec3 getOutputCoords() {
689
893
  ivec2 resTexRC = ivec2(resultUV.yx *
690
894
  vec2(outTexShape[0], outTexShape[1]));
691
895
  int index = resTexRC.x * outTexShape[1] + resTexRC.y;
692
- ${se(["r", "c", "d"], e)}
896
+ ${Q(["r", "c", "d"], e)}
693
897
  return ivec3(r, c, d);
694
898
  }
695
899
  `;
696
- const r = V(["r", "c", "d"], e);
900
+ const r = y(["r", "c", "d"], e);
697
901
  return `
698
902
  ivec3 getOutputCoords() {
699
903
  ivec2 resTexRC = ivec2(resultUV.yx *
@@ -704,7 +908,7 @@ function je(e, t, n) {
704
908
  }
705
909
  `;
706
910
  }
707
- function Je(e, t, n) {
911
+ function Pe(e, t, n) {
708
912
  if (n)
709
913
  return `
710
914
  ivec4 getOutputCoords() {
@@ -729,43 +933,43 @@ function Je(e, t, n) {
729
933
  return ivec4(b2, b, r, c);
730
934
  }
731
935
  `;
732
- const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], o = Math.ceil(e[e.length - 1] / 2), i = o * Math.ceil(e[e.length - 2] / 2);
733
- let a = i, s = "", c = "b, r, c";
734
- for (let u = 2; u < e.length - 1; u++)
735
- a *= e[e.length - u - 1], s = `
736
- int b${u} = index / ${a};
737
- index -= b${u} * ${a};
738
- ` + s, c = `b${u}, ` + c;
936
+ const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], o = Math.ceil(e[e.length - 1] / 2), a = o * Math.ceil(e[e.length - 2] / 2);
937
+ let i = a, c = "", s = "b, r, c";
938
+ for (let l = 2; l < e.length - 1; l++)
939
+ i *= e[e.length - l - 1], c = `
940
+ int b${l} = index / ${i};
941
+ index -= b${l} * ${i};
942
+ ` + c, s = `b${l}, ` + s;
739
943
  return `
740
944
  ivec${e.length} getOutputCoords() {
741
945
  ivec2 resTexRC = ivec2(resultUV.yx *
742
946
  vec2(${r[0]}, ${r[1]}));
743
947
  int index = resTexRC.x * ${r[1]} + resTexRC.y;
744
948
 
745
- ${s}
949
+ ${c}
746
950
 
747
- int b = index / ${i};
748
- index -= b * ${i};
951
+ int b = index / ${a};
952
+ index -= b * ${a};
749
953
 
750
954
  int r = 2 * (index / ${o});
751
955
  int c = imod(index, ${o}) * 2;
752
956
 
753
- return ivec${e.length}(${c});
957
+ return ivec${e.length}(${s});
754
958
  }
755
959
  `;
756
960
  }
757
- function Ye(e, t, n) {
961
+ function Ve(e, t, n) {
758
962
  if (n)
759
963
  return `
760
964
  ivec4 getOutputCoords() {
761
965
  ivec2 resTexRC = ivec2(resultUV.yx *
762
966
  vec2(outTexShape[0], outTexShape[1]));
763
967
  int index = resTexRC.x * outTexShape[1] + resTexRC.y;
764
- ${se(["r", "c", "d", "d2"], e)}
968
+ ${Q(["r", "c", "d", "d2"], e)}
765
969
  return ivec4(r, c, d, d2);
766
970
  }
767
971
  `;
768
- const r = V(["r", "c", "d", "d2"], e);
972
+ const r = y(["r", "c", "d", "d2"], e);
769
973
  return `
770
974
  ivec4 getOutputCoords() {
771
975
  ivec2 resTexRC = ivec2(resultUV.yx *
@@ -776,8 +980,8 @@ function Ye(e, t, n) {
776
980
  }
777
981
  `;
778
982
  }
779
- function Ke(e, t) {
780
- const n = V(["r", "c", "d", "d2", "d3"], e);
983
+ function Xe(e, t) {
984
+ const n = y(["r", "c", "d", "d2", "d3"], e);
781
985
  return `
782
986
  ivec5 getOutputCoords() {
783
987
  ivec2 resTexRC = ivec2(resultUV.yx * vec2(${t[0]},
@@ -792,8 +996,8 @@ function Ke(e, t) {
792
996
  }
793
997
  `;
794
998
  }
795
- function Ze(e, t) {
796
- const n = V(["r", "c", "d", "d2", "d3", "d4"], e);
999
+ function We(e, t) {
1000
+ const n = y(["r", "c", "d", "d2", "d3", "d4"], e);
797
1001
  return `
798
1002
  ivec6 getOutputCoords() {
799
1003
  ivec2 resTexRC = ivec2(resultUV.yx *
@@ -807,7 +1011,7 @@ function Ze(e, t) {
807
1011
  }
808
1012
  `;
809
1013
  }
810
- function Qe(e, t, n) {
1014
+ function ze(e, t, n) {
811
1015
  const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
812
1016
  if (T(e, t))
813
1017
  return n ? `
@@ -847,7 +1051,7 @@ function Qe(e, t, n) {
847
1051
  }
848
1052
  `;
849
1053
  }
850
- function et(e, t, n) {
1054
+ function Ge(e, t, n) {
851
1055
  return T(e, t) ? n ? `
852
1056
  ivec2 getOutputCoords() {
853
1057
  return ivec2(resultUV.yx * vec2(outTexShape[0], outTexShape[1]));
@@ -904,10 +1108,10 @@ function et(e, t, n) {
904
1108
  }
905
1109
  `;
906
1110
  }
907
- function U(e) {
1111
+ function O(e) {
908
1112
  return `offset${e}`;
909
1113
  }
910
- function tt(e) {
1114
+ function He(e) {
911
1115
  const t = e.name, n = "get" + t.charAt(0).toUpperCase() + t.slice(1), r = L();
912
1116
  return `
913
1117
  vec4 ${n}() {
@@ -915,54 +1119,54 @@ function tt(e) {
915
1119
  }
916
1120
  `;
917
1121
  }
918
- function nt(e, t) {
1122
+ function qe(e, t) {
919
1123
  const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1);
920
1124
  if (e.shapeInfo.isUniform)
921
1125
  return `float ${r}() {return ${n};}`;
922
- const [o, i] = e.shapeInfo.texShape;
923
- if (o === 1 && i === 1)
1126
+ const [o, a] = e.shapeInfo.texShape;
1127
+ if (o === 1 && a === 1)
924
1128
  return `
925
1129
  float ${r}() {
926
1130
  return sampleTexture(${n}, halfCR);
927
1131
  }
928
1132
  `;
929
- const a = U(n);
1133
+ const i = O(n);
930
1134
  if (t)
931
1135
  return `
932
1136
  float ${r}() {
933
- vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], ${a});
1137
+ vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], ${i});
934
1138
  return sampleTexture(${n}, uv);
935
1139
  }
936
1140
  `;
937
- const [s, c] = e.shapeInfo.texShape;
1141
+ const [c, s] = e.shapeInfo.texShape;
938
1142
  return `
939
1143
  float ${r}() {
940
- vec2 uv = uvFromFlat(${s}, ${c}, ${a});
1144
+ vec2 uv = uvFromFlat(${c}, ${s}, ${i});
941
1145
  return sampleTexture(${n}, uv);
942
1146
  }
943
1147
  `;
944
1148
  }
945
- function rt(e, t) {
946
- const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = e.shapeInfo.texShape, i = L();
1149
+ function je(e, t) {
1150
+ const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = e.shapeInfo.texShape, a = L();
947
1151
  if (t)
948
1152
  return `
949
1153
  vec4 ${r}(int index) {
950
1154
  ivec2 packedTexShape = ivec2(ceil(float(${n}TexShape[0]) / 2.0), ceil(float(${n}TexShape[1]) / 2.0));
951
1155
  vec2 uv = packedUVfrom1D(
952
1156
  packedTexShape[0], packedTexShape[1], index);
953
- return ${i.texture2D}(${n}, uv);
1157
+ return ${a.texture2D}(${n}, uv);
954
1158
  }
955
1159
  `;
956
- const a = [Math.ceil(o[0] / 2), Math.ceil(o[1] / 2)];
1160
+ const i = [Math.ceil(o[0] / 2), Math.ceil(o[1] / 2)];
957
1161
  return `
958
1162
  vec4 ${r}(int index) {
959
1163
  vec2 uv = packedUVfrom1D(
960
- ${a[0]}, ${a[1]}, index);
961
- return ${i.texture2D}(${n}, uv);
1164
+ ${i[0]}, ${i[1]}, index);
1165
+ return ${a.texture2D}(${n}, uv);
962
1166
  }
963
1167
  `;
964
1168
  }
965
- function ot(e, t) {
1169
+ function Ye(e, t) {
966
1170
  const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1);
967
1171
  if (e.shapeInfo.isUniform)
968
1172
  return `
@@ -970,60 +1174,60 @@ function ot(e, t) {
970
1174
  ${D(e)}
971
1175
  }
972
1176
  `;
973
- const o = e.shapeInfo.texShape, i = o[0], a = o[1];
974
- if (a === 1 && i === 1)
1177
+ const o = e.shapeInfo.texShape, a = o[0], i = o[1];
1178
+ if (i === 1 && a === 1)
975
1179
  return `
976
1180
  float ${r}(int index) {
977
1181
  return sampleTexture(${n}, halfCR);
978
1182
  }
979
1183
  `;
980
- const s = U(n);
981
- return a === 1 ? t ? `
1184
+ const c = O(n);
1185
+ return i === 1 ? t ? `
982
1186
  float ${r}(int index) {
983
- vec2 uv = vec2(0.5, (float(index + ${s}) + 0.5) / float(${n}TexShape[0]));
1187
+ vec2 uv = vec2(0.5, (float(index + ${c}) + 0.5) / float(${n}TexShape[0]));
984
1188
  return sampleTexture(${n}, uv);
985
1189
  }
986
1190
  ` : `
987
1191
  float ${r}(int index) {
988
- vec2 uv = vec2(0.5, (float(index + ${s}) + 0.5) / ${i}.0);
1192
+ vec2 uv = vec2(0.5, (float(index + ${c}) + 0.5) / ${a}.0);
989
1193
  return sampleTexture(${n}, uv);
990
1194
  }
991
- ` : i === 1 ? t ? `
1195
+ ` : a === 1 ? t ? `
992
1196
  float ${r}(int index) {
993
- vec2 uv = vec2((float(index + ${s}) + 0.5) / float(${n}TexShape[1]), 0.5);
1197
+ vec2 uv = vec2((float(index + ${c}) + 0.5) / float(${n}TexShape[1]), 0.5);
994
1198
  return sampleTexture(${n}, uv);
995
1199
  }
996
1200
  ` : `
997
1201
  float ${r}(int index) {
998
- vec2 uv = vec2((float(index + ${s}) + 0.5) / ${a}.0, 0.5);
1202
+ vec2 uv = vec2((float(index + ${c}) + 0.5) / ${i}.0, 0.5);
999
1203
  return sampleTexture(${n}, uv);
1000
1204
  }
1001
1205
  ` : t ? `
1002
1206
  float ${r}(int index) {
1003
- vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], index + ${s});
1207
+ vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], index + ${c});
1004
1208
  return sampleTexture(${n}, uv);
1005
1209
  }
1006
1210
  ` : `
1007
1211
  float ${r}(int index) {
1008
- vec2 uv = uvFromFlat(${i}, ${a}, index + ${s});
1212
+ vec2 uv = uvFromFlat(${a}, ${i}, index + ${c});
1009
1213
  return sampleTexture(${n}, uv);
1010
1214
  }
1011
1215
  `;
1012
1216
  }
1013
- function it(e, t) {
1014
- const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), i = e.shapeInfo.texShape, a = i[0], s = i[1], c = L();
1015
- if (i != null && T(n, i))
1217
+ function Ke(e, t) {
1218
+ const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = e.shapeInfo.texShape, i = a[0], c = a[1], s = L();
1219
+ if (a != null && T(n, a))
1016
1220
  return t ? `
1017
1221
  vec4 ${o}(int row, int col) {
1018
1222
  vec2 uv = (vec2(col, row) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
1019
1223
 
1020
- return ${c.texture2D}(${r}, uv);
1224
+ return ${s.texture2D}(${r}, uv);
1021
1225
  }
1022
1226
  ` : `
1023
1227
  vec4 ${o}(int row, int col) {
1024
- vec2 uv = (vec2(col, row) + halfCR) / vec2(${s}.0, ${a}.0);
1228
+ vec2 uv = (vec2(col, row) + halfCR) / vec2(${c}.0, ${i}.0);
1025
1229
 
1026
- return ${c.texture2D}(${r}, uv);
1230
+ return ${s.texture2D}(${r}, uv);
1027
1231
  }
1028
1232
  `;
1029
1233
  if (t)
@@ -1032,20 +1236,20 @@ function it(e, t) {
1032
1236
  ivec2 packedTexShape = ivec2(ceil(float(${r}TexShape[0]) / 2.0), ceil(float(${r}TexShape[1]) / 2.0));
1033
1237
  int valuesPerRow = int(ceil(float(${r}Shape[1]) / 2.0));
1034
1238
  vec2 uv = packedUVfrom2D(valuesPerRow, packedTexShape[0], packedTexShape[1], row, col);
1035
- return ${c.texture2D}(${r}, uv);
1239
+ return ${s.texture2D}(${r}, uv);
1036
1240
  }
1037
1241
  `;
1038
- const u = [Math.ceil(i[0] / 2), Math.ceil(i[1] / 2)], l = Math.ceil(n[1] / 2);
1242
+ const l = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)], u = Math.ceil(n[1] / 2);
1039
1243
  return `
1040
1244
  vec4 ${o}(int row, int col) {
1041
- vec2 uv = packedUVfrom2D(${l}, ${u[0]}, ${u[1]}, row, col);
1042
- return ${c.texture2D}(${r}, uv);
1245
+ vec2 uv = packedUVfrom2D(${u}, ${l[0]}, ${l[1]}, row, col);
1246
+ return ${s.texture2D}(${r}, uv);
1043
1247
  }
1044
1248
  `;
1045
1249
  }
1046
- function at(e, t) {
1047
- const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), i = e.shapeInfo.texShape;
1048
- if (i != null && T(n, i)) {
1250
+ function Ze(e, t) {
1251
+ const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = e.shapeInfo.texShape;
1252
+ if (a != null && T(n, a)) {
1049
1253
  if (t)
1050
1254
  return `
1051
1255
  float ${o}(int row, int col) {
@@ -1053,21 +1257,21 @@ function at(e, t) {
1053
1257
  return sampleTexture(${r}, uv);
1054
1258
  }
1055
1259
  `;
1056
- const d = i[0], h = i[1];
1260
+ const d = a[0], x = a[1];
1057
1261
  return `
1058
1262
  float ${o}(int row, int col) {
1059
- vec2 uv = (vec2(col, row) + halfCR) / vec2(${h}.0, ${d}.0);
1263
+ vec2 uv = (vec2(col, row) + halfCR) / vec2(${x}.0, ${d}.0);
1060
1264
  return sampleTexture(${r}, uv);
1061
1265
  }
1062
1266
  `;
1063
1267
  }
1064
- const { newShape: a, keptDims: s } = I(n), c = a;
1065
- if (c.length < n.length) {
1066
- const d = y(e, c), h = ["row", "col"];
1268
+ const { newShape: i, keptDims: c } = N(n), s = i;
1269
+ if (s.length < n.length) {
1270
+ const d = g(e, s), x = ["row", "col"];
1067
1271
  return `
1068
- ${b(d, t)}
1272
+ ${U(d, t)}
1069
1273
  float ${o}(int row, int col) {
1070
- return ${o}(${M(h, s)});
1274
+ return ${o}(${b(x, c)});
1071
1275
  }
1072
1276
  `;
1073
1277
  }
@@ -1078,8 +1282,8 @@ function at(e, t) {
1078
1282
  ${D(e)}
1079
1283
  }
1080
1284
  `;
1081
- const u = i[0], l = i[1], f = U(r);
1082
- return l === 1 ? t ? `
1285
+ const l = a[0], u = a[1], f = O(r);
1286
+ return u === 1 ? t ? `
1083
1287
  float ${o}(int row, int col) {
1084
1288
  float index = dot(vec3(row, col, ${f}), vec3(${r}Shape[1], 1, 1));
1085
1289
  vec2 uv = vec2(0.5, (index + 0.5) / float(${r}TexShape[0]));
@@ -1088,10 +1292,10 @@ function at(e, t) {
1088
1292
  ` : `
1089
1293
  float ${o}(int row, int col) {
1090
1294
  float index = dot(vec3(row, col, ${f}), vec3(${n[1]}, 1, 1));
1091
- vec2 uv = vec2(0.5, (index + 0.5) / ${u}.0);
1295
+ vec2 uv = vec2(0.5, (index + 0.5) / ${l}.0);
1092
1296
  return sampleTexture(${r}, uv);
1093
1297
  }
1094
- ` : u === 1 ? t ? `
1298
+ ` : l === 1 ? t ? `
1095
1299
  float ${o}(int row, int col) {
1096
1300
  float index = dot(vec3(row, col, ${f}), vec3(${r}Shape[1], 1, 1));
1097
1301
  vec2 uv = vec2((index + 0.5) / float(${r}TexShape[1]), 0.5);
@@ -1100,7 +1304,7 @@ function at(e, t) {
1100
1304
  ` : `
1101
1305
  float ${o}(int row, int col) {
1102
1306
  float index = dot(vec3(row, col, ${f}), vec3(${n[1]}, 1, 1));
1103
- vec2 uv = vec2((index + 0.5) / ${l}.0, 0.5);
1307
+ vec2 uv = vec2((index + 0.5) / ${u}.0, 0.5);
1104
1308
  return sampleTexture(${r}, uv);
1105
1309
  }
1106
1310
  ` : t ? `
@@ -1114,23 +1318,23 @@ function at(e, t) {
1114
1318
  float ${o}(int row, int col) {
1115
1319
  // Explicitly use integer operations as dot() only works on floats.
1116
1320
  int index = row * ${n[1]} + col + ${f};
1117
- vec2 uv = uvFromFlat(${u}, ${l}, index);
1321
+ vec2 uv = uvFromFlat(${l}, ${u}, index);
1118
1322
  return sampleTexture(${r}, uv);
1119
1323
  }
1120
1324
  `;
1121
1325
  }
1122
- function ct(e, t) {
1123
- const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), i = e.shapeInfo.texShape, a = [Math.ceil(i[0] / 2), Math.ceil(i[1] / 2)];
1326
+ function Je(e, t) {
1327
+ const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = e.shapeInfo.texShape, i = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)];
1124
1328
  if (n[0] === 1) {
1125
- const d = n.slice(1), h = [1, 2], x = y(e, d), p = ["b", "row", "col"];
1329
+ const d = n.slice(1), x = [1, 2], h = g(e, d), p = ["b", "row", "col"];
1126
1330
  return `
1127
- ${le(x, t)}
1331
+ ${te(h, t)}
1128
1332
  vec4 ${o}(int b, int row, int col) {
1129
- return ${o}(${M(p, h)});
1333
+ return ${o}(${b(p, x)});
1130
1334
  }
1131
1335
  `;
1132
1336
  }
1133
- const s = L();
1337
+ const c = L();
1134
1338
  if (t)
1135
1339
  return `
1136
1340
  vec4 ${o}(int b, int row, int col) {
@@ -1139,26 +1343,26 @@ function ct(e, t) {
1139
1343
  int texelsInBatch = valuesPerRow * int(ceil(float(${r}Shape[1]) / 2.0));
1140
1344
  vec2 uv = packedUVfrom3D(
1141
1345
  packedTexShape[0], packedTexShape[1], texelsInBatch, valuesPerRow, b, row, col);
1142
- return ${s.texture2D}(${r}, uv);
1346
+ return ${c.texture2D}(${r}, uv);
1143
1347
  }
1144
1348
  `;
1145
- const c = a[0], u = a[1], l = Math.ceil(n[2] / 2), f = l * Math.ceil(n[1] / 2);
1349
+ const s = i[0], l = i[1], u = Math.ceil(n[2] / 2), f = u * Math.ceil(n[1] / 2);
1146
1350
  return `
1147
1351
  vec4 ${o}(int b, int row, int col) {
1148
1352
  vec2 uv = packedUVfrom3D(
1149
- ${c}, ${u}, ${f}, ${l}, b, row, col);
1150
- return ${s.texture2D}(${r}, uv);
1353
+ ${s}, ${l}, ${f}, ${u}, b, row, col);
1354
+ return ${c.texture2D}(${r}, uv);
1151
1355
  }
1152
1356
  `;
1153
1357
  }
1154
- function st(e, t) {
1155
- const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), i = n[1] * n[2], a = n[2], { newShape: s, keptDims: c } = I(n), u = s;
1156
- if (u.length < n.length) {
1157
- const p = y(e, u), $ = ["row", "col", "depth"];
1358
+ function Qe(e, t) {
1359
+ const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = n[1] * n[2], i = n[2], { newShape: c, keptDims: s } = N(n), l = c;
1360
+ if (l.length < n.length) {
1361
+ const p = g(e, l), m = ["row", "col", "depth"];
1158
1362
  return `
1159
- ${b(p, t)}
1363
+ ${U(p, t)}
1160
1364
  float ${o}(int row, int col, int depth) {
1161
- return ${o}(${M($, c)});
1365
+ return ${o}(${b(m, s)});
1162
1366
  }
1163
1367
  `;
1164
1368
  }
@@ -1166,12 +1370,12 @@ function st(e, t) {
1166
1370
  return `
1167
1371
  float ${o}(int row, int col, int depth) {
1168
1372
  int index = round(dot(vec3(row, col, depth),
1169
- vec3(${i}, ${a}, 1)));
1373
+ vec3(${a}, ${i}, 1)));
1170
1374
  ${D(e)}
1171
1375
  }
1172
1376
  `;
1173
- const l = e.shapeInfo.texShape, f = l[0], d = l[1], h = e.shapeInfo.flatOffset;
1174
- if (d === i && h == null)
1377
+ const u = e.shapeInfo.texShape, f = u[0], d = u[1], x = e.shapeInfo.flatOffset;
1378
+ if (d === a && x == null)
1175
1379
  return t ? `
1176
1380
  float ${o}(int row, int col, int depth) {
1177
1381
  int stride1 = ${r}Shape[2];
@@ -1184,13 +1388,13 @@ function st(e, t) {
1184
1388
  ` : `
1185
1389
  float ${o}(int row, int col, int depth) {
1186
1390
  float texR = float(row);
1187
- float texC = dot(vec2(col, depth), vec2(${a}, 1));
1391
+ float texC = dot(vec2(col, depth), vec2(${i}, 1));
1188
1392
  vec2 uv = (vec2(texC, texR) + halfCR) /
1189
1393
  vec2(${d}.0, ${f}.0);
1190
1394
  return sampleTexture(${r}, uv);
1191
1395
  }
1192
1396
  `;
1193
- if (d === a && h == null)
1397
+ if (d === i && x == null)
1194
1398
  return t ? `
1195
1399
  float ${o}(int row, int col, int depth) {
1196
1400
  float texR = dot(vec2(row, col), vec2(${r}Shape[1], 1));
@@ -1206,26 +1410,26 @@ function st(e, t) {
1206
1410
  return sampleTexture(${r}, uv);
1207
1411
  }
1208
1412
  `;
1209
- const x = U(r);
1413
+ const h = O(r);
1210
1414
  return t ? `
1211
1415
  float ${o}(int row, int col, int depth) {
1212
1416
  // Explicitly use integer operations as dot() only works on floats.
1213
1417
  int stride0 = ${r}Shape[1] * ${r}Shape[2];
1214
1418
  int stride1 = ${r}Shape[2];
1215
- int index = row * stride0 + col * stride1 + depth + ${x};
1419
+ int index = row * stride0 + col * stride1 + depth + ${h};
1216
1420
  vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index);
1217
1421
  return sampleTexture(${r}, uv);
1218
1422
  }
1219
1423
  ` : `
1220
1424
  float ${o}(int row, int col, int depth) {
1221
1425
  // Explicitly use integer operations as dot() only works on floats.
1222
- int index = row * ${i} + col * ${a} + depth + ${x};
1426
+ int index = row * ${a} + col * ${i} + depth + ${h};
1223
1427
  vec2 uv = uvFromFlat(${f}, ${d}, index);
1224
1428
  return sampleTexture(${r}, uv);
1225
1429
  }
1226
1430
  `;
1227
1431
  }
1228
- function ut(e, t) {
1432
+ function et(e, t) {
1229
1433
  const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = L();
1230
1434
  if (t)
1231
1435
  return `
@@ -1241,28 +1445,28 @@ function ut(e, t) {
1241
1445
  vec2 uv = (vec2(texC, texR) + halfCR) / vec2(packedTexShape[1], packedTexShape[0]); return ${o.texture2D}(${n}, uv);
1242
1446
  }
1243
1447
  `;
1244
- const i = e.shapeInfo.logicalShape, a = i.length, s = e.shapeInfo.texShape, c = [Math.ceil(s[0] / 2), Math.ceil(s[1] / 2)], u = c[0], l = c[1], f = Math.ceil(i[a - 1] / 2);
1245
- let d = f * Math.ceil(i[a - 2] / 2), h = "int b, int row, int col", x = `b * ${d} + (row / 2) * ${f} + (col / 2)`;
1246
- for (let p = 2; p < a - 1; p++)
1247
- h = `int b${p}, ` + h, d *= i[a - p - 1], x = `b${p} * ${d} + ` + x;
1448
+ const a = e.shapeInfo.logicalShape, i = a.length, c = e.shapeInfo.texShape, s = [Math.ceil(c[0] / 2), Math.ceil(c[1] / 2)], l = s[0], u = s[1], f = Math.ceil(a[i - 1] / 2);
1449
+ let d = f * Math.ceil(a[i - 2] / 2), x = "int b, int row, int col", h = `b * ${d} + (row / 2) * ${f} + (col / 2)`;
1450
+ for (let p = 2; p < i - 1; p++)
1451
+ x = `int b${p}, ` + x, d *= a[i - p - 1], h = `b${p} * ${d} + ` + h;
1248
1452
  return `
1249
- vec4 ${r}(${h}) {
1250
- int index = ${x};
1251
- int texR = index / ${l};
1252
- int texC = index - texR * ${l};
1253
- vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${l}, ${u});
1453
+ vec4 ${r}(${x}) {
1454
+ int index = ${h};
1455
+ int texR = index / ${u};
1456
+ int texC = index - texR * ${u};
1457
+ vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${u}, ${l});
1254
1458
  return ${o.texture2D}(${n}, uv);
1255
1459
  }
1256
1460
  `;
1257
1461
  }
1258
- function lt(e, t) {
1259
- const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), i = n[3], a = n[2] * i, s = n[1] * a, { newShape: c, keptDims: u } = I(n);
1260
- if (c.length < n.length) {
1261
- const R = y(e, c), w = ["row", "col", "depth", "depth2"];
1462
+ function tt(e, t) {
1463
+ const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = n[3], i = n[2] * a, c = n[1] * i, { newShape: s, keptDims: l } = N(n);
1464
+ if (s.length < n.length) {
1465
+ const R = g(e, s), F = ["row", "col", "depth", "depth2"];
1262
1466
  return `
1263
- ${b(R, t)}
1467
+ ${U(R, t)}
1264
1468
  float ${o}(int row, int col, int depth, int depth2) {
1265
- return ${o}(${M(w, u)});
1469
+ return ${o}(${b(F, l)});
1266
1470
  }
1267
1471
  `;
1268
1472
  }
@@ -1270,15 +1474,15 @@ function lt(e, t) {
1270
1474
  return `
1271
1475
  float ${o}(int row, int col, int depth, int depth2) {
1272
1476
  int index = round(dot(vec4(row, col, depth, depth2),
1273
- vec4(${s}, ${a}, ${i}, 1)));
1477
+ vec4(${c}, ${i}, ${a}, 1)));
1274
1478
  ${D(e)}
1275
1479
  }
1276
1480
  `;
1277
- const l = e.shapeInfo.flatOffset, f = e.shapeInfo.texShape, d = f[0], h = f[1], x = `int stride2 = ${r}Shape[3];`, p = `int stride1 = ${r}Shape[2] * stride2;`, $ = `int stride0 = ${r}Shape[1] * stride1;`;
1278
- if (h === s && l == null)
1481
+ const u = e.shapeInfo.flatOffset, f = e.shapeInfo.texShape, d = f[0], x = f[1], h = `int stride2 = ${r}Shape[3];`, p = `int stride1 = ${r}Shape[2] * stride2;`, m = `int stride0 = ${r}Shape[1] * stride1;`;
1482
+ if (x === c && u == null)
1279
1483
  return t ? `
1280
1484
  float ${o}(int row, int col, int depth, int depth2) {
1281
- ${x}
1485
+ ${h}
1282
1486
  ${p}
1283
1487
  float texR = float(row);
1284
1488
  float texC =
@@ -1293,13 +1497,13 @@ function lt(e, t) {
1293
1497
  float texR = float(row);
1294
1498
  float texC =
1295
1499
  dot(vec3(col, depth, depth2),
1296
- vec3(${a}, ${i}, 1));
1500
+ vec3(${i}, ${a}, 1));
1297
1501
  vec2 uv = (vec2(texC, texR) + halfCR) /
1298
- vec2(${h}.0, ${d}.0);
1502
+ vec2(${x}.0, ${d}.0);
1299
1503
  return sampleTexture(${r}, uv);
1300
1504
  }
1301
1505
  `;
1302
- if (h === i && l == null)
1506
+ if (x === a && u == null)
1303
1507
  return t ? `
1304
1508
  float ${o}(int row, int col, int depth, int depth2) {
1305
1509
  float texR = dot(vec3(row, col, depth),
@@ -1315,17 +1519,17 @@ function lt(e, t) {
1315
1519
  vec3(${n[1] * n[2]}, ${n[2]}, 1));
1316
1520
  float texC = float(depth2);
1317
1521
  vec2 uv = (vec2(texC, texR) + halfCR) /
1318
- vec2(${h}.0, ${d}.0);
1522
+ vec2(${x}.0, ${d}.0);
1319
1523
  return sampleTexture(${r}, uv);
1320
1524
  }
1321
1525
  `;
1322
- const S = U(r);
1526
+ const S = O(r);
1323
1527
  return t ? `
1324
1528
  float ${o}(int row, int col, int depth, int depth2) {
1325
1529
  // Explicitly use integer operations as dot() only works on floats.
1326
- ${x}
1530
+ ${h}
1327
1531
  ${p}
1328
- ${$}
1532
+ ${m}
1329
1533
  int index = row * stride0 + col * stride1 +
1330
1534
  depth * stride2 + depth2;
1331
1535
  vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index + ${S});
@@ -1334,21 +1538,21 @@ function lt(e, t) {
1334
1538
  ` : `
1335
1539
  float ${o}(int row, int col, int depth, int depth2) {
1336
1540
  // Explicitly use integer operations as dot() only works on floats.
1337
- int index = row * ${s} + col * ${a} +
1338
- depth * ${i} + depth2;
1339
- vec2 uv = uvFromFlat(${d}, ${h}, index + ${S});
1541
+ int index = row * ${c} + col * ${i} +
1542
+ depth * ${a} + depth2;
1543
+ vec2 uv = uvFromFlat(${d}, ${x}, index + ${S});
1340
1544
  return sampleTexture(${r}, uv);
1341
1545
  }
1342
1546
  `;
1343
1547
  }
1344
- function ft(e) {
1345
- const t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = t[4], i = t[3] * o, a = t[2] * i, s = t[1] * a, { newShape: c, keptDims: u } = I(t);
1346
- if (c.length < t.length) {
1347
- const p = y(e, c), $ = ["row", "col", "depth", "depth2", "depth3"];
1548
+ function nt(e) {
1549
+ const t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = t[4], a = t[3] * o, i = t[2] * a, c = t[1] * i, { newShape: s, keptDims: l } = N(t);
1550
+ if (s.length < t.length) {
1551
+ const p = g(e, s), m = ["row", "col", "depth", "depth2", "depth3"];
1348
1552
  return `
1349
- ${b(p)}
1553
+ ${U(p)}
1350
1554
  float ${r}(int row, int col, int depth, int depth2, int depth3) {
1351
- return ${r}(${M($, u)});
1555
+ return ${r}(${b(m, l)});
1352
1556
  }
1353
1557
  `;
1354
1558
  }
@@ -1357,24 +1561,24 @@ function ft(e) {
1357
1561
  float ${r}(int row, int col, int depth, int depth2, int depth3) {
1358
1562
  float index = dot(
1359
1563
  vec4(row, col, depth, depth2),
1360
- vec4(${s}, ${a}, ${i}, ${o})) +
1564
+ vec4(${c}, ${i}, ${a}, ${o})) +
1361
1565
  depth3;
1362
1566
  ${D(e)}
1363
1567
  }
1364
1568
  `;
1365
- const l = e.shapeInfo.flatOffset, f = e.shapeInfo.texShape, d = f[0], h = f[1];
1366
- if (h === s && l == null)
1569
+ const u = e.shapeInfo.flatOffset, f = e.shapeInfo.texShape, d = f[0], x = f[1];
1570
+ if (x === c && u == null)
1367
1571
  return `
1368
1572
  float ${r}(int row, int col, int depth, int depth2, int depth3) {
1369
1573
  int texR = row;
1370
1574
  float texC = dot(vec4(col, depth, depth2, depth3),
1371
- vec4(${a}, ${i}, ${o}, 1));
1575
+ vec4(${i}, ${a}, ${o}, 1));
1372
1576
  vec2 uv = (vec2(texC, texR) + halfCR) /
1373
- vec2(${h}.0, ${d}.0);
1577
+ vec2(${x}.0, ${d}.0);
1374
1578
  return sampleTexture(${n}, uv);
1375
1579
  }
1376
1580
  `;
1377
- if (h === o && l == null)
1581
+ if (x === o && u == null)
1378
1582
  return `
1379
1583
  float ${r}(int row, int col, int depth, int depth2, int depth3) {
1380
1584
  float texR = dot(
@@ -1383,62 +1587,62 @@ function ft(e) {
1383
1587
  ${t[2] * t[3]}, ${t[3]}, 1));
1384
1588
  int texC = depth3;
1385
1589
  vec2 uv = (vec2(texC, texR) + halfCR) /
1386
- vec2(${h}.0, ${d}.0);
1590
+ vec2(${x}.0, ${d}.0);
1387
1591
  return sampleTexture(${n}, uv);
1388
1592
  }
1389
1593
  `;
1390
- const x = U(n);
1594
+ const h = O(n);
1391
1595
  return `
1392
1596
  float ${r}(int row, int col, int depth, int depth2, int depth3) {
1393
1597
  // Explicitly use integer operations as dot() only works on floats.
1394
- int index = row * ${s} + col * ${a} + depth * ${i} +
1395
- depth2 * ${o} + depth3 + ${x};
1396
- vec2 uv = uvFromFlat(${d}, ${h}, index);
1598
+ int index = row * ${c} + col * ${i} + depth * ${a} +
1599
+ depth2 * ${o} + depth3 + ${h};
1600
+ vec2 uv = uvFromFlat(${d}, ${x}, index);
1397
1601
  return sampleTexture(${n}, uv);
1398
1602
  }
1399
1603
  `;
1400
1604
  }
1401
- function ht(e) {
1402
- const t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), { newShape: o, keptDims: i } = I(t);
1605
+ function rt(e) {
1606
+ const t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), { newShape: o, keptDims: a } = N(t);
1403
1607
  if (o.length < t.length) {
1404
- const $ = y(e, o), S = ["row", "col", "depth", "depth2", "depth3", "depth4"];
1608
+ const m = g(e, o), S = ["row", "col", "depth", "depth2", "depth3", "depth4"];
1405
1609
  return `
1406
- ${b($)}
1610
+ ${U(m)}
1407
1611
  float ${r}(int row, int col, int depth,
1408
1612
  int depth2, int depth3, int depth4) {
1409
- return ${r}(${M(S, i)});
1613
+ return ${r}(${b(S, a)});
1410
1614
  }
1411
1615
  `;
1412
1616
  }
1413
- const a = t[5], s = t[4] * a, c = t[3] * s, u = t[2] * c, l = t[1] * u;
1617
+ const i = t[5], c = t[4] * i, s = t[3] * c, l = t[2] * s, u = t[1] * l;
1414
1618
  if (e.shapeInfo.isUniform)
1415
1619
  return `
1416
1620
  float ${r}(int row, int col, int depth,
1417
1621
  int depth2, int depth3, int depth4) {
1418
1622
  int index = round(dot(
1419
1623
  vec4(row, col, depth, depth2),
1420
- vec4(${l}, ${u}, ${c}, ${s})) +
1624
+ vec4(${u}, ${l}, ${s}, ${c})) +
1421
1625
  dot(
1422
1626
  vec2(depth3, depth4),
1423
- vec2(${a}, 1)));
1627
+ vec2(${i}, 1)));
1424
1628
  ${D(e)}
1425
1629
  }
1426
1630
  `;
1427
- const f = e.shapeInfo.flatOffset, d = e.shapeInfo.texShape, h = d[0], x = d[1];
1428
- if (x === l && f == null)
1631
+ const f = e.shapeInfo.flatOffset, d = e.shapeInfo.texShape, x = d[0], h = d[1];
1632
+ if (h === u && f == null)
1429
1633
  return `
1430
1634
  float ${r}(int row, int col, int depth,
1431
1635
  int depth2, int depth3, int depth4) {
1432
1636
  int texR = row;
1433
1637
  float texC = dot(vec4(col, depth, depth2, depth3),
1434
- vec4(${u}, ${c}, ${s}, ${a})) +
1638
+ vec4(${l}, ${s}, ${c}, ${i})) +
1435
1639
  float(depth4);
1436
1640
  vec2 uv = (vec2(texC, texR) + halfCR) /
1437
- vec2(${x}.0, ${h}.0);
1641
+ vec2(${h}.0, ${x}.0);
1438
1642
  return sampleTexture(${n}, uv);
1439
1643
  }
1440
1644
  `;
1441
- if (x === a && f == null)
1645
+ if (h === i && f == null)
1442
1646
  return `
1443
1647
  float ${r}(int row, int col, int depth,
1444
1648
  int depth2, int depth3, int depth4) {
@@ -1449,18 +1653,18 @@ function ht(e) {
1449
1653
  ${t[4]})) + float(depth3);
1450
1654
  int texC = depth4;
1451
1655
  vec2 uv = (vec2(texC, texR) + halfCR) /
1452
- vec2(${x}.0, ${h}.0);
1656
+ vec2(${h}.0, ${x}.0);
1453
1657
  return sampleTexture(${n}, uv);
1454
1658
  }
1455
1659
  `;
1456
- const p = U(n);
1660
+ const p = O(n);
1457
1661
  return `
1458
1662
  float ${r}(int row, int col, int depth,
1459
1663
  int depth2, int depth3, int depth4) {
1460
1664
  // Explicitly use integer operations as dot() only works on floats.
1461
- int index = row * ${l} + col * ${u} + depth * ${c} +
1462
- depth2 * ${s} + depth3 * ${a} + depth4 + ${p};
1463
- vec2 uv = uvFromFlat(${h}, ${x}, index);
1665
+ int index = row * ${u} + col * ${l} + depth * ${s} +
1666
+ depth2 * ${c} + depth3 * ${i} + depth4 + ${p};
1667
+ vec2 uv = uvFromFlat(${x}, ${h}, index);
1464
1668
  return sampleTexture(${n}, uv);
1465
1669
  }
1466
1670
  `;
@@ -1475,62 +1679,62 @@ function D(e) {
1475
1679
  }
1476
1680
  `;
1477
1681
  }
1478
- function dt(e, t) {
1479
- const n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), o = "get" + r + "AtOutCoords", i = e.shapeInfo.logicalShape.length, a = t.logicalShape.length, s = ue(e.shapeInfo.logicalShape, t.logicalShape), c = he(a), u = a - i;
1480
- let l;
1682
+ function ot(e, t) {
1683
+ const n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), o = "get" + r + "AtOutCoords", a = e.shapeInfo.logicalShape.length, i = t.logicalShape.length, c = ee(e.shapeInfo.logicalShape, t.logicalShape), s = re(i), l = i - a;
1684
+ let u;
1481
1685
  const f = ["x", "y", "z", "w", "u", "v"];
1482
- i === 0 ? l = "" : a < 2 && s.length >= 1 ? l = "coords = 0;" : l = s.map((R) => `coords.${f[R + u]} = 0;`).join(`
1686
+ a === 0 ? u = "" : i < 2 && c.length >= 1 ? u = "coords = 0;" : u = c.map((R) => `coords.${f[R + l]} = 0;`).join(`
1483
1687
  `);
1484
1688
  let d = "";
1485
- a < 2 && i > 0 ? d = "coords" : d = e.shapeInfo.logicalShape.map((R, w) => `coords.${f[w + u]}`).join(", ");
1486
- let h = "return outputValue;";
1689
+ i < 2 && a > 0 ? d = "coords" : d = e.shapeInfo.logicalShape.map((R, F) => `coords.${f[F + l]}`).join(", ");
1690
+ let x = "return outputValue;";
1487
1691
  const p = E(e.shapeInfo.logicalShape) === 1, S = E(t.logicalShape) === 1;
1488
- if (i === 1 && !p && !S)
1489
- h = `
1692
+ if (a === 1 && !p && !S)
1693
+ x = `
1490
1694
  return vec4(outputValue.xy, outputValue.xy);
1491
1695
  `;
1492
1696
  else if (p && !S)
1493
- a === 1 ? h = `
1697
+ i === 1 ? x = `
1494
1698
  return vec4(outputValue.x, outputValue.x, 0., 0.);
1495
- ` : h = `
1699
+ ` : x = `
1496
1700
  return vec4(outputValue.x);
1497
1701
  `;
1498
- else if (s.length) {
1499
- const R = i - 2, w = i - 1;
1500
- s.indexOf(R) > -1 && s.indexOf(w) > -1 ? h = "return vec4(outputValue.x);" : s.indexOf(R) > -1 ? h = "return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);" : s.indexOf(w) > -1 && (h = "return vec4(outputValue.xx, outputValue.zz);");
1702
+ else if (c.length) {
1703
+ const R = a - 2, F = a - 1;
1704
+ c.indexOf(R) > -1 && c.indexOf(F) > -1 ? x = "return vec4(outputValue.x);" : c.indexOf(R) > -1 ? x = "return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);" : c.indexOf(F) > -1 && (x = "return vec4(outputValue.xx, outputValue.zz);");
1501
1705
  }
1502
1706
  return `
1503
1707
  vec4 ${o}() {
1504
- ${c} coords = getOutputCoords();
1505
- ${l}
1708
+ ${s} coords = getOutputCoords();
1709
+ ${u}
1506
1710
  vec4 outputValue = get${r}(${d});
1507
- ${h}
1711
+ ${x}
1508
1712
  }
1509
1713
  `;
1510
1714
  }
1511
- function xt(e, t) {
1512
- const n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), o = "get" + r + "AtOutCoords", i = t.texShape, a = e.shapeInfo.texShape, s = e.shapeInfo.logicalShape.length, c = t.logicalShape.length;
1513
- if (!e.shapeInfo.isUniform && s === c && e.shapeInfo.flatOffset == null && T(a, i))
1715
+ function at(e, t) {
1716
+ const n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), o = "get" + r + "AtOutCoords", a = t.texShape, i = e.shapeInfo.texShape, c = e.shapeInfo.logicalShape.length, s = t.logicalShape.length;
1717
+ if (!e.shapeInfo.isUniform && c === s && e.shapeInfo.flatOffset == null && T(i, a))
1514
1718
  return `
1515
1719
  float ${o}() {
1516
1720
  return sampleTexture(${n}, resultUV);
1517
1721
  }
1518
1722
  `;
1519
- const u = he(c), l = ue(e.shapeInfo.logicalShape, t.logicalShape), f = c - s;
1723
+ const l = re(s), u = ee(e.shapeInfo.logicalShape, t.logicalShape), f = s - c;
1520
1724
  let d;
1521
- const h = ["x", "y", "z", "w", "u", "v"];
1522
- s === 0 ? d = "" : c < 2 && l.length >= 1 ? d = "coords = 0;" : d = l.map((p) => `coords.${h[p + f]} = 0;`).join(`
1725
+ const x = ["x", "y", "z", "w", "u", "v"];
1726
+ c === 0 ? d = "" : s < 2 && u.length >= 1 ? d = "coords = 0;" : d = u.map((p) => `coords.${x[p + f]} = 0;`).join(`
1523
1727
  `);
1524
- let x = "";
1525
- return c < 2 && s > 0 ? x = "coords" : x = e.shapeInfo.logicalShape.map((p, $) => `coords.${h[$ + f]}`).join(", "), `
1728
+ let h = "";
1729
+ return s < 2 && c > 0 ? h = "coords" : h = e.shapeInfo.logicalShape.map((p, m) => `coords.${x[m + f]}`).join(", "), `
1526
1730
  float ${o}() {
1527
- ${u} coords = getOutputCoords();
1731
+ ${l} coords = getOutputCoords();
1528
1732
  ${d}
1529
- return get${r}(${x});
1733
+ return get${r}(${h});
1530
1734
  }
1531
1735
  `;
1532
1736
  }
1533
- function he(e) {
1737
+ function re(e) {
1534
1738
  if (e <= 1)
1535
1739
  return "int";
1536
1740
  if (e === 2)
@@ -1545,419 +1749,41 @@ function he(e) {
1545
1749
  return "ivec6";
1546
1750
  throw Error(`GPU for rank ${e} is not yet supported`);
1547
1751
  }
1548
- function j(e, t, n) {
1549
- const { newShape: r, keptDims: o } = I(t), i = t.length, a = e && i === 3 && t[0] === 1, s = a ? t.slice(1) : r, c = !e && i > 1 && !T(t, n) && r.length < i || a;
1550
- return { useSqueezeShape: c, uniformShape: c ? s : t, keptDims: o };
1752
+ function z(e, t, n) {
1753
+ const { newShape: r, keptDims: o } = N(t), a = t.length, i = e && a === 3 && t[0] === 1, c = i ? t.slice(1) : r, s = !e && a > 1 && !T(t, n) && r.length < a || i;
1754
+ return { useSqueezeShape: s, uniformShape: s ? c : t, keptDims: o };
1551
1755
  }
1552
- function y(e, t) {
1756
+ function g(e, t) {
1553
1757
  const n = JSON.parse(JSON.stringify(e));
1554
1758
  return n.shapeInfo.logicalShape = t, n;
1555
1759
  }
1556
- function M(e, t) {
1760
+ function b(e, t) {
1557
1761
  return t.map((n) => e[n]).join(", ");
1558
1762
  }
1559
- const A = {}, k = {
1560
- alpha: !1,
1561
- antialias: !1,
1562
- premultipliedAlpha: !1,
1563
- preserveDrawingBuffer: !1,
1564
- depth: !1,
1565
- stencil: !1,
1566
- failIfMajorPerformanceCaveat: !0
1567
- };
1568
- function Bt(e, t) {
1569
- A[e] = t;
1570
- }
1571
- function _(e, t) {
1572
- if (!(e in A) || t != null) {
1573
- const r = vt(e, t);
1574
- if (r !== null)
1575
- A[e] = r;
1576
- else
1577
- return console.log("Could not get context for WebGL version", e), null;
1578
- }
1579
- const n = A[e];
1580
- return n == null || n.isContextLost() ? (delete A[e], _(e)) : (n.disable(n.DEPTH_TEST), n.disable(n.STENCIL_TEST), n.disable(n.BLEND), n.disable(n.DITHER), n.disable(n.POLYGON_OFFSET_FILL), n.disable(n.SAMPLE_COVERAGE), n.enable(n.SCISSOR_TEST), n.enable(n.CULL_FACE), n.cullFace(n.BACK), A[e]);
1581
- }
1582
- function pt(e) {
1583
- if (!v().getBool("IS_SAFARI") && typeof OffscreenCanvas < "u" && e === 2)
1584
- return new OffscreenCanvas(300, 150);
1585
- if (typeof document < "u")
1586
- return document.createElement("canvas");
1587
- throw new Error("Cannot create a canvas in this context");
1588
- }
1589
- function vt(e, t) {
1590
- if (e !== 1 && e !== 2)
1591
- throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");
1592
- const n = t ?? pt(e);
1593
- return n.addEventListener("webglcontextlost", (r) => {
1594
- r.preventDefault(), delete A[e];
1595
- }, !1), v().getBool("SOFTWARE_WEBGL_ENABLED") && (k.failIfMajorPerformanceCaveat = !1), e === 1 ? (
1596
- // tslint:disable-next-line
1597
- n.getContext("webgl", k) || n.getContext("experimental-webgl", k)
1598
- ) : n.getContext("webgl2", k);
1599
- }
1600
- var ee;
1601
- (function(e) {
1602
- e[e.DENSE = 0] = "DENSE", e[e.SHARED_BATCH = 1] = "SHARED_BATCH";
1603
- })(ee || (ee = {}));
1604
- var te;
1605
- (function(e) {
1606
- e[e.RENDER = 0] = "RENDER", e[e.UPLOAD = 1] = "UPLOAD", e[e.PIXELS = 2] = "PIXELS", e[e.DOWNLOAD = 3] = "DOWNLOAD";
1607
- })(te || (te = {}));
1608
- var ne;
1609
- (function(e) {
1610
- e[e.UNPACKED_FLOAT16 = 0] = "UNPACKED_FLOAT16", e[e.UNPACKED_FLOAT32 = 1] = "UNPACKED_FLOAT32", e[e.PACKED_4X1_UNSIGNED_BYTE = 2] = "PACKED_4X1_UNSIGNED_BYTE", e[e.PACKED_2X2_FLOAT32 = 3] = "PACKED_2X2_FLOAT32", e[e.PACKED_2X2_FLOAT16 = 4] = "PACKED_2X2_FLOAT16";
1611
- })(ne || (ne = {}));
1612
- function kt(e, t) {
1613
- return [t, e];
1614
- }
1615
- function Pt(e, t) {
1616
- return e * t;
1617
- }
1618
- function Vt(e) {
1619
- const t = E(e), n = Math.ceil(t / 4);
1620
- return H(n);
1621
- }
1622
- function mt(e, t) {
1623
- return [
1624
- Math.max(1, Math.ceil(t / 2)),
1625
- Math.max(1, Math.ceil(e / 2))
1626
- ];
1627
- }
1628
- function Wt(e, t) {
1629
- const [n, r] = mt(e, t);
1630
- return n * r * 4;
1631
- }
1632
- function de(e, t) {
1633
- const n = e;
1634
- let r, o, i, a, s, c, u, l, f, d;
1635
- return v().getNumber("WEBGL_VERSION") === 2 ? (r = n.R32F, o = n.R16F, i = n.RGBA16F, a = n.RGBA32F, s = n.RED, u = 4, l = 1, f = n.HALF_FLOAT, d = n.FLOAT, c = n.RGBA8) : (r = e.RGBA, o = e.RGBA, i = e.RGBA, a = n.RGBA, s = e.RGBA, u = 4, l = 4, f = t != null ? t.HALF_FLOAT_OES : null, d = e.FLOAT, c = e.RGBA), {
1636
- internalFormatFloat: r,
1637
- internalFormatHalfFloat: o,
1638
- internalFormatPackedHalfFloat: i,
1639
- internalFormatPackedFloat: a,
1640
- textureFormatFloat: s,
1641
- downloadTextureFormat: c,
1642
- downloadUnpackNumChannels: u,
1643
- defaultNumChannels: l,
1644
- textureTypeHalfFloat: f,
1645
- textureTypeFloat: d
1646
- };
1647
- }
1648
- function m(e, t) {
1649
- const n = t();
1650
- return v().getBool("DEBUG") && $t(e), n;
1651
- }
1652
- function $t(e) {
1653
- const t = e.getError();
1654
- if (t !== e.NO_ERROR)
1655
- throw new Error("WebGL Error: " + Rt(e, t));
1656
- }
1657
- const Tt = 596e-10, St = 65504;
1658
- function Xt(e) {
1659
- return !!(v().getBool("WEBGL_RENDER_FLOAT32_ENABLED") || e === 0 || Tt < Math.abs(e) && Math.abs(e) < St);
1660
- }
1661
- function Rt(e, t) {
1662
- switch (t) {
1663
- case e.NO_ERROR:
1664
- return "NO_ERROR";
1665
- case e.INVALID_ENUM:
1666
- return "INVALID_ENUM";
1667
- case e.INVALID_VALUE:
1668
- return "INVALID_VALUE";
1669
- case e.INVALID_OPERATION:
1670
- return "INVALID_OPERATION";
1671
- case e.INVALID_FRAMEBUFFER_OPERATION:
1672
- return "INVALID_FRAMEBUFFER_OPERATION";
1673
- case e.OUT_OF_MEMORY:
1674
- return "OUT_OF_MEMORY";
1675
- case e.CONTEXT_LOST_WEBGL:
1676
- return "CONTEXT_LOST_WEBGL";
1677
- default:
1678
- return `Unknown error code ${t}`;
1679
- }
1680
- }
1681
- function Ht(e, t) {
1682
- return C(e, () => e.getExtension(t), 'Extension "' + t + '" not supported on this browser.');
1683
- }
1684
- function Gt(e, t) {
1685
- const n = C(e, () => e.createShader(e.VERTEX_SHADER), "Unable to create vertex WebGLShader.");
1686
- if (m(e, () => e.shaderSource(n, t)), m(e, () => e.compileShader(n)), e.getShaderParameter(n, e.COMPILE_STATUS) === !1)
1687
- throw console.log(e.getShaderInfoLog(n)), new Error("Failed to compile vertex shader.");
1688
- return n;
1689
- }
1690
- function Et(e, t) {
1691
- const n = C(e, () => e.createShader(e.FRAGMENT_SHADER), "Unable to create fragment WebGLShader.");
1692
- if (m(e, () => e.shaderSource(n, t)), m(e, () => e.compileShader(n)), v().get("ENGINE_COMPILE_ONLY"))
1693
- return n;
1694
- if (e.getShaderParameter(n, e.COMPILE_STATUS) === !1)
1695
- throw wt(t, e.getShaderInfoLog(n)), new Error("Failed to compile fragment shader.");
1696
- return n;
1697
- }
1698
- const Ct = /ERROR: [0-9]+:([0-9]+):/g;
1699
- function wt(e, t) {
1700
- const n = Ct.exec(t);
1701
- if (n == null) {
1702
- console.log(`Couldn't parse line number in error: ${t}`), console.log(e);
1703
- return;
1704
- }
1705
- const r = +n[1], o = e.split(`
1706
- `), i = o.length.toString().length + 2, a = o.map((f, d) => Y((d + 1).toString(), i) + f);
1707
- let s = 0;
1708
- for (let f = 0; f < a.length; f++)
1709
- s = Math.max(a[f].length, s);
1710
- const c = a.slice(0, r - 1), u = a.slice(r - 1, r), l = a.slice(r);
1711
- console.log(c.join(`
1712
- `)), console.log(t.split(`
1713
- `)[0]), console.log(`%c ${Y(u[0], s)}`, "border:1px solid red; background-color:#e3d2d2; color:#a61717"), console.log(l.join(`
1714
- `));
1715
- }
1716
- function zt(e) {
1717
- return C(e, () => e.createProgram(), "Unable to create WebGLProgram.");
1718
- }
1719
- function qt(e, t) {
1720
- if (m(e, () => e.linkProgram(t)), !v().get("ENGINE_COMPILE_ONLY") && e.getProgramParameter(t, e.LINK_STATUS) === !1)
1721
- throw console.log(e.getProgramInfoLog(t)), new Error("Failed to link vertex and fragment shaders.");
1722
- }
1723
- function jt(e, t) {
1724
- if (m(e, () => e.validateProgram(t)), e.getProgramParameter(t, e.VALIDATE_STATUS) === !1)
1725
- throw console.log(e.getProgramInfoLog(t)), new Error("Shader program validation failed.");
1726
- }
1727
- function Jt(e, t) {
1728
- const n = C(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
1729
- return m(e, () => e.bindBuffer(e.ARRAY_BUFFER, n)), m(e, () => e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
1730
- }
1731
- function Yt(e, t) {
1732
- const n = C(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
1733
- return m(e, () => e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, n)), m(e, () => e.bufferData(e.ELEMENT_ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
1734
- }
1735
- function Kt(e) {
1736
- return C(e, () => e.createTexture(), "Unable to create WebGLTexture.");
1737
- }
1738
- function Zt(e, t) {
1739
- const n = v().getNumber("WEBGL_MAX_TEXTURE_SIZE");
1740
- if (e <= 0 || t <= 0) {
1741
- const r = `[${e}x${t}]`;
1742
- throw new Error("Requested texture size " + r + " is invalid.");
1743
- }
1744
- if (e > n || t > n) {
1745
- const r = `[${e}x${t}]`, o = `[${n}x${n}]`;
1746
- throw new Error("Requested texture size " + r + " greater than WebGL maximum on this browser / GPU " + o + ".");
1747
- }
1748
- }
1749
- function Qt(e) {
1750
- return C(e, () => e.createFramebuffer(), "Unable to create WebGLFramebuffer.");
1751
- }
1752
- function en(e, t, n, r, o, i, a) {
1753
- const s = e.getAttribLocation(t, n);
1754
- return s === -1 ? !1 : (m(e, () => e.bindBuffer(e.ARRAY_BUFFER, r)), m(e, () => e.vertexAttribPointer(s, o, e.FLOAT, !1, i, a)), m(e, () => e.enableVertexAttribArray(s)), !0);
1755
- }
1756
- function Ft(e, t, n) {
1757
- _t(e, n), m(e, () => e.activeTexture(e.TEXTURE0 + n)), m(e, () => e.bindTexture(e.TEXTURE_2D, t));
1758
- }
1759
- function tn(e, t, n) {
1760
- return C(e, () => e.getUniformLocation(t, n), 'uniform "' + n + '" not present in program.');
1761
- }
1762
- function nn(e, t, n) {
1763
- return e.getUniformLocation(t, n);
1764
- }
1765
- function rn(e, t, n, r) {
1766
- m(e, () => Ft(e, t, r)), m(e, () => e.uniform1i(n, r));
1767
- }
1768
- function on(e, t, n) {
1769
- m(e, () => e.bindFramebuffer(e.FRAMEBUFFER, n)), m(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, t, 0));
1770
- }
1771
- function an(e, t) {
1772
- m(e, () => e.bindFramebuffer(e.FRAMEBUFFER, t)), m(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, null, 0));
1773
- }
1774
- function cn(e) {
1775
- const t = e.checkFramebufferStatus(e.FRAMEBUFFER);
1776
- if (t !== e.FRAMEBUFFER_COMPLETE)
1777
- throw new Error("Error binding framebuffer: " + gt(e, t));
1778
- }
1779
- function gt(e, t) {
1780
- switch (t) {
1781
- case e.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
1782
- return "FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
1783
- case e.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
1784
- return "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
1785
- case e.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
1786
- return "FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
1787
- case e.FRAMEBUFFER_UNSUPPORTED:
1788
- return "FRAMEBUFFER_UNSUPPORTED";
1789
- default:
1790
- return `unknown error ${t}`;
1791
- }
1792
- }
1793
- function C(e, t, n) {
1794
- const r = m(e, () => t());
1795
- if (r == null)
1796
- throw new Error(n);
1797
- return r;
1798
- }
1799
- function _t(e, t) {
1800
- const n = e.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1, r = t + e.TEXTURE0;
1801
- if (r < e.TEXTURE0 || r > n) {
1802
- const o = `[gl.TEXTURE0, gl.TEXTURE${n}]`;
1803
- throw new Error(`textureUnit must be in ${o}.`);
1804
- }
1805
- }
1806
- function xe(e, t = 2) {
1807
- return E(e.slice(0, e.length - t));
1808
- }
1809
- function pe(e) {
1810
- if (e.length === 0)
1811
- throw Error("Cannot get rows and columns of an empty shape array.");
1812
- return [
1813
- e.length > 1 ? e[e.length - 2] : 1,
1814
- e[e.length - 1]
1815
- ];
1816
- }
1817
- function sn(e) {
1818
- let t = [1, 1, 1];
1819
- return e.length === 0 || e.length === 1 && e[0] === 1 || (t = [xe(e), ...pe(e)]), t;
1820
- }
1821
- function un(e, t = !1) {
1822
- let n = v().getNumber("WEBGL_MAX_TEXTURE_SIZE"), r = v().getNumber("WEBGL_MAX_SIZE_FOR_NARROW_TEXTURE");
1823
- r === 1 / 0 && v().getBool("WEBGL_AUTO_SQUARIFY_NARROW_TEXTURE_SHAPE") && (r = n / 2), t && (n = n * 2, r = r * 2, e = e.map((s, c) => c >= e.length - 2 ? Te(e[c]) : e[c]), e.length === 1 && (e = [2, e[0]])), e.length !== 2 && (e = I(e).newShape);
1824
- let o = E(e), i = null;
1825
- e.length <= 1 && o <= n ? i = [1, o] : e.length === 2 && e[0] <= n && e[1] <= n ? i = e : e.length === 3 && e[0] * e[1] <= n && e[2] <= n ? i = [e[0] * e[1], e[2]] : e.length === 3 && e[0] <= n && e[1] * e[2] <= n ? i = [e[0], e[1] * e[2]] : e.length === 4 && e[0] * e[1] * e[2] <= n && e[3] <= n ? i = [e[0] * e[1] * e[2], e[3]] : e.length === 4 && e[0] <= n && e[1] * e[2] * e[3] <= n && (i = [e[0], e[1] * e[2] * e[3]]);
1826
- const a = i != null && Math.max(...i) > r && Math.min(...i) <= (t ? 2 : 1) && Math.min(...i) > 0;
1827
- if (i == null || a)
1828
- if (t) {
1829
- const s = xe(e);
1830
- let c = 2, u = 2;
1831
- e.length && ([c, u] = pe(e)), o = s * (c / 2) * (u / 2), i = H(o).map((l) => l * 2);
1832
- } else
1833
- i = H(o);
1834
- return i;
1835
- }
1836
- function P(e) {
1837
- return e % 2 === 0;
1838
- }
1839
- function ln(e, t) {
1840
- if (e = e.slice(-2), t = t.slice(-2), T(e, t) || !e.length || !t.length || e[0] === 0 || e[1] === 0 || t[0] === 0 || t[1] === 0)
1841
- return !0;
1842
- if (e.length !== t.length) {
1843
- const n = e[e.length - 1], r = t[t.length - 1];
1844
- if (n === r || P(n) && P(r) && (e[0] === 1 || t[0] === 1))
1845
- return !0;
1846
- }
1847
- return e[1] === t[1] && P(e[0]) && P(t[0]);
1848
- }
1849
- let W, X;
1850
- function fn(e) {
1851
- if (W == null) {
1852
- const t = _(e);
1853
- W = t.getParameter(t.MAX_TEXTURE_SIZE);
1854
- }
1855
- return W;
1856
- }
1857
- function hn(e) {
1858
- if (X == null) {
1859
- const t = _(e);
1860
- X = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);
1861
- }
1862
- return Math.min(16, X);
1863
- }
1864
- function dn(e) {
1865
- if (e === 0)
1866
- return 0;
1867
- let t;
1868
- const n = _(e);
1869
- return g(n, "EXT_disjoint_timer_query_webgl2") && e === 2 ? t = 2 : g(n, "EXT_disjoint_timer_query") ? t = 1 : t = 0, t;
1870
- }
1871
- function g(e, t) {
1872
- return e.getExtension(t) != null;
1873
- }
1874
- function xn(e) {
1875
- try {
1876
- if (_(e) != null)
1877
- return !0;
1878
- } catch (t) {
1879
- return console.log("Error when getting WebGL context: ", t), !1;
1880
- }
1881
- return !1;
1882
- }
1883
- function pn(e) {
1884
- if (e === 0)
1885
- return !1;
1886
- const t = _(e);
1887
- if (e === 1) {
1888
- if (!g(t, "OES_texture_float"))
1889
- return !1;
1890
- } else if (!g(t, "EXT_color_buffer_float"))
1891
- return !1;
1892
- return G(t);
1893
- }
1894
- function vn(e) {
1895
- if (e === 0)
1896
- return !1;
1897
- const t = _(e);
1898
- if (e === 1) {
1899
- if (!g(t, "OES_texture_float") || !g(t, "WEBGL_color_buffer_float"))
1900
- return !1;
1901
- } else {
1902
- if (g(t, "EXT_color_buffer_float"))
1903
- return G(t);
1904
- const r = "EXT_color_buffer_half_float";
1905
- if (g(t, r)) {
1906
- const o = t.getExtension(r);
1907
- return At(t, o);
1908
- }
1909
- return !1;
1910
- }
1911
- return G(t);
1912
- }
1913
- function G(e) {
1914
- const t = de(e), n = e.createTexture();
1915
- e.bindTexture(e.TEXTURE_2D, n), e.texImage2D(e.TEXTURE_2D, 0, t.internalFormatFloat, 1, 1, 0, t.textureFormatFloat, t.textureTypeFloat, null);
1916
- const i = e.createFramebuffer();
1917
- e.bindFramebuffer(e.FRAMEBUFFER, i), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, n, 0);
1918
- const a = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
1919
- return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(n), e.deleteFramebuffer(i), a;
1920
- }
1921
- function At(e, t) {
1922
- const n = de(e, t), r = e.createTexture();
1923
- e.bindTexture(e.TEXTURE_2D, r), e.texImage2D(e.TEXTURE_2D, 0, n.internalFormatHalfFloat, 1, 1, 0, n.textureFormatFloat, n.textureTypeHalfFloat, null);
1924
- const a = e.createFramebuffer();
1925
- e.bindFramebuffer(e.FRAMEBUFFER, a), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, r, 0);
1926
- const s = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
1927
- return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(r), e.deleteFramebuffer(a), s;
1928
- }
1929
- function mn(e) {
1930
- return e !== 2 ? !1 : _(e).fenceSync != null;
1931
- }
1932
- function $n(e, t) {
1933
- Array.isArray(e) || (e = [e]), e.forEach((n) => {
1934
- n != null && F(n.dtype !== "complex64", () => `${t} does not support complex64 tensors in the WebGL backend.`);
1935
- });
1936
- }
1937
- function Tn(e, t, n, r) {
1938
- const o = n.map((l, f) => {
1763
+ function qt(e, t, n, r) {
1764
+ const o = n.map((u, f) => {
1939
1765
  const d = {
1940
- logicalShape: l.shape,
1941
- texShape: l.isUniform ? null : l.texData.texShape,
1942
- isUniform: l.isUniform,
1943
- isPacked: l.isUniform ? !1 : l.texData.isPacked,
1766
+ logicalShape: u.shape,
1767
+ texShape: u.isUniform ? null : u.texData.texShape,
1768
+ isUniform: u.isUniform,
1769
+ isPacked: u.isUniform ? !1 : u.texData.isPacked,
1944
1770
  flatOffset: null
1945
1771
  };
1946
- return l.texData != null && l.texData.slice != null && l.texData.slice.flatOffset > 0 && (d.flatOffset = l.texData.slice.flatOffset), { name: t.variableNames[f], shapeInfo: d };
1947
- }), i = o.map((l) => l.shapeInfo), a = {
1772
+ return u.texData != null && u.texData.slice != null && u.texData.slice.flatOffset > 0 && (d.flatOffset = u.texData.slice.flatOffset), { name: t.variableNames[f], shapeInfo: d };
1773
+ }), a = o.map((u) => u.shapeInfo), i = {
1948
1774
  logicalShape: r.shape,
1949
1775
  texShape: r.texData.texShape,
1950
1776
  isUniform: !1,
1951
1777
  isPacked: r.texData.isPacked,
1952
1778
  flatOffset: null
1953
- }, s = Le(o, a, t), c = Et(e.gl, s), u = e.createProgram(c);
1954
- return v().get("ENGINE_COMPILE_ONLY") ? {
1779
+ }, c = Fe(o, i, t), s = ve(e.gl, c), l = e.createProgram(s);
1780
+ return $().get("ENGINE_COMPILE_ONLY") ? {
1955
1781
  program: t,
1956
- fragmentShader: c,
1957
- source: s,
1958
- webGLProgram: u,
1959
- inShapeInfos: i,
1960
- outShapeInfo: a,
1782
+ fragmentShader: s,
1783
+ source: c,
1784
+ webGLProgram: l,
1785
+ inShapeInfos: a,
1786
+ outShapeInfo: i,
1961
1787
  variablesLocations: null,
1962
1788
  customUniformLocations: null,
1963
1789
  infLoc: null,
@@ -1965,232 +1791,232 @@ function Tn(e, t, n, r) {
1965
1791
  outShapeLocation: null,
1966
1792
  outShapeStridesLocation: null,
1967
1793
  outTexShapeLocation: null
1968
- } : (e.buildVao(u), Object.assign({
1794
+ } : (e.buildVao(l), Object.assign({
1969
1795
  program: t,
1970
- fragmentShader: c,
1971
- source: s,
1972
- webGLProgram: u,
1973
- inShapeInfos: i,
1974
- outShapeInfo: a
1975
- }, Nt(e, t, u)));
1976
- }
1977
- function Nt(e, t, n) {
1796
+ fragmentShader: s,
1797
+ source: c,
1798
+ webGLProgram: l,
1799
+ inShapeInfos: a,
1800
+ outShapeInfo: i
1801
+ }, it(e, t, l)));
1802
+ }
1803
+ function it(e, t, n) {
1978
1804
  const r = [], o = [];
1979
- let i, a, s, c = null, u = null;
1980
- u = e.getUniformLocation(n, "NAN", !1), v().getNumber("WEBGL_VERSION") === 1 && (c = e.getUniformLocation(n, "INFINITY", !1));
1981
- const l = !1;
1805
+ let a, i, c, s = null, l = null;
1806
+ l = e.getUniformLocation(n, "NAN", !1), $().getNumber("WEBGL_VERSION") === 1 && (s = e.getUniformLocation(n, "INFINITY", !1));
1807
+ const u = !1;
1982
1808
  for (const f of t.variableNames) {
1983
1809
  const d = {
1984
1810
  name: f,
1985
- uniform: e.getUniformLocation(n, f, l),
1986
- offset: e.getUniformLocation(n, `offset${f}`, l)
1811
+ uniform: e.getUniformLocation(n, f, u),
1812
+ offset: e.getUniformLocation(n, `offset${f}`, u)
1987
1813
  };
1988
- t.enableShapeUniforms && (d.shape = e.getUniformLocation(n, `${f}Shape`, l), d.texShape = e.getUniformLocation(n, `${f}TexShape`, l)), r.push(d);
1814
+ t.enableShapeUniforms && (d.shape = e.getUniformLocation(n, `${f}Shape`, u), d.texShape = e.getUniformLocation(n, `${f}TexShape`, u)), r.push(d);
1989
1815
  }
1990
- if (t.enableShapeUniforms && (i = e.getUniformLocation(n, "outShape", l), s = e.getUniformLocation(n, "outShapeStrides", l), a = e.getUniformLocation(n, "outTexShape", l)), t.customUniforms)
1816
+ if (t.enableShapeUniforms && (a = e.getUniformLocation(n, "outShape", u), c = e.getUniformLocation(n, "outShapeStrides", u), i = e.getUniformLocation(n, "outTexShape", u)), t.customUniforms)
1991
1817
  for (const f of t.customUniforms)
1992
- o.push(e.getUniformLocation(n, f.name, l));
1818
+ o.push(e.getUniformLocation(n, f.name, u));
1993
1819
  return {
1994
1820
  variablesLocations: r,
1995
1821
  customUniformLocations: o,
1996
- infLoc: c,
1997
- nanLoc: u,
1998
- outShapeLocation: i,
1999
- outShapeStridesLocation: s,
2000
- outTexShapeLocation: a
1822
+ infLoc: s,
1823
+ nanLoc: l,
1824
+ outShapeLocation: a,
1825
+ outShapeStridesLocation: c,
1826
+ outTexShapeLocation: i
2001
1827
  };
2002
1828
  }
2003
- function re(e, t) {
1829
+ function Y(e, t) {
2004
1830
  if (e.length !== t.length)
2005
1831
  throw Error(`Binary was compiled with ${e.length} inputs, but was executed with ${t.length} inputs`);
2006
1832
  e.forEach((n, r) => {
2007
- const o = n.logicalShape, i = t[r], a = i.shape;
2008
- if (!T(o, a))
2009
- throw Error(`Binary was compiled with different shapes than the current args. Shapes ${o} and ${a} must match`);
2010
- if (n.isUniform && i.isUniform)
1833
+ const o = n.logicalShape, a = t[r], i = a.shape;
1834
+ if (!T(o, i))
1835
+ throw Error(`Binary was compiled with different shapes than the current args. Shapes ${o} and ${i} must match`);
1836
+ if (n.isUniform && a.isUniform)
2011
1837
  return;
2012
- const s = n.texShape, c = i.isUniform ? null : i.texData.texShape;
2013
- if (!T(s, c))
2014
- throw Error(`Binary was compiled with different texture shapes than the current args. Shape ${s} and ${c} must match`);
1838
+ const c = n.texShape, s = a.isUniform ? null : a.texData.texShape;
1839
+ if (!T(c, s))
1840
+ throw Error(`Binary was compiled with different texture shapes than the current args. Shape ${c} and ${s} must match`);
2015
1841
  });
2016
1842
  }
2017
- function Sn(e, t, n, r, o) {
2018
- t.program.enableShapeUniforms || (re(t.inShapeInfos, n), re([t.outShapeInfo], [r]));
2019
- const i = r.texData.texture, a = r.texData.texShape;
2020
- r.texData.isPacked ? e.setOutputPackedMatrixTexture(i.texture, a[0], a[1]) : e.setOutputMatrixTexture(i.texture, a[0], a[1]), e.setProgram(t.webGLProgram), e.bindVertexArray(t.webGLProgram.vao), v().getNumber("WEBGL_VERSION") === 1 && t.infLoc !== null && e.gl.uniform1f(t.infLoc, 1 / 0), t.nanLoc !== null && e.gl.uniform1f(t.nanLoc, NaN);
2021
- for (let c = 0; c < n.length; ++c) {
2022
- const u = n[c], { uniform: l, offset: f, shape: d, texShape: h } = t.variablesLocations[c];
1843
+ function jt(e, t, n, r, o) {
1844
+ t.program.enableShapeUniforms || (Y(t.inShapeInfos, n), Y([t.outShapeInfo], [r]));
1845
+ const a = r.texData.texture, i = r.texData.texShape;
1846
+ r.texData.isPacked ? e.setOutputPackedMatrixTexture(a.texture, i[0], i[1]) : e.setOutputMatrixTexture(a.texture, i[0], i[1]), e.setProgram(t.webGLProgram), e.bindVertexArray(t.webGLProgram.vao), $().getNumber("WEBGL_VERSION") === 1 && t.infLoc !== null && e.gl.uniform1f(t.infLoc, 1 / 0), t.nanLoc !== null && e.gl.uniform1f(t.nanLoc, NaN);
1847
+ for (let s = 0; s < n.length; ++s) {
1848
+ const l = n[s], { uniform: u, offset: f, shape: d, texShape: x } = t.variablesLocations[s];
2023
1849
  if (d) {
2024
- const { uniformShape: x } = j(t.program.packedInputs, u.shape, u.texData.texShape);
2025
- switch (x.length) {
1850
+ const { uniformShape: h } = z(t.program.packedInputs, l.shape, l.texData.texShape);
1851
+ switch (h.length) {
2026
1852
  case 1:
2027
- e.gl.uniform1iv(d, new Int32Array(x));
1853
+ e.gl.uniform1iv(d, new Int32Array(h));
2028
1854
  break;
2029
1855
  case 2:
2030
- e.gl.uniform2iv(d, new Int32Array(x));
1856
+ e.gl.uniform2iv(d, new Int32Array(h));
2031
1857
  break;
2032
1858
  case 3:
2033
- e.gl.uniform3iv(d, new Int32Array(x));
1859
+ e.gl.uniform3iv(d, new Int32Array(h));
2034
1860
  break;
2035
1861
  case 4:
2036
- e.gl.uniform4iv(d, new Int32Array(x));
1862
+ e.gl.uniform4iv(d, new Int32Array(h));
2037
1863
  break;
2038
1864
  }
2039
1865
  }
2040
- if (h && e.gl.uniform2i(h, u.texData.texShape[0], u.texData.texShape[1]), l != null) {
2041
- if (u.isUniform) {
2042
- if (E(u.shape) < 2)
2043
- e.gl.uniform1f(l, u.uniformValues[0]);
1866
+ if (x && e.gl.uniform2i(x, l.texData.texShape[0], l.texData.texShape[1]), u != null) {
1867
+ if (l.isUniform) {
1868
+ if (E(l.shape) < 2)
1869
+ e.gl.uniform1f(u, l.uniformValues[0]);
2044
1870
  else {
2045
- let x = u.uniformValues;
2046
- x instanceof Float32Array || (x = new Float32Array(x)), e.gl.uniform1fv(l, x);
1871
+ let h = l.uniformValues;
1872
+ h instanceof Float32Array || (h = new Float32Array(h)), e.gl.uniform1fv(u, h);
2047
1873
  }
2048
1874
  continue;
2049
1875
  }
2050
- u.texData.slice != null && f != null && e.gl.uniform1i(f, u.texData.slice.flatOffset), e.setInputMatrixTexture(u.texData.texture.texture, l, c);
1876
+ l.texData.slice != null && f != null && e.gl.uniform1i(f, l.texData.slice.flatOffset), e.setInputMatrixTexture(l.texData.texture.texture, u, s);
2051
1877
  }
2052
1878
  }
2053
- const s = t.outShapeLocation;
2054
- if (s)
1879
+ const c = t.outShapeLocation;
1880
+ if (c)
2055
1881
  switch (r.shape.length) {
2056
1882
  case 1:
2057
- e.gl.uniform1iv(s, new Int32Array(r.shape));
1883
+ e.gl.uniform1iv(c, new Int32Array(r.shape));
2058
1884
  break;
2059
1885
  case 2:
2060
- e.gl.uniform2iv(s, new Int32Array(r.shape));
1886
+ e.gl.uniform2iv(c, new Int32Array(r.shape));
2061
1887
  break;
2062
1888
  case 3:
2063
- e.gl.uniform3iv(s, new Int32Array(r.shape));
1889
+ e.gl.uniform3iv(c, new Int32Array(r.shape));
2064
1890
  break;
2065
1891
  case 4:
2066
- e.gl.uniform4iv(s, new Int32Array(r.shape));
1892
+ e.gl.uniform4iv(c, new Int32Array(r.shape));
2067
1893
  break;
2068
1894
  }
2069
1895
  if (t.outShapeStridesLocation) {
2070
- const c = B(r.shape);
1896
+ const s = k(r.shape);
2071
1897
  switch (r.shape.length) {
2072
1898
  case 2:
2073
- e.gl.uniform1iv(t.outShapeStridesLocation, new Int32Array(c));
1899
+ e.gl.uniform1iv(t.outShapeStridesLocation, new Int32Array(s));
2074
1900
  break;
2075
1901
  case 3:
2076
- e.gl.uniform2iv(t.outShapeStridesLocation, new Int32Array(c));
1902
+ e.gl.uniform2iv(t.outShapeStridesLocation, new Int32Array(s));
2077
1903
  break;
2078
1904
  case 4:
2079
- e.gl.uniform3iv(t.outShapeStridesLocation, new Int32Array(c));
1905
+ e.gl.uniform3iv(t.outShapeStridesLocation, new Int32Array(s));
2080
1906
  break;
2081
1907
  }
2082
1908
  }
2083
1909
  if (t.outTexShapeLocation && e.gl.uniform2i(t.outTexShapeLocation, r.texData.texShape[0], r.texData.texShape[1]), t.program.customUniforms && o)
2084
- for (let c = 0; c < t.program.customUniforms.length; ++c) {
2085
- const u = t.program.customUniforms[c], l = t.customUniformLocations[c], f = o[c];
2086
- if (u.type === "float")
2087
- e.gl.uniform1fv(l, f);
2088
- else if (u.type === "vec2")
2089
- e.gl.uniform2fv(l, f);
2090
- else if (u.type === "vec3")
2091
- e.gl.uniform3fv(l, f);
2092
- else if (u.type === "vec4")
2093
- e.gl.uniform4fv(l, f);
2094
- else if (u.type === "int")
2095
- e.gl.uniform1iv(l, f);
2096
- else if (u.type === "ivec2")
2097
- e.gl.uniform2iv(l, f);
2098
- else if (u.type === "ivec3")
2099
- e.gl.uniform3iv(l, f);
2100
- else if (u.type === "ivec4")
2101
- e.gl.uniform4iv(l, f);
1910
+ for (let s = 0; s < t.program.customUniforms.length; ++s) {
1911
+ const l = t.program.customUniforms[s], u = t.customUniformLocations[s], f = o[s];
1912
+ if (l.type === "float")
1913
+ e.gl.uniform1fv(u, f);
1914
+ else if (l.type === "vec2")
1915
+ e.gl.uniform2fv(u, f);
1916
+ else if (l.type === "vec3")
1917
+ e.gl.uniform3fv(u, f);
1918
+ else if (l.type === "vec4")
1919
+ e.gl.uniform4fv(u, f);
1920
+ else if (l.type === "int")
1921
+ e.gl.uniform1iv(u, f);
1922
+ else if (l.type === "ivec2")
1923
+ e.gl.uniform2iv(u, f);
1924
+ else if (l.type === "ivec3")
1925
+ e.gl.uniform3iv(u, f);
1926
+ else if (l.type === "ivec4")
1927
+ e.gl.uniform4iv(u, f);
2102
1928
  else
2103
- throw Error(`uniform type ${u.type} is not supported yet.`);
1929
+ throw Error(`uniform type ${l.type} is not supported yet.`);
2104
1930
  }
2105
1931
  e.executeProgram();
2106
1932
  }
2107
- function Rn(e, t, n) {
1933
+ function Yt(e, t, n) {
2108
1934
  let r = "";
2109
- t.concat(n).forEach((a) => {
2110
- const s = a.texData != null && a.texData.slice != null && a.texData.slice.flatOffset > 0;
2111
- if (e.enableShapeUniforms && !a.isUniform) {
2112
- const c = a.texData.texShape, { useSqueezeShape: u, uniformShape: l, keptDims: f } = j(e.packedInputs, a.shape, c);
2113
- let d = "", h = "", x = "";
2114
- if (l.length === 1 && e.packedInputs) {
2115
- const O = [Math.ceil(c[0] / 2), Math.ceil(c[1] / 2)];
2116
- d = `${O[0] > 1}_${O[1] > 1}`;
2117
- } else if (l.length === 2 && !e.packedInputs)
2118
- h = `${l[0] > 1}_${l[1] > 1}`;
2119
- else if (l.length > 2 && !e.packedInputs) {
2120
- const O = B(l);
2121
- x = `${O[0] === c[1]}_${O[O.length - 1] === c[1]}`;
2122
- }
2123
- const p = a.shape.length, $ = l.length === 2 && T(a.shape, c), S = E(a.shape) === 1, R = $e(a.shape, n.shape), w = !e.packedInputs && p === n.shape.length && T(c, n.texData.texShape), ve = e.packedInputs || l.length > 2 ? "" : `${c[0] > 1}_${c[1] > 1}`;
2124
- r += `${p}_${w}_${u ? f : ""}_${l.length}_${S}_${R}_${$}_${d}_${h}_${x}_${ve}_${s}`;
1935
+ t.concat(n).forEach((i) => {
1936
+ const c = i.texData != null && i.texData.slice != null && i.texData.slice.flatOffset > 0;
1937
+ if (e.enableShapeUniforms && !i.isUniform) {
1938
+ const s = i.texData.texShape, { useSqueezeShape: l, uniformShape: u, keptDims: f } = z(e.packedInputs, i.shape, s);
1939
+ let d = "", x = "", h = "";
1940
+ if (u.length === 1 && e.packedInputs) {
1941
+ const I = [Math.ceil(s[0] / 2), Math.ceil(s[1] / 2)];
1942
+ d = `${I[0] > 1}_${I[1] > 1}`;
1943
+ } else if (u.length === 2 && !e.packedInputs)
1944
+ x = `${u[0] > 1}_${u[1] > 1}`;
1945
+ else if (u.length > 2 && !e.packedInputs) {
1946
+ const I = k(u);
1947
+ h = `${I[0] === s[1]}_${I[I.length - 1] === s[1]}`;
1948
+ }
1949
+ const p = i.shape.length, m = u.length === 2 && T(i.shape, s), S = E(i.shape) === 1, R = ce(i.shape, n.shape), F = !e.packedInputs && p === n.shape.length && T(s, n.texData.texShape), oe = e.packedInputs || u.length > 2 ? "" : `${s[0] > 1}_${s[1] > 1}`;
1950
+ r += `${p}_${F}_${l ? f : ""}_${u.length}_${S}_${R}_${m}_${d}_${x}_${h}_${oe}_${c}`;
2125
1951
  } else {
2126
- const c = a.isUniform ? "uniform" : a.texData.texShape;
2127
- r += `${a.shape}_${c}_${s}`;
1952
+ const s = i.isUniform ? "uniform" : i.texData.texShape;
1953
+ r += `${i.shape}_${s}_${c}`;
2128
1954
  }
2129
1955
  });
2130
1956
  const o = e.userCode;
2131
- let i = e.constructor.name;
2132
- return i += "_" + r + "_" + o + `${v().getNumber("WEBGL_VERSION")}`, i;
1957
+ let a = e.constructor.name;
1958
+ return a += "_" + r + "_" + o + `${$().getNumber("WEBGL_VERSION")}`, a;
2133
1959
  }
2134
- function En(e) {
2135
- return v().getBool("WEBGL_USE_SHAPES_UNIFORMS") && e <= 4;
1960
+ function Kt(e) {
1961
+ return $().getBool("WEBGL_USE_SHAPES_UNIFORMS") && e <= 4;
2136
1962
  }
2137
1963
  export {
2138
- Sn as $,
2139
- mt as A,
2140
- Pt as B,
2141
- Wt as C,
2142
- _ as D,
2143
- Mt as E,
2144
- Ht as F,
2145
- g as G,
2146
- Qt as H,
2147
- de as I,
2148
- an as J,
2149
- zt as K,
2150
- qt as L,
2151
- jt as M,
2152
- tn as N,
2153
- nn as O,
2154
- ee as P,
2155
- rn as Q,
2156
- cn as R,
2157
- on as S,
2158
- te as T,
2159
- Bt as U,
2160
- ne as V,
2161
- sn as W,
2162
- Vt as X,
2163
- Xt as Y,
2164
- Rn as Z,
2165
- Tn as _,
2166
- Dt as a,
2167
- un as a0,
2168
- wt as a1,
2169
- Nt as a2,
2170
- $n as a3,
2171
- bt as b,
2172
- V as c,
2173
- xe as d,
2174
- pe as e,
2175
- he as f,
2176
- yt as g,
2177
- xn as h,
2178
- ln as i,
2179
- fn as j,
2180
- hn as k,
2181
- dn as l,
2182
- pn as m,
2183
- vn as n,
2184
- mn as o,
1964
+ jt as $,
1965
+ fe as A,
1966
+ ft as B,
1967
+ dt as C,
1968
+ A as D,
1969
+ Ht as E,
1970
+ pt as F,
1971
+ _ as G,
1972
+ Ft as H,
1973
+ K as I,
1974
+ It as J,
1975
+ $t as K,
1976
+ mt as L,
1977
+ Tt as M,
1978
+ At as N,
1979
+ wt as O,
1980
+ H as P,
1981
+ Nt as Q,
1982
+ Lt as R,
1983
+ Ot as S,
1984
+ q as T,
1985
+ ut as U,
1986
+ j as V,
1987
+ Ut as W,
1988
+ xt as X,
1989
+ ht as Y,
1990
+ Yt as Z,
1991
+ qt as _,
1992
+ zt as a,
1993
+ Dt as a0,
1994
+ me as a1,
1995
+ it as a2,
1996
+ Xt as a3,
1997
+ Wt as b,
1998
+ y as c,
1999
+ Z as d,
2000
+ J as e,
2001
+ re as f,
2002
+ Gt as g,
2003
+ Bt as h,
2004
+ gt as i,
2005
+ bt as j,
2006
+ kt as k,
2007
+ Mt as l,
2008
+ yt as m,
2009
+ Pt as n,
2010
+ Vt as o,
2185
2011
  L as p,
2186
- se as q,
2187
- Jt as r,
2188
- Yt as s,
2189
- m as t,
2190
- En as u,
2191
- kt as v,
2192
- Gt as w,
2193
- en as x,
2194
- Zt as y,
2195
- Kt as z
2012
+ Q as q,
2013
+ St as r,
2014
+ Rt as s,
2015
+ v as t,
2016
+ Kt as u,
2017
+ lt as v,
2018
+ vt as w,
2019
+ _t as x,
2020
+ Ct as y,
2021
+ Et as z
2196
2022
  };