@genai-fi/nanogpt 0.5.6 → 0.6.0

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