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