@genai-fi/nanogpt 1.6.1 → 1.7.1

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