@genai-fi/nanogpt 0.20.0 → 0.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (433) hide show
  1. package/dist/BaseTokeniser-DSg9zcYq.js +221 -0
  2. package/dist/DatasetBuilder-DgURD85T.js +712 -0
  3. package/dist/Generator.d.ts +82 -0
  4. package/dist/Generator.js +2 -0
  5. package/dist/RealDiv-DBu0FQqT.js +362 -0
  6. package/dist/Reshape-CABOPB9d.js +94 -0
  7. package/dist/Reshape-DqO3r8BC.js +17 -0
  8. package/dist/TeachableLLM.d.ts +70 -0
  9. package/dist/TeachableLLM.js +2 -0
  10. package/dist/Trainer.d.ts +43 -0
  11. package/dist/Trainer.js +2 -0
  12. package/dist/backend.d.ts +2 -0
  13. package/dist/backend.js +13 -0
  14. package/dist/backend_util-Cg-roD1p.js +399 -0
  15. package/dist/binary_op_util-CrYk9LXL.js +103 -0
  16. package/dist/checks/appendCache.d.ts +1 -0
  17. package/dist/checks/appendCache.js +55 -0
  18. package/dist/checks/attentionMask.d.ts +1 -0
  19. package/dist/checks/attentionMask.js +56 -0
  20. package/dist/checks/check.d.ts +9 -0
  21. package/dist/checks/check.js +32 -0
  22. package/dist/checks/gelu.d.ts +1 -0
  23. package/dist/checks/gelu.js +46 -0
  24. package/dist/checks/index.d.ts +26 -0
  25. package/dist/checks/index.js +28 -0
  26. package/dist/checks/matMulGelu.d.ts +1 -0
  27. package/dist/checks/matMulGelu.js +84 -0
  28. package/dist/checks/normRMS.d.ts +1 -0
  29. package/dist/checks/normRMS.js +28 -0
  30. package/dist/checks/normRMSGrad.d.ts +1 -0
  31. package/dist/checks/normRMSGrad.js +22 -0
  32. package/dist/checks/packUnpack.d.ts +1 -0
  33. package/dist/checks/packUnpack.js +46 -0
  34. package/dist/checks/qkv.d.ts +1 -0
  35. package/dist/checks/qkv.js +34 -0
  36. package/dist/checks/rope.d.ts +1 -0
  37. package/dist/checks/rope.js +30 -0
  38. package/dist/checks/weights.d.ts +14 -0
  39. package/dist/checks/weights.js +27 -0
  40. package/dist/chunk-BPntVaq0.js +23 -0
  41. package/dist/complex_util-CkazZsaH.js +60 -0
  42. package/dist/concat_util-CWDZCBlA.js +19 -0
  43. package/dist/data/docx.d.ts +2 -0
  44. package/dist/data/docx.js +3046 -0
  45. package/dist/data/pdf.d.ts +2 -0
  46. package/dist/data/pdf.js +17 -0
  47. package/dist/data/textLoader.d.ts +7 -0
  48. package/dist/data/textLoader.js +613 -0
  49. package/dist/dist-BewPQWjc.js +7572 -0
  50. package/dist/dist-DVmq73nz.js +8775 -0
  51. package/dist/dist-DXwIvKxl.js +896 -0
  52. package/dist/dist-VEU5mfO0.js +7545 -0
  53. package/dist/gelu-Bf1HW1RY.js +27 -0
  54. package/dist/gpgpu_math-DvLcCH6u.js +1612 -0
  55. package/dist/inference/types.d.ts +16 -0
  56. package/dist/inference/types.js +0 -0
  57. package/dist/kernel_funcs_utils-HiXOOx3f.js +229 -0
  58. package/dist/layers/BaseLayer.d.ts +44 -0
  59. package/dist/layers/BaseLayer.js +76 -0
  60. package/dist/layers/CausalSelfAttention.d.ts +39 -0
  61. package/dist/layers/CausalSelfAttention.js +99 -0
  62. package/dist/layers/LoRA.d.ts +14 -0
  63. package/dist/layers/LoRA.js +48 -0
  64. package/dist/layers/MLP.d.ts +17 -0
  65. package/dist/layers/MLP.js +34 -0
  66. package/dist/layers/PositionEmbedding.d.ts +8 -0
  67. package/dist/layers/PositionEmbedding.js +27 -0
  68. package/dist/layers/RMSNorm.d.ts +12 -0
  69. package/dist/layers/RMSNorm.js +20 -0
  70. package/dist/layers/RoPECache.d.ts +18 -0
  71. package/dist/layers/RoPECache.js +337 -0
  72. package/dist/layers/TiedEmbedding.d.ts +13 -0
  73. package/dist/layers/TiedEmbedding.js +32 -0
  74. package/dist/layers/TransformerBlock.d.ts +27 -0
  75. package/dist/layers/TransformerBlock.js +51 -0
  76. package/dist/layers/WeightStore.d.ts +20 -0
  77. package/dist/layers/WeightStore.js +69 -0
  78. package/dist/loader/load.d.ts +6 -0
  79. package/dist/loader/load.js +2 -0
  80. package/dist/loader/loadHF.d.ts +8 -0
  81. package/dist/loader/loadHF.js +2 -0
  82. package/dist/loader/loadTransformers.d.ts +4 -0
  83. package/dist/loader/loadTransformers.js +2 -0
  84. package/dist/loader/loadZipMeta.d.ts +3 -0
  85. package/dist/loader/loadZipMeta.js +16 -0
  86. package/dist/loader/newZipLoad.d.ts +3 -0
  87. package/dist/loader/newZipLoad.js +2 -0
  88. package/dist/loader/oldZipLoad.d.ts +9 -0
  89. package/dist/loader/oldZipLoad.js +2 -0
  90. package/dist/loader/save.d.ts +16 -0
  91. package/dist/loader/save.js +2 -0
  92. package/dist/loader/types.d.ts +68 -0
  93. package/dist/loader/types.js +0 -0
  94. package/dist/main-D5CbfCiV.js +13500 -0
  95. package/dist/main.d.ts +50 -0
  96. package/dist/main.js +16 -0
  97. package/dist/matMul16-BNfZSnNM.js +81 -0
  98. package/dist/matMulGelu-CPTntosE.js +162 -0
  99. package/dist/models/NanoGPTV1.d.ts +16 -0
  100. package/dist/models/NanoGPTV1.js +2 -0
  101. package/dist/models/NanoGPTV2.d.ts +16 -0
  102. package/dist/models/NanoGPTV2.js +2 -0
  103. package/dist/models/config.d.ts +27 -0
  104. package/dist/models/config.js +37 -0
  105. package/dist/models/factory.d.ts +3 -0
  106. package/dist/models/factory.js +2 -0
  107. package/dist/models/model.d.ts +44 -0
  108. package/dist/models/model.js +2 -0
  109. package/dist/ops/adamAdjust.d.ts +2 -0
  110. package/dist/ops/adamAdjust.js +18 -0
  111. package/dist/ops/adamMoments.d.ts +2 -0
  112. package/dist/ops/adamMoments.js +16 -0
  113. package/dist/ops/add16.d.ts +2 -0
  114. package/dist/ops/add16.js +12 -0
  115. package/dist/ops/appendCache.d.ts +2 -0
  116. package/dist/ops/appendCache.js +25 -0
  117. package/dist/ops/attentionMask.d.ts +2 -0
  118. package/dist/ops/attentionMask.js +16 -0
  119. package/dist/ops/concat16.d.ts +2 -0
  120. package/dist/ops/concat16.js +8 -0
  121. package/dist/ops/cpu/adamAdjust.d.ts +1 -0
  122. package/dist/ops/cpu/adamAdjust.js +16 -0
  123. package/dist/ops/cpu/adamMoments.d.ts +1 -0
  124. package/dist/ops/cpu/adamMoments.js +16 -0
  125. package/dist/ops/cpu/appendCache.d.ts +1 -0
  126. package/dist/ops/cpu/appendCache.js +65 -0
  127. package/dist/ops/cpu/attentionMask.d.ts +1 -0
  128. package/dist/ops/cpu/attentionMask.js +16 -0
  129. package/dist/ops/cpu/fusedSoftmax.d.ts +9 -0
  130. package/dist/ops/cpu/fusedSoftmax.js +22 -0
  131. package/dist/ops/cpu/gatherSub.d.ts +1 -0
  132. package/dist/ops/cpu/gatherSub.js +12 -0
  133. package/dist/ops/cpu/gelu.d.ts +1 -0
  134. package/dist/ops/cpu/gelu.js +36 -0
  135. package/dist/ops/cpu/matMul16.d.ts +1 -0
  136. package/dist/ops/cpu/matMul16.js +14 -0
  137. package/dist/ops/cpu/matMulGelu.d.ts +1 -0
  138. package/dist/ops/cpu/matMulGelu.js +41 -0
  139. package/dist/ops/cpu/matMulMul.d.ts +1 -0
  140. package/dist/ops/cpu/matMulMul.js +20 -0
  141. package/dist/ops/cpu/mulDropout.d.ts +1 -0
  142. package/dist/ops/cpu/mulDropout.js +20 -0
  143. package/dist/ops/cpu/normRMS.d.ts +1 -0
  144. package/dist/ops/cpu/normRMS.js +35 -0
  145. package/dist/ops/cpu/qkv.d.ts +5 -0
  146. package/dist/ops/cpu/qkv.js +73 -0
  147. package/dist/ops/cpu/rope.d.ts +6 -0
  148. package/dist/ops/cpu/rope.js +81 -0
  149. package/dist/ops/cpu/scatterSub.d.ts +1 -0
  150. package/dist/ops/cpu/scatterSub.js +12 -0
  151. package/dist/ops/dot16.d.ts +2 -0
  152. package/dist/ops/dot16.js +29 -0
  153. package/dist/ops/dropout.d.ts +2 -0
  154. package/dist/ops/dropout.js +11 -0
  155. package/dist/ops/dropout16.d.ts +2 -0
  156. package/dist/ops/dropout16.js +22 -0
  157. package/dist/ops/gatherSub.d.ts +2 -0
  158. package/dist/ops/gatherSub.js +13 -0
  159. package/dist/ops/gelu.d.ts +3 -0
  160. package/dist/ops/gelu.js +2 -0
  161. package/dist/ops/globalNorm.d.ts +2 -0
  162. package/dist/ops/globalNorm.js +19 -0
  163. package/dist/ops/grads/add16.d.ts +1 -0
  164. package/dist/ops/grads/add16.js +27 -0
  165. package/dist/ops/grads/attentionMask.d.ts +1 -0
  166. package/dist/ops/grads/attentionMask.js +26 -0
  167. package/dist/ops/grads/dropout16.d.ts +1 -0
  168. package/dist/ops/grads/dropout16.js +1 -0
  169. package/dist/ops/grads/gelu.d.ts +2 -0
  170. package/dist/ops/grads/gelu.js +2 -0
  171. package/dist/ops/grads/matMul16.d.ts +2 -0
  172. package/dist/ops/grads/matMul16.js +2 -0
  173. package/dist/ops/grads/matMulGelu.d.ts +1 -0
  174. package/dist/ops/grads/matMulGelu.js +22 -0
  175. package/dist/ops/grads/mul16.d.ts +1 -0
  176. package/dist/ops/grads/mul16.js +1 -0
  177. package/dist/ops/grads/normRMS.d.ts +3 -0
  178. package/dist/ops/grads/normRMS.js +37 -0
  179. package/dist/ops/grads/pack16.d.ts +2 -0
  180. package/dist/ops/grads/pack16.js +2 -0
  181. package/dist/ops/grads/qkv.d.ts +3 -0
  182. package/dist/ops/grads/qkv.js +46 -0
  183. package/dist/ops/grads/rope.d.ts +2 -0
  184. package/dist/ops/grads/rope.js +2 -0
  185. package/dist/ops/grads/softmax16.d.ts +2 -0
  186. package/dist/ops/grads/softmax16.js +23 -0
  187. package/dist/ops/grads/unpack16.d.ts +2 -0
  188. package/dist/ops/grads/unpack16.js +2 -0
  189. package/dist/ops/grads/utils.d.ts +4 -0
  190. package/dist/ops/grads/utils.js +12 -0
  191. package/dist/ops/log.d.ts +0 -0
  192. package/dist/ops/log.js +1 -0
  193. package/dist/ops/matMul16.d.ts +15 -0
  194. package/dist/ops/matMul16.js +2 -0
  195. package/dist/ops/matMulGelu.d.ts +3 -0
  196. package/dist/ops/matMulGelu.js +20 -0
  197. package/dist/ops/matMulMul.d.ts +2 -0
  198. package/dist/ops/matMulMul.js +16 -0
  199. package/dist/ops/mul16.d.ts +2 -0
  200. package/dist/ops/mul16.js +43 -0
  201. package/dist/ops/mulDrop.d.ts +2 -0
  202. package/dist/ops/mulDrop.js +15 -0
  203. package/dist/ops/normRMS.d.ts +2 -0
  204. package/dist/ops/normRMS.js +22 -0
  205. package/dist/ops/pack16.d.ts +2 -0
  206. package/dist/ops/pack16.js +2 -0
  207. package/dist/ops/qkv.d.ts +2 -0
  208. package/dist/ops/qkv.js +16 -0
  209. package/dist/ops/reshape16.d.ts +2 -0
  210. package/dist/ops/reshape16.js +33 -0
  211. package/dist/ops/rope.d.ts +3 -0
  212. package/dist/ops/rope.js +2 -0
  213. package/dist/ops/scatterSub.d.ts +2 -0
  214. package/dist/ops/scatterSub.js +13 -0
  215. package/dist/ops/slice16.d.ts +2 -0
  216. package/dist/ops/slice16.js +11 -0
  217. package/dist/ops/softmax16.d.ts +2 -0
  218. package/dist/ops/softmax16.js +9 -0
  219. package/dist/ops/sub16.d.ts +2 -0
  220. package/dist/ops/sub16.js +11 -0
  221. package/dist/ops/sum16.d.ts +2 -0
  222. package/dist/ops/sum16.js +13 -0
  223. package/dist/ops/transpose16.d.ts +3 -0
  224. package/dist/ops/transpose16.js +32 -0
  225. package/dist/ops/unpack16.d.ts +2 -0
  226. package/dist/ops/unpack16.js +2 -0
  227. package/dist/ops/webgl/adamAdjust.d.ts +1 -0
  228. package/dist/ops/webgl/adamAdjust.js +82 -0
  229. package/dist/ops/webgl/adamMoments.d.ts +1 -0
  230. package/dist/ops/webgl/adamMoments.js +44 -0
  231. package/dist/ops/webgl/appendCache.d.ts +1 -0
  232. package/dist/ops/webgl/appendCache.js +53 -0
  233. package/dist/ops/webgl/attentionMask.d.ts +1 -0
  234. package/dist/ops/webgl/attentionMask.js +64 -0
  235. package/dist/ops/webgl/dropout16.d.ts +1 -0
  236. package/dist/ops/webgl/dropout16.js +12 -0
  237. package/dist/ops/webgl/fusedSoftmax.d.ts +11 -0
  238. package/dist/ops/webgl/fusedSoftmax.js +70 -0
  239. package/dist/ops/webgl/gatherSub.d.ts +1 -0
  240. package/dist/ops/webgl/gatherSub.js +28 -0
  241. package/dist/ops/webgl/gelu.d.ts +2 -0
  242. package/dist/ops/webgl/gelu.js +48 -0
  243. package/dist/ops/webgl/log.d.ts +17 -0
  244. package/dist/ops/webgl/log.js +14 -0
  245. package/dist/ops/webgl/matMul16.d.ts +1 -0
  246. package/dist/ops/webgl/matMul16.js +37 -0
  247. package/dist/ops/webgl/matMulGelu.d.ts +21 -0
  248. package/dist/ops/webgl/matMulGelu.js +2 -0
  249. package/dist/ops/webgl/matMulMul.d.ts +14 -0
  250. package/dist/ops/webgl/matMulMul.js +24 -0
  251. package/dist/ops/webgl/mulDropout.d.ts +1 -0
  252. package/dist/ops/webgl/mulDropout.js +32 -0
  253. package/dist/ops/webgl/normRMS.d.ts +1 -0
  254. package/dist/ops/webgl/normRMS.js +114 -0
  255. package/dist/ops/webgl/qkv.d.ts +1 -0
  256. package/dist/ops/webgl/qkv.js +54 -0
  257. package/dist/ops/webgl/rope.d.ts +1 -0
  258. package/dist/ops/webgl/rope.js +72 -0
  259. package/dist/ops/webgl/scatterSub.d.ts +1 -0
  260. package/dist/ops/webgl/scatterSub.js +28 -0
  261. package/dist/ops/webgpu/adamAdjust.d.ts +1 -0
  262. package/dist/ops/webgpu/adamAdjust.js +77 -0
  263. package/dist/ops/webgpu/adamMoments.d.ts +1 -0
  264. package/dist/ops/webgpu/adamMoments.js +76 -0
  265. package/dist/ops/webgpu/add16.d.ts +1 -0
  266. package/dist/ops/webgpu/add16.js +14 -0
  267. package/dist/ops/webgpu/appendCache.d.ts +1 -0
  268. package/dist/ops/webgpu/appendCache.js +130 -0
  269. package/dist/ops/webgpu/attentionMask.d.ts +1 -0
  270. package/dist/ops/webgpu/attentionMask.js +42 -0
  271. package/dist/ops/webgpu/attentionMask32_program.d.ts +19 -0
  272. package/dist/ops/webgpu/attentionMask32_program.js +62 -0
  273. package/dist/ops/webgpu/clipScale.d.ts +1 -0
  274. package/dist/ops/webgpu/clipScale.js +45 -0
  275. package/dist/ops/webgpu/concat16.d.ts +19 -0
  276. package/dist/ops/webgpu/concat16.js +111 -0
  277. package/dist/ops/webgpu/dropout16.d.ts +1 -0
  278. package/dist/ops/webgpu/dropout16.js +59 -0
  279. package/dist/ops/webgpu/gatherSub.d.ts +1 -0
  280. package/dist/ops/webgpu/gatherSub.js +52 -0
  281. package/dist/ops/webgpu/gelu.d.ts +14 -0
  282. package/dist/ops/webgpu/gelu.js +147 -0
  283. package/dist/ops/webgpu/index.d.ts +0 -0
  284. package/dist/ops/webgpu/index.js +26 -0
  285. package/dist/ops/webgpu/matMul16.d.ts +1 -0
  286. package/dist/ops/webgpu/matMul16.js +70 -0
  287. package/dist/ops/webgpu/matMul16_program.d.ts +42 -0
  288. package/dist/ops/webgpu/matMul16_program.js +303 -0
  289. package/dist/ops/webgpu/mul16.d.ts +1 -0
  290. package/dist/ops/webgpu/mul16.js +14 -0
  291. package/dist/ops/webgpu/norm2.d.ts +1 -0
  292. package/dist/ops/webgpu/norm2.js +46 -0
  293. package/dist/ops/webgpu/normRMS.d.ts +1 -0
  294. package/dist/ops/webgpu/normRMS.js +26 -0
  295. package/dist/ops/webgpu/normRMS16_program.d.ts +10 -0
  296. package/dist/ops/webgpu/normRMS16_program.js +28 -0
  297. package/dist/ops/webgpu/normRMS32_program.d.ts +10 -0
  298. package/dist/ops/webgpu/normRMS32_program.js +28 -0
  299. package/dist/ops/webgpu/normRMSGrad.d.ts +1 -0
  300. package/dist/ops/webgpu/normRMSGrad.js +225 -0
  301. package/dist/ops/webgpu/pack16.d.ts +1 -0
  302. package/dist/ops/webgpu/pack16.js +21 -0
  303. package/dist/ops/webgpu/pack16_program.d.ts +19 -0
  304. package/dist/ops/webgpu/pack16_program.js +93 -0
  305. package/dist/ops/webgpu/qkv.d.ts +1 -0
  306. package/dist/ops/webgpu/qkv.js +64 -0
  307. package/dist/ops/webgpu/rope.d.ts +1 -0
  308. package/dist/ops/webgpu/rope.js +163 -0
  309. package/dist/ops/webgpu/scatterSub.d.ts +1 -0
  310. package/dist/ops/webgpu/scatterSub.js +53 -0
  311. package/dist/ops/webgpu/slice16.d.ts +7 -0
  312. package/dist/ops/webgpu/slice16.js +74 -0
  313. package/dist/ops/webgpu/softmax16.d.ts +17 -0
  314. package/dist/ops/webgpu/softmax16.js +18 -0
  315. package/dist/ops/webgpu/softmax16_program.d.ts +13 -0
  316. package/dist/ops/webgpu/softmax16_program.js +89 -0
  317. package/dist/ops/webgpu/softmax16_subgroup_program.d.ts +17 -0
  318. package/dist/ops/webgpu/softmax16_subgroup_program.js +70 -0
  319. package/dist/ops/webgpu/softmax16grad.d.ts +1 -0
  320. package/dist/ops/webgpu/softmax16grad.js +31 -0
  321. package/dist/ops/webgpu/sub16.d.ts +1 -0
  322. package/dist/ops/webgpu/sub16.js +14 -0
  323. package/dist/ops/webgpu/sum16.d.ts +1 -0
  324. package/dist/ops/webgpu/sum16.js +29 -0
  325. package/dist/ops/webgpu/transpose16.d.ts +1 -0
  326. package/dist/ops/webgpu/transpose16.js +37 -0
  327. package/dist/ops/webgpu/transpose16_program.d.ts +16 -0
  328. package/dist/ops/webgpu/transpose16_program.js +51 -0
  329. package/dist/ops/webgpu/transpose16_shared_program.d.ts +15 -0
  330. package/dist/ops/webgpu/transpose16_shared_program.js +79 -0
  331. package/dist/ops/webgpu/unpack16.d.ts +1 -0
  332. package/dist/ops/webgpu/unpack16.js +60 -0
  333. package/dist/ops/webgpu/utils/binary_op.d.ts +35 -0
  334. package/dist/ops/webgpu/utils/binary_op.js +141 -0
  335. package/dist/ops/webgpu/utils/deviceInfo.d.ts +7 -0
  336. package/dist/ops/webgpu/utils/deviceInfo.js +11 -0
  337. package/dist/ops/webgpu/utils/reductions.d.ts +43 -0
  338. package/dist/ops/webgpu/utils/reductions.js +263 -0
  339. package/dist/pack16-Ck-spx_F.js +39 -0
  340. package/dist/patches/webgpu_backend.d.ts +18 -0
  341. package/dist/patches/webgpu_backend.js +43 -0
  342. package/dist/patches/webgpu_base.d.ts +21 -0
  343. package/dist/patches/webgpu_base.js +22 -0
  344. package/dist/patches/webgpu_program.d.ts +36 -0
  345. package/dist/patches/webgpu_program.js +293 -0
  346. package/dist/pdf-UoDqCYzz.js +16726 -0
  347. package/dist/picomatch-3tUnMMbd.js +1063 -0
  348. package/dist/rope-CbeGlsV8.js +25 -0
  349. package/dist/selu_util-zkAx5doH.js +24 -0
  350. package/dist/shared-D1coEFea.js +1314 -0
  351. package/dist/shared-DOgWaqvL.js +5 -0
  352. package/dist/slice_util-Dgb3ANWI.js +208 -0
  353. package/dist/tfjs_backend-BjuQ5FqB.js +614 -0
  354. package/dist/tokeniser/BaseTokeniser.d.ts +33 -0
  355. package/dist/tokeniser/BaseTokeniser.js +2 -0
  356. package/dist/tokeniser/CharTokeniser.d.ts +24 -0
  357. package/dist/tokeniser/CharTokeniser.js +92 -0
  358. package/dist/tokeniser/bpe.d.ts +28 -0
  359. package/dist/tokeniser/bpe.js +170 -0
  360. package/dist/tokeniser/messages.d.ts +61 -0
  361. package/dist/tokeniser/messages.js +0 -0
  362. package/dist/tokeniser/type.d.ts +34 -0
  363. package/dist/tokeniser/type.js +0 -0
  364. package/dist/training/AdamW.d.ts +36 -0
  365. package/dist/training/AdamW.js +128 -0
  366. package/dist/training/BasicTrainer.d.ts +63 -0
  367. package/dist/training/BasicTrainer.js +265 -0
  368. package/dist/training/DatasetBuilder.d.ts +26 -0
  369. package/dist/training/DatasetBuilder.js +2 -0
  370. package/dist/training/Evaluator.d.ts +19 -0
  371. package/dist/training/Evaluator.js +48 -0
  372. package/dist/training/LRScheduler.d.ts +12 -0
  373. package/dist/training/LRScheduler.js +38 -0
  374. package/dist/training/PreTrainer.d.ts +11 -0
  375. package/dist/training/PreTrainer.js +22 -0
  376. package/dist/training/SFTTrainer.d.ts +12 -0
  377. package/dist/training/SFTTrainer.js +24 -0
  378. package/dist/training/loss.d.ts +3 -0
  379. package/dist/training/loss.js +19 -0
  380. package/dist/training/orthoGrad.d.ts +2 -0
  381. package/dist/training/orthoGrad.js +10 -0
  382. package/dist/training/sparseCrossEntropy.d.ts +7 -0
  383. package/dist/training/sparseCrossEntropy.js +47 -0
  384. package/dist/training/tasks/ConversationTask.d.ts +18 -0
  385. package/dist/training/tasks/ConversationTask.js +38 -0
  386. package/dist/training/tasks/PretrainingTask.d.ts +17 -0
  387. package/dist/training/tasks/PretrainingTask.js +42 -0
  388. package/dist/training/tasks/StartSentenceTask.d.ts +18 -0
  389. package/dist/training/tasks/StartSentenceTask.js +45 -0
  390. package/dist/training/tasks/Task.d.ts +22 -0
  391. package/dist/training/tasks/Task.js +55 -0
  392. package/dist/training/tasks/splitter.d.ts +5 -0
  393. package/dist/training/tasks/splitter.js +18 -0
  394. package/dist/training/types.d.ts +78 -0
  395. package/dist/training/types.js +0 -0
  396. package/dist/training/validation.d.ts +17 -0
  397. package/dist/training/validation.js +2 -0
  398. package/dist/utilities/arrayClose.d.ts +1 -0
  399. package/dist/utilities/arrayClose.js +16 -0
  400. package/dist/utilities/datasetID.d.ts +2 -0
  401. package/dist/utilities/datasetID.js +18 -0
  402. package/dist/utilities/dummy.d.ts +9 -0
  403. package/dist/utilities/dummy.js +36 -0
  404. package/dist/utilities/multinomialCPU.d.ts +2 -0
  405. package/dist/utilities/multinomialCPU.js +9 -0
  406. package/dist/utilities/naming.d.ts +4 -0
  407. package/dist/utilities/naming.js +0 -0
  408. package/dist/utilities/packed.d.ts +4 -0
  409. package/dist/utilities/packed.js +13 -0
  410. package/dist/utilities/parameters.d.ts +11 -0
  411. package/dist/utilities/parameters.js +38 -0
  412. package/dist/utilities/performance.d.ts +2 -0
  413. package/dist/utilities/performance.js +16 -0
  414. package/dist/utilities/profile.d.ts +17 -0
  415. package/dist/utilities/profile.js +33 -0
  416. package/dist/utilities/safetensors.d.ts +3 -0
  417. package/dist/utilities/safetensors.js +53 -0
  418. package/dist/utilities/sentences.d.ts +5 -0
  419. package/dist/utilities/sentences.js +32 -0
  420. package/dist/utilities/tokenParse.d.ts +1 -0
  421. package/dist/utilities/tokenParse.js +17 -0
  422. package/dist/utilities/topP.d.ts +1 -0
  423. package/dist/utilities/topP.js +12 -0
  424. package/dist/utilities/waitForModel.d.ts +2 -0
  425. package/dist/utilities/waitForModel.js +12 -0
  426. package/dist/utilities/weights.d.ts +12 -0
  427. package/dist/utilities/weights.js +40 -0
  428. package/dist/utilities/yielder.d.ts +1 -0
  429. package/dist/utilities/yielder.js +7 -0
  430. package/dist/webgpu-Dt7BMzWz.js +525 -0
  431. package/dist/webgpu_program-WOyIVMlZ.js +392 -0
  432. package/dist/webgpu_util-B_F3SShA.js +106 -0
  433. package/package.json +1 -1
@@ -0,0 +1,1612 @@
1
+ import { Ln as e, Ms as t, Ns as n, Ps as r, Rs as i, cc as a, ic as o, oc as s, sc as c, tc as l } from "./dist-BewPQWjc.js";
2
+ import { t as u } from "./backend_util-Cg-roD1p.js";
3
+ //#region node_modules/@tensorflow/tfjs-backend-webgl/dist/canvas_util.js
4
+ var d = {}, f = {
5
+ alpha: !1,
6
+ antialias: !1,
7
+ premultipliedAlpha: !1,
8
+ preserveDrawingBuffer: !1,
9
+ depth: !1,
10
+ stencil: !1,
11
+ failIfMajorPerformanceCaveat: !0
12
+ };
13
+ function p(e, t) {
14
+ d[e] = t;
15
+ }
16
+ function m(e, t) {
17
+ if (!(e in d) || t != null) {
18
+ let n = g(e, t);
19
+ if (n !== null) d[e] = n;
20
+ else return console.log("Could not get context for WebGL version", e), null;
21
+ }
22
+ let n = d[e];
23
+ return n == null || n.isContextLost() ? (delete d[e], m(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), d[e]);
24
+ }
25
+ function h(e) {
26
+ if (!t().getBool("IS_SAFARI") && typeof OffscreenCanvas < "u" && e === 2) return new OffscreenCanvas(300, 150);
27
+ if (typeof document < "u") return document.createElement("canvas");
28
+ throw Error("Cannot create a canvas in this context");
29
+ }
30
+ function g(e, n) {
31
+ if (e !== 1 && e !== 2) throw Error("Cannot get WebGL rendering context, WebGL is disabled.");
32
+ let r = n ?? h(e);
33
+ return r.addEventListener("webglcontextlost", (t) => {
34
+ t.preventDefault(), delete d[e];
35
+ }, !1), t().getBool("SOFTWARE_WEBGL_ENABLED") && (f.failIfMajorPerformanceCaveat = !1), e === 1 ? r.getContext("webgl", f) || r.getContext("experimental-webgl", f) : r.getContext("webgl2", f);
36
+ }
37
+ //#endregion
38
+ //#region node_modules/@tensorflow/tfjs-backend-webgl/dist/tex_util.js
39
+ var _;
40
+ (function(e) {
41
+ e[e.DENSE = 0] = "DENSE", e[e.SHARED_BATCH = 1] = "SHARED_BATCH";
42
+ })(_ ||= {});
43
+ var v;
44
+ (function(e) {
45
+ e[e.RENDER = 0] = "RENDER", e[e.UPLOAD = 1] = "UPLOAD", e[e.PIXELS = 2] = "PIXELS", e[e.DOWNLOAD = 3] = "DOWNLOAD";
46
+ })(v ||= {});
47
+ var y;
48
+ (function(e) {
49
+ 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";
50
+ })(y ||= {});
51
+ function b(e, t) {
52
+ return [t, e];
53
+ }
54
+ function x(e, t) {
55
+ return e * t;
56
+ }
57
+ function ee(e) {
58
+ let t = s(e);
59
+ return c(Math.ceil(t / 4));
60
+ }
61
+ function S(e, t) {
62
+ return [Math.max(1, Math.ceil(t / 2)), Math.max(1, Math.ceil(e / 2))];
63
+ }
64
+ function C(e, t) {
65
+ let [n, r] = S(e, t);
66
+ return n * r * 4;
67
+ }
68
+ function w(e, n) {
69
+ let r = e, i, a, o, s, c, l, u, d, f, p;
70
+ return t().getNumber("WEBGL_VERSION") === 2 ? (i = r.R32F, a = r.R16F, o = r.RGBA16F, s = r.RGBA32F, c = r.RED, u = 4, d = 1, f = r.HALF_FLOAT, p = r.FLOAT, l = r.RGBA8) : (i = e.RGBA, a = e.RGBA, o = e.RGBA, s = r.RGBA, c = e.RGBA, u = 4, d = 4, f = n == null ? null : n.HALF_FLOAT_OES, p = e.FLOAT, l = e.RGBA), {
71
+ internalFormatFloat: i,
72
+ internalFormatHalfFloat: a,
73
+ internalFormatPackedHalfFloat: o,
74
+ internalFormatPackedFloat: s,
75
+ textureFormatFloat: c,
76
+ downloadTextureFormat: l,
77
+ downloadUnpackNumChannels: u,
78
+ defaultNumChannels: d,
79
+ textureTypeHalfFloat: f,
80
+ textureTypeFloat: p
81
+ };
82
+ }
83
+ //#endregion
84
+ //#region node_modules/@tensorflow/tfjs-backend-webgl/dist/webgl_util.js
85
+ function T(e, n) {
86
+ let r = n();
87
+ return t().getBool("DEBUG") && te(e), r;
88
+ }
89
+ function te(e) {
90
+ let t = e.getError();
91
+ if (t !== e.NO_ERROR) throw Error("WebGL Error: " + ae(e, t));
92
+ }
93
+ var ne = 5.96e-8, re = 65504;
94
+ function ie(e) {
95
+ return !!(t().getBool("WEBGL_RENDER_FLOAT32_ENABLED") || e === 0 || ne < Math.abs(e) && Math.abs(e) < re);
96
+ }
97
+ function ae(e, t) {
98
+ switch (t) {
99
+ case e.NO_ERROR: return "NO_ERROR";
100
+ case e.INVALID_ENUM: return "INVALID_ENUM";
101
+ case e.INVALID_VALUE: return "INVALID_VALUE";
102
+ case e.INVALID_OPERATION: return "INVALID_OPERATION";
103
+ case e.INVALID_FRAMEBUFFER_OPERATION: return "INVALID_FRAMEBUFFER_OPERATION";
104
+ case e.OUT_OF_MEMORY: return "OUT_OF_MEMORY";
105
+ case e.CONTEXT_LOST_WEBGL: return "CONTEXT_LOST_WEBGL";
106
+ default: return `Unknown error code ${t}`;
107
+ }
108
+ }
109
+ function oe(e, t) {
110
+ return A(e, () => e.getExtension(t), "Extension \"" + t + "\" not supported on this browser.");
111
+ }
112
+ function se(e, t) {
113
+ let n = A(e, () => e.createShader(e.VERTEX_SHADER), "Unable to create vertex WebGLShader.");
114
+ if (T(e, () => e.shaderSource(n, t)), T(e, () => e.compileShader(n)), e.getShaderParameter(n, e.COMPILE_STATUS) === !1) throw console.log(e.getShaderInfoLog(n)), Error("Failed to compile vertex shader.");
115
+ return n;
116
+ }
117
+ function ce(e, n) {
118
+ let r = A(e, () => e.createShader(e.FRAGMENT_SHADER), "Unable to create fragment WebGLShader.");
119
+ if (T(e, () => e.shaderSource(r, n)), T(e, () => e.compileShader(r)), t().get("ENGINE_COMPILE_ONLY")) return r;
120
+ if (e.getShaderParameter(r, e.COMPILE_STATUS) === !1) throw E(n, e.getShaderInfoLog(r)), Error("Failed to compile fragment shader.");
121
+ return r;
122
+ }
123
+ var le = /ERROR: [0-9]+:([0-9]+):/g;
124
+ function E(e, t) {
125
+ let n = le.exec(t);
126
+ if (n == null) {
127
+ console.log(`Couldn't parse line number in error: ${t}`), console.log(e);
128
+ return;
129
+ }
130
+ let r = +n[1], i = e.split("\n"), a = i.length.toString().length + 2, s = i.map((e, t) => o((t + 1).toString(), a) + e), c = 0;
131
+ for (let e = 0; e < s.length; e++) c = Math.max(s[e].length, c);
132
+ let l = s.slice(0, r - 1), u = s.slice(r - 1, r), d = s.slice(r);
133
+ console.log(l.join("\n")), console.log(t.split("\n")[0]), console.log(`%c ${o(u[0], c)}`, "border:1px solid red; background-color:#e3d2d2; color:#a61717"), console.log(d.join("\n"));
134
+ }
135
+ function ue(e) {
136
+ return A(e, () => e.createProgram(), "Unable to create WebGLProgram.");
137
+ }
138
+ function de(e, n) {
139
+ if (T(e, () => e.linkProgram(n)), !t().get("ENGINE_COMPILE_ONLY") && e.getProgramParameter(n, e.LINK_STATUS) === !1) throw console.log(e.getProgramInfoLog(n)), Error("Failed to link vertex and fragment shaders.");
140
+ }
141
+ function fe(e, t) {
142
+ if (T(e, () => e.validateProgram(t)), e.getProgramParameter(t, e.VALIDATE_STATUS) === !1) throw console.log(e.getProgramInfoLog(t)), Error("Shader program validation failed.");
143
+ }
144
+ function pe(e, t) {
145
+ let n = A(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
146
+ return T(e, () => e.bindBuffer(e.ARRAY_BUFFER, n)), T(e, () => e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
147
+ }
148
+ function me(e, t) {
149
+ let n = A(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
150
+ return T(e, () => e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, n)), T(e, () => e.bufferData(e.ELEMENT_ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
151
+ }
152
+ function he(e) {
153
+ return A(e, () => e.createTexture(), "Unable to create WebGLTexture.");
154
+ }
155
+ function ge(e, n) {
156
+ let r = t().getNumber("WEBGL_MAX_TEXTURE_SIZE");
157
+ if (e <= 0 || n <= 0) {
158
+ let t = `[${e}x${n}]`;
159
+ throw Error("Requested texture size " + t + " is invalid.");
160
+ }
161
+ if (e > r || n > r) {
162
+ let t = `[${e}x${n}]`, i = `[${r}x${r}]`;
163
+ throw Error("Requested texture size " + t + " greater than WebGL maximum on this browser / GPU " + i + ".");
164
+ }
165
+ }
166
+ function _e(e) {
167
+ return A(e, () => e.createFramebuffer(), "Unable to create WebGLFramebuffer.");
168
+ }
169
+ function ve(e, t, n, r, i, a, o) {
170
+ let s = e.getAttribLocation(t, n);
171
+ return s === -1 ? !1 : (T(e, () => e.bindBuffer(e.ARRAY_BUFFER, r)), T(e, () => e.vertexAttribPointer(s, i, e.FLOAT, !1, a, o)), T(e, () => e.enableVertexAttribArray(s)), !0);
172
+ }
173
+ function ye(e, t, n) {
174
+ we(e, n), T(e, () => e.activeTexture(e.TEXTURE0 + n)), T(e, () => e.bindTexture(e.TEXTURE_2D, t));
175
+ }
176
+ function be(e, t, n) {
177
+ return A(e, () => e.getUniformLocation(t, n), "uniform \"" + n + "\" not present in program.");
178
+ }
179
+ function xe(e, t, n) {
180
+ return e.getUniformLocation(t, n);
181
+ }
182
+ function Se(e, t, n, r) {
183
+ T(e, () => ye(e, t, r)), T(e, () => e.uniform1i(n, r));
184
+ }
185
+ function Ce(e, t, n) {
186
+ T(e, () => e.bindFramebuffer(e.FRAMEBUFFER, n)), T(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, t, 0));
187
+ }
188
+ function D(e, t) {
189
+ T(e, () => e.bindFramebuffer(e.FRAMEBUFFER, t)), T(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, null, 0));
190
+ }
191
+ function O(e) {
192
+ let t = e.checkFramebufferStatus(e.FRAMEBUFFER);
193
+ if (t !== e.FRAMEBUFFER_COMPLETE) throw Error("Error binding framebuffer: " + k(e, t));
194
+ }
195
+ function k(e, t) {
196
+ switch (t) {
197
+ case e.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: return "FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
198
+ case e.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: return "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
199
+ case e.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: return "FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
200
+ case e.FRAMEBUFFER_UNSUPPORTED: return "FRAMEBUFFER_UNSUPPORTED";
201
+ default: return `unknown error ${t}`;
202
+ }
203
+ }
204
+ function A(e, t, n) {
205
+ let r = T(e, () => t());
206
+ if (r == null) throw Error(n);
207
+ return r;
208
+ }
209
+ function we(e, t) {
210
+ let n = e.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1, r = t + e.TEXTURE0;
211
+ if (r < e.TEXTURE0 || r > n) {
212
+ let e = `[gl.TEXTURE0, gl.TEXTURE${n}]`;
213
+ throw Error(`textureUnit must be in ${e}.`);
214
+ }
215
+ }
216
+ function j(e, t = 2) {
217
+ return s(e.slice(0, e.length - t));
218
+ }
219
+ function M(e) {
220
+ if (e.length === 0) throw Error("Cannot get rows and columns of an empty shape array.");
221
+ return [e.length > 1 ? e[e.length - 2] : 1, e[e.length - 1]];
222
+ }
223
+ function Te(e) {
224
+ let t = [
225
+ 1,
226
+ 1,
227
+ 1
228
+ ];
229
+ return e.length === 0 || e.length === 1 && e[0] === 1 || (t = [j(e), ...M(e)]), t;
230
+ }
231
+ function Ee(e, n = !1) {
232
+ let r = t().getNumber("WEBGL_MAX_TEXTURE_SIZE"), i = t().getNumber("WEBGL_MAX_SIZE_FOR_NARROW_TEXTURE");
233
+ i === Infinity && t().getBool("WEBGL_AUTO_SQUARIFY_NARROW_TEXTURE_SHAPE") && (i = r / 2), n && (r *= 2, i *= 2, e = e.map((t, n) => n >= e.length - 2 ? l(e[n]) : e[n]), e.length === 1 && (e = [2, e[0]])), e.length !== 2 && (e = a(e).newShape);
234
+ let o = s(e), u = null;
235
+ e.length <= 1 && o <= r ? u = [1, o] : e.length === 2 && e[0] <= r && e[1] <= r ? u = e : e.length === 3 && e[0] * e[1] <= r && e[2] <= r ? u = [e[0] * e[1], e[2]] : e.length === 3 && e[0] <= r && e[1] * e[2] <= r ? u = [e[0], e[1] * e[2]] : e.length === 4 && e[0] * e[1] * e[2] <= r && e[3] <= r ? u = [e[0] * e[1] * e[2], e[3]] : e.length === 4 && e[0] <= r && e[1] * e[2] * e[3] <= r && (u = [e[0], e[1] * e[2] * e[3]]);
236
+ let d = u != null && Math.max(...u) > i && Math.min(...u) <= (n ? 2 : 1) && Math.min(...u) > 0;
237
+ if (u == null || d) if (n) {
238
+ let t = j(e), n = 2, r = 2;
239
+ e.length && ([n, r] = M(e)), o = n / 2 * t * (r / 2), u = c(o).map((e) => e * 2);
240
+ } else u = c(o);
241
+ return u;
242
+ }
243
+ function N(e) {
244
+ return e % 2 == 0;
245
+ }
246
+ function De(e, t) {
247
+ if (e = e.slice(-2), t = t.slice(-2), n(e, t) || !e.length || !t.length || e[0] === 0 || e[1] === 0 || t[0] === 0 || t[1] === 0) return !0;
248
+ if (e.length !== t.length) {
249
+ let n = e[e.length - 1], r = t[t.length - 1];
250
+ if (n === r || N(n) && N(r) && (e[0] === 1 || t[0] === 1)) return !0;
251
+ }
252
+ return e[1] === t[1] && N(e[0]) && N(t[0]);
253
+ }
254
+ var P, F;
255
+ function Oe(e) {
256
+ if (P == null) {
257
+ let t = m(e);
258
+ P = t.getParameter(t.MAX_TEXTURE_SIZE);
259
+ }
260
+ return P;
261
+ }
262
+ function ke(e) {
263
+ if (F == null) {
264
+ let t = m(e);
265
+ F = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);
266
+ }
267
+ return Math.min(16, F);
268
+ }
269
+ function Ae(e) {
270
+ if (e === 0) return 0;
271
+ let t, n = m(e);
272
+ return t = I(n, "EXT_disjoint_timer_query_webgl2") && e === 2 ? 2 : +!!I(n, "EXT_disjoint_timer_query"), t;
273
+ }
274
+ function I(e, t) {
275
+ return e.getExtension(t) != null;
276
+ }
277
+ function je(e) {
278
+ try {
279
+ if (m(e) != null) return !0;
280
+ } catch (e) {
281
+ return console.log("Error when getting WebGL context: ", e), !1;
282
+ }
283
+ return !1;
284
+ }
285
+ function Me(e) {
286
+ if (e === 0) return !1;
287
+ let t = m(e);
288
+ if (e === 1) {
289
+ if (!I(t, "OES_texture_float")) return !1;
290
+ } else if (!I(t, "EXT_color_buffer_float")) return !1;
291
+ return L(t);
292
+ }
293
+ function Ne(e) {
294
+ if (e === 0) return !1;
295
+ let t = m(e);
296
+ if (e === 1) {
297
+ if (!I(t, "OES_texture_float") || !I(t, "WEBGL_color_buffer_float")) return !1;
298
+ } else {
299
+ if (I(t, "EXT_color_buffer_float")) return L(t);
300
+ let e = "EXT_color_buffer_half_float";
301
+ return I(t, e) ? Pe(t, t.getExtension(e)) : !1;
302
+ }
303
+ return L(t);
304
+ }
305
+ function L(e) {
306
+ let t = w(e), n = e.createTexture();
307
+ e.bindTexture(e.TEXTURE_2D, n), e.texImage2D(e.TEXTURE_2D, 0, t.internalFormatFloat, 1, 1, 0, t.textureFormatFloat, t.textureTypeFloat, null);
308
+ let r = e.createFramebuffer();
309
+ e.bindFramebuffer(e.FRAMEBUFFER, r), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, n, 0);
310
+ let i = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
311
+ return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(n), e.deleteFramebuffer(r), i;
312
+ }
313
+ function Pe(e, t) {
314
+ let n = w(e, t), r = e.createTexture();
315
+ e.bindTexture(e.TEXTURE_2D, r), e.texImage2D(e.TEXTURE_2D, 0, n.internalFormatHalfFloat, 1, 1, 0, n.textureFormatFloat, n.textureTypeHalfFloat, null);
316
+ let i = e.createFramebuffer();
317
+ e.bindFramebuffer(e.FRAMEBUFFER, i), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, r, 0);
318
+ let a = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
319
+ return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(r), e.deleteFramebuffer(i), a;
320
+ }
321
+ function Fe(e) {
322
+ return e === 2 ? m(e).fenceSync != null : !1;
323
+ }
324
+ function Ie(e, t) {
325
+ Array.isArray(e) || (e = [e]), e.forEach((e) => {
326
+ e != null && r(e.dtype !== "complex64", () => `${t} does not support complex64 tensors in the WebGL backend.`);
327
+ });
328
+ }
329
+ //#endregion
330
+ //#region node_modules/@tensorflow/tfjs-backend-webgl/dist/glsl_version.js
331
+ function R() {
332
+ let e, n, r, i, a, o, s, c, l, u;
333
+ return t().getNumber("WEBGL_VERSION") === 2 ? (e = "#version 300 es", n = "in", r = "out", i = "in", a = "texture", o = "outputColor", s = "out vec4 outputColor;", c = t().getBool("WEBGL2_ISNAN_CUSTOM") ? "\n bool isnan_custom(float val) {\n uint floatToUint = floatBitsToUint(val);\n return (floatToUint & 0x7fffffffu) > 0x7f800000u;\n }\n\n bvec4 isnan_custom(vec4 val) {\n return bvec4(isnan_custom(val.x),\n isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));\n }\n\n #define isnan(value) isnan_custom(value)\n " : "", l = "", u = "\n #define round(value) newRound(value)\n int newRound(float value) {\n return int(floor(value + 0.5));\n }\n\n ivec4 newRound(vec4 value) {\n return ivec4(floor(value + vec4(0.5)));\n }\n ") : (e = "", n = "attribute", r = "varying", i = "varying", a = "texture2D", o = "gl_FragColor", s = "", c = "\n #define isnan(value) isnan_custom(value)\n bool isnan_custom(float val) {\n return (val > 0. || val < 1. || val == 0.) ? false : true;\n }\n bvec4 isnan_custom(vec4 val) {\n return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));\n }\n ", l = "\n uniform float INFINITY;\n\n bool isinf(float val) {\n return abs(val) == INFINITY;\n }\n bvec4 isinf(vec4 val) {\n return equal(abs(val), vec4(INFINITY));\n }\n ", u = "\n int round(float value) {\n return int(floor(value + 0.5));\n }\n\n ivec4 round(vec4 value) {\n return ivec4(floor(value + vec4(0.5)));\n }\n "), {
334
+ version: e,
335
+ attribute: n,
336
+ varyingVs: r,
337
+ varyingFs: i,
338
+ texture2D: a,
339
+ output: o,
340
+ defineOutput: s,
341
+ defineSpecialNaN: c,
342
+ defineSpecialInf: l,
343
+ defineRound: u
344
+ };
345
+ }
346
+ //#endregion
347
+ //#region node_modules/@tensorflow/tfjs-backend-webgl/dist/shader_compiler_util.js
348
+ function z(e, t, n = "index") {
349
+ let r = i(t);
350
+ return r.map((t, i) => `${`int ${e[i]} = ${n} / ${t}`}; ${i === r.length - 1 ? `int ${e[i + 1]} = ${n} - ${e[i]} * ${t}` : `index -= ${e[i]} * ${t}`};`).join("");
351
+ }
352
+ function B(e, t, n = "index") {
353
+ let r = i(t);
354
+ return r.map((t, i) => `${`int ${e[i]} = ${n} / outShapeStrides[${i}]`}; ${i === r.length - 1 ? `int ${e[i + 1]} = ${n} - ${e[i]} * outShapeStrides[${i}]` : `index -= ${e[i]} * outShapeStrides[${i}]`};`).join("");
355
+ }
356
+ function Le(e, t) {
357
+ let n = e.length, r = e.map((e) => `${t}[${e}]`), i = Array(n - 1);
358
+ i[n - 2] = r[n - 1];
359
+ for (let e = n - 3; e >= 0; --e) i[e] = `(${i[e + 1]} * ${r[e + 1]})`;
360
+ return i;
361
+ }
362
+ function Re(e, t, n = "index") {
363
+ let r = Le(e.map((e, t) => t), t);
364
+ return r.map((t, i) => `${`int ${e[i]} = ${n} / ${r[i]}`}; ${i === r.length - 1 ? `int ${e[i + 1]} = ${n} - ${e[i]} * ${r[i]}` : `index -= ${e[i]} * ${r[i]}`};`).join("");
365
+ }
366
+ function ze(e) {
367
+ let t = i(e).map((e) => e.toString());
368
+ return `
369
+ int getFlatIndex(ivec3 coords) {
370
+ return coords.x * ${t[0]} + coords.y * ${t[1]} + coords.z;
371
+ }
372
+ `;
373
+ }
374
+ function Be() {
375
+ return "\n int getFlatIndex(ivec3 coords) {\n return coords.x * outShapeStrides[0] + coords.y * outShapeStrides[1] + coords.z;\n }\n";
376
+ }
377
+ var Ve = "\n const float FLOAT_MAX = 1.70141184e38;\n const float FLOAT_MIN = 1.17549435e-38;\n\n lowp vec4 encode_float(highp float v) {\n if (isnan(v)) {\n return vec4(255, 255, 255, 255);\n }\n\n highp float av = abs(v);\n\n if(av < FLOAT_MIN) {\n return vec4(0.0, 0.0, 0.0, 0.0);\n } else if(v > FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;\n } else if(v < -FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;\n }\n\n highp vec4 c = vec4(0,0,0,0);\n\n highp float e = floor(log2(av));\n highp float m = exp2(fract(log2(av))) - 1.0;\n\n c[2] = floor(128.0 * m);\n m -= c[2] / 128.0;\n c[1] = floor(32768.0 * m);\n m -= c[1] / 32768.0;\n c[0] = floor(8388608.0 * m);\n\n highp float ebias = e + 127.0;\n c[3] = floor(ebias / 2.0);\n ebias -= c[3] * 2.0;\n c[2] += floor(ebias) * 128.0;\n\n c[3] += 128.0 * step(0.0, -v);\n\n return c / 255.0;\n }\n", { getBroadcastDims: V } = u;
378
+ function He(e, t, n) {
379
+ let r = [];
380
+ if (e.forEach((e) => {
381
+ let t = s(e.shapeInfo.logicalShape);
382
+ if (e.shapeInfo.isUniform ? r.push(`uniform float ${e.name}${t > 1 ? `[${t}]` : ""};`) : (r.push(`uniform sampler2D ${e.name};`), r.push(`uniform int offset${e.name};`)), n.enableShapeUniforms) {
383
+ let { uniformShape: t } = Y(n.packedInputs, e.shapeInfo.logicalShape, e.shapeInfo.texShape);
384
+ switch (t.length) {
385
+ case 1:
386
+ r.push(`uniform int ${e.name}Shape;`);
387
+ break;
388
+ case 2:
389
+ r.push(`uniform ivec2 ${e.name}Shape;`);
390
+ break;
391
+ case 3:
392
+ r.push(`uniform ivec3 ${e.name}Shape;`);
393
+ break;
394
+ case 4:
395
+ r.push(`uniform ivec4 ${e.name}Shape;`);
396
+ break;
397
+ default: break;
398
+ }
399
+ r.push(`uniform ivec2 ${e.name}TexShape;`);
400
+ }
401
+ }), n.enableShapeUniforms) {
402
+ switch (t.logicalShape.length) {
403
+ case 1:
404
+ r.push("uniform int outShape;");
405
+ break;
406
+ case 2:
407
+ r.push("uniform ivec2 outShape;"), r.push("uniform int outShapeStrides;");
408
+ break;
409
+ case 3:
410
+ r.push("uniform ivec3 outShape;"), r.push("uniform ivec2 outShapeStrides;");
411
+ break;
412
+ case 4:
413
+ r.push("uniform ivec4 outShape;"), r.push("uniform ivec3 outShapeStrides;");
414
+ break;
415
+ default: break;
416
+ }
417
+ r.push("uniform ivec2 outTexShape;");
418
+ }
419
+ n.customUniforms && n.customUniforms.forEach((e) => {
420
+ r.push(`uniform ${e.type} ${e.name}${e.arrayIndex ? `[${e.arrayIndex}]` : ""};`);
421
+ });
422
+ let i = r.join("\n"), a = e.map((e) => Ue(e, t, n.packedInputs, n.enableShapeUniforms)).join("\n"), o = t.texShape, c = R(), l = Ke(c), u, d, f = Ye(c);
423
+ return t.isPacked ? (u = We(t.logicalShape, o, n.enableShapeUniforms), d = Je(c)) : (u = Ge(t.logicalShape, o, n.enableShapeUniforms), d = qe(c)), n.packedInputs && (f += $e), [
424
+ f,
425
+ l,
426
+ d,
427
+ i,
428
+ u,
429
+ a,
430
+ n.userCode
431
+ ].join("\n");
432
+ }
433
+ function H(e, t = !1) {
434
+ let n = e.shapeInfo.logicalShape;
435
+ switch (n.length) {
436
+ case 0: return dt(e, t);
437
+ case 1: return pt(e, t);
438
+ case 2: return ht(e, t);
439
+ case 3: return _t(e, t);
440
+ case 4: return yt(e, t);
441
+ case 5: return K(e);
442
+ case 6: return bt(e);
443
+ default: throw Error(`${n.length}-D input sampling is not yet supported`);
444
+ }
445
+ }
446
+ function U(e, t) {
447
+ switch (e.shapeInfo.logicalShape.length) {
448
+ case 0: return ut(e);
449
+ case 1: return ft(e, t);
450
+ case 2: return mt(e, t);
451
+ case 3: return gt(e, t);
452
+ default: return vt(e, t);
453
+ }
454
+ }
455
+ function Ue(e, t, n = !1, r) {
456
+ let i = "";
457
+ n ? i += U(e, r) : i += H(e, r);
458
+ let a = e.shapeInfo.logicalShape, o = t.logicalShape;
459
+ return a.length <= o.length && (n ? i += xt(e, t) : i += St(e, t)), i;
460
+ }
461
+ function We(e, t, n) {
462
+ switch (e.length) {
463
+ case 0: return W();
464
+ case 1: return et(e, t, n);
465
+ case 2: return ct(e, t, n);
466
+ case 3: return nt(e, t, n);
467
+ default: return it(e, t, n);
468
+ }
469
+ }
470
+ function Ge(e, t, n) {
471
+ switch (e.length) {
472
+ case 0: return W();
473
+ case 1: return tt(e, t, n);
474
+ case 2: return lt(e, t, n);
475
+ case 3: return rt(e, t, n);
476
+ case 4: return at(e, t, n);
477
+ case 5: return ot(e, t);
478
+ case 6: return st(e, t);
479
+ default: throw Error(`${e.length}-D output sampling is not yet supported`);
480
+ }
481
+ }
482
+ function Ke(e) {
483
+ return `
484
+ float sampleTexture(sampler2D textureSampler, vec2 uv) {
485
+ return ${e.texture2D}(textureSampler, uv).r;
486
+ }
487
+ `;
488
+ }
489
+ function qe(e) {
490
+ return `
491
+ void setOutput(float val) {
492
+ ${e.output} = vec4(val, 0, 0, 0);
493
+ }
494
+ `;
495
+ }
496
+ function Je(e) {
497
+ return `
498
+ void setOutput(vec4 val) {
499
+ ${e.output} = val;
500
+ }
501
+ `;
502
+ }
503
+ function Ye(e) {
504
+ return `${e.version}
505
+ precision highp float;
506
+ precision highp int;
507
+ precision highp sampler2D;
508
+ ${e.varyingFs} vec2 resultUV;
509
+ ${e.defineOutput}
510
+ const vec2 halfCR = vec2(0.5, 0.5);
511
+
512
+ struct ivec5
513
+ {
514
+ int x;
515
+ int y;
516
+ int z;
517
+ int w;
518
+ int u;
519
+ };
520
+
521
+ struct ivec6
522
+ {
523
+ int x;
524
+ int y;
525
+ int z;
526
+ int w;
527
+ int u;
528
+ int v;
529
+ };
530
+
531
+ uniform float NAN;
532
+ ${e.defineSpecialNaN}
533
+ ${e.defineSpecialInf}
534
+ ${e.defineRound}
535
+
536
+ int imod(int x, int y) {
537
+ return x - y * (x / y);
538
+ }
539
+
540
+ int idiv(int a, int b, float sign) {
541
+ int res = a / b;
542
+ int mod = imod(a, b);
543
+ if (sign < 0. && mod != 0) {
544
+ res -= 1;
545
+ }
546
+ return res;
547
+ }
548
+
549
+ //Based on the work of Dave Hoskins
550
+ //https://www.shadertoy.com/view/4djSRW
551
+ #define HASHSCALE1 443.8975
552
+ float random(float seed){
553
+ vec2 p = resultUV * seed;
554
+ vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);
555
+ p3 += dot(p3, p3.yzx + 19.19);
556
+ return fract((p3.x + p3.y) * p3.z);
557
+ }
558
+
559
+ ${Xe}
560
+ ${Ze}
561
+ ${Qe}
562
+ `;
563
+ }
564
+ var Xe = "\nvec2 uvFromFlat(int texNumR, int texNumC, int index) {\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\nvec2 packedUVfrom1D(int texNumR, int texNumC, int index) {\n int texelIndex = index / 2;\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n", Ze = "\nvec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,\n int texNumC, int row, int col) {\n int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n", Qe = "\nvec2 packedUVfrom3D(int texNumR, int texNumC,\n int texelsInBatch, int texelsInLogicalRow, int b,\n int row, int col) {\n int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n", $e = "\n float getChannel(vec4 frag, vec2 innerDims) {\n vec2 modCoord = mod(innerDims, 2.);\n return modCoord.x == 0. ?\n (modCoord.y == 0. ? frag.r : frag.g) :\n (modCoord.y == 0. ? frag.b : frag.a);\n }\n float getChannel(vec4 frag, int dim) {\n float modCoord = mod(float(dim), 2.);\n return modCoord == 0. ? frag.r : frag.g;\n }\n";
565
+ function W() {
566
+ return "\n int getOutputCoords() {\n return 0;\n }\n ";
567
+ }
568
+ function et(e, t, n) {
569
+ let r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
570
+ return r[0] === 1 ? n ? "\n int getOutputCoords() {\n return 2 * int(resultUV.x * ceil(float(outTexShape[1]) / 2.0));\n }\n " : `
571
+ int getOutputCoords() {
572
+ return 2 * int(resultUV.x * ${r[1]}.0);
573
+ }
574
+ ` : r[1] === 1 ? n ? "\n int getOutputCoords() {\n return 2 * int(resultUV.y * ceil(float(outTexShape[0]) / 2.0));\n }\n " : `
575
+ int getOutputCoords() {
576
+ return 2 * int(resultUV.y * ${r[0]}.0);
577
+ }
578
+ ` : n ? "\n int getOutputCoords() {\n ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(packedTexShape[0], packedTexShape[1]));\n return 2 * (resTexRC.x * packedTexShape[1] + resTexRC.y);\n }\n " : `
579
+ int getOutputCoords() {
580
+ ivec2 resTexRC = ivec2(resultUV.yx *
581
+ vec2(${r[0]}, ${r[1]}));
582
+ return 2 * (resTexRC.x * ${r[1]} + resTexRC.y);
583
+ }
584
+ `;
585
+ }
586
+ function tt(e, t, n) {
587
+ return t[0] === 1 ? n ? "\n int getOutputCoords() {\n return int(resultUV.x * float(outTexShape[1]));\n }\n " : `
588
+ int getOutputCoords() {
589
+ return int(resultUV.x * ${t[1]}.0);
590
+ }
591
+ ` : t[1] === 1 ? n ? "\n int getOutputCoords() {\n return int(resultUV.y * float(outTexShape[0]));\n }\n " : `
592
+ int getOutputCoords() {
593
+ return int(resultUV.y * ${t[0]}.0);
594
+ }
595
+ ` : n ? "\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(outTexShape[0], outTexShape[1]));\n return resTexRC.x * outTexShape[1] + resTexRC.y;\n }\n " : `
596
+ int getOutputCoords() {
597
+ ivec2 resTexRC = ivec2(resultUV.yx *
598
+ vec2(${t[0]}, ${t[1]}));
599
+ return resTexRC.x * ${t[1]} + resTexRC.y;
600
+ }
601
+ `;
602
+ }
603
+ function nt(e, t, n) {
604
+ if (n) return "\n ivec3 getOutputCoords() {\n ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));\n int texelsInLogicalRow = int(ceil(float(outShape[2]) / 2.0));\n int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[1]) / 2.0));\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(packedTexShape[0], packedTexShape[1]));\n int index = resTexRC.x * packedTexShape[1] + resTexRC.y;\n\n int b = index / texelsInBatch;\n index -= b * texelsInBatch;\n\n int r = 2 * (index / texelsInLogicalRow);\n int c = imod(index, texelsInLogicalRow) * 2;\n\n return ivec3(b, r, c);\n }\n ";
605
+ let r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], i = Math.ceil(e[2] / 2), a = i * Math.ceil(e[1] / 2);
606
+ return `
607
+ ivec3 getOutputCoords() {
608
+ ivec2 resTexRC = ivec2(resultUV.yx *
609
+ vec2(${r[0]}, ${r[1]}));
610
+ int index = resTexRC.x * ${r[1]} + resTexRC.y;
611
+
612
+ int b = index / ${a};
613
+ index -= b * ${a};
614
+
615
+ int r = 2 * (index / ${i});
616
+ int c = imod(index, ${i}) * 2;
617
+
618
+ return ivec3(b, r, c);
619
+ }
620
+ `;
621
+ }
622
+ function rt(e, t, n) {
623
+ if (n) return `
624
+ ivec3 getOutputCoords() {
625
+ ivec2 resTexRC = ivec2(resultUV.yx *
626
+ vec2(outTexShape[0], outTexShape[1]));
627
+ int index = resTexRC.x * outTexShape[1] + resTexRC.y;
628
+ ${B([
629
+ "r",
630
+ "c",
631
+ "d"
632
+ ], e)}
633
+ return ivec3(r, c, d);
634
+ }
635
+ `;
636
+ let r = z([
637
+ "r",
638
+ "c",
639
+ "d"
640
+ ], e);
641
+ return `
642
+ ivec3 getOutputCoords() {
643
+ ivec2 resTexRC = ivec2(resultUV.yx *
644
+ vec2(${t[0]}, ${t[1]}));
645
+ int index = resTexRC.x * ${t[1]} + resTexRC.y;
646
+ ${r}
647
+ return ivec3(r, c, d);
648
+ }
649
+ `;
650
+ }
651
+ function it(e, t, n) {
652
+ if (n) return "\n ivec4 getOutputCoords() {\n ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(packedTexShape[0], packedTexShape[1]));\n int index = resTexRC.x * packedTexShape[1] + resTexRC.y;\n\n int texelsInLogicalRow = int(ceil(float(outShape[3]) / 2.0));\n int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[2]) / 2.0));\n int texelsInBatchN = texelsInBatch * outShape[1];\n\n int b2 = index / texelsInBatchN;\n index -= b2 * texelsInBatchN;\n\n int b = index / texelsInBatch;\n index -= b * texelsInBatch;\n\n int r = 2 * (index / texelsInLogicalRow);\n int c = imod(index, texelsInLogicalRow) * 2;\n\n return ivec4(b2, b, r, c);\n }\n ";
653
+ let r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], i = Math.ceil(e[e.length - 1] / 2), a = i * Math.ceil(e[e.length - 2] / 2), o = a, s = "", c = "b, r, c";
654
+ for (let t = 2; t < e.length - 1; t++) o *= e[e.length - t - 1], s = `
655
+ int b${t} = index / ${o};
656
+ index -= b${t} * ${o};
657
+ ` + s, c = `b${t}, ` + c;
658
+ return `
659
+ ivec${e.length} getOutputCoords() {
660
+ ivec2 resTexRC = ivec2(resultUV.yx *
661
+ vec2(${r[0]}, ${r[1]}));
662
+ int index = resTexRC.x * ${r[1]} + resTexRC.y;
663
+
664
+ ${s}
665
+
666
+ int b = index / ${a};
667
+ index -= b * ${a};
668
+
669
+ int r = 2 * (index / ${i});
670
+ int c = imod(index, ${i}) * 2;
671
+
672
+ return ivec${e.length}(${c});
673
+ }
674
+ `;
675
+ }
676
+ function at(e, t, n) {
677
+ if (n) return `
678
+ ivec4 getOutputCoords() {
679
+ ivec2 resTexRC = ivec2(resultUV.yx *
680
+ vec2(outTexShape[0], outTexShape[1]));
681
+ int index = resTexRC.x * outTexShape[1] + resTexRC.y;
682
+ ${B([
683
+ "r",
684
+ "c",
685
+ "d",
686
+ "d2"
687
+ ], e)}
688
+ return ivec4(r, c, d, d2);
689
+ }
690
+ `;
691
+ let r = z([
692
+ "r",
693
+ "c",
694
+ "d",
695
+ "d2"
696
+ ], e);
697
+ return `
698
+ ivec4 getOutputCoords() {
699
+ ivec2 resTexRC = ivec2(resultUV.yx *
700
+ vec2(${t[0]}, ${t[1]}));
701
+ int index = resTexRC.x * ${t[1]} + resTexRC.y;
702
+ ${r}
703
+ return ivec4(r, c, d, d2);
704
+ }
705
+ `;
706
+ }
707
+ function ot(e, t) {
708
+ let n = z([
709
+ "r",
710
+ "c",
711
+ "d",
712
+ "d2",
713
+ "d3"
714
+ ], e);
715
+ return `
716
+ ivec5 getOutputCoords() {
717
+ ivec2 resTexRC = ivec2(resultUV.yx * vec2(${t[0]},
718
+ ${t[1]}));
719
+
720
+ int index = resTexRC.x * ${t[1]} + resTexRC.y;
721
+
722
+ ${n}
723
+
724
+ ivec5 outShape = ivec5(r, c, d, d2, d3);
725
+ return outShape;
726
+ }
727
+ `;
728
+ }
729
+ function st(e, t) {
730
+ let n = z([
731
+ "r",
732
+ "c",
733
+ "d",
734
+ "d2",
735
+ "d3",
736
+ "d4"
737
+ ], e);
738
+ return `
739
+ ivec6 getOutputCoords() {
740
+ ivec2 resTexRC = ivec2(resultUV.yx *
741
+ vec2(${t[0]}, ${t[1]}));
742
+ int index = resTexRC.x * ${t[1]} + resTexRC.y;
743
+
744
+ ${n}
745
+
746
+ ivec6 result = ivec6(r, c, d, d2, d3, d4);
747
+ return result;
748
+ }
749
+ `;
750
+ }
751
+ function ct(e, t, r) {
752
+ let i = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
753
+ if (n(e, t)) return r ? "\n ivec2 getOutputCoords() {\n ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));\n return 2 * ivec2(resultUV.yx * vec2(packedTexShape[0], packedTexShape[1]));\n }\n " : `
754
+ ivec2 getOutputCoords() {
755
+ return 2 * ivec2(resultUV.yx * vec2(${i[0]}, ${i[1]}));
756
+ }
757
+ `;
758
+ let a = Math.ceil(e[1] / 2);
759
+ return r ? "\n ivec2 getOutputCoords() {\n ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));\n int texelsInLogicalRow = int(ceil(float(outShape[1]) / 2.0));\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(packedTexShape[0], packedTexShape[1]));\n\n int index = resTexRC.x * packedTexShape[1] + resTexRC.y;\n int r = 2 * (index / texelsInLogicalRow);\n int c = imod(index, texelsInLogicalRow) * 2;\n\n return ivec2(r, c);\n }\n " : `
760
+ ivec2 getOutputCoords() {
761
+ ivec2 resTexRC = ivec2(resultUV.yx *
762
+ vec2(${i[0]}, ${i[1]}));
763
+
764
+ int index = resTexRC.x * ${i[1]} + resTexRC.y;
765
+ int r = 2 * (index / ${a});
766
+ int c = imod(index, ${a}) * 2;
767
+
768
+ return ivec2(r, c);
769
+ }
770
+ `;
771
+ }
772
+ function lt(e, t, r) {
773
+ return n(e, t) ? r ? "\n ivec2 getOutputCoords() {\n return ivec2(resultUV.yx * vec2(outTexShape[0], outTexShape[1]));\n }\n " : `
774
+ ivec2 getOutputCoords() {
775
+ return ivec2(resultUV.yx * vec2(${t[0]}, ${t[1]}));
776
+ }
777
+ ` : e[1] === 1 ? r ? "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(outTexShape[0], outTexShape[1]));\n int index = resTexRC.x * outTexShape[1] + resTexRC.y;\n return ivec2(index, 0);\n }\n " : `
778
+ ivec2 getOutputCoords() {
779
+ ivec2 resTexRC = ivec2(resultUV.yx *
780
+ vec2(${t[0]}, ${t[1]}));
781
+ int index = resTexRC.x * ${t[1]} + resTexRC.y;
782
+ return ivec2(index, 0);
783
+ }
784
+ ` : e[0] === 1 ? r ? "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(outTexShape[0], outTexShape[1]));\n int index = resTexRC.x * outTexShape[1] + resTexRC.y;\n return ivec2(0, index);\n }\n " : `
785
+ ivec2 getOutputCoords() {
786
+ ivec2 resTexRC = ivec2(resultUV.yx *
787
+ vec2(${t[0]}, ${t[1]}));
788
+ int index = resTexRC.x * ${t[1]} + resTexRC.y;
789
+ return ivec2(0, index);
790
+ }
791
+ ` : r ? "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(outTexShape[0], outTexShape[1]));\n int index = resTexRC.x * outTexShape[1] + resTexRC.y;\n int r = index / outShape[1];\n int c = index - r * outShape[1];\n return ivec2(r, c);\n }\n " : `
792
+ ivec2 getOutputCoords() {
793
+ ivec2 resTexRC = ivec2(resultUV.yx *
794
+ vec2(${t[0]}, ${t[1]}));
795
+ int index = resTexRC.x * ${t[1]} + resTexRC.y;
796
+ int r = index / ${e[1]};
797
+ int c = index - r * ${e[1]};
798
+ return ivec2(r, c);
799
+ }
800
+ `;
801
+ }
802
+ function G(e) {
803
+ return `offset${e}`;
804
+ }
805
+ function ut(e) {
806
+ let t = e.name;
807
+ return `
808
+ vec4 ${"get" + t.charAt(0).toUpperCase() + t.slice(1)}() {
809
+ return ${R().texture2D}(${t}, halfCR);
810
+ }
811
+ `;
812
+ }
813
+ function dt(e, t) {
814
+ let n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1);
815
+ if (e.shapeInfo.isUniform) return `float ${r}() {return ${n};}`;
816
+ let [i, a] = e.shapeInfo.texShape;
817
+ if (i === 1 && a === 1) return `
818
+ float ${r}() {
819
+ return sampleTexture(${n}, halfCR);
820
+ }
821
+ `;
822
+ let o = G(n);
823
+ if (t) return `
824
+ float ${r}() {
825
+ vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], ${o});
826
+ return sampleTexture(${n}, uv);
827
+ }
828
+ `;
829
+ let [s, c] = e.shapeInfo.texShape;
830
+ return `
831
+ float ${r}() {
832
+ vec2 uv = uvFromFlat(${s}, ${c}, ${o});
833
+ return sampleTexture(${n}, uv);
834
+ }
835
+ `;
836
+ }
837
+ function ft(e, t) {
838
+ let n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), i = e.shapeInfo.texShape, a = R();
839
+ if (t) return `
840
+ vec4 ${r}(int index) {
841
+ ivec2 packedTexShape = ivec2(ceil(float(${n}TexShape[0]) / 2.0), ceil(float(${n}TexShape[1]) / 2.0));
842
+ vec2 uv = packedUVfrom1D(
843
+ packedTexShape[0], packedTexShape[1], index);
844
+ return ${a.texture2D}(${n}, uv);
845
+ }
846
+ `;
847
+ let o = [Math.ceil(i[0] / 2), Math.ceil(i[1] / 2)];
848
+ return `
849
+ vec4 ${r}(int index) {
850
+ vec2 uv = packedUVfrom1D(
851
+ ${o[0]}, ${o[1]}, index);
852
+ return ${a.texture2D}(${n}, uv);
853
+ }
854
+ `;
855
+ }
856
+ function pt(e, t) {
857
+ let n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1);
858
+ if (e.shapeInfo.isUniform) return `
859
+ float ${r}(int index) {
860
+ ${q(e)}
861
+ }
862
+ `;
863
+ let i = e.shapeInfo.texShape, a = i[0], o = i[1];
864
+ if (o === 1 && a === 1) return `
865
+ float ${r}(int index) {
866
+ return sampleTexture(${n}, halfCR);
867
+ }
868
+ `;
869
+ let s = G(n);
870
+ return o === 1 ? t ? `
871
+ float ${r}(int index) {
872
+ vec2 uv = vec2(0.5, (float(index + ${s}) + 0.5) / float(${n}TexShape[0]));
873
+ return sampleTexture(${n}, uv);
874
+ }
875
+ ` : `
876
+ float ${r}(int index) {
877
+ vec2 uv = vec2(0.5, (float(index + ${s}) + 0.5) / ${a}.0);
878
+ return sampleTexture(${n}, uv);
879
+ }
880
+ ` : a === 1 ? t ? `
881
+ float ${r}(int index) {
882
+ vec2 uv = vec2((float(index + ${s}) + 0.5) / float(${n}TexShape[1]), 0.5);
883
+ return sampleTexture(${n}, uv);
884
+ }
885
+ ` : `
886
+ float ${r}(int index) {
887
+ vec2 uv = vec2((float(index + ${s}) + 0.5) / ${o}.0, 0.5);
888
+ return sampleTexture(${n}, uv);
889
+ }
890
+ ` : t ? `
891
+ float ${r}(int index) {
892
+ vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], index + ${s});
893
+ return sampleTexture(${n}, uv);
894
+ }
895
+ ` : `
896
+ float ${r}(int index) {
897
+ vec2 uv = uvFromFlat(${a}, ${o}, index + ${s});
898
+ return sampleTexture(${n}, uv);
899
+ }
900
+ `;
901
+ }
902
+ function mt(e, t) {
903
+ let r = e.shapeInfo.logicalShape, i = e.name, a = "get" + i.charAt(0).toUpperCase() + i.slice(1), o = e.shapeInfo.texShape, s = o[0], c = o[1], l = R();
904
+ if (o != null && n(r, o)) return t ? `
905
+ vec4 ${a}(int row, int col) {
906
+ vec2 uv = (vec2(col, row) + halfCR) / vec2(${i}TexShape[1], ${i}TexShape[0]);
907
+
908
+ return ${l.texture2D}(${i}, uv);
909
+ }
910
+ ` : `
911
+ vec4 ${a}(int row, int col) {
912
+ vec2 uv = (vec2(col, row) + halfCR) / vec2(${c}.0, ${s}.0);
913
+
914
+ return ${l.texture2D}(${i}, uv);
915
+ }
916
+ `;
917
+ if (t) return `
918
+ vec4 ${a}(int row, int col) {
919
+ ivec2 packedTexShape = ivec2(ceil(float(${i}TexShape[0]) / 2.0), ceil(float(${i}TexShape[1]) / 2.0));
920
+ int valuesPerRow = int(ceil(float(${i}Shape[1]) / 2.0));
921
+ vec2 uv = packedUVfrom2D(valuesPerRow, packedTexShape[0], packedTexShape[1], row, col);
922
+ return ${l.texture2D}(${i}, uv);
923
+ }
924
+ `;
925
+ let u = [Math.ceil(o[0] / 2), Math.ceil(o[1] / 2)];
926
+ return `
927
+ vec4 ${a}(int row, int col) {
928
+ vec2 uv = packedUVfrom2D(${Math.ceil(r[1] / 2)}, ${u[0]}, ${u[1]}, row, col);
929
+ return ${l.texture2D}(${i}, uv);
930
+ }
931
+ `;
932
+ }
933
+ function ht(e, t) {
934
+ let r = e.shapeInfo.logicalShape, i = e.name, o = "get" + i.charAt(0).toUpperCase() + i.slice(1), s = e.shapeInfo.texShape;
935
+ if (s != null && n(r, s)) {
936
+ if (t) return `
937
+ float ${o}(int row, int col) {
938
+ vec2 uv = (vec2(col, row) + halfCR) / vec2(${i}TexShape[1], ${i}TexShape[0]);
939
+ return sampleTexture(${i}, uv);
940
+ }
941
+ `;
942
+ let e = s[0];
943
+ return `
944
+ float ${o}(int row, int col) {
945
+ vec2 uv = (vec2(col, row) + halfCR) / vec2(${s[1]}.0, ${e}.0);
946
+ return sampleTexture(${i}, uv);
947
+ }
948
+ `;
949
+ }
950
+ let { newShape: c, keptDims: l } = a(r), u = c;
951
+ if (u.length < r.length) return `
952
+ ${H(X(e, u), t)}
953
+ float ${o}(int row, int col) {
954
+ return ${o}(${Z(["row", "col"], l)});
955
+ }
956
+ `;
957
+ if (e.shapeInfo.isUniform) return `
958
+ float ${o}(int row, int col) {
959
+ int index = round(dot(vec2(row, col), vec2(${r[1]}, 1)));
960
+ ${q(e)}
961
+ }
962
+ `;
963
+ let d = s[0], f = s[1], p = G(i);
964
+ return f === 1 ? t ? `
965
+ float ${o}(int row, int col) {
966
+ float index = dot(vec3(row, col, ${p}), vec3(${i}Shape[1], 1, 1));
967
+ vec2 uv = vec2(0.5, (index + 0.5) / float(${i}TexShape[0]));
968
+ return sampleTexture(${i}, uv);
969
+ }
970
+ ` : `
971
+ float ${o}(int row, int col) {
972
+ float index = dot(vec3(row, col, ${p}), vec3(${r[1]}, 1, 1));
973
+ vec2 uv = vec2(0.5, (index + 0.5) / ${d}.0);
974
+ return sampleTexture(${i}, uv);
975
+ }
976
+ ` : d === 1 ? t ? `
977
+ float ${o}(int row, int col) {
978
+ float index = dot(vec3(row, col, ${p}), vec3(${i}Shape[1], 1, 1));
979
+ vec2 uv = vec2((index + 0.5) / float(${i}TexShape[1]), 0.5);
980
+ return sampleTexture(${i}, uv);
981
+ }
982
+ ` : `
983
+ float ${o}(int row, int col) {
984
+ float index = dot(vec3(row, col, ${p}), vec3(${r[1]}, 1, 1));
985
+ vec2 uv = vec2((index + 0.5) / ${f}.0, 0.5);
986
+ return sampleTexture(${i}, uv);
987
+ }
988
+ ` : t ? `
989
+ float ${o}(int row, int col) {
990
+ // Explicitly use integer operations as dot() only works on floats.
991
+ int index = row * ${i}Shape[1] + col + ${p};
992
+ vec2 uv = uvFromFlat(${i}TexShape[0], ${i}TexShape[1], index);
993
+ return sampleTexture(${i}, uv);
994
+ }
995
+ ` : `
996
+ float ${o}(int row, int col) {
997
+ // Explicitly use integer operations as dot() only works on floats.
998
+ int index = row * ${r[1]} + col + ${p};
999
+ vec2 uv = uvFromFlat(${d}, ${f}, index);
1000
+ return sampleTexture(${i}, uv);
1001
+ }
1002
+ `;
1003
+ }
1004
+ function gt(e, t) {
1005
+ let n = e.shapeInfo.logicalShape, r = e.name, i = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = e.shapeInfo.texShape, o = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)];
1006
+ if (n[0] === 1) return `
1007
+ ${U(X(e, n.slice(1)), t)}
1008
+ vec4 ${i}(int b, int row, int col) {
1009
+ return ${i}(${Z([
1010
+ "b",
1011
+ "row",
1012
+ "col"
1013
+ ], [1, 2])});
1014
+ }
1015
+ `;
1016
+ let s = R();
1017
+ if (t) return `
1018
+ vec4 ${i}(int b, int row, int col) {
1019
+ ivec2 packedTexShape = ivec2(ceil(float(${r}TexShape[0]) / 2.0), ceil(float(${r}TexShape[1]) / 2.0));
1020
+ int valuesPerRow = int(ceil(float(${r}Shape[2]) / 2.0));
1021
+ int texelsInBatch = valuesPerRow * int(ceil(float(${r}Shape[1]) / 2.0));
1022
+ vec2 uv = packedUVfrom3D(
1023
+ packedTexShape[0], packedTexShape[1], texelsInBatch, valuesPerRow, b, row, col);
1024
+ return ${s.texture2D}(${r}, uv);
1025
+ }
1026
+ `;
1027
+ let c = o[0], l = o[1], u = Math.ceil(n[2] / 2);
1028
+ return `
1029
+ vec4 ${i}(int b, int row, int col) {
1030
+ vec2 uv = packedUVfrom3D(
1031
+ ${c}, ${l}, ${u * Math.ceil(n[1] / 2)}, ${u}, b, row, col);
1032
+ return ${s.texture2D}(${r}, uv);
1033
+ }
1034
+ `;
1035
+ }
1036
+ function _t(e, t) {
1037
+ let n = e.shapeInfo.logicalShape, r = e.name, i = "get" + r.charAt(0).toUpperCase() + r.slice(1), o = n[1] * n[2], s = n[2], { newShape: c, keptDims: l } = a(n), u = c;
1038
+ if (u.length < n.length) return `
1039
+ ${H(X(e, u), t)}
1040
+ float ${i}(int row, int col, int depth) {
1041
+ return ${i}(${Z([
1042
+ "row",
1043
+ "col",
1044
+ "depth"
1045
+ ], l)});
1046
+ }
1047
+ `;
1048
+ if (e.shapeInfo.isUniform) return `
1049
+ float ${i}(int row, int col, int depth) {
1050
+ int index = round(dot(vec3(row, col, depth),
1051
+ vec3(${o}, ${s}, 1)));
1052
+ ${q(e)}
1053
+ }
1054
+ `;
1055
+ let d = e.shapeInfo.texShape, f = d[0], p = d[1], m = e.shapeInfo.flatOffset;
1056
+ if (p === o && m == null) return t ? `
1057
+ float ${i}(int row, int col, int depth) {
1058
+ int stride1 = ${r}Shape[2];
1059
+ float texR = float(row);
1060
+ float texC = dot(vec2(col, depth), vec2(stride1, 1));
1061
+ vec2 uv = (vec2(texC, texR) + halfCR) /
1062
+ vec2(${r}TexShape[1], ${r}TexShape[0]);
1063
+ return sampleTexture(${r}, uv);
1064
+ }
1065
+ ` : `
1066
+ float ${i}(int row, int col, int depth) {
1067
+ float texR = float(row);
1068
+ float texC = dot(vec2(col, depth), vec2(${s}, 1));
1069
+ vec2 uv = (vec2(texC, texR) + halfCR) /
1070
+ vec2(${p}.0, ${f}.0);
1071
+ return sampleTexture(${r}, uv);
1072
+ }
1073
+ `;
1074
+ if (p === s && m == null) return t ? `
1075
+ float ${i}(int row, int col, int depth) {
1076
+ float texR = dot(vec2(row, col), vec2(${r}Shape[1], 1));
1077
+ float texC = float(depth);
1078
+ vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
1079
+ return sampleTexture(${r}, uv);
1080
+ }
1081
+ ` : `
1082
+ float ${i}(int row, int col, int depth) {
1083
+ float texR = dot(vec2(row, col), vec2(${n[1]}, 1));
1084
+ float texC = float(depth);
1085
+ vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${p}.0, ${f}.0);
1086
+ return sampleTexture(${r}, uv);
1087
+ }
1088
+ `;
1089
+ let h = G(r);
1090
+ return t ? `
1091
+ float ${i}(int row, int col, int depth) {
1092
+ // Explicitly use integer operations as dot() only works on floats.
1093
+ int stride0 = ${r}Shape[1] * ${r}Shape[2];
1094
+ int stride1 = ${r}Shape[2];
1095
+ int index = row * stride0 + col * stride1 + depth + ${h};
1096
+ vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index);
1097
+ return sampleTexture(${r}, uv);
1098
+ }
1099
+ ` : `
1100
+ float ${i}(int row, int col, int depth) {
1101
+ // Explicitly use integer operations as dot() only works on floats.
1102
+ int index = row * ${o} + col * ${s} + depth + ${h};
1103
+ vec2 uv = uvFromFlat(${f}, ${p}, index);
1104
+ return sampleTexture(${r}, uv);
1105
+ }
1106
+ `;
1107
+ }
1108
+ function vt(e, t) {
1109
+ let n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), i = R();
1110
+ if (t) return `
1111
+ vec4 ${r}(int b2, int b, int row, int col) {
1112
+ int valuesPerRow = int(ceil(float(${n}Shape[3]) / 2.0));
1113
+ int texelsInBatch = valuesPerRow * int(ceil(float(${n}Shape[2]) / 2.0));
1114
+ int index = b * texelsInBatch + (row / 2) * valuesPerRow + (col / 2);
1115
+ texelsInBatch *= ${n}Shape[1];
1116
+ index = b2 * texelsInBatch + index;
1117
+ ivec2 packedTexShape = ivec2(ceil(float(${n}TexShape[0]) / 2.0), ceil(float(${n}TexShape[1]) / 2.0));
1118
+ int texR = index / packedTexShape[1];
1119
+ int texC = index - texR * packedTexShape[1];
1120
+ vec2 uv = (vec2(texC, texR) + halfCR) / vec2(packedTexShape[1], packedTexShape[0]); return ${i.texture2D}(${n}, uv);
1121
+ }
1122
+ `;
1123
+ let a = e.shapeInfo.logicalShape, o = a.length, s = e.shapeInfo.texShape, c = [Math.ceil(s[0] / 2), Math.ceil(s[1] / 2)], l = c[0], u = c[1], d = Math.ceil(a[o - 1] / 2), f = d * Math.ceil(a[o - 2] / 2), p = "int b, int row, int col", m = `b * ${f} + (row / 2) * ${d} + (col / 2)`;
1124
+ for (let e = 2; e < o - 1; e++) p = `int b${e}, ` + p, f *= a[o - e - 1], m = `b${e} * ${f} + ` + m;
1125
+ return `
1126
+ vec4 ${r}(${p}) {
1127
+ int index = ${m};
1128
+ int texR = index / ${u};
1129
+ int texC = index - texR * ${u};
1130
+ vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${u}, ${l});
1131
+ return ${i.texture2D}(${n}, uv);
1132
+ }
1133
+ `;
1134
+ }
1135
+ function yt(e, t) {
1136
+ let n = e.shapeInfo.logicalShape, r = e.name, i = "get" + r.charAt(0).toUpperCase() + r.slice(1), o = n[3], s = n[2] * o, c = n[1] * s, { newShape: l, keptDims: u } = a(n);
1137
+ if (l.length < n.length) return `
1138
+ ${H(X(e, l), t)}
1139
+ float ${i}(int row, int col, int depth, int depth2) {
1140
+ return ${i}(${Z([
1141
+ "row",
1142
+ "col",
1143
+ "depth",
1144
+ "depth2"
1145
+ ], u)});
1146
+ }
1147
+ `;
1148
+ if (e.shapeInfo.isUniform) return `
1149
+ float ${i}(int row, int col, int depth, int depth2) {
1150
+ int index = round(dot(vec4(row, col, depth, depth2),
1151
+ vec4(${c}, ${s}, ${o}, 1)));
1152
+ ${q(e)}
1153
+ }
1154
+ `;
1155
+ let d = e.shapeInfo.flatOffset, f = e.shapeInfo.texShape, p = f[0], m = f[1], h = `int stride2 = ${r}Shape[3];`, g = `int stride1 = ${r}Shape[2] * stride2;`, _ = `int stride0 = ${r}Shape[1] * stride1;`;
1156
+ if (m === c && d == null) return t ? `
1157
+ float ${i}(int row, int col, int depth, int depth2) {
1158
+ ${h}
1159
+ ${g}
1160
+ float texR = float(row);
1161
+ float texC =
1162
+ dot(vec3(col, depth, depth2),
1163
+ vec3(stride1, stride2, 1));
1164
+ vec2 uv = (vec2(texC, texR) + halfCR) /
1165
+ vec2(${r}TexShape[1], ${r}TexShape[0]);
1166
+ return sampleTexture(${r}, uv);
1167
+ }
1168
+ ` : `
1169
+ float ${i}(int row, int col, int depth, int depth2) {
1170
+ float texR = float(row);
1171
+ float texC =
1172
+ dot(vec3(col, depth, depth2),
1173
+ vec3(${s}, ${o}, 1));
1174
+ vec2 uv = (vec2(texC, texR) + halfCR) /
1175
+ vec2(${m}.0, ${p}.0);
1176
+ return sampleTexture(${r}, uv);
1177
+ }
1178
+ `;
1179
+ if (m === o && d == null) return t ? `
1180
+ float ${i}(int row, int col, int depth, int depth2) {
1181
+ float texR = dot(vec3(row, col, depth),
1182
+ vec3(${r}Shape[1] * ${r}Shape[2], ${r}Shape[2], 1));
1183
+ float texC = float(depth2);
1184
+ vec2 uv = (vec2(texC, texR) + halfCR) /
1185
+ vec2(${r}TexShape[1], ${r}TexShape[0]);
1186
+ return sampleTexture(${r}, uv);
1187
+ }
1188
+ ` : `
1189
+ float ${i}(int row, int col, int depth, int depth2) {
1190
+ float texR = dot(vec3(row, col, depth),
1191
+ vec3(${n[1] * n[2]}, ${n[2]}, 1));
1192
+ float texC = float(depth2);
1193
+ vec2 uv = (vec2(texC, texR) + halfCR) /
1194
+ vec2(${m}.0, ${p}.0);
1195
+ return sampleTexture(${r}, uv);
1196
+ }
1197
+ `;
1198
+ let v = G(r);
1199
+ return t ? `
1200
+ float ${i}(int row, int col, int depth, int depth2) {
1201
+ // Explicitly use integer operations as dot() only works on floats.
1202
+ ${h}
1203
+ ${g}
1204
+ ${_}
1205
+ int index = row * stride0 + col * stride1 +
1206
+ depth * stride2 + depth2;
1207
+ vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index + ${v});
1208
+ return sampleTexture(${r}, uv);
1209
+ }
1210
+ ` : `
1211
+ float ${i}(int row, int col, int depth, int depth2) {
1212
+ // Explicitly use integer operations as dot() only works on floats.
1213
+ int index = row * ${c} + col * ${s} +
1214
+ depth * ${o} + depth2;
1215
+ vec2 uv = uvFromFlat(${p}, ${m}, index + ${v});
1216
+ return sampleTexture(${r}, uv);
1217
+ }
1218
+ `;
1219
+ }
1220
+ function K(e) {
1221
+ let t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), i = t[4], o = t[3] * i, s = t[2] * o, c = t[1] * s, { newShape: l, keptDims: u } = a(t);
1222
+ if (l.length < t.length) return `
1223
+ ${H(X(e, l))}
1224
+ float ${r}(int row, int col, int depth, int depth2, int depth3) {
1225
+ return ${r}(${Z([
1226
+ "row",
1227
+ "col",
1228
+ "depth",
1229
+ "depth2",
1230
+ "depth3"
1231
+ ], u)});
1232
+ }
1233
+ `;
1234
+ if (e.shapeInfo.isUniform) return `
1235
+ float ${r}(int row, int col, int depth, int depth2, int depth3) {
1236
+ float index = dot(
1237
+ vec4(row, col, depth, depth2),
1238
+ vec4(${c}, ${s}, ${o}, ${i})) +
1239
+ depth3;
1240
+ ${q(e)}
1241
+ }
1242
+ `;
1243
+ let d = e.shapeInfo.flatOffset, f = e.shapeInfo.texShape, p = f[0], m = f[1];
1244
+ return m === c && d == null ? `
1245
+ float ${r}(int row, int col, int depth, int depth2, int depth3) {
1246
+ int texR = row;
1247
+ float texC = dot(vec4(col, depth, depth2, depth3),
1248
+ vec4(${s}, ${o}, ${i}, 1));
1249
+ vec2 uv = (vec2(texC, texR) + halfCR) /
1250
+ vec2(${m}.0, ${p}.0);
1251
+ return sampleTexture(${n}, uv);
1252
+ }
1253
+ ` : m === i && d == null ? `
1254
+ float ${r}(int row, int col, int depth, int depth2, int depth3) {
1255
+ float texR = dot(
1256
+ vec4(row, col, depth, depth2),
1257
+ vec4(${t[1] * t[2] * t[3]},
1258
+ ${t[2] * t[3]}, ${t[3]}, 1));
1259
+ int texC = depth3;
1260
+ vec2 uv = (vec2(texC, texR) + halfCR) /
1261
+ vec2(${m}.0, ${p}.0);
1262
+ return sampleTexture(${n}, uv);
1263
+ }
1264
+ ` : `
1265
+ float ${r}(int row, int col, int depth, int depth2, int depth3) {
1266
+ // Explicitly use integer operations as dot() only works on floats.
1267
+ int index = row * ${c} + col * ${s} + depth * ${o} +
1268
+ depth2 * ${i} + depth3 + ${G(n)};
1269
+ vec2 uv = uvFromFlat(${p}, ${m}, index);
1270
+ return sampleTexture(${n}, uv);
1271
+ }
1272
+ `;
1273
+ }
1274
+ function bt(e) {
1275
+ let t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), { newShape: i, keptDims: o } = a(t);
1276
+ if (i.length < t.length) return `
1277
+ ${H(X(e, i))}
1278
+ float ${r}(int row, int col, int depth,
1279
+ int depth2, int depth3, int depth4) {
1280
+ return ${r}(${Z([
1281
+ "row",
1282
+ "col",
1283
+ "depth",
1284
+ "depth2",
1285
+ "depth3",
1286
+ "depth4"
1287
+ ], o)});
1288
+ }
1289
+ `;
1290
+ let s = t[5], c = t[4] * s, l = t[3] * c, u = t[2] * l, d = t[1] * u;
1291
+ if (e.shapeInfo.isUniform) return `
1292
+ float ${r}(int row, int col, int depth,
1293
+ int depth2, int depth3, int depth4) {
1294
+ int index = round(dot(
1295
+ vec4(row, col, depth, depth2),
1296
+ vec4(${d}, ${u}, ${l}, ${c})) +
1297
+ dot(
1298
+ vec2(depth3, depth4),
1299
+ vec2(${s}, 1)));
1300
+ ${q(e)}
1301
+ }
1302
+ `;
1303
+ let f = e.shapeInfo.flatOffset, p = e.shapeInfo.texShape, m = p[0], h = p[1];
1304
+ return h === d && f == null ? `
1305
+ float ${r}(int row, int col, int depth,
1306
+ int depth2, int depth3, int depth4) {
1307
+ int texR = row;
1308
+ float texC = dot(vec4(col, depth, depth2, depth3),
1309
+ vec4(${u}, ${l}, ${c}, ${s})) +
1310
+ float(depth4);
1311
+ vec2 uv = (vec2(texC, texR) + halfCR) /
1312
+ vec2(${h}.0, ${m}.0);
1313
+ return sampleTexture(${n}, uv);
1314
+ }
1315
+ ` : h === s && f == null ? `
1316
+ float ${r}(int row, int col, int depth,
1317
+ int depth2, int depth3, int depth4) {
1318
+ float texR = dot(vec4(row, col, depth, depth2),
1319
+ vec4(${t[1] * t[2] * t[3] * t[4]},
1320
+ ${t[2] * t[3] * t[4]},
1321
+ ${t[3] * t[4]},
1322
+ ${t[4]})) + float(depth3);
1323
+ int texC = depth4;
1324
+ vec2 uv = (vec2(texC, texR) + halfCR) /
1325
+ vec2(${h}.0, ${m}.0);
1326
+ return sampleTexture(${n}, uv);
1327
+ }
1328
+ ` : `
1329
+ float ${r}(int row, int col, int depth,
1330
+ int depth2, int depth3, int depth4) {
1331
+ // Explicitly use integer operations as dot() only works on floats.
1332
+ int index = row * ${d} + col * ${u} + depth * ${l} +
1333
+ depth2 * ${c} + depth3 * ${s} + depth4 + ${G(n)};
1334
+ vec2 uv = uvFromFlat(${m}, ${h}, index);
1335
+ return sampleTexture(${n}, uv);
1336
+ }
1337
+ `;
1338
+ }
1339
+ function q(e) {
1340
+ let t = e.name, n = s(e.shapeInfo.logicalShape);
1341
+ return n < 2 ? `return ${t};` : `
1342
+ for (int i = 0; i < ${n}; i++) {
1343
+ if (i == index) {
1344
+ return ${t}[i];
1345
+ }
1346
+ }
1347
+ `;
1348
+ }
1349
+ function xt(e, t) {
1350
+ let n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), i = "get" + r + "AtOutCoords", a = e.shapeInfo.logicalShape.length, o = t.logicalShape.length, c = V(e.shapeInfo.logicalShape, t.logicalShape), l = J(o), u = o - a, d, f = [
1351
+ "x",
1352
+ "y",
1353
+ "z",
1354
+ "w",
1355
+ "u",
1356
+ "v"
1357
+ ];
1358
+ d = a === 0 ? "" : o < 2 && c.length >= 1 ? "coords = 0;" : c.map((e) => `coords.${f[e + u]} = 0;`).join("\n");
1359
+ let p = "";
1360
+ p = o < 2 && a > 0 ? "coords" : e.shapeInfo.logicalShape.map((e, t) => `coords.${f[t + u]}`).join(", ");
1361
+ let m = "return outputValue;", h = s(e.shapeInfo.logicalShape) === 1, g = s(t.logicalShape) === 1;
1362
+ if (a === 1 && !h && !g) m = "\n return vec4(outputValue.xy, outputValue.xy);\n ";
1363
+ else if (h && !g) m = o === 1 ? "\n return vec4(outputValue.x, outputValue.x, 0., 0.);\n " : "\n return vec4(outputValue.x);\n ";
1364
+ else if (c.length) {
1365
+ let e = a - 2, t = a - 1;
1366
+ c.indexOf(e) > -1 && c.indexOf(t) > -1 ? m = "return vec4(outputValue.x);" : c.indexOf(e) > -1 ? m = "return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);" : c.indexOf(t) > -1 && (m = "return vec4(outputValue.xx, outputValue.zz);");
1367
+ }
1368
+ return `
1369
+ vec4 ${i}() {
1370
+ ${l} coords = getOutputCoords();
1371
+ ${d}
1372
+ vec4 outputValue = get${r}(${p});
1373
+ ${m}
1374
+ }
1375
+ `;
1376
+ }
1377
+ function St(e, t) {
1378
+ let r = e.name, i = r.charAt(0).toUpperCase() + r.slice(1), a = "get" + i + "AtOutCoords", o = t.texShape, s = e.shapeInfo.texShape, c = e.shapeInfo.logicalShape.length, l = t.logicalShape.length;
1379
+ if (!e.shapeInfo.isUniform && c === l && e.shapeInfo.flatOffset == null && n(s, o)) return `
1380
+ float ${a}() {
1381
+ return sampleTexture(${r}, resultUV);
1382
+ }
1383
+ `;
1384
+ let u = J(l), d = V(e.shapeInfo.logicalShape, t.logicalShape), f = l - c, p, m = [
1385
+ "x",
1386
+ "y",
1387
+ "z",
1388
+ "w",
1389
+ "u",
1390
+ "v"
1391
+ ];
1392
+ p = c === 0 ? "" : l < 2 && d.length >= 1 ? "coords = 0;" : d.map((e) => `coords.${m[e + f]} = 0;`).join("\n");
1393
+ let h = "";
1394
+ return h = l < 2 && c > 0 ? "coords" : e.shapeInfo.logicalShape.map((e, t) => `coords.${m[t + f]}`).join(", "), `
1395
+ float ${a}() {
1396
+ ${u} coords = getOutputCoords();
1397
+ ${p}
1398
+ return get${i}(${h});
1399
+ }
1400
+ `;
1401
+ }
1402
+ function J(e) {
1403
+ if (e <= 1) return "int";
1404
+ if (e === 2) return "ivec2";
1405
+ if (e === 3) return "ivec3";
1406
+ if (e === 4) return "ivec4";
1407
+ if (e === 5) return "ivec5";
1408
+ if (e === 6) return "ivec6";
1409
+ throw Error(`GPU for rank ${e} is not yet supported`);
1410
+ }
1411
+ function Y(e, t, r) {
1412
+ let { newShape: i, keptDims: o } = a(t), s = t.length, c = e && s === 3 && t[0] === 1, l = c ? t.slice(1) : i, u = !e && s > 1 && !n(t, r) && i.length < s || c;
1413
+ return {
1414
+ useSqueezeShape: u,
1415
+ uniformShape: u ? l : t,
1416
+ keptDims: o
1417
+ };
1418
+ }
1419
+ function X(e, t) {
1420
+ let n = JSON.parse(JSON.stringify(e));
1421
+ return n.shapeInfo.logicalShape = t, n;
1422
+ }
1423
+ function Z(e, t) {
1424
+ return t.map((t) => e[t]).join(", ");
1425
+ }
1426
+ //#endregion
1427
+ //#region node_modules/@tensorflow/tfjs-backend-webgl/dist/gpgpu_math.js
1428
+ function Ct(e, n, r, i) {
1429
+ let a = r.map((e, t) => {
1430
+ let r = {
1431
+ logicalShape: e.shape,
1432
+ texShape: e.isUniform ? null : e.texData.texShape,
1433
+ isUniform: e.isUniform,
1434
+ isPacked: e.isUniform ? !1 : e.texData.isPacked,
1435
+ flatOffset: null
1436
+ };
1437
+ return e.texData != null && e.texData.slice != null && e.texData.slice.flatOffset > 0 && (r.flatOffset = e.texData.slice.flatOffset), {
1438
+ name: n.variableNames[t],
1439
+ shapeInfo: r
1440
+ };
1441
+ }), o = a.map((e) => e.shapeInfo), s = {
1442
+ logicalShape: i.shape,
1443
+ texShape: i.texData.texShape,
1444
+ isUniform: !1,
1445
+ isPacked: i.texData.isPacked,
1446
+ flatOffset: null
1447
+ }, c = He(a, s, n), l = ce(e.gl, c), u = e.createProgram(l);
1448
+ return t().get("ENGINE_COMPILE_ONLY") ? {
1449
+ program: n,
1450
+ fragmentShader: l,
1451
+ source: c,
1452
+ webGLProgram: u,
1453
+ inShapeInfos: o,
1454
+ outShapeInfo: s,
1455
+ variablesLocations: null,
1456
+ customUniformLocations: null,
1457
+ infLoc: null,
1458
+ nanLoc: null,
1459
+ outShapeLocation: null,
1460
+ outShapeStridesLocation: null,
1461
+ outTexShapeLocation: null
1462
+ } : (e.buildVao(u), Object.assign({
1463
+ program: n,
1464
+ fragmentShader: l,
1465
+ source: c,
1466
+ webGLProgram: u,
1467
+ inShapeInfos: o,
1468
+ outShapeInfo: s
1469
+ }, Q(e, n, u)));
1470
+ }
1471
+ function Q(e, n, r) {
1472
+ let i = [], a = [], o, s, c, l = null, u = null;
1473
+ u = e.getUniformLocation(r, "NAN", !1), t().getNumber("WEBGL_VERSION") === 1 && (l = e.getUniformLocation(r, "INFINITY", !1));
1474
+ for (let t of n.variableNames) {
1475
+ let a = {
1476
+ name: t,
1477
+ uniform: e.getUniformLocation(r, t, !1),
1478
+ offset: e.getUniformLocation(r, `offset${t}`, !1)
1479
+ };
1480
+ n.enableShapeUniforms && (a.shape = e.getUniformLocation(r, `${t}Shape`, !1), a.texShape = e.getUniformLocation(r, `${t}TexShape`, !1)), i.push(a);
1481
+ }
1482
+ if (n.enableShapeUniforms && (o = e.getUniformLocation(r, "outShape", !1), c = e.getUniformLocation(r, "outShapeStrides", !1), s = e.getUniformLocation(r, "outTexShape", !1)), n.customUniforms) for (let t of n.customUniforms) a.push(e.getUniformLocation(r, t.name, !1));
1483
+ return {
1484
+ variablesLocations: i,
1485
+ customUniformLocations: a,
1486
+ infLoc: l,
1487
+ nanLoc: u,
1488
+ outShapeLocation: o,
1489
+ outShapeStridesLocation: c,
1490
+ outTexShapeLocation: s
1491
+ };
1492
+ }
1493
+ function $(e, t) {
1494
+ if (e.length !== t.length) throw Error(`Binary was compiled with ${e.length} inputs, but was executed with ${t.length} inputs`);
1495
+ e.forEach((e, r) => {
1496
+ let i = e.logicalShape, a = t[r], o = a.shape;
1497
+ if (!n(i, o)) throw Error(`Binary was compiled with different shapes than the current args. Shapes ${i} and ${o} must match`);
1498
+ if (e.isUniform && a.isUniform) return;
1499
+ let s = e.texShape, c = a.isUniform ? null : a.texData.texShape;
1500
+ if (!n(s, c)) throw Error(`Binary was compiled with different texture shapes than the current args. Shape ${s} and ${c} must match`);
1501
+ });
1502
+ }
1503
+ function wt(e, n, r, a, o) {
1504
+ n.program.enableShapeUniforms || ($(n.inShapeInfos, r), $([n.outShapeInfo], [a]));
1505
+ let c = a.texData.texture, l = a.texData.texShape;
1506
+ a.texData.isPacked ? e.setOutputPackedMatrixTexture(c.texture, l[0], l[1]) : e.setOutputMatrixTexture(c.texture, l[0], l[1]), e.setProgram(n.webGLProgram), e.bindVertexArray(n.webGLProgram.vao), t().getNumber("WEBGL_VERSION") === 1 && n.infLoc !== null && e.gl.uniform1f(n.infLoc, Infinity), n.nanLoc !== null && e.gl.uniform1f(n.nanLoc, NaN);
1507
+ for (let t = 0; t < r.length; ++t) {
1508
+ let i = r[t], { uniform: a, offset: o, shape: c, texShape: l } = n.variablesLocations[t];
1509
+ if (c) {
1510
+ let { uniformShape: t } = Y(n.program.packedInputs, i.shape, i.texData.texShape);
1511
+ switch (t.length) {
1512
+ case 1:
1513
+ e.gl.uniform1iv(c, new Int32Array(t));
1514
+ break;
1515
+ case 2:
1516
+ e.gl.uniform2iv(c, new Int32Array(t));
1517
+ break;
1518
+ case 3:
1519
+ e.gl.uniform3iv(c, new Int32Array(t));
1520
+ break;
1521
+ case 4:
1522
+ e.gl.uniform4iv(c, new Int32Array(t));
1523
+ break;
1524
+ default: break;
1525
+ }
1526
+ }
1527
+ if (l && e.gl.uniform2i(l, i.texData.texShape[0], i.texData.texShape[1]), a != null) {
1528
+ if (i.isUniform) {
1529
+ if (s(i.shape) < 2) e.gl.uniform1f(a, i.uniformValues[0]);
1530
+ else {
1531
+ let t = i.uniformValues;
1532
+ t instanceof Float32Array || (t = new Float32Array(t)), e.gl.uniform1fv(a, t);
1533
+ }
1534
+ continue;
1535
+ }
1536
+ i.texData.slice != null && o != null && e.gl.uniform1i(o, i.texData.slice.flatOffset), e.setInputMatrixTexture(i.texData.texture.texture, a, t);
1537
+ }
1538
+ }
1539
+ let u = n.outShapeLocation;
1540
+ if (u) switch (a.shape.length) {
1541
+ case 1:
1542
+ e.gl.uniform1iv(u, new Int32Array(a.shape));
1543
+ break;
1544
+ case 2:
1545
+ e.gl.uniform2iv(u, new Int32Array(a.shape));
1546
+ break;
1547
+ case 3:
1548
+ e.gl.uniform3iv(u, new Int32Array(a.shape));
1549
+ break;
1550
+ case 4:
1551
+ e.gl.uniform4iv(u, new Int32Array(a.shape));
1552
+ break;
1553
+ default: break;
1554
+ }
1555
+ if (n.outShapeStridesLocation) {
1556
+ let t = i(a.shape);
1557
+ switch (a.shape.length) {
1558
+ case 2:
1559
+ e.gl.uniform1iv(n.outShapeStridesLocation, new Int32Array(t));
1560
+ break;
1561
+ case 3:
1562
+ e.gl.uniform2iv(n.outShapeStridesLocation, new Int32Array(t));
1563
+ break;
1564
+ case 4:
1565
+ e.gl.uniform3iv(n.outShapeStridesLocation, new Int32Array(t));
1566
+ break;
1567
+ default: break;
1568
+ }
1569
+ }
1570
+ if (n.outTexShapeLocation && e.gl.uniform2i(n.outTexShapeLocation, a.texData.texShape[0], a.texData.texShape[1]), n.program.customUniforms && o) for (let t = 0; t < n.program.customUniforms.length; ++t) {
1571
+ let r = n.program.customUniforms[t], i = n.customUniformLocations[t], a = o[t];
1572
+ if (r.type === "float") e.gl.uniform1fv(i, a);
1573
+ else if (r.type === "vec2") e.gl.uniform2fv(i, a);
1574
+ else if (r.type === "vec3") e.gl.uniform3fv(i, a);
1575
+ else if (r.type === "vec4") e.gl.uniform4fv(i, a);
1576
+ else if (r.type === "int") e.gl.uniform1iv(i, a);
1577
+ else if (r.type === "ivec2") e.gl.uniform2iv(i, a);
1578
+ else if (r.type === "ivec3") e.gl.uniform3iv(i, a);
1579
+ else if (r.type === "ivec4") e.gl.uniform4iv(i, a);
1580
+ else throw Error(`uniform type ${r.type} is not supported yet.`);
1581
+ }
1582
+ e.executeProgram();
1583
+ }
1584
+ function Tt(r, a, o) {
1585
+ let c = "";
1586
+ a.concat(o).forEach((t) => {
1587
+ let a = t.texData != null && t.texData.slice != null && t.texData.slice.flatOffset > 0;
1588
+ if (r.enableShapeUniforms && !t.isUniform) {
1589
+ let l = t.texData.texShape, { useSqueezeShape: u, uniformShape: d, keptDims: f } = Y(r.packedInputs, t.shape, l), p = "", m = "", h = "";
1590
+ if (d.length === 1 && r.packedInputs) {
1591
+ let e = [Math.ceil(l[0] / 2), Math.ceil(l[1] / 2)];
1592
+ p = `${e[0] > 1}_${e[1] > 1}`;
1593
+ } else if (d.length === 2 && !r.packedInputs) m = `${d[0] > 1}_${d[1] > 1}`;
1594
+ else if (d.length > 2 && !r.packedInputs) {
1595
+ let e = i(d);
1596
+ h = `${e[0] === l[1]}_${e[e.length - 1] === l[1]}`;
1597
+ }
1598
+ let g = t.shape.length, _ = d.length === 2 && n(t.shape, l), v = s(t.shape) === 1, y = e(t.shape, o.shape), b = !r.packedInputs && g === o.shape.length && n(l, o.texData.texShape), x = r.packedInputs || d.length > 2 ? "" : `${l[0] > 1}_${l[1] > 1}`;
1599
+ c += `${g}_${b}_${u ? f : ""}_${d.length}_${v}_${y}_${_}_${p}_${m}_${h}_${x}_${a}`;
1600
+ } else {
1601
+ let e = t.isUniform ? "uniform" : t.texData.texShape;
1602
+ c += `${t.shape}_${e}_${a}`;
1603
+ }
1604
+ });
1605
+ let l = r.userCode, u = r.constructor.name;
1606
+ return u += "_" + c + "_" + l + `${t().getNumber("WEBGL_VERSION")}`, u;
1607
+ }
1608
+ function Et(e) {
1609
+ return t().getBool("WEBGL_USE_SHAPES_UNIFORMS") && e <= 4;
1610
+ }
1611
+ //#endregion
1612
+ export { C as $, be as A, Fe as B, pe as C, oe as D, j as E, Oe as F, O as G, de as H, I, _ as J, fe as K, Me as L, Te as M, Ee as N, ke as O, Ae as P, S as Q, Ne as R, me as S, se as T, E as U, je as V, D as W, v as X, y as Y, ee as Z, ve as _, Et as a, _e as b, ze as c, Re as d, w as et, B as f, Se as g, Ce as h, wt as i, p as it, M as j, xe as k, Be as l, Ie as m, Q as n, b as nt, J as o, R as p, ge as q, Tt as r, m as rt, Ve as s, Ct as t, x as tt, z as u, T as v, he as w, ue as x, ie as y, De as z };