@genai-fi/nanogpt 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Generator.js +7 -7
- package/dist/NanoGPTModel.js +70 -121
- package/dist/RealDiv-BYViZwhN.js +540 -0
- package/dist/Reshape-t7Kcikjk.js +127 -0
- package/dist/TeachableLLM.d.ts +2 -0
- package/dist/TeachableLLM.js +34 -27
- package/dist/{TiedEmbedding-BhxWO8QR.js → TiedEmbedding-9WeDwvjO.js} +12 -13
- package/dist/{axis_util-D17qZRQm.js → axis_util-Bu4h7XWV.js} +14 -12
- package/dist/{broadcast_to-BMQLjvt_.js → broadcast_to-DARN-DBD.js} +2 -2
- package/dist/{concat-DhZfF1GY.js → concat-5aPGqw3Z.js} +3 -3
- package/dist/{dataset-oilnemHf.js → dataset-pgqp-YfL.js} +3 -3
- package/dist/{dropout-CrMQPCeG.js → dropout-Bciw46HT.js} +7 -7
- package/dist/{gather-DZCMHZuN.js → gather-DjyCjmOD.js} +1 -1
- package/dist/gpgpu_math-CNslybmD.js +3115 -0
- package/dist/{index-bMBtI-WR.js → index-BAzbokzv.js} +846 -649
- package/dist/{kernel_funcs_utils-CNmjLWnB.js → kernel_funcs_utils-CUxJCg0g.js} +232 -138
- package/dist/layers/BaseLayer.js +2 -2
- package/dist/layers/CausalSelfAttention.js +6 -6
- package/dist/layers/MLP.js +5 -5
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +13 -33
- package/dist/layers/TiedEmbedding.js +6 -7
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/loader/load.d.ts +13 -0
- package/dist/loader/load.js +27 -0
- package/dist/loader/loadHF.d.ts +7 -0
- package/dist/loader/loadHF.js +22 -0
- package/dist/{utilities/load.d.ts → loader/loadTransformers.d.ts} +11 -11
- package/dist/loader/loadTransformers.js +28 -0
- package/dist/loader/newZipLoad.d.ts +8 -0
- package/dist/loader/newZipLoad.js +21 -0
- package/dist/loader/oldZipLoad.d.ts +7 -0
- package/dist/loader/oldZipLoad.js +76 -0
- package/dist/{log_sum_exp-BHdkCb4s.js → log_sum_exp-YEo2h3gb.js} +14 -14
- package/dist/main.js +23 -20
- package/dist/{mat_mul-BsrLfy81.js → mat_mul-7121rsJk.js} +1 -1
- package/dist/{max-DechV4Bc.js → max-DtlIuVeW.js} +1 -1
- package/dist/mulmat_packed_gpu-D4nKF7Je.js +71 -0
- package/dist/{norm-B9hWHZH1.js → norm-CzltS9Fz.js} +16 -16
- package/dist/{ones-g0K8jVwm.js → ones-BBlSRqn1.js} +2 -2
- package/dist/ops/appendCache.js +3 -3
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/appendCache.js +2 -2
- package/dist/ops/cpu/attentionMask.js +6 -6
- package/dist/ops/cpu/fusedSoftmax.js +2 -2
- package/dist/ops/cpu/gatherSub.js +9 -9
- package/dist/ops/cpu/gelu.js +1 -1
- package/dist/ops/cpu/matMulGelu.js +1 -1
- package/dist/ops/cpu/matMulMul.js +1 -1
- package/dist/ops/cpu/mulDropout.js +1 -1
- package/dist/ops/cpu/normRMS.js +1 -1
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +17 -48
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +1 -1
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.js +4 -4
- package/dist/ops/grads/gelu.js +1 -1
- package/dist/ops/grads/matMulGelu.js +1 -1
- package/dist/ops/grads/normRMS.js +1 -1
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +1 -1
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/matMulMul.js +1 -1
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/normRMS.js +1 -1
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/rope.js +8 -4
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +29 -560
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.js +3 -3
- package/dist/ops/webgl/matMulGelu.js +46 -113
- package/dist/ops/webgl/matMulMul.js +1 -1
- package/dist/ops/webgl/mulDropout.js +1 -1
- package/dist/ops/webgl/normRMS.js +2 -2
- package/dist/ops/webgl/qkv.js +1 -1
- package/dist/ops/webgl/rope.js +1 -1
- package/dist/ops/webgl/scatterSub.js +1 -1
- package/dist/{ops-Mv7Ta72x.js → ops-C0sQEcPw.js} +117 -109
- package/dist/{random_width-BBAWzDym.js → random_width-DWzaOgrn.js} +6925 -6291
- package/dist/{range-DMaG9A3G.js → range-DYsrnfiy.js} +1 -1
- package/dist/{gpgpu_math-Ctc31slO.js → reciprocal-CJQeasVa.js} +7 -5
- package/dist/register_all_kernels-BfFCQAqs.js +21397 -0
- package/dist/{reshape-T4yDEqoF.js → reshape-krWGKraP.js} +1 -1
- package/dist/scatter_nd_util-93ln7Hut.js +46 -0
- package/dist/selu_util-sntGesxr.js +740 -0
- package/dist/{shared-XNAoXhOa.js → shared-Ca6iDobD.js} +1462 -1089
- package/dist/{sin-EEhbrRO_.js → sin-D_h-qCSx.js} +1 -1
- package/dist/{softmax-B2_IKPDR.js → softmax-fsdtf6JC.js} +1 -1
- package/dist/{split-dcks18H1.js → split-eiktj-6L.js} +1 -1
- package/dist/{stack-lpJ5kYvE.js → stack-dfEEz2OY.js} +2 -2
- package/dist/{sum-CutF5lj2.js → sum-BE_Irnim.js} +1 -1
- package/dist/{tensor-C15NA2LA.js → tensor-Xyi595sG.js} +1 -1
- package/dist/{tensor2d-DZ_e5eKM.js → tensor2d-CPEkynbH.js} +1 -1
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +2 -2
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +3 -3
- package/dist/training/sparseCrossEntropy.js +5 -5
- package/dist/utilities/dummy.d.ts +6 -0
- package/dist/utilities/dummy.js +31 -10
- package/dist/utilities/generate.js +3 -3
- package/dist/utilities/profile.d.ts +5 -0
- package/dist/utilities/profile.js +10 -7
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/save.js +1 -1
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-CdRKKp8x.js → variable-wSS22xj5.js} +1 -1
- package/dist/{zeros-CAbHfODe.js → zeros-YJDE7oRb.js} +4 -4
- package/package.json +2 -8
- package/dist/Reshape-CLOrdpve.js +0 -212
- package/dist/slice_util-Ddk0uxGJ.js +0 -49
- package/dist/tfjs_backend-BDb8r9qx.js +0 -1010
- package/dist/utilities/load.js +0 -99
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { c as
|
|
4
|
-
import { b as
|
|
5
|
-
import { r as
|
|
6
|
-
import {
|
|
7
|
-
import { g as
|
|
8
|
-
function
|
|
1
|
+
import { i as qt, bc as _e, g as A, h as Ut, W as K, bd as et, aH as ht, be as gt, bf as at, _ as Ve, $ as st, ak as De, a$ as We, bg as $e, bh as ze, bi as Be, bj as Mt, ah as H, bk as Ot, bl as D, bm as Lt, bn as At, a8 as _t, bo as Vt, ag as Dt, bp as Wt, aT as $t, aU as zt, aW as Bt, aX as Gt, a9 as jt, bq as Zt, a_ as Ht, br as Kt, aY as Ge, am as je, bs as Xt, b2 as Ze, bt as He, p as Yt, u as Ke, t as Xe, bu as Jt, bv as wt, ap as Qt, aO as Ye, bw as te, bx as ee, by as ne, aG as pt, bz as se, bA as ot } from "./index-BAzbokzv.js";
|
|
2
|
+
import { h as it, m as kt, k as Je, l as Qe, R as tn, v as en, n as nn, o as sn, p as on, q as rn, r as an, s as ln, t as cn, w as un, x as hn, y as fn, z as Nt, A as gn, B as dn, C as mn } from "./gpgpu_math-CNslybmD.js";
|
|
3
|
+
import { g as pn, a as In, e as wn, c as bn } from "./axis_util-Bu4h7XWV.js";
|
|
4
|
+
import { b as xn } from "./broadcast_to-DARN-DBD.js";
|
|
5
|
+
import { r as En } from "./reshape-krWGKraP.js";
|
|
6
|
+
import { p as Fn, q as yn, r as kn, u as Nn } from "./selu_util-sntGesxr.js";
|
|
7
|
+
import { g as Sn } from "./_commonjsHelpers-ByX85dGu.js";
|
|
8
|
+
function vn(e, t) {
|
|
9
9
|
for (var n = 0; n < t.length; n++) {
|
|
10
|
-
const
|
|
11
|
-
if (typeof
|
|
12
|
-
for (const o in
|
|
10
|
+
const s = t[n];
|
|
11
|
+
if (typeof s != "string" && !Array.isArray(s)) {
|
|
12
|
+
for (const o in s)
|
|
13
13
|
if (o !== "default" && !(o in e)) {
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const a = Object.getOwnPropertyDescriptor(s, o);
|
|
15
|
+
a && Object.defineProperty(e, o, a.get ? a : {
|
|
16
16
|
enumerable: !0,
|
|
17
|
-
get: () =>
|
|
17
|
+
get: () => s[o]
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
return Object.freeze(Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }));
|
|
23
23
|
}
|
|
24
|
-
var
|
|
25
|
-
function
|
|
26
|
-
if (
|
|
27
|
-
|
|
24
|
+
var It, St;
|
|
25
|
+
function Tn() {
|
|
26
|
+
if (St) return It;
|
|
27
|
+
St = 1, It = t;
|
|
28
28
|
var e = null;
|
|
29
29
|
try {
|
|
30
30
|
e = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
|
|
@@ -317,327 +317,327 @@ function Zt() {
|
|
|
317
317
|
])), {}).exports;
|
|
318
318
|
} catch {
|
|
319
319
|
}
|
|
320
|
-
function t(w,
|
|
321
|
-
this.low = w | 0, this.high =
|
|
320
|
+
function t(w, c, E) {
|
|
321
|
+
this.low = w | 0, this.high = c | 0, this.unsigned = !!E;
|
|
322
322
|
}
|
|
323
323
|
t.prototype.__isLong__, Object.defineProperty(t.prototype, "__isLong__", { value: !0 });
|
|
324
324
|
function n(w) {
|
|
325
325
|
return (w && w.__isLong__) === !0;
|
|
326
326
|
}
|
|
327
327
|
t.isLong = n;
|
|
328
|
-
var
|
|
329
|
-
function
|
|
330
|
-
var
|
|
331
|
-
return
|
|
328
|
+
var s = {}, o = {};
|
|
329
|
+
function a(w, c) {
|
|
330
|
+
var E, N, q;
|
|
331
|
+
return c ? (w >>>= 0, (q = 0 <= w && w < 256) && (N = o[w], N) ? N : (E = i(w, (w | 0) < 0 ? -1 : 0, !0), q && (o[w] = E), E)) : (w |= 0, (q = -128 <= w && w < 128) && (N = s[w], N) ? N : (E = i(w, w < 0 ? -1 : 0, !1), q && (s[w] = E), E));
|
|
332
332
|
}
|
|
333
|
-
t.fromInt =
|
|
334
|
-
function
|
|
333
|
+
t.fromInt = a;
|
|
334
|
+
function r(w, c) {
|
|
335
335
|
if (isNaN(w))
|
|
336
|
-
return
|
|
337
|
-
if (
|
|
336
|
+
return c ? b : d;
|
|
337
|
+
if (c) {
|
|
338
338
|
if (w < 0)
|
|
339
|
-
return
|
|
339
|
+
return b;
|
|
340
340
|
if (w >= m)
|
|
341
|
-
return
|
|
341
|
+
return C;
|
|
342
342
|
} else {
|
|
343
|
-
if (w <= -
|
|
344
|
-
return
|
|
345
|
-
if (w + 1 >=
|
|
346
|
-
return
|
|
343
|
+
if (w <= -F)
|
|
344
|
+
return v;
|
|
345
|
+
if (w + 1 >= F)
|
|
346
|
+
return P;
|
|
347
347
|
}
|
|
348
|
-
return w < 0 ?
|
|
348
|
+
return w < 0 ? r(-w, c).neg() : i(w % I | 0, w / I | 0, c);
|
|
349
349
|
}
|
|
350
|
-
t.fromNumber =
|
|
351
|
-
function
|
|
352
|
-
return new t(w,
|
|
350
|
+
t.fromNumber = r;
|
|
351
|
+
function i(w, c, E) {
|
|
352
|
+
return new t(w, c, E);
|
|
353
353
|
}
|
|
354
|
-
t.fromBits =
|
|
355
|
-
var
|
|
356
|
-
function
|
|
354
|
+
t.fromBits = i;
|
|
355
|
+
var l = Math.pow;
|
|
356
|
+
function u(w, c, E) {
|
|
357
357
|
if (w.length === 0)
|
|
358
358
|
throw Error("empty string");
|
|
359
359
|
if (w === "NaN" || w === "Infinity" || w === "+Infinity" || w === "-Infinity")
|
|
360
360
|
return d;
|
|
361
|
-
if (typeof
|
|
361
|
+
if (typeof c == "number" ? (E = c, c = !1) : c = !!c, E = E || 10, E < 2 || 36 < E)
|
|
362
362
|
throw RangeError("radix");
|
|
363
|
-
var
|
|
364
|
-
if ((
|
|
363
|
+
var N;
|
|
364
|
+
if ((N = w.indexOf("-")) > 0)
|
|
365
365
|
throw Error("interior hyphen");
|
|
366
|
-
if (
|
|
367
|
-
return
|
|
368
|
-
for (var
|
|
369
|
-
var
|
|
370
|
-
if (
|
|
371
|
-
var
|
|
372
|
-
|
|
366
|
+
if (N === 0)
|
|
367
|
+
return u(w.substring(1), c, E).neg();
|
|
368
|
+
for (var q = r(l(E, 8)), R = d, M = 0; M < w.length; M += 8) {
|
|
369
|
+
var $ = Math.min(8, w.length - M), G = parseInt(w.substring(M, M + $), E);
|
|
370
|
+
if ($ < 8) {
|
|
371
|
+
var _ = r(l(E, $));
|
|
372
|
+
R = R.mul(_).add(r(G));
|
|
373
373
|
} else
|
|
374
|
-
|
|
374
|
+
R = R.mul(q), R = R.add(r(G));
|
|
375
375
|
}
|
|
376
|
-
return
|
|
376
|
+
return R.unsigned = c, R;
|
|
377
377
|
}
|
|
378
|
-
t.fromString =
|
|
379
|
-
function
|
|
380
|
-
return typeof w == "number" ?
|
|
378
|
+
t.fromString = u;
|
|
379
|
+
function h(w, c) {
|
|
380
|
+
return typeof w == "number" ? r(w, c) : typeof w == "string" ? u(w, c) : i(w.low, w.high, typeof c == "boolean" ? c : w.unsigned);
|
|
381
381
|
}
|
|
382
|
-
t.fromValue =
|
|
383
|
-
var f = 65536, p = 1 << 24, I = f * f, m = I * I,
|
|
382
|
+
t.fromValue = h;
|
|
383
|
+
var f = 65536, p = 1 << 24, I = f * f, m = I * I, F = m / 2, g = a(p), d = a(0);
|
|
384
384
|
t.ZERO = d;
|
|
385
|
-
var
|
|
386
|
-
t.UZERO =
|
|
387
|
-
var
|
|
388
|
-
t.ONE =
|
|
389
|
-
var
|
|
390
|
-
t.UONE =
|
|
391
|
-
var
|
|
392
|
-
t.NEG_ONE =
|
|
393
|
-
var
|
|
394
|
-
t.MAX_VALUE =
|
|
395
|
-
var
|
|
396
|
-
t.MAX_UNSIGNED_VALUE =
|
|
397
|
-
var
|
|
398
|
-
t.MIN_VALUE =
|
|
399
|
-
var
|
|
400
|
-
return
|
|
385
|
+
var b = a(0, !0);
|
|
386
|
+
t.UZERO = b;
|
|
387
|
+
var k = a(1);
|
|
388
|
+
t.ONE = k;
|
|
389
|
+
var y = a(1, !0);
|
|
390
|
+
t.UONE = y;
|
|
391
|
+
var S = a(-1);
|
|
392
|
+
t.NEG_ONE = S;
|
|
393
|
+
var P = i(-1, 2147483647, !1);
|
|
394
|
+
t.MAX_VALUE = P;
|
|
395
|
+
var C = i(-1, -1, !0);
|
|
396
|
+
t.MAX_UNSIGNED_VALUE = C;
|
|
397
|
+
var v = i(0, -2147483648, !1);
|
|
398
|
+
t.MIN_VALUE = v;
|
|
399
|
+
var x = t.prototype;
|
|
400
|
+
return x.toInt = function() {
|
|
401
401
|
return this.unsigned ? this.low >>> 0 : this.low;
|
|
402
|
-
},
|
|
402
|
+
}, x.toNumber = function() {
|
|
403
403
|
return this.unsigned ? (this.high >>> 0) * I + (this.low >>> 0) : this.high * I + (this.low >>> 0);
|
|
404
|
-
},
|
|
405
|
-
if (
|
|
404
|
+
}, x.toString = function(c) {
|
|
405
|
+
if (c = c || 10, c < 2 || 36 < c)
|
|
406
406
|
throw RangeError("radix");
|
|
407
407
|
if (this.isZero())
|
|
408
408
|
return "0";
|
|
409
409
|
if (this.isNegative())
|
|
410
|
-
if (this.eq(
|
|
411
|
-
var
|
|
412
|
-
return
|
|
410
|
+
if (this.eq(v)) {
|
|
411
|
+
var E = r(c), N = this.div(E), q = N.mul(E).sub(this);
|
|
412
|
+
return N.toString(c) + q.toInt().toString(c);
|
|
413
413
|
} else
|
|
414
|
-
return "-" + this.neg().toString(
|
|
415
|
-
for (var
|
|
416
|
-
var
|
|
417
|
-
if (M =
|
|
418
|
-
return
|
|
419
|
-
for (;
|
|
420
|
-
|
|
421
|
-
|
|
414
|
+
return "-" + this.neg().toString(c);
|
|
415
|
+
for (var R = r(l(c, 6), this.unsigned), M = this, $ = ""; ; ) {
|
|
416
|
+
var G = M.div(R), _ = M.sub(G.mul(R)).toInt() >>> 0, U = _.toString(c);
|
|
417
|
+
if (M = G, M.isZero())
|
|
418
|
+
return U + $;
|
|
419
|
+
for (; U.length < 6; )
|
|
420
|
+
U = "0" + U;
|
|
421
|
+
$ = "" + U + $;
|
|
422
422
|
}
|
|
423
|
-
},
|
|
423
|
+
}, x.getHighBits = function() {
|
|
424
424
|
return this.high;
|
|
425
|
-
},
|
|
425
|
+
}, x.getHighBitsUnsigned = function() {
|
|
426
426
|
return this.high >>> 0;
|
|
427
|
-
},
|
|
427
|
+
}, x.getLowBits = function() {
|
|
428
428
|
return this.low;
|
|
429
|
-
},
|
|
429
|
+
}, x.getLowBitsUnsigned = function() {
|
|
430
430
|
return this.low >>> 0;
|
|
431
|
-
},
|
|
431
|
+
}, x.getNumBitsAbs = function() {
|
|
432
432
|
if (this.isNegative())
|
|
433
|
-
return this.eq(
|
|
434
|
-
for (var
|
|
433
|
+
return this.eq(v) ? 64 : this.neg().getNumBitsAbs();
|
|
434
|
+
for (var c = this.high != 0 ? this.high : this.low, E = 31; E > 0 && (c & 1 << E) == 0; E--)
|
|
435
435
|
;
|
|
436
|
-
return this.high != 0 ?
|
|
437
|
-
},
|
|
436
|
+
return this.high != 0 ? E + 33 : E + 1;
|
|
437
|
+
}, x.isZero = function() {
|
|
438
438
|
return this.high === 0 && this.low === 0;
|
|
439
|
-
},
|
|
439
|
+
}, x.eqz = x.isZero, x.isNegative = function() {
|
|
440
440
|
return !this.unsigned && this.high < 0;
|
|
441
|
-
},
|
|
441
|
+
}, x.isPositive = function() {
|
|
442
442
|
return this.unsigned || this.high >= 0;
|
|
443
|
-
},
|
|
443
|
+
}, x.isOdd = function() {
|
|
444
444
|
return (this.low & 1) === 1;
|
|
445
|
-
},
|
|
445
|
+
}, x.isEven = function() {
|
|
446
446
|
return (this.low & 1) === 0;
|
|
447
|
-
},
|
|
448
|
-
return n(
|
|
449
|
-
},
|
|
447
|
+
}, x.equals = function(c) {
|
|
448
|
+
return n(c) || (c = h(c)), this.unsigned !== c.unsigned && this.high >>> 31 === 1 && c.high >>> 31 === 1 ? !1 : this.high === c.high && this.low === c.low;
|
|
449
|
+
}, x.eq = x.equals, x.notEquals = function(c) {
|
|
450
450
|
return !this.eq(
|
|
451
451
|
/* validates */
|
|
452
|
-
|
|
452
|
+
c
|
|
453
453
|
);
|
|
454
|
-
},
|
|
454
|
+
}, x.neq = x.notEquals, x.ne = x.notEquals, x.lessThan = function(c) {
|
|
455
455
|
return this.comp(
|
|
456
456
|
/* validates */
|
|
457
|
-
|
|
457
|
+
c
|
|
458
458
|
) < 0;
|
|
459
|
-
},
|
|
459
|
+
}, x.lt = x.lessThan, x.lessThanOrEqual = function(c) {
|
|
460
460
|
return this.comp(
|
|
461
461
|
/* validates */
|
|
462
|
-
|
|
462
|
+
c
|
|
463
463
|
) <= 0;
|
|
464
|
-
},
|
|
464
|
+
}, x.lte = x.lessThanOrEqual, x.le = x.lessThanOrEqual, x.greaterThan = function(c) {
|
|
465
465
|
return this.comp(
|
|
466
466
|
/* validates */
|
|
467
|
-
|
|
467
|
+
c
|
|
468
468
|
) > 0;
|
|
469
|
-
},
|
|
469
|
+
}, x.gt = x.greaterThan, x.greaterThanOrEqual = function(c) {
|
|
470
470
|
return this.comp(
|
|
471
471
|
/* validates */
|
|
472
|
-
|
|
472
|
+
c
|
|
473
473
|
) >= 0;
|
|
474
|
-
},
|
|
475
|
-
if (n(
|
|
474
|
+
}, x.gte = x.greaterThanOrEqual, x.ge = x.greaterThanOrEqual, x.compare = function(c) {
|
|
475
|
+
if (n(c) || (c = h(c)), this.eq(c))
|
|
476
476
|
return 0;
|
|
477
|
-
var
|
|
478
|
-
return
|
|
479
|
-
},
|
|
480
|
-
return !this.unsigned && this.eq(
|
|
481
|
-
},
|
|
482
|
-
n(
|
|
483
|
-
var
|
|
484
|
-
return
|
|
485
|
-
},
|
|
486
|
-
return n(
|
|
487
|
-
},
|
|
477
|
+
var E = this.isNegative(), N = c.isNegative();
|
|
478
|
+
return E && !N ? -1 : !E && N ? 1 : this.unsigned ? c.high >>> 0 > this.high >>> 0 || c.high === this.high && c.low >>> 0 > this.low >>> 0 ? -1 : 1 : this.sub(c).isNegative() ? -1 : 1;
|
|
479
|
+
}, x.comp = x.compare, x.negate = function() {
|
|
480
|
+
return !this.unsigned && this.eq(v) ? v : this.not().add(k);
|
|
481
|
+
}, x.neg = x.negate, x.add = function(c) {
|
|
482
|
+
n(c) || (c = h(c));
|
|
483
|
+
var E = this.high >>> 16, N = this.high & 65535, q = this.low >>> 16, R = this.low & 65535, M = c.high >>> 16, $ = c.high & 65535, G = c.low >>> 16, _ = c.low & 65535, U = 0, j = 0, L = 0, B = 0;
|
|
484
|
+
return B += R + _, L += B >>> 16, B &= 65535, L += q + G, j += L >>> 16, L &= 65535, j += N + $, U += j >>> 16, j &= 65535, U += E + M, U &= 65535, i(L << 16 | B, U << 16 | j, this.unsigned);
|
|
485
|
+
}, x.subtract = function(c) {
|
|
486
|
+
return n(c) || (c = h(c)), this.add(c.neg());
|
|
487
|
+
}, x.sub = x.subtract, x.multiply = function(c) {
|
|
488
488
|
if (this.isZero())
|
|
489
489
|
return d;
|
|
490
|
-
if (n(
|
|
491
|
-
var
|
|
490
|
+
if (n(c) || (c = h(c)), e) {
|
|
491
|
+
var E = e.mul(
|
|
492
492
|
this.low,
|
|
493
493
|
this.high,
|
|
494
|
-
|
|
495
|
-
|
|
494
|
+
c.low,
|
|
495
|
+
c.high
|
|
496
496
|
);
|
|
497
|
-
return
|
|
497
|
+
return i(E, e.get_high(), this.unsigned);
|
|
498
498
|
}
|
|
499
|
-
if (
|
|
499
|
+
if (c.isZero())
|
|
500
500
|
return d;
|
|
501
|
-
if (this.eq(
|
|
502
|
-
return
|
|
503
|
-
if (
|
|
504
|
-
return this.isOdd() ?
|
|
501
|
+
if (this.eq(v))
|
|
502
|
+
return c.isOdd() ? v : d;
|
|
503
|
+
if (c.eq(v))
|
|
504
|
+
return this.isOdd() ? v : d;
|
|
505
505
|
if (this.isNegative())
|
|
506
|
-
return
|
|
507
|
-
if (
|
|
508
|
-
return this.mul(
|
|
509
|
-
if (this.lt(g) &&
|
|
510
|
-
return
|
|
511
|
-
var
|
|
512
|
-
return
|
|
513
|
-
},
|
|
514
|
-
if (n(
|
|
506
|
+
return c.isNegative() ? this.neg().mul(c.neg()) : this.neg().mul(c).neg();
|
|
507
|
+
if (c.isNegative())
|
|
508
|
+
return this.mul(c.neg()).neg();
|
|
509
|
+
if (this.lt(g) && c.lt(g))
|
|
510
|
+
return r(this.toNumber() * c.toNumber(), this.unsigned);
|
|
511
|
+
var N = this.high >>> 16, q = this.high & 65535, R = this.low >>> 16, M = this.low & 65535, $ = c.high >>> 16, G = c.high & 65535, _ = c.low >>> 16, U = c.low & 65535, j = 0, L = 0, B = 0, ct = 0;
|
|
512
|
+
return ct += M * U, B += ct >>> 16, ct &= 65535, B += R * U, L += B >>> 16, B &= 65535, B += M * _, L += B >>> 16, B &= 65535, L += q * U, j += L >>> 16, L &= 65535, L += R * _, j += L >>> 16, L &= 65535, L += M * G, j += L >>> 16, L &= 65535, j += N * U + q * _ + R * G + M * $, j &= 65535, i(B << 16 | ct, j << 16 | L, this.unsigned);
|
|
513
|
+
}, x.mul = x.multiply, x.divide = function(c) {
|
|
514
|
+
if (n(c) || (c = h(c)), c.isZero())
|
|
515
515
|
throw Error("division by zero");
|
|
516
516
|
if (e) {
|
|
517
|
-
if (!this.unsigned && this.high === -2147483648 &&
|
|
517
|
+
if (!this.unsigned && this.high === -2147483648 && c.low === -1 && c.high === -1)
|
|
518
518
|
return this;
|
|
519
|
-
var
|
|
519
|
+
var E = (this.unsigned ? e.div_u : e.div_s)(
|
|
520
520
|
this.low,
|
|
521
521
|
this.high,
|
|
522
|
-
|
|
523
|
-
|
|
522
|
+
c.low,
|
|
523
|
+
c.high
|
|
524
524
|
);
|
|
525
|
-
return
|
|
525
|
+
return i(E, e.get_high(), this.unsigned);
|
|
526
526
|
}
|
|
527
527
|
if (this.isZero())
|
|
528
|
-
return this.unsigned ?
|
|
529
|
-
var
|
|
528
|
+
return this.unsigned ? b : d;
|
|
529
|
+
var N, q, R;
|
|
530
530
|
if (this.unsigned) {
|
|
531
|
-
if (
|
|
532
|
-
return
|
|
533
|
-
if (
|
|
534
|
-
return
|
|
535
|
-
|
|
531
|
+
if (c.unsigned || (c = c.toUnsigned()), c.gt(this))
|
|
532
|
+
return b;
|
|
533
|
+
if (c.gt(this.shru(1)))
|
|
534
|
+
return y;
|
|
535
|
+
R = b;
|
|
536
536
|
} else {
|
|
537
|
-
if (this.eq(
|
|
538
|
-
if (
|
|
539
|
-
return
|
|
540
|
-
if (
|
|
541
|
-
return
|
|
537
|
+
if (this.eq(v)) {
|
|
538
|
+
if (c.eq(k) || c.eq(S))
|
|
539
|
+
return v;
|
|
540
|
+
if (c.eq(v))
|
|
541
|
+
return k;
|
|
542
542
|
var M = this.shr(1);
|
|
543
|
-
return
|
|
544
|
-
} else if (
|
|
545
|
-
return this.unsigned ?
|
|
543
|
+
return N = M.div(c).shl(1), N.eq(d) ? c.isNegative() ? k : S : (q = this.sub(c.mul(N)), R = N.add(q.div(c)), R);
|
|
544
|
+
} else if (c.eq(v))
|
|
545
|
+
return this.unsigned ? b : d;
|
|
546
546
|
if (this.isNegative())
|
|
547
|
-
return
|
|
548
|
-
if (
|
|
549
|
-
return this.div(
|
|
550
|
-
|
|
547
|
+
return c.isNegative() ? this.neg().div(c.neg()) : this.neg().div(c).neg();
|
|
548
|
+
if (c.isNegative())
|
|
549
|
+
return this.div(c.neg()).neg();
|
|
550
|
+
R = d;
|
|
551
551
|
}
|
|
552
|
-
for (
|
|
553
|
-
|
|
554
|
-
for (var
|
|
555
|
-
|
|
556
|
-
|
|
552
|
+
for (q = this; q.gte(c); ) {
|
|
553
|
+
N = Math.max(1, Math.floor(q.toNumber() / c.toNumber()));
|
|
554
|
+
for (var $ = Math.ceil(Math.log(N) / Math.LN2), G = $ <= 48 ? 1 : l(2, $ - 48), _ = r(N), U = _.mul(c); U.isNegative() || U.gt(q); )
|
|
555
|
+
N -= G, _ = r(N, this.unsigned), U = _.mul(c);
|
|
556
|
+
_.isZero() && (_ = k), R = R.add(_), q = q.sub(U);
|
|
557
557
|
}
|
|
558
|
-
return
|
|
559
|
-
},
|
|
560
|
-
if (n(
|
|
561
|
-
var
|
|
558
|
+
return R;
|
|
559
|
+
}, x.div = x.divide, x.modulo = function(c) {
|
|
560
|
+
if (n(c) || (c = h(c)), e) {
|
|
561
|
+
var E = (this.unsigned ? e.rem_u : e.rem_s)(
|
|
562
562
|
this.low,
|
|
563
563
|
this.high,
|
|
564
|
-
|
|
565
|
-
|
|
564
|
+
c.low,
|
|
565
|
+
c.high
|
|
566
566
|
);
|
|
567
|
-
return
|
|
567
|
+
return i(E, e.get_high(), this.unsigned);
|
|
568
568
|
}
|
|
569
|
-
return this.sub(this.div(
|
|
570
|
-
},
|
|
571
|
-
return
|
|
572
|
-
},
|
|
573
|
-
return n(
|
|
574
|
-
},
|
|
575
|
-
return n(
|
|
576
|
-
},
|
|
577
|
-
return n(
|
|
578
|
-
},
|
|
579
|
-
return n(
|
|
580
|
-
},
|
|
581
|
-
return n(
|
|
582
|
-
},
|
|
583
|
-
if (n(
|
|
569
|
+
return this.sub(this.div(c).mul(c));
|
|
570
|
+
}, x.mod = x.modulo, x.rem = x.modulo, x.not = function() {
|
|
571
|
+
return i(~this.low, ~this.high, this.unsigned);
|
|
572
|
+
}, x.and = function(c) {
|
|
573
|
+
return n(c) || (c = h(c)), i(this.low & c.low, this.high & c.high, this.unsigned);
|
|
574
|
+
}, x.or = function(c) {
|
|
575
|
+
return n(c) || (c = h(c)), i(this.low | c.low, this.high | c.high, this.unsigned);
|
|
576
|
+
}, x.xor = function(c) {
|
|
577
|
+
return n(c) || (c = h(c)), i(this.low ^ c.low, this.high ^ c.high, this.unsigned);
|
|
578
|
+
}, x.shiftLeft = function(c) {
|
|
579
|
+
return n(c) && (c = c.toInt()), (c &= 63) === 0 ? this : c < 32 ? i(this.low << c, this.high << c | this.low >>> 32 - c, this.unsigned) : i(0, this.low << c - 32, this.unsigned);
|
|
580
|
+
}, x.shl = x.shiftLeft, x.shiftRight = function(c) {
|
|
581
|
+
return n(c) && (c = c.toInt()), (c &= 63) === 0 ? this : c < 32 ? i(this.low >>> c | this.high << 32 - c, this.high >> c, this.unsigned) : i(this.high >> c - 32, this.high >= 0 ? 0 : -1, this.unsigned);
|
|
582
|
+
}, x.shr = x.shiftRight, x.shiftRightUnsigned = function(c) {
|
|
583
|
+
if (n(c) && (c = c.toInt()), c &= 63, c === 0)
|
|
584
584
|
return this;
|
|
585
|
-
var
|
|
586
|
-
if (
|
|
587
|
-
var
|
|
588
|
-
return
|
|
589
|
-
} else return
|
|
590
|
-
},
|
|
591
|
-
return this.unsigned ?
|
|
592
|
-
},
|
|
593
|
-
return this.unsigned ? this :
|
|
594
|
-
},
|
|
595
|
-
return
|
|
596
|
-
},
|
|
597
|
-
var
|
|
585
|
+
var E = this.high;
|
|
586
|
+
if (c < 32) {
|
|
587
|
+
var N = this.low;
|
|
588
|
+
return i(N >>> c | E << 32 - c, E >>> c, this.unsigned);
|
|
589
|
+
} else return c === 32 ? i(E, 0, this.unsigned) : i(E >>> c - 32, 0, this.unsigned);
|
|
590
|
+
}, x.shru = x.shiftRightUnsigned, x.shr_u = x.shiftRightUnsigned, x.toSigned = function() {
|
|
591
|
+
return this.unsigned ? i(this.low, this.high, !1) : this;
|
|
592
|
+
}, x.toUnsigned = function() {
|
|
593
|
+
return this.unsigned ? this : i(this.low, this.high, !0);
|
|
594
|
+
}, x.toBytes = function(c) {
|
|
595
|
+
return c ? this.toBytesLE() : this.toBytesBE();
|
|
596
|
+
}, x.toBytesLE = function() {
|
|
597
|
+
var c = this.high, E = this.low;
|
|
598
598
|
return [
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
599
|
+
E & 255,
|
|
600
|
+
E >>> 8 & 255,
|
|
601
|
+
E >>> 16 & 255,
|
|
602
|
+
E >>> 24,
|
|
603
|
+
c & 255,
|
|
604
|
+
c >>> 8 & 255,
|
|
605
|
+
c >>> 16 & 255,
|
|
606
|
+
c >>> 24
|
|
607
607
|
];
|
|
608
|
-
},
|
|
609
|
-
var
|
|
608
|
+
}, x.toBytesBE = function() {
|
|
609
|
+
var c = this.high, E = this.low;
|
|
610
610
|
return [
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
611
|
+
c >>> 24,
|
|
612
|
+
c >>> 16 & 255,
|
|
613
|
+
c >>> 8 & 255,
|
|
614
|
+
c & 255,
|
|
615
|
+
E >>> 24,
|
|
616
|
+
E >>> 16 & 255,
|
|
617
|
+
E >>> 8 & 255,
|
|
618
|
+
E & 255
|
|
619
619
|
];
|
|
620
|
-
}, t.fromBytes = function(
|
|
621
|
-
return
|
|
622
|
-
}, t.fromBytesLE = function(
|
|
620
|
+
}, t.fromBytes = function(c, E, N) {
|
|
621
|
+
return N ? t.fromBytesLE(c, E) : t.fromBytesBE(c, E);
|
|
622
|
+
}, t.fromBytesLE = function(c, E) {
|
|
623
623
|
return new t(
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
624
|
+
c[0] | c[1] << 8 | c[2] << 16 | c[3] << 24,
|
|
625
|
+
c[4] | c[5] << 8 | c[6] << 16 | c[7] << 24,
|
|
626
|
+
E
|
|
627
627
|
);
|
|
628
|
-
}, t.fromBytesBE = function(
|
|
628
|
+
}, t.fromBytesBE = function(c, E) {
|
|
629
629
|
return new t(
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
630
|
+
c[4] << 24 | c[5] << 16 | c[6] << 8 | c[7],
|
|
631
|
+
c[0] << 24 | c[1] << 16 | c[2] << 8 | c[3],
|
|
632
|
+
E
|
|
633
633
|
);
|
|
634
|
-
},
|
|
634
|
+
}, It;
|
|
635
635
|
}
|
|
636
|
-
var
|
|
637
|
-
const
|
|
636
|
+
var oe = Tn();
|
|
637
|
+
const re = /* @__PURE__ */ Sn(oe), Rn = /* @__PURE__ */ vn({
|
|
638
638
|
__proto__: null,
|
|
639
|
-
default:
|
|
640
|
-
}, [
|
|
639
|
+
default: re
|
|
640
|
+
}, [oe]);
|
|
641
641
|
/**
|
|
642
642
|
* @license
|
|
643
643
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -654,86 +654,86 @@ const Rt = /* @__PURE__ */ Gt(xt), Ct = /* @__PURE__ */ jt({
|
|
|
654
654
|
* limitations under the License.
|
|
655
655
|
* =============================================================================
|
|
656
656
|
*/
|
|
657
|
-
const
|
|
657
|
+
const tt = (
|
|
658
658
|
// tslint:disable-next-line
|
|
659
|
-
|
|
659
|
+
re || Rn
|
|
660
660
|
);
|
|
661
|
-
function
|
|
662
|
-
return
|
|
661
|
+
function dt(e) {
|
|
662
|
+
return tt.fromString(e, !0, 16);
|
|
663
663
|
}
|
|
664
|
-
const
|
|
665
|
-
function
|
|
664
|
+
const ae = dt("c3a5c85c97cb3127"), Q = dt("b492b66fbe98f273"), V = dt("9ae16a3b2f90404f");
|
|
665
|
+
function bt(e) {
|
|
666
666
|
return e.xor(e.shru(47));
|
|
667
667
|
}
|
|
668
|
-
function
|
|
669
|
-
const
|
|
670
|
-
return
|
|
668
|
+
function ie(e, t, n) {
|
|
669
|
+
const s = e.slice(t, t + n);
|
|
670
|
+
return tt.fromBytes(Array.from(s), !0, !0);
|
|
671
671
|
}
|
|
672
|
-
function
|
|
673
|
-
return
|
|
672
|
+
function T(e, t) {
|
|
673
|
+
return ie(e, t, 8);
|
|
674
674
|
}
|
|
675
|
-
function
|
|
676
|
-
return
|
|
675
|
+
function vt(e, t) {
|
|
676
|
+
return ie(e, t, 4);
|
|
677
677
|
}
|
|
678
|
-
function
|
|
678
|
+
function O(e, t) {
|
|
679
679
|
return t === 0 ? e : e.shru(t).or(e.shl(64 - t));
|
|
680
680
|
}
|
|
681
|
-
function
|
|
682
|
-
let
|
|
683
|
-
|
|
684
|
-
let o = t.xor(
|
|
681
|
+
function Y(e, t, n = dt("9ddfea08eb382d69")) {
|
|
682
|
+
let s = e.xor(t).mul(n);
|
|
683
|
+
s = s.xor(s.shru(47));
|
|
684
|
+
let o = t.xor(s).mul(n);
|
|
685
685
|
return o = o.xor(o.shru(47)), o = o.mul(n), o;
|
|
686
686
|
}
|
|
687
|
-
function
|
|
688
|
-
o = o.add(e),
|
|
689
|
-
const
|
|
690
|
-
return o = o.add(t), o = o.add(n),
|
|
687
|
+
function Pn(e, t, n, s, o, a) {
|
|
688
|
+
o = o.add(e), a = O(a.add(o).add(s), 21);
|
|
689
|
+
const r = o;
|
|
690
|
+
return o = o.add(t), o = o.add(n), a = a.add(O(o, 44)), [o.add(s), a.add(r)];
|
|
691
691
|
}
|
|
692
|
-
function
|
|
693
|
-
return
|
|
692
|
+
function ut(e, t, n, s) {
|
|
693
|
+
return Pn(T(e, t), T(e, t + 8), T(e, t + 16), T(e, t + 24), n, s);
|
|
694
694
|
}
|
|
695
|
-
function
|
|
695
|
+
function Cn(e, t = e.length) {
|
|
696
696
|
if (t >= 8) {
|
|
697
|
-
const n =
|
|
698
|
-
return
|
|
697
|
+
const n = V.add(t * 2), s = T(e, 0).add(V), o = T(e, t - 8), a = O(o, 37).mul(n).add(s), r = O(s, 25).add(o).mul(n);
|
|
698
|
+
return Y(a, r, n);
|
|
699
699
|
}
|
|
700
700
|
if (t >= 4) {
|
|
701
|
-
const n =
|
|
702
|
-
return
|
|
701
|
+
const n = V.add(t * 2), s = vt(e, 0);
|
|
702
|
+
return Y(s.shl(3).add(t), vt(e, t - 4), n);
|
|
703
703
|
}
|
|
704
704
|
if (t > 0) {
|
|
705
|
-
const n = e[0],
|
|
706
|
-
return
|
|
705
|
+
const n = e[0], s = e[t >> 1], o = e[t - 1], a = n + (s << 8), r = t + (o << 2);
|
|
706
|
+
return bt(V.mul(a).xor(ae.mul(r))).mul(V);
|
|
707
707
|
}
|
|
708
|
-
return
|
|
708
|
+
return V;
|
|
709
709
|
}
|
|
710
|
-
function
|
|
711
|
-
const n =
|
|
712
|
-
return
|
|
710
|
+
function qn(e, t = e.length) {
|
|
711
|
+
const n = V.add(t * 2), s = T(e, 0).mul(Q), o = T(e, 8), a = T(e, t - 8).mul(n), r = T(e, t - 16).mul(V);
|
|
712
|
+
return Y(O(s.add(o), 43).add(O(a, 30)).add(r), s.add(O(o.add(V), 18)).add(a), n);
|
|
713
713
|
}
|
|
714
|
-
function
|
|
715
|
-
const n =
|
|
716
|
-
return
|
|
714
|
+
function Un(e, t = e.length) {
|
|
715
|
+
const n = V.add(t * 2), s = T(e, 0).mul(V), o = T(e, 8), a = T(e, t - 8).mul(n), r = T(e, t - 16).mul(V), i = O(s.add(o), 43).add(O(a, 30)).add(r), l = Y(i, s.add(O(o.add(V), 18)).add(a), n), u = T(e, 16).mul(n), h = T(e, 24), f = i.add(T(e, t - 32)).mul(n), p = l.add(T(e, t - 24)).mul(n);
|
|
716
|
+
return Y(O(u.add(h), 43).add(O(f, 30)).add(p), u.add(O(h.add(s), 18)).add(f), n);
|
|
717
717
|
}
|
|
718
|
-
function
|
|
719
|
-
const n =
|
|
718
|
+
function Mn(e, t = e.length) {
|
|
719
|
+
const n = tt.fromNumber(81, !0);
|
|
720
720
|
if (t <= 32)
|
|
721
|
-
return t <= 16 ?
|
|
721
|
+
return t <= 16 ? Cn(e, t) : qn(e, t);
|
|
722
722
|
if (t <= 64)
|
|
723
|
-
return
|
|
724
|
-
let
|
|
725
|
-
|
|
726
|
-
let
|
|
727
|
-
const
|
|
723
|
+
return Un(e, t);
|
|
724
|
+
let s = n, o = n.mul(Q).add(113), a = bt(o.mul(V).add(113)).mul(V), r = [tt.UZERO, tt.UZERO], i = [tt.UZERO, tt.UZERO];
|
|
725
|
+
s = s.mul(V).add(T(e, 0));
|
|
726
|
+
let l = 0;
|
|
727
|
+
const u = (t - 1 >> 6) * 64, h = u + (t - 1 & 63) - 63;
|
|
728
728
|
do
|
|
729
|
-
|
|
730
|
-
while (
|
|
731
|
-
const f = Q.add(
|
|
732
|
-
return
|
|
729
|
+
s = O(s.add(o).add(r[0]).add(T(e, l + 8)), 37).mul(Q), o = O(o.add(r[1]).add(T(e, l + 48)), 42).mul(Q), s = s.xor(i[1]), o = o.add(r[0]).add(T(e, l + 40)), a = O(a.add(i[0]), 33).mul(Q), r = ut(e, l, r[1].mul(Q), s.add(i[0])), i = ut(e, l + 32, a.add(i[1]), o.add(T(e, l + 16))), [a, s] = [s, a], l += 64;
|
|
730
|
+
while (l !== u);
|
|
731
|
+
const f = Q.add(a.and(255).shl(1));
|
|
732
|
+
return l = h, i[0] = i[0].add(t - 1 & 63), r[0] = r[0].add(i[0]), i[0] = i[0].add(r[0]), s = O(s.add(o).add(r[0]).add(T(e, l + 8)), 37).mul(f), o = O(o.add(r[1]).add(T(e, l + 48)), 42).mul(f), s = s.xor(i[1].mul(9)), o = o.add(r[0].mul(9).add(T(e, l + 40))), a = O(a.add(i[0]), 33).mul(f), r = ut(e, l, r[1].mul(f), s.add(i[0])), i = ut(e, l + 32, a.add(i[1]), o.add(T(e, l + 16))), [a, s] = [s, a], Y(Y(r[0], i[0], f).add(bt(o).mul(ae)).add(a), Y(r[1], i[1], f).add(s), f);
|
|
733
733
|
}
|
|
734
734
|
/**
|
|
735
735
|
* @license
|
|
736
|
-
* Copyright
|
|
736
|
+
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
737
737
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
738
738
|
* you may not use this file except in compliance with the License.
|
|
739
739
|
* You may obtain a copy of the License at
|
|
@@ -747,68 +747,47 @@ function Xt(e, t = e.length) {
|
|
|
747
747
|
* limitations under the License.
|
|
748
748
|
* =============================================================================
|
|
749
749
|
*/
|
|
750
|
-
|
|
751
|
-
(
|
|
752
|
-
|
|
753
|
-
})
|
|
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;
|
|
750
|
+
function nt(e, t) {
|
|
751
|
+
Array.isArray(e) || (e = [e]), e.forEach((n) => {
|
|
752
|
+
n != null && qt(n.dtype !== "complex64", () => `${t} does not support complex64 tensors in the CPU backend.`);
|
|
753
|
+
});
|
|
796
754
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
755
|
+
/**
|
|
756
|
+
* @license
|
|
757
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
758
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
759
|
+
* you may not use this file except in compliance with the License.
|
|
760
|
+
* You may obtain a copy of the License at
|
|
761
|
+
*
|
|
762
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
763
|
+
*
|
|
764
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
765
|
+
* distributed under the License is distributed on an AS IS BASIS,
|
|
766
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
767
|
+
* See the License for the specific language governing permissions and
|
|
768
|
+
* limitations under the License.
|
|
769
|
+
* =============================================================================
|
|
770
|
+
*/
|
|
771
|
+
function le(e) {
|
|
772
|
+
const t = new Float32Array(e.length);
|
|
773
|
+
for (let n = 0; n < e.length; ++n)
|
|
774
|
+
t[n] = Math.abs(e[n]);
|
|
775
|
+
return t;
|
|
808
776
|
}
|
|
777
|
+
const On = (e) => {
|
|
778
|
+
const { x: t } = e.inputs, n = e.backend;
|
|
779
|
+
nt(t, "abs");
|
|
780
|
+
let s = new Float32Array(A(t.shape));
|
|
781
|
+
const o = n.data.get(t.dataId).values;
|
|
782
|
+
return s = le(o), n.makeOutput(s, t.shape, t.dtype);
|
|
783
|
+
}, Ys = {
|
|
784
|
+
kernelName: _e,
|
|
785
|
+
backendName: "cpu",
|
|
786
|
+
kernelFunc: On
|
|
787
|
+
};
|
|
809
788
|
/**
|
|
810
789
|
* @license
|
|
811
|
-
* Copyright
|
|
790
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
812
791
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
813
792
|
* you may not use this file except in compliance with the License.
|
|
814
793
|
* You may obtain a copy of the License at
|
|
@@ -822,19 +801,27 @@ function te(e, t) {
|
|
|
822
801
|
* limitations under the License.
|
|
823
802
|
* =============================================================================
|
|
824
803
|
*/
|
|
825
|
-
function
|
|
826
|
-
return
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
804
|
+
function W(e) {
|
|
805
|
+
return (t, n, s, o, a) => {
|
|
806
|
+
const r = Ut(t, n), i = r.length, l = K(r), u = A(r), h = et(a, u), f = t.length, p = n.length, I = K(t), m = K(n), F = ht(t, r), g = ht(n, r);
|
|
807
|
+
if (F.length + g.length === 0)
|
|
808
|
+
for (let d = 0; d < h.length; ++d)
|
|
809
|
+
h[d] = e(s[d % s.length], o[d % o.length]);
|
|
810
|
+
else
|
|
811
|
+
for (let d = 0; d < h.length; ++d) {
|
|
812
|
+
const b = gt(d, i, l), k = b.slice(-f);
|
|
813
|
+
F.forEach((C) => k[C] = 0);
|
|
814
|
+
const y = at(k, f, I), S = b.slice(-p);
|
|
815
|
+
g.forEach((C) => S[C] = 0);
|
|
816
|
+
const P = at(S, p, m);
|
|
817
|
+
h[d] = e(s[y], o[P]);
|
|
818
|
+
}
|
|
819
|
+
return [h, r];
|
|
820
|
+
};
|
|
834
821
|
}
|
|
835
822
|
/**
|
|
836
823
|
* @license
|
|
837
|
-
* Copyright
|
|
824
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
838
825
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
839
826
|
* you may not use this file except in compliance with the License.
|
|
840
827
|
* You may obtain a copy of the License at
|
|
@@ -848,27 +835,21 @@ function re(e, t, n) {
|
|
|
848
835
|
* limitations under the License.
|
|
849
836
|
* =============================================================================
|
|
850
837
|
*/
|
|
851
|
-
function
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
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
|
-
}
|
|
838
|
+
function mt(e) {
|
|
839
|
+
const { inputs: t, backend: n } = e, { real: s, imag: o } = t, a = n.data.get(s.dataId).values, r = n.data.get(o.dataId).values, i = n.makeTensorInfo(s.shape, "complex64"), l = n.data.get(i.dataId);
|
|
840
|
+
return l.complexTensorInfos = {
|
|
841
|
+
real: n.makeTensorInfo(s.shape, "float32", a),
|
|
842
|
+
imag: n.makeTensorInfo(o.shape, "float32", r)
|
|
843
|
+
}, i;
|
|
844
|
+
}
|
|
845
|
+
const Js = {
|
|
846
|
+
kernelName: Ve,
|
|
847
|
+
backendName: "cpu",
|
|
848
|
+
kernelFunc: mt
|
|
849
|
+
};
|
|
869
850
|
/**
|
|
870
851
|
* @license
|
|
871
|
-
* Copyright
|
|
852
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
872
853
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
873
854
|
* you may not use this file except in compliance with the License.
|
|
874
855
|
* You may obtain a copy of the License at
|
|
@@ -882,40 +863,39 @@ function ue(e, t) {
|
|
|
882
863
|
* limitations under the License.
|
|
883
864
|
* =============================================================================
|
|
884
865
|
*/
|
|
885
|
-
function
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
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})`;
|
|
866
|
+
function xt(e, t, n = "float32") {
|
|
867
|
+
if (n === "complex64") {
|
|
868
|
+
const o = xt(e, t, "float32"), a = xt(e, t, "float32");
|
|
869
|
+
return mt({ inputs: { real: o, imag: a }, backend: e });
|
|
870
|
+
}
|
|
871
|
+
const s = st(A(t), n);
|
|
872
|
+
return e.makeTensorInfo(t, n, s);
|
|
896
873
|
}
|
|
897
874
|
/**
|
|
898
875
|
* @license
|
|
899
876
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
900
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
877
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
901
878
|
* you may not use this file except in compliance with the License.
|
|
902
879
|
* You may obtain a copy of the License at
|
|
903
880
|
*
|
|
904
881
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
905
882
|
*
|
|
906
883
|
* Unless required by applicable law or agreed to in writing, software
|
|
907
|
-
* distributed under the License is distributed on an AS IS BASIS,
|
|
884
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
908
885
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
909
886
|
* See the License for the specific language governing permissions and
|
|
910
887
|
* limitations under the License.
|
|
911
888
|
* =============================================================================
|
|
912
889
|
*/
|
|
913
|
-
function
|
|
914
|
-
const t =
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
890
|
+
function Et(e) {
|
|
891
|
+
const { inputs: t, backend: n } = e, { x: s } = t;
|
|
892
|
+
return n.incRef(s.dataId), { dataId: s.dataId, shape: s.shape, dtype: s.dtype };
|
|
893
|
+
}
|
|
894
|
+
const Qs = {
|
|
895
|
+
kernelName: De,
|
|
896
|
+
backendName: "cpu",
|
|
897
|
+
kernelFunc: Et
|
|
898
|
+
};
|
|
919
899
|
/**
|
|
920
900
|
* @license
|
|
921
901
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -932,24 +912,15 @@ function fe(e) {
|
|
|
932
912
|
* limitations under the License.
|
|
933
913
|
* =============================================================================
|
|
934
914
|
*/
|
|
935
|
-
function
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
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
|
-
}
|
|
915
|
+
function ce(e) {
|
|
916
|
+
const { inputs: t, backend: n } = e, { input: s } = t, o = n.data.get(s.dataId).complexTensorInfos.real, a = n.data.get(o.dataId).values;
|
|
917
|
+
return n.makeTensorInfo(o.shape, o.dtype, a);
|
|
918
|
+
}
|
|
919
|
+
const to = {
|
|
920
|
+
kernelName: We,
|
|
921
|
+
backendName: "cpu",
|
|
922
|
+
kernelFunc: ce
|
|
923
|
+
};
|
|
953
924
|
/**
|
|
954
925
|
* @license
|
|
955
926
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -966,17 +937,41 @@ function U(e) {
|
|
|
966
937
|
* limitations under the License.
|
|
967
938
|
* =============================================================================
|
|
968
939
|
*/
|
|
969
|
-
function
|
|
970
|
-
if (
|
|
940
|
+
function ue(e, t, n, s) {
|
|
941
|
+
if (s === "int32") {
|
|
971
942
|
const o = Int32Array.from(e);
|
|
972
943
|
return [t, "int32", o];
|
|
973
944
|
}
|
|
974
|
-
if (
|
|
975
|
-
const o =
|
|
976
|
-
return [
|
|
945
|
+
if (s === "bool") {
|
|
946
|
+
const o = Be([0], n), [a, r] = W((i, l) => i !== l ? 1 : 0)(t, [], e, o, "bool");
|
|
947
|
+
return [r, "bool", a];
|
|
977
948
|
}
|
|
978
|
-
throw new Error(`Error in Cast: failed to cast ${n} to ${
|
|
949
|
+
throw new Error(`Error in Cast: failed to cast ${n} to ${s}`);
|
|
979
950
|
}
|
|
951
|
+
function lt(e) {
|
|
952
|
+
const { inputs: t, backend: n, attrs: s } = e, { x: o } = t, { dtype: a } = s;
|
|
953
|
+
if (a === "complex64") {
|
|
954
|
+
if (o.dtype === "complex64")
|
|
955
|
+
return Et({ inputs: { x: o }, backend: n });
|
|
956
|
+
const h = xt(n, o.shape, o.dtype), f = lt({ inputs: { x: o }, backend: n, attrs: { dtype: "float32" } }), p = mt({ inputs: { real: f, imag: h }, backend: n });
|
|
957
|
+
return n.disposeIntermediateTensorInfo(h), n.disposeIntermediateTensorInfo(f), p;
|
|
958
|
+
}
|
|
959
|
+
if (o.dtype === "complex64") {
|
|
960
|
+
const h = ce({ inputs: { input: o }, backend: n }), f = lt({ inputs: { x: h }, backend: n, attrs: { dtype: a } });
|
|
961
|
+
return n.disposeIntermediateTensorInfo(h), f;
|
|
962
|
+
}
|
|
963
|
+
if (!ze(o.dtype, a)) {
|
|
964
|
+
const h = Et({ inputs: { x: o }, backend: n });
|
|
965
|
+
return { dataId: h.dataId, shape: h.shape, dtype: a };
|
|
966
|
+
}
|
|
967
|
+
const r = n.data.get(o.dataId).values, [i, l, u] = ue(r, o.shape, o.dtype, a);
|
|
968
|
+
return n.makeTensorInfo(i, l, u);
|
|
969
|
+
}
|
|
970
|
+
const eo = {
|
|
971
|
+
kernelName: $e,
|
|
972
|
+
backendName: "cpu",
|
|
973
|
+
kernelFunc: lt
|
|
974
|
+
};
|
|
980
975
|
/**
|
|
981
976
|
* @license
|
|
982
977
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -993,7 +988,49 @@ function ge(e, t, n, r) {
|
|
|
993
988
|
* limitations under the License.
|
|
994
989
|
* =============================================================================
|
|
995
990
|
*/
|
|
996
|
-
|
|
991
|
+
function z(e, t, n, s) {
|
|
992
|
+
return n == null ? ({ inputs: o, backend: a }) => {
|
|
993
|
+
const { a: r, b: i } = o, l = a;
|
|
994
|
+
nt([r, i], e);
|
|
995
|
+
const u = l.data.get(r.dataId).values, h = l.data.get(i.dataId).values, f = r.dtype === "string" ? (
|
|
996
|
+
// tslint:disable-next-line: no-any
|
|
997
|
+
it(u)
|
|
998
|
+
) : u, p = r.dtype === "string" ? (
|
|
999
|
+
// tslint:disable-next-line: no-any
|
|
1000
|
+
it(h)
|
|
1001
|
+
) : h, I = s || r.dtype, [m, F] = t(r.shape, i.shape, f, p, I);
|
|
1002
|
+
return l.makeTensorInfo(F, I, m);
|
|
1003
|
+
} : ({ inputs: o, backend: a }) => {
|
|
1004
|
+
const { a: r, b: i } = o, l = a;
|
|
1005
|
+
if (r.dtype === "complex64" || i.dtype === "complex64") {
|
|
1006
|
+
const u = lt({ inputs: { x: r }, backend: l, attrs: { dtype: "complex64" } }), h = l.data.get(u.dataId), f = h.complexTensorInfos.real, p = h.complexTensorInfos.imag, I = l.data.get(f.dataId).values, m = l.data.get(p.dataId).values, F = lt({ inputs: { x: i }, backend: l, attrs: { dtype: "complex64" } }), g = l.data.get(F.dataId), d = g.complexTensorInfos.real, b = g.complexTensorInfos.imag, k = l.data.get(d.dataId).values, y = l.data.get(b.dataId).values, [S, P, C] = n(r.shape, i.shape, I, m, k, y), v = l.makeTensorInfo(C, "float32", S), x = l.makeTensorInfo(C, "float32", P), w = mt({ inputs: { real: v, imag: x }, backend: l });
|
|
1007
|
+
return l.disposeIntermediateTensorInfo(u), l.disposeIntermediateTensorInfo(F), l.disposeIntermediateTensorInfo(v), l.disposeIntermediateTensorInfo(x), w;
|
|
1008
|
+
} else {
|
|
1009
|
+
const u = l.data.get(r.dataId).values, h = l.data.get(i.dataId).values, f = s || r.dtype, [p, I] = t(r.shape, i.shape, u, h, f);
|
|
1010
|
+
return l.makeTensorInfo(I, f, p);
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
function Ft(e) {
|
|
1015
|
+
return (t, n, s, o, a, r) => {
|
|
1016
|
+
const i = Ut(t, n), l = A(i), u = i.length, h = K(i), f = et("float32", l), p = et("float32", l), I = ht(t, i), m = ht(n, i), F = kt(s, o), g = kt(a, r), d = t.length, b = K(t), k = n.length, y = K(n);
|
|
1017
|
+
if (I.length + m.length === 0)
|
|
1018
|
+
for (let S = 0; S < f.length; S++) {
|
|
1019
|
+
const P = S % F.length, C = S % g.length, v = e(F[P * 2], F[P * 2 + 1], g[C * 2], g[C * 2 + 1]);
|
|
1020
|
+
f[S] = v.real, p[S] = v.imag;
|
|
1021
|
+
}
|
|
1022
|
+
else
|
|
1023
|
+
for (let S = 0; S < f.length; S++) {
|
|
1024
|
+
const P = gt(S, u, h), C = P.slice(-d);
|
|
1025
|
+
I.forEach((E) => C[E] = 0);
|
|
1026
|
+
const v = at(C, d, b), x = P.slice(-k);
|
|
1027
|
+
m.forEach((E) => x[E] = 0);
|
|
1028
|
+
const w = at(x, k, y), c = e(F[v * 2], F[v * 2 + 1], g[w * 2], g[w * 2 + 1]);
|
|
1029
|
+
f[S] = c.real, p[S] = c.imag;
|
|
1030
|
+
}
|
|
1031
|
+
return [f, p, i];
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
997
1034
|
/**
|
|
998
1035
|
* @license
|
|
999
1036
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1010,26 +1047,47 @@ const de = U((e, t) => e + t);
|
|
|
1010
1047
|
* limitations under the License.
|
|
1011
1048
|
* =============================================================================
|
|
1012
1049
|
*/
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1050
|
+
const he = W((e, t) => e + t), Ln = Ft((e, t, n, s) => ({ real: e + n, imag: t + s })), An = z(Mt, he, Ln), no = {
|
|
1051
|
+
kernelName: Mt,
|
|
1052
|
+
backendName: "cpu",
|
|
1053
|
+
kernelFunc: An
|
|
1054
|
+
};
|
|
1055
|
+
/**
|
|
1056
|
+
* @license
|
|
1057
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1058
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1059
|
+
* you may not use this file except in compliance with the License.
|
|
1060
|
+
* You may obtain a copy of the License at
|
|
1061
|
+
*
|
|
1062
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1063
|
+
*
|
|
1064
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1065
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1066
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1067
|
+
* See the License for the specific language governing permissions and
|
|
1068
|
+
* limitations under the License.
|
|
1069
|
+
* =============================================================================
|
|
1070
|
+
*/
|
|
1071
|
+
function _n(e, t, n, s, o) {
|
|
1072
|
+
const a = A(s), r = st(o, n);
|
|
1073
|
+
for (let i = 0; i < e.length; i++) {
|
|
1074
|
+
const l = e[i];
|
|
1075
|
+
if (l < 0)
|
|
1018
1076
|
throw new Error("Input x must be non-negative!");
|
|
1019
|
-
|
|
1077
|
+
l >= o || (a > 0 ? r[l] += t[i] : r[l] += 1);
|
|
1020
1078
|
}
|
|
1021
|
-
return
|
|
1079
|
+
return r;
|
|
1022
1080
|
}
|
|
1023
|
-
function
|
|
1024
|
-
const o = e.shape[0],
|
|
1025
|
-
for (let
|
|
1026
|
-
for (let
|
|
1027
|
-
const
|
|
1028
|
-
if (
|
|
1081
|
+
function Vn(e, t, n, s = !1) {
|
|
1082
|
+
const o = e.shape[0], a = e.shape[1], r = H([o, n], t.dtype);
|
|
1083
|
+
for (let i = 0; i < o; i++)
|
|
1084
|
+
for (let l = 0; l < a; l++) {
|
|
1085
|
+
const u = e.get(i, l);
|
|
1086
|
+
if (u < 0)
|
|
1029
1087
|
throw new Error("Input x must be non-negative!");
|
|
1030
|
-
|
|
1088
|
+
u >= n || (s ? r.set(1, i, u) : t.size > 0 ? r.set(r.get(i, u) + t.get(i, l), i, u) : r.set(r.get(i, u) + 1, i, u));
|
|
1031
1089
|
}
|
|
1032
|
-
return
|
|
1090
|
+
return r;
|
|
1033
1091
|
}
|
|
1034
1092
|
/**
|
|
1035
1093
|
* @license
|
|
@@ -1047,7 +1105,11 @@ function we(e, t, n, r = !1) {
|
|
|
1047
1105
|
* limitations under the License.
|
|
1048
1106
|
* =============================================================================
|
|
1049
1107
|
*/
|
|
1050
|
-
const
|
|
1108
|
+
const fe = W((e, t) => e & t), Dn = z(Ot, fe), so = {
|
|
1109
|
+
kernelName: Ot,
|
|
1110
|
+
backendName: "cpu",
|
|
1111
|
+
kernelFunc: Dn
|
|
1112
|
+
};
|
|
1051
1113
|
/**
|
|
1052
1114
|
* @license
|
|
1053
1115
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1064,14 +1126,50 @@ const pe = U((e, t) => e & t);
|
|
|
1064
1126
|
* limitations under the License.
|
|
1065
1127
|
* =============================================================================
|
|
1066
1128
|
*/
|
|
1067
|
-
function
|
|
1068
|
-
return (t, n,
|
|
1069
|
-
const o =
|
|
1070
|
-
for (let
|
|
1071
|
-
o[
|
|
1129
|
+
function X(e) {
|
|
1130
|
+
return (t, n, s) => {
|
|
1131
|
+
const o = D(n, t.length);
|
|
1132
|
+
for (let a = 0; a < t.length; ++a)
|
|
1133
|
+
o[a] = e(t[a], s);
|
|
1072
1134
|
return o;
|
|
1073
1135
|
};
|
|
1074
1136
|
}
|
|
1137
|
+
/**
|
|
1138
|
+
* @license
|
|
1139
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1140
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1141
|
+
* you may not use this file except in compliance with the License.
|
|
1142
|
+
* You may obtain a copy of the License at
|
|
1143
|
+
*
|
|
1144
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1145
|
+
*
|
|
1146
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1147
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1148
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1149
|
+
* See the License for the specific language governing permissions and
|
|
1150
|
+
* limitations under the License.
|
|
1151
|
+
* =============================================================================
|
|
1152
|
+
*/
|
|
1153
|
+
function ge(e, t, n) {
|
|
1154
|
+
const s = X(t);
|
|
1155
|
+
return J(e, s, n);
|
|
1156
|
+
}
|
|
1157
|
+
function J(e, t, n) {
|
|
1158
|
+
return ({ inputs: s, attrs: o, backend: a }) => {
|
|
1159
|
+
const { x: r } = s;
|
|
1160
|
+
nt(r, e);
|
|
1161
|
+
const i = a, l = i.data.get(r.dataId).values;
|
|
1162
|
+
let u;
|
|
1163
|
+
if (r.dtype === "string") {
|
|
1164
|
+
if (!Array.isArray(l))
|
|
1165
|
+
throw new Error("String tensor's value was not an instance of Array");
|
|
1166
|
+
u = it(l);
|
|
1167
|
+
} else
|
|
1168
|
+
u = l;
|
|
1169
|
+
const h = n || r.dtype, f = t(u, h, o);
|
|
1170
|
+
return i.makeTensorInfo(r.shape, h, f);
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1075
1173
|
/**
|
|
1076
1174
|
* @license
|
|
1077
1175
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1088,7 +1186,11 @@ function K(e) {
|
|
|
1088
1186
|
* limitations under the License.
|
|
1089
1187
|
* =============================================================================
|
|
1090
1188
|
*/
|
|
1091
|
-
const
|
|
1189
|
+
const de = X((e) => Math.ceil(e)), Wn = J(Lt, de), oo = {
|
|
1190
|
+
kernelName: Lt,
|
|
1191
|
+
backendName: "cpu",
|
|
1192
|
+
kernelFunc: Wn
|
|
1193
|
+
};
|
|
1092
1194
|
/**
|
|
1093
1195
|
* @license
|
|
1094
1196
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1105,25 +1207,25 @@ const Ie = K((e) => Math.ceil(e));
|
|
|
1105
1207
|
* limitations under the License.
|
|
1106
1208
|
* =============================================================================
|
|
1107
1209
|
*/
|
|
1108
|
-
function
|
|
1109
|
-
const o =
|
|
1110
|
-
if (
|
|
1111
|
-
let
|
|
1112
|
-
e.forEach((
|
|
1113
|
-
const
|
|
1114
|
-
o.set(
|
|
1210
|
+
function $n(e, t, n, s) {
|
|
1211
|
+
const o = D(n, A(t));
|
|
1212
|
+
if (s && n !== "string") {
|
|
1213
|
+
let a = 0;
|
|
1214
|
+
e.forEach((r) => {
|
|
1215
|
+
const i = A(r.shape);
|
|
1216
|
+
o.set(r.vals, a), a += i;
|
|
1115
1217
|
});
|
|
1116
1218
|
} else {
|
|
1117
|
-
let
|
|
1118
|
-
e.forEach((
|
|
1119
|
-
const
|
|
1120
|
-
let
|
|
1121
|
-
for (let
|
|
1122
|
-
const
|
|
1123
|
-
for (let f = 0; f <
|
|
1124
|
-
o[
|
|
1219
|
+
let a = 0;
|
|
1220
|
+
e.forEach((r) => {
|
|
1221
|
+
const i = n === "string" ? it(r.vals) : r.vals;
|
|
1222
|
+
let l = 0;
|
|
1223
|
+
for (let u = 0; u < r.shape[0]; ++u) {
|
|
1224
|
+
const h = u * t[1] + a;
|
|
1225
|
+
for (let f = 0; f < r.shape[1]; ++f)
|
|
1226
|
+
o[h + f] = i[l++];
|
|
1125
1227
|
}
|
|
1126
|
-
|
|
1228
|
+
a += r.shape[1];
|
|
1127
1229
|
});
|
|
1128
1230
|
}
|
|
1129
1231
|
return o;
|
|
@@ -1144,7 +1246,11 @@ function Ee(e, t, n, r) {
|
|
|
1144
1246
|
* limitations under the License.
|
|
1145
1247
|
* =============================================================================
|
|
1146
1248
|
*/
|
|
1147
|
-
const
|
|
1249
|
+
const me = W((e, t) => e === t ? 1 : 0), zn = z(At, me, null, "bool"), ro = {
|
|
1250
|
+
kernelName: At,
|
|
1251
|
+
backendName: "cpu",
|
|
1252
|
+
kernelFunc: zn
|
|
1253
|
+
};
|
|
1148
1254
|
/**
|
|
1149
1255
|
* @license
|
|
1150
1256
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1161,7 +1267,11 @@ const Se = U((e, t) => e === t ? 1 : 0);
|
|
|
1161
1267
|
* limitations under the License.
|
|
1162
1268
|
* =============================================================================
|
|
1163
1269
|
*/
|
|
1164
|
-
const
|
|
1270
|
+
const pe = X((e) => Math.exp(e)), Bn = J(_t, pe, "float32"), ao = {
|
|
1271
|
+
kernelName: _t,
|
|
1272
|
+
backendName: "cpu",
|
|
1273
|
+
kernelFunc: Bn
|
|
1274
|
+
};
|
|
1165
1275
|
/**
|
|
1166
1276
|
* @license
|
|
1167
1277
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1178,7 +1288,11 @@ const Fe = K((e) => Math.exp(e));
|
|
|
1178
1288
|
* limitations under the License.
|
|
1179
1289
|
* =============================================================================
|
|
1180
1290
|
*/
|
|
1181
|
-
const
|
|
1291
|
+
const Ie = X((e) => Math.expm1(e)), Gn = J(Vt, Ie), io = {
|
|
1292
|
+
kernelName: Vt,
|
|
1293
|
+
backendName: "cpu",
|
|
1294
|
+
kernelFunc: Gn
|
|
1295
|
+
};
|
|
1182
1296
|
/**
|
|
1183
1297
|
* @license
|
|
1184
1298
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1195,7 +1309,11 @@ const be = K((e) => Math.expm1(e));
|
|
|
1195
1309
|
* limitations under the License.
|
|
1196
1310
|
* =============================================================================
|
|
1197
1311
|
*/
|
|
1198
|
-
const
|
|
1312
|
+
const we = X((e) => Math.floor(e)), jn = J(Dt, we), lo = {
|
|
1313
|
+
kernelName: Dt,
|
|
1314
|
+
backendName: "cpu",
|
|
1315
|
+
kernelFunc: jn
|
|
1316
|
+
};
|
|
1199
1317
|
/**
|
|
1200
1318
|
* @license
|
|
1201
1319
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1212,7 +1330,11 @@ const xe = K((e) => Math.floor(e));
|
|
|
1212
1330
|
* limitations under the License.
|
|
1213
1331
|
* =============================================================================
|
|
1214
1332
|
*/
|
|
1215
|
-
const
|
|
1333
|
+
const be = W((e, t) => Math.floor(e / t)), Zn = z(Wt, be, null, "int32"), co = {
|
|
1334
|
+
kernelName: Wt,
|
|
1335
|
+
backendName: "cpu",
|
|
1336
|
+
kernelFunc: Zn
|
|
1337
|
+
};
|
|
1216
1338
|
/**
|
|
1217
1339
|
* @license
|
|
1218
1340
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -1229,21 +1351,21 @@ const Re = U((e, t) => Math.floor(e / t));
|
|
|
1229
1351
|
* limitations under the License.
|
|
1230
1352
|
* =============================================================================
|
|
1231
1353
|
*/
|
|
1232
|
-
function
|
|
1233
|
-
const
|
|
1234
|
-
for (let
|
|
1354
|
+
function Hn(e, t, n, s, o, a, r, i, l) {
|
|
1355
|
+
const u = H([s, a], n);
|
|
1356
|
+
for (let h = 0; h < s; h++) {
|
|
1235
1357
|
const f = [];
|
|
1236
1358
|
let p = 0;
|
|
1237
1359
|
for (let I = 0; I < o; I++) {
|
|
1238
|
-
const m = e[
|
|
1239
|
-
p += m *
|
|
1360
|
+
const m = e[h * o + I];
|
|
1361
|
+
p += m * r[I], f.push(m);
|
|
1240
1362
|
}
|
|
1241
|
-
if (p < 0 || p >=
|
|
1242
|
-
throw new Error(`Invalid indices: ${f} does not index into ${
|
|
1243
|
-
for (let I = 0; I <
|
|
1244
|
-
|
|
1363
|
+
if (p < 0 || p >= l / a)
|
|
1364
|
+
throw new Error(`Invalid indices: ${f} does not index into ${i}`);
|
|
1365
|
+
for (let I = 0; I < a; I++)
|
|
1366
|
+
u.values[h * a + I] = t.get(...t.indexToLoc(p * a + I));
|
|
1245
1367
|
}
|
|
1246
|
-
return
|
|
1368
|
+
return u;
|
|
1247
1369
|
}
|
|
1248
1370
|
/**
|
|
1249
1371
|
* @license
|
|
@@ -1261,15 +1383,15 @@ function Te(e, t, n, r, o, s, i, u, a) {
|
|
|
1261
1383
|
* limitations under the License.
|
|
1262
1384
|
* =============================================================================
|
|
1263
1385
|
*/
|
|
1264
|
-
function
|
|
1265
|
-
const
|
|
1266
|
-
for (let o = 0; o <
|
|
1267
|
-
const
|
|
1268
|
-
|
|
1269
|
-
const
|
|
1270
|
-
0 <=
|
|
1386
|
+
function Kn(e, t, n) {
|
|
1387
|
+
const s = H(n, e.dtype);
|
|
1388
|
+
for (let o = 0; o < s.size; ++o) {
|
|
1389
|
+
const r = s.indexToLoc(o).slice(), i = r[0], l = r[2], u = t.locToIndex([i, l]);
|
|
1390
|
+
r[2] = t.values[u];
|
|
1391
|
+
const h = e.locToIndex(r);
|
|
1392
|
+
0 <= h && h < e.values.length && (s.values[o] = e.values[h]);
|
|
1271
1393
|
}
|
|
1272
|
-
return
|
|
1394
|
+
return s;
|
|
1273
1395
|
}
|
|
1274
1396
|
/**
|
|
1275
1397
|
* @license
|
|
@@ -1287,7 +1409,11 @@ function ve(e, t, n) {
|
|
|
1287
1409
|
* limitations under the License.
|
|
1288
1410
|
* =============================================================================
|
|
1289
1411
|
*/
|
|
1290
|
-
const
|
|
1412
|
+
const xe = W((e, t) => e > t ? 1 : 0), Xn = z($t, xe, null, "bool"), uo = {
|
|
1413
|
+
kernelName: $t,
|
|
1414
|
+
backendName: "cpu",
|
|
1415
|
+
kernelFunc: Xn
|
|
1416
|
+
};
|
|
1291
1417
|
/**
|
|
1292
1418
|
* @license
|
|
1293
1419
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1304,7 +1430,11 @@ const Oe = U((e, t) => e > t ? 1 : 0);
|
|
|
1304
1430
|
* limitations under the License.
|
|
1305
1431
|
* =============================================================================
|
|
1306
1432
|
*/
|
|
1307
|
-
const
|
|
1433
|
+
const Ee = W((e, t) => e >= t ? 1 : 0), Yn = z(zt, Ee, null, "bool"), ho = {
|
|
1434
|
+
kernelName: zt,
|
|
1435
|
+
backendName: "cpu",
|
|
1436
|
+
kernelFunc: Yn
|
|
1437
|
+
};
|
|
1308
1438
|
/**
|
|
1309
1439
|
* @license
|
|
1310
1440
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1321,7 +1451,11 @@ const _e = U((e, t) => e >= t ? 1 : 0);
|
|
|
1321
1451
|
* limitations under the License.
|
|
1322
1452
|
* =============================================================================
|
|
1323
1453
|
*/
|
|
1324
|
-
const
|
|
1454
|
+
const Fe = W((e, t) => e < t ? 1 : 0), Jn = z(Bt, Fe, null, "bool"), fo = {
|
|
1455
|
+
kernelName: Bt,
|
|
1456
|
+
backendName: "cpu",
|
|
1457
|
+
kernelFunc: Jn
|
|
1458
|
+
};
|
|
1325
1459
|
/**
|
|
1326
1460
|
* @license
|
|
1327
1461
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1338,7 +1472,11 @@ const ye = U((e, t) => e < t ? 1 : 0);
|
|
|
1338
1472
|
* limitations under the License.
|
|
1339
1473
|
* =============================================================================
|
|
1340
1474
|
*/
|
|
1341
|
-
const
|
|
1475
|
+
const ye = W((e, t) => e <= t ? 1 : 0), Qn = z(Gt, ye, null, "bool"), go = {
|
|
1476
|
+
kernelName: Gt,
|
|
1477
|
+
backendName: "cpu",
|
|
1478
|
+
kernelFunc: Qn
|
|
1479
|
+
};
|
|
1342
1480
|
/**
|
|
1343
1481
|
* @license
|
|
1344
1482
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1355,11 +1493,11 @@ const Le = U((e, t) => e <= t ? 1 : 0);
|
|
|
1355
1493
|
* limitations under the License.
|
|
1356
1494
|
* =============================================================================
|
|
1357
1495
|
*/
|
|
1358
|
-
function
|
|
1359
|
-
const
|
|
1496
|
+
function ts(e, t, n) {
|
|
1497
|
+
const s = (t - e) / (n - 1), o = st(n, "float32");
|
|
1360
1498
|
o[0] = e;
|
|
1361
|
-
for (let
|
|
1362
|
-
o[
|
|
1499
|
+
for (let a = 1; a < o.length; a++)
|
|
1500
|
+
o[a] = o[a - 1] + s;
|
|
1363
1501
|
return o;
|
|
1364
1502
|
}
|
|
1365
1503
|
/**
|
|
@@ -1378,7 +1516,11 @@ function Me(e, t, n) {
|
|
|
1378
1516
|
* limitations under the License.
|
|
1379
1517
|
* =============================================================================
|
|
1380
1518
|
*/
|
|
1381
|
-
const
|
|
1519
|
+
const ke = X((e) => Math.log(e)), es = J(jt, ke), mo = {
|
|
1520
|
+
kernelName: jt,
|
|
1521
|
+
backendName: "cpu",
|
|
1522
|
+
kernelFunc: es
|
|
1523
|
+
};
|
|
1382
1524
|
/**
|
|
1383
1525
|
* @license
|
|
1384
1526
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1395,16 +1537,16 @@ const Ne = K((e) => Math.log(e));
|
|
|
1395
1537
|
* limitations under the License.
|
|
1396
1538
|
* =============================================================================
|
|
1397
1539
|
*/
|
|
1398
|
-
function
|
|
1399
|
-
const o =
|
|
1400
|
-
for (let
|
|
1401
|
-
const
|
|
1402
|
-
let
|
|
1403
|
-
for (let
|
|
1404
|
-
const
|
|
1405
|
-
(Number.isNaN(
|
|
1540
|
+
function ns(e, t, n, s) {
|
|
1541
|
+
const o = et(s, A(n));
|
|
1542
|
+
for (let a = 0; a < o.length; ++a) {
|
|
1543
|
+
const r = a * t;
|
|
1544
|
+
let i = e[r];
|
|
1545
|
+
for (let l = 0; l < t; ++l) {
|
|
1546
|
+
const u = e[r + l];
|
|
1547
|
+
(Number.isNaN(u) || u > i) && (i = u);
|
|
1406
1548
|
}
|
|
1407
|
-
o[
|
|
1549
|
+
o[a] = i;
|
|
1408
1550
|
}
|
|
1409
1551
|
return o;
|
|
1410
1552
|
}
|
|
@@ -1424,7 +1566,11 @@ function $e(e, t, n, r) {
|
|
|
1424
1566
|
* limitations under the License.
|
|
1425
1567
|
* =============================================================================
|
|
1426
1568
|
*/
|
|
1427
|
-
const
|
|
1569
|
+
const Ne = W((e, t) => Math.max(e, t)), ss = z(Zt, Ne), po = {
|
|
1570
|
+
kernelName: Zt,
|
|
1571
|
+
backendName: "cpu",
|
|
1572
|
+
kernelFunc: ss
|
|
1573
|
+
};
|
|
1428
1574
|
/**
|
|
1429
1575
|
* @license
|
|
1430
1576
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1441,7 +1587,11 @@ const Ae = U((e, t) => Math.max(e, t));
|
|
|
1441
1587
|
* limitations under the License.
|
|
1442
1588
|
* =============================================================================
|
|
1443
1589
|
*/
|
|
1444
|
-
const
|
|
1590
|
+
const Se = W((e, t) => Math.min(e, t)), os = z(Ht, Se), Io = {
|
|
1591
|
+
kernelName: Ht,
|
|
1592
|
+
backendName: "cpu",
|
|
1593
|
+
kernelFunc: os
|
|
1594
|
+
};
|
|
1445
1595
|
/**
|
|
1446
1596
|
* @license
|
|
1447
1597
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1458,7 +1608,14 @@ const De = U((e, t) => Math.min(e, t));
|
|
|
1458
1608
|
* limitations under the License.
|
|
1459
1609
|
* =============================================================================
|
|
1460
1610
|
*/
|
|
1461
|
-
const
|
|
1611
|
+
const yt = W((e, t) => e * t), rs = Ft((e, t, n, s) => ({
|
|
1612
|
+
real: e * n - t * s,
|
|
1613
|
+
imag: e * s + t * n
|
|
1614
|
+
})), as = z(Kt, yt, rs), wo = {
|
|
1615
|
+
kernelName: Kt,
|
|
1616
|
+
backendName: "cpu",
|
|
1617
|
+
kernelFunc: as
|
|
1618
|
+
};
|
|
1462
1619
|
/**
|
|
1463
1620
|
* @license
|
|
1464
1621
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1475,10 +1632,21 @@ const Ot = U((e, t) => e * t);
|
|
|
1475
1632
|
* limitations under the License.
|
|
1476
1633
|
* =============================================================================
|
|
1477
1634
|
*/
|
|
1478
|
-
function
|
|
1479
|
-
const
|
|
1480
|
-
return
|
|
1481
|
-
}
|
|
1635
|
+
function ve(e, t, n) {
|
|
1636
|
+
const s = je(-1, n);
|
|
1637
|
+
return yt([], t, s, e, n);
|
|
1638
|
+
}
|
|
1639
|
+
function is(e) {
|
|
1640
|
+
const { inputs: t, backend: n } = e, { x: s } = t;
|
|
1641
|
+
nt(s, "neg");
|
|
1642
|
+
const o = n.data.get(s.dataId).values, [a, r] = ve(o, s.shape, s.dtype);
|
|
1643
|
+
return n.makeTensorInfo(r, s.dtype, a);
|
|
1644
|
+
}
|
|
1645
|
+
const bo = {
|
|
1646
|
+
kernelName: Ge,
|
|
1647
|
+
backendName: "cpu",
|
|
1648
|
+
kernelFunc: is
|
|
1649
|
+
};
|
|
1482
1650
|
/**
|
|
1483
1651
|
* @license
|
|
1484
1652
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1495,7 +1663,11 @@ function Pe(e, t, n) {
|
|
|
1495
1663
|
* limitations under the License.
|
|
1496
1664
|
* =============================================================================
|
|
1497
1665
|
*/
|
|
1498
|
-
const
|
|
1666
|
+
const Te = W((e, t) => e !== t ? 1 : 0), ls = z(Xt, Te, null, "bool"), xo = {
|
|
1667
|
+
kernelName: Xt,
|
|
1668
|
+
backendName: "cpu",
|
|
1669
|
+
kernelFunc: ls
|
|
1670
|
+
};
|
|
1499
1671
|
/**
|
|
1500
1672
|
* @license
|
|
1501
1673
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1512,16 +1684,16 @@ const We = U((e, t) => e !== t ? 1 : 0);
|
|
|
1512
1684
|
* limitations under the License.
|
|
1513
1685
|
* =============================================================================
|
|
1514
1686
|
*/
|
|
1515
|
-
function
|
|
1516
|
-
const
|
|
1517
|
-
for (let
|
|
1518
|
-
const f = gt(
|
|
1687
|
+
function Re(e, t, n, s, o) {
|
|
1688
|
+
const a = t.length, r = A(t), i = K(t), l = K(o), u = et(n, A(o));
|
|
1689
|
+
for (let h = 0; h < r; ++h) {
|
|
1690
|
+
const f = gt(h, a, i), p = new Array(f.length);
|
|
1519
1691
|
for (let m = 0; m < p.length; m++)
|
|
1520
|
-
p[m] = f[
|
|
1521
|
-
const I =
|
|
1522
|
-
|
|
1692
|
+
p[m] = f[s[m]];
|
|
1693
|
+
const I = at(p, a, l);
|
|
1694
|
+
u[I] = e[h];
|
|
1523
1695
|
}
|
|
1524
|
-
return
|
|
1696
|
+
return u;
|
|
1525
1697
|
}
|
|
1526
1698
|
/**
|
|
1527
1699
|
* @license
|
|
@@ -1539,17 +1711,63 @@ function qe(e, t, n, r, o) {
|
|
|
1539
1711
|
* limitations under the License.
|
|
1540
1712
|
* =============================================================================
|
|
1541
1713
|
*/
|
|
1542
|
-
function
|
|
1543
|
-
const
|
|
1544
|
-
|
|
1545
|
-
|
|
1714
|
+
function Pe(e) {
|
|
1715
|
+
const { inputs: t, attrs: n, backend: s } = e, { x: o } = t, { perm: a } = n;
|
|
1716
|
+
nt(o, "transpose");
|
|
1717
|
+
const r = o.shape.length, i = new Array(r);
|
|
1718
|
+
for (let f = 0; f < i.length; f++)
|
|
1719
|
+
i[f] = o.shape[a[f]];
|
|
1720
|
+
const l = s.data.get(o.dataId).values, u = Re(l, o.shape, o.dtype, a, i);
|
|
1721
|
+
return { dataId: s.write(u, i, o.dtype), shape: i, dtype: o.dtype };
|
|
1722
|
+
}
|
|
1723
|
+
const Eo = {
|
|
1724
|
+
kernelName: Ze,
|
|
1725
|
+
backendName: "cpu",
|
|
1726
|
+
kernelFunc: Pe
|
|
1727
|
+
};
|
|
1728
|
+
/**
|
|
1729
|
+
* @license
|
|
1730
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
1731
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1732
|
+
* you may not use this file except in compliance with the License.
|
|
1733
|
+
* You may obtain a copy of the License at
|
|
1734
|
+
*
|
|
1735
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1736
|
+
*
|
|
1737
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1738
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1739
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1740
|
+
* See the License for the specific language governing permissions and
|
|
1741
|
+
* limitations under the License.
|
|
1742
|
+
* =============================================================================
|
|
1743
|
+
*/
|
|
1744
|
+
function Ce(e, t, n, s) {
|
|
1745
|
+
const [o, a] = bn(e, s), r = Ke(t, "int32"), i = st(A(o), r), l = A(a);
|
|
1746
|
+
for (let u = 0; u < i.length; ++u) {
|
|
1747
|
+
const h = u * l;
|
|
1546
1748
|
let f = 1;
|
|
1547
|
-
for (let p = 0; p <
|
|
1548
|
-
f *= n[
|
|
1549
|
-
u
|
|
1550
|
-
}
|
|
1551
|
-
return { outVals:
|
|
1552
|
-
}
|
|
1749
|
+
for (let p = 0; p < l; ++p)
|
|
1750
|
+
f *= n[h + p];
|
|
1751
|
+
i[u] = f;
|
|
1752
|
+
}
|
|
1753
|
+
return { outVals: i, outShape: o, outDtype: r };
|
|
1754
|
+
}
|
|
1755
|
+
function cs(e) {
|
|
1756
|
+
const { inputs: t, backend: n, attrs: s } = e, { x: o } = t, { axis: a, keepDims: r } = s;
|
|
1757
|
+
nt(o, "prod");
|
|
1758
|
+
const i = o.shape.length, l = Yt(a, o.shape), u = pn(l, i);
|
|
1759
|
+
let h = l, f = o;
|
|
1760
|
+
const p = [];
|
|
1761
|
+
u != null && (f = Pe({ inputs: { x: o }, backend: n, attrs: { perm: u } }), p.push(f), h = In(h.length, i));
|
|
1762
|
+
const I = n.data.get(f.dataId).values, { outVals: m, outShape: F, outDtype: g } = Ce(f.shape, f.dtype, I, h);
|
|
1763
|
+
let d = F;
|
|
1764
|
+
return r && (d = wn(F, l)), p.forEach((b) => n.disposeIntermediateTensorInfo(b)), n.makeTensorInfo(d, g, m);
|
|
1765
|
+
}
|
|
1766
|
+
const Fo = {
|
|
1767
|
+
kernelName: He,
|
|
1768
|
+
backendName: "cpu",
|
|
1769
|
+
kernelFunc: cs
|
|
1770
|
+
};
|
|
1553
1771
|
/**
|
|
1554
1772
|
* @license
|
|
1555
1773
|
* Copyright 2022 Google LLC. All Rights Reserved.
|
|
@@ -1566,96 +1784,96 @@ function Ve(e, t, n, r) {
|
|
|
1566
1784
|
* limitations under the License.
|
|
1567
1785
|
* =============================================================================
|
|
1568
1786
|
*/
|
|
1569
|
-
function
|
|
1570
|
-
e.forEach((
|
|
1571
|
-
if (
|
|
1572
|
-
const
|
|
1573
|
-
throw new Error(`indices[${
|
|
1787
|
+
function us(e, t, n) {
|
|
1788
|
+
e.forEach((s, o) => {
|
|
1789
|
+
if (s < 0 || s >= n) {
|
|
1790
|
+
const a = gt(o, t.length, K(t)).join(",");
|
|
1791
|
+
throw new Error(`indices[${a}] = ${s} is not in [0, ${n})`);
|
|
1574
1792
|
}
|
|
1575
1793
|
});
|
|
1576
1794
|
}
|
|
1577
|
-
function
|
|
1795
|
+
function hs(e, t) {
|
|
1578
1796
|
for (let n = 0; n < e.length; ++n) {
|
|
1579
|
-
const
|
|
1580
|
-
if (
|
|
1797
|
+
const s = e[n], o = n === e.length - 1 ? t : e[n + 1].length;
|
|
1798
|
+
if (s.length === 0)
|
|
1581
1799
|
throw new Error("Ragged splits may not be empty");
|
|
1582
|
-
if (
|
|
1800
|
+
if (s[0] < 0)
|
|
1583
1801
|
throw new Error("Ragged splits must be non-negative");
|
|
1584
|
-
if (
|
|
1802
|
+
if (s[s.length - 1] > o)
|
|
1585
1803
|
throw new Error("Ragged splits must not point past values");
|
|
1586
|
-
for (let
|
|
1587
|
-
if (
|
|
1804
|
+
for (let a = 1; a < s.length; ++a)
|
|
1805
|
+
if (s[a - 1] > s[a])
|
|
1588
1806
|
throw new Error("Ragged splits must be sorted in ascending order");
|
|
1589
1807
|
}
|
|
1590
1808
|
}
|
|
1591
|
-
function
|
|
1809
|
+
function fs(e, t, n, s) {
|
|
1592
1810
|
const o = [];
|
|
1593
|
-
let
|
|
1594
|
-
const
|
|
1595
|
-
|
|
1596
|
-
let
|
|
1597
|
-
for (let
|
|
1598
|
-
|
|
1599
|
-
const
|
|
1600
|
-
for (let f = 1; f <
|
|
1601
|
-
u
|
|
1602
|
-
}
|
|
1603
|
-
for (let
|
|
1604
|
-
let
|
|
1811
|
+
let a = 0;
|
|
1812
|
+
const r = t.length - 1 + n.length, i = new Array(r).fill(null).map(() => [0]);
|
|
1813
|
+
hs(n, s);
|
|
1814
|
+
let l = 1;
|
|
1815
|
+
for (let u = 0; u < t.length - 1; ++u) {
|
|
1816
|
+
l *= t[u];
|
|
1817
|
+
const h = t[u + 1];
|
|
1818
|
+
for (let f = 1; f < l + 1; ++f)
|
|
1819
|
+
i[u].push(f * h);
|
|
1820
|
+
}
|
|
1821
|
+
for (let u = 0; u < e.length; ++u) {
|
|
1822
|
+
let h = e[u], f = e[u] + 1;
|
|
1605
1823
|
for (let p = 0; p < n.length; ++p) {
|
|
1606
1824
|
const I = n[p], m = p + t.length - 1;
|
|
1607
1825
|
if (m >= 0) {
|
|
1608
|
-
const
|
|
1609
|
-
for (let d =
|
|
1610
|
-
|
|
1826
|
+
const F = i[m], g = F[F.length - 1] - I[h];
|
|
1827
|
+
for (let d = h; d < f; ++d)
|
|
1828
|
+
i[m].push(I[d + 1] + g);
|
|
1611
1829
|
}
|
|
1612
|
-
|
|
1830
|
+
h = I[h], f = I[f];
|
|
1613
1831
|
}
|
|
1614
|
-
f !==
|
|
1832
|
+
f !== h && (o.push([h, f]), a += f - h);
|
|
1615
1833
|
}
|
|
1616
|
-
return { outSplits:
|
|
1834
|
+
return { outSplits: i, valueSlices: o, numValues: a };
|
|
1617
1835
|
}
|
|
1618
|
-
function
|
|
1836
|
+
function gs(e) {
|
|
1619
1837
|
const t = [];
|
|
1620
1838
|
for (let n = 0; n < e.length; ++n) {
|
|
1621
|
-
const
|
|
1622
|
-
t.push(o), e[n].forEach((
|
|
1839
|
+
const s = e[n].length, o = D("int32", s);
|
|
1840
|
+
t.push(o), e[n].forEach((a, r) => o[r] = a);
|
|
1623
1841
|
}
|
|
1624
1842
|
return t;
|
|
1625
1843
|
}
|
|
1626
|
-
function
|
|
1844
|
+
function Tt(e, t) {
|
|
1627
1845
|
const n = e.slice(0, t);
|
|
1628
1846
|
for (; n.length < t; )
|
|
1629
1847
|
n.push(1);
|
|
1630
|
-
for (let
|
|
1631
|
-
n[t - 1] *= e[
|
|
1848
|
+
for (let s = t; s < e.length; s++)
|
|
1849
|
+
n[t - 1] *= e[s];
|
|
1632
1850
|
return n;
|
|
1633
1851
|
}
|
|
1634
|
-
function
|
|
1635
|
-
const
|
|
1636
|
-
let
|
|
1637
|
-
for (const
|
|
1638
|
-
for (let
|
|
1639
|
-
for (let f = 0; f <
|
|
1640
|
-
o[
|
|
1641
|
-
++
|
|
1852
|
+
function ds(e, t, n, s, o, a) {
|
|
1853
|
+
const r = Tt(t, 2)[1], i = Tt(a, 2)[1];
|
|
1854
|
+
let l = 0;
|
|
1855
|
+
for (const u of n)
|
|
1856
|
+
for (let h = u[0]; h < u[1]; ++h) {
|
|
1857
|
+
for (let f = 0; f < s; ++f)
|
|
1858
|
+
o[l * i + f] = e[h * r + f];
|
|
1859
|
+
++l;
|
|
1642
1860
|
}
|
|
1643
1861
|
}
|
|
1644
|
-
function
|
|
1645
|
-
const
|
|
1646
|
-
|
|
1647
|
-
const
|
|
1648
|
-
return
|
|
1862
|
+
function ms(e, t, n, s, o) {
|
|
1863
|
+
const a = t.slice();
|
|
1864
|
+
a[0] = o;
|
|
1865
|
+
const r = D(n, A(a)), i = e.length, l = i === 0 ? 0 : i / t[0];
|
|
1866
|
+
return ds(e, t, s, l, r, a), [r, a];
|
|
1649
1867
|
}
|
|
1650
|
-
function
|
|
1868
|
+
function ps(e, t, n, s, o, a, r, i) {
|
|
1651
1869
|
if (e.length === 0)
|
|
1652
1870
|
throw new Error("paramsNestedSplits must be non empty");
|
|
1653
1871
|
if (t[0].length === 0)
|
|
1654
1872
|
throw new Error("Split tensors must not be scalars");
|
|
1655
|
-
const
|
|
1656
|
-
if (
|
|
1873
|
+
const l = t[0][0] - 1;
|
|
1874
|
+
if (us(a, r, l), s.length === 0)
|
|
1657
1875
|
throw new Error("params.rank must be nonzero");
|
|
1658
|
-
const
|
|
1876
|
+
const u = s[0], { outSplits: h, valueSlices: f, numValues: p } = fs(a, r, e, u), I = gs(h), m = ms(n, s, o, f, p);
|
|
1659
1877
|
return [I, m[0], m[1]];
|
|
1660
1878
|
}
|
|
1661
1879
|
/**
|
|
@@ -1674,40 +1892,40 @@ function Be(e, t, n, r, o, s, i, u) {
|
|
|
1674
1892
|
* limitations under the License.
|
|
1675
1893
|
* =============================================================================
|
|
1676
1894
|
*/
|
|
1677
|
-
const
|
|
1678
|
-
function
|
|
1895
|
+
const Rt = 2147483647;
|
|
1896
|
+
function Is(e, t, n, s, o, a, r) {
|
|
1679
1897
|
if (t.length > 1)
|
|
1680
1898
|
throw new Error("starts must be a scalar or vector");
|
|
1681
1899
|
if (o.length > 1)
|
|
1682
1900
|
throw new Error("limits must be a scalar or vector");
|
|
1683
|
-
if (
|
|
1901
|
+
if (r.length > 1)
|
|
1684
1902
|
throw new Error("deltas must be a scalar or vector");
|
|
1685
|
-
const
|
|
1686
|
-
|
|
1687
|
-
for (let g = 1; g <
|
|
1688
|
-
if (
|
|
1903
|
+
const i = t.length === 0, l = o.length === 0, u = r.length === 0, h = [];
|
|
1904
|
+
i || h.push(t[0]), l || h.push(o[0]), u || h.push(r[0]);
|
|
1905
|
+
for (let g = 1; g < h.length; ++g)
|
|
1906
|
+
if (h[g] !== h[g - 1])
|
|
1689
1907
|
throw new Error("starts, limits, and deltas must have the same shape");
|
|
1690
|
-
const f =
|
|
1908
|
+
const f = h.length === 0 ? 1 : h[0], p = D("int32", f + 1);
|
|
1691
1909
|
p[0] = 0;
|
|
1692
1910
|
for (let g = 0; g < f; ++g) {
|
|
1693
|
-
const d =
|
|
1694
|
-
if (
|
|
1911
|
+
const d = i ? e[0] : e[g], b = l ? s[0] : s[g], k = u ? a[0] : a[g];
|
|
1912
|
+
if (k === 0)
|
|
1695
1913
|
throw new Error("Requires delta != 0");
|
|
1696
|
-
let
|
|
1697
|
-
if (
|
|
1698
|
-
|
|
1699
|
-
else if (
|
|
1700
|
-
throw new Error(`Requires ((limit - start) / delta) <= ${
|
|
1701
|
-
p[g + 1] = p[g] +
|
|
1702
|
-
}
|
|
1703
|
-
const I = p[f], m =
|
|
1704
|
-
let
|
|
1914
|
+
let y;
|
|
1915
|
+
if (k > 0 && b < d || k < 0 && b > d)
|
|
1916
|
+
y = 0;
|
|
1917
|
+
else if (y = Math.ceil(Math.abs((b - d) / k)), y > Rt)
|
|
1918
|
+
throw new Error(`Requires ((limit - start) / delta) <= ${Rt}`);
|
|
1919
|
+
p[g + 1] = p[g] + y;
|
|
1920
|
+
}
|
|
1921
|
+
const I = p[f], m = D(n, I);
|
|
1922
|
+
let F = 0;
|
|
1705
1923
|
for (let g = 0; g < f; ++g) {
|
|
1706
1924
|
const d = p[g + 1] - p[g];
|
|
1707
|
-
let
|
|
1708
|
-
const
|
|
1709
|
-
for (let
|
|
1710
|
-
m[
|
|
1925
|
+
let b = i ? e[0] : e[g];
|
|
1926
|
+
const k = u ? a[0] : a[g];
|
|
1927
|
+
for (let y = 0; y < d; ++y)
|
|
1928
|
+
m[F++] = b, b += k;
|
|
1711
1929
|
}
|
|
1712
1930
|
return [p, m];
|
|
1713
1931
|
}
|
|
@@ -1727,67 +1945,67 @@ function ke(e, t, n, r, o, s, i) {
|
|
|
1727
1945
|
* limitations under the License.
|
|
1728
1946
|
* =============================================================================
|
|
1729
1947
|
*/
|
|
1730
|
-
var
|
|
1731
|
-
class
|
|
1732
|
-
constructor(t, n,
|
|
1733
|
-
this.shape = t, this.shapeShape = n, this.values =
|
|
1948
|
+
var Z = tn;
|
|
1949
|
+
class ft {
|
|
1950
|
+
constructor(t, n, s, o, a, r, i, l, u, h) {
|
|
1951
|
+
this.shape = t, this.shapeShape = n, this.values = s, this.valuesShape = o, this.valuesDType = a, this.defaultValue = r, this.defaultValueShape = i, this.rowPartitionValues = l, this.rowPartitionValuesShapes = u, this.rowPartitionTypes = Je(h), this.raggedRank = Qe(this.rowPartitionTypes);
|
|
1734
1952
|
}
|
|
1735
1953
|
getRowPartitionTypeByDimension(t) {
|
|
1736
|
-
return this.rowPartitionTypes[0] ===
|
|
1954
|
+
return this.rowPartitionTypes[0] === Z.FIRST_DIM_SIZE ? this.rowPartitionTypes[t + 1] : this.rowPartitionTypes[t];
|
|
1737
1955
|
}
|
|
1738
1956
|
// Returns the relationship between dimension and dimension + 1.
|
|
1739
1957
|
getRowPartitionTensor(t) {
|
|
1740
|
-
return this.rowPartitionTypes[0] ===
|
|
1958
|
+
return this.rowPartitionTypes[0] === Z.FIRST_DIM_SIZE ? this.rowPartitionValues[t + 1] : this.rowPartitionValues[t];
|
|
1741
1959
|
}
|
|
1742
1960
|
getMaxWidth(t) {
|
|
1743
1961
|
const n = this.getRowPartitionTensor(t - 1);
|
|
1744
1962
|
switch (this.getRowPartitionTypeByDimension(t - 1)) {
|
|
1745
|
-
case
|
|
1746
|
-
return
|
|
1747
|
-
case
|
|
1748
|
-
return
|
|
1963
|
+
case Z.VALUE_ROWIDS:
|
|
1964
|
+
return ft.getMaxWidthValueRowID(n);
|
|
1965
|
+
case Z.ROW_SPLITS:
|
|
1966
|
+
return ft.getMaxWidthRowSplit(n);
|
|
1749
1967
|
default:
|
|
1750
|
-
throw new Error(`Cannot handle partition type ${
|
|
1968
|
+
throw new Error(`Cannot handle partition type ${Z[this.getRowPartitionTypeByDimension(t - 1)]}`);
|
|
1751
1969
|
}
|
|
1752
1970
|
}
|
|
1753
1971
|
static getMaxWidthRowSplit(t) {
|
|
1754
1972
|
const n = t.length;
|
|
1755
1973
|
if (n === 0 || n === 1)
|
|
1756
1974
|
return 0;
|
|
1757
|
-
let
|
|
1975
|
+
let s = 0;
|
|
1758
1976
|
for (let o = 0; o < n - 1; ++o) {
|
|
1759
|
-
const
|
|
1760
|
-
|
|
1977
|
+
const a = t[o + 1] - t[o];
|
|
1978
|
+
a > s && (s = a);
|
|
1761
1979
|
}
|
|
1762
|
-
return
|
|
1980
|
+
return s;
|
|
1763
1981
|
}
|
|
1764
1982
|
static getMaxWidthValueRowID(t) {
|
|
1765
1983
|
const n = t.length;
|
|
1766
1984
|
if (n === 0)
|
|
1767
1985
|
return 0;
|
|
1768
|
-
let
|
|
1769
|
-
for (let
|
|
1770
|
-
const
|
|
1771
|
-
|
|
1986
|
+
let s = 0, o = t[0], a = 0;
|
|
1987
|
+
for (let r = 1; r < n; ++r) {
|
|
1988
|
+
const i = t[r];
|
|
1989
|
+
i !== o && (o = i, a = Math.max(r - s, a), s = r);
|
|
1772
1990
|
}
|
|
1773
|
-
return Math.max(n -
|
|
1991
|
+
return Math.max(n - s, a);
|
|
1774
1992
|
}
|
|
1775
|
-
tensorShapeFromTensor(t, n,
|
|
1993
|
+
tensorShapeFromTensor(t, n, s = !0) {
|
|
1776
1994
|
if (n.length === 0) {
|
|
1777
1995
|
if (t[0] === -1)
|
|
1778
1996
|
return [];
|
|
1779
1997
|
throw new Error("The only valid scalar shape tensor is the fully unknown shape specified as -1.");
|
|
1780
1998
|
}
|
|
1781
|
-
return
|
|
1999
|
+
return Ct(t, s);
|
|
1782
2000
|
}
|
|
1783
2001
|
calculateOutputSize(t) {
|
|
1784
|
-
const n = this.valuesShape,
|
|
1785
|
-
|
|
1786
|
-
const o = this.tensorShapeFromTensor(this.shape, this.shapeShape),
|
|
1787
|
-
|
|
1788
|
-
for (let
|
|
1789
|
-
i
|
|
1790
|
-
return
|
|
2002
|
+
const n = this.valuesShape, s = this.defaultValueShape;
|
|
2003
|
+
en(s, n);
|
|
2004
|
+
const o = this.tensorShapeFromTensor(this.shape, this.shapeShape), r = nn(this.raggedRank, o, n);
|
|
2005
|
+
r[0] < 0 && (r[0] = t);
|
|
2006
|
+
for (let i = 1; i <= this.raggedRank; ++i)
|
|
2007
|
+
r[i] < 0 && (r[i] = this.getMaxWidth(i));
|
|
2008
|
+
return r;
|
|
1791
2009
|
}
|
|
1792
2010
|
/**
|
|
1793
2011
|
* The outputIndex represents the index in the output tensor
|
|
@@ -1799,29 +2017,29 @@ class it {
|
|
|
1799
2017
|
* If firstDimensionOutput = 11 instead, then:
|
|
1800
2018
|
* result = [0 100 200 300 400 500 600 700 800 900]
|
|
1801
2019
|
*/
|
|
1802
|
-
calculateFirstParentOutputIndex(t, n,
|
|
1803
|
-
const o = Math.min(t,
|
|
1804
|
-
let
|
|
1805
|
-
for (let
|
|
1806
|
-
|
|
1807
|
-
for (let
|
|
1808
|
-
|
|
1809
|
-
return
|
|
1810
|
-
}
|
|
1811
|
-
calculateOutputIndexRowSplit(t, n,
|
|
1812
|
-
const
|
|
1813
|
-
for (let
|
|
1814
|
-
const
|
|
1815
|
-
let
|
|
1816
|
-
|
|
1817
|
-
for (let f = 0; f <
|
|
1818
|
-
|
|
1819
|
-
for (let f = 0; f <
|
|
1820
|
-
|
|
2020
|
+
calculateFirstParentOutputIndex(t, n, s) {
|
|
2021
|
+
const o = Math.min(t, s), a = [];
|
|
2022
|
+
let r = 0;
|
|
2023
|
+
for (let i = 0; i < o; ++i, r += n)
|
|
2024
|
+
a.push(r);
|
|
2025
|
+
for (let i = o; i < t; ++i)
|
|
2026
|
+
a.push(-1);
|
|
2027
|
+
return qt(a.length === t, () => "Final length of result must be equal to firstDimension."), a;
|
|
2028
|
+
}
|
|
2029
|
+
calculateOutputIndexRowSplit(t, n, s, o) {
|
|
2030
|
+
const a = t.length, r = [];
|
|
2031
|
+
for (let i = 0; i < a - 1; ++i) {
|
|
2032
|
+
const l = t[i + 1] - t[i];
|
|
2033
|
+
let u = Math.min(o, l), h = n[i];
|
|
2034
|
+
h === -1 && (u = 0);
|
|
2035
|
+
for (let f = 0; f < u; ++f)
|
|
2036
|
+
r.push(h), h += s;
|
|
2037
|
+
for (let f = 0; f < l - u; ++f)
|
|
2038
|
+
r.push(-1);
|
|
1821
2039
|
}
|
|
1822
|
-
if (
|
|
2040
|
+
if (a > 0 && r.length !== t[a - 1])
|
|
1823
2041
|
throw new Error("Invalid row split size.");
|
|
1824
|
-
return
|
|
2042
|
+
return r;
|
|
1825
2043
|
}
|
|
1826
2044
|
// Calculate the output index of the first element of a list.
|
|
1827
2045
|
// The parentOutputIndex is the same computation for the previous list.
|
|
@@ -1844,41 +2062,41 @@ class it {
|
|
|
1844
2062
|
// result[6] = -1 because parentOutputIndex[valueRowIds[6]] == -1
|
|
1845
2063
|
// result[7] = -1 because parentOutputIndex[valueRowIds[6]] == -1
|
|
1846
2064
|
// result[8] = parentOutputIndex[valueRowIds[7]]
|
|
1847
|
-
calculateOutputIndexValueRowID(t, n,
|
|
1848
|
-
const
|
|
1849
|
-
if (
|
|
2065
|
+
calculateOutputIndexValueRowID(t, n, s, o) {
|
|
2066
|
+
const a = t.length, r = [];
|
|
2067
|
+
if (a === 0)
|
|
1850
2068
|
return [];
|
|
1851
|
-
let
|
|
1852
|
-
if (
|
|
1853
|
-
throw new Error(`Got currentValueRowId=${
|
|
1854
|
-
let
|
|
1855
|
-
|
|
1856
|
-
for (let
|
|
1857
|
-
const f = t[
|
|
1858
|
-
if (f ===
|
|
1859
|
-
|
|
2069
|
+
let i = 0, l = t[0];
|
|
2070
|
+
if (l >= n.length)
|
|
2071
|
+
throw new Error(`Got currentValueRowId=${l}, which is not less than ${n.length}`);
|
|
2072
|
+
let u = n[l];
|
|
2073
|
+
r.push(u);
|
|
2074
|
+
for (let h = 1; h < a; ++h) {
|
|
2075
|
+
const f = t[h];
|
|
2076
|
+
if (f === l)
|
|
2077
|
+
u >= 0 && (++i, i < o ? u += s : u = -1);
|
|
1860
2078
|
else {
|
|
1861
|
-
if (
|
|
2079
|
+
if (i = 0, l = f, f >= n.length)
|
|
1862
2080
|
throw new Error(`Got nextValueRowId=${f} which is not less than ${n.length}`);
|
|
1863
|
-
|
|
2081
|
+
u = n[f];
|
|
1864
2082
|
}
|
|
1865
|
-
|
|
2083
|
+
r.push(u);
|
|
1866
2084
|
}
|
|
1867
|
-
if (
|
|
2085
|
+
if (r.length !== t.length)
|
|
1868
2086
|
throw new Error("Invalid row ids.");
|
|
1869
|
-
return
|
|
1870
|
-
}
|
|
1871
|
-
calculateOutputIndex(t, n,
|
|
1872
|
-
const
|
|
1873
|
-
switch (
|
|
1874
|
-
case
|
|
1875
|
-
return this.calculateOutputIndexValueRowID(
|
|
1876
|
-
case
|
|
1877
|
-
if (
|
|
1878
|
-
throw new Error(`Row partition size is greater than output size: ${
|
|
1879
|
-
return this.calculateOutputIndexRowSplit(
|
|
2087
|
+
return r;
|
|
2088
|
+
}
|
|
2089
|
+
calculateOutputIndex(t, n, s, o) {
|
|
2090
|
+
const a = this.getRowPartitionTensor(t), r = this.getRowPartitionTypeByDimension(t);
|
|
2091
|
+
switch (r) {
|
|
2092
|
+
case Z.VALUE_ROWIDS:
|
|
2093
|
+
return this.calculateOutputIndexValueRowID(a, n, s, o);
|
|
2094
|
+
case Z.ROW_SPLITS:
|
|
2095
|
+
if (a.length - 1 > n.length)
|
|
2096
|
+
throw new Error(`Row partition size is greater than output size: ${a.length - 1} > ${n.length}`);
|
|
2097
|
+
return this.calculateOutputIndexRowSplit(a, n, s, o);
|
|
1880
2098
|
default:
|
|
1881
|
-
throw new Error(`Unsupported partition type: ${
|
|
2099
|
+
throw new Error(`Unsupported partition type: ${Z[r]}`);
|
|
1882
2100
|
}
|
|
1883
2101
|
}
|
|
1884
2102
|
getFirstDimensionSize() {
|
|
@@ -1887,94 +2105,94 @@ class it {
|
|
|
1887
2105
|
throw new Error("No row_partition_types given.");
|
|
1888
2106
|
const n = this.rowPartitionTypes[0];
|
|
1889
2107
|
switch (n) {
|
|
1890
|
-
case
|
|
2108
|
+
case Z.FIRST_DIM_SIZE:
|
|
1891
2109
|
return t[0];
|
|
1892
|
-
case
|
|
2110
|
+
case Z.VALUE_ROWIDS:
|
|
1893
2111
|
throw new Error("Cannot handle VALUE_ROWIDS in first dimension.");
|
|
1894
|
-
case
|
|
2112
|
+
case Z.ROW_SPLITS:
|
|
1895
2113
|
return this.rowPartitionValuesShapes[0][0] - 1;
|
|
1896
2114
|
default:
|
|
1897
|
-
throw new Error(`Cannot handle type ${
|
|
2115
|
+
throw new Error(`Cannot handle type ${Z[n]}`);
|
|
1898
2116
|
}
|
|
1899
2117
|
}
|
|
1900
2118
|
compute() {
|
|
1901
2119
|
if (this.rowPartitionValues[0].length <= 0)
|
|
1902
2120
|
throw new Error("Invalid first partition input. Tensor requires at least one element.");
|
|
1903
|
-
const n = this.getFirstDimensionSize(),
|
|
2121
|
+
const n = this.getFirstDimensionSize(), s = this.calculateOutputSize(n), o = new Array(this.raggedRank + 1);
|
|
1904
2122
|
o[o.length - 1] = 1;
|
|
1905
|
-
for (let
|
|
1906
|
-
o[
|
|
1907
|
-
const
|
|
1908
|
-
if (o[0] *
|
|
1909
|
-
let
|
|
1910
|
-
for (let
|
|
1911
|
-
|
|
1912
|
-
this.setOutput(this.raggedRank,
|
|
2123
|
+
for (let l = o.length - 2; l >= 0; --l)
|
|
2124
|
+
o[l] = o[l + 1] * s[l + 1];
|
|
2125
|
+
const a = Ct(s, !1), r = D(this.valuesDType, A(a));
|
|
2126
|
+
if (o[0] * s[0] > 0) {
|
|
2127
|
+
let l = this.calculateFirstParentOutputIndex(n, o[0], s[0]);
|
|
2128
|
+
for (let u = 1; u <= this.raggedRank; ++u)
|
|
2129
|
+
l = this.calculateOutputIndex(u - 1, l, o[u], s[u]);
|
|
2130
|
+
this.setOutput(this.raggedRank, l, r, a);
|
|
1913
2131
|
}
|
|
1914
|
-
return [
|
|
2132
|
+
return [a, r];
|
|
1915
2133
|
}
|
|
1916
|
-
setOutput(t, n,
|
|
1917
|
-
if (
|
|
2134
|
+
setOutput(t, n, s, o) {
|
|
2135
|
+
if (s.length === 0)
|
|
1918
2136
|
return;
|
|
1919
|
-
const
|
|
1920
|
-
let
|
|
1921
|
-
|
|
1922
|
-
const
|
|
1923
|
-
let
|
|
1924
|
-
if (
|
|
2137
|
+
const a = this.values, r = s;
|
|
2138
|
+
let i = o.slice();
|
|
2139
|
+
i = i.slice(t + 1);
|
|
2140
|
+
const l = A(i), u = n.length;
|
|
2141
|
+
let h = this.defaultValue;
|
|
2142
|
+
if (h.length !== l && h.length !== 1) {
|
|
1925
2143
|
const m = this.defaultValueShape;
|
|
1926
|
-
|
|
1927
|
-
const
|
|
1928
|
-
|
|
2144
|
+
Xe(() => {
|
|
2145
|
+
const F = En(h, m);
|
|
2146
|
+
h = xn(F, i).dataSync();
|
|
1929
2147
|
});
|
|
1930
2148
|
}
|
|
1931
2149
|
let f = 0, p = 0, I = 0;
|
|
1932
|
-
for (let m = 0; m <=
|
|
1933
|
-
let
|
|
1934
|
-
if (
|
|
2150
|
+
for (let m = 0; m <= u; ++m) {
|
|
2151
|
+
let F = m < u ? n[m] : -1;
|
|
2152
|
+
if (F === I) {
|
|
1935
2153
|
++I;
|
|
1936
2154
|
continue;
|
|
1937
2155
|
}
|
|
1938
2156
|
if (p < I) {
|
|
1939
|
-
const g =
|
|
1940
|
-
|
|
2157
|
+
const g = a.subarray(f * l), d = r.subarray(p * l), b = (I - p) * l;
|
|
2158
|
+
Pt(d, g, b);
|
|
1941
2159
|
}
|
|
1942
|
-
if (m >=
|
|
1943
|
-
const g =
|
|
1944
|
-
|
|
2160
|
+
if (m >= u) {
|
|
2161
|
+
const g = s.length;
|
|
2162
|
+
F = Math.floor(g / l);
|
|
1945
2163
|
}
|
|
1946
|
-
if (
|
|
2164
|
+
if (F > I)
|
|
1947
2165
|
if (this.defaultValue.length === 1)
|
|
1948
|
-
|
|
2166
|
+
r.subarray(I * l, F * l).fill(this.defaultValue[0]), I = F;
|
|
1949
2167
|
else
|
|
1950
|
-
for (;
|
|
1951
|
-
const g =
|
|
1952
|
-
|
|
2168
|
+
for (; F > I; ) {
|
|
2169
|
+
const g = r.slice(I * l);
|
|
2170
|
+
Pt(g, h, l), ++I;
|
|
1953
2171
|
}
|
|
1954
|
-
|
|
2172
|
+
F < 0 ? (f = m + 1, p = I) : (f = m, p = I, I = p + 1);
|
|
1955
2173
|
}
|
|
1956
2174
|
}
|
|
1957
2175
|
}
|
|
1958
|
-
function
|
|
1959
|
-
for (let
|
|
1960
|
-
e[
|
|
2176
|
+
function Pt(e, t, n) {
|
|
2177
|
+
for (let s = 0; s < n; s++)
|
|
2178
|
+
e[s] = t[s];
|
|
1961
2179
|
}
|
|
1962
|
-
function
|
|
2180
|
+
function Ct(e, t) {
|
|
1963
2181
|
const n = [];
|
|
1964
|
-
for (let
|
|
1965
|
-
if (
|
|
2182
|
+
for (let s of e) {
|
|
2183
|
+
if (s < 0) {
|
|
1966
2184
|
if (!t)
|
|
1967
|
-
throw new Error(`Dimension ${
|
|
1968
|
-
if (
|
|
1969
|
-
throw new Error(`Dimension ${
|
|
1970
|
-
|
|
2185
|
+
throw new Error(`Dimension ${s} must be >= 0`);
|
|
2186
|
+
if (s < -1)
|
|
2187
|
+
throw new Error(`Dimension ${s} must be >= -1`);
|
|
2188
|
+
s = -1;
|
|
1971
2189
|
}
|
|
1972
|
-
n.push(
|
|
2190
|
+
n.push(s);
|
|
1973
2191
|
}
|
|
1974
2192
|
return n;
|
|
1975
2193
|
}
|
|
1976
|
-
function
|
|
1977
|
-
return new
|
|
2194
|
+
function ws(e, t, n, s, o, a, r, i, l, u) {
|
|
2195
|
+
return new ft(e, t, n, s, o, a, r, i, l, u).compute();
|
|
1978
2196
|
}
|
|
1979
2197
|
/**
|
|
1980
2198
|
* @license
|
|
@@ -1992,15 +2210,15 @@ function He(e, t, n, r, o, s, i, u, a, h) {
|
|
|
1992
2210
|
* limitations under the License.
|
|
1993
2211
|
* =============================================================================
|
|
1994
2212
|
*/
|
|
1995
|
-
function
|
|
1996
|
-
const o = e === t,
|
|
1997
|
-
if (o ||
|
|
1998
|
-
return
|
|
1999
|
-
const
|
|
2000
|
-
t < e && n === 1 && (n = -1),
|
|
2001
|
-
for (let
|
|
2002
|
-
|
|
2003
|
-
return
|
|
2213
|
+
function bs(e, t, n, s) {
|
|
2214
|
+
const o = e === t, a = e < t && n < 0, r = t < e && n > 1;
|
|
2215
|
+
if (o || a || r)
|
|
2216
|
+
return st(0, s);
|
|
2217
|
+
const i = Math.abs(Math.ceil((t - e) / n)), l = st(i, s);
|
|
2218
|
+
t < e && n === 1 && (n = -1), l[0] = e;
|
|
2219
|
+
for (let u = 1; u < l.length; u++)
|
|
2220
|
+
l[u] = l[u - 1] + n;
|
|
2221
|
+
return l;
|
|
2004
2222
|
}
|
|
2005
2223
|
/**
|
|
2006
2224
|
* @license
|
|
@@ -2018,7 +2236,11 @@ function Ke(e, t, n, r) {
|
|
|
2018
2236
|
* limitations under the License.
|
|
2019
2237
|
* =============================================================================
|
|
2020
2238
|
*/
|
|
2021
|
-
const
|
|
2239
|
+
const qe = X((e) => 1 / Math.sqrt(e)), xs = J(Jt, qe), yo = {
|
|
2240
|
+
kernelName: Jt,
|
|
2241
|
+
backendName: "cpu",
|
|
2242
|
+
kernelFunc: xs
|
|
2243
|
+
};
|
|
2022
2244
|
/**
|
|
2023
2245
|
* @license
|
|
2024
2246
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2035,23 +2257,23 @@ const Xe = K((e) => 1 / Math.sqrt(e));
|
|
|
2035
2257
|
* limitations under the License.
|
|
2036
2258
|
* =============================================================================
|
|
2037
2259
|
*/
|
|
2038
|
-
function
|
|
2039
|
-
const
|
|
2040
|
-
if (
|
|
2041
|
-
return
|
|
2042
|
-
const I =
|
|
2043
|
-
typeof
|
|
2044
|
-
for (let m = 0; m <
|
|
2045
|
-
const
|
|
2260
|
+
function Es(e, t, n, s, o, a, r, i, l, u) {
|
|
2261
|
+
const h = [s / o, o], f = e.values, p = t.values;
|
|
2262
|
+
if (s === 0)
|
|
2263
|
+
return H(n, t.dtype);
|
|
2264
|
+
const I = l instanceof wt ? l : H(h, t.dtype);
|
|
2265
|
+
typeof l == "string" || typeof l == "number" ? I.values.fill(l) : typeof l == "boolean" && I.values.fill(+l);
|
|
2266
|
+
for (let m = 0; m < a; m++) {
|
|
2267
|
+
const F = [];
|
|
2046
2268
|
let g = 0;
|
|
2047
|
-
for (let d = 0; d <
|
|
2048
|
-
const
|
|
2049
|
-
|
|
2269
|
+
for (let d = 0; d < r; d++) {
|
|
2270
|
+
const b = f[m * r + d];
|
|
2271
|
+
F.push(b), g += b * i[d];
|
|
2050
2272
|
}
|
|
2051
|
-
if (g < 0 || g >=
|
|
2052
|
-
throw new Error(`Invalid indices: ${
|
|
2273
|
+
if (g < 0 || g >= s / o)
|
|
2274
|
+
throw new Error(`Invalid indices: ${F} does not index into ${n}`);
|
|
2053
2275
|
for (let d = 0; d < o; d++)
|
|
2054
|
-
|
|
2276
|
+
u ? I.values[g * o + d] += p[m * o + d] : I.values[g * o + d] = t.rank === 0 ? p[0] : p[m * o + d];
|
|
2055
2277
|
}
|
|
2056
2278
|
return I;
|
|
2057
2279
|
}
|
|
@@ -2071,7 +2293,11 @@ function Qe(e, t, n, r, o, s, i, u, a, h) {
|
|
|
2071
2293
|
* limitations under the License.
|
|
2072
2294
|
* =============================================================================
|
|
2073
2295
|
*/
|
|
2074
|
-
const
|
|
2296
|
+
const Fs = X((e) => 1 / (1 + Math.exp(-e))), ys = ge(Qt, (e) => 1 / (1 + Math.exp(-e))), ko = {
|
|
2297
|
+
kernelName: Qt,
|
|
2298
|
+
backendName: "cpu",
|
|
2299
|
+
kernelFunc: ys
|
|
2300
|
+
};
|
|
2075
2301
|
/**
|
|
2076
2302
|
* @license
|
|
2077
2303
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2088,19 +2314,32 @@ const Je = K((e) => 1 / (1 + Math.exp(-e)));
|
|
|
2088
2314
|
* limitations under the License.
|
|
2089
2315
|
* =============================================================================
|
|
2090
2316
|
*/
|
|
2091
|
-
function
|
|
2092
|
-
const
|
|
2093
|
-
if (
|
|
2094
|
-
const f =
|
|
2095
|
-
return o === "string" ? e.slice(f, f +
|
|
2096
|
-
}
|
|
2097
|
-
const
|
|
2098
|
-
for (let f = 0; f <
|
|
2099
|
-
const p =
|
|
2100
|
-
|
|
2101
|
-
}
|
|
2102
|
-
return o === "string" ?
|
|
2103
|
-
}
|
|
2317
|
+
function Ue(e, t, n, s, o) {
|
|
2318
|
+
const a = kn(s, t, n), r = A(n), i = K(s);
|
|
2319
|
+
if (a) {
|
|
2320
|
+
const f = Nn(t, i);
|
|
2321
|
+
return o === "string" ? e.slice(f, f + r) : e.subarray(f, f + r);
|
|
2322
|
+
}
|
|
2323
|
+
const l = o === "string" ? it(e) : e, u = H(s, o, l), h = H(n, o);
|
|
2324
|
+
for (let f = 0; f < h.size; ++f) {
|
|
2325
|
+
const p = h.indexToLoc(f), I = p.map((m, F) => m + t[F]);
|
|
2326
|
+
h.set(u.get(...I), ...p);
|
|
2327
|
+
}
|
|
2328
|
+
return o === "string" ? sn(h.values) : h.values;
|
|
2329
|
+
}
|
|
2330
|
+
function ks(e) {
|
|
2331
|
+
const { inputs: t, backend: n, attrs: s } = e, { x: o } = t, { begin: a, size: r } = s;
|
|
2332
|
+
nt(o, "slice");
|
|
2333
|
+
const [i, l] = Fn(o, a, r);
|
|
2334
|
+
yn(o, i, l);
|
|
2335
|
+
const u = n.data.get(o.dataId).values, h = Ue(u, i, l, o.shape, o.dtype);
|
|
2336
|
+
return n.makeTensorInfo(l, o.dtype, h);
|
|
2337
|
+
}
|
|
2338
|
+
const No = {
|
|
2339
|
+
kernelName: Ye,
|
|
2340
|
+
backendName: "cpu",
|
|
2341
|
+
kernelFunc: ks
|
|
2342
|
+
};
|
|
2104
2343
|
/**
|
|
2105
2344
|
* @license
|
|
2106
2345
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -2117,69 +2356,69 @@ function Ye(e, t, n, r, o) {
|
|
|
2117
2356
|
* limitations under the License.
|
|
2118
2357
|
* =============================================================================
|
|
2119
2358
|
*/
|
|
2120
|
-
function
|
|
2121
|
-
const
|
|
2122
|
-
if (
|
|
2123
|
-
if (
|
|
2124
|
-
throw new Error(
|
|
2125
|
-
const g =
|
|
2359
|
+
function Ns(e, t, n, s, o, a, r) {
|
|
2360
|
+
const i = t[0], l = a[0], u = new Array(l), h = new Array(i), f = t[1];
|
|
2361
|
+
if (l === 0) {
|
|
2362
|
+
if (i !== 0)
|
|
2363
|
+
throw new Error(on(i));
|
|
2364
|
+
const g = D(n, 0), d = D(o, 0);
|
|
2126
2365
|
return [
|
|
2127
2366
|
g,
|
|
2128
2367
|
[0, f],
|
|
2129
2368
|
d,
|
|
2130
|
-
|
|
2131
|
-
|
|
2369
|
+
u,
|
|
2370
|
+
h
|
|
2132
2371
|
];
|
|
2133
2372
|
}
|
|
2134
2373
|
let p = !0, I = 0;
|
|
2135
|
-
const m = new Array(
|
|
2136
|
-
for (let g = 0; g <
|
|
2374
|
+
const m = new Array(l).fill(0);
|
|
2375
|
+
for (let g = 0; g < i; ++g) {
|
|
2137
2376
|
const d = e[g * f];
|
|
2138
2377
|
if (d < 0)
|
|
2139
|
-
throw new Error(
|
|
2140
|
-
if (d >=
|
|
2141
|
-
throw new Error(
|
|
2378
|
+
throw new Error(rn(g, d));
|
|
2379
|
+
if (d >= l)
|
|
2380
|
+
throw new Error(an(g, d, l));
|
|
2142
2381
|
++m[d], p = p && d >= I, I = d;
|
|
2143
2382
|
}
|
|
2144
|
-
let
|
|
2145
|
-
for (let g = 0; g <
|
|
2383
|
+
let F = !0;
|
|
2384
|
+
for (let g = 0; g < l; ++g) {
|
|
2146
2385
|
const d = m[g] === 0;
|
|
2147
|
-
|
|
2386
|
+
u[g] = d, F = F && !d, m[g] = Math.max(m[g], 1), g > 0 && (m[g] += m[g - 1]);
|
|
2148
2387
|
}
|
|
2149
|
-
if (
|
|
2150
|
-
const g = e, d =
|
|
2151
|
-
for (let
|
|
2152
|
-
|
|
2388
|
+
if (F && p) {
|
|
2389
|
+
const g = e, d = s;
|
|
2390
|
+
for (let b = 0; b < i; ++b)
|
|
2391
|
+
h[b] = b;
|
|
2153
2392
|
return [
|
|
2154
2393
|
g,
|
|
2155
|
-
[
|
|
2394
|
+
[i, f],
|
|
2156
2395
|
d,
|
|
2157
|
-
|
|
2158
|
-
|
|
2396
|
+
u,
|
|
2397
|
+
h
|
|
2159
2398
|
];
|
|
2160
2399
|
} else {
|
|
2161
|
-
const g = m[
|
|
2162
|
-
for (let
|
|
2163
|
-
const
|
|
2164
|
-
|
|
2165
|
-
for (let
|
|
2166
|
-
d[
|
|
2167
|
-
|
|
2400
|
+
const g = m[l - 1], d = D(n, g * f), b = D(o, g), k = new Array(l).fill(0);
|
|
2401
|
+
for (let y = 0; y < i; ++y) {
|
|
2402
|
+
const S = e[y * f], P = k[S], C = (S === 0 ? 0 : m[S - 1]) + P;
|
|
2403
|
+
k[S]++;
|
|
2404
|
+
for (let v = 0; v < f; ++v)
|
|
2405
|
+
d[C * f + v] = e[y * f + v];
|
|
2406
|
+
b[C] = s[y], h[y] = C;
|
|
2168
2407
|
}
|
|
2169
|
-
for (let
|
|
2170
|
-
if (
|
|
2171
|
-
const
|
|
2172
|
-
d[
|
|
2173
|
-
for (let
|
|
2174
|
-
d[
|
|
2175
|
-
|
|
2408
|
+
for (let y = 0; y < l; ++y)
|
|
2409
|
+
if (k[y] === 0) {
|
|
2410
|
+
const P = y === 0 ? 0 : m[y - 1];
|
|
2411
|
+
d[P * f + 0] = y;
|
|
2412
|
+
for (let C = 1; C < f; ++C)
|
|
2413
|
+
d[P * f + C] = 0;
|
|
2414
|
+
b[P] = r;
|
|
2176
2415
|
}
|
|
2177
2416
|
return [
|
|
2178
2417
|
d,
|
|
2179
2418
|
[g, f],
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2419
|
+
b,
|
|
2420
|
+
u,
|
|
2421
|
+
h
|
|
2183
2422
|
];
|
|
2184
2423
|
}
|
|
2185
2424
|
}
|
|
@@ -2199,52 +2438,52 @@ function tn(e, t, n, r, o, s, i) {
|
|
|
2199
2438
|
* limitations under the License.
|
|
2200
2439
|
* =============================================================================
|
|
2201
2440
|
*/
|
|
2202
|
-
function
|
|
2203
|
-
const
|
|
2204
|
-
let
|
|
2205
|
-
for (let g = 0; g <
|
|
2441
|
+
function Ss(e, t, n, s, o) {
|
|
2442
|
+
const a = A(s), r = t[0], i = o.length, l = [];
|
|
2443
|
+
let u = 1, h = -1;
|
|
2444
|
+
for (let g = 0; g < i; ++g) {
|
|
2206
2445
|
const d = o[g];
|
|
2207
2446
|
if (d === -1) {
|
|
2208
|
-
if (
|
|
2209
|
-
throw new Error(
|
|
2210
|
-
|
|
2447
|
+
if (h !== -1)
|
|
2448
|
+
throw new Error(ln(h, g));
|
|
2449
|
+
h = g, l.push(1);
|
|
2211
2450
|
} else {
|
|
2212
2451
|
if (d < 0)
|
|
2213
|
-
throw new Error(
|
|
2214
|
-
|
|
2452
|
+
throw new Error(cn(g, d));
|
|
2453
|
+
u *= d, l.push(d);
|
|
2215
2454
|
}
|
|
2216
2455
|
}
|
|
2217
|
-
if (
|
|
2218
|
-
if (
|
|
2219
|
-
throw new Error(
|
|
2220
|
-
const g = Math.trunc(
|
|
2221
|
-
if (
|
|
2222
|
-
throw new Error(
|
|
2223
|
-
|
|
2224
|
-
}
|
|
2225
|
-
if (
|
|
2226
|
-
throw new Error(
|
|
2227
|
-
const p =
|
|
2456
|
+
if (h !== -1) {
|
|
2457
|
+
if (u <= 0)
|
|
2458
|
+
throw new Error(un());
|
|
2459
|
+
const g = Math.trunc(a / u);
|
|
2460
|
+
if (u * g !== a)
|
|
2461
|
+
throw new Error(hn(s, l));
|
|
2462
|
+
l[h] = g;
|
|
2463
|
+
}
|
|
2464
|
+
if (A(l) !== a)
|
|
2465
|
+
throw new Error(fn(s, l));
|
|
2466
|
+
const p = s.length, I = [];
|
|
2228
2467
|
if (p > 0) {
|
|
2229
2468
|
I[p - 1] = 1;
|
|
2230
2469
|
for (let g = p - 2; g >= 0; --g)
|
|
2231
|
-
I[g] = I[g + 1] *
|
|
2470
|
+
I[g] = I[g + 1] * s[g + 1];
|
|
2232
2471
|
}
|
|
2233
2472
|
const m = [];
|
|
2234
|
-
if (
|
|
2235
|
-
m[
|
|
2236
|
-
for (let g =
|
|
2237
|
-
m[g] = m[g + 1] *
|
|
2473
|
+
if (i > 0) {
|
|
2474
|
+
m[i - 1] = 1;
|
|
2475
|
+
for (let g = i - 2; g >= 0; --g)
|
|
2476
|
+
m[g] = m[g + 1] * l[g + 1];
|
|
2238
2477
|
}
|
|
2239
|
-
const
|
|
2240
|
-
for (let g = 0; g <
|
|
2478
|
+
const F = D(n, r * i);
|
|
2479
|
+
for (let g = 0; g < r; ++g) {
|
|
2241
2480
|
let d = 0;
|
|
2242
|
-
for (let
|
|
2243
|
-
d += e[g * p +
|
|
2244
|
-
for (let
|
|
2245
|
-
|
|
2481
|
+
for (let b = 0; b < p; ++b)
|
|
2482
|
+
d += e[g * p + b] * I[b];
|
|
2483
|
+
for (let b = 0; b < i; ++b)
|
|
2484
|
+
F[g * i + b] = Math.trunc(d / m[b]), d %= m[b];
|
|
2246
2485
|
}
|
|
2247
|
-
return [
|
|
2486
|
+
return [F, [r, i], l];
|
|
2248
2487
|
}
|
|
2249
2488
|
/**
|
|
2250
2489
|
* @license
|
|
@@ -2262,45 +2501,45 @@ function en(e, t, n, r, o) {
|
|
|
2262
2501
|
* limitations under the License.
|
|
2263
2502
|
* =============================================================================
|
|
2264
2503
|
*/
|
|
2265
|
-
function
|
|
2266
|
-
const
|
|
2504
|
+
function vs(e, t, n, s, o, a = !1, r = 0) {
|
|
2505
|
+
const i = s.length, l = [t[0], e.length / t[0]], u = l[1], f = i > 0 ? o[i - 1] + 1 : 0;
|
|
2267
2506
|
if (f < 0)
|
|
2268
|
-
throw new Error(
|
|
2507
|
+
throw new Error(Nt());
|
|
2269
2508
|
const p = t.slice();
|
|
2270
2509
|
p[0] = f;
|
|
2271
|
-
const I = p.reduce((
|
|
2272
|
-
if (
|
|
2273
|
-
return f > 0 && m.fill(
|
|
2510
|
+
const I = p.reduce((k, y) => k * y, 1), m = D(n, I);
|
|
2511
|
+
if (i === 0)
|
|
2512
|
+
return f > 0 && m.fill(r), [m, p];
|
|
2274
2513
|
if (f <= 0)
|
|
2275
|
-
throw new Error(
|
|
2276
|
-
let
|
|
2514
|
+
throw new Error(Nt());
|
|
2515
|
+
let F = 0, g = 1, d = 0, b = o[F];
|
|
2277
2516
|
for (; ; ) {
|
|
2278
|
-
let
|
|
2279
|
-
if (g <
|
|
2280
|
-
if (
|
|
2517
|
+
let k = 0;
|
|
2518
|
+
if (g < i) {
|
|
2519
|
+
if (k = o[g], b === k) {
|
|
2281
2520
|
++g;
|
|
2282
2521
|
continue;
|
|
2283
2522
|
}
|
|
2284
|
-
if (
|
|
2285
|
-
throw new Error(
|
|
2523
|
+
if (b >= k)
|
|
2524
|
+
throw new Error(gn());
|
|
2286
2525
|
}
|
|
2287
|
-
if (
|
|
2288
|
-
throw new Error(
|
|
2289
|
-
|
|
2290
|
-
for (let
|
|
2291
|
-
const
|
|
2292
|
-
if (
|
|
2293
|
-
throw new Error(
|
|
2294
|
-
for (let
|
|
2295
|
-
m[
|
|
2526
|
+
if (b < 0 || b >= f)
|
|
2527
|
+
throw new Error(dn(b, f));
|
|
2528
|
+
b > d && m.fill(r, d * u, b * u);
|
|
2529
|
+
for (let y = F; y < g; ++y) {
|
|
2530
|
+
const S = s[y];
|
|
2531
|
+
if (S < 0 || S >= l[0])
|
|
2532
|
+
throw new Error(mn(y, s[y], l[0]));
|
|
2533
|
+
for (let P = 0; P < u; P++)
|
|
2534
|
+
m[b * u + P] += e[S * u + P];
|
|
2296
2535
|
}
|
|
2297
|
-
if (
|
|
2298
|
-
for (let
|
|
2299
|
-
m[
|
|
2300
|
-
if (
|
|
2536
|
+
if (a)
|
|
2537
|
+
for (let y = 0; y < u; y++)
|
|
2538
|
+
m[b * u + y] /= g - F;
|
|
2539
|
+
if (F = g, ++g, d = b + 1, b = k, g > i)
|
|
2301
2540
|
break;
|
|
2302
2541
|
}
|
|
2303
|
-
return d < f && m.fill(
|
|
2542
|
+
return d < f && m.fill(r, d * u, f * u), [m, p];
|
|
2304
2543
|
}
|
|
2305
2544
|
/**
|
|
2306
2545
|
* @license
|
|
@@ -2318,7 +2557,11 @@ function nn(e, t, n, r, o, s = !1, i = 0) {
|
|
|
2318
2557
|
* limitations under the License.
|
|
2319
2558
|
* =============================================================================
|
|
2320
2559
|
*/
|
|
2321
|
-
const
|
|
2560
|
+
const Ts = X((e) => Math.sqrt(e)), Rs = ge(te, (e) => Math.sqrt(e)), So = {
|
|
2561
|
+
kernelName: te,
|
|
2562
|
+
backendName: "cpu",
|
|
2563
|
+
kernelFunc: Rs
|
|
2564
|
+
};
|
|
2322
2565
|
/**
|
|
2323
2566
|
* @license
|
|
2324
2567
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2335,10 +2578,14 @@ const rn = K((e) => Math.sqrt(e));
|
|
|
2335
2578
|
* limitations under the License.
|
|
2336
2579
|
* =============================================================================
|
|
2337
2580
|
*/
|
|
2338
|
-
const
|
|
2581
|
+
const Me = W((e, t) => {
|
|
2339
2582
|
const n = e - t;
|
|
2340
2583
|
return n * n;
|
|
2341
|
-
})
|
|
2584
|
+
}), Ps = z(ee, Me), vo = {
|
|
2585
|
+
kernelName: ee,
|
|
2586
|
+
backendName: "cpu",
|
|
2587
|
+
kernelFunc: Ps
|
|
2588
|
+
};
|
|
2342
2589
|
/**
|
|
2343
2590
|
* @license
|
|
2344
2591
|
* Copyright 2023 Google LLC.
|
|
@@ -2355,10 +2602,14 @@ const on = U((e, t) => {
|
|
|
2355
2602
|
* limitations under the License.
|
|
2356
2603
|
* =============================================================================
|
|
2357
2604
|
*/
|
|
2358
|
-
const
|
|
2359
|
-
const { pattern: n, replaceGlobal:
|
|
2360
|
-
return e.replace(new RegExp(n,
|
|
2361
|
-
})
|
|
2605
|
+
const Oe = X((e, t) => {
|
|
2606
|
+
const { pattern: n, replaceGlobal: s, rewrite: o } = t;
|
|
2607
|
+
return e.replace(new RegExp(n, s ? "g" : ""), o);
|
|
2608
|
+
}), Cs = J(ne, Oe), To = {
|
|
2609
|
+
kernelName: ne,
|
|
2610
|
+
backendName: "cpu",
|
|
2611
|
+
kernelFunc: Cs
|
|
2612
|
+
};
|
|
2362
2613
|
/**
|
|
2363
2614
|
* @license
|
|
2364
2615
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2375,13 +2626,13 @@ const sn = K((e, t) => {
|
|
|
2375
2626
|
* limitations under the License.
|
|
2376
2627
|
* =============================================================================
|
|
2377
2628
|
*/
|
|
2378
|
-
function
|
|
2379
|
-
const o =
|
|
2380
|
-
for (let
|
|
2381
|
-
const
|
|
2382
|
-
for (let
|
|
2383
|
-
|
|
2384
|
-
o.set(t.get(...
|
|
2629
|
+
function qs(e, t, n, s) {
|
|
2630
|
+
const o = H(e, t.dtype);
|
|
2631
|
+
for (let a = 0; a < o.size; a++) {
|
|
2632
|
+
const r = o.indexToLoc(a), i = new Array(r.length);
|
|
2633
|
+
for (let l = 0; l < i.length; l++)
|
|
2634
|
+
i[l] = r[l] * n[l] + s[l];
|
|
2635
|
+
o.set(t.get(...i), ...r);
|
|
2385
2636
|
}
|
|
2386
2637
|
return o;
|
|
2387
2638
|
}
|
|
@@ -2401,40 +2652,40 @@ function ln(e, t, n, r) {
|
|
|
2401
2652
|
* limitations under the License.
|
|
2402
2653
|
* =============================================================================
|
|
2403
2654
|
*/
|
|
2404
|
-
class
|
|
2405
|
-
constructor(t, n,
|
|
2406
|
-
this.separator =
|
|
2655
|
+
class Us {
|
|
2656
|
+
constructor(t, n, s, o, a, r) {
|
|
2657
|
+
this.separator = pt(t), this.nGramWidths = n, this.leftPad = pt(s), this.rightPad = pt(o), this.padWidth = a, this.preserveShort = r;
|
|
2407
2658
|
}
|
|
2408
2659
|
getPadWidth(t) {
|
|
2409
2660
|
return Math.min(this.padWidth < 0 ? t - 1 : this.padWidth, t - 1);
|
|
2410
2661
|
}
|
|
2411
2662
|
getNumNGrams(t, n) {
|
|
2412
|
-
const
|
|
2413
|
-
return Math.max(0, t + 2 *
|
|
2663
|
+
const s = this.getPadWidth(n);
|
|
2664
|
+
return Math.max(0, t + 2 * s - n + 1);
|
|
2414
2665
|
}
|
|
2415
|
-
createNGrams(t, n,
|
|
2416
|
-
for (let
|
|
2417
|
-
const
|
|
2666
|
+
createNGrams(t, n, s, o, a, r) {
|
|
2667
|
+
for (let i = 0; i < a; ++i) {
|
|
2668
|
+
const l = this.getPadWidth(r), u = Math.max(0, l - i), h = Math.max(0, l - (a - (i + 1))), f = r - (u + h), p = n + (u > 0 ? 0 : i - l);
|
|
2418
2669
|
let I = 0;
|
|
2419
|
-
I +=
|
|
2420
|
-
for (let
|
|
2421
|
-
I += t[p +
|
|
2422
|
-
I +=
|
|
2423
|
-
const m =
|
|
2424
|
-
I += m * this.separator.length,
|
|
2425
|
-
const
|
|
2670
|
+
I += u * this.leftPad.length;
|
|
2671
|
+
for (let b = 0; b < f; ++b)
|
|
2672
|
+
I += t[p + b].length;
|
|
2673
|
+
I += h * this.rightPad.length;
|
|
2674
|
+
const m = u + h + f - 1;
|
|
2675
|
+
I += m * this.separator.length, s[o + i] = new Uint8Array(I);
|
|
2676
|
+
const F = s[o + i];
|
|
2426
2677
|
let g = 0;
|
|
2427
|
-
const d = (
|
|
2428
|
-
for (let
|
|
2678
|
+
const d = (b) => b.forEach((k) => F[g++] = k);
|
|
2679
|
+
for (let b = 0; b < u; ++b)
|
|
2429
2680
|
d(this.leftPad), d(this.separator);
|
|
2430
|
-
for (let
|
|
2431
|
-
d(t[p +
|
|
2681
|
+
for (let b = 0; b < f - 1; ++b)
|
|
2682
|
+
d(t[p + b]), d(this.separator);
|
|
2432
2683
|
if (f > 0) {
|
|
2433
2684
|
d(t[p + f - 1]);
|
|
2434
|
-
for (let
|
|
2685
|
+
for (let b = 0; b < h; ++b)
|
|
2435
2686
|
d(this.separator), d(this.rightPad);
|
|
2436
2687
|
} else {
|
|
2437
|
-
for (let
|
|
2688
|
+
for (let b = 0; b < h - 1; ++b)
|
|
2438
2689
|
d(this.rightPad), d(this.separator);
|
|
2439
2690
|
d(this.rightPad);
|
|
2440
2691
|
}
|
|
@@ -2444,55 +2695,55 @@ class un {
|
|
|
2444
2695
|
// where data is 1 dimensional and contains the values of the tensor
|
|
2445
2696
|
// and splits denotes the indices at which each row starts.
|
|
2446
2697
|
compute(t, n) {
|
|
2447
|
-
const
|
|
2698
|
+
const s = t.length, o = n.length;
|
|
2448
2699
|
if (o > 0) {
|
|
2449
|
-
let
|
|
2450
|
-
if (
|
|
2451
|
-
throw new Error(`First split value must be 0, got ${
|
|
2452
|
-
for (let
|
|
2453
|
-
let
|
|
2454
|
-
if (
|
|
2455
|
-
throw new Error(`Invalid split value ${n[
|
|
2456
|
-
|
|
2700
|
+
let l = n[0];
|
|
2701
|
+
if (l !== 0)
|
|
2702
|
+
throw new Error(`First split value must be 0, got ${l}`);
|
|
2703
|
+
for (let u = 1; u < o; ++u) {
|
|
2704
|
+
let h = n[u] >= l;
|
|
2705
|
+
if (h = h && n[u] <= s, !h)
|
|
2706
|
+
throw new Error(`Invalid split value ${n[u]}, must be in [${l}, ${s}]`);
|
|
2707
|
+
l = n[u];
|
|
2457
2708
|
}
|
|
2458
|
-
if (
|
|
2459
|
-
throw new Error(`Last split value must be data size. Expected ${
|
|
2709
|
+
if (l !== s)
|
|
2710
|
+
throw new Error(`Last split value must be data size. Expected ${s}, got ${l}`);
|
|
2460
2711
|
}
|
|
2461
|
-
const
|
|
2462
|
-
if (
|
|
2463
|
-
const
|
|
2464
|
-
for (let
|
|
2465
|
-
|
|
2466
|
-
return [
|
|
2712
|
+
const a = o - 1, r = D("int32", o);
|
|
2713
|
+
if (s === 0 || o === 0) {
|
|
2714
|
+
const l = new Array(s);
|
|
2715
|
+
for (let u = 0; u <= a; ++u)
|
|
2716
|
+
r[u] = 0;
|
|
2717
|
+
return [l, r];
|
|
2467
2718
|
}
|
|
2468
|
-
|
|
2469
|
-
for (let
|
|
2470
|
-
const
|
|
2471
|
-
let
|
|
2719
|
+
r[0] = 0;
|
|
2720
|
+
for (let l = 1; l <= a; ++l) {
|
|
2721
|
+
const u = n[l] - n[l - 1];
|
|
2722
|
+
let h = 0;
|
|
2472
2723
|
this.nGramWidths.forEach((f) => {
|
|
2473
|
-
|
|
2474
|
-
}), this.preserveShort &&
|
|
2724
|
+
h += this.getNumNGrams(u, f);
|
|
2725
|
+
}), this.preserveShort && u > 0 && h === 0 && (h = 1), r[l] = r[l - 1] + h;
|
|
2475
2726
|
}
|
|
2476
|
-
const
|
|
2477
|
-
for (let
|
|
2478
|
-
const
|
|
2479
|
-
let
|
|
2727
|
+
const i = new Array(r[a]);
|
|
2728
|
+
for (let l = 0; l < a; ++l) {
|
|
2729
|
+
const u = n[l];
|
|
2730
|
+
let h = r[l];
|
|
2480
2731
|
if (this.nGramWidths.forEach((f) => {
|
|
2481
|
-
const p = n[
|
|
2482
|
-
this.createNGrams(t,
|
|
2483
|
-
}), this.preserveShort &&
|
|
2484
|
-
const f = n[
|
|
2732
|
+
const p = n[l + 1] - n[l], I = this.getNumNGrams(p, f);
|
|
2733
|
+
this.createNGrams(t, u, i, h, I, f), h += I;
|
|
2734
|
+
}), this.preserveShort && h === r[l]) {
|
|
2735
|
+
const f = n[l + 1] - n[l];
|
|
2485
2736
|
if (f === 0)
|
|
2486
2737
|
continue;
|
|
2487
2738
|
const p = f + 2 * this.padWidth;
|
|
2488
|
-
this.createNGrams(t,
|
|
2739
|
+
this.createNGrams(t, u, i, h, 1, p);
|
|
2489
2740
|
}
|
|
2490
2741
|
}
|
|
2491
|
-
return [
|
|
2742
|
+
return [i, r];
|
|
2492
2743
|
}
|
|
2493
2744
|
}
|
|
2494
|
-
function
|
|
2495
|
-
return new
|
|
2745
|
+
function Ms(e, t, n, s, o, a, r, i) {
|
|
2746
|
+
return new Us(n, s, o, a, r, i).compute(e, t);
|
|
2496
2747
|
}
|
|
2497
2748
|
/**
|
|
2498
2749
|
* @license
|
|
@@ -2510,47 +2761,47 @@ function an(e, t, n, r, o, s, i, u) {
|
|
|
2510
2761
|
* limitations under the License.
|
|
2511
2762
|
* =============================================================================
|
|
2512
2763
|
*/
|
|
2513
|
-
function
|
|
2764
|
+
function Os(e, t, n, s) {
|
|
2514
2765
|
if (!e.length)
|
|
2515
2766
|
return;
|
|
2516
2767
|
if (t.length === 0) {
|
|
2517
|
-
for (let
|
|
2518
|
-
|
|
2768
|
+
for (let a = 0; a < e.length; ++a)
|
|
2769
|
+
s.push(e.subarray(a, a + 1));
|
|
2519
2770
|
return;
|
|
2520
2771
|
}
|
|
2521
2772
|
if (t.length === 1) {
|
|
2522
|
-
const
|
|
2523
|
-
let
|
|
2524
|
-
for (;
|
|
2525
|
-
const
|
|
2526
|
-
(!n ||
|
|
2773
|
+
const a = t[0];
|
|
2774
|
+
let r = e.indexOf(a);
|
|
2775
|
+
for (; r !== -1; ) {
|
|
2776
|
+
const i = e.subarray(0, r);
|
|
2777
|
+
(!n || i.length !== 0) && s.push(i), e = e.subarray(r + 1), r = e.indexOf(a);
|
|
2527
2778
|
}
|
|
2528
|
-
(!n || e.length !== 0) &&
|
|
2779
|
+
(!n || e.length !== 0) && s.push(e);
|
|
2529
2780
|
return;
|
|
2530
2781
|
}
|
|
2531
2782
|
let o = 0;
|
|
2532
|
-
for (let
|
|
2533
|
-
if (
|
|
2534
|
-
const
|
|
2535
|
-
(!n ||
|
|
2783
|
+
for (let a = 0; a < e.length + 1; a++)
|
|
2784
|
+
if (a === e.length || t.indexOf(e[a]) !== -1) {
|
|
2785
|
+
const r = e.subarray(o, a);
|
|
2786
|
+
(!n || r.length !== 0) && s.push(r), o = a + 1;
|
|
2536
2787
|
}
|
|
2537
2788
|
}
|
|
2538
|
-
function
|
|
2539
|
-
const
|
|
2540
|
-
let
|
|
2541
|
-
const
|
|
2542
|
-
for (let p = 0; p <
|
|
2789
|
+
function Ls(e, t, n) {
|
|
2790
|
+
const s = e.length, o = [];
|
|
2791
|
+
let a = 0, r = 0;
|
|
2792
|
+
const i = new Array(s);
|
|
2793
|
+
for (let p = 0; p < s; ++p) {
|
|
2543
2794
|
const I = o.length;
|
|
2544
|
-
|
|
2795
|
+
Os(e[p], t, n, o);
|
|
2545
2796
|
const m = o.length - I;
|
|
2546
|
-
|
|
2797
|
+
i[p] = m, a += m, r = Math.max(r, m);
|
|
2547
2798
|
}
|
|
2548
|
-
const
|
|
2799
|
+
const l = D("int32", a * 2), u = new Array(a), h = [s, r];
|
|
2549
2800
|
let f = 0;
|
|
2550
|
-
for (let p = 0; p <
|
|
2551
|
-
for (let I = 0; I <
|
|
2552
|
-
|
|
2553
|
-
return [
|
|
2801
|
+
for (let p = 0; p < s; ++p)
|
|
2802
|
+
for (let I = 0; I < i[p]; ++I)
|
|
2803
|
+
l[f * 2] = p, l[f * 2 + 1] = I, u[f] = o[f], ++f;
|
|
2804
|
+
return [l, u, h];
|
|
2554
2805
|
}
|
|
2555
2806
|
/**
|
|
2556
2807
|
* @license
|
|
@@ -2568,10 +2819,10 @@ function cn(e, t, n) {
|
|
|
2568
2819
|
* limitations under the License.
|
|
2569
2820
|
* =============================================================================
|
|
2570
2821
|
*/
|
|
2571
|
-
function
|
|
2572
|
-
const n =
|
|
2573
|
-
for (let
|
|
2574
|
-
n[
|
|
2822
|
+
function As(e, t) {
|
|
2823
|
+
const n = D("int32", e.length);
|
|
2824
|
+
for (let s = 0; s < e.length; ++s)
|
|
2825
|
+
n[s] = Mn(e[s]).modulo(t).getLowBitsUnsigned();
|
|
2575
2826
|
return n;
|
|
2576
2827
|
}
|
|
2577
2828
|
/**
|
|
@@ -2590,7 +2841,11 @@ function fn(e, t) {
|
|
|
2590
2841
|
* limitations under the License.
|
|
2591
2842
|
* =============================================================================
|
|
2592
2843
|
*/
|
|
2593
|
-
const
|
|
2844
|
+
const Le = W((e, t) => e - t), _s = Ft((e, t, n, s) => ({ real: e - n, imag: t - s })), Vs = z(se, Le, _s), Ro = {
|
|
2845
|
+
kernelName: se,
|
|
2846
|
+
backendName: "cpu",
|
|
2847
|
+
kernelFunc: Vs
|
|
2848
|
+
};
|
|
2594
2849
|
/**
|
|
2595
2850
|
* @license
|
|
2596
2851
|
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
@@ -2607,19 +2862,19 @@ const gn = U((e, t) => e - t);
|
|
|
2607
2862
|
* limitations under the License.
|
|
2608
2863
|
* =============================================================================
|
|
2609
2864
|
*/
|
|
2610
|
-
function
|
|
2865
|
+
function Ds(e, t) {
|
|
2611
2866
|
const n = new Array(e.rank);
|
|
2612
2867
|
for (let o = 0; o < n.length; o++)
|
|
2613
2868
|
n[o] = e.shape[o] * t[o];
|
|
2614
|
-
const
|
|
2615
|
-
for (let o = 0; o <
|
|
2616
|
-
const
|
|
2617
|
-
for (let
|
|
2618
|
-
|
|
2619
|
-
const
|
|
2620
|
-
|
|
2869
|
+
const s = H(n, e.dtype);
|
|
2870
|
+
for (let o = 0; o < s.values.length; ++o) {
|
|
2871
|
+
const a = s.indexToLoc(o), r = new Array(e.rank);
|
|
2872
|
+
for (let l = 0; l < r.length; l++)
|
|
2873
|
+
r[l] = a[l] % e.shape[l];
|
|
2874
|
+
const i = e.locToIndex(r);
|
|
2875
|
+
s.values[o] = e.values[i];
|
|
2621
2876
|
}
|
|
2622
|
-
return
|
|
2877
|
+
return s;
|
|
2623
2878
|
}
|
|
2624
2879
|
/**
|
|
2625
2880
|
* @license
|
|
@@ -2637,41 +2892,41 @@ function dn(e, t) {
|
|
|
2637
2892
|
* limitations under the License.
|
|
2638
2893
|
* =============================================================================
|
|
2639
2894
|
*/
|
|
2640
|
-
const
|
|
2895
|
+
const rt = (e, t) => {
|
|
2641
2896
|
const n = t.value - e.value;
|
|
2642
2897
|
return n === 0 ? e.index - t.index : n;
|
|
2643
2898
|
};
|
|
2644
|
-
function
|
|
2645
|
-
for (;
|
|
2646
|
-
if (
|
|
2647
|
-
const
|
|
2648
|
-
|
|
2899
|
+
function Ae(e, t, n = 0, s = e.length - 1) {
|
|
2900
|
+
for (; s > n; ) {
|
|
2901
|
+
if (s - n > 600) {
|
|
2902
|
+
const i = s - n + 1, l = t - n + 1, u = Math.log(i), h = 0.5 * Math.exp(2 * u / 3), f = 0.5 * Math.sqrt(u * h * (i - h) / i) * Math.sign(l - i / 2), p = Math.max(n, Math.floor(t - l * h / i + f)), I = Math.min(s, Math.floor(t + (i - l) * h / i + f));
|
|
2903
|
+
Ae(e, t, p, I);
|
|
2649
2904
|
}
|
|
2650
2905
|
const o = e[t];
|
|
2651
|
-
let
|
|
2652
|
-
for (
|
|
2653
|
-
for (
|
|
2654
|
-
|
|
2655
|
-
for (;
|
|
2656
|
-
|
|
2906
|
+
let a = n, r = s;
|
|
2907
|
+
for (ot(e, n, t), rt(e[s], o) > 0 && ot(e, n, s); a < r; ) {
|
|
2908
|
+
for (ot(e, a, r), a++, r--; rt(e[a], o) < 0; )
|
|
2909
|
+
a = a + 1;
|
|
2910
|
+
for (; rt(e[r], o) > 0; )
|
|
2911
|
+
r = r - 1;
|
|
2657
2912
|
}
|
|
2658
|
-
|
|
2913
|
+
rt(e[n], o) === 0 ? ot(e, n, r) : (r = r + 1, ot(e, r, s)), r <= t && (n = r + 1), t <= r && (s = r - 1);
|
|
2659
2914
|
}
|
|
2660
2915
|
}
|
|
2661
|
-
function
|
|
2662
|
-
const
|
|
2663
|
-
for (let f = 0; f <
|
|
2664
|
-
const p = f *
|
|
2916
|
+
function Ws(e, t, n, s, o) {
|
|
2917
|
+
const a = t[t.length - 1], [r, i] = [e.length / a, a], l = et(n, r * s), u = et("int32", r * s);
|
|
2918
|
+
for (let f = 0; f < r; f++) {
|
|
2919
|
+
const p = f * i, I = e.subarray(p, p + i);
|
|
2665
2920
|
let m = new Array(I.length);
|
|
2666
|
-
I.forEach((
|
|
2667
|
-
const
|
|
2668
|
-
for (let
|
|
2669
|
-
g[
|
|
2670
|
-
}
|
|
2671
|
-
const
|
|
2672
|
-
return
|
|
2673
|
-
|
|
2674
|
-
|
|
2921
|
+
I.forEach((b, k) => m[k] = { value: b, index: k }), s < m.length && (Ae(m, s), m = m.slice(0, s)), o && m.sort(rt);
|
|
2922
|
+
const F = f * s, g = l.subarray(F, F + s), d = u.subarray(F, F + s);
|
|
2923
|
+
for (let b = 0; b < s; b++)
|
|
2924
|
+
g[b] = m[b].value, d[b] = m[b].index;
|
|
2925
|
+
}
|
|
2926
|
+
const h = t.slice();
|
|
2927
|
+
return h[h.length - 1] = s, [
|
|
2928
|
+
H(h, n, l),
|
|
2929
|
+
H(h, "int32", u)
|
|
2675
2930
|
];
|
|
2676
2931
|
}
|
|
2677
2932
|
/**
|
|
@@ -2690,46 +2945,46 @@ function mn(e, t, n, r, o) {
|
|
|
2690
2945
|
* limitations under the License.
|
|
2691
2946
|
* =============================================================================
|
|
2692
2947
|
*/
|
|
2693
|
-
function
|
|
2694
|
-
const o =
|
|
2948
|
+
function $s(e, t, n, s) {
|
|
2949
|
+
const o = Yt(t, n)[0], a = [1, n[0], 1];
|
|
2695
2950
|
for (let m = 0; m < o; m++)
|
|
2696
|
-
|
|
2697
|
-
|
|
2951
|
+
a[0] *= n[m];
|
|
2952
|
+
a[1] = n[o];
|
|
2698
2953
|
for (let m = o + 1; m < n.length; m++)
|
|
2699
|
-
|
|
2700
|
-
const
|
|
2954
|
+
a[2] *= n[m];
|
|
2955
|
+
const r = /* @__PURE__ */ new Map(), i = new Int32Array(n[o]), l = new wt(a, s, e), u = [], h = a[0] === 1 && a[2] === 1;
|
|
2701
2956
|
for (let m = 0; m < n[o]; m++) {
|
|
2702
|
-
let
|
|
2703
|
-
if (
|
|
2704
|
-
|
|
2957
|
+
let F;
|
|
2958
|
+
if (h)
|
|
2959
|
+
F = e[m].toString();
|
|
2705
2960
|
else {
|
|
2706
2961
|
const d = [];
|
|
2707
|
-
for (let
|
|
2708
|
-
for (let
|
|
2709
|
-
d.push(
|
|
2710
|
-
|
|
2962
|
+
for (let b = 0; b < a[0]; b++)
|
|
2963
|
+
for (let k = 0; k < a[2]; k++)
|
|
2964
|
+
d.push(l.get(b, m, k));
|
|
2965
|
+
F = d.join(",");
|
|
2711
2966
|
}
|
|
2712
|
-
const g =
|
|
2967
|
+
const g = r.get(F);
|
|
2713
2968
|
if (g != null)
|
|
2714
|
-
|
|
2969
|
+
i[m] = g;
|
|
2715
2970
|
else {
|
|
2716
|
-
const d =
|
|
2717
|
-
|
|
2971
|
+
const d = r.size;
|
|
2972
|
+
r.set(F, d), i[m] = d, u.push(m);
|
|
2718
2973
|
}
|
|
2719
2974
|
}
|
|
2720
|
-
const f =
|
|
2721
|
-
f[1] =
|
|
2722
|
-
const p = new
|
|
2723
|
-
|
|
2724
|
-
for (let g = 0; g <
|
|
2725
|
-
for (let d = 0; d <
|
|
2726
|
-
p.set(
|
|
2975
|
+
const f = a.slice();
|
|
2976
|
+
f[1] = r.size;
|
|
2977
|
+
const p = new wt(f, s);
|
|
2978
|
+
u.forEach((m, F) => {
|
|
2979
|
+
for (let g = 0; g < a[0]; g++)
|
|
2980
|
+
for (let d = 0; d < a[2]; d++)
|
|
2981
|
+
p.set(l.get(g, m, d), g, F, d);
|
|
2727
2982
|
});
|
|
2728
2983
|
const I = n.slice();
|
|
2729
2984
|
return I[o] = f[1], {
|
|
2730
2985
|
outputValues: p.values,
|
|
2731
2986
|
outputShape: I,
|
|
2732
|
-
indices:
|
|
2987
|
+
indices: i
|
|
2733
2988
|
};
|
|
2734
2989
|
}
|
|
2735
2990
|
/**
|
|
@@ -2748,59 +3003,59 @@ function wn(e, t, n, r) {
|
|
|
2748
3003
|
* limitations under the License.
|
|
2749
3004
|
* =============================================================================
|
|
2750
3005
|
*/
|
|
2751
|
-
const
|
|
3006
|
+
const zs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2752
3007
|
__proto__: null,
|
|
2753
|
-
addImpl:
|
|
2754
|
-
bincountImpl:
|
|
2755
|
-
bincountReduceImpl:
|
|
2756
|
-
bitwiseAndImpl:
|
|
2757
|
-
castImpl:
|
|
2758
|
-
ceilImpl:
|
|
2759
|
-
concatImpl:
|
|
2760
|
-
equalImpl:
|
|
2761
|
-
expImpl:
|
|
2762
|
-
expm1Impl:
|
|
2763
|
-
floorDivImpl:
|
|
2764
|
-
floorImpl:
|
|
2765
|
-
gatherNdImpl:
|
|
2766
|
-
gatherV2Impl:
|
|
2767
|
-
greaterEqualImpl:
|
|
2768
|
-
greaterImpl:
|
|
2769
|
-
lessEqualImpl:
|
|
2770
|
-
lessImpl:
|
|
2771
|
-
linSpaceImpl:
|
|
2772
|
-
logImpl:
|
|
2773
|
-
maxImpl:
|
|
2774
|
-
maximumImpl:
|
|
2775
|
-
minimumImpl:
|
|
2776
|
-
multiplyImpl:
|
|
2777
|
-
negImpl:
|
|
2778
|
-
notEqualImpl:
|
|
2779
|
-
prodImpl:
|
|
2780
|
-
raggedGatherImpl:
|
|
2781
|
-
raggedRangeImpl:
|
|
2782
|
-
raggedTensorToTensorImpl:
|
|
2783
|
-
rangeImpl:
|
|
2784
|
-
rsqrtImpl:
|
|
2785
|
-
scatterImpl:
|
|
2786
|
-
sigmoidImpl:
|
|
2787
|
-
simpleAbsImpl:
|
|
2788
|
-
sliceImpl:
|
|
2789
|
-
sparseFillEmptyRowsImpl:
|
|
2790
|
-
sparseReshapeImpl:
|
|
2791
|
-
sparseSegmentReductionImpl:
|
|
2792
|
-
sqrtImpl:
|
|
2793
|
-
squaredDifferenceImpl:
|
|
2794
|
-
staticRegexReplaceImpl:
|
|
2795
|
-
stridedSliceImpl:
|
|
2796
|
-
stringNGramsImpl:
|
|
2797
|
-
stringSplitImpl:
|
|
2798
|
-
stringToHashBucketFastImpl:
|
|
2799
|
-
subImpl:
|
|
2800
|
-
tileImpl:
|
|
2801
|
-
topKImpl:
|
|
2802
|
-
transposeImpl:
|
|
2803
|
-
uniqueImpl:
|
|
3008
|
+
addImpl: he,
|
|
3009
|
+
bincountImpl: _n,
|
|
3010
|
+
bincountReduceImpl: Vn,
|
|
3011
|
+
bitwiseAndImpl: fe,
|
|
3012
|
+
castImpl: ue,
|
|
3013
|
+
ceilImpl: de,
|
|
3014
|
+
concatImpl: $n,
|
|
3015
|
+
equalImpl: me,
|
|
3016
|
+
expImpl: pe,
|
|
3017
|
+
expm1Impl: Ie,
|
|
3018
|
+
floorDivImpl: be,
|
|
3019
|
+
floorImpl: we,
|
|
3020
|
+
gatherNdImpl: Hn,
|
|
3021
|
+
gatherV2Impl: Kn,
|
|
3022
|
+
greaterEqualImpl: Ee,
|
|
3023
|
+
greaterImpl: xe,
|
|
3024
|
+
lessEqualImpl: ye,
|
|
3025
|
+
lessImpl: Fe,
|
|
3026
|
+
linSpaceImpl: ts,
|
|
3027
|
+
logImpl: ke,
|
|
3028
|
+
maxImpl: ns,
|
|
3029
|
+
maximumImpl: Ne,
|
|
3030
|
+
minimumImpl: Se,
|
|
3031
|
+
multiplyImpl: yt,
|
|
3032
|
+
negImpl: ve,
|
|
3033
|
+
notEqualImpl: Te,
|
|
3034
|
+
prodImpl: Ce,
|
|
3035
|
+
raggedGatherImpl: ps,
|
|
3036
|
+
raggedRangeImpl: Is,
|
|
3037
|
+
raggedTensorToTensorImpl: ws,
|
|
3038
|
+
rangeImpl: bs,
|
|
3039
|
+
rsqrtImpl: qe,
|
|
3040
|
+
scatterImpl: Es,
|
|
3041
|
+
sigmoidImpl: Fs,
|
|
3042
|
+
simpleAbsImpl: le,
|
|
3043
|
+
sliceImpl: Ue,
|
|
3044
|
+
sparseFillEmptyRowsImpl: Ns,
|
|
3045
|
+
sparseReshapeImpl: Ss,
|
|
3046
|
+
sparseSegmentReductionImpl: vs,
|
|
3047
|
+
sqrtImpl: Ts,
|
|
3048
|
+
squaredDifferenceImpl: Me,
|
|
3049
|
+
staticRegexReplaceImpl: Oe,
|
|
3050
|
+
stridedSliceImpl: qs,
|
|
3051
|
+
stringNGramsImpl: Ms,
|
|
3052
|
+
stringSplitImpl: Ls,
|
|
3053
|
+
stringToHashBucketFastImpl: As,
|
|
3054
|
+
subImpl: Le,
|
|
3055
|
+
tileImpl: Ds,
|
|
3056
|
+
topKImpl: Ws,
|
|
3057
|
+
transposeImpl: Re,
|
|
3058
|
+
uniqueImpl: $s
|
|
2804
3059
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2805
3060
|
/**
|
|
2806
3061
|
* @license
|
|
@@ -2818,9 +3073,127 @@ const pn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
2818
3073
|
* limitations under the License.
|
|
2819
3074
|
* =============================================================================
|
|
2820
3075
|
*/
|
|
2821
|
-
const { logImpl:
|
|
3076
|
+
const { addImpl: Po, bincountImpl: Co, bincountReduceImpl: qo, bitwiseAndImpl: Uo, castImpl: Mo, ceilImpl: Oo, concatImpl: Lo, equalImpl: Ao, expImpl: _o, expm1Impl: Vo, floorImpl: Do, gatherNdImpl: Wo, gatherV2Impl: $o, greaterImpl: zo, greaterEqualImpl: Bo, lessImpl: Go, lessEqualImpl: jo, linSpaceImpl: Zo, logImpl: Ho, maxImpl: Ko, maximumImpl: Xo, minimumImpl: Yo, multiplyImpl: Jo, negImpl: Qo, notEqualImpl: tr, prodImpl: er, raggedGatherImpl: nr, raggedRangeImpl: sr, raggedTensorToTensorImpl: or, rangeImpl: rr, rsqrtImpl: ar, scatterImpl: ir, sigmoidImpl: lr, simpleAbsImpl: cr, sliceImpl: ur, sparseFillEmptyRowsImpl: hr, sparseReshapeImpl: fr, sparseSegmentReductionImpl: gr, sqrtImpl: dr, staticRegexReplaceImpl: mr, stridedSliceImpl: pr, stringNGramsImpl: Ir, stringSplitImpl: wr, stringToHashBucketFastImpl: br, subImpl: xr, tileImpl: Er, topKImpl: Fr, transposeImpl: yr, uniqueImpl: kr } = zs;
|
|
2822
3077
|
export {
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
3078
|
+
uo as $,
|
|
3079
|
+
ps as A,
|
|
3080
|
+
Is as B,
|
|
3081
|
+
ws as C,
|
|
3082
|
+
bs as D,
|
|
3083
|
+
Es as E,
|
|
3084
|
+
Ns as F,
|
|
3085
|
+
Ss as G,
|
|
3086
|
+
vs as H,
|
|
3087
|
+
qs as I,
|
|
3088
|
+
Ms as J,
|
|
3089
|
+
Ls as K,
|
|
3090
|
+
As as L,
|
|
3091
|
+
Ds as M,
|
|
3092
|
+
Ws as N,
|
|
3093
|
+
$s as O,
|
|
3094
|
+
zn as P,
|
|
3095
|
+
Ys as Q,
|
|
3096
|
+
no as R,
|
|
3097
|
+
so as S,
|
|
3098
|
+
eo as T,
|
|
3099
|
+
oo as U,
|
|
3100
|
+
Js as V,
|
|
3101
|
+
ro as W,
|
|
3102
|
+
ao as X,
|
|
3103
|
+
io as Y,
|
|
3104
|
+
lo as Z,
|
|
3105
|
+
co as _,
|
|
3106
|
+
nt as a,
|
|
3107
|
+
br as a$,
|
|
3108
|
+
ho as a0,
|
|
3109
|
+
Qs as a1,
|
|
3110
|
+
fo as a2,
|
|
3111
|
+
go as a3,
|
|
3112
|
+
mo as a4,
|
|
3113
|
+
po as a5,
|
|
3114
|
+
Io as a6,
|
|
3115
|
+
wo as a7,
|
|
3116
|
+
bo as a8,
|
|
3117
|
+
xo as a9,
|
|
3118
|
+
$o as aA,
|
|
3119
|
+
zo as aB,
|
|
3120
|
+
Bo as aC,
|
|
3121
|
+
Go as aD,
|
|
3122
|
+
jo as aE,
|
|
3123
|
+
Zo as aF,
|
|
3124
|
+
Ho as aG,
|
|
3125
|
+
Xo as aH,
|
|
3126
|
+
Yo as aI,
|
|
3127
|
+
xr as aJ,
|
|
3128
|
+
Qo as aK,
|
|
3129
|
+
er as aL,
|
|
3130
|
+
nr as aM,
|
|
3131
|
+
sr as aN,
|
|
3132
|
+
or as aO,
|
|
3133
|
+
rr as aP,
|
|
3134
|
+
ar as aQ,
|
|
3135
|
+
lr as aR,
|
|
3136
|
+
hr as aS,
|
|
3137
|
+
fr as aT,
|
|
3138
|
+
gr as aU,
|
|
3139
|
+
ir as aV,
|
|
3140
|
+
dr as aW,
|
|
3141
|
+
mr as aX,
|
|
3142
|
+
pr as aY,
|
|
3143
|
+
Ir as aZ,
|
|
3144
|
+
wr as a_,
|
|
3145
|
+
Fo as aa,
|
|
3146
|
+
to as ab,
|
|
3147
|
+
yo as ac,
|
|
3148
|
+
ko as ad,
|
|
3149
|
+
No as ae,
|
|
3150
|
+
So as af,
|
|
3151
|
+
vo as ag,
|
|
3152
|
+
To as ah,
|
|
3153
|
+
Ro as ai,
|
|
3154
|
+
Eo as aj,
|
|
3155
|
+
cr as ak,
|
|
3156
|
+
Jo as al,
|
|
3157
|
+
Po as am,
|
|
3158
|
+
ur as an,
|
|
3159
|
+
Co as ao,
|
|
3160
|
+
Uo as ap,
|
|
3161
|
+
tr as aq,
|
|
3162
|
+
Mo as ar,
|
|
3163
|
+
Oo as as,
|
|
3164
|
+
Lo as at,
|
|
3165
|
+
qo as au,
|
|
3166
|
+
Ao as av,
|
|
3167
|
+
_o as aw,
|
|
3168
|
+
Vo as ax,
|
|
3169
|
+
Do as ay,
|
|
3170
|
+
Wo as az,
|
|
3171
|
+
An as b,
|
|
3172
|
+
Er as b0,
|
|
3173
|
+
Fr as b1,
|
|
3174
|
+
kr as b2,
|
|
3175
|
+
W as c,
|
|
3176
|
+
Pe as d,
|
|
3177
|
+
z as e,
|
|
3178
|
+
ks as f,
|
|
3179
|
+
_n as g,
|
|
3180
|
+
mt as h,
|
|
3181
|
+
Et as i,
|
|
3182
|
+
$n as j,
|
|
3183
|
+
Vn as k,
|
|
3184
|
+
lt as l,
|
|
3185
|
+
Ko as m,
|
|
3186
|
+
as as n,
|
|
3187
|
+
Vs as o,
|
|
3188
|
+
Hn as p,
|
|
3189
|
+
Kn as q,
|
|
3190
|
+
ce as r,
|
|
3191
|
+
ys as s,
|
|
3192
|
+
yr as t,
|
|
3193
|
+
ge as u,
|
|
3194
|
+
ts as v,
|
|
3195
|
+
Re as w,
|
|
3196
|
+
ns as x,
|
|
3197
|
+
Bn as y,
|
|
3198
|
+
xt as z
|
|
2826
3199
|
};
|