@genai-fi/nanogpt 0.9.1 → 0.10.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 (343) hide show
  1. package/README.md +352 -14
  2. package/dist/Generator.js +69 -78
  3. package/dist/{RealDiv-D4EzDsC0.js → RealDiv-DgA3z9oO.js} +32 -206
  4. package/dist/Reshape-CF6odzV4.js +16 -0
  5. package/dist/Reshape-_kILl6tK.js +81 -0
  6. package/dist/TeachableLLM.js +28 -22
  7. package/dist/Trainer.d.ts +2 -0
  8. package/dist/Trainer.js +3 -2
  9. package/dist/{axis_util-TbGYJ208.js → axis_util-BvHEw88j.js} +7 -23
  10. package/dist/backend.d.ts +2 -1
  11. package/dist/backend.js +10 -4
  12. package/dist/backend_util-D-rUb2ty.js +474 -0
  13. package/dist/backend_webgpu-B0u2ndUn.js +547 -0
  14. package/dist/binary_op_util-pKXltfxI.js +192 -0
  15. package/dist/broadcast_to-CwF7XIeu.js +30 -0
  16. package/dist/checks/appendCache.js +2 -2
  17. package/dist/checks/attentionMask.js +3 -3
  18. package/dist/checks/check.d.ts +1 -1
  19. package/dist/checks/check.js +8 -8
  20. package/dist/checks/gelu.js +2 -2
  21. package/dist/checks/index.d.ts +2 -0
  22. package/dist/checks/index.js +7 -5
  23. package/dist/checks/matMulGelu.js +6 -6
  24. package/dist/checks/normRMS.js +7 -7
  25. package/dist/checks/normRMSGrad.js +3 -3
  26. package/dist/checks/packUnpack.d.ts +1 -0
  27. package/dist/checks/packUnpack.js +18 -0
  28. package/dist/checks/qkv.js +12 -27
  29. package/dist/checks/rope.js +2 -2
  30. package/dist/checks/weights.js +18 -16
  31. package/dist/complex-CSlYz-2T.js +13 -0
  32. package/dist/complex_util-Yc1A_gV1.js +55 -0
  33. package/dist/concat-BHlIJeyT.js +19 -0
  34. package/dist/concat_util-DcJk7YHS.js +22 -0
  35. package/dist/data/docx.js +1 -1
  36. package/dist/data/parquet.js +2 -2
  37. package/dist/data/pdf.js +1 -1
  38. package/dist/data/textLoader.js +1 -1
  39. package/dist/{dataset-DlZtKmBq.js → dataset-0xP8GjwI.js} +136 -236
  40. package/dist/dropout-C1pM3f11.js +99 -0
  41. package/dist/expand_dims-BPG4fwBP.js +13 -0
  42. package/dist/exports_initializers-xuidcwI4.js +7 -0
  43. package/dist/gather-DykLGqmW.js +10 -0
  44. package/dist/{gelu-Bp_-935b.js → gelu-CNLFZWea.js} +11 -10
  45. package/dist/{gpgpu_math-CDaYiyE_.js → gpgpu_math-DDVJCn6-.js} +90 -265
  46. package/dist/{index-C4L8Cm77.js → index-CieiGp4Y.js} +14 -14
  47. package/dist/index-CjOj7j-u.js +7308 -0
  48. package/dist/{index-Tf7vU29b.js → index-Cp39cXWe.js} +3 -10
  49. package/dist/{index-Dwqa6Zy2.js → index-DvYrXKkX.js} +2 -2
  50. package/dist/index-ZyQhjEPo.js +2157 -0
  51. package/dist/{jszip.min-CjP2V1VV.js → jszip.min-Bz5-11Bk.js} +56 -57
  52. package/dist/kernel_funcs_utils-Dg_-E44D.js +308 -0
  53. package/dist/layers/BaseLayer.d.ts +1 -0
  54. package/dist/layers/BaseLayer.js +7 -6
  55. package/dist/layers/CausalSelfAttention.d.ts +0 -1
  56. package/dist/layers/CausalSelfAttention.js +56 -55
  57. package/dist/layers/MLP.js +15 -16
  58. package/dist/layers/PositionEmbedding.js +5 -14
  59. package/dist/layers/RMSNorm.js +3 -3
  60. package/dist/layers/RoPECache.d.ts +2 -0
  61. package/dist/layers/RoPECache.js +22 -17
  62. package/dist/layers/TiedEmbedding.js +22 -17
  63. package/dist/layers/TransformerBlock.js +21 -20
  64. package/dist/loader/load.js +1 -1
  65. package/dist/loader/loadTransformers.js +1 -1
  66. package/dist/loader/oldZipLoad.js +39 -33
  67. package/dist/loader/save.js +1 -1
  68. package/dist/log_sum_exp-DWI-76TI.js +41 -0
  69. package/dist/main.d.ts +8 -0
  70. package/dist/main.js +63 -52
  71. package/dist/matMul16--R5hOwDG.js +77 -0
  72. package/dist/mat_mul-DeAh4uTH.js +12 -0
  73. package/dist/mod-Gt1rMB4n.js +12 -0
  74. package/dist/models/NanoGPTV1.js +40 -31
  75. package/dist/models/model.d.ts +2 -0
  76. package/dist/models/model.js +37 -29
  77. package/dist/{mulmat_packed_gpu-BT60jmzP.js → mulmat_packed_gpu-BMFhLwta.js} +1 -17
  78. package/dist/{non_max_suppression_impl-CsEgBuMA.js → non_max_suppression_impl-B2W7YjZB.js} +0 -32
  79. package/dist/ones-CAMiP4I2.js +15 -0
  80. package/dist/ops/adamAdjust.js +1 -1
  81. package/dist/ops/adamMoments.d.ts +1 -1
  82. package/dist/ops/adamMoments.js +4 -4
  83. package/dist/ops/add16.d.ts +2 -0
  84. package/dist/ops/add16.js +9 -0
  85. package/dist/ops/appendCache.js +16 -9
  86. package/dist/ops/attentionMask.js +4 -4
  87. package/dist/ops/concat16.d.ts +2 -0
  88. package/dist/ops/concat16.js +9 -0
  89. package/dist/ops/cpu/adamAdjust.js +14 -13
  90. package/dist/ops/cpu/adamMoments.js +10 -9
  91. package/dist/ops/cpu/appendCache.js +9 -8
  92. package/dist/ops/cpu/attentionMask.js +15 -14
  93. package/dist/ops/cpu/fusedSoftmax.js +13 -12
  94. package/dist/ops/cpu/gatherSub.js +9 -24
  95. package/dist/ops/cpu/gelu.js +13 -12
  96. package/dist/ops/cpu/matMul16.d.ts +1 -0
  97. package/dist/ops/cpu/matMul16.js +16 -0
  98. package/dist/ops/cpu/matMulGelu.js +18 -16
  99. package/dist/ops/cpu/matMulMul.js +8 -7
  100. package/dist/ops/cpu/mulDropout.js +4 -3
  101. package/dist/ops/cpu/normRMS.js +11 -10
  102. package/dist/ops/cpu/qkv.js +17 -13
  103. package/dist/ops/cpu/rope.js +23 -22
  104. package/dist/ops/cpu/scatterSub.js +16 -30
  105. package/dist/ops/dot16.d.ts +2 -0
  106. package/dist/ops/dot16.js +42 -0
  107. package/dist/ops/gatherSub.js +1 -1
  108. package/dist/ops/gelu.js +2 -2
  109. package/dist/ops/grads/add16.d.ts +1 -0
  110. package/dist/ops/grads/add16.js +27 -0
  111. package/dist/ops/grads/attentionMask.js +12 -19
  112. package/dist/ops/grads/gelu.js +4 -3
  113. package/dist/ops/grads/matMul16.d.ts +2 -0
  114. package/dist/ops/grads/matMul16.js +9 -0
  115. package/dist/ops/grads/matMulGelu.js +8 -7
  116. package/dist/ops/grads/normRMS.js +8 -7
  117. package/dist/ops/grads/{fusedSoftmax.d.ts → pack16.d.ts} +1 -1
  118. package/dist/ops/grads/pack16.js +7 -0
  119. package/dist/ops/grads/qkv.d.ts +3 -1
  120. package/dist/ops/grads/qkv.js +28 -22
  121. package/dist/ops/grads/rope.d.ts +2 -1
  122. package/dist/ops/grads/rope.js +6 -13
  123. package/dist/ops/grads/softmax16.d.ts +2 -0
  124. package/dist/ops/grads/softmax16.js +26 -0
  125. package/dist/ops/grads/unpack16.d.ts +2 -0
  126. package/dist/ops/grads/unpack16.js +6 -0
  127. package/dist/ops/grads/utils.d.ts +3 -0
  128. package/dist/ops/grads/utils.js +10 -0
  129. package/dist/ops/matMul16.d.ts +15 -0
  130. package/dist/ops/matMul16.js +13 -0
  131. package/dist/ops/matMulGelu.js +1 -1
  132. package/dist/ops/matMulMul.js +1 -1
  133. package/dist/ops/mul16.d.ts +2 -0
  134. package/dist/ops/mul16.js +8 -0
  135. package/dist/ops/mulDrop.js +1 -1
  136. package/dist/ops/normRMS.js +1 -1
  137. package/dist/ops/pack16.d.ts +2 -0
  138. package/dist/ops/pack16.js +6 -0
  139. package/dist/ops/qkv.d.ts +1 -1
  140. package/dist/ops/qkv.js +8 -4
  141. package/dist/ops/reshape16.d.ts +2 -0
  142. package/dist/ops/reshape16.js +43 -0
  143. package/dist/ops/rope.d.ts +1 -1
  144. package/dist/ops/rope.js +8 -10
  145. package/dist/ops/scatterSub.js +1 -1
  146. package/dist/ops/slice16.d.ts +2 -0
  147. package/dist/ops/slice16.js +9 -0
  148. package/dist/ops/softmax16.d.ts +2 -0
  149. package/dist/ops/softmax16.js +12 -0
  150. package/dist/ops/sub16.d.ts +2 -0
  151. package/dist/ops/sub16.js +8 -0
  152. package/dist/ops/sum16.d.ts +2 -0
  153. package/dist/ops/sum16.js +13 -0
  154. package/dist/ops/transpose16.d.ts +3 -0
  155. package/dist/ops/transpose16.js +41 -0
  156. package/dist/ops/unpack16.d.ts +2 -0
  157. package/dist/ops/unpack16.js +6 -0
  158. package/dist/ops/webgl/adamAdjust.js +3 -2
  159. package/dist/ops/webgl/adamMoments.js +2 -1
  160. package/dist/ops/webgl/appendCache.js +2 -1
  161. package/dist/ops/webgl/attentionMask.js +5 -4
  162. package/dist/ops/webgl/fusedSoftmax.js +6 -4
  163. package/dist/ops/webgl/gatherSub.js +7 -6
  164. package/dist/ops/webgl/gelu.js +3 -2
  165. package/dist/ops/webgl/log.js +12 -27
  166. package/dist/ops/webgl/matMul16.d.ts +1 -0
  167. package/dist/ops/webgl/matMul16.js +37 -0
  168. package/dist/ops/webgl/matMulGelu.js +17 -15
  169. package/dist/ops/webgl/matMulMul.js +13 -12
  170. package/dist/ops/webgl/mulDropout.js +9 -8
  171. package/dist/ops/webgl/normRMS.js +8 -7
  172. package/dist/ops/webgl/qkv.js +6 -5
  173. package/dist/ops/webgl/rope.js +11 -10
  174. package/dist/ops/webgl/scatterSub.js +6 -5
  175. package/dist/ops/webgpu/adamAdjust.js +12 -10
  176. package/dist/ops/webgpu/adamMoments.js +27 -22
  177. package/dist/ops/webgpu/add16.d.ts +1 -0
  178. package/dist/ops/webgpu/add16.js +14 -0
  179. package/dist/ops/webgpu/appendCache.js +64 -17
  180. package/dist/ops/webgpu/attentionMask.js +19 -62
  181. package/dist/ops/webgpu/attentionMask32_program.d.ts +19 -0
  182. package/dist/ops/webgpu/attentionMask32_program.js +54 -0
  183. package/dist/ops/webgpu/concat16.d.ts +19 -0
  184. package/dist/ops/webgpu/concat16.js +128 -0
  185. package/dist/ops/webgpu/gatherSub.js +9 -7
  186. package/dist/ops/webgpu/gelu.js +78 -31
  187. package/dist/ops/webgpu/index.js +12 -0
  188. package/dist/ops/webgpu/matMul16.d.ts +1 -0
  189. package/dist/ops/webgpu/matMul16.js +58 -0
  190. package/dist/ops/webgpu/matMul16_program.d.ts +42 -0
  191. package/dist/ops/webgpu/matMul16_program.js +336 -0
  192. package/dist/ops/webgpu/mul16.d.ts +1 -0
  193. package/dist/ops/webgpu/mul16.js +14 -0
  194. package/dist/ops/webgpu/normRMS.js +21 -40
  195. package/dist/ops/webgpu/normRMS16_program.d.ts +9 -0
  196. package/dist/ops/webgpu/normRMS16_program.js +24 -0
  197. package/dist/ops/webgpu/normRMS32_program.d.ts +9 -0
  198. package/dist/ops/webgpu/normRMS32_program.js +24 -0
  199. package/dist/ops/webgpu/normRMSGrad.js +113 -64
  200. package/dist/ops/webgpu/pack16.d.ts +1 -0
  201. package/dist/ops/webgpu/pack16.js +19 -0
  202. package/dist/ops/webgpu/pack16_program.d.ts +19 -0
  203. package/dist/ops/webgpu/pack16_program.js +92 -0
  204. package/dist/ops/webgpu/qkv.js +20 -55
  205. package/dist/ops/webgpu/rope.js +77 -22
  206. package/dist/ops/webgpu/scatterSub.js +9 -7
  207. package/dist/ops/webgpu/slice16.d.ts +7 -0
  208. package/dist/ops/webgpu/slice16.js +71 -0
  209. package/dist/{variable-Bm2OFwGI.js → ops/webgpu/softmax16.d.ts} +2 -8
  210. package/dist/ops/webgpu/softmax16.js +23 -0
  211. package/dist/ops/webgpu/softmax16_program.d.ts +13 -0
  212. package/dist/ops/webgpu/softmax16_program.js +73 -0
  213. package/dist/ops/webgpu/softmax16_subgroup_program.d.ts +17 -0
  214. package/dist/ops/webgpu/softmax16_subgroup_program.js +75 -0
  215. package/dist/ops/webgpu/softmax16grad.d.ts +1 -0
  216. package/dist/ops/webgpu/softmax16grad.js +38 -0
  217. package/dist/ops/webgpu/sub16.d.ts +1 -0
  218. package/dist/ops/webgpu/sub16.js +14 -0
  219. package/dist/ops/webgpu/sum16.d.ts +1 -0
  220. package/dist/ops/webgpu/sum16.js +40 -0
  221. package/dist/ops/webgpu/transpose16.d.ts +1 -0
  222. package/dist/ops/webgpu/transpose16.js +35 -0
  223. package/dist/ops/webgpu/transpose16_program.d.ts +16 -0
  224. package/dist/ops/webgpu/transpose16_program.js +50 -0
  225. package/dist/ops/webgpu/transpose16_shared_program.d.ts +15 -0
  226. package/dist/ops/webgpu/transpose16_shared_program.js +71 -0
  227. package/dist/ops/webgpu/unpack16.d.ts +1 -0
  228. package/dist/ops/webgpu/unpack16.js +49 -0
  229. package/dist/ops/webgpu/utils/binary_op.d.ts +19 -0
  230. package/dist/ops/webgpu/utils/binary_op.js +79 -0
  231. package/dist/ops/webgpu/utils/deviceInfo.d.ts +7 -0
  232. package/dist/ops/webgpu/utils/deviceInfo.js +11 -0
  233. package/dist/ops/webgpu/utils/reductions.d.ts +32 -4
  234. package/dist/ops/webgpu/utils/reductions.js +236 -45
  235. package/dist/ops-CNI3TwqM.js +645 -0
  236. package/dist/pack16-CFUqumar.js +41 -0
  237. package/dist/{papaparse.min-C8l2Kvo1.js → papaparse.min-C0cScC2i.js} +2 -8
  238. package/dist/{parquet-C0Tlmv9c.js → parquet-BE8MU_ge.js} +201 -278
  239. package/dist/patches/PackedTensor.d.ts +12 -0
  240. package/dist/patches/PackedTensor.js +11 -0
  241. package/dist/patches/engine.d.ts +261 -0
  242. package/dist/patches/engine.js +10 -0
  243. package/dist/patches/tape.d.ts +12 -0
  244. package/dist/patches/tape.js +5 -0
  245. package/dist/patches/webgpu_backend.d.ts +18 -0
  246. package/dist/patches/webgpu_backend.js +57 -0
  247. package/dist/{tensor-CZr4dh61.js → patches/webgpu_base.d.ts} +5 -8
  248. package/dist/patches/webgpu_base.js +34 -0
  249. package/dist/patches/webgpu_program.d.ts +36 -0
  250. package/dist/patches/webgpu_program.js +401 -0
  251. package/dist/{pdf-kJD-f258.js → pdf-NIhmP3sq.js} +424 -428
  252. package/dist/random_width-DY6Kk2Dl.js +10051 -0
  253. package/dist/range-BMS52eQi.js +11 -0
  254. package/dist/reciprocal-CTmshQ9J.js +10 -0
  255. package/dist/{register_all_kernels-DIGpEwcf.js → register_all_kernels-Bwu1PTuU.js} +719 -9766
  256. package/dist/relu-yZ2-7WxU.js +10 -0
  257. package/dist/reshape-DevtBWtf.js +10 -0
  258. package/dist/rope-B5UUMsPi.js +32 -0
  259. package/dist/{scatter_nd_util-BQdz--Gn.js → scatter_nd_util-5EL-8VAQ.js} +1 -1
  260. package/dist/selu_util-D1w6yyTO.js +303 -0
  261. package/dist/{shared-DuP7ue-R.js → shared-BRksrJb3.js} +1 -17
  262. package/dist/shared-BuAXb4CI.js +2145 -0
  263. package/dist/sin-BGfy2HZo.js +16 -0
  264. package/dist/slice-D_gkkqZK.js +13 -0
  265. package/dist/slice_util-DtEldBfK.js +261 -0
  266. package/dist/softmax-ZHVebtR1.js +13 -0
  267. package/dist/split-DrfihRpZ.js +10 -0
  268. package/dist/squeeze-DZEpeblb.js +11 -0
  269. package/dist/stack-yOIAalTq.js +13 -0
  270. package/dist/sum-_fzj5ZTB.js +12 -0
  271. package/dist/tensor-DdQUJZlz.js +909 -0
  272. package/dist/tensor-f35l8Odg.js +8 -0
  273. package/dist/tensor1d-CeZuc-Rv.js +12 -0
  274. package/dist/tensor2d-G4Ys2GxX.js +15 -0
  275. package/dist/tensor4d-B8roDgtc.js +15 -0
  276. package/dist/tensor_util-DV-FP5Q3.js +523 -0
  277. package/dist/tfjs_backend-kNyO5L2d.js +653 -0
  278. package/dist/tile-BzyEiF-F.js +13 -0
  279. package/dist/tokeniser/CharTokeniser.js +1 -1
  280. package/dist/tokeniser/bpe.js +1 -1
  281. package/dist/training/Adam.d.ts +2 -1
  282. package/dist/training/Adam.js +12 -28
  283. package/dist/training/AdamExt.d.ts +1 -0
  284. package/dist/training/AdamExt.js +2 -2
  285. package/dist/training/DatasetBuilder.js +3 -20
  286. package/dist/training/FullTrainer.js +55 -48
  287. package/dist/training/Trainer.d.ts +11 -6
  288. package/dist/training/Trainer.js +51 -39
  289. package/dist/training/sparseCrossEntropy.js +3 -3
  290. package/dist/transpose-DKELTqhe.js +38 -0
  291. package/dist/utilities/arrayClose.js +7 -7
  292. package/dist/utilities/dummy.js +35 -27
  293. package/dist/utilities/multinomialCPU.js +2 -2
  294. package/dist/utilities/packed.d.ts +7 -0
  295. package/dist/utilities/packed.js +716 -0
  296. package/dist/utilities/performance.js +1 -1
  297. package/dist/utilities/profile.js +1 -1
  298. package/dist/utilities/safetensors.js +2 -2
  299. package/dist/utilities/sentences.d.ts +5 -0
  300. package/dist/utilities/sentences.js +41 -0
  301. package/dist/utilities/weights.js +2 -2
  302. package/dist/variable-Bhn5bHYv.js +7 -0
  303. package/dist/{webgpu_program-DkQJOJSd.js → webgpu_program-Cigz-7RF.js} +15 -44
  304. package/dist/webgpu_util-BBCnKm2X.js +65 -0
  305. package/dist/zeros-2gldETuK.js +14 -0
  306. package/package.json +4 -3
  307. package/dist/Reshape-Bowtk9BP.js +0 -127
  308. package/dist/Reshape-DUqYftGC.js +0 -30
  309. package/dist/backend_util-CJIiDoV1.js +0 -749
  310. package/dist/broadcast_to-DzlNweb8.js +0 -44
  311. package/dist/concat-B912vBbo.js +0 -33
  312. package/dist/dropout-C-csYCLj.js +0 -193
  313. package/dist/exports_initializers-B8iZMgQ0.js +0 -16
  314. package/dist/gather-Dnpgw-YQ.js +0 -25
  315. package/dist/index-BzFyqcy-.js +0 -4457
  316. package/dist/index-C1rx_Ajs.js +0 -12076
  317. package/dist/kernel_funcs_utils-DKLK0Mg3.js +0 -466
  318. package/dist/log_sum_exp-DO6z8tSE.js +0 -103
  319. package/dist/mat_mul-DzjTFx-u.js +0 -27
  320. package/dist/mod-Dobti4j4.js +0 -27
  321. package/dist/ones-tIJeHlq-.js +0 -29
  322. package/dist/ops/fusedSoftmax.d.ts +0 -2
  323. package/dist/ops/fusedSoftmax.js +0 -10
  324. package/dist/ops/grads/fusedSoftmax.js +0 -22
  325. package/dist/ops-LuCMAnmM.js +0 -1525
  326. package/dist/random_width-CXVRloNK.js +0 -13670
  327. package/dist/range-CWcz7xFA.js +0 -26
  328. package/dist/reciprocal-C4rNcM-S.js +0 -25
  329. package/dist/relu-BjCh_SYb.js +0 -25
  330. package/dist/reshape-CnIwVG1c.js +0 -25
  331. package/dist/selu_util-OtRzVwW5.js +0 -719
  332. package/dist/shared-DmRsFyaJ.js +0 -3134
  333. package/dist/sin-gpDNRxE0.js +0 -47
  334. package/dist/slice-d0Vo9XTN.js +0 -28
  335. package/dist/softmax-D7Jj3p_P.js +0 -28
  336. package/dist/split-DK2k5eHf.js +0 -25
  337. package/dist/stack-DFatutCx.js +0 -27
  338. package/dist/sum-CJ0ULhmt.js +0 -27
  339. package/dist/tensor1d-vML0r3q6.js +0 -27
  340. package/dist/tensor2d-D76QGjF3.js +0 -30
  341. package/dist/tensor4d-Df1WlVDY.js +0 -30
  342. package/dist/webgpu_util-pLEV9tks.js +0 -80
  343. package/dist/zeros-Bj5rMYA7.js +0 -52
@@ -1,719 +0,0 @@
1
- import { n as D, aq as H, E as C, F as N, G, ar as te, as as ne, at as se, au as re, av as ie, aw as oe, a as le, ax as ue, ay as O } from "./index-BzFyqcy-.js";
2
- import { r as fe } from "./relu-BjCh_SYb.js";
3
- import { r as ce } from "./reshape-CnIwVG1c.js";
4
- import { s as ae } from "./sum-CJ0ULhmt.js";
5
- /**
6
- * @license
7
- * Copyright 2020 Google LLC. All Rights Reserved.
8
- * Licensed under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License.
10
- * You may obtain a copy of the License at
11
- *
12
- * http://www.apache.org/licenses/LICENSE-2.0
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- * =============================================================================
20
- */
21
- function Ke(e, t, n, s, r = "NHWC", u) {
22
- const i = e[3], o = [...t, i], c = Ae(r);
23
- return X(e, o, n, u, s, null, null, c);
24
- }
25
- function Xe(e, t, n, s, r, u, i = "channelsLast") {
26
- const [o, c] = T(t);
27
- let a;
28
- if (i === "channelsLast")
29
- a = [o, c, e[3], e[3]];
30
- else if (i === "channelsFirst")
31
- a = [o, c, e[1], e[1]];
32
- else
33
- throw new Error(`Unknown dataFormat ${i}`);
34
- return X(e, a, n, s, r, u, !1, i);
35
- }
36
- function Be(e, t, n, s, r, u, i = "NDHWC") {
37
- const [o, c, a] = W(t);
38
- let p, g;
39
- if (i === "NDHWC")
40
- g = "channelsLast", p = [o, c, a, e[4], e[4]];
41
- else if (i === "NCDHW")
42
- g = "channelsFirst", p = [o, c, a, e[1], e[1]];
43
- else
44
- throw new Error(`Unknown dataFormat ${i}`);
45
- return he(e, p, n, s, r, !1, g, u);
46
- }
47
- function X(e, t, n, s, r, u, i = !1, o = "channelsLast") {
48
- let [c, a, p, g] = [-1, -1, -1, -1];
49
- if (o === "channelsLast")
50
- [c, a, p, g] = e;
51
- else if (o === "channelsFirst")
52
- [c, g, a, p] = e;
53
- else
54
- throw new Error(`Unknown dataFormat ${o}`);
55
- const [l, h, , d] = t, [A, m] = T(n), [b, k] = T(s), f = L(l, b), w = L(h, k), { padInfo: E, outHeight: I, outWidth: y } = de(r, a, p, A, m, f, w, u, o), x = i ? d * g : d;
56
- let $;
57
- return o === "channelsFirst" ? $ = [c, x, I, y] : o === "channelsLast" && ($ = [c, I, y, x]), {
58
- batchSize: c,
59
- dataFormat: o,
60
- inHeight: a,
61
- inWidth: p,
62
- inChannels: g,
63
- outHeight: I,
64
- outWidth: y,
65
- outChannels: x,
66
- padInfo: E,
67
- strideHeight: A,
68
- strideWidth: m,
69
- filterHeight: l,
70
- filterWidth: h,
71
- effectiveFilterHeight: f,
72
- effectiveFilterWidth: w,
73
- dilationHeight: b,
74
- dilationWidth: k,
75
- inShape: e,
76
- outShape: $,
77
- filterShape: t
78
- };
79
- }
80
- function he(e, t, n, s, r, u = !1, i = "channelsLast", o) {
81
- let [c, a, p, g, l] = [-1, -1, -1, -1, -1];
82
- if (i === "channelsLast")
83
- [c, a, p, g, l] = e;
84
- else if (i === "channelsFirst")
85
- [c, l, a, p, g] = e;
86
- else
87
- throw new Error(`Unknown dataFormat ${i}`);
88
- const [h, d, A, , m] = t, [b, k, f] = W(n), [w, E, I] = W(s), y = L(h, w), x = L(d, E), $ = L(A, I), { padInfo: _, outDepth: M, outHeight: S, outWidth: R } = me(r, a, p, g, b, k, f, y, x, $, o), V = u ? m * l : m;
89
- let U;
90
- return i === "channelsFirst" ? U = [c, V, M, S, R] : i === "channelsLast" && (U = [c, M, S, R, V]), {
91
- batchSize: c,
92
- dataFormat: i,
93
- inDepth: a,
94
- inHeight: p,
95
- inWidth: g,
96
- inChannels: l,
97
- outDepth: M,
98
- outHeight: S,
99
- outWidth: R,
100
- outChannels: V,
101
- padInfo: _,
102
- strideDepth: b,
103
- strideHeight: k,
104
- strideWidth: f,
105
- filterDepth: h,
106
- filterHeight: d,
107
- filterWidth: A,
108
- effectiveFilterDepth: y,
109
- effectiveFilterHeight: x,
110
- effectiveFilterWidth: $,
111
- dilationDepth: w,
112
- dilationHeight: E,
113
- dilationWidth: I,
114
- inShape: e,
115
- outShape: U,
116
- filterShape: t
117
- };
118
- }
119
- function ge(e, t, n, s, r) {
120
- s == null && (s = B(e, t, n));
121
- const u = e[0], i = e[1], o = F((u - t + 2 * s) / n + 1, r), c = F((i - t + 2 * s) / n + 1, r);
122
- return [o, c];
123
- }
124
- function pe(e, t, n, s, r, u) {
125
- r == null && (r = B(e, t[0], s[0]));
126
- const i = [0, 0, 0, n];
127
- for (let o = 0; o < 3; o++)
128
- e[o] + 2 * r >= t[o] && (i[o] = F((e[o] - t[o] + 2 * r) / s[o] + 1, u));
129
- return i;
130
- }
131
- function B(e, t, n, s = 1) {
132
- const r = L(t, s);
133
- return Math.floor((e[0] * (n - 1) - n + r) / 2);
134
- }
135
- function T(e) {
136
- return typeof e == "number" ? [e, e, e] : e.length === 2 ? [e[0], e[1], 1] : e;
137
- }
138
- function W(e) {
139
- return typeof e == "number" ? [e, e, e] : e;
140
- }
141
- function L(e, t) {
142
- return t <= 1 ? e : e + (e - 1) * (t - 1);
143
- }
144
- function de(e, t, n, s, r, u, i, o, c) {
145
- let a, p, g;
146
- if (typeof e == "number") {
147
- a = { top: e, bottom: e, left: e, right: e, type: e === 0 ? "VALID" : "NUMBER" };
148
- const h = ge([t, n], u, s, e, o);
149
- p = h[0], g = h[1];
150
- } else if (e === "same") {
151
- p = Math.ceil(t / s), g = Math.ceil(n / r);
152
- const l = Math.max(0, (p - 1) * s + u - t), h = Math.max(0, (g - 1) * r + i - n), d = Math.floor(l / 2), A = l - d, m = Math.floor(h / 2), b = h - m;
153
- a = { top: d, bottom: A, left: m, right: b, type: "SAME" };
154
- } else if (e === "valid")
155
- a = { top: 0, bottom: 0, left: 0, right: 0, type: "VALID" }, p = Math.ceil((t - u + 1) / s), g = Math.ceil((n - i + 1) / r);
156
- else if (typeof e == "object") {
157
- const l = c === "channelsLast" ? e[1][0] : e[2][0], h = c === "channelsLast" ? e[1][1] : e[2][1], d = c === "channelsLast" ? e[2][0] : e[3][0], A = c === "channelsLast" ? e[2][1] : e[3][1];
158
- a = { top: l, bottom: h, left: d, right: A, type: l === 0 && h === 0 && d === 0 && A === 0 ? "VALID" : "EXPLICIT" }, p = F((t - u + l + h) / s + 1, o), g = F((n - i + d + A) / r + 1, o);
159
- } else
160
- throw Error(`Unknown padding parameter: ${e}`);
161
- return { padInfo: a, outHeight: p, outWidth: g };
162
- }
163
- function me(e, t, n, s, r, u, i, o, c, a, p) {
164
- let g, l, h, d;
165
- if (e === "valid" && (e = 0), typeof e == "number") {
166
- g = {
167
- top: e,
168
- bottom: e,
169
- left: e,
170
- right: e,
171
- front: e,
172
- back: e,
173
- type: e === 0 ? "VALID" : "NUMBER"
174
- };
175
- const m = pe([t, n, s, 1], [o, c, a], 1, [r, u, i], e, p);
176
- l = m[0], h = m[1], d = m[2];
177
- } else if (e === "same") {
178
- l = Math.ceil(t / r), h = Math.ceil(n / u), d = Math.ceil(s / i);
179
- const A = (l - 1) * r + o - t, m = (h - 1) * u + c - n, b = (d - 1) * i + a - s, k = Math.floor(A / 2), f = A - k, w = Math.floor(m / 2), E = m - w, I = Math.floor(b / 2), y = b - I;
180
- g = { top: w, bottom: E, left: I, right: y, front: k, back: f, type: "SAME" };
181
- } else
182
- throw Error(`Unknown padding parameter: ${e}`);
183
- return { padInfo: g, outDepth: l, outHeight: h, outWidth: d };
184
- }
185
- function F(e, t) {
186
- if (!t)
187
- return Math.trunc(e);
188
- switch (t) {
189
- case "round":
190
- return Math.round(e);
191
- case "ceil":
192
- return Math.ceil(e);
193
- case "floor":
194
- return Math.floor(e);
195
- default:
196
- throw new Error(`Unknown roundingMode ${t}`);
197
- }
198
- }
199
- function P(e) {
200
- const [t, n, s] = T(e);
201
- return t === 1 && n === 1 && s === 1;
202
- }
203
- function je(e, t) {
204
- return P(e) || P(t);
205
- }
206
- function qe(e) {
207
- return T(e).every((t) => t > 0);
208
- }
209
- function Ae(e) {
210
- if (e === "NHWC")
211
- return "channelsLast";
212
- if (e === "NCHW")
213
- return "channelsFirst";
214
- throw new Error(`Unknown dataFormat ${e}`);
215
- }
216
- function Je(e, t, n) {
217
- if (n != null) {
218
- if (typeof t == "string")
219
- throw Error(`Error in ${e}: pad must be an integer when using dimRoundingMode ${n} but got pad ${t}.`);
220
- if (typeof t == "number")
221
- D(H(t), () => `Error in ${e}: pad must be an integer when using dimRoundingMode ${n} but got pad ${t}.`);
222
- else if (typeof t == "object")
223
- t.forEach((s) => {
224
- s.forEach((r) => {
225
- D(H(r), () => `Error in ${e}: pad must be an integer when using dimRoundingMode ${n} but got pad ${r}.`);
226
- });
227
- });
228
- else
229
- throw Error(`Error in ${e}: Unknown padding parameter: ${t}`);
230
- }
231
- }
232
- /**
233
- * @license
234
- * Copyright 2018 Google LLC. All Rights Reserved.
235
- * Licensed under the Apache License, Version 2.0 (the "License");
236
- * you may not use this file except in compliance with the License.
237
- * You may obtain a copy of the License at
238
- *
239
- * http://www.apache.org/licenses/LICENSE-2.0
240
- *
241
- * Unless required by applicable law or agreed to in writing, software
242
- * distributed under the License is distributed on an "AS IS" BASIS,
243
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
244
- * See the License for the specific language governing permissions and
245
- * limitations under the License.
246
- * =============================================================================
247
- */
248
- function we(e) {
249
- const n = { x: N(e, "x", "sigmoid", "float32") };
250
- return G.runKernel(te, n);
251
- }
252
- const Ee = /* @__PURE__ */ C({ sigmoid_: we });
253
- /**
254
- * @license
255
- * Copyright 2020 Google LLC. All Rights Reserved.
256
- * Licensed under the Apache License, Version 2.0 (the "License");
257
- * you may not use this file except in compliance with the License.
258
- * You may obtain a copy of the License at
259
- *
260
- * http://www.apache.org/licenses/LICENSE-2.0
261
- *
262
- * Unless required by applicable law or agreed to in writing, software
263
- * distributed under the License is distributed on an "AS IS" BASIS,
264
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
265
- * See the License for the specific language governing permissions and
266
- * limitations under the License.
267
- * =============================================================================
268
- */
269
- function be(e) {
270
- const n = { x: N(e, "x", "elu", "float32") };
271
- return G.runKernel(ne, n);
272
- }
273
- const $e = /* @__PURE__ */ C({ elu_: be });
274
- /**
275
- * @license
276
- * Copyright 2020 Google LLC. All Rights Reserved.
277
- * Licensed under the Apache License, Version 2.0 (the "License");
278
- * you may not use this file except in compliance with the License.
279
- * You may obtain a copy of the License at
280
- *
281
- * http://www.apache.org/licenses/LICENSE-2.0
282
- *
283
- * Unless required by applicable law or agreed to in writing, software
284
- * distributed under the License is distributed on an "AS IS" BASIS,
285
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286
- * See the License for the specific language governing permissions and
287
- * limitations under the License.
288
- * =============================================================================
289
- */
290
- function Ie(e, t = 0.2) {
291
- const s = { x: N(e, "x", "leakyRelu") }, r = { alpha: t };
292
- return G.runKernel(se, s, r);
293
- }
294
- const ye = /* @__PURE__ */ C({ leakyRelu_: Ie });
295
- /**
296
- * @license
297
- * Copyright 2020 Google LLC. All Rights Reserved.
298
- * Licensed under the Apache License, Version 2.0 (the "License");
299
- * you may not use this file except in compliance with the License.
300
- * You may obtain a copy of the License at
301
- *
302
- * http://www.apache.org/licenses/LICENSE-2.0
303
- *
304
- * Unless required by applicable law or agreed to in writing, software
305
- * distributed under the License is distributed on an "AS IS" BASIS,
306
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
307
- * See the License for the specific language governing permissions and
308
- * limitations under the License.
309
- * =============================================================================
310
- */
311
- function xe(e, t) {
312
- const n = N(e, "x", "prelu"), s = N(t, "alpha", "prelu"), r = { x: n, alpha: s };
313
- return G.runKernel(re, r);
314
- }
315
- const Me = /* @__PURE__ */ C({ prelu_: xe });
316
- /**
317
- * @license
318
- * Copyright 2020 Google LLC. All Rights Reserved.
319
- * Licensed under the Apache License, Version 2.0 (the "License");
320
- * you may not use this file except in compliance with the License.
321
- * You may obtain a copy of the License at
322
- *
323
- * http://www.apache.org/licenses/LICENSE-2.0
324
- *
325
- * Unless required by applicable law or agreed to in writing, software
326
- * distributed under the License is distributed on an "AS IS" BASIS,
327
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
328
- * See the License for the specific language governing permissions and
329
- * limitations under the License.
330
- * =============================================================================
331
- */
332
- function ke(e) {
333
- const n = { x: N(e, "x", "relu6") };
334
- return G.runKernel(ie, n);
335
- }
336
- const Se = /* @__PURE__ */ C({ relu6_: ke });
337
- /**
338
- * @license
339
- * Copyright 2018 Google LLC. All Rights Reserved.
340
- * Licensed under the Apache License, Version 2.0 (the "License");
341
- * you may not use this file except in compliance with the License.
342
- * You may obtain a copy of the License at
343
- *
344
- * http://www.apache.org/licenses/LICENSE-2.0
345
- *
346
- * Unless required by applicable law or agreed to in writing, software
347
- * distributed under the License is distributed on an "AS IS" BASIS,
348
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
349
- * See the License for the specific language governing permissions and
350
- * limitations under the License.
351
- * =============================================================================
352
- */
353
- function De(e, t = 0) {
354
- const s = { x: N(e, "x", "step") }, r = { alpha: t };
355
- return G.runKernel(oe, s, r);
356
- }
357
- const Ne = /* @__PURE__ */ C({ step_: De });
358
- /**
359
- * @license
360
- * Copyright 2019 Google LLC. All Rights Reserved.
361
- * Licensed under the Apache License, Version 2.0 (the "License");
362
- * you may not use this file except in compliance with the License.
363
- * You may obtain a copy of the License at
364
- *
365
- * http://www.apache.org/licenses/LICENSE-2.0
366
- *
367
- * Unless required by applicable law or agreed to in writing, software
368
- * distributed under the License is distributed on an "AS IS" BASIS,
369
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
370
- * See the License for the specific language governing permissions and
371
- * limitations under the License.
372
- * =============================================================================
373
- */
374
- function Qe(e, t, n) {
375
- if (n == null || n === "linear")
376
- return e;
377
- if (n === "relu")
378
- return le(e, Ne(t));
379
- throw new Error(`Cannot compute gradient for fused activation ${n}.`);
380
- }
381
- function Ye(e, t) {
382
- let n = t;
383
- const s = ue(e.shape, t.shape);
384
- return s.length > 0 && (n = ae(n, s)), ce(n, e.shape);
385
- }
386
- function Ze(e, t, n, s) {
387
- if (t === "linear")
388
- return e;
389
- if (t === "relu")
390
- return fe(e);
391
- if (t === "elu")
392
- return $e(e);
393
- if (t === "relu6")
394
- return Se(e);
395
- if (t === "prelu")
396
- return Me(e, n);
397
- if (t === "leakyrelu")
398
- return ye(e, s);
399
- if (t === "sigmoid")
400
- return Ee(e);
401
- throw new Error(`Unknown fused activation ${t}.`);
402
- }
403
- const ze = (e, t) => !(e > 0) || t === "linear";
404
- /**
405
- * @license
406
- * Copyright 2021 Google LLC. All Rights Reserved.
407
- * Licensed under the Apache License, Version 2.0 (the "License");
408
- * you may not use this file except in compliance with the License.
409
- * You may obtain a copy of the License at
410
- *
411
- * http://www.apache.org/licenses/LICENSE-2.0
412
- *
413
- * Unless required by applicable law or agreed to in writing, software
414
- * distributed under the License is distributed on an "AS IS" BASIS,
415
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
416
- * See the License for the specific language governing permissions and
417
- * limitations under the License.
418
- * =============================================================================
419
- */
420
- const v = -2, _e = -1;
421
- function Le(e, t, n) {
422
- const s = e.shape.length;
423
- D(s === t.length, () => `Error in slice${s}D: Length of begin ${t} must match the rank of the array (${s}).`), D(s === n.length, () => `Error in slice${s}D: Length of size ${n} must match the rank of the array (${s}).`);
424
- for (let r = 0; r < s; ++r)
425
- D(t[r] + n[r] <= e.shape[r], () => `Error in slice${s}D: begin[${r}] + size[${r}] (${t[r] + n[r]}) would overflow input.shape[${r}] (${e.shape[r]})`);
426
- }
427
- function Ce(e) {
428
- const t = [];
429
- let n = 0;
430
- for (; e > 0; )
431
- e & 1 && t.push(n), e /= 2, n++;
432
- return t;
433
- }
434
- function Ge(e, t, n) {
435
- const s = [];
436
- for (let r = 0; r < e.length; r++)
437
- s[r] = Math.ceil((t[r] - e[r]) / n[r]);
438
- return s;
439
- }
440
- function j(e, t, n, s) {
441
- const r = [...e];
442
- for (let u = r.length; u < s.length; u++)
443
- r.push(1);
444
- for (let u = 0; u < n; u++)
445
- u === 0 ? r[t] = 1 : (r.splice(
446
- t,
447
- 0,
448
- 1
449
- /* element to add */
450
- ), r.pop());
451
- return r;
452
- }
453
- function q(e, t, n) {
454
- return n <= e ? n : n - (t - 1);
455
- }
456
- function J(e, t) {
457
- const n = [];
458
- for (let s = 0; s < e; s++)
459
- n.push(t + s);
460
- return n;
461
- }
462
- function Te(e, t, n, s, r, u, i, o, c) {
463
- const a = e.length;
464
- let p = new Array(a), g = new Array(a), l = new Array(a);
465
- if (t.length && n > 0) {
466
- const h = t[0], d = n + 1;
467
- p = Q(i, h, d, s, e), g = Y(o, h, d, r, e), l = j(u, h, d, e);
468
- } else
469
- for (let h = 0; h < a; h++)
470
- p[h] = z(i, s, u, e, h, c), g[h] = ee(o, r, u, e, h, c), l[h] = Z(u, h, c);
471
- return {
472
- begin: p,
473
- end: g,
474
- strides: l
475
- };
476
- }
477
- function Q(e, t, n, s, r) {
478
- const u = [...r], i = J(n, t);
479
- for (let o = 0; o < u.length; o++)
480
- if (i.indexOf(o) > -1)
481
- u[o] = 0;
482
- else {
483
- const c = q(t, n, o);
484
- let a = s[c];
485
- e & 1 << c && (a = 0), u[o] = a;
486
- }
487
- return u;
488
- }
489
- function Y(e, t, n, s, r) {
490
- const u = [...r], i = J(n, t);
491
- for (let o = 0; o < u.length; o++)
492
- if (i.indexOf(o) > -1)
493
- u[o] = Number.MAX_SAFE_INTEGER;
494
- else {
495
- const c = q(t, n, o);
496
- let a = s[c];
497
- e & 1 << c && (a = Number.MAX_SAFE_INTEGER), u[o] = a;
498
- }
499
- for (let o = 0; o < u.length; o++) {
500
- const c = r[o];
501
- u[o] < 0 && (u[o] += c), u[o] = O(0, u[o], r[o]);
502
- }
503
- return u;
504
- }
505
- function Z(e, t, n) {
506
- let s = e[t];
507
- return (n & 1 << t || s == null) && (s = 1), s;
508
- }
509
- function z(e, t, n, s, r, u) {
510
- let i = t[r];
511
- const o = n[r] || 1;
512
- (e & 1 << r || u & 1 << r || i == null) && (o > 0 ? i = Number.MIN_SAFE_INTEGER : i = Number.MAX_SAFE_INTEGER);
513
- const c = s[r];
514
- return i < 0 && (i += c), i = O(0, i, c - 1), i;
515
- }
516
- function ee(e, t, n, s, r, u) {
517
- let i = t[r];
518
- const o = n[r] || 1;
519
- (e & 1 << r || u & 1 << r || i == null) && (o > 0 ? i = Number.MAX_SAFE_INTEGER : i = Number.MIN_SAFE_INTEGER);
520
- const c = s[r];
521
- return i < 0 && (i += c), o > 0 ? i = O(0, i, c) : i = O(-1, i, c - 1), i;
522
- }
523
- function Fe(e, t, n) {
524
- let s = n.length;
525
- for (let r = 0; r < n.length; r++)
526
- if (n[r] > 1) {
527
- s = r;
528
- break;
529
- }
530
- for (let r = s + 1; r < n.length; r++)
531
- if (t[r] > 0 || n[r] !== e[r])
532
- return !1;
533
- return !0;
534
- }
535
- function Oe(e, t) {
536
- let n = e.length > 0 ? e[e.length - 1] : 1;
537
- for (let s = 0; s < e.length - 1; s++)
538
- n += e[s] * t[s];
539
- return n;
540
- }
541
- function Re(e, t, n) {
542
- let s;
543
- const r = e.shape.length;
544
- typeof t == "number" ? s = [t, ...new Array(r - 1).fill(0)] : t.length < r ? s = t.concat(new Array(r - t.length).fill(0)) : s = t.slice(), s.forEach((i) => {
545
- D(i !== -1, () => "slice() does not support negative begin indexing.");
546
- });
547
- let u;
548
- return n == null ? u = new Array(r).fill(-1) : typeof n == "number" ? u = [n, ...new Array(r - 1).fill(-1)] : n.length < r ? u = n.concat(new Array(r - n.length).fill(-1)) : u = n, u = u.map((i, o) => i >= 0 ? i : (D(i === -1, () => `Negative size values should be exactly -1 but got ${i} for the slice() size at index ${o}.`), e.shape[o] - s[o])), [s, u];
549
- }
550
- function Ve(e, t, n, s, r, u, i, o, c) {
551
- let a;
552
- if (s == null ? (a = new Array(t.length), a.fill(1)) : a = s, i != null && (i & i - 1) !== 0)
553
- throw new Error("Multiple ellipses in slice is not allowed.");
554
- let p = !1;
555
- const g = {
556
- dims: a.length,
557
- numAddAxisAfterEllipsis: 0,
558
- begin: t.slice(),
559
- end: n.slice(),
560
- strides: a.slice(),
561
- beginMask: r,
562
- endMask: u,
563
- ellipsisMask: i,
564
- newAxisMask: o,
565
- shrinkAxisMask: c
566
- };
567
- for (let f = 0; f < g.dims; f++)
568
- p && (1 << f & o) !== 0 && g.numAddAxisAfterEllipsis++, 1 << f & i && (p = !0);
569
- p || (g.ellipsisMask |= 1 << g.dims, g.dims++);
570
- const l = {
571
- dims: e.length,
572
- beginMask: 0,
573
- endMask: 0,
574
- beginValid: !1,
575
- endValid: !1
576
- };
577
- Ue(g, l);
578
- let h = !0, d = !0, A = !0;
579
- const m = [], b = [];
580
- for (let f = 0; f < e.length; ++f) {
581
- if (l.strides[f] === 0)
582
- throw Error(`strides[${f}] must be non-zero`);
583
- const w = !!(l.shrinkAxisMask & 1 << f), E = e[f];
584
- if (E === -1) {
585
- m.push(w ? 1 : -1);
586
- continue;
587
- }
588
- const I = [l.beginMask & 1 << f, l.endMask & 1 << f], y = [
589
- l.strides[f] > 0 ? 0 : -1,
590
- l.strides[f] > 0 ? E : E - 1
591
- ];
592
- if (w && l.strides[f] <= 0)
593
- throw Error("only stride 1 allowed on non-range indexing.");
594
- A = A && l.strides[f] === 1;
595
- const x = !!(l.beginMask & 1 << f && l.endMask & 1 << f);
596
- if (l.beginValid && l.endValid) {
597
- if (w) {
598
- const S = l.begin[f] < 0 ? E + l.begin[f] : l.begin[f];
599
- if (l.begin[f] = S, l.end[f] = l.begin[f] + 1, S < 0 || S >= E)
600
- throw Error(`slice index ${l.begin[f]} of dimension ${f} out of bounds.`);
601
- } else
602
- l.begin[f] = K(l.begin[f], 0, l.strides[f], E, I, y), l.end[f] = K(l.end[f], 1, l.strides[f], E, I, y);
603
- const M = l.strides[f] === 1 && l.begin[f] === 0 && l.end[f] === E;
604
- h = h && M, d = d && (f === 0 && l.strides[f] === 1 || M);
605
- } else
606
- h = h && l.strides[f] === 1 && x, d = d && (f === 0 && l.strides[f] === 1 || x);
607
- let $, _ = !1;
608
- if (l.beginValid && l.endValid ? ($ = l.end[f] - l.begin[f], _ = !0) : w ? ($ = 1, _ = !0) : x && E >= 0 && (l.strides[f] < 0 ? $ = -E : $ = E, _ = !0), _) {
609
- let M;
610
- $ === 0 || $ < 0 != l.strides[f] < 0 ? M = 0 : M = Math.trunc($ / l.strides[f]) + ($ % l.strides[f] !== 0 ? 1 : 0), m.push(M);
611
- } else
612
- m.push(-1);
613
- }
614
- for (let f = 0; f < l.finalShapeGatherIndices.length; ++f) {
615
- const w = l.finalShapeGatherIndices[f];
616
- w >= 0 ? b.push(m[w]) : w === v && b.push(1);
617
- }
618
- return {
619
- finalShapeSparse: b.filter((f, w) => l.finalShapeGatherIndices[w] !== v),
620
- finalShape: b,
621
- isIdentity: h,
622
- sliceDim0: d,
623
- isSimpleSlice: A,
624
- begin: l.begin,
625
- end: l.end,
626
- strides: l.strides
627
- };
628
- }
629
- function Ue(e, t) {
630
- t.beginMask = 0, t.endMask = 0, t.shrinkAxisMask = 0;
631
- let n = 0;
632
- t.beginValid = e.begin != null, t.endValid = e.end != null, t.begin = new Array(t.dims), t.end = new Array(t.dims), t.strides = new Array(t.dims), t.finalShapeGatherIndices = [], t.finalShapeGatherIndicesSparse = [], t.inputShapeGatherIndicesSparse = new Array(t.dims);
633
- for (let s = 0; s < e.dims; s++)
634
- if (1 << s & e.ellipsisMask) {
635
- const r = Math.min(t.dims - (e.dims - s) + 1 + e.numAddAxisAfterEllipsis, t.dims);
636
- for (; n < r; n++)
637
- t.begin[n] = 0, t.end[n] = 0, t.strides[n] = 1, t.beginMask |= 1 << n, t.endMask |= 1 << n, t.finalShapeGatherIndices.push(n), t.finalShapeGatherIndicesSparse.push(-1), t.inputShapeGatherIndicesSparse[n] = s;
638
- } else if (1 << s & e.newAxisMask)
639
- t.finalShapeGatherIndices.push(v), t.finalShapeGatherIndicesSparse.push(-1);
640
- else {
641
- if (n === t.begin.length)
642
- throw Error(`Index out of range using input dim ${n}; input has only ${t.dims} dims, ${t.begin.length}.`);
643
- e.begin != null && (t.begin[n] = e.begin[s]), e.end != null && (t.end[n] = e.end[s]), t.strides[n] = e.strides[s], e.beginMask & 1 << s && (t.beginMask |= 1 << n), e.endMask & 1 << s && (t.endMask |= 1 << n), e.shrinkAxisMask & 1 << s ? (t.finalShapeGatherIndices.push(_e), t.finalShapeGatherIndicesSparse.push(-1), t.shrinkAxisMask |= 1 << n) : (t.finalShapeGatherIndices.push(n), t.finalShapeGatherIndicesSparse.push(s)), t.inputShapeGatherIndicesSparse[n] = s, n++;
644
- }
645
- }
646
- function K(e, t, n, s, r, u) {
647
- if (r[t])
648
- return n > 0 ? u[t] : u[t + 1 & 1];
649
- {
650
- const i = e < 0 ? s + e : e;
651
- return i < u[0] ? u[0] : i > u[1] ? u[1] : i;
652
- }
653
- }
654
- const et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
655
- __proto__: null,
656
- assertParamsValid: Le,
657
- computeFlatOffset: Oe,
658
- computeOutShape: Ge,
659
- getNormalizedAxes: Te,
660
- isSliceContinous: Fe,
661
- maskToAxes: Ce,
662
- parseSliceParams: Re,
663
- sliceInfo: Ve,
664
- startForAxis: z,
665
- startIndicesWithElidedDims: Q,
666
- stopForAxis: ee,
667
- stopIndicesWithElidedDims: Y,
668
- stridesForAxis: Z,
669
- stridesWithElidedDims: j
670
- }, Symbol.toStringTag, { value: "Module" }));
671
- /**
672
- * @license
673
- * Copyright 2018 Google LLC. All Rights Reserved.
674
- * Licensed under the Apache License, Version 2.0 (the "License");
675
- * you may not use this file except in compliance with the License.
676
- * You may obtain a copy of the License at
677
- *
678
- * http://www.apache.org/licenses/LICENSE-2.0
679
- *
680
- * Unless required by applicable law or agreed to in writing, software
681
- * distributed under the License is distributed on an "AS IS" BASIS,
682
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
683
- * See the License for the specific language governing permissions and
684
- * limitations under the License.
685
- * =============================================================================
686
- */
687
- const tt = 1.7580993408473768, nt = 1.0507009873554805;
688
- export {
689
- Ve as A,
690
- Ge as B,
691
- Se as C,
692
- nt as S,
693
- tt as a,
694
- Ze as b,
695
- Je as c,
696
- X as d,
697
- he as e,
698
- B as f,
699
- Ke as g,
700
- Xe as h,
701
- Be as i,
702
- Ae as j,
703
- je as k,
704
- Ye as l,
705
- Qe as m,
706
- et as n,
707
- qe as o,
708
- Re as p,
709
- Le as q,
710
- Fe as r,
711
- ze as s,
712
- P as t,
713
- Oe as u,
714
- Ne as v,
715
- Ee as w,
716
- $e as x,
717
- ye as y,
718
- Me as z
719
- };