@genai-fi/nanogpt 1.5.0 → 1.6.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/dist/{DatasetBuilder-DU1G1OKX.js → DatasetBuilder-DRDW8tcM.js} +85 -86
- package/dist/Generator-BcR_14Cj.js +316 -0
- package/dist/{RealDiv-CSnvtN2E.js → RealDiv-Cl8k3YTx.js} +54 -62
- package/dist/{Reshape-BlylqwWy.js → Reshape-CKxKPKqi.js} +9 -12
- package/dist/Reshape-H5zZRgr9.js +16 -0
- package/dist/RoPECache-dYscFINl.js +722 -0
- package/dist/TeachableLLM.js +29 -34
- package/dist/api/beamer.js +5 -6
- package/dist/api/responses.js +11 -12
- package/dist/api/training.js +12 -14
- package/dist/axis_util-rF9RnwKE.js +37 -0
- package/dist/backend.js +5 -6
- package/dist/{backend_util-DAV0I34P.js → backend_util-Cpp0Gwlp.js} +180 -185
- package/dist/{binary_op_util-CrYk9LXL.js → binary_op_util-WY9YIl0q.js} +3 -7
- package/dist/broadcast_to-CGvLNiQ0.js +20 -0
- package/dist/checks/appendCache.js +7 -7
- package/dist/checks/attentionMask.js +9 -8
- package/dist/checks/check.js +1 -2
- package/dist/checks/gelu.js +6 -6
- package/dist/checks/index.js +24 -25
- package/dist/checks/matMulGelu.js +7 -7
- package/dist/checks/normRMS.js +14 -12
- package/dist/checks/normRMSGrad.js +9 -8
- package/dist/checks/packUnpack.js +7 -7
- package/dist/checks/qkv.js +1 -34
- package/dist/checks/rope.js +6 -6
- package/dist/checks/weights.js +1 -2
- package/dist/clip_by_value-D-UX9am5.js +13 -0
- package/dist/complex-Cl904TqN.js +13 -0
- package/dist/{complex_util-CkazZsaH.js → complex_util-BBlPAm-s.js} +1 -2
- package/dist/concat-Oip5acVY.js +14 -0
- package/dist/{concat_util-CWzvQQlK.js → concat_util-CY45Hf4F.js} +2 -3
- package/dist/data/docx.js +3 -4
- package/dist/data/pdf.js +11 -14
- package/dist/data/stream.js +1 -2
- package/dist/data/textLoader.js +16 -15
- package/dist/data-CV_i_H6B.js +11 -0
- package/dist/data.js +5 -12
- package/dist/dist-CMMLi-qO.js +2675 -0
- package/dist/{dist-BGVm64AY.js → dist-DeVH1nGn.js} +1465 -1573
- package/dist/{dist-CwK5S7Ls.js → dist-DyL7qSLJ.js} +2664 -2400
- package/dist/dropout16-CA31Ud5a.js +20 -0
- package/dist/dropout_util-SiFMbFXz.js +22 -0
- package/dist/{eventemitter3-D_qV3Lof.js → eventemitter3-wmfmOP_f.js} +2 -3
- package/dist/expand_dims-Dh3Fulyn.js +10 -0
- package/dist/floor-BwjmUb7X.js +8 -0
- package/dist/gather-B5Z1RFt5.js +14 -0
- package/dist/gatherSub-CRUfUzBa.js +22 -0
- package/dist/gelu-Xx9-ohH9.js +25 -0
- package/dist/{gpgpu_math-20tPK8LM.js → gpgpu_math-48m8q3jI.js} +265 -286
- package/dist/inference/Beamer.js +34 -27
- package/dist/inference/Generator.js +1 -273
- package/dist/inference/tokenisePrompt.js +5 -4
- package/dist/inference/types.d.ts +6 -0
- package/dist/inference/utilities.js +1 -2
- package/dist/{jszip.min-DKa1Rjyn.js → jszip.min-Btv48m44.js} +68 -64
- package/dist/{kernel_funcs_utils-ql8Y8qPn.js → kernel_funcs_utils-BYRpSfV_.js} +39 -42
- package/dist/layers/BaseLayer.js +9 -10
- package/dist/layers/GQA.js +45 -44
- package/dist/layers/HeadLayer.js +13 -13
- package/dist/layers/LoRA.js +17 -20
- package/dist/layers/MHA.d.ts +2 -2
- package/dist/layers/MHA.js +46 -45
- package/dist/layers/MLP.js +22 -21
- package/dist/layers/PositionEmbedding.js +14 -13
- package/dist/layers/RMSNorm.js +14 -13
- package/dist/layers/RoPECache.js +1 -338
- package/dist/layers/TiedEmbedding.js +15 -14
- package/dist/layers/TransformerBlock.d.ts +3 -9
- package/dist/layers/TransformerBlock.js +29 -30
- package/dist/layers/WeightStore.js +4 -5
- package/dist/layers-CFqEip3s.js +13 -0
- package/dist/layers.js +3 -11
- package/dist/loader/load.js +27 -24
- package/dist/loader/loadHF.js +3 -3
- package/dist/loader/loadTransformers.js +5 -6
- package/dist/loader/loadZipMeta.js +1 -2
- package/dist/loader/newZipLoad.js +1 -2
- package/dist/loader/oldZipLoad.js +8 -9
- package/dist/loader/save.js +15 -16
- package/dist/main.js +3281 -3463
- package/dist/{matMul16-CO1QhsRt.js → matMul16-tE26fnhf.js} +29 -27
- package/dist/{matMulGelu-CBoqTZM7.js → matMulGelu-ASUWlKqu.js} +33 -33
- package/dist/mat_mul-R9_DWmIT.js +16 -0
- package/dist/models/Llama.js +48 -49
- package/dist/models/NanoGPTV1.js +53 -54
- package/dist/models/NanoGPTV2.js +48 -49
- package/dist/models/Qwen3.js +48 -49
- package/dist/models/config.js +3 -8
- package/dist/models/factory.js +7 -8
- package/dist/models/model.d.ts +5 -7
- package/dist/models/model.js +1 -2
- package/dist/models-DyBpJJwM.js +13 -0
- package/dist/models.js +6 -14
- package/dist/mul16-C7sqgqik.js +41 -0
- package/dist/non_max_suppression_impl-B0H318rb.js +72 -0
- package/dist/not_equal-Bu3O8rh_.js +67 -0
- package/dist/one_hot-TEMPumJj.js +14 -0
- package/dist/ones-DpPXWa6A.js +13 -0
- package/dist/ops/adamAdjust.js +2 -3
- package/dist/ops/adamMoments.js +2 -3
- package/dist/ops/add16.js +2 -3
- package/dist/ops/appendCache.js +9 -8
- package/dist/ops/attentionMask.d.ts +1 -1
- package/dist/ops/attentionMask.js +8 -5
- package/dist/ops/concat16.js +5 -5
- package/dist/ops/cpu/adamAdjust.js +7 -8
- package/dist/ops/cpu/adamMoments.js +5 -5
- package/dist/ops/cpu/appendCache.js +3 -3
- package/dist/ops/cpu/attentionMask.js +12 -8
- package/dist/ops/cpu/fusedSoftmax.js +3 -3
- package/dist/ops/cpu/gatherSub.js +1 -12
- package/dist/ops/cpu/gelu.js +12 -13
- package/dist/ops/cpu/matMul16.js +7 -7
- package/dist/ops/cpu/matMulGelu.js +21 -18
- package/dist/ops/cpu/matMulMul.js +8 -9
- package/dist/ops/cpu/mulDropout.js +8 -9
- package/dist/ops/cpu/normRMS.js +12 -13
- package/dist/ops/cpu/qkv.js +14 -13
- package/dist/ops/cpu/rope.js +11 -8
- package/dist/ops/cpu/scatterSub.js +1 -12
- package/dist/ops/dot16.js +16 -17
- package/dist/ops/dropout.js +9 -8
- package/dist/ops/dropout16.js +1 -22
- package/dist/ops/gatherSub.js +3 -4
- package/dist/ops/gelu.js +1 -2
- package/dist/ops/globalNorm.js +10 -10
- package/dist/ops/grads/add16.js +16 -17
- package/dist/ops/grads/attentionMask.js +6 -7
- package/dist/ops/grads/dropout16.js +1 -1
- package/dist/ops/grads/gelu.js +1 -2
- package/dist/ops/grads/matMul16.js +1 -2
- package/dist/ops/grads/matMulGelu.js +6 -7
- package/dist/ops/grads/mul16.js +1 -1
- package/dist/ops/grads/normRMS.js +8 -9
- package/dist/ops/grads/pack16.js +1 -2
- package/dist/ops/grads/qkv.js +10 -10
- package/dist/ops/grads/rope.js +1 -2
- package/dist/ops/grads/silu.js +1 -2
- package/dist/ops/grads/softmax16.js +6 -7
- package/dist/ops/grads/unpack16.js +1 -2
- package/dist/ops/grads/utils.js +1 -2
- package/dist/ops/matMul16.d.ts +1 -1
- package/dist/ops/matMul16.js +1 -2
- package/dist/ops/matMulGelu.js +3 -4
- package/dist/ops/matMulMul.js +2 -3
- package/dist/ops/mul16.js +1 -43
- package/dist/ops/mulDrop.js +2 -3
- package/dist/ops/normRMS.js +2 -3
- package/dist/ops/pack16.js +1 -2
- package/dist/ops/qkv.js +2 -3
- package/dist/ops/reshape16.js +11 -11
- package/dist/ops/rope.js +1 -2
- package/dist/ops/scatterSub.js +3 -4
- package/dist/ops/silu.js +1 -2
- package/dist/ops/slice16.js +5 -5
- package/dist/ops/softmax16.js +3 -4
- package/dist/ops/sub16.js +3 -4
- package/dist/ops/sum16.js +3 -3
- package/dist/ops/transpose16.js +16 -15
- package/dist/ops/unpack16.js +1 -2
- package/dist/ops/webgl/adamAdjust.js +8 -9
- package/dist/ops/webgl/adamMoments.js +2 -3
- package/dist/ops/webgl/appendCache.js +2 -3
- package/dist/ops/webgl/attentionMask.js +2 -3
- package/dist/ops/webgl/dropout16.js +2 -3
- package/dist/ops/webgl/fusedSoftmax.js +13 -13
- package/dist/ops/webgl/gatherSub.js +2 -3
- package/dist/ops/webgl/gelu.js +11 -12
- package/dist/ops/webgl/log.js +10 -10
- package/dist/ops/webgl/matMul16.js +31 -24
- package/dist/ops/webgl/matMulGelu.js +1 -2
- package/dist/ops/webgl/matMulMul.js +3 -4
- package/dist/ops/webgl/mulDropout.js +2 -3
- package/dist/ops/webgl/normRMS.js +11 -10
- package/dist/ops/webgl/qkv.js +2 -3
- package/dist/ops/webgl/rope.js +4 -5
- package/dist/ops/webgl/scatterSub.js +2 -3
- package/dist/ops/webgpu/adamAdjust.js +13 -14
- package/dist/ops/webgpu/adamMoments.js +13 -14
- package/dist/ops/webgpu/add16.js +3 -4
- package/dist/ops/webgpu/appendCache.js +20 -21
- package/dist/ops/webgpu/attentionMask.js +18 -19
- package/dist/ops/webgpu/attentionMask32_program.js +7 -8
- package/dist/ops/webgpu/clipScale.js +11 -12
- package/dist/ops/webgpu/concat16.js +17 -18
- package/dist/ops/webgpu/dropout16.js +6 -7
- package/dist/ops/webgpu/gatherSub.js +11 -12
- package/dist/ops/webgpu/gelu.js +10 -11
- package/dist/ops/webgpu/index.js +17 -17
- package/dist/ops/webgpu/matMul16.js +74 -63
- package/dist/ops/webgpu/matMul16_program.d.ts +2 -1
- package/dist/ops/webgpu/matMul16_program.js +29 -21
- package/dist/ops/webgpu/mul16.js +3 -4
- package/dist/ops/webgpu/norm2.js +9 -10
- package/dist/ops/webgpu/normRMS.js +9 -10
- package/dist/ops/webgpu/normRMS16_program.js +1 -2
- package/dist/ops/webgpu/normRMS32_program.js +1 -2
- package/dist/ops/webgpu/normRMSGrad.js +30 -30
- package/dist/ops/webgpu/pack16.js +2 -3
- package/dist/ops/webgpu/pack16_program.js +3 -4
- package/dist/ops/webgpu/qkv.js +10 -11
- package/dist/ops/webgpu/rope.js +26 -27
- package/dist/ops/webgpu/scatterSub.js +12 -13
- package/dist/ops/webgpu/silu.js +10 -11
- package/dist/ops/webgpu/slice16.js +17 -18
- package/dist/ops/webgpu/softmax16.js +9 -9
- package/dist/ops/webgpu/softmax16_program.js +9 -10
- package/dist/ops/webgpu/softmax16_subgroup_program.js +11 -12
- package/dist/ops/webgpu/softmax16grad.js +8 -9
- package/dist/ops/webgpu/sub16.js +3 -4
- package/dist/ops/webgpu/sum16.js +16 -15
- package/dist/ops/webgpu/transpose16.js +13 -12
- package/dist/ops/webgpu/transpose16_program.js +3 -4
- package/dist/ops/webgpu/transpose16_shared_program.js +17 -18
- package/dist/ops/webgpu/unpack16.js +8 -9
- package/dist/ops/webgpu/utils/binary_op.js +20 -21
- package/dist/ops/webgpu/utils/deviceInfo.js +1 -2
- package/dist/ops/webgpu/utils/reductions.js +21 -20
- package/dist/ops-Be5ACU5R.js +13 -0
- package/dist/ops-C1UpdEYM.js +509 -0
- package/dist/{pack16-BhuXNUS7.js → pack16-BHO4t1-M.js} +14 -17
- package/dist/pad-Dy-1IP3A.js +13 -0
- package/dist/patches/webgpu_backend.js +18 -19
- package/dist/patches/webgpu_base.js +2 -3
- package/dist/patches/webgpu_program.js +21 -22
- package/dist/{pdf-Bzuk68Vy.js → pdf-CbnQ75VG.js} +380 -701
- package/dist/{picomatch-BO4HbNfo.js → picomatch--TW6gyBJ.js} +229 -291
- package/dist/qkv-BQfNPucX.js +42 -0
- package/dist/rand_util-_vCY93Uw.js +44 -0
- package/dist/random_normal-DUIT8kyC.js +11 -0
- package/dist/range-CYvQC3fW.js +13 -0
- package/dist/relu-C4XULT8A.js +8 -0
- package/dist/reshape-DJb1jgMt.js +8 -0
- package/dist/resize_nearest_neighbor-DAqcTYUe.js +188 -0
- package/dist/{chunk-CWhphoD1.js → rolldown-runtime-CwxnZyOB.js} +4 -5
- package/dist/{rope-BPu_uooz.js → rope-JjBVufF_.js} +6 -8
- package/dist/scatterSub-BOnqk-uY.js +27 -0
- package/dist/scatter_nd_util-BepMCpLY.js +34 -0
- package/dist/seedrandom-SHEGFK6H.js +282 -0
- package/dist/selu_util-DeOTf-sc.js +27 -0
- package/dist/shared-BIDMUBCs.js +1864 -0
- package/dist/{shared-CfTzpULd.js → shared-CX_iPI5K.js} +2 -3
- package/dist/silu-DsAE2cJ5.js +23 -0
- package/dist/slice-Dlb1FlzG.js +13 -0
- package/dist/{slice_util-Dve4TkDn.js → slice_util-BVgPRoij.js} +3 -4
- package/dist/softmax-Dpav_dWw.js +10 -0
- package/dist/split-DYnT8chz.js +11 -0
- package/dist/squeeze-B3XYGAlg.js +9 -0
- package/dist/stack-Dbbt9mIk.js +10 -0
- package/dist/step-DA-5DNu9.js +348 -0
- package/dist/{stream-BpAwcvHz.js → stream-BBe2apn4.js} +68 -88
- package/dist/sum-C8qNbFNp.js +13 -0
- package/dist/tensor-ALxWZfmz.js +7 -0
- package/dist/tensor1d-BHgkkhTE.js +9 -0
- package/dist/tensor2d-ARItvqVn.js +10 -0
- package/dist/tensor4d-D1zRBipJ.js +10 -0
- package/dist/tfjs_backend-CsXOum0h.js +685 -0
- package/dist/tile-DfyQ0KX-.js +10 -0
- package/dist/tokenise-DbS2Ea-T.js +14 -0
- package/dist/tokenise.js +6 -15
- package/dist/tokeniser/BaseTokeniser.js +5 -9
- package/dist/tokeniser/CharTokeniser.js +1 -2
- package/dist/tokeniser/bpe.js +19 -20
- package/dist/topk-BrU2pkrR.js +19 -0
- package/dist/training/AdamW.js +35 -31
- package/dist/training/BasicTrainer.js +56 -56
- package/dist/training/DatasetBuilder.js +1 -2
- package/dist/training/Evaluator.js +4 -4
- package/dist/training/LRScheduler.js +1 -2
- package/dist/training/PreTrainer.js +7 -8
- package/dist/training/SFTTrainer.js +7 -8
- package/dist/training/configure.js +16 -15
- package/dist/training/factory.js +1 -2
- package/dist/training/loss.js +1 -2
- package/dist/training/orthoGrad.js +2 -3
- package/dist/training/prepareData.js +18 -17
- package/dist/training/sparseCrossEntropy.js +38 -32
- package/dist/training/tasks/TokenStore.js +21 -22
- package/dist/training/tasks/tokenStream.js +1 -2
- package/dist/training/validateOptions.js +1 -2
- package/dist/training/validation.js +1 -2
- package/dist/transpose-BC-M_OoT.js +34 -0
- package/dist/unsorted_segment_sum-BelC7R-q.js +408 -0
- package/dist/utilities/arrayClose.js +5 -4
- package/dist/utilities/arrayShape.js +1 -2
- package/dist/utilities/datasetID.js +1 -2
- package/dist/utilities/dummy.js +15 -15
- package/dist/utilities/float16.js +10 -10
- package/dist/utilities/maxHeap.js +1 -2
- package/dist/utilities/multinomialCPU.d.ts +1 -2
- package/dist/utilities/multinomialCPU.js +6 -8
- package/dist/utilities/packed.js +2 -3
- package/dist/utilities/parameters.js +3 -4
- package/dist/utilities/performance.js +2 -3
- package/dist/utilities/profile.js +3 -4
- package/dist/utilities/random.js +1 -2
- package/dist/utilities/safetensors.js +14 -14
- package/dist/utilities/sentences.js +16 -13
- package/dist/utilities/tokenParse.js +1 -2
- package/dist/utilities/tokens.js +5 -6
- package/dist/utilities/topP.d.ts +1 -0
- package/dist/utilities/topP.js +20 -13
- package/dist/utilities/waitForModel.js +1 -2
- package/dist/utilities/weights.js +4 -4
- package/dist/utilities/yielder.js +1 -2
- package/dist/{v4-BK7K-jy_.js → v4-YCkfo8OR.js} +4 -7
- package/dist/{webgpu-IAn9VotJ.js → webgpu-BHX-uBym.js} +156 -163
- package/dist/{webgpu_program-B0PokuRJ.js → webgpu_program-DvkFqRlR.js} +28 -29
- package/dist/{webgpu_util-DfODg6XI.js → webgpu_util-5QTyovaf.js} +2 -3
- package/dist/zeros-hxKGkRfl.js +12 -0
- package/package.json +3 -3
- package/dist/Reshape-CwxdaU8n.js +0 -17
- package/dist/dist-Da20xy8E.js +0 -6375
- package/dist/gelu-B6637MKa.js +0 -27
- package/dist/selu_util-B_AFEfoz.js +0 -24
- package/dist/shared-24EoeHJl.js +0 -1314
- package/dist/silu-B6bvCgJ7.js +0 -25
- package/dist/tfjs_backend-h5weiy1O.js +0 -614
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as u } from "./backend_util-
|
|
3
|
-
|
|
1
|
+
import { Gi as e, Hi as t, Ji as n, Ti as r, Yi as i, _i as a, qi as o, vi as s, w as c, yi as l } from "./dist-CMMLi-qO.js";
|
|
2
|
+
import { t as u } from "./backend_util-Cpp0Gwlp.js";
|
|
3
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/glsl_version.js
|
|
4
4
|
function d() {
|
|
5
|
-
let e, n, r, i,
|
|
6
|
-
return
|
|
5
|
+
let e, t, n, r, i, o, s, c, l, u;
|
|
6
|
+
return a().getNumber("WEBGL_VERSION") === 2 ? (e = "#version 300 es", t = "in", n = "out", r = "in", i = "texture", o = "outputColor", s = "out vec4 outputColor;", c = a().getBool("WEBGL2_ISNAN_CUSTOM") ? "\n bool isnan_custom(float val) {\n uint floatToUint = floatBitsToUint(val);\n return (floatToUint & 0x7fffffffu) > 0x7f800000u;\n }\n\n bvec4 isnan_custom(vec4 val) {\n return bvec4(isnan_custom(val.x),\n isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));\n }\n\n #define isnan(value) isnan_custom(value)\n " : "", l = "", u = "\n #define round(value) newRound(value)\n int newRound(float value) {\n return int(floor(value + 0.5));\n }\n\n ivec4 newRound(vec4 value) {\n return ivec4(floor(value + vec4(0.5)));\n }\n ") : (e = "", t = "attribute", n = "varying", r = "varying", i = "texture2D", o = "gl_FragColor", s = "", c = "\n #define isnan(value) isnan_custom(value)\n bool isnan_custom(float val) {\n return (val > 0. || val < 1. || val == 0.) ? false : true;\n }\n bvec4 isnan_custom(vec4 val) {\n return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));\n }\n ", l = "\n uniform float INFINITY;\n\n bool isinf(float val) {\n return abs(val) == INFINITY;\n }\n bvec4 isinf(vec4 val) {\n return equal(abs(val), vec4(INFINITY));\n }\n ", u = "\n int round(float value) {\n return int(floor(value + 0.5));\n }\n\n ivec4 round(vec4 value) {\n return ivec4(floor(value + vec4(0.5)));\n }\n "), {
|
|
7
7
|
version: e,
|
|
8
|
-
attribute:
|
|
9
|
-
varyingVs:
|
|
10
|
-
varyingFs:
|
|
11
|
-
texture2D:
|
|
8
|
+
attribute: t,
|
|
9
|
+
varyingVs: n,
|
|
10
|
+
varyingFs: r,
|
|
11
|
+
texture2D: i,
|
|
12
12
|
output: o,
|
|
13
13
|
defineOutput: s,
|
|
14
14
|
defineSpecialNaN: c,
|
|
@@ -16,15 +16,14 @@ function d() {
|
|
|
16
16
|
defineRound: u
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
//#region node_modules/@tensorflow/tfjs-backend-webgl/dist/shader_compiler_util.js
|
|
19
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/shader_compiler_util.js
|
|
21
20
|
function f(e, t, n = "index") {
|
|
22
|
-
let
|
|
23
|
-
return
|
|
21
|
+
let i = r(t);
|
|
22
|
+
return i.map((t, r) => `${`int ${e[r]} = ${n} / ${t}`}; ${r === i.length - 1 ? `int ${e[r + 1]} = ${n} - ${e[r]} * ${t}` : `index -= ${e[r]} * ${t}`};`).join("");
|
|
24
23
|
}
|
|
25
24
|
function p(e, t, n = "index") {
|
|
26
|
-
let
|
|
27
|
-
return
|
|
25
|
+
let i = r(t);
|
|
26
|
+
return i.map((t, r) => `${`int ${e[r]} = ${n} / outShapeStrides[${r}]`}; ${r === i.length - 1 ? `int ${e[r + 1]} = ${n} - ${e[r]} * outShapeStrides[${r}]` : `index -= ${e[r]} * outShapeStrides[${r}]`};`).join("");
|
|
28
27
|
}
|
|
29
28
|
function m(e, t) {
|
|
30
29
|
let n = e.length, r = e.map((e) => `${t}[${e}]`), i = Array(n - 1);
|
|
@@ -37,7 +36,7 @@ function h(e, t, n = "index") {
|
|
|
37
36
|
return r.map((t, i) => `${`int ${e[i]} = ${n} / ${r[i]}`}; ${i === r.length - 1 ? `int ${e[i + 1]} = ${n} - ${e[i]} * ${r[i]}` : `index -= ${e[i]} * ${r[i]}`};`).join("");
|
|
38
37
|
}
|
|
39
38
|
function g(e) {
|
|
40
|
-
let t =
|
|
39
|
+
let t = r(e).map((e) => e.toString());
|
|
41
40
|
return `
|
|
42
41
|
int getFlatIndex(ivec3 coords) {
|
|
43
42
|
return coords.x * ${t[0]} + coords.y * ${t[1]} + coords.z;
|
|
@@ -51,7 +50,7 @@ var v = "\n const float FLOAT_MAX = 1.70141184e38;\n const float FLOAT_MIN = 1
|
|
|
51
50
|
function b(e, t, n) {
|
|
52
51
|
let r = [];
|
|
53
52
|
if (e.forEach((e) => {
|
|
54
|
-
let t =
|
|
53
|
+
let t = o(e.shapeInfo.logicalShape);
|
|
55
54
|
if (e.shapeInfo.isUniform ? r.push(`uniform float ${e.name}${t > 1 ? `[${t}]` : ""};`) : (r.push(`uniform sampler2D ${e.name};`), r.push(`uniform int offset${e.name};`)), n.enableShapeUniforms) {
|
|
56
55
|
let { uniformShape: t } = A(n.packedInputs, e.shapeInfo.logicalShape, e.shapeInfo.texShape);
|
|
57
56
|
switch (t.length) {
|
|
@@ -64,10 +63,7 @@ function b(e, t, n) {
|
|
|
64
63
|
case 3:
|
|
65
64
|
r.push(`uniform ivec3 ${e.name}Shape;`);
|
|
66
65
|
break;
|
|
67
|
-
case 4:
|
|
68
|
-
r.push(`uniform ivec4 ${e.name}Shape;`);
|
|
69
|
-
break;
|
|
70
|
-
default: break;
|
|
66
|
+
case 4: r.push(`uniform ivec4 ${e.name}Shape;`);
|
|
71
67
|
}
|
|
72
68
|
r.push(`uniform ivec2 ${e.name}TexShape;`);
|
|
73
69
|
}
|
|
@@ -82,18 +78,15 @@ function b(e, t, n) {
|
|
|
82
78
|
case 3:
|
|
83
79
|
r.push("uniform ivec3 outShape;"), r.push("uniform ivec2 outShapeStrides;");
|
|
84
80
|
break;
|
|
85
|
-
case 4:
|
|
86
|
-
r.push("uniform ivec4 outShape;"), r.push("uniform ivec3 outShapeStrides;");
|
|
87
|
-
break;
|
|
88
|
-
default: break;
|
|
81
|
+
case 4: r.push("uniform ivec4 outShape;"), r.push("uniform ivec3 outShapeStrides;");
|
|
89
82
|
}
|
|
90
83
|
r.push("uniform ivec2 outTexShape;");
|
|
91
84
|
}
|
|
92
85
|
n.customUniforms && n.customUniforms.forEach((e) => {
|
|
93
86
|
r.push(`uniform ${e.type} ${e.name}${e.arrayIndex ? `[${e.arrayIndex}]` : ""};`);
|
|
94
87
|
});
|
|
95
|
-
let i = r.join("\n"), a = e.map((e) => ee(e, t, n.packedInputs, n.enableShapeUniforms)).join("\n"),
|
|
96
|
-
return t.isPacked ? (u = te(t.logicalShape,
|
|
88
|
+
let i = r.join("\n"), a = e.map((e) => ee(e, t, n.packedInputs, n.enableShapeUniforms)).join("\n"), s = t.texShape, c = d(), l = re(c), u, f, p = oe(c);
|
|
89
|
+
return t.isPacked ? (u = te(t.logicalShape, s, n.enableShapeUniforms), f = ae(c)) : (u = ne(t.logicalShape, s, n.enableShapeUniforms), f = ie(c)), n.packedInputs && (p += ue), [
|
|
97
90
|
p,
|
|
98
91
|
l,
|
|
99
92
|
f,
|
|
@@ -127,9 +120,9 @@ function S(e, t) {
|
|
|
127
120
|
}
|
|
128
121
|
function ee(e, t, n = !1, r) {
|
|
129
122
|
let i = "";
|
|
130
|
-
n ?
|
|
123
|
+
i += n ? S(e, r) : x(e, r);
|
|
131
124
|
let a = e.shapeInfo.logicalShape, o = t.logicalShape;
|
|
132
|
-
return a.length <= o.length && (n ?
|
|
125
|
+
return a.length <= o.length && (i += n ? Ae(e, t) : je(e, t)), i;
|
|
133
126
|
}
|
|
134
127
|
function te(e, t, n) {
|
|
135
128
|
switch (e.length) {
|
|
@@ -421,47 +414,47 @@ function ve(e, t) {
|
|
|
421
414
|
}
|
|
422
415
|
`;
|
|
423
416
|
}
|
|
424
|
-
function ye(e, t,
|
|
425
|
-
let
|
|
426
|
-
if (
|
|
417
|
+
function ye(e, t, n) {
|
|
418
|
+
let r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
|
|
419
|
+
if (s(e, t)) return n ? "\n ivec2 getOutputCoords() {\n ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));\n return 2 * ivec2(resultUV.yx * vec2(packedTexShape[0], packedTexShape[1]));\n }\n " : `
|
|
427
420
|
ivec2 getOutputCoords() {
|
|
428
|
-
return 2 * ivec2(resultUV.yx * vec2(${
|
|
421
|
+
return 2 * ivec2(resultUV.yx * vec2(${r[0]}, ${r[1]}));
|
|
429
422
|
}
|
|
430
423
|
`;
|
|
431
|
-
let
|
|
432
|
-
return
|
|
424
|
+
let i = Math.ceil(e[1] / 2);
|
|
425
|
+
return n ? "\n ivec2 getOutputCoords() {\n ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));\n int texelsInLogicalRow = int(ceil(float(outShape[1]) / 2.0));\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(packedTexShape[0], packedTexShape[1]));\n\n int index = resTexRC.x * packedTexShape[1] + resTexRC.y;\n int r = 2 * (index / texelsInLogicalRow);\n int c = imod(index, texelsInLogicalRow) * 2;\n\n return ivec2(r, c);\n }\n " : `
|
|
433
426
|
ivec2 getOutputCoords() {
|
|
434
427
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
435
|
-
vec2(${
|
|
428
|
+
vec2(${r[0]}, ${r[1]}));
|
|
436
429
|
|
|
437
|
-
int index = resTexRC.x * ${
|
|
438
|
-
int r = 2 * (index / ${
|
|
439
|
-
int c = imod(index, ${
|
|
430
|
+
int index = resTexRC.x * ${r[1]} + resTexRC.y;
|
|
431
|
+
int r = 2 * (index / ${i});
|
|
432
|
+
int c = imod(index, ${i}) * 2;
|
|
440
433
|
|
|
441
434
|
return ivec2(r, c);
|
|
442
435
|
}
|
|
443
436
|
`;
|
|
444
437
|
}
|
|
445
|
-
function be(e, t,
|
|
446
|
-
return
|
|
438
|
+
function be(e, t, n) {
|
|
439
|
+
return s(e, t) ? n ? "\n ivec2 getOutputCoords() {\n return ivec2(resultUV.yx * vec2(outTexShape[0], outTexShape[1]));\n }\n " : `
|
|
447
440
|
ivec2 getOutputCoords() {
|
|
448
441
|
return ivec2(resultUV.yx * vec2(${t[0]}, ${t[1]}));
|
|
449
442
|
}
|
|
450
|
-
` : e[1] === 1 ?
|
|
443
|
+
` : e[1] === 1 ? n ? "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(outTexShape[0], outTexShape[1]));\n int index = resTexRC.x * outTexShape[1] + resTexRC.y;\n return ivec2(index, 0);\n }\n " : `
|
|
451
444
|
ivec2 getOutputCoords() {
|
|
452
445
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
453
446
|
vec2(${t[0]}, ${t[1]}));
|
|
454
447
|
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
455
448
|
return ivec2(index, 0);
|
|
456
449
|
}
|
|
457
|
-
` : e[0] === 1 ?
|
|
450
|
+
` : e[0] === 1 ? n ? "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(outTexShape[0], outTexShape[1]));\n int index = resTexRC.x * outTexShape[1] + resTexRC.y;\n return ivec2(0, index);\n }\n " : `
|
|
458
451
|
ivec2 getOutputCoords() {
|
|
459
452
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
460
453
|
vec2(${t[0]}, ${t[1]}));
|
|
461
454
|
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
462
455
|
return ivec2(0, index);
|
|
463
456
|
}
|
|
464
|
-
` :
|
|
457
|
+
` : n ? "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(outTexShape[0], outTexShape[1]));\n int index = resTexRC.x * outTexShape[1] + resTexRC.y;\n int r = index / outShape[1];\n int c = index - r * outShape[1];\n return ivec2(r, c);\n }\n " : `
|
|
465
458
|
ivec2 getOutputCoords() {
|
|
466
459
|
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
467
460
|
vec2(${t[0]}, ${t[1]}));
|
|
@@ -573,104 +566,104 @@ function we(e, t) {
|
|
|
573
566
|
`;
|
|
574
567
|
}
|
|
575
568
|
function Te(e, t) {
|
|
576
|
-
let
|
|
577
|
-
if (
|
|
578
|
-
vec4 ${
|
|
579
|
-
vec2 uv = (vec2(col, row) + halfCR) / vec2(${
|
|
569
|
+
let n = e.shapeInfo.logicalShape, r = e.name, i = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = e.shapeInfo.texShape, o = a[0], c = a[1], l = d();
|
|
570
|
+
if (a != null && s(n, a)) return t ? `
|
|
571
|
+
vec4 ${i}(int row, int col) {
|
|
572
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
580
573
|
|
|
581
|
-
return ${l.texture2D}(${
|
|
574
|
+
return ${l.texture2D}(${r}, uv);
|
|
582
575
|
}
|
|
583
576
|
` : `
|
|
584
|
-
vec4 ${
|
|
585
|
-
vec2 uv = (vec2(col, row) + halfCR) / vec2(${c}.0, ${
|
|
577
|
+
vec4 ${i}(int row, int col) {
|
|
578
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${c}.0, ${o}.0);
|
|
586
579
|
|
|
587
|
-
return ${l.texture2D}(${
|
|
580
|
+
return ${l.texture2D}(${r}, uv);
|
|
588
581
|
}
|
|
589
582
|
`;
|
|
590
583
|
if (t) return `
|
|
591
|
-
vec4 ${
|
|
592
|
-
ivec2 packedTexShape = ivec2(ceil(float(${
|
|
593
|
-
int valuesPerRow = int(ceil(float(${
|
|
584
|
+
vec4 ${i}(int row, int col) {
|
|
585
|
+
ivec2 packedTexShape = ivec2(ceil(float(${r}TexShape[0]) / 2.0), ceil(float(${r}TexShape[1]) / 2.0));
|
|
586
|
+
int valuesPerRow = int(ceil(float(${r}Shape[1]) / 2.0));
|
|
594
587
|
vec2 uv = packedUVfrom2D(valuesPerRow, packedTexShape[0], packedTexShape[1], row, col);
|
|
595
|
-
return ${l.texture2D}(${
|
|
588
|
+
return ${l.texture2D}(${r}, uv);
|
|
596
589
|
}
|
|
597
590
|
`;
|
|
598
|
-
let u = [Math.ceil(
|
|
591
|
+
let u = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)];
|
|
599
592
|
return `
|
|
600
|
-
vec4 ${
|
|
601
|
-
vec2 uv = packedUVfrom2D(${Math.ceil(
|
|
602
|
-
return ${l.texture2D}(${
|
|
593
|
+
vec4 ${i}(int row, int col) {
|
|
594
|
+
vec2 uv = packedUVfrom2D(${Math.ceil(n[1] / 2)}, ${u[0]}, ${u[1]}, row, col);
|
|
595
|
+
return ${l.texture2D}(${r}, uv);
|
|
603
596
|
}
|
|
604
597
|
`;
|
|
605
598
|
}
|
|
606
599
|
function Ee(e, t) {
|
|
607
|
-
let
|
|
608
|
-
if (
|
|
600
|
+
let n = e.shapeInfo.logicalShape, r = e.name, a = "get" + r.charAt(0).toUpperCase() + r.slice(1), o = e.shapeInfo.texShape;
|
|
601
|
+
if (o != null && s(n, o)) {
|
|
609
602
|
if (t) return `
|
|
610
|
-
float ${
|
|
611
|
-
vec2 uv = (vec2(col, row) + halfCR) / vec2(${
|
|
612
|
-
return sampleTexture(${
|
|
603
|
+
float ${a}(int row, int col) {
|
|
604
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
605
|
+
return sampleTexture(${r}, uv);
|
|
613
606
|
}
|
|
614
607
|
`;
|
|
615
|
-
let e =
|
|
608
|
+
let e = o[0];
|
|
616
609
|
return `
|
|
617
|
-
float ${
|
|
618
|
-
vec2 uv = (vec2(col, row) + halfCR) / vec2(${
|
|
619
|
-
return sampleTexture(${
|
|
610
|
+
float ${a}(int row, int col) {
|
|
611
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${o[1]}.0, ${e}.0);
|
|
612
|
+
return sampleTexture(${r}, uv);
|
|
620
613
|
}
|
|
621
614
|
`;
|
|
622
615
|
}
|
|
623
|
-
let { newShape: c, keptDims: l } =
|
|
624
|
-
if (u.length <
|
|
616
|
+
let { newShape: c, keptDims: l } = i(n), u = c;
|
|
617
|
+
if (u.length < n.length) return `
|
|
625
618
|
${x(j(e, u), t)}
|
|
626
|
-
float ${
|
|
627
|
-
return ${
|
|
619
|
+
float ${a}(int row, int col) {
|
|
620
|
+
return ${a}(${M(["row", "col"], l)});
|
|
628
621
|
}
|
|
629
622
|
`;
|
|
630
623
|
if (e.shapeInfo.isUniform) return `
|
|
631
|
-
float ${
|
|
632
|
-
int index = round(dot(vec2(row, col), vec2(${
|
|
624
|
+
float ${a}(int row, int col) {
|
|
625
|
+
int index = round(dot(vec2(row, col), vec2(${n[1]}, 1)));
|
|
633
626
|
${O(e)}
|
|
634
627
|
}
|
|
635
628
|
`;
|
|
636
|
-
let d =
|
|
629
|
+
let d = o[0], f = o[1], p = w(r);
|
|
637
630
|
return f === 1 ? t ? `
|
|
638
|
-
float ${
|
|
639
|
-
float index = dot(vec3(row, col, ${p}), vec3(${
|
|
640
|
-
vec2 uv = vec2(0.5, (index + 0.5) / float(${
|
|
641
|
-
return sampleTexture(${
|
|
631
|
+
float ${a}(int row, int col) {
|
|
632
|
+
float index = dot(vec3(row, col, ${p}), vec3(${r}Shape[1], 1, 1));
|
|
633
|
+
vec2 uv = vec2(0.5, (index + 0.5) / float(${r}TexShape[0]));
|
|
634
|
+
return sampleTexture(${r}, uv);
|
|
642
635
|
}
|
|
643
636
|
` : `
|
|
644
|
-
float ${
|
|
645
|
-
float index = dot(vec3(row, col, ${p}), vec3(${
|
|
637
|
+
float ${a}(int row, int col) {
|
|
638
|
+
float index = dot(vec3(row, col, ${p}), vec3(${n[1]}, 1, 1));
|
|
646
639
|
vec2 uv = vec2(0.5, (index + 0.5) / ${d}.0);
|
|
647
|
-
return sampleTexture(${
|
|
640
|
+
return sampleTexture(${r}, uv);
|
|
648
641
|
}
|
|
649
642
|
` : d === 1 ? t ? `
|
|
650
|
-
float ${
|
|
651
|
-
float index = dot(vec3(row, col, ${p}), vec3(${
|
|
652
|
-
vec2 uv = vec2((index + 0.5) / float(${
|
|
653
|
-
return sampleTexture(${
|
|
643
|
+
float ${a}(int row, int col) {
|
|
644
|
+
float index = dot(vec3(row, col, ${p}), vec3(${r}Shape[1], 1, 1));
|
|
645
|
+
vec2 uv = vec2((index + 0.5) / float(${r}TexShape[1]), 0.5);
|
|
646
|
+
return sampleTexture(${r}, uv);
|
|
654
647
|
}
|
|
655
648
|
` : `
|
|
656
|
-
float ${
|
|
657
|
-
float index = dot(vec3(row, col, ${p}), vec3(${
|
|
649
|
+
float ${a}(int row, int col) {
|
|
650
|
+
float index = dot(vec3(row, col, ${p}), vec3(${n[1]}, 1, 1));
|
|
658
651
|
vec2 uv = vec2((index + 0.5) / ${f}.0, 0.5);
|
|
659
|
-
return sampleTexture(${
|
|
652
|
+
return sampleTexture(${r}, uv);
|
|
660
653
|
}
|
|
661
654
|
` : t ? `
|
|
662
|
-
float ${
|
|
655
|
+
float ${a}(int row, int col) {
|
|
663
656
|
// Explicitly use integer operations as dot() only works on floats.
|
|
664
|
-
int index = row * ${
|
|
665
|
-
vec2 uv = uvFromFlat(${
|
|
666
|
-
return sampleTexture(${
|
|
657
|
+
int index = row * ${r}Shape[1] + col + ${p};
|
|
658
|
+
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index);
|
|
659
|
+
return sampleTexture(${r}, uv);
|
|
667
660
|
}
|
|
668
661
|
` : `
|
|
669
|
-
float ${
|
|
662
|
+
float ${a}(int row, int col) {
|
|
670
663
|
// Explicitly use integer operations as dot() only works on floats.
|
|
671
|
-
int index = row * ${
|
|
664
|
+
int index = row * ${n[1]} + col + ${p};
|
|
672
665
|
vec2 uv = uvFromFlat(${d}, ${f}, index);
|
|
673
|
-
return sampleTexture(${
|
|
666
|
+
return sampleTexture(${r}, uv);
|
|
674
667
|
}
|
|
675
668
|
`;
|
|
676
669
|
}
|
|
@@ -707,11 +700,11 @@ function T(e, t) {
|
|
|
707
700
|
`;
|
|
708
701
|
}
|
|
709
702
|
function E(e, t) {
|
|
710
|
-
let n = e.shapeInfo.logicalShape, r = e.name,
|
|
703
|
+
let n = e.shapeInfo.logicalShape, r = e.name, a = "get" + r.charAt(0).toUpperCase() + r.slice(1), o = n[1] * n[2], s = n[2], { newShape: c, keptDims: l } = i(n), u = c;
|
|
711
704
|
if (u.length < n.length) return `
|
|
712
705
|
${x(j(e, u), t)}
|
|
713
|
-
float ${
|
|
714
|
-
return ${
|
|
706
|
+
float ${a}(int row, int col, int depth) {
|
|
707
|
+
return ${a}(${M([
|
|
715
708
|
"row",
|
|
716
709
|
"col",
|
|
717
710
|
"depth"
|
|
@@ -719,7 +712,7 @@ function E(e, t) {
|
|
|
719
712
|
}
|
|
720
713
|
`;
|
|
721
714
|
if (e.shapeInfo.isUniform) return `
|
|
722
|
-
float ${
|
|
715
|
+
float ${a}(int row, int col, int depth) {
|
|
723
716
|
int index = round(dot(vec3(row, col, depth),
|
|
724
717
|
vec3(${o}, ${s}, 1)));
|
|
725
718
|
${O(e)}
|
|
@@ -727,7 +720,7 @@ function E(e, t) {
|
|
|
727
720
|
`;
|
|
728
721
|
let d = e.shapeInfo.texShape, f = d[0], p = d[1], m = e.shapeInfo.flatOffset;
|
|
729
722
|
if (p === o && m == null) return t ? `
|
|
730
|
-
float ${
|
|
723
|
+
float ${a}(int row, int col, int depth) {
|
|
731
724
|
int stride1 = ${r}Shape[2];
|
|
732
725
|
float texR = float(row);
|
|
733
726
|
float texC = dot(vec2(col, depth), vec2(stride1, 1));
|
|
@@ -736,7 +729,7 @@ function E(e, t) {
|
|
|
736
729
|
return sampleTexture(${r}, uv);
|
|
737
730
|
}
|
|
738
731
|
` : `
|
|
739
|
-
float ${
|
|
732
|
+
float ${a}(int row, int col, int depth) {
|
|
740
733
|
float texR = float(row);
|
|
741
734
|
float texC = dot(vec2(col, depth), vec2(${s}, 1));
|
|
742
735
|
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
@@ -745,14 +738,14 @@ function E(e, t) {
|
|
|
745
738
|
}
|
|
746
739
|
`;
|
|
747
740
|
if (p === s && m == null) return t ? `
|
|
748
|
-
float ${
|
|
741
|
+
float ${a}(int row, int col, int depth) {
|
|
749
742
|
float texR = dot(vec2(row, col), vec2(${r}Shape[1], 1));
|
|
750
743
|
float texC = float(depth);
|
|
751
744
|
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
752
745
|
return sampleTexture(${r}, uv);
|
|
753
746
|
}
|
|
754
747
|
` : `
|
|
755
|
-
float ${
|
|
748
|
+
float ${a}(int row, int col, int depth) {
|
|
756
749
|
float texR = dot(vec2(row, col), vec2(${n[1]}, 1));
|
|
757
750
|
float texC = float(depth);
|
|
758
751
|
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${p}.0, ${f}.0);
|
|
@@ -761,7 +754,7 @@ function E(e, t) {
|
|
|
761
754
|
`;
|
|
762
755
|
let h = w(r);
|
|
763
756
|
return t ? `
|
|
764
|
-
float ${
|
|
757
|
+
float ${a}(int row, int col, int depth) {
|
|
765
758
|
// Explicitly use integer operations as dot() only works on floats.
|
|
766
759
|
int stride0 = ${r}Shape[1] * ${r}Shape[2];
|
|
767
760
|
int stride1 = ${r}Shape[2];
|
|
@@ -770,7 +763,7 @@ function E(e, t) {
|
|
|
770
763
|
return sampleTexture(${r}, uv);
|
|
771
764
|
}
|
|
772
765
|
` : `
|
|
773
|
-
float ${
|
|
766
|
+
float ${a}(int row, int col, int depth) {
|
|
774
767
|
// Explicitly use integer operations as dot() only works on floats.
|
|
775
768
|
int index = row * ${o} + col * ${s} + depth + ${h};
|
|
776
769
|
vec2 uv = uvFromFlat(${f}, ${p}, index);
|
|
@@ -806,11 +799,11 @@ function D(e, t) {
|
|
|
806
799
|
`;
|
|
807
800
|
}
|
|
808
801
|
function De(e, t) {
|
|
809
|
-
let n = e.shapeInfo.logicalShape, r = e.name,
|
|
802
|
+
let n = e.shapeInfo.logicalShape, r = e.name, a = "get" + r.charAt(0).toUpperCase() + r.slice(1), o = n[3], s = n[2] * o, c = n[1] * s, { newShape: l, keptDims: u } = i(n);
|
|
810
803
|
if (l.length < n.length) return `
|
|
811
804
|
${x(j(e, l), t)}
|
|
812
|
-
float ${
|
|
813
|
-
return ${
|
|
805
|
+
float ${a}(int row, int col, int depth, int depth2) {
|
|
806
|
+
return ${a}(${M([
|
|
814
807
|
"row",
|
|
815
808
|
"col",
|
|
816
809
|
"depth",
|
|
@@ -819,7 +812,7 @@ function De(e, t) {
|
|
|
819
812
|
}
|
|
820
813
|
`;
|
|
821
814
|
if (e.shapeInfo.isUniform) return `
|
|
822
|
-
float ${
|
|
815
|
+
float ${a}(int row, int col, int depth, int depth2) {
|
|
823
816
|
int index = round(dot(vec4(row, col, depth, depth2),
|
|
824
817
|
vec4(${c}, ${s}, ${o}, 1)));
|
|
825
818
|
${O(e)}
|
|
@@ -827,7 +820,7 @@ function De(e, t) {
|
|
|
827
820
|
`;
|
|
828
821
|
let d = e.shapeInfo.flatOffset, f = e.shapeInfo.texShape, p = f[0], m = f[1], h = `int stride2 = ${r}Shape[3];`, g = `int stride1 = ${r}Shape[2] * stride2;`, _ = `int stride0 = ${r}Shape[1] * stride1;`;
|
|
829
822
|
if (m === c && d == null) return t ? `
|
|
830
|
-
float ${
|
|
823
|
+
float ${a}(int row, int col, int depth, int depth2) {
|
|
831
824
|
${h}
|
|
832
825
|
${g}
|
|
833
826
|
float texR = float(row);
|
|
@@ -839,7 +832,7 @@ function De(e, t) {
|
|
|
839
832
|
return sampleTexture(${r}, uv);
|
|
840
833
|
}
|
|
841
834
|
` : `
|
|
842
|
-
float ${
|
|
835
|
+
float ${a}(int row, int col, int depth, int depth2) {
|
|
843
836
|
float texR = float(row);
|
|
844
837
|
float texC =
|
|
845
838
|
dot(vec3(col, depth, depth2),
|
|
@@ -850,7 +843,7 @@ function De(e, t) {
|
|
|
850
843
|
}
|
|
851
844
|
`;
|
|
852
845
|
if (m === o && d == null) return t ? `
|
|
853
|
-
float ${
|
|
846
|
+
float ${a}(int row, int col, int depth, int depth2) {
|
|
854
847
|
float texR = dot(vec3(row, col, depth),
|
|
855
848
|
vec3(${r}Shape[1] * ${r}Shape[2], ${r}Shape[2], 1));
|
|
856
849
|
float texC = float(depth2);
|
|
@@ -859,7 +852,7 @@ function De(e, t) {
|
|
|
859
852
|
return sampleTexture(${r}, uv);
|
|
860
853
|
}
|
|
861
854
|
` : `
|
|
862
|
-
float ${
|
|
855
|
+
float ${a}(int row, int col, int depth, int depth2) {
|
|
863
856
|
float texR = dot(vec3(row, col, depth),
|
|
864
857
|
vec3(${n[1] * n[2]}, ${n[2]}, 1));
|
|
865
858
|
float texC = float(depth2);
|
|
@@ -870,7 +863,7 @@ function De(e, t) {
|
|
|
870
863
|
`;
|
|
871
864
|
let v = w(r);
|
|
872
865
|
return t ? `
|
|
873
|
-
float ${
|
|
866
|
+
float ${a}(int row, int col, int depth, int depth2) {
|
|
874
867
|
// Explicitly use integer operations as dot() only works on floats.
|
|
875
868
|
${h}
|
|
876
869
|
${g}
|
|
@@ -881,7 +874,7 @@ function De(e, t) {
|
|
|
881
874
|
return sampleTexture(${r}, uv);
|
|
882
875
|
}
|
|
883
876
|
` : `
|
|
884
|
-
float ${
|
|
877
|
+
float ${a}(int row, int col, int depth, int depth2) {
|
|
885
878
|
// Explicitly use integer operations as dot() only works on floats.
|
|
886
879
|
int index = row * ${c} + col * ${s} +
|
|
887
880
|
depth * ${o} + depth2;
|
|
@@ -891,7 +884,7 @@ function De(e, t) {
|
|
|
891
884
|
`;
|
|
892
885
|
}
|
|
893
886
|
function Oe(e) {
|
|
894
|
-
let t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1),
|
|
887
|
+
let t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), a = t[4], o = t[3] * a, s = t[2] * o, c = t[1] * s, { newShape: l, keptDims: u } = i(t);
|
|
895
888
|
if (l.length < t.length) return `
|
|
896
889
|
${x(j(e, l))}
|
|
897
890
|
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
@@ -908,7 +901,7 @@ function Oe(e) {
|
|
|
908
901
|
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
909
902
|
float index = dot(
|
|
910
903
|
vec4(row, col, depth, depth2),
|
|
911
|
-
vec4(${c}, ${s}, ${o}, ${
|
|
904
|
+
vec4(${c}, ${s}, ${o}, ${a})) +
|
|
912
905
|
depth3;
|
|
913
906
|
${O(e)}
|
|
914
907
|
}
|
|
@@ -918,12 +911,12 @@ function Oe(e) {
|
|
|
918
911
|
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
919
912
|
int texR = row;
|
|
920
913
|
float texC = dot(vec4(col, depth, depth2, depth3),
|
|
921
|
-
vec4(${s}, ${o}, ${
|
|
914
|
+
vec4(${s}, ${o}, ${a}, 1));
|
|
922
915
|
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
923
916
|
vec2(${m}.0, ${p}.0);
|
|
924
917
|
return sampleTexture(${n}, uv);
|
|
925
918
|
}
|
|
926
|
-
` : m ===
|
|
919
|
+
` : m === a && d == null ? `
|
|
927
920
|
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
928
921
|
float texR = dot(
|
|
929
922
|
vec4(row, col, depth, depth2),
|
|
@@ -938,16 +931,16 @@ function Oe(e) {
|
|
|
938
931
|
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
939
932
|
// Explicitly use integer operations as dot() only works on floats.
|
|
940
933
|
int index = row * ${c} + col * ${s} + depth * ${o} +
|
|
941
|
-
depth2 * ${
|
|
934
|
+
depth2 * ${a} + depth3 + ${w(n)};
|
|
942
935
|
vec2 uv = uvFromFlat(${p}, ${m}, index);
|
|
943
936
|
return sampleTexture(${n}, uv);
|
|
944
937
|
}
|
|
945
938
|
`;
|
|
946
939
|
}
|
|
947
940
|
function ke(e) {
|
|
948
|
-
let t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), { newShape:
|
|
949
|
-
if (
|
|
950
|
-
${x(j(e,
|
|
941
|
+
let t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), { newShape: a, keptDims: o } = i(t);
|
|
942
|
+
if (a.length < t.length) return `
|
|
943
|
+
${x(j(e, a))}
|
|
951
944
|
float ${r}(int row, int col, int depth,
|
|
952
945
|
int depth2, int depth3, int depth4) {
|
|
953
946
|
return ${r}(${M([
|
|
@@ -1010,7 +1003,7 @@ function ke(e) {
|
|
|
1010
1003
|
`;
|
|
1011
1004
|
}
|
|
1012
1005
|
function O(e) {
|
|
1013
|
-
let t = e.name, n =
|
|
1006
|
+
let t = e.name, n = o(e.shapeInfo.logicalShape);
|
|
1014
1007
|
return n < 2 ? `return ${t};` : `
|
|
1015
1008
|
for (int i = 0; i < ${n}; i++) {
|
|
1016
1009
|
if (i == index) {
|
|
@@ -1020,7 +1013,7 @@ function O(e) {
|
|
|
1020
1013
|
`;
|
|
1021
1014
|
}
|
|
1022
1015
|
function Ae(e, t) {
|
|
1023
|
-
let n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), i = "get" + r + "AtOutCoords", a = e.shapeInfo.logicalShape.length,
|
|
1016
|
+
let n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), i = "get" + r + "AtOutCoords", a = e.shapeInfo.logicalShape.length, s = t.logicalShape.length, c = y(e.shapeInfo.logicalShape, t.logicalShape), l = k(s), u = s - a, d, f = [
|
|
1024
1017
|
"x",
|
|
1025
1018
|
"y",
|
|
1026
1019
|
"z",
|
|
@@ -1028,12 +1021,12 @@ function Ae(e, t) {
|
|
|
1028
1021
|
"u",
|
|
1029
1022
|
"v"
|
|
1030
1023
|
];
|
|
1031
|
-
d = a === 0 ? "" :
|
|
1024
|
+
d = a === 0 ? "" : s < 2 && c.length >= 1 ? "coords = 0;" : c.map((e) => `coords.${f[e + u]} = 0;`).join("\n");
|
|
1032
1025
|
let p = "";
|
|
1033
|
-
p =
|
|
1034
|
-
let m = "return outputValue;", h =
|
|
1026
|
+
p = s < 2 && a > 0 ? "coords" : e.shapeInfo.logicalShape.map((e, t) => `coords.${f[t + u]}`).join(", ");
|
|
1027
|
+
let m = "return outputValue;", h = o(e.shapeInfo.logicalShape) === 1, g = o(t.logicalShape) === 1;
|
|
1035
1028
|
if (a === 1 && !h && !g) m = "\n return vec4(outputValue.xy, outputValue.xy);\n ";
|
|
1036
|
-
else if (h && !g) m =
|
|
1029
|
+
else if (h && !g) m = s === 1 ? "\n return vec4(outputValue.x, outputValue.x, 0., 0.);\n " : "\n return vec4(outputValue.x);\n ";
|
|
1037
1030
|
else if (c.length) {
|
|
1038
1031
|
let e = a - 2, t = a - 1;
|
|
1039
1032
|
c.indexOf(e) > -1 && c.indexOf(t) > -1 ? m = "return vec4(outputValue.x);" : c.indexOf(e) > -1 ? m = "return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);" : c.indexOf(t) > -1 && (m = "return vec4(outputValue.xx, outputValue.zz);");
|
|
@@ -1048,10 +1041,10 @@ function Ae(e, t) {
|
|
|
1048
1041
|
`;
|
|
1049
1042
|
}
|
|
1050
1043
|
function je(e, t) {
|
|
1051
|
-
let
|
|
1052
|
-
if (!e.shapeInfo.isUniform && c === l && e.shapeInfo.flatOffset == null &&
|
|
1053
|
-
float ${
|
|
1054
|
-
return sampleTexture(${
|
|
1044
|
+
let n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), i = "get" + r + "AtOutCoords", a = t.texShape, o = e.shapeInfo.texShape, c = e.shapeInfo.logicalShape.length, l = t.logicalShape.length;
|
|
1045
|
+
if (!e.shapeInfo.isUniform && c === l && e.shapeInfo.flatOffset == null && s(o, a)) return `
|
|
1046
|
+
float ${i}() {
|
|
1047
|
+
return sampleTexture(${n}, resultUV);
|
|
1055
1048
|
}
|
|
1056
1049
|
`;
|
|
1057
1050
|
let u = k(l), d = y(e.shapeInfo.logicalShape, t.logicalShape), f = l - c, p, m = [
|
|
@@ -1065,10 +1058,10 @@ function je(e, t) {
|
|
|
1065
1058
|
p = c === 0 ? "" : l < 2 && d.length >= 1 ? "coords = 0;" : d.map((e) => `coords.${m[e + f]} = 0;`).join("\n");
|
|
1066
1059
|
let h = "";
|
|
1067
1060
|
return h = l < 2 && c > 0 ? "coords" : e.shapeInfo.logicalShape.map((e, t) => `coords.${m[t + f]}`).join(", "), `
|
|
1068
|
-
float ${
|
|
1061
|
+
float ${i}() {
|
|
1069
1062
|
${u} coords = getOutputCoords();
|
|
1070
1063
|
${p}
|
|
1071
|
-
return get${
|
|
1064
|
+
return get${r}(${h});
|
|
1072
1065
|
}
|
|
1073
1066
|
`;
|
|
1074
1067
|
}
|
|
@@ -1081,12 +1074,12 @@ function k(e) {
|
|
|
1081
1074
|
if (e === 6) return "ivec6";
|
|
1082
1075
|
throw Error(`GPU for rank ${e} is not yet supported`);
|
|
1083
1076
|
}
|
|
1084
|
-
function A(e, t,
|
|
1085
|
-
let { newShape:
|
|
1077
|
+
function A(e, t, n) {
|
|
1078
|
+
let { newShape: r, keptDims: a } = i(t), o = t.length, c = e && o === 3 && t[0] === 1, l = c ? t.slice(1) : r, u = !e && o > 1 && !s(t, n) && r.length < o || c;
|
|
1086
1079
|
return {
|
|
1087
1080
|
useSqueezeShape: u,
|
|
1088
1081
|
uniformShape: u ? l : t,
|
|
1089
|
-
keptDims:
|
|
1082
|
+
keptDims: a
|
|
1090
1083
|
};
|
|
1091
1084
|
}
|
|
1092
1085
|
function j(e, t) {
|
|
@@ -1096,8 +1089,7 @@ function j(e, t) {
|
|
|
1096
1089
|
function M(e, t) {
|
|
1097
1090
|
return t.map((t) => e[t]).join(", ");
|
|
1098
1091
|
}
|
|
1099
|
-
|
|
1100
|
-
//#region node_modules/@tensorflow/tfjs-backend-webgl/dist/canvas_util.js
|
|
1092
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/canvas_util.js
|
|
1101
1093
|
var N = {}, P = {
|
|
1102
1094
|
alpha: !1,
|
|
1103
1095
|
antialias: !1,
|
|
@@ -1120,19 +1112,18 @@ function F(e, t) {
|
|
|
1120
1112
|
return n == null || n.isContextLost() ? (delete N[e], F(e)) : (n.disable(n.DEPTH_TEST), n.disable(n.STENCIL_TEST), n.disable(n.BLEND), n.disable(n.DITHER), n.disable(n.POLYGON_OFFSET_FILL), n.disable(n.SAMPLE_COVERAGE), n.enable(n.SCISSOR_TEST), n.enable(n.CULL_FACE), n.cullFace(n.BACK), N[e]);
|
|
1121
1113
|
}
|
|
1122
1114
|
function Ne(e) {
|
|
1123
|
-
if (!
|
|
1115
|
+
if (!a().getBool("IS_SAFARI") && typeof OffscreenCanvas < "u" && e === 2) return new OffscreenCanvas(300, 150);
|
|
1124
1116
|
if (typeof document < "u") return document.createElement("canvas");
|
|
1125
1117
|
throw Error("Cannot create a canvas in this context");
|
|
1126
1118
|
}
|
|
1127
|
-
function Pe(e,
|
|
1119
|
+
function Pe(e, t) {
|
|
1128
1120
|
if (e !== 1 && e !== 2) throw Error("Cannot get WebGL rendering context, WebGL is disabled.");
|
|
1129
|
-
let
|
|
1130
|
-
return
|
|
1121
|
+
let n = t ?? Ne(e);
|
|
1122
|
+
return n.addEventListener("webglcontextlost", (t) => {
|
|
1131
1123
|
t.preventDefault(), delete N[e];
|
|
1132
|
-
}, !1),
|
|
1124
|
+
}, !1), a().getBool("SOFTWARE_WEBGL_ENABLED") && (P.failIfMajorPerformanceCaveat = !1), e === 1 ? n.getContext("webgl", P) || n.getContext("experimental-webgl", P) : n.getContext("webgl2", P);
|
|
1133
1125
|
}
|
|
1134
|
-
|
|
1135
|
-
//#region node_modules/@tensorflow/tfjs-backend-webgl/dist/tex_util.js
|
|
1126
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/tex_util.js
|
|
1136
1127
|
var I;
|
|
1137
1128
|
(function(e) {
|
|
1138
1129
|
e[e.DENSE = 0] = "DENSE", e[e.SHARED_BATCH = 1] = "SHARED_BATCH";
|
|
@@ -1152,8 +1143,8 @@ function Ie(e, t) {
|
|
|
1152
1143
|
return e * t;
|
|
1153
1144
|
}
|
|
1154
1145
|
function Le(e) {
|
|
1155
|
-
let t =
|
|
1156
|
-
return
|
|
1146
|
+
let t = o(e), r = Math.ceil(t / 4);
|
|
1147
|
+
return n(r);
|
|
1157
1148
|
}
|
|
1158
1149
|
function z(e, t) {
|
|
1159
1150
|
return [Math.max(1, Math.ceil(t / 2)), Math.max(1, Math.ceil(e / 2))];
|
|
@@ -1162,11 +1153,11 @@ function Re(e, t) {
|
|
|
1162
1153
|
let [n, r] = z(e, t);
|
|
1163
1154
|
return n * r * 4;
|
|
1164
1155
|
}
|
|
1165
|
-
function B(e,
|
|
1166
|
-
let
|
|
1167
|
-
return
|
|
1168
|
-
internalFormatFloat:
|
|
1169
|
-
internalFormatHalfFloat:
|
|
1156
|
+
function B(e, t) {
|
|
1157
|
+
let n = e, r, i, o, s, c, l, u, d, f, p;
|
|
1158
|
+
return a().getNumber("WEBGL_VERSION") === 2 ? (r = n.R32F, i = n.R16F, o = n.RGBA16F, s = n.RGBA32F, c = n.RED, u = 4, d = 1, f = n.HALF_FLOAT, p = n.FLOAT, l = n.RGBA8) : (r = e.RGBA, i = e.RGBA, o = e.RGBA, s = n.RGBA, c = e.RGBA, u = 4, d = 4, f = t == null ? null : t.HALF_FLOAT_OES, p = e.FLOAT, l = e.RGBA), {
|
|
1159
|
+
internalFormatFloat: r,
|
|
1160
|
+
internalFormatHalfFloat: i,
|
|
1170
1161
|
internalFormatPackedHalfFloat: o,
|
|
1171
1162
|
internalFormatPackedFloat: s,
|
|
1172
1163
|
textureFormatFloat: c,
|
|
@@ -1177,11 +1168,10 @@ function B(e, n) {
|
|
|
1177
1168
|
textureTypeFloat: p
|
|
1178
1169
|
};
|
|
1179
1170
|
}
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
return t().getBool("DEBUG") && ze(e), r;
|
|
1171
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/webgl_util.js
|
|
1172
|
+
function V(e, t) {
|
|
1173
|
+
let n = t();
|
|
1174
|
+
return a().getBool("DEBUG") && ze(e), n;
|
|
1185
1175
|
}
|
|
1186
1176
|
function ze(e) {
|
|
1187
1177
|
let t = e.getError();
|
|
@@ -1189,7 +1179,7 @@ function ze(e) {
|
|
|
1189
1179
|
}
|
|
1190
1180
|
var Be = 5.96e-8, Ve = 65504;
|
|
1191
1181
|
function He(e) {
|
|
1192
|
-
return !!(
|
|
1182
|
+
return !!(a().getBool("WEBGL_RENDER_FLOAT32_ENABLED") || e === 0 || Be < Math.abs(e) && Math.abs(e) < Ve);
|
|
1193
1183
|
}
|
|
1194
1184
|
function Ue(e, t) {
|
|
1195
1185
|
switch (t) {
|
|
@@ -1211,29 +1201,29 @@ function Ge(e, t) {
|
|
|
1211
1201
|
if (V(e, () => e.shaderSource(n, t)), V(e, () => e.compileShader(n)), e.getShaderParameter(n, e.COMPILE_STATUS) === !1) throw console.log(e.getShaderInfoLog(n)), Error("Failed to compile vertex shader.");
|
|
1212
1202
|
return n;
|
|
1213
1203
|
}
|
|
1214
|
-
function Ke(e,
|
|
1215
|
-
let
|
|
1216
|
-
if (V(e, () => e.shaderSource(
|
|
1217
|
-
if (e.getShaderParameter(
|
|
1218
|
-
return
|
|
1204
|
+
function Ke(e, t) {
|
|
1205
|
+
let n = W(e, () => e.createShader(e.FRAGMENT_SHADER), "Unable to create fragment WebGLShader.");
|
|
1206
|
+
if (V(e, () => e.shaderSource(n, t)), V(e, () => e.compileShader(n)), a().get("ENGINE_COMPILE_ONLY")) return n;
|
|
1207
|
+
if (e.getShaderParameter(n, e.COMPILE_STATUS) === !1) throw U(t, e.getShaderInfoLog(n)), Error("Failed to compile fragment shader.");
|
|
1208
|
+
return n;
|
|
1219
1209
|
}
|
|
1220
1210
|
var H = /ERROR: [0-9]+:([0-9]+):/g;
|
|
1221
|
-
function U(
|
|
1222
|
-
let
|
|
1223
|
-
if (
|
|
1224
|
-
console.log(`Couldn't parse line number in error: ${
|
|
1211
|
+
function U(t, n) {
|
|
1212
|
+
let r = H.exec(n);
|
|
1213
|
+
if (r == null) {
|
|
1214
|
+
console.log(`Couldn't parse line number in error: ${n}`), console.log(t);
|
|
1225
1215
|
return;
|
|
1226
1216
|
}
|
|
1227
|
-
let
|
|
1217
|
+
let i = +r[1], a = t.split("\n"), o = a.length.toString().length + 2, s = a.map((t, n) => e((n + 1).toString(), o) + t), c = 0;
|
|
1228
1218
|
for (let e = 0; e < s.length; e++) c = Math.max(s[e].length, c);
|
|
1229
|
-
let l = s.slice(0,
|
|
1230
|
-
console.log(l.join("\n")), console.log(
|
|
1219
|
+
let l = s.slice(0, i - 1), u = s.slice(i - 1, i), d = s.slice(i);
|
|
1220
|
+
console.log(l.join("\n")), console.log(n.split("\n")[0]), console.log(`%c ${e(u[0], c)}`, "border:1px solid red; background-color:#e3d2d2; color:#a61717"), console.log(d.join("\n"));
|
|
1231
1221
|
}
|
|
1232
1222
|
function qe(e) {
|
|
1233
1223
|
return W(e, () => e.createProgram(), "Unable to create WebGLProgram.");
|
|
1234
1224
|
}
|
|
1235
|
-
function Je(e,
|
|
1236
|
-
if (V(e, () => e.linkProgram(
|
|
1225
|
+
function Je(e, t) {
|
|
1226
|
+
if (V(e, () => e.linkProgram(t)), !a().get("ENGINE_COMPILE_ONLY") && e.getProgramParameter(t, e.LINK_STATUS) === !1) throw console.log(e.getProgramInfoLog(t)), Error("Failed to link vertex and fragment shaders.");
|
|
1237
1227
|
}
|
|
1238
1228
|
function Ye(e, t) {
|
|
1239
1229
|
if (V(e, () => e.validateProgram(t)), e.getProgramParameter(t, e.VALIDATE_STATUS) === !1) throw console.log(e.getProgramInfoLog(t)), Error("Shader program validation failed.");
|
|
@@ -1249,15 +1239,15 @@ function Ze(e, t) {
|
|
|
1249
1239
|
function Qe(e) {
|
|
1250
1240
|
return W(e, () => e.createTexture(), "Unable to create WebGLTexture.");
|
|
1251
1241
|
}
|
|
1252
|
-
function $e(e,
|
|
1253
|
-
let
|
|
1254
|
-
if (e <= 0 ||
|
|
1255
|
-
let
|
|
1256
|
-
throw Error("Requested texture size " +
|
|
1242
|
+
function $e(e, t) {
|
|
1243
|
+
let n = a().getNumber("WEBGL_MAX_TEXTURE_SIZE");
|
|
1244
|
+
if (e <= 0 || t <= 0) {
|
|
1245
|
+
let n = `[${e}x${t}]`;
|
|
1246
|
+
throw Error("Requested texture size " + n + " is invalid.");
|
|
1257
1247
|
}
|
|
1258
|
-
if (e >
|
|
1259
|
-
let
|
|
1260
|
-
throw Error("Requested texture size " +
|
|
1248
|
+
if (e > n || t > n) {
|
|
1249
|
+
let r = `[${e}x${t}]`, i = `[${n}x${n}]`;
|
|
1250
|
+
throw Error("Requested texture size " + r + " greater than WebGL maximum on this browser / GPU " + i + ".");
|
|
1261
1251
|
}
|
|
1262
1252
|
}
|
|
1263
1253
|
function et(e) {
|
|
@@ -1265,7 +1255,7 @@ function et(e) {
|
|
|
1265
1255
|
}
|
|
1266
1256
|
function tt(e, t, n, r, i, a, o) {
|
|
1267
1257
|
let s = e.getAttribLocation(t, n);
|
|
1268
|
-
return s
|
|
1258
|
+
return s !== -1 && (V(e, () => e.bindBuffer(e.ARRAY_BUFFER, r)), V(e, () => e.vertexAttribPointer(s, i, e.FLOAT, !1, a, o)), V(e, () => e.enableVertexAttribArray(s)), !0);
|
|
1269
1259
|
}
|
|
1270
1260
|
function nt(e, t, n) {
|
|
1271
1261
|
ut(e, n), V(e, () => e.activeTexture(e.TEXTURE0 + n)), V(e, () => e.bindTexture(e.TEXTURE_2D, t));
|
|
@@ -1311,7 +1301,7 @@ function ut(e, t) {
|
|
|
1311
1301
|
}
|
|
1312
1302
|
}
|
|
1313
1303
|
function G(e, t = 2) {
|
|
1314
|
-
return
|
|
1304
|
+
return o(e.slice(0, e.length - t));
|
|
1315
1305
|
}
|
|
1316
1306
|
function K(e) {
|
|
1317
1307
|
if (e.length === 0) throw Error("Cannot get rows and columns of an empty shape array.");
|
|
@@ -1325,23 +1315,25 @@ function dt(e) {
|
|
|
1325
1315
|
];
|
|
1326
1316
|
return e.length === 0 || e.length === 1 && e[0] === 1 || (t = [G(e), ...K(e)]), t;
|
|
1327
1317
|
}
|
|
1328
|
-
function ft(e,
|
|
1329
|
-
let
|
|
1330
|
-
|
|
1331
|
-
let
|
|
1332
|
-
e.length <= 1 &&
|
|
1333
|
-
let d = u != null && Math.max(...u) >
|
|
1334
|
-
if (u == null || d)
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1318
|
+
function ft(e, r = !1) {
|
|
1319
|
+
let s = a().getNumber("WEBGL_MAX_TEXTURE_SIZE"), c = a().getNumber("WEBGL_MAX_SIZE_FOR_NARROW_TEXTURE");
|
|
1320
|
+
c === Infinity && a().getBool("WEBGL_AUTO_SQUARIFY_NARROW_TEXTURE_SHAPE") && (c = s / 2), r && (s *= 2, c *= 2, e = e.map((n, r) => r >= e.length - 2 ? t(e[r]) : e[r]), e.length === 1 && (e = [2, e[0]])), e.length !== 2 && (e = i(e).newShape);
|
|
1321
|
+
let l = o(e), u = null;
|
|
1322
|
+
e.length <= 1 && l <= s ? u = [1, l] : e.length === 2 && e[0] <= s && e[1] <= s ? u = e : e.length === 3 && e[0] * e[1] <= s && e[2] <= s ? u = [e[0] * e[1], e[2]] : e.length === 3 && e[0] <= s && e[1] * e[2] <= s ? u = [e[0], e[1] * e[2]] : e.length === 4 && e[0] * e[1] * e[2] <= s && e[3] <= s ? u = [e[0] * e[1] * e[2], e[3]] : e.length === 4 && e[0] <= s && e[1] * e[2] * e[3] <= s && (u = [e[0], e[1] * e[2] * e[3]]);
|
|
1323
|
+
let d = u != null && Math.max(...u) > c && Math.min(...u) <= (r ? 2 : 1) && Math.min(...u) > 0;
|
|
1324
|
+
if (u == null || d) {
|
|
1325
|
+
if (r) {
|
|
1326
|
+
let t = G(e), r = 2, i = 2;
|
|
1327
|
+
e.length && ([r, i] = K(e)), l = r / 2 * t * (i / 2), u = n(l).map((e) => e * 2);
|
|
1328
|
+
} else u = n(l);
|
|
1329
|
+
}
|
|
1338
1330
|
return u;
|
|
1339
1331
|
}
|
|
1340
1332
|
function q(e) {
|
|
1341
1333
|
return e % 2 == 0;
|
|
1342
1334
|
}
|
|
1343
1335
|
function pt(e, t) {
|
|
1344
|
-
if (e = e.slice(-2), t = t.slice(-2),
|
|
1336
|
+
if (e = e.slice(-2), t = t.slice(-2), s(e, t) || !e.length || !t.length || e[0] === 0 || e[1] === 0 || t[0] === 0 || t[1] === 0) return !0;
|
|
1345
1337
|
if (e.length !== t.length) {
|
|
1346
1338
|
let n = e[e.length - 1], r = t[t.length - 1];
|
|
1347
1339
|
if (n === r || q(n) && q(r) && (e[0] === 1 || t[0] === 1)) return !0;
|
|
@@ -1416,37 +1408,36 @@ function bt(e, t) {
|
|
|
1416
1408
|
return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(r), e.deleteFramebuffer(i), a;
|
|
1417
1409
|
}
|
|
1418
1410
|
function xt(e) {
|
|
1419
|
-
return e === 2
|
|
1411
|
+
return e === 2 && F(e).fenceSync != null;
|
|
1420
1412
|
}
|
|
1421
1413
|
function St(e, t) {
|
|
1422
1414
|
Array.isArray(e) || (e = [e]), e.forEach((e) => {
|
|
1423
|
-
e != null &&
|
|
1415
|
+
e != null && l(e.dtype !== "complex64", () => `${t} does not support complex64 tensors in the WebGL backend.`);
|
|
1424
1416
|
});
|
|
1425
1417
|
}
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
let a = r.map((e, t) => {
|
|
1418
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/gpgpu_math.js
|
|
1419
|
+
function Ct(e, t, n, r) {
|
|
1420
|
+
let i = n.map((e, n) => {
|
|
1430
1421
|
let r = {
|
|
1431
1422
|
logicalShape: e.shape,
|
|
1432
1423
|
texShape: e.isUniform ? null : e.texData.texShape,
|
|
1433
1424
|
isUniform: e.isUniform,
|
|
1434
|
-
isPacked: e.isUniform
|
|
1425
|
+
isPacked: !e.isUniform && e.texData.isPacked,
|
|
1435
1426
|
flatOffset: null
|
|
1436
1427
|
};
|
|
1437
1428
|
return e.texData != null && e.texData.slice != null && e.texData.slice.flatOffset > 0 && (r.flatOffset = e.texData.slice.flatOffset), {
|
|
1438
|
-
name:
|
|
1429
|
+
name: t.variableNames[n],
|
|
1439
1430
|
shapeInfo: r
|
|
1440
1431
|
};
|
|
1441
|
-
}), o =
|
|
1442
|
-
logicalShape:
|
|
1443
|
-
texShape:
|
|
1432
|
+
}), o = i.map((e) => e.shapeInfo), s = {
|
|
1433
|
+
logicalShape: r.shape,
|
|
1434
|
+
texShape: r.texData.texShape,
|
|
1444
1435
|
isUniform: !1,
|
|
1445
|
-
isPacked:
|
|
1436
|
+
isPacked: r.texData.isPacked,
|
|
1446
1437
|
flatOffset: null
|
|
1447
|
-
}, c = b(
|
|
1448
|
-
return
|
|
1449
|
-
program:
|
|
1438
|
+
}, c = b(i, s, t), l = Ke(e.gl, c), u = e.createProgram(l);
|
|
1439
|
+
return a().get("ENGINE_COMPILE_ONLY") ? {
|
|
1440
|
+
program: t,
|
|
1450
1441
|
fragmentShader: l,
|
|
1451
1442
|
source: c,
|
|
1452
1443
|
webGLProgram: u,
|
|
@@ -1460,29 +1451,29 @@ function Ct(e, n, r, i) {
|
|
|
1460
1451
|
outShapeStridesLocation: null,
|
|
1461
1452
|
outTexShapeLocation: null
|
|
1462
1453
|
} : (e.buildVao(u), Object.assign({
|
|
1463
|
-
program:
|
|
1454
|
+
program: t,
|
|
1464
1455
|
fragmentShader: l,
|
|
1465
1456
|
source: c,
|
|
1466
1457
|
webGLProgram: u,
|
|
1467
1458
|
inShapeInfos: o,
|
|
1468
1459
|
outShapeInfo: s
|
|
1469
|
-
}, Q(e,
|
|
1460
|
+
}, Q(e, t, u)));
|
|
1470
1461
|
}
|
|
1471
|
-
function Q(e,
|
|
1472
|
-
let
|
|
1473
|
-
u = e.getUniformLocation(
|
|
1474
|
-
for (let
|
|
1462
|
+
function Q(e, t, n) {
|
|
1463
|
+
let r = [], i = [], o, s, c, l = null, u = null;
|
|
1464
|
+
u = e.getUniformLocation(n, "NAN", !1), a().getNumber("WEBGL_VERSION") === 1 && (l = e.getUniformLocation(n, "INFINITY", !1));
|
|
1465
|
+
for (let i of t.variableNames) {
|
|
1475
1466
|
let a = {
|
|
1476
|
-
name:
|
|
1477
|
-
uniform: e.getUniformLocation(
|
|
1478
|
-
offset: e.getUniformLocation(
|
|
1467
|
+
name: i,
|
|
1468
|
+
uniform: e.getUniformLocation(n, i, !1),
|
|
1469
|
+
offset: e.getUniformLocation(n, `offset${i}`, !1)
|
|
1479
1470
|
};
|
|
1480
|
-
|
|
1471
|
+
t.enableShapeUniforms && (a.shape = e.getUniformLocation(n, `${i}Shape`, !1), a.texShape = e.getUniformLocation(n, `${i}TexShape`, !1)), r.push(a);
|
|
1481
1472
|
}
|
|
1482
|
-
if (
|
|
1473
|
+
if (t.enableShapeUniforms && (o = e.getUniformLocation(n, "outShape", !1), c = e.getUniformLocation(n, "outShapeStrides", !1), s = e.getUniformLocation(n, "outTexShape", !1)), t.customUniforms) for (let r of t.customUniforms) i.push(e.getUniformLocation(n, r.name, !1));
|
|
1483
1474
|
return {
|
|
1484
|
-
variablesLocations:
|
|
1485
|
-
customUniformLocations:
|
|
1475
|
+
variablesLocations: r,
|
|
1476
|
+
customUniformLocations: i,
|
|
1486
1477
|
infLoc: l,
|
|
1487
1478
|
nanLoc: u,
|
|
1488
1479
|
outShapeLocation: o,
|
|
@@ -1492,83 +1483,72 @@ function Q(e, n, r) {
|
|
|
1492
1483
|
}
|
|
1493
1484
|
function $(e, t) {
|
|
1494
1485
|
if (e.length !== t.length) throw Error(`Binary was compiled with ${e.length} inputs, but was executed with ${t.length} inputs`);
|
|
1495
|
-
e.forEach((e,
|
|
1496
|
-
let
|
|
1497
|
-
if (!
|
|
1498
|
-
if (e.isUniform &&
|
|
1499
|
-
let
|
|
1500
|
-
if (!
|
|
1486
|
+
e.forEach((e, n) => {
|
|
1487
|
+
let r = e.logicalShape, i = t[n], a = i.shape;
|
|
1488
|
+
if (!s(r, a)) throw Error(`Binary was compiled with different shapes than the current args. Shapes ${r} and ${a} must match`);
|
|
1489
|
+
if (e.isUniform && i.isUniform) return;
|
|
1490
|
+
let o = e.texShape, c = i.isUniform ? null : i.texData.texShape;
|
|
1491
|
+
if (!s(o, c)) throw Error(`Binary was compiled with different texture shapes than the current args. Shape ${o} and ${c} must match`);
|
|
1501
1492
|
});
|
|
1502
1493
|
}
|
|
1503
|
-
function wt(e,
|
|
1504
|
-
|
|
1505
|
-
let c =
|
|
1506
|
-
|
|
1507
|
-
for (let
|
|
1508
|
-
let i = r
|
|
1494
|
+
function wt(e, t, n, i, s) {
|
|
1495
|
+
t.program.enableShapeUniforms || ($(t.inShapeInfos, n), $([t.outShapeInfo], [i]));
|
|
1496
|
+
let c = i.texData.texture, l = i.texData.texShape;
|
|
1497
|
+
i.texData.isPacked ? e.setOutputPackedMatrixTexture(c.texture, l[0], l[1]) : e.setOutputMatrixTexture(c.texture, l[0], l[1]), e.setProgram(t.webGLProgram), e.bindVertexArray(t.webGLProgram.vao), a().getNumber("WEBGL_VERSION") === 1 && t.infLoc !== null && e.gl.uniform1f(t.infLoc, Infinity), t.nanLoc !== null && e.gl.uniform1f(t.nanLoc, NaN);
|
|
1498
|
+
for (let r = 0; r < n.length; ++r) {
|
|
1499
|
+
let i = n[r], { uniform: a, offset: s, shape: c, texShape: l } = t.variablesLocations[r];
|
|
1509
1500
|
if (c) {
|
|
1510
|
-
let { uniformShape:
|
|
1511
|
-
switch (
|
|
1501
|
+
let { uniformShape: n } = A(t.program.packedInputs, i.shape, i.texData.texShape);
|
|
1502
|
+
switch (n.length) {
|
|
1512
1503
|
case 1:
|
|
1513
|
-
e.gl.uniform1iv(c, new Int32Array(
|
|
1504
|
+
e.gl.uniform1iv(c, new Int32Array(n));
|
|
1514
1505
|
break;
|
|
1515
1506
|
case 2:
|
|
1516
|
-
e.gl.uniform2iv(c, new Int32Array(
|
|
1507
|
+
e.gl.uniform2iv(c, new Int32Array(n));
|
|
1517
1508
|
break;
|
|
1518
1509
|
case 3:
|
|
1519
|
-
e.gl.uniform3iv(c, new Int32Array(
|
|
1520
|
-
break;
|
|
1521
|
-
case 4:
|
|
1522
|
-
e.gl.uniform4iv(c, new Int32Array(t));
|
|
1510
|
+
e.gl.uniform3iv(c, new Int32Array(n));
|
|
1523
1511
|
break;
|
|
1524
|
-
|
|
1512
|
+
case 4: e.gl.uniform4iv(c, new Int32Array(n));
|
|
1525
1513
|
}
|
|
1526
1514
|
}
|
|
1527
1515
|
if (l && e.gl.uniform2i(l, i.texData.texShape[0], i.texData.texShape[1]), a != null) {
|
|
1528
1516
|
if (i.isUniform) {
|
|
1529
|
-
if (
|
|
1517
|
+
if (o(i.shape) < 2) e.gl.uniform1f(a, i.uniformValues[0]);
|
|
1530
1518
|
else {
|
|
1531
1519
|
let t = i.uniformValues;
|
|
1532
1520
|
t instanceof Float32Array || (t = new Float32Array(t)), e.gl.uniform1fv(a, t);
|
|
1533
1521
|
}
|
|
1534
|
-
|
|
1535
|
-
}
|
|
1536
|
-
i.texData.slice != null && o != null && e.gl.uniform1i(o, i.texData.slice.flatOffset), e.setInputMatrixTexture(i.texData.texture.texture, a, t);
|
|
1522
|
+
} else i.texData.slice != null && s != null && e.gl.uniform1i(s, i.texData.slice.flatOffset), e.setInputMatrixTexture(i.texData.texture.texture, a, r);
|
|
1537
1523
|
}
|
|
1538
1524
|
}
|
|
1539
|
-
let u =
|
|
1540
|
-
if (u) switch (
|
|
1525
|
+
let u = t.outShapeLocation;
|
|
1526
|
+
if (u) switch (i.shape.length) {
|
|
1541
1527
|
case 1:
|
|
1542
|
-
e.gl.uniform1iv(u, new Int32Array(
|
|
1528
|
+
e.gl.uniform1iv(u, new Int32Array(i.shape));
|
|
1543
1529
|
break;
|
|
1544
1530
|
case 2:
|
|
1545
|
-
e.gl.uniform2iv(u, new Int32Array(
|
|
1531
|
+
e.gl.uniform2iv(u, new Int32Array(i.shape));
|
|
1546
1532
|
break;
|
|
1547
1533
|
case 3:
|
|
1548
|
-
e.gl.uniform3iv(u, new Int32Array(
|
|
1534
|
+
e.gl.uniform3iv(u, new Int32Array(i.shape));
|
|
1549
1535
|
break;
|
|
1550
|
-
case 4:
|
|
1551
|
-
e.gl.uniform4iv(u, new Int32Array(a.shape));
|
|
1552
|
-
break;
|
|
1553
|
-
default: break;
|
|
1536
|
+
case 4: e.gl.uniform4iv(u, new Int32Array(i.shape));
|
|
1554
1537
|
}
|
|
1555
|
-
if (
|
|
1556
|
-
let
|
|
1557
|
-
switch (
|
|
1538
|
+
if (t.outShapeStridesLocation) {
|
|
1539
|
+
let n = r(i.shape);
|
|
1540
|
+
switch (i.shape.length) {
|
|
1558
1541
|
case 2:
|
|
1559
|
-
e.gl.uniform1iv(
|
|
1542
|
+
e.gl.uniform1iv(t.outShapeStridesLocation, new Int32Array(n));
|
|
1560
1543
|
break;
|
|
1561
1544
|
case 3:
|
|
1562
|
-
e.gl.uniform2iv(
|
|
1563
|
-
break;
|
|
1564
|
-
case 4:
|
|
1565
|
-
e.gl.uniform3iv(n.outShapeStridesLocation, new Int32Array(t));
|
|
1545
|
+
e.gl.uniform2iv(t.outShapeStridesLocation, new Int32Array(n));
|
|
1566
1546
|
break;
|
|
1567
|
-
|
|
1547
|
+
case 4: e.gl.uniform3iv(t.outShapeStridesLocation, new Int32Array(n));
|
|
1568
1548
|
}
|
|
1569
1549
|
}
|
|
1570
|
-
if (
|
|
1571
|
-
let r =
|
|
1550
|
+
if (t.outTexShapeLocation && e.gl.uniform2i(t.outTexShapeLocation, i.texData.texShape[0], i.texData.texShape[1]), t.program.customUniforms && s) for (let n = 0; n < t.program.customUniforms.length; ++n) {
|
|
1551
|
+
let r = t.program.customUniforms[n], i = t.customUniformLocations[n], a = s[n];
|
|
1572
1552
|
if (r.type === "float") e.gl.uniform1fv(i, a);
|
|
1573
1553
|
else if (r.type === "vec2") e.gl.uniform2fv(i, a);
|
|
1574
1554
|
else if (r.type === "vec3") e.gl.uniform3fv(i, a);
|
|
@@ -1581,32 +1561,31 @@ function wt(e, n, r, a, o) {
|
|
|
1581
1561
|
}
|
|
1582
1562
|
e.executeProgram();
|
|
1583
1563
|
}
|
|
1584
|
-
function Tt(
|
|
1585
|
-
let
|
|
1586
|
-
|
|
1564
|
+
function Tt(e, t, n) {
|
|
1565
|
+
let i = "";
|
|
1566
|
+
t.concat(n).forEach((t) => {
|
|
1587
1567
|
let a = t.texData != null && t.texData.slice != null && t.texData.slice.flatOffset > 0;
|
|
1588
|
-
if (
|
|
1589
|
-
let l = t.texData.texShape, { useSqueezeShape: u, uniformShape: d, keptDims: f } = A(
|
|
1590
|
-
if (d.length === 1 &&
|
|
1568
|
+
if (e.enableShapeUniforms && !t.isUniform) {
|
|
1569
|
+
let l = t.texData.texShape, { useSqueezeShape: u, uniformShape: d, keptDims: f } = A(e.packedInputs, t.shape, l), p = "", m = "", h = "";
|
|
1570
|
+
if (d.length === 1 && e.packedInputs) {
|
|
1591
1571
|
let e = [Math.ceil(l[0] / 2), Math.ceil(l[1] / 2)];
|
|
1592
1572
|
p = `${e[0] > 1}_${e[1] > 1}`;
|
|
1593
|
-
} else if (d.length === 2 && !
|
|
1594
|
-
else if (d.length > 2 && !
|
|
1595
|
-
let e =
|
|
1573
|
+
} else if (d.length === 2 && !e.packedInputs) m = `${d[0] > 1}_${d[1] > 1}`;
|
|
1574
|
+
else if (d.length > 2 && !e.packedInputs) {
|
|
1575
|
+
let e = r(d);
|
|
1596
1576
|
h = `${e[0] === l[1]}_${e[e.length - 1] === l[1]}`;
|
|
1597
1577
|
}
|
|
1598
|
-
let g = t.shape.length, _ = d.length === 2 &&
|
|
1599
|
-
|
|
1578
|
+
let g = t.shape.length, _ = d.length === 2 && s(t.shape, l), v = o(t.shape) === 1, y = c(t.shape, n.shape), b = !e.packedInputs && g === n.shape.length && s(l, n.texData.texShape), x = e.packedInputs || d.length > 2 ? "" : `${l[0] > 1}_${l[1] > 1}`;
|
|
1579
|
+
i += `${g}_${b}_${u ? f : ""}_${d.length}_${v}_${y}_${_}_${p}_${m}_${h}_${x}_${a}`;
|
|
1600
1580
|
} else {
|
|
1601
1581
|
let e = t.isUniform ? "uniform" : t.texData.texShape;
|
|
1602
|
-
|
|
1582
|
+
i += `${t.shape}_${e}_${a}`;
|
|
1603
1583
|
}
|
|
1604
1584
|
});
|
|
1605
|
-
let l =
|
|
1606
|
-
return u += "_" +
|
|
1585
|
+
let l = e.userCode, u = e.constructor.name;
|
|
1586
|
+
return u += "_" + i + "_" + l + `${a().getNumber("WEBGL_VERSION")}`, u;
|
|
1607
1587
|
}
|
|
1608
1588
|
function Et(e) {
|
|
1609
|
-
return
|
|
1589
|
+
return a().getBool("WEBGL_USE_SHAPES_UNIFORMS") && e <= 4;
|
|
1610
1590
|
}
|
|
1611
|
-
//#endregion
|
|
1612
1591
|
export { g as $, yt as A, I as B, K as C, mt as D, gt as E, U as F, Re as G, L as H, st as I, Fe as J, B as K, ct as L, xt as M, _t as N, X as O, Je as P, v as Q, Ye as R, rt as S, ft as T, Le as U, R as V, z as W, Me as X, F as Y, k as Z, Ge as _, Et as a, ht as b, at as c, He as d, _ as et, et as f, Qe as g, Xe as h, wt as i, d as it, pt as j, vt as k, tt as l, Ze as m, Q as n, h as nt, St as o, qe as p, Ie as q, Tt as r, p as rt, ot as s, Ct as t, f as tt, V as u, G as v, dt as w, it as x, We as y, $e as z };
|