@genai-fi/nanogpt 0.5.5 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Generator.js +8 -7
- package/dist/NanoGPTModel.js +8 -8
- package/dist/{Reshape-Biok_3X1.js → Reshape-CLOrdpve.js} +2 -2
- package/dist/TeachableLLM.js +18 -17
- package/dist/{TiedEmbedding-8S8xn8e6.js → TiedEmbedding-BhxWO8QR.js} +5 -5
- package/dist/{axis_util-BczFISHz.js → axis_util-D17qZRQm.js} +1 -1
- package/dist/{broadcast_to-B7NGsBSh.js → broadcast_to-BMQLjvt_.js} +2 -2
- package/dist/{concat-DdKPyAtw.js → concat-DhZfF1GY.js} +1 -1
- package/dist/{dataset-iqT4Otvb.js → dataset-oilnemHf.js} +3 -3
- package/dist/{dropout-B09InSJS.js → dropout-CrMQPCeG.js} +1 -1
- package/dist/{gather-D6MsdXqc.js → gather-DZCMHZuN.js} +1 -1
- package/dist/{gpgpu_math-BFbOyvk4.js → gpgpu_math-Ctc31slO.js} +1 -1
- package/dist/{index-Du-bmOP8.js → index-bMBtI-WR.js} +50 -50
- package/dist/{kernel_funcs_utils-DShm7-0k.js → kernel_funcs_utils-CNmjLWnB.js} +26 -24
- 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 +3 -3
- package/dist/layers/TiedEmbedding.js +6 -6
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/{log_sum_exp-CxfBtUaG.js → log_sum_exp-BHdkCb4s.js} +5 -5
- package/dist/main.d.ts +1 -0
- package/dist/main.js +20 -19
- package/dist/{mat_mul-CbiqIe2d.js → mat_mul-BsrLfy81.js} +1 -1
- package/dist/{max-0Xnlpv8k.js → max-DechV4Bc.js} +1 -1
- package/dist/{norm-01kY9I2B.js → norm-B9hWHZH1.js} +5 -5
- package/dist/{ones-CrutWGas.js → ones-g0K8jVwm.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 +3 -3
- 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 +4 -4
- 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 +15 -11
- package/dist/ops/grads/fusedSoftmax.js +12 -10
- 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/log.d.ts +0 -0
- package/dist/ops/log.js +1 -0
- 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/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 +205 -3022
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.d.ts +17 -0
- package/dist/ops/webgl/log.js +39 -0
- package/dist/ops/webgl/matMulGelu.js +4 -4
- 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-CJNniCAV.js → ops-Mv7Ta72x.js} +13 -13
- package/dist/{random_width-C-v-35bY.js → random_width-BBAWzDym.js} +23 -23
- package/dist/{range-Bvs1hidm.js → range-DMaG9A3G.js} +1 -1
- package/dist/{reshape-BH7eBpwq.js → reshape-T4yDEqoF.js} +1 -1
- package/dist/shared-XNAoXhOa.js +2826 -0
- package/dist/{sin-CPAZXNjH.js → sin-EEhbrRO_.js} +1 -1
- package/dist/{slice_util-DskXqRZa.js → slice_util-Ddk0uxGJ.js} +1 -1
- package/dist/{softmax-DhWoBa7r.js → softmax-B2_IKPDR.js} +1 -1
- package/dist/{split-BCUhuU7B.js → split-dcks18H1.js} +1 -1
- package/dist/{stack-BV1v7l3S.js → stack-lpJ5kYvE.js} +1 -1
- package/dist/{sum-Cvq06317.js → sum-CutF5lj2.js} +1 -1
- package/dist/{tensor-DgTOPY6h.js → tensor-C15NA2LA.js} +1 -1
- package/dist/{tensor2d-CRWjDyUe.js → tensor2d-DZ_e5eKM.js} +1 -1
- package/dist/{tfjs_backend-D9Ytje0G.js → tfjs_backend-BDb8r9qx.js} +28 -28
- 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.js +2 -2
- package/dist/utilities/generate.js +3 -3
- package/dist/utilities/load.d.ts +25 -0
- package/dist/utilities/load.js +89 -37
- package/dist/utilities/profile.js +4 -4
- package/dist/utilities/safetensors.d.ts +3 -0
- package/dist/utilities/safetensors.js +83 -0
- package/dist/utilities/save.js +47 -29
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-DZ3fF0R2.js → variable-CdRKKp8x.js} +1 -1
- package/dist/{zeros-BaHhQTWf.js → zeros-CAbHfODe.js} +1 -1
- package/package.json +1 -1
|
@@ -1,2703 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { b as
|
|
5
|
-
import {
|
|
6
|
-
import { i as ne, c as oe } from "../../slice_util-DskXqRZa.js";
|
|
7
|
-
import { g as se } from "../../_commonjsHelpers-ByX85dGu.js";
|
|
8
|
-
import { r as st } from "../../Reshape-Biok_3X1.js";
|
|
9
|
-
function re(t, e) {
|
|
10
|
-
for (var n = 0; n < e.length; n++) {
|
|
11
|
-
const o = e[n];
|
|
12
|
-
if (typeof o != "string" && !Array.isArray(o)) {
|
|
13
|
-
for (const s in o)
|
|
14
|
-
if (s !== "default" && !(s in t)) {
|
|
15
|
-
const r = Object.getOwnPropertyDescriptor(o, s);
|
|
16
|
-
r && Object.defineProperty(t, s, r.get ? r : {
|
|
17
|
-
enumerable: !0,
|
|
18
|
-
get: () => o[s]
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return Object.freeze(Object.defineProperty(t, Symbol.toStringTag, { value: "Module" }));
|
|
24
|
-
}
|
|
25
|
-
var ht, xt;
|
|
26
|
-
function ie() {
|
|
27
|
-
if (xt) return ht;
|
|
28
|
-
xt = 1, ht = e;
|
|
29
|
-
var t = null;
|
|
30
|
-
try {
|
|
31
|
-
t = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
|
|
32
|
-
0,
|
|
33
|
-
97,
|
|
34
|
-
115,
|
|
35
|
-
109,
|
|
36
|
-
1,
|
|
37
|
-
0,
|
|
38
|
-
0,
|
|
39
|
-
0,
|
|
40
|
-
1,
|
|
41
|
-
13,
|
|
42
|
-
2,
|
|
43
|
-
96,
|
|
44
|
-
0,
|
|
45
|
-
1,
|
|
46
|
-
127,
|
|
47
|
-
96,
|
|
48
|
-
4,
|
|
49
|
-
127,
|
|
50
|
-
127,
|
|
51
|
-
127,
|
|
52
|
-
127,
|
|
53
|
-
1,
|
|
54
|
-
127,
|
|
55
|
-
3,
|
|
56
|
-
7,
|
|
57
|
-
6,
|
|
58
|
-
0,
|
|
59
|
-
1,
|
|
60
|
-
1,
|
|
61
|
-
1,
|
|
62
|
-
1,
|
|
63
|
-
1,
|
|
64
|
-
6,
|
|
65
|
-
6,
|
|
66
|
-
1,
|
|
67
|
-
127,
|
|
68
|
-
1,
|
|
69
|
-
65,
|
|
70
|
-
0,
|
|
71
|
-
11,
|
|
72
|
-
7,
|
|
73
|
-
50,
|
|
74
|
-
6,
|
|
75
|
-
3,
|
|
76
|
-
109,
|
|
77
|
-
117,
|
|
78
|
-
108,
|
|
79
|
-
0,
|
|
80
|
-
1,
|
|
81
|
-
5,
|
|
82
|
-
100,
|
|
83
|
-
105,
|
|
84
|
-
118,
|
|
85
|
-
95,
|
|
86
|
-
115,
|
|
87
|
-
0,
|
|
88
|
-
2,
|
|
89
|
-
5,
|
|
90
|
-
100,
|
|
91
|
-
105,
|
|
92
|
-
118,
|
|
93
|
-
95,
|
|
94
|
-
117,
|
|
95
|
-
0,
|
|
96
|
-
3,
|
|
97
|
-
5,
|
|
98
|
-
114,
|
|
99
|
-
101,
|
|
100
|
-
109,
|
|
101
|
-
95,
|
|
102
|
-
115,
|
|
103
|
-
0,
|
|
104
|
-
4,
|
|
105
|
-
5,
|
|
106
|
-
114,
|
|
107
|
-
101,
|
|
108
|
-
109,
|
|
109
|
-
95,
|
|
110
|
-
117,
|
|
111
|
-
0,
|
|
112
|
-
5,
|
|
113
|
-
8,
|
|
114
|
-
103,
|
|
115
|
-
101,
|
|
116
|
-
116,
|
|
117
|
-
95,
|
|
118
|
-
104,
|
|
119
|
-
105,
|
|
120
|
-
103,
|
|
121
|
-
104,
|
|
122
|
-
0,
|
|
123
|
-
0,
|
|
124
|
-
10,
|
|
125
|
-
191,
|
|
126
|
-
1,
|
|
127
|
-
6,
|
|
128
|
-
4,
|
|
129
|
-
0,
|
|
130
|
-
35,
|
|
131
|
-
0,
|
|
132
|
-
11,
|
|
133
|
-
36,
|
|
134
|
-
1,
|
|
135
|
-
1,
|
|
136
|
-
126,
|
|
137
|
-
32,
|
|
138
|
-
0,
|
|
139
|
-
173,
|
|
140
|
-
32,
|
|
141
|
-
1,
|
|
142
|
-
173,
|
|
143
|
-
66,
|
|
144
|
-
32,
|
|
145
|
-
134,
|
|
146
|
-
132,
|
|
147
|
-
32,
|
|
148
|
-
2,
|
|
149
|
-
173,
|
|
150
|
-
32,
|
|
151
|
-
3,
|
|
152
|
-
173,
|
|
153
|
-
66,
|
|
154
|
-
32,
|
|
155
|
-
134,
|
|
156
|
-
132,
|
|
157
|
-
126,
|
|
158
|
-
34,
|
|
159
|
-
4,
|
|
160
|
-
66,
|
|
161
|
-
32,
|
|
162
|
-
135,
|
|
163
|
-
167,
|
|
164
|
-
36,
|
|
165
|
-
0,
|
|
166
|
-
32,
|
|
167
|
-
4,
|
|
168
|
-
167,
|
|
169
|
-
11,
|
|
170
|
-
36,
|
|
171
|
-
1,
|
|
172
|
-
1,
|
|
173
|
-
126,
|
|
174
|
-
32,
|
|
175
|
-
0,
|
|
176
|
-
173,
|
|
177
|
-
32,
|
|
178
|
-
1,
|
|
179
|
-
173,
|
|
180
|
-
66,
|
|
181
|
-
32,
|
|
182
|
-
134,
|
|
183
|
-
132,
|
|
184
|
-
32,
|
|
185
|
-
2,
|
|
186
|
-
173,
|
|
187
|
-
32,
|
|
188
|
-
3,
|
|
189
|
-
173,
|
|
190
|
-
66,
|
|
191
|
-
32,
|
|
192
|
-
134,
|
|
193
|
-
132,
|
|
194
|
-
127,
|
|
195
|
-
34,
|
|
196
|
-
4,
|
|
197
|
-
66,
|
|
198
|
-
32,
|
|
199
|
-
135,
|
|
200
|
-
167,
|
|
201
|
-
36,
|
|
202
|
-
0,
|
|
203
|
-
32,
|
|
204
|
-
4,
|
|
205
|
-
167,
|
|
206
|
-
11,
|
|
207
|
-
36,
|
|
208
|
-
1,
|
|
209
|
-
1,
|
|
210
|
-
126,
|
|
211
|
-
32,
|
|
212
|
-
0,
|
|
213
|
-
173,
|
|
214
|
-
32,
|
|
215
|
-
1,
|
|
216
|
-
173,
|
|
217
|
-
66,
|
|
218
|
-
32,
|
|
219
|
-
134,
|
|
220
|
-
132,
|
|
221
|
-
32,
|
|
222
|
-
2,
|
|
223
|
-
173,
|
|
224
|
-
32,
|
|
225
|
-
3,
|
|
226
|
-
173,
|
|
227
|
-
66,
|
|
228
|
-
32,
|
|
229
|
-
134,
|
|
230
|
-
132,
|
|
231
|
-
128,
|
|
232
|
-
34,
|
|
233
|
-
4,
|
|
234
|
-
66,
|
|
235
|
-
32,
|
|
236
|
-
135,
|
|
237
|
-
167,
|
|
238
|
-
36,
|
|
239
|
-
0,
|
|
240
|
-
32,
|
|
241
|
-
4,
|
|
242
|
-
167,
|
|
243
|
-
11,
|
|
244
|
-
36,
|
|
245
|
-
1,
|
|
246
|
-
1,
|
|
247
|
-
126,
|
|
248
|
-
32,
|
|
249
|
-
0,
|
|
250
|
-
173,
|
|
251
|
-
32,
|
|
252
|
-
1,
|
|
253
|
-
173,
|
|
254
|
-
66,
|
|
255
|
-
32,
|
|
256
|
-
134,
|
|
257
|
-
132,
|
|
258
|
-
32,
|
|
259
|
-
2,
|
|
260
|
-
173,
|
|
261
|
-
32,
|
|
262
|
-
3,
|
|
263
|
-
173,
|
|
264
|
-
66,
|
|
265
|
-
32,
|
|
266
|
-
134,
|
|
267
|
-
132,
|
|
268
|
-
129,
|
|
269
|
-
34,
|
|
270
|
-
4,
|
|
271
|
-
66,
|
|
272
|
-
32,
|
|
273
|
-
135,
|
|
274
|
-
167,
|
|
275
|
-
36,
|
|
276
|
-
0,
|
|
277
|
-
32,
|
|
278
|
-
4,
|
|
279
|
-
167,
|
|
280
|
-
11,
|
|
281
|
-
36,
|
|
282
|
-
1,
|
|
283
|
-
1,
|
|
284
|
-
126,
|
|
285
|
-
32,
|
|
286
|
-
0,
|
|
287
|
-
173,
|
|
288
|
-
32,
|
|
289
|
-
1,
|
|
290
|
-
173,
|
|
291
|
-
66,
|
|
292
|
-
32,
|
|
293
|
-
134,
|
|
294
|
-
132,
|
|
295
|
-
32,
|
|
296
|
-
2,
|
|
297
|
-
173,
|
|
298
|
-
32,
|
|
299
|
-
3,
|
|
300
|
-
173,
|
|
301
|
-
66,
|
|
302
|
-
32,
|
|
303
|
-
134,
|
|
304
|
-
132,
|
|
305
|
-
130,
|
|
306
|
-
34,
|
|
307
|
-
4,
|
|
308
|
-
66,
|
|
309
|
-
32,
|
|
310
|
-
135,
|
|
311
|
-
167,
|
|
312
|
-
36,
|
|
313
|
-
0,
|
|
314
|
-
32,
|
|
315
|
-
4,
|
|
316
|
-
167,
|
|
317
|
-
11
|
|
318
|
-
])), {}).exports;
|
|
319
|
-
} catch {
|
|
320
|
-
}
|
|
321
|
-
function e(I, l, E) {
|
|
322
|
-
this.low = I | 0, this.high = l | 0, this.unsigned = !!E;
|
|
323
|
-
}
|
|
324
|
-
e.prototype.__isLong__, Object.defineProperty(e.prototype, "__isLong__", { value: !0 });
|
|
325
|
-
function n(I) {
|
|
326
|
-
return (I && I.__isLong__) === !0;
|
|
327
|
-
}
|
|
328
|
-
e.isLong = n;
|
|
329
|
-
var o = {}, s = {};
|
|
330
|
-
function r(I, l) {
|
|
331
|
-
var E, F, T;
|
|
332
|
-
return l ? (I >>>= 0, (T = 0 <= I && I < 256) && (F = s[I], F) ? F : (E = i(I, (I | 0) < 0 ? -1 : 0, !0), T && (s[I] = E), E)) : (I |= 0, (T = -128 <= I && I < 128) && (F = o[I], F) ? F : (E = i(I, I < 0 ? -1 : 0, !1), T && (o[I] = E), E));
|
|
333
|
-
}
|
|
334
|
-
e.fromInt = r;
|
|
335
|
-
function a(I, l) {
|
|
336
|
-
if (isNaN(I))
|
|
337
|
-
return l ? x : g;
|
|
338
|
-
if (l) {
|
|
339
|
-
if (I < 0)
|
|
340
|
-
return x;
|
|
341
|
-
if (I >= m)
|
|
342
|
-
return L;
|
|
343
|
-
} else {
|
|
344
|
-
if (I <= -v)
|
|
345
|
-
return _;
|
|
346
|
-
if (I + 1 >= v)
|
|
347
|
-
return D;
|
|
348
|
-
}
|
|
349
|
-
return I < 0 ? a(-I, l).neg() : i(I % p | 0, I / p | 0, l);
|
|
350
|
-
}
|
|
351
|
-
e.fromNumber = a;
|
|
352
|
-
function i(I, l, E) {
|
|
353
|
-
return new e(I, l, E);
|
|
354
|
-
}
|
|
355
|
-
e.fromBits = i;
|
|
356
|
-
var u = Math.pow;
|
|
357
|
-
function c(I, l, E) {
|
|
358
|
-
if (I.length === 0)
|
|
359
|
-
throw Error("empty string");
|
|
360
|
-
if (I === "NaN" || I === "Infinity" || I === "+Infinity" || I === "-Infinity")
|
|
361
|
-
return g;
|
|
362
|
-
if (typeof l == "number" ? (E = l, l = !1) : l = !!l, E = E || 10, E < 2 || 36 < E)
|
|
363
|
-
throw RangeError("radix");
|
|
364
|
-
var F;
|
|
365
|
-
if ((F = I.indexOf("-")) > 0)
|
|
366
|
-
throw Error("interior hyphen");
|
|
367
|
-
if (F === 0)
|
|
368
|
-
return c(I.substring(1), l, E).neg();
|
|
369
|
-
for (var T = a(u(E, 8)), $ = g, N = 0; N < I.length; N += 8) {
|
|
370
|
-
var k = Math.min(8, I.length - N), G = parseInt(I.substring(N, N + k), E);
|
|
371
|
-
if (k < 8) {
|
|
372
|
-
var z = a(u(E, k));
|
|
373
|
-
$ = $.mul(z).add(a(G));
|
|
374
|
-
} else
|
|
375
|
-
$ = $.mul(T), $ = $.add(a(G));
|
|
376
|
-
}
|
|
377
|
-
return $.unsigned = l, $;
|
|
378
|
-
}
|
|
379
|
-
e.fromString = c;
|
|
380
|
-
function h(I, l) {
|
|
381
|
-
return typeof I == "number" ? a(I, l) : typeof I == "string" ? c(I, l) : i(I.low, I.high, typeof l == "boolean" ? l : I.unsigned);
|
|
382
|
-
}
|
|
383
|
-
e.fromValue = h;
|
|
384
|
-
var f = 65536, w = 1 << 24, p = f * f, m = p * p, v = m / 2, d = r(w), g = r(0);
|
|
385
|
-
e.ZERO = g;
|
|
386
|
-
var x = r(0, !0);
|
|
387
|
-
e.UZERO = x;
|
|
388
|
-
var O = r(1);
|
|
389
|
-
e.ONE = O;
|
|
390
|
-
var b = r(1, !0);
|
|
391
|
-
e.UONE = b;
|
|
392
|
-
var V = r(-1);
|
|
393
|
-
e.NEG_ONE = V;
|
|
394
|
-
var D = i(-1, 2147483647, !1);
|
|
395
|
-
e.MAX_VALUE = D;
|
|
396
|
-
var L = i(-1, -1, !0);
|
|
397
|
-
e.MAX_UNSIGNED_VALUE = L;
|
|
398
|
-
var _ = i(0, -2147483648, !1);
|
|
399
|
-
e.MIN_VALUE = _;
|
|
400
|
-
var S = e.prototype;
|
|
401
|
-
return S.toInt = function() {
|
|
402
|
-
return this.unsigned ? this.low >>> 0 : this.low;
|
|
403
|
-
}, S.toNumber = function() {
|
|
404
|
-
return this.unsigned ? (this.high >>> 0) * p + (this.low >>> 0) : this.high * p + (this.low >>> 0);
|
|
405
|
-
}, S.toString = function(l) {
|
|
406
|
-
if (l = l || 10, l < 2 || 36 < l)
|
|
407
|
-
throw RangeError("radix");
|
|
408
|
-
if (this.isZero())
|
|
409
|
-
return "0";
|
|
410
|
-
if (this.isNegative())
|
|
411
|
-
if (this.eq(_)) {
|
|
412
|
-
var E = a(l), F = this.div(E), T = F.mul(E).sub(this);
|
|
413
|
-
return F.toString(l) + T.toInt().toString(l);
|
|
414
|
-
} else
|
|
415
|
-
return "-" + this.neg().toString(l);
|
|
416
|
-
for (var $ = a(u(l, 6), this.unsigned), N = this, k = ""; ; ) {
|
|
417
|
-
var G = N.div($), z = N.sub(G.mul($)).toInt() >>> 0, M = z.toString(l);
|
|
418
|
-
if (N = G, N.isZero())
|
|
419
|
-
return M + k;
|
|
420
|
-
for (; M.length < 6; )
|
|
421
|
-
M = "0" + M;
|
|
422
|
-
k = "" + M + k;
|
|
423
|
-
}
|
|
424
|
-
}, S.getHighBits = function() {
|
|
425
|
-
return this.high;
|
|
426
|
-
}, S.getHighBitsUnsigned = function() {
|
|
427
|
-
return this.high >>> 0;
|
|
428
|
-
}, S.getLowBits = function() {
|
|
429
|
-
return this.low;
|
|
430
|
-
}, S.getLowBitsUnsigned = function() {
|
|
431
|
-
return this.low >>> 0;
|
|
432
|
-
}, S.getNumBitsAbs = function() {
|
|
433
|
-
if (this.isNegative())
|
|
434
|
-
return this.eq(_) ? 64 : this.neg().getNumBitsAbs();
|
|
435
|
-
for (var l = this.high != 0 ? this.high : this.low, E = 31; E > 0 && (l & 1 << E) == 0; E--)
|
|
436
|
-
;
|
|
437
|
-
return this.high != 0 ? E + 33 : E + 1;
|
|
438
|
-
}, S.isZero = function() {
|
|
439
|
-
return this.high === 0 && this.low === 0;
|
|
440
|
-
}, S.eqz = S.isZero, S.isNegative = function() {
|
|
441
|
-
return !this.unsigned && this.high < 0;
|
|
442
|
-
}, S.isPositive = function() {
|
|
443
|
-
return this.unsigned || this.high >= 0;
|
|
444
|
-
}, S.isOdd = function() {
|
|
445
|
-
return (this.low & 1) === 1;
|
|
446
|
-
}, S.isEven = function() {
|
|
447
|
-
return (this.low & 1) === 0;
|
|
448
|
-
}, S.equals = function(l) {
|
|
449
|
-
return n(l) || (l = h(l)), this.unsigned !== l.unsigned && this.high >>> 31 === 1 && l.high >>> 31 === 1 ? !1 : this.high === l.high && this.low === l.low;
|
|
450
|
-
}, S.eq = S.equals, S.notEquals = function(l) {
|
|
451
|
-
return !this.eq(
|
|
452
|
-
/* validates */
|
|
453
|
-
l
|
|
454
|
-
);
|
|
455
|
-
}, S.neq = S.notEquals, S.ne = S.notEquals, S.lessThan = function(l) {
|
|
456
|
-
return this.comp(
|
|
457
|
-
/* validates */
|
|
458
|
-
l
|
|
459
|
-
) < 0;
|
|
460
|
-
}, S.lt = S.lessThan, S.lessThanOrEqual = function(l) {
|
|
461
|
-
return this.comp(
|
|
462
|
-
/* validates */
|
|
463
|
-
l
|
|
464
|
-
) <= 0;
|
|
465
|
-
}, S.lte = S.lessThanOrEqual, S.le = S.lessThanOrEqual, S.greaterThan = function(l) {
|
|
466
|
-
return this.comp(
|
|
467
|
-
/* validates */
|
|
468
|
-
l
|
|
469
|
-
) > 0;
|
|
470
|
-
}, S.gt = S.greaterThan, S.greaterThanOrEqual = function(l) {
|
|
471
|
-
return this.comp(
|
|
472
|
-
/* validates */
|
|
473
|
-
l
|
|
474
|
-
) >= 0;
|
|
475
|
-
}, S.gte = S.greaterThanOrEqual, S.ge = S.greaterThanOrEqual, S.compare = function(l) {
|
|
476
|
-
if (n(l) || (l = h(l)), this.eq(l))
|
|
477
|
-
return 0;
|
|
478
|
-
var E = this.isNegative(), F = l.isNegative();
|
|
479
|
-
return E && !F ? -1 : !E && F ? 1 : this.unsigned ? l.high >>> 0 > this.high >>> 0 || l.high === this.high && l.low >>> 0 > this.low >>> 0 ? -1 : 1 : this.sub(l).isNegative() ? -1 : 1;
|
|
480
|
-
}, S.comp = S.compare, S.negate = function() {
|
|
481
|
-
return !this.unsigned && this.eq(_) ? _ : this.not().add(O);
|
|
482
|
-
}, S.neg = S.negate, S.add = function(l) {
|
|
483
|
-
n(l) || (l = h(l));
|
|
484
|
-
var E = this.high >>> 16, F = this.high & 65535, T = this.low >>> 16, $ = this.low & 65535, N = l.high >>> 16, k = l.high & 65535, G = l.low >>> 16, z = l.low & 65535, M = 0, j = 0, P = 0, U = 0;
|
|
485
|
-
return U += $ + z, P += U >>> 16, U &= 65535, P += T + G, j += P >>> 16, P &= 65535, j += F + k, M += j >>> 16, j &= 65535, M += E + N, M &= 65535, i(P << 16 | U, M << 16 | j, this.unsigned);
|
|
486
|
-
}, S.subtract = function(l) {
|
|
487
|
-
return n(l) || (l = h(l)), this.add(l.neg());
|
|
488
|
-
}, S.sub = S.subtract, S.multiply = function(l) {
|
|
489
|
-
if (this.isZero())
|
|
490
|
-
return g;
|
|
491
|
-
if (n(l) || (l = h(l)), t) {
|
|
492
|
-
var E = t.mul(
|
|
493
|
-
this.low,
|
|
494
|
-
this.high,
|
|
495
|
-
l.low,
|
|
496
|
-
l.high
|
|
497
|
-
);
|
|
498
|
-
return i(E, t.get_high(), this.unsigned);
|
|
499
|
-
}
|
|
500
|
-
if (l.isZero())
|
|
501
|
-
return g;
|
|
502
|
-
if (this.eq(_))
|
|
503
|
-
return l.isOdd() ? _ : g;
|
|
504
|
-
if (l.eq(_))
|
|
505
|
-
return this.isOdd() ? _ : g;
|
|
506
|
-
if (this.isNegative())
|
|
507
|
-
return l.isNegative() ? this.neg().mul(l.neg()) : this.neg().mul(l).neg();
|
|
508
|
-
if (l.isNegative())
|
|
509
|
-
return this.mul(l.neg()).neg();
|
|
510
|
-
if (this.lt(d) && l.lt(d))
|
|
511
|
-
return a(this.toNumber() * l.toNumber(), this.unsigned);
|
|
512
|
-
var F = this.high >>> 16, T = this.high & 65535, $ = this.low >>> 16, N = this.low & 65535, k = l.high >>> 16, G = l.high & 65535, z = l.low >>> 16, M = l.low & 65535, j = 0, P = 0, U = 0, rt = 0;
|
|
513
|
-
return rt += N * M, U += rt >>> 16, rt &= 65535, U += $ * M, P += U >>> 16, U &= 65535, U += N * z, P += U >>> 16, U &= 65535, P += T * M, j += P >>> 16, P &= 65535, P += $ * z, j += P >>> 16, P &= 65535, P += N * G, j += P >>> 16, P &= 65535, j += F * M + T * z + $ * G + N * k, j &= 65535, i(U << 16 | rt, j << 16 | P, this.unsigned);
|
|
514
|
-
}, S.mul = S.multiply, S.divide = function(l) {
|
|
515
|
-
if (n(l) || (l = h(l)), l.isZero())
|
|
516
|
-
throw Error("division by zero");
|
|
517
|
-
if (t) {
|
|
518
|
-
if (!this.unsigned && this.high === -2147483648 && l.low === -1 && l.high === -1)
|
|
519
|
-
return this;
|
|
520
|
-
var E = (this.unsigned ? t.div_u : t.div_s)(
|
|
521
|
-
this.low,
|
|
522
|
-
this.high,
|
|
523
|
-
l.low,
|
|
524
|
-
l.high
|
|
525
|
-
);
|
|
526
|
-
return i(E, t.get_high(), this.unsigned);
|
|
527
|
-
}
|
|
528
|
-
if (this.isZero())
|
|
529
|
-
return this.unsigned ? x : g;
|
|
530
|
-
var F, T, $;
|
|
531
|
-
if (this.unsigned) {
|
|
532
|
-
if (l.unsigned || (l = l.toUnsigned()), l.gt(this))
|
|
533
|
-
return x;
|
|
534
|
-
if (l.gt(this.shru(1)))
|
|
535
|
-
return b;
|
|
536
|
-
$ = x;
|
|
537
|
-
} else {
|
|
538
|
-
if (this.eq(_)) {
|
|
539
|
-
if (l.eq(O) || l.eq(V))
|
|
540
|
-
return _;
|
|
541
|
-
if (l.eq(_))
|
|
542
|
-
return O;
|
|
543
|
-
var N = this.shr(1);
|
|
544
|
-
return F = N.div(l).shl(1), F.eq(g) ? l.isNegative() ? O : V : (T = this.sub(l.mul(F)), $ = F.add(T.div(l)), $);
|
|
545
|
-
} else if (l.eq(_))
|
|
546
|
-
return this.unsigned ? x : g;
|
|
547
|
-
if (this.isNegative())
|
|
548
|
-
return l.isNegative() ? this.neg().div(l.neg()) : this.neg().div(l).neg();
|
|
549
|
-
if (l.isNegative())
|
|
550
|
-
return this.div(l.neg()).neg();
|
|
551
|
-
$ = g;
|
|
552
|
-
}
|
|
553
|
-
for (T = this; T.gte(l); ) {
|
|
554
|
-
F = Math.max(1, Math.floor(T.toNumber() / l.toNumber()));
|
|
555
|
-
for (var k = Math.ceil(Math.log(F) / Math.LN2), G = k <= 48 ? 1 : u(2, k - 48), z = a(F), M = z.mul(l); M.isNegative() || M.gt(T); )
|
|
556
|
-
F -= G, z = a(F, this.unsigned), M = z.mul(l);
|
|
557
|
-
z.isZero() && (z = O), $ = $.add(z), T = T.sub(M);
|
|
558
|
-
}
|
|
559
|
-
return $;
|
|
560
|
-
}, S.div = S.divide, S.modulo = function(l) {
|
|
561
|
-
if (n(l) || (l = h(l)), t) {
|
|
562
|
-
var E = (this.unsigned ? t.rem_u : t.rem_s)(
|
|
563
|
-
this.low,
|
|
564
|
-
this.high,
|
|
565
|
-
l.low,
|
|
566
|
-
l.high
|
|
567
|
-
);
|
|
568
|
-
return i(E, t.get_high(), this.unsigned);
|
|
569
|
-
}
|
|
570
|
-
return this.sub(this.div(l).mul(l));
|
|
571
|
-
}, S.mod = S.modulo, S.rem = S.modulo, S.not = function() {
|
|
572
|
-
return i(~this.low, ~this.high, this.unsigned);
|
|
573
|
-
}, S.and = function(l) {
|
|
574
|
-
return n(l) || (l = h(l)), i(this.low & l.low, this.high & l.high, this.unsigned);
|
|
575
|
-
}, S.or = function(l) {
|
|
576
|
-
return n(l) || (l = h(l)), i(this.low | l.low, this.high | l.high, this.unsigned);
|
|
577
|
-
}, S.xor = function(l) {
|
|
578
|
-
return n(l) || (l = h(l)), i(this.low ^ l.low, this.high ^ l.high, this.unsigned);
|
|
579
|
-
}, S.shiftLeft = function(l) {
|
|
580
|
-
return n(l) && (l = l.toInt()), (l &= 63) === 0 ? this : l < 32 ? i(this.low << l, this.high << l | this.low >>> 32 - l, this.unsigned) : i(0, this.low << l - 32, this.unsigned);
|
|
581
|
-
}, S.shl = S.shiftLeft, S.shiftRight = function(l) {
|
|
582
|
-
return n(l) && (l = l.toInt()), (l &= 63) === 0 ? this : l < 32 ? i(this.low >>> l | this.high << 32 - l, this.high >> l, this.unsigned) : i(this.high >> l - 32, this.high >= 0 ? 0 : -1, this.unsigned);
|
|
583
|
-
}, S.shr = S.shiftRight, S.shiftRightUnsigned = function(l) {
|
|
584
|
-
if (n(l) && (l = l.toInt()), l &= 63, l === 0)
|
|
585
|
-
return this;
|
|
586
|
-
var E = this.high;
|
|
587
|
-
if (l < 32) {
|
|
588
|
-
var F = this.low;
|
|
589
|
-
return i(F >>> l | E << 32 - l, E >>> l, this.unsigned);
|
|
590
|
-
} else return l === 32 ? i(E, 0, this.unsigned) : i(E >>> l - 32, 0, this.unsigned);
|
|
591
|
-
}, S.shru = S.shiftRightUnsigned, S.shr_u = S.shiftRightUnsigned, S.toSigned = function() {
|
|
592
|
-
return this.unsigned ? i(this.low, this.high, !1) : this;
|
|
593
|
-
}, S.toUnsigned = function() {
|
|
594
|
-
return this.unsigned ? this : i(this.low, this.high, !0);
|
|
595
|
-
}, S.toBytes = function(l) {
|
|
596
|
-
return l ? this.toBytesLE() : this.toBytesBE();
|
|
597
|
-
}, S.toBytesLE = function() {
|
|
598
|
-
var l = this.high, E = this.low;
|
|
599
|
-
return [
|
|
600
|
-
E & 255,
|
|
601
|
-
E >>> 8 & 255,
|
|
602
|
-
E >>> 16 & 255,
|
|
603
|
-
E >>> 24,
|
|
604
|
-
l & 255,
|
|
605
|
-
l >>> 8 & 255,
|
|
606
|
-
l >>> 16 & 255,
|
|
607
|
-
l >>> 24
|
|
608
|
-
];
|
|
609
|
-
}, S.toBytesBE = function() {
|
|
610
|
-
var l = this.high, E = this.low;
|
|
611
|
-
return [
|
|
612
|
-
l >>> 24,
|
|
613
|
-
l >>> 16 & 255,
|
|
614
|
-
l >>> 8 & 255,
|
|
615
|
-
l & 255,
|
|
616
|
-
E >>> 24,
|
|
617
|
-
E >>> 16 & 255,
|
|
618
|
-
E >>> 8 & 255,
|
|
619
|
-
E & 255
|
|
620
|
-
];
|
|
621
|
-
}, e.fromBytes = function(l, E, F) {
|
|
622
|
-
return F ? e.fromBytesLE(l, E) : e.fromBytesBE(l, E);
|
|
623
|
-
}, e.fromBytesLE = function(l, E) {
|
|
624
|
-
return new e(
|
|
625
|
-
l[0] | l[1] << 8 | l[2] << 16 | l[3] << 24,
|
|
626
|
-
l[4] | l[5] << 8 | l[6] << 16 | l[7] << 24,
|
|
627
|
-
E
|
|
628
|
-
);
|
|
629
|
-
}, e.fromBytesBE = function(l, E) {
|
|
630
|
-
return new e(
|
|
631
|
-
l[4] << 24 | l[5] << 16 | l[6] << 8 | l[7],
|
|
632
|
-
l[0] << 24 | l[1] << 16 | l[2] << 8 | l[3],
|
|
633
|
-
E
|
|
634
|
-
);
|
|
635
|
-
}, ht;
|
|
636
|
-
}
|
|
637
|
-
var Lt = ie();
|
|
638
|
-
const _t = /* @__PURE__ */ se(Lt), ae = /* @__PURE__ */ re({
|
|
639
|
-
__proto__: null,
|
|
640
|
-
default: _t
|
|
641
|
-
}, [Lt]);
|
|
642
|
-
/**
|
|
643
|
-
* @license
|
|
644
|
-
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
645
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
646
|
-
* you may not use this file except in compliance with the License.
|
|
647
|
-
* You may obtain a copy of the License at
|
|
648
|
-
*
|
|
649
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
650
|
-
*
|
|
651
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
652
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
653
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
654
|
-
* See the License for the specific language governing permissions and
|
|
655
|
-
* limitations under the License.
|
|
656
|
-
* =============================================================================
|
|
657
|
-
*/
|
|
658
|
-
const Y = (
|
|
659
|
-
// tslint:disable-next-line
|
|
660
|
-
_t || ae
|
|
661
|
-
);
|
|
662
|
-
function lt(t) {
|
|
663
|
-
return Y.fromString(t, !0, 16);
|
|
664
|
-
}
|
|
665
|
-
const Nt = lt("c3a5c85c97cb3127"), Q = lt("b492b66fbe98f273"), W = lt("9ae16a3b2f90404f");
|
|
666
|
-
function gt(t) {
|
|
667
|
-
return t.xor(t.shru(47));
|
|
668
|
-
}
|
|
669
|
-
function At(t, e, n) {
|
|
670
|
-
const o = t.slice(e, e + n);
|
|
671
|
-
return Y.fromBytes(Array.from(o), !0, !0);
|
|
672
|
-
}
|
|
673
|
-
function R(t, e) {
|
|
674
|
-
return At(t, e, 8);
|
|
675
|
-
}
|
|
676
|
-
function St(t, e) {
|
|
677
|
-
return At(t, e, 4);
|
|
678
|
-
}
|
|
679
|
-
function A(t, e) {
|
|
680
|
-
return e === 0 ? t : t.shru(e).or(t.shl(64 - e));
|
|
681
|
-
}
|
|
682
|
-
function X(t, e, n = lt("9ddfea08eb382d69")) {
|
|
683
|
-
let o = t.xor(e).mul(n);
|
|
684
|
-
o = o.xor(o.shru(47));
|
|
685
|
-
let s = e.xor(o).mul(n);
|
|
686
|
-
return s = s.xor(s.shru(47)), s = s.mul(n), s;
|
|
687
|
-
}
|
|
688
|
-
function ue(t, e, n, o, s, r) {
|
|
689
|
-
s = s.add(t), r = A(r.add(s).add(o), 21);
|
|
690
|
-
const a = s;
|
|
691
|
-
return s = s.add(e), s = s.add(n), r = r.add(A(s, 44)), [s.add(o), r.add(a)];
|
|
692
|
-
}
|
|
693
|
-
function it(t, e, n, o) {
|
|
694
|
-
return ue(R(t, e), R(t, e + 8), R(t, e + 16), R(t, e + 24), n, o);
|
|
695
|
-
}
|
|
696
|
-
function le(t, e = t.length) {
|
|
697
|
-
if (e >= 8) {
|
|
698
|
-
const n = W.add(e * 2), o = R(t, 0).add(W), s = R(t, e - 8), r = A(s, 37).mul(n).add(o), a = A(o, 25).add(s).mul(n);
|
|
699
|
-
return X(r, a, n);
|
|
700
|
-
}
|
|
701
|
-
if (e >= 4) {
|
|
702
|
-
const n = W.add(e * 2), o = St(t, 0);
|
|
703
|
-
return X(o.shl(3).add(e), St(t, e - 4), n);
|
|
704
|
-
}
|
|
705
|
-
if (e > 0) {
|
|
706
|
-
const n = t[0], o = t[e >> 1], s = t[e - 1], r = n + (o << 8), a = e + (s << 2);
|
|
707
|
-
return gt(W.mul(r).xor(Nt.mul(a))).mul(W);
|
|
708
|
-
}
|
|
709
|
-
return W;
|
|
710
|
-
}
|
|
711
|
-
function ce(t, e = t.length) {
|
|
712
|
-
const n = W.add(e * 2), o = R(t, 0).mul(Q), s = R(t, 8), r = R(t, e - 8).mul(n), a = R(t, e - 16).mul(W);
|
|
713
|
-
return X(A(o.add(s), 43).add(A(r, 30)).add(a), o.add(A(s.add(W), 18)).add(r), n);
|
|
714
|
-
}
|
|
715
|
-
function he(t, e = t.length) {
|
|
716
|
-
const n = W.add(e * 2), o = R(t, 0).mul(W), s = R(t, 8), r = R(t, e - 8).mul(n), a = R(t, e - 16).mul(W), i = A(o.add(s), 43).add(A(r, 30)).add(a), u = X(i, o.add(A(s.add(W), 18)).add(r), n), c = R(t, 16).mul(n), h = R(t, 24), f = i.add(R(t, e - 32)).mul(n), w = u.add(R(t, e - 24)).mul(n);
|
|
717
|
-
return X(A(c.add(h), 43).add(A(f, 30)).add(w), c.add(A(h.add(o), 18)).add(f), n);
|
|
718
|
-
}
|
|
719
|
-
function fe(t, e = t.length) {
|
|
720
|
-
const n = Y.fromNumber(81, !0);
|
|
721
|
-
if (e <= 32)
|
|
722
|
-
return e <= 16 ? le(t, e) : ce(t, e);
|
|
723
|
-
if (e <= 64)
|
|
724
|
-
return he(t, e);
|
|
725
|
-
let o = n, s = n.mul(Q).add(113), r = gt(s.mul(W).add(113)).mul(W), a = [Y.UZERO, Y.UZERO], i = [Y.UZERO, Y.UZERO];
|
|
726
|
-
o = o.mul(W).add(R(t, 0));
|
|
727
|
-
let u = 0;
|
|
728
|
-
const c = (e - 1 >> 6) * 64, h = c + (e - 1 & 63) - 63;
|
|
729
|
-
do
|
|
730
|
-
o = A(o.add(s).add(a[0]).add(R(t, u + 8)), 37).mul(Q), s = A(s.add(a[1]).add(R(t, u + 48)), 42).mul(Q), o = o.xor(i[1]), s = s.add(a[0]).add(R(t, u + 40)), r = A(r.add(i[0]), 33).mul(Q), a = it(t, u, a[1].mul(Q), o.add(i[0])), i = it(t, u + 32, r.add(i[1]), s.add(R(t, u + 16))), [r, o] = [o, r], u += 64;
|
|
731
|
-
while (u !== c);
|
|
732
|
-
const f = Q.add(r.and(255).shl(1));
|
|
733
|
-
return u = h, i[0] = i[0].add(e - 1 & 63), a[0] = a[0].add(i[0]), i[0] = i[0].add(a[0]), o = A(o.add(s).add(a[0]).add(R(t, u + 8)), 37).mul(f), s = A(s.add(a[1]).add(R(t, u + 48)), 42).mul(f), o = o.xor(i[1].mul(9)), s = s.add(a[0].mul(9).add(R(t, u + 40))), r = A(r.add(i[0]), 33).mul(f), a = it(t, u, a[1].mul(f), o.add(i[0])), i = it(t, u + 32, r.add(i[1]), s.add(R(t, u + 16))), [r, o] = [o, r], X(X(a[0], i[0], f).add(gt(s).mul(Nt)).add(r), X(a[1], i[1], f).add(o), f);
|
|
734
|
-
}
|
|
735
|
-
/**
|
|
736
|
-
* @license
|
|
737
|
-
* Copyright 2022 Google LLC. All Rights Reserved.
|
|
738
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
739
|
-
* you may not use this file except in compliance with the License.
|
|
740
|
-
* You may obtain a copy of the License at
|
|
741
|
-
*
|
|
742
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
743
|
-
*
|
|
744
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
745
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
746
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
747
|
-
* See the License for the specific language governing permissions and
|
|
748
|
-
* limitations under the License.
|
|
749
|
-
* =============================================================================
|
|
750
|
-
*/
|
|
751
|
-
var H;
|
|
752
|
-
(function(t) {
|
|
753
|
-
t[t.FIRST_DIM_SIZE = 0] = "FIRST_DIM_SIZE", t[t.VALUE_ROWIDS = 1] = "VALUE_ROWIDS", t[t.ROW_LENGTHS = 2] = "ROW_LENGTHS", t[t.ROW_SPLITS = 3] = "ROW_SPLITS", t[t.ROW_LIMITS = 4] = "ROW_LIMITS", t[t.ROW_STARTS = 5] = "ROW_STARTS";
|
|
754
|
-
})(H || (H = {}));
|
|
755
|
-
function de(t, e, n) {
|
|
756
|
-
let o = new Array();
|
|
757
|
-
if (n == null && e == null)
|
|
758
|
-
return o;
|
|
759
|
-
if (e == null)
|
|
760
|
-
for (; o.length < t + n.length; )
|
|
761
|
-
o.push(-1);
|
|
762
|
-
else
|
|
763
|
-
o = e.slice();
|
|
764
|
-
if (n == null)
|
|
765
|
-
return o;
|
|
766
|
-
if (t + n.length !== o.length)
|
|
767
|
-
throw new Error(`rt input.shape and shape=${e} are incompatible: rt input.rank = ${t + n.length}, but shape.rank = ${o.length}`);
|
|
768
|
-
for (let s = 1; s < n.length; ++s) {
|
|
769
|
-
const r = n[s], a = o[o.length - n.length + s], i = o[a];
|
|
770
|
-
if (r >= 0)
|
|
771
|
-
if (i >= 0) {
|
|
772
|
-
if (i !== r)
|
|
773
|
-
throw new Error(`rt input.shape and shape=${e} are incompatible: rt input.shape[${s + t}] = ${r} but shape[${s + t}] = ${i}`);
|
|
774
|
-
} else
|
|
775
|
-
o[a] = r;
|
|
776
|
-
}
|
|
777
|
-
return o;
|
|
778
|
-
}
|
|
779
|
-
function ge(t) {
|
|
780
|
-
const e = {
|
|
781
|
-
FIRST_DIM_SIZE: H.FIRST_DIM_SIZE,
|
|
782
|
-
VALUE_ROWIDS: H.VALUE_ROWIDS,
|
|
783
|
-
ROW_LENGTHS: H.ROW_LENGTHS,
|
|
784
|
-
ROW_SPLITS: H.ROW_SPLITS,
|
|
785
|
-
ROW_LIMITS: H.ROW_LIMITS,
|
|
786
|
-
ROW_STARTS: H.ROW_STARTS
|
|
787
|
-
}, n = [];
|
|
788
|
-
for (const o of t)
|
|
789
|
-
if (o in e)
|
|
790
|
-
n.push(e[o]);
|
|
791
|
-
else
|
|
792
|
-
break;
|
|
793
|
-
return n;
|
|
794
|
-
}
|
|
795
|
-
function pe(t) {
|
|
796
|
-
return t.length === 0 ? 0 : t[0] === H.FIRST_DIM_SIZE ? t.length - 1 : t.length;
|
|
797
|
-
}
|
|
798
|
-
function me(t, e) {
|
|
799
|
-
if (t == null || e == null)
|
|
800
|
-
return;
|
|
801
|
-
const n = t.length, o = e.length;
|
|
802
|
-
if (n >= o)
|
|
803
|
-
throw new Error(`defaultValue.shape=${t} and ragged tensor flatValues.shape=${e}, are incompatible: defaultValue.rank = ${n} must be less than ragged tensor input flatValues.rank = ${o})`);
|
|
804
|
-
for (let s = 0; s < Math.min(n, o - 1); ++s) {
|
|
805
|
-
const r = t[s], a = e[s + 1];
|
|
806
|
-
if (r >= 0 && a >= 0 && r !== 1 && r !== a)
|
|
807
|
-
throw new Error(`defaultValue.shape=${t}, and ragged tensor input flatValues.shape=${e} are incompatible: defaultValue.shape[${s - t.length}] = ${r} but ragged tensor input.flatValues.shape[${s - t.length}] = ${a}`);
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* @license
|
|
812
|
-
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
813
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
814
|
-
* you may not use this file except in compliance with the License.
|
|
815
|
-
* You may obtain a copy of the License at
|
|
816
|
-
*
|
|
817
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
818
|
-
*
|
|
819
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
820
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
821
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
822
|
-
* See the License for the specific language governing permissions and
|
|
823
|
-
* limitations under the License.
|
|
824
|
-
* =============================================================================
|
|
825
|
-
*/
|
|
826
|
-
const we = 30;
|
|
827
|
-
function Ie(t) {
|
|
828
|
-
return t <= we ? t : qt(t, Math.floor(Math.sqrt(t)));
|
|
829
|
-
}
|
|
830
|
-
/**
|
|
831
|
-
* @license
|
|
832
|
-
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
833
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
834
|
-
* you may not use this file except in compliance with the License.
|
|
835
|
-
* You may obtain a copy of the License at
|
|
836
|
-
*
|
|
837
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
838
|
-
*
|
|
839
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
840
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
841
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
842
|
-
* See the License for the specific language governing permissions and
|
|
843
|
-
* limitations under the License.
|
|
844
|
-
* =============================================================================
|
|
845
|
-
*/
|
|
846
|
-
function xe(t) {
|
|
847
|
-
return `Received SparseTensor with denseShape[0] = 0 but
|
|
848
|
-
indices.shape[0] = ${t}`;
|
|
849
|
-
}
|
|
850
|
-
function Se(t, e) {
|
|
851
|
-
return `indices(${t}, 0) is invalid: ${e} < 0`;
|
|
852
|
-
}
|
|
853
|
-
function Ee(t, e, n) {
|
|
854
|
-
return `indices(${t}, 0) is invalid: ${e} >= ${n}`;
|
|
855
|
-
}
|
|
856
|
-
/**
|
|
857
|
-
* @license
|
|
858
|
-
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
859
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
860
|
-
* you may not use this file except in compliance with the License.
|
|
861
|
-
* You may obtain a copy of the License at
|
|
862
|
-
*
|
|
863
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
864
|
-
*
|
|
865
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
866
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
867
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
868
|
-
* See the License for the specific language governing permissions and
|
|
869
|
-
* limitations under the License.
|
|
870
|
-
* =============================================================================
|
|
871
|
-
*/
|
|
872
|
-
function ve(t, e) {
|
|
873
|
-
return `only one output dimension may be -1, not both ${t} and ${e}`;
|
|
874
|
-
}
|
|
875
|
-
function be(t, e) {
|
|
876
|
-
return `size ${t} must be non-negative, not ${e}`;
|
|
877
|
-
}
|
|
878
|
-
function Oe() {
|
|
879
|
-
return "reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero";
|
|
880
|
-
}
|
|
881
|
-
function Fe(t, e) {
|
|
882
|
-
const n = y(t), o = y(e);
|
|
883
|
-
return `Input to reshape is a SparseTensor with ${n}
|
|
884
|
-
dense values, but the requested shape requires a multiple of ${o}. inputShape=${t} outputShape= ${e}`;
|
|
885
|
-
}
|
|
886
|
-
function Re(t, e) {
|
|
887
|
-
const n = y(t), o = y(e);
|
|
888
|
-
return `Input to reshape is a tensor with ${n} dense values, but the requested shape has ${o}. inputShape=${t} outputShape=${e}`;
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* @license
|
|
892
|
-
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
893
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
894
|
-
* you may not use this file except in compliance with the License.
|
|
895
|
-
* You may obtain a copy of the License at
|
|
896
|
-
*
|
|
897
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
898
|
-
*
|
|
899
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
900
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
901
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
902
|
-
* See the License for the specific language governing permissions and
|
|
903
|
-
* limitations under the License.
|
|
904
|
-
* =============================================================================
|
|
905
|
-
*/
|
|
906
|
-
function Et() {
|
|
907
|
-
return "segment ids must be >= 0";
|
|
908
|
-
}
|
|
909
|
-
function $e() {
|
|
910
|
-
return "segment ids are not increasing";
|
|
911
|
-
}
|
|
912
|
-
function ye(t, e) {
|
|
913
|
-
return `Segment id ${t} out of range [0, ${e}), possibly because segmentIds input is not sorted.`;
|
|
914
|
-
}
|
|
915
|
-
function Te(t, e, n) {
|
|
916
|
-
return `Bad: indices[${t}] == ${e} out of range [0, ${n})`;
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
* @license
|
|
920
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
921
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
922
|
-
* you may not use this file except in compliance with the License.
|
|
923
|
-
* You may obtain a copy of the License at
|
|
924
|
-
*
|
|
925
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
926
|
-
*
|
|
927
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
928
|
-
* distributed under the License is distributed on an AS IS BASIS,
|
|
929
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
930
|
-
* See the License for the specific language governing permissions and
|
|
931
|
-
* limitations under the License.
|
|
932
|
-
* =============================================================================
|
|
933
|
-
*/
|
|
934
|
-
function Ve(t) {
|
|
935
|
-
const e = new Float32Array(t.length);
|
|
936
|
-
for (let n = 0; n < t.length; ++n)
|
|
937
|
-
e[n] = Math.abs(t[n]);
|
|
938
|
-
return e;
|
|
939
|
-
}
|
|
940
|
-
/**
|
|
941
|
-
* @license
|
|
942
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
943
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
944
|
-
* you may not use this file except in compliance with the License.
|
|
945
|
-
* You may obtain a copy of the License at
|
|
946
|
-
*
|
|
947
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
948
|
-
*
|
|
949
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
950
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
951
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
952
|
-
* See the License for the specific language governing permissions and
|
|
953
|
-
* limitations under the License.
|
|
954
|
-
* =============================================================================
|
|
955
|
-
*/
|
|
956
|
-
function C(t) {
|
|
957
|
-
return (e, n, o, s, r) => {
|
|
958
|
-
const a = Ct(e, n), i = a.length, u = J(a), c = y(a), h = nt(r, c), f = e.length, w = n.length, p = J(e), m = J(n), v = It(e, a), d = It(n, a);
|
|
959
|
-
if (v.length + d.length === 0)
|
|
960
|
-
for (let g = 0; g < h.length; ++g)
|
|
961
|
-
h[g] = t(o[g % o.length], s[g % s.length]);
|
|
962
|
-
else
|
|
963
|
-
for (let g = 0; g < h.length; ++g) {
|
|
964
|
-
const x = pt(g, i, u), O = x.slice(-f);
|
|
965
|
-
v.forEach((L) => O[L] = 0);
|
|
966
|
-
const b = ft(O, f, p), V = x.slice(-w);
|
|
967
|
-
d.forEach((L) => V[L] = 0);
|
|
968
|
-
const D = ft(V, w, m);
|
|
969
|
-
h[g] = t(o[b], s[D]);
|
|
970
|
-
}
|
|
971
|
-
return [h, a];
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
/**
|
|
975
|
-
* @license
|
|
976
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
977
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
978
|
-
* you may not use this file except in compliance with the License.
|
|
979
|
-
* You may obtain a copy of the License at
|
|
980
|
-
*
|
|
981
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
982
|
-
*
|
|
983
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
984
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
985
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
986
|
-
* See the License for the specific language governing permissions and
|
|
987
|
-
* limitations under the License.
|
|
988
|
-
* =============================================================================
|
|
989
|
-
*/
|
|
990
|
-
function Me(t, e, n, o) {
|
|
991
|
-
if (o === "int32") {
|
|
992
|
-
const s = Int32Array.from(t);
|
|
993
|
-
return [e, "int32", s];
|
|
994
|
-
}
|
|
995
|
-
if (o === "bool") {
|
|
996
|
-
const s = kt([0], n), [r, a] = C((i, u) => i !== u ? 1 : 0)(e, [], t, s, "bool");
|
|
997
|
-
return [a, "bool", r];
|
|
998
|
-
}
|
|
999
|
-
throw new Error(`Error in Cast: failed to cast ${n} to ${o}`);
|
|
1000
|
-
}
|
|
1001
|
-
/**
|
|
1002
|
-
* @license
|
|
1003
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1004
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1005
|
-
* you may not use this file except in compliance with the License.
|
|
1006
|
-
* You may obtain a copy of the License at
|
|
1007
|
-
*
|
|
1008
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1009
|
-
*
|
|
1010
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1011
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1012
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1013
|
-
* See the License for the specific language governing permissions and
|
|
1014
|
-
* limitations under the License.
|
|
1015
|
-
* =============================================================================
|
|
1016
|
-
*/
|
|
1017
|
-
const Le = C((t, e) => t + e);
|
|
1018
|
-
/**
|
|
1019
|
-
* @license
|
|
1020
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1021
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1022
|
-
* you may not use this file except in compliance with the License.
|
|
1023
|
-
* You may obtain a copy of the License at
|
|
1024
|
-
*
|
|
1025
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1026
|
-
*
|
|
1027
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1028
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1029
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1030
|
-
* See the License for the specific language governing permissions and
|
|
1031
|
-
* limitations under the License.
|
|
1032
|
-
* =============================================================================
|
|
1033
|
-
*/
|
|
1034
|
-
function _e(t, e, n, o, s) {
|
|
1035
|
-
const r = y(o), a = ot(s, n);
|
|
1036
|
-
for (let i = 0; i < t.length; i++) {
|
|
1037
|
-
const u = t[i];
|
|
1038
|
-
if (u < 0)
|
|
1039
|
-
throw new Error("Input x must be non-negative!");
|
|
1040
|
-
u >= s || (r > 0 ? a[u] += e[i] : a[u] += 1);
|
|
1041
|
-
}
|
|
1042
|
-
return a;
|
|
1043
|
-
}
|
|
1044
|
-
function Ne(t, e, n, o = !1) {
|
|
1045
|
-
const s = t.shape[0], r = t.shape[1], a = B([s, n], e.dtype);
|
|
1046
|
-
for (let i = 0; i < s; i++)
|
|
1047
|
-
for (let u = 0; u < r; u++) {
|
|
1048
|
-
const c = t.get(i, u);
|
|
1049
|
-
if (c < 0)
|
|
1050
|
-
throw new Error("Input x must be non-negative!");
|
|
1051
|
-
c >= n || (o ? a.set(1, i, c) : e.size > 0 ? a.set(a.get(i, c) + e.get(i, u), i, c) : a.set(a.get(i, c) + 1, i, c));
|
|
1052
|
-
}
|
|
1053
|
-
return a;
|
|
1054
|
-
}
|
|
1055
|
-
/**
|
|
1056
|
-
* @license
|
|
1057
|
-
* Copyright 2023 Google LLC.
|
|
1058
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1059
|
-
* you may not use this file except in compliance with the License.
|
|
1060
|
-
* You may obtain a copy of the License at
|
|
1061
|
-
*
|
|
1062
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1063
|
-
*
|
|
1064
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1065
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1066
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1067
|
-
* See the License for the specific language governing permissions and
|
|
1068
|
-
* limitations under the License.
|
|
1069
|
-
* =============================================================================
|
|
1070
|
-
*/
|
|
1071
|
-
const Ae = C((t, e) => t & e);
|
|
1072
|
-
/**
|
|
1073
|
-
* @license
|
|
1074
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1075
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1076
|
-
* you may not use this file except in compliance with the License.
|
|
1077
|
-
* You may obtain a copy of the License at
|
|
1078
|
-
*
|
|
1079
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1080
|
-
*
|
|
1081
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1082
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1083
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1084
|
-
* See the License for the specific language governing permissions and
|
|
1085
|
-
* limitations under the License.
|
|
1086
|
-
* =============================================================================
|
|
1087
|
-
*/
|
|
1088
|
-
function K(t) {
|
|
1089
|
-
return (e, n, o) => {
|
|
1090
|
-
const s = q(n, e.length);
|
|
1091
|
-
for (let r = 0; r < e.length; ++r)
|
|
1092
|
-
s[r] = t(e[r], o);
|
|
1093
|
-
return s;
|
|
1094
|
-
};
|
|
1095
|
-
}
|
|
1096
|
-
/**
|
|
1097
|
-
* @license
|
|
1098
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1099
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
1100
|
-
* you may not use this file except in compliance with the License.
|
|
1101
|
-
* You may obtain a copy of the License at
|
|
1102
|
-
*
|
|
1103
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1104
|
-
*
|
|
1105
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1106
|
-
* distributed under the License is distributed on an AS IS BASIS,
|
|
1107
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1108
|
-
* See the License for the specific language governing permissions and
|
|
1109
|
-
* limitations under the License.
|
|
1110
|
-
* =============================================================================
|
|
1111
|
-
*/
|
|
1112
|
-
const Pe = K((t) => Math.ceil(t));
|
|
1113
|
-
/**
|
|
1114
|
-
* @license
|
|
1115
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1116
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1117
|
-
* you may not use this file except in compliance with the License.
|
|
1118
|
-
* You may obtain a copy of the License at
|
|
1119
|
-
*
|
|
1120
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1121
|
-
*
|
|
1122
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1123
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1124
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1125
|
-
* See the License for the specific language governing permissions and
|
|
1126
|
-
* limitations under the License.
|
|
1127
|
-
* =============================================================================
|
|
1128
|
-
*/
|
|
1129
|
-
function De(t, e, n, o) {
|
|
1130
|
-
const s = q(n, y(e));
|
|
1131
|
-
if (o && n !== "string") {
|
|
1132
|
-
let r = 0;
|
|
1133
|
-
t.forEach((a) => {
|
|
1134
|
-
const i = y(a.shape);
|
|
1135
|
-
s.set(a.vals, r), r += i;
|
|
1136
|
-
});
|
|
1137
|
-
} else {
|
|
1138
|
-
let r = 0;
|
|
1139
|
-
t.forEach((a) => {
|
|
1140
|
-
const i = n === "string" ? $t(a.vals) : a.vals;
|
|
1141
|
-
let u = 0;
|
|
1142
|
-
for (let c = 0; c < a.shape[0]; ++c) {
|
|
1143
|
-
const h = c * e[1] + r;
|
|
1144
|
-
for (let f = 0; f < a.shape[1]; ++f)
|
|
1145
|
-
s[h + f] = i[u++];
|
|
1146
|
-
}
|
|
1147
|
-
r += a.shape[1];
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
return s;
|
|
1151
|
-
}
|
|
1152
|
-
/**
|
|
1153
|
-
* @license
|
|
1154
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1155
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1156
|
-
* you may not use this file except in compliance with the License.
|
|
1157
|
-
* You may obtain a copy of the License at
|
|
1158
|
-
*
|
|
1159
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1160
|
-
*
|
|
1161
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1162
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1163
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1164
|
-
* See the License for the specific language governing permissions and
|
|
1165
|
-
* limitations under the License.
|
|
1166
|
-
* =============================================================================
|
|
1167
|
-
*/
|
|
1168
|
-
const ze = C((t, e) => t === e ? 1 : 0);
|
|
1169
|
-
/**
|
|
1170
|
-
* @license
|
|
1171
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1172
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
1173
|
-
* you may not use this file except in compliance with the License.
|
|
1174
|
-
* You may obtain a copy of the License at
|
|
1175
|
-
*
|
|
1176
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1177
|
-
*
|
|
1178
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1179
|
-
* distributed under the License is distributed on an AS IS BASIS,
|
|
1180
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1181
|
-
* See the License for the specific language governing permissions and
|
|
1182
|
-
* limitations under the License.
|
|
1183
|
-
* =============================================================================
|
|
1184
|
-
*/
|
|
1185
|
-
const We = K((t) => Math.exp(t));
|
|
1186
|
-
/**
|
|
1187
|
-
* @license
|
|
1188
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1189
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
1190
|
-
* you may not use this file except in compliance with the License.
|
|
1191
|
-
* You may obtain a copy of the License at
|
|
1192
|
-
*
|
|
1193
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1194
|
-
*
|
|
1195
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1196
|
-
* distributed under the License is distributed on an AS IS BASIS,
|
|
1197
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1198
|
-
* See the License for the specific language governing permissions and
|
|
1199
|
-
* limitations under the License.
|
|
1200
|
-
* =============================================================================
|
|
1201
|
-
*/
|
|
1202
|
-
const qe = K((t) => Math.expm1(t));
|
|
1203
|
-
/**
|
|
1204
|
-
* @license
|
|
1205
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1206
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
1207
|
-
* you may not use this file except in compliance with the License.
|
|
1208
|
-
* You may obtain a copy of the License at
|
|
1209
|
-
*
|
|
1210
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1211
|
-
*
|
|
1212
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1213
|
-
* distributed under the License is distributed on an AS IS BASIS,
|
|
1214
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1215
|
-
* See the License for the specific language governing permissions and
|
|
1216
|
-
* limitations under the License.
|
|
1217
|
-
* =============================================================================
|
|
1218
|
-
*/
|
|
1219
|
-
const Ce = K((t) => Math.floor(t));
|
|
1220
|
-
/**
|
|
1221
|
-
* @license
|
|
1222
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1223
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1224
|
-
* you may not use this file except in compliance with the License.
|
|
1225
|
-
* You may obtain a copy of the License at
|
|
1226
|
-
*
|
|
1227
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1228
|
-
*
|
|
1229
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1230
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1231
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1232
|
-
* See the License for the specific language governing permissions and
|
|
1233
|
-
* limitations under the License.
|
|
1234
|
-
* =============================================================================
|
|
1235
|
-
*/
|
|
1236
|
-
const ke = C((t, e) => Math.floor(t / e));
|
|
1237
|
-
/**
|
|
1238
|
-
* @license
|
|
1239
|
-
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
1240
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1241
|
-
* you may not use this file except in compliance with the License.
|
|
1242
|
-
* You may obtain a copy of the License at
|
|
1243
|
-
*
|
|
1244
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1245
|
-
*
|
|
1246
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1247
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1248
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1249
|
-
* See the License for the specific language governing permissions and
|
|
1250
|
-
* limitations under the License.
|
|
1251
|
-
* =============================================================================
|
|
1252
|
-
*/
|
|
1253
|
-
function Ue(t, e, n, o, s, r, a, i, u) {
|
|
1254
|
-
const c = B([o, r], n);
|
|
1255
|
-
for (let h = 0; h < o; h++) {
|
|
1256
|
-
const f = [];
|
|
1257
|
-
let w = 0;
|
|
1258
|
-
for (let p = 0; p < s; p++) {
|
|
1259
|
-
const m = t[h * s + p];
|
|
1260
|
-
w += m * a[p], f.push(m);
|
|
1261
|
-
}
|
|
1262
|
-
if (w < 0 || w >= u / r)
|
|
1263
|
-
throw new Error(`Invalid indices: ${f} does not index into ${i}`);
|
|
1264
|
-
for (let p = 0; p < r; p++)
|
|
1265
|
-
c.values[h * r + p] = e.get(...e.indexToLoc(w * r + p));
|
|
1266
|
-
}
|
|
1267
|
-
return c;
|
|
1268
|
-
}
|
|
1269
|
-
/**
|
|
1270
|
-
* @license
|
|
1271
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1272
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1273
|
-
* you may not use this file except in compliance with the License.
|
|
1274
|
-
* You may obtain a copy of the License at
|
|
1275
|
-
*
|
|
1276
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1277
|
-
*
|
|
1278
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1279
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1280
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1281
|
-
* See the License for the specific language governing permissions and
|
|
1282
|
-
* limitations under the License.
|
|
1283
|
-
* =============================================================================
|
|
1284
|
-
*/
|
|
1285
|
-
function Ge(t, e, n) {
|
|
1286
|
-
const o = B(n, t.dtype);
|
|
1287
|
-
for (let s = 0; s < o.size; ++s) {
|
|
1288
|
-
const a = o.indexToLoc(s).slice(), i = a[0], u = a[2], c = e.locToIndex([i, u]);
|
|
1289
|
-
a[2] = e.values[c];
|
|
1290
|
-
const h = t.locToIndex(a);
|
|
1291
|
-
0 <= h && h < t.values.length && (o.values[s] = t.values[h]);
|
|
1292
|
-
}
|
|
1293
|
-
return o;
|
|
1294
|
-
}
|
|
1295
|
-
/**
|
|
1296
|
-
* @license
|
|
1297
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1298
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1299
|
-
* you may not use this file except in compliance with the License.
|
|
1300
|
-
* You may obtain a copy of the License at
|
|
1301
|
-
*
|
|
1302
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1303
|
-
*
|
|
1304
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1305
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1306
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1307
|
-
* See the License for the specific language governing permissions and
|
|
1308
|
-
* limitations under the License.
|
|
1309
|
-
* =============================================================================
|
|
1310
|
-
*/
|
|
1311
|
-
const je = C((t, e) => t > e ? 1 : 0);
|
|
1312
|
-
/**
|
|
1313
|
-
* @license
|
|
1314
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1315
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1316
|
-
* you may not use this file except in compliance with the License.
|
|
1317
|
-
* You may obtain a copy of the License at
|
|
1318
|
-
*
|
|
1319
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1320
|
-
*
|
|
1321
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1322
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1323
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1324
|
-
* See the License for the specific language governing permissions and
|
|
1325
|
-
* limitations under the License.
|
|
1326
|
-
* =============================================================================
|
|
1327
|
-
*/
|
|
1328
|
-
const Ze = C((t, e) => t >= e ? 1 : 0);
|
|
1329
|
-
/**
|
|
1330
|
-
* @license
|
|
1331
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1332
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1333
|
-
* you may not use this file except in compliance with the License.
|
|
1334
|
-
* You may obtain a copy of the License at
|
|
1335
|
-
*
|
|
1336
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1337
|
-
*
|
|
1338
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1339
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1340
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1341
|
-
* See the License for the specific language governing permissions and
|
|
1342
|
-
* limitations under the License.
|
|
1343
|
-
* =============================================================================
|
|
1344
|
-
*/
|
|
1345
|
-
const Be = C((t, e) => t < e ? 1 : 0);
|
|
1346
|
-
/**
|
|
1347
|
-
* @license
|
|
1348
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1349
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1350
|
-
* you may not use this file except in compliance with the License.
|
|
1351
|
-
* You may obtain a copy of the License at
|
|
1352
|
-
*
|
|
1353
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1354
|
-
*
|
|
1355
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1356
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1357
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1358
|
-
* See the License for the specific language governing permissions and
|
|
1359
|
-
* limitations under the License.
|
|
1360
|
-
* =============================================================================
|
|
1361
|
-
*/
|
|
1362
|
-
const He = C((t, e) => t <= e ? 1 : 0);
|
|
1363
|
-
/**
|
|
1364
|
-
* @license
|
|
1365
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1366
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1367
|
-
* you may not use this file except in compliance with the License.
|
|
1368
|
-
* You may obtain a copy of the License at
|
|
1369
|
-
*
|
|
1370
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1371
|
-
*
|
|
1372
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1373
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1374
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1375
|
-
* See the License for the specific language governing permissions and
|
|
1376
|
-
* limitations under the License.
|
|
1377
|
-
* =============================================================================
|
|
1378
|
-
*/
|
|
1379
|
-
function Ke(t, e, n) {
|
|
1380
|
-
const o = (e - t) / (n - 1), s = ot(n, "float32");
|
|
1381
|
-
s[0] = t;
|
|
1382
|
-
for (let r = 1; r < s.length; r++)
|
|
1383
|
-
s[r] = s[r - 1] + o;
|
|
1384
|
-
return s;
|
|
1385
|
-
}
|
|
1386
|
-
/**
|
|
1387
|
-
* @license
|
|
1388
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1389
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
1390
|
-
* you may not use this file except in compliance with the License.
|
|
1391
|
-
* You may obtain a copy of the License at
|
|
1392
|
-
*
|
|
1393
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1394
|
-
*
|
|
1395
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1396
|
-
* distributed under the License is distributed on an AS IS BASIS,
|
|
1397
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1398
|
-
* See the License for the specific language governing permissions and
|
|
1399
|
-
* limitations under the License.
|
|
1400
|
-
* =============================================================================
|
|
1401
|
-
*/
|
|
1402
|
-
const Xe = K((t) => Math.log(t));
|
|
1403
|
-
/**
|
|
1404
|
-
* @license
|
|
1405
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1406
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1407
|
-
* you may not use this file except in compliance with the License.
|
|
1408
|
-
* You may obtain a copy of the License at
|
|
1409
|
-
*
|
|
1410
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1411
|
-
*
|
|
1412
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1413
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1414
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1415
|
-
* See the License for the specific language governing permissions and
|
|
1416
|
-
* limitations under the License.
|
|
1417
|
-
* =============================================================================
|
|
1418
|
-
*/
|
|
1419
|
-
function Qe(t, e, n, o) {
|
|
1420
|
-
const s = nt(o, y(n));
|
|
1421
|
-
for (let r = 0; r < s.length; ++r) {
|
|
1422
|
-
const a = r * e;
|
|
1423
|
-
let i = t[a];
|
|
1424
|
-
for (let u = 0; u < e; ++u) {
|
|
1425
|
-
const c = t[a + u];
|
|
1426
|
-
(Number.isNaN(c) || c > i) && (i = c);
|
|
1427
|
-
}
|
|
1428
|
-
s[r] = i;
|
|
1429
|
-
}
|
|
1430
|
-
return s;
|
|
1431
|
-
}
|
|
1432
|
-
/**
|
|
1433
|
-
* @license
|
|
1434
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1435
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1436
|
-
* you may not use this file except in compliance with the License.
|
|
1437
|
-
* You may obtain a copy of the License at
|
|
1438
|
-
*
|
|
1439
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1440
|
-
*
|
|
1441
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1442
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1443
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1444
|
-
* See the License for the specific language governing permissions and
|
|
1445
|
-
* limitations under the License.
|
|
1446
|
-
* =============================================================================
|
|
1447
|
-
*/
|
|
1448
|
-
const Ye = C((t, e) => Math.max(t, e));
|
|
1449
|
-
/**
|
|
1450
|
-
* @license
|
|
1451
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1452
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1453
|
-
* you may not use this file except in compliance with the License.
|
|
1454
|
-
* You may obtain a copy of the License at
|
|
1455
|
-
*
|
|
1456
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1457
|
-
*
|
|
1458
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1459
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1460
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1461
|
-
* See the License for the specific language governing permissions and
|
|
1462
|
-
* limitations under the License.
|
|
1463
|
-
* =============================================================================
|
|
1464
|
-
*/
|
|
1465
|
-
const Je = C((t, e) => Math.min(t, e));
|
|
1466
|
-
/**
|
|
1467
|
-
* @license
|
|
1468
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1469
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1470
|
-
* you may not use this file except in compliance with the License.
|
|
1471
|
-
* You may obtain a copy of the License at
|
|
1472
|
-
*
|
|
1473
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1474
|
-
*
|
|
1475
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1476
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1477
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1478
|
-
* See the License for the specific language governing permissions and
|
|
1479
|
-
* limitations under the License.
|
|
1480
|
-
* =============================================================================
|
|
1481
|
-
*/
|
|
1482
|
-
const Pt = C((t, e) => t * e);
|
|
1483
|
-
/**
|
|
1484
|
-
* @license
|
|
1485
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1486
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1487
|
-
* you may not use this file except in compliance with the License.
|
|
1488
|
-
* You may obtain a copy of the License at
|
|
1489
|
-
*
|
|
1490
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1491
|
-
*
|
|
1492
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1493
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1494
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1495
|
-
* See the License for the specific language governing permissions and
|
|
1496
|
-
* limitations under the License.
|
|
1497
|
-
* =============================================================================
|
|
1498
|
-
*/
|
|
1499
|
-
function tn(t, e, n) {
|
|
1500
|
-
const o = Ut(-1, n);
|
|
1501
|
-
return Pt([], e, o, t, n);
|
|
1502
|
-
}
|
|
1503
|
-
/**
|
|
1504
|
-
* @license
|
|
1505
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1506
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1507
|
-
* you may not use this file except in compliance with the License.
|
|
1508
|
-
* You may obtain a copy of the License at
|
|
1509
|
-
*
|
|
1510
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1511
|
-
*
|
|
1512
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1513
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1514
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1515
|
-
* See the License for the specific language governing permissions and
|
|
1516
|
-
* limitations under the License.
|
|
1517
|
-
* =============================================================================
|
|
1518
|
-
*/
|
|
1519
|
-
const en = C((t, e) => t !== e ? 1 : 0);
|
|
1520
|
-
/**
|
|
1521
|
-
* @license
|
|
1522
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1523
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1524
|
-
* you may not use this file except in compliance with the License.
|
|
1525
|
-
* You may obtain a copy of the License at
|
|
1526
|
-
*
|
|
1527
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1528
|
-
*
|
|
1529
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1530
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1531
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1532
|
-
* See the License for the specific language governing permissions and
|
|
1533
|
-
* limitations under the License.
|
|
1534
|
-
* =============================================================================
|
|
1535
|
-
*/
|
|
1536
|
-
function nn(t, e, n, o, s) {
|
|
1537
|
-
const r = e.length, a = y(e), i = J(e), u = J(s), c = nt(n, y(s));
|
|
1538
|
-
for (let h = 0; h < a; ++h) {
|
|
1539
|
-
const f = pt(h, r, i), w = new Array(f.length);
|
|
1540
|
-
for (let m = 0; m < w.length; m++)
|
|
1541
|
-
w[m] = f[o[m]];
|
|
1542
|
-
const p = ft(w, r, u);
|
|
1543
|
-
c[p] = t[h];
|
|
1544
|
-
}
|
|
1545
|
-
return c;
|
|
1546
|
-
}
|
|
1547
|
-
/**
|
|
1548
|
-
* @license
|
|
1549
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1550
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1551
|
-
* you may not use this file except in compliance with the License.
|
|
1552
|
-
* You may obtain a copy of the License at
|
|
1553
|
-
*
|
|
1554
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1555
|
-
*
|
|
1556
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1557
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1558
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1559
|
-
* See the License for the specific language governing permissions and
|
|
1560
|
-
* limitations under the License.
|
|
1561
|
-
* =============================================================================
|
|
1562
|
-
*/
|
|
1563
|
-
function on(t, e, n, o) {
|
|
1564
|
-
const [s, r] = mt(t, o), a = Gt(e, "int32"), i = ot(y(s), a), u = y(r);
|
|
1565
|
-
for (let c = 0; c < i.length; ++c) {
|
|
1566
|
-
const h = c * u;
|
|
1567
|
-
let f = 1;
|
|
1568
|
-
for (let w = 0; w < u; ++w)
|
|
1569
|
-
f *= n[h + w];
|
|
1570
|
-
i[c] = f;
|
|
1571
|
-
}
|
|
1572
|
-
return { outVals: i, outShape: s, outDtype: a };
|
|
1573
|
-
}
|
|
1574
|
-
/**
|
|
1575
|
-
* @license
|
|
1576
|
-
* Copyright 2022 Google LLC. All Rights Reserved.
|
|
1577
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1578
|
-
* you may not use this file except in compliance with the License.
|
|
1579
|
-
* You may obtain a copy of the License at
|
|
1580
|
-
*
|
|
1581
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1582
|
-
*
|
|
1583
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1584
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1585
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1586
|
-
* See the License for the specific language governing permissions and
|
|
1587
|
-
* limitations under the License.
|
|
1588
|
-
* =============================================================================
|
|
1589
|
-
*/
|
|
1590
|
-
function sn(t, e, n) {
|
|
1591
|
-
t.forEach((o, s) => {
|
|
1592
|
-
if (o < 0 || o >= n) {
|
|
1593
|
-
const r = pt(s, e.length, J(e)).join(",");
|
|
1594
|
-
throw new Error(`indices[${r}] = ${o} is not in [0, ${n})`);
|
|
1595
|
-
}
|
|
1596
|
-
});
|
|
1597
|
-
}
|
|
1598
|
-
function rn(t, e) {
|
|
1599
|
-
for (let n = 0; n < t.length; ++n) {
|
|
1600
|
-
const o = t[n], s = n === t.length - 1 ? e : t[n + 1].length;
|
|
1601
|
-
if (o.length === 0)
|
|
1602
|
-
throw new Error("Ragged splits may not be empty");
|
|
1603
|
-
if (o[0] < 0)
|
|
1604
|
-
throw new Error("Ragged splits must be non-negative");
|
|
1605
|
-
if (o[o.length - 1] > s)
|
|
1606
|
-
throw new Error("Ragged splits must not point past values");
|
|
1607
|
-
for (let r = 1; r < o.length; ++r)
|
|
1608
|
-
if (o[r - 1] > o[r])
|
|
1609
|
-
throw new Error("Ragged splits must be sorted in ascending order");
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
function an(t, e, n, o) {
|
|
1613
|
-
const s = [];
|
|
1614
|
-
let r = 0;
|
|
1615
|
-
const a = e.length - 1 + n.length, i = new Array(a).fill(null).map(() => [0]);
|
|
1616
|
-
rn(n, o);
|
|
1617
|
-
let u = 1;
|
|
1618
|
-
for (let c = 0; c < e.length - 1; ++c) {
|
|
1619
|
-
u *= e[c];
|
|
1620
|
-
const h = e[c + 1];
|
|
1621
|
-
for (let f = 1; f < u + 1; ++f)
|
|
1622
|
-
i[c].push(f * h);
|
|
1623
|
-
}
|
|
1624
|
-
for (let c = 0; c < t.length; ++c) {
|
|
1625
|
-
let h = t[c], f = t[c] + 1;
|
|
1626
|
-
for (let w = 0; w < n.length; ++w) {
|
|
1627
|
-
const p = n[w], m = w + e.length - 1;
|
|
1628
|
-
if (m >= 0) {
|
|
1629
|
-
const v = i[m], d = v[v.length - 1] - p[h];
|
|
1630
|
-
for (let g = h; g < f; ++g)
|
|
1631
|
-
i[m].push(p[g + 1] + d);
|
|
1632
|
-
}
|
|
1633
|
-
h = p[h], f = p[f];
|
|
1634
|
-
}
|
|
1635
|
-
f !== h && (s.push([h, f]), r += f - h);
|
|
1636
|
-
}
|
|
1637
|
-
return { outSplits: i, valueSlices: s, numValues: r };
|
|
1638
|
-
}
|
|
1639
|
-
function un(t) {
|
|
1640
|
-
const e = [];
|
|
1641
|
-
for (let n = 0; n < t.length; ++n) {
|
|
1642
|
-
const o = t[n].length, s = q("int32", o);
|
|
1643
|
-
e.push(s), t[n].forEach((r, a) => s[a] = r);
|
|
1644
|
-
}
|
|
1645
|
-
return e;
|
|
1646
|
-
}
|
|
1647
|
-
function vt(t, e) {
|
|
1648
|
-
const n = t.slice(0, e);
|
|
1649
|
-
for (; n.length < e; )
|
|
1650
|
-
n.push(1);
|
|
1651
|
-
for (let o = e; o < t.length; o++)
|
|
1652
|
-
n[e - 1] *= t[o];
|
|
1653
|
-
return n;
|
|
1654
|
-
}
|
|
1655
|
-
function ln(t, e, n, o, s, r) {
|
|
1656
|
-
const a = vt(e, 2)[1], i = vt(r, 2)[1];
|
|
1657
|
-
let u = 0;
|
|
1658
|
-
for (const c of n)
|
|
1659
|
-
for (let h = c[0]; h < c[1]; ++h) {
|
|
1660
|
-
for (let f = 0; f < o; ++f)
|
|
1661
|
-
s[u * i + f] = t[h * a + f];
|
|
1662
|
-
++u;
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
function cn(t, e, n, o, s) {
|
|
1666
|
-
const r = e.slice();
|
|
1667
|
-
r[0] = s;
|
|
1668
|
-
const a = q(n, y(r)), i = t.length, u = i === 0 ? 0 : i / e[0];
|
|
1669
|
-
return ln(t, e, o, u, a, r), [a, r];
|
|
1670
|
-
}
|
|
1671
|
-
function hn(t, e, n, o, s, r, a, i) {
|
|
1672
|
-
if (t.length === 0)
|
|
1673
|
-
throw new Error("paramsNestedSplits must be non empty");
|
|
1674
|
-
if (e[0].length === 0)
|
|
1675
|
-
throw new Error("Split tensors must not be scalars");
|
|
1676
|
-
const u = e[0][0] - 1;
|
|
1677
|
-
if (sn(r, a, u), o.length === 0)
|
|
1678
|
-
throw new Error("params.rank must be nonzero");
|
|
1679
|
-
const c = o[0], { outSplits: h, valueSlices: f, numValues: w } = an(r, a, t, c), p = un(h), m = cn(n, o, s, f, w);
|
|
1680
|
-
return [p, m[0], m[1]];
|
|
1681
|
-
}
|
|
1682
|
-
/**
|
|
1683
|
-
* @license
|
|
1684
|
-
* Copyright 2022 Google LLC.
|
|
1685
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1686
|
-
* you may not use this file except in compliance with the License.
|
|
1687
|
-
* You may obtain a copy of the License at
|
|
1688
|
-
*
|
|
1689
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1690
|
-
*
|
|
1691
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1692
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1693
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1694
|
-
* See the License for the specific language governing permissions and
|
|
1695
|
-
* limitations under the License.
|
|
1696
|
-
* =============================================================================
|
|
1697
|
-
*/
|
|
1698
|
-
const bt = 2147483647;
|
|
1699
|
-
function fn(t, e, n, o, s, r, a) {
|
|
1700
|
-
if (e.length > 1)
|
|
1701
|
-
throw new Error("starts must be a scalar or vector");
|
|
1702
|
-
if (s.length > 1)
|
|
1703
|
-
throw new Error("limits must be a scalar or vector");
|
|
1704
|
-
if (a.length > 1)
|
|
1705
|
-
throw new Error("deltas must be a scalar or vector");
|
|
1706
|
-
const i = e.length === 0, u = s.length === 0, c = a.length === 0, h = [];
|
|
1707
|
-
i || h.push(e[0]), u || h.push(s[0]), c || h.push(a[0]);
|
|
1708
|
-
for (let d = 1; d < h.length; ++d)
|
|
1709
|
-
if (h[d] !== h[d - 1])
|
|
1710
|
-
throw new Error("starts, limits, and deltas must have the same shape");
|
|
1711
|
-
const f = h.length === 0 ? 1 : h[0], w = q("int32", f + 1);
|
|
1712
|
-
w[0] = 0;
|
|
1713
|
-
for (let d = 0; d < f; ++d) {
|
|
1714
|
-
const g = i ? t[0] : t[d], x = u ? o[0] : o[d], O = c ? r[0] : r[d];
|
|
1715
|
-
if (O === 0)
|
|
1716
|
-
throw new Error("Requires delta != 0");
|
|
1717
|
-
let b;
|
|
1718
|
-
if (O > 0 && x < g || O < 0 && x > g)
|
|
1719
|
-
b = 0;
|
|
1720
|
-
else if (b = Math.ceil(Math.abs((x - g) / O)), b > bt)
|
|
1721
|
-
throw new Error(`Requires ((limit - start) / delta) <= ${bt}`);
|
|
1722
|
-
w[d + 1] = w[d] + b;
|
|
1723
|
-
}
|
|
1724
|
-
const p = w[f], m = q(n, p);
|
|
1725
|
-
let v = 0;
|
|
1726
|
-
for (let d = 0; d < f; ++d) {
|
|
1727
|
-
const g = w[d + 1] - w[d];
|
|
1728
|
-
let x = i ? t[0] : t[d];
|
|
1729
|
-
const O = c ? r[0] : r[d];
|
|
1730
|
-
for (let b = 0; b < g; ++b)
|
|
1731
|
-
m[v++] = x, x += O;
|
|
1732
|
-
}
|
|
1733
|
-
return [w, m];
|
|
1734
|
-
}
|
|
1735
|
-
/**
|
|
1736
|
-
* @license
|
|
1737
|
-
* Copyright 2022 Google LLC. All Rights Reserved.
|
|
1738
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1739
|
-
* you may not use this file except in compliance with the License.
|
|
1740
|
-
* You may obtain a copy of the License at
|
|
1741
|
-
*
|
|
1742
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1743
|
-
*
|
|
1744
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
1745
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1746
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1747
|
-
* See the License for the specific language governing permissions and
|
|
1748
|
-
* limitations under the License.
|
|
1749
|
-
* =============================================================================
|
|
1750
|
-
*/
|
|
1751
|
-
var Z = H;
|
|
1752
|
-
class at {
|
|
1753
|
-
constructor(e, n, o, s, r, a, i, u, c, h) {
|
|
1754
|
-
this.shape = e, this.shapeShape = n, this.values = o, this.valuesShape = s, this.valuesDType = r, this.defaultValue = a, this.defaultValueShape = i, this.rowPartitionValues = u, this.rowPartitionValuesShapes = c, this.rowPartitionTypes = ge(h), this.raggedRank = pe(this.rowPartitionTypes);
|
|
1755
|
-
}
|
|
1756
|
-
getRowPartitionTypeByDimension(e) {
|
|
1757
|
-
return this.rowPartitionTypes[0] === Z.FIRST_DIM_SIZE ? this.rowPartitionTypes[e + 1] : this.rowPartitionTypes[e];
|
|
1758
|
-
}
|
|
1759
|
-
// Returns the relationship between dimension and dimension + 1.
|
|
1760
|
-
getRowPartitionTensor(e) {
|
|
1761
|
-
return this.rowPartitionTypes[0] === Z.FIRST_DIM_SIZE ? this.rowPartitionValues[e + 1] : this.rowPartitionValues[e];
|
|
1762
|
-
}
|
|
1763
|
-
getMaxWidth(e) {
|
|
1764
|
-
const n = this.getRowPartitionTensor(e - 1);
|
|
1765
|
-
switch (this.getRowPartitionTypeByDimension(e - 1)) {
|
|
1766
|
-
case Z.VALUE_ROWIDS:
|
|
1767
|
-
return at.getMaxWidthValueRowID(n);
|
|
1768
|
-
case Z.ROW_SPLITS:
|
|
1769
|
-
return at.getMaxWidthRowSplit(n);
|
|
1770
|
-
default:
|
|
1771
|
-
throw new Error(`Cannot handle partition type ${Z[this.getRowPartitionTypeByDimension(e - 1)]}`);
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
static getMaxWidthRowSplit(e) {
|
|
1775
|
-
const n = e.length;
|
|
1776
|
-
if (n === 0 || n === 1)
|
|
1777
|
-
return 0;
|
|
1778
|
-
let o = 0;
|
|
1779
|
-
for (let s = 0; s < n - 1; ++s) {
|
|
1780
|
-
const r = e[s + 1] - e[s];
|
|
1781
|
-
r > o && (o = r);
|
|
1782
|
-
}
|
|
1783
|
-
return o;
|
|
1784
|
-
}
|
|
1785
|
-
static getMaxWidthValueRowID(e) {
|
|
1786
|
-
const n = e.length;
|
|
1787
|
-
if (n === 0)
|
|
1788
|
-
return 0;
|
|
1789
|
-
let o = 0, s = e[0], r = 0;
|
|
1790
|
-
for (let a = 1; a < n; ++a) {
|
|
1791
|
-
const i = e[a];
|
|
1792
|
-
i !== s && (s = i, r = Math.max(a - o, r), o = a);
|
|
1793
|
-
}
|
|
1794
|
-
return Math.max(n - o, r);
|
|
1795
|
-
}
|
|
1796
|
-
tensorShapeFromTensor(e, n, o = !0) {
|
|
1797
|
-
if (n.length === 0) {
|
|
1798
|
-
if (e[0] === -1)
|
|
1799
|
-
return [];
|
|
1800
|
-
throw new Error("The only valid scalar shape tensor is the fully unknown shape specified as -1.");
|
|
1801
|
-
}
|
|
1802
|
-
return Ft(e, o);
|
|
1803
|
-
}
|
|
1804
|
-
calculateOutputSize(e) {
|
|
1805
|
-
const n = this.valuesShape, o = this.defaultValueShape;
|
|
1806
|
-
me(o, n);
|
|
1807
|
-
const s = this.tensorShapeFromTensor(this.shape, this.shapeShape), a = de(this.raggedRank, s, n);
|
|
1808
|
-
a[0] < 0 && (a[0] = e);
|
|
1809
|
-
for (let i = 1; i <= this.raggedRank; ++i)
|
|
1810
|
-
a[i] < 0 && (a[i] = this.getMaxWidth(i));
|
|
1811
|
-
return a;
|
|
1812
|
-
}
|
|
1813
|
-
/**
|
|
1814
|
-
* The outputIndex represents the index in the output tensor
|
|
1815
|
-
* where the first element of a particular dimension would be written.
|
|
1816
|
-
* If it is -1, it indicates that the index is out of scope.
|
|
1817
|
-
* Example, given firstDimension = 10, firstDimensionOutput = 6,
|
|
1818
|
-
* and outputIndexMultiplier = 100:
|
|
1819
|
-
* result = [0 100 200 300 400 500 -1 -1 -1 -1]
|
|
1820
|
-
* If firstDimensionOutput = 11 instead, then:
|
|
1821
|
-
* result = [0 100 200 300 400 500 600 700 800 900]
|
|
1822
|
-
*/
|
|
1823
|
-
calculateFirstParentOutputIndex(e, n, o) {
|
|
1824
|
-
const s = Math.min(e, o), r = [];
|
|
1825
|
-
let a = 0;
|
|
1826
|
-
for (let i = 0; i < s; ++i, a += n)
|
|
1827
|
-
r.push(a);
|
|
1828
|
-
for (let i = s; i < e; ++i)
|
|
1829
|
-
r.push(-1);
|
|
1830
|
-
return jt(r.length === e, () => "Final length of result must be equal to firstDimension."), r;
|
|
1831
|
-
}
|
|
1832
|
-
calculateOutputIndexRowSplit(e, n, o, s) {
|
|
1833
|
-
const r = e.length, a = [];
|
|
1834
|
-
for (let i = 0; i < r - 1; ++i) {
|
|
1835
|
-
const u = e[i + 1] - e[i];
|
|
1836
|
-
let c = Math.min(s, u), h = n[i];
|
|
1837
|
-
h === -1 && (c = 0);
|
|
1838
|
-
for (let f = 0; f < c; ++f)
|
|
1839
|
-
a.push(h), h += o;
|
|
1840
|
-
for (let f = 0; f < u - c; ++f)
|
|
1841
|
-
a.push(-1);
|
|
1842
|
-
}
|
|
1843
|
-
if (r > 0 && a.length !== e[r - 1])
|
|
1844
|
-
throw new Error("Invalid row split size.");
|
|
1845
|
-
return a;
|
|
1846
|
-
}
|
|
1847
|
-
// Calculate the output index of the first element of a list.
|
|
1848
|
-
// The parentOutputIndex is the same computation for the previous list.
|
|
1849
|
-
// -1 indicates an element or list that is out of range.
|
|
1850
|
-
// The outputIndexMultiplier is the number of output indices one moves
|
|
1851
|
-
// forward for each column.
|
|
1852
|
-
// E.g., given:
|
|
1853
|
-
// valueRowIds:[0 1 2 2 2 3 5 5 6]
|
|
1854
|
-
// parentOutputIndex:[1000 1100 2000 2100 -1 3000 4000]
|
|
1855
|
-
// outputIndexMultiplier: 10
|
|
1856
|
-
// outputSize: 2
|
|
1857
|
-
// You get:
|
|
1858
|
-
// result = [1000 1100 2000 2010 -1 2100 -1 -1 3000]
|
|
1859
|
-
// result[0] = parentOutputIndex[valueRowIds[0]]
|
|
1860
|
-
// result[1] = parentOutputIndex[valueRowIds[1]]
|
|
1861
|
-
// result[2] = parentOutputIndex[valueRowIds[2]]
|
|
1862
|
-
// result[3] = parentOutputIndex[valueRowIds[2] + 10]
|
|
1863
|
-
// result[4] = -1 because it is the third element the size is 2.
|
|
1864
|
-
// result[5] = parentOutputIndex[valueRowIds[3]]
|
|
1865
|
-
// result[6] = -1 because parentOutputIndex[valueRowIds[6]] == -1
|
|
1866
|
-
// result[7] = -1 because parentOutputIndex[valueRowIds[6]] == -1
|
|
1867
|
-
// result[8] = parentOutputIndex[valueRowIds[7]]
|
|
1868
|
-
calculateOutputIndexValueRowID(e, n, o, s) {
|
|
1869
|
-
const r = e.length, a = [];
|
|
1870
|
-
if (r === 0)
|
|
1871
|
-
return [];
|
|
1872
|
-
let i = 0, u = e[0];
|
|
1873
|
-
if (u >= n.length)
|
|
1874
|
-
throw new Error(`Got currentValueRowId=${u}, which is not less than ${n.length}`);
|
|
1875
|
-
let c = n[u];
|
|
1876
|
-
a.push(c);
|
|
1877
|
-
for (let h = 1; h < r; ++h) {
|
|
1878
|
-
const f = e[h];
|
|
1879
|
-
if (f === u)
|
|
1880
|
-
c >= 0 && (++i, i < s ? c += o : c = -1);
|
|
1881
|
-
else {
|
|
1882
|
-
if (i = 0, u = f, f >= n.length)
|
|
1883
|
-
throw new Error(`Got nextValueRowId=${f} which is not less than ${n.length}`);
|
|
1884
|
-
c = n[f];
|
|
1885
|
-
}
|
|
1886
|
-
a.push(c);
|
|
1887
|
-
}
|
|
1888
|
-
if (a.length !== e.length)
|
|
1889
|
-
throw new Error("Invalid row ids.");
|
|
1890
|
-
return a;
|
|
1891
|
-
}
|
|
1892
|
-
calculateOutputIndex(e, n, o, s) {
|
|
1893
|
-
const r = this.getRowPartitionTensor(e), a = this.getRowPartitionTypeByDimension(e);
|
|
1894
|
-
switch (a) {
|
|
1895
|
-
case Z.VALUE_ROWIDS:
|
|
1896
|
-
return this.calculateOutputIndexValueRowID(r, n, o, s);
|
|
1897
|
-
case Z.ROW_SPLITS:
|
|
1898
|
-
if (r.length - 1 > n.length)
|
|
1899
|
-
throw new Error(`Row partition size is greater than output size: ${r.length - 1} > ${n.length}`);
|
|
1900
|
-
return this.calculateOutputIndexRowSplit(r, n, o, s);
|
|
1901
|
-
default:
|
|
1902
|
-
throw new Error(`Unsupported partition type: ${Z[a]}`);
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
getFirstDimensionSize() {
|
|
1906
|
-
const e = this.rowPartitionValues[0];
|
|
1907
|
-
if (this.rowPartitionTypes.length === 0)
|
|
1908
|
-
throw new Error("No row_partition_types given.");
|
|
1909
|
-
const n = this.rowPartitionTypes[0];
|
|
1910
|
-
switch (n) {
|
|
1911
|
-
case Z.FIRST_DIM_SIZE:
|
|
1912
|
-
return e[0];
|
|
1913
|
-
case Z.VALUE_ROWIDS:
|
|
1914
|
-
throw new Error("Cannot handle VALUE_ROWIDS in first dimension.");
|
|
1915
|
-
case Z.ROW_SPLITS:
|
|
1916
|
-
return this.rowPartitionValuesShapes[0][0] - 1;
|
|
1917
|
-
default:
|
|
1918
|
-
throw new Error(`Cannot handle type ${Z[n]}`);
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
compute() {
|
|
1922
|
-
if (this.rowPartitionValues[0].length <= 0)
|
|
1923
|
-
throw new Error("Invalid first partition input. Tensor requires at least one element.");
|
|
1924
|
-
const n = this.getFirstDimensionSize(), o = this.calculateOutputSize(n), s = new Array(this.raggedRank + 1);
|
|
1925
|
-
s[s.length - 1] = 1;
|
|
1926
|
-
for (let u = s.length - 2; u >= 0; --u)
|
|
1927
|
-
s[u] = s[u + 1] * o[u + 1];
|
|
1928
|
-
const r = Ft(o, !1), a = q(this.valuesDType, y(r));
|
|
1929
|
-
if (s[0] * o[0] > 0) {
|
|
1930
|
-
let u = this.calculateFirstParentOutputIndex(n, s[0], o[0]);
|
|
1931
|
-
for (let c = 1; c <= this.raggedRank; ++c)
|
|
1932
|
-
u = this.calculateOutputIndex(c - 1, u, s[c], o[c]);
|
|
1933
|
-
this.setOutput(this.raggedRank, u, a, r);
|
|
1934
|
-
}
|
|
1935
|
-
return [r, a];
|
|
1936
|
-
}
|
|
1937
|
-
setOutput(e, n, o, s) {
|
|
1938
|
-
if (o.length === 0)
|
|
1939
|
-
return;
|
|
1940
|
-
const r = this.values, a = o;
|
|
1941
|
-
let i = s.slice();
|
|
1942
|
-
i = i.slice(e + 1);
|
|
1943
|
-
const u = y(i), c = n.length;
|
|
1944
|
-
let h = this.defaultValue;
|
|
1945
|
-
if (h.length !== u && h.length !== 1) {
|
|
1946
|
-
const m = this.defaultValueShape;
|
|
1947
|
-
Zt(() => {
|
|
1948
|
-
const v = ee(h, m);
|
|
1949
|
-
h = te(v, i).dataSync();
|
|
1950
|
-
});
|
|
1951
|
-
}
|
|
1952
|
-
let f = 0, w = 0, p = 0;
|
|
1953
|
-
for (let m = 0; m <= c; ++m) {
|
|
1954
|
-
let v = m < c ? n[m] : -1;
|
|
1955
|
-
if (v === p) {
|
|
1956
|
-
++p;
|
|
1957
|
-
continue;
|
|
1958
|
-
}
|
|
1959
|
-
if (w < p) {
|
|
1960
|
-
const d = r.subarray(f * u), g = a.subarray(w * u), x = (p - w) * u;
|
|
1961
|
-
Ot(g, d, x);
|
|
1962
|
-
}
|
|
1963
|
-
if (m >= c) {
|
|
1964
|
-
const d = o.length;
|
|
1965
|
-
v = Math.floor(d / u);
|
|
1966
|
-
}
|
|
1967
|
-
if (v > p)
|
|
1968
|
-
if (this.defaultValue.length === 1)
|
|
1969
|
-
a.subarray(p * u, v * u).fill(this.defaultValue[0]), p = v;
|
|
1970
|
-
else
|
|
1971
|
-
for (; v > p; ) {
|
|
1972
|
-
const d = a.slice(p * u);
|
|
1973
|
-
Ot(d, h, u), ++p;
|
|
1974
|
-
}
|
|
1975
|
-
v < 0 ? (f = m + 1, w = p) : (f = m, w = p, p = w + 1);
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
}
|
|
1979
|
-
function Ot(t, e, n) {
|
|
1980
|
-
for (let o = 0; o < n; o++)
|
|
1981
|
-
t[o] = e[o];
|
|
1982
|
-
}
|
|
1983
|
-
function Ft(t, e) {
|
|
1984
|
-
const n = [];
|
|
1985
|
-
for (let o of t) {
|
|
1986
|
-
if (o < 0) {
|
|
1987
|
-
if (!e)
|
|
1988
|
-
throw new Error(`Dimension ${o} must be >= 0`);
|
|
1989
|
-
if (o < -1)
|
|
1990
|
-
throw new Error(`Dimension ${o} must be >= -1`);
|
|
1991
|
-
o = -1;
|
|
1992
|
-
}
|
|
1993
|
-
n.push(o);
|
|
1994
|
-
}
|
|
1995
|
-
return n;
|
|
1996
|
-
}
|
|
1997
|
-
function dn(t, e, n, o, s, r, a, i, u, c) {
|
|
1998
|
-
return new at(t, e, n, o, s, r, a, i, u, c).compute();
|
|
1999
|
-
}
|
|
2000
|
-
/**
|
|
2001
|
-
* @license
|
|
2002
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2003
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2004
|
-
* you may not use this file except in compliance with the License.
|
|
2005
|
-
* You may obtain a copy of the License at
|
|
2006
|
-
*
|
|
2007
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2008
|
-
*
|
|
2009
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2010
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2011
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2012
|
-
* See the License for the specific language governing permissions and
|
|
2013
|
-
* limitations under the License.
|
|
2014
|
-
* =============================================================================
|
|
2015
|
-
*/
|
|
2016
|
-
function gn(t, e, n, o) {
|
|
2017
|
-
const s = t === e, r = t < e && n < 0, a = e < t && n > 1;
|
|
2018
|
-
if (s || r || a)
|
|
2019
|
-
return ot(0, o);
|
|
2020
|
-
const i = Math.abs(Math.ceil((e - t) / n)), u = ot(i, o);
|
|
2021
|
-
e < t && n === 1 && (n = -1), u[0] = t;
|
|
2022
|
-
for (let c = 1; c < u.length; c++)
|
|
2023
|
-
u[c] = u[c - 1] + n;
|
|
2024
|
-
return u;
|
|
2025
|
-
}
|
|
2026
|
-
/**
|
|
2027
|
-
* @license
|
|
2028
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2029
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
2030
|
-
* you may not use this file except in compliance with the License.
|
|
2031
|
-
* You may obtain a copy of the License at
|
|
2032
|
-
*
|
|
2033
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2034
|
-
*
|
|
2035
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2036
|
-
* distributed under the License is distributed on an AS IS BASIS,
|
|
2037
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2038
|
-
* See the License for the specific language governing permissions and
|
|
2039
|
-
* limitations under the License.
|
|
2040
|
-
* =============================================================================
|
|
2041
|
-
*/
|
|
2042
|
-
const pn = K((t) => 1 / Math.sqrt(t));
|
|
2043
|
-
/**
|
|
2044
|
-
* @license
|
|
2045
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2046
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2047
|
-
* you may not use this file except in compliance with the License.
|
|
2048
|
-
* You may obtain a copy of the License at
|
|
2049
|
-
*
|
|
2050
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2051
|
-
*
|
|
2052
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2053
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2054
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2055
|
-
* See the License for the specific language governing permissions and
|
|
2056
|
-
* limitations under the License.
|
|
2057
|
-
* =============================================================================
|
|
2058
|
-
*/
|
|
2059
|
-
function mn(t, e, n, o, s, r, a, i, u, c) {
|
|
2060
|
-
const h = [o / s, s], f = t.values, w = e.values;
|
|
2061
|
-
if (o === 0)
|
|
2062
|
-
return B(n, e.dtype);
|
|
2063
|
-
const p = u instanceof dt ? u : B(h, e.dtype);
|
|
2064
|
-
typeof u == "string" || typeof u == "number" ? p.values.fill(u) : typeof u == "boolean" && p.values.fill(+u);
|
|
2065
|
-
for (let m = 0; m < r; m++) {
|
|
2066
|
-
const v = [];
|
|
2067
|
-
let d = 0;
|
|
2068
|
-
for (let g = 0; g < a; g++) {
|
|
2069
|
-
const x = f[m * a + g];
|
|
2070
|
-
v.push(x), d += x * i[g];
|
|
2071
|
-
}
|
|
2072
|
-
if (d < 0 || d >= o / s)
|
|
2073
|
-
throw new Error(`Invalid indices: ${v} does not index into ${n}`);
|
|
2074
|
-
for (let g = 0; g < s; g++)
|
|
2075
|
-
c ? p.values[d * s + g] += w[m * s + g] : p.values[d * s + g] = e.rank === 0 ? w[0] : w[m * s + g];
|
|
2076
|
-
}
|
|
2077
|
-
return p;
|
|
2078
|
-
}
|
|
2079
|
-
/**
|
|
2080
|
-
* @license
|
|
2081
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2082
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
2083
|
-
* you may not use this file except in compliance with the License.
|
|
2084
|
-
* You may obtain a copy of the License at
|
|
2085
|
-
*
|
|
2086
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2087
|
-
*
|
|
2088
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2089
|
-
* distributed under the License is distributed on an AS IS BASIS,
|
|
2090
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2091
|
-
* See the License for the specific language governing permissions and
|
|
2092
|
-
* limitations under the License.
|
|
2093
|
-
* =============================================================================
|
|
2094
|
-
*/
|
|
2095
|
-
const wn = K((t) => 1 / (1 + Math.exp(-t)));
|
|
2096
|
-
/**
|
|
2097
|
-
* @license
|
|
2098
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2099
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2100
|
-
* you may not use this file except in compliance with the License.
|
|
2101
|
-
* You may obtain a copy of the License at
|
|
2102
|
-
*
|
|
2103
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2104
|
-
*
|
|
2105
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2106
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2107
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2108
|
-
* See the License for the specific language governing permissions and
|
|
2109
|
-
* limitations under the License.
|
|
2110
|
-
* =============================================================================
|
|
2111
|
-
*/
|
|
2112
|
-
function In(t, e, n, o, s) {
|
|
2113
|
-
const r = ne(o, e, n), a = y(n), i = J(o);
|
|
2114
|
-
if (r) {
|
|
2115
|
-
const f = oe(e, i);
|
|
2116
|
-
return s === "string" ? t.slice(f, f + a) : t.subarray(f, f + a);
|
|
2117
|
-
}
|
|
2118
|
-
const u = s === "string" ? $t(t) : t, c = B(o, s, u), h = B(n, s);
|
|
2119
|
-
for (let f = 0; f < h.size; ++f) {
|
|
2120
|
-
const w = h.indexToLoc(f), p = w.map((m, v) => m + e[v]);
|
|
2121
|
-
h.set(c.get(...p), ...w);
|
|
2122
|
-
}
|
|
2123
|
-
return s === "string" ? Qt(h.values) : h.values;
|
|
2124
|
-
}
|
|
2125
|
-
/**
|
|
2126
|
-
* @license
|
|
2127
|
-
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
2128
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2129
|
-
* you may not use this file except in compliance with the License.
|
|
2130
|
-
* You may obtain a copy of the License at
|
|
2131
|
-
*
|
|
2132
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2133
|
-
*
|
|
2134
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2135
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2136
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2137
|
-
* See the License for the specific language governing permissions and
|
|
2138
|
-
* limitations under the License.
|
|
2139
|
-
* =============================================================================
|
|
2140
|
-
*/
|
|
2141
|
-
function xn(t, e, n, o, s, r, a) {
|
|
2142
|
-
const i = e[0], u = r[0], c = new Array(u), h = new Array(i), f = e[1];
|
|
2143
|
-
if (u === 0) {
|
|
2144
|
-
if (i !== 0)
|
|
2145
|
-
throw new Error(xe(i));
|
|
2146
|
-
const d = q(n, 0), g = q(s, 0);
|
|
2147
|
-
return [
|
|
2148
|
-
d,
|
|
2149
|
-
[0, f],
|
|
2150
|
-
g,
|
|
2151
|
-
c,
|
|
2152
|
-
h
|
|
2153
|
-
];
|
|
2154
|
-
}
|
|
2155
|
-
let w = !0, p = 0;
|
|
2156
|
-
const m = new Array(u).fill(0);
|
|
2157
|
-
for (let d = 0; d < i; ++d) {
|
|
2158
|
-
const g = t[d * f];
|
|
2159
|
-
if (g < 0)
|
|
2160
|
-
throw new Error(Se(d, g));
|
|
2161
|
-
if (g >= u)
|
|
2162
|
-
throw new Error(Ee(d, g, u));
|
|
2163
|
-
++m[g], w = w && g >= p, p = g;
|
|
2164
|
-
}
|
|
2165
|
-
let v = !0;
|
|
2166
|
-
for (let d = 0; d < u; ++d) {
|
|
2167
|
-
const g = m[d] === 0;
|
|
2168
|
-
c[d] = g, v = v && !g, m[d] = Math.max(m[d], 1), d > 0 && (m[d] += m[d - 1]);
|
|
2169
|
-
}
|
|
2170
|
-
if (v && w) {
|
|
2171
|
-
const d = t, g = o;
|
|
2172
|
-
for (let x = 0; x < i; ++x)
|
|
2173
|
-
h[x] = x;
|
|
2174
|
-
return [
|
|
2175
|
-
d,
|
|
2176
|
-
[i, f],
|
|
2177
|
-
g,
|
|
2178
|
-
c,
|
|
2179
|
-
h
|
|
2180
|
-
];
|
|
2181
|
-
} else {
|
|
2182
|
-
const d = m[u - 1], g = q(n, d * f), x = q(s, d), O = new Array(u).fill(0);
|
|
2183
|
-
for (let b = 0; b < i; ++b) {
|
|
2184
|
-
const V = t[b * f], D = O[V], L = (V === 0 ? 0 : m[V - 1]) + D;
|
|
2185
|
-
O[V]++;
|
|
2186
|
-
for (let _ = 0; _ < f; ++_)
|
|
2187
|
-
g[L * f + _] = t[b * f + _];
|
|
2188
|
-
x[L] = o[b], h[b] = L;
|
|
2189
|
-
}
|
|
2190
|
-
for (let b = 0; b < u; ++b)
|
|
2191
|
-
if (O[b] === 0) {
|
|
2192
|
-
const D = b === 0 ? 0 : m[b - 1];
|
|
2193
|
-
g[D * f + 0] = b;
|
|
2194
|
-
for (let L = 1; L < f; ++L)
|
|
2195
|
-
g[D * f + L] = 0;
|
|
2196
|
-
x[D] = a;
|
|
2197
|
-
}
|
|
2198
|
-
return [
|
|
2199
|
-
g,
|
|
2200
|
-
[d, f],
|
|
2201
|
-
x,
|
|
2202
|
-
c,
|
|
2203
|
-
h
|
|
2204
|
-
];
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
/**
|
|
2208
|
-
* @license
|
|
2209
|
-
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
2210
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2211
|
-
* you may not use this file except in compliance with the License.
|
|
2212
|
-
* You may obtain a copy of the License at
|
|
2213
|
-
*
|
|
2214
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2215
|
-
*
|
|
2216
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2217
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2218
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2219
|
-
* See the License for the specific language governing permissions and
|
|
2220
|
-
* limitations under the License.
|
|
2221
|
-
* =============================================================================
|
|
2222
|
-
*/
|
|
2223
|
-
function Sn(t, e, n, o, s) {
|
|
2224
|
-
const r = y(o), a = e[0], i = s.length, u = [];
|
|
2225
|
-
let c = 1, h = -1;
|
|
2226
|
-
for (let d = 0; d < i; ++d) {
|
|
2227
|
-
const g = s[d];
|
|
2228
|
-
if (g === -1) {
|
|
2229
|
-
if (h !== -1)
|
|
2230
|
-
throw new Error(ve(h, d));
|
|
2231
|
-
h = d, u.push(1);
|
|
2232
|
-
} else {
|
|
2233
|
-
if (g < 0)
|
|
2234
|
-
throw new Error(be(d, g));
|
|
2235
|
-
c *= g, u.push(g);
|
|
2236
|
-
}
|
|
2237
|
-
}
|
|
2238
|
-
if (h !== -1) {
|
|
2239
|
-
if (c <= 0)
|
|
2240
|
-
throw new Error(Oe());
|
|
2241
|
-
const d = Math.trunc(r / c);
|
|
2242
|
-
if (c * d !== r)
|
|
2243
|
-
throw new Error(Fe(o, u));
|
|
2244
|
-
u[h] = d;
|
|
2245
|
-
}
|
|
2246
|
-
if (y(u) !== r)
|
|
2247
|
-
throw new Error(Re(o, u));
|
|
2248
|
-
const w = o.length, p = [];
|
|
2249
|
-
if (w > 0) {
|
|
2250
|
-
p[w - 1] = 1;
|
|
2251
|
-
for (let d = w - 2; d >= 0; --d)
|
|
2252
|
-
p[d] = p[d + 1] * o[d + 1];
|
|
2253
|
-
}
|
|
2254
|
-
const m = [];
|
|
2255
|
-
if (i > 0) {
|
|
2256
|
-
m[i - 1] = 1;
|
|
2257
|
-
for (let d = i - 2; d >= 0; --d)
|
|
2258
|
-
m[d] = m[d + 1] * u[d + 1];
|
|
2259
|
-
}
|
|
2260
|
-
const v = q(n, a * i);
|
|
2261
|
-
for (let d = 0; d < a; ++d) {
|
|
2262
|
-
let g = 0;
|
|
2263
|
-
for (let x = 0; x < w; ++x)
|
|
2264
|
-
g += t[d * w + x] * p[x];
|
|
2265
|
-
for (let x = 0; x < i; ++x)
|
|
2266
|
-
v[d * i + x] = Math.trunc(g / m[x]), g %= m[x];
|
|
2267
|
-
}
|
|
2268
|
-
return [v, [a, i], u];
|
|
2269
|
-
}
|
|
2270
|
-
/**
|
|
2271
|
-
* @license
|
|
2272
|
-
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
2273
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2274
|
-
* you may not use this file except in compliance with the License.
|
|
2275
|
-
* You may obtain a copy of the License at
|
|
2276
|
-
*
|
|
2277
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2278
|
-
*
|
|
2279
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2280
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2281
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2282
|
-
* See the License for the specific language governing permissions and
|
|
2283
|
-
* limitations under the License.
|
|
2284
|
-
* =============================================================================
|
|
2285
|
-
*/
|
|
2286
|
-
function En(t, e, n, o, s, r = !1, a = 0) {
|
|
2287
|
-
const i = o.length, u = [e[0], t.length / e[0]], c = u[1], f = i > 0 ? s[i - 1] + 1 : 0;
|
|
2288
|
-
if (f < 0)
|
|
2289
|
-
throw new Error(Et());
|
|
2290
|
-
const w = e.slice();
|
|
2291
|
-
w[0] = f;
|
|
2292
|
-
const p = w.reduce((O, b) => O * b, 1), m = q(n, p);
|
|
2293
|
-
if (i === 0)
|
|
2294
|
-
return f > 0 && m.fill(a), [m, w];
|
|
2295
|
-
if (f <= 0)
|
|
2296
|
-
throw new Error(Et());
|
|
2297
|
-
let v = 0, d = 1, g = 0, x = s[v];
|
|
2298
|
-
for (; ; ) {
|
|
2299
|
-
let O = 0;
|
|
2300
|
-
if (d < i) {
|
|
2301
|
-
if (O = s[d], x === O) {
|
|
2302
|
-
++d;
|
|
2303
|
-
continue;
|
|
2304
|
-
}
|
|
2305
|
-
if (x >= O)
|
|
2306
|
-
throw new Error($e());
|
|
2307
|
-
}
|
|
2308
|
-
if (x < 0 || x >= f)
|
|
2309
|
-
throw new Error(ye(x, f));
|
|
2310
|
-
x > g && m.fill(a, g * c, x * c);
|
|
2311
|
-
for (let b = v; b < d; ++b) {
|
|
2312
|
-
const V = o[b];
|
|
2313
|
-
if (V < 0 || V >= u[0])
|
|
2314
|
-
throw new Error(Te(b, o[b], u[0]));
|
|
2315
|
-
for (let D = 0; D < c; D++)
|
|
2316
|
-
m[x * c + D] += t[V * c + D];
|
|
2317
|
-
}
|
|
2318
|
-
if (r)
|
|
2319
|
-
for (let b = 0; b < c; b++)
|
|
2320
|
-
m[x * c + b] /= d - v;
|
|
2321
|
-
if (v = d, ++d, g = x + 1, x = O, d > i)
|
|
2322
|
-
break;
|
|
2323
|
-
}
|
|
2324
|
-
return g < f && m.fill(a, g * c, f * c), [m, w];
|
|
2325
|
-
}
|
|
2326
|
-
/**
|
|
2327
|
-
* @license
|
|
2328
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2329
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
2330
|
-
* you may not use this file except in compliance with the License.
|
|
2331
|
-
* You may obtain a copy of the License at
|
|
2332
|
-
*
|
|
2333
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2334
|
-
*
|
|
2335
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2336
|
-
* distributed under the License is distributed on an AS IS BASIS,
|
|
2337
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2338
|
-
* See the License for the specific language governing permissions and
|
|
2339
|
-
* limitations under the License.
|
|
2340
|
-
* =============================================================================
|
|
2341
|
-
*/
|
|
2342
|
-
const vn = K((t) => Math.sqrt(t));
|
|
2343
|
-
/**
|
|
2344
|
-
* @license
|
|
2345
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2346
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2347
|
-
* you may not use this file except in compliance with the License.
|
|
2348
|
-
* You may obtain a copy of the License at
|
|
2349
|
-
*
|
|
2350
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2351
|
-
*
|
|
2352
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2353
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2354
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2355
|
-
* See the License for the specific language governing permissions and
|
|
2356
|
-
* limitations under the License.
|
|
2357
|
-
* =============================================================================
|
|
2358
|
-
*/
|
|
2359
|
-
const bn = C((t, e) => {
|
|
2360
|
-
const n = t - e;
|
|
2361
|
-
return n * n;
|
|
2362
|
-
});
|
|
2363
|
-
/**
|
|
2364
|
-
* @license
|
|
2365
|
-
* Copyright 2023 Google LLC.
|
|
2366
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2367
|
-
* you may not use this file except in compliance with the License.
|
|
2368
|
-
* You may obtain a copy of the License at
|
|
2369
|
-
*
|
|
2370
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2371
|
-
*
|
|
2372
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2373
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2374
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2375
|
-
* See the License for the specific language governing permissions and
|
|
2376
|
-
* limitations under the License.
|
|
2377
|
-
* =============================================================================
|
|
2378
|
-
*/
|
|
2379
|
-
const On = K((t, e) => {
|
|
2380
|
-
const { pattern: n, replaceGlobal: o, rewrite: s } = e;
|
|
2381
|
-
return t.replace(new RegExp(n, o ? "g" : ""), s);
|
|
2382
|
-
});
|
|
2383
|
-
/**
|
|
2384
|
-
* @license
|
|
2385
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2386
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2387
|
-
* you may not use this file except in compliance with the License.
|
|
2388
|
-
* You may obtain a copy of the License at
|
|
2389
|
-
*
|
|
2390
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2391
|
-
*
|
|
2392
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2393
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2394
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2395
|
-
* See the License for the specific language governing permissions and
|
|
2396
|
-
* limitations under the License.
|
|
2397
|
-
* =============================================================================
|
|
2398
|
-
*/
|
|
2399
|
-
function Fn(t, e, n, o) {
|
|
2400
|
-
const s = B(t, e.dtype);
|
|
2401
|
-
for (let r = 0; r < s.size; r++) {
|
|
2402
|
-
const a = s.indexToLoc(r), i = new Array(a.length);
|
|
2403
|
-
for (let u = 0; u < i.length; u++)
|
|
2404
|
-
i[u] = a[u] * n[u] + o[u];
|
|
2405
|
-
s.set(e.get(...i), ...a);
|
|
2406
|
-
}
|
|
2407
|
-
return s;
|
|
2408
|
-
}
|
|
2409
|
-
/**
|
|
2410
|
-
* @license
|
|
2411
|
-
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
2412
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2413
|
-
* you may not use this file except in compliance with the License.
|
|
2414
|
-
* You may obtain a copy of the License at
|
|
2415
|
-
*
|
|
2416
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2417
|
-
*
|
|
2418
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2419
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2420
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2421
|
-
* See the License for the specific language governing permissions and
|
|
2422
|
-
* limitations under the License.
|
|
2423
|
-
* =============================================================================
|
|
2424
|
-
*/
|
|
2425
|
-
class Rn {
|
|
2426
|
-
constructor(e, n, o, s, r, a) {
|
|
2427
|
-
this.separator = ct(e), this.nGramWidths = n, this.leftPad = ct(o), this.rightPad = ct(s), this.padWidth = r, this.preserveShort = a;
|
|
2428
|
-
}
|
|
2429
|
-
getPadWidth(e) {
|
|
2430
|
-
return Math.min(this.padWidth < 0 ? e - 1 : this.padWidth, e - 1);
|
|
2431
|
-
}
|
|
2432
|
-
getNumNGrams(e, n) {
|
|
2433
|
-
const o = this.getPadWidth(n);
|
|
2434
|
-
return Math.max(0, e + 2 * o - n + 1);
|
|
2435
|
-
}
|
|
2436
|
-
createNGrams(e, n, o, s, r, a) {
|
|
2437
|
-
for (let i = 0; i < r; ++i) {
|
|
2438
|
-
const u = this.getPadWidth(a), c = Math.max(0, u - i), h = Math.max(0, u - (r - (i + 1))), f = a - (c + h), w = n + (c > 0 ? 0 : i - u);
|
|
2439
|
-
let p = 0;
|
|
2440
|
-
p += c * this.leftPad.length;
|
|
2441
|
-
for (let x = 0; x < f; ++x)
|
|
2442
|
-
p += e[w + x].length;
|
|
2443
|
-
p += h * this.rightPad.length;
|
|
2444
|
-
const m = c + h + f - 1;
|
|
2445
|
-
p += m * this.separator.length, o[s + i] = new Uint8Array(p);
|
|
2446
|
-
const v = o[s + i];
|
|
2447
|
-
let d = 0;
|
|
2448
|
-
const g = (x) => x.forEach((O) => v[d++] = O);
|
|
2449
|
-
for (let x = 0; x < c; ++x)
|
|
2450
|
-
g(this.leftPad), g(this.separator);
|
|
2451
|
-
for (let x = 0; x < f - 1; ++x)
|
|
2452
|
-
g(e[w + x]), g(this.separator);
|
|
2453
|
-
if (f > 0) {
|
|
2454
|
-
g(e[w + f - 1]);
|
|
2455
|
-
for (let x = 0; x < h; ++x)
|
|
2456
|
-
g(this.separator), g(this.rightPad);
|
|
2457
|
-
} else {
|
|
2458
|
-
for (let x = 0; x < h - 1; ++x)
|
|
2459
|
-
g(this.rightPad), g(this.separator);
|
|
2460
|
-
g(this.rightPad);
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
}
|
|
2464
|
-
// Data and splits together form the definition of the ragged tensor,
|
|
2465
|
-
// where data is 1 dimensional and contains the values of the tensor
|
|
2466
|
-
// and splits denotes the indices at which each row starts.
|
|
2467
|
-
compute(e, n) {
|
|
2468
|
-
const o = e.length, s = n.length;
|
|
2469
|
-
if (s > 0) {
|
|
2470
|
-
let u = n[0];
|
|
2471
|
-
if (u !== 0)
|
|
2472
|
-
throw new Error(`First split value must be 0, got ${u}`);
|
|
2473
|
-
for (let c = 1; c < s; ++c) {
|
|
2474
|
-
let h = n[c] >= u;
|
|
2475
|
-
if (h = h && n[c] <= o, !h)
|
|
2476
|
-
throw new Error(`Invalid split value ${n[c]}, must be in [${u}, ${o}]`);
|
|
2477
|
-
u = n[c];
|
|
2478
|
-
}
|
|
2479
|
-
if (u !== o)
|
|
2480
|
-
throw new Error(`Last split value must be data size. Expected ${o}, got ${u}`);
|
|
2481
|
-
}
|
|
2482
|
-
const r = s - 1, a = q("int32", s);
|
|
2483
|
-
if (o === 0 || s === 0) {
|
|
2484
|
-
const u = new Array(o);
|
|
2485
|
-
for (let c = 0; c <= r; ++c)
|
|
2486
|
-
a[c] = 0;
|
|
2487
|
-
return [u, a];
|
|
2488
|
-
}
|
|
2489
|
-
a[0] = 0;
|
|
2490
|
-
for (let u = 1; u <= r; ++u) {
|
|
2491
|
-
const c = n[u] - n[u - 1];
|
|
2492
|
-
let h = 0;
|
|
2493
|
-
this.nGramWidths.forEach((f) => {
|
|
2494
|
-
h += this.getNumNGrams(c, f);
|
|
2495
|
-
}), this.preserveShort && c > 0 && h === 0 && (h = 1), a[u] = a[u - 1] + h;
|
|
2496
|
-
}
|
|
2497
|
-
const i = new Array(a[r]);
|
|
2498
|
-
for (let u = 0; u < r; ++u) {
|
|
2499
|
-
const c = n[u];
|
|
2500
|
-
let h = a[u];
|
|
2501
|
-
if (this.nGramWidths.forEach((f) => {
|
|
2502
|
-
const w = n[u + 1] - n[u], p = this.getNumNGrams(w, f);
|
|
2503
|
-
this.createNGrams(e, c, i, h, p, f), h += p;
|
|
2504
|
-
}), this.preserveShort && h === a[u]) {
|
|
2505
|
-
const f = n[u + 1] - n[u];
|
|
2506
|
-
if (f === 0)
|
|
2507
|
-
continue;
|
|
2508
|
-
const w = f + 2 * this.padWidth;
|
|
2509
|
-
this.createNGrams(e, c, i, h, 1, w);
|
|
2510
|
-
}
|
|
2511
|
-
}
|
|
2512
|
-
return [i, a];
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
function $n(t, e, n, o, s, r, a, i) {
|
|
2516
|
-
return new Rn(n, o, s, r, a, i).compute(t, e);
|
|
2517
|
-
}
|
|
2518
|
-
/**
|
|
2519
|
-
* @license
|
|
2520
|
-
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
2521
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2522
|
-
* you may not use this file except in compliance with the License.
|
|
2523
|
-
* You may obtain a copy of the License at
|
|
2524
|
-
*
|
|
2525
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2526
|
-
*
|
|
2527
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2528
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2529
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2530
|
-
* See the License for the specific language governing permissions and
|
|
2531
|
-
* limitations under the License.
|
|
2532
|
-
* =============================================================================
|
|
2533
|
-
*/
|
|
2534
|
-
function yn(t, e, n, o) {
|
|
2535
|
-
if (!t.length)
|
|
2536
|
-
return;
|
|
2537
|
-
if (e.length === 0) {
|
|
2538
|
-
for (let r = 0; r < t.length; ++r)
|
|
2539
|
-
o.push(t.subarray(r, r + 1));
|
|
2540
|
-
return;
|
|
2541
|
-
}
|
|
2542
|
-
if (e.length === 1) {
|
|
2543
|
-
const r = e[0];
|
|
2544
|
-
let a = t.indexOf(r);
|
|
2545
|
-
for (; a !== -1; ) {
|
|
2546
|
-
const i = t.subarray(0, a);
|
|
2547
|
-
(!n || i.length !== 0) && o.push(i), t = t.subarray(a + 1), a = t.indexOf(r);
|
|
2548
|
-
}
|
|
2549
|
-
(!n || t.length !== 0) && o.push(t);
|
|
2550
|
-
return;
|
|
2551
|
-
}
|
|
2552
|
-
let s = 0;
|
|
2553
|
-
for (let r = 0; r < t.length + 1; r++)
|
|
2554
|
-
if (r === t.length || e.indexOf(t[r]) !== -1) {
|
|
2555
|
-
const a = t.subarray(s, r);
|
|
2556
|
-
(!n || a.length !== 0) && o.push(a), s = r + 1;
|
|
2557
|
-
}
|
|
2558
|
-
}
|
|
2559
|
-
function Tn(t, e, n) {
|
|
2560
|
-
const o = t.length, s = [];
|
|
2561
|
-
let r = 0, a = 0;
|
|
2562
|
-
const i = new Array(o);
|
|
2563
|
-
for (let w = 0; w < o; ++w) {
|
|
2564
|
-
const p = s.length;
|
|
2565
|
-
yn(t[w], e, n, s);
|
|
2566
|
-
const m = s.length - p;
|
|
2567
|
-
i[w] = m, r += m, a = Math.max(a, m);
|
|
2568
|
-
}
|
|
2569
|
-
const u = q("int32", r * 2), c = new Array(r), h = [o, a];
|
|
2570
|
-
let f = 0;
|
|
2571
|
-
for (let w = 0; w < o; ++w)
|
|
2572
|
-
for (let p = 0; p < i[w]; ++p)
|
|
2573
|
-
u[f * 2] = w, u[f * 2 + 1] = p, c[f] = s[f], ++f;
|
|
2574
|
-
return [u, c, h];
|
|
2575
|
-
}
|
|
2576
|
-
/**
|
|
2577
|
-
* @license
|
|
2578
|
-
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
2579
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2580
|
-
* you may not use this file except in compliance with the License.
|
|
2581
|
-
* You may obtain a copy of the License at
|
|
2582
|
-
*
|
|
2583
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2584
|
-
*
|
|
2585
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2586
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2587
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2588
|
-
* See the License for the specific language governing permissions and
|
|
2589
|
-
* limitations under the License.
|
|
2590
|
-
* =============================================================================
|
|
2591
|
-
*/
|
|
2592
|
-
function Vn(t, e) {
|
|
2593
|
-
const n = q("int32", t.length);
|
|
2594
|
-
for (let o = 0; o < t.length; ++o)
|
|
2595
|
-
n[o] = fe(t[o]).modulo(e).getLowBitsUnsigned();
|
|
2596
|
-
return n;
|
|
2597
|
-
}
|
|
2598
|
-
/**
|
|
2599
|
-
* @license
|
|
2600
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2601
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2602
|
-
* you may not use this file except in compliance with the License.
|
|
2603
|
-
* You may obtain a copy of the License at
|
|
2604
|
-
*
|
|
2605
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2606
|
-
*
|
|
2607
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2608
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2609
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2610
|
-
* See the License for the specific language governing permissions and
|
|
2611
|
-
* limitations under the License.
|
|
2612
|
-
* =============================================================================
|
|
2613
|
-
*/
|
|
2614
|
-
const Mn = C((t, e) => t - e);
|
|
2615
|
-
/**
|
|
2616
|
-
* @license
|
|
2617
|
-
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
2618
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2619
|
-
* you may not use this file except in compliance with the License.
|
|
2620
|
-
* You may obtain a copy of the License at
|
|
2621
|
-
*
|
|
2622
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2623
|
-
*
|
|
2624
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2625
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2626
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2627
|
-
* See the License for the specific language governing permissions and
|
|
2628
|
-
* limitations under the License.
|
|
2629
|
-
* =============================================================================
|
|
2630
|
-
*/
|
|
2631
|
-
function Ln(t, e) {
|
|
2632
|
-
const n = new Array(t.rank);
|
|
2633
|
-
for (let s = 0; s < n.length; s++)
|
|
2634
|
-
n[s] = t.shape[s] * e[s];
|
|
2635
|
-
const o = B(n, t.dtype);
|
|
2636
|
-
for (let s = 0; s < o.values.length; ++s) {
|
|
2637
|
-
const r = o.indexToLoc(s), a = new Array(t.rank);
|
|
2638
|
-
for (let u = 0; u < a.length; u++)
|
|
2639
|
-
a[u] = r[u] % t.shape[u];
|
|
2640
|
-
const i = t.locToIndex(a);
|
|
2641
|
-
o.values[s] = t.values[i];
|
|
2642
|
-
}
|
|
2643
|
-
return o;
|
|
2644
|
-
}
|
|
2645
|
-
/**
|
|
2646
|
-
* @license
|
|
2647
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2648
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2649
|
-
* you may not use this file except in compliance with the License.
|
|
2650
|
-
* You may obtain a copy of the License at
|
|
2651
|
-
*
|
|
2652
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2653
|
-
*
|
|
2654
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2655
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2656
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2657
|
-
* See the License for the specific language governing permissions and
|
|
2658
|
-
* limitations under the License.
|
|
2659
|
-
* =============================================================================
|
|
2660
|
-
*/
|
|
2661
|
-
const et = (t, e) => {
|
|
2662
|
-
const n = e.value - t.value;
|
|
2663
|
-
return n === 0 ? t.index - e.index : n;
|
|
2664
|
-
};
|
|
2665
|
-
function Dt(t, e, n = 0, o = t.length - 1) {
|
|
2666
|
-
for (; o > n; ) {
|
|
2667
|
-
if (o - n > 600) {
|
|
2668
|
-
const i = o - n + 1, u = e - n + 1, c = Math.log(i), h = 0.5 * Math.exp(2 * c / 3), f = 0.5 * Math.sqrt(c * h * (i - h) / i) * Math.sign(u - i / 2), w = Math.max(n, Math.floor(e - u * h / i + f)), p = Math.min(o, Math.floor(e + (i - u) * h / i + f));
|
|
2669
|
-
Dt(t, e, w, p);
|
|
2670
|
-
}
|
|
2671
|
-
const s = t[e];
|
|
2672
|
-
let r = n, a = o;
|
|
2673
|
-
for (tt(t, n, e), et(t[o], s) > 0 && tt(t, n, o); r < a; ) {
|
|
2674
|
-
for (tt(t, r, a), r++, a--; et(t[r], s) < 0; )
|
|
2675
|
-
r = r + 1;
|
|
2676
|
-
for (; et(t[a], s) > 0; )
|
|
2677
|
-
a = a - 1;
|
|
2678
|
-
}
|
|
2679
|
-
et(t[n], s) === 0 ? tt(t, n, a) : (a = a + 1, tt(t, a, o)), a <= e && (n = a + 1), e <= a && (o = a - 1);
|
|
2680
|
-
}
|
|
2681
|
-
}
|
|
2682
|
-
function _n(t, e, n, o, s) {
|
|
2683
|
-
const r = e[e.length - 1], [a, i] = [t.length / r, r], u = nt(n, a * o), c = nt("int32", a * o);
|
|
2684
|
-
for (let f = 0; f < a; f++) {
|
|
2685
|
-
const w = f * i, p = t.subarray(w, w + i);
|
|
2686
|
-
let m = new Array(p.length);
|
|
2687
|
-
p.forEach((x, O) => m[O] = { value: x, index: O }), o < m.length && (Dt(m, o), m = m.slice(0, o)), s && m.sort(et);
|
|
2688
|
-
const v = f * o, d = u.subarray(v, v + o), g = c.subarray(v, v + o);
|
|
2689
|
-
for (let x = 0; x < o; x++)
|
|
2690
|
-
d[x] = m[x].value, g[x] = m[x].index;
|
|
2691
|
-
}
|
|
2692
|
-
const h = e.slice();
|
|
2693
|
-
return h[h.length - 1] = o, [
|
|
2694
|
-
B(h, n, u),
|
|
2695
|
-
B(h, "int32", c)
|
|
2696
|
-
];
|
|
2697
|
-
}
|
|
1
|
+
import { ao as E, ap as T, q as V, N as L, a1 as w, aq as K, r as W } from "../../index-bMBtI-WR.js";
|
|
2
|
+
import { t as B, m as G } from "../../shared-XNAoXhOa.js";
|
|
3
|
+
import { r as b } from "../../Reshape-CLOrdpve.js";
|
|
4
|
+
import { g as C, a as U, b as _ } from "../../kernel_funcs_utils-CNmjLWnB.js";
|
|
5
|
+
import { g as k, a as R, b as P, c as y, e as O } from "../../axis_util-D17qZRQm.js";
|
|
2698
6
|
/**
|
|
2699
7
|
* @license
|
|
2700
|
-
* Copyright
|
|
8
|
+
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
2701
9
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2702
10
|
* you may not use this file except in compliance with the License.
|
|
2703
11
|
* You may obtain a copy of the License at
|
|
@@ -2711,47 +19,9 @@ function _n(t, e, n, o, s) {
|
|
|
2711
19
|
* limitations under the License.
|
|
2712
20
|
* =============================================================================
|
|
2713
21
|
*/
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
r[0] *= n[m];
|
|
2718
|
-
r[1] = n[s];
|
|
2719
|
-
for (let m = s + 1; m < n.length; m++)
|
|
2720
|
-
r[2] *= n[m];
|
|
2721
|
-
const a = /* @__PURE__ */ new Map(), i = new Int32Array(n[s]), u = new dt(r, o, t), c = [], h = r[0] === 1 && r[2] === 1;
|
|
2722
|
-
for (let m = 0; m < n[s]; m++) {
|
|
2723
|
-
let v;
|
|
2724
|
-
if (h)
|
|
2725
|
-
v = t[m].toString();
|
|
2726
|
-
else {
|
|
2727
|
-
const g = [];
|
|
2728
|
-
for (let x = 0; x < r[0]; x++)
|
|
2729
|
-
for (let O = 0; O < r[2]; O++)
|
|
2730
|
-
g.push(u.get(x, m, O));
|
|
2731
|
-
v = g.join(",");
|
|
2732
|
-
}
|
|
2733
|
-
const d = a.get(v);
|
|
2734
|
-
if (d != null)
|
|
2735
|
-
i[m] = d;
|
|
2736
|
-
else {
|
|
2737
|
-
const g = a.size;
|
|
2738
|
-
a.set(v, g), i[m] = g, c.push(m);
|
|
2739
|
-
}
|
|
2740
|
-
}
|
|
2741
|
-
const f = r.slice();
|
|
2742
|
-
f[1] = a.size;
|
|
2743
|
-
const w = new dt(f, o);
|
|
2744
|
-
c.forEach((m, v) => {
|
|
2745
|
-
for (let d = 0; d < r[0]; d++)
|
|
2746
|
-
for (let g = 0; g < r[2]; g++)
|
|
2747
|
-
w.set(u.get(d, m, g), d, v, g);
|
|
2748
|
-
});
|
|
2749
|
-
const p = n.slice();
|
|
2750
|
-
return p[s] = f[1], {
|
|
2751
|
-
outputValues: w.values,
|
|
2752
|
-
outputShape: p,
|
|
2753
|
-
indices: i
|
|
2754
|
-
};
|
|
22
|
+
const q = 30;
|
|
23
|
+
function F(a) {
|
|
24
|
+
return a <= q ? a : E(a, Math.floor(Math.sqrt(a)));
|
|
2755
25
|
}
|
|
2756
26
|
/**
|
|
2757
27
|
* @license
|
|
@@ -2769,114 +39,27 @@ function Nn(t, e, n, o) {
|
|
|
2769
39
|
* limitations under the License.
|
|
2770
40
|
* =============================================================================
|
|
2771
41
|
*/
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
addImpl: Le,
|
|
2775
|
-
bincountImpl: _e,
|
|
2776
|
-
bincountReduceImpl: Ne,
|
|
2777
|
-
bitwiseAndImpl: Ae,
|
|
2778
|
-
castImpl: Me,
|
|
2779
|
-
ceilImpl: Pe,
|
|
2780
|
-
concatImpl: De,
|
|
2781
|
-
equalImpl: ze,
|
|
2782
|
-
expImpl: We,
|
|
2783
|
-
expm1Impl: qe,
|
|
2784
|
-
floorDivImpl: ke,
|
|
2785
|
-
floorImpl: Ce,
|
|
2786
|
-
gatherNdImpl: Ue,
|
|
2787
|
-
gatherV2Impl: Ge,
|
|
2788
|
-
greaterEqualImpl: Ze,
|
|
2789
|
-
greaterImpl: je,
|
|
2790
|
-
lessEqualImpl: He,
|
|
2791
|
-
lessImpl: Be,
|
|
2792
|
-
linSpaceImpl: Ke,
|
|
2793
|
-
logImpl: Xe,
|
|
2794
|
-
maxImpl: Qe,
|
|
2795
|
-
maximumImpl: Ye,
|
|
2796
|
-
minimumImpl: Je,
|
|
2797
|
-
multiplyImpl: Pt,
|
|
2798
|
-
negImpl: tn,
|
|
2799
|
-
notEqualImpl: en,
|
|
2800
|
-
prodImpl: on,
|
|
2801
|
-
raggedGatherImpl: hn,
|
|
2802
|
-
raggedRangeImpl: fn,
|
|
2803
|
-
raggedTensorToTensorImpl: dn,
|
|
2804
|
-
rangeImpl: gn,
|
|
2805
|
-
rsqrtImpl: pn,
|
|
2806
|
-
scatterImpl: mn,
|
|
2807
|
-
sigmoidImpl: wn,
|
|
2808
|
-
simpleAbsImpl: Ve,
|
|
2809
|
-
sliceImpl: In,
|
|
2810
|
-
sparseFillEmptyRowsImpl: xn,
|
|
2811
|
-
sparseReshapeImpl: Sn,
|
|
2812
|
-
sparseSegmentReductionImpl: En,
|
|
2813
|
-
sqrtImpl: vn,
|
|
2814
|
-
squaredDifferenceImpl: bn,
|
|
2815
|
-
staticRegexReplaceImpl: On,
|
|
2816
|
-
stridedSliceImpl: Fn,
|
|
2817
|
-
stringNGramsImpl: $n,
|
|
2818
|
-
stringSplitImpl: Tn,
|
|
2819
|
-
stringToHashBucketFastImpl: Vn,
|
|
2820
|
-
subImpl: Mn,
|
|
2821
|
-
tileImpl: Ln,
|
|
2822
|
-
topKImpl: _n,
|
|
2823
|
-
transposeImpl: nn,
|
|
2824
|
-
uniqueImpl: Nn
|
|
2825
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
2826
|
-
/**
|
|
2827
|
-
* @license
|
|
2828
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2829
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2830
|
-
* you may not use this file except in compliance with the License.
|
|
2831
|
-
* You may obtain a copy of the License at
|
|
2832
|
-
*
|
|
2833
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2834
|
-
*
|
|
2835
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2836
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2837
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2838
|
-
* See the License for the specific language governing permissions and
|
|
2839
|
-
* limitations under the License.
|
|
2840
|
-
* =============================================================================
|
|
2841
|
-
*/
|
|
2842
|
-
const { maxImpl: Pn, transposeImpl: Dn } = An;
|
|
2843
|
-
/**
|
|
2844
|
-
* @license
|
|
2845
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
2846
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2847
|
-
* you may not use this file except in compliance with the License.
|
|
2848
|
-
* You may obtain a copy of the License at
|
|
2849
|
-
*
|
|
2850
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2851
|
-
*
|
|
2852
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2853
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2854
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2855
|
-
* See the License for the specific language governing permissions and
|
|
2856
|
-
* limitations under the License.
|
|
2857
|
-
* =============================================================================
|
|
2858
|
-
*/
|
|
2859
|
-
class Rt {
|
|
2860
|
-
constructor(e, n) {
|
|
42
|
+
class A {
|
|
43
|
+
constructor(o, t) {
|
|
2861
44
|
this.variableNames = ["x"];
|
|
2862
|
-
const { windowSize:
|
|
2863
|
-
this.outputShape = [
|
|
2864
|
-
const
|
|
2865
|
-
let
|
|
2866
|
-
if (
|
|
2867
|
-
const
|
|
2868
|
-
|
|
2869
|
-
}
|
|
2870
|
-
let
|
|
2871
|
-
|
|
2872
|
-
if (inIdx < 0 || inIdx >= ${
|
|
45
|
+
const { windowSize: e, batchSize: n, inSize: u, outSize: l } = o;
|
|
46
|
+
this.outputShape = [n, l];
|
|
47
|
+
const s = Math.floor(e / 4) * 4, c = e % 4;
|
|
48
|
+
let i = "sumValue += dot(values, ones);";
|
|
49
|
+
if (t != null) {
|
|
50
|
+
const p = 1 / t;
|
|
51
|
+
i = `sumValue += dot(values * ${T(p) ? p.toPrecision(2) : p}, ones);`;
|
|
52
|
+
}
|
|
53
|
+
let r = "";
|
|
54
|
+
u % e > 0 && (r = `
|
|
55
|
+
if (inIdx < 0 || inIdx >= ${u}) {
|
|
2873
56
|
return 0.0;
|
|
2874
57
|
}
|
|
2875
58
|
`), this.userCode = `
|
|
2876
59
|
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
|
|
2877
60
|
|
|
2878
61
|
float getValue(int batch, int inIdx) {
|
|
2879
|
-
${
|
|
62
|
+
${r}
|
|
2880
63
|
return getX(batch, inIdx);
|
|
2881
64
|
}
|
|
2882
65
|
|
|
@@ -2884,11 +67,11 @@ class Rt {
|
|
|
2884
67
|
ivec2 coords = getOutputCoords();
|
|
2885
68
|
int batch = coords[0];
|
|
2886
69
|
int outIdx = coords[1];
|
|
2887
|
-
int inOffset = outIdx * ${
|
|
70
|
+
int inOffset = outIdx * ${e};
|
|
2888
71
|
|
|
2889
72
|
float sumValue = 0.0;
|
|
2890
73
|
|
|
2891
|
-
for (int i = 0; i < ${
|
|
74
|
+
for (int i = 0; i < ${s}; i += 4) {
|
|
2892
75
|
int inIdx = inOffset + i;
|
|
2893
76
|
vec4 values = vec4(
|
|
2894
77
|
getValue(batch, inIdx),
|
|
@@ -2897,27 +80,27 @@ class Rt {
|
|
|
2897
80
|
getValue(batch, inIdx + 3)
|
|
2898
81
|
);
|
|
2899
82
|
|
|
2900
|
-
${
|
|
83
|
+
${i}
|
|
2901
84
|
}
|
|
2902
85
|
|
|
2903
|
-
int inIdx = inOffset + ${
|
|
2904
|
-
if (${
|
|
86
|
+
int inIdx = inOffset + ${s};
|
|
87
|
+
if (${c === 1}) {
|
|
2905
88
|
vec4 values = vec4(getValue(batch, inIdx), 0.0, 0.0, 0.0);
|
|
2906
89
|
|
|
2907
|
-
${
|
|
2908
|
-
} else if (${
|
|
90
|
+
${i}
|
|
91
|
+
} else if (${c === 2}) {
|
|
2909
92
|
vec4 values = vec4(
|
|
2910
93
|
getValue(batch, inIdx),
|
|
2911
94
|
getValue(batch, inIdx + 1), 0.0, 0.0);
|
|
2912
95
|
|
|
2913
|
-
${
|
|
2914
|
-
} else if (${
|
|
96
|
+
${i}
|
|
97
|
+
} else if (${c === 3}) {
|
|
2915
98
|
vec4 values = vec4(
|
|
2916
99
|
getValue(batch, inIdx),
|
|
2917
100
|
getValue(batch, inIdx + 1),
|
|
2918
101
|
getValue(batch, inIdx + 2), 0.0);
|
|
2919
102
|
|
|
2920
|
-
${
|
|
103
|
+
${i}
|
|
2921
104
|
}
|
|
2922
105
|
setOutput(sumValue);
|
|
2923
106
|
}
|
|
@@ -2940,53 +123,53 @@ class Rt {
|
|
|
2940
123
|
* limitations under the License.
|
|
2941
124
|
* =============================================================================
|
|
2942
125
|
*/
|
|
2943
|
-
class
|
|
2944
|
-
constructor(
|
|
126
|
+
class j {
|
|
127
|
+
constructor(o, t) {
|
|
2945
128
|
this.variableNames = ["x"];
|
|
2946
|
-
const { windowSize:
|
|
2947
|
-
this.outputShape = [
|
|
2948
|
-
let
|
|
2949
|
-
|
|
2950
|
-
let
|
|
2951
|
-
|
|
2952
|
-
const
|
|
2953
|
-
let
|
|
2954
|
-
if (${
|
|
129
|
+
const { windowSize: e, batchSize: n, inSize: u, outSize: l } = o;
|
|
130
|
+
this.outputShape = [n, l];
|
|
131
|
+
let s = "0.0", c = "";
|
|
132
|
+
t === "prod" ? s = "1.0" : t === "min" ? (s = "1.0 / 1e-20", c = "min") : t === "max" && (s = "-1.0 / 1e-20", c = "max");
|
|
133
|
+
let i = `${t}(${t}(${t}(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])`;
|
|
134
|
+
t === "sum" ? i = "sumValue" : t === "prod" ? i = "prodValue" : t === "all" ? i = "allValue" : t === "any" && (i = "anyValue");
|
|
135
|
+
const r = Math.floor(e / 4) * 4, p = e % 4;
|
|
136
|
+
let h = `
|
|
137
|
+
if (${t === "sum"}) {
|
|
2955
138
|
sumValue += dot(values, ones);
|
|
2956
|
-
} else if (${
|
|
139
|
+
} else if (${t === "prod"}) {
|
|
2957
140
|
vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);
|
|
2958
141
|
prodValue *= tmp[0] * tmp[1];
|
|
2959
142
|
} else {
|
|
2960
|
-
minMaxValue = ${
|
|
2961
|
-
if (${
|
|
2962
|
-
minMaxValue = ${
|
|
143
|
+
minMaxValue = ${c}(values, minMaxValue);
|
|
144
|
+
if (${t === "min"} || ${t === "max"}) {
|
|
145
|
+
minMaxValue = ${c}(values, minMaxValue);
|
|
2963
146
|
bvec4 isNaN = isnan(values);
|
|
2964
147
|
if (isNaN.r || isNaN.g || isNaN.b || isNaN.a) {
|
|
2965
148
|
minMaxValue = vec4(NAN);
|
|
2966
149
|
}
|
|
2967
150
|
}
|
|
2968
151
|
}
|
|
2969
|
-
`,
|
|
2970
|
-
|
|
152
|
+
`, d = "vec4";
|
|
153
|
+
t === "all" ? (s = "1.0", h = `
|
|
2971
154
|
bool reducedAllValue = all(values);
|
|
2972
155
|
float floatedReducedAllValue = float(reducedAllValue);
|
|
2973
156
|
allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);
|
|
2974
|
-
`,
|
|
157
|
+
`, d = "bvec4") : t === "any" && (s = "0.0", h = `
|
|
2975
158
|
bool reducedAnyValue = any(values);
|
|
2976
159
|
float floatedReducedAnyValue = float(reducedAnyValue);
|
|
2977
160
|
anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);
|
|
2978
|
-
`,
|
|
2979
|
-
let
|
|
2980
|
-
|
|
2981
|
-
if (inIdx < 0 || inIdx >= ${
|
|
161
|
+
`, d = "bvec4");
|
|
162
|
+
let f = "";
|
|
163
|
+
u % e > 0 && (f = `
|
|
164
|
+
if (inIdx < 0 || inIdx >= ${u}) {
|
|
2982
165
|
return initializationValue;
|
|
2983
166
|
}
|
|
2984
167
|
`), this.userCode = `
|
|
2985
|
-
const float initializationValue = ${
|
|
168
|
+
const float initializationValue = ${s};
|
|
2986
169
|
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
|
|
2987
170
|
|
|
2988
171
|
float getValue(int batch, int inIdx) {
|
|
2989
|
-
${
|
|
172
|
+
${f}
|
|
2990
173
|
return getX(batch, inIdx);
|
|
2991
174
|
}
|
|
2992
175
|
|
|
@@ -2994,56 +177,56 @@ class zn {
|
|
|
2994
177
|
ivec2 coords = getOutputCoords();
|
|
2995
178
|
int batch = coords[0];
|
|
2996
179
|
int outIdx = coords[1];
|
|
2997
|
-
int inOffset = outIdx * ${
|
|
180
|
+
int inOffset = outIdx * ${e};
|
|
2998
181
|
|
|
2999
|
-
vec4 minMaxValue = vec4(${
|
|
182
|
+
vec4 minMaxValue = vec4(${s});
|
|
3000
183
|
float prodValue = 1.0;
|
|
3001
184
|
float sumValue = 0.0;
|
|
3002
185
|
float allValue = 1.0;
|
|
3003
186
|
float anyValue = 0.0;
|
|
3004
187
|
|
|
3005
|
-
for (int i = 0; i < ${
|
|
188
|
+
for (int i = 0; i < ${r}; i += 4) {
|
|
3006
189
|
int inIdx = inOffset + i;
|
|
3007
|
-
${
|
|
190
|
+
${d} values = ${d}(
|
|
3008
191
|
getValue(batch, inIdx),
|
|
3009
192
|
getValue(batch, inIdx + 1),
|
|
3010
193
|
getValue(batch, inIdx + 2),
|
|
3011
194
|
getValue(batch, inIdx + 3)
|
|
3012
195
|
);
|
|
3013
196
|
|
|
3014
|
-
${
|
|
197
|
+
${h}
|
|
3015
198
|
}
|
|
3016
199
|
|
|
3017
|
-
int inIdx = inOffset + ${
|
|
3018
|
-
if (${
|
|
3019
|
-
${
|
|
200
|
+
int inIdx = inOffset + ${r};
|
|
201
|
+
if (${p === 1}) {
|
|
202
|
+
${d} values = ${d}(
|
|
3020
203
|
getValue(batch, inIdx),
|
|
3021
204
|
initializationValue,
|
|
3022
205
|
initializationValue,
|
|
3023
206
|
initializationValue
|
|
3024
207
|
);
|
|
3025
208
|
|
|
3026
|
-
${
|
|
3027
|
-
} else if (${
|
|
3028
|
-
${
|
|
209
|
+
${h}
|
|
210
|
+
} else if (${p === 2}) {
|
|
211
|
+
${d} values = ${d}(
|
|
3029
212
|
getValue(batch, inIdx),
|
|
3030
213
|
getValue(batch, inIdx + 1),
|
|
3031
214
|
initializationValue,
|
|
3032
215
|
initializationValue
|
|
3033
216
|
);
|
|
3034
217
|
|
|
3035
|
-
${
|
|
3036
|
-
} else if (${
|
|
3037
|
-
${
|
|
218
|
+
${h}
|
|
219
|
+
} else if (${p === 3}) {
|
|
220
|
+
${d} values = ${d}(
|
|
3038
221
|
getValue(batch, inIdx),
|
|
3039
222
|
getValue(batch, inIdx + 1),
|
|
3040
223
|
getValue(batch, inIdx + 2),
|
|
3041
224
|
initializationValue
|
|
3042
225
|
);
|
|
3043
226
|
|
|
3044
|
-
${
|
|
227
|
+
${h}
|
|
3045
228
|
}
|
|
3046
|
-
setOutput(${
|
|
229
|
+
setOutput(${i});
|
|
3047
230
|
}
|
|
3048
231
|
`;
|
|
3049
232
|
}
|
|
@@ -3064,27 +247,27 @@ class zn {
|
|
|
3064
247
|
* limitations under the License.
|
|
3065
248
|
* =============================================================================
|
|
3066
249
|
*/
|
|
3067
|
-
function
|
|
3068
|
-
const
|
|
3069
|
-
for (;
|
|
3070
|
-
const
|
|
3071
|
-
|
|
3072
|
-
inSize:
|
|
3073
|
-
windowSize:
|
|
3074
|
-
outSize: Math.ceil(
|
|
250
|
+
function H(a) {
|
|
251
|
+
const o = [];
|
|
252
|
+
for (; o.length === 0 || o[o.length - 1].outSize !== 1; ) {
|
|
253
|
+
const t = o.length ? o[o.length - 1].outSize : a[1], e = F(t);
|
|
254
|
+
o.push({
|
|
255
|
+
inSize: t,
|
|
256
|
+
windowSize: e,
|
|
257
|
+
outSize: Math.ceil(t / e)
|
|
3075
258
|
});
|
|
3076
259
|
}
|
|
3077
|
-
return
|
|
260
|
+
return o;
|
|
3078
261
|
}
|
|
3079
|
-
function
|
|
3080
|
-
const
|
|
3081
|
-
let
|
|
3082
|
-
for (let
|
|
3083
|
-
const { inSize:
|
|
3084
|
-
let
|
|
3085
|
-
|
|
262
|
+
function N(a, o, t, e) {
|
|
263
|
+
const n = H(a.shape);
|
|
264
|
+
let u = a;
|
|
265
|
+
for (let l = 0; l < n.length; l++) {
|
|
266
|
+
const { inSize: s, windowSize: c, outSize: i } = n[l];
|
|
267
|
+
let r, p;
|
|
268
|
+
t === "mean" ? r = l === 0 ? new A({ windowSize: c, inSize: s, batchSize: a.shape[0], outSize: i }, s) : new A({ windowSize: c, inSize: s, batchSize: a.shape[0], outSize: i }) : r = new j({ windowSize: c, inSize: s, batchSize: a.shape[0], outSize: i }, t), p = u, u = e.runWebGLProgram(r, [u], o), p.dataId !== a.dataId && e.disposeIntermediateTensorInfo(p);
|
|
3086
269
|
}
|
|
3087
|
-
return
|
|
270
|
+
return u;
|
|
3088
271
|
}
|
|
3089
272
|
/**
|
|
3090
273
|
* @license
|
|
@@ -3102,9 +285,9 @@ function zt(t, e, n, o) {
|
|
|
3102
285
|
* limitations under the License.
|
|
3103
286
|
* =============================================================================
|
|
3104
287
|
*/
|
|
3105
|
-
function
|
|
3106
|
-
const
|
|
3107
|
-
return
|
|
288
|
+
function X(a, o, t, e) {
|
|
289
|
+
const n = V(o), l = V(a.shape) / n, s = b({ inputs: { x: a }, attrs: { shape: [l, n] }, backend: e }), c = N(s, a.dtype, "max", e), i = b({ inputs: { x: c }, attrs: { shape: t }, backend: e });
|
|
290
|
+
return e.disposeIntermediateTensorInfo(s), e.disposeIntermediateTensorInfo(c), i;
|
|
3108
291
|
}
|
|
3109
292
|
/**
|
|
3110
293
|
* @license
|
|
@@ -3122,30 +305,30 @@ function qn(t, e, n, o) {
|
|
|
3122
305
|
* limitations under the License.
|
|
3123
306
|
* =============================================================================
|
|
3124
307
|
*/
|
|
3125
|
-
class
|
|
3126
|
-
constructor(
|
|
308
|
+
class Y {
|
|
309
|
+
constructor(o, t) {
|
|
3127
310
|
this.variableNames = ["A"];
|
|
3128
|
-
const
|
|
3129
|
-
for (let
|
|
3130
|
-
|
|
3131
|
-
this.outputShape =
|
|
3132
|
-
const
|
|
311
|
+
const e = new Array(o.length);
|
|
312
|
+
for (let l = 0; l < e.length; l++)
|
|
313
|
+
e[l] = o[t[l]];
|
|
314
|
+
this.outputShape = e, this.rank = e.length;
|
|
315
|
+
const n = C(this.rank), u = Z(t);
|
|
3133
316
|
this.userCode = `
|
|
3134
317
|
void main() {
|
|
3135
|
-
${
|
|
3136
|
-
setOutput(getA(${
|
|
318
|
+
${n} resRC = getOutputCoords();
|
|
319
|
+
setOutput(getA(${u}));
|
|
3137
320
|
}
|
|
3138
321
|
`;
|
|
3139
322
|
}
|
|
3140
323
|
}
|
|
3141
|
-
function
|
|
3142
|
-
const
|
|
3143
|
-
if (
|
|
3144
|
-
throw Error(`Transpose for rank ${
|
|
3145
|
-
const
|
|
3146
|
-
for (let
|
|
3147
|
-
|
|
3148
|
-
return
|
|
324
|
+
function Z(a) {
|
|
325
|
+
const o = a.length;
|
|
326
|
+
if (o > 6)
|
|
327
|
+
throw Error(`Transpose for rank ${o} is not yet supported`);
|
|
328
|
+
const t = ["resRC.x", "resRC.y", "resRC.z", "resRC.w", "resRC.u", "resRC.v"], e = new Array(o);
|
|
329
|
+
for (let n = 0; n < a.length; n++)
|
|
330
|
+
e[a[n]] = t[n];
|
|
331
|
+
return e.join();
|
|
3149
332
|
}
|
|
3150
333
|
/**
|
|
3151
334
|
* @license
|
|
@@ -3163,31 +346,31 @@ function kn(t) {
|
|
|
3163
346
|
* limitations under the License.
|
|
3164
347
|
* =============================================================================
|
|
3165
348
|
*/
|
|
3166
|
-
class
|
|
3167
|
-
constructor(
|
|
349
|
+
class J {
|
|
350
|
+
constructor(o, t) {
|
|
3168
351
|
this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0;
|
|
3169
|
-
const
|
|
3170
|
-
for (let
|
|
3171
|
-
|
|
3172
|
-
if (this.outputShape =
|
|
352
|
+
const e = new Array(o.length);
|
|
353
|
+
for (let r = 0; r < e.length; r++)
|
|
354
|
+
e[r] = o[t[r]];
|
|
355
|
+
if (this.outputShape = e, this.rank = e.length, this.rank > 6)
|
|
3173
356
|
throw Error(`Packed transpose for rank ${this.rank} is not yet supported.`);
|
|
3174
|
-
const
|
|
3175
|
-
for (let
|
|
3176
|
-
|
|
3177
|
-
const
|
|
357
|
+
const n = C(this.rank), u = U("rc", this.rank), l = new Array(this.rank);
|
|
358
|
+
for (let r = 0; r < t.length; r++)
|
|
359
|
+
l[t[r]] = u[r];
|
|
360
|
+
const s = `vec2(${l.slice(-2).join()})`, c = `++${u[this.rank - 1]} < ${e[this.rank - 1]}`, i = `getChannel(getA(${l.join()}), ${s})`;
|
|
3178
361
|
this.userCode = `
|
|
3179
362
|
void main() {
|
|
3180
|
-
${
|
|
363
|
+
${n} rc = getOutputCoords();
|
|
3181
364
|
vec4 result = vec4(0.);
|
|
3182
|
-
result[0] = ${
|
|
3183
|
-
if(${
|
|
3184
|
-
result[1] = ${
|
|
365
|
+
result[0] = ${i};
|
|
366
|
+
if(${c}) {
|
|
367
|
+
result[1] = ${i};
|
|
3185
368
|
}
|
|
3186
|
-
--${
|
|
3187
|
-
if(++${
|
|
3188
|
-
result[2] = ${
|
|
3189
|
-
if(${
|
|
3190
|
-
result[3] = ${
|
|
369
|
+
--${u[this.rank - 1]};
|
|
370
|
+
if(++${u[this.rank - 2]} < ${e[this.rank - 2]}) {
|
|
371
|
+
result[2] = ${i};
|
|
372
|
+
if(${c}) {
|
|
373
|
+
result[3] = ${i};
|
|
3191
374
|
}
|
|
3192
375
|
}
|
|
3193
376
|
setOutput(result);
|
|
@@ -3211,9 +394,9 @@ class Un {
|
|
|
3211
394
|
* limitations under the License.
|
|
3212
395
|
* =============================================================================
|
|
3213
396
|
*/
|
|
3214
|
-
function
|
|
3215
|
-
const
|
|
3216
|
-
return
|
|
397
|
+
function D(a, o, t) {
|
|
398
|
+
const e = L().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new J(a.shape, o) : new Y(a.shape, o);
|
|
399
|
+
return t.runWebGLProgram(e, [a], a.dtype);
|
|
3217
400
|
}
|
|
3218
401
|
/**
|
|
3219
402
|
* @license
|
|
@@ -3231,37 +414,37 @@ function Wt(t, e, n) {
|
|
|
3231
414
|
* limitations under the License.
|
|
3232
415
|
* =============================================================================
|
|
3233
416
|
*/
|
|
3234
|
-
function
|
|
3235
|
-
const { inputs:
|
|
3236
|
-
let
|
|
3237
|
-
const
|
|
3238
|
-
let
|
|
3239
|
-
if (
|
|
3240
|
-
if (
|
|
3241
|
-
const
|
|
3242
|
-
for (let
|
|
3243
|
-
|
|
3244
|
-
const
|
|
3245
|
-
|
|
3246
|
-
const
|
|
3247
|
-
|
|
417
|
+
function Q(a) {
|
|
418
|
+
const { inputs: o, backend: t, attrs: e } = a, { x: n } = o, { reductionIndices: u, keepDims: l } = e, s = n.shape.length, c = w(u, n.shape);
|
|
419
|
+
let i = c;
|
|
420
|
+
const r = k(i, s), p = r != null, h = t.shouldExecuteOnCPU([n]);
|
|
421
|
+
let d = n;
|
|
422
|
+
if (p) {
|
|
423
|
+
if (h) {
|
|
424
|
+
const I = t.texData.get(d.dataId).values, g = new Array(s);
|
|
425
|
+
for (let $ = 0; $ < g.length; $++)
|
|
426
|
+
g[$] = n.shape[r[$]];
|
|
427
|
+
const z = B(I, n.shape, n.dtype, r, g);
|
|
428
|
+
d = t.makeTensorInfo(g, n.dtype);
|
|
429
|
+
const M = t.texData.get(d.dataId);
|
|
430
|
+
M.values = z;
|
|
3248
431
|
} else
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
}
|
|
3252
|
-
|
|
3253
|
-
const [
|
|
3254
|
-
let
|
|
3255
|
-
|
|
3256
|
-
let
|
|
3257
|
-
if (
|
|
3258
|
-
const
|
|
3259
|
-
|
|
3260
|
-
const
|
|
3261
|
-
|
|
432
|
+
d = D(n, r, t);
|
|
433
|
+
i = R(i.length, s);
|
|
434
|
+
}
|
|
435
|
+
P("max", i, s);
|
|
436
|
+
const [f, v] = y(d.shape, i);
|
|
437
|
+
let x = f;
|
|
438
|
+
l && (x = O(f, c));
|
|
439
|
+
let m;
|
|
440
|
+
if (h) {
|
|
441
|
+
const I = t.texData.get(d.dataId).values, g = G(I, V(v), x, n.dtype);
|
|
442
|
+
m = t.makeTensorInfo(x, n.dtype);
|
|
443
|
+
const z = t.texData.get(m.dataId);
|
|
444
|
+
z.values = g;
|
|
3262
445
|
} else
|
|
3263
|
-
|
|
3264
|
-
return
|
|
446
|
+
m = X(d, v, x, t);
|
|
447
|
+
return p && t.disposeIntermediateTensorInfo(d), m;
|
|
3265
448
|
}
|
|
3266
449
|
/**
|
|
3267
450
|
* @license
|
|
@@ -3279,17 +462,17 @@ function Gn(t) {
|
|
|
3279
462
|
* limitations under the License.
|
|
3280
463
|
* =============================================================================
|
|
3281
464
|
*/
|
|
3282
|
-
function
|
|
3283
|
-
const
|
|
3284
|
-
let
|
|
3285
|
-
const
|
|
3286
|
-
let
|
|
3287
|
-
|
|
3288
|
-
const [
|
|
3289
|
-
let
|
|
3290
|
-
|
|
3291
|
-
const
|
|
3292
|
-
return
|
|
465
|
+
function ee(a, o, t, e) {
|
|
466
|
+
const n = o, u = a.shape.length, l = w(n, a.shape);
|
|
467
|
+
let s = l;
|
|
468
|
+
const c = k(s, u), i = c != null;
|
|
469
|
+
let r = a;
|
|
470
|
+
i && (r = D(a, c, e), s = R(s.length, u)), P("sum", s, u);
|
|
471
|
+
const [p, h] = y(r.shape, s);
|
|
472
|
+
let d = p;
|
|
473
|
+
t && (d = O(p, l));
|
|
474
|
+
const f = V(h), x = V(a.shape) / f, m = b({ inputs: { x: r }, attrs: { shape: [x, f] }, backend: e }), S = K(a.dtype), I = N(m, S, "sum", e), g = b({ inputs: { x: I }, attrs: { shape: d }, backend: e });
|
|
475
|
+
return e.disposeIntermediateTensorInfo(m), e.disposeIntermediateTensorInfo(I), i && e.disposeIntermediateTensorInfo(r), g;
|
|
3293
476
|
}
|
|
3294
477
|
/**
|
|
3295
478
|
* @license
|
|
@@ -3307,9 +490,9 @@ function jn(t, e, n, o) {
|
|
|
3307
490
|
* limitations under the License.
|
|
3308
491
|
* =============================================================================
|
|
3309
492
|
*/
|
|
3310
|
-
function
|
|
3311
|
-
const { inputs:
|
|
3312
|
-
return
|
|
493
|
+
function te(a) {
|
|
494
|
+
const { inputs: o, backend: t, attrs: e } = a, { x: n } = o, { axis: u, keepDims: l } = e;
|
|
495
|
+
return ee(n, u, l, t);
|
|
3313
496
|
}
|
|
3314
497
|
/**
|
|
3315
498
|
* @license
|
|
@@ -3327,11 +510,11 @@ function Zn(t) {
|
|
|
3327
510
|
* limitations under the License.
|
|
3328
511
|
* =============================================================================
|
|
3329
512
|
*/
|
|
3330
|
-
const
|
|
513
|
+
const ae = `
|
|
3331
514
|
if (a == b) {
|
|
3332
515
|
return 1.0;
|
|
3333
516
|
};
|
|
3334
|
-
return a / b;`,
|
|
517
|
+
return a / b;`, se = `
|
|
3335
518
|
// vec4 one = vec4(equal(a, b));
|
|
3336
519
|
// return one + (vec4(1.0) - one) * a / b;
|
|
3337
520
|
vec4 result = a / b;
|
|
@@ -3349,13 +532,13 @@ return a / b;`, Hn = `
|
|
|
3349
532
|
}
|
|
3350
533
|
|
|
3351
534
|
return result;
|
|
3352
|
-
`,
|
|
3353
|
-
class
|
|
535
|
+
`, oe = _({ opSnippet: ae, packedOpSnippet: se, checkOutOfBounds: !0 });
|
|
536
|
+
class ne {
|
|
3354
537
|
variableNames = ["logits", "maxLogits"];
|
|
3355
538
|
outputShape;
|
|
3356
539
|
userCode;
|
|
3357
|
-
constructor(
|
|
3358
|
-
this.outputShape =
|
|
540
|
+
constructor(o) {
|
|
541
|
+
this.outputShape = o, this.userCode = `
|
|
3359
542
|
void main() {
|
|
3360
543
|
ivec4 coords = getOutputCoords(); // [batch, nh, t1, t2]
|
|
3361
544
|
int b = coords.x;
|
|
@@ -3369,7 +552,7 @@ class Xn {
|
|
|
3369
552
|
`;
|
|
3370
553
|
}
|
|
3371
554
|
}
|
|
3372
|
-
class
|
|
555
|
+
class ie {
|
|
3373
556
|
variableNames = ["exp", "sum"];
|
|
3374
557
|
outputShape;
|
|
3375
558
|
userCode;
|
|
@@ -3377,8 +560,8 @@ class Qn {
|
|
|
3377
560
|
{ name: "dropoutRate", type: "float" },
|
|
3378
561
|
{ name: "seed", type: "float" }
|
|
3379
562
|
];
|
|
3380
|
-
constructor(
|
|
3381
|
-
this.outputShape =
|
|
563
|
+
constructor(o) {
|
|
564
|
+
this.outputShape = o, this.userCode = `
|
|
3382
565
|
float random(ivec4 coords) {
|
|
3383
566
|
float x = float(coords.x * 4096 + coords.y * 256 + coords.z * 16 + coords.w);
|
|
3384
567
|
return fract(sin(seed + x) * 43758.5453123);
|
|
@@ -3396,33 +579,33 @@ class Qn {
|
|
|
3396
579
|
`;
|
|
3397
580
|
}
|
|
3398
581
|
}
|
|
3399
|
-
function
|
|
3400
|
-
const { inputs:
|
|
3401
|
-
if (!
|
|
582
|
+
function re(a) {
|
|
583
|
+
const { inputs: o, attrs: t } = a, { logits: e } = o, { dim: n, dropoutRate: u, seed: l } = t, s = a.backend;
|
|
584
|
+
if (!e)
|
|
3402
585
|
throw new Error("Error in softmax: input logits is null");
|
|
3403
|
-
const
|
|
3404
|
-
inputs: { x:
|
|
3405
|
-
backend:
|
|
3406
|
-
attrs: { reductionIndices:
|
|
3407
|
-
}),
|
|
3408
|
-
|
|
3409
|
-
const
|
|
3410
|
-
if (
|
|
3411
|
-
const
|
|
3412
|
-
[
|
|
3413
|
-
[
|
|
586
|
+
const c = w([n], e.shape), i = Q({
|
|
587
|
+
inputs: { x: e },
|
|
588
|
+
backend: s,
|
|
589
|
+
attrs: { reductionIndices: c, keepDims: !1 }
|
|
590
|
+
}), r = O(i.shape, c), p = new ne(e.shape), h = s.runWebGLProgram(p, [e, i], "float32");
|
|
591
|
+
s.disposeIntermediateTensorInfo(i);
|
|
592
|
+
const d = te({ inputs: { x: h }, backend: s, attrs: { axis: c, keepDims: !1 } }), f = b({ inputs: { x: d }, backend: s, attrs: { shape: r } });
|
|
593
|
+
if (u !== void 0 && u > 0) {
|
|
594
|
+
const x = new ie(e.shape), m = s.runWebGLProgram(x, [h, f], "float32", [
|
|
595
|
+
[u],
|
|
596
|
+
[l ?? Math.random() * 1e4]
|
|
3414
597
|
]);
|
|
3415
|
-
return
|
|
598
|
+
return s.disposeIntermediateTensorInfo(h), s.disposeIntermediateTensorInfo(d), s.disposeIntermediateTensorInfo(f), m;
|
|
3416
599
|
}
|
|
3417
|
-
const v =
|
|
3418
|
-
return
|
|
600
|
+
const v = oe({ inputs: { a: h, b: f }, backend: s });
|
|
601
|
+
return s.disposeIntermediateTensorInfo(h), s.disposeIntermediateTensorInfo(d), s.disposeIntermediateTensorInfo(f), v;
|
|
3419
602
|
}
|
|
3420
|
-
const
|
|
603
|
+
const ue = {
|
|
3421
604
|
kernelName: "FusedSoftmax",
|
|
3422
605
|
backendName: "webgl",
|
|
3423
|
-
kernelFunc:
|
|
606
|
+
kernelFunc: re
|
|
3424
607
|
};
|
|
3425
|
-
|
|
608
|
+
W(ue);
|
|
3426
609
|
export {
|
|
3427
|
-
|
|
610
|
+
re as softmax
|
|
3428
611
|
};
|