@genai-fi/nanogpt 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Generator.js +7 -7
- package/dist/NanoGPTModel.js +70 -121
- package/dist/RealDiv-7xu-pkZN.js +540 -0
- package/dist/Reshape-BYC1oUku.js +127 -0
- package/dist/TeachableLLM.d.ts +2 -0
- package/dist/TeachableLLM.js +34 -27
- package/dist/{TiedEmbedding-BhxWO8QR.js → TiedEmbedding-C1HBot-5.js} +12 -13
- package/dist/{axis_util-D17qZRQm.js → axis_util-CCNL7jea.js} +14 -12
- package/dist/{broadcast_to-BMQLjvt_.js → broadcast_to-CddAF879.js} +2 -2
- package/dist/{concat-DhZfF1GY.js → concat-XOK9ANZu.js} +7 -7
- package/dist/{dataset-oilnemHf.js → dataset-BFFipD1c.js} +5 -5
- package/dist/{dropout-CrMQPCeG.js → dropout-xlKRoJyU.js} +9 -9
- package/dist/{gather-DZCMHZuN.js → gather-DKtUaTtA.js} +1 -1
- package/dist/gpgpu_math-B_ycgZ4W.js +3115 -0
- package/dist/{index-bMBtI-WR.js → index-CamYe_M8.js} +843 -646
- package/dist/{kernel_funcs_utils-CNmjLWnB.js → kernel_funcs_utils-D5MS0JFg.js} +232 -138
- package/dist/layers/BaseLayer.js +2 -2
- package/dist/layers/CausalSelfAttention.js +6 -6
- package/dist/layers/MLP.js +5 -5
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +13 -33
- package/dist/layers/TiedEmbedding.js +6 -7
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/{log_sum_exp-BHdkCb4s.js → log_sum_exp-CV_5-TTu.js} +15 -15
- package/dist/main.js +23 -20
- package/dist/{mat_mul-BsrLfy81.js → mat_mul-CAbRFWUj.js} +4 -4
- package/dist/{max-DechV4Bc.js → max-JBBv7aUf.js} +3 -3
- package/dist/mulmat_packed_gpu-DW4doKL_.js +71 -0
- package/dist/{norm-B9hWHZH1.js → norm-B9dQTFYn.js} +12 -12
- package/dist/{ones-g0K8jVwm.js → ones-CMHNqMr6.js} +2 -2
- package/dist/ops/appendCache.js +3 -3
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/appendCache.js +2 -2
- package/dist/ops/cpu/attentionMask.js +5 -5
- package/dist/ops/cpu/fusedSoftmax.js +2 -2
- package/dist/ops/cpu/gatherSub.js +5 -5
- package/dist/ops/cpu/gelu.js +1 -1
- package/dist/ops/cpu/matMulGelu.js +1 -1
- package/dist/ops/cpu/matMulMul.js +1 -1
- package/dist/ops/cpu/mulDropout.js +1 -1
- package/dist/ops/cpu/normRMS.js +1 -1
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +18 -49
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +1 -1
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.js +2 -2
- package/dist/ops/grads/gelu.js +1 -1
- package/dist/ops/grads/matMulGelu.js +1 -1
- package/dist/ops/grads/normRMS.js +1 -1
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +1 -1
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/matMulMul.js +1 -1
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/normRMS.js +1 -1
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/rope.js +8 -4
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +29 -560
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.js +3 -3
- package/dist/ops/webgl/matMulGelu.js +48 -115
- package/dist/ops/webgl/matMulMul.js +1 -1
- package/dist/ops/webgl/mulDropout.js +1 -1
- package/dist/ops/webgl/normRMS.js +2 -2
- package/dist/ops/webgl/qkv.js +1 -1
- package/dist/ops/webgl/rope.js +1 -1
- package/dist/ops/webgl/scatterSub.js +1 -1
- package/dist/{ops-Mv7Ta72x.js → ops-DqtYemmV.js} +143 -135
- package/dist/{random_width-BBAWzDym.js → random_width-CLMQG5Jn.js} +6925 -6291
- package/dist/{range-DMaG9A3G.js → range-DqYjKnuG.js} +1 -1
- package/dist/{gpgpu_math-Ctc31slO.js → reciprocal-z49filta.js} +7 -5
- package/dist/register_all_kernels-COt6wLD0.js +21397 -0
- package/dist/{reshape-T4yDEqoF.js → reshape-C45vIIRU.js} +1 -1
- package/dist/scatter_nd_util-qgtnviTE.js +46 -0
- package/dist/selu_util-4QV_GXTB.js +740 -0
- package/dist/{shared-XNAoXhOa.js → shared-ByfrGA97.js} +1462 -1089
- package/dist/{sin-EEhbrRO_.js → sin-9JBrfVaB.js} +1 -1
- package/dist/{softmax-B2_IKPDR.js → softmax-DvMvui-_.js} +1 -1
- package/dist/{split-dcks18H1.js → split-DxrHrPFK.js} +4 -4
- package/dist/{stack-lpJ5kYvE.js → stack-DgaoDmnF.js} +1 -1
- package/dist/{sum-CutF5lj2.js → sum-BpcpxNEh.js} +3 -3
- package/dist/{tensor-C15NA2LA.js → tensor-CDz5x1mP.js} +1 -1
- package/dist/{tensor2d-DZ_e5eKM.js → tensor2d-jO8JY5Jd.js} +1 -1
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +2 -2
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +3 -3
- package/dist/training/sparseCrossEntropy.js +4 -4
- package/dist/utilities/dummy.d.ts +6 -0
- package/dist/utilities/dummy.js +31 -10
- package/dist/utilities/generate.js +3 -3
- package/dist/utilities/load.js +1 -1
- package/dist/utilities/profile.d.ts +5 -0
- package/dist/utilities/profile.js +10 -7
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-CdRKKp8x.js → variable-CLVXjN7F.js} +1 -1
- package/dist/{zeros-CAbHfODe.js → zeros-DUkkVccu.js} +8 -8
- package/package.json +3 -9
- package/dist/Reshape-CLOrdpve.js +0 -212
- package/dist/slice_util-Ddk0uxGJ.js +0 -49
- package/dist/tfjs_backend-BDb8r9qx.js +0 -1010
|
@@ -0,0 +1,3115 @@
|
|
|
1
|
+
import { ay as J, ac as m, az as le, aA as fe, aB as he, k as $, aC as we, aD as Q, i as T, W as D, aE as z, aF as Ce, aG as Fe, j as Ae, aH as de, au as _e, aI as Ie, u as Oe, aJ as Ne, aK as N, ai as E, aL as q, aM as ye, aN as ee } from "./index-CamYe_M8.js";
|
|
2
|
+
import "./index-Tf7vU29b.js";
|
|
3
|
+
import { b as Le, d as De, f as be, c as Ue, e as Me, g as Be, a as ke, h as Pe } from "./axis_util-CCNL7jea.js";
|
|
4
|
+
import { S as We, a as Ve, b as He, c as Xe, d as Ge, e as ze, f as qe, g as je, h as Je, i as Ye, j as Ke, k as Ze, l as Qe, m as et, s as tt, n as nt, o as rt, t as ot } from "./selu_util-4QV_GXTB.js";
|
|
5
|
+
import { c as at, v as st, a as it } from "./scatter_nd_util-qgtnviTE.js";
|
|
6
|
+
/**
|
|
7
|
+
* @license
|
|
8
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
9
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License.
|
|
11
|
+
* You may obtain a copy of the License at
|
|
12
|
+
*
|
|
13
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
* =============================================================================
|
|
21
|
+
*/
|
|
22
|
+
const ct = "model", ut = ".json", lt = ".weights.bin";
|
|
23
|
+
function te(e) {
|
|
24
|
+
return new Promise((t) => setTimeout(t)).then(e);
|
|
25
|
+
}
|
|
26
|
+
class O {
|
|
27
|
+
constructor(t) {
|
|
28
|
+
if (!m().getBool("IS_BROWSER"))
|
|
29
|
+
throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");
|
|
30
|
+
t.startsWith(O.URL_SCHEME) && (t = t.slice(O.URL_SCHEME.length)), (t == null || t.length === 0) && (t = ct), this.modelJsonFileName = t + ut, this.weightDataFileName = t + lt;
|
|
31
|
+
}
|
|
32
|
+
async save(t) {
|
|
33
|
+
if (typeof document > "u")
|
|
34
|
+
throw new Error("Browser downloads are not supported in this environment since `document` is not present");
|
|
35
|
+
const n = le.join(t.weightData), r = window.URL.createObjectURL(new Blob([n], { type: "application/octet-stream" }));
|
|
36
|
+
if (t.modelTopology instanceof ArrayBuffer)
|
|
37
|
+
throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");
|
|
38
|
+
{
|
|
39
|
+
const o = [{
|
|
40
|
+
paths: ["./" + this.weightDataFileName],
|
|
41
|
+
weights: t.weightSpecs
|
|
42
|
+
}], a = fe(t, o), s = window.URL.createObjectURL(new Blob([JSON.stringify(a)], { type: "application/json" })), i = this.modelJsonAnchor == null ? document.createElement("a") : this.modelJsonAnchor;
|
|
43
|
+
if (i.download = this.modelJsonFileName, i.href = s, await te(() => i.dispatchEvent(new MouseEvent("click"))), t.weightData != null) {
|
|
44
|
+
const c = this.weightDataAnchor == null ? document.createElement("a") : this.weightDataAnchor;
|
|
45
|
+
c.download = this.weightDataFileName, c.href = r, await te(() => c.dispatchEvent(new MouseEvent("click")));
|
|
46
|
+
}
|
|
47
|
+
return { modelArtifactsInfo: he(t) };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
O.URL_SCHEME = "downloads://";
|
|
52
|
+
const ft = (e) => m().getBool("IS_BROWSER") && !Array.isArray(e) && e.startsWith(O.URL_SCHEME) ? ht(e.slice(O.URL_SCHEME.length)) : null;
|
|
53
|
+
J.registerSaveRouter(ft);
|
|
54
|
+
function ht(e = "model") {
|
|
55
|
+
return new O(e);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @license
|
|
59
|
+
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
60
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
61
|
+
* you may not use this file except in compliance with the License.
|
|
62
|
+
* You may obtain a copy of the License at
|
|
63
|
+
*
|
|
64
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
65
|
+
*
|
|
66
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
67
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
68
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
69
|
+
* See the License for the specific language governing permissions and
|
|
70
|
+
* limitations under the License.
|
|
71
|
+
* =============================================================================
|
|
72
|
+
*/
|
|
73
|
+
function ne(e, t, n, r) {
|
|
74
|
+
s(e), n = n ?? 0, r = r ?? 1, i(n, r);
|
|
75
|
+
let o = 0;
|
|
76
|
+
const a = (c) => (c.then((l) => {
|
|
77
|
+
const f = n + ++o / e.length * (r - n);
|
|
78
|
+
return t(f), l;
|
|
79
|
+
}), c);
|
|
80
|
+
function s(c) {
|
|
81
|
+
$(c != null && Array.isArray(c) && c.length > 0, () => "promises must be a none empty array");
|
|
82
|
+
}
|
|
83
|
+
function i(c, l) {
|
|
84
|
+
$(c >= 0 && c <= 1, () => `Progress fraction must be in range [0, 1], but got startFraction ${c}`), $(l >= 0 && l <= 1, () => `Progress fraction must be in range [0, 1], but got endFraction ${l}`), $(l >= c, () => `startFraction must be no more than endFraction, but got startFraction ${c} and endFraction ${l}`);
|
|
85
|
+
}
|
|
86
|
+
return Promise.all(e.map(a));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @license
|
|
90
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
91
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
92
|
+
* you may not use this file except in compliance with the License.
|
|
93
|
+
* You may obtain a copy of the License at
|
|
94
|
+
*
|
|
95
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
96
|
+
*
|
|
97
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
98
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
99
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
100
|
+
* See the License for the specific language governing permissions and
|
|
101
|
+
* limitations under the License.
|
|
102
|
+
* =============================================================================
|
|
103
|
+
*/
|
|
104
|
+
async function dt(e, t) {
|
|
105
|
+
t == null && (t = {});
|
|
106
|
+
const n = t.fetchFunc == null ? m().platform.fetch : t.fetchFunc, r = e.map((u) => n(u, t.requestInit, { isBinary: !0 })), i = (t.onProgress == null ? await Promise.all(r) : await ne(r, t.onProgress, 0, 0.5)).map((u) => u.arrayBuffer());
|
|
107
|
+
return t.onProgress == null ? await Promise.all(i) : await ne(i, t.onProgress, 0.5, 1);
|
|
108
|
+
}
|
|
109
|
+
function pt(e, t) {
|
|
110
|
+
var n;
|
|
111
|
+
const r = t.fetchFunc == null ? m().platform.fetch : t.fetchFunc;
|
|
112
|
+
let o = 0, a;
|
|
113
|
+
return (n = t.onProgress) === null || n === void 0 || n.call(t, 0), new ReadableStream({
|
|
114
|
+
pull: async (s) => {
|
|
115
|
+
for (var i; o < e.length; ) {
|
|
116
|
+
a || (a = (await r(e[o], t.requestInit, { isBinary: !0 })).body.getReader());
|
|
117
|
+
const { done: c, value: l } = await a.read();
|
|
118
|
+
if (c) {
|
|
119
|
+
o++, a = void 0, (i = t.onProgress) === null || i === void 0 || i.call(t, o / e.length);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
s.enqueue(l);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
s.close();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @license
|
|
131
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
132
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
133
|
+
* you may not use this file except in compliance with the License.
|
|
134
|
+
* You may obtain a copy of the License at
|
|
135
|
+
*
|
|
136
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
137
|
+
*
|
|
138
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
139
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
140
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
141
|
+
* See the License for the specific language governing permissions and
|
|
142
|
+
* limitations under the License.
|
|
143
|
+
* =============================================================================
|
|
144
|
+
*/
|
|
145
|
+
const xt = "application/octet-stream", mt = "application/json";
|
|
146
|
+
class Y {
|
|
147
|
+
constructor(t, n) {
|
|
148
|
+
if (this.DEFAULT_METHOD = "POST", n == null && (n = {}), this.weightPathPrefix = n.weightPathPrefix, this.weightUrlConverter = n.weightUrlConverter, n.fetchFunc != null ? ($(typeof n.fetchFunc == "function", () => "Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"), this.fetch = n.fetchFunc) : this.fetch = m().platform.fetch, $(t != null && t.length > 0, () => "URL path for http must not be null, undefined or empty."), Array.isArray(t) && $(t.length === 2, () => `URL paths for http must have a length of 2, (actual length is ${t.length}).`), this.path = t, n.requestInit != null && n.requestInit.body != null)
|
|
149
|
+
throw new Error("requestInit is expected to have no pre-existing body, but has one.");
|
|
150
|
+
this.requestInit = n.requestInit || {}, this.loadOptions = n;
|
|
151
|
+
}
|
|
152
|
+
async save(t) {
|
|
153
|
+
if (t.modelTopology instanceof ArrayBuffer)
|
|
154
|
+
throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");
|
|
155
|
+
const n = Object.assign({ method: this.DEFAULT_METHOD }, this.requestInit);
|
|
156
|
+
n.body = new FormData();
|
|
157
|
+
const r = [{
|
|
158
|
+
paths: ["./model.weights.bin"],
|
|
159
|
+
weights: t.weightSpecs
|
|
160
|
+
}], o = fe(t, r);
|
|
161
|
+
if (n.body.append("model.json", new Blob([JSON.stringify(o)], { type: mt }), "model.json"), t.weightData != null) {
|
|
162
|
+
const s = le.join(t.weightData);
|
|
163
|
+
n.body.append("model.weights.bin", new Blob([s], { type: xt }), "model.weights.bin");
|
|
164
|
+
}
|
|
165
|
+
const a = await this.fetch(this.path, n);
|
|
166
|
+
if (a.ok)
|
|
167
|
+
return {
|
|
168
|
+
modelArtifactsInfo: he(t),
|
|
169
|
+
responses: [a]
|
|
170
|
+
};
|
|
171
|
+
throw new Error(`BrowserHTTPRequest.save() failed due to HTTP response status ${a.status}.`);
|
|
172
|
+
}
|
|
173
|
+
async loadModelJSON() {
|
|
174
|
+
const t = await this.fetch(this.path, this.requestInit);
|
|
175
|
+
if (!t.ok)
|
|
176
|
+
throw new Error(`Request to ${this.path} failed with status code ${t.status}. Please verify this URL points to the model JSON of the model to load.`);
|
|
177
|
+
let n;
|
|
178
|
+
try {
|
|
179
|
+
n = await t.json();
|
|
180
|
+
} catch {
|
|
181
|
+
let s = `Failed to parse model JSON of response from ${this.path}.`;
|
|
182
|
+
throw this.path.endsWith(".pb") ? s += " Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository." : s += " Please make sure the server is serving valid JSON for this request.", new Error(s);
|
|
183
|
+
}
|
|
184
|
+
const r = n.modelTopology, o = n.weightsManifest;
|
|
185
|
+
if (r == null && o == null)
|
|
186
|
+
throw new Error(`The JSON from HTTP path ${this.path} contains neither model topology or manifest for weights.`);
|
|
187
|
+
return n;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Load model artifacts via HTTP request(s).
|
|
191
|
+
*
|
|
192
|
+
* See the documentation to `tf.io.http` for details on the saved
|
|
193
|
+
* artifacts.
|
|
194
|
+
*
|
|
195
|
+
* @returns The loaded model artifacts (if loading succeeds).
|
|
196
|
+
*/
|
|
197
|
+
async load() {
|
|
198
|
+
if (this.loadOptions.streamWeights)
|
|
199
|
+
return this.loadStream();
|
|
200
|
+
const t = await this.loadModelJSON();
|
|
201
|
+
return we(t, (n) => this.loadWeights(n));
|
|
202
|
+
}
|
|
203
|
+
async loadStream() {
|
|
204
|
+
const t = await this.loadModelJSON(), n = await this.getWeightUrls(t.weightsManifest), r = Q(t.weightsManifest), o = () => pt(n, this.loadOptions);
|
|
205
|
+
return Object.assign(Object.assign({}, t), { weightSpecs: r, getWeightStream: o });
|
|
206
|
+
}
|
|
207
|
+
async getWeightUrls(t) {
|
|
208
|
+
const n = Array.isArray(this.path) ? this.path[1] : this.path, [r, o] = vt(n), a = this.weightPathPrefix || r, s = [], i = [];
|
|
209
|
+
for (const c of t)
|
|
210
|
+
for (const l of c.paths)
|
|
211
|
+
this.weightUrlConverter != null ? i.push(this.weightUrlConverter(l)) : s.push(a + l + o);
|
|
212
|
+
return this.weightUrlConverter && s.push(...await Promise.all(i)), s;
|
|
213
|
+
}
|
|
214
|
+
async loadWeights(t) {
|
|
215
|
+
const n = await this.getWeightUrls(t), r = Q(t), o = await dt(n, this.loadOptions);
|
|
216
|
+
return [r, o];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
Y.URL_SCHEME_REGEX = /^https?:\/\//;
|
|
220
|
+
function vt(e) {
|
|
221
|
+
const t = e.lastIndexOf("/"), n = e.lastIndexOf("?"), r = e.substring(0, t), o = n > t ? e.substring(n) : "";
|
|
222
|
+
return [r + "/", o];
|
|
223
|
+
}
|
|
224
|
+
function re(e) {
|
|
225
|
+
return e.match(Y.URL_SCHEME_REGEX) != null;
|
|
226
|
+
}
|
|
227
|
+
const pe = (e, t) => {
|
|
228
|
+
if (typeof fetch > "u" && (t == null || t.fetchFunc == null))
|
|
229
|
+
return null;
|
|
230
|
+
{
|
|
231
|
+
let n = !0;
|
|
232
|
+
if (Array.isArray(e) ? n = e.every((r) => re(r)) : n = re(e), n)
|
|
233
|
+
return $t(e, t);
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
};
|
|
237
|
+
J.registerSaveRouter(pe);
|
|
238
|
+
J.registerLoadRouter(pe);
|
|
239
|
+
function $t(e, t) {
|
|
240
|
+
return new Y(e, t);
|
|
241
|
+
}
|
|
242
|
+
function Tt(e, t) {
|
|
243
|
+
const n = e.shape.length, r = t.shape.length;
|
|
244
|
+
if (n < 1)
|
|
245
|
+
throw new Error(`tf.gatherND() expects the input to be rank 1 or higher, but the rank was ${n}.`);
|
|
246
|
+
if (r < 1)
|
|
247
|
+
throw new Error(`tf.gatherND() expects the indices to be rank 1 or higher, but the rank was ${r}.`);
|
|
248
|
+
if (t.dtype !== "int32")
|
|
249
|
+
throw new Error(`tf.gatherND() expects the indices to be int32 type, but the dtype was ${t.dtype}.`);
|
|
250
|
+
if (t.shape[r - 1] > n)
|
|
251
|
+
throw new Error(`index innermost dimension length must be <= tensor rank; saw: ${t.shape[r - 1]} vs. ${n}`);
|
|
252
|
+
if (T(e.shape) === 0)
|
|
253
|
+
throw new Error(`Requested more than 0 entries, but input is empty. Input shape: ${e.shape}.`);
|
|
254
|
+
const o = t.shape, a = o[o.length - 1];
|
|
255
|
+
let s = 1;
|
|
256
|
+
for (let u = 0; u < o.length - 1; ++u)
|
|
257
|
+
s *= o[u];
|
|
258
|
+
const i = e.shape, c = o.slice();
|
|
259
|
+
c.pop();
|
|
260
|
+
let l = 1;
|
|
261
|
+
for (let u = a; u < n; ++u)
|
|
262
|
+
l *= i[u], c.push(i[u]);
|
|
263
|
+
const f = [
|
|
264
|
+
...D(e.shape).map((u) => u / l),
|
|
265
|
+
1
|
|
266
|
+
].slice(0, a);
|
|
267
|
+
return [c, s, l, f];
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* @license
|
|
271
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
272
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
273
|
+
* you may not use this file except in compliance with the License.
|
|
274
|
+
* You may obtain a copy of the License at
|
|
275
|
+
*
|
|
276
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
277
|
+
*
|
|
278
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
279
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
280
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
281
|
+
* See the License for the specific language governing permissions and
|
|
282
|
+
* limitations under the License.
|
|
283
|
+
* =============================================================================
|
|
284
|
+
*/
|
|
285
|
+
function St(e, t) {
|
|
286
|
+
const n = e[0].length;
|
|
287
|
+
e.forEach((o, a) => {
|
|
288
|
+
$(o.length === n, () => `Error in concat${n}D: rank of tensors[${a}] must be the same as the rank of the rest (${n})`);
|
|
289
|
+
}), $(t >= 0 && t < n, () => `Error in concat${n}D: axis must be between 0 and ${n - 1}.`);
|
|
290
|
+
const r = e[0];
|
|
291
|
+
e.forEach((o, a) => {
|
|
292
|
+
for (let s = 0; s < n; s++)
|
|
293
|
+
$(s === t || o[s] === r[s], () => `Error in concat${n}D: Shape of tensors[${a}] (${o}) does not match the shape of the rest (${r}) along the non-concatenated axis ${a}.`);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
function Et(e, t) {
|
|
297
|
+
const n = e[0].slice();
|
|
298
|
+
for (let r = 1; r < e.length; r++)
|
|
299
|
+
n[t] += e[r][t];
|
|
300
|
+
return n;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* @license
|
|
304
|
+
* Copyright 2022 Google LLC. All Rights Reserved.
|
|
305
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
306
|
+
* you may not use this file except in compliance with the License.
|
|
307
|
+
* You may obtain a copy of the License at
|
|
308
|
+
*
|
|
309
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
310
|
+
*
|
|
311
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
312
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
313
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
314
|
+
* See the License for the specific language governing permissions and
|
|
315
|
+
* limitations under the License.
|
|
316
|
+
* =============================================================================
|
|
317
|
+
*/
|
|
318
|
+
var R;
|
|
319
|
+
(function(e) {
|
|
320
|
+
e[e.FIRST_DIM_SIZE = 0] = "FIRST_DIM_SIZE", e[e.VALUE_ROWIDS = 1] = "VALUE_ROWIDS", e[e.ROW_LENGTHS = 2] = "ROW_LENGTHS", e[e.ROW_SPLITS = 3] = "ROW_SPLITS", e[e.ROW_LIMITS = 4] = "ROW_LIMITS", e[e.ROW_STARTS = 5] = "ROW_STARTS";
|
|
321
|
+
})(R || (R = {}));
|
|
322
|
+
function Rt(e, t, n) {
|
|
323
|
+
let r = new Array();
|
|
324
|
+
if (n == null && t == null)
|
|
325
|
+
return r;
|
|
326
|
+
if (t == null)
|
|
327
|
+
for (; r.length < e + n.length; )
|
|
328
|
+
r.push(-1);
|
|
329
|
+
else
|
|
330
|
+
r = t.slice();
|
|
331
|
+
if (n == null)
|
|
332
|
+
return r;
|
|
333
|
+
if (e + n.length !== r.length)
|
|
334
|
+
throw new Error(`rt input.shape and shape=${t} are incompatible: rt input.rank = ${e + n.length}, but shape.rank = ${r.length}`);
|
|
335
|
+
for (let o = 1; o < n.length; ++o) {
|
|
336
|
+
const a = n[o], s = r[r.length - n.length + o], i = r[s];
|
|
337
|
+
if (a >= 0)
|
|
338
|
+
if (i >= 0) {
|
|
339
|
+
if (i !== a)
|
|
340
|
+
throw new Error(`rt input.shape and shape=${t} are incompatible: rt input.shape[${o + e}] = ${a} but shape[${o + e}] = ${i}`);
|
|
341
|
+
} else
|
|
342
|
+
r[s] = a;
|
|
343
|
+
}
|
|
344
|
+
return r;
|
|
345
|
+
}
|
|
346
|
+
function gt(e) {
|
|
347
|
+
const t = {
|
|
348
|
+
FIRST_DIM_SIZE: R.FIRST_DIM_SIZE,
|
|
349
|
+
VALUE_ROWIDS: R.VALUE_ROWIDS,
|
|
350
|
+
ROW_LENGTHS: R.ROW_LENGTHS,
|
|
351
|
+
ROW_SPLITS: R.ROW_SPLITS,
|
|
352
|
+
ROW_LIMITS: R.ROW_LIMITS,
|
|
353
|
+
ROW_STARTS: R.ROW_STARTS
|
|
354
|
+
}, n = [];
|
|
355
|
+
for (const r of e)
|
|
356
|
+
if (r in t)
|
|
357
|
+
n.push(t[r]);
|
|
358
|
+
else
|
|
359
|
+
break;
|
|
360
|
+
return n;
|
|
361
|
+
}
|
|
362
|
+
function wt(e) {
|
|
363
|
+
return e.length === 0 ? 0 : e[0] === R.FIRST_DIM_SIZE ? e.length - 1 : e.length;
|
|
364
|
+
}
|
|
365
|
+
function Ct(e, t) {
|
|
366
|
+
if (e == null || t == null)
|
|
367
|
+
return;
|
|
368
|
+
const n = e.length, r = t.length;
|
|
369
|
+
if (n >= r)
|
|
370
|
+
throw new Error(`defaultValue.shape=${e} and ragged tensor flatValues.shape=${t}, are incompatible: defaultValue.rank = ${n} must be less than ragged tensor input flatValues.rank = ${r})`);
|
|
371
|
+
for (let o = 0; o < Math.min(n, r - 1); ++o) {
|
|
372
|
+
const a = e[o], s = t[o + 1];
|
|
373
|
+
if (a >= 0 && s >= 0 && a !== 1 && a !== s)
|
|
374
|
+
throw new Error(`defaultValue.shape=${e}, and ragged tensor input flatValues.shape=${t} are incompatible: defaultValue.shape[${o - e.length}] = ${a} but ragged tensor input.flatValues.shape[${o - e.length}] = ${s}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* @license
|
|
379
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
380
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
381
|
+
* you may not use this file except in compliance with the License.
|
|
382
|
+
* You may obtain a copy of the License at
|
|
383
|
+
*
|
|
384
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
385
|
+
*
|
|
386
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
387
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
388
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
389
|
+
* See the License for the specific language governing permissions and
|
|
390
|
+
* limitations under the License.
|
|
391
|
+
* =============================================================================
|
|
392
|
+
*/
|
|
393
|
+
const K = 30;
|
|
394
|
+
function Ft(e) {
|
|
395
|
+
return e <= K ? e : z(e, Math.floor(Math.sqrt(e)));
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* @license
|
|
399
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
400
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
401
|
+
* you may not use this file except in compliance with the License.
|
|
402
|
+
* You may obtain a copy of the License at
|
|
403
|
+
*
|
|
404
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
405
|
+
*
|
|
406
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
407
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
408
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
409
|
+
* See the License for the specific language governing permissions and
|
|
410
|
+
* limitations under the License.
|
|
411
|
+
* =============================================================================
|
|
412
|
+
*/
|
|
413
|
+
function At(e, t, n) {
|
|
414
|
+
const r = n * (typeof e == "number" ? e : e[0]), o = t * (typeof e == "number" ? e : e[1]);
|
|
415
|
+
return [r, o];
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* @license
|
|
419
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
420
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
421
|
+
* you may not use this file except in compliance with the License.
|
|
422
|
+
* You may obtain a copy of the License at
|
|
423
|
+
*
|
|
424
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
425
|
+
*
|
|
426
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
427
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
428
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
429
|
+
* See the License for the specific language governing permissions and
|
|
430
|
+
* limitations under the License.
|
|
431
|
+
* =============================================================================
|
|
432
|
+
*/
|
|
433
|
+
function _t(e, t, n, r = !0) {
|
|
434
|
+
let o = [];
|
|
435
|
+
if (r)
|
|
436
|
+
o = o.concat(t.slice(0)), o.push(e[0] / n), o = o.concat(e.slice(1));
|
|
437
|
+
else {
|
|
438
|
+
o = o.concat(e[0]);
|
|
439
|
+
const a = t.length;
|
|
440
|
+
for (let s = 0; s < a; ++s)
|
|
441
|
+
o = o.concat([e[s + 1] / t[s], t[s]]);
|
|
442
|
+
o = o.concat(e.slice(a + 1));
|
|
443
|
+
}
|
|
444
|
+
return o;
|
|
445
|
+
}
|
|
446
|
+
function It(e, t, n = !0) {
|
|
447
|
+
const r = [];
|
|
448
|
+
if (n) {
|
|
449
|
+
r.push(t);
|
|
450
|
+
for (let o = t + 1; o < e; ++o)
|
|
451
|
+
o <= 2 * t ? (r.push(o), r.push(o - (t + 1))) : r.push(o);
|
|
452
|
+
} else {
|
|
453
|
+
const o = [], a = [];
|
|
454
|
+
for (let s = 1; s < e; ++s)
|
|
455
|
+
s >= t * 2 + 1 || s % 2 === 1 ? a.push(s) : o.push(s);
|
|
456
|
+
r.push(...o), r.push(0), r.push(...a);
|
|
457
|
+
}
|
|
458
|
+
return r;
|
|
459
|
+
}
|
|
460
|
+
function Ot(e, t, n, r = !0) {
|
|
461
|
+
const o = [];
|
|
462
|
+
r ? o.push(e[0] / n) : o.push(e[0] * n);
|
|
463
|
+
for (let a = 1; a < e.length; ++a)
|
|
464
|
+
a <= t.length ? r ? o.push(t[a - 1] * e[a]) : o.push(e[a] / t[a - 1]) : o.push(e[a]);
|
|
465
|
+
return o;
|
|
466
|
+
}
|
|
467
|
+
function Nt(e, t) {
|
|
468
|
+
const n = [0];
|
|
469
|
+
for (let r = 0; r < t; ++r)
|
|
470
|
+
n.push(e[r][0]);
|
|
471
|
+
return n;
|
|
472
|
+
}
|
|
473
|
+
function yt(e, t, n) {
|
|
474
|
+
const r = e.slice(0, 1);
|
|
475
|
+
for (let o = 0; o < n; ++o)
|
|
476
|
+
r.push(e[o + 1] - t[o][0] - t[o][1]);
|
|
477
|
+
return r;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* @license
|
|
481
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
482
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
483
|
+
* you may not use this file except in compliance with the License.
|
|
484
|
+
* You may obtain a copy of the License at
|
|
485
|
+
*
|
|
486
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
487
|
+
*
|
|
488
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
489
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
490
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
491
|
+
* See the License for the specific language governing permissions and
|
|
492
|
+
* limitations under the License.
|
|
493
|
+
* =============================================================================
|
|
494
|
+
*/
|
|
495
|
+
const Lt = 0.3275911, Dt = 0.254829592, bt = -0.284496736, Ut = 1.421413741, Mt = -1.453152027, Bt = 1.061405429;
|
|
496
|
+
/**
|
|
497
|
+
* @license
|
|
498
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
499
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
500
|
+
* you may not use this file except in compliance with the License.
|
|
501
|
+
* You may obtain a copy of the License at
|
|
502
|
+
*
|
|
503
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
504
|
+
*
|
|
505
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
506
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
507
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
508
|
+
* See the License for the specific language governing permissions and
|
|
509
|
+
* limitations under the License.
|
|
510
|
+
* =============================================================================
|
|
511
|
+
*/
|
|
512
|
+
function kt(e, t) {
|
|
513
|
+
if (e.length !== t.length)
|
|
514
|
+
throw new Error(`Cannot merge real and imag arrays of different lengths. real:${e.length}, imag: ${t.length}.`);
|
|
515
|
+
const n = new Float32Array(e.length * 2);
|
|
516
|
+
for (let r = 0; r < n.length; r += 2)
|
|
517
|
+
n[r] = e[r / 2], n[r + 1] = t[r / 2];
|
|
518
|
+
return n;
|
|
519
|
+
}
|
|
520
|
+
function Pt(e) {
|
|
521
|
+
const t = new Float32Array(e.length / 2), n = new Float32Array(e.length / 2);
|
|
522
|
+
for (let r = 0; r < e.length; r += 2)
|
|
523
|
+
t[r / 2] = e[r], n[r / 2] = e[r + 1];
|
|
524
|
+
return { real: t, imag: n };
|
|
525
|
+
}
|
|
526
|
+
function Wt(e) {
|
|
527
|
+
const t = Math.ceil(e.length / 4), n = new Float32Array(t), r = new Float32Array(t);
|
|
528
|
+
for (let o = 0; o < e.length; o += 4)
|
|
529
|
+
n[Math.floor(o / 4)] = e[o], r[Math.floor(o / 4)] = e[o + 1];
|
|
530
|
+
return { real: n, imag: r };
|
|
531
|
+
}
|
|
532
|
+
function Vt(e) {
|
|
533
|
+
const t = Math.floor(e.length / 4), n = new Float32Array(t), r = new Float32Array(t);
|
|
534
|
+
for (let o = 2; o < e.length; o += 4)
|
|
535
|
+
n[Math.floor(o / 4)] = e[o], r[Math.floor(o / 4)] = e[o + 1];
|
|
536
|
+
return { real: n, imag: r };
|
|
537
|
+
}
|
|
538
|
+
function Ht(e, t) {
|
|
539
|
+
const n = e[t * 2], r = e[t * 2 + 1];
|
|
540
|
+
return { real: n, imag: r };
|
|
541
|
+
}
|
|
542
|
+
function Xt(e, t, n, r) {
|
|
543
|
+
e[r * 2] = t, e[r * 2 + 1] = n;
|
|
544
|
+
}
|
|
545
|
+
function Gt(e, t) {
|
|
546
|
+
const n = new Float32Array(e / 2), r = new Float32Array(e / 2);
|
|
547
|
+
for (let o = 0; o < Math.ceil(e / 2); o++) {
|
|
548
|
+
const a = (t ? 2 : -2) * Math.PI * (o / e);
|
|
549
|
+
n[o] = Math.cos(a), r[o] = Math.sin(a);
|
|
550
|
+
}
|
|
551
|
+
return { real: n, imag: r };
|
|
552
|
+
}
|
|
553
|
+
function zt(e, t, n) {
|
|
554
|
+
const r = (n ? 2 : -2) * Math.PI * (e / t), o = Math.cos(r), a = Math.sin(r);
|
|
555
|
+
return { real: o, imag: a };
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* @license
|
|
559
|
+
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
560
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
561
|
+
* you may not use this file except in compliance with the License.
|
|
562
|
+
* You may obtain a copy of the License at
|
|
563
|
+
*
|
|
564
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
565
|
+
*
|
|
566
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
567
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
568
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
569
|
+
* See the License for the specific language governing permissions and
|
|
570
|
+
* limitations under the License.
|
|
571
|
+
* =============================================================================
|
|
572
|
+
*/
|
|
573
|
+
const H = "->", qt = /->/g, oe = ",", ae = "...";
|
|
574
|
+
function jt(e, t) {
|
|
575
|
+
e = e.replace(/\s/g, "");
|
|
576
|
+
const n = (e.length - e.replace(qt, "").length) / H.length;
|
|
577
|
+
if (n < 1)
|
|
578
|
+
throw new Error("Equations without an arrow are not supported.");
|
|
579
|
+
if (n > 1)
|
|
580
|
+
throw new Error(`Equation must contain exactly one arrow ("${H}").`);
|
|
581
|
+
const [r, o] = e.split(H);
|
|
582
|
+
$(r.indexOf(ae) === -1, () => `The ellipsis notation ("${ae}") is not supported yet.`);
|
|
583
|
+
const a = r.split(oe), s = a.length;
|
|
584
|
+
if (t !== s)
|
|
585
|
+
throw new Error(`Expected ${s} input tensors, received ${t}`);
|
|
586
|
+
if (s > 2)
|
|
587
|
+
throw new Error("Support for more than 2 input tensors is not implemented yet.");
|
|
588
|
+
const i = [];
|
|
589
|
+
for (let h = 0; h < o.length; ++h) {
|
|
590
|
+
const d = o[h];
|
|
591
|
+
if (!a.some((p) => p.indexOf(d) !== -1))
|
|
592
|
+
throw new Error(`Output subscripts contain the label ${d} not present in the input subscripts.`);
|
|
593
|
+
i.indexOf(d) === -1 && i.push(d);
|
|
594
|
+
}
|
|
595
|
+
for (let h = 0; h < r.length; ++h) {
|
|
596
|
+
const d = r[h];
|
|
597
|
+
i.indexOf(d) === -1 && d !== oe && i.push(d);
|
|
598
|
+
}
|
|
599
|
+
const c = new Array(a.length);
|
|
600
|
+
for (let h = 0; h < s; ++h) {
|
|
601
|
+
if (new Set(a[h].split("")).size !== a[h].length)
|
|
602
|
+
throw new Error(`Found duplicate axes in input component ${a[h]}. Support for duplicate axes in input is not implemented yet.`);
|
|
603
|
+
c[h] = [];
|
|
604
|
+
for (let d = 0; d < a[h].length; ++d)
|
|
605
|
+
c[h].push(i.indexOf(a[h][d]));
|
|
606
|
+
}
|
|
607
|
+
const l = i.length, f = o.length, u = [];
|
|
608
|
+
for (let h = f; h < l; ++h)
|
|
609
|
+
u.push(h);
|
|
610
|
+
return { allDims: i, summedDims: u, idDims: c };
|
|
611
|
+
}
|
|
612
|
+
function Jt(e, t) {
|
|
613
|
+
let n = new Array(e);
|
|
614
|
+
n.fill(-1);
|
|
615
|
+
for (let o = 0; o < t.length; ++o)
|
|
616
|
+
n[t[o]] = o;
|
|
617
|
+
const r = [];
|
|
618
|
+
for (let o = 0; o < e; ++o)
|
|
619
|
+
n[o] === -1 && r.push(o);
|
|
620
|
+
return n = n.filter((o) => o !== -1), { permutationIndices: n, expandDims: r };
|
|
621
|
+
}
|
|
622
|
+
function Yt(e, t, n) {
|
|
623
|
+
const r = new Array(e);
|
|
624
|
+
for (let o = 0; o < n.length; ++o) {
|
|
625
|
+
const a = n[o].shape;
|
|
626
|
+
for (let s = 0; s < t[o].length; ++s)
|
|
627
|
+
r[t[o][s]] === void 0 ? r[t[o][s]] = a[s] : $(r[t[o][s]] === a[s], () => `Expected dimension ${r[t[o][s]]} at axis ${s} of input shaped ${JSON.stringify(a)}, but got dimension ${a[s]}`);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
function Kt(e, t) {
|
|
631
|
+
const n = e, r = [];
|
|
632
|
+
let o = 0;
|
|
633
|
+
e.length === 0 && n.push(-1), o = e.length + 1;
|
|
634
|
+
for (let s = 0; s < o; ++s)
|
|
635
|
+
r.push([]);
|
|
636
|
+
const a = [];
|
|
637
|
+
for (let s = 0; s < n.length; ++s) {
|
|
638
|
+
const i = n[s], c = Qt(t, i);
|
|
639
|
+
for (const l of c)
|
|
640
|
+
a.indexOf(l) === -1 && (r[s].push(l), a.push(l));
|
|
641
|
+
}
|
|
642
|
+
return { path: n, steps: r };
|
|
643
|
+
}
|
|
644
|
+
function Zt(e) {
|
|
645
|
+
return e.every((t, n) => t === n);
|
|
646
|
+
}
|
|
647
|
+
function Qt(e, t) {
|
|
648
|
+
const n = [];
|
|
649
|
+
for (let r = 0; r < e.length; ++r)
|
|
650
|
+
(e[r].length === 0 || e[r].indexOf(t) !== -1 || t === -1) && n.push(r);
|
|
651
|
+
return n;
|
|
652
|
+
}
|
|
653
|
+
function en(e, t, n = 0) {
|
|
654
|
+
let r = [];
|
|
655
|
+
if (typeof t == "number")
|
|
656
|
+
$(e.shape[n] % t === 0, () => "Number of splits must evenly divide the axis."), r = new Array(t).fill(e.shape[n] / t);
|
|
657
|
+
else {
|
|
658
|
+
const o = t.reduce((s, i) => (i === -1 && (s += 1), s), 0);
|
|
659
|
+
$(o <= 1, () => "There should be only one negative value in split array.");
|
|
660
|
+
const a = t.indexOf(-1);
|
|
661
|
+
if (a !== -1) {
|
|
662
|
+
const s = t.reduce((i, c) => c > 0 ? i + c : i);
|
|
663
|
+
t[a] = e.shape[n] - s;
|
|
664
|
+
}
|
|
665
|
+
$(e.shape[n] === t.reduce((s, i) => s + i), () => "The sum of sizes must match the size of the axis dimension."), r = t;
|
|
666
|
+
}
|
|
667
|
+
return r;
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* @license
|
|
671
|
+
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
672
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
673
|
+
* you may not use this file except in compliance with the License.
|
|
674
|
+
* You may obtain a copy of the License at
|
|
675
|
+
*
|
|
676
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
677
|
+
*
|
|
678
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
679
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
680
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
681
|
+
* See the License for the specific language governing permissions and
|
|
682
|
+
* limitations under the License.
|
|
683
|
+
* =============================================================================
|
|
684
|
+
*/
|
|
685
|
+
function tn(e) {
|
|
686
|
+
return `Received SparseTensor with denseShape[0] = 0 but
|
|
687
|
+
indices.shape[0] = ${e}`;
|
|
688
|
+
}
|
|
689
|
+
function nn(e, t) {
|
|
690
|
+
return `indices(${e}, 0) is invalid: ${t} < 0`;
|
|
691
|
+
}
|
|
692
|
+
function rn(e, t, n) {
|
|
693
|
+
return `indices(${e}, 0) is invalid: ${t} >= ${n}`;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* @license
|
|
697
|
+
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
698
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
699
|
+
* you may not use this file except in compliance with the License.
|
|
700
|
+
* You may obtain a copy of the License at
|
|
701
|
+
*
|
|
702
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
703
|
+
*
|
|
704
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
705
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
706
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
707
|
+
* See the License for the specific language governing permissions and
|
|
708
|
+
* limitations under the License.
|
|
709
|
+
* =============================================================================
|
|
710
|
+
*/
|
|
711
|
+
function on(e, t) {
|
|
712
|
+
return `only one output dimension may be -1, not both ${e} and ${t}`;
|
|
713
|
+
}
|
|
714
|
+
function an(e, t) {
|
|
715
|
+
return `size ${e} must be non-negative, not ${t}`;
|
|
716
|
+
}
|
|
717
|
+
function sn() {
|
|
718
|
+
return "reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero";
|
|
719
|
+
}
|
|
720
|
+
function cn(e, t) {
|
|
721
|
+
const n = T(e), r = T(t);
|
|
722
|
+
return `Input to reshape is a SparseTensor with ${n}
|
|
723
|
+
dense values, but the requested shape requires a multiple of ${r}. inputShape=${e} outputShape= ${t}`;
|
|
724
|
+
}
|
|
725
|
+
function un(e, t) {
|
|
726
|
+
const n = T(e), r = T(t);
|
|
727
|
+
return `Input to reshape is a tensor with ${n} dense values, but the requested shape has ${r}. inputShape=${e} outputShape=${t}`;
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* @license
|
|
731
|
+
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
732
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
733
|
+
* you may not use this file except in compliance with the License.
|
|
734
|
+
* You may obtain a copy of the License at
|
|
735
|
+
*
|
|
736
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
737
|
+
*
|
|
738
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
739
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
740
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
741
|
+
* See the License for the specific language governing permissions and
|
|
742
|
+
* limitations under the License.
|
|
743
|
+
* =============================================================================
|
|
744
|
+
*/
|
|
745
|
+
function ln() {
|
|
746
|
+
return "segment ids must be >= 0";
|
|
747
|
+
}
|
|
748
|
+
function fn() {
|
|
749
|
+
return "segment ids are not increasing";
|
|
750
|
+
}
|
|
751
|
+
function hn(e, t) {
|
|
752
|
+
return `Segment id ${e} out of range [0, ${t}), possibly because segmentIds input is not sorted.`;
|
|
753
|
+
}
|
|
754
|
+
function dn(e, t, n) {
|
|
755
|
+
return `Bad: indices[${e}] == ${t} out of range [0, ${n})`;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* @license
|
|
759
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
760
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
761
|
+
* you may not use this file except in compliance with the License.
|
|
762
|
+
* You may obtain a copy of the License at
|
|
763
|
+
*
|
|
764
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
765
|
+
*
|
|
766
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
767
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
768
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
769
|
+
* See the License for the specific language governing permissions and
|
|
770
|
+
* limitations under the License.
|
|
771
|
+
* =============================================================================
|
|
772
|
+
*/
|
|
773
|
+
function pn(e, t) {
|
|
774
|
+
let n = !1, r;
|
|
775
|
+
for (e <= K ? (r = e, n = !0) : r = z(e, Math.floor(Math.sqrt(e))); !n; )
|
|
776
|
+
r > t || r === e ? n = !0 : r = z(e, r + 1);
|
|
777
|
+
return r;
|
|
778
|
+
}
|
|
779
|
+
function xn(e, t, n) {
|
|
780
|
+
const r = [], o = e.length;
|
|
781
|
+
for (let a = 0; a < o; a++)
|
|
782
|
+
a !== t ? r.push(e[a]) : r.push(n);
|
|
783
|
+
return r;
|
|
784
|
+
}
|
|
785
|
+
function mn(e, t, n, r) {
|
|
786
|
+
const o = t.shape.length, a = e.shape.length;
|
|
787
|
+
if (r !== 0 && (r < -o || r > o))
|
|
788
|
+
throw new Error(`Expect batchDims in the range of [-${o}, ${o}], but got ${r}`);
|
|
789
|
+
if (r < 0 && (r += o), r > a)
|
|
790
|
+
throw new Error(`batchDims (${r}) must be less than rank(x) (
|
|
791
|
+
${a}).`);
|
|
792
|
+
if (n < r)
|
|
793
|
+
throw new Error(`batchDims (${r}) must be less than or equal to axis (${n}).`);
|
|
794
|
+
for (let u = 0; u < r; ++u)
|
|
795
|
+
if (e.shape[u] !== t.shape[u])
|
|
796
|
+
throw new Error(`x.shape[${u}]: ${e.shape[u]} should be equal to indices.shape[${u}]: ${t.shape[u]}.`);
|
|
797
|
+
const s = e.shape[n], i = [];
|
|
798
|
+
let c = 1, l = 1, f = 1;
|
|
799
|
+
for (let u = 0; u < r; ++u)
|
|
800
|
+
i.push(e.shape[u]), c *= e.shape[u];
|
|
801
|
+
for (let u = r; u < n; u++)
|
|
802
|
+
i.push(e.shape[u]), l *= e.shape[u];
|
|
803
|
+
for (let u = r; u < o; u++)
|
|
804
|
+
i.push(t.shape[u]);
|
|
805
|
+
for (let u = n + 1; u < a; u++)
|
|
806
|
+
i.push(e.shape[u]), f *= e.shape[u];
|
|
807
|
+
return { batchSize: c, sliceSize: f, outerSize: l, dimSize: s, outputShape: i };
|
|
808
|
+
}
|
|
809
|
+
const vn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
810
|
+
__proto__: null,
|
|
811
|
+
collectGatherOpShapeInfo: mn,
|
|
812
|
+
computeOutShape: xn,
|
|
813
|
+
segOpComputeOptimalWindowSize: pn
|
|
814
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
815
|
+
/**
|
|
816
|
+
* @license
|
|
817
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
818
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
819
|
+
* you may not use this file except in compliance with the License.
|
|
820
|
+
* You may obtain a copy of the License at
|
|
821
|
+
*
|
|
822
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
823
|
+
*
|
|
824
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
825
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
826
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
827
|
+
* See the License for the specific language governing permissions and
|
|
828
|
+
* limitations under the License.
|
|
829
|
+
* =============================================================================
|
|
830
|
+
*/
|
|
831
|
+
function $n(e) {
|
|
832
|
+
try {
|
|
833
|
+
return e.map((t) => Ce(t));
|
|
834
|
+
} catch (t) {
|
|
835
|
+
throw new Error(`Failed to decode encoded string bytes into utf-8, error: ${t}`);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
function Tn(e) {
|
|
839
|
+
return e.map((t) => Fe(t));
|
|
840
|
+
}
|
|
841
|
+
const Sn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
842
|
+
__proto__: null,
|
|
843
|
+
ERF_A1: Dt,
|
|
844
|
+
ERF_A2: bt,
|
|
845
|
+
ERF_A3: Ut,
|
|
846
|
+
ERF_A4: Mt,
|
|
847
|
+
ERF_A5: Bt,
|
|
848
|
+
ERF_P: Lt,
|
|
849
|
+
PARALLELIZE_THRESHOLD: K,
|
|
850
|
+
get RowPartitionType() {
|
|
851
|
+
return R;
|
|
852
|
+
},
|
|
853
|
+
SELU_SCALE: We,
|
|
854
|
+
SELU_SCALEALPHA: Ve,
|
|
855
|
+
applyActivation: He,
|
|
856
|
+
assertAndGetBroadcastShape: Ae,
|
|
857
|
+
assertAxesAreInnerMostDims: Le,
|
|
858
|
+
assertParamsConsistent: St,
|
|
859
|
+
assignToTypedArray: Xt,
|
|
860
|
+
axesAreInnerMostDims: De,
|
|
861
|
+
calculateShapes: at,
|
|
862
|
+
checkEinsumDimSizes: Yt,
|
|
863
|
+
checkPadOnDimRoundingMode: Xe,
|
|
864
|
+
combineLocations: be,
|
|
865
|
+
combineRaggedTensorToTensorShapes: Rt,
|
|
866
|
+
complexWithEvenIndex: Wt,
|
|
867
|
+
complexWithOddIndex: Vt,
|
|
868
|
+
computeConv2DInfo: Ge,
|
|
869
|
+
computeConv3DInfo: ze,
|
|
870
|
+
computeDefaultPad: qe,
|
|
871
|
+
computeDilation2DInfo: je,
|
|
872
|
+
computeOptimalWindowSize: Ft,
|
|
873
|
+
computeOutAndReduceShapes: Ue,
|
|
874
|
+
computeOutShape: Et,
|
|
875
|
+
computePool2DInfo: Je,
|
|
876
|
+
computePool3DInfo: Ye,
|
|
877
|
+
convertConv2DDataFormat: Ke,
|
|
878
|
+
decodeEinsumEquation: jt,
|
|
879
|
+
eitherStridesOrDilationsAreOne: Ze,
|
|
880
|
+
expandShapeToKeepDim: Me,
|
|
881
|
+
exponent: zt,
|
|
882
|
+
exponents: Gt,
|
|
883
|
+
fromStringArrayToUint8: Tn,
|
|
884
|
+
fromUint8ToStringArray: $n,
|
|
885
|
+
getAxesPermutation: Be,
|
|
886
|
+
getBroadcastDims: de,
|
|
887
|
+
getComplexWithIndex: Ht,
|
|
888
|
+
getEinsumComputePath: Kt,
|
|
889
|
+
getEinsumPermutation: Jt,
|
|
890
|
+
getFusedBiasGradient: Qe,
|
|
891
|
+
getFusedDyActivation: et,
|
|
892
|
+
getImageCenter: At,
|
|
893
|
+
getInnerMostAxes: ke,
|
|
894
|
+
getPermuted: It,
|
|
895
|
+
getRaggedRank: wt,
|
|
896
|
+
getReductionAxes: _e,
|
|
897
|
+
getReshaped: _t,
|
|
898
|
+
getReshapedPermuted: Ot,
|
|
899
|
+
getRowPartitionTypesHelper: gt,
|
|
900
|
+
getSliceBeginCoords: Nt,
|
|
901
|
+
getSliceSize: yt,
|
|
902
|
+
getSparseFillEmptyRowsIndicesDenseShapeMismatch: tn,
|
|
903
|
+
getSparseFillEmptyRowsNegativeIndexErrorMessage: nn,
|
|
904
|
+
getSparseFillEmptyRowsOutOfRangeIndexErrorMessage: rn,
|
|
905
|
+
getSparseReshapeEmptyTensorZeroOutputDimErrorMessage: sn,
|
|
906
|
+
getSparseReshapeInputOutputMismatchErrorMessage: un,
|
|
907
|
+
getSparseReshapeInputOutputMultipleErrorMessage: cn,
|
|
908
|
+
getSparseReshapeMultipleNegativeOneOutputDimErrorMessage: on,
|
|
909
|
+
getSparseReshapeNegativeOutputDimErrorMessage: an,
|
|
910
|
+
getSparseSegmentReductionIndicesOutOfRangeErrorMessage: dn,
|
|
911
|
+
getSparseSegmentReductionNegativeSegmentIdsErrorMessage: ln,
|
|
912
|
+
getSparseSegmentReductionNonIncreasingSegmentIdsErrorMessage: fn,
|
|
913
|
+
getSparseSegmentReductionSegmentIdOutOfRangeErrorMessage: hn,
|
|
914
|
+
getUndoAxesPermutation: Pe,
|
|
915
|
+
isIdentityPermutation: Zt,
|
|
916
|
+
log: Ie,
|
|
917
|
+
mergeRealAndImagArrays: kt,
|
|
918
|
+
prepareAndValidate: Tt,
|
|
919
|
+
prepareSplitSize: en,
|
|
920
|
+
segment_util: vn,
|
|
921
|
+
shouldFuse: tt,
|
|
922
|
+
slice_util: nt,
|
|
923
|
+
splitRealAndImagArrays: Pt,
|
|
924
|
+
stridesOrDilationsArePositive: rt,
|
|
925
|
+
tupleValuesAreOne: ot,
|
|
926
|
+
upcastType: Oe,
|
|
927
|
+
validateDefaultValueShape: Ct,
|
|
928
|
+
validateInput: st,
|
|
929
|
+
validateUpdateShape: it,
|
|
930
|
+
warn: Ne
|
|
931
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
932
|
+
/**
|
|
933
|
+
* @license
|
|
934
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
935
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
936
|
+
* you may not use this file except in compliance with the License.
|
|
937
|
+
* You may obtain a copy of the License at
|
|
938
|
+
*
|
|
939
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
940
|
+
*
|
|
941
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
942
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
943
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
944
|
+
* See the License for the specific language governing permissions and
|
|
945
|
+
* limitations under the License.
|
|
946
|
+
* =============================================================================
|
|
947
|
+
*/
|
|
948
|
+
function b() {
|
|
949
|
+
let e, t, n, r, o, a, s, i, c, l;
|
|
950
|
+
return m().getNumber("WEBGL_VERSION") === 2 ? (e = "#version 300 es", t = "in", n = "out", r = "in", o = "texture", a = "outputColor", s = "out vec4 outputColor;", i = m().getBool("WEBGL2_ISNAN_CUSTOM") ? `
|
|
951
|
+
bool isnan_custom(float val) {
|
|
952
|
+
uint floatToUint = floatBitsToUint(val);
|
|
953
|
+
return (floatToUint & 0x7fffffffu) > 0x7f800000u;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
bvec4 isnan_custom(vec4 val) {
|
|
957
|
+
return bvec4(isnan_custom(val.x),
|
|
958
|
+
isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
#define isnan(value) isnan_custom(value)
|
|
962
|
+
` : "", c = "", l = `
|
|
963
|
+
#define round(value) newRound(value)
|
|
964
|
+
int newRound(float value) {
|
|
965
|
+
return int(floor(value + 0.5));
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
ivec4 newRound(vec4 value) {
|
|
969
|
+
return ivec4(floor(value + vec4(0.5)));
|
|
970
|
+
}
|
|
971
|
+
`) : (e = "", t = "attribute", n = "varying", r = "varying", o = "texture2D", a = "gl_FragColor", s = "", i = `
|
|
972
|
+
#define isnan(value) isnan_custom(value)
|
|
973
|
+
bool isnan_custom(float val) {
|
|
974
|
+
return (val > 0. || val < 1. || val == 0.) ? false : true;
|
|
975
|
+
}
|
|
976
|
+
bvec4 isnan_custom(vec4 val) {
|
|
977
|
+
return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));
|
|
978
|
+
}
|
|
979
|
+
`, c = `
|
|
980
|
+
uniform float INFINITY;
|
|
981
|
+
|
|
982
|
+
bool isinf(float val) {
|
|
983
|
+
return abs(val) == INFINITY;
|
|
984
|
+
}
|
|
985
|
+
bvec4 isinf(vec4 val) {
|
|
986
|
+
return equal(abs(val), vec4(INFINITY));
|
|
987
|
+
}
|
|
988
|
+
`, l = `
|
|
989
|
+
int round(float value) {
|
|
990
|
+
return int(floor(value + 0.5));
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
ivec4 round(vec4 value) {
|
|
994
|
+
return ivec4(floor(value + vec4(0.5)));
|
|
995
|
+
}
|
|
996
|
+
`), {
|
|
997
|
+
version: e,
|
|
998
|
+
attribute: t,
|
|
999
|
+
varyingVs: n,
|
|
1000
|
+
varyingFs: r,
|
|
1001
|
+
texture2D: o,
|
|
1002
|
+
output: a,
|
|
1003
|
+
defineOutput: s,
|
|
1004
|
+
defineSpecialNaN: i,
|
|
1005
|
+
defineSpecialInf: c,
|
|
1006
|
+
defineRound: l
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* @license
|
|
1011
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
1012
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1013
|
+
* you may not use this file except in compliance with the License.
|
|
1014
|
+
* You may obtain a copy of the License at
|
|
1015
|
+
*
|
|
1016
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1017
|
+
*
|
|
1018
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1019
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1020
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1021
|
+
* See the License for the specific language governing permissions and
|
|
1022
|
+
* limitations under the License.
|
|
1023
|
+
* =============================================================================
|
|
1024
|
+
*/
|
|
1025
|
+
function V(e, t, n = "index") {
|
|
1026
|
+
const r = D(t);
|
|
1027
|
+
return r.map((o, a) => {
|
|
1028
|
+
const s = `int ${e[a]} = ${n} / ${o}`, i = a === r.length - 1 ? `int ${e[a + 1]} = ${n} - ${e[a]} * ${o}` : `index -= ${e[a]} * ${o}`;
|
|
1029
|
+
return `${s}; ${i};`;
|
|
1030
|
+
}).join("");
|
|
1031
|
+
}
|
|
1032
|
+
function xe(e, t, n = "index") {
|
|
1033
|
+
const r = D(t);
|
|
1034
|
+
return r.map((o, a) => {
|
|
1035
|
+
const s = `int ${e[a]} = ${n} / outShapeStrides[${a}]`, i = a === r.length - 1 ? `int ${e[a + 1]} = ${n} - ${e[a]} * outShapeStrides[${a}]` : `index -= ${e[a]} * outShapeStrides[${a}]`;
|
|
1036
|
+
return `${s}; ${i};`;
|
|
1037
|
+
}).join("");
|
|
1038
|
+
}
|
|
1039
|
+
function En(e, t) {
|
|
1040
|
+
const n = e.length, r = e.map((a) => `${t}[${a}]`), o = new Array(n - 1);
|
|
1041
|
+
o[n - 2] = r[n - 1];
|
|
1042
|
+
for (let a = n - 3; a >= 0; --a)
|
|
1043
|
+
o[a] = `(${o[a + 1]} * ${r[a + 1]})`;
|
|
1044
|
+
return o;
|
|
1045
|
+
}
|
|
1046
|
+
function wr(e, t, n = "index") {
|
|
1047
|
+
const r = e.map((a, s) => s), o = En(r, t);
|
|
1048
|
+
return o.map((a, s) => {
|
|
1049
|
+
const i = `int ${e[s]} = ${n} / ${o[s]}`, c = s === o.length - 1 ? `int ${e[s + 1]} = ${n} - ${e[s]} * ${o[s]}` : `index -= ${e[s]} * ${o[s]}`;
|
|
1050
|
+
return `${i}; ${c};`;
|
|
1051
|
+
}).join("");
|
|
1052
|
+
}
|
|
1053
|
+
function Cr(e) {
|
|
1054
|
+
const t = D(e).map((n) => n.toString());
|
|
1055
|
+
return `
|
|
1056
|
+
int getFlatIndex(ivec3 coords) {
|
|
1057
|
+
return coords.x * ${t[0]} + coords.y * ${t[1]} + coords.z;
|
|
1058
|
+
}
|
|
1059
|
+
`;
|
|
1060
|
+
}
|
|
1061
|
+
function Fr() {
|
|
1062
|
+
return `
|
|
1063
|
+
int getFlatIndex(ivec3 coords) {
|
|
1064
|
+
return coords.x * outShapeStrides[0] + coords.y * outShapeStrides[1] + coords.z;
|
|
1065
|
+
}
|
|
1066
|
+
`;
|
|
1067
|
+
}
|
|
1068
|
+
const Ar = `
|
|
1069
|
+
const float FLOAT_MAX = 1.70141184e38;
|
|
1070
|
+
const float FLOAT_MIN = 1.17549435e-38;
|
|
1071
|
+
|
|
1072
|
+
lowp vec4 encode_float(highp float v) {
|
|
1073
|
+
if (isnan(v)) {
|
|
1074
|
+
return vec4(255, 255, 255, 255);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
highp float av = abs(v);
|
|
1078
|
+
|
|
1079
|
+
if(av < FLOAT_MIN) {
|
|
1080
|
+
return vec4(0.0, 0.0, 0.0, 0.0);
|
|
1081
|
+
} else if(v > FLOAT_MAX) {
|
|
1082
|
+
return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;
|
|
1083
|
+
} else if(v < -FLOAT_MAX) {
|
|
1084
|
+
return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
highp vec4 c = vec4(0,0,0,0);
|
|
1088
|
+
|
|
1089
|
+
highp float e = floor(log2(av));
|
|
1090
|
+
highp float m = exp2(fract(log2(av))) - 1.0;
|
|
1091
|
+
|
|
1092
|
+
c[2] = floor(128.0 * m);
|
|
1093
|
+
m -= c[2] / 128.0;
|
|
1094
|
+
c[1] = floor(32768.0 * m);
|
|
1095
|
+
m -= c[1] / 32768.0;
|
|
1096
|
+
c[0] = floor(8388608.0 * m);
|
|
1097
|
+
|
|
1098
|
+
highp float ebias = e + 127.0;
|
|
1099
|
+
c[3] = floor(ebias / 2.0);
|
|
1100
|
+
ebias -= c[3] * 2.0;
|
|
1101
|
+
c[2] += floor(ebias) * 128.0;
|
|
1102
|
+
|
|
1103
|
+
c[3] += 128.0 * step(0.0, -v);
|
|
1104
|
+
|
|
1105
|
+
return c / 255.0;
|
|
1106
|
+
}
|
|
1107
|
+
`;
|
|
1108
|
+
/**
|
|
1109
|
+
* @license
|
|
1110
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
1111
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1112
|
+
* you may not use this file except in compliance with the License.
|
|
1113
|
+
* You may obtain a copy of the License at
|
|
1114
|
+
*
|
|
1115
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1116
|
+
*
|
|
1117
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1118
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1119
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1120
|
+
* See the License for the specific language governing permissions and
|
|
1121
|
+
* limitations under the License.
|
|
1122
|
+
* =============================================================================
|
|
1123
|
+
*/
|
|
1124
|
+
const { getBroadcastDims: me } = Sn;
|
|
1125
|
+
function Rn(e, t, n) {
|
|
1126
|
+
const r = [];
|
|
1127
|
+
if (e.forEach((d) => {
|
|
1128
|
+
const p = T(d.shapeInfo.logicalShape);
|
|
1129
|
+
if (d.shapeInfo.isUniform ? r.push(`uniform float ${d.name}${p > 1 ? `[${p}]` : ""};`) : (r.push(`uniform sampler2D ${d.name};`), r.push(`uniform int offset${d.name};`)), n.enableShapeUniforms) {
|
|
1130
|
+
const { uniformShape: x } = Z(n.packedInputs, d.shapeInfo.logicalShape, d.shapeInfo.texShape);
|
|
1131
|
+
switch (x.length) {
|
|
1132
|
+
case 1:
|
|
1133
|
+
r.push(`uniform int ${d.name}Shape;`);
|
|
1134
|
+
break;
|
|
1135
|
+
case 2:
|
|
1136
|
+
r.push(`uniform ivec2 ${d.name}Shape;`);
|
|
1137
|
+
break;
|
|
1138
|
+
case 3:
|
|
1139
|
+
r.push(`uniform ivec3 ${d.name}Shape;`);
|
|
1140
|
+
break;
|
|
1141
|
+
case 4:
|
|
1142
|
+
r.push(`uniform ivec4 ${d.name}Shape;`);
|
|
1143
|
+
break;
|
|
1144
|
+
}
|
|
1145
|
+
r.push(`uniform ivec2 ${d.name}TexShape;`);
|
|
1146
|
+
}
|
|
1147
|
+
}), n.enableShapeUniforms) {
|
|
1148
|
+
switch (t.logicalShape.length) {
|
|
1149
|
+
case 1:
|
|
1150
|
+
r.push("uniform int outShape;");
|
|
1151
|
+
break;
|
|
1152
|
+
case 2:
|
|
1153
|
+
r.push("uniform ivec2 outShape;"), r.push("uniform int outShapeStrides;");
|
|
1154
|
+
break;
|
|
1155
|
+
case 3:
|
|
1156
|
+
r.push("uniform ivec3 outShape;"), r.push("uniform ivec2 outShapeStrides;");
|
|
1157
|
+
break;
|
|
1158
|
+
case 4:
|
|
1159
|
+
r.push("uniform ivec4 outShape;"), r.push("uniform ivec3 outShapeStrides;");
|
|
1160
|
+
break;
|
|
1161
|
+
}
|
|
1162
|
+
r.push("uniform ivec2 outTexShape;");
|
|
1163
|
+
}
|
|
1164
|
+
n.customUniforms && n.customUniforms.forEach((d) => {
|
|
1165
|
+
r.push(`uniform ${d.type} ${d.name}${d.arrayIndex ? `[${d.arrayIndex}]` : ""};`);
|
|
1166
|
+
});
|
|
1167
|
+
const o = r.join(`
|
|
1168
|
+
`), a = e.map((d) => gn(d, t, n.packedInputs, n.enableShapeUniforms)).join(`
|
|
1169
|
+
`), s = t.texShape, i = b(), c = Fn(i);
|
|
1170
|
+
let l, f, u = In(i);
|
|
1171
|
+
return t.isPacked ? (l = wn(t.logicalShape, s, n.enableShapeUniforms), f = _n(i)) : (l = Cn(t.logicalShape, s, n.enableShapeUniforms), f = An(i)), n.packedInputs && (u += Ln), [
|
|
1172
|
+
u,
|
|
1173
|
+
c,
|
|
1174
|
+
f,
|
|
1175
|
+
o,
|
|
1176
|
+
l,
|
|
1177
|
+
a,
|
|
1178
|
+
n.userCode
|
|
1179
|
+
].join(`
|
|
1180
|
+
`);
|
|
1181
|
+
}
|
|
1182
|
+
function U(e, t = !1) {
|
|
1183
|
+
const n = e.shapeInfo.logicalShape;
|
|
1184
|
+
switch (n.length) {
|
|
1185
|
+
case 0:
|
|
1186
|
+
return Gn(e, t);
|
|
1187
|
+
case 1:
|
|
1188
|
+
return qn(e, t);
|
|
1189
|
+
case 2:
|
|
1190
|
+
return Jn(e, t);
|
|
1191
|
+
case 3:
|
|
1192
|
+
return Kn(e, t);
|
|
1193
|
+
case 4:
|
|
1194
|
+
return Qn(e, t);
|
|
1195
|
+
case 5:
|
|
1196
|
+
return er(e);
|
|
1197
|
+
case 6:
|
|
1198
|
+
return tr(e);
|
|
1199
|
+
default:
|
|
1200
|
+
throw new Error(`${n.length}-D input sampling is not yet supported`);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
function ve(e, t) {
|
|
1204
|
+
switch (e.shapeInfo.logicalShape.length) {
|
|
1205
|
+
case 0:
|
|
1206
|
+
return Xn(e);
|
|
1207
|
+
case 1:
|
|
1208
|
+
return zn(e, t);
|
|
1209
|
+
case 2:
|
|
1210
|
+
return jn(e, t);
|
|
1211
|
+
case 3:
|
|
1212
|
+
return Yn(e, t);
|
|
1213
|
+
default:
|
|
1214
|
+
return Zn(e, t);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
function gn(e, t, n = !1, r) {
|
|
1218
|
+
let o = "";
|
|
1219
|
+
n ? o += ve(e, r) : o += U(e, r);
|
|
1220
|
+
const a = e.shapeInfo.logicalShape, s = t.logicalShape;
|
|
1221
|
+
return a.length <= s.length && (n ? o += nr(e, t) : o += rr(e, t)), o;
|
|
1222
|
+
}
|
|
1223
|
+
function wn(e, t, n) {
|
|
1224
|
+
switch (e.length) {
|
|
1225
|
+
case 0:
|
|
1226
|
+
return $e();
|
|
1227
|
+
case 1:
|
|
1228
|
+
return Dn(e, t, n);
|
|
1229
|
+
case 2:
|
|
1230
|
+
return Vn(e, t, n);
|
|
1231
|
+
case 3:
|
|
1232
|
+
return Un(e, t, n);
|
|
1233
|
+
default:
|
|
1234
|
+
return Bn(e, t, n);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
function Cn(e, t, n) {
|
|
1238
|
+
switch (e.length) {
|
|
1239
|
+
case 0:
|
|
1240
|
+
return $e();
|
|
1241
|
+
case 1:
|
|
1242
|
+
return bn(e, t, n);
|
|
1243
|
+
case 2:
|
|
1244
|
+
return Hn(e, t, n);
|
|
1245
|
+
case 3:
|
|
1246
|
+
return Mn(e, t, n);
|
|
1247
|
+
case 4:
|
|
1248
|
+
return kn(e, t, n);
|
|
1249
|
+
case 5:
|
|
1250
|
+
return Pn(e, t);
|
|
1251
|
+
case 6:
|
|
1252
|
+
return Wn(e, t);
|
|
1253
|
+
default:
|
|
1254
|
+
throw new Error(`${e.length}-D output sampling is not yet supported`);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
function Fn(e) {
|
|
1258
|
+
return `
|
|
1259
|
+
float sampleTexture(sampler2D textureSampler, vec2 uv) {
|
|
1260
|
+
return ${e.texture2D}(textureSampler, uv).r;
|
|
1261
|
+
}
|
|
1262
|
+
`;
|
|
1263
|
+
}
|
|
1264
|
+
function An(e) {
|
|
1265
|
+
return `
|
|
1266
|
+
void setOutput(float val) {
|
|
1267
|
+
${e.output} = vec4(val, 0, 0, 0);
|
|
1268
|
+
}
|
|
1269
|
+
`;
|
|
1270
|
+
}
|
|
1271
|
+
function _n(e) {
|
|
1272
|
+
return `
|
|
1273
|
+
void setOutput(vec4 val) {
|
|
1274
|
+
${e.output} = val;
|
|
1275
|
+
}
|
|
1276
|
+
`;
|
|
1277
|
+
}
|
|
1278
|
+
function In(e) {
|
|
1279
|
+
return `${e.version}
|
|
1280
|
+
precision highp float;
|
|
1281
|
+
precision highp int;
|
|
1282
|
+
precision highp sampler2D;
|
|
1283
|
+
${e.varyingFs} vec2 resultUV;
|
|
1284
|
+
${e.defineOutput}
|
|
1285
|
+
const vec2 halfCR = vec2(0.5, 0.5);
|
|
1286
|
+
|
|
1287
|
+
struct ivec5
|
|
1288
|
+
{
|
|
1289
|
+
int x;
|
|
1290
|
+
int y;
|
|
1291
|
+
int z;
|
|
1292
|
+
int w;
|
|
1293
|
+
int u;
|
|
1294
|
+
};
|
|
1295
|
+
|
|
1296
|
+
struct ivec6
|
|
1297
|
+
{
|
|
1298
|
+
int x;
|
|
1299
|
+
int y;
|
|
1300
|
+
int z;
|
|
1301
|
+
int w;
|
|
1302
|
+
int u;
|
|
1303
|
+
int v;
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1306
|
+
uniform float NAN;
|
|
1307
|
+
${e.defineSpecialNaN}
|
|
1308
|
+
${e.defineSpecialInf}
|
|
1309
|
+
${e.defineRound}
|
|
1310
|
+
|
|
1311
|
+
int imod(int x, int y) {
|
|
1312
|
+
return x - y * (x / y);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
int idiv(int a, int b, float sign) {
|
|
1316
|
+
int res = a / b;
|
|
1317
|
+
int mod = imod(a, b);
|
|
1318
|
+
if (sign < 0. && mod != 0) {
|
|
1319
|
+
res -= 1;
|
|
1320
|
+
}
|
|
1321
|
+
return res;
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
//Based on the work of Dave Hoskins
|
|
1325
|
+
//https://www.shadertoy.com/view/4djSRW
|
|
1326
|
+
#define HASHSCALE1 443.8975
|
|
1327
|
+
float random(float seed){
|
|
1328
|
+
vec2 p = resultUV * seed;
|
|
1329
|
+
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);
|
|
1330
|
+
p3 += dot(p3, p3.yzx + 19.19);
|
|
1331
|
+
return fract((p3.x + p3.y) * p3.z);
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
${On}
|
|
1335
|
+
${Nn}
|
|
1336
|
+
${yn}
|
|
1337
|
+
`;
|
|
1338
|
+
}
|
|
1339
|
+
const On = `
|
|
1340
|
+
vec2 uvFromFlat(int texNumR, int texNumC, int index) {
|
|
1341
|
+
int texR = index / texNumC;
|
|
1342
|
+
int texC = index - texR * texNumC;
|
|
1343
|
+
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
1344
|
+
}
|
|
1345
|
+
vec2 packedUVfrom1D(int texNumR, int texNumC, int index) {
|
|
1346
|
+
int texelIndex = index / 2;
|
|
1347
|
+
int texR = texelIndex / texNumC;
|
|
1348
|
+
int texC = texelIndex - texR * texNumC;
|
|
1349
|
+
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
1350
|
+
}
|
|
1351
|
+
`, Nn = `
|
|
1352
|
+
vec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,
|
|
1353
|
+
int texNumC, int row, int col) {
|
|
1354
|
+
int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);
|
|
1355
|
+
int texR = texelIndex / texNumC;
|
|
1356
|
+
int texC = texelIndex - texR * texNumC;
|
|
1357
|
+
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
1358
|
+
}
|
|
1359
|
+
`, yn = `
|
|
1360
|
+
vec2 packedUVfrom3D(int texNumR, int texNumC,
|
|
1361
|
+
int texelsInBatch, int texelsInLogicalRow, int b,
|
|
1362
|
+
int row, int col) {
|
|
1363
|
+
int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);
|
|
1364
|
+
int texR = index / texNumC;
|
|
1365
|
+
int texC = index - texR * texNumC;
|
|
1366
|
+
return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
|
|
1367
|
+
}
|
|
1368
|
+
`, Ln = `
|
|
1369
|
+
float getChannel(vec4 frag, vec2 innerDims) {
|
|
1370
|
+
vec2 modCoord = mod(innerDims, 2.);
|
|
1371
|
+
return modCoord.x == 0. ?
|
|
1372
|
+
(modCoord.y == 0. ? frag.r : frag.g) :
|
|
1373
|
+
(modCoord.y == 0. ? frag.b : frag.a);
|
|
1374
|
+
}
|
|
1375
|
+
float getChannel(vec4 frag, int dim) {
|
|
1376
|
+
float modCoord = mod(float(dim), 2.);
|
|
1377
|
+
return modCoord == 0. ? frag.r : frag.g;
|
|
1378
|
+
}
|
|
1379
|
+
`;
|
|
1380
|
+
function $e() {
|
|
1381
|
+
return `
|
|
1382
|
+
int getOutputCoords() {
|
|
1383
|
+
return 0;
|
|
1384
|
+
}
|
|
1385
|
+
`;
|
|
1386
|
+
}
|
|
1387
|
+
function Dn(e, t, n) {
|
|
1388
|
+
const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
|
|
1389
|
+
return r[0] === 1 ? n ? `
|
|
1390
|
+
int getOutputCoords() {
|
|
1391
|
+
return 2 * int(resultUV.x * ceil(float(outTexShape[1]) / 2.0));
|
|
1392
|
+
}
|
|
1393
|
+
` : `
|
|
1394
|
+
int getOutputCoords() {
|
|
1395
|
+
return 2 * int(resultUV.x * ${r[1]}.0);
|
|
1396
|
+
}
|
|
1397
|
+
` : r[1] === 1 ? n ? `
|
|
1398
|
+
int getOutputCoords() {
|
|
1399
|
+
return 2 * int(resultUV.y * ceil(float(outTexShape[0]) / 2.0));
|
|
1400
|
+
}
|
|
1401
|
+
` : `
|
|
1402
|
+
int getOutputCoords() {
|
|
1403
|
+
return 2 * int(resultUV.y * ${r[0]}.0);
|
|
1404
|
+
}
|
|
1405
|
+
` : n ? `
|
|
1406
|
+
int getOutputCoords() {
|
|
1407
|
+
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
1408
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1409
|
+
vec2(packedTexShape[0], packedTexShape[1]));
|
|
1410
|
+
return 2 * (resTexRC.x * packedTexShape[1] + resTexRC.y);
|
|
1411
|
+
}
|
|
1412
|
+
` : `
|
|
1413
|
+
int getOutputCoords() {
|
|
1414
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1415
|
+
vec2(${r[0]}, ${r[1]}));
|
|
1416
|
+
return 2 * (resTexRC.x * ${r[1]} + resTexRC.y);
|
|
1417
|
+
}
|
|
1418
|
+
`;
|
|
1419
|
+
}
|
|
1420
|
+
function bn(e, t, n) {
|
|
1421
|
+
return t[0] === 1 ? n ? `
|
|
1422
|
+
int getOutputCoords() {
|
|
1423
|
+
return int(resultUV.x * float(outTexShape[1]));
|
|
1424
|
+
}
|
|
1425
|
+
` : `
|
|
1426
|
+
int getOutputCoords() {
|
|
1427
|
+
return int(resultUV.x * ${t[1]}.0);
|
|
1428
|
+
}
|
|
1429
|
+
` : t[1] === 1 ? n ? `
|
|
1430
|
+
int getOutputCoords() {
|
|
1431
|
+
return int(resultUV.y * float(outTexShape[0]));
|
|
1432
|
+
}
|
|
1433
|
+
` : `
|
|
1434
|
+
int getOutputCoords() {
|
|
1435
|
+
return int(resultUV.y * ${t[0]}.0);
|
|
1436
|
+
}
|
|
1437
|
+
` : n ? `
|
|
1438
|
+
int getOutputCoords() {
|
|
1439
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1440
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
1441
|
+
return resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
1442
|
+
}
|
|
1443
|
+
` : `
|
|
1444
|
+
int getOutputCoords() {
|
|
1445
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1446
|
+
vec2(${t[0]}, ${t[1]}));
|
|
1447
|
+
return resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1448
|
+
}
|
|
1449
|
+
`;
|
|
1450
|
+
}
|
|
1451
|
+
function Un(e, t, n) {
|
|
1452
|
+
if (n)
|
|
1453
|
+
return `
|
|
1454
|
+
ivec3 getOutputCoords() {
|
|
1455
|
+
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
1456
|
+
int texelsInLogicalRow = int(ceil(float(outShape[2]) / 2.0));
|
|
1457
|
+
int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[1]) / 2.0));
|
|
1458
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1459
|
+
vec2(packedTexShape[0], packedTexShape[1]));
|
|
1460
|
+
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
|
|
1461
|
+
|
|
1462
|
+
int b = index / texelsInBatch;
|
|
1463
|
+
index -= b * texelsInBatch;
|
|
1464
|
+
|
|
1465
|
+
int r = 2 * (index / texelsInLogicalRow);
|
|
1466
|
+
int c = imod(index, texelsInLogicalRow) * 2;
|
|
1467
|
+
|
|
1468
|
+
return ivec3(b, r, c);
|
|
1469
|
+
}
|
|
1470
|
+
`;
|
|
1471
|
+
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);
|
|
1472
|
+
return `
|
|
1473
|
+
ivec3 getOutputCoords() {
|
|
1474
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1475
|
+
vec2(${r[0]}, ${r[1]}));
|
|
1476
|
+
int index = resTexRC.x * ${r[1]} + resTexRC.y;
|
|
1477
|
+
|
|
1478
|
+
int b = index / ${a};
|
|
1479
|
+
index -= b * ${a};
|
|
1480
|
+
|
|
1481
|
+
int r = 2 * (index / ${o});
|
|
1482
|
+
int c = imod(index, ${o}) * 2;
|
|
1483
|
+
|
|
1484
|
+
return ivec3(b, r, c);
|
|
1485
|
+
}
|
|
1486
|
+
`;
|
|
1487
|
+
}
|
|
1488
|
+
function Mn(e, t, n) {
|
|
1489
|
+
if (n)
|
|
1490
|
+
return `
|
|
1491
|
+
ivec3 getOutputCoords() {
|
|
1492
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1493
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
1494
|
+
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
1495
|
+
${xe(["r", "c", "d"], e)}
|
|
1496
|
+
return ivec3(r, c, d);
|
|
1497
|
+
}
|
|
1498
|
+
`;
|
|
1499
|
+
const r = V(["r", "c", "d"], e);
|
|
1500
|
+
return `
|
|
1501
|
+
ivec3 getOutputCoords() {
|
|
1502
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1503
|
+
vec2(${t[0]}, ${t[1]}));
|
|
1504
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1505
|
+
${r}
|
|
1506
|
+
return ivec3(r, c, d);
|
|
1507
|
+
}
|
|
1508
|
+
`;
|
|
1509
|
+
}
|
|
1510
|
+
function Bn(e, t, n) {
|
|
1511
|
+
if (n)
|
|
1512
|
+
return `
|
|
1513
|
+
ivec4 getOutputCoords() {
|
|
1514
|
+
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
1515
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1516
|
+
vec2(packedTexShape[0], packedTexShape[1]));
|
|
1517
|
+
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
|
|
1518
|
+
|
|
1519
|
+
int texelsInLogicalRow = int(ceil(float(outShape[3]) / 2.0));
|
|
1520
|
+
int texelsInBatch = texelsInLogicalRow * int(ceil(float(outShape[2]) / 2.0));
|
|
1521
|
+
int texelsInBatchN = texelsInBatch * outShape[1];
|
|
1522
|
+
|
|
1523
|
+
int b2 = index / texelsInBatchN;
|
|
1524
|
+
index -= b2 * texelsInBatchN;
|
|
1525
|
+
|
|
1526
|
+
int b = index / texelsInBatch;
|
|
1527
|
+
index -= b * texelsInBatch;
|
|
1528
|
+
|
|
1529
|
+
int r = 2 * (index / texelsInLogicalRow);
|
|
1530
|
+
int c = imod(index, texelsInLogicalRow) * 2;
|
|
1531
|
+
|
|
1532
|
+
return ivec4(b2, b, r, c);
|
|
1533
|
+
}
|
|
1534
|
+
`;
|
|
1535
|
+
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);
|
|
1536
|
+
let s = a, i = "", c = "b, r, c";
|
|
1537
|
+
for (let l = 2; l < e.length - 1; l++)
|
|
1538
|
+
s *= e[e.length - l - 1], i = `
|
|
1539
|
+
int b${l} = index / ${s};
|
|
1540
|
+
index -= b${l} * ${s};
|
|
1541
|
+
` + i, c = `b${l}, ` + c;
|
|
1542
|
+
return `
|
|
1543
|
+
ivec${e.length} getOutputCoords() {
|
|
1544
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1545
|
+
vec2(${r[0]}, ${r[1]}));
|
|
1546
|
+
int index = resTexRC.x * ${r[1]} + resTexRC.y;
|
|
1547
|
+
|
|
1548
|
+
${i}
|
|
1549
|
+
|
|
1550
|
+
int b = index / ${a};
|
|
1551
|
+
index -= b * ${a};
|
|
1552
|
+
|
|
1553
|
+
int r = 2 * (index / ${o});
|
|
1554
|
+
int c = imod(index, ${o}) * 2;
|
|
1555
|
+
|
|
1556
|
+
return ivec${e.length}(${c});
|
|
1557
|
+
}
|
|
1558
|
+
`;
|
|
1559
|
+
}
|
|
1560
|
+
function kn(e, t, n) {
|
|
1561
|
+
if (n)
|
|
1562
|
+
return `
|
|
1563
|
+
ivec4 getOutputCoords() {
|
|
1564
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1565
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
1566
|
+
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
1567
|
+
${xe(["r", "c", "d", "d2"], e)}
|
|
1568
|
+
return ivec4(r, c, d, d2);
|
|
1569
|
+
}
|
|
1570
|
+
`;
|
|
1571
|
+
const r = V(["r", "c", "d", "d2"], e);
|
|
1572
|
+
return `
|
|
1573
|
+
ivec4 getOutputCoords() {
|
|
1574
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1575
|
+
vec2(${t[0]}, ${t[1]}));
|
|
1576
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1577
|
+
${r}
|
|
1578
|
+
return ivec4(r, c, d, d2);
|
|
1579
|
+
}
|
|
1580
|
+
`;
|
|
1581
|
+
}
|
|
1582
|
+
function Pn(e, t) {
|
|
1583
|
+
const n = V(["r", "c", "d", "d2", "d3"], e);
|
|
1584
|
+
return `
|
|
1585
|
+
ivec5 getOutputCoords() {
|
|
1586
|
+
ivec2 resTexRC = ivec2(resultUV.yx * vec2(${t[0]},
|
|
1587
|
+
${t[1]}));
|
|
1588
|
+
|
|
1589
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1590
|
+
|
|
1591
|
+
${n}
|
|
1592
|
+
|
|
1593
|
+
ivec5 outShape = ivec5(r, c, d, d2, d3);
|
|
1594
|
+
return outShape;
|
|
1595
|
+
}
|
|
1596
|
+
`;
|
|
1597
|
+
}
|
|
1598
|
+
function Wn(e, t) {
|
|
1599
|
+
const n = V(["r", "c", "d", "d2", "d3", "d4"], e);
|
|
1600
|
+
return `
|
|
1601
|
+
ivec6 getOutputCoords() {
|
|
1602
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1603
|
+
vec2(${t[0]}, ${t[1]}));
|
|
1604
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1605
|
+
|
|
1606
|
+
${n}
|
|
1607
|
+
|
|
1608
|
+
ivec6 result = ivec6(r, c, d, d2, d3, d4);
|
|
1609
|
+
return result;
|
|
1610
|
+
}
|
|
1611
|
+
`;
|
|
1612
|
+
}
|
|
1613
|
+
function Vn(e, t, n) {
|
|
1614
|
+
const r = [Math.ceil(t[0] / 2), Math.ceil(t[1] / 2)];
|
|
1615
|
+
if (E(e, t))
|
|
1616
|
+
return n ? `
|
|
1617
|
+
ivec2 getOutputCoords() {
|
|
1618
|
+
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
1619
|
+
return 2 * ivec2(resultUV.yx * vec2(packedTexShape[0], packedTexShape[1]));
|
|
1620
|
+
}
|
|
1621
|
+
` : `
|
|
1622
|
+
ivec2 getOutputCoords() {
|
|
1623
|
+
return 2 * ivec2(resultUV.yx * vec2(${r[0]}, ${r[1]}));
|
|
1624
|
+
}
|
|
1625
|
+
`;
|
|
1626
|
+
const o = Math.ceil(e[1] / 2);
|
|
1627
|
+
return n ? `
|
|
1628
|
+
ivec2 getOutputCoords() {
|
|
1629
|
+
ivec2 packedTexShape = ivec2(ceil(float(outTexShape[0]) / 2.0), ceil(float(outTexShape[1]) / 2.0));
|
|
1630
|
+
int texelsInLogicalRow = int(ceil(float(outShape[1]) / 2.0));
|
|
1631
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1632
|
+
vec2(packedTexShape[0], packedTexShape[1]));
|
|
1633
|
+
|
|
1634
|
+
int index = resTexRC.x * packedTexShape[1] + resTexRC.y;
|
|
1635
|
+
int r = 2 * (index / texelsInLogicalRow);
|
|
1636
|
+
int c = imod(index, texelsInLogicalRow) * 2;
|
|
1637
|
+
|
|
1638
|
+
return ivec2(r, c);
|
|
1639
|
+
}
|
|
1640
|
+
` : `
|
|
1641
|
+
ivec2 getOutputCoords() {
|
|
1642
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1643
|
+
vec2(${r[0]}, ${r[1]}));
|
|
1644
|
+
|
|
1645
|
+
int index = resTexRC.x * ${r[1]} + resTexRC.y;
|
|
1646
|
+
int r = 2 * (index / ${o});
|
|
1647
|
+
int c = imod(index, ${o}) * 2;
|
|
1648
|
+
|
|
1649
|
+
return ivec2(r, c);
|
|
1650
|
+
}
|
|
1651
|
+
`;
|
|
1652
|
+
}
|
|
1653
|
+
function Hn(e, t, n) {
|
|
1654
|
+
return E(e, t) ? n ? `
|
|
1655
|
+
ivec2 getOutputCoords() {
|
|
1656
|
+
return ivec2(resultUV.yx * vec2(outTexShape[0], outTexShape[1]));
|
|
1657
|
+
}
|
|
1658
|
+
` : `
|
|
1659
|
+
ivec2 getOutputCoords() {
|
|
1660
|
+
return ivec2(resultUV.yx * vec2(${t[0]}, ${t[1]}));
|
|
1661
|
+
}
|
|
1662
|
+
` : e[1] === 1 ? n ? `
|
|
1663
|
+
ivec2 getOutputCoords() {
|
|
1664
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1665
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
1666
|
+
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
1667
|
+
return ivec2(index, 0);
|
|
1668
|
+
}
|
|
1669
|
+
` : `
|
|
1670
|
+
ivec2 getOutputCoords() {
|
|
1671
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1672
|
+
vec2(${t[0]}, ${t[1]}));
|
|
1673
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1674
|
+
return ivec2(index, 0);
|
|
1675
|
+
}
|
|
1676
|
+
` : e[0] === 1 ? n ? `
|
|
1677
|
+
ivec2 getOutputCoords() {
|
|
1678
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1679
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
1680
|
+
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
1681
|
+
return ivec2(0, index);
|
|
1682
|
+
}
|
|
1683
|
+
` : `
|
|
1684
|
+
ivec2 getOutputCoords() {
|
|
1685
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1686
|
+
vec2(${t[0]}, ${t[1]}));
|
|
1687
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1688
|
+
return ivec2(0, index);
|
|
1689
|
+
}
|
|
1690
|
+
` : n ? `
|
|
1691
|
+
ivec2 getOutputCoords() {
|
|
1692
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1693
|
+
vec2(outTexShape[0], outTexShape[1]));
|
|
1694
|
+
int index = resTexRC.x * outTexShape[1] + resTexRC.y;
|
|
1695
|
+
int r = index / outShape[1];
|
|
1696
|
+
int c = index - r * outShape[1];
|
|
1697
|
+
return ivec2(r, c);
|
|
1698
|
+
}
|
|
1699
|
+
` : `
|
|
1700
|
+
ivec2 getOutputCoords() {
|
|
1701
|
+
ivec2 resTexRC = ivec2(resultUV.yx *
|
|
1702
|
+
vec2(${t[0]}, ${t[1]}));
|
|
1703
|
+
int index = resTexRC.x * ${t[1]} + resTexRC.y;
|
|
1704
|
+
int r = index / ${e[1]};
|
|
1705
|
+
int c = index - r * ${e[1]};
|
|
1706
|
+
return ivec2(r, c);
|
|
1707
|
+
}
|
|
1708
|
+
`;
|
|
1709
|
+
}
|
|
1710
|
+
function y(e) {
|
|
1711
|
+
return `offset${e}`;
|
|
1712
|
+
}
|
|
1713
|
+
function Xn(e) {
|
|
1714
|
+
const t = e.name, n = "get" + t.charAt(0).toUpperCase() + t.slice(1), r = b();
|
|
1715
|
+
return `
|
|
1716
|
+
vec4 ${n}() {
|
|
1717
|
+
return ${r.texture2D}(${t}, halfCR);
|
|
1718
|
+
}
|
|
1719
|
+
`;
|
|
1720
|
+
}
|
|
1721
|
+
function Gn(e, t) {
|
|
1722
|
+
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1);
|
|
1723
|
+
if (e.shapeInfo.isUniform)
|
|
1724
|
+
return `float ${r}() {return ${n};}`;
|
|
1725
|
+
const [o, a] = e.shapeInfo.texShape;
|
|
1726
|
+
if (o === 1 && a === 1)
|
|
1727
|
+
return `
|
|
1728
|
+
float ${r}() {
|
|
1729
|
+
return sampleTexture(${n}, halfCR);
|
|
1730
|
+
}
|
|
1731
|
+
`;
|
|
1732
|
+
const s = y(n);
|
|
1733
|
+
if (t)
|
|
1734
|
+
return `
|
|
1735
|
+
float ${r}() {
|
|
1736
|
+
vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], ${s});
|
|
1737
|
+
return sampleTexture(${n}, uv);
|
|
1738
|
+
}
|
|
1739
|
+
`;
|
|
1740
|
+
const [i, c] = e.shapeInfo.texShape;
|
|
1741
|
+
return `
|
|
1742
|
+
float ${r}() {
|
|
1743
|
+
vec2 uv = uvFromFlat(${i}, ${c}, ${s});
|
|
1744
|
+
return sampleTexture(${n}, uv);
|
|
1745
|
+
}
|
|
1746
|
+
`;
|
|
1747
|
+
}
|
|
1748
|
+
function zn(e, t) {
|
|
1749
|
+
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = e.shapeInfo.texShape, a = b();
|
|
1750
|
+
if (t)
|
|
1751
|
+
return `
|
|
1752
|
+
vec4 ${r}(int index) {
|
|
1753
|
+
ivec2 packedTexShape = ivec2(ceil(float(${n}TexShape[0]) / 2.0), ceil(float(${n}TexShape[1]) / 2.0));
|
|
1754
|
+
vec2 uv = packedUVfrom1D(
|
|
1755
|
+
packedTexShape[0], packedTexShape[1], index);
|
|
1756
|
+
return ${a.texture2D}(${n}, uv);
|
|
1757
|
+
}
|
|
1758
|
+
`;
|
|
1759
|
+
const s = [Math.ceil(o[0] / 2), Math.ceil(o[1] / 2)];
|
|
1760
|
+
return `
|
|
1761
|
+
vec4 ${r}(int index) {
|
|
1762
|
+
vec2 uv = packedUVfrom1D(
|
|
1763
|
+
${s[0]}, ${s[1]}, index);
|
|
1764
|
+
return ${a.texture2D}(${n}, uv);
|
|
1765
|
+
}
|
|
1766
|
+
`;
|
|
1767
|
+
}
|
|
1768
|
+
function qn(e, t) {
|
|
1769
|
+
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1);
|
|
1770
|
+
if (e.shapeInfo.isUniform)
|
|
1771
|
+
return `
|
|
1772
|
+
float ${r}(int index) {
|
|
1773
|
+
${M(e)}
|
|
1774
|
+
}
|
|
1775
|
+
`;
|
|
1776
|
+
const o = e.shapeInfo.texShape, a = o[0], s = o[1];
|
|
1777
|
+
if (s === 1 && a === 1)
|
|
1778
|
+
return `
|
|
1779
|
+
float ${r}(int index) {
|
|
1780
|
+
return sampleTexture(${n}, halfCR);
|
|
1781
|
+
}
|
|
1782
|
+
`;
|
|
1783
|
+
const i = y(n);
|
|
1784
|
+
return s === 1 ? t ? `
|
|
1785
|
+
float ${r}(int index) {
|
|
1786
|
+
vec2 uv = vec2(0.5, (float(index + ${i}) + 0.5) / float(${n}TexShape[0]));
|
|
1787
|
+
return sampleTexture(${n}, uv);
|
|
1788
|
+
}
|
|
1789
|
+
` : `
|
|
1790
|
+
float ${r}(int index) {
|
|
1791
|
+
vec2 uv = vec2(0.5, (float(index + ${i}) + 0.5) / ${a}.0);
|
|
1792
|
+
return sampleTexture(${n}, uv);
|
|
1793
|
+
}
|
|
1794
|
+
` : a === 1 ? t ? `
|
|
1795
|
+
float ${r}(int index) {
|
|
1796
|
+
vec2 uv = vec2((float(index + ${i}) + 0.5) / float(${n}TexShape[1]), 0.5);
|
|
1797
|
+
return sampleTexture(${n}, uv);
|
|
1798
|
+
}
|
|
1799
|
+
` : `
|
|
1800
|
+
float ${r}(int index) {
|
|
1801
|
+
vec2 uv = vec2((float(index + ${i}) + 0.5) / ${s}.0, 0.5);
|
|
1802
|
+
return sampleTexture(${n}, uv);
|
|
1803
|
+
}
|
|
1804
|
+
` : t ? `
|
|
1805
|
+
float ${r}(int index) {
|
|
1806
|
+
vec2 uv = uvFromFlat(${n}TexShape[0], ${n}TexShape[1], index + ${i});
|
|
1807
|
+
return sampleTexture(${n}, uv);
|
|
1808
|
+
}
|
|
1809
|
+
` : `
|
|
1810
|
+
float ${r}(int index) {
|
|
1811
|
+
vec2 uv = uvFromFlat(${a}, ${s}, index + ${i});
|
|
1812
|
+
return sampleTexture(${n}, uv);
|
|
1813
|
+
}
|
|
1814
|
+
`;
|
|
1815
|
+
}
|
|
1816
|
+
function jn(e, t) {
|
|
1817
|
+
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = e.shapeInfo.texShape, s = a[0], i = a[1], c = b();
|
|
1818
|
+
if (a != null && E(n, a))
|
|
1819
|
+
return t ? `
|
|
1820
|
+
vec4 ${o}(int row, int col) {
|
|
1821
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1822
|
+
|
|
1823
|
+
return ${c.texture2D}(${r}, uv);
|
|
1824
|
+
}
|
|
1825
|
+
` : `
|
|
1826
|
+
vec4 ${o}(int row, int col) {
|
|
1827
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${i}.0, ${s}.0);
|
|
1828
|
+
|
|
1829
|
+
return ${c.texture2D}(${r}, uv);
|
|
1830
|
+
}
|
|
1831
|
+
`;
|
|
1832
|
+
if (t)
|
|
1833
|
+
return `
|
|
1834
|
+
vec4 ${o}(int row, int col) {
|
|
1835
|
+
ivec2 packedTexShape = ivec2(ceil(float(${r}TexShape[0]) / 2.0), ceil(float(${r}TexShape[1]) / 2.0));
|
|
1836
|
+
int valuesPerRow = int(ceil(float(${r}Shape[1]) / 2.0));
|
|
1837
|
+
vec2 uv = packedUVfrom2D(valuesPerRow, packedTexShape[0], packedTexShape[1], row, col);
|
|
1838
|
+
return ${c.texture2D}(${r}, uv);
|
|
1839
|
+
}
|
|
1840
|
+
`;
|
|
1841
|
+
const l = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)], f = Math.ceil(n[1] / 2);
|
|
1842
|
+
return `
|
|
1843
|
+
vec4 ${o}(int row, int col) {
|
|
1844
|
+
vec2 uv = packedUVfrom2D(${f}, ${l[0]}, ${l[1]}, row, col);
|
|
1845
|
+
return ${c.texture2D}(${r}, uv);
|
|
1846
|
+
}
|
|
1847
|
+
`;
|
|
1848
|
+
}
|
|
1849
|
+
function Jn(e, t) {
|
|
1850
|
+
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = e.shapeInfo.texShape;
|
|
1851
|
+
if (a != null && E(n, a)) {
|
|
1852
|
+
if (t)
|
|
1853
|
+
return `
|
|
1854
|
+
float ${o}(int row, int col) {
|
|
1855
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1856
|
+
return sampleTexture(${r}, uv);
|
|
1857
|
+
}
|
|
1858
|
+
`;
|
|
1859
|
+
const h = a[0], d = a[1];
|
|
1860
|
+
return `
|
|
1861
|
+
float ${o}(int row, int col) {
|
|
1862
|
+
vec2 uv = (vec2(col, row) + halfCR) / vec2(${d}.0, ${h}.0);
|
|
1863
|
+
return sampleTexture(${r}, uv);
|
|
1864
|
+
}
|
|
1865
|
+
`;
|
|
1866
|
+
}
|
|
1867
|
+
const { newShape: s, keptDims: i } = N(n), c = s;
|
|
1868
|
+
if (c.length < n.length) {
|
|
1869
|
+
const h = B(e, c), d = ["row", "col"];
|
|
1870
|
+
return `
|
|
1871
|
+
${U(h, t)}
|
|
1872
|
+
float ${o}(int row, int col) {
|
|
1873
|
+
return ${o}(${k(d, i)});
|
|
1874
|
+
}
|
|
1875
|
+
`;
|
|
1876
|
+
}
|
|
1877
|
+
if (e.shapeInfo.isUniform)
|
|
1878
|
+
return `
|
|
1879
|
+
float ${o}(int row, int col) {
|
|
1880
|
+
int index = round(dot(vec2(row, col), vec2(${n[1]}, 1)));
|
|
1881
|
+
${M(e)}
|
|
1882
|
+
}
|
|
1883
|
+
`;
|
|
1884
|
+
const l = a[0], f = a[1], u = y(r);
|
|
1885
|
+
return f === 1 ? t ? `
|
|
1886
|
+
float ${o}(int row, int col) {
|
|
1887
|
+
float index = dot(vec3(row, col, ${u}), vec3(${r}Shape[1], 1, 1));
|
|
1888
|
+
vec2 uv = vec2(0.5, (index + 0.5) / float(${r}TexShape[0]));
|
|
1889
|
+
return sampleTexture(${r}, uv);
|
|
1890
|
+
}
|
|
1891
|
+
` : `
|
|
1892
|
+
float ${o}(int row, int col) {
|
|
1893
|
+
float index = dot(vec3(row, col, ${u}), vec3(${n[1]}, 1, 1));
|
|
1894
|
+
vec2 uv = vec2(0.5, (index + 0.5) / ${l}.0);
|
|
1895
|
+
return sampleTexture(${r}, uv);
|
|
1896
|
+
}
|
|
1897
|
+
` : l === 1 ? t ? `
|
|
1898
|
+
float ${o}(int row, int col) {
|
|
1899
|
+
float index = dot(vec3(row, col, ${u}), vec3(${r}Shape[1], 1, 1));
|
|
1900
|
+
vec2 uv = vec2((index + 0.5) / float(${r}TexShape[1]), 0.5);
|
|
1901
|
+
return sampleTexture(${r}, uv);
|
|
1902
|
+
}
|
|
1903
|
+
` : `
|
|
1904
|
+
float ${o}(int row, int col) {
|
|
1905
|
+
float index = dot(vec3(row, col, ${u}), vec3(${n[1]}, 1, 1));
|
|
1906
|
+
vec2 uv = vec2((index + 0.5) / ${f}.0, 0.5);
|
|
1907
|
+
return sampleTexture(${r}, uv);
|
|
1908
|
+
}
|
|
1909
|
+
` : t ? `
|
|
1910
|
+
float ${o}(int row, int col) {
|
|
1911
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
1912
|
+
int index = row * ${r}Shape[1] + col + ${u};
|
|
1913
|
+
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index);
|
|
1914
|
+
return sampleTexture(${r}, uv);
|
|
1915
|
+
}
|
|
1916
|
+
` : `
|
|
1917
|
+
float ${o}(int row, int col) {
|
|
1918
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
1919
|
+
int index = row * ${n[1]} + col + ${u};
|
|
1920
|
+
vec2 uv = uvFromFlat(${l}, ${f}, index);
|
|
1921
|
+
return sampleTexture(${r}, uv);
|
|
1922
|
+
}
|
|
1923
|
+
`;
|
|
1924
|
+
}
|
|
1925
|
+
function Yn(e, t) {
|
|
1926
|
+
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = e.shapeInfo.texShape, s = [Math.ceil(a[0] / 2), Math.ceil(a[1] / 2)];
|
|
1927
|
+
if (n[0] === 1) {
|
|
1928
|
+
const h = n.slice(1), d = [1, 2], p = B(e, h), x = ["b", "row", "col"];
|
|
1929
|
+
return `
|
|
1930
|
+
${ve(p, t)}
|
|
1931
|
+
vec4 ${o}(int b, int row, int col) {
|
|
1932
|
+
return ${o}(${k(x, d)});
|
|
1933
|
+
}
|
|
1934
|
+
`;
|
|
1935
|
+
}
|
|
1936
|
+
const i = b();
|
|
1937
|
+
if (t)
|
|
1938
|
+
return `
|
|
1939
|
+
vec4 ${o}(int b, int row, int col) {
|
|
1940
|
+
ivec2 packedTexShape = ivec2(ceil(float(${r}TexShape[0]) / 2.0), ceil(float(${r}TexShape[1]) / 2.0));
|
|
1941
|
+
int valuesPerRow = int(ceil(float(${r}Shape[2]) / 2.0));
|
|
1942
|
+
int texelsInBatch = valuesPerRow * int(ceil(float(${r}Shape[1]) / 2.0));
|
|
1943
|
+
vec2 uv = packedUVfrom3D(
|
|
1944
|
+
packedTexShape[0], packedTexShape[1], texelsInBatch, valuesPerRow, b, row, col);
|
|
1945
|
+
return ${i.texture2D}(${r}, uv);
|
|
1946
|
+
}
|
|
1947
|
+
`;
|
|
1948
|
+
const c = s[0], l = s[1], f = Math.ceil(n[2] / 2), u = f * Math.ceil(n[1] / 2);
|
|
1949
|
+
return `
|
|
1950
|
+
vec4 ${o}(int b, int row, int col) {
|
|
1951
|
+
vec2 uv = packedUVfrom3D(
|
|
1952
|
+
${c}, ${l}, ${u}, ${f}, b, row, col);
|
|
1953
|
+
return ${i.texture2D}(${r}, uv);
|
|
1954
|
+
}
|
|
1955
|
+
`;
|
|
1956
|
+
}
|
|
1957
|
+
function Kn(e, t) {
|
|
1958
|
+
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = n[1] * n[2], s = n[2], { newShape: i, keptDims: c } = N(n), l = i;
|
|
1959
|
+
if (l.length < n.length) {
|
|
1960
|
+
const x = B(e, l), S = ["row", "col", "depth"];
|
|
1961
|
+
return `
|
|
1962
|
+
${U(x, t)}
|
|
1963
|
+
float ${o}(int row, int col, int depth) {
|
|
1964
|
+
return ${o}(${k(S, c)});
|
|
1965
|
+
}
|
|
1966
|
+
`;
|
|
1967
|
+
}
|
|
1968
|
+
if (e.shapeInfo.isUniform)
|
|
1969
|
+
return `
|
|
1970
|
+
float ${o}(int row, int col, int depth) {
|
|
1971
|
+
int index = round(dot(vec3(row, col, depth),
|
|
1972
|
+
vec3(${a}, ${s}, 1)));
|
|
1973
|
+
${M(e)}
|
|
1974
|
+
}
|
|
1975
|
+
`;
|
|
1976
|
+
const f = e.shapeInfo.texShape, u = f[0], h = f[1], d = e.shapeInfo.flatOffset;
|
|
1977
|
+
if (h === a && d == null)
|
|
1978
|
+
return t ? `
|
|
1979
|
+
float ${o}(int row, int col, int depth) {
|
|
1980
|
+
int stride1 = ${r}Shape[2];
|
|
1981
|
+
float texR = float(row);
|
|
1982
|
+
float texC = dot(vec2(col, depth), vec2(stride1, 1));
|
|
1983
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1984
|
+
vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
1985
|
+
return sampleTexture(${r}, uv);
|
|
1986
|
+
}
|
|
1987
|
+
` : `
|
|
1988
|
+
float ${o}(int row, int col, int depth) {
|
|
1989
|
+
float texR = float(row);
|
|
1990
|
+
float texC = dot(vec2(col, depth), vec2(${s}, 1));
|
|
1991
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
1992
|
+
vec2(${h}.0, ${u}.0);
|
|
1993
|
+
return sampleTexture(${r}, uv);
|
|
1994
|
+
}
|
|
1995
|
+
`;
|
|
1996
|
+
if (h === s && d == null)
|
|
1997
|
+
return t ? `
|
|
1998
|
+
float ${o}(int row, int col, int depth) {
|
|
1999
|
+
float texR = dot(vec2(row, col), vec2(${r}Shape[1], 1));
|
|
2000
|
+
float texC = float(depth);
|
|
2001
|
+
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
2002
|
+
return sampleTexture(${r}, uv);
|
|
2003
|
+
}
|
|
2004
|
+
` : `
|
|
2005
|
+
float ${o}(int row, int col, int depth) {
|
|
2006
|
+
float texR = dot(vec2(row, col), vec2(${n[1]}, 1));
|
|
2007
|
+
float texC = float(depth);
|
|
2008
|
+
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${h}.0, ${u}.0);
|
|
2009
|
+
return sampleTexture(${r}, uv);
|
|
2010
|
+
}
|
|
2011
|
+
`;
|
|
2012
|
+
const p = y(r);
|
|
2013
|
+
return t ? `
|
|
2014
|
+
float ${o}(int row, int col, int depth) {
|
|
2015
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
2016
|
+
int stride0 = ${r}Shape[1] * ${r}Shape[2];
|
|
2017
|
+
int stride1 = ${r}Shape[2];
|
|
2018
|
+
int index = row * stride0 + col * stride1 + depth + ${p};
|
|
2019
|
+
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index);
|
|
2020
|
+
return sampleTexture(${r}, uv);
|
|
2021
|
+
}
|
|
2022
|
+
` : `
|
|
2023
|
+
float ${o}(int row, int col, int depth) {
|
|
2024
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
2025
|
+
int index = row * ${a} + col * ${s} + depth + ${p};
|
|
2026
|
+
vec2 uv = uvFromFlat(${u}, ${h}, index);
|
|
2027
|
+
return sampleTexture(${r}, uv);
|
|
2028
|
+
}
|
|
2029
|
+
`;
|
|
2030
|
+
}
|
|
2031
|
+
function Zn(e, t) {
|
|
2032
|
+
const n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = b();
|
|
2033
|
+
if (t)
|
|
2034
|
+
return `
|
|
2035
|
+
vec4 ${r}(int b2, int b, int row, int col) {
|
|
2036
|
+
int valuesPerRow = int(ceil(float(${n}Shape[3]) / 2.0));
|
|
2037
|
+
int texelsInBatch = valuesPerRow * int(ceil(float(${n}Shape[2]) / 2.0));
|
|
2038
|
+
int index = b * texelsInBatch + (row / 2) * valuesPerRow + (col / 2);
|
|
2039
|
+
texelsInBatch *= ${n}Shape[1];
|
|
2040
|
+
index = b2 * texelsInBatch + index;
|
|
2041
|
+
ivec2 packedTexShape = ivec2(ceil(float(${n}TexShape[0]) / 2.0), ceil(float(${n}TexShape[1]) / 2.0));
|
|
2042
|
+
int texR = index / packedTexShape[1];
|
|
2043
|
+
int texC = index - texR * packedTexShape[1];
|
|
2044
|
+
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(packedTexShape[1], packedTexShape[0]); return ${o.texture2D}(${n}, uv);
|
|
2045
|
+
}
|
|
2046
|
+
`;
|
|
2047
|
+
const a = e.shapeInfo.logicalShape, s = a.length, i = e.shapeInfo.texShape, c = [Math.ceil(i[0] / 2), Math.ceil(i[1] / 2)], l = c[0], f = c[1], u = Math.ceil(a[s - 1] / 2);
|
|
2048
|
+
let h = u * Math.ceil(a[s - 2] / 2), d = "int b, int row, int col", p = `b * ${h} + (row / 2) * ${u} + (col / 2)`;
|
|
2049
|
+
for (let x = 2; x < s - 1; x++)
|
|
2050
|
+
d = `int b${x}, ` + d, h *= a[s - x - 1], p = `b${x} * ${h} + ` + p;
|
|
2051
|
+
return `
|
|
2052
|
+
vec4 ${r}(${d}) {
|
|
2053
|
+
int index = ${p};
|
|
2054
|
+
int texR = index / ${f};
|
|
2055
|
+
int texC = index - texR * ${f};
|
|
2056
|
+
vec2 uv = (vec2(texC, texR) + halfCR) / vec2(${f}, ${l});
|
|
2057
|
+
return ${o.texture2D}(${n}, uv);
|
|
2058
|
+
}
|
|
2059
|
+
`;
|
|
2060
|
+
}
|
|
2061
|
+
function Qn(e, t) {
|
|
2062
|
+
const n = e.shapeInfo.logicalShape, r = e.name, o = "get" + r.charAt(0).toUpperCase() + r.slice(1), a = n[3], s = n[2] * a, i = n[1] * s, { newShape: c, keptDims: l } = N(n);
|
|
2063
|
+
if (c.length < n.length) {
|
|
2064
|
+
const w = B(e, c), F = ["row", "col", "depth", "depth2"];
|
|
2065
|
+
return `
|
|
2066
|
+
${U(w, t)}
|
|
2067
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
2068
|
+
return ${o}(${k(F, l)});
|
|
2069
|
+
}
|
|
2070
|
+
`;
|
|
2071
|
+
}
|
|
2072
|
+
if (e.shapeInfo.isUniform)
|
|
2073
|
+
return `
|
|
2074
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
2075
|
+
int index = round(dot(vec4(row, col, depth, depth2),
|
|
2076
|
+
vec4(${i}, ${s}, ${a}, 1)));
|
|
2077
|
+
${M(e)}
|
|
2078
|
+
}
|
|
2079
|
+
`;
|
|
2080
|
+
const f = e.shapeInfo.flatOffset, u = e.shapeInfo.texShape, h = u[0], d = u[1], p = `int stride2 = ${r}Shape[3];`, x = `int stride1 = ${r}Shape[2] * stride2;`, S = `int stride0 = ${r}Shape[1] * stride1;`;
|
|
2081
|
+
if (d === i && f == null)
|
|
2082
|
+
return t ? `
|
|
2083
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
2084
|
+
${p}
|
|
2085
|
+
${x}
|
|
2086
|
+
float texR = float(row);
|
|
2087
|
+
float texC =
|
|
2088
|
+
dot(vec3(col, depth, depth2),
|
|
2089
|
+
vec3(stride1, stride2, 1));
|
|
2090
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
2091
|
+
vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
2092
|
+
return sampleTexture(${r}, uv);
|
|
2093
|
+
}
|
|
2094
|
+
` : `
|
|
2095
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
2096
|
+
float texR = float(row);
|
|
2097
|
+
float texC =
|
|
2098
|
+
dot(vec3(col, depth, depth2),
|
|
2099
|
+
vec3(${s}, ${a}, 1));
|
|
2100
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
2101
|
+
vec2(${d}.0, ${h}.0);
|
|
2102
|
+
return sampleTexture(${r}, uv);
|
|
2103
|
+
}
|
|
2104
|
+
`;
|
|
2105
|
+
if (d === a && f == null)
|
|
2106
|
+
return t ? `
|
|
2107
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
2108
|
+
float texR = dot(vec3(row, col, depth),
|
|
2109
|
+
vec3(${r}Shape[1] * ${r}Shape[2], ${r}Shape[2], 1));
|
|
2110
|
+
float texC = float(depth2);
|
|
2111
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
2112
|
+
vec2(${r}TexShape[1], ${r}TexShape[0]);
|
|
2113
|
+
return sampleTexture(${r}, uv);
|
|
2114
|
+
}
|
|
2115
|
+
` : `
|
|
2116
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
2117
|
+
float texR = dot(vec3(row, col, depth),
|
|
2118
|
+
vec3(${n[1] * n[2]}, ${n[2]}, 1));
|
|
2119
|
+
float texC = float(depth2);
|
|
2120
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
2121
|
+
vec2(${d}.0, ${h}.0);
|
|
2122
|
+
return sampleTexture(${r}, uv);
|
|
2123
|
+
}
|
|
2124
|
+
`;
|
|
2125
|
+
const g = y(r);
|
|
2126
|
+
return t ? `
|
|
2127
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
2128
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
2129
|
+
${p}
|
|
2130
|
+
${x}
|
|
2131
|
+
${S}
|
|
2132
|
+
int index = row * stride0 + col * stride1 +
|
|
2133
|
+
depth * stride2 + depth2;
|
|
2134
|
+
vec2 uv = uvFromFlat(${r}TexShape[0], ${r}TexShape[1], index + ${g});
|
|
2135
|
+
return sampleTexture(${r}, uv);
|
|
2136
|
+
}
|
|
2137
|
+
` : `
|
|
2138
|
+
float ${o}(int row, int col, int depth, int depth2) {
|
|
2139
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
2140
|
+
int index = row * ${i} + col * ${s} +
|
|
2141
|
+
depth * ${a} + depth2;
|
|
2142
|
+
vec2 uv = uvFromFlat(${h}, ${d}, index + ${g});
|
|
2143
|
+
return sampleTexture(${r}, uv);
|
|
2144
|
+
}
|
|
2145
|
+
`;
|
|
2146
|
+
}
|
|
2147
|
+
function er(e) {
|
|
2148
|
+
const t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), o = t[4], a = t[3] * o, s = t[2] * a, i = t[1] * s, { newShape: c, keptDims: l } = N(t);
|
|
2149
|
+
if (c.length < t.length) {
|
|
2150
|
+
const x = B(e, c), S = ["row", "col", "depth", "depth2", "depth3"];
|
|
2151
|
+
return `
|
|
2152
|
+
${U(x)}
|
|
2153
|
+
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
2154
|
+
return ${r}(${k(S, l)});
|
|
2155
|
+
}
|
|
2156
|
+
`;
|
|
2157
|
+
}
|
|
2158
|
+
if (e.shapeInfo.isUniform)
|
|
2159
|
+
return `
|
|
2160
|
+
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
2161
|
+
float index = dot(
|
|
2162
|
+
vec4(row, col, depth, depth2),
|
|
2163
|
+
vec4(${i}, ${s}, ${a}, ${o})) +
|
|
2164
|
+
depth3;
|
|
2165
|
+
${M(e)}
|
|
2166
|
+
}
|
|
2167
|
+
`;
|
|
2168
|
+
const f = e.shapeInfo.flatOffset, u = e.shapeInfo.texShape, h = u[0], d = u[1];
|
|
2169
|
+
if (d === i && f == null)
|
|
2170
|
+
return `
|
|
2171
|
+
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
2172
|
+
int texR = row;
|
|
2173
|
+
float texC = dot(vec4(col, depth, depth2, depth3),
|
|
2174
|
+
vec4(${s}, ${a}, ${o}, 1));
|
|
2175
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
2176
|
+
vec2(${d}.0, ${h}.0);
|
|
2177
|
+
return sampleTexture(${n}, uv);
|
|
2178
|
+
}
|
|
2179
|
+
`;
|
|
2180
|
+
if (d === o && f == null)
|
|
2181
|
+
return `
|
|
2182
|
+
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
2183
|
+
float texR = dot(
|
|
2184
|
+
vec4(row, col, depth, depth2),
|
|
2185
|
+
vec4(${t[1] * t[2] * t[3]},
|
|
2186
|
+
${t[2] * t[3]}, ${t[3]}, 1));
|
|
2187
|
+
int texC = depth3;
|
|
2188
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
2189
|
+
vec2(${d}.0, ${h}.0);
|
|
2190
|
+
return sampleTexture(${n}, uv);
|
|
2191
|
+
}
|
|
2192
|
+
`;
|
|
2193
|
+
const p = y(n);
|
|
2194
|
+
return `
|
|
2195
|
+
float ${r}(int row, int col, int depth, int depth2, int depth3) {
|
|
2196
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
2197
|
+
int index = row * ${i} + col * ${s} + depth * ${a} +
|
|
2198
|
+
depth2 * ${o} + depth3 + ${p};
|
|
2199
|
+
vec2 uv = uvFromFlat(${h}, ${d}, index);
|
|
2200
|
+
return sampleTexture(${n}, uv);
|
|
2201
|
+
}
|
|
2202
|
+
`;
|
|
2203
|
+
}
|
|
2204
|
+
function tr(e) {
|
|
2205
|
+
const t = e.shapeInfo.logicalShape, n = e.name, r = "get" + n.charAt(0).toUpperCase() + n.slice(1), { newShape: o, keptDims: a } = N(t);
|
|
2206
|
+
if (o.length < t.length) {
|
|
2207
|
+
const S = B(e, o), g = ["row", "col", "depth", "depth2", "depth3", "depth4"];
|
|
2208
|
+
return `
|
|
2209
|
+
${U(S)}
|
|
2210
|
+
float ${r}(int row, int col, int depth,
|
|
2211
|
+
int depth2, int depth3, int depth4) {
|
|
2212
|
+
return ${r}(${k(g, a)});
|
|
2213
|
+
}
|
|
2214
|
+
`;
|
|
2215
|
+
}
|
|
2216
|
+
const s = t[5], i = t[4] * s, c = t[3] * i, l = t[2] * c, f = t[1] * l;
|
|
2217
|
+
if (e.shapeInfo.isUniform)
|
|
2218
|
+
return `
|
|
2219
|
+
float ${r}(int row, int col, int depth,
|
|
2220
|
+
int depth2, int depth3, int depth4) {
|
|
2221
|
+
int index = round(dot(
|
|
2222
|
+
vec4(row, col, depth, depth2),
|
|
2223
|
+
vec4(${f}, ${l}, ${c}, ${i})) +
|
|
2224
|
+
dot(
|
|
2225
|
+
vec2(depth3, depth4),
|
|
2226
|
+
vec2(${s}, 1)));
|
|
2227
|
+
${M(e)}
|
|
2228
|
+
}
|
|
2229
|
+
`;
|
|
2230
|
+
const u = e.shapeInfo.flatOffset, h = e.shapeInfo.texShape, d = h[0], p = h[1];
|
|
2231
|
+
if (p === f && u == null)
|
|
2232
|
+
return `
|
|
2233
|
+
float ${r}(int row, int col, int depth,
|
|
2234
|
+
int depth2, int depth3, int depth4) {
|
|
2235
|
+
int texR = row;
|
|
2236
|
+
float texC = dot(vec4(col, depth, depth2, depth3),
|
|
2237
|
+
vec4(${l}, ${c}, ${i}, ${s})) +
|
|
2238
|
+
float(depth4);
|
|
2239
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
2240
|
+
vec2(${p}.0, ${d}.0);
|
|
2241
|
+
return sampleTexture(${n}, uv);
|
|
2242
|
+
}
|
|
2243
|
+
`;
|
|
2244
|
+
if (p === s && u == null)
|
|
2245
|
+
return `
|
|
2246
|
+
float ${r}(int row, int col, int depth,
|
|
2247
|
+
int depth2, int depth3, int depth4) {
|
|
2248
|
+
float texR = dot(vec4(row, col, depth, depth2),
|
|
2249
|
+
vec4(${t[1] * t[2] * t[3] * t[4]},
|
|
2250
|
+
${t[2] * t[3] * t[4]},
|
|
2251
|
+
${t[3] * t[4]},
|
|
2252
|
+
${t[4]})) + float(depth3);
|
|
2253
|
+
int texC = depth4;
|
|
2254
|
+
vec2 uv = (vec2(texC, texR) + halfCR) /
|
|
2255
|
+
vec2(${p}.0, ${d}.0);
|
|
2256
|
+
return sampleTexture(${n}, uv);
|
|
2257
|
+
}
|
|
2258
|
+
`;
|
|
2259
|
+
const x = y(n);
|
|
2260
|
+
return `
|
|
2261
|
+
float ${r}(int row, int col, int depth,
|
|
2262
|
+
int depth2, int depth3, int depth4) {
|
|
2263
|
+
// Explicitly use integer operations as dot() only works on floats.
|
|
2264
|
+
int index = row * ${f} + col * ${l} + depth * ${c} +
|
|
2265
|
+
depth2 * ${i} + depth3 * ${s} + depth4 + ${x};
|
|
2266
|
+
vec2 uv = uvFromFlat(${d}, ${p}, index);
|
|
2267
|
+
return sampleTexture(${n}, uv);
|
|
2268
|
+
}
|
|
2269
|
+
`;
|
|
2270
|
+
}
|
|
2271
|
+
function M(e) {
|
|
2272
|
+
const t = e.name, n = T(e.shapeInfo.logicalShape);
|
|
2273
|
+
return n < 2 ? `return ${t};` : `
|
|
2274
|
+
for (int i = 0; i < ${n}; i++) {
|
|
2275
|
+
if (i == index) {
|
|
2276
|
+
return ${t}[i];
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
`;
|
|
2280
|
+
}
|
|
2281
|
+
function nr(e, t) {
|
|
2282
|
+
const n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), o = "get" + r + "AtOutCoords", a = e.shapeInfo.logicalShape.length, s = t.logicalShape.length, i = me(e.shapeInfo.logicalShape, t.logicalShape), c = Te(s), l = s - a;
|
|
2283
|
+
let f;
|
|
2284
|
+
const u = ["x", "y", "z", "w", "u", "v"];
|
|
2285
|
+
a === 0 ? f = "" : s < 2 && i.length >= 1 ? f = "coords = 0;" : f = i.map((w) => `coords.${u[w + l]} = 0;`).join(`
|
|
2286
|
+
`);
|
|
2287
|
+
let h = "";
|
|
2288
|
+
s < 2 && a > 0 ? h = "coords" : h = e.shapeInfo.logicalShape.map((w, F) => `coords.${u[F + l]}`).join(", ");
|
|
2289
|
+
let d = "return outputValue;";
|
|
2290
|
+
const x = T(e.shapeInfo.logicalShape) === 1, g = T(t.logicalShape) === 1;
|
|
2291
|
+
if (a === 1 && !x && !g)
|
|
2292
|
+
d = `
|
|
2293
|
+
return vec4(outputValue.xy, outputValue.xy);
|
|
2294
|
+
`;
|
|
2295
|
+
else if (x && !g)
|
|
2296
|
+
s === 1 ? d = `
|
|
2297
|
+
return vec4(outputValue.x, outputValue.x, 0., 0.);
|
|
2298
|
+
` : d = `
|
|
2299
|
+
return vec4(outputValue.x);
|
|
2300
|
+
`;
|
|
2301
|
+
else if (i.length) {
|
|
2302
|
+
const w = a - 2, F = a - 1;
|
|
2303
|
+
i.indexOf(w) > -1 && i.indexOf(F) > -1 ? d = "return vec4(outputValue.x);" : i.indexOf(w) > -1 ? d = "return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);" : i.indexOf(F) > -1 && (d = "return vec4(outputValue.xx, outputValue.zz);");
|
|
2304
|
+
}
|
|
2305
|
+
return `
|
|
2306
|
+
vec4 ${o}() {
|
|
2307
|
+
${c} coords = getOutputCoords();
|
|
2308
|
+
${f}
|
|
2309
|
+
vec4 outputValue = get${r}(${h});
|
|
2310
|
+
${d}
|
|
2311
|
+
}
|
|
2312
|
+
`;
|
|
2313
|
+
}
|
|
2314
|
+
function rr(e, t) {
|
|
2315
|
+
const n = e.name, r = n.charAt(0).toUpperCase() + n.slice(1), o = "get" + r + "AtOutCoords", a = t.texShape, s = e.shapeInfo.texShape, i = e.shapeInfo.logicalShape.length, c = t.logicalShape.length;
|
|
2316
|
+
if (!e.shapeInfo.isUniform && i === c && e.shapeInfo.flatOffset == null && E(s, a))
|
|
2317
|
+
return `
|
|
2318
|
+
float ${o}() {
|
|
2319
|
+
return sampleTexture(${n}, resultUV);
|
|
2320
|
+
}
|
|
2321
|
+
`;
|
|
2322
|
+
const l = Te(c), f = me(e.shapeInfo.logicalShape, t.logicalShape), u = c - i;
|
|
2323
|
+
let h;
|
|
2324
|
+
const d = ["x", "y", "z", "w", "u", "v"];
|
|
2325
|
+
i === 0 ? h = "" : c < 2 && f.length >= 1 ? h = "coords = 0;" : h = f.map((x) => `coords.${d[x + u]} = 0;`).join(`
|
|
2326
|
+
`);
|
|
2327
|
+
let p = "";
|
|
2328
|
+
return c < 2 && i > 0 ? p = "coords" : p = e.shapeInfo.logicalShape.map((x, S) => `coords.${d[S + u]}`).join(", "), `
|
|
2329
|
+
float ${o}() {
|
|
2330
|
+
${l} coords = getOutputCoords();
|
|
2331
|
+
${h}
|
|
2332
|
+
return get${r}(${p});
|
|
2333
|
+
}
|
|
2334
|
+
`;
|
|
2335
|
+
}
|
|
2336
|
+
function Te(e) {
|
|
2337
|
+
if (e <= 1)
|
|
2338
|
+
return "int";
|
|
2339
|
+
if (e === 2)
|
|
2340
|
+
return "ivec2";
|
|
2341
|
+
if (e === 3)
|
|
2342
|
+
return "ivec3";
|
|
2343
|
+
if (e === 4)
|
|
2344
|
+
return "ivec4";
|
|
2345
|
+
if (e === 5)
|
|
2346
|
+
return "ivec5";
|
|
2347
|
+
if (e === 6)
|
|
2348
|
+
return "ivec6";
|
|
2349
|
+
throw Error(`GPU for rank ${e} is not yet supported`);
|
|
2350
|
+
}
|
|
2351
|
+
function Z(e, t, n) {
|
|
2352
|
+
const { newShape: r, keptDims: o } = N(t), a = t.length, s = e && a === 3 && t[0] === 1, i = s ? t.slice(1) : r, c = !e && a > 1 && !E(t, n) && r.length < a || s;
|
|
2353
|
+
return { useSqueezeShape: c, uniformShape: c ? i : t, keptDims: o };
|
|
2354
|
+
}
|
|
2355
|
+
function B(e, t) {
|
|
2356
|
+
const n = JSON.parse(JSON.stringify(e));
|
|
2357
|
+
return n.shapeInfo.logicalShape = t, n;
|
|
2358
|
+
}
|
|
2359
|
+
function k(e, t) {
|
|
2360
|
+
return t.map((n) => e[n]).join(", ");
|
|
2361
|
+
}
|
|
2362
|
+
/**
|
|
2363
|
+
* @license
|
|
2364
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
2365
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2366
|
+
* you may not use this file except in compliance with the License.
|
|
2367
|
+
* You may obtain a copy of the License at
|
|
2368
|
+
*
|
|
2369
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2370
|
+
*
|
|
2371
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2372
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2373
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2374
|
+
* See the License for the specific language governing permissions and
|
|
2375
|
+
* limitations under the License.
|
|
2376
|
+
* =============================================================================
|
|
2377
|
+
*/
|
|
2378
|
+
const I = {}, P = {
|
|
2379
|
+
alpha: !1,
|
|
2380
|
+
antialias: !1,
|
|
2381
|
+
premultipliedAlpha: !1,
|
|
2382
|
+
preserveDrawingBuffer: !1,
|
|
2383
|
+
depth: !1,
|
|
2384
|
+
stencil: !1,
|
|
2385
|
+
failIfMajorPerformanceCaveat: !0
|
|
2386
|
+
};
|
|
2387
|
+
function _r(e, t) {
|
|
2388
|
+
I[e] = t;
|
|
2389
|
+
}
|
|
2390
|
+
function _(e, t) {
|
|
2391
|
+
if (!(e in I) || t != null) {
|
|
2392
|
+
const r = ar(e, t);
|
|
2393
|
+
if (r !== null)
|
|
2394
|
+
I[e] = r;
|
|
2395
|
+
else
|
|
2396
|
+
return console.log("Could not get context for WebGL version", e), null;
|
|
2397
|
+
}
|
|
2398
|
+
const n = I[e];
|
|
2399
|
+
return n == null || n.isContextLost() ? (delete I[e], _(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), I[e]);
|
|
2400
|
+
}
|
|
2401
|
+
function or(e) {
|
|
2402
|
+
if (!m().getBool("IS_SAFARI") && typeof OffscreenCanvas < "u" && e === 2)
|
|
2403
|
+
return new OffscreenCanvas(300, 150);
|
|
2404
|
+
if (typeof document < "u")
|
|
2405
|
+
return document.createElement("canvas");
|
|
2406
|
+
throw new Error("Cannot create a canvas in this context");
|
|
2407
|
+
}
|
|
2408
|
+
function ar(e, t) {
|
|
2409
|
+
if (e !== 1 && e !== 2)
|
|
2410
|
+
throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");
|
|
2411
|
+
const n = t ?? or(e);
|
|
2412
|
+
return n.addEventListener("webglcontextlost", (r) => {
|
|
2413
|
+
r.preventDefault(), delete I[e];
|
|
2414
|
+
}, !1), m().getBool("SOFTWARE_WEBGL_ENABLED") && (P.failIfMajorPerformanceCaveat = !1), e === 1 ? (
|
|
2415
|
+
// tslint:disable-next-line
|
|
2416
|
+
n.getContext("webgl", P) || n.getContext("experimental-webgl", P)
|
|
2417
|
+
) : n.getContext("webgl2", P);
|
|
2418
|
+
}
|
|
2419
|
+
/**
|
|
2420
|
+
* @license
|
|
2421
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
2422
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2423
|
+
* you may not use this file except in compliance with the License.
|
|
2424
|
+
* You may obtain a copy of the License at
|
|
2425
|
+
*
|
|
2426
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2427
|
+
*
|
|
2428
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2429
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2430
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2431
|
+
* See the License for the specific language governing permissions and
|
|
2432
|
+
* limitations under the License.
|
|
2433
|
+
* =============================================================================
|
|
2434
|
+
*/
|
|
2435
|
+
var se;
|
|
2436
|
+
(function(e) {
|
|
2437
|
+
e[e.DENSE = 0] = "DENSE", e[e.SHARED_BATCH = 1] = "SHARED_BATCH";
|
|
2438
|
+
})(se || (se = {}));
|
|
2439
|
+
var ie;
|
|
2440
|
+
(function(e) {
|
|
2441
|
+
e[e.RENDER = 0] = "RENDER", e[e.UPLOAD = 1] = "UPLOAD", e[e.PIXELS = 2] = "PIXELS", e[e.DOWNLOAD = 3] = "DOWNLOAD";
|
|
2442
|
+
})(ie || (ie = {}));
|
|
2443
|
+
var ce;
|
|
2444
|
+
(function(e) {
|
|
2445
|
+
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";
|
|
2446
|
+
})(ce || (ce = {}));
|
|
2447
|
+
function Ir(e, t) {
|
|
2448
|
+
return [t, e];
|
|
2449
|
+
}
|
|
2450
|
+
function Or(e, t) {
|
|
2451
|
+
return e * t;
|
|
2452
|
+
}
|
|
2453
|
+
function Nr(e) {
|
|
2454
|
+
const t = T(e), n = Math.ceil(t / 4);
|
|
2455
|
+
return q(n);
|
|
2456
|
+
}
|
|
2457
|
+
function sr(e, t) {
|
|
2458
|
+
return [
|
|
2459
|
+
Math.max(1, Math.ceil(t / 2)),
|
|
2460
|
+
Math.max(1, Math.ceil(e / 2))
|
|
2461
|
+
];
|
|
2462
|
+
}
|
|
2463
|
+
function yr(e, t) {
|
|
2464
|
+
const [n, r] = sr(e, t);
|
|
2465
|
+
return n * r * 4;
|
|
2466
|
+
}
|
|
2467
|
+
function Se(e, t) {
|
|
2468
|
+
const n = e;
|
|
2469
|
+
let r, o, a, s, i, c, l, f, u, h;
|
|
2470
|
+
return m().getNumber("WEBGL_VERSION") === 2 ? (r = n.R32F, o = n.R16F, a = n.RGBA16F, s = n.RGBA32F, i = n.RED, l = 4, f = 1, u = n.HALF_FLOAT, h = n.FLOAT, c = n.RGBA8) : (r = e.RGBA, o = e.RGBA, a = e.RGBA, s = n.RGBA, i = e.RGBA, l = 4, f = 4, u = t != null ? t.HALF_FLOAT_OES : null, h = e.FLOAT, c = e.RGBA), {
|
|
2471
|
+
internalFormatFloat: r,
|
|
2472
|
+
internalFormatHalfFloat: o,
|
|
2473
|
+
internalFormatPackedHalfFloat: a,
|
|
2474
|
+
internalFormatPackedFloat: s,
|
|
2475
|
+
textureFormatFloat: i,
|
|
2476
|
+
downloadTextureFormat: c,
|
|
2477
|
+
downloadUnpackNumChannels: l,
|
|
2478
|
+
defaultNumChannels: f,
|
|
2479
|
+
textureTypeHalfFloat: u,
|
|
2480
|
+
textureTypeFloat: h
|
|
2481
|
+
};
|
|
2482
|
+
}
|
|
2483
|
+
/**
|
|
2484
|
+
* @license
|
|
2485
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
2486
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2487
|
+
* you may not use this file except in compliance with the License.
|
|
2488
|
+
* You may obtain a copy of the License at
|
|
2489
|
+
*
|
|
2490
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2491
|
+
*
|
|
2492
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2493
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2494
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2495
|
+
* See the License for the specific language governing permissions and
|
|
2496
|
+
* limitations under the License.
|
|
2497
|
+
* =============================================================================
|
|
2498
|
+
*/
|
|
2499
|
+
function v(e, t) {
|
|
2500
|
+
const n = t();
|
|
2501
|
+
return m().getBool("DEBUG") && ir(e), n;
|
|
2502
|
+
}
|
|
2503
|
+
function ir(e) {
|
|
2504
|
+
const t = e.getError();
|
|
2505
|
+
if (t !== e.NO_ERROR)
|
|
2506
|
+
throw new Error("WebGL Error: " + lr(e, t));
|
|
2507
|
+
}
|
|
2508
|
+
const cr = 596e-10, ur = 65504;
|
|
2509
|
+
function Lr(e) {
|
|
2510
|
+
return !!(m().getBool("WEBGL_RENDER_FLOAT32_ENABLED") || e === 0 || cr < Math.abs(e) && Math.abs(e) < ur);
|
|
2511
|
+
}
|
|
2512
|
+
function lr(e, t) {
|
|
2513
|
+
switch (t) {
|
|
2514
|
+
case e.NO_ERROR:
|
|
2515
|
+
return "NO_ERROR";
|
|
2516
|
+
case e.INVALID_ENUM:
|
|
2517
|
+
return "INVALID_ENUM";
|
|
2518
|
+
case e.INVALID_VALUE:
|
|
2519
|
+
return "INVALID_VALUE";
|
|
2520
|
+
case e.INVALID_OPERATION:
|
|
2521
|
+
return "INVALID_OPERATION";
|
|
2522
|
+
case e.INVALID_FRAMEBUFFER_OPERATION:
|
|
2523
|
+
return "INVALID_FRAMEBUFFER_OPERATION";
|
|
2524
|
+
case e.OUT_OF_MEMORY:
|
|
2525
|
+
return "OUT_OF_MEMORY";
|
|
2526
|
+
case e.CONTEXT_LOST_WEBGL:
|
|
2527
|
+
return "CONTEXT_LOST_WEBGL";
|
|
2528
|
+
default:
|
|
2529
|
+
return `Unknown error code ${t}`;
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
function Dr(e, t) {
|
|
2533
|
+
return C(e, () => e.getExtension(t), 'Extension "' + t + '" not supported on this browser.');
|
|
2534
|
+
}
|
|
2535
|
+
function br(e, t) {
|
|
2536
|
+
const n = C(e, () => e.createShader(e.VERTEX_SHADER), "Unable to create vertex WebGLShader.");
|
|
2537
|
+
if (v(e, () => e.shaderSource(n, t)), v(e, () => e.compileShader(n)), e.getShaderParameter(n, e.COMPILE_STATUS) === !1)
|
|
2538
|
+
throw console.log(e.getShaderInfoLog(n)), new Error("Failed to compile vertex shader.");
|
|
2539
|
+
return n;
|
|
2540
|
+
}
|
|
2541
|
+
function fr(e, t) {
|
|
2542
|
+
const n = C(e, () => e.createShader(e.FRAGMENT_SHADER), "Unable to create fragment WebGLShader.");
|
|
2543
|
+
if (v(e, () => e.shaderSource(n, t)), v(e, () => e.compileShader(n)), m().get("ENGINE_COMPILE_ONLY"))
|
|
2544
|
+
return n;
|
|
2545
|
+
if (e.getShaderParameter(n, e.COMPILE_STATUS) === !1)
|
|
2546
|
+
throw dr(t, e.getShaderInfoLog(n)), new Error("Failed to compile fragment shader.");
|
|
2547
|
+
return n;
|
|
2548
|
+
}
|
|
2549
|
+
const hr = /ERROR: [0-9]+:([0-9]+):/g;
|
|
2550
|
+
function dr(e, t) {
|
|
2551
|
+
const n = hr.exec(t);
|
|
2552
|
+
if (n == null) {
|
|
2553
|
+
console.log(`Couldn't parse line number in error: ${t}`), console.log(e);
|
|
2554
|
+
return;
|
|
2555
|
+
}
|
|
2556
|
+
const r = +n[1], o = e.split(`
|
|
2557
|
+
`), a = o.length.toString().length + 2, s = o.map((u, h) => ee((h + 1).toString(), a) + u);
|
|
2558
|
+
let i = 0;
|
|
2559
|
+
for (let u = 0; u < s.length; u++)
|
|
2560
|
+
i = Math.max(s[u].length, i);
|
|
2561
|
+
const c = s.slice(0, r - 1), l = s.slice(r - 1, r), f = s.slice(r);
|
|
2562
|
+
console.log(c.join(`
|
|
2563
|
+
`)), console.log(t.split(`
|
|
2564
|
+
`)[0]), console.log(`%c ${ee(l[0], i)}`, "border:1px solid red; background-color:#e3d2d2; color:#a61717"), console.log(f.join(`
|
|
2565
|
+
`));
|
|
2566
|
+
}
|
|
2567
|
+
function Ur(e) {
|
|
2568
|
+
return C(e, () => e.createProgram(), "Unable to create WebGLProgram.");
|
|
2569
|
+
}
|
|
2570
|
+
function Mr(e, t) {
|
|
2571
|
+
if (v(e, () => e.linkProgram(t)), !m().get("ENGINE_COMPILE_ONLY") && e.getProgramParameter(t, e.LINK_STATUS) === !1)
|
|
2572
|
+
throw console.log(e.getProgramInfoLog(t)), new Error("Failed to link vertex and fragment shaders.");
|
|
2573
|
+
}
|
|
2574
|
+
function Br(e, t) {
|
|
2575
|
+
if (v(e, () => e.validateProgram(t)), e.getProgramParameter(t, e.VALIDATE_STATUS) === !1)
|
|
2576
|
+
throw console.log(e.getProgramInfoLog(t)), new Error("Shader program validation failed.");
|
|
2577
|
+
}
|
|
2578
|
+
function kr(e, t) {
|
|
2579
|
+
const n = C(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
|
|
2580
|
+
return v(e, () => e.bindBuffer(e.ARRAY_BUFFER, n)), v(e, () => e.bufferData(e.ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
|
|
2581
|
+
}
|
|
2582
|
+
function Pr(e, t) {
|
|
2583
|
+
const n = C(e, () => e.createBuffer(), "Unable to create WebGLBuffer");
|
|
2584
|
+
return v(e, () => e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, n)), v(e, () => e.bufferData(e.ELEMENT_ARRAY_BUFFER, t, e.STATIC_DRAW)), n;
|
|
2585
|
+
}
|
|
2586
|
+
function Wr(e) {
|
|
2587
|
+
return C(e, () => e.createTexture(), "Unable to create WebGLTexture.");
|
|
2588
|
+
}
|
|
2589
|
+
function Vr(e, t) {
|
|
2590
|
+
const n = m().getNumber("WEBGL_MAX_TEXTURE_SIZE");
|
|
2591
|
+
if (e <= 0 || t <= 0) {
|
|
2592
|
+
const r = `[${e}x${t}]`;
|
|
2593
|
+
throw new Error("Requested texture size " + r + " is invalid.");
|
|
2594
|
+
}
|
|
2595
|
+
if (e > n || t > n) {
|
|
2596
|
+
const r = `[${e}x${t}]`, o = `[${n}x${n}]`;
|
|
2597
|
+
throw new Error("Requested texture size " + r + " greater than WebGL maximum on this browser / GPU " + o + ".");
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
function Hr(e) {
|
|
2601
|
+
return C(e, () => e.createFramebuffer(), "Unable to create WebGLFramebuffer.");
|
|
2602
|
+
}
|
|
2603
|
+
function Xr(e, t, n, r, o, a, s) {
|
|
2604
|
+
const i = e.getAttribLocation(t, n);
|
|
2605
|
+
return i === -1 ? !1 : (v(e, () => e.bindBuffer(e.ARRAY_BUFFER, r)), v(e, () => e.vertexAttribPointer(i, o, e.FLOAT, !1, a, s)), v(e, () => e.enableVertexAttribArray(i)), !0);
|
|
2606
|
+
}
|
|
2607
|
+
function pr(e, t, n) {
|
|
2608
|
+
mr(e, n), v(e, () => e.activeTexture(e.TEXTURE0 + n)), v(e, () => e.bindTexture(e.TEXTURE_2D, t));
|
|
2609
|
+
}
|
|
2610
|
+
function Gr(e, t, n) {
|
|
2611
|
+
return C(e, () => e.getUniformLocation(t, n), 'uniform "' + n + '" not present in program.');
|
|
2612
|
+
}
|
|
2613
|
+
function zr(e, t, n) {
|
|
2614
|
+
return e.getUniformLocation(t, n);
|
|
2615
|
+
}
|
|
2616
|
+
function qr(e, t, n, r) {
|
|
2617
|
+
v(e, () => pr(e, t, r)), v(e, () => e.uniform1i(n, r));
|
|
2618
|
+
}
|
|
2619
|
+
function jr(e, t, n) {
|
|
2620
|
+
v(e, () => e.bindFramebuffer(e.FRAMEBUFFER, n)), v(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, t, 0));
|
|
2621
|
+
}
|
|
2622
|
+
function Jr(e, t) {
|
|
2623
|
+
v(e, () => e.bindFramebuffer(e.FRAMEBUFFER, t)), v(e, () => e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, null, 0));
|
|
2624
|
+
}
|
|
2625
|
+
function Yr(e) {
|
|
2626
|
+
const t = e.checkFramebufferStatus(e.FRAMEBUFFER);
|
|
2627
|
+
if (t !== e.FRAMEBUFFER_COMPLETE)
|
|
2628
|
+
throw new Error("Error binding framebuffer: " + xr(e, t));
|
|
2629
|
+
}
|
|
2630
|
+
function xr(e, t) {
|
|
2631
|
+
switch (t) {
|
|
2632
|
+
case e.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
|
2633
|
+
return "FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
|
|
2634
|
+
case e.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
|
2635
|
+
return "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
|
|
2636
|
+
case e.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
|
|
2637
|
+
return "FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
|
|
2638
|
+
case e.FRAMEBUFFER_UNSUPPORTED:
|
|
2639
|
+
return "FRAMEBUFFER_UNSUPPORTED";
|
|
2640
|
+
default:
|
|
2641
|
+
return `unknown error ${t}`;
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
function C(e, t, n) {
|
|
2645
|
+
const r = v(e, () => t());
|
|
2646
|
+
if (r == null)
|
|
2647
|
+
throw new Error(n);
|
|
2648
|
+
return r;
|
|
2649
|
+
}
|
|
2650
|
+
function mr(e, t) {
|
|
2651
|
+
const n = e.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1, r = t + e.TEXTURE0;
|
|
2652
|
+
if (r < e.TEXTURE0 || r > n) {
|
|
2653
|
+
const o = `[gl.TEXTURE0, gl.TEXTURE${n}]`;
|
|
2654
|
+
throw new Error(`textureUnit must be in ${o}.`);
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
function Ee(e, t = 2) {
|
|
2658
|
+
return T(e.slice(0, e.length - t));
|
|
2659
|
+
}
|
|
2660
|
+
function Re(e) {
|
|
2661
|
+
if (e.length === 0)
|
|
2662
|
+
throw Error("Cannot get rows and columns of an empty shape array.");
|
|
2663
|
+
return [
|
|
2664
|
+
e.length > 1 ? e[e.length - 2] : 1,
|
|
2665
|
+
e[e.length - 1]
|
|
2666
|
+
];
|
|
2667
|
+
}
|
|
2668
|
+
function Kr(e) {
|
|
2669
|
+
let t = [1, 1, 1];
|
|
2670
|
+
return e.length === 0 || e.length === 1 && e[0] === 1 || (t = [Ee(e), ...Re(e)]), t;
|
|
2671
|
+
}
|
|
2672
|
+
function Zr(e, t = !1) {
|
|
2673
|
+
let n = m().getNumber("WEBGL_MAX_TEXTURE_SIZE"), r = m().getNumber("WEBGL_MAX_SIZE_FOR_NARROW_TEXTURE");
|
|
2674
|
+
r === 1 / 0 && m().getBool("WEBGL_AUTO_SQUARIFY_NARROW_TEXTURE_SHAPE") && (r = n / 2), t && (n = n * 2, r = r * 2, e = e.map((i, c) => c >= e.length - 2 ? ye(e[c]) : e[c]), e.length === 1 && (e = [2, e[0]])), e.length !== 2 && (e = N(e).newShape);
|
|
2675
|
+
let o = T(e), a = null;
|
|
2676
|
+
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]]);
|
|
2677
|
+
const s = a != null && Math.max(...a) > r && Math.min(...a) <= (t ? 2 : 1) && Math.min(...a) > 0;
|
|
2678
|
+
if (a == null || s)
|
|
2679
|
+
if (t) {
|
|
2680
|
+
const i = Ee(e);
|
|
2681
|
+
let c = 2, l = 2;
|
|
2682
|
+
e.length && ([c, l] = Re(e)), o = i * (c / 2) * (l / 2), a = q(o).map((f) => f * 2);
|
|
2683
|
+
} else
|
|
2684
|
+
a = q(o);
|
|
2685
|
+
return a;
|
|
2686
|
+
}
|
|
2687
|
+
function W(e) {
|
|
2688
|
+
return e % 2 === 0;
|
|
2689
|
+
}
|
|
2690
|
+
function Qr(e, t) {
|
|
2691
|
+
if (e = e.slice(-2), t = t.slice(-2), E(e, t) || !e.length || !t.length || e[0] === 0 || e[1] === 0 || t[0] === 0 || t[1] === 0)
|
|
2692
|
+
return !0;
|
|
2693
|
+
if (e.length !== t.length) {
|
|
2694
|
+
const n = e[e.length - 1], r = t[t.length - 1];
|
|
2695
|
+
if (n === r || W(n) && W(r) && (e[0] === 1 || t[0] === 1))
|
|
2696
|
+
return !0;
|
|
2697
|
+
}
|
|
2698
|
+
return e[1] === t[1] && W(e[0]) && W(t[0]);
|
|
2699
|
+
}
|
|
2700
|
+
let X, G;
|
|
2701
|
+
function eo(e) {
|
|
2702
|
+
if (X == null) {
|
|
2703
|
+
const t = _(e);
|
|
2704
|
+
X = t.getParameter(t.MAX_TEXTURE_SIZE);
|
|
2705
|
+
}
|
|
2706
|
+
return X;
|
|
2707
|
+
}
|
|
2708
|
+
function to(e) {
|
|
2709
|
+
if (G == null) {
|
|
2710
|
+
const t = _(e);
|
|
2711
|
+
G = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);
|
|
2712
|
+
}
|
|
2713
|
+
return Math.min(16, G);
|
|
2714
|
+
}
|
|
2715
|
+
function no(e) {
|
|
2716
|
+
if (e === 0)
|
|
2717
|
+
return 0;
|
|
2718
|
+
let t;
|
|
2719
|
+
const n = _(e);
|
|
2720
|
+
return A(n, "EXT_disjoint_timer_query_webgl2") && e === 2 ? t = 2 : A(n, "EXT_disjoint_timer_query") ? t = 1 : t = 0, t;
|
|
2721
|
+
}
|
|
2722
|
+
function A(e, t) {
|
|
2723
|
+
return e.getExtension(t) != null;
|
|
2724
|
+
}
|
|
2725
|
+
function ro(e) {
|
|
2726
|
+
try {
|
|
2727
|
+
if (_(e) != null)
|
|
2728
|
+
return !0;
|
|
2729
|
+
} catch (t) {
|
|
2730
|
+
return console.log("Error when getting WebGL context: ", t), !1;
|
|
2731
|
+
}
|
|
2732
|
+
return !1;
|
|
2733
|
+
}
|
|
2734
|
+
function oo(e) {
|
|
2735
|
+
if (e === 0)
|
|
2736
|
+
return !1;
|
|
2737
|
+
const t = _(e);
|
|
2738
|
+
if (e === 1) {
|
|
2739
|
+
if (!A(t, "OES_texture_float"))
|
|
2740
|
+
return !1;
|
|
2741
|
+
} else if (!A(t, "EXT_color_buffer_float"))
|
|
2742
|
+
return !1;
|
|
2743
|
+
return j(t);
|
|
2744
|
+
}
|
|
2745
|
+
function ao(e) {
|
|
2746
|
+
if (e === 0)
|
|
2747
|
+
return !1;
|
|
2748
|
+
const t = _(e);
|
|
2749
|
+
if (e === 1) {
|
|
2750
|
+
if (!A(t, "OES_texture_float") || !A(t, "WEBGL_color_buffer_float"))
|
|
2751
|
+
return !1;
|
|
2752
|
+
} else {
|
|
2753
|
+
if (A(t, "EXT_color_buffer_float"))
|
|
2754
|
+
return j(t);
|
|
2755
|
+
const r = "EXT_color_buffer_half_float";
|
|
2756
|
+
if (A(t, r)) {
|
|
2757
|
+
const o = t.getExtension(r);
|
|
2758
|
+
return vr(t, o);
|
|
2759
|
+
}
|
|
2760
|
+
return !1;
|
|
2761
|
+
}
|
|
2762
|
+
return j(t);
|
|
2763
|
+
}
|
|
2764
|
+
function j(e) {
|
|
2765
|
+
const t = Se(e), n = e.createTexture();
|
|
2766
|
+
e.bindTexture(e.TEXTURE_2D, n), e.texImage2D(e.TEXTURE_2D, 0, t.internalFormatFloat, 1, 1, 0, t.textureFormatFloat, t.textureTypeFloat, null);
|
|
2767
|
+
const a = e.createFramebuffer();
|
|
2768
|
+
e.bindFramebuffer(e.FRAMEBUFFER, a), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, n, 0);
|
|
2769
|
+
const s = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
|
|
2770
|
+
return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(n), e.deleteFramebuffer(a), s;
|
|
2771
|
+
}
|
|
2772
|
+
function vr(e, t) {
|
|
2773
|
+
const n = Se(e, t), r = e.createTexture();
|
|
2774
|
+
e.bindTexture(e.TEXTURE_2D, r), e.texImage2D(e.TEXTURE_2D, 0, n.internalFormatHalfFloat, 1, 1, 0, n.textureFormatFloat, n.textureTypeHalfFloat, null);
|
|
2775
|
+
const s = e.createFramebuffer();
|
|
2776
|
+
e.bindFramebuffer(e.FRAMEBUFFER, s), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, r, 0);
|
|
2777
|
+
const i = e.checkFramebufferStatus(e.FRAMEBUFFER) === e.FRAMEBUFFER_COMPLETE;
|
|
2778
|
+
return e.bindTexture(e.TEXTURE_2D, null), e.bindFramebuffer(e.FRAMEBUFFER, null), e.deleteTexture(r), e.deleteFramebuffer(s), i;
|
|
2779
|
+
}
|
|
2780
|
+
function so(e) {
|
|
2781
|
+
return e !== 2 ? !1 : _(e).fenceSync != null;
|
|
2782
|
+
}
|
|
2783
|
+
function io(e, t) {
|
|
2784
|
+
Array.isArray(e) || (e = [e]), e.forEach((n) => {
|
|
2785
|
+
n != null && $(n.dtype !== "complex64", () => `${t} does not support complex64 tensors in the WebGL backend.`);
|
|
2786
|
+
});
|
|
2787
|
+
}
|
|
2788
|
+
/**
|
|
2789
|
+
* @license
|
|
2790
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
2791
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2792
|
+
* you may not use this file except in compliance with the License.
|
|
2793
|
+
* You may obtain a copy of the License at
|
|
2794
|
+
*
|
|
2795
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2796
|
+
*
|
|
2797
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2798
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2799
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2800
|
+
* See the License for the specific language governing permissions and
|
|
2801
|
+
* limitations under the License.
|
|
2802
|
+
* =============================================================================
|
|
2803
|
+
*/
|
|
2804
|
+
function co(e, t, n, r) {
|
|
2805
|
+
const o = n.map((f, u) => {
|
|
2806
|
+
const h = {
|
|
2807
|
+
logicalShape: f.shape,
|
|
2808
|
+
texShape: f.isUniform ? null : f.texData.texShape,
|
|
2809
|
+
isUniform: f.isUniform,
|
|
2810
|
+
isPacked: f.isUniform ? !1 : f.texData.isPacked,
|
|
2811
|
+
flatOffset: null
|
|
2812
|
+
};
|
|
2813
|
+
return f.texData != null && f.texData.slice != null && f.texData.slice.flatOffset > 0 && (h.flatOffset = f.texData.slice.flatOffset), { name: t.variableNames[u], shapeInfo: h };
|
|
2814
|
+
}), a = o.map((f) => f.shapeInfo), s = {
|
|
2815
|
+
logicalShape: r.shape,
|
|
2816
|
+
texShape: r.texData.texShape,
|
|
2817
|
+
isUniform: !1,
|
|
2818
|
+
isPacked: r.texData.isPacked,
|
|
2819
|
+
flatOffset: null
|
|
2820
|
+
}, i = Rn(o, s, t), c = fr(e.gl, i), l = e.createProgram(c);
|
|
2821
|
+
return m().get("ENGINE_COMPILE_ONLY") ? {
|
|
2822
|
+
program: t,
|
|
2823
|
+
fragmentShader: c,
|
|
2824
|
+
source: i,
|
|
2825
|
+
webGLProgram: l,
|
|
2826
|
+
inShapeInfos: a,
|
|
2827
|
+
outShapeInfo: s,
|
|
2828
|
+
variablesLocations: null,
|
|
2829
|
+
customUniformLocations: null,
|
|
2830
|
+
infLoc: null,
|
|
2831
|
+
nanLoc: null,
|
|
2832
|
+
outShapeLocation: null,
|
|
2833
|
+
outShapeStridesLocation: null,
|
|
2834
|
+
outTexShapeLocation: null
|
|
2835
|
+
} : (e.buildVao(l), Object.assign({
|
|
2836
|
+
program: t,
|
|
2837
|
+
fragmentShader: c,
|
|
2838
|
+
source: i,
|
|
2839
|
+
webGLProgram: l,
|
|
2840
|
+
inShapeInfos: a,
|
|
2841
|
+
outShapeInfo: s
|
|
2842
|
+
}, $r(e, t, l)));
|
|
2843
|
+
}
|
|
2844
|
+
function $r(e, t, n) {
|
|
2845
|
+
const r = [], o = [];
|
|
2846
|
+
let a, s, i, c = null, l = null;
|
|
2847
|
+
l = e.getUniformLocation(n, "NAN", !1), m().getNumber("WEBGL_VERSION") === 1 && (c = e.getUniformLocation(n, "INFINITY", !1));
|
|
2848
|
+
const f = !1;
|
|
2849
|
+
for (const u of t.variableNames) {
|
|
2850
|
+
const h = {
|
|
2851
|
+
name: u,
|
|
2852
|
+
uniform: e.getUniformLocation(n, u, f),
|
|
2853
|
+
offset: e.getUniformLocation(n, `offset${u}`, f)
|
|
2854
|
+
};
|
|
2855
|
+
t.enableShapeUniforms && (h.shape = e.getUniformLocation(n, `${u}Shape`, f), h.texShape = e.getUniformLocation(n, `${u}TexShape`, f)), r.push(h);
|
|
2856
|
+
}
|
|
2857
|
+
if (t.enableShapeUniforms && (a = e.getUniformLocation(n, "outShape", f), i = e.getUniformLocation(n, "outShapeStrides", f), s = e.getUniformLocation(n, "outTexShape", f)), t.customUniforms)
|
|
2858
|
+
for (const u of t.customUniforms)
|
|
2859
|
+
o.push(e.getUniformLocation(n, u.name, f));
|
|
2860
|
+
return {
|
|
2861
|
+
variablesLocations: r,
|
|
2862
|
+
customUniformLocations: o,
|
|
2863
|
+
infLoc: c,
|
|
2864
|
+
nanLoc: l,
|
|
2865
|
+
outShapeLocation: a,
|
|
2866
|
+
outShapeStridesLocation: i,
|
|
2867
|
+
outTexShapeLocation: s
|
|
2868
|
+
};
|
|
2869
|
+
}
|
|
2870
|
+
function ue(e, t) {
|
|
2871
|
+
if (e.length !== t.length)
|
|
2872
|
+
throw Error(`Binary was compiled with ${e.length} inputs, but was executed with ${t.length} inputs`);
|
|
2873
|
+
e.forEach((n, r) => {
|
|
2874
|
+
const o = n.logicalShape, a = t[r], s = a.shape;
|
|
2875
|
+
if (!E(o, s))
|
|
2876
|
+
throw Error(`Binary was compiled with different shapes than the current args. Shapes ${o} and ${s} must match`);
|
|
2877
|
+
if (n.isUniform && a.isUniform)
|
|
2878
|
+
return;
|
|
2879
|
+
const i = n.texShape, c = a.isUniform ? null : a.texData.texShape;
|
|
2880
|
+
if (!E(i, c))
|
|
2881
|
+
throw Error(`Binary was compiled with different texture shapes than the current args. Shape ${i} and ${c} must match`);
|
|
2882
|
+
});
|
|
2883
|
+
}
|
|
2884
|
+
function uo(e, t, n, r, o) {
|
|
2885
|
+
t.program.enableShapeUniforms || (ue(t.inShapeInfos, n), ue([t.outShapeInfo], [r]));
|
|
2886
|
+
const a = r.texData.texture, s = r.texData.texShape;
|
|
2887
|
+
r.texData.isPacked ? e.setOutputPackedMatrixTexture(a.texture, s[0], s[1]) : e.setOutputMatrixTexture(a.texture, s[0], s[1]), e.setProgram(t.webGLProgram), e.bindVertexArray(t.webGLProgram.vao), m().getNumber("WEBGL_VERSION") === 1 && t.infLoc !== null && e.gl.uniform1f(t.infLoc, 1 / 0), t.nanLoc !== null && e.gl.uniform1f(t.nanLoc, NaN);
|
|
2888
|
+
for (let c = 0; c < n.length; ++c) {
|
|
2889
|
+
const l = n[c], { uniform: f, offset: u, shape: h, texShape: d } = t.variablesLocations[c];
|
|
2890
|
+
if (h) {
|
|
2891
|
+
const { uniformShape: p } = Z(t.program.packedInputs, l.shape, l.texData.texShape);
|
|
2892
|
+
switch (p.length) {
|
|
2893
|
+
case 1:
|
|
2894
|
+
e.gl.uniform1iv(h, new Int32Array(p));
|
|
2895
|
+
break;
|
|
2896
|
+
case 2:
|
|
2897
|
+
e.gl.uniform2iv(h, new Int32Array(p));
|
|
2898
|
+
break;
|
|
2899
|
+
case 3:
|
|
2900
|
+
e.gl.uniform3iv(h, new Int32Array(p));
|
|
2901
|
+
break;
|
|
2902
|
+
case 4:
|
|
2903
|
+
e.gl.uniform4iv(h, new Int32Array(p));
|
|
2904
|
+
break;
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
if (d && e.gl.uniform2i(d, l.texData.texShape[0], l.texData.texShape[1]), f != null) {
|
|
2908
|
+
if (l.isUniform) {
|
|
2909
|
+
if (T(l.shape) < 2)
|
|
2910
|
+
e.gl.uniform1f(f, l.uniformValues[0]);
|
|
2911
|
+
else {
|
|
2912
|
+
let p = l.uniformValues;
|
|
2913
|
+
p instanceof Float32Array || (p = new Float32Array(p)), e.gl.uniform1fv(f, p);
|
|
2914
|
+
}
|
|
2915
|
+
continue;
|
|
2916
|
+
}
|
|
2917
|
+
l.texData.slice != null && u != null && e.gl.uniform1i(u, l.texData.slice.flatOffset), e.setInputMatrixTexture(l.texData.texture.texture, f, c);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
const i = t.outShapeLocation;
|
|
2921
|
+
if (i)
|
|
2922
|
+
switch (r.shape.length) {
|
|
2923
|
+
case 1:
|
|
2924
|
+
e.gl.uniform1iv(i, new Int32Array(r.shape));
|
|
2925
|
+
break;
|
|
2926
|
+
case 2:
|
|
2927
|
+
e.gl.uniform2iv(i, new Int32Array(r.shape));
|
|
2928
|
+
break;
|
|
2929
|
+
case 3:
|
|
2930
|
+
e.gl.uniform3iv(i, new Int32Array(r.shape));
|
|
2931
|
+
break;
|
|
2932
|
+
case 4:
|
|
2933
|
+
e.gl.uniform4iv(i, new Int32Array(r.shape));
|
|
2934
|
+
break;
|
|
2935
|
+
}
|
|
2936
|
+
if (t.outShapeStridesLocation) {
|
|
2937
|
+
const c = D(r.shape);
|
|
2938
|
+
switch (r.shape.length) {
|
|
2939
|
+
case 2:
|
|
2940
|
+
e.gl.uniform1iv(t.outShapeStridesLocation, new Int32Array(c));
|
|
2941
|
+
break;
|
|
2942
|
+
case 3:
|
|
2943
|
+
e.gl.uniform2iv(t.outShapeStridesLocation, new Int32Array(c));
|
|
2944
|
+
break;
|
|
2945
|
+
case 4:
|
|
2946
|
+
e.gl.uniform3iv(t.outShapeStridesLocation, new Int32Array(c));
|
|
2947
|
+
break;
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
if (t.outTexShapeLocation && e.gl.uniform2i(t.outTexShapeLocation, r.texData.texShape[0], r.texData.texShape[1]), t.program.customUniforms && o)
|
|
2951
|
+
for (let c = 0; c < t.program.customUniforms.length; ++c) {
|
|
2952
|
+
const l = t.program.customUniforms[c], f = t.customUniformLocations[c], u = o[c];
|
|
2953
|
+
if (l.type === "float")
|
|
2954
|
+
e.gl.uniform1fv(f, u);
|
|
2955
|
+
else if (l.type === "vec2")
|
|
2956
|
+
e.gl.uniform2fv(f, u);
|
|
2957
|
+
else if (l.type === "vec3")
|
|
2958
|
+
e.gl.uniform3fv(f, u);
|
|
2959
|
+
else if (l.type === "vec4")
|
|
2960
|
+
e.gl.uniform4fv(f, u);
|
|
2961
|
+
else if (l.type === "int")
|
|
2962
|
+
e.gl.uniform1iv(f, u);
|
|
2963
|
+
else if (l.type === "ivec2")
|
|
2964
|
+
e.gl.uniform2iv(f, u);
|
|
2965
|
+
else if (l.type === "ivec3")
|
|
2966
|
+
e.gl.uniform3iv(f, u);
|
|
2967
|
+
else if (l.type === "ivec4")
|
|
2968
|
+
e.gl.uniform4iv(f, u);
|
|
2969
|
+
else
|
|
2970
|
+
throw Error(`uniform type ${l.type} is not supported yet.`);
|
|
2971
|
+
}
|
|
2972
|
+
e.executeProgram();
|
|
2973
|
+
}
|
|
2974
|
+
function lo(e, t, n) {
|
|
2975
|
+
let r = "";
|
|
2976
|
+
t.concat(n).forEach((s) => {
|
|
2977
|
+
const i = s.texData != null && s.texData.slice != null && s.texData.slice.flatOffset > 0;
|
|
2978
|
+
if (e.enableShapeUniforms && !s.isUniform) {
|
|
2979
|
+
const c = s.texData.texShape, { useSqueezeShape: l, uniformShape: f, keptDims: u } = Z(e.packedInputs, s.shape, c);
|
|
2980
|
+
let h = "", d = "", p = "";
|
|
2981
|
+
if (f.length === 1 && e.packedInputs) {
|
|
2982
|
+
const L = [Math.ceil(c[0] / 2), Math.ceil(c[1] / 2)];
|
|
2983
|
+
h = `${L[0] > 1}_${L[1] > 1}`;
|
|
2984
|
+
} else if (f.length === 2 && !e.packedInputs)
|
|
2985
|
+
d = `${f[0] > 1}_${f[1] > 1}`;
|
|
2986
|
+
else if (f.length > 2 && !e.packedInputs) {
|
|
2987
|
+
const L = D(f);
|
|
2988
|
+
p = `${L[0] === c[1]}_${L[L.length - 1] === c[1]}`;
|
|
2989
|
+
}
|
|
2990
|
+
const x = s.shape.length, S = f.length === 2 && E(s.shape, c), g = T(s.shape) === 1, w = de(s.shape, n.shape), F = !e.packedInputs && x === n.shape.length && E(c, n.texData.texShape), ge = e.packedInputs || f.length > 2 ? "" : `${c[0] > 1}_${c[1] > 1}`;
|
|
2991
|
+
r += `${x}_${F}_${l ? u : ""}_${f.length}_${g}_${w}_${S}_${h}_${d}_${p}_${ge}_${i}`;
|
|
2992
|
+
} else {
|
|
2993
|
+
const c = s.isUniform ? "uniform" : s.texData.texShape;
|
|
2994
|
+
r += `${s.shape}_${c}_${i}`;
|
|
2995
|
+
}
|
|
2996
|
+
});
|
|
2997
|
+
const o = e.userCode;
|
|
2998
|
+
let a = e.constructor.name;
|
|
2999
|
+
return a += "_" + r + "_" + o + `${m().getNumber("WEBGL_VERSION")}`, a;
|
|
3000
|
+
}
|
|
3001
|
+
function fo(e) {
|
|
3002
|
+
return m().getBool("WEBGL_USE_SHAPES_UNIFORMS") && e <= 4;
|
|
3003
|
+
}
|
|
3004
|
+
export {
|
|
3005
|
+
Xt as $,
|
|
3006
|
+
fn as A,
|
|
3007
|
+
hn as B,
|
|
3008
|
+
dn as C,
|
|
3009
|
+
_t as D,
|
|
3010
|
+
It as E,
|
|
3011
|
+
Ot as F,
|
|
3012
|
+
Nt as G,
|
|
3013
|
+
yt as H,
|
|
3014
|
+
St as I,
|
|
3015
|
+
Et as J,
|
|
3016
|
+
jt as K,
|
|
3017
|
+
Yt as L,
|
|
3018
|
+
Kt as M,
|
|
3019
|
+
Jt as N,
|
|
3020
|
+
Zt as O,
|
|
3021
|
+
Bt as P,
|
|
3022
|
+
Mt as Q,
|
|
3023
|
+
R,
|
|
3024
|
+
Ut as S,
|
|
3025
|
+
bt as T,
|
|
3026
|
+
Dt as U,
|
|
3027
|
+
Lt as V,
|
|
3028
|
+
Ht as W,
|
|
3029
|
+
Pt as X,
|
|
3030
|
+
Wt as Y,
|
|
3031
|
+
Vt as Z,
|
|
3032
|
+
Gt as _,
|
|
3033
|
+
Cr as a,
|
|
3034
|
+
zt as a0,
|
|
3035
|
+
Tt as a1,
|
|
3036
|
+
mn as a2,
|
|
3037
|
+
At as a3,
|
|
3038
|
+
en as a4,
|
|
3039
|
+
ro as a5,
|
|
3040
|
+
eo as a6,
|
|
3041
|
+
to as a7,
|
|
3042
|
+
no as a8,
|
|
3043
|
+
oo as a9,
|
|
3044
|
+
Br as aA,
|
|
3045
|
+
Gr as aB,
|
|
3046
|
+
zr as aC,
|
|
3047
|
+
qr as aD,
|
|
3048
|
+
Yr as aE,
|
|
3049
|
+
jr as aF,
|
|
3050
|
+
_r as aG,
|
|
3051
|
+
ce as aH,
|
|
3052
|
+
Kr as aI,
|
|
3053
|
+
Nr as aJ,
|
|
3054
|
+
Lr as aK,
|
|
3055
|
+
lo as aL,
|
|
3056
|
+
co as aM,
|
|
3057
|
+
uo as aN,
|
|
3058
|
+
Zr as aO,
|
|
3059
|
+
dr as aP,
|
|
3060
|
+
$r as aQ,
|
|
3061
|
+
io as aR,
|
|
3062
|
+
xn as aS,
|
|
3063
|
+
pn as aT,
|
|
3064
|
+
ao as aa,
|
|
3065
|
+
so as ab,
|
|
3066
|
+
se as ac,
|
|
3067
|
+
b as ad,
|
|
3068
|
+
xe as ae,
|
|
3069
|
+
ie as af,
|
|
3070
|
+
Ar as ag,
|
|
3071
|
+
kr as ah,
|
|
3072
|
+
Pr as ai,
|
|
3073
|
+
v as aj,
|
|
3074
|
+
Ir as ak,
|
|
3075
|
+
br as al,
|
|
3076
|
+
Xr as am,
|
|
3077
|
+
Vr as an,
|
|
3078
|
+
Wr as ao,
|
|
3079
|
+
sr as ap,
|
|
3080
|
+
Or as aq,
|
|
3081
|
+
yr as ar,
|
|
3082
|
+
_ as as,
|
|
3083
|
+
Dr as at,
|
|
3084
|
+
A as au,
|
|
3085
|
+
Hr as av,
|
|
3086
|
+
Se as aw,
|
|
3087
|
+
Jr as ax,
|
|
3088
|
+
Ur as ay,
|
|
3089
|
+
Mr as az,
|
|
3090
|
+
wr as b,
|
|
3091
|
+
V as c,
|
|
3092
|
+
Ee as d,
|
|
3093
|
+
Re as e,
|
|
3094
|
+
Te as f,
|
|
3095
|
+
Fr as g,
|
|
3096
|
+
$n as h,
|
|
3097
|
+
Qr as i,
|
|
3098
|
+
Ft as j,
|
|
3099
|
+
gt as k,
|
|
3100
|
+
wt as l,
|
|
3101
|
+
kt as m,
|
|
3102
|
+
Rt as n,
|
|
3103
|
+
Tn as o,
|
|
3104
|
+
tn as p,
|
|
3105
|
+
nn as q,
|
|
3106
|
+
rn as r,
|
|
3107
|
+
on as s,
|
|
3108
|
+
an as t,
|
|
3109
|
+
fo as u,
|
|
3110
|
+
Ct as v,
|
|
3111
|
+
sn as w,
|
|
3112
|
+
cn as x,
|
|
3113
|
+
un as y,
|
|
3114
|
+
ln as z
|
|
3115
|
+
};
|