@genai-fi/nanogpt 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -10
- package/dist/Generator.d.ts +0 -82
- package/dist/Generator.js +0 -11941
- package/dist/RealDiv-CGwv0liw.js +0 -365
- package/dist/Reshape-BW__R4mZ.js +0 -79
- package/dist/Reshape-CPBkTIH2.js +0 -14
- package/dist/TeachableLLM.d.ts +0 -70
- package/dist/TeachableLLM.js +0 -273
- package/dist/Trainer.d.ts +0 -43
- package/dist/Trainer.js +0 -244
- package/dist/_commonjsHelpers-ByX85dGu.js +0 -33
- package/dist/axis_util-GTVlo58H.js +0 -55
- package/dist/backend.d.ts +0 -2
- package/dist/backend.js +0 -13
- package/dist/backend_util-GaFarB78.js +0 -425
- package/dist/backend_webgpu-BqASlsbV.js +0 -545
- package/dist/binary_op_util-pKXltfxI.js +0 -192
- package/dist/broadcast_to-eS93CCN_.js +0 -28
- package/dist/checks/appendCache.d.ts +0 -1
- package/dist/checks/appendCache.js +0 -22
- package/dist/checks/attentionMask.d.ts +0 -1
- package/dist/checks/attentionMask.js +0 -37
- package/dist/checks/check.d.ts +0 -9
- package/dist/checks/check.js +0 -20
- package/dist/checks/gelu.d.ts +0 -1
- package/dist/checks/gelu.js +0 -18
- package/dist/checks/index.d.ts +0 -26
- package/dist/checks/index.js +0 -28
- package/dist/checks/matMulGelu.d.ts +0 -1
- package/dist/checks/matMulGelu.js +0 -28
- package/dist/checks/normRMS.d.ts +0 -1
- package/dist/checks/normRMS.js +0 -16
- package/dist/checks/normRMSGrad.d.ts +0 -1
- package/dist/checks/normRMSGrad.js +0 -12
- package/dist/checks/packUnpack.d.ts +0 -1
- package/dist/checks/packUnpack.js +0 -18
- package/dist/checks/qkv.d.ts +0 -1
- package/dist/checks/qkv.js +0 -34
- package/dist/checks/rope.d.ts +0 -1
- package/dist/checks/rope.js +0 -36
- package/dist/checks/weights.d.ts +0 -14
- package/dist/checks/weights.js +0 -31
- package/dist/clip_by_value-DDA7rrcT.js +0 -12
- package/dist/complex-DI35Q-gW.js +0 -11
- package/dist/complex_util-Yc1A_gV1.js +0 -55
- package/dist/concat-CAQpCret.js +0 -17
- package/dist/concat_util-D18dJ4fD.js +0 -22
- package/dist/data/docx.d.ts +0 -2
- package/dist/data/docx.js +0 -15
- package/dist/data/parquet.d.ts +0 -2
- package/dist/data/parquet.js +0 -17
- package/dist/data/pdf.d.ts +0 -2
- package/dist/data/pdf.js +0 -14
- package/dist/data/textLoader.d.ts +0 -7
- package/dist/data/textLoader.js +0 -108
- package/dist/dataset-CGGp1z9P.js +0 -1124
- package/dist/dropout_util--NxWuYg2.js +0 -27
- package/dist/expand_dims-Bkd1YD5x.js +0 -11
- package/dist/exports_initializers-CYzKLjN7.js +0 -7
- package/dist/floor-BQtb-Azg.js +0 -9
- package/dist/gather-qIqEqaGn.js +0 -9
- package/dist/gelu-B220X1Go.js +0 -26
- package/dist/gpgpu_math-BwvV12df.js +0 -2022
- package/dist/index-CUXkjxiT.js +0 -3516
- package/dist/index-CieiGp4Y.js +0 -349
- package/dist/index-CjOWnMXP.js +0 -7308
- package/dist/index-Cp39cXWe.js +0 -1016
- package/dist/index-D5v913EJ.js +0 -4
- package/dist/index-DmeWGGmS.js +0 -1074
- package/dist/index-DvYrXKkX.js +0 -113
- package/dist/index-Ksja3su6.js +0 -151
- package/dist/index-xuotMAFm.js +0 -118
- package/dist/inference/types.d.ts +0 -16
- package/dist/inference/types.js +0 -1
- package/dist/jszip.min-BZhlzntC.js +0 -2313
- package/dist/kernel_funcs_utils-pq0CK9co.js +0 -306
- package/dist/layers/BaseLayer.d.ts +0 -44
- package/dist/layers/BaseLayer.js +0 -74
- package/dist/layers/CausalSelfAttention.d.ts +0 -39
- package/dist/layers/CausalSelfAttention.js +0 -86
- package/dist/layers/LoRA.d.ts +0 -14
- package/dist/layers/LoRA.js +0 -58
- package/dist/layers/MLP.d.ts +0 -17
- package/dist/layers/MLP.js +0 -44
- package/dist/layers/PositionEmbedding.d.ts +0 -8
- package/dist/layers/PositionEmbedding.js +0 -31
- package/dist/layers/RMSNorm.d.ts +0 -12
- package/dist/layers/RMSNorm.js +0 -22
- package/dist/layers/RoPECache.d.ts +0 -18
- package/dist/layers/RoPECache.js +0 -50
- package/dist/layers/TiedEmbedding.d.ts +0 -13
- package/dist/layers/TiedEmbedding.js +0 -36
- package/dist/layers/TransformerBlock.d.ts +0 -27
- package/dist/layers/TransformerBlock.js +0 -40
- package/dist/layers/WeightStore.d.ts +0 -20
- package/dist/layers/WeightStore.js +0 -76
- package/dist/loader/load.d.ts +0 -6
- package/dist/loader/load.js +0 -68
- package/dist/loader/loadHF.d.ts +0 -8
- package/dist/loader/loadHF.js +0 -22
- package/dist/loader/loadTransformers.d.ts +0 -4
- package/dist/loader/loadTransformers.js +0 -44
- package/dist/loader/loadZipMeta.d.ts +0 -3
- package/dist/loader/loadZipMeta.js +0 -16
- package/dist/loader/newZipLoad.d.ts +0 -3
- package/dist/loader/newZipLoad.js +0 -31
- package/dist/loader/oldZipLoad.d.ts +0 -9
- package/dist/loader/oldZipLoad.js +0 -80
- package/dist/loader/save.d.ts +0 -16
- package/dist/loader/save.js +0 -90
- package/dist/loader/types.d.ts +0 -67
- package/dist/loader/types.js +0 -1
- package/dist/main.d.ts +0 -50
- package/dist/main.js +0 -109
- package/dist/matMul16-BcVC_E62.js +0 -80
- package/dist/matMulGelu-JNLZqKQp.js +0 -163
- package/dist/mat_mul-DhG0Newp.js +0 -11
- package/dist/mod-CSdCpRjf.js +0 -11
- package/dist/models/NanoGPTV1.d.ts +0 -16
- package/dist/models/NanoGPTV1.js +0 -99
- package/dist/models/NanoGPTV2.d.ts +0 -16
- package/dist/models/NanoGPTV2.js +0 -90
- package/dist/models/config.d.ts +0 -27
- package/dist/models/config.js +0 -50
- package/dist/models/factory.d.ts +0 -3
- package/dist/models/factory.js +0 -16
- package/dist/models/model.d.ts +0 -44
- package/dist/models/model.js +0 -134
- package/dist/non_max_suppression_impl-B2W7YjZB.js +0 -102
- package/dist/not_equal-hurPF26l.js +0 -64
- package/dist/ones-BytntneX.js +0 -14
- package/dist/ops/adamAdjust.d.ts +0 -2
- package/dist/ops/adamAdjust.js +0 -9
- package/dist/ops/adamMoments.d.ts +0 -2
- package/dist/ops/adamMoments.js +0 -9
- package/dist/ops/add16.d.ts +0 -2
- package/dist/ops/add16.js +0 -9
- package/dist/ops/appendCache.d.ts +0 -2
- package/dist/ops/appendCache.js +0 -22
- package/dist/ops/attentionMask.d.ts +0 -2
- package/dist/ops/attentionMask.js +0 -10
- package/dist/ops/concat16.d.ts +0 -2
- package/dist/ops/concat16.js +0 -9
- package/dist/ops/cpu/adamAdjust.d.ts +0 -1
- package/dist/ops/cpu/adamAdjust.js +0 -18
- package/dist/ops/cpu/adamMoments.d.ts +0 -1
- package/dist/ops/cpu/adamMoments.js +0 -16
- package/dist/ops/cpu/appendCache.d.ts +0 -1
- package/dist/ops/cpu/appendCache.js +0 -23
- package/dist/ops/cpu/attentionMask.d.ts +0 -1
- package/dist/ops/cpu/attentionMask.js +0 -22
- package/dist/ops/cpu/fusedSoftmax.d.ts +0 -9
- package/dist/ops/cpu/fusedSoftmax.js +0 -29
- package/dist/ops/cpu/gatherSub.d.ts +0 -1
- package/dist/ops/cpu/gatherSub.js +0 -18
- package/dist/ops/cpu/gelu.d.ts +0 -1
- package/dist/ops/cpu/gelu.js +0 -40
- package/dist/ops/cpu/matMul16.d.ts +0 -1
- package/dist/ops/cpu/matMul16.js +0 -15
- package/dist/ops/cpu/matMulGelu.d.ts +0 -1
- package/dist/ops/cpu/matMulGelu.js +0 -53
- package/dist/ops/cpu/matMulMul.d.ts +0 -1
- package/dist/ops/cpu/matMulMul.js +0 -23
- package/dist/ops/cpu/mulDropout.d.ts +0 -1
- package/dist/ops/cpu/mulDropout.js +0 -23
- package/dist/ops/cpu/normRMS.d.ts +0 -1
- package/dist/ops/cpu/normRMS.js +0 -39
- package/dist/ops/cpu/qkv.d.ts +0 -5
- package/dist/ops/cpu/qkv.js +0 -41
- package/dist/ops/cpu/rope.d.ts +0 -6
- package/dist/ops/cpu/rope.js +0 -38
- package/dist/ops/cpu/scatterSub.d.ts +0 -1
- package/dist/ops/cpu/scatterSub.js +0 -23
- package/dist/ops/dot16.d.ts +0 -2
- package/dist/ops/dot16.js +0 -42
- package/dist/ops/dropout.d.ts +0 -2
- package/dist/ops/dropout.js +0 -14
- package/dist/ops/dropout16.d.ts +0 -2
- package/dist/ops/dropout16.js +0 -25
- package/dist/ops/gatherSub.d.ts +0 -2
- package/dist/ops/gatherSub.js +0 -9
- package/dist/ops/gelu.d.ts +0 -3
- package/dist/ops/gelu.js +0 -8
- package/dist/ops/globalNorm.d.ts +0 -2
- package/dist/ops/globalNorm.js +0 -13
- package/dist/ops/grads/add16.d.ts +0 -1
- package/dist/ops/grads/add16.js +0 -26
- package/dist/ops/grads/attentionMask.d.ts +0 -1
- package/dist/ops/grads/attentionMask.js +0 -21
- package/dist/ops/grads/dropout16.d.ts +0 -1
- package/dist/ops/grads/dropout16.js +0 -2
- package/dist/ops/grads/gelu.d.ts +0 -2
- package/dist/ops/grads/gelu.js +0 -5
- package/dist/ops/grads/matMul16.d.ts +0 -2
- package/dist/ops/grads/matMul16.js +0 -9
- package/dist/ops/grads/matMulGelu.d.ts +0 -1
- package/dist/ops/grads/matMulGelu.js +0 -17
- package/dist/ops/grads/mul16.d.ts +0 -1
- package/dist/ops/grads/mul16.js +0 -4
- package/dist/ops/grads/normRMS.d.ts +0 -3
- package/dist/ops/grads/normRMS.js +0 -33
- package/dist/ops/grads/pack16.d.ts +0 -2
- package/dist/ops/grads/pack16.js +0 -6
- package/dist/ops/grads/qkv.d.ts +0 -3
- package/dist/ops/grads/qkv.js +0 -34
- package/dist/ops/grads/rope.d.ts +0 -2
- package/dist/ops/grads/rope.js +0 -5
- package/dist/ops/grads/softmax16.d.ts +0 -2
- package/dist/ops/grads/softmax16.js +0 -25
- package/dist/ops/grads/unpack16.d.ts +0 -2
- package/dist/ops/grads/unpack16.js +0 -5
- package/dist/ops/grads/utils.d.ts +0 -4
- package/dist/ops/grads/utils.js +0 -14
- package/dist/ops/log.d.ts +0 -0
- package/dist/ops/log.js +0 -1
- package/dist/ops/matMul16.d.ts +0 -15
- package/dist/ops/matMul16.js +0 -13
- package/dist/ops/matMulGelu.d.ts +0 -3
- package/dist/ops/matMulGelu.js +0 -14
- package/dist/ops/matMulMul.d.ts +0 -2
- package/dist/ops/matMulMul.js +0 -9
- package/dist/ops/mul16.d.ts +0 -2
- package/dist/ops/mul16.js +0 -39
- package/dist/ops/mulDrop.d.ts +0 -2
- package/dist/ops/mulDrop.js +0 -9
- package/dist/ops/normRMS.d.ts +0 -2
- package/dist/ops/normRMS.js +0 -19
- package/dist/ops/pack16.d.ts +0 -2
- package/dist/ops/pack16.js +0 -5
- package/dist/ops/qkv.d.ts +0 -2
- package/dist/ops/qkv.js +0 -10
- package/dist/ops/reshape16.d.ts +0 -2
- package/dist/ops/reshape16.js +0 -41
- package/dist/ops/rope.d.ts +0 -3
- package/dist/ops/rope.js +0 -7
- package/dist/ops/scatterSub.d.ts +0 -2
- package/dist/ops/scatterSub.js +0 -9
- package/dist/ops/slice16.d.ts +0 -2
- package/dist/ops/slice16.js +0 -9
- package/dist/ops/softmax16.d.ts +0 -2
- package/dist/ops/softmax16.js +0 -9
- package/dist/ops/sub16.d.ts +0 -2
- package/dist/ops/sub16.js +0 -8
- package/dist/ops/sum16.d.ts +0 -2
- package/dist/ops/sum16.js +0 -13
- package/dist/ops/transpose16.d.ts +0 -3
- package/dist/ops/transpose16.js +0 -40
- package/dist/ops/unpack16.d.ts +0 -2
- package/dist/ops/unpack16.js +0 -6
- package/dist/ops/webgl/adamAdjust.d.ts +0 -1
- package/dist/ops/webgl/adamAdjust.js +0 -49
- package/dist/ops/webgl/adamMoments.d.ts +0 -1
- package/dist/ops/webgl/adamMoments.js +0 -40
- package/dist/ops/webgl/appendCache.d.ts +0 -1
- package/dist/ops/webgl/appendCache.js +0 -44
- package/dist/ops/webgl/attentionMask.d.ts +0 -1
- package/dist/ops/webgl/attentionMask.js +0 -45
- package/dist/ops/webgl/dropout16.d.ts +0 -1
- package/dist/ops/webgl/dropout16.js +0 -11
- package/dist/ops/webgl/fusedSoftmax.d.ts +0 -11
- package/dist/ops/webgl/fusedSoftmax.js +0 -80
- package/dist/ops/webgl/gatherSub.d.ts +0 -1
- package/dist/ops/webgl/gatherSub.js +0 -27
- package/dist/ops/webgl/gelu.d.ts +0 -2
- package/dist/ops/webgl/gelu.js +0 -50
- package/dist/ops/webgl/log.d.ts +0 -17
- package/dist/ops/webgl/log.js +0 -23
- package/dist/ops/webgl/matMul16.d.ts +0 -1
- package/dist/ops/webgl/matMul16.js +0 -45
- package/dist/ops/webgl/matMulGelu.d.ts +0 -21
- package/dist/ops/webgl/matMulGelu.js +0 -9
- package/dist/ops/webgl/matMulMul.d.ts +0 -14
- package/dist/ops/webgl/matMulMul.js +0 -28
- package/dist/ops/webgl/mulDropout.d.ts +0 -1
- package/dist/ops/webgl/mulDropout.js +0 -41
- package/dist/ops/webgl/normRMS.d.ts +0 -1
- package/dist/ops/webgl/normRMS.js +0 -93
- package/dist/ops/webgl/qkv.d.ts +0 -1
- package/dist/ops/webgl/qkv.js +0 -46
- package/dist/ops/webgl/rope.d.ts +0 -1
- package/dist/ops/webgl/rope.js +0 -56
- package/dist/ops/webgl/scatterSub.d.ts +0 -1
- package/dist/ops/webgl/scatterSub.js +0 -27
- package/dist/ops/webgpu/adamAdjust.d.ts +0 -1
- package/dist/ops/webgpu/adamAdjust.js +0 -57
- package/dist/ops/webgpu/adamMoments.d.ts +0 -1
- package/dist/ops/webgpu/adamMoments.js +0 -60
- package/dist/ops/webgpu/add16.d.ts +0 -1
- package/dist/ops/webgpu/add16.js +0 -13
- package/dist/ops/webgpu/appendCache.d.ts +0 -1
- package/dist/ops/webgpu/appendCache.js +0 -105
- package/dist/ops/webgpu/attentionMask.d.ts +0 -1
- package/dist/ops/webgpu/attentionMask.js +0 -26
- package/dist/ops/webgpu/attentionMask32_program.d.ts +0 -19
- package/dist/ops/webgpu/attentionMask32_program.js +0 -54
- package/dist/ops/webgpu/clipScale.d.ts +0 -1
- package/dist/ops/webgpu/clipScale.js +0 -58
- package/dist/ops/webgpu/concat16.d.ts +0 -19
- package/dist/ops/webgpu/concat16.js +0 -126
- package/dist/ops/webgpu/dropout16.d.ts +0 -1
- package/dist/ops/webgpu/dropout16.js +0 -51
- package/dist/ops/webgpu/gatherSub.d.ts +0 -1
- package/dist/ops/webgpu/gatherSub.js +0 -39
- package/dist/ops/webgpu/gelu.d.ts +0 -14
- package/dist/ops/webgpu/gelu.js +0 -141
- package/dist/ops/webgpu/index.d.ts +0 -0
- package/dist/ops/webgpu/index.js +0 -26
- package/dist/ops/webgpu/matMul16.d.ts +0 -1
- package/dist/ops/webgpu/matMul16.js +0 -65
- package/dist/ops/webgpu/matMul16_program.d.ts +0 -42
- package/dist/ops/webgpu/matMul16_program.js +0 -343
- package/dist/ops/webgpu/mul16.d.ts +0 -1
- package/dist/ops/webgpu/mul16.js +0 -13
- package/dist/ops/webgpu/norm2.d.ts +0 -1
- package/dist/ops/webgpu/norm2.js +0 -76
- package/dist/ops/webgpu/normRMS.d.ts +0 -1
- package/dist/ops/webgpu/normRMS.js +0 -34
- package/dist/ops/webgpu/normRMS16_program.d.ts +0 -10
- package/dist/ops/webgpu/normRMS16_program.js +0 -25
- package/dist/ops/webgpu/normRMS32_program.d.ts +0 -10
- package/dist/ops/webgpu/normRMS32_program.js +0 -25
- package/dist/ops/webgpu/normRMSGrad.d.ts +0 -1
- package/dist/ops/webgpu/normRMSGrad.js +0 -284
- package/dist/ops/webgpu/pack16.d.ts +0 -1
- package/dist/ops/webgpu/pack16.js +0 -18
- package/dist/ops/webgpu/pack16_program.d.ts +0 -19
- package/dist/ops/webgpu/pack16_program.js +0 -92
- package/dist/ops/webgpu/qkv.d.ts +0 -1
- package/dist/ops/webgpu/qkv.js +0 -24
- package/dist/ops/webgpu/rope.d.ts +0 -1
- package/dist/ops/webgpu/rope.js +0 -135
- package/dist/ops/webgpu/scatterSub.d.ts +0 -1
- package/dist/ops/webgpu/scatterSub.js +0 -40
- package/dist/ops/webgpu/slice16.d.ts +0 -7
- package/dist/ops/webgpu/slice16.js +0 -69
- package/dist/ops/webgpu/softmax16.d.ts +0 -17
- package/dist/ops/webgpu/softmax16.js +0 -21
- package/dist/ops/webgpu/softmax16_program.d.ts +0 -13
- package/dist/ops/webgpu/softmax16_program.js +0 -73
- package/dist/ops/webgpu/softmax16_subgroup_program.d.ts +0 -17
- package/dist/ops/webgpu/softmax16_subgroup_program.js +0 -75
- package/dist/ops/webgpu/softmax16grad.d.ts +0 -1
- package/dist/ops/webgpu/softmax16grad.js +0 -37
- package/dist/ops/webgpu/sub16.d.ts +0 -1
- package/dist/ops/webgpu/sub16.js +0 -13
- package/dist/ops/webgpu/sum16.d.ts +0 -1
- package/dist/ops/webgpu/sum16.js +0 -38
- package/dist/ops/webgpu/transpose16.d.ts +0 -1
- package/dist/ops/webgpu/transpose16.js +0 -34
- package/dist/ops/webgpu/transpose16_program.d.ts +0 -16
- package/dist/ops/webgpu/transpose16_program.js +0 -50
- package/dist/ops/webgpu/transpose16_shared_program.d.ts +0 -15
- package/dist/ops/webgpu/transpose16_shared_program.js +0 -70
- package/dist/ops/webgpu/unpack16.d.ts +0 -1
- package/dist/ops/webgpu/unpack16.js +0 -48
- package/dist/ops/webgpu/utils/binary_op.d.ts +0 -35
- package/dist/ops/webgpu/utils/binary_op.js +0 -139
- package/dist/ops/webgpu/utils/deviceInfo.d.ts +0 -7
- package/dist/ops/webgpu/utils/deviceInfo.js +0 -11
- package/dist/ops/webgpu/utils/reductions.d.ts +0 -43
- package/dist/ops/webgpu/utils/reductions.js +0 -275
- package/dist/ops-CsXeTq1P.js +0 -476
- package/dist/pack16-bqltoUlR.js +0 -39
- package/dist/papaparse.min-C0cScC2i.js +0 -418
- package/dist/parquet-Bqjmp2vo.js +0 -44231
- package/dist/patches/webgpu_backend.d.ts +0 -18
- package/dist/patches/webgpu_backend.js +0 -56
- package/dist/patches/webgpu_base.d.ts +0 -21
- package/dist/patches/webgpu_base.js +0 -34
- package/dist/patches/webgpu_program.d.ts +0 -36
- package/dist/patches/webgpu_program.js +0 -400
- package/dist/pdf-NIhmP3sq.js +0 -19477
- package/dist/rand_util-CZ7yLoUm.js +0 -50
- package/dist/random_normal-IBRrha8a.js +0 -14
- package/dist/random_width-DN5ZtQkM.js +0 -9796
- package/dist/range-C-CjF-LI.js +0 -10
- package/dist/relu-J_X6MUzx.js +0 -9
- package/dist/reshape-BDOuCSNW.js +0 -9
- package/dist/resize_nearest_neighbor-BojqlfRe.js +0 -150
- package/dist/rope-DcrZM_e6.js +0 -24
- package/dist/scatter_nd_util-ByNJaL6I.js +0 -46
- package/dist/segment_util-Dasb2Zaf.js +0 -43
- package/dist/selu_util-BLhIqRkw.js +0 -44
- package/dist/shared-3agzAqQ_.js +0 -53
- package/dist/shared-CagdqkLh.js +0 -2143
- package/dist/slice-BzS11Qh0.js +0 -12
- package/dist/slice_util-CC35pLmT.js +0 -153
- package/dist/softmax-D4q1LJN7.js +0 -12
- package/dist/split-C2Sj255c.js +0 -9
- package/dist/squeeze-ho4wLUek.js +0 -10
- package/dist/stack-DudVrtmG.js +0 -11
- package/dist/step-BTxPtq1r.js +0 -261
- package/dist/sum-BpiwSWvg.js +0 -11
- package/dist/tensor-BWFldCso.js +0 -8
- package/dist/tensor1d-LMGMIUlr.js +0 -11
- package/dist/tensor2d-BnXMKScO.js +0 -14
- package/dist/tensor4d-C6UCG_u8.js +0 -14
- package/dist/tfjs_backend-BGnG-ppu.js +0 -654
- package/dist/tile-CFy-xTO6.js +0 -11
- package/dist/tokeniser/BaseTokeniser.d.ts +0 -33
- package/dist/tokeniser/BaseTokeniser.js +0 -124
- package/dist/tokeniser/CharTokeniser.d.ts +0 -24
- package/dist/tokeniser/CharTokeniser.js +0 -107
- package/dist/tokeniser/bpe.d.ts +0 -28
- package/dist/tokeniser/bpe.js +0 -173
- package/dist/tokeniser/messages.d.ts +0 -61
- package/dist/tokeniser/messages.js +0 -1
- package/dist/tokeniser/type.d.ts +0 -34
- package/dist/tokeniser/type.js +0 -1
- package/dist/training/AdamW.d.ts +0 -36
- package/dist/training/AdamW.js +0 -138
- package/dist/training/BasicTrainer.d.ts +0 -63
- package/dist/training/BasicTrainer.js +0 -265
- package/dist/training/DatasetBuilder.d.ts +0 -26
- package/dist/training/DatasetBuilder.js +0 -86
- package/dist/training/Evaluator.d.ts +0 -19
- package/dist/training/Evaluator.js +0 -39
- package/dist/training/LRScheduler.d.ts +0 -12
- package/dist/training/LRScheduler.js +0 -34
- package/dist/training/PreTrainer.d.ts +0 -11
- package/dist/training/PreTrainer.js +0 -20
- package/dist/training/SFTTrainer.d.ts +0 -12
- package/dist/training/SFTTrainer.js +0 -22
- package/dist/training/loss.d.ts +0 -3
- package/dist/training/loss.js +0 -24
- package/dist/training/orthoGrad.d.ts +0 -2
- package/dist/training/orthoGrad.js +0 -10
- package/dist/training/sparseCrossEntropy.d.ts +0 -7
- package/dist/training/sparseCrossEntropy.js +0 -69
- package/dist/training/tasks/ConversationTask.d.ts +0 -18
- package/dist/training/tasks/ConversationTask.js +0 -40
- package/dist/training/tasks/PretrainingTask.d.ts +0 -17
- package/dist/training/tasks/PretrainingTask.js +0 -47
- package/dist/training/tasks/StartSentenceTask.d.ts +0 -18
- package/dist/training/tasks/StartSentenceTask.js +0 -49
- package/dist/training/tasks/Task.d.ts +0 -22
- package/dist/training/tasks/Task.js +0 -68
- package/dist/training/tasks/splitter.d.ts +0 -5
- package/dist/training/tasks/splitter.js +0 -21
- package/dist/training/types.d.ts +0 -78
- package/dist/training/types.js +0 -1
- package/dist/training/validation.d.ts +0 -17
- package/dist/training/validation.js +0 -84
- package/dist/transpose-9kRxIXWR.js +0 -36
- package/dist/unsorted_segment_sum-DJvk5xnh.js +0 -277
- package/dist/utilities/arrayClose.d.ts +0 -1
- package/dist/utilities/arrayClose.js +0 -20
- package/dist/utilities/datasetID.d.ts +0 -2
- package/dist/utilities/datasetID.js +0 -21
- package/dist/utilities/dummy.d.ts +0 -9
- package/dist/utilities/dummy.js +0 -43
- package/dist/utilities/multinomialCPU.d.ts +0 -2
- package/dist/utilities/multinomialCPU.js +0 -13
- package/dist/utilities/naming.d.ts +0 -4
- package/dist/utilities/naming.js +0 -1
- package/dist/utilities/packed.d.ts +0 -4
- package/dist/utilities/packed.js +0 -15
- package/dist/utilities/parameters.d.ts +0 -11
- package/dist/utilities/parameters.js +0 -57
- package/dist/utilities/performance.d.ts +0 -2
- package/dist/utilities/performance.js +0 -16
- package/dist/utilities/profile.d.ts +0 -17
- package/dist/utilities/profile.js +0 -38
- package/dist/utilities/safetensors.d.ts +0 -3
- package/dist/utilities/safetensors.js +0 -83
- package/dist/utilities/sentences.d.ts +0 -5
- package/dist/utilities/sentences.js +0 -41
- package/dist/utilities/tokenParse.d.ts +0 -1
- package/dist/utilities/tokenParse.js +0 -21
- package/dist/utilities/topP.d.ts +0 -1
- package/dist/utilities/topP.js +0 -13
- package/dist/utilities/waitForModel.d.ts +0 -2
- package/dist/utilities/waitForModel.js +0 -12
- package/dist/utilities/weights.d.ts +0 -12
- package/dist/utilities/weights.js +0 -45
- package/dist/utilities/yielder.d.ts +0 -1
- package/dist/utilities/yielder.js +0 -7
- package/dist/variable-Ck482e3n.js +0 -7
- package/dist/webgpu_program-B4HmApL1.js +0 -525
- package/dist/webgpu_util-DYlGSwOJ.js +0 -64
- package/dist/zeros-DvZpK8s6.js +0 -13
- package/dist/zeros_like-CWjDdwr-.js +0 -721
|
@@ -1,2022 +0,0 @@
|
|
|
1
|
-
import { ab as $, U as E, aR as X, ac as T, aS as ae, K as N, aT as G, x as ie, a9 as k, ad as ce } from "./index-CUXkjxiT.js";
|
|
2
|
-
import { b as se } from "./backend_util-GaFarB78.js";
|
|
3
|
-
const w = {}, M = {
|
|
4
|
-
alpha: !1,
|
|
5
|
-
antialias: !1,
|
|
6
|
-
premultipliedAlpha: !1,
|
|
7
|
-
preserveDrawingBuffer: !1,
|
|
8
|
-
depth: !1,
|
|
9
|
-
stencil: !1,
|
|
10
|
-
failIfMajorPerformanceCaveat: !0
|
|
11
|
-
};
|
|
12
|
-
function ut(e, t) {
|
|
13
|
-
w[e] = t;
|
|
14
|
-
}
|
|
15
|
-
function A(e, t) {
|
|
16
|
-
if (!(e in w) || t != null) {
|
|
17
|
-
const r = le(e, t);
|
|
18
|
-
if (r !== null)
|
|
19
|
-
w[e] = r;
|
|
20
|
-
else
|
|
21
|
-
return console.log("Could not get context for WebGL version", e), null;
|
|
22
|
-
}
|
|
23
|
-
const n = w[e];
|
|
24
|
-
return n == null || n.isContextLost() ? (delete w[e], A(e)) : (n.disable(n.DEPTH_TEST), n.disable(n.STENCIL_TEST), n.disable(n.BLEND), n.disable(n.DITHER), n.disable(n.POLYGON_OFFSET_FILL), n.disable(n.SAMPLE_COVERAGE), n.enable(n.SCISSOR_TEST), n.enable(n.CULL_FACE), n.cullFace(n.BACK), w[e]);
|
|
25
|
-
}
|
|
26
|
-
function ue(e) {
|
|
27
|
-
if (!$().getBool("IS_SAFARI") && typeof OffscreenCanvas < "u" && e === 2)
|
|
28
|
-
return new OffscreenCanvas(300, 150);
|
|
29
|
-
if (typeof document < "u")
|
|
30
|
-
return document.createElement("canvas");
|
|
31
|
-
throw new Error("Cannot create a canvas in this context");
|
|
32
|
-
}
|
|
33
|
-
function le(e, t) {
|
|
34
|
-
if (e !== 1 && e !== 2)
|
|
35
|
-
throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");
|
|
36
|
-
const n = t ?? ue(e);
|
|
37
|
-
return n.addEventListener("webglcontextlost", (r) => {
|
|
38
|
-
r.preventDefault(), delete w[e];
|
|
39
|
-
}, !1), $().getBool("SOFTWARE_WEBGL_ENABLED") && (M.failIfMajorPerformanceCaveat = !1), e === 1 ? (
|
|
40
|
-
// tslint:disable-next-line
|
|
41
|
-
n.getContext("webgl", M) || n.getContext("experimental-webgl", M)
|
|
42
|
-
) : n.getContext("webgl2", M);
|
|
43
|
-
}
|
|
44
|
-
var H;
|
|
45
|
-
(function(e) {
|
|
46
|
-
e[e.DENSE = 0] = "DENSE", e[e.SHARED_BATCH = 1] = "SHARED_BATCH";
|
|
47
|
-
})(H || (H = {}));
|
|
48
|
-
var q;
|
|
49
|
-
(function(e) {
|
|
50
|
-
e[e.RENDER = 0] = "RENDER", e[e.UPLOAD = 1] = "UPLOAD", e[e.PIXELS = 2] = "PIXELS", e[e.DOWNLOAD = 3] = "DOWNLOAD";
|
|
51
|
-
})(q || (q = {}));
|
|
52
|
-
var j;
|
|
53
|
-
(function(e) {
|
|
54
|
-
e[e.UNPACKED_FLOAT16 = 0] = "UNPACKED_FLOAT16", e[e.UNPACKED_FLOAT32 = 1] = "UNPACKED_FLOAT32", e[e.PACKED_4X1_UNSIGNED_BYTE = 2] = "PACKED_4X1_UNSIGNED_BYTE", e[e.PACKED_2X2_FLOAT32 = 3] = "PACKED_2X2_FLOAT32", e[e.PACKED_2X2_FLOAT16 = 4] = "PACKED_2X2_FLOAT16";
|
|
55
|
-
})(j || (j = {}));
|
|
56
|
-
function lt(e, t) {
|
|
57
|
-
return [t, e];
|
|
58
|
-
}
|
|
59
|
-
function ft(e, t) {
|
|
60
|
-
return e * t;
|
|
61
|
-
}
|
|
62
|
-
function xt(e) {
|
|
63
|
-
const t = E(e), n = Math.ceil(t / 4);
|
|
64
|
-
return X(n);
|
|
65
|
-
}
|
|
66
|
-
function fe(e, t) {
|
|
67
|
-
return [
|
|
68
|
-
Math.max(1, Math.ceil(t / 2)),
|
|
69
|
-
Math.max(1, Math.ceil(e / 2))
|
|
70
|
-
];
|
|
71
|
-
}
|
|
72
|
-
function dt(e, t) {
|
|
73
|
-
const [n, r] = fe(e, t);
|
|
74
|
-
return n * r * 4;
|
|
75
|
-
}
|
|
76
|
-
function K(e, t) {
|
|
77
|
-
const n = e;
|
|
78
|
-
let r, o, a, i, c, s, l, u, f, d;
|
|
79
|
-
return $().getNumber("WEBGL_VERSION") === 2 ? (r = n.R32F, o = n.R16F, a = n.RGBA16F, i = n.RGBA32F, c = n.RED, l = 4, u = 1, f = n.HALF_FLOAT, d = n.FLOAT, s = n.RGBA8) : (r = e.RGBA, o = e.RGBA, a = e.RGBA, i = n.RGBA, c = e.RGBA, l = 4, u = 4, f = t != null ? t.HALF_FLOAT_OES : null, d = e.FLOAT, s = e.RGBA), {
|
|
80
|
-
internalFormatFloat: r,
|
|
81
|
-
internalFormatHalfFloat: o,
|
|
82
|
-
internalFormatPackedHalfFloat: a,
|
|
83
|
-
internalFormatPackedFloat: i,
|
|
84
|
-
textureFormatFloat: c,
|
|
85
|
-
downloadTextureFormat: s,
|
|
86
|
-
downloadUnpackNumChannels: l,
|
|
87
|
-
defaultNumChannels: u,
|
|
88
|
-
textureTypeHalfFloat: f,
|
|
89
|
-
textureTypeFloat: d
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function v(e, t) {
|
|
93
|
-
const n = t();
|
|
94
|
-
return $().getBool("DEBUG") && xe(e), n;
|
|
95
|
-
}
|
|
96
|
-
function xe(e) {
|
|
97
|
-
const t = e.getError();
|
|
98
|
-
if (t !== e.NO_ERROR)
|
|
99
|
-
throw new Error("WebGL Error: " + pe(e, t));
|
|
100
|
-
}
|
|
101
|
-
const de = 596e-10, he = 65504;
|
|
102
|
-
function ht(e) {
|
|
103
|
-
return !!($().getBool("WEBGL_RENDER_FLOAT32_ENABLED") || e === 0 || de < Math.abs(e) && Math.abs(e) < he);
|
|
104
|
-
}
|
|
105
|
-
function pe(e, t) {
|
|
106
|
-
switch (t) {
|
|
107
|
-
case e.NO_ERROR:
|
|
108
|
-
return "NO_ERROR";
|
|
109
|
-
case e.INVALID_ENUM:
|
|
110
|
-
return "INVALID_ENUM";
|
|
111
|
-
case e.INVALID_VALUE:
|
|
112
|
-
return "INVALID_VALUE";
|
|
113
|
-
case e.INVALID_OPERATION:
|
|
114
|
-
return "INVALID_OPERATION";
|
|
115
|
-
case e.INVALID_FRAMEBUFFER_OPERATION:
|
|
116
|
-
return "INVALID_FRAMEBUFFER_OPERATION";
|
|
117
|
-
case e.OUT_OF_MEMORY:
|
|
118
|
-
return "OUT_OF_MEMORY";
|
|
119
|
-
case e.CONTEXT_LOST_WEBGL:
|
|
120
|
-
return "CONTEXT_LOST_WEBGL";
|
|
121
|
-
default:
|
|
122
|
-
return `Unknown error code ${t}`;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function pt(e, t) {
|
|
126
|
-
return C(e, () => e.getExtension(t), 'Extension "' + t + '" not supported on this browser.');
|
|
127
|
-
}
|
|
128
|
-
function vt(e, t) {
|
|
129
|
-
const n = C(e, () => e.createShader(e.VERTEX_SHADER), "Unable to create vertex WebGLShader.");
|
|
130
|
-
if (v(e, () => e.shaderSource(n, t)), v(e, () => e.compileShader(n)), e.getShaderParameter(n, e.COMPILE_STATUS) === !1)
|
|
131
|
-
throw console.log(e.getShaderInfoLog(n)), new Error("Failed to compile vertex shader.");
|
|
132
|
-
return n;
|
|
133
|
-
}
|
|
134
|
-
function ve(e, t) {
|
|
135
|
-
const n = C(e, () => e.createShader(e.FRAGMENT_SHADER), "Unable to create fragment WebGLShader.");
|
|
136
|
-
if (v(e, () => e.shaderSource(n, t)), v(e, () => e.compileShader(n)), $().get("ENGINE_COMPILE_ONLY"))
|
|
137
|
-
return n;
|
|
138
|
-
if (e.getShaderParameter(n, e.COMPILE_STATUS) === !1)
|
|
139
|
-
throw me(t, e.getShaderInfoLog(n)), new Error("Failed to compile fragment shader.");
|
|
140
|
-
return n;
|
|
141
|
-
}
|
|
142
|
-
const $e = /ERROR: [0-9]+:([0-9]+):/g;
|
|
143
|
-
function me(e, t) {
|
|
144
|
-
const n = $e.exec(t);
|
|
145
|
-
if (n == null) {
|
|
146
|
-
console.log(`Couldn't parse line number in error: ${t}`), console.log(e);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const r = +n[1], o = e.split(`
|
|
150
|
-
`), a = o.length.toString().length + 2, i = o.map((f, d) => G((d + 1).toString(), a) + f);
|
|
151
|
-
let c = 0;
|
|
152
|
-
for (let f = 0; f < i.length; f++)
|
|
153
|
-
c = Math.max(i[f].length, c);
|
|
154
|
-
const s = i.slice(0, r - 1), l = i.slice(r - 1, r), u = i.slice(r);
|
|
155
|
-
console.log(s.join(`
|
|
156
|
-
`)), console.log(t.split(`
|
|
157
|
-
`)[0]), console.log(`%c ${G(l[0], c)}`, "border:1px solid red; background-color:#e3d2d2; color:#a61717"), console.log(u.join(`
|
|
158
|
-
`));
|
|
159
|
-
}
|
|
160
|
-
function $t(e) {
|
|
161
|
-
return C(e, () => e.createProgram(), "Unable to create WebGLProgram.");
|
|
162
|
-
}
|
|
163
|
-
function mt(e, t) {
|
|
164
|
-
if (v(e, () => e.linkProgram(t)), !$().get("ENGINE_COMPILE_ONLY") && e.getProgramParameter(t, e.LINK_STATUS) === !1)
|
|
165
|
-
throw console.log(e.getProgramInfoLog(t)), new Error("Failed to link vertex and fragment shaders.");
|
|
166
|
-
}
|
|
167
|
-
function Tt(e, t) {
|
|
168
|
-
if (v(e, () => e.validateProgram(t)), e.getProgramParameter(t, e.VALIDATE_STATUS) === !1)
|
|
169
|
-
throw console.log(e.getProgramInfoLog(t)), new Error("Shader program validation failed.");
|
|
170
|
-
}
|
|
171
|
-
function St(e, t) {
|
|
172
|
-
const n = C(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
|
|
173
|
-
return v(e, () => e.bindBuffer(e.ARRAY_BUFFER, n)), v(e, () => e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
|
|
174
|
-
}
|
|
175
|
-
function Rt(e, t) {
|
|
176
|
-
const n = C(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
|
|
177
|
-
return v(e, () => e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, n)), v(e, () => e.bufferData(e.ELEMENT_ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
|
|
178
|
-
}
|
|
179
|
-
function Et(e) {
|
|
180
|
-
return C(e, () => e.createTexture(), "Unable to create WebGLTexture.");
|
|
181
|
-
}
|
|
182
|
-
function Ct(e, t) {
|
|
183
|
-
const n = $().getNumber("WEBGL_MAX_TEXTURE_SIZE");
|
|
184
|
-
if (e <= 0 || t <= 0) {
|
|
185
|
-
const r = `[${e}x${t}]`;
|
|
186
|
-
throw new Error("Requested texture size " + r + " is invalid.");
|
|
187
|
-
}
|
|
188
|
-
if (e > n || t > n) {
|
|
189
|
-
const r = `[${e}x${t}]`, o = `[${n}x${n}]`;
|
|
190
|
-
throw new Error("Requested texture size " + r + " greater than WebGL maximum on this browser / GPU " + o + ".");
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
function Ft(e) {
|
|
194
|
-
return C(e, () => e.createFramebuffer(), "Unable to create WebGLFramebuffer.");
|
|
195
|
-
}
|
|
196
|
-
function _t(e, t, n, r, o, a, i) {
|
|
197
|
-
const c = e.getAttribLocation(t, n);
|
|
198
|
-
return c === -1 ? !1 : (v(e, () => e.bindBuffer(e.ARRAY_BUFFER, r)), v(e, () => e.vertexAttribPointer(c, o, e.FLOAT, !1, a, i)), v(e, () => e.enableVertexAttribArray(c)), !0);
|
|
199
|
-
}
|
|
200
|
-
function Te(e, t, n) {
|
|
201
|
-
Re(e, n), v(e, () => e.activeTexture(e.TEXTURE0 + n)), v(e, () => e.bindTexture(e.TEXTURE_2D, t));
|
|
202
|
-
}
|
|
203
|
-
function At(e, t, n) {
|
|
204
|
-
return C(e, () => e.getUniformLocation(t, n), 'uniform "' + n + '" not present in program.');
|
|
205
|
-
}
|
|
206
|
-
function wt(e, t, n) {
|
|
207
|
-
return e.getUniformLocation(t, n);
|
|
208
|
-
}
|
|
209
|
-
function Nt(e, t, n, r) {
|
|
210
|
-
v(e, () => Te(e, t, r)), v(e, () => e.uniform1i(n, r));
|
|
211
|
-
}
|
|
212
|
-
function Ot(e, t, n) {
|
|
213
|
-
v(e, () => e.bindFramebuffer(e.FRAMEBUFFER, n)), v(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, t, 0));
|
|
214
|
-
}
|
|
215
|
-
function It(e, t) {
|
|
216
|
-
v(e, () => e.bindFramebuffer(e.FRAMEBUFFER, t)), v(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, null, 0));
|
|
217
|
-
}
|
|
218
|
-
function Ut(e) {
|
|
219
|
-
const t = e.checkFramebufferStatus(e.FRAMEBUFFER);
|
|
220
|
-
if (t !== e.FRAMEBUFFER_COMPLETE)
|
|
221
|
-
throw new Error("Error binding framebuffer: " + Se(e, t));
|
|
222
|
-
}
|
|
223
|
-
function Se(e, t) {
|
|
224
|
-
switch (t) {
|
|
225
|
-
case e.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
|
226
|
-
return "FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
|
|
227
|
-
case e.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
|
228
|
-
return "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
|
|
229
|
-
case e.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
|
|
230
|
-
return "FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
|
|
231
|
-
case e.FRAMEBUFFER_UNSUPPORTED:
|
|
232
|
-
return "FRAMEBUFFER_UNSUPPORTED";
|
|
233
|
-
default:
|
|
234
|
-
return `unknown error ${t}`;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
function C(e, t, n) {
|
|
238
|
-
const r = v(e, () => t());
|
|
239
|
-
if (r == null)
|
|
240
|
-
throw new Error(n);
|
|
241
|
-
return r;
|
|
242
|
-
}
|
|
243
|
-
function Re(e, t) {
|
|
244
|
-
const n = e.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1, r = t + e.TEXTURE0;
|
|
245
|
-
if (r < e.TEXTURE0 || r > n) {
|
|
246
|
-
const o = `[gl.TEXTURE0, gl.TEXTURE${n}]`;
|
|
247
|
-
throw new Error(`textureUnit must be in ${o}.`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
function Z(e, t = 2) {
|
|
251
|
-
return E(e.slice(0, e.length - t));
|
|
252
|
-
}
|
|
253
|
-
function J(e) {
|
|
254
|
-
if (e.length === 0)
|
|
255
|
-
throw Error("Cannot get rows and columns of an empty shape array.");
|
|
256
|
-
return [
|
|
257
|
-
e.length > 1 ? e[e.length - 2] : 1,
|
|
258
|
-
e[e.length - 1]
|
|
259
|
-
];
|
|
260
|
-
}
|
|
261
|
-
function Lt(e) {
|
|
262
|
-
let t = [1, 1, 1];
|
|
263
|
-
return e.length === 0 || e.length === 1 && e[0] === 1 || (t = [Z(e), ...J(e)]), t;
|
|
264
|
-
}
|
|
265
|
-
function Dt(e, t = !1) {
|
|
266
|
-
let n = $().getNumber("WEBGL_MAX_TEXTURE_SIZE"), r = $().getNumber("WEBGL_MAX_SIZE_FOR_NARROW_TEXTURE");
|
|
267
|
-
r === 1 / 0 && $().getBool("WEBGL_AUTO_SQUARIFY_NARROW_TEXTURE_SHAPE") && (r = n / 2), t && (n = n * 2, r = r * 2, e = e.map((c, s) => s >= e.length - 2 ? ae(e[s]) : e[s]), e.length === 1 && (e = [2, e[0]])), e.length !== 2 && (e = N(e).newShape);
|
|
268
|
-
let o = E(e), a = null;
|
|
269
|
-
e.length <= 1 && o <= n ? a = [1, o] : e.length === 2 && e[0] <= n && e[1] <= n ? a = e : e.length === 3 && e[0] * e[1] <= n && e[2] <= n ? a = [e[0] * e[1], e[2]] : e.length === 3 && e[0] <= n && e[1] * e[2] <= n ? a = [e[0], e[1] * e[2]] : e.length === 4 && e[0] * e[1] * e[2] <= n && e[3] <= n ? a = [e[0] * e[1] * e[2], e[3]] : e.length === 4 && e[0] <= n && e[1] * e[2] * e[3] <= n && (a = [e[0], e[1] * e[2] * e[3]]);
|
|
270
|
-
const i = a != null && Math.max(...a) > r && Math.min(...a) <= (t ? 2 : 1) && Math.min(...a) > 0;
|
|
271
|
-
if (a == null || i)
|
|
272
|
-
if (t) {
|
|
273
|
-
const c = Z(e);
|
|
274
|
-
let s = 2, l = 2;
|
|
275
|
-
e.length && ([s, l] = J(e)), o = c * (s / 2) * (l / 2), a = X(o).map((u) => u * 2);
|
|
276
|
-
} else
|
|
277
|
-
a = X(o);
|
|
278
|
-
return a;
|
|
279
|
-
}
|
|
280
|
-
function B(e) {
|
|
281
|
-
return e % 2 === 0;
|
|
282
|
-
}
|
|
283
|
-
function gt(e, t) {
|
|
284
|
-
if (e = e.slice(-2), t = t.slice(-2), T(e, t) || !e.length || !t.length || e[0] === 0 || e[1] === 0 || t[0] === 0 || t[1] === 0)
|
|
285
|
-
return !0;
|
|
286
|
-
if (e.length !== t.length) {
|
|
287
|
-
const n = e[e.length - 1], r = t[t.length - 1];
|
|
288
|
-
if (n === r || B(n) && B(r) && (e[0] === 1 || t[0] === 1))
|
|
289
|
-
return !0;
|
|
290
|
-
}
|
|
291
|
-
return e[1] === t[1] && B(e[0]) && B(t[0]);
|
|
292
|
-
}
|
|
293
|
-
let P, V;
|
|
294
|
-
function bt(e) {
|
|
295
|
-
if (P == null) {
|
|
296
|
-
const t = A(e);
|
|
297
|
-
P = t.getParameter(t.MAX_TEXTURE_SIZE);
|
|
298
|
-
}
|
|
299
|
-
return P;
|
|
300
|
-
}
|
|
301
|
-
function kt(e) {
|
|
302
|
-
if (V == null) {
|
|
303
|
-
const t = A(e);
|
|
304
|
-
V = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);
|
|
305
|
-
}
|
|
306
|
-
return Math.min(16, V);
|
|
307
|
-
}
|
|
308
|
-
function Mt(e) {
|
|
309
|
-
if (e === 0)
|
|
310
|
-
return 0;
|
|
311
|
-
let t;
|
|
312
|
-
const n = A(e);
|
|
313
|
-
return _(n, "EXT_disjoint_timer_query_webgl2") && e === 2 ? t = 2 : _(n, "EXT_disjoint_timer_query") ? t = 1 : t = 0, t;
|
|
314
|
-
}
|
|
315
|
-
function _(e, t) {
|
|
316
|
-
return e.getExtension(t) != null;
|
|
317
|
-
}
|
|
318
|
-
function Bt(e) {
|
|
319
|
-
try {
|
|
320
|
-
if (A(e) != null)
|
|
321
|
-
return !0;
|
|
322
|
-
} catch (t) {
|
|
323
|
-
return console.log("Error when getting WebGL context: ", t), !1;
|
|
324
|
-
}
|
|
325
|
-
return !1;
|
|
326
|
-
}
|
|
327
|
-
function yt(e) {
|
|
328
|
-
if (e === 0)
|
|
329
|
-
return !1;
|
|
330
|
-
const t = A(e);
|
|
331
|
-
if (e === 1) {
|
|
332
|
-
if (!_(t, "OES_texture_float"))
|
|
333
|
-
return !1;
|
|
334
|
-
} else if (!_(t, "EXT_color_buffer_float"))
|
|
335
|
-
return !1;
|
|
336
|
-
return W(t);
|
|
337
|
-
}
|
|
338
|
-
function Pt(e) {
|
|
339
|
-
if (e === 0)
|
|
340
|
-
return !1;
|
|
341
|
-
const t = A(e);
|
|
342
|
-
if (e === 1) {
|
|
343
|
-
if (!_(t, "OES_texture_float") || !_(t, "WEBGL_color_buffer_float"))
|
|
344
|
-
return !1;
|
|
345
|
-
} else {
|
|
346
|
-
if (_(t, "EXT_color_buffer_float"))
|
|
347
|
-
return W(t);
|
|
348
|
-
const r = "EXT_color_buffer_half_float";
|
|
349
|
-
if (_(t, r)) {
|
|
350
|
-
const o = t.getExtension(r);
|
|
351
|
-
return Ee(t, o);
|
|
352
|
-
}
|
|
353
|
-
return !1;
|
|
354
|
-
}
|
|
355
|
-
return W(t);
|
|
356
|
-
}
|
|
357
|
-
function W(e) {
|
|
358
|
-
const t = K(e), n = e.createTexture();
|
|
359
|
-
e.bindTexture(e.TEXTURE_2D, n), e.texImage2D(e.TEXTURE_2D, 0, t.internalFormatFloat, 1, 1, 0, t.textureFormatFloat, t.textureTypeFloat, null);
|
|
360
|
-
const a = e.createFramebuffer();
|
|
361
|
-
e.bindFramebuffer(e.FRAMEBUFFER, a), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, n, 0);
|
|
362
|
-
const i = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
|
|
363
|
-
return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(n), e.deleteFramebuffer(a), i;
|
|
364
|
-
}
|
|
365
|
-
function Ee(e, t) {
|
|
366
|
-
const n = K(e, t), r = e.createTexture();
|
|
367
|
-
e.bindTexture(e.TEXTURE_2D, r), e.texImage2D(e.TEXTURE_2D, 0, n.internalFormatHalfFloat, 1, 1, 0, n.textureFormatFloat, n.textureTypeHalfFloat, null);
|
|
368
|
-
const i = e.createFramebuffer();
|
|
369
|
-
e.bindFramebuffer(e.FRAMEBUFFER, i), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, r, 0);
|
|
370
|
-
const c = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
|
|
371
|
-
return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(r), e.deleteFramebuffer(i), c;
|
|
372
|
-
}
|
|
373
|
-
function Vt(e) {
|
|
374
|
-
return e !== 2 ? !1 : A(e).fenceSync != null;
|
|
375
|
-
}
|
|
376
|
-
function Xt(e, t) {
|
|
377
|
-
Array.isArray(e) || (e = [e]), e.forEach((n) => {
|
|
378
|
-
n != null && ie(n.dtype !== "complex64", () => `${t} does not support complex64 tensors in the WebGL backend.`);
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
function U() {
|
|
382
|
-
let e, t, n, r, o, a, i, c, s, l;
|
|
383
|
-
return $().getNumber("WEBGL_VERSION") === 2 ? (e = "#version 300 es", t = "in", n = "out", r = "in", o = "texture", a = "outputColor", i = "out vec4 outputColor;", c = $().getBool("WEBGL2_ISNAN_CUSTOM") ? `
|
|
384
|
-
bool isnan_custom(float val) {
|
|
385
|
-
uint floatToUint = floatBitsToUint(val);
|
|
386
|
-
return (floatToUint & 0x7fffffffu) > 0x7f800000u;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
bvec4 isnan_custom(vec4 val) {
|
|
390
|
-
return bvec4(isnan_custom(val.x),
|
|
391
|
-
isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
#define isnan(value) isnan_custom(value)
|
|
395
|
-
` : "", s = "", l = `
|
|
396
|
-
#define round(value) newRound(value)
|
|
397
|
-
int newRound(float value) {
|
|
398
|
-
return int(floor(value + 0.5));
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
ivec4 newRound(vec4 value) {
|
|
402
|
-
return ivec4(floor(value + vec4(0.5)));
|
|
403
|
-
}
|
|
404
|
-
`) : (e = "", t = "attribute", n = "varying", r = "varying", o = "texture2D", a = "gl_FragColor", i = "", c = `
|
|
405
|
-
#define isnan(value) isnan_custom(value)
|
|
406
|
-
bool isnan_custom(float val) {
|
|
407
|
-
return (val > 0. || val < 1. || val == 0.) ? false : true;
|
|
408
|
-
}
|
|
409
|
-
bvec4 isnan_custom(vec4 val) {
|
|
410
|
-
return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));
|
|
411
|
-
}
|
|
412
|
-
`, s = `
|
|
413
|
-
uniform float INFINITY;
|
|
414
|
-
|
|
415
|
-
bool isinf(float val) {
|
|
416
|
-
return abs(val) == INFINITY;
|
|
417
|
-
}
|
|
418
|
-
bvec4 isinf(vec4 val) {
|
|
419
|
-
return equal(abs(val), vec4(INFINITY));
|
|
420
|
-
}
|
|
421
|
-
`, l = `
|
|
422
|
-
int round(float value) {
|
|
423
|
-
return int(floor(value + 0.5));
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
ivec4 round(vec4 value) {
|
|
427
|
-
return ivec4(floor(value + vec4(0.5)));
|
|
428
|
-
}
|
|
429
|
-
`), {
|
|
430
|
-
version: e,
|
|
431
|
-
attribute: t,
|
|
432
|
-
varyingVs: n,
|
|
433
|
-
varyingFs: r,
|
|
434
|
-
texture2D: o,
|
|
435
|
-
output: a,
|
|
436
|
-
defineOutput: i,
|
|
437
|
-
defineSpecialNaN: c,
|
|
438
|
-
defineSpecialInf: s,
|
|
439
|
-
defineRound: l
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
function y(e, t, n = "index") {
|
|
443
|
-
const r = k(t);
|
|
444
|
-
return r.map((o, a) => {
|
|
445
|
-
const i = `int ${e[a]} = ${n} / ${o}`, c = a === r.length - 1 ? `int ${e[a + 1]} = ${n} - ${e[a]} * ${o}` : `index -= ${e[a]} * ${o}`;
|
|
446
|
-
return `${i}; ${c};`;
|
|
447
|
-
}).join("");
|
|
448
|
-
}
|
|
449
|
-
function Q(e, t, n = "index") {
|
|
450
|
-
const r = k(t);
|
|
451
|
-
return r.map((o, a) => {
|
|
452
|
-
const i = `int ${e[a]} = ${n} / outShapeStrides[${a}]`, c = a === r.length - 1 ? `int ${e[a + 1]} = ${n} - ${e[a]} * outShapeStrides[${a}]` : `index -= ${e[a]} * outShapeStrides[${a}]`;
|
|
453
|
-
return `${i}; ${c};`;
|
|
454
|
-
}).join("");
|
|
455
|
-
}
|
|
456
|
-
function Ce(e, t) {
|
|
457
|
-
const n = e.length, r = e.map((a) => `${t}[${a}]`), o = new Array(n - 1);
|
|
458
|
-
o[n - 2] = r[n - 1];
|
|
459
|
-
for (let a = n - 3; a >= 0; --a)
|
|
460
|
-
o[a] = `(${o[a + 1]} * ${r[a + 1]})`;
|
|
461
|
-
return o;
|
|
462
|
-
}
|
|
463
|
-
function Wt(e, t, n = "index") {
|
|
464
|
-
const r = e.map((a, i) => i), o = Ce(r, t);
|
|
465
|
-
return o.map((a, i) => {
|
|
466
|
-
const c = `int ${e[i]} = ${n} / ${o[i]}`, s = i === o.length - 1 ? `int ${e[i + 1]} = ${n} - ${e[i]} * ${o[i]}` : `index -= ${e[i]} * ${o[i]}`;
|
|
467
|
-
return `${c}; ${s};`;
|
|
468
|
-
}).join("");
|
|
469
|
-
}
|
|
470
|
-
function zt(e) {
|
|
471
|
-
const t = k(e).map((n) => n.toString());
|
|
472
|
-
return `
|
|
473
|
-
int getFlatIndex(ivec3 coords) {
|
|
474
|
-
return coords.x * ${t[0]} + coords.y * ${t[1]} + coords.z;
|
|
475
|
-
}
|
|
476
|
-
`;
|
|
477
|
-
}
|
|
478
|
-
function Gt() {
|
|
479
|
-
return `
|
|
480
|
-
int getFlatIndex(ivec3 coords) {
|
|
481
|
-
return coords.x * outShapeStrides[0] + coords.y * outShapeStrides[1] + coords.z;
|
|
482
|
-
}
|
|
483
|
-
`;
|
|
484
|
-
}
|
|
485
|
-
const Ht = `
|
|
486
|
-
const float FLOAT_MAX = 1.70141184e38;
|
|
487
|
-
const float FLOAT_MIN = 1.17549435e-38;
|
|
488
|
-
|
|
489
|
-
lowp vec4 encode_float(highp float v) {
|
|
490
|
-
if (isnan(v)) {
|
|
491
|
-
return vec4(255, 255, 255, 255);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
highp float av = abs(v);
|
|
495
|
-
|
|
496
|
-
if(av < FLOAT_MIN) {
|
|
497
|
-
return vec4(0.0, 0.0, 0.0, 0.0);
|
|
498
|
-
} else if(v > FLOAT_MAX) {
|
|
499
|
-
return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;
|
|
500
|
-
} else if(v < -FLOAT_MAX) {
|
|
501
|
-
return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
highp vec4 c = vec4(0,0,0,0);
|
|
505
|
-
|
|
506
|
-
highp float e = floor(log2(av));
|
|
507
|
-
highp float m = exp2(fract(log2(av))) - 1.0;
|
|
508
|
-
|
|
509
|
-
c[2] = floor(128.0 * m);
|
|
510
|
-
m -= c[2] / 128.0;
|
|
511
|
-
c[1] = floor(32768.0 * m);
|
|
512
|
-
m -= c[1] / 32768.0;
|
|
513
|
-
c[0] = floor(8388608.0 * m);
|
|
514
|
-
|
|
515
|
-
highp float ebias = e + 127.0;
|
|
516
|
-
c[3] = floor(ebias / 2.0);
|
|
517
|
-
ebias -= c[3] * 2.0;
|
|
518
|
-
c[2] += floor(ebias) * 128.0;
|
|
519
|
-
|
|
520
|
-
c[3] += 128.0 * step(0.0, -v);
|
|
521
|
-
|
|
522
|
-
return c / 255.0;
|
|
523
|
-
}
|
|
524
|
-
`;
|
|
525
|
-
const { getBroadcastDims: ee } = se;
|
|
526
|
-
function Fe(e, t, n) {
|
|
527
|
-
const r = [];
|
|
528
|
-
if (e.forEach((x) => {
|
|
529
|
-
const h = E(x.shapeInfo.logicalShape);
|
|
530
|
-
if (x.shapeInfo.isUniform ? r.push(`uniform float ${x.name}${h > 1 ? `[${h}]` : ""};`) : (r.push(`uniform sampler2D ${x.name};`), r.push(`uniform int offset${x.name};`)), n.enableShapeUniforms) {
|
|
531
|
-
const { uniformShape: p } = z(n.packedInputs, x.shapeInfo.logicalShape, x.shapeInfo.texShape);
|
|
532
|
-
switch (p.length) {
|
|
533
|
-
case 1:
|
|
534
|
-
r.push(`uniform int ${x.name}Shape;`);
|
|
535
|
-
break;
|
|
536
|
-
case 2:
|
|
537
|
-
r.push(`uniform ivec2 ${x.name}Shape;`);
|
|
538
|
-
break;
|
|
539
|
-
case 3:
|
|
540
|
-
r.push(`uniform ivec3 ${x.name}Shape;`);
|
|
541
|
-
break;
|
|
542
|
-
case 4:
|
|
543
|
-
r.push(`uniform ivec4 ${x.name}Shape;`);
|
|
544
|
-
break;
|
|
545
|
-
}
|
|
546
|
-
r.push(`uniform ivec2 ${x.name}TexShape;`);
|
|
547
|
-
}
|
|
548
|
-
}), n.enableShapeUniforms) {
|
|
549
|
-
switch (t.logicalShape.length) {
|
|
550
|
-
case 1:
|
|
551
|
-
r.push("uniform int outShape;");
|
|
552
|
-
break;
|
|
553
|
-
case 2:
|
|
554
|
-
r.push("uniform ivec2 outShape;"), r.push("uniform int outShapeStrides;");
|
|
555
|
-
break;
|
|
556
|
-
case 3:
|
|
557
|
-
r.push("uniform ivec3 outShape;"), r.push("uniform ivec2 outShapeStrides;");
|
|
558
|
-
break;
|
|
559
|
-
case 4:
|
|
560
|
-
r.push("uniform ivec4 outShape;"), r.push("uniform ivec3 outShapeStrides;");
|
|
561
|
-
break;
|
|
562
|
-
}
|
|
563
|
-
r.push("uniform ivec2 outTexShape;");
|
|
564
|
-
}
|
|
565
|
-
n.customUniforms && n.customUniforms.forEach((x) => {
|
|
566
|
-
r.push(`uniform ${x.type} ${x.name}${x.arrayIndex ? `[${x.arrayIndex}]` : ""};`);
|
|
567
|
-
});
|
|
568
|
-
const o = r.join(`
|
|
569
|
-
`), a = e.map((x) => _e(x, t, n.packedInputs, n.enableShapeUniforms)).join(`
|
|
570
|
-
`), i = t.texShape, c = U(), s = Ne(c);
|
|
571
|
-
let l, u, f = Ue(c);
|
|
572
|
-
return t.isPacked ? (l = Ae(t.logicalShape, i, n.enableShapeUniforms), u = Ie(c)) : (l = we(t.logicalShape, i, n.enableShapeUniforms), u = Oe(c)), n.packedInputs && (f += be), [
|
|
573
|
-
f,
|
|
574
|
-
s,
|
|
575
|
-
u,
|
|
576
|
-
o,
|
|
577
|
-
l,
|
|
578
|
-
a,
|
|
579
|
-
n.userCode
|
|
580
|
-
].join(`
|
|
581
|
-
`);
|
|
582
|
-
}
|
|
583
|
-
function L(e, t = !1) {
|
|
584
|
-
const n = e.shapeInfo.logicalShape;
|
|
585
|
-
switch (n.length) {
|
|
586
|
-
case 0:
|
|
587
|
-
return qe(e, t);
|
|
588
|
-
case 1:
|
|
589
|
-
return Ye(e, t);
|
|
590
|
-
case 2:
|
|
591
|
-
return Ze(e, t);
|
|
592
|
-
case 3:
|
|
593
|
-
return Qe(e, t);
|
|
594
|
-
case 4:
|
|
595
|
-
return tt(e, t);
|
|
596
|
-
case 5:
|
|
597
|
-
return nt(e);
|
|
598
|
-
case 6:
|
|
599
|
-
return rt(e);
|
|
600
|
-
default:
|
|
601
|
-
throw new Error(`${n.length}-D input sampling is not yet supported`);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
function te(e, t) {
|
|
605
|
-
switch (e.shapeInfo.logicalShape.length) {
|
|
606
|
-
case 0:
|
|
607
|
-
return He(e);
|
|
608
|
-
case 1:
|
|
609
|
-
return je(e, t);
|
|
610
|
-
case 2:
|
|
611
|
-
return Ke(e, t);
|
|
612
|
-
case 3:
|
|
613
|
-
return Je(e, t);
|
|
614
|
-
default:
|
|
615
|
-
return et(e, t);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
function _e(e, t, n = !1, r) {
|
|
619
|
-
let o = "";
|
|
620
|
-
n ? o += te(e, r) : o += L(e, r);
|
|
621
|
-
const a = e.shapeInfo.logicalShape, i = t.logicalShape;
|
|
622
|
-
return a.length <= i.length && (n ? o += ot(e, t) : o += at(e, t)), o;
|
|
623
|
-
}
|
|
624
|
-
function Ae(e, t, n) {
|
|
625
|
-
switch (e.length) {
|
|
626
|
-
case 0:
|
|
627
|
-
return ne();
|
|
628
|
-
case 1:
|
|
629
|
-
return ke(e, t, n);
|
|
630
|
-
case 2:
|
|
631
|
-
return ze(e, t, n);
|
|
632
|
-
case 3:
|
|
633
|
-
return Be(e, t, n);
|
|
634
|
-
default:
|
|
635
|
-
return Pe(e, t, n);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
function we(e, t, n) {
|
|
639
|
-
switch (e.length) {
|
|
640
|
-
case 0:
|
|
641
|
-
return ne();
|
|
642
|
-
case 1:
|
|
643
|
-
return Me(e, t, n);
|
|
644
|
-
case 2:
|
|
645
|
-
return Ge(e, t, n);
|
|
646
|
-
case 3:
|
|
647
|
-
return ye(e, t, n);
|
|
648
|
-
case 4:
|
|
649
|
-
return Ve(e, t, n);
|
|
650
|
-
case 5:
|
|
651
|
-
return Xe(e, t);
|
|
652
|
-
case 6:
|
|
653
|
-
return We(e, t);
|
|
654
|
-
default:
|
|
655
|
-
throw new Error(`${e.length}-D output sampling is not yet supported`);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
function Ne(e) {
|
|
659
|
-
return `
|
|
660
|
-
float sampleTexture(sampler2D textureSampler, vec2 uv) {
|
|
661
|
-
return ${e.texture2D}(textureSampler, uv).r;
|
|
662
|
-
}
|
|
663
|
-
`;
|
|
664
|
-
}
|
|
665
|
-
function Oe(e) {
|
|
666
|
-
return `
|
|
667
|
-
void setOutput(float val) {
|
|
668
|
-
${e.output} = vec4(val, 0, 0, 0);
|
|
669
|
-
}
|
|
670
|
-
`;
|
|
671
|
-
}
|
|
672
|
-
function Ie(e) {
|
|
673
|
-
return `
|
|
674
|
-
void setOutput(vec4 val) {
|
|
675
|
-
${e.output} = val;
|
|
676
|
-
}
|
|
677
|
-
`;
|
|
678
|
-
}
|
|
679
|
-
function Ue(e) {
|
|
680
|
-
return `${e.version}
|
|
681
|
-
precision highp float;
|
|
682
|
-
precision highp int;
|
|
683
|
-
precision highp sampler2D;
|
|
684
|
-
${e.varyingFs} vec2 resultUV;
|
|
685
|
-
${e.defineOutput}
|
|
686
|
-
const vec2 halfCR = vec2(0.5, 0.5);
|
|
687
|
-
|
|
688
|
-
struct ivec5
|
|
689
|
-
{
|
|
690
|
-
int x;
|
|
691
|
-
int y;
|
|
692
|
-
int z;
|
|
693
|
-
int w;
|
|
694
|
-
int u;
|
|
695
|
-
};
|
|
696
|
-
|
|
697
|
-
struct ivec6
|
|
698
|
-
{
|
|
699
|
-
int x;
|
|
700
|
-
int y;
|
|
701
|
-
int z;
|
|
702
|
-
int w;
|
|
703
|
-
int u;
|
|
704
|
-
int v;
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
uniform float NAN;
|
|
708
|
-
${e.defineSpecialNaN}
|
|
709
|
-
${e.defineSpecialInf}
|
|
710
|
-
${e.defineRound}
|
|
711
|
-
|
|
712
|
-
int imod(int x, int y) {
|
|
713
|
-
return x - y * (x / y);
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
int idiv(int a, int b, float sign) {
|
|
717
|
-
int res = a / b;
|
|
718
|
-
int mod = imod(a, b);
|
|
719
|
-
if (sign < 0. && mod != 0) {
|
|
720
|
-
res -= 1;
|
|
721
|
-
}
|
|
722
|
-
return res;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
//Based on the work of Dave Hoskins
|
|
726
|
-
//https://www.shadertoy.com/view/4djSRW
|
|
727
|
-
#define HASHSCALE1 443.8975
|
|
728
|
-
float random(float seed){
|
|
729
|
-
vec2 p = resultUV * seed;
|
|
730
|
-
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);
|
|
731
|
-
p3 += dot(p3, p3.yzx + 19.19);
|
|
732
|
-
return fract((p3.x + p3.y) * p3.z);
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
${Le}
|
|
736
|
-
${De}
|
|
737
|
-
${ge}
|
|
738
|
-
`;
|
|
739
|
-
}
|
|
740
|
-
const Le = `
|
|
741
|
-
vec2 uvFromFlat(int texNumR, int texNumC, int index) {
|
|
742
|
-
int texR = index / texNumC;
|
|
743
|
-
int texC = index - texR * texNumC;
|
|
744
|
-
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
745
|
-
}
|
|
746
|
-
vec2 packedUVfrom1D(int texNumR, int texNumC, int index) {
|
|
747
|
-
int texelIndex = index / 2;
|
|
748
|
-
int texR = texelIndex / texNumC;
|
|
749
|
-
int texC = texelIndex - texR * texNumC;
|
|
750
|
-
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
751
|
-
}
|
|
752
|
-
`, De = `
|
|
753
|
-
vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
|
|
754
|
-
int texNumC, int row, int col) {
|
|
755
|
-
int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);
|
|
756
|
-
int texR = texelIndex / texNumC;
|
|
757
|
-
int texC = texelIndex - texR * texNumC;
|
|
758
|
-
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
759
|
-
}
|
|
760
|
-
`, ge = `
|
|
761
|
-
vec2 packedUVfrom3D(int texNumR, int texNumC,
|
|
762
|
-
int texelsInBatch, int texelsInLogicalRow, int b,
|
|
763
|
-
int row, int col) {
|
|
764
|
-
int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);
|
|
765
|
-
int texR = index / texNumC;
|
|
766
|
-
int texC = index - texR * texNumC;
|
|
767
|
-
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
768
|
-
}
|
|
769
|
-
`, be = `
|
|
770
|
-
float getChannel(vec4 frag, vec2 innerDims) {
|
|
771
|
-
vec2 modCoord = mod(innerDims, 2.);
|
|
772
|
-
return modCoord.x == 0. ?
|
|
773
|
-
(modCoord.y == 0. ? frag.r : frag.g) :
|
|
774
|
-
(modCoord.y == 0. ? frag.b : frag.a);
|
|
775
|
-
}
|
|
776
|
-
float getChannel(vec4 frag, int dim) {
|
|
777
|
-
float modCoord = mod(float(dim), 2.);
|
|
778
|
-
return modCoord == 0. ? frag.r : frag.g;
|
|
779
|
-
}
|
|
780
|
-
`;
|
|
781
|
-
function ne() {
|
|
782
|
-
return `
|
|
783
|
-
int getOutputCoords() {
|
|
784
|
-
return 0;
|
|
785
|
-
}
|
|
786
|
-
`;
|
|
787
|
-
}
|
|
788
|
-
function ke(e, t, n) {
|
|
789
|
-
const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
|
|
790
|
-
return r[0] === 1 ? n ? `
|
|
791
|
-
int getOutputCoords() {
|
|
792
|
-
return 2 * int(resultUV.x * ceil(float(outTexShape[1]) / 2.0));
|
|
793
|
-
}
|
|
794
|
-
` : `
|
|
795
|
-
int getOutputCoords() {
|
|
796
|
-
return 2 * int(resultUV.x * ${r[1]}.0);
|
|
797
|
-
}
|
|
798
|
-
` : r[1] === 1 ? n ? `
|
|
799
|
-
int getOutputCoords() {
|
|
800
|
-
return 2 * int(resultUV.y * ceil(float(outTexShape[0]) / 2.0));
|
|
801
|
-
}
|
|
802
|
-
` : `
|
|
803
|
-
int getOutputCoords() {
|
|
804
|
-
return 2 * int(resultUV.y * ${r[0]}.0);
|
|
805
|
-
}
|
|
806
|
-
` : n ? `
|
|
807
|
-
int getOutputCoords() {
|
|
808
|
-
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
809
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
810
|
-
vec2(packedTexShape[0], packedTexShape[1]));
|
|
811
|
-
return 2 * (resTexRC.x * packedTexShape[1] + resTexRC.y);
|
|
812
|
-
}
|
|
813
|
-
` : `
|
|
814
|
-
int getOutputCoords() {
|
|
815
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
816
|
-
vec2(${r[0]}, ${r[1]}));
|
|
817
|
-
return 2 * (resTexRC.x * ${r[1]} + resTexRC.y);
|
|
818
|
-
}
|
|
819
|
-
`;
|
|
820
|
-
}
|
|
821
|
-
function Me(e, t, n) {
|
|
822
|
-
return t[0] === 1 ? n ? `
|
|
823
|
-
int getOutputCoords() {
|
|
824
|
-
return int(resultUV.x * float(outTexShape[1]));
|
|
825
|
-
}
|
|
826
|
-
` : `
|
|
827
|
-
int getOutputCoords() {
|
|
828
|
-
return int(resultUV.x * ${t[1]}.0);
|
|
829
|
-
}
|
|
830
|
-
` : t[1] === 1 ? n ? `
|
|
831
|
-
int getOutputCoords() {
|
|
832
|
-
return int(resultUV.y * float(outTexShape[0]));
|
|
833
|
-
}
|
|
834
|
-
` : `
|
|
835
|
-
int getOutputCoords() {
|
|
836
|
-
return int(resultUV.y * ${t[0]}.0);
|
|
837
|
-
}
|
|
838
|
-
` : n ? `
|
|
839
|
-
int getOutputCoords() {
|
|
840
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
841
|
-
vec2(outTexShape[0], outTexShape[1]));
|
|
842
|
-
return resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
843
|
-
}
|
|
844
|
-
` : `
|
|
845
|
-
int getOutputCoords() {
|
|
846
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
847
|
-
vec2(${t[0]}, ${t[1]}));
|
|
848
|
-
return resTexRC.x * ${t[1]} + resTexRC.y;
|
|
849
|
-
}
|
|
850
|
-
`;
|
|
851
|
-
}
|
|
852
|
-
function Be(e, t, n) {
|
|
853
|
-
if (n)
|
|
854
|
-
return `
|
|
855
|
-
ivec3 getOutputCoords() {
|
|
856
|
-
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
857
|
-
int texelsInLogicalRow = int(ceil(float(outShape[2]) / 2.0));
|
|
858
|
-
int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[1]) / 2.0));
|
|
859
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
860
|
-
vec2(packedTexShape[0], packedTexShape[1]));
|
|
861
|
-
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
|
|
862
|
-
|
|
863
|
-
int b = index / texelsInBatch;
|
|
864
|
-
index -= b * texelsInBatch;
|
|
865
|
-
|
|
866
|
-
int r = 2 * (index / texelsInLogicalRow);
|
|
867
|
-
int c = imod(index, texelsInLogicalRow) * 2;
|
|
868
|
-
|
|
869
|
-
return ivec3(b, r, c);
|
|
870
|
-
}
|
|
871
|
-
`;
|
|
872
|
-
const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], o = Math.ceil(e[2] / 2), a = o * Math.ceil(e[1] / 2);
|
|
873
|
-
return `
|
|
874
|
-
ivec3 getOutputCoords() {
|
|
875
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
876
|
-
vec2(${r[0]}, ${r[1]}));
|
|
877
|
-
int index = resTexRC.x * ${r[1]} + resTexRC.y;
|
|
878
|
-
|
|
879
|
-
int b = index / ${a};
|
|
880
|
-
index -= b * ${a};
|
|
881
|
-
|
|
882
|
-
int r = 2 * (index / ${o});
|
|
883
|
-
int c = imod(index, ${o}) * 2;
|
|
884
|
-
|
|
885
|
-
return ivec3(b, r, c);
|
|
886
|
-
}
|
|
887
|
-
`;
|
|
888
|
-
}
|
|
889
|
-
function ye(e, t, n) {
|
|
890
|
-
if (n)
|
|
891
|
-
return `
|
|
892
|
-
ivec3 getOutputCoords() {
|
|
893
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
894
|
-
vec2(outTexShape[0], outTexShape[1]));
|
|
895
|
-
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
896
|
-
${Q(["r", "c", "d"], e)}
|
|
897
|
-
return ivec3(r, c, d);
|
|
898
|
-
}
|
|
899
|
-
`;
|
|
900
|
-
const r = y(["r", "c", "d"], e);
|
|
901
|
-
return `
|
|
902
|
-
ivec3 getOutputCoords() {
|
|
903
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
904
|
-
vec2(${t[0]}, ${t[1]}));
|
|
905
|
-
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
906
|
-
${r}
|
|
907
|
-
return ivec3(r, c, d);
|
|
908
|
-
}
|
|
909
|
-
`;
|
|
910
|
-
}
|
|
911
|
-
function Pe(e, t, n) {
|
|
912
|
-
if (n)
|
|
913
|
-
return `
|
|
914
|
-
ivec4 getOutputCoords() {
|
|
915
|
-
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
916
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
917
|
-
vec2(packedTexShape[0], packedTexShape[1]));
|
|
918
|
-
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
|
|
919
|
-
|
|
920
|
-
int texelsInLogicalRow = int(ceil(float(outShape[3]) / 2.0));
|
|
921
|
-
int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[2]) / 2.0));
|
|
922
|
-
int texelsInBatchN = texelsInBatch * outShape[1];
|
|
923
|
-
|
|
924
|
-
int b2 = index / texelsInBatchN;
|
|
925
|
-
index -= b2 * texelsInBatchN;
|
|
926
|
-
|
|
927
|
-
int b = index / texelsInBatch;
|
|
928
|
-
index -= b * texelsInBatch;
|
|
929
|
-
|
|
930
|
-
int r = 2 * (index / texelsInLogicalRow);
|
|
931
|
-
int c = imod(index, texelsInLogicalRow) * 2;
|
|
932
|
-
|
|
933
|
-
return ivec4(b2, b, r, c);
|
|
934
|
-
}
|
|
935
|
-
`;
|
|
936
|
-
const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)], o = Math.ceil(e[e.length - 1] / 2), a = o * Math.ceil(e[e.length - 2] / 2);
|
|
937
|
-
let i = a, c = "", s = "b, r, c";
|
|
938
|
-
for (let l = 2; l < e.length - 1; l++)
|
|
939
|
-
i *= e[e.length - l - 1], c = `
|
|
940
|
-
int b${l} = index / ${i};
|
|
941
|
-
index -= b${l} * ${i};
|
|
942
|
-
` + c, s = `b${l}, ` + s;
|
|
943
|
-
return `
|
|
944
|
-
ivec${e.length} getOutputCoords() {
|
|
945
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
946
|
-
vec2(${r[0]}, ${r[1]}));
|
|
947
|
-
int index = resTexRC.x * ${r[1]} + resTexRC.y;
|
|
948
|
-
|
|
949
|
-
${c}
|
|
950
|
-
|
|
951
|
-
int b = index / ${a};
|
|
952
|
-
index -= b * ${a};
|
|
953
|
-
|
|
954
|
-
int r = 2 * (index / ${o});
|
|
955
|
-
int c = imod(index, ${o}) * 2;
|
|
956
|
-
|
|
957
|
-
return ivec${e.length}(${s});
|
|
958
|
-
}
|
|
959
|
-
`;
|
|
960
|
-
}
|
|
961
|
-
function Ve(e, t, n) {
|
|
962
|
-
if (n)
|
|
963
|
-
return `
|
|
964
|
-
ivec4 getOutputCoords() {
|
|
965
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
966
|
-
vec2(outTexShape[0], outTexShape[1]));
|
|
967
|
-
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
968
|
-
${Q(["r", "c", "d", "d2"], e)}
|
|
969
|
-
return ivec4(r, c, d, d2);
|
|
970
|
-
}
|
|
971
|
-
`;
|
|
972
|
-
const r = y(["r", "c", "d", "d2"], e);
|
|
973
|
-
return `
|
|
974
|
-
ivec4 getOutputCoords() {
|
|
975
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
976
|
-
vec2(${t[0]}, ${t[1]}));
|
|
977
|
-
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
978
|
-
${r}
|
|
979
|
-
return ivec4(r, c, d, d2);
|
|
980
|
-
}
|
|
981
|
-
`;
|
|
982
|
-
}
|
|
983
|
-
function Xe(e, t) {
|
|
984
|
-
const n = y(["r", "c", "d", "d2", "d3"], e);
|
|
985
|
-
return `
|
|
986
|
-
ivec5 getOutputCoords() {
|
|
987
|
-
ivec2 resTexRC = ivec2(resultUV.yx * vec2(${t[0]},
|
|
988
|
-
${t[1]}));
|
|
989
|
-
|
|
990
|
-
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
991
|
-
|
|
992
|
-
${n}
|
|
993
|
-
|
|
994
|
-
ivec5 outShape = ivec5(r, c, d, d2, d3);
|
|
995
|
-
return outShape;
|
|
996
|
-
}
|
|
997
|
-
`;
|
|
998
|
-
}
|
|
999
|
-
function We(e, t) {
|
|
1000
|
-
const n = y(["r", "c", "d", "d2", "d3", "d4"], e);
|
|
1001
|
-
return `
|
|
1002
|
-
ivec6 getOutputCoords() {
|
|
1003
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1004
|
-
vec2(${t[0]}, ${t[1]}));
|
|
1005
|
-
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1006
|
-
|
|
1007
|
-
${n}
|
|
1008
|
-
|
|
1009
|
-
ivec6 result = ivec6(r, c, d, d2, d3, d4);
|
|
1010
|
-
return result;
|
|
1011
|
-
}
|
|
1012
|
-
`;
|
|
1013
|
-
}
|
|
1014
|
-
function ze(e, t, n) {
|
|
1015
|
-
const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
|
|
1016
|
-
if (T(e, t))
|
|
1017
|
-
return n ? `
|
|
1018
|
-
ivec2 getOutputCoords() {
|
|
1019
|
-
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
1020
|
-
return 2 * ivec2(resultUV.yx * vec2(packedTexShape[0], packedTexShape[1]));
|
|
1021
|
-
}
|
|
1022
|
-
` : `
|
|
1023
|
-
ivec2 getOutputCoords() {
|
|
1024
|
-
return 2 * ivec2(resultUV.yx * vec2(${r[0]}, ${r[1]}));
|
|
1025
|
-
}
|
|
1026
|
-
`;
|
|
1027
|
-
const o = Math.ceil(e[1] / 2);
|
|
1028
|
-
return n ? `
|
|
1029
|
-
ivec2 getOutputCoords() {
|
|
1030
|
-
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
1031
|
-
int texelsInLogicalRow = int(ceil(float(outShape[1]) / 2.0));
|
|
1032
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1033
|
-
vec2(packedTexShape[0], packedTexShape[1]));
|
|
1034
|
-
|
|
1035
|
-
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
|
|
1036
|
-
int r = 2 * (index / texelsInLogicalRow);
|
|
1037
|
-
int c = imod(index, texelsInLogicalRow) * 2;
|
|
1038
|
-
|
|
1039
|
-
return ivec2(r, c);
|
|
1040
|
-
}
|
|
1041
|
-
` : `
|
|
1042
|
-
ivec2 getOutputCoords() {
|
|
1043
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1044
|
-
vec2(${r[0]}, ${r[1]}));
|
|
1045
|
-
|
|
1046
|
-
int index = resTexRC.x * ${r[1]} + resTexRC.y;
|
|
1047
|
-
int r = 2 * (index / ${o});
|
|
1048
|
-
int c = imod(index, ${o}) * 2;
|
|
1049
|
-
|
|
1050
|
-
return ivec2(r, c);
|
|
1051
|
-
}
|
|
1052
|
-
`;
|
|
1053
|
-
}
|
|
1054
|
-
function Ge(e, t, n) {
|
|
1055
|
-
return T(e, t) ? n ? `
|
|
1056
|
-
ivec2 getOutputCoords() {
|
|
1057
|
-
return ivec2(resultUV.yx * vec2(outTexShape[0], outTexShape[1]));
|
|
1058
|
-
}
|
|
1059
|
-
` : `
|
|
1060
|
-
ivec2 getOutputCoords() {
|
|
1061
|
-
return ivec2(resultUV.yx * vec2(${t[0]}, ${t[1]}));
|
|
1062
|
-
}
|
|
1063
|
-
` : e[1] === 1 ? n ? `
|
|
1064
|
-
ivec2 getOutputCoords() {
|
|
1065
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1066
|
-
vec2(outTexShape[0], outTexShape[1]));
|
|
1067
|
-
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
1068
|
-
return ivec2(index, 0);
|
|
1069
|
-
}
|
|
1070
|
-
` : `
|
|
1071
|
-
ivec2 getOutputCoords() {
|
|
1072
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1073
|
-
vec2(${t[0]}, ${t[1]}));
|
|
1074
|
-
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1075
|
-
return ivec2(index, 0);
|
|
1076
|
-
}
|
|
1077
|
-
` : e[0] === 1 ? n ? `
|
|
1078
|
-
ivec2 getOutputCoords() {
|
|
1079
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1080
|
-
vec2(outTexShape[0], outTexShape[1]));
|
|
1081
|
-
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
1082
|
-
return ivec2(0, index);
|
|
1083
|
-
}
|
|
1084
|
-
` : `
|
|
1085
|
-
ivec2 getOutputCoords() {
|
|
1086
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1087
|
-
vec2(${t[0]}, ${t[1]}));
|
|
1088
|
-
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1089
|
-
return ivec2(0, index);
|
|
1090
|
-
}
|
|
1091
|
-
` : n ? `
|
|
1092
|
-
ivec2 getOutputCoords() {
|
|
1093
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1094
|
-
vec2(outTexShape[0], outTexShape[1]));
|
|
1095
|
-
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
1096
|
-
int r = index / outShape[1];
|
|
1097
|
-
int c = index - r * outShape[1];
|
|
1098
|
-
return ivec2(r, c);
|
|
1099
|
-
}
|
|
1100
|
-
` : `
|
|
1101
|
-
ivec2 getOutputCoords() {
|
|
1102
|
-
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1103
|
-
vec2(${t[0]}, ${t[1]}));
|
|
1104
|
-
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1105
|
-
int r = index / ${e[1]};
|
|
1106
|
-
int c = index - r * ${e[1]};
|
|
1107
|
-
return ivec2(r, c);
|
|
1108
|
-
}
|
|
1109
|
-
`;
|
|
1110
|
-
}
|
|
1111
|
-
function O(e) {
|
|
1112
|
-
return `offset${e}`;
|
|
1113
|
-
}
|
|
1114
|
-
function He(e) {
|
|
1115
|
-
const t = e.name, n = "get" + t.charAt(0).toUpperCase() + t.slice(1), r = U();
|
|
1116
|
-
return `
|
|
1117
|
-
vec4 ${n}() {
|
|
1118
|
-
return ${r.texture2D}(${t}, halfCR);
|
|
1119
|
-
}
|
|
1120
|
-
`;
|
|
1121
|
-
}
|
|
1122
|
-
function qe(e, t) {
|
|
1123
|
-
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1);
|
|
1124
|
-
if (e.shapeInfo.isUniform)
|
|
1125
|
-
return `float ${r}() {return ${n};}`;
|
|
1126
|
-
const [o, a] = e.shapeInfo.texShape;
|
|
1127
|
-
if (o === 1 && a === 1)
|
|
1128
|
-
return `
|
|
1129
|
-
float ${r}() {
|
|
1130
|
-
return sampleTexture(${n}, halfCR);
|
|
1131
|
-
}
|
|
1132
|
-
`;
|
|
1133
|
-
const i = O(n);
|
|
1134
|
-
if (t)
|
|
1135
|
-
return `
|
|
1136
|
-
float ${r}() {
|
|
1137
|
-
vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], ${i});
|
|
1138
|
-
return sampleTexture(${n}, uv);
|
|
1139
|
-
}
|
|
1140
|
-
`;
|
|
1141
|
-
const [c, s] = e.shapeInfo.texShape;
|
|
1142
|
-
return `
|
|
1143
|
-
float ${r}() {
|
|
1144
|
-
vec2 uv = uvFromFlat(${c}, ${s}, ${i});
|
|
1145
|
-
return sampleTexture(${n}, uv);
|
|
1146
|
-
}
|
|
1147
|
-
`;
|
|
1148
|
-
}
|
|
1149
|
-
function je(e, t) {
|
|
1150
|
-
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = e.shapeInfo.texShape, a = U();
|
|
1151
|
-
if (t)
|
|
1152
|
-
return `
|
|
1153
|
-
vec4 ${r}(int index) {
|
|
1154
|
-
ivec2 packedTexShape = ivec2(ceil(float(${n}TexShape[0]) / 2.0), ceil(float(${n}TexShape[1]) / 2.0));
|
|
1155
|
-
vec2 uv = packedUVfrom1D(
|
|
1156
|
-
packedTexShape[0], packedTexShape[1], index);
|
|
1157
|
-
return ${a.texture2D}(${n}, uv);
|
|
1158
|
-
}
|
|
1159
|
-
`;
|
|
1160
|
-
const i = [Math.ceil(o[0] / 2), Math.ceil(o[1] / 2)];
|
|
1161
|
-
return `
|
|
1162
|
-
vec4 ${r}(int index) {
|
|
1163
|
-
vec2 uv = packedUVfrom1D(
|
|
1164
|
-
${i[0]}, ${i[1]}, index);
|
|
1165
|
-
return ${a.texture2D}(${n}, uv);
|
|
1166
|
-
}
|
|
1167
|
-
`;
|
|
1168
|
-
}
|
|
1169
|
-
function Ye(e, t) {
|
|
1170
|
-
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1);
|
|
1171
|
-
if (e.shapeInfo.isUniform)
|
|
1172
|
-
return `
|
|
1173
|
-
float ${r}(int index) {
|
|
1174
|
-
${D(e)}
|
|
1175
|
-
}
|
|
1176
|
-
`;
|
|
1177
|
-
const o = e.shapeInfo.texShape, a = o[0], i = o[1];
|
|
1178
|
-
if (i === 1 && a === 1)
|
|
1179
|
-
return `
|
|
1180
|
-
float ${r}(int index) {
|
|
1181
|
-
return sampleTexture(${n}, halfCR);
|
|
1182
|
-
}
|
|
1183
|
-
`;
|
|
1184
|
-
const c = O(n);
|
|
1185
|
-
return i === 1 ? t ? `
|
|
1186
|
-
float ${r}(int index) {
|
|
1187
|
-
vec2 uv = vec2(0.5, (float(index + ${c}) + 0.5) / float(${n}TexShape[0]));
|
|
1188
|
-
return sampleTexture(${n}, uv);
|
|
1189
|
-
}
|
|
1190
|
-
` : `
|
|
1191
|
-
float ${r}(int index) {
|
|
1192
|
-
vec2 uv = vec2(0.5, (float(index + ${c}) + 0.5) / ${a}.0);
|
|
1193
|
-
return sampleTexture(${n}, uv);
|
|
1194
|
-
}
|
|
1195
|
-
` : a === 1 ? t ? `
|
|
1196
|
-
float ${r}(int index) {
|
|
1197
|
-
vec2 uv = vec2((float(index + ${c}) + 0.5) / float(${n}TexShape[1]), 0.5);
|
|
1198
|
-
return sampleTexture(${n}, uv);
|
|
1199
|
-
}
|
|
1200
|
-
` : `
|
|
1201
|
-
float ${r}(int index) {
|
|
1202
|
-
vec2 uv = vec2((float(index + ${c}) + 0.5) / ${i}.0, 0.5);
|
|
1203
|
-
return sampleTexture(${n}, uv);
|
|
1204
|
-
}
|
|
1205
|
-
` : t ? `
|
|
1206
|
-
float ${r}(int index) {
|
|
1207
|
-
vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], index + ${c});
|
|
1208
|
-
return sampleTexture(${n}, uv);
|
|
1209
|
-
}
|
|
1210
|
-
` : `
|
|
1211
|
-
float ${r}(int index) {
|
|
1212
|
-
vec2 uv = uvFromFlat(${a}, ${i}, index + ${c});
|
|
1213
|
-
return sampleTexture(${n}, uv);
|
|
1214
|
-
}
|
|
1215
|
-
`;
|
|
1216
|
-
}
|
|
1217
|
-
function Ke(e, t) {
|
|
1218
|
-
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = e.shapeInfo.texShape, i = a[0], c = a[1], s = U();
|
|
1219
|
-
if (a != null && T(n, a))
|
|
1220
|
-
return t ? `
|
|
1221
|
-
vec4 ${o}(int row, int col) {
|
|
1222
|
-
vec2 uv = (vec2(col, row) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1223
|
-
|
|
1224
|
-
return ${s.texture2D}(${r}, uv);
|
|
1225
|
-
}
|
|
1226
|
-
` : `
|
|
1227
|
-
vec4 ${o}(int row, int col) {
|
|
1228
|
-
vec2 uv = (vec2(col, row) + halfCR) / vec2(${c}.0, ${i}.0);
|
|
1229
|
-
|
|
1230
|
-
return ${s.texture2D}(${r}, uv);
|
|
1231
|
-
}
|
|
1232
|
-
`;
|
|
1233
|
-
if (t)
|
|
1234
|
-
return `
|
|
1235
|
-
vec4 ${o}(int row, int col) {
|
|
1236
|
-
ivec2 packedTexShape = ivec2(ceil(float(${r}TexShape[0]) / 2.0), ceil(float(${r}TexShape[1]) / 2.0));
|
|
1237
|
-
int valuesPerRow = int(ceil(float(${r}Shape[1]) / 2.0));
|
|
1238
|
-
vec2 uv = packedUVfrom2D(valuesPerRow, packedTexShape[0], packedTexShape[1], row, col);
|
|
1239
|
-
return ${s.texture2D}(${r}, uv);
|
|
1240
|
-
}
|
|
1241
|
-
`;
|
|
1242
|
-
const l = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)], u = Math.ceil(n[1] / 2);
|
|
1243
|
-
return `
|
|
1244
|
-
vec4 ${o}(int row, int col) {
|
|
1245
|
-
vec2 uv = packedUVfrom2D(${u}, ${l[0]}, ${l[1]}, row, col);
|
|
1246
|
-
return ${s.texture2D}(${r}, uv);
|
|
1247
|
-
}
|
|
1248
|
-
`;
|
|
1249
|
-
}
|
|
1250
|
-
function Ze(e, t) {
|
|
1251
|
-
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = e.shapeInfo.texShape;
|
|
1252
|
-
if (a != null && T(n, a)) {
|
|
1253
|
-
if (t)
|
|
1254
|
-
return `
|
|
1255
|
-
float ${o}(int row, int col) {
|
|
1256
|
-
vec2 uv = (vec2(col, row) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1257
|
-
return sampleTexture(${r}, uv);
|
|
1258
|
-
}
|
|
1259
|
-
`;
|
|
1260
|
-
const d = a[0], x = a[1];
|
|
1261
|
-
return `
|
|
1262
|
-
float ${o}(int row, int col) {
|
|
1263
|
-
vec2 uv = (vec2(col, row) + halfCR) / vec2(${x}.0, ${d}.0);
|
|
1264
|
-
return sampleTexture(${r}, uv);
|
|
1265
|
-
}
|
|
1266
|
-
`;
|
|
1267
|
-
}
|
|
1268
|
-
const { newShape: i, keptDims: c } = N(n), s = i;
|
|
1269
|
-
if (s.length < n.length) {
|
|
1270
|
-
const d = g(e, s), x = ["row", "col"];
|
|
1271
|
-
return `
|
|
1272
|
-
${L(d, t)}
|
|
1273
|
-
float ${o}(int row, int col) {
|
|
1274
|
-
return ${o}(${b(x, c)});
|
|
1275
|
-
}
|
|
1276
|
-
`;
|
|
1277
|
-
}
|
|
1278
|
-
if (e.shapeInfo.isUniform)
|
|
1279
|
-
return `
|
|
1280
|
-
float ${o}(int row, int col) {
|
|
1281
|
-
int index = round(dot(vec2(row, col), vec2(${n[1]}, 1)));
|
|
1282
|
-
${D(e)}
|
|
1283
|
-
}
|
|
1284
|
-
`;
|
|
1285
|
-
const l = a[0], u = a[1], f = O(r);
|
|
1286
|
-
return u === 1 ? t ? `
|
|
1287
|
-
float ${o}(int row, int col) {
|
|
1288
|
-
float index = dot(vec3(row, col, ${f}), vec3(${r}Shape[1], 1, 1));
|
|
1289
|
-
vec2 uv = vec2(0.5, (index + 0.5) / float(${r}TexShape[0]));
|
|
1290
|
-
return sampleTexture(${r}, uv);
|
|
1291
|
-
}
|
|
1292
|
-
` : `
|
|
1293
|
-
float ${o}(int row, int col) {
|
|
1294
|
-
float index = dot(vec3(row, col, ${f}), vec3(${n[1]}, 1, 1));
|
|
1295
|
-
vec2 uv = vec2(0.5, (index + 0.5) / ${l}.0);
|
|
1296
|
-
return sampleTexture(${r}, uv);
|
|
1297
|
-
}
|
|
1298
|
-
` : l === 1 ? t ? `
|
|
1299
|
-
float ${o}(int row, int col) {
|
|
1300
|
-
float index = dot(vec3(row, col, ${f}), vec3(${r}Shape[1], 1, 1));
|
|
1301
|
-
vec2 uv = vec2((index + 0.5) / float(${r}TexShape[1]), 0.5);
|
|
1302
|
-
return sampleTexture(${r}, uv);
|
|
1303
|
-
}
|
|
1304
|
-
` : `
|
|
1305
|
-
float ${o}(int row, int col) {
|
|
1306
|
-
float index = dot(vec3(row, col, ${f}), vec3(${n[1]}, 1, 1));
|
|
1307
|
-
vec2 uv = vec2((index + 0.5) / ${u}.0, 0.5);
|
|
1308
|
-
return sampleTexture(${r}, uv);
|
|
1309
|
-
}
|
|
1310
|
-
` : t ? `
|
|
1311
|
-
float ${o}(int row, int col) {
|
|
1312
|
-
// Explicitly use integer operations as dot() only works on floats.
|
|
1313
|
-
int index = row * ${r}Shape[1] + col + ${f};
|
|
1314
|
-
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index);
|
|
1315
|
-
return sampleTexture(${r}, uv);
|
|
1316
|
-
}
|
|
1317
|
-
` : `
|
|
1318
|
-
float ${o}(int row, int col) {
|
|
1319
|
-
// Explicitly use integer operations as dot() only works on floats.
|
|
1320
|
-
int index = row * ${n[1]} + col + ${f};
|
|
1321
|
-
vec2 uv = uvFromFlat(${l}, ${u}, index);
|
|
1322
|
-
return sampleTexture(${r}, uv);
|
|
1323
|
-
}
|
|
1324
|
-
`;
|
|
1325
|
-
}
|
|
1326
|
-
function Je(e, t) {
|
|
1327
|
-
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = e.shapeInfo.texShape, i = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)];
|
|
1328
|
-
if (n[0] === 1) {
|
|
1329
|
-
const d = n.slice(1), x = [1, 2], h = g(e, d), p = ["b", "row", "col"];
|
|
1330
|
-
return `
|
|
1331
|
-
${te(h, t)}
|
|
1332
|
-
vec4 ${o}(int b, int row, int col) {
|
|
1333
|
-
return ${o}(${b(p, x)});
|
|
1334
|
-
}
|
|
1335
|
-
`;
|
|
1336
|
-
}
|
|
1337
|
-
const c = U();
|
|
1338
|
-
if (t)
|
|
1339
|
-
return `
|
|
1340
|
-
vec4 ${o}(int b, int row, int col) {
|
|
1341
|
-
ivec2 packedTexShape = ivec2(ceil(float(${r}TexShape[0]) / 2.0), ceil(float(${r}TexShape[1]) / 2.0));
|
|
1342
|
-
int valuesPerRow = int(ceil(float(${r}Shape[2]) / 2.0));
|
|
1343
|
-
int texelsInBatch = valuesPerRow * int(ceil(float(${r}Shape[1]) / 2.0));
|
|
1344
|
-
vec2 uv = packedUVfrom3D(
|
|
1345
|
-
packedTexShape[0], packedTexShape[1], texelsInBatch, valuesPerRow, b, row, col);
|
|
1346
|
-
return ${c.texture2D}(${r}, uv);
|
|
1347
|
-
}
|
|
1348
|
-
`;
|
|
1349
|
-
const s = i[0], l = i[1], u = Math.ceil(n[2] / 2), f = u * Math.ceil(n[1] / 2);
|
|
1350
|
-
return `
|
|
1351
|
-
vec4 ${o}(int b, int row, int col) {
|
|
1352
|
-
vec2 uv = packedUVfrom3D(
|
|
1353
|
-
${s}, ${l}, ${f}, ${u}, b, row, col);
|
|
1354
|
-
return ${c.texture2D}(${r}, uv);
|
|
1355
|
-
}
|
|
1356
|
-
`;
|
|
1357
|
-
}
|
|
1358
|
-
function Qe(e, t) {
|
|
1359
|
-
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = n[1] * n[2], i = n[2], { newShape: c, keptDims: s } = N(n), l = c;
|
|
1360
|
-
if (l.length < n.length) {
|
|
1361
|
-
const p = g(e, l), m = ["row", "col", "depth"];
|
|
1362
|
-
return `
|
|
1363
|
-
${L(p, t)}
|
|
1364
|
-
float ${o}(int row, int col, int depth) {
|
|
1365
|
-
return ${o}(${b(m, s)});
|
|
1366
|
-
}
|
|
1367
|
-
`;
|
|
1368
|
-
}
|
|
1369
|
-
if (e.shapeInfo.isUniform)
|
|
1370
|
-
return `
|
|
1371
|
-
float ${o}(int row, int col, int depth) {
|
|
1372
|
-
int index = round(dot(vec3(row, col, depth),
|
|
1373
|
-
vec3(${a}, ${i}, 1)));
|
|
1374
|
-
${D(e)}
|
|
1375
|
-
}
|
|
1376
|
-
`;
|
|
1377
|
-
const u = e.shapeInfo.texShape, f = u[0], d = u[1], x = e.shapeInfo.flatOffset;
|
|
1378
|
-
if (d === a && x == null)
|
|
1379
|
-
return t ? `
|
|
1380
|
-
float ${o}(int row, int col, int depth) {
|
|
1381
|
-
int stride1 = ${r}Shape[2];
|
|
1382
|
-
float texR = float(row);
|
|
1383
|
-
float texC = dot(vec2(col, depth), vec2(stride1, 1));
|
|
1384
|
-
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1385
|
-
vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1386
|
-
return sampleTexture(${r}, uv);
|
|
1387
|
-
}
|
|
1388
|
-
` : `
|
|
1389
|
-
float ${o}(int row, int col, int depth) {
|
|
1390
|
-
float texR = float(row);
|
|
1391
|
-
float texC = dot(vec2(col, depth), vec2(${i}, 1));
|
|
1392
|
-
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1393
|
-
vec2(${d}.0, ${f}.0);
|
|
1394
|
-
return sampleTexture(${r}, uv);
|
|
1395
|
-
}
|
|
1396
|
-
`;
|
|
1397
|
-
if (d === i && x == null)
|
|
1398
|
-
return t ? `
|
|
1399
|
-
float ${o}(int row, int col, int depth) {
|
|
1400
|
-
float texR = dot(vec2(row, col), vec2(${r}Shape[1], 1));
|
|
1401
|
-
float texC = float(depth);
|
|
1402
|
-
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1403
|
-
return sampleTexture(${r}, uv);
|
|
1404
|
-
}
|
|
1405
|
-
` : `
|
|
1406
|
-
float ${o}(int row, int col, int depth) {
|
|
1407
|
-
float texR = dot(vec2(row, col), vec2(${n[1]}, 1));
|
|
1408
|
-
float texC = float(depth);
|
|
1409
|
-
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${d}.0, ${f}.0);
|
|
1410
|
-
return sampleTexture(${r}, uv);
|
|
1411
|
-
}
|
|
1412
|
-
`;
|
|
1413
|
-
const h = O(r);
|
|
1414
|
-
return t ? `
|
|
1415
|
-
float ${o}(int row, int col, int depth) {
|
|
1416
|
-
// Explicitly use integer operations as dot() only works on floats.
|
|
1417
|
-
int stride0 = ${r}Shape[1] * ${r}Shape[2];
|
|
1418
|
-
int stride1 = ${r}Shape[2];
|
|
1419
|
-
int index = row * stride0 + col * stride1 + depth + ${h};
|
|
1420
|
-
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index);
|
|
1421
|
-
return sampleTexture(${r}, uv);
|
|
1422
|
-
}
|
|
1423
|
-
` : `
|
|
1424
|
-
float ${o}(int row, int col, int depth) {
|
|
1425
|
-
// Explicitly use integer operations as dot() only works on floats.
|
|
1426
|
-
int index = row * ${a} + col * ${i} + depth + ${h};
|
|
1427
|
-
vec2 uv = uvFromFlat(${f}, ${d}, index);
|
|
1428
|
-
return sampleTexture(${r}, uv);
|
|
1429
|
-
}
|
|
1430
|
-
`;
|
|
1431
|
-
}
|
|
1432
|
-
function et(e, t) {
|
|
1433
|
-
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = U();
|
|
1434
|
-
if (t)
|
|
1435
|
-
return `
|
|
1436
|
-
vec4 ${r}(int b2, int b, int row, int col) {
|
|
1437
|
-
int valuesPerRow = int(ceil(float(${n}Shape[3]) / 2.0));
|
|
1438
|
-
int texelsInBatch = valuesPerRow * int(ceil(float(${n}Shape[2]) / 2.0));
|
|
1439
|
-
int index = b * texelsInBatch + (row / 2) * valuesPerRow + (col / 2);
|
|
1440
|
-
texelsInBatch *= ${n}Shape[1];
|
|
1441
|
-
index = b2 * texelsInBatch + index;
|
|
1442
|
-
ivec2 packedTexShape = ivec2(ceil(float(${n}TexShape[0]) / 2.0), ceil(float(${n}TexShape[1]) / 2.0));
|
|
1443
|
-
int texR = index / packedTexShape[1];
|
|
1444
|
-
int texC = index - texR * packedTexShape[1];
|
|
1445
|
-
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(packedTexShape[1], packedTexShape[0]); return ${o.texture2D}(${n}, uv);
|
|
1446
|
-
}
|
|
1447
|
-
`;
|
|
1448
|
-
const a = e.shapeInfo.logicalShape, i = a.length, c = e.shapeInfo.texShape, s = [Math.ceil(c[0] / 2), Math.ceil(c[1] / 2)], l = s[0], u = s[1], f = Math.ceil(a[i - 1] / 2);
|
|
1449
|
-
let d = f * Math.ceil(a[i - 2] / 2), x = "int b, int row, int col", h = `b * ${d} + (row / 2) * ${f} + (col / 2)`;
|
|
1450
|
-
for (let p = 2; p < i - 1; p++)
|
|
1451
|
-
x = `int b${p}, ` + x, d *= a[i - p - 1], h = `b${p} * ${d} + ` + h;
|
|
1452
|
-
return `
|
|
1453
|
-
vec4 ${r}(${x}) {
|
|
1454
|
-
int index = ${h};
|
|
1455
|
-
int texR = index / ${u};
|
|
1456
|
-
int texC = index - texR * ${u};
|
|
1457
|
-
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${u}, ${l});
|
|
1458
|
-
return ${o.texture2D}(${n}, uv);
|
|
1459
|
-
}
|
|
1460
|
-
`;
|
|
1461
|
-
}
|
|
1462
|
-
function tt(e, t) {
|
|
1463
|
-
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = n[3], i = n[2] * a, c = n[1] * i, { newShape: s, keptDims: l } = N(n);
|
|
1464
|
-
if (s.length < n.length) {
|
|
1465
|
-
const R = g(e, s), F = ["row", "col", "depth", "depth2"];
|
|
1466
|
-
return `
|
|
1467
|
-
${L(R, t)}
|
|
1468
|
-
float ${o}(int row, int col, int depth, int depth2) {
|
|
1469
|
-
return ${o}(${b(F, l)});
|
|
1470
|
-
}
|
|
1471
|
-
`;
|
|
1472
|
-
}
|
|
1473
|
-
if (e.shapeInfo.isUniform)
|
|
1474
|
-
return `
|
|
1475
|
-
float ${o}(int row, int col, int depth, int depth2) {
|
|
1476
|
-
int index = round(dot(vec4(row, col, depth, depth2),
|
|
1477
|
-
vec4(${c}, ${i}, ${a}, 1)));
|
|
1478
|
-
${D(e)}
|
|
1479
|
-
}
|
|
1480
|
-
`;
|
|
1481
|
-
const u = e.shapeInfo.flatOffset, f = e.shapeInfo.texShape, d = f[0], x = f[1], h = `int stride2 = ${r}Shape[3];`, p = `int stride1 = ${r}Shape[2] * stride2;`, m = `int stride0 = ${r}Shape[1] * stride1;`;
|
|
1482
|
-
if (x === c && u == null)
|
|
1483
|
-
return t ? `
|
|
1484
|
-
float ${o}(int row, int col, int depth, int depth2) {
|
|
1485
|
-
${h}
|
|
1486
|
-
${p}
|
|
1487
|
-
float texR = float(row);
|
|
1488
|
-
float texC =
|
|
1489
|
-
dot(vec3(col, depth, depth2),
|
|
1490
|
-
vec3(stride1, stride2, 1));
|
|
1491
|
-
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1492
|
-
vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1493
|
-
return sampleTexture(${r}, uv);
|
|
1494
|
-
}
|
|
1495
|
-
` : `
|
|
1496
|
-
float ${o}(int row, int col, int depth, int depth2) {
|
|
1497
|
-
float texR = float(row);
|
|
1498
|
-
float texC =
|
|
1499
|
-
dot(vec3(col, depth, depth2),
|
|
1500
|
-
vec3(${i}, ${a}, 1));
|
|
1501
|
-
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1502
|
-
vec2(${x}.0, ${d}.0);
|
|
1503
|
-
return sampleTexture(${r}, uv);
|
|
1504
|
-
}
|
|
1505
|
-
`;
|
|
1506
|
-
if (x === a && u == null)
|
|
1507
|
-
return t ? `
|
|
1508
|
-
float ${o}(int row, int col, int depth, int depth2) {
|
|
1509
|
-
float texR = dot(vec3(row, col, depth),
|
|
1510
|
-
vec3(${r}Shape[1] * ${r}Shape[2], ${r}Shape[2], 1));
|
|
1511
|
-
float texC = float(depth2);
|
|
1512
|
-
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1513
|
-
vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1514
|
-
return sampleTexture(${r}, uv);
|
|
1515
|
-
}
|
|
1516
|
-
` : `
|
|
1517
|
-
float ${o}(int row, int col, int depth, int depth2) {
|
|
1518
|
-
float texR = dot(vec3(row, col, depth),
|
|
1519
|
-
vec3(${n[1] * n[2]}, ${n[2]}, 1));
|
|
1520
|
-
float texC = float(depth2);
|
|
1521
|
-
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1522
|
-
vec2(${x}.0, ${d}.0);
|
|
1523
|
-
return sampleTexture(${r}, uv);
|
|
1524
|
-
}
|
|
1525
|
-
`;
|
|
1526
|
-
const S = O(r);
|
|
1527
|
-
return t ? `
|
|
1528
|
-
float ${o}(int row, int col, int depth, int depth2) {
|
|
1529
|
-
// Explicitly use integer operations as dot() only works on floats.
|
|
1530
|
-
${h}
|
|
1531
|
-
${p}
|
|
1532
|
-
${m}
|
|
1533
|
-
int index = row * stride0 + col * stride1 +
|
|
1534
|
-
depth * stride2 + depth2;
|
|
1535
|
-
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index + ${S});
|
|
1536
|
-
return sampleTexture(${r}, uv);
|
|
1537
|
-
}
|
|
1538
|
-
` : `
|
|
1539
|
-
float ${o}(int row, int col, int depth, int depth2) {
|
|
1540
|
-
// Explicitly use integer operations as dot() only works on floats.
|
|
1541
|
-
int index = row * ${c} + col * ${i} +
|
|
1542
|
-
depth * ${a} + depth2;
|
|
1543
|
-
vec2 uv = uvFromFlat(${d}, ${x}, index + ${S});
|
|
1544
|
-
return sampleTexture(${r}, uv);
|
|
1545
|
-
}
|
|
1546
|
-
`;
|
|
1547
|
-
}
|
|
1548
|
-
function nt(e) {
|
|
1549
|
-
const t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = t[4], a = t[3] * o, i = t[2] * a, c = t[1] * i, { newShape: s, keptDims: l } = N(t);
|
|
1550
|
-
if (s.length < t.length) {
|
|
1551
|
-
const p = g(e, s), m = ["row", "col", "depth", "depth2", "depth3"];
|
|
1552
|
-
return `
|
|
1553
|
-
${L(p)}
|
|
1554
|
-
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
1555
|
-
return ${r}(${b(m, l)});
|
|
1556
|
-
}
|
|
1557
|
-
`;
|
|
1558
|
-
}
|
|
1559
|
-
if (e.shapeInfo.isUniform)
|
|
1560
|
-
return `
|
|
1561
|
-
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
1562
|
-
float index = dot(
|
|
1563
|
-
vec4(row, col, depth, depth2),
|
|
1564
|
-
vec4(${c}, ${i}, ${a}, ${o})) +
|
|
1565
|
-
depth3;
|
|
1566
|
-
${D(e)}
|
|
1567
|
-
}
|
|
1568
|
-
`;
|
|
1569
|
-
const u = e.shapeInfo.flatOffset, f = e.shapeInfo.texShape, d = f[0], x = f[1];
|
|
1570
|
-
if (x === c && u == null)
|
|
1571
|
-
return `
|
|
1572
|
-
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
1573
|
-
int texR = row;
|
|
1574
|
-
float texC = dot(vec4(col, depth, depth2, depth3),
|
|
1575
|
-
vec4(${i}, ${a}, ${o}, 1));
|
|
1576
|
-
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1577
|
-
vec2(${x}.0, ${d}.0);
|
|
1578
|
-
return sampleTexture(${n}, uv);
|
|
1579
|
-
}
|
|
1580
|
-
`;
|
|
1581
|
-
if (x === o && u == null)
|
|
1582
|
-
return `
|
|
1583
|
-
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
1584
|
-
float texR = dot(
|
|
1585
|
-
vec4(row, col, depth, depth2),
|
|
1586
|
-
vec4(${t[1] * t[2] * t[3]},
|
|
1587
|
-
${t[2] * t[3]}, ${t[3]}, 1));
|
|
1588
|
-
int texC = depth3;
|
|
1589
|
-
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1590
|
-
vec2(${x}.0, ${d}.0);
|
|
1591
|
-
return sampleTexture(${n}, uv);
|
|
1592
|
-
}
|
|
1593
|
-
`;
|
|
1594
|
-
const h = O(n);
|
|
1595
|
-
return `
|
|
1596
|
-
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
1597
|
-
// Explicitly use integer operations as dot() only works on floats.
|
|
1598
|
-
int index = row * ${c} + col * ${i} + depth * ${a} +
|
|
1599
|
-
depth2 * ${o} + depth3 + ${h};
|
|
1600
|
-
vec2 uv = uvFromFlat(${d}, ${x}, index);
|
|
1601
|
-
return sampleTexture(${n}, uv);
|
|
1602
|
-
}
|
|
1603
|
-
`;
|
|
1604
|
-
}
|
|
1605
|
-
function rt(e) {
|
|
1606
|
-
const t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), { newShape: o, keptDims: a } = N(t);
|
|
1607
|
-
if (o.length < t.length) {
|
|
1608
|
-
const m = g(e, o), S = ["row", "col", "depth", "depth2", "depth3", "depth4"];
|
|
1609
|
-
return `
|
|
1610
|
-
${L(m)}
|
|
1611
|
-
float ${r}(int row, int col, int depth,
|
|
1612
|
-
int depth2, int depth3, int depth4) {
|
|
1613
|
-
return ${r}(${b(S, a)});
|
|
1614
|
-
}
|
|
1615
|
-
`;
|
|
1616
|
-
}
|
|
1617
|
-
const i = t[5], c = t[4] * i, s = t[3] * c, l = t[2] * s, u = t[1] * l;
|
|
1618
|
-
if (e.shapeInfo.isUniform)
|
|
1619
|
-
return `
|
|
1620
|
-
float ${r}(int row, int col, int depth,
|
|
1621
|
-
int depth2, int depth3, int depth4) {
|
|
1622
|
-
int index = round(dot(
|
|
1623
|
-
vec4(row, col, depth, depth2),
|
|
1624
|
-
vec4(${u}, ${l}, ${s}, ${c})) +
|
|
1625
|
-
dot(
|
|
1626
|
-
vec2(depth3, depth4),
|
|
1627
|
-
vec2(${i}, 1)));
|
|
1628
|
-
${D(e)}
|
|
1629
|
-
}
|
|
1630
|
-
`;
|
|
1631
|
-
const f = e.shapeInfo.flatOffset, d = e.shapeInfo.texShape, x = d[0], h = d[1];
|
|
1632
|
-
if (h === u && f == null)
|
|
1633
|
-
return `
|
|
1634
|
-
float ${r}(int row, int col, int depth,
|
|
1635
|
-
int depth2, int depth3, int depth4) {
|
|
1636
|
-
int texR = row;
|
|
1637
|
-
float texC = dot(vec4(col, depth, depth2, depth3),
|
|
1638
|
-
vec4(${l}, ${s}, ${c}, ${i})) +
|
|
1639
|
-
float(depth4);
|
|
1640
|
-
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1641
|
-
vec2(${h}.0, ${x}.0);
|
|
1642
|
-
return sampleTexture(${n}, uv);
|
|
1643
|
-
}
|
|
1644
|
-
`;
|
|
1645
|
-
if (h === i && f == null)
|
|
1646
|
-
return `
|
|
1647
|
-
float ${r}(int row, int col, int depth,
|
|
1648
|
-
int depth2, int depth3, int depth4) {
|
|
1649
|
-
float texR = dot(vec4(row, col, depth, depth2),
|
|
1650
|
-
vec4(${t[1] * t[2] * t[3] * t[4]},
|
|
1651
|
-
${t[2] * t[3] * t[4]},
|
|
1652
|
-
${t[3] * t[4]},
|
|
1653
|
-
${t[4]})) + float(depth3);
|
|
1654
|
-
int texC = depth4;
|
|
1655
|
-
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1656
|
-
vec2(${h}.0, ${x}.0);
|
|
1657
|
-
return sampleTexture(${n}, uv);
|
|
1658
|
-
}
|
|
1659
|
-
`;
|
|
1660
|
-
const p = O(n);
|
|
1661
|
-
return `
|
|
1662
|
-
float ${r}(int row, int col, int depth,
|
|
1663
|
-
int depth2, int depth3, int depth4) {
|
|
1664
|
-
// Explicitly use integer operations as dot() only works on floats.
|
|
1665
|
-
int index = row * ${u} + col * ${l} + depth * ${s} +
|
|
1666
|
-
depth2 * ${c} + depth3 * ${i} + depth4 + ${p};
|
|
1667
|
-
vec2 uv = uvFromFlat(${x}, ${h}, index);
|
|
1668
|
-
return sampleTexture(${n}, uv);
|
|
1669
|
-
}
|
|
1670
|
-
`;
|
|
1671
|
-
}
|
|
1672
|
-
function D(e) {
|
|
1673
|
-
const t = e.name, n = E(e.shapeInfo.logicalShape);
|
|
1674
|
-
return n < 2 ? `return ${t};` : `
|
|
1675
|
-
for (int i = 0; i < ${n}; i++) {
|
|
1676
|
-
if (i == index) {
|
|
1677
|
-
return ${t}[i];
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
`;
|
|
1681
|
-
}
|
|
1682
|
-
function ot(e, t) {
|
|
1683
|
-
const n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), o = "get" + r + "AtOutCoords", a = e.shapeInfo.logicalShape.length, i = t.logicalShape.length, c = ee(e.shapeInfo.logicalShape, t.logicalShape), s = re(i), l = i - a;
|
|
1684
|
-
let u;
|
|
1685
|
-
const f = ["x", "y", "z", "w", "u", "v"];
|
|
1686
|
-
a === 0 ? u = "" : i < 2 && c.length >= 1 ? u = "coords = 0;" : u = c.map((R) => `coords.${f[R + l]} = 0;`).join(`
|
|
1687
|
-
`);
|
|
1688
|
-
let d = "";
|
|
1689
|
-
i < 2 && a > 0 ? d = "coords" : d = e.shapeInfo.logicalShape.map((R, F) => `coords.${f[F + l]}`).join(", ");
|
|
1690
|
-
let x = "return outputValue;";
|
|
1691
|
-
const p = E(e.shapeInfo.logicalShape) === 1, S = E(t.logicalShape) === 1;
|
|
1692
|
-
if (a === 1 && !p && !S)
|
|
1693
|
-
x = `
|
|
1694
|
-
return vec4(outputValue.xy, outputValue.xy);
|
|
1695
|
-
`;
|
|
1696
|
-
else if (p && !S)
|
|
1697
|
-
i === 1 ? x = `
|
|
1698
|
-
return vec4(outputValue.x, outputValue.x, 0., 0.);
|
|
1699
|
-
` : x = `
|
|
1700
|
-
return vec4(outputValue.x);
|
|
1701
|
-
`;
|
|
1702
|
-
else if (c.length) {
|
|
1703
|
-
const R = a - 2, F = a - 1;
|
|
1704
|
-
c.indexOf(R) > -1 && c.indexOf(F) > -1 ? x = "return vec4(outputValue.x);" : c.indexOf(R) > -1 ? x = "return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);" : c.indexOf(F) > -1 && (x = "return vec4(outputValue.xx, outputValue.zz);");
|
|
1705
|
-
}
|
|
1706
|
-
return `
|
|
1707
|
-
vec4 ${o}() {
|
|
1708
|
-
${s} coords = getOutputCoords();
|
|
1709
|
-
${u}
|
|
1710
|
-
vec4 outputValue = get${r}(${d});
|
|
1711
|
-
${x}
|
|
1712
|
-
}
|
|
1713
|
-
`;
|
|
1714
|
-
}
|
|
1715
|
-
function at(e, t) {
|
|
1716
|
-
const n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), o = "get" + r + "AtOutCoords", a = t.texShape, i = e.shapeInfo.texShape, c = e.shapeInfo.logicalShape.length, s = t.logicalShape.length;
|
|
1717
|
-
if (!e.shapeInfo.isUniform && c === s && e.shapeInfo.flatOffset == null && T(i, a))
|
|
1718
|
-
return `
|
|
1719
|
-
float ${o}() {
|
|
1720
|
-
return sampleTexture(${n}, resultUV);
|
|
1721
|
-
}
|
|
1722
|
-
`;
|
|
1723
|
-
const l = re(s), u = ee(e.shapeInfo.logicalShape, t.logicalShape), f = s - c;
|
|
1724
|
-
let d;
|
|
1725
|
-
const x = ["x", "y", "z", "w", "u", "v"];
|
|
1726
|
-
c === 0 ? d = "" : s < 2 && u.length >= 1 ? d = "coords = 0;" : d = u.map((p) => `coords.${x[p + f]} = 0;`).join(`
|
|
1727
|
-
`);
|
|
1728
|
-
let h = "";
|
|
1729
|
-
return s < 2 && c > 0 ? h = "coords" : h = e.shapeInfo.logicalShape.map((p, m) => `coords.${x[m + f]}`).join(", "), `
|
|
1730
|
-
float ${o}() {
|
|
1731
|
-
${l} coords = getOutputCoords();
|
|
1732
|
-
${d}
|
|
1733
|
-
return get${r}(${h});
|
|
1734
|
-
}
|
|
1735
|
-
`;
|
|
1736
|
-
}
|
|
1737
|
-
function re(e) {
|
|
1738
|
-
if (e <= 1)
|
|
1739
|
-
return "int";
|
|
1740
|
-
if (e === 2)
|
|
1741
|
-
return "ivec2";
|
|
1742
|
-
if (e === 3)
|
|
1743
|
-
return "ivec3";
|
|
1744
|
-
if (e === 4)
|
|
1745
|
-
return "ivec4";
|
|
1746
|
-
if (e === 5)
|
|
1747
|
-
return "ivec5";
|
|
1748
|
-
if (e === 6)
|
|
1749
|
-
return "ivec6";
|
|
1750
|
-
throw Error(`GPU for rank ${e} is not yet supported`);
|
|
1751
|
-
}
|
|
1752
|
-
function z(e, t, n) {
|
|
1753
|
-
const { newShape: r, keptDims: o } = N(t), a = t.length, i = e && a === 3 && t[0] === 1, c = i ? t.slice(1) : r, s = !e && a > 1 && !T(t, n) && r.length < a || i;
|
|
1754
|
-
return { useSqueezeShape: s, uniformShape: s ? c : t, keptDims: o };
|
|
1755
|
-
}
|
|
1756
|
-
function g(e, t) {
|
|
1757
|
-
const n = JSON.parse(JSON.stringify(e));
|
|
1758
|
-
return n.shapeInfo.logicalShape = t, n;
|
|
1759
|
-
}
|
|
1760
|
-
function b(e, t) {
|
|
1761
|
-
return t.map((n) => e[n]).join(", ");
|
|
1762
|
-
}
|
|
1763
|
-
function qt(e, t, n, r) {
|
|
1764
|
-
const o = n.map((u, f) => {
|
|
1765
|
-
const d = {
|
|
1766
|
-
logicalShape: u.shape,
|
|
1767
|
-
texShape: u.isUniform ? null : u.texData.texShape,
|
|
1768
|
-
isUniform: u.isUniform,
|
|
1769
|
-
isPacked: u.isUniform ? !1 : u.texData.isPacked,
|
|
1770
|
-
flatOffset: null
|
|
1771
|
-
};
|
|
1772
|
-
return u.texData != null && u.texData.slice != null && u.texData.slice.flatOffset > 0 && (d.flatOffset = u.texData.slice.flatOffset), { name: t.variableNames[f], shapeInfo: d };
|
|
1773
|
-
}), a = o.map((u) => u.shapeInfo), i = {
|
|
1774
|
-
logicalShape: r.shape,
|
|
1775
|
-
texShape: r.texData.texShape,
|
|
1776
|
-
isUniform: !1,
|
|
1777
|
-
isPacked: r.texData.isPacked,
|
|
1778
|
-
flatOffset: null
|
|
1779
|
-
}, c = Fe(o, i, t), s = ve(e.gl, c), l = e.createProgram(s);
|
|
1780
|
-
return $().get("ENGINE_COMPILE_ONLY") ? {
|
|
1781
|
-
program: t,
|
|
1782
|
-
fragmentShader: s,
|
|
1783
|
-
source: c,
|
|
1784
|
-
webGLProgram: l,
|
|
1785
|
-
inShapeInfos: a,
|
|
1786
|
-
outShapeInfo: i,
|
|
1787
|
-
variablesLocations: null,
|
|
1788
|
-
customUniformLocations: null,
|
|
1789
|
-
infLoc: null,
|
|
1790
|
-
nanLoc: null,
|
|
1791
|
-
outShapeLocation: null,
|
|
1792
|
-
outShapeStridesLocation: null,
|
|
1793
|
-
outTexShapeLocation: null
|
|
1794
|
-
} : (e.buildVao(l), Object.assign({
|
|
1795
|
-
program: t,
|
|
1796
|
-
fragmentShader: s,
|
|
1797
|
-
source: c,
|
|
1798
|
-
webGLProgram: l,
|
|
1799
|
-
inShapeInfos: a,
|
|
1800
|
-
outShapeInfo: i
|
|
1801
|
-
}, it(e, t, l)));
|
|
1802
|
-
}
|
|
1803
|
-
function it(e, t, n) {
|
|
1804
|
-
const r = [], o = [];
|
|
1805
|
-
let a, i, c, s = null, l = null;
|
|
1806
|
-
l = e.getUniformLocation(n, "NAN", !1), $().getNumber("WEBGL_VERSION") === 1 && (s = e.getUniformLocation(n, "INFINITY", !1));
|
|
1807
|
-
const u = !1;
|
|
1808
|
-
for (const f of t.variableNames) {
|
|
1809
|
-
const d = {
|
|
1810
|
-
name: f,
|
|
1811
|
-
uniform: e.getUniformLocation(n, f, u),
|
|
1812
|
-
offset: e.getUniformLocation(n, `offset${f}`, u)
|
|
1813
|
-
};
|
|
1814
|
-
t.enableShapeUniforms && (d.shape = e.getUniformLocation(n, `${f}Shape`, u), d.texShape = e.getUniformLocation(n, `${f}TexShape`, u)), r.push(d);
|
|
1815
|
-
}
|
|
1816
|
-
if (t.enableShapeUniforms && (a = e.getUniformLocation(n, "outShape", u), c = e.getUniformLocation(n, "outShapeStrides", u), i = e.getUniformLocation(n, "outTexShape", u)), t.customUniforms)
|
|
1817
|
-
for (const f of t.customUniforms)
|
|
1818
|
-
o.push(e.getUniformLocation(n, f.name, u));
|
|
1819
|
-
return {
|
|
1820
|
-
variablesLocations: r,
|
|
1821
|
-
customUniformLocations: o,
|
|
1822
|
-
infLoc: s,
|
|
1823
|
-
nanLoc: l,
|
|
1824
|
-
outShapeLocation: a,
|
|
1825
|
-
outShapeStridesLocation: c,
|
|
1826
|
-
outTexShapeLocation: i
|
|
1827
|
-
};
|
|
1828
|
-
}
|
|
1829
|
-
function Y(e, t) {
|
|
1830
|
-
if (e.length !== t.length)
|
|
1831
|
-
throw Error(`Binary was compiled with ${e.length} inputs, but was executed with ${t.length} inputs`);
|
|
1832
|
-
e.forEach((n, r) => {
|
|
1833
|
-
const o = n.logicalShape, a = t[r], i = a.shape;
|
|
1834
|
-
if (!T(o, i))
|
|
1835
|
-
throw Error(`Binary was compiled with different shapes than the current args. Shapes ${o} and ${i} must match`);
|
|
1836
|
-
if (n.isUniform && a.isUniform)
|
|
1837
|
-
return;
|
|
1838
|
-
const c = n.texShape, s = a.isUniform ? null : a.texData.texShape;
|
|
1839
|
-
if (!T(c, s))
|
|
1840
|
-
throw Error(`Binary was compiled with different texture shapes than the current args. Shape ${c} and ${s} must match`);
|
|
1841
|
-
});
|
|
1842
|
-
}
|
|
1843
|
-
function jt(e, t, n, r, o) {
|
|
1844
|
-
t.program.enableShapeUniforms || (Y(t.inShapeInfos, n), Y([t.outShapeInfo], [r]));
|
|
1845
|
-
const a = r.texData.texture, i = r.texData.texShape;
|
|
1846
|
-
r.texData.isPacked ? e.setOutputPackedMatrixTexture(a.texture, i[0], i[1]) : e.setOutputMatrixTexture(a.texture, i[0], i[1]), e.setProgram(t.webGLProgram), e.bindVertexArray(t.webGLProgram.vao), $().getNumber("WEBGL_VERSION") === 1 && t.infLoc !== null && e.gl.uniform1f(t.infLoc, 1 / 0), t.nanLoc !== null && e.gl.uniform1f(t.nanLoc, NaN);
|
|
1847
|
-
for (let s = 0; s < n.length; ++s) {
|
|
1848
|
-
const l = n[s], { uniform: u, offset: f, shape: d, texShape: x } = t.variablesLocations[s];
|
|
1849
|
-
if (d) {
|
|
1850
|
-
const { uniformShape: h } = z(t.program.packedInputs, l.shape, l.texData.texShape);
|
|
1851
|
-
switch (h.length) {
|
|
1852
|
-
case 1:
|
|
1853
|
-
e.gl.uniform1iv(d, new Int32Array(h));
|
|
1854
|
-
break;
|
|
1855
|
-
case 2:
|
|
1856
|
-
e.gl.uniform2iv(d, new Int32Array(h));
|
|
1857
|
-
break;
|
|
1858
|
-
case 3:
|
|
1859
|
-
e.gl.uniform3iv(d, new Int32Array(h));
|
|
1860
|
-
break;
|
|
1861
|
-
case 4:
|
|
1862
|
-
e.gl.uniform4iv(d, new Int32Array(h));
|
|
1863
|
-
break;
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
if (x && e.gl.uniform2i(x, l.texData.texShape[0], l.texData.texShape[1]), u != null) {
|
|
1867
|
-
if (l.isUniform) {
|
|
1868
|
-
if (E(l.shape) < 2)
|
|
1869
|
-
e.gl.uniform1f(u, l.uniformValues[0]);
|
|
1870
|
-
else {
|
|
1871
|
-
let h = l.uniformValues;
|
|
1872
|
-
h instanceof Float32Array || (h = new Float32Array(h)), e.gl.uniform1fv(u, h);
|
|
1873
|
-
}
|
|
1874
|
-
continue;
|
|
1875
|
-
}
|
|
1876
|
-
l.texData.slice != null && f != null && e.gl.uniform1i(f, l.texData.slice.flatOffset), e.setInputMatrixTexture(l.texData.texture.texture, u, s);
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
const c = t.outShapeLocation;
|
|
1880
|
-
if (c)
|
|
1881
|
-
switch (r.shape.length) {
|
|
1882
|
-
case 1:
|
|
1883
|
-
e.gl.uniform1iv(c, new Int32Array(r.shape));
|
|
1884
|
-
break;
|
|
1885
|
-
case 2:
|
|
1886
|
-
e.gl.uniform2iv(c, new Int32Array(r.shape));
|
|
1887
|
-
break;
|
|
1888
|
-
case 3:
|
|
1889
|
-
e.gl.uniform3iv(c, new Int32Array(r.shape));
|
|
1890
|
-
break;
|
|
1891
|
-
case 4:
|
|
1892
|
-
e.gl.uniform4iv(c, new Int32Array(r.shape));
|
|
1893
|
-
break;
|
|
1894
|
-
}
|
|
1895
|
-
if (t.outShapeStridesLocation) {
|
|
1896
|
-
const s = k(r.shape);
|
|
1897
|
-
switch (r.shape.length) {
|
|
1898
|
-
case 2:
|
|
1899
|
-
e.gl.uniform1iv(t.outShapeStridesLocation, new Int32Array(s));
|
|
1900
|
-
break;
|
|
1901
|
-
case 3:
|
|
1902
|
-
e.gl.uniform2iv(t.outShapeStridesLocation, new Int32Array(s));
|
|
1903
|
-
break;
|
|
1904
|
-
case 4:
|
|
1905
|
-
e.gl.uniform3iv(t.outShapeStridesLocation, new Int32Array(s));
|
|
1906
|
-
break;
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
|
-
if (t.outTexShapeLocation && e.gl.uniform2i(t.outTexShapeLocation, r.texData.texShape[0], r.texData.texShape[1]), t.program.customUniforms && o)
|
|
1910
|
-
for (let s = 0; s < t.program.customUniforms.length; ++s) {
|
|
1911
|
-
const l = t.program.customUniforms[s], u = t.customUniformLocations[s], f = o[s];
|
|
1912
|
-
if (l.type === "float")
|
|
1913
|
-
e.gl.uniform1fv(u, f);
|
|
1914
|
-
else if (l.type === "vec2")
|
|
1915
|
-
e.gl.uniform2fv(u, f);
|
|
1916
|
-
else if (l.type === "vec3")
|
|
1917
|
-
e.gl.uniform3fv(u, f);
|
|
1918
|
-
else if (l.type === "vec4")
|
|
1919
|
-
e.gl.uniform4fv(u, f);
|
|
1920
|
-
else if (l.type === "int")
|
|
1921
|
-
e.gl.uniform1iv(u, f);
|
|
1922
|
-
else if (l.type === "ivec2")
|
|
1923
|
-
e.gl.uniform2iv(u, f);
|
|
1924
|
-
else if (l.type === "ivec3")
|
|
1925
|
-
e.gl.uniform3iv(u, f);
|
|
1926
|
-
else if (l.type === "ivec4")
|
|
1927
|
-
e.gl.uniform4iv(u, f);
|
|
1928
|
-
else
|
|
1929
|
-
throw Error(`uniform type ${l.type} is not supported yet.`);
|
|
1930
|
-
}
|
|
1931
|
-
e.executeProgram();
|
|
1932
|
-
}
|
|
1933
|
-
function Yt(e, t, n) {
|
|
1934
|
-
let r = "";
|
|
1935
|
-
t.concat(n).forEach((i) => {
|
|
1936
|
-
const c = i.texData != null && i.texData.slice != null && i.texData.slice.flatOffset > 0;
|
|
1937
|
-
if (e.enableShapeUniforms && !i.isUniform) {
|
|
1938
|
-
const s = i.texData.texShape, { useSqueezeShape: l, uniformShape: u, keptDims: f } = z(e.packedInputs, i.shape, s);
|
|
1939
|
-
let d = "", x = "", h = "";
|
|
1940
|
-
if (u.length === 1 && e.packedInputs) {
|
|
1941
|
-
const I = [Math.ceil(s[0] / 2), Math.ceil(s[1] / 2)];
|
|
1942
|
-
d = `${I[0] > 1}_${I[1] > 1}`;
|
|
1943
|
-
} else if (u.length === 2 && !e.packedInputs)
|
|
1944
|
-
x = `${u[0] > 1}_${u[1] > 1}`;
|
|
1945
|
-
else if (u.length > 2 && !e.packedInputs) {
|
|
1946
|
-
const I = k(u);
|
|
1947
|
-
h = `${I[0] === s[1]}_${I[I.length - 1] === s[1]}`;
|
|
1948
|
-
}
|
|
1949
|
-
const p = i.shape.length, m = u.length === 2 && T(i.shape, s), S = E(i.shape) === 1, R = ce(i.shape, n.shape), F = !e.packedInputs && p === n.shape.length && T(s, n.texData.texShape), oe = e.packedInputs || u.length > 2 ? "" : `${s[0] > 1}_${s[1] > 1}`;
|
|
1950
|
-
r += `${p}_${F}_${l ? f : ""}_${u.length}_${S}_${R}_${m}_${d}_${x}_${h}_${oe}_${c}`;
|
|
1951
|
-
} else {
|
|
1952
|
-
const s = i.isUniform ? "uniform" : i.texData.texShape;
|
|
1953
|
-
r += `${i.shape}_${s}_${c}`;
|
|
1954
|
-
}
|
|
1955
|
-
});
|
|
1956
|
-
const o = e.userCode;
|
|
1957
|
-
let a = e.constructor.name;
|
|
1958
|
-
return a += "_" + r + "_" + o + `${$().getNumber("WEBGL_VERSION")}`, a;
|
|
1959
|
-
}
|
|
1960
|
-
function Kt(e) {
|
|
1961
|
-
return $().getBool("WEBGL_USE_SHAPES_UNIFORMS") && e <= 4;
|
|
1962
|
-
}
|
|
1963
|
-
export {
|
|
1964
|
-
jt as $,
|
|
1965
|
-
fe as A,
|
|
1966
|
-
ft as B,
|
|
1967
|
-
dt as C,
|
|
1968
|
-
A as D,
|
|
1969
|
-
Ht as E,
|
|
1970
|
-
pt as F,
|
|
1971
|
-
_ as G,
|
|
1972
|
-
Ft as H,
|
|
1973
|
-
K as I,
|
|
1974
|
-
It as J,
|
|
1975
|
-
$t as K,
|
|
1976
|
-
mt as L,
|
|
1977
|
-
Tt as M,
|
|
1978
|
-
At as N,
|
|
1979
|
-
wt as O,
|
|
1980
|
-
H as P,
|
|
1981
|
-
Nt as Q,
|
|
1982
|
-
Ut as R,
|
|
1983
|
-
Ot as S,
|
|
1984
|
-
q as T,
|
|
1985
|
-
ut as U,
|
|
1986
|
-
j as V,
|
|
1987
|
-
Lt as W,
|
|
1988
|
-
xt as X,
|
|
1989
|
-
ht as Y,
|
|
1990
|
-
Yt as Z,
|
|
1991
|
-
qt as _,
|
|
1992
|
-
zt as a,
|
|
1993
|
-
Dt as a0,
|
|
1994
|
-
me as a1,
|
|
1995
|
-
it as a2,
|
|
1996
|
-
Xt as a3,
|
|
1997
|
-
Wt as b,
|
|
1998
|
-
y as c,
|
|
1999
|
-
Z as d,
|
|
2000
|
-
J as e,
|
|
2001
|
-
re as f,
|
|
2002
|
-
Gt as g,
|
|
2003
|
-
Bt as h,
|
|
2004
|
-
gt as i,
|
|
2005
|
-
bt as j,
|
|
2006
|
-
kt as k,
|
|
2007
|
-
Mt as l,
|
|
2008
|
-
yt as m,
|
|
2009
|
-
Pt as n,
|
|
2010
|
-
Vt as o,
|
|
2011
|
-
U as p,
|
|
2012
|
-
Q as q,
|
|
2013
|
-
St as r,
|
|
2014
|
-
Rt as s,
|
|
2015
|
-
v as t,
|
|
2016
|
-
Kt as u,
|
|
2017
|
-
vt as v,
|
|
2018
|
-
_t as w,
|
|
2019
|
-
Ct as x,
|
|
2020
|
-
Et as y,
|
|
2021
|
-
lt as z
|
|
2022
|
-
};
|