@genai-fi/nanogpt 0.4.3 → 0.4.4
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 +3 -3
- package/dist/NanoGPTModel.js +7 -7
- package/dist/Reshape-CiAY8ltP.js +212 -0
- package/dist/TeachableLLM.js +7 -1
- package/dist/{TiedEmbedding-CnJ1bx4q.js → TiedEmbedding-DznFwzcB.js} +244 -244
- package/dist/{axis_util-BgTGy5w8.js → axis_util-QP0LdI1v.js} +1 -1
- package/dist/{concat-CuRsVY-K.js → concat-DvWM7HGZ.js} +1 -1
- package/dist/data/parquet.js +9 -6
- package/dist/data/textLoader.js +6 -5
- package/dist/{dropout-DfDdklfL.js → dropout-DFEXTPV0.js} +4 -4
- package/dist/{gather-ZYRWhmXR.js → gather-C5D8PxwA.js} +1 -1
- package/dist/gpgpu_math-CUzjlO9A.js +23 -0
- package/dist/{index-C4JCoBvj.js → index--6vO-cOz.js} +87 -87
- package/dist/{kernel_funcs_utils-CAd1h9X1.js → kernel_funcs_utils-C6YBCuOt.js} +72 -91
- package/dist/layers/CausalSelfAttention.js +8 -8
- package/dist/layers/MLP.js +31 -33
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +3 -3
- package/dist/layers/TiedEmbedding.js +5 -5
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/{log_sum_exp-BswFnwOb.js → log_sum_exp-CiEy1aUe.js} +7 -7
- package/dist/main.js +25 -19
- package/dist/{mat_mul-415y5Qn2.js → mat_mul-BEHRPMh0.js} +1 -1
- package/dist/{max-CP_9O2Yd.js → max-BUShNgfh.js} +1 -1
- package/dist/{moments-CjeIaVdp.js → moments-DYOHXoRV.js} +5 -5
- package/dist/{norm-CZM380I3.js → norm-DSva3hI3.js} +13 -13
- package/dist/{ones-Bf3YR48P.js → ones-D6kB8bdY.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 +2 -2
- package/dist/ops/cpu/fusedSoftmax.js +2 -2
- package/dist/ops/cpu/gatherSub.js +4 -4
- package/dist/ops/cpu/gelu.js +1 -1
- package/dist/ops/cpu/matMulGelu.d.ts +1 -0
- package/dist/ops/cpu/matMulGelu.js +40 -0
- package/dist/ops/cpu/mulDropout.js +1 -1
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +4 -4
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.js +2 -2
- package/dist/ops/grads/gelu.js +24 -3
- package/dist/ops/grads/matMulGelu.d.ts +1 -0
- package/dist/ops/grads/matMulGelu.js +17 -0
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +1 -1
- package/dist/ops/matMulGelu.d.ts +3 -0
- package/dist/ops/matMulGelu.js +14 -0
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/node/sparseCrossEntropy.js +1 -1
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +689 -895
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/matMulGelu.d.ts +20 -0
- package/dist/ops/webgl/matMulGelu.js +166 -0
- package/dist/ops/webgl/mulDropout.js +1 -1
- 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/{range-9AzeApCc.js → range-C_vpUjBu.js} +1 -1
- package/dist/{reshape-Boe4DuIO.js → reshape-z51Eu-re.js} +1 -1
- package/dist/{sin-KmhiDuMa.js → sin-H567uayl.js} +1 -1
- package/dist/{slice_util-19zDNNSn.js → slice_util-BdhYwFY_.js} +2 -2
- package/dist/{softmax-Cujsg4ay.js → softmax-Dsxflvdl.js} +1 -1
- package/dist/{split-DbcNm1-i.js → split-B_k_jwud.js} +1 -1
- package/dist/{stack-D1YjmgKN.js → stack-CmqSdsfs.js} +1 -1
- package/dist/{sum-R28pucR5.js → sum-DdkDf2MG.js} +1 -1
- package/dist/{tensor-BVeHdl7V.js → tensor-BGYi41cj.js} +1 -1
- package/dist/{tensor2d-DqFGNs_K.js → tensor2d-DUr_htjt.js} +1 -1
- package/dist/{tfjs_backend-Cug-PH75.js → tfjs_backend-DuKis_xG.js} +46 -46
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +18 -18
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +5 -5
- package/dist/training/sparseCrossEntropy.js +4 -4
- package/dist/utilities/dummy.js +2 -2
- package/dist/utilities/generate.js +3 -3
- package/dist/utilities/load.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-LJT9Ld63.js → variable-BJTZ3jOy.js} +1 -1
- package/dist/{zeros-dnQxFgAD.js → zeros-8xl-W2DC.js} +1 -1
- package/package.json +1 -1
- package/dist/gelu-CnCt17Lk.js +0 -26
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { f as
|
|
3
|
-
import { c as
|
|
4
|
-
import { b as
|
|
5
|
-
import { r as
|
|
6
|
-
import { g as
|
|
7
|
-
|
|
1
|
+
import { a$ as qt, n as y, O as Ct, ac as J, b0 as nt, b1 as It, b2 as pt, b3 as ft, b4 as kt, Z as ot, ag as B, b5 as q, b6 as Ut, Q as Gt, j as jt, t as Zt, b7 as dt, ao as ct, b8 as tt, $ as ut, b9 as Bt, L as Ht, ba as Kt, r as Xt } from "../../index--6vO-cOz.js";
|
|
2
|
+
import { f as $t, a as Qt, g as yt, b as Yt, c as Jt } from "../../kernel_funcs_utils-C6YBCuOt.js";
|
|
3
|
+
import { c as mt, g as Tt, a as Vt, b as Mt, e as wt } from "../../axis_util-QP0LdI1v.js";
|
|
4
|
+
import { b as te, i as ee, c as ne } from "../../slice_util-BdhYwFY_.js";
|
|
5
|
+
import { r as oe } from "../../reshape-z51Eu-re.js";
|
|
6
|
+
import { g as se } from "../../_commonjsHelpers-ByX85dGu.js";
|
|
7
|
+
import { r as st } from "../../Reshape-CiAY8ltP.js";
|
|
8
|
+
function re(t, e) {
|
|
8
9
|
for (var n = 0; n < e.length; n++) {
|
|
9
10
|
const o = e[n];
|
|
10
11
|
if (typeof o != "string" && !Array.isArray(o)) {
|
|
@@ -20,10 +21,10 @@ function fe(t, e) {
|
|
|
20
21
|
}
|
|
21
22
|
return Object.freeze(Object.defineProperty(t, Symbol.toStringTag, { value: "Module" }));
|
|
22
23
|
}
|
|
23
|
-
var
|
|
24
|
-
function
|
|
25
|
-
if (
|
|
26
|
-
|
|
24
|
+
var ht, xt;
|
|
25
|
+
function ie() {
|
|
26
|
+
if (xt) return ht;
|
|
27
|
+
xt = 1, ht = e;
|
|
27
28
|
var t = null;
|
|
28
29
|
try {
|
|
29
30
|
t = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
|
|
@@ -316,8 +317,8 @@ function de() {
|
|
|
316
317
|
])), {}).exports;
|
|
317
318
|
} catch {
|
|
318
319
|
}
|
|
319
|
-
function e(I, l,
|
|
320
|
-
this.low = I | 0, this.high = l | 0, this.unsigned = !!
|
|
320
|
+
function e(I, l, E) {
|
|
321
|
+
this.low = I | 0, this.high = l | 0, this.unsigned = !!E;
|
|
321
322
|
}
|
|
322
323
|
e.prototype.__isLong__, Object.defineProperty(e.prototype, "__isLong__", { value: !0 });
|
|
323
324
|
function n(I) {
|
|
@@ -326,74 +327,74 @@ function de() {
|
|
|
326
327
|
e.isLong = n;
|
|
327
328
|
var o = {}, s = {};
|
|
328
329
|
function r(I, l) {
|
|
329
|
-
var
|
|
330
|
-
return l ? (I >>>= 0, (T = 0 <= I && I < 256) && (
|
|
330
|
+
var E, F, T;
|
|
331
|
+
return l ? (I >>>= 0, (T = 0 <= I && I < 256) && (F = s[I], F) ? F : (E = i(I, (I | 0) < 0 ? -1 : 0, !0), T && (s[I] = E), E)) : (I |= 0, (T = -128 <= I && I < 128) && (F = o[I], F) ? F : (E = i(I, I < 0 ? -1 : 0, !1), T && (o[I] = E), E));
|
|
331
332
|
}
|
|
332
333
|
e.fromInt = r;
|
|
333
|
-
function
|
|
334
|
+
function a(I, l) {
|
|
334
335
|
if (isNaN(I))
|
|
335
336
|
return l ? x : g;
|
|
336
337
|
if (l) {
|
|
337
338
|
if (I < 0)
|
|
338
339
|
return x;
|
|
339
340
|
if (I >= m)
|
|
340
|
-
return
|
|
341
|
+
return L;
|
|
341
342
|
} else {
|
|
342
343
|
if (I <= -b)
|
|
343
344
|
return _;
|
|
344
345
|
if (I + 1 >= b)
|
|
345
|
-
return
|
|
346
|
+
return D;
|
|
346
347
|
}
|
|
347
|
-
return I < 0 ?
|
|
348
|
+
return I < 0 ? a(-I, l).neg() : i(I % p | 0, I / p | 0, l);
|
|
348
349
|
}
|
|
349
|
-
e.fromNumber =
|
|
350
|
-
function
|
|
351
|
-
return new e(I, l,
|
|
350
|
+
e.fromNumber = a;
|
|
351
|
+
function i(I, l, E) {
|
|
352
|
+
return new e(I, l, E);
|
|
352
353
|
}
|
|
353
|
-
e.fromBits =
|
|
354
|
+
e.fromBits = i;
|
|
354
355
|
var u = Math.pow;
|
|
355
|
-
function c(I, l,
|
|
356
|
+
function c(I, l, E) {
|
|
356
357
|
if (I.length === 0)
|
|
357
358
|
throw Error("empty string");
|
|
358
359
|
if (I === "NaN" || I === "Infinity" || I === "+Infinity" || I === "-Infinity")
|
|
359
360
|
return g;
|
|
360
|
-
if (typeof l == "number" ? (
|
|
361
|
+
if (typeof l == "number" ? (E = l, l = !1) : l = !!l, E = E || 10, E < 2 || 36 < E)
|
|
361
362
|
throw RangeError("radix");
|
|
362
|
-
var
|
|
363
|
-
if ((
|
|
363
|
+
var F;
|
|
364
|
+
if ((F = I.indexOf("-")) > 0)
|
|
364
365
|
throw Error("interior hyphen");
|
|
365
|
-
if (
|
|
366
|
-
return c(I.substring(1), l,
|
|
367
|
-
for (var T =
|
|
368
|
-
var
|
|
369
|
-
if (
|
|
370
|
-
var
|
|
371
|
-
|
|
366
|
+
if (F === 0)
|
|
367
|
+
return c(I.substring(1), l, E).neg();
|
|
368
|
+
for (var T = a(u(E, 8)), $ = g, N = 0; N < I.length; N += 8) {
|
|
369
|
+
var k = Math.min(8, I.length - N), G = parseInt(I.substring(N, N + k), E);
|
|
370
|
+
if (k < 8) {
|
|
371
|
+
var z = a(u(E, k));
|
|
372
|
+
$ = $.mul(z).add(a(G));
|
|
372
373
|
} else
|
|
373
|
-
|
|
374
|
+
$ = $.mul(T), $ = $.add(a(G));
|
|
374
375
|
}
|
|
375
|
-
return
|
|
376
|
+
return $.unsigned = l, $;
|
|
376
377
|
}
|
|
377
378
|
e.fromString = c;
|
|
378
379
|
function h(I, l) {
|
|
379
|
-
return typeof I == "number" ?
|
|
380
|
+
return typeof I == "number" ? a(I, l) : typeof I == "string" ? c(I, l) : i(I.low, I.high, typeof l == "boolean" ? l : I.unsigned);
|
|
380
381
|
}
|
|
381
382
|
e.fromValue = h;
|
|
382
383
|
var f = 65536, w = 1 << 24, p = f * f, m = p * p, b = m / 2, d = r(w), g = r(0);
|
|
383
384
|
e.ZERO = g;
|
|
384
385
|
var x = r(0, !0);
|
|
385
386
|
e.UZERO = x;
|
|
386
|
-
var
|
|
387
|
-
e.ONE =
|
|
388
|
-
var
|
|
389
|
-
e.UONE =
|
|
387
|
+
var O = r(1);
|
|
388
|
+
e.ONE = O;
|
|
389
|
+
var v = r(1, !0);
|
|
390
|
+
e.UONE = v;
|
|
390
391
|
var V = r(-1);
|
|
391
392
|
e.NEG_ONE = V;
|
|
392
|
-
var
|
|
393
|
-
e.MAX_VALUE =
|
|
394
|
-
var
|
|
395
|
-
e.MAX_UNSIGNED_VALUE =
|
|
396
|
-
var _ =
|
|
393
|
+
var D = i(-1, 2147483647, !1);
|
|
394
|
+
e.MAX_VALUE = D;
|
|
395
|
+
var L = i(-1, -1, !0);
|
|
396
|
+
e.MAX_UNSIGNED_VALUE = L;
|
|
397
|
+
var _ = i(0, -2147483648, !1);
|
|
397
398
|
e.MIN_VALUE = _;
|
|
398
399
|
var S = e.prototype;
|
|
399
400
|
return S.toInt = function() {
|
|
@@ -407,17 +408,17 @@ function de() {
|
|
|
407
408
|
return "0";
|
|
408
409
|
if (this.isNegative())
|
|
409
410
|
if (this.eq(_)) {
|
|
410
|
-
var
|
|
411
|
-
return
|
|
411
|
+
var E = a(l), F = this.div(E), T = F.mul(E).sub(this);
|
|
412
|
+
return F.toString(l) + T.toInt().toString(l);
|
|
412
413
|
} else
|
|
413
414
|
return "-" + this.neg().toString(l);
|
|
414
|
-
for (var
|
|
415
|
-
var G =
|
|
416
|
-
if (
|
|
417
|
-
return
|
|
418
|
-
for (;
|
|
419
|
-
|
|
420
|
-
|
|
415
|
+
for (var $ = a(u(l, 6), this.unsigned), N = this, k = ""; ; ) {
|
|
416
|
+
var G = N.div($), z = N.sub(G.mul($)).toInt() >>> 0, M = z.toString(l);
|
|
417
|
+
if (N = G, N.isZero())
|
|
418
|
+
return M + k;
|
|
419
|
+
for (; M.length < 6; )
|
|
420
|
+
M = "0" + M;
|
|
421
|
+
k = "" + M + k;
|
|
421
422
|
}
|
|
422
423
|
}, S.getHighBits = function() {
|
|
423
424
|
return this.high;
|
|
@@ -430,9 +431,9 @@ function de() {
|
|
|
430
431
|
}, S.getNumBitsAbs = function() {
|
|
431
432
|
if (this.isNegative())
|
|
432
433
|
return this.eq(_) ? 64 : this.neg().getNumBitsAbs();
|
|
433
|
-
for (var l = this.high != 0 ? this.high : this.low,
|
|
434
|
+
for (var l = this.high != 0 ? this.high : this.low, E = 31; E > 0 && (l & 1 << E) == 0; E--)
|
|
434
435
|
;
|
|
435
|
-
return this.high != 0 ?
|
|
436
|
+
return this.high != 0 ? E + 33 : E + 1;
|
|
436
437
|
}, S.isZero = function() {
|
|
437
438
|
return this.high === 0 && this.low === 0;
|
|
438
439
|
}, S.eqz = S.isZero, S.isNegative = function() {
|
|
@@ -473,27 +474,27 @@ function de() {
|
|
|
473
474
|
}, S.gte = S.greaterThanOrEqual, S.ge = S.greaterThanOrEqual, S.compare = function(l) {
|
|
474
475
|
if (n(l) || (l = h(l)), this.eq(l))
|
|
475
476
|
return 0;
|
|
476
|
-
var
|
|
477
|
-
return
|
|
477
|
+
var E = this.isNegative(), F = l.isNegative();
|
|
478
|
+
return E && !F ? -1 : !E && F ? 1 : this.unsigned ? l.high >>> 0 > this.high >>> 0 || l.high === this.high && l.low >>> 0 > this.low >>> 0 ? -1 : 1 : this.sub(l).isNegative() ? -1 : 1;
|
|
478
479
|
}, S.comp = S.compare, S.negate = function() {
|
|
479
|
-
return !this.unsigned && this.eq(_) ? _ : this.not().add(
|
|
480
|
+
return !this.unsigned && this.eq(_) ? _ : this.not().add(O);
|
|
480
481
|
}, S.neg = S.negate, S.add = function(l) {
|
|
481
482
|
n(l) || (l = h(l));
|
|
482
|
-
var
|
|
483
|
-
return U +=
|
|
483
|
+
var E = this.high >>> 16, F = this.high & 65535, T = this.low >>> 16, $ = this.low & 65535, N = l.high >>> 16, k = l.high & 65535, G = l.low >>> 16, z = l.low & 65535, M = 0, j = 0, P = 0, U = 0;
|
|
484
|
+
return U += $ + z, P += U >>> 16, U &= 65535, P += T + G, j += P >>> 16, P &= 65535, j += F + k, M += j >>> 16, j &= 65535, M += E + N, M &= 65535, i(P << 16 | U, M << 16 | j, this.unsigned);
|
|
484
485
|
}, S.subtract = function(l) {
|
|
485
486
|
return n(l) || (l = h(l)), this.add(l.neg());
|
|
486
487
|
}, S.sub = S.subtract, S.multiply = function(l) {
|
|
487
488
|
if (this.isZero())
|
|
488
489
|
return g;
|
|
489
490
|
if (n(l) || (l = h(l)), t) {
|
|
490
|
-
var
|
|
491
|
+
var E = t.mul(
|
|
491
492
|
this.low,
|
|
492
493
|
this.high,
|
|
493
494
|
l.low,
|
|
494
495
|
l.high
|
|
495
496
|
);
|
|
496
|
-
return
|
|
497
|
+
return i(E, t.get_high(), this.unsigned);
|
|
497
498
|
}
|
|
498
499
|
if (l.isZero())
|
|
499
500
|
return g;
|
|
@@ -506,137 +507,137 @@ function de() {
|
|
|
506
507
|
if (l.isNegative())
|
|
507
508
|
return this.mul(l.neg()).neg();
|
|
508
509
|
if (this.lt(d) && l.lt(d))
|
|
509
|
-
return
|
|
510
|
-
var
|
|
511
|
-
return rt +=
|
|
510
|
+
return a(this.toNumber() * l.toNumber(), this.unsigned);
|
|
511
|
+
var F = this.high >>> 16, T = this.high & 65535, $ = this.low >>> 16, N = this.low & 65535, k = l.high >>> 16, G = l.high & 65535, z = l.low >>> 16, M = l.low & 65535, j = 0, P = 0, U = 0, rt = 0;
|
|
512
|
+
return rt += N * M, U += rt >>> 16, rt &= 65535, U += $ * M, P += U >>> 16, U &= 65535, U += N * z, P += U >>> 16, U &= 65535, P += T * M, j += P >>> 16, P &= 65535, P += $ * z, j += P >>> 16, P &= 65535, P += N * G, j += P >>> 16, P &= 65535, j += F * M + T * z + $ * G + N * k, j &= 65535, i(U << 16 | rt, j << 16 | P, this.unsigned);
|
|
512
513
|
}, S.mul = S.multiply, S.divide = function(l) {
|
|
513
514
|
if (n(l) || (l = h(l)), l.isZero())
|
|
514
515
|
throw Error("division by zero");
|
|
515
516
|
if (t) {
|
|
516
517
|
if (!this.unsigned && this.high === -2147483648 && l.low === -1 && l.high === -1)
|
|
517
518
|
return this;
|
|
518
|
-
var
|
|
519
|
+
var E = (this.unsigned ? t.div_u : t.div_s)(
|
|
519
520
|
this.low,
|
|
520
521
|
this.high,
|
|
521
522
|
l.low,
|
|
522
523
|
l.high
|
|
523
524
|
);
|
|
524
|
-
return
|
|
525
|
+
return i(E, t.get_high(), this.unsigned);
|
|
525
526
|
}
|
|
526
527
|
if (this.isZero())
|
|
527
528
|
return this.unsigned ? x : g;
|
|
528
|
-
var
|
|
529
|
+
var F, T, $;
|
|
529
530
|
if (this.unsigned) {
|
|
530
531
|
if (l.unsigned || (l = l.toUnsigned()), l.gt(this))
|
|
531
532
|
return x;
|
|
532
533
|
if (l.gt(this.shru(1)))
|
|
533
|
-
return
|
|
534
|
-
|
|
534
|
+
return v;
|
|
535
|
+
$ = x;
|
|
535
536
|
} else {
|
|
536
537
|
if (this.eq(_)) {
|
|
537
|
-
if (l.eq(
|
|
538
|
+
if (l.eq(O) || l.eq(V))
|
|
538
539
|
return _;
|
|
539
540
|
if (l.eq(_))
|
|
540
|
-
return
|
|
541
|
-
var
|
|
542
|
-
return
|
|
541
|
+
return O;
|
|
542
|
+
var N = this.shr(1);
|
|
543
|
+
return F = N.div(l).shl(1), F.eq(g) ? l.isNegative() ? O : V : (T = this.sub(l.mul(F)), $ = F.add(T.div(l)), $);
|
|
543
544
|
} else if (l.eq(_))
|
|
544
545
|
return this.unsigned ? x : g;
|
|
545
546
|
if (this.isNegative())
|
|
546
547
|
return l.isNegative() ? this.neg().div(l.neg()) : this.neg().div(l).neg();
|
|
547
548
|
if (l.isNegative())
|
|
548
549
|
return this.div(l.neg()).neg();
|
|
549
|
-
|
|
550
|
+
$ = g;
|
|
550
551
|
}
|
|
551
552
|
for (T = this; T.gte(l); ) {
|
|
552
|
-
|
|
553
|
-
for (var
|
|
554
|
-
|
|
555
|
-
|
|
553
|
+
F = Math.max(1, Math.floor(T.toNumber() / l.toNumber()));
|
|
554
|
+
for (var k = Math.ceil(Math.log(F) / Math.LN2), G = k <= 48 ? 1 : u(2, k - 48), z = a(F), M = z.mul(l); M.isNegative() || M.gt(T); )
|
|
555
|
+
F -= G, z = a(F, this.unsigned), M = z.mul(l);
|
|
556
|
+
z.isZero() && (z = O), $ = $.add(z), T = T.sub(M);
|
|
556
557
|
}
|
|
557
|
-
return
|
|
558
|
+
return $;
|
|
558
559
|
}, S.div = S.divide, S.modulo = function(l) {
|
|
559
560
|
if (n(l) || (l = h(l)), t) {
|
|
560
|
-
var
|
|
561
|
+
var E = (this.unsigned ? t.rem_u : t.rem_s)(
|
|
561
562
|
this.low,
|
|
562
563
|
this.high,
|
|
563
564
|
l.low,
|
|
564
565
|
l.high
|
|
565
566
|
);
|
|
566
|
-
return
|
|
567
|
+
return i(E, t.get_high(), this.unsigned);
|
|
567
568
|
}
|
|
568
569
|
return this.sub(this.div(l).mul(l));
|
|
569
570
|
}, S.mod = S.modulo, S.rem = S.modulo, S.not = function() {
|
|
570
|
-
return
|
|
571
|
+
return i(~this.low, ~this.high, this.unsigned);
|
|
571
572
|
}, S.and = function(l) {
|
|
572
|
-
return n(l) || (l = h(l)),
|
|
573
|
+
return n(l) || (l = h(l)), i(this.low & l.low, this.high & l.high, this.unsigned);
|
|
573
574
|
}, S.or = function(l) {
|
|
574
|
-
return n(l) || (l = h(l)),
|
|
575
|
+
return n(l) || (l = h(l)), i(this.low | l.low, this.high | l.high, this.unsigned);
|
|
575
576
|
}, S.xor = function(l) {
|
|
576
|
-
return n(l) || (l = h(l)),
|
|
577
|
+
return n(l) || (l = h(l)), i(this.low ^ l.low, this.high ^ l.high, this.unsigned);
|
|
577
578
|
}, S.shiftLeft = function(l) {
|
|
578
|
-
return n(l) && (l = l.toInt()), (l &= 63) === 0 ? this : l < 32 ?
|
|
579
|
+
return n(l) && (l = l.toInt()), (l &= 63) === 0 ? this : l < 32 ? i(this.low << l, this.high << l | this.low >>> 32 - l, this.unsigned) : i(0, this.low << l - 32, this.unsigned);
|
|
579
580
|
}, S.shl = S.shiftLeft, S.shiftRight = function(l) {
|
|
580
|
-
return n(l) && (l = l.toInt()), (l &= 63) === 0 ? this : l < 32 ?
|
|
581
|
+
return n(l) && (l = l.toInt()), (l &= 63) === 0 ? this : l < 32 ? i(this.low >>> l | this.high << 32 - l, this.high >> l, this.unsigned) : i(this.high >> l - 32, this.high >= 0 ? 0 : -1, this.unsigned);
|
|
581
582
|
}, S.shr = S.shiftRight, S.shiftRightUnsigned = function(l) {
|
|
582
583
|
if (n(l) && (l = l.toInt()), l &= 63, l === 0)
|
|
583
584
|
return this;
|
|
584
|
-
var
|
|
585
|
+
var E = this.high;
|
|
585
586
|
if (l < 32) {
|
|
586
|
-
var
|
|
587
|
-
return
|
|
588
|
-
} else return l === 32 ?
|
|
587
|
+
var F = this.low;
|
|
588
|
+
return i(F >>> l | E << 32 - l, E >>> l, this.unsigned);
|
|
589
|
+
} else return l === 32 ? i(E, 0, this.unsigned) : i(E >>> l - 32, 0, this.unsigned);
|
|
589
590
|
}, S.shru = S.shiftRightUnsigned, S.shr_u = S.shiftRightUnsigned, S.toSigned = function() {
|
|
590
|
-
return this.unsigned ?
|
|
591
|
+
return this.unsigned ? i(this.low, this.high, !1) : this;
|
|
591
592
|
}, S.toUnsigned = function() {
|
|
592
|
-
return this.unsigned ? this :
|
|
593
|
+
return this.unsigned ? this : i(this.low, this.high, !0);
|
|
593
594
|
}, S.toBytes = function(l) {
|
|
594
595
|
return l ? this.toBytesLE() : this.toBytesBE();
|
|
595
596
|
}, S.toBytesLE = function() {
|
|
596
|
-
var l = this.high,
|
|
597
|
+
var l = this.high, E = this.low;
|
|
597
598
|
return [
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
599
|
+
E & 255,
|
|
600
|
+
E >>> 8 & 255,
|
|
601
|
+
E >>> 16 & 255,
|
|
602
|
+
E >>> 24,
|
|
602
603
|
l & 255,
|
|
603
604
|
l >>> 8 & 255,
|
|
604
605
|
l >>> 16 & 255,
|
|
605
606
|
l >>> 24
|
|
606
607
|
];
|
|
607
608
|
}, S.toBytesBE = function() {
|
|
608
|
-
var l = this.high,
|
|
609
|
+
var l = this.high, E = this.low;
|
|
609
610
|
return [
|
|
610
611
|
l >>> 24,
|
|
611
612
|
l >>> 16 & 255,
|
|
612
613
|
l >>> 8 & 255,
|
|
613
614
|
l & 255,
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
615
|
+
E >>> 24,
|
|
616
|
+
E >>> 16 & 255,
|
|
617
|
+
E >>> 8 & 255,
|
|
618
|
+
E & 255
|
|
618
619
|
];
|
|
619
|
-
}, e.fromBytes = function(l,
|
|
620
|
-
return
|
|
621
|
-
}, e.fromBytesLE = function(l,
|
|
620
|
+
}, e.fromBytes = function(l, E, F) {
|
|
621
|
+
return F ? e.fromBytesLE(l, E) : e.fromBytesBE(l, E);
|
|
622
|
+
}, e.fromBytesLE = function(l, E) {
|
|
622
623
|
return new e(
|
|
623
624
|
l[0] | l[1] << 8 | l[2] << 16 | l[3] << 24,
|
|
624
625
|
l[4] | l[5] << 8 | l[6] << 16 | l[7] << 24,
|
|
625
|
-
|
|
626
|
+
E
|
|
626
627
|
);
|
|
627
|
-
}, e.fromBytesBE = function(l,
|
|
628
|
+
}, e.fromBytesBE = function(l, E) {
|
|
628
629
|
return new e(
|
|
629
630
|
l[4] << 24 | l[5] << 16 | l[6] << 8 | l[7],
|
|
630
631
|
l[0] << 24 | l[1] << 16 | l[2] << 8 | l[3],
|
|
631
|
-
|
|
632
|
+
E
|
|
632
633
|
);
|
|
633
|
-
},
|
|
634
|
+
}, ht;
|
|
634
635
|
}
|
|
635
|
-
var
|
|
636
|
-
const
|
|
636
|
+
var Lt = ie();
|
|
637
|
+
const _t = /* @__PURE__ */ se(Lt), ae = /* @__PURE__ */ re({
|
|
637
638
|
__proto__: null,
|
|
638
|
-
default:
|
|
639
|
-
}, [
|
|
639
|
+
default: _t
|
|
640
|
+
}, [Lt]);
|
|
640
641
|
/**
|
|
641
642
|
* @license
|
|
642
643
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -653,82 +654,82 @@ const Pt = /* @__PURE__ */ he(zt), ge = /* @__PURE__ */ fe({
|
|
|
653
654
|
* limitations under the License.
|
|
654
655
|
* =============================================================================
|
|
655
656
|
*/
|
|
656
|
-
const
|
|
657
|
+
const Y = (
|
|
657
658
|
// tslint:disable-next-line
|
|
658
|
-
|
|
659
|
+
_t || ae
|
|
659
660
|
);
|
|
660
|
-
function
|
|
661
|
-
return
|
|
661
|
+
function lt(t) {
|
|
662
|
+
return Y.fromString(t, !0, 16);
|
|
662
663
|
}
|
|
663
|
-
const
|
|
664
|
-
function
|
|
664
|
+
const Nt = lt("c3a5c85c97cb3127"), Q = lt("b492b66fbe98f273"), W = lt("9ae16a3b2f90404f");
|
|
665
|
+
function gt(t) {
|
|
665
666
|
return t.xor(t.shru(47));
|
|
666
667
|
}
|
|
667
|
-
function
|
|
668
|
+
function At(t, e, n) {
|
|
668
669
|
const o = t.slice(e, e + n);
|
|
669
|
-
return
|
|
670
|
+
return Y.fromBytes(Array.from(o), !0, !0);
|
|
670
671
|
}
|
|
671
|
-
function
|
|
672
|
-
return
|
|
672
|
+
function R(t, e) {
|
|
673
|
+
return At(t, e, 8);
|
|
673
674
|
}
|
|
674
|
-
function
|
|
675
|
-
return
|
|
675
|
+
function St(t, e) {
|
|
676
|
+
return At(t, e, 4);
|
|
676
677
|
}
|
|
677
|
-
function
|
|
678
|
+
function A(t, e) {
|
|
678
679
|
return e === 0 ? t : t.shru(e).or(t.shl(64 - e));
|
|
679
680
|
}
|
|
680
|
-
function
|
|
681
|
+
function X(t, e, n = lt("9ddfea08eb382d69")) {
|
|
681
682
|
let o = t.xor(e).mul(n);
|
|
682
683
|
o = o.xor(o.shru(47));
|
|
683
684
|
let s = e.xor(o).mul(n);
|
|
684
685
|
return s = s.xor(s.shru(47)), s = s.mul(n), s;
|
|
685
686
|
}
|
|
686
|
-
function
|
|
687
|
-
s = s.add(t), r =
|
|
688
|
-
const
|
|
689
|
-
return s = s.add(e), s = s.add(n), r = r.add(
|
|
687
|
+
function ue(t, e, n, o, s, r) {
|
|
688
|
+
s = s.add(t), r = A(r.add(s).add(o), 21);
|
|
689
|
+
const a = s;
|
|
690
|
+
return s = s.add(e), s = s.add(n), r = r.add(A(s, 44)), [s.add(o), r.add(a)];
|
|
690
691
|
}
|
|
691
692
|
function it(t, e, n, o) {
|
|
692
|
-
return
|
|
693
|
+
return ue(R(t, e), R(t, e + 8), R(t, e + 16), R(t, e + 24), n, o);
|
|
693
694
|
}
|
|
694
|
-
function
|
|
695
|
+
function le(t, e = t.length) {
|
|
695
696
|
if (e >= 8) {
|
|
696
|
-
const n =
|
|
697
|
-
return
|
|
697
|
+
const n = W.add(e * 2), o = R(t, 0).add(W), s = R(t, e - 8), r = A(s, 37).mul(n).add(o), a = A(o, 25).add(s).mul(n);
|
|
698
|
+
return X(r, a, n);
|
|
698
699
|
}
|
|
699
700
|
if (e >= 4) {
|
|
700
|
-
const n =
|
|
701
|
-
return
|
|
701
|
+
const n = W.add(e * 2), o = St(t, 0);
|
|
702
|
+
return X(o.shl(3).add(e), St(t, e - 4), n);
|
|
702
703
|
}
|
|
703
704
|
if (e > 0) {
|
|
704
|
-
const n = t[0], o = t[e >> 1], s = t[e - 1], r = n + (o << 8),
|
|
705
|
-
return
|
|
705
|
+
const n = t[0], o = t[e >> 1], s = t[e - 1], r = n + (o << 8), a = e + (s << 2);
|
|
706
|
+
return gt(W.mul(r).xor(Nt.mul(a))).mul(W);
|
|
706
707
|
}
|
|
707
|
-
return
|
|
708
|
+
return W;
|
|
708
709
|
}
|
|
709
|
-
function
|
|
710
|
-
const n =
|
|
711
|
-
return
|
|
710
|
+
function ce(t, e = t.length) {
|
|
711
|
+
const n = W.add(e * 2), o = R(t, 0).mul(Q), s = R(t, 8), r = R(t, e - 8).mul(n), a = R(t, e - 16).mul(W);
|
|
712
|
+
return X(A(o.add(s), 43).add(A(r, 30)).add(a), o.add(A(s.add(W), 18)).add(r), n);
|
|
712
713
|
}
|
|
713
|
-
function
|
|
714
|
-
const n =
|
|
715
|
-
return
|
|
714
|
+
function he(t, e = t.length) {
|
|
715
|
+
const n = W.add(e * 2), o = R(t, 0).mul(W), s = R(t, 8), r = R(t, e - 8).mul(n), a = R(t, e - 16).mul(W), i = A(o.add(s), 43).add(A(r, 30)).add(a), u = X(i, o.add(A(s.add(W), 18)).add(r), n), c = R(t, 16).mul(n), h = R(t, 24), f = i.add(R(t, e - 32)).mul(n), w = u.add(R(t, e - 24)).mul(n);
|
|
716
|
+
return X(A(c.add(h), 43).add(A(f, 30)).add(w), c.add(A(h.add(o), 18)).add(f), n);
|
|
716
717
|
}
|
|
717
|
-
function
|
|
718
|
-
const n =
|
|
718
|
+
function fe(t, e = t.length) {
|
|
719
|
+
const n = Y.fromNumber(81, !0);
|
|
719
720
|
if (e <= 32)
|
|
720
|
-
return e <= 16 ?
|
|
721
|
+
return e <= 16 ? le(t, e) : ce(t, e);
|
|
721
722
|
if (e <= 64)
|
|
722
|
-
return
|
|
723
|
-
let o = n, s = n.mul(
|
|
724
|
-
o = o.mul(
|
|
723
|
+
return he(t, e);
|
|
724
|
+
let o = n, s = n.mul(Q).add(113), r = gt(s.mul(W).add(113)).mul(W), a = [Y.UZERO, Y.UZERO], i = [Y.UZERO, Y.UZERO];
|
|
725
|
+
o = o.mul(W).add(R(t, 0));
|
|
725
726
|
let u = 0;
|
|
726
727
|
const c = (e - 1 >> 6) * 64, h = c + (e - 1 & 63) - 63;
|
|
727
728
|
do
|
|
728
|
-
o =
|
|
729
|
+
o = A(o.add(s).add(a[0]).add(R(t, u + 8)), 37).mul(Q), s = A(s.add(a[1]).add(R(t, u + 48)), 42).mul(Q), o = o.xor(i[1]), s = s.add(a[0]).add(R(t, u + 40)), r = A(r.add(i[0]), 33).mul(Q), a = it(t, u, a[1].mul(Q), o.add(i[0])), i = it(t, u + 32, r.add(i[1]), s.add(R(t, u + 16))), [r, o] = [o, r], u += 64;
|
|
729
730
|
while (u !== c);
|
|
730
|
-
const f =
|
|
731
|
-
return u = h,
|
|
731
|
+
const f = Q.add(r.and(255).shl(1));
|
|
732
|
+
return u = h, i[0] = i[0].add(e - 1 & 63), a[0] = a[0].add(i[0]), i[0] = i[0].add(a[0]), o = A(o.add(s).add(a[0]).add(R(t, u + 8)), 37).mul(f), s = A(s.add(a[1]).add(R(t, u + 48)), 42).mul(f), o = o.xor(i[1].mul(9)), s = s.add(a[0].mul(9).add(R(t, u + 40))), r = A(r.add(i[0]), 33).mul(f), a = it(t, u, a[1].mul(f), o.add(i[0])), i = it(t, u + 32, r.add(i[1]), s.add(R(t, u + 16))), [r, o] = [o, r], X(X(a[0], i[0], f).add(gt(s).mul(Nt)).add(r), X(a[1], i[1], f).add(o), f);
|
|
732
733
|
}
|
|
733
734
|
/**
|
|
734
735
|
* @license
|
|
@@ -750,7 +751,7 @@ var H;
|
|
|
750
751
|
(function(t) {
|
|
751
752
|
t[t.FIRST_DIM_SIZE = 0] = "FIRST_DIM_SIZE", t[t.VALUE_ROWIDS = 1] = "VALUE_ROWIDS", t[t.ROW_LENGTHS = 2] = "ROW_LENGTHS", t[t.ROW_SPLITS = 3] = "ROW_SPLITS", t[t.ROW_LIMITS = 4] = "ROW_LIMITS", t[t.ROW_STARTS = 5] = "ROW_STARTS";
|
|
752
753
|
})(H || (H = {}));
|
|
753
|
-
function
|
|
754
|
+
function de(t, e, n) {
|
|
754
755
|
let o = new Array();
|
|
755
756
|
if (n == null && e == null)
|
|
756
757
|
return o;
|
|
@@ -764,17 +765,17 @@ function Se(t, e, n) {
|
|
|
764
765
|
if (t + n.length !== o.length)
|
|
765
766
|
throw new Error(`rt input.shape and shape=${e} are incompatible: rt input.rank = ${t + n.length}, but shape.rank = ${o.length}`);
|
|
766
767
|
for (let s = 1; s < n.length; ++s) {
|
|
767
|
-
const r = n[s],
|
|
768
|
+
const r = n[s], a = o[o.length - n.length + s], i = o[a];
|
|
768
769
|
if (r >= 0)
|
|
769
|
-
if (
|
|
770
|
-
if (
|
|
771
|
-
throw new Error(`rt input.shape and shape=${e} are incompatible: rt input.shape[${s + t}] = ${r} but shape[${s + t}] = ${
|
|
770
|
+
if (i >= 0) {
|
|
771
|
+
if (i !== r)
|
|
772
|
+
throw new Error(`rt input.shape and shape=${e} are incompatible: rt input.shape[${s + t}] = ${r} but shape[${s + t}] = ${i}`);
|
|
772
773
|
} else
|
|
773
|
-
o[
|
|
774
|
+
o[a] = r;
|
|
774
775
|
}
|
|
775
776
|
return o;
|
|
776
777
|
}
|
|
777
|
-
function
|
|
778
|
+
function ge(t) {
|
|
778
779
|
const e = {
|
|
779
780
|
FIRST_DIM_SIZE: H.FIRST_DIM_SIZE,
|
|
780
781
|
VALUE_ROWIDS: H.VALUE_ROWIDS,
|
|
@@ -790,19 +791,19 @@ function ve(t) {
|
|
|
790
791
|
break;
|
|
791
792
|
return n;
|
|
792
793
|
}
|
|
793
|
-
function
|
|
794
|
+
function pe(t) {
|
|
794
795
|
return t.length === 0 ? 0 : t[0] === H.FIRST_DIM_SIZE ? t.length - 1 : t.length;
|
|
795
796
|
}
|
|
796
|
-
function
|
|
797
|
+
function me(t, e) {
|
|
797
798
|
if (t == null || e == null)
|
|
798
799
|
return;
|
|
799
800
|
const n = t.length, o = e.length;
|
|
800
801
|
if (n >= o)
|
|
801
802
|
throw new Error(`defaultValue.shape=${t} and ragged tensor flatValues.shape=${e}, are incompatible: defaultValue.rank = ${n} must be less than ragged tensor input flatValues.rank = ${o})`);
|
|
802
803
|
for (let s = 0; s < Math.min(n, o - 1); ++s) {
|
|
803
|
-
const r = t[s],
|
|
804
|
-
if (r >= 0 &&
|
|
805
|
-
throw new Error(`defaultValue.shape=${t}, and ragged tensor input flatValues.shape=${e} are incompatible: defaultValue.shape[${s - t.length}] = ${r} but ragged tensor input.flatValues.shape[${s - t.length}] = ${
|
|
804
|
+
const r = t[s], a = e[s + 1];
|
|
805
|
+
if (r >= 0 && a >= 0 && r !== 1 && r !== a)
|
|
806
|
+
throw new Error(`defaultValue.shape=${t}, and ragged tensor input flatValues.shape=${e} are incompatible: defaultValue.shape[${s - t.length}] = ${r} but ragged tensor input.flatValues.shape[${s - t.length}] = ${a}`);
|
|
806
807
|
}
|
|
807
808
|
}
|
|
808
809
|
/**
|
|
@@ -821,9 +822,9 @@ function Ee(t, e) {
|
|
|
821
822
|
* limitations under the License.
|
|
822
823
|
* =============================================================================
|
|
823
824
|
*/
|
|
824
|
-
const
|
|
825
|
-
function
|
|
826
|
-
return t <=
|
|
825
|
+
const we = 30;
|
|
826
|
+
function Ie(t) {
|
|
827
|
+
return t <= we ? t : qt(t, Math.floor(Math.sqrt(t)));
|
|
827
828
|
}
|
|
828
829
|
/**
|
|
829
830
|
* @license
|
|
@@ -841,14 +842,14 @@ function Re(t) {
|
|
|
841
842
|
* limitations under the License.
|
|
842
843
|
* =============================================================================
|
|
843
844
|
*/
|
|
844
|
-
function
|
|
845
|
+
function xe(t) {
|
|
845
846
|
return `Received SparseTensor with denseShape[0] = 0 but
|
|
846
847
|
indices.shape[0] = ${t}`;
|
|
847
848
|
}
|
|
848
|
-
function
|
|
849
|
+
function Se(t, e) {
|
|
849
850
|
return `indices(${t}, 0) is invalid: ${e} < 0`;
|
|
850
851
|
}
|
|
851
|
-
function
|
|
852
|
+
function Ee(t, e, n) {
|
|
852
853
|
return `indices(${t}, 0) is invalid: ${e} >= ${n}`;
|
|
853
854
|
}
|
|
854
855
|
/**
|
|
@@ -867,22 +868,22 @@ function ye(t, e, n) {
|
|
|
867
868
|
* limitations under the License.
|
|
868
869
|
* =============================================================================
|
|
869
870
|
*/
|
|
870
|
-
function
|
|
871
|
+
function be(t, e) {
|
|
871
872
|
return `only one output dimension may be -1, not both ${t} and ${e}`;
|
|
872
873
|
}
|
|
873
|
-
function
|
|
874
|
+
function ve(t, e) {
|
|
874
875
|
return `size ${t} must be non-negative, not ${e}`;
|
|
875
876
|
}
|
|
876
|
-
function
|
|
877
|
+
function Oe() {
|
|
877
878
|
return "reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero";
|
|
878
879
|
}
|
|
879
|
-
function
|
|
880
|
-
const n =
|
|
880
|
+
function Fe(t, e) {
|
|
881
|
+
const n = y(t), o = y(e);
|
|
881
882
|
return `Input to reshape is a SparseTensor with ${n}
|
|
882
883
|
dense values, but the requested shape requires a multiple of ${o}. inputShape=${t} outputShape= ${e}`;
|
|
883
884
|
}
|
|
884
|
-
function
|
|
885
|
-
const n =
|
|
885
|
+
function Re(t, e) {
|
|
886
|
+
const n = y(t), o = y(e);
|
|
886
887
|
return `Input to reshape is a tensor with ${n} dense values, but the requested shape has ${o}. inputShape=${t} outputShape=${e}`;
|
|
887
888
|
}
|
|
888
889
|
/**
|
|
@@ -901,16 +902,16 @@ function _e(t, e) {
|
|
|
901
902
|
* limitations under the License.
|
|
902
903
|
* =============================================================================
|
|
903
904
|
*/
|
|
904
|
-
function
|
|
905
|
+
function Et() {
|
|
905
906
|
return "segment ids must be >= 0";
|
|
906
907
|
}
|
|
907
|
-
function
|
|
908
|
+
function $e() {
|
|
908
909
|
return "segment ids are not increasing";
|
|
909
910
|
}
|
|
910
|
-
function
|
|
911
|
+
function ye(t, e) {
|
|
911
912
|
return `Segment id ${t} out of range [0, ${e}), possibly because segmentIds input is not sorted.`;
|
|
912
913
|
}
|
|
913
|
-
function
|
|
914
|
+
function Te(t, e, n) {
|
|
914
915
|
return `Bad: indices[${t}] == ${e} out of range [0, ${n})`;
|
|
915
916
|
}
|
|
916
917
|
/**
|
|
@@ -929,7 +930,7 @@ function De(t, e, n) {
|
|
|
929
930
|
* limitations under the License.
|
|
930
931
|
* =============================================================================
|
|
931
932
|
*/
|
|
932
|
-
function
|
|
933
|
+
function Ve(t) {
|
|
933
934
|
const e = new Float32Array(t.length);
|
|
934
935
|
for (let n = 0; n < t.length; ++n)
|
|
935
936
|
e[n] = Math.abs(t[n]);
|
|
@@ -951,22 +952,22 @@ function ze(t) {
|
|
|
951
952
|
* limitations under the License.
|
|
952
953
|
* =============================================================================
|
|
953
954
|
*/
|
|
954
|
-
function
|
|
955
|
+
function C(t) {
|
|
955
956
|
return (e, n, o, s, r) => {
|
|
956
|
-
const
|
|
957
|
+
const a = Ct(e, n), i = a.length, u = J(a), c = y(a), h = nt(r, c), f = e.length, w = n.length, p = J(e), m = J(n), b = It(e, a), d = It(n, a);
|
|
957
958
|
if (b.length + d.length === 0)
|
|
958
959
|
for (let g = 0; g < h.length; ++g)
|
|
959
960
|
h[g] = t(o[g % o.length], s[g % s.length]);
|
|
960
961
|
else
|
|
961
962
|
for (let g = 0; g < h.length; ++g) {
|
|
962
|
-
const x =
|
|
963
|
-
b.forEach((
|
|
964
|
-
const
|
|
965
|
-
d.forEach((
|
|
966
|
-
const
|
|
967
|
-
h[g] = t(o[
|
|
963
|
+
const x = pt(g, i, u), O = x.slice(-f);
|
|
964
|
+
b.forEach((L) => O[L] = 0);
|
|
965
|
+
const v = ft(O, f, p), V = x.slice(-w);
|
|
966
|
+
d.forEach((L) => V[L] = 0);
|
|
967
|
+
const D = ft(V, w, m);
|
|
968
|
+
h[g] = t(o[v], s[D]);
|
|
968
969
|
}
|
|
969
|
-
return [h,
|
|
970
|
+
return [h, a];
|
|
970
971
|
};
|
|
971
972
|
}
|
|
972
973
|
/**
|
|
@@ -985,14 +986,14 @@ function k(t) {
|
|
|
985
986
|
* limitations under the License.
|
|
986
987
|
* =============================================================================
|
|
987
988
|
*/
|
|
988
|
-
function
|
|
989
|
+
function Me(t, e, n, o) {
|
|
989
990
|
if (o === "int32") {
|
|
990
991
|
const s = Int32Array.from(t);
|
|
991
992
|
return [e, "int32", s];
|
|
992
993
|
}
|
|
993
994
|
if (o === "bool") {
|
|
994
|
-
const s =
|
|
995
|
-
return [
|
|
995
|
+
const s = kt([0], n), [r, a] = C((i, u) => i !== u ? 1 : 0)(e, [], t, s, "bool");
|
|
996
|
+
return [a, "bool", r];
|
|
996
997
|
}
|
|
997
998
|
throw new Error(`Error in Cast: failed to cast ${n} to ${o}`);
|
|
998
999
|
}
|
|
@@ -1012,7 +1013,7 @@ function Pe(t, e, n, o) {
|
|
|
1012
1013
|
* limitations under the License.
|
|
1013
1014
|
* =============================================================================
|
|
1014
1015
|
*/
|
|
1015
|
-
const
|
|
1016
|
+
const Le = C((t, e) => t + e);
|
|
1016
1017
|
/**
|
|
1017
1018
|
* @license
|
|
1018
1019
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1029,26 +1030,26 @@ const Ce = k((t, e) => t + e);
|
|
|
1029
1030
|
* limitations under the License.
|
|
1030
1031
|
* =============================================================================
|
|
1031
1032
|
*/
|
|
1032
|
-
function
|
|
1033
|
-
const r =
|
|
1034
|
-
for (let
|
|
1035
|
-
const u = t[
|
|
1033
|
+
function _e(t, e, n, o, s) {
|
|
1034
|
+
const r = y(o), a = ot(s, n);
|
|
1035
|
+
for (let i = 0; i < t.length; i++) {
|
|
1036
|
+
const u = t[i];
|
|
1036
1037
|
if (u < 0)
|
|
1037
1038
|
throw new Error("Input x must be non-negative!");
|
|
1038
|
-
u >= s || (r > 0 ?
|
|
1039
|
+
u >= s || (r > 0 ? a[u] += e[i] : a[u] += 1);
|
|
1039
1040
|
}
|
|
1040
|
-
return
|
|
1041
|
+
return a;
|
|
1041
1042
|
}
|
|
1042
|
-
function
|
|
1043
|
-
const s = t.shape[0], r = t.shape[1],
|
|
1044
|
-
for (let
|
|
1043
|
+
function Ne(t, e, n, o = !1) {
|
|
1044
|
+
const s = t.shape[0], r = t.shape[1], a = B([s, n], e.dtype);
|
|
1045
|
+
for (let i = 0; i < s; i++)
|
|
1045
1046
|
for (let u = 0; u < r; u++) {
|
|
1046
|
-
const c = t.get(
|
|
1047
|
+
const c = t.get(i, u);
|
|
1047
1048
|
if (c < 0)
|
|
1048
1049
|
throw new Error("Input x must be non-negative!");
|
|
1049
|
-
c >= n || (o ?
|
|
1050
|
+
c >= n || (o ? a.set(1, i, c) : e.size > 0 ? a.set(a.get(i, c) + e.get(i, u), i, c) : a.set(a.get(i, c) + 1, i, c));
|
|
1050
1051
|
}
|
|
1051
|
-
return
|
|
1052
|
+
return a;
|
|
1052
1053
|
}
|
|
1053
1054
|
/**
|
|
1054
1055
|
* @license
|
|
@@ -1066,7 +1067,7 @@ function ke(t, e, n, o = !1) {
|
|
|
1066
1067
|
* limitations under the License.
|
|
1067
1068
|
* =============================================================================
|
|
1068
1069
|
*/
|
|
1069
|
-
const
|
|
1070
|
+
const Ae = C((t, e) => t & e);
|
|
1070
1071
|
/**
|
|
1071
1072
|
* @license
|
|
1072
1073
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1083,9 +1084,9 @@ const qe = k((t, e) => t & e);
|
|
|
1083
1084
|
* limitations under the License.
|
|
1084
1085
|
* =============================================================================
|
|
1085
1086
|
*/
|
|
1086
|
-
function
|
|
1087
|
+
function K(t) {
|
|
1087
1088
|
return (e, n, o) => {
|
|
1088
|
-
const s =
|
|
1089
|
+
const s = q(n, e.length);
|
|
1089
1090
|
for (let r = 0; r < e.length; ++r)
|
|
1090
1091
|
s[r] = t(e[r], o);
|
|
1091
1092
|
return s;
|
|
@@ -1107,7 +1108,7 @@ function X(t) {
|
|
|
1107
1108
|
* limitations under the License.
|
|
1108
1109
|
* =============================================================================
|
|
1109
1110
|
*/
|
|
1110
|
-
const
|
|
1111
|
+
const Pe = K((t) => Math.ceil(t));
|
|
1111
1112
|
/**
|
|
1112
1113
|
* @license
|
|
1113
1114
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1124,25 +1125,25 @@ const Ue = X((t) => Math.ceil(t));
|
|
|
1124
1125
|
* limitations under the License.
|
|
1125
1126
|
* =============================================================================
|
|
1126
1127
|
*/
|
|
1127
|
-
function
|
|
1128
|
-
const s =
|
|
1128
|
+
function De(t, e, n, o) {
|
|
1129
|
+
const s = q(n, y(e));
|
|
1129
1130
|
if (o && n !== "string") {
|
|
1130
1131
|
let r = 0;
|
|
1131
|
-
t.forEach((
|
|
1132
|
-
const
|
|
1133
|
-
s.set(
|
|
1132
|
+
t.forEach((a) => {
|
|
1133
|
+
const i = y(a.shape);
|
|
1134
|
+
s.set(a.vals, r), r += i;
|
|
1134
1135
|
});
|
|
1135
1136
|
} else {
|
|
1136
1137
|
let r = 0;
|
|
1137
|
-
t.forEach((
|
|
1138
|
-
const
|
|
1138
|
+
t.forEach((a) => {
|
|
1139
|
+
const i = n === "string" ? $t(a.vals) : a.vals;
|
|
1139
1140
|
let u = 0;
|
|
1140
|
-
for (let c = 0; c <
|
|
1141
|
+
for (let c = 0; c < a.shape[0]; ++c) {
|
|
1141
1142
|
const h = c * e[1] + r;
|
|
1142
|
-
for (let f = 0; f <
|
|
1143
|
-
s[h + f] =
|
|
1143
|
+
for (let f = 0; f < a.shape[1]; ++f)
|
|
1144
|
+
s[h + f] = i[u++];
|
|
1144
1145
|
}
|
|
1145
|
-
r +=
|
|
1146
|
+
r += a.shape[1];
|
|
1146
1147
|
});
|
|
1147
1148
|
}
|
|
1148
1149
|
return s;
|
|
@@ -1163,7 +1164,7 @@ function Ge(t, e, n, o) {
|
|
|
1163
1164
|
* limitations under the License.
|
|
1164
1165
|
* =============================================================================
|
|
1165
1166
|
*/
|
|
1166
|
-
const
|
|
1167
|
+
const ze = C((t, e) => t === e ? 1 : 0);
|
|
1167
1168
|
/**
|
|
1168
1169
|
* @license
|
|
1169
1170
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1180,7 +1181,7 @@ const je = k((t, e) => t === e ? 1 : 0);
|
|
|
1180
1181
|
* limitations under the License.
|
|
1181
1182
|
* =============================================================================
|
|
1182
1183
|
*/
|
|
1183
|
-
const
|
|
1184
|
+
const We = K((t) => Math.exp(t));
|
|
1184
1185
|
/**
|
|
1185
1186
|
* @license
|
|
1186
1187
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1197,7 +1198,7 @@ const Be = X((t) => Math.exp(t));
|
|
|
1197
1198
|
* limitations under the License.
|
|
1198
1199
|
* =============================================================================
|
|
1199
1200
|
*/
|
|
1200
|
-
const
|
|
1201
|
+
const qe = K((t) => Math.expm1(t));
|
|
1201
1202
|
/**
|
|
1202
1203
|
* @license
|
|
1203
1204
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1214,7 +1215,7 @@ const Ze = X((t) => Math.expm1(t));
|
|
|
1214
1215
|
* limitations under the License.
|
|
1215
1216
|
* =============================================================================
|
|
1216
1217
|
*/
|
|
1217
|
-
const
|
|
1218
|
+
const Ce = K((t) => Math.floor(t));
|
|
1218
1219
|
/**
|
|
1219
1220
|
* @license
|
|
1220
1221
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1231,7 +1232,7 @@ const He = X((t) => Math.floor(t));
|
|
|
1231
1232
|
* limitations under the License.
|
|
1232
1233
|
* =============================================================================
|
|
1233
1234
|
*/
|
|
1234
|
-
const
|
|
1235
|
+
const ke = C((t, e) => Math.floor(t / e));
|
|
1235
1236
|
/**
|
|
1236
1237
|
* @license
|
|
1237
1238
|
* Copyright 2021 Google LLC. All Rights Reserved.
|
|
@@ -1248,17 +1249,17 @@ const Ke = k((t, e) => Math.floor(t / e));
|
|
|
1248
1249
|
* limitations under the License.
|
|
1249
1250
|
* =============================================================================
|
|
1250
1251
|
*/
|
|
1251
|
-
function
|
|
1252
|
-
const c =
|
|
1252
|
+
function Ue(t, e, n, o, s, r, a, i, u) {
|
|
1253
|
+
const c = B([o, r], n);
|
|
1253
1254
|
for (let h = 0; h < o; h++) {
|
|
1254
1255
|
const f = [];
|
|
1255
1256
|
let w = 0;
|
|
1256
1257
|
for (let p = 0; p < s; p++) {
|
|
1257
1258
|
const m = t[h * s + p];
|
|
1258
|
-
w += m *
|
|
1259
|
+
w += m * a[p], f.push(m);
|
|
1259
1260
|
}
|
|
1260
1261
|
if (w < 0 || w >= u / r)
|
|
1261
|
-
throw new Error(`Invalid indices: ${f} does not index into ${
|
|
1262
|
+
throw new Error(`Invalid indices: ${f} does not index into ${i}`);
|
|
1262
1263
|
for (let p = 0; p < r; p++)
|
|
1263
1264
|
c.values[h * r + p] = e.get(...e.indexToLoc(w * r + p));
|
|
1264
1265
|
}
|
|
@@ -1280,12 +1281,12 @@ function Xe(t, e, n, o, s, r, i, a, u) {
|
|
|
1280
1281
|
* limitations under the License.
|
|
1281
1282
|
* =============================================================================
|
|
1282
1283
|
*/
|
|
1283
|
-
function
|
|
1284
|
-
const o =
|
|
1284
|
+
function Ge(t, e, n) {
|
|
1285
|
+
const o = B(n, t.dtype);
|
|
1285
1286
|
for (let s = 0; s < o.size; ++s) {
|
|
1286
|
-
const
|
|
1287
|
-
|
|
1288
|
-
const h = t.locToIndex(
|
|
1287
|
+
const a = o.indexToLoc(s).slice(), i = a[0], u = a[2], c = e.locToIndex([i, u]);
|
|
1288
|
+
a[2] = e.values[c];
|
|
1289
|
+
const h = t.locToIndex(a);
|
|
1289
1290
|
0 <= h && h < t.values.length && (o.values[s] = t.values[h]);
|
|
1290
1291
|
}
|
|
1291
1292
|
return o;
|
|
@@ -1306,7 +1307,7 @@ function Ye(t, e, n) {
|
|
|
1306
1307
|
* limitations under the License.
|
|
1307
1308
|
* =============================================================================
|
|
1308
1309
|
*/
|
|
1309
|
-
const
|
|
1310
|
+
const je = C((t, e) => t > e ? 1 : 0);
|
|
1310
1311
|
/**
|
|
1311
1312
|
* @license
|
|
1312
1313
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1323,7 +1324,7 @@ const Je = k((t, e) => t > e ? 1 : 0);
|
|
|
1323
1324
|
* limitations under the License.
|
|
1324
1325
|
* =============================================================================
|
|
1325
1326
|
*/
|
|
1326
|
-
const
|
|
1327
|
+
const Ze = C((t, e) => t >= e ? 1 : 0);
|
|
1327
1328
|
/**
|
|
1328
1329
|
* @license
|
|
1329
1330
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1340,7 +1341,7 @@ const Qe = k((t, e) => t >= e ? 1 : 0);
|
|
|
1340
1341
|
* limitations under the License.
|
|
1341
1342
|
* =============================================================================
|
|
1342
1343
|
*/
|
|
1343
|
-
const
|
|
1344
|
+
const Be = C((t, e) => t < e ? 1 : 0);
|
|
1344
1345
|
/**
|
|
1345
1346
|
* @license
|
|
1346
1347
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1357,7 +1358,7 @@ const tn = k((t, e) => t < e ? 1 : 0);
|
|
|
1357
1358
|
* limitations under the License.
|
|
1358
1359
|
* =============================================================================
|
|
1359
1360
|
*/
|
|
1360
|
-
const
|
|
1361
|
+
const He = C((t, e) => t <= e ? 1 : 0);
|
|
1361
1362
|
/**
|
|
1362
1363
|
* @license
|
|
1363
1364
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1374,7 +1375,7 @@ const en = k((t, e) => t <= e ? 1 : 0);
|
|
|
1374
1375
|
* limitations under the License.
|
|
1375
1376
|
* =============================================================================
|
|
1376
1377
|
*/
|
|
1377
|
-
function
|
|
1378
|
+
function Ke(t, e, n) {
|
|
1378
1379
|
const o = (e - t) / (n - 1), s = ot(n, "float32");
|
|
1379
1380
|
s[0] = t;
|
|
1380
1381
|
for (let r = 1; r < s.length; r++)
|
|
@@ -1397,7 +1398,7 @@ function nn(t, e, n) {
|
|
|
1397
1398
|
* limitations under the License.
|
|
1398
1399
|
* =============================================================================
|
|
1399
1400
|
*/
|
|
1400
|
-
const
|
|
1401
|
+
const Xe = K((t) => Math.log(t));
|
|
1401
1402
|
/**
|
|
1402
1403
|
* @license
|
|
1403
1404
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1414,16 +1415,16 @@ const on = X((t) => Math.log(t));
|
|
|
1414
1415
|
* limitations under the License.
|
|
1415
1416
|
* =============================================================================
|
|
1416
1417
|
*/
|
|
1417
|
-
function
|
|
1418
|
-
const s = nt(o,
|
|
1418
|
+
function Qe(t, e, n, o) {
|
|
1419
|
+
const s = nt(o, y(n));
|
|
1419
1420
|
for (let r = 0; r < s.length; ++r) {
|
|
1420
|
-
const
|
|
1421
|
-
let
|
|
1421
|
+
const a = r * e;
|
|
1422
|
+
let i = t[a];
|
|
1422
1423
|
for (let u = 0; u < e; ++u) {
|
|
1423
|
-
const c = t[
|
|
1424
|
-
(Number.isNaN(c) || c >
|
|
1424
|
+
const c = t[a + u];
|
|
1425
|
+
(Number.isNaN(c) || c > i) && (i = c);
|
|
1425
1426
|
}
|
|
1426
|
-
s[r] =
|
|
1427
|
+
s[r] = i;
|
|
1427
1428
|
}
|
|
1428
1429
|
return s;
|
|
1429
1430
|
}
|
|
@@ -1443,7 +1444,7 @@ function sn(t, e, n, o) {
|
|
|
1443
1444
|
* limitations under the License.
|
|
1444
1445
|
* =============================================================================
|
|
1445
1446
|
*/
|
|
1446
|
-
const
|
|
1447
|
+
const Ye = C((t, e) => Math.max(t, e));
|
|
1447
1448
|
/**
|
|
1448
1449
|
* @license
|
|
1449
1450
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1460,7 +1461,7 @@ const rn = k((t, e) => Math.max(t, e));
|
|
|
1460
1461
|
* limitations under the License.
|
|
1461
1462
|
* =============================================================================
|
|
1462
1463
|
*/
|
|
1463
|
-
const
|
|
1464
|
+
const Je = C((t, e) => Math.min(t, e));
|
|
1464
1465
|
/**
|
|
1465
1466
|
* @license
|
|
1466
1467
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1477,7 +1478,7 @@ const an = k((t, e) => Math.min(t, e));
|
|
|
1477
1478
|
* limitations under the License.
|
|
1478
1479
|
* =============================================================================
|
|
1479
1480
|
*/
|
|
1480
|
-
const
|
|
1481
|
+
const Pt = C((t, e) => t * e);
|
|
1481
1482
|
/**
|
|
1482
1483
|
* @license
|
|
1483
1484
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1494,9 +1495,9 @@ const kt = k((t, e) => t * e);
|
|
|
1494
1495
|
* limitations under the License.
|
|
1495
1496
|
* =============================================================================
|
|
1496
1497
|
*/
|
|
1497
|
-
function
|
|
1498
|
-
const o =
|
|
1499
|
-
return
|
|
1498
|
+
function tn(t, e, n) {
|
|
1499
|
+
const o = Ut(-1, n);
|
|
1500
|
+
return Pt([], e, o, t, n);
|
|
1500
1501
|
}
|
|
1501
1502
|
/**
|
|
1502
1503
|
* @license
|
|
@@ -1514,7 +1515,7 @@ function un(t, e, n) {
|
|
|
1514
1515
|
* limitations under the License.
|
|
1515
1516
|
* =============================================================================
|
|
1516
1517
|
*/
|
|
1517
|
-
const
|
|
1518
|
+
const en = C((t, e) => t !== e ? 1 : 0);
|
|
1518
1519
|
/**
|
|
1519
1520
|
* @license
|
|
1520
1521
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -1531,13 +1532,13 @@ const ln = k((t, e) => t !== e ? 1 : 0);
|
|
|
1531
1532
|
* limitations under the License.
|
|
1532
1533
|
* =============================================================================
|
|
1533
1534
|
*/
|
|
1534
|
-
function
|
|
1535
|
-
const r = e.length,
|
|
1536
|
-
for (let h = 0; h <
|
|
1537
|
-
const f =
|
|
1535
|
+
function nn(t, e, n, o, s) {
|
|
1536
|
+
const r = e.length, a = y(e), i = J(e), u = J(s), c = nt(n, y(s));
|
|
1537
|
+
for (let h = 0; h < a; ++h) {
|
|
1538
|
+
const f = pt(h, r, i), w = new Array(f.length);
|
|
1538
1539
|
for (let m = 0; m < w.length; m++)
|
|
1539
1540
|
w[m] = f[o[m]];
|
|
1540
|
-
const p =
|
|
1541
|
+
const p = ft(w, r, u);
|
|
1541
1542
|
c[p] = t[h];
|
|
1542
1543
|
}
|
|
1543
1544
|
return c;
|
|
@@ -1558,16 +1559,16 @@ function cn(t, e, n, o, s) {
|
|
|
1558
1559
|
* limitations under the License.
|
|
1559
1560
|
* =============================================================================
|
|
1560
1561
|
*/
|
|
1561
|
-
function
|
|
1562
|
-
const [s, r] =
|
|
1563
|
-
for (let c = 0; c <
|
|
1562
|
+
function on(t, e, n, o) {
|
|
1563
|
+
const [s, r] = mt(t, o), a = Gt(e, "int32"), i = ot(y(s), a), u = y(r);
|
|
1564
|
+
for (let c = 0; c < i.length; ++c) {
|
|
1564
1565
|
const h = c * u;
|
|
1565
1566
|
let f = 1;
|
|
1566
1567
|
for (let w = 0; w < u; ++w)
|
|
1567
1568
|
f *= n[h + w];
|
|
1568
|
-
|
|
1569
|
+
i[c] = f;
|
|
1569
1570
|
}
|
|
1570
|
-
return { outVals:
|
|
1571
|
+
return { outVals: i, outShape: s, outDtype: a };
|
|
1571
1572
|
}
|
|
1572
1573
|
/**
|
|
1573
1574
|
* @license
|
|
@@ -1585,15 +1586,15 @@ function hn(t, e, n, o) {
|
|
|
1585
1586
|
* limitations under the License.
|
|
1586
1587
|
* =============================================================================
|
|
1587
1588
|
*/
|
|
1588
|
-
function
|
|
1589
|
+
function sn(t, e, n) {
|
|
1589
1590
|
t.forEach((o, s) => {
|
|
1590
1591
|
if (o < 0 || o >= n) {
|
|
1591
|
-
const r =
|
|
1592
|
+
const r = pt(s, e.length, J(e)).join(",");
|
|
1592
1593
|
throw new Error(`indices[${r}] = ${o} is not in [0, ${n})`);
|
|
1593
1594
|
}
|
|
1594
1595
|
});
|
|
1595
1596
|
}
|
|
1596
|
-
function
|
|
1597
|
+
function rn(t, e) {
|
|
1597
1598
|
for (let n = 0; n < t.length; ++n) {
|
|
1598
1599
|
const o = t[n], s = n === t.length - 1 ? e : t[n + 1].length;
|
|
1599
1600
|
if (o.length === 0)
|
|
@@ -1607,42 +1608,42 @@ function dn(t, e) {
|
|
|
1607
1608
|
throw new Error("Ragged splits must be sorted in ascending order");
|
|
1608
1609
|
}
|
|
1609
1610
|
}
|
|
1610
|
-
function
|
|
1611
|
+
function an(t, e, n, o) {
|
|
1611
1612
|
const s = [];
|
|
1612
1613
|
let r = 0;
|
|
1613
|
-
const
|
|
1614
|
-
|
|
1614
|
+
const a = e.length - 1 + n.length, i = new Array(a).fill(null).map(() => [0]);
|
|
1615
|
+
rn(n, o);
|
|
1615
1616
|
let u = 1;
|
|
1616
1617
|
for (let c = 0; c < e.length - 1; ++c) {
|
|
1617
1618
|
u *= e[c];
|
|
1618
1619
|
const h = e[c + 1];
|
|
1619
1620
|
for (let f = 1; f < u + 1; ++f)
|
|
1620
|
-
|
|
1621
|
+
i[c].push(f * h);
|
|
1621
1622
|
}
|
|
1622
1623
|
for (let c = 0; c < t.length; ++c) {
|
|
1623
1624
|
let h = t[c], f = t[c] + 1;
|
|
1624
1625
|
for (let w = 0; w < n.length; ++w) {
|
|
1625
1626
|
const p = n[w], m = w + e.length - 1;
|
|
1626
1627
|
if (m >= 0) {
|
|
1627
|
-
const b =
|
|
1628
|
+
const b = i[m], d = b[b.length - 1] - p[h];
|
|
1628
1629
|
for (let g = h; g < f; ++g)
|
|
1629
|
-
|
|
1630
|
+
i[m].push(p[g + 1] + d);
|
|
1630
1631
|
}
|
|
1631
1632
|
h = p[h], f = p[f];
|
|
1632
1633
|
}
|
|
1633
1634
|
f !== h && (s.push([h, f]), r += f - h);
|
|
1634
1635
|
}
|
|
1635
|
-
return { outSplits:
|
|
1636
|
+
return { outSplits: i, valueSlices: s, numValues: r };
|
|
1636
1637
|
}
|
|
1637
|
-
function
|
|
1638
|
+
function un(t) {
|
|
1638
1639
|
const e = [];
|
|
1639
1640
|
for (let n = 0; n < t.length; ++n) {
|
|
1640
|
-
const o = t[n].length, s =
|
|
1641
|
-
e.push(s), t[n].forEach((r,
|
|
1641
|
+
const o = t[n].length, s = q("int32", o);
|
|
1642
|
+
e.push(s), t[n].forEach((r, a) => s[a] = r);
|
|
1642
1643
|
}
|
|
1643
1644
|
return e;
|
|
1644
1645
|
}
|
|
1645
|
-
function
|
|
1646
|
+
function bt(t, e) {
|
|
1646
1647
|
const n = t.slice(0, e);
|
|
1647
1648
|
for (; n.length < e; )
|
|
1648
1649
|
n.push(1);
|
|
@@ -1650,31 +1651,31 @@ function Et(t, e) {
|
|
|
1650
1651
|
n[e - 1] *= t[o];
|
|
1651
1652
|
return n;
|
|
1652
1653
|
}
|
|
1653
|
-
function
|
|
1654
|
-
const
|
|
1654
|
+
function ln(t, e, n, o, s, r) {
|
|
1655
|
+
const a = bt(e, 2)[1], i = bt(r, 2)[1];
|
|
1655
1656
|
let u = 0;
|
|
1656
1657
|
for (const c of n)
|
|
1657
1658
|
for (let h = c[0]; h < c[1]; ++h) {
|
|
1658
1659
|
for (let f = 0; f < o; ++f)
|
|
1659
|
-
s[u *
|
|
1660
|
+
s[u * i + f] = t[h * a + f];
|
|
1660
1661
|
++u;
|
|
1661
1662
|
}
|
|
1662
1663
|
}
|
|
1663
|
-
function
|
|
1664
|
+
function cn(t, e, n, o, s) {
|
|
1664
1665
|
const r = e.slice();
|
|
1665
1666
|
r[0] = s;
|
|
1666
|
-
const
|
|
1667
|
-
return
|
|
1667
|
+
const a = q(n, y(r)), i = t.length, u = i === 0 ? 0 : i / e[0];
|
|
1668
|
+
return ln(t, e, o, u, a, r), [a, r];
|
|
1668
1669
|
}
|
|
1669
|
-
function
|
|
1670
|
+
function hn(t, e, n, o, s, r, a, i) {
|
|
1670
1671
|
if (t.length === 0)
|
|
1671
1672
|
throw new Error("paramsNestedSplits must be non empty");
|
|
1672
1673
|
if (e[0].length === 0)
|
|
1673
1674
|
throw new Error("Split tensors must not be scalars");
|
|
1674
1675
|
const u = e[0][0] - 1;
|
|
1675
|
-
if (
|
|
1676
|
+
if (sn(r, a, u), o.length === 0)
|
|
1676
1677
|
throw new Error("params.rank must be nonzero");
|
|
1677
|
-
const c = o[0], { outSplits: h, valueSlices: f, numValues: w } =
|
|
1678
|
+
const c = o[0], { outSplits: h, valueSlices: f, numValues: w } = an(r, a, t, c), p = un(h), m = cn(n, o, s, f, w);
|
|
1678
1679
|
return [p, m[0], m[1]];
|
|
1679
1680
|
}
|
|
1680
1681
|
/**
|
|
@@ -1693,40 +1694,40 @@ function In(t, e, n, o, s, r, i, a) {
|
|
|
1693
1694
|
* limitations under the License.
|
|
1694
1695
|
* =============================================================================
|
|
1695
1696
|
*/
|
|
1696
|
-
const
|
|
1697
|
-
function
|
|
1697
|
+
const vt = 2147483647;
|
|
1698
|
+
function fn(t, e, n, o, s, r, a) {
|
|
1698
1699
|
if (e.length > 1)
|
|
1699
1700
|
throw new Error("starts must be a scalar or vector");
|
|
1700
1701
|
if (s.length > 1)
|
|
1701
1702
|
throw new Error("limits must be a scalar or vector");
|
|
1702
|
-
if (
|
|
1703
|
+
if (a.length > 1)
|
|
1703
1704
|
throw new Error("deltas must be a scalar or vector");
|
|
1704
|
-
const
|
|
1705
|
-
|
|
1705
|
+
const i = e.length === 0, u = s.length === 0, c = a.length === 0, h = [];
|
|
1706
|
+
i || h.push(e[0]), u || h.push(s[0]), c || h.push(a[0]);
|
|
1706
1707
|
for (let d = 1; d < h.length; ++d)
|
|
1707
1708
|
if (h[d] !== h[d - 1])
|
|
1708
1709
|
throw new Error("starts, limits, and deltas must have the same shape");
|
|
1709
|
-
const f = h.length === 0 ? 1 : h[0], w =
|
|
1710
|
+
const f = h.length === 0 ? 1 : h[0], w = q("int32", f + 1);
|
|
1710
1711
|
w[0] = 0;
|
|
1711
1712
|
for (let d = 0; d < f; ++d) {
|
|
1712
|
-
const g =
|
|
1713
|
-
if (
|
|
1713
|
+
const g = i ? t[0] : t[d], x = u ? o[0] : o[d], O = c ? r[0] : r[d];
|
|
1714
|
+
if (O === 0)
|
|
1714
1715
|
throw new Error("Requires delta != 0");
|
|
1715
|
-
let
|
|
1716
|
-
if (
|
|
1717
|
-
|
|
1718
|
-
else if (
|
|
1719
|
-
throw new Error(`Requires ((limit - start) / delta) <= ${
|
|
1720
|
-
w[d + 1] = w[d] +
|
|
1721
|
-
}
|
|
1722
|
-
const p = w[f], m =
|
|
1716
|
+
let v;
|
|
1717
|
+
if (O > 0 && x < g || O < 0 && x > g)
|
|
1718
|
+
v = 0;
|
|
1719
|
+
else if (v = Math.ceil(Math.abs((x - g) / O)), v > vt)
|
|
1720
|
+
throw new Error(`Requires ((limit - start) / delta) <= ${vt}`);
|
|
1721
|
+
w[d + 1] = w[d] + v;
|
|
1722
|
+
}
|
|
1723
|
+
const p = w[f], m = q(n, p);
|
|
1723
1724
|
let b = 0;
|
|
1724
1725
|
for (let d = 0; d < f; ++d) {
|
|
1725
1726
|
const g = w[d + 1] - w[d];
|
|
1726
|
-
let x =
|
|
1727
|
-
const
|
|
1728
|
-
for (let
|
|
1729
|
-
m[b++] = x, x +=
|
|
1727
|
+
let x = i ? t[0] : t[d];
|
|
1728
|
+
const O = c ? r[0] : r[d];
|
|
1729
|
+
for (let v = 0; v < g; ++v)
|
|
1730
|
+
m[b++] = x, x += O;
|
|
1730
1731
|
}
|
|
1731
1732
|
return [w, m];
|
|
1732
1733
|
}
|
|
@@ -1746,27 +1747,27 @@ function xn(t, e, n, o, s, r, i) {
|
|
|
1746
1747
|
* limitations under the License.
|
|
1747
1748
|
* =============================================================================
|
|
1748
1749
|
*/
|
|
1749
|
-
var
|
|
1750
|
-
class
|
|
1751
|
-
constructor(e, n, o, s, r,
|
|
1752
|
-
this.shape = e, this.shapeShape = n, this.values = o, this.valuesShape = s, this.valuesDType = r, this.defaultValue =
|
|
1750
|
+
var Z = H;
|
|
1751
|
+
class at {
|
|
1752
|
+
constructor(e, n, o, s, r, a, i, u, c, h) {
|
|
1753
|
+
this.shape = e, this.shapeShape = n, this.values = o, this.valuesShape = s, this.valuesDType = r, this.defaultValue = a, this.defaultValueShape = i, this.rowPartitionValues = u, this.rowPartitionValuesShapes = c, this.rowPartitionTypes = ge(h), this.raggedRank = pe(this.rowPartitionTypes);
|
|
1753
1754
|
}
|
|
1754
1755
|
getRowPartitionTypeByDimension(e) {
|
|
1755
|
-
return this.rowPartitionTypes[0] ===
|
|
1756
|
+
return this.rowPartitionTypes[0] === Z.FIRST_DIM_SIZE ? this.rowPartitionTypes[e + 1] : this.rowPartitionTypes[e];
|
|
1756
1757
|
}
|
|
1757
1758
|
// Returns the relationship between dimension and dimension + 1.
|
|
1758
1759
|
getRowPartitionTensor(e) {
|
|
1759
|
-
return this.rowPartitionTypes[0] ===
|
|
1760
|
+
return this.rowPartitionTypes[0] === Z.FIRST_DIM_SIZE ? this.rowPartitionValues[e + 1] : this.rowPartitionValues[e];
|
|
1760
1761
|
}
|
|
1761
1762
|
getMaxWidth(e) {
|
|
1762
1763
|
const n = this.getRowPartitionTensor(e - 1);
|
|
1763
1764
|
switch (this.getRowPartitionTypeByDimension(e - 1)) {
|
|
1764
|
-
case
|
|
1765
|
-
return
|
|
1766
|
-
case
|
|
1767
|
-
return
|
|
1765
|
+
case Z.VALUE_ROWIDS:
|
|
1766
|
+
return at.getMaxWidthValueRowID(n);
|
|
1767
|
+
case Z.ROW_SPLITS:
|
|
1768
|
+
return at.getMaxWidthRowSplit(n);
|
|
1768
1769
|
default:
|
|
1769
|
-
throw new Error(`Cannot handle partition type ${
|
|
1770
|
+
throw new Error(`Cannot handle partition type ${Z[this.getRowPartitionTypeByDimension(e - 1)]}`);
|
|
1770
1771
|
}
|
|
1771
1772
|
}
|
|
1772
1773
|
static getMaxWidthRowSplit(e) {
|
|
@@ -1785,9 +1786,9 @@ class ut {
|
|
|
1785
1786
|
if (n === 0)
|
|
1786
1787
|
return 0;
|
|
1787
1788
|
let o = 0, s = e[0], r = 0;
|
|
1788
|
-
for (let
|
|
1789
|
-
const
|
|
1790
|
-
|
|
1789
|
+
for (let a = 1; a < n; ++a) {
|
|
1790
|
+
const i = e[a];
|
|
1791
|
+
i !== s && (s = i, r = Math.max(a - o, r), o = a);
|
|
1791
1792
|
}
|
|
1792
1793
|
return Math.max(n - o, r);
|
|
1793
1794
|
}
|
|
@@ -1801,12 +1802,12 @@ class ut {
|
|
|
1801
1802
|
}
|
|
1802
1803
|
calculateOutputSize(e) {
|
|
1803
1804
|
const n = this.valuesShape, o = this.defaultValueShape;
|
|
1804
|
-
|
|
1805
|
-
const s = this.tensorShapeFromTensor(this.shape, this.shapeShape),
|
|
1806
|
-
|
|
1807
|
-
for (let
|
|
1808
|
-
i
|
|
1809
|
-
return
|
|
1805
|
+
me(o, n);
|
|
1806
|
+
const s = this.tensorShapeFromTensor(this.shape, this.shapeShape), a = de(this.raggedRank, s, n);
|
|
1807
|
+
a[0] < 0 && (a[0] = e);
|
|
1808
|
+
for (let i = 1; i <= this.raggedRank; ++i)
|
|
1809
|
+
a[i] < 0 && (a[i] = this.getMaxWidth(i));
|
|
1810
|
+
return a;
|
|
1810
1811
|
}
|
|
1811
1812
|
/**
|
|
1812
1813
|
* The outputIndex represents the index in the output tensor
|
|
@@ -1820,27 +1821,27 @@ class ut {
|
|
|
1820
1821
|
*/
|
|
1821
1822
|
calculateFirstParentOutputIndex(e, n, o) {
|
|
1822
1823
|
const s = Math.min(e, o), r = [];
|
|
1823
|
-
let
|
|
1824
|
-
for (let
|
|
1825
|
-
r.push(
|
|
1826
|
-
for (let
|
|
1824
|
+
let a = 0;
|
|
1825
|
+
for (let i = 0; i < s; ++i, a += n)
|
|
1826
|
+
r.push(a);
|
|
1827
|
+
for (let i = s; i < e; ++i)
|
|
1827
1828
|
r.push(-1);
|
|
1828
|
-
return
|
|
1829
|
+
return jt(r.length === e, () => "Final length of result must be equal to firstDimension."), r;
|
|
1829
1830
|
}
|
|
1830
1831
|
calculateOutputIndexRowSplit(e, n, o, s) {
|
|
1831
|
-
const r = e.length,
|
|
1832
|
-
for (let
|
|
1833
|
-
const u = e[
|
|
1834
|
-
let c = Math.min(s, u), h = n[
|
|
1832
|
+
const r = e.length, a = [];
|
|
1833
|
+
for (let i = 0; i < r - 1; ++i) {
|
|
1834
|
+
const u = e[i + 1] - e[i];
|
|
1835
|
+
let c = Math.min(s, u), h = n[i];
|
|
1835
1836
|
h === -1 && (c = 0);
|
|
1836
1837
|
for (let f = 0; f < c; ++f)
|
|
1837
|
-
|
|
1838
|
+
a.push(h), h += o;
|
|
1838
1839
|
for (let f = 0; f < u - c; ++f)
|
|
1839
|
-
|
|
1840
|
+
a.push(-1);
|
|
1840
1841
|
}
|
|
1841
|
-
if (r > 0 &&
|
|
1842
|
+
if (r > 0 && a.length !== e[r - 1])
|
|
1842
1843
|
throw new Error("Invalid row split size.");
|
|
1843
|
-
return
|
|
1844
|
+
return a;
|
|
1844
1845
|
}
|
|
1845
1846
|
// Calculate the output index of the first element of a list.
|
|
1846
1847
|
// The parentOutputIndex is the same computation for the previous list.
|
|
@@ -1864,40 +1865,40 @@ class ut {
|
|
|
1864
1865
|
// result[7] = -1 because parentOutputIndex[valueRowIds[6]] == -1
|
|
1865
1866
|
// result[8] = parentOutputIndex[valueRowIds[7]]
|
|
1866
1867
|
calculateOutputIndexValueRowID(e, n, o, s) {
|
|
1867
|
-
const r = e.length,
|
|
1868
|
+
const r = e.length, a = [];
|
|
1868
1869
|
if (r === 0)
|
|
1869
1870
|
return [];
|
|
1870
|
-
let
|
|
1871
|
+
let i = 0, u = e[0];
|
|
1871
1872
|
if (u >= n.length)
|
|
1872
1873
|
throw new Error(`Got currentValueRowId=${u}, which is not less than ${n.length}`);
|
|
1873
1874
|
let c = n[u];
|
|
1874
|
-
|
|
1875
|
+
a.push(c);
|
|
1875
1876
|
for (let h = 1; h < r; ++h) {
|
|
1876
1877
|
const f = e[h];
|
|
1877
1878
|
if (f === u)
|
|
1878
|
-
c >= 0 && (++
|
|
1879
|
+
c >= 0 && (++i, i < s ? c += o : c = -1);
|
|
1879
1880
|
else {
|
|
1880
|
-
if (
|
|
1881
|
+
if (i = 0, u = f, f >= n.length)
|
|
1881
1882
|
throw new Error(`Got nextValueRowId=${f} which is not less than ${n.length}`);
|
|
1882
1883
|
c = n[f];
|
|
1883
1884
|
}
|
|
1884
|
-
|
|
1885
|
+
a.push(c);
|
|
1885
1886
|
}
|
|
1886
|
-
if (
|
|
1887
|
+
if (a.length !== e.length)
|
|
1887
1888
|
throw new Error("Invalid row ids.");
|
|
1888
|
-
return
|
|
1889
|
+
return a;
|
|
1889
1890
|
}
|
|
1890
1891
|
calculateOutputIndex(e, n, o, s) {
|
|
1891
|
-
const r = this.getRowPartitionTensor(e),
|
|
1892
|
-
switch (
|
|
1893
|
-
case
|
|
1892
|
+
const r = this.getRowPartitionTensor(e), a = this.getRowPartitionTypeByDimension(e);
|
|
1893
|
+
switch (a) {
|
|
1894
|
+
case Z.VALUE_ROWIDS:
|
|
1894
1895
|
return this.calculateOutputIndexValueRowID(r, n, o, s);
|
|
1895
|
-
case
|
|
1896
|
+
case Z.ROW_SPLITS:
|
|
1896
1897
|
if (r.length - 1 > n.length)
|
|
1897
1898
|
throw new Error(`Row partition size is greater than output size: ${r.length - 1} > ${n.length}`);
|
|
1898
1899
|
return this.calculateOutputIndexRowSplit(r, n, o, s);
|
|
1899
1900
|
default:
|
|
1900
|
-
throw new Error(`Unsupported partition type: ${
|
|
1901
|
+
throw new Error(`Unsupported partition type: ${Z[a]}`);
|
|
1901
1902
|
}
|
|
1902
1903
|
}
|
|
1903
1904
|
getFirstDimensionSize() {
|
|
@@ -1906,14 +1907,14 @@ class ut {
|
|
|
1906
1907
|
throw new Error("No row_partition_types given.");
|
|
1907
1908
|
const n = this.rowPartitionTypes[0];
|
|
1908
1909
|
switch (n) {
|
|
1909
|
-
case
|
|
1910
|
+
case Z.FIRST_DIM_SIZE:
|
|
1910
1911
|
return e[0];
|
|
1911
|
-
case
|
|
1912
|
+
case Z.VALUE_ROWIDS:
|
|
1912
1913
|
throw new Error("Cannot handle VALUE_ROWIDS in first dimension.");
|
|
1913
|
-
case
|
|
1914
|
+
case Z.ROW_SPLITS:
|
|
1914
1915
|
return this.rowPartitionValuesShapes[0][0] - 1;
|
|
1915
1916
|
default:
|
|
1916
|
-
throw new Error(`Cannot handle type ${
|
|
1917
|
+
throw new Error(`Cannot handle type ${Z[n]}`);
|
|
1917
1918
|
}
|
|
1918
1919
|
}
|
|
1919
1920
|
compute() {
|
|
@@ -1923,28 +1924,28 @@ class ut {
|
|
|
1923
1924
|
s[s.length - 1] = 1;
|
|
1924
1925
|
for (let u = s.length - 2; u >= 0; --u)
|
|
1925
1926
|
s[u] = s[u + 1] * o[u + 1];
|
|
1926
|
-
const r = Ft(o, !1),
|
|
1927
|
+
const r = Ft(o, !1), a = q(this.valuesDType, y(r));
|
|
1927
1928
|
if (s[0] * o[0] > 0) {
|
|
1928
1929
|
let u = this.calculateFirstParentOutputIndex(n, s[0], o[0]);
|
|
1929
1930
|
for (let c = 1; c <= this.raggedRank; ++c)
|
|
1930
1931
|
u = this.calculateOutputIndex(c - 1, u, s[c], o[c]);
|
|
1931
|
-
this.setOutput(this.raggedRank, u,
|
|
1932
|
+
this.setOutput(this.raggedRank, u, a, r);
|
|
1932
1933
|
}
|
|
1933
|
-
return [r,
|
|
1934
|
+
return [r, a];
|
|
1934
1935
|
}
|
|
1935
1936
|
setOutput(e, n, o, s) {
|
|
1936
1937
|
if (o.length === 0)
|
|
1937
1938
|
return;
|
|
1938
|
-
const r = this.values,
|
|
1939
|
-
let
|
|
1940
|
-
|
|
1941
|
-
const u =
|
|
1939
|
+
const r = this.values, a = o;
|
|
1940
|
+
let i = s.slice();
|
|
1941
|
+
i = i.slice(e + 1);
|
|
1942
|
+
const u = y(i), c = n.length;
|
|
1942
1943
|
let h = this.defaultValue;
|
|
1943
1944
|
if (h.length !== u && h.length !== 1) {
|
|
1944
1945
|
const m = this.defaultValueShape;
|
|
1945
|
-
|
|
1946
|
-
const b =
|
|
1947
|
-
h =
|
|
1946
|
+
Zt(() => {
|
|
1947
|
+
const b = oe(h, m);
|
|
1948
|
+
h = te(b, i).dataSync();
|
|
1948
1949
|
});
|
|
1949
1950
|
}
|
|
1950
1951
|
let f = 0, w = 0, p = 0;
|
|
@@ -1955,8 +1956,8 @@ class ut {
|
|
|
1955
1956
|
continue;
|
|
1956
1957
|
}
|
|
1957
1958
|
if (w < p) {
|
|
1958
|
-
const d = r.subarray(f * u), g =
|
|
1959
|
-
|
|
1959
|
+
const d = r.subarray(f * u), g = a.subarray(w * u), x = (p - w) * u;
|
|
1960
|
+
Ot(g, d, x);
|
|
1960
1961
|
}
|
|
1961
1962
|
if (m >= c) {
|
|
1962
1963
|
const d = o.length;
|
|
@@ -1964,17 +1965,17 @@ class ut {
|
|
|
1964
1965
|
}
|
|
1965
1966
|
if (b > p)
|
|
1966
1967
|
if (this.defaultValue.length === 1)
|
|
1967
|
-
|
|
1968
|
+
a.subarray(p * u, b * u).fill(this.defaultValue[0]), p = b;
|
|
1968
1969
|
else
|
|
1969
1970
|
for (; b > p; ) {
|
|
1970
|
-
const d =
|
|
1971
|
-
|
|
1971
|
+
const d = a.slice(p * u);
|
|
1972
|
+
Ot(d, h, u), ++p;
|
|
1972
1973
|
}
|
|
1973
1974
|
b < 0 ? (f = m + 1, w = p) : (f = m, w = p, p = w + 1);
|
|
1974
1975
|
}
|
|
1975
1976
|
}
|
|
1976
1977
|
}
|
|
1977
|
-
function
|
|
1978
|
+
function Ot(t, e, n) {
|
|
1978
1979
|
for (let o = 0; o < n; o++)
|
|
1979
1980
|
t[o] = e[o];
|
|
1980
1981
|
}
|
|
@@ -1992,8 +1993,8 @@ function Ft(t, e) {
|
|
|
1992
1993
|
}
|
|
1993
1994
|
return n;
|
|
1994
1995
|
}
|
|
1995
|
-
function
|
|
1996
|
-
return new
|
|
1996
|
+
function dn(t, e, n, o, s, r, a, i, u, c) {
|
|
1997
|
+
return new at(t, e, n, o, s, r, a, i, u, c).compute();
|
|
1997
1998
|
}
|
|
1998
1999
|
/**
|
|
1999
2000
|
* @license
|
|
@@ -2011,11 +2012,11 @@ function Sn(t, e, n, o, s, r, i, a, u, c) {
|
|
|
2011
2012
|
* limitations under the License.
|
|
2012
2013
|
* =============================================================================
|
|
2013
2014
|
*/
|
|
2014
|
-
function
|
|
2015
|
-
const s = t === e, r = t < e && n < 0,
|
|
2016
|
-
if (s || r ||
|
|
2015
|
+
function gn(t, e, n, o) {
|
|
2016
|
+
const s = t === e, r = t < e && n < 0, a = e < t && n > 1;
|
|
2017
|
+
if (s || r || a)
|
|
2017
2018
|
return ot(0, o);
|
|
2018
|
-
const
|
|
2019
|
+
const i = Math.abs(Math.ceil((e - t) / n)), u = ot(i, o);
|
|
2019
2020
|
e < t && n === 1 && (n = -1), u[0] = t;
|
|
2020
2021
|
for (let c = 1; c < u.length; c++)
|
|
2021
2022
|
u[c] = u[c - 1] + n;
|
|
@@ -2037,7 +2038,7 @@ function vn(t, e, n, o) {
|
|
|
2037
2038
|
* limitations under the License.
|
|
2038
2039
|
* =============================================================================
|
|
2039
2040
|
*/
|
|
2040
|
-
const
|
|
2041
|
+
const pn = K((t) => 1 / Math.sqrt(t));
|
|
2041
2042
|
/**
|
|
2042
2043
|
* @license
|
|
2043
2044
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2054,18 +2055,18 @@ const bn = X((t) => 1 / Math.sqrt(t));
|
|
|
2054
2055
|
* limitations under the License.
|
|
2055
2056
|
* =============================================================================
|
|
2056
2057
|
*/
|
|
2057
|
-
function
|
|
2058
|
+
function mn(t, e, n, o, s, r, a, i, u, c) {
|
|
2058
2059
|
const h = [o / s, s], f = t.values, w = e.values;
|
|
2059
2060
|
if (o === 0)
|
|
2060
|
-
return
|
|
2061
|
-
const p = u instanceof
|
|
2061
|
+
return B(n, e.dtype);
|
|
2062
|
+
const p = u instanceof dt ? u : B(h, e.dtype);
|
|
2062
2063
|
typeof u == "string" || typeof u == "number" ? p.values.fill(u) : typeof u == "boolean" && p.values.fill(+u);
|
|
2063
2064
|
for (let m = 0; m < r; m++) {
|
|
2064
2065
|
const b = [];
|
|
2065
2066
|
let d = 0;
|
|
2066
|
-
for (let g = 0; g <
|
|
2067
|
-
const x = f[m *
|
|
2068
|
-
b.push(x), d += x *
|
|
2067
|
+
for (let g = 0; g < a; g++) {
|
|
2068
|
+
const x = f[m * a + g];
|
|
2069
|
+
b.push(x), d += x * i[g];
|
|
2069
2070
|
}
|
|
2070
2071
|
if (d < 0 || d >= o / s)
|
|
2071
2072
|
throw new Error(`Invalid indices: ${b} does not index into ${n}`);
|
|
@@ -2090,7 +2091,7 @@ function En(t, e, n, o, s, r, i, a, u, c) {
|
|
|
2090
2091
|
* limitations under the License.
|
|
2091
2092
|
* =============================================================================
|
|
2092
2093
|
*/
|
|
2093
|
-
const
|
|
2094
|
+
const wn = K((t) => 1 / (1 + Math.exp(-t)));
|
|
2094
2095
|
/**
|
|
2095
2096
|
* @license
|
|
2096
2097
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2107,18 +2108,18 @@ const $n = X((t) => 1 / (1 + Math.exp(-t)));
|
|
|
2107
2108
|
* limitations under the License.
|
|
2108
2109
|
* =============================================================================
|
|
2109
2110
|
*/
|
|
2110
|
-
function
|
|
2111
|
-
const r =
|
|
2111
|
+
function In(t, e, n, o, s) {
|
|
2112
|
+
const r = ee(o, e, n), a = y(n), i = J(o);
|
|
2112
2113
|
if (r) {
|
|
2113
|
-
const f =
|
|
2114
|
-
return s === "string" ? t.slice(f, f +
|
|
2114
|
+
const f = ne(e, i);
|
|
2115
|
+
return s === "string" ? t.slice(f, f + a) : t.subarray(f, f + a);
|
|
2115
2116
|
}
|
|
2116
|
-
const u = s === "string" ?
|
|
2117
|
+
const u = s === "string" ? $t(t) : t, c = B(o, s, u), h = B(n, s);
|
|
2117
2118
|
for (let f = 0; f < h.size; ++f) {
|
|
2118
2119
|
const w = h.indexToLoc(f), p = w.map((m, b) => m + e[b]);
|
|
2119
2120
|
h.set(c.get(...p), ...w);
|
|
2120
2121
|
}
|
|
2121
|
-
return s === "string" ?
|
|
2122
|
+
return s === "string" ? Qt(h.values) : h.values;
|
|
2122
2123
|
}
|
|
2123
2124
|
/**
|
|
2124
2125
|
* @license
|
|
@@ -2136,12 +2137,12 @@ function Rn(t, e, n, o, s) {
|
|
|
2136
2137
|
* limitations under the License.
|
|
2137
2138
|
* =============================================================================
|
|
2138
2139
|
*/
|
|
2139
|
-
function
|
|
2140
|
-
const
|
|
2140
|
+
function xn(t, e, n, o, s, r, a) {
|
|
2141
|
+
const i = e[0], u = r[0], c = new Array(u), h = new Array(i), f = e[1];
|
|
2141
2142
|
if (u === 0) {
|
|
2142
|
-
if (
|
|
2143
|
-
throw new Error(
|
|
2144
|
-
const d =
|
|
2143
|
+
if (i !== 0)
|
|
2144
|
+
throw new Error(xe(i));
|
|
2145
|
+
const d = q(n, 0), g = q(s, 0);
|
|
2145
2146
|
return [
|
|
2146
2147
|
d,
|
|
2147
2148
|
[0, f],
|
|
@@ -2152,12 +2153,12 @@ function Fn(t, e, n, o, s, r, i) {
|
|
|
2152
2153
|
}
|
|
2153
2154
|
let w = !0, p = 0;
|
|
2154
2155
|
const m = new Array(u).fill(0);
|
|
2155
|
-
for (let d = 0; d <
|
|
2156
|
+
for (let d = 0; d < i; ++d) {
|
|
2156
2157
|
const g = t[d * f];
|
|
2157
2158
|
if (g < 0)
|
|
2158
|
-
throw new Error(
|
|
2159
|
+
throw new Error(Se(d, g));
|
|
2159
2160
|
if (g >= u)
|
|
2160
|
-
throw new Error(
|
|
2161
|
+
throw new Error(Ee(d, g, u));
|
|
2161
2162
|
++m[g], w = w && g >= p, p = g;
|
|
2162
2163
|
}
|
|
2163
2164
|
let b = !0;
|
|
@@ -2167,31 +2168,31 @@ function Fn(t, e, n, o, s, r, i) {
|
|
|
2167
2168
|
}
|
|
2168
2169
|
if (b && w) {
|
|
2169
2170
|
const d = t, g = o;
|
|
2170
|
-
for (let x = 0; x <
|
|
2171
|
+
for (let x = 0; x < i; ++x)
|
|
2171
2172
|
h[x] = x;
|
|
2172
2173
|
return [
|
|
2173
2174
|
d,
|
|
2174
|
-
[
|
|
2175
|
+
[i, f],
|
|
2175
2176
|
g,
|
|
2176
2177
|
c,
|
|
2177
2178
|
h
|
|
2178
2179
|
];
|
|
2179
2180
|
} else {
|
|
2180
|
-
const d = m[u - 1], g =
|
|
2181
|
-
for (let
|
|
2182
|
-
const V = t[
|
|
2183
|
-
|
|
2181
|
+
const d = m[u - 1], g = q(n, d * f), x = q(s, d), O = new Array(u).fill(0);
|
|
2182
|
+
for (let v = 0; v < i; ++v) {
|
|
2183
|
+
const V = t[v * f], D = O[V], L = (V === 0 ? 0 : m[V - 1]) + D;
|
|
2184
|
+
O[V]++;
|
|
2184
2185
|
for (let _ = 0; _ < f; ++_)
|
|
2185
|
-
g[
|
|
2186
|
-
x[
|
|
2186
|
+
g[L * f + _] = t[v * f + _];
|
|
2187
|
+
x[L] = o[v], h[v] = L;
|
|
2187
2188
|
}
|
|
2188
|
-
for (let
|
|
2189
|
-
if (
|
|
2190
|
-
const
|
|
2191
|
-
g[
|
|
2192
|
-
for (let
|
|
2193
|
-
g[
|
|
2194
|
-
x[
|
|
2189
|
+
for (let v = 0; v < u; ++v)
|
|
2190
|
+
if (O[v] === 0) {
|
|
2191
|
+
const D = v === 0 ? 0 : m[v - 1];
|
|
2192
|
+
g[D * f + 0] = v;
|
|
2193
|
+
for (let L = 1; L < f; ++L)
|
|
2194
|
+
g[D * f + L] = 0;
|
|
2195
|
+
x[D] = a;
|
|
2195
2196
|
}
|
|
2196
2197
|
return [
|
|
2197
2198
|
g,
|
|
@@ -2218,31 +2219,31 @@ function Fn(t, e, n, o, s, r, i) {
|
|
|
2218
2219
|
* limitations under the License.
|
|
2219
2220
|
* =============================================================================
|
|
2220
2221
|
*/
|
|
2221
|
-
function
|
|
2222
|
-
const r =
|
|
2222
|
+
function Sn(t, e, n, o, s) {
|
|
2223
|
+
const r = y(o), a = e[0], i = s.length, u = [];
|
|
2223
2224
|
let c = 1, h = -1;
|
|
2224
|
-
for (let d = 0; d <
|
|
2225
|
+
for (let d = 0; d < i; ++d) {
|
|
2225
2226
|
const g = s[d];
|
|
2226
2227
|
if (g === -1) {
|
|
2227
2228
|
if (h !== -1)
|
|
2228
|
-
throw new Error(
|
|
2229
|
+
throw new Error(be(h, d));
|
|
2229
2230
|
h = d, u.push(1);
|
|
2230
2231
|
} else {
|
|
2231
2232
|
if (g < 0)
|
|
2232
|
-
throw new Error(
|
|
2233
|
+
throw new Error(ve(d, g));
|
|
2233
2234
|
c *= g, u.push(g);
|
|
2234
2235
|
}
|
|
2235
2236
|
}
|
|
2236
2237
|
if (h !== -1) {
|
|
2237
2238
|
if (c <= 0)
|
|
2238
|
-
throw new Error(
|
|
2239
|
+
throw new Error(Oe());
|
|
2239
2240
|
const d = Math.trunc(r / c);
|
|
2240
2241
|
if (c * d !== r)
|
|
2241
|
-
throw new Error(
|
|
2242
|
+
throw new Error(Fe(o, u));
|
|
2242
2243
|
u[h] = d;
|
|
2243
2244
|
}
|
|
2244
|
-
if (
|
|
2245
|
-
throw new Error(
|
|
2245
|
+
if (y(u) !== r)
|
|
2246
|
+
throw new Error(Re(o, u));
|
|
2246
2247
|
const w = o.length, p = [];
|
|
2247
2248
|
if (w > 0) {
|
|
2248
2249
|
p[w - 1] = 1;
|
|
@@ -2250,20 +2251,20 @@ function On(t, e, n, o, s) {
|
|
|
2250
2251
|
p[d] = p[d + 1] * o[d + 1];
|
|
2251
2252
|
}
|
|
2252
2253
|
const m = [];
|
|
2253
|
-
if (
|
|
2254
|
-
m[
|
|
2255
|
-
for (let d =
|
|
2254
|
+
if (i > 0) {
|
|
2255
|
+
m[i - 1] = 1;
|
|
2256
|
+
for (let d = i - 2; d >= 0; --d)
|
|
2256
2257
|
m[d] = m[d + 1] * u[d + 1];
|
|
2257
2258
|
}
|
|
2258
|
-
const b =
|
|
2259
|
-
for (let d = 0; d <
|
|
2259
|
+
const b = q(n, a * i);
|
|
2260
|
+
for (let d = 0; d < a; ++d) {
|
|
2260
2261
|
let g = 0;
|
|
2261
2262
|
for (let x = 0; x < w; ++x)
|
|
2262
2263
|
g += t[d * w + x] * p[x];
|
|
2263
|
-
for (let x = 0; x <
|
|
2264
|
-
b[d *
|
|
2264
|
+
for (let x = 0; x < i; ++x)
|
|
2265
|
+
b[d * i + x] = Math.trunc(g / m[x]), g %= m[x];
|
|
2265
2266
|
}
|
|
2266
|
-
return [b, [
|
|
2267
|
+
return [b, [a, i], u];
|
|
2267
2268
|
}
|
|
2268
2269
|
/**
|
|
2269
2270
|
* @license
|
|
@@ -2281,45 +2282,45 @@ function On(t, e, n, o, s) {
|
|
|
2281
2282
|
* limitations under the License.
|
|
2282
2283
|
* =============================================================================
|
|
2283
2284
|
*/
|
|
2284
|
-
function
|
|
2285
|
-
const
|
|
2285
|
+
function En(t, e, n, o, s, r = !1, a = 0) {
|
|
2286
|
+
const i = o.length, u = [e[0], t.length / e[0]], c = u[1], f = i > 0 ? s[i - 1] + 1 : 0;
|
|
2286
2287
|
if (f < 0)
|
|
2287
|
-
throw new Error(
|
|
2288
|
+
throw new Error(Et());
|
|
2288
2289
|
const w = e.slice();
|
|
2289
2290
|
w[0] = f;
|
|
2290
|
-
const p = w.reduce((
|
|
2291
|
-
if (
|
|
2292
|
-
return f > 0 && m.fill(
|
|
2291
|
+
const p = w.reduce((O, v) => O * v, 1), m = q(n, p);
|
|
2292
|
+
if (i === 0)
|
|
2293
|
+
return f > 0 && m.fill(a), [m, w];
|
|
2293
2294
|
if (f <= 0)
|
|
2294
|
-
throw new Error(
|
|
2295
|
+
throw new Error(Et());
|
|
2295
2296
|
let b = 0, d = 1, g = 0, x = s[b];
|
|
2296
2297
|
for (; ; ) {
|
|
2297
|
-
let
|
|
2298
|
-
if (d <
|
|
2299
|
-
if (
|
|
2298
|
+
let O = 0;
|
|
2299
|
+
if (d < i) {
|
|
2300
|
+
if (O = s[d], x === O) {
|
|
2300
2301
|
++d;
|
|
2301
2302
|
continue;
|
|
2302
2303
|
}
|
|
2303
|
-
if (x >=
|
|
2304
|
-
throw new Error(
|
|
2304
|
+
if (x >= O)
|
|
2305
|
+
throw new Error($e());
|
|
2305
2306
|
}
|
|
2306
2307
|
if (x < 0 || x >= f)
|
|
2307
|
-
throw new Error(
|
|
2308
|
-
x > g && m.fill(
|
|
2309
|
-
for (let
|
|
2310
|
-
const V = o[
|
|
2308
|
+
throw new Error(ye(x, f));
|
|
2309
|
+
x > g && m.fill(a, g * c, x * c);
|
|
2310
|
+
for (let v = b; v < d; ++v) {
|
|
2311
|
+
const V = o[v];
|
|
2311
2312
|
if (V < 0 || V >= u[0])
|
|
2312
|
-
throw new Error(
|
|
2313
|
-
for (let
|
|
2314
|
-
m[x * c +
|
|
2313
|
+
throw new Error(Te(v, o[v], u[0]));
|
|
2314
|
+
for (let D = 0; D < c; D++)
|
|
2315
|
+
m[x * c + D] += t[V * c + D];
|
|
2315
2316
|
}
|
|
2316
2317
|
if (r)
|
|
2317
|
-
for (let
|
|
2318
|
-
m[x * c +
|
|
2319
|
-
if (b = d, ++d, g = x + 1, x =
|
|
2318
|
+
for (let v = 0; v < c; v++)
|
|
2319
|
+
m[x * c + v] /= d - b;
|
|
2320
|
+
if (b = d, ++d, g = x + 1, x = O, d > i)
|
|
2320
2321
|
break;
|
|
2321
2322
|
}
|
|
2322
|
-
return g < f && m.fill(
|
|
2323
|
+
return g < f && m.fill(a, g * c, f * c), [m, w];
|
|
2323
2324
|
}
|
|
2324
2325
|
/**
|
|
2325
2326
|
* @license
|
|
@@ -2337,7 +2338,7 @@ function yn(t, e, n, o, s, r = !1, i = 0) {
|
|
|
2337
2338
|
* limitations under the License.
|
|
2338
2339
|
* =============================================================================
|
|
2339
2340
|
*/
|
|
2340
|
-
const
|
|
2341
|
+
const bn = K((t) => Math.sqrt(t));
|
|
2341
2342
|
/**
|
|
2342
2343
|
* @license
|
|
2343
2344
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2354,7 +2355,7 @@ const Tn = X((t) => Math.sqrt(t));
|
|
|
2354
2355
|
* limitations under the License.
|
|
2355
2356
|
* =============================================================================
|
|
2356
2357
|
*/
|
|
2357
|
-
const
|
|
2358
|
+
const vn = C((t, e) => {
|
|
2358
2359
|
const n = t - e;
|
|
2359
2360
|
return n * n;
|
|
2360
2361
|
});
|
|
@@ -2374,7 +2375,7 @@ const Vn = k((t, e) => {
|
|
|
2374
2375
|
* limitations under the License.
|
|
2375
2376
|
* =============================================================================
|
|
2376
2377
|
*/
|
|
2377
|
-
const
|
|
2378
|
+
const On = K((t, e) => {
|
|
2378
2379
|
const { pattern: n, replaceGlobal: o, rewrite: s } = e;
|
|
2379
2380
|
return t.replace(new RegExp(n, o ? "g" : ""), s);
|
|
2380
2381
|
});
|
|
@@ -2394,13 +2395,13 @@ const Ln = X((t, e) => {
|
|
|
2394
2395
|
* limitations under the License.
|
|
2395
2396
|
* =============================================================================
|
|
2396
2397
|
*/
|
|
2397
|
-
function
|
|
2398
|
-
const s =
|
|
2398
|
+
function Fn(t, e, n, o) {
|
|
2399
|
+
const s = B(t, e.dtype);
|
|
2399
2400
|
for (let r = 0; r < s.size; r++) {
|
|
2400
|
-
const
|
|
2401
|
-
for (let u = 0; u <
|
|
2402
|
-
|
|
2403
|
-
s.set(e.get(...
|
|
2401
|
+
const a = s.indexToLoc(r), i = new Array(a.length);
|
|
2402
|
+
for (let u = 0; u < i.length; u++)
|
|
2403
|
+
i[u] = a[u] * n[u] + o[u];
|
|
2404
|
+
s.set(e.get(...i), ...a);
|
|
2404
2405
|
}
|
|
2405
2406
|
return s;
|
|
2406
2407
|
}
|
|
@@ -2420,9 +2421,9 @@ function Mn(t, e, n, o) {
|
|
|
2420
2421
|
* limitations under the License.
|
|
2421
2422
|
* =============================================================================
|
|
2422
2423
|
*/
|
|
2423
|
-
class
|
|
2424
|
-
constructor(e, n, o, s, r,
|
|
2425
|
-
this.separator =
|
|
2424
|
+
class Rn {
|
|
2425
|
+
constructor(e, n, o, s, r, a) {
|
|
2426
|
+
this.separator = ct(e), this.nGramWidths = n, this.leftPad = ct(o), this.rightPad = ct(s), this.padWidth = r, this.preserveShort = a;
|
|
2426
2427
|
}
|
|
2427
2428
|
getPadWidth(e) {
|
|
2428
2429
|
return Math.min(this.padWidth < 0 ? e - 1 : this.padWidth, e - 1);
|
|
@@ -2431,19 +2432,19 @@ class _n {
|
|
|
2431
2432
|
const o = this.getPadWidth(n);
|
|
2432
2433
|
return Math.max(0, e + 2 * o - n + 1);
|
|
2433
2434
|
}
|
|
2434
|
-
createNGrams(e, n, o, s, r,
|
|
2435
|
-
for (let
|
|
2436
|
-
const u = this.getPadWidth(
|
|
2435
|
+
createNGrams(e, n, o, s, r, a) {
|
|
2436
|
+
for (let i = 0; i < r; ++i) {
|
|
2437
|
+
const u = this.getPadWidth(a), c = Math.max(0, u - i), h = Math.max(0, u - (r - (i + 1))), f = a - (c + h), w = n + (c > 0 ? 0 : i - u);
|
|
2437
2438
|
let p = 0;
|
|
2438
2439
|
p += c * this.leftPad.length;
|
|
2439
2440
|
for (let x = 0; x < f; ++x)
|
|
2440
2441
|
p += e[w + x].length;
|
|
2441
2442
|
p += h * this.rightPad.length;
|
|
2442
2443
|
const m = c + h + f - 1;
|
|
2443
|
-
p += m * this.separator.length, o[s +
|
|
2444
|
-
const b = o[s +
|
|
2444
|
+
p += m * this.separator.length, o[s + i] = new Uint8Array(p);
|
|
2445
|
+
const b = o[s + i];
|
|
2445
2446
|
let d = 0;
|
|
2446
|
-
const g = (x) => x.forEach((
|
|
2447
|
+
const g = (x) => x.forEach((O) => b[d++] = O);
|
|
2447
2448
|
for (let x = 0; x < c; ++x)
|
|
2448
2449
|
g(this.leftPad), g(this.separator);
|
|
2449
2450
|
for (let x = 0; x < f - 1; ++x)
|
|
@@ -2477,41 +2478,41 @@ class _n {
|
|
|
2477
2478
|
if (u !== o)
|
|
2478
2479
|
throw new Error(`Last split value must be data size. Expected ${o}, got ${u}`);
|
|
2479
2480
|
}
|
|
2480
|
-
const r = s - 1,
|
|
2481
|
+
const r = s - 1, a = q("int32", s);
|
|
2481
2482
|
if (o === 0 || s === 0) {
|
|
2482
2483
|
const u = new Array(o);
|
|
2483
2484
|
for (let c = 0; c <= r; ++c)
|
|
2484
|
-
|
|
2485
|
-
return [u,
|
|
2485
|
+
a[c] = 0;
|
|
2486
|
+
return [u, a];
|
|
2486
2487
|
}
|
|
2487
|
-
|
|
2488
|
+
a[0] = 0;
|
|
2488
2489
|
for (let u = 1; u <= r; ++u) {
|
|
2489
2490
|
const c = n[u] - n[u - 1];
|
|
2490
2491
|
let h = 0;
|
|
2491
2492
|
this.nGramWidths.forEach((f) => {
|
|
2492
2493
|
h += this.getNumNGrams(c, f);
|
|
2493
|
-
}), this.preserveShort && c > 0 && h === 0 && (h = 1),
|
|
2494
|
+
}), this.preserveShort && c > 0 && h === 0 && (h = 1), a[u] = a[u - 1] + h;
|
|
2494
2495
|
}
|
|
2495
|
-
const
|
|
2496
|
+
const i = new Array(a[r]);
|
|
2496
2497
|
for (let u = 0; u < r; ++u) {
|
|
2497
2498
|
const c = n[u];
|
|
2498
|
-
let h =
|
|
2499
|
+
let h = a[u];
|
|
2499
2500
|
if (this.nGramWidths.forEach((f) => {
|
|
2500
2501
|
const w = n[u + 1] - n[u], p = this.getNumNGrams(w, f);
|
|
2501
|
-
this.createNGrams(e, c,
|
|
2502
|
-
}), this.preserveShort && h ===
|
|
2502
|
+
this.createNGrams(e, c, i, h, p, f), h += p;
|
|
2503
|
+
}), this.preserveShort && h === a[u]) {
|
|
2503
2504
|
const f = n[u + 1] - n[u];
|
|
2504
2505
|
if (f === 0)
|
|
2505
2506
|
continue;
|
|
2506
2507
|
const w = f + 2 * this.padWidth;
|
|
2507
|
-
this.createNGrams(e, c,
|
|
2508
|
+
this.createNGrams(e, c, i, h, 1, w);
|
|
2508
2509
|
}
|
|
2509
2510
|
}
|
|
2510
|
-
return [
|
|
2511
|
+
return [i, a];
|
|
2511
2512
|
}
|
|
2512
2513
|
}
|
|
2513
|
-
function
|
|
2514
|
-
return new
|
|
2514
|
+
function $n(t, e, n, o, s, r, a, i) {
|
|
2515
|
+
return new Rn(n, o, s, r, a, i).compute(t, e);
|
|
2515
2516
|
}
|
|
2516
2517
|
/**
|
|
2517
2518
|
* @license
|
|
@@ -2529,7 +2530,7 @@ function An(t, e, n, o, s, r, i, a) {
|
|
|
2529
2530
|
* limitations under the License.
|
|
2530
2531
|
* =============================================================================
|
|
2531
2532
|
*/
|
|
2532
|
-
function
|
|
2533
|
+
function yn(t, e, n, o) {
|
|
2533
2534
|
if (!t.length)
|
|
2534
2535
|
return;
|
|
2535
2536
|
if (e.length === 0) {
|
|
@@ -2539,10 +2540,10 @@ function Nn(t, e, n, o) {
|
|
|
2539
2540
|
}
|
|
2540
2541
|
if (e.length === 1) {
|
|
2541
2542
|
const r = e[0];
|
|
2542
|
-
let
|
|
2543
|
-
for (;
|
|
2544
|
-
const
|
|
2545
|
-
(!n ||
|
|
2543
|
+
let a = t.indexOf(r);
|
|
2544
|
+
for (; a !== -1; ) {
|
|
2545
|
+
const i = t.subarray(0, a);
|
|
2546
|
+
(!n || i.length !== 0) && o.push(i), t = t.subarray(a + 1), a = t.indexOf(r);
|
|
2546
2547
|
}
|
|
2547
2548
|
(!n || t.length !== 0) && o.push(t);
|
|
2548
2549
|
return;
|
|
@@ -2550,24 +2551,24 @@ function Nn(t, e, n, o) {
|
|
|
2550
2551
|
let s = 0;
|
|
2551
2552
|
for (let r = 0; r < t.length + 1; r++)
|
|
2552
2553
|
if (r === t.length || e.indexOf(t[r]) !== -1) {
|
|
2553
|
-
const
|
|
2554
|
-
(!n ||
|
|
2554
|
+
const a = t.subarray(s, r);
|
|
2555
|
+
(!n || a.length !== 0) && o.push(a), s = r + 1;
|
|
2555
2556
|
}
|
|
2556
2557
|
}
|
|
2557
|
-
function
|
|
2558
|
+
function Tn(t, e, n) {
|
|
2558
2559
|
const o = t.length, s = [];
|
|
2559
|
-
let r = 0,
|
|
2560
|
-
const
|
|
2560
|
+
let r = 0, a = 0;
|
|
2561
|
+
const i = new Array(o);
|
|
2561
2562
|
for (let w = 0; w < o; ++w) {
|
|
2562
2563
|
const p = s.length;
|
|
2563
|
-
|
|
2564
|
+
yn(t[w], e, n, s);
|
|
2564
2565
|
const m = s.length - p;
|
|
2565
|
-
|
|
2566
|
+
i[w] = m, r += m, a = Math.max(a, m);
|
|
2566
2567
|
}
|
|
2567
|
-
const u =
|
|
2568
|
+
const u = q("int32", r * 2), c = new Array(r), h = [o, a];
|
|
2568
2569
|
let f = 0;
|
|
2569
2570
|
for (let w = 0; w < o; ++w)
|
|
2570
|
-
for (let p = 0; p <
|
|
2571
|
+
for (let p = 0; p < i[w]; ++p)
|
|
2571
2572
|
u[f * 2] = w, u[f * 2 + 1] = p, c[f] = s[f], ++f;
|
|
2572
2573
|
return [u, c, h];
|
|
2573
2574
|
}
|
|
@@ -2587,10 +2588,10 @@ function Dn(t, e, n) {
|
|
|
2587
2588
|
* limitations under the License.
|
|
2588
2589
|
* =============================================================================
|
|
2589
2590
|
*/
|
|
2590
|
-
function
|
|
2591
|
-
const n =
|
|
2591
|
+
function Vn(t, e) {
|
|
2592
|
+
const n = q("int32", t.length);
|
|
2592
2593
|
for (let o = 0; o < t.length; ++o)
|
|
2593
|
-
n[o] =
|
|
2594
|
+
n[o] = fe(t[o]).modulo(e).getLowBitsUnsigned();
|
|
2594
2595
|
return n;
|
|
2595
2596
|
}
|
|
2596
2597
|
/**
|
|
@@ -2609,7 +2610,7 @@ function zn(t, e) {
|
|
|
2609
2610
|
* limitations under the License.
|
|
2610
2611
|
* =============================================================================
|
|
2611
2612
|
*/
|
|
2612
|
-
const
|
|
2613
|
+
const Mn = C((t, e) => t - e);
|
|
2613
2614
|
/**
|
|
2614
2615
|
* @license
|
|
2615
2616
|
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
@@ -2626,17 +2627,17 @@ const Pn = k((t, e) => t - e);
|
|
|
2626
2627
|
* limitations under the License.
|
|
2627
2628
|
* =============================================================================
|
|
2628
2629
|
*/
|
|
2629
|
-
function
|
|
2630
|
+
function Ln(t, e) {
|
|
2630
2631
|
const n = new Array(t.rank);
|
|
2631
2632
|
for (let s = 0; s < n.length; s++)
|
|
2632
2633
|
n[s] = t.shape[s] * e[s];
|
|
2633
|
-
const o =
|
|
2634
|
+
const o = B(n, t.dtype);
|
|
2634
2635
|
for (let s = 0; s < o.values.length; ++s) {
|
|
2635
|
-
const r = o.indexToLoc(s),
|
|
2636
|
-
for (let u = 0; u <
|
|
2637
|
-
|
|
2638
|
-
const
|
|
2639
|
-
o.values[s] = t.values[
|
|
2636
|
+
const r = o.indexToLoc(s), a = new Array(t.rank);
|
|
2637
|
+
for (let u = 0; u < a.length; u++)
|
|
2638
|
+
a[u] = r[u] % t.shape[u];
|
|
2639
|
+
const i = t.locToIndex(a);
|
|
2640
|
+
o.values[s] = t.values[i];
|
|
2640
2641
|
}
|
|
2641
2642
|
return o;
|
|
2642
2643
|
}
|
|
@@ -2660,37 +2661,37 @@ const et = (t, e) => {
|
|
|
2660
2661
|
const n = e.value - t.value;
|
|
2661
2662
|
return n === 0 ? t.index - e.index : n;
|
|
2662
2663
|
};
|
|
2663
|
-
function
|
|
2664
|
+
function Dt(t, e, n = 0, o = t.length - 1) {
|
|
2664
2665
|
for (; o > n; ) {
|
|
2665
2666
|
if (o - n > 600) {
|
|
2666
|
-
const
|
|
2667
|
-
|
|
2667
|
+
const i = o - n + 1, u = e - n + 1, c = Math.log(i), h = 0.5 * Math.exp(2 * c / 3), f = 0.5 * Math.sqrt(c * h * (i - h) / i) * Math.sign(u - i / 2), w = Math.max(n, Math.floor(e - u * h / i + f)), p = Math.min(o, Math.floor(e + (i - u) * h / i + f));
|
|
2668
|
+
Dt(t, e, w, p);
|
|
2668
2669
|
}
|
|
2669
2670
|
const s = t[e];
|
|
2670
|
-
let r = n,
|
|
2671
|
-
for (tt(t, n, e), et(t[o], s) > 0 && tt(t, n, o); r <
|
|
2672
|
-
for (tt(t, r,
|
|
2671
|
+
let r = n, a = o;
|
|
2672
|
+
for (tt(t, n, e), et(t[o], s) > 0 && tt(t, n, o); r < a; ) {
|
|
2673
|
+
for (tt(t, r, a), r++, a--; et(t[r], s) < 0; )
|
|
2673
2674
|
r = r + 1;
|
|
2674
|
-
for (; et(t[
|
|
2675
|
-
|
|
2675
|
+
for (; et(t[a], s) > 0; )
|
|
2676
|
+
a = a - 1;
|
|
2676
2677
|
}
|
|
2677
|
-
et(t[n], s) === 0 ? tt(t, n,
|
|
2678
|
+
et(t[n], s) === 0 ? tt(t, n, a) : (a = a + 1, tt(t, a, o)), a <= e && (n = a + 1), e <= a && (o = a - 1);
|
|
2678
2679
|
}
|
|
2679
2680
|
}
|
|
2680
|
-
function
|
|
2681
|
-
const r = e[e.length - 1], [
|
|
2682
|
-
for (let f = 0; f <
|
|
2683
|
-
const w = f *
|
|
2681
|
+
function _n(t, e, n, o, s) {
|
|
2682
|
+
const r = e[e.length - 1], [a, i] = [t.length / r, r], u = nt(n, a * o), c = nt("int32", a * o);
|
|
2683
|
+
for (let f = 0; f < a; f++) {
|
|
2684
|
+
const w = f * i, p = t.subarray(w, w + i);
|
|
2684
2685
|
let m = new Array(p.length);
|
|
2685
|
-
p.forEach((x,
|
|
2686
|
+
p.forEach((x, O) => m[O] = { value: x, index: O }), o < m.length && (Dt(m, o), m = m.slice(0, o)), s && m.sort(et);
|
|
2686
2687
|
const b = f * o, d = u.subarray(b, b + o), g = c.subarray(b, b + o);
|
|
2687
2688
|
for (let x = 0; x < o; x++)
|
|
2688
2689
|
d[x] = m[x].value, g[x] = m[x].index;
|
|
2689
2690
|
}
|
|
2690
2691
|
const h = e.slice();
|
|
2691
2692
|
return h[h.length - 1] = o, [
|
|
2692
|
-
|
|
2693
|
-
|
|
2693
|
+
B(h, n, u),
|
|
2694
|
+
B(h, "int32", c)
|
|
2694
2695
|
];
|
|
2695
2696
|
}
|
|
2696
2697
|
/**
|
|
@@ -2709,14 +2710,14 @@ function Wn(t, e, n, o, s) {
|
|
|
2709
2710
|
* limitations under the License.
|
|
2710
2711
|
* =============================================================================
|
|
2711
2712
|
*/
|
|
2712
|
-
function
|
|
2713
|
-
const s =
|
|
2713
|
+
function Nn(t, e, n, o) {
|
|
2714
|
+
const s = ut(e, n)[0], r = [1, n[0], 1];
|
|
2714
2715
|
for (let m = 0; m < s; m++)
|
|
2715
2716
|
r[0] *= n[m];
|
|
2716
2717
|
r[1] = n[s];
|
|
2717
2718
|
for (let m = s + 1; m < n.length; m++)
|
|
2718
2719
|
r[2] *= n[m];
|
|
2719
|
-
const
|
|
2720
|
+
const a = /* @__PURE__ */ new Map(), i = new Int32Array(n[s]), u = new dt(r, o, t), c = [], h = r[0] === 1 && r[2] === 1;
|
|
2720
2721
|
for (let m = 0; m < n[s]; m++) {
|
|
2721
2722
|
let b;
|
|
2722
2723
|
if (h)
|
|
@@ -2724,21 +2725,21 @@ function kn(t, e, n, o) {
|
|
|
2724
2725
|
else {
|
|
2725
2726
|
const g = [];
|
|
2726
2727
|
for (let x = 0; x < r[0]; x++)
|
|
2727
|
-
for (let
|
|
2728
|
-
g.push(u.get(x, m,
|
|
2728
|
+
for (let O = 0; O < r[2]; O++)
|
|
2729
|
+
g.push(u.get(x, m, O));
|
|
2729
2730
|
b = g.join(",");
|
|
2730
2731
|
}
|
|
2731
|
-
const d =
|
|
2732
|
+
const d = a.get(b);
|
|
2732
2733
|
if (d != null)
|
|
2733
|
-
|
|
2734
|
+
i[m] = d;
|
|
2734
2735
|
else {
|
|
2735
|
-
const g =
|
|
2736
|
-
|
|
2736
|
+
const g = a.size;
|
|
2737
|
+
a.set(b, g), i[m] = g, c.push(m);
|
|
2737
2738
|
}
|
|
2738
2739
|
}
|
|
2739
2740
|
const f = r.slice();
|
|
2740
|
-
f[1] =
|
|
2741
|
-
const w = new
|
|
2741
|
+
f[1] = a.size;
|
|
2742
|
+
const w = new dt(f, o);
|
|
2742
2743
|
c.forEach((m, b) => {
|
|
2743
2744
|
for (let d = 0; d < r[0]; d++)
|
|
2744
2745
|
for (let g = 0; g < r[2]; g++)
|
|
@@ -2748,7 +2749,7 @@ function kn(t, e, n, o) {
|
|
|
2748
2749
|
return p[s] = f[1], {
|
|
2749
2750
|
outputValues: w.values,
|
|
2750
2751
|
outputShape: p,
|
|
2751
|
-
indices:
|
|
2752
|
+
indices: i
|
|
2752
2753
|
};
|
|
2753
2754
|
}
|
|
2754
2755
|
/**
|
|
@@ -2767,59 +2768,59 @@ function kn(t, e, n, o) {
|
|
|
2767
2768
|
* limitations under the License.
|
|
2768
2769
|
* =============================================================================
|
|
2769
2770
|
*/
|
|
2770
|
-
const
|
|
2771
|
+
const An = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2771
2772
|
__proto__: null,
|
|
2772
|
-
addImpl:
|
|
2773
|
-
bincountImpl:
|
|
2774
|
-
bincountReduceImpl:
|
|
2775
|
-
bitwiseAndImpl:
|
|
2776
|
-
castImpl:
|
|
2777
|
-
ceilImpl:
|
|
2778
|
-
concatImpl:
|
|
2779
|
-
equalImpl:
|
|
2780
|
-
expImpl:
|
|
2781
|
-
expm1Impl:
|
|
2782
|
-
floorDivImpl:
|
|
2783
|
-
floorImpl:
|
|
2784
|
-
gatherNdImpl:
|
|
2785
|
-
gatherV2Impl:
|
|
2786
|
-
greaterEqualImpl:
|
|
2787
|
-
greaterImpl:
|
|
2788
|
-
lessEqualImpl:
|
|
2789
|
-
lessImpl:
|
|
2790
|
-
linSpaceImpl:
|
|
2791
|
-
logImpl:
|
|
2792
|
-
maxImpl:
|
|
2793
|
-
maximumImpl:
|
|
2794
|
-
minimumImpl:
|
|
2795
|
-
multiplyImpl:
|
|
2796
|
-
negImpl:
|
|
2797
|
-
notEqualImpl:
|
|
2798
|
-
prodImpl:
|
|
2799
|
-
raggedGatherImpl:
|
|
2800
|
-
raggedRangeImpl:
|
|
2801
|
-
raggedTensorToTensorImpl:
|
|
2802
|
-
rangeImpl:
|
|
2803
|
-
rsqrtImpl:
|
|
2804
|
-
scatterImpl:
|
|
2805
|
-
sigmoidImpl:
|
|
2806
|
-
simpleAbsImpl:
|
|
2807
|
-
sliceImpl:
|
|
2808
|
-
sparseFillEmptyRowsImpl:
|
|
2809
|
-
sparseReshapeImpl:
|
|
2810
|
-
sparseSegmentReductionImpl:
|
|
2811
|
-
sqrtImpl:
|
|
2812
|
-
squaredDifferenceImpl:
|
|
2813
|
-
staticRegexReplaceImpl:
|
|
2814
|
-
stridedSliceImpl:
|
|
2815
|
-
stringNGramsImpl:
|
|
2816
|
-
stringSplitImpl:
|
|
2817
|
-
stringToHashBucketFastImpl:
|
|
2818
|
-
subImpl:
|
|
2819
|
-
tileImpl:
|
|
2820
|
-
topKImpl:
|
|
2821
|
-
transposeImpl:
|
|
2822
|
-
uniqueImpl:
|
|
2773
|
+
addImpl: Le,
|
|
2774
|
+
bincountImpl: _e,
|
|
2775
|
+
bincountReduceImpl: Ne,
|
|
2776
|
+
bitwiseAndImpl: Ae,
|
|
2777
|
+
castImpl: Me,
|
|
2778
|
+
ceilImpl: Pe,
|
|
2779
|
+
concatImpl: De,
|
|
2780
|
+
equalImpl: ze,
|
|
2781
|
+
expImpl: We,
|
|
2782
|
+
expm1Impl: qe,
|
|
2783
|
+
floorDivImpl: ke,
|
|
2784
|
+
floorImpl: Ce,
|
|
2785
|
+
gatherNdImpl: Ue,
|
|
2786
|
+
gatherV2Impl: Ge,
|
|
2787
|
+
greaterEqualImpl: Ze,
|
|
2788
|
+
greaterImpl: je,
|
|
2789
|
+
lessEqualImpl: He,
|
|
2790
|
+
lessImpl: Be,
|
|
2791
|
+
linSpaceImpl: Ke,
|
|
2792
|
+
logImpl: Xe,
|
|
2793
|
+
maxImpl: Qe,
|
|
2794
|
+
maximumImpl: Ye,
|
|
2795
|
+
minimumImpl: Je,
|
|
2796
|
+
multiplyImpl: Pt,
|
|
2797
|
+
negImpl: tn,
|
|
2798
|
+
notEqualImpl: en,
|
|
2799
|
+
prodImpl: on,
|
|
2800
|
+
raggedGatherImpl: hn,
|
|
2801
|
+
raggedRangeImpl: fn,
|
|
2802
|
+
raggedTensorToTensorImpl: dn,
|
|
2803
|
+
rangeImpl: gn,
|
|
2804
|
+
rsqrtImpl: pn,
|
|
2805
|
+
scatterImpl: mn,
|
|
2806
|
+
sigmoidImpl: wn,
|
|
2807
|
+
simpleAbsImpl: Ve,
|
|
2808
|
+
sliceImpl: In,
|
|
2809
|
+
sparseFillEmptyRowsImpl: xn,
|
|
2810
|
+
sparseReshapeImpl: Sn,
|
|
2811
|
+
sparseSegmentReductionImpl: En,
|
|
2812
|
+
sqrtImpl: bn,
|
|
2813
|
+
squaredDifferenceImpl: vn,
|
|
2814
|
+
staticRegexReplaceImpl: On,
|
|
2815
|
+
stridedSliceImpl: Fn,
|
|
2816
|
+
stringNGramsImpl: $n,
|
|
2817
|
+
stringSplitImpl: Tn,
|
|
2818
|
+
stringToHashBucketFastImpl: Vn,
|
|
2819
|
+
subImpl: Mn,
|
|
2820
|
+
tileImpl: Ln,
|
|
2821
|
+
topKImpl: _n,
|
|
2822
|
+
transposeImpl: nn,
|
|
2823
|
+
uniqueImpl: Nn
|
|
2823
2824
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2824
2825
|
/**
|
|
2825
2826
|
* @license
|
|
@@ -2837,7 +2838,7 @@ const qn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
2837
2838
|
* limitations under the License.
|
|
2838
2839
|
* =============================================================================
|
|
2839
2840
|
*/
|
|
2840
|
-
const { maxImpl:
|
|
2841
|
+
const { maxImpl: Pn, transposeImpl: Dn } = An;
|
|
2841
2842
|
/**
|
|
2842
2843
|
* @license
|
|
2843
2844
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -2854,16 +2855,16 @@ const { maxImpl: Un, transposeImpl: Gn } = qn;
|
|
|
2854
2855
|
* limitations under the License.
|
|
2855
2856
|
* =============================================================================
|
|
2856
2857
|
*/
|
|
2857
|
-
class
|
|
2858
|
+
class Rt {
|
|
2858
2859
|
constructor(e, n) {
|
|
2859
2860
|
this.variableNames = ["x"];
|
|
2860
|
-
const { windowSize: o, batchSize: s, inSize: r, outSize:
|
|
2861
|
-
this.outputShape = [s,
|
|
2862
|
-
const
|
|
2861
|
+
const { windowSize: o, batchSize: s, inSize: r, outSize: a } = e;
|
|
2862
|
+
this.outputShape = [s, a];
|
|
2863
|
+
const i = Math.floor(o / 4) * 4, u = o % 4;
|
|
2863
2864
|
let c = "sumValue += dot(values, ones);";
|
|
2864
2865
|
if (n != null) {
|
|
2865
2866
|
const f = 1 / n;
|
|
2866
|
-
c = `sumValue += dot(values * ${
|
|
2867
|
+
c = `sumValue += dot(values * ${Bt(f) ? f.toPrecision(2) : f}, ones);`;
|
|
2867
2868
|
}
|
|
2868
2869
|
let h = "";
|
|
2869
2870
|
r % o > 0 && (h = `
|
|
@@ -2886,7 +2887,7 @@ class Ot {
|
|
|
2886
2887
|
|
|
2887
2888
|
float sumValue = 0.0;
|
|
2888
2889
|
|
|
2889
|
-
for (int i = 0; i < ${
|
|
2890
|
+
for (int i = 0; i < ${i}; i += 4) {
|
|
2890
2891
|
int inIdx = inOffset + i;
|
|
2891
2892
|
vec4 values = vec4(
|
|
2892
2893
|
getValue(batch, inIdx),
|
|
@@ -2898,7 +2899,7 @@ class Ot {
|
|
|
2898
2899
|
${c}
|
|
2899
2900
|
}
|
|
2900
2901
|
|
|
2901
|
-
int inIdx = inOffset + ${
|
|
2902
|
+
int inIdx = inOffset + ${i};
|
|
2902
2903
|
if (${u === 1}) {
|
|
2903
2904
|
vec4 values = vec4(getValue(batch, inIdx), 0.0, 0.0, 0.0);
|
|
2904
2905
|
|
|
@@ -2938,13 +2939,13 @@ class Ot {
|
|
|
2938
2939
|
* limitations under the License.
|
|
2939
2940
|
* =============================================================================
|
|
2940
2941
|
*/
|
|
2941
|
-
class
|
|
2942
|
+
class zn {
|
|
2942
2943
|
constructor(e, n) {
|
|
2943
2944
|
this.variableNames = ["x"];
|
|
2944
|
-
const { windowSize: o, batchSize: s, inSize: r, outSize:
|
|
2945
|
-
this.outputShape = [s,
|
|
2946
|
-
let
|
|
2947
|
-
n === "prod" ?
|
|
2945
|
+
const { windowSize: o, batchSize: s, inSize: r, outSize: a } = e;
|
|
2946
|
+
this.outputShape = [s, a];
|
|
2947
|
+
let i = "0.0", u = "";
|
|
2948
|
+
n === "prod" ? i = "1.0" : n === "min" ? (i = "1.0 / 1e-20", u = "min") : n === "max" && (i = "-1.0 / 1e-20", u = "max");
|
|
2948
2949
|
let c = `${n}(${n}(${n}(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])`;
|
|
2949
2950
|
n === "sum" ? c = "sumValue" : n === "prod" ? c = "prodValue" : n === "all" ? c = "allValue" : n === "any" && (c = "anyValue");
|
|
2950
2951
|
const h = Math.floor(o / 4) * 4, f = o % 4;
|
|
@@ -2965,11 +2966,11 @@ class jn {
|
|
|
2965
2966
|
}
|
|
2966
2967
|
}
|
|
2967
2968
|
`, p = "vec4";
|
|
2968
|
-
n === "all" ? (
|
|
2969
|
+
n === "all" ? (i = "1.0", w = `
|
|
2969
2970
|
bool reducedAllValue = all(values);
|
|
2970
2971
|
float floatedReducedAllValue = float(reducedAllValue);
|
|
2971
2972
|
allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);
|
|
2972
|
-
`, p = "bvec4") : n === "any" && (
|
|
2973
|
+
`, p = "bvec4") : n === "any" && (i = "0.0", w = `
|
|
2973
2974
|
bool reducedAnyValue = any(values);
|
|
2974
2975
|
float floatedReducedAnyValue = float(reducedAnyValue);
|
|
2975
2976
|
anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);
|
|
@@ -2980,7 +2981,7 @@ class jn {
|
|
|
2980
2981
|
return initializationValue;
|
|
2981
2982
|
}
|
|
2982
2983
|
`), this.userCode = `
|
|
2983
|
-
const float initializationValue = ${
|
|
2984
|
+
const float initializationValue = ${i};
|
|
2984
2985
|
const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);
|
|
2985
2986
|
|
|
2986
2987
|
float getValue(int batch, int inIdx) {
|
|
@@ -2994,7 +2995,7 @@ class jn {
|
|
|
2994
2995
|
int outIdx = coords[1];
|
|
2995
2996
|
int inOffset = outIdx * ${o};
|
|
2996
2997
|
|
|
2997
|
-
vec4 minMaxValue = vec4(${
|
|
2998
|
+
vec4 minMaxValue = vec4(${i});
|
|
2998
2999
|
float prodValue = 1.0;
|
|
2999
3000
|
float sumValue = 0.0;
|
|
3000
3001
|
float allValue = 1.0;
|
|
@@ -3062,10 +3063,10 @@ class jn {
|
|
|
3062
3063
|
* limitations under the License.
|
|
3063
3064
|
* =============================================================================
|
|
3064
3065
|
*/
|
|
3065
|
-
function
|
|
3066
|
+
function Wn(t) {
|
|
3066
3067
|
const e = [];
|
|
3067
3068
|
for (; e.length === 0 || e[e.length - 1].outSize !== 1; ) {
|
|
3068
|
-
const n = e.length ? e[e.length - 1].outSize : t[1], o =
|
|
3069
|
+
const n = e.length ? e[e.length - 1].outSize : t[1], o = Ie(n);
|
|
3069
3070
|
e.push({
|
|
3070
3071
|
inSize: n,
|
|
3071
3072
|
windowSize: o,
|
|
@@ -3074,171 +3075,16 @@ function Bn(t) {
|
|
|
3074
3075
|
}
|
|
3075
3076
|
return e;
|
|
3076
3077
|
}
|
|
3077
|
-
function
|
|
3078
|
-
const s =
|
|
3078
|
+
function zt(t, e, n, o) {
|
|
3079
|
+
const s = Wn(t.shape);
|
|
3079
3080
|
let r = t;
|
|
3080
|
-
for (let
|
|
3081
|
-
const { inSize:
|
|
3081
|
+
for (let a = 0; a < s.length; a++) {
|
|
3082
|
+
const { inSize: i, windowSize: u, outSize: c } = s[a];
|
|
3082
3083
|
let h, f;
|
|
3083
|
-
n === "mean" ? h =
|
|
3084
|
+
n === "mean" ? h = a === 0 ? new Rt({ windowSize: u, inSize: i, batchSize: t.shape[0], outSize: c }, i) : new Rt({ windowSize: u, inSize: i, batchSize: t.shape[0], outSize: c }) : h = new zn({ windowSize: u, inSize: i, batchSize: t.shape[0], outSize: c }, n), f = r, r = o.runWebGLProgram(h, [r], e), f.dataId !== t.dataId && o.disposeIntermediateTensorInfo(f);
|
|
3084
3085
|
}
|
|
3085
3086
|
return r;
|
|
3086
3087
|
}
|
|
3087
|
-
/**
|
|
3088
|
-
* @license
|
|
3089
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3090
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3091
|
-
* you may not use this file except in compliance with the License.
|
|
3092
|
-
* You may obtain a copy of the License at
|
|
3093
|
-
*
|
|
3094
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3095
|
-
*
|
|
3096
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3097
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3098
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3099
|
-
* See the License for the specific language governing permissions and
|
|
3100
|
-
* limitations under the License.
|
|
3101
|
-
* =============================================================================
|
|
3102
|
-
*/
|
|
3103
|
-
function Zn(t, e, n = "index") {
|
|
3104
|
-
const o = K(e);
|
|
3105
|
-
return o.map((s, r) => {
|
|
3106
|
-
const i = `int ${t[r]} = ${n} / ${s}`, a = r === o.length - 1 ? `int ${t[r + 1]} = ${n} - ${t[r]} * ${s}` : `index -= ${t[r]} * ${s}`;
|
|
3107
|
-
return `${i}; ${a};`;
|
|
3108
|
-
}).join("");
|
|
3109
|
-
}
|
|
3110
|
-
function Hn(t, e) {
|
|
3111
|
-
const n = t.length, o = t.map((r) => `${e}[${r}]`), s = new Array(n - 1);
|
|
3112
|
-
s[n - 2] = o[n - 1];
|
|
3113
|
-
for (let r = n - 3; r >= 0; --r)
|
|
3114
|
-
s[r] = `(${s[r + 1]} * ${o[r + 1]})`;
|
|
3115
|
-
return s;
|
|
3116
|
-
}
|
|
3117
|
-
function Kn(t, e, n = "index") {
|
|
3118
|
-
const o = t.map((r, i) => i), s = Hn(o, e);
|
|
3119
|
-
return s.map((r, i) => {
|
|
3120
|
-
const a = `int ${t[i]} = ${n} / ${s[i]}`, u = i === s.length - 1 ? `int ${t[i + 1]} = ${n} - ${t[i]} * ${s[i]}` : `index -= ${t[i]} * ${s[i]}`;
|
|
3121
|
-
return `${a}; ${u};`;
|
|
3122
|
-
}).join("");
|
|
3123
|
-
}
|
|
3124
|
-
function Xn(t) {
|
|
3125
|
-
const e = K(t).map((n) => n.toString());
|
|
3126
|
-
return `
|
|
3127
|
-
int getFlatIndex(ivec3 coords) {
|
|
3128
|
-
return coords.x * ${e[0]} + coords.y * ${e[1]} + coords.z;
|
|
3129
|
-
}
|
|
3130
|
-
`;
|
|
3131
|
-
}
|
|
3132
|
-
function Yn() {
|
|
3133
|
-
return `
|
|
3134
|
-
int getFlatIndex(ivec3 coords) {
|
|
3135
|
-
return coords.x * outShapeStrides[0] + coords.y * outShapeStrides[1] + coords.z;
|
|
3136
|
-
}
|
|
3137
|
-
`;
|
|
3138
|
-
}
|
|
3139
|
-
/**
|
|
3140
|
-
* @license
|
|
3141
|
-
* Copyright 2017 Google LLC. All Rights Reserved.
|
|
3142
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3143
|
-
* you may not use this file except in compliance with the License.
|
|
3144
|
-
* You may obtain a copy of the License at
|
|
3145
|
-
*
|
|
3146
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3147
|
-
*
|
|
3148
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3149
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3150
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3151
|
-
* See the License for the specific language governing permissions and
|
|
3152
|
-
* limitations under the License.
|
|
3153
|
-
* =============================================================================
|
|
3154
|
-
*/
|
|
3155
|
-
function yt(t, e = 2) {
|
|
3156
|
-
return O(t.slice(0, t.length - e));
|
|
3157
|
-
}
|
|
3158
|
-
function Tt(t) {
|
|
3159
|
-
if (t.length === 0)
|
|
3160
|
-
throw Error("Cannot get rows and columns of an empty shape array.");
|
|
3161
|
-
return [
|
|
3162
|
-
t.length > 1 ? t[t.length - 2] : 1,
|
|
3163
|
-
t[t.length - 1]
|
|
3164
|
-
];
|
|
3165
|
-
}
|
|
3166
|
-
function at(t) {
|
|
3167
|
-
return t % 2 === 0;
|
|
3168
|
-
}
|
|
3169
|
-
function Vt(t, e) {
|
|
3170
|
-
if (t = t.slice(-2), e = e.slice(-2), Jt(t, e) || !t.length || !e.length || t[0] === 0 || t[1] === 0 || e[0] === 0 || e[1] === 0)
|
|
3171
|
-
return !0;
|
|
3172
|
-
if (t.length !== e.length) {
|
|
3173
|
-
const n = t[t.length - 1], o = e[e.length - 1];
|
|
3174
|
-
if (n === o || at(n) && at(o) && (t[0] === 1 || e[0] === 1))
|
|
3175
|
-
return !0;
|
|
3176
|
-
}
|
|
3177
|
-
return t[1] === e[1] && at(t[0]) && at(e[0]);
|
|
3178
|
-
}
|
|
3179
|
-
/**
|
|
3180
|
-
* @license
|
|
3181
|
-
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
3182
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3183
|
-
* you may not use this file except in compliance with the License.
|
|
3184
|
-
* You may obtain a copy of the License at
|
|
3185
|
-
*
|
|
3186
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3187
|
-
*
|
|
3188
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3189
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3190
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3191
|
-
* See the License for the specific language governing permissions and
|
|
3192
|
-
* limitations under the License.
|
|
3193
|
-
* =============================================================================
|
|
3194
|
-
*/
|
|
3195
|
-
class Jn {
|
|
3196
|
-
constructor(e, n) {
|
|
3197
|
-
this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.customUniforms = [{ name: "inputShape", type: "ivec3" }], this.outputShape = e, this.enableShapeUniforms = se(this.outputShape.length);
|
|
3198
|
-
let o = "";
|
|
3199
|
-
for (let s = 0; s < 4; s++) {
|
|
3200
|
-
let r = "thisRC = rc;";
|
|
3201
|
-
s % 2 === 1 && (r += "thisRC.z += 1;"), s > 1 && (r += "thisRC.y += 1;"), o += `
|
|
3202
|
-
${r}
|
|
3203
|
-
${s > 0 ? "if(thisRC.y < rows && thisRC.z < cols){" : ""}
|
|
3204
|
-
int flatIndex = getFlatIndex(thisRC);
|
|
3205
|
-
|
|
3206
|
-
ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);
|
|
3207
|
-
vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));
|
|
3208
|
-
|
|
3209
|
-
result[${s}] =
|
|
3210
|
-
getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);
|
|
3211
|
-
${s > 0 ? "}" : ""}
|
|
3212
|
-
`;
|
|
3213
|
-
}
|
|
3214
|
-
this.userCode = `
|
|
3215
|
-
${Qn(n, this.enableShapeUniforms)}
|
|
3216
|
-
${this.enableShapeUniforms ? Yn() : Xn(e)}
|
|
3217
|
-
|
|
3218
|
-
void main() {
|
|
3219
|
-
ivec3 rc = getOutputCoords();
|
|
3220
|
-
|
|
3221
|
-
vec4 result = vec4(0.);
|
|
3222
|
-
|
|
3223
|
-
ivec3 thisRC;
|
|
3224
|
-
int rows = ${this.enableShapeUniforms ? "outShape[1]" : e[1]};
|
|
3225
|
-
int cols = ${this.enableShapeUniforms ? "outShape[2]" : e[2]};
|
|
3226
|
-
|
|
3227
|
-
${o}
|
|
3228
|
-
|
|
3229
|
-
setOutput(result);
|
|
3230
|
-
}
|
|
3231
|
-
`;
|
|
3232
|
-
}
|
|
3233
|
-
}
|
|
3234
|
-
function Qn(t, e) {
|
|
3235
|
-
return `
|
|
3236
|
-
ivec3 inputCoordsFromReshapedOutCoords(int index) {
|
|
3237
|
-
${e ? Kn(["r", "c", "d"], "inputShape") : Zn(["r", "c", "d"], t)}
|
|
3238
|
-
return ivec3(r, c, d);
|
|
3239
|
-
}
|
|
3240
|
-
`;
|
|
3241
|
-
}
|
|
3242
3088
|
/**
|
|
3243
3089
|
* @license
|
|
3244
3090
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -3255,61 +3101,9 @@ function Qn(t, e) {
|
|
|
3255
3101
|
* limitations under the License.
|
|
3256
3102
|
* =============================================================================
|
|
3257
3103
|
*/
|
|
3258
|
-
function
|
|
3259
|
-
const o =
|
|
3260
|
-
|
|
3261
|
-
...Tt(t.shape)
|
|
3262
|
-
], s = {
|
|
3263
|
-
dtype: t.dtype,
|
|
3264
|
-
shape: o,
|
|
3265
|
-
dataId: t.dataId
|
|
3266
|
-
}, r = [
|
|
3267
|
-
yt(e),
|
|
3268
|
-
...Tt(e)
|
|
3269
|
-
], i = new Jn(r, o), a = !0, u = [o], c = n.runWebGLProgram(i, [s], t.dtype, u, a);
|
|
3270
|
-
return { dataId: c.dataId, shape: e, dtype: c.dtype };
|
|
3271
|
-
}
|
|
3272
|
-
/**
|
|
3273
|
-
* @license
|
|
3274
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
3275
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3276
|
-
* you may not use this file except in compliance with the License.
|
|
3277
|
-
* You may obtain a copy of the License at
|
|
3278
|
-
*
|
|
3279
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3280
|
-
*
|
|
3281
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3282
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3283
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3284
|
-
* See the License for the specific language governing permissions and
|
|
3285
|
-
* limitations under the License.
|
|
3286
|
-
* =============================================================================
|
|
3287
|
-
*/
|
|
3288
|
-
function st(t) {
|
|
3289
|
-
const { inputs: e, backend: n, attrs: o } = t, { x: s } = e, { shape: r } = o, i = n, a = O(s.shape), u = Qt(r, a), c = O(u);
|
|
3290
|
-
Lt(a === c, () => `The new shape (${u}) has ${c} elements and the old shape (${s.shape}) has ${a} elements. The new shape and old shape must have the same number of elements.`);
|
|
3291
|
-
const h = i.texData.get(s.dataId);
|
|
3292
|
-
return h.isPacked && !Vt(s.shape, u) && !(h.texture !== null && Vt(h.shape, u)) ? to(s, u, i) : (i.incRef(s.dataId), { dataId: s.dataId, shape: u, dtype: s.dtype });
|
|
3293
|
-
}
|
|
3294
|
-
/**
|
|
3295
|
-
* @license
|
|
3296
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
3297
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3298
|
-
* you may not use this file except in compliance with the License.
|
|
3299
|
-
* You may obtain a copy of the License at
|
|
3300
|
-
*
|
|
3301
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3302
|
-
*
|
|
3303
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
3304
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3305
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3306
|
-
* See the License for the specific language governing permissions and
|
|
3307
|
-
* limitations under the License.
|
|
3308
|
-
* =============================================================================
|
|
3309
|
-
*/
|
|
3310
|
-
function eo(t, e, n, o) {
|
|
3311
|
-
const s = O(e), i = O(t.shape) / s, a = st({ inputs: { x: t }, attrs: { shape: [i, s] }, backend: o }), u = Ut(a, t.dtype, "max", o), c = st({ inputs: { x: u }, attrs: { shape: n }, backend: o });
|
|
3312
|
-
return o.disposeIntermediateTensorInfo(a), o.disposeIntermediateTensorInfo(u), c;
|
|
3104
|
+
function qn(t, e, n, o) {
|
|
3105
|
+
const s = y(e), a = y(t.shape) / s, i = st({ inputs: { x: t }, attrs: { shape: [a, s] }, backend: o }), u = zt(i, t.dtype, "max", o), c = st({ inputs: { x: u }, attrs: { shape: n }, backend: o });
|
|
3106
|
+
return o.disposeIntermediateTensorInfo(i), o.disposeIntermediateTensorInfo(u), c;
|
|
3313
3107
|
}
|
|
3314
3108
|
/**
|
|
3315
3109
|
* @license
|
|
@@ -3327,14 +3121,14 @@ function eo(t, e, n, o) {
|
|
|
3327
3121
|
* limitations under the License.
|
|
3328
3122
|
* =============================================================================
|
|
3329
3123
|
*/
|
|
3330
|
-
class
|
|
3124
|
+
class Cn {
|
|
3331
3125
|
constructor(e, n) {
|
|
3332
3126
|
this.variableNames = ["A"];
|
|
3333
3127
|
const o = new Array(e.length);
|
|
3334
|
-
for (let
|
|
3335
|
-
o[
|
|
3128
|
+
for (let a = 0; a < o.length; a++)
|
|
3129
|
+
o[a] = e[n[a]];
|
|
3336
3130
|
this.outputShape = o, this.rank = o.length;
|
|
3337
|
-
const s =
|
|
3131
|
+
const s = yt(this.rank), r = kn(n);
|
|
3338
3132
|
this.userCode = `
|
|
3339
3133
|
void main() {
|
|
3340
3134
|
${s} resRC = getOutputCoords();
|
|
@@ -3343,7 +3137,7 @@ class no {
|
|
|
3343
3137
|
`;
|
|
3344
3138
|
}
|
|
3345
3139
|
}
|
|
3346
|
-
function
|
|
3140
|
+
function kn(t) {
|
|
3347
3141
|
const e = t.length;
|
|
3348
3142
|
if (e > 6)
|
|
3349
3143
|
throw Error(`Transpose for rank ${e} is not yet supported`);
|
|
@@ -3368,7 +3162,7 @@ function oo(t) {
|
|
|
3368
3162
|
* limitations under the License.
|
|
3369
3163
|
* =============================================================================
|
|
3370
3164
|
*/
|
|
3371
|
-
class
|
|
3165
|
+
class Un {
|
|
3372
3166
|
constructor(e, n) {
|
|
3373
3167
|
this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0;
|
|
3374
3168
|
const o = new Array(e.length);
|
|
@@ -3376,10 +3170,10 @@ class so {
|
|
|
3376
3170
|
o[h] = e[n[h]];
|
|
3377
3171
|
if (this.outputShape = o, this.rank = o.length, this.rank > 6)
|
|
3378
3172
|
throw Error(`Packed transpose for rank ${this.rank} is not yet supported.`);
|
|
3379
|
-
const s =
|
|
3173
|
+
const s = yt(this.rank), r = Yt("rc", this.rank), a = new Array(this.rank);
|
|
3380
3174
|
for (let h = 0; h < n.length; h++)
|
|
3381
|
-
|
|
3382
|
-
const
|
|
3175
|
+
a[n[h]] = r[h];
|
|
3176
|
+
const i = `vec2(${a.slice(-2).join()})`, u = `++${r[this.rank - 1]} < ${o[this.rank - 1]}`, c = `getChannel(getA(${a.join()}), ${i})`;
|
|
3383
3177
|
this.userCode = `
|
|
3384
3178
|
void main() {
|
|
3385
3179
|
${s} rc = getOutputCoords();
|
|
@@ -3416,8 +3210,8 @@ class so {
|
|
|
3416
3210
|
* limitations under the License.
|
|
3417
3211
|
* =============================================================================
|
|
3418
3212
|
*/
|
|
3419
|
-
function
|
|
3420
|
-
const o =
|
|
3213
|
+
function Wt(t, e, n) {
|
|
3214
|
+
const o = Ht().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new Un(t.shape, e) : new Cn(t.shape, e);
|
|
3421
3215
|
return n.runWebGLProgram(o, [t], t.dtype);
|
|
3422
3216
|
}
|
|
3423
3217
|
/**
|
|
@@ -3436,36 +3230,36 @@ function Gt(t, e, n) {
|
|
|
3436
3230
|
* limitations under the License.
|
|
3437
3231
|
* =============================================================================
|
|
3438
3232
|
*/
|
|
3439
|
-
function
|
|
3440
|
-
const { inputs: e, backend: n, attrs: o } = t, { x: s } = e, { reductionIndices: r, keepDims:
|
|
3233
|
+
function Gn(t) {
|
|
3234
|
+
const { inputs: e, backend: n, attrs: o } = t, { x: s } = e, { reductionIndices: r, keepDims: a } = o, i = s.shape.length, u = ut(r, s.shape);
|
|
3441
3235
|
let c = u;
|
|
3442
|
-
const h =
|
|
3236
|
+
const h = Tt(c, i), f = h != null, w = n.shouldExecuteOnCPU([s]);
|
|
3443
3237
|
let p = s;
|
|
3444
3238
|
if (f) {
|
|
3445
3239
|
if (w) {
|
|
3446
|
-
const
|
|
3447
|
-
for (let
|
|
3448
|
-
|
|
3449
|
-
const V =
|
|
3450
|
-
p = n.makeTensorInfo(
|
|
3451
|
-
const
|
|
3452
|
-
|
|
3240
|
+
const O = n.texData.get(p.dataId).values, v = new Array(i);
|
|
3241
|
+
for (let L = 0; L < v.length; L++)
|
|
3242
|
+
v[L] = s.shape[h[L]];
|
|
3243
|
+
const V = Dn(O, s.shape, s.dtype, h, v);
|
|
3244
|
+
p = n.makeTensorInfo(v, s.dtype);
|
|
3245
|
+
const D = n.texData.get(p.dataId);
|
|
3246
|
+
D.values = V;
|
|
3453
3247
|
} else
|
|
3454
|
-
p =
|
|
3455
|
-
c =
|
|
3248
|
+
p = Wt(s, h, n);
|
|
3249
|
+
c = Vt(c.length, i);
|
|
3456
3250
|
}
|
|
3457
|
-
|
|
3458
|
-
const [m, b] =
|
|
3251
|
+
Mt("max", c, i);
|
|
3252
|
+
const [m, b] = mt(p.shape, c);
|
|
3459
3253
|
let d = m;
|
|
3460
|
-
|
|
3254
|
+
a && (d = wt(m, u));
|
|
3461
3255
|
let g;
|
|
3462
3256
|
if (w) {
|
|
3463
|
-
const
|
|
3257
|
+
const O = n.texData.get(p.dataId).values, v = Pn(O, y(b), d, s.dtype);
|
|
3464
3258
|
g = n.makeTensorInfo(d, s.dtype);
|
|
3465
3259
|
const V = n.texData.get(g.dataId);
|
|
3466
|
-
V.values =
|
|
3260
|
+
V.values = v;
|
|
3467
3261
|
} else
|
|
3468
|
-
g =
|
|
3262
|
+
g = qn(p, b, d, n);
|
|
3469
3263
|
return f && n.disposeIntermediateTensorInfo(p), g;
|
|
3470
3264
|
}
|
|
3471
3265
|
/**
|
|
@@ -3484,17 +3278,17 @@ function ro(t) {
|
|
|
3484
3278
|
* limitations under the License.
|
|
3485
3279
|
* =============================================================================
|
|
3486
3280
|
*/
|
|
3487
|
-
function
|
|
3488
|
-
const s = e, r = t.shape.length,
|
|
3489
|
-
let
|
|
3490
|
-
const u =
|
|
3281
|
+
function jn(t, e, n, o) {
|
|
3282
|
+
const s = e, r = t.shape.length, a = ut(s, t.shape);
|
|
3283
|
+
let i = a;
|
|
3284
|
+
const u = Tt(i, r), c = u != null;
|
|
3491
3285
|
let h = t;
|
|
3492
|
-
c && (h =
|
|
3493
|
-
const [f, w] =
|
|
3286
|
+
c && (h = Wt(t, u, o), i = Vt(i.length, r)), Mt("sum", i, r);
|
|
3287
|
+
const [f, w] = mt(h.shape, i);
|
|
3494
3288
|
let p = f;
|
|
3495
|
-
n && (p =
|
|
3496
|
-
const m =
|
|
3497
|
-
return o.disposeIntermediateTensorInfo(g), o.disposeIntermediateTensorInfo(
|
|
3289
|
+
n && (p = wt(f, a));
|
|
3290
|
+
const m = y(w), d = y(t.shape) / m, g = st({ inputs: { x: h }, attrs: { shape: [d, m] }, backend: o }), x = Kt(t.dtype), O = zt(g, x, "sum", o), v = st({ inputs: { x: O }, attrs: { shape: p }, backend: o });
|
|
3291
|
+
return o.disposeIntermediateTensorInfo(g), o.disposeIntermediateTensorInfo(O), c && o.disposeIntermediateTensorInfo(h), v;
|
|
3498
3292
|
}
|
|
3499
3293
|
/**
|
|
3500
3294
|
* @license
|
|
@@ -3512,9 +3306,9 @@ function io(t, e, n, o) {
|
|
|
3512
3306
|
* limitations under the License.
|
|
3513
3307
|
* =============================================================================
|
|
3514
3308
|
*/
|
|
3515
|
-
function
|
|
3516
|
-
const { inputs: e, backend: n, attrs: o } = t, { x: s } = e, { axis: r, keepDims:
|
|
3517
|
-
return
|
|
3309
|
+
function Zn(t) {
|
|
3310
|
+
const { inputs: e, backend: n, attrs: o } = t, { x: s } = e, { axis: r, keepDims: a } = o;
|
|
3311
|
+
return jn(s, r, a, n);
|
|
3518
3312
|
}
|
|
3519
3313
|
/**
|
|
3520
3314
|
* @license
|
|
@@ -3532,11 +3326,11 @@ function ao(t) {
|
|
|
3532
3326
|
* limitations under the License.
|
|
3533
3327
|
* =============================================================================
|
|
3534
3328
|
*/
|
|
3535
|
-
const
|
|
3329
|
+
const Bn = `
|
|
3536
3330
|
if (a == b) {
|
|
3537
3331
|
return 1.0;
|
|
3538
3332
|
};
|
|
3539
|
-
return a / b;`,
|
|
3333
|
+
return a / b;`, Hn = `
|
|
3540
3334
|
// vec4 one = vec4(equal(a, b));
|
|
3541
3335
|
// return one + (vec4(1.0) - one) * a / b;
|
|
3542
3336
|
vec4 result = a / b;
|
|
@@ -3554,8 +3348,8 @@ return a / b;`, lo = `
|
|
|
3554
3348
|
}
|
|
3555
3349
|
|
|
3556
3350
|
return result;
|
|
3557
|
-
`,
|
|
3558
|
-
class
|
|
3351
|
+
`, Kn = Jt({ opSnippet: Bn, packedOpSnippet: Hn, checkOutOfBounds: !0 });
|
|
3352
|
+
class Xn {
|
|
3559
3353
|
variableNames = ["logits", "maxLogits"];
|
|
3560
3354
|
outputShape;
|
|
3561
3355
|
userCode;
|
|
@@ -3574,7 +3368,7 @@ class ho {
|
|
|
3574
3368
|
`;
|
|
3575
3369
|
}
|
|
3576
3370
|
}
|
|
3577
|
-
class
|
|
3371
|
+
class Qn {
|
|
3578
3372
|
variableNames = ["exp", "sum"];
|
|
3579
3373
|
outputShape;
|
|
3580
3374
|
userCode;
|
|
@@ -3601,31 +3395,31 @@ class fo {
|
|
|
3601
3395
|
`;
|
|
3602
3396
|
}
|
|
3603
3397
|
}
|
|
3604
|
-
function
|
|
3605
|
-
const { inputs: e, attrs: n } = t, { logits: o } = e, { dim: s, dropoutRate: r, seed:
|
|
3398
|
+
function Yn(t) {
|
|
3399
|
+
const { inputs: e, attrs: n } = t, { logits: o } = e, { dim: s, dropoutRate: r, seed: a } = n, i = t.backend;
|
|
3606
3400
|
if (!o)
|
|
3607
3401
|
throw new Error("Error in softmax: input logits is null");
|
|
3608
|
-
const u =
|
|
3402
|
+
const u = ut([s], o.shape), c = Gn({
|
|
3609
3403
|
inputs: { x: o },
|
|
3610
|
-
backend:
|
|
3404
|
+
backend: i,
|
|
3611
3405
|
attrs: { reductionIndices: u, keepDims: !1 }
|
|
3612
|
-
}), h =
|
|
3406
|
+
}), h = wt(c.shape, u), f = new Xn(o.shape), w = i.runWebGLProgram(f, [o, c], "float32"), p = Zn({ inputs: { x: w }, backend: i, attrs: { axis: u, keepDims: !1 } }), m = st({ inputs: { x: p }, backend: i, attrs: { shape: h } });
|
|
3613
3407
|
if (r !== void 0 && r > 0) {
|
|
3614
|
-
const d = new
|
|
3408
|
+
const d = new Qn(o.shape), g = i.runWebGLProgram(d, [w, m], "float32", [
|
|
3615
3409
|
[r],
|
|
3616
|
-
[
|
|
3410
|
+
[a ?? Math.random() * 1e4]
|
|
3617
3411
|
]);
|
|
3618
|
-
return
|
|
3412
|
+
return i.disposeIntermediateTensorInfo(c), i.disposeIntermediateTensorInfo(w), i.disposeIntermediateTensorInfo(p), i.disposeIntermediateTensorInfo(m), g;
|
|
3619
3413
|
}
|
|
3620
|
-
const b =
|
|
3621
|
-
return
|
|
3414
|
+
const b = Kn({ inputs: { a: w, b: m }, backend: i });
|
|
3415
|
+
return i.disposeIntermediateTensorInfo(c), i.disposeIntermediateTensorInfo(w), i.disposeIntermediateTensorInfo(p), i.disposeIntermediateTensorInfo(m), b;
|
|
3622
3416
|
}
|
|
3623
|
-
const
|
|
3417
|
+
const Jn = {
|
|
3624
3418
|
kernelName: "FusedSoftmax",
|
|
3625
3419
|
backendName: "webgl",
|
|
3626
|
-
kernelFunc:
|
|
3420
|
+
kernelFunc: Yn
|
|
3627
3421
|
};
|
|
3628
|
-
|
|
3422
|
+
Xt(Jn);
|
|
3629
3423
|
export {
|
|
3630
|
-
|
|
3424
|
+
Yn as softmax
|
|
3631
3425
|
};
|