@genai-fi/nanogpt 0.2.12 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/Generator.js +30 -25
  2. package/dist/NanoGPTModel.d.ts +13 -14
  3. package/dist/NanoGPTModel.js +167 -85
  4. package/dist/TeachableLLM.d.ts +3 -5
  5. package/dist/TeachableLLM.js +47 -35
  6. package/dist/Trainer.js +8 -8
  7. package/dist/concat-BIZS_td9.js +33 -0
  8. package/dist/data/parquet.js +1 -1
  9. package/dist/exports_layers-7idKoYqh.js +25 -0
  10. package/dist/{sum-D7fu15XL.js → gather-BPGW8RsB.js} +6 -8
  11. package/dist/index-C4L8Cm77.js +349 -0
  12. package/dist/{index-YPKosni4.js → index-pWA4_lUh.js} +1020 -782
  13. package/dist/layers/CausalSelfAttention.d.ts +11 -11
  14. package/dist/layers/CausalSelfAttention.js +71 -63
  15. package/dist/layers/MLP.d.ts +6 -7
  16. package/dist/layers/MLP.js +18 -16
  17. package/dist/layers/RMSNorm.d.ts +6 -7
  18. package/dist/layers/RMSNorm.js +15 -13
  19. package/dist/layers/RoPECache.d.ts +4 -5
  20. package/dist/layers/RoPECache.js +36 -12
  21. package/dist/layers/TiedEmbedding.d.ts +7 -8
  22. package/dist/layers/TiedEmbedding.js +16 -418
  23. package/dist/layers/TransformerBlock.d.ts +8 -9
  24. package/dist/layers/TransformerBlock.js +12 -12
  25. package/dist/main.d.ts +1 -0
  26. package/dist/main.js +35 -21
  27. package/dist/{mat_mul-Bu7bhLms.js → mat_mul-D7_a4KJn.js} +5 -5
  28. package/dist/moments-DfcpfwKi.js +132 -0
  29. package/dist/ones-Cog-G2ag.js +29 -0
  30. package/dist/ops/appendCache.d.ts +2 -0
  31. package/dist/ops/appendCache.js +9 -0
  32. package/dist/ops/attentionMask.d.ts +1 -1
  33. package/dist/ops/attentionMask.js +7 -85
  34. package/dist/ops/cpu/appendCache.d.ts +2 -0
  35. package/dist/ops/cpu/appendCache.js +28 -0
  36. package/dist/ops/cpu/attentionMask.js +18 -0
  37. package/dist/ops/cpu/gatherSub.d.ts +1 -0
  38. package/dist/ops/cpu/gatherSub.js +34 -0
  39. package/dist/ops/cpu/qkv.d.ts +5 -0
  40. package/dist/ops/cpu/qkv.js +38 -0
  41. package/dist/ops/cpu/rope.d.ts +6 -0
  42. package/dist/ops/cpu/rope.js +38 -0
  43. package/dist/ops/cpu/scatterSub.d.ts +1 -0
  44. package/dist/ops/cpu/scatterSub.js +70 -0
  45. package/dist/ops/gatherSub.d.ts +1 -1
  46. package/dist/ops/gatherSub.js +6 -63
  47. package/dist/ops/grads/attentionMask.d.ts +1 -0
  48. package/dist/ops/grads/attentionMask.js +21 -0
  49. package/dist/ops/grads/qkv.d.ts +1 -0
  50. package/dist/ops/grads/qkv.js +20 -0
  51. package/dist/ops/grads/rope.d.ts +1 -0
  52. package/dist/ops/grads/rope.js +14 -0
  53. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  54. package/dist/ops/qkv.d.ts +1 -6
  55. package/dist/ops/qkv.js +7 -124
  56. package/dist/ops/rope.d.ts +0 -5
  57. package/dist/ops/rope.js +7 -151
  58. package/dist/ops/scatterSub.d.ts +1 -1
  59. package/dist/ops/scatterSub.js +6 -147
  60. package/dist/ops/webgl/appendCache.d.ts +1 -0
  61. package/dist/ops/webgl/appendCache.js +43 -0
  62. package/dist/ops/webgl/attentionMask.d.ts +1 -0
  63. package/dist/ops/webgl/attentionMask.js +43 -0
  64. package/dist/ops/webgl/gatherSub.d.ts +1 -0
  65. package/dist/ops/webgl/gatherSub.js +27 -0
  66. package/dist/ops/webgl/qkv.d.ts +1 -0
  67. package/dist/ops/webgl/qkv.js +46 -0
  68. package/dist/ops/webgl/rope.d.ts +1 -0
  69. package/dist/ops/webgl/rope.js +56 -0
  70. package/dist/ops/webgl/scatterSub.d.ts +1 -0
  71. package/dist/ops/webgl/scatterSub.js +27 -0
  72. package/dist/{parquet-BRl5lE_I.js → parquet-C0Tlmv9c.js} +3045 -3048
  73. package/dist/random_width-PbCt7RXv.js +15489 -0
  74. package/dist/range-CcDl05lo.js +26 -0
  75. package/dist/{reshape-DmnmKT6r.js → reshape-C8CR_Bad.js} +3 -3
  76. package/dist/sin-BJIrfnj7.js +47 -0
  77. package/dist/softmax-Be_lsqUc.js +105 -0
  78. package/dist/{complex-CJ-qCcLB.js → split-DZbvruEP.js} +6 -8
  79. package/dist/stack-BMm-efee.js +27 -0
  80. package/dist/sum-C7Mgy9Bw.js +104 -0
  81. package/dist/tensor-DJVbYhh1.js +24 -0
  82. package/dist/tensor2d-ZuQSh2D-.js +30 -0
  83. package/dist/tokeniser/bpe.d.ts +17 -6
  84. package/dist/tokeniser/bpe.js +88 -60
  85. package/dist/training/AdamExt.js +1 -1
  86. package/dist/training/DatasetBuilder.d.ts +6 -6
  87. package/dist/training/DatasetBuilder.js +1262 -17
  88. package/dist/training/Evaluator.d.ts +3 -2
  89. package/dist/training/FullTrainer.d.ts +9 -8
  90. package/dist/training/FullTrainer.js +26 -25
  91. package/dist/training/LayerTrainer.d.ts +9 -8
  92. package/dist/training/LayerTrainer.js +34 -33
  93. package/dist/training/Trainer.d.ts +22 -21
  94. package/dist/training/Trainer.js +21 -18
  95. package/dist/training/sparseCrossEntropy.js +22 -166
  96. package/dist/utilities/dummy.js +10 -8
  97. package/dist/utilities/generate.js +14 -11
  98. package/dist/utilities/load.d.ts +1 -2
  99. package/dist/utilities/load.js +37 -35
  100. package/dist/utilities/profile.js +1 -1
  101. package/dist/utilities/save.js +14 -9
  102. package/dist/utilities/tokenParse.d.ts +1 -1
  103. package/dist/utilities/tokenParse.js +7 -61
  104. package/dist/utilities/weights.d.ts +3 -3
  105. package/dist/utilities/weights.js +21 -19
  106. package/dist/variable-Dl_ub3pk.js +23 -0
  107. package/dist/{stack-BtKpB0Ry.js → zeros-CCy9C3uU.js} +18 -16
  108. package/package.json +2 -1
  109. package/dist/assets/worker-BYeSPNkq.js +0 -1
  110. package/dist/tokeniser/NodeTokeniser.d.ts +0 -20
  111. package/dist/tokeniser/NodeTokeniser.js +0 -46
  112. package/dist/tokeniser/WebTokeniser.d.ts +0 -18
  113. package/dist/tokeniser/WebTokeniser.js +0 -96
  114. package/dist/tokeniser/worker.js +0 -53
  115. /package/dist/{tokeniser/worker.d.ts → ops/cpu/attentionMask.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { g as Ot } from "./index-D5v913EJ.js";
2
- import { p as Q } from "./index-xuotMAFm.js";
2
+ import { p as Z } from "./index-xuotMAFm.js";
3
3
  import { B as gt } from "./index-Tf7vU29b.js";
4
4
  /**
5
5
  * @license
@@ -17,8 +17,8 @@ import { B as gt } from "./index-Tf7vU29b.js";
17
17
  * limitations under the License.
18
18
  * =============================================================================
19
19
  */
20
- const Ee = 1e-7, Ae = 1e-4;
21
- class Be {
20
+ const Ae = 1e-7, Be = 1e-4;
21
+ class ve {
22
22
  refCount(t) {
23
23
  return v("refCount");
24
24
  }
@@ -49,7 +49,7 @@ class Be {
49
49
  write(t, e, s) {
50
50
  return v("write");
51
51
  }
52
- move(t, e, s, r, i) {
52
+ move(t, e, s, r, a) {
53
53
  return v("move");
54
54
  }
55
55
  createTensorFromGPUData(t, e, s) {
@@ -64,7 +64,7 @@ class Be {
64
64
  }
65
65
  /** Returns the smallest representable number. */
66
66
  epsilon() {
67
- return this.floatPrecision() === 32 ? Ee : Ae;
67
+ return this.floatPrecision() === 32 ? Ae : Be;
68
68
  }
69
69
  dispose() {
70
70
  return v("dispose");
@@ -89,14 +89,26 @@ function v(n) {
89
89
  * limitations under the License.
90
90
  * =============================================================================
91
91
  */
92
+ function Bs(n) {
93
+ let t = n.length, e = 0;
94
+ for (; t > 0; )
95
+ e = Math.random() * t | 0, t--, Me(n, t, e);
96
+ }
97
+ function Me(n, t, e) {
98
+ const s = n[t];
99
+ n[t] = n[e], n[e] = s;
100
+ }
92
101
  function y(n, t) {
93
102
  if (!n)
94
103
  throw new Error(typeof t == "string" ? t : t());
95
104
  }
96
- function Is(n, t, e = "") {
97
- y(Rt(n, t), () => e + ` Shapes ${n} and ${t} must match`);
105
+ function vs(n, t, e = "") {
106
+ y(Ft(n, t), () => e + ` Shapes ${n} and ${t} must match`);
107
+ }
108
+ function Ms(n) {
109
+ y(n != null, () => "The input to the tensor constructor must be a non-null value.");
98
110
  }
99
- function G(n) {
111
+ function z(n) {
100
112
  if (n.length === 0)
101
113
  return 1;
102
114
  let t = n[0];
@@ -104,7 +116,7 @@ function G(n) {
104
116
  t *= n[e];
105
117
  return t;
106
118
  }
107
- function Rt(n, t) {
119
+ function Ft(n, t) {
108
120
  if (n === t)
109
121
  return !0;
110
122
  if (n == null || t == null || n.length !== t.length)
@@ -114,17 +126,30 @@ function Rt(n, t) {
114
126
  return !1;
115
127
  return !0;
116
128
  }
117
- function ve(n) {
129
+ function Ne(n) {
118
130
  return n % 1 === 0;
119
131
  }
120
- function ct(n, t) {
132
+ function lt(n, t) {
121
133
  return t <= n.length ? n : n + " ".repeat(t - n.length);
122
134
  }
123
- function Ts(n, t) {
135
+ function Re(n, t) {
124
136
  const e = t.length;
125
- return n = n == null ? t.map((s, r) => r) : [].concat(n), y(n.every((s) => s >= -e && s < e), () => `All values in axis param must be in range [-${e}, ${e}) but got axis ${n}`), y(n.every((s) => ve(s)), () => `All values in axis param must be integers but got axis ${n}`), n.map((s) => s < 0 ? e + s : s);
137
+ return n = n == null ? t.map((s, r) => r) : [].concat(n), y(n.every((s) => s >= -e && s < e), () => `All values in axis param must be in range [-${e}, ${e}) but got axis ${n}`), y(n.every((s) => Ne(s)), () => `All values in axis param must be integers but got axis ${n}`), n.map((s) => s < 0 ? e + s : s);
138
+ }
139
+ function Ns(n, t) {
140
+ const e = [], s = [], r = t != null && Array.isArray(t) && t.length === 0, a = t == null || r ? null : Re(t, n).sort();
141
+ let o = 0;
142
+ for (let i = 0; i < n.length; ++i) {
143
+ if (a != null) {
144
+ if (a[o] === i && n[i] !== 1)
145
+ throw new Error(`Can't squeeze axis ${i} since its dim '${n[i]}' is not 1`);
146
+ (a[o] == null || a[o] > i) && n[i] === 1 && (e.push(n[i]), s.push(i)), a[o] <= i && o++;
147
+ }
148
+ n[i] !== 1 && (e.push(n[i]), s.push(i));
149
+ }
150
+ return { newShape: e, keptDims: s };
126
151
  }
127
- function Me(n, t) {
152
+ function Fe(n, t) {
128
153
  let e = null;
129
154
  if (n == null || n === "float32")
130
155
  e = new Float32Array(t);
@@ -138,7 +163,7 @@ function Me(n, t) {
138
163
  throw new Error(`Unknown data type ${n}`);
139
164
  return e;
140
165
  }
141
- function Fe(n, t) {
166
+ function De(n, t) {
142
167
  for (let e = 0; e < n.length; e++) {
143
168
  const s = n[e];
144
169
  if (isNaN(s) || !isFinite(s))
@@ -157,28 +182,28 @@ function St(n) {
157
182
  return 1;
158
183
  throw new Error(`Unknown dtype ${n}`);
159
184
  }
160
- function Re(n) {
185
+ function xe(n) {
161
186
  if (n == null)
162
187
  return 0;
163
188
  let t = 0;
164
189
  return n.forEach((e) => t += e.length), t;
165
190
  }
166
- function xt(n) {
191
+ function Dt(n) {
167
192
  return typeof n == "string" || n instanceof String;
168
193
  }
169
- function xe(n) {
194
+ function Ce(n) {
170
195
  return typeof n == "boolean";
171
196
  }
172
- function Ne(n) {
197
+ function Pe(n) {
173
198
  return typeof n == "number";
174
199
  }
175
200
  function mt(n) {
176
- return Array.isArray(n) ? mt(n[0]) : n instanceof Float32Array ? "float32" : n instanceof Int32Array || n instanceof Uint8Array || n instanceof Uint8ClampedArray ? "int32" : Ne(n) ? "float32" : xt(n) ? "string" : xe(n) ? "bool" : "float32";
201
+ return Array.isArray(n) ? mt(n[0]) : n instanceof Float32Array ? "float32" : n instanceof Int32Array || n instanceof Uint8Array || n instanceof Uint8ClampedArray ? "int32" : Pe(n) ? "float32" : Dt(n) ? "string" : Ce(n) ? "bool" : "float32";
177
202
  }
178
203
  function kt(n) {
179
204
  return !!(n && n.constructor && n.call && n.apply);
180
205
  }
181
- function Nt(n) {
206
+ function $t(n) {
182
207
  const t = n.length;
183
208
  if (t < 2)
184
209
  return [];
@@ -188,36 +213,36 @@ function Nt(n) {
188
213
  e[s] = e[s + 1] * n[s + 1];
189
214
  return e;
190
215
  }
191
- function Qt(n, t, e, s = !1) {
216
+ function Zt(n, t, e, s = !1) {
192
217
  const r = new Array();
193
218
  if (t.length === 1) {
194
- const i = t[0] * (s ? 2 : 1);
195
- for (let o = 0; o < i; o++)
219
+ const a = t[0] * (s ? 2 : 1);
220
+ for (let o = 0; o < a; o++)
196
221
  r[o] = e[n + o];
197
222
  } else {
198
- const i = t[0], o = t.slice(1), a = o.reduce((c, l) => c * l) * (s ? 2 : 1);
199
- for (let c = 0; c < i; c++)
200
- r[c] = Qt(n + c * a, o, e, s);
223
+ const a = t[0], o = t.slice(1), i = o.reduce((c, l) => c * l) * (s ? 2 : 1);
224
+ for (let c = 0; c < a; c++)
225
+ r[c] = Zt(n + c * i, o, e, s);
201
226
  }
202
227
  return r;
203
228
  }
204
- function Lt(n, t, e = !1) {
229
+ function _t(n, t, e = !1) {
205
230
  if (n.length === 0)
206
231
  return t[0];
207
- const s = n.reduce((r, i) => r * i) * (e ? 2 : 1);
232
+ const s = n.reduce((r, a) => r * a) * (e ? 2 : 1);
208
233
  if (s === 0)
209
234
  return [];
210
235
  if (s !== t.length)
211
236
  throw new Error(`[${n}] does not match the input size ${t.length}${e ? " for a complex tensor" : ""}.`);
212
- return Qt(0, n, t, e);
237
+ return Zt(0, n, t, e);
213
238
  }
214
- function De(n, t) {
215
- const e = Zt(n, t);
239
+ function Le(n, t) {
240
+ const e = te(n, t);
216
241
  for (let s = 0; s < e.length; s++)
217
242
  e[s] = 1;
218
243
  return e;
219
244
  }
220
- function Zt(n, t) {
245
+ function te(n, t) {
221
246
  if (t == null || t === "float32" || t === "complex64")
222
247
  return new Float32Array(n);
223
248
  if (t === "int32")
@@ -226,7 +251,7 @@ function Zt(n, t) {
226
251
  return new Uint8Array(n);
227
252
  throw new Error(`Unknown data type ${t}`);
228
253
  }
229
- function Dt(n) {
254
+ function xt(n) {
230
255
  n.forEach((t) => {
231
256
  y(Number.isInteger(t) && t >= 0, () => `Tensor must have a shape comprised of positive integers but got shape [${n}].`);
232
257
  });
@@ -251,18 +276,18 @@ function Ct(n) {
251
276
  * =============================================================================
252
277
  */
253
278
  const Ut = "tfjsflags";
254
- class Ce {
279
+ class Oe {
255
280
  // tslint:disable-next-line: no-any
256
281
  constructor(t) {
257
282
  this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.getQueryParams = _e, this.populateURLFlags();
258
283
  }
259
284
  setPlatform(t, e) {
260
- this.platform != null && (S().getBool("IS_TEST") || S().getBool("PROD") || console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${t}.`)), this.platformName = t, this.platform = e;
285
+ this.platform != null && (k().getBool("IS_TEST") || k().getBool("PROD") || console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${t}.`)), this.platformName = t, this.platform = e;
261
286
  }
262
287
  registerFlag(t, e, s) {
263
288
  if (this.flagRegistry[t] = { evaluationFn: e, setHook: s }, this.urlFlags[t] != null) {
264
289
  const r = this.urlFlags[t];
265
- S().getBool("IS_TEST") || S().getBool("PROD") || console.warn(`Setting feature override from URL ${t}: ${r}.`), this.set(t, r);
290
+ k().getBool("IS_TEST") || k().getBool("PROD") || console.warn(`Setting feature override from URL ${t}: ${r}.`), this.set(t, r);
266
291
  }
267
292
  }
268
293
  async getAsync(t) {
@@ -313,28 +338,28 @@ class Ce {
313
338
  return;
314
339
  const t = this.getQueryParams(this.global.location.search);
315
340
  Ut in t && t[Ut].split(",").forEach((s) => {
316
- const [r, i] = s.split(":");
317
- this.urlFlags[r] = Oe(r, i);
341
+ const [r, a] = s.split(":");
342
+ this.urlFlags[r] = Ge(r, a);
318
343
  });
319
344
  }
320
345
  }
321
346
  function _e(n) {
322
347
  const t = {};
323
- return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, (e, ...s) => (Pe(t, s[0], s[1]), s.join("="))), t;
348
+ return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, (e, ...s) => (Ue(t, s[0], s[1]), s.join("="))), t;
324
349
  }
325
- function Pe(n, t, e) {
350
+ function Ue(n, t, e) {
326
351
  n[decodeURIComponent(t)] = decodeURIComponent(e || "");
327
352
  }
328
- function Oe(n, t) {
353
+ function Ge(n, t) {
329
354
  const e = t.toLowerCase();
330
355
  return e === "true" || e === "false" ? e === "true" : `${+e}` === e ? +e : t;
331
356
  }
332
- function S() {
333
- return te;
357
+ function k() {
358
+ return ee;
334
359
  }
335
- let te = null;
336
- function Le(n) {
337
- te = n;
360
+ let ee = null;
361
+ function ze(n) {
362
+ ee = n;
338
363
  }
339
364
  /**
340
365
  * @license
@@ -353,15 +378,15 @@ function Le(n) {
353
378
  * =============================================================================
354
379
  */
355
380
  let pt;
356
- function ee() {
381
+ function ne() {
357
382
  if (pt == null) {
358
383
  let n;
359
384
  if (typeof window < "u")
360
385
  n = window;
361
386
  else if (typeof Ot < "u")
362
387
  n = Ot;
363
- else if (typeof Q < "u")
364
- n = Q;
388
+ else if (typeof Z < "u")
389
+ n = Z;
365
390
  else if (typeof self < "u")
366
391
  n = self;
367
392
  else
@@ -370,12 +395,12 @@ function ee() {
370
395
  }
371
396
  return pt;
372
397
  }
373
- function Ue() {
374
- const n = ee();
398
+ function Ve() {
399
+ const n = ne();
375
400
  return n._tfGlobals == null && (n._tfGlobals = /* @__PURE__ */ new Map()), n._tfGlobals;
376
401
  }
377
- function _t(n, t) {
378
- const e = Ue();
402
+ function Pt(n, t) {
403
+ const e = Ve();
379
404
  if (e.has(n))
380
405
  return e.get(n);
381
406
  {
@@ -383,7 +408,7 @@ function _t(n, t) {
383
408
  return e.set(n, s), e.get(n);
384
409
  }
385
410
  }
386
- const Ge = "Abs", ne = "Add", Es = "BatchMatMul", se = "Cast", As = "Complex", ze = "ComplexAbs", Bs = "Concat", We = "RealDiv", vs = "Elu", Ms = "Exp", je = "Fill", Ke = "FloorDiv", Fs = "GatherV2", $s = "GatherNd", re = "Identity", Rs = "Imag", xs = "LeakyRelu", Ns = "Log", Ds = "Max", Ve = "Maximum", qe = "Multiply", Cs = "Neg", _s = "Pack", He = "Pow", Ps = "Prelu", Os = "Range", Ls = "Real", Us = "Relu", Gs = "Reshape", zs = "Relu6", Ws = "ScatterNd", js = "Sigmoid", Je = "Sqrt", Ks = "Sum", Vs = "SplitV", qs = "Softmax", Xe = "Sub", Hs = "Transpose", Ye = "ZerosLike", Js = "Step", Xs = "_FusedMatMul";
411
+ const We = "Abs", Rs = "Acos", Fs = "Acosh", se = "Add", Ds = "AddN", $s = "All", xs = "Any", Cs = "ArgMax", Ps = "ArgMin", Ls = "Asin", Os = "Asinh", _s = "Atan", Us = "Atanh", Gs = "Atan2", zs = "AvgPool", Vs = "AvgPoolGrad", Ws = "AvgPool3D", js = "AvgPool3DGrad", Ks = "BatchMatMul", qs = "BatchToSpaceND", Hs = "Bincount", Js = "BroadcastTo", re = "Cast", Xs = "Ceil", Ys = "ClipByValue", Qs = "Complex", je = "ComplexAbs", Zs = "Concat", tr = "Conv2D", er = "Conv2DBackpropFilter", nr = "Conv2DBackpropInput", sr = "Conv3D", rr = "Conv3DBackpropFilterV2", ar = "Conv3DBackpropInputV2", or = "Cos", ir = "Cosh", cr = "Cumprod", lr = "Cumsum", ur = "CropAndResize", hr = "DenseBincount", dr = "DepthwiseConv2dNative", fr = "DepthwiseConv2dNativeBackpropFilter", gr = "DepthwiseConv2dNativeBackpropInput", mr = "Dilation2D", pr = "Dilation2DBackpropInput", yr = "Dilation2DBackpropFilter", Ke = "RealDiv", br = "Einsum", wr = "Elu", Sr = "EluGrad", kr = "Erf", Ir = "Equal", Tr = "Exp", Er = "ExpandDims", Ar = "Expm1", qe = "Fill", Br = "FlipLeftRight", vr = "Floor", He = "FloorDiv", Mr = "FusedBatchNorm", Nr = "GatherV2", Rr = "GatherNd", Fr = "Greater", Dr = "GreaterEqual", ae = "Identity", $r = "Imag", xr = "IsFinite", Cr = "IsInf", Pr = "IsNan", Lr = "LeakyRelu", Or = "Less", _r = "LessEqual", Ur = "Log", Gr = "Log1p", zr = "LogicalAnd", Vr = "LogicalNot", Wr = "LogSoftmax", jr = "LRN", Kr = "LRNGrad", qr = "Max", Je = "Maximum", Hr = "MaxPool", Jr = "MaxPoolGrad", Xr = "MaxPool3D", Yr = "MaxPool3DGrad", Qr = "Mean", Zr = "Min", ta = "Minimum", ea = "MirrorPad", na = "Mod", sa = "Multinomial", Xe = "Multiply", ra = "Neg", aa = "NotEqual", oa = "NonMaxSuppressionV3", ia = "NonMaxSuppressionV4", ca = "NonMaxSuppressionV5", la = "OnesLike", ua = "OneHot", ha = "Pack", da = "PadV2", Ye = "Pow", fa = "Prelu", ga = "Prod", ma = "Range", pa = "Real", ya = "Reciprocal", ba = "Relu", wa = "Reshape", Sa = "ResizeNearestNeighbor", ka = "ResizeNearestNeighborGrad", Ia = "ResizeBilinear", Ta = "ResizeBilinearGrad", Ea = "Relu6", Aa = "Reverse", Ba = "Round", va = "Rsqrt", Ma = "ScatterNd", Na = "Select", Ra = "Selu", Fa = "Slice", Da = "Sin", $a = "Sinh", xa = "Sign", Ca = "Sigmoid", Pa = "Softplus", Qe = "Sqrt", La = "Sum", Oa = "SpaceToBatchND", _a = "SplitV", Ua = "Softmax", Ga = "SquaredDifference", za = "Square", Ze = "Sub", Va = "Tan", Wa = "Tanh", ja = "Tile", Ka = "TopK", qa = "Transform", Ha = "Transpose", Ja = "Unpack", Xa = "UnsortedSegmentSum", tn = "ZerosLike", Ya = "Step", Qa = "RotateWithOffset", Za = "_FusedMatMul", to = "FusedConv2D";
387
412
  /**
388
413
  * @license
389
414
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -400,8 +425,8 @@ const Ge = "Abs", ne = "Add", Es = "BatchMatMul", se = "Cast", As = "Complex", z
400
425
  * limitations under the License.
401
426
  * =============================================================================
402
427
  */
403
- function O(...n) {
404
- S().getBool("IS_TEST") || S().getBool("PROD") || console.warn(...n);
428
+ function _(...n) {
429
+ k().getBool("IS_TEST") || k().getBool("PROD") || console.warn(...n);
405
430
  }
406
431
  /**
407
432
  * @license
@@ -419,34 +444,34 @@ function O(...n) {
419
444
  * limitations under the License.
420
445
  * =============================================================================
421
446
  */
422
- const ht = _t("kernelRegistry", () => /* @__PURE__ */ new Map()), It = _t("gradRegistry", () => /* @__PURE__ */ new Map());
447
+ const ht = Pt("kernelRegistry", () => /* @__PURE__ */ new Map()), It = Pt("gradRegistry", () => /* @__PURE__ */ new Map());
423
448
  function Gt(n, t) {
424
- const e = ie(n, t);
449
+ const e = oe(n, t);
425
450
  return ht.get(e);
426
451
  }
427
452
  function zt(n) {
428
453
  return It.get(n);
429
454
  }
430
- function Wt(n) {
455
+ function Vt(n) {
431
456
  const t = ht.entries(), e = [];
432
457
  for (; ; ) {
433
458
  const { done: s, value: r } = t.next();
434
459
  if (s)
435
460
  break;
436
- const [i, o] = r, [a] = i.split("_");
437
- a === n && e.push(o);
461
+ const [a, o] = r, [i] = a.split("_");
462
+ i === n && e.push(o);
438
463
  }
439
464
  return e;
440
465
  }
441
- function Ys(n) {
442
- const { kernelName: t, backendName: e } = n, s = ie(t, e);
443
- ht.has(s) && O(`The kernel '${t}' for backend '${e}' is already registered`), ht.set(s, n);
466
+ function eo(n) {
467
+ const { kernelName: t, backendName: e } = n, s = oe(t, e);
468
+ ht.has(s) && _(`The kernel '${t}' for backend '${e}' is already registered`), ht.set(s, n);
444
469
  }
445
- function Qs(n) {
470
+ function no(n) {
446
471
  const { kernelName: t } = n;
447
- It.has(t) && S().getBool("DEBUG") && O(`Overriding the gradient for '${t}'`), It.set(t, n);
472
+ It.has(t) && k().getBool("DEBUG") && _(`Overriding the gradient for '${t}'`), It.set(t, n);
448
473
  }
449
- function ie(n, t) {
474
+ function oe(n, t) {
450
475
  return `${t}_${n}`;
451
476
  }
452
477
  /**
@@ -465,7 +490,7 @@ function ie(n, t) {
465
490
  * limitations under the License.
466
491
  * =============================================================================
467
492
  */
468
- function oe(n) {
493
+ function ie(n) {
469
494
  return n instanceof Float32Array || n instanceof Int32Array || n instanceof Uint8Array || n instanceof Uint8ClampedArray;
470
495
  }
471
496
  /**
@@ -484,13 +509,13 @@ function oe(n) {
484
509
  * limitations under the License.
485
510
  * =============================================================================
486
511
  */
487
- function Qe(n, t) {
512
+ function en(n, t) {
488
513
  return n instanceof Float32Array && t === "float32" || n instanceof Int32Array && t === "int32" || n instanceof Uint8Array && t === "bool";
489
514
  }
490
- function ae(n, t) {
515
+ function ce(n, t) {
491
516
  if (t === "string")
492
517
  throw new Error("Cannot convert a string[] to a TypedArray");
493
- if (Array.isArray(n) && (n = at(n)), S().getBool("DEBUG") && Fe(n, t), Qe(n, t))
518
+ if (Array.isArray(n) && (n = ct(n)), k().getBool("DEBUG") && De(n, t), en(n, t))
494
519
  return n;
495
520
  if (t == null || t === "float32" || t === "complex64")
496
521
  return new Float32Array(n);
@@ -504,30 +529,30 @@ function ae(n, t) {
504
529
  } else
505
530
  throw new Error(`Unknown data type ${t}`);
506
531
  }
507
- function ft() {
508
- return S().platform.now();
532
+ function dt() {
533
+ return k().platform.now();
509
534
  }
510
- function Ze(n, t = "utf-8") {
511
- return t = t || "utf-8", S().platform.encode(n, t);
535
+ function nn(n, t = "utf-8") {
536
+ return t = t || "utf-8", k().platform.encode(n, t);
512
537
  }
513
- function jt(n, t = "utf-8") {
514
- return t = t || "utf-8", S().platform.decode(n, t);
538
+ function Wt(n, t = "utf-8") {
539
+ return t = t || "utf-8", k().platform.decode(n, t);
515
540
  }
516
- function $(n) {
517
- return S().platform.isTypedArray != null ? S().platform.isTypedArray(n) : oe(n);
541
+ function R(n) {
542
+ return k().platform.isTypedArray != null ? k().platform.isTypedArray(n) : ie(n);
518
543
  }
519
- function at(n, t = [], e = !1) {
520
- if (t == null && (t = []), typeof n == "boolean" || typeof n == "number" || typeof n == "string" || Ct(n) || n == null || $(n) && e)
544
+ function ct(n, t = [], e = !1) {
545
+ if (t == null && (t = []), typeof n == "boolean" || typeof n == "number" || typeof n == "string" || Ct(n) || n == null || R(n) && e)
521
546
  t.push(n);
522
- else if (Array.isArray(n) || $(n))
547
+ else if (Array.isArray(n) || R(n))
523
548
  for (let s = 0; s < n.length; ++s)
524
- at(n[s], t, e);
549
+ ct(n[s], t, e);
525
550
  else {
526
551
  let s = -1;
527
552
  for (const r of Object.keys(n))
528
553
  /^([1-9]+[0-9]*|0)$/.test(r) && (s = Math.max(s, Number(r)));
529
554
  for (let r = 0; r <= s; r++)
530
- at(n[r], t, e);
555
+ ct(n[r], t, e);
531
556
  }
532
557
  return t;
533
558
  }
@@ -547,30 +572,30 @@ function at(n, t = [], e = !1) {
547
572
  * limitations under the License.
548
573
  * =============================================================================
549
574
  */
550
- class tn {
575
+ class sn {
551
576
  constructor(t, e) {
552
- this.backendTimer = t, this.logger = e, e == null && (this.logger = new nn());
577
+ this.backendTimer = t, this.logger = e, e == null && (this.logger = new an());
553
578
  }
554
579
  profileKernel(t, e, s) {
555
580
  let r;
556
- const i = () => {
581
+ const a = () => {
557
582
  r = s();
558
583
  };
559
584
  let o;
560
- const a = ft();
585
+ const i = dt();
561
586
  if (this.backendTimer.timerAvailable())
562
- o = this.backendTimer.time(i);
587
+ o = this.backendTimer.time(a);
563
588
  else {
564
- i();
589
+ a();
565
590
  for (const l of r)
566
591
  l.dataSync();
567
- o = Promise.resolve({ kernelMs: ft() - a });
592
+ o = Promise.resolve({ kernelMs: dt() - i });
568
593
  }
569
- if (S().getBool("CHECK_COMPUTATION_FOR_ERRORS"))
594
+ if (k().getBool("CHECK_COMPUTATION_FOR_ERRORS"))
570
595
  for (let l = 0; l < r.length; l++) {
571
596
  const u = r[l];
572
597
  u.data().then((h) => {
573
- en(h, u.dtype, t);
598
+ rn(h, u.dtype, t);
574
599
  });
575
600
  }
576
601
  return {
@@ -582,15 +607,15 @@ class tn {
582
607
  };
583
608
  }
584
609
  logKernelProfile(t) {
585
- const { kernelName: e, outputs: s, timeMs: r, inputs: i, extraInfo: o } = t;
586
- s.forEach((a) => {
587
- Promise.all([a.data(), r, o]).then((c) => {
588
- this.logger.logKernelProfile(e, a, c[0], c[1], i, c[2]);
610
+ const { kernelName: e, outputs: s, timeMs: r, inputs: a, extraInfo: o } = t;
611
+ s.forEach((i) => {
612
+ Promise.all([i.data(), r, o]).then((c) => {
613
+ this.logger.logKernelProfile(e, i, c[0], c[1], a, c[2]);
589
614
  });
590
615
  });
591
616
  }
592
617
  }
593
- function en(n, t, e) {
618
+ function rn(n, t, e) {
594
619
  if (t !== "float32")
595
620
  return !1;
596
621
  for (let s = 0; s < n.length; s++) {
@@ -600,18 +625,18 @@ function en(n, t, e) {
600
625
  }
601
626
  return !1;
602
627
  }
603
- class nn {
604
- logKernelProfile(t, e, s, r, i, o) {
605
- const a = typeof r == "number" ? ct(`${r}ms`, 9) : r.error, c = ct(t, 25), l = e.rank, u = e.size, h = ct(e.shape.toString(), 14);
606
- let f = "";
607
- for (const m in i) {
608
- const b = i[m];
609
- if (b != null) {
610
- const d = b.shape || e.shape, k = d.length;
611
- f += `${m}: ${k}D ${k > 0 ? d : ""} `;
628
+ class an {
629
+ logKernelProfile(t, e, s, r, a, o) {
630
+ const i = typeof r == "number" ? lt(`${r}ms`, 9) : r.error, c = lt(t, 25), l = e.rank, u = e.size, h = lt(e.shape.toString(), 14);
631
+ let d = "";
632
+ for (const m in a) {
633
+ const p = a[m];
634
+ if (p != null) {
635
+ const f = p.shape || e.shape, w = f.length;
636
+ d += `${m}: ${w}D ${w > 0 ? f : ""} `;
612
637
  }
613
638
  }
614
- console.log(`%c${c} %c${a} %c${l}D ${h} %c${u} %c${f} %c${o}`, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue");
639
+ console.log(`%c${c} %c${i} %c${l}D ${h} %c${u} %c${d} %c${o}`, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue");
615
640
  }
616
641
  }
617
642
  /**
@@ -630,69 +655,69 @@ class nn {
630
655
  * limitations under the License.
631
656
  * =============================================================================
632
657
  */
633
- function sn(n, t, e) {
658
+ function on(n, t, e) {
634
659
  const s = {}, r = {};
635
660
  for (let c = 0; c < t.length; c++)
636
661
  s[t[c].id] = !0;
637
662
  for (let c = 0; c < n.length; c++) {
638
663
  const l = n[c], u = l.inputs;
639
664
  for (const h in u) {
640
- const f = u[h];
665
+ const d = u[h];
641
666
  let m = !1;
642
- for (let b = 0; b < t.length; b++)
643
- if (s[f.id]) {
644
- l.outputs.forEach((d) => s[d.id] = !0), m = !0, r[l.id] = !0;
667
+ for (let p = 0; p < t.length; p++)
668
+ if (s[d.id]) {
669
+ l.outputs.forEach((f) => s[f.id] = !0), m = !0, r[l.id] = !0;
645
670
  break;
646
671
  }
647
672
  if (m)
648
673
  break;
649
674
  }
650
675
  }
651
- const i = {};
652
- i[e.id] = !0;
676
+ const a = {};
677
+ a[e.id] = !0;
653
678
  const o = {};
654
679
  for (let c = n.length - 1; c >= 0; c--) {
655
680
  const l = n[c], u = l.inputs;
656
681
  for (let h = 0; h < l.outputs.length; h++)
657
- if (i[l.outputs[h].id]) {
658
- for (const f in u)
659
- i[u[f].id] = !0, o[l.id] = !0;
682
+ if (a[l.outputs[h].id]) {
683
+ for (const d in u)
684
+ a[u[d].id] = !0, o[l.id] = !0;
660
685
  break;
661
686
  }
662
687
  }
663
- const a = [];
688
+ const i = [];
664
689
  for (let c = 0; c < n.length; c++) {
665
690
  const l = n[c];
666
691
  if (r[l.id] && o[l.id]) {
667
692
  const u = {};
668
- for (const f in l.inputs) {
669
- const m = l.inputs[f];
670
- s[m.id] && (u[f] = m);
693
+ for (const d in l.inputs) {
694
+ const m = l.inputs[d];
695
+ s[m.id] && (u[d] = m);
671
696
  }
672
697
  const h = Object.assign({}, l);
673
- h.inputs = u, h.outputs = l.outputs, a.push(h);
698
+ h.inputs = u, h.outputs = l.outputs, i.push(h);
674
699
  }
675
700
  }
676
- return a;
701
+ return i;
677
702
  }
678
- function rn(n, t, e, s) {
703
+ function cn(n, t, e, s) {
679
704
  for (let r = t.length - 1; r >= 0; r--) {
680
- const i = t[r], o = [];
681
- if (i.outputs.forEach((c) => {
705
+ const a = t[r], o = [];
706
+ if (a.outputs.forEach((c) => {
682
707
  const l = n[c.id];
683
708
  l != null ? o.push(l) : o.push(null);
684
- }), i.gradient == null)
685
- throw new Error(`Cannot compute gradient: gradient function not found for ${i.kernelName}.`);
686
- const a = i.gradient(o);
687
- for (const c in i.inputs) {
688
- if (!(c in a))
689
- throw new Error(`Cannot backprop through input ${c}. Available gradients found: ${Object.keys(a)}.`);
690
- const l = e(() => a[c]());
709
+ }), a.gradient == null)
710
+ throw new Error(`Cannot compute gradient: gradient function not found for ${a.kernelName}.`);
711
+ const i = a.gradient(o);
712
+ for (const c in a.inputs) {
713
+ if (!(c in i))
714
+ throw new Error(`Cannot backprop through input ${c}. Available gradients found: ${Object.keys(i)}.`);
715
+ const l = e(() => i[c]());
691
716
  if (l.dtype !== "float32")
692
- throw new Error(`Error in gradient for op ${i.kernelName}. The gradient of input ${c} must have 'float32' dtype, but has '${l.dtype}'`);
693
- const u = i.inputs[c];
694
- if (!Rt(l.shape, u.shape))
695
- throw new Error(`Error in gradient for op ${i.kernelName}. The gradient of input '${c}' has shape '${l.shape}', which does not match the shape of the input '${u.shape}'`);
717
+ throw new Error(`Error in gradient for op ${a.kernelName}. The gradient of input ${c} must have 'float32' dtype, but has '${l.dtype}'`);
718
+ const u = a.inputs[c];
719
+ if (!Ft(l.shape, u.shape))
720
+ throw new Error(`Error in gradient for op ${a.kernelName}. The gradient of input '${c}' has shape '${l.shape}', which does not match the shape of the input '${u.shape}'`);
696
721
  if (n[u.id] == null)
697
722
  n[u.id] = l;
698
723
  else {
@@ -718,57 +743,57 @@ function rn(n, t, e, s) {
718
743
  * limitations under the License.
719
744
  * =============================================================================
720
745
  */
721
- const Kt = 20, rt = 3, yt = 7;
722
- function on(n, t, e, s) {
723
- const r = Nt(t), i = an(n, t, e, r), o = t.length, a = ut(n, t, e, r, i), c = ["Tensor"];
724
- return s && (c.push(` dtype: ${e}`), c.push(` rank: ${o}`), c.push(` shape: [${t}]`), c.push(" values:")), c.push(a.map((l) => " " + l).join(`
746
+ const jt = 20, at = 3, yt = 7;
747
+ function ln(n, t, e, s) {
748
+ const r = $t(t), a = un(n, t, e, r), o = t.length, i = ut(n, t, e, r, a), c = ["Tensor"];
749
+ return s && (c.push(` dtype: ${e}`), c.push(` rank: ${o}`), c.push(` shape: [${t}]`), c.push(" values:")), c.push(i.map((l) => " " + l).join(`
725
750
  `)), c.join(`
726
751
  `);
727
752
  }
728
- function an(n, t, e, s) {
729
- const r = G(t), i = s[s.length - 1], o = new Array(i).fill(0), a = t.length, c = e === "complex64" ? ot(n) : n;
730
- if (a > 1)
731
- for (let l = 0; l < r / i; l++) {
732
- const u = l * i;
733
- for (let h = 0; h < i; h++)
734
- o[h] = Math.max(o[h], it(c[u + h], 0, e).length);
753
+ function un(n, t, e, s) {
754
+ const r = z(t), a = s[s.length - 1], o = new Array(a).fill(0), i = t.length, c = e === "complex64" ? it(n) : n;
755
+ if (i > 1)
756
+ for (let l = 0; l < r / a; l++) {
757
+ const u = l * a;
758
+ for (let h = 0; h < a; h++)
759
+ o[h] = Math.max(o[h], ot(c[u + h], 0, e).length);
735
760
  }
736
761
  return o;
737
762
  }
738
- function it(n, t, e) {
763
+ function ot(n, t, e) {
739
764
  let s;
740
- return Array.isArray(n) ? s = `${parseFloat(n[0].toFixed(yt))} + ${parseFloat(n[1].toFixed(yt))}j` : xt(n) ? s = `'${n}'` : e === "bool" ? s = le(n) : s = parseFloat(n.toFixed(yt)).toString(), ct(s, t);
765
+ return Array.isArray(n) ? s = `${parseFloat(n[0].toFixed(yt))} + ${parseFloat(n[1].toFixed(yt))}j` : Dt(n) ? s = `'${n}'` : e === "bool" ? s = le(n) : s = parseFloat(n.toFixed(yt)).toString(), lt(s, t);
741
766
  }
742
767
  function le(n) {
743
768
  return n === 0 ? "false" : "true";
744
769
  }
745
- function ut(n, t, e, s, r, i = !0) {
746
- const o = e === "complex64" ? 2 : 1, a = t[0], c = t.length;
770
+ function ut(n, t, e, s, r, a = !0) {
771
+ const o = e === "complex64" ? 2 : 1, i = t[0], c = t.length;
747
772
  if (c === 0) {
748
773
  if (e === "complex64") {
749
- const d = ot(n);
750
- return [it(d[0], 0, e)];
774
+ const f = it(n);
775
+ return [ot(f[0], 0, e)];
751
776
  }
752
777
  return e === "bool" ? [le(n[0])] : [n[0].toString()];
753
778
  }
754
779
  if (c === 1) {
755
- if (a > Kt) {
756
- const k = rt * o;
757
- let T = Array.from(n.slice(0, k)), nt = Array.from(n.slice((a - rt) * o, a * o));
758
- return e === "complex64" && (T = ot(T), nt = ot(nt)), [
759
- "[" + T.map((H, J) => it(H, r[J], e)).join(", ") + ", ..., " + nt.map((H, J) => it(H, r[a - rt + J], e)).join(", ") + "]"
780
+ if (i > jt) {
781
+ const w = at * o;
782
+ let I = Array.from(n.slice(0, w)), O = Array.from(n.slice((i - at) * o, i * o));
783
+ return e === "complex64" && (I = it(I), O = it(O)), [
784
+ "[" + I.map((J, X) => ot(J, r[X], e)).join(", ") + ", ..., " + O.map((J, X) => ot(J, r[i - at + X], e)).join(", ") + "]"
760
785
  ];
761
786
  }
762
787
  return [
763
- "[" + (e === "complex64" ? ot(n) : Array.from(n)).map((k, T) => it(k, r[T], e)).join(", ") + "]"
788
+ "[" + (e === "complex64" ? it(n) : Array.from(n)).map((w, I) => ot(w, r[I], e)).join(", ") + "]"
764
789
  ];
765
790
  }
766
- const l = t.slice(1), u = s.slice(1), h = s[0] * o, f = [];
767
- if (a > Kt) {
768
- for (let d = 0; d < rt; d++) {
769
- const k = d * h, T = k + h;
770
- f.push(...ut(
771
- n.slice(k, T),
791
+ const l = t.slice(1), u = s.slice(1), h = s[0] * o, d = [];
792
+ if (i > jt) {
793
+ for (let f = 0; f < at; f++) {
794
+ const w = f * h, I = w + h;
795
+ d.push(...ut(
796
+ n.slice(w, I),
772
797
  l,
773
798
  e,
774
799
  u,
@@ -777,44 +802,44 @@ function ut(n, t, e, s, r, i = !0) {
777
802
  /* isLast */
778
803
  ));
779
804
  }
780
- f.push("...");
781
- for (let d = a - rt; d < a; d++) {
782
- const k = d * h, T = k + h;
783
- f.push(...ut(
784
- n.slice(k, T),
805
+ d.push("...");
806
+ for (let f = i - at; f < i; f++) {
807
+ const w = f * h, I = w + h;
808
+ d.push(...ut(
809
+ n.slice(w, I),
785
810
  l,
786
811
  e,
787
812
  u,
788
813
  r,
789
- d === a - 1
814
+ f === i - 1
790
815
  /* isLast */
791
816
  ));
792
817
  }
793
818
  } else
794
- for (let d = 0; d < a; d++) {
795
- const k = d * h, T = k + h;
796
- f.push(...ut(
797
- n.slice(k, T),
819
+ for (let f = 0; f < i; f++) {
820
+ const w = f * h, I = w + h;
821
+ d.push(...ut(
822
+ n.slice(w, I),
798
823
  l,
799
824
  e,
800
825
  u,
801
826
  r,
802
- d === a - 1
827
+ f === i - 1
803
828
  /* isLast */
804
829
  ));
805
830
  }
806
831
  const m = c === 2 ? "," : "";
807
- f[0] = "[" + (a > 0 ? f[0] + m : "");
808
- for (let d = 1; d < f.length - 1; d++)
809
- f[d] = " " + f[d] + m;
810
- let b = `,
832
+ d[0] = "[" + (i > 0 ? d[0] + m : "");
833
+ for (let f = 1; f < d.length - 1; f++)
834
+ d[f] = " " + d[f] + m;
835
+ let p = `,
811
836
  `;
812
- for (let d = 2; d < c; d++)
813
- b += `
837
+ for (let f = 2; f < c; f++)
838
+ p += `
814
839
  `;
815
- return f[f.length - 1] = " " + f[f.length - 1] + "]" + (i ? "" : b), f;
840
+ return d[d.length - 1] = " " + d[d.length - 1] + "]" + (a ? "" : p), d;
816
841
  }
817
- function ot(n) {
842
+ function it(n) {
818
843
  const t = [];
819
844
  for (let e = 0; e < n.length; e += 2)
820
845
  t.push([n[e], n[e + 1]]);
@@ -836,15 +861,15 @@ function ot(n) {
836
861
  * limitations under the License.
837
862
  * =============================================================================
838
863
  */
839
- class ln {
864
+ class hn {
840
865
  constructor(t, e, s) {
841
- if (this.dtype = e, this.shape = t.slice(), this.size = G(t), s != null) {
866
+ if (this.dtype = e, this.shape = t.slice(), this.size = z(t), s != null) {
842
867
  const r = s.length;
843
868
  y(r === this.size, () => `Length of values '${r}' does not match the size inferred by the shape '${this.size}'.`);
844
869
  }
845
870
  if (e === "complex64")
846
871
  throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");
847
- this.values = s || Me(e, this.size), this.strides = Nt(t);
872
+ this.values = s || Fe(e, this.size), this.strides = $t(t);
848
873
  }
849
874
  /**
850
875
  * Sets a value in the buffer at a given location.
@@ -871,8 +896,8 @@ class ln {
871
896
  let e = 0;
872
897
  for (const r of t) {
873
898
  if (r < 0 || r >= this.shape[e]) {
874
- const i = `Requested out of range element at ${t}. Buffer shape=${this.shape}`;
875
- throw new Error(i);
899
+ const a = `Requested out of range element at ${t}. Buffer shape=${this.shape}`;
900
+ throw new Error(a);
876
901
  }
877
902
  e++;
878
903
  }
@@ -910,19 +935,19 @@ class ln {
910
935
  * @doc {heading: 'Tensors', subheading: 'Creation'}
911
936
  */
912
937
  toTensor() {
913
- return R().makeTensor(this.values, this.shape, this.dtype);
938
+ return F().makeTensor(this.values, this.shape, this.dtype);
914
939
  }
915
940
  }
916
- let R = null, X = null;
917
- function cn(n) {
918
- R = n;
941
+ let F = null, Y = null;
942
+ function dn(n) {
943
+ F = n;
919
944
  }
920
- function un(n) {
921
- X = n;
945
+ function fn(n) {
946
+ Y = n;
922
947
  }
923
- class x {
948
+ class D {
924
949
  constructor(t, e, s, r) {
925
- this.kept = !1, this.isDisposedInternal = !1, this.shape = t.slice(), this.dtype = e || "float32", this.size = G(t), this.strides = Nt(t), this.dataId = s, this.id = r, this.rankType = this.rank < 5 ? this.rank.toString() : "higher";
950
+ this.kept = !1, this.isDisposedInternal = !1, this.shape = t.slice(), this.dtype = e || "float32", this.size = z(t), this.strides = $t(t), this.dataId = s, this.id = r, this.rankType = this.rank < 5 ? this.rank.toString() : "higher";
926
951
  }
927
952
  get rank() {
928
953
  return this.shape.length;
@@ -934,14 +959,14 @@ class x {
934
959
  */
935
960
  async buffer() {
936
961
  const t = await this.data();
937
- return X.buffer(this.shape, this.dtype, t);
962
+ return Y.buffer(this.shape, this.dtype, t);
938
963
  }
939
964
  /**
940
965
  * Returns a `tf.TensorBuffer` that holds the underlying data.
941
966
  * @doc {heading: 'Tensors', subheading: 'Classes'}
942
967
  */
943
968
  bufferSync() {
944
- return X.buffer(this.shape, this.dtype, this.dataSync());
969
+ return Y.buffer(this.shape, this.dtype, this.dataSync());
945
970
  }
946
971
  /**
947
972
  * Returns the tensor data as a nested array. The transfer of data is done
@@ -951,7 +976,7 @@ class x {
951
976
  */
952
977
  async array() {
953
978
  const t = await this.data();
954
- return Lt(this.shape, t, this.dtype === "complex64");
979
+ return _t(this.shape, t, this.dtype === "complex64");
955
980
  }
956
981
  /**
957
982
  * Returns the tensor data as a nested array. The transfer of data is done
@@ -960,7 +985,7 @@ class x {
960
985
  * @doc {heading: 'Tensors', subheading: 'Classes'}
961
986
  */
962
987
  arraySync() {
963
- return Lt(this.shape, this.dataSync(), this.dtype === "complex64");
988
+ return _t(this.shape, this.dataSync(), this.dtype === "complex64");
964
989
  }
965
990
  /**
966
991
  * Asynchronously downloads the values from the `tf.Tensor`. Returns a
@@ -970,11 +995,11 @@ class x {
970
995
  */
971
996
  async data() {
972
997
  this.throwIfDisposed();
973
- const t = R().read(this.dataId);
998
+ const t = F().read(this.dataId);
974
999
  if (this.dtype === "string") {
975
1000
  const e = await t;
976
1001
  try {
977
- return e.map((s) => jt(s));
1002
+ return e.map((s) => Wt(s));
978
1003
  } catch {
979
1004
  throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
980
1005
  }
@@ -1016,7 +1041,7 @@ class x {
1016
1041
  * @doc {heading: 'Tensors', subheading: 'Classes'}
1017
1042
  */
1018
1043
  dataToGPU(t) {
1019
- return this.throwIfDisposed(), R().readToGPU(this.dataId, t);
1044
+ return this.throwIfDisposed(), F().readToGPU(this.dataId, t);
1020
1045
  }
1021
1046
  /**
1022
1047
  * Synchronously downloads the values from the `tf.Tensor`. This blocks the
@@ -1026,10 +1051,10 @@ class x {
1026
1051
  */
1027
1052
  dataSync() {
1028
1053
  this.throwIfDisposed();
1029
- const t = R().readSync(this.dataId);
1054
+ const t = F().readSync(this.dataId);
1030
1055
  if (this.dtype === "string")
1031
1056
  try {
1032
- return t.map((e) => jt(e));
1057
+ return t.map((e) => Wt(e));
1033
1058
  } catch {
1034
1059
  throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
1035
1060
  }
@@ -1038,7 +1063,7 @@ class x {
1038
1063
  /** Returns the underlying bytes of the tensor's data. */
1039
1064
  async bytes() {
1040
1065
  this.throwIfDisposed();
1041
- const t = await R().read(this.dataId);
1066
+ const t = await F().read(this.dataId);
1042
1067
  return this.dtype === "string" ? t : new Uint8Array(t.buffer);
1043
1068
  }
1044
1069
  /**
@@ -1047,7 +1072,7 @@ class x {
1047
1072
  * @doc {heading: 'Tensors', subheading: 'Classes'}
1048
1073
  */
1049
1074
  dispose() {
1050
- this.isDisposed || (this.kerasMask && this.kerasMask.dispose(), R().disposeTensor(this), this.isDisposedInternal = !0);
1075
+ this.isDisposed || (this.kerasMask && this.kerasMask.dispose(), F().disposeTensor(this), this.isDisposedInternal = !0);
1051
1076
  }
1052
1077
  get isDisposed() {
1053
1078
  return this.isDisposedInternal;
@@ -1065,14 +1090,14 @@ class x {
1065
1090
  * @doc {heading: 'Tensors', subheading: 'Classes'}
1066
1091
  */
1067
1092
  print(t = !1) {
1068
- return X.print(this, t);
1093
+ return Y.print(this, t);
1069
1094
  }
1070
1095
  /**
1071
1096
  * Returns a copy of the tensor. See `tf.clone` for details.
1072
1097
  * @doc {heading: 'Tensors', subheading: 'Classes'}
1073
1098
  */
1074
1099
  clone() {
1075
- return this.throwIfDisposed(), X.clone(this);
1100
+ return this.throwIfDisposed(), Y.clone(this);
1076
1101
  }
1077
1102
  /**
1078
1103
  * Returns a human-readable description of the tensor. Useful for logging.
@@ -1081,23 +1106,23 @@ class x {
1081
1106
  */
1082
1107
  toString(t = !1) {
1083
1108
  const e = this.dataSync();
1084
- return on(e, this.shape, this.dtype, t);
1109
+ return ln(e, this.shape, this.dtype, t);
1085
1110
  }
1086
1111
  cast(t) {
1087
- return this.throwIfDisposed(), X.cast(this, t);
1112
+ return this.throwIfDisposed(), Y.cast(this, t);
1088
1113
  }
1089
1114
  variable(t = !0, e, s) {
1090
- return this.throwIfDisposed(), R().makeVariable(this, t, e, s);
1115
+ return this.throwIfDisposed(), F().makeVariable(this, t, e, s);
1091
1116
  }
1092
1117
  }
1093
- Object.defineProperty(x, Symbol.hasInstance, {
1118
+ Object.defineProperty(D, Symbol.hasInstance, {
1094
1119
  value: (n) => !!n && n.data != null && n.dataSync != null && n.throwIfDisposed != null
1095
1120
  });
1096
- function ce() {
1097
- return _t("Tensor", () => x);
1121
+ function ue() {
1122
+ return Pt("Tensor", () => D);
1098
1123
  }
1099
- ce();
1100
- class dt extends x {
1124
+ ue();
1125
+ class ft extends D {
1101
1126
  constructor(t, e, s, r) {
1102
1127
  super(t.shape, t.dtype, t.dataId, r), this.trainable = e, this.name = s;
1103
1128
  }
@@ -1112,20 +1137,20 @@ class dt extends x {
1112
1137
  assign(t) {
1113
1138
  if (t.dtype !== this.dtype)
1114
1139
  throw new Error(`dtype of the new value (${t.dtype}) and previous value (${this.dtype}) must match`);
1115
- if (!Rt(t.shape, this.shape))
1140
+ if (!Ft(t.shape, this.shape))
1116
1141
  throw new Error(`shape of the new value (${t.shape}) and previous value (${this.shape}) must match`);
1117
- R().disposeTensor(this), this.dataId = t.dataId, R().incRef(
1142
+ F().disposeTensor(this), this.dataId = t.dataId, F().incRef(
1118
1143
  this,
1119
1144
  null
1120
1145
  /* backend */
1121
1146
  );
1122
1147
  }
1123
1148
  dispose() {
1124
- R().disposeVariable(this), this.isDisposedInternal = !0;
1149
+ F().disposeVariable(this), this.isDisposedInternal = !0;
1125
1150
  }
1126
1151
  }
1127
- Object.defineProperty(dt, Symbol.hasInstance, {
1128
- value: (n) => n instanceof x && n.assign != null && n.assign instanceof Function
1152
+ Object.defineProperty(ft, Symbol.hasInstance, {
1153
+ value: (n) => n instanceof D && n.assign != null && n.assign instanceof Function
1129
1154
  });
1130
1155
  /**
1131
1156
  * @license
@@ -1143,10 +1168,10 @@ Object.defineProperty(dt, Symbol.hasInstance, {
1143
1168
  * limitations under the License.
1144
1169
  * =============================================================================
1145
1170
  */
1146
- var Vt;
1171
+ var Kt;
1147
1172
  (function(n) {
1148
1173
  n.R0 = "R0", n.R1 = "R1", n.R2 = "R2", n.R3 = "R3", n.R4 = "R4", n.R5 = "R5", n.R6 = "R6";
1149
- })(Vt || (Vt = {}));
1174
+ })(Kt || (Kt = {}));
1150
1175
  var Tt;
1151
1176
  (function(n) {
1152
1177
  n.float32 = "float32", n.int32 = "int32", n.bool = "int32", n.complex64 = "complex64";
@@ -1163,24 +1188,24 @@ var Bt;
1163
1188
  (function(n) {
1164
1189
  n.float32 = "complex64", n.int32 = "complex64", n.bool = "complex64", n.complex64 = "complex64";
1165
1190
  })(Bt || (Bt = {}));
1166
- const hn = {
1191
+ const gn = {
1167
1192
  float32: At,
1168
1193
  int32: Tt,
1169
1194
  bool: Et,
1170
1195
  complex64: Bt
1171
1196
  };
1172
- function fn(n, t) {
1197
+ function mn(n, t) {
1173
1198
  if (n === "string" || t === "string") {
1174
1199
  if (n === "string" && t === "string")
1175
1200
  return "string";
1176
1201
  throw new Error(`Can not upcast ${n} with ${t}`);
1177
1202
  }
1178
- return hn[n][t];
1203
+ return gn[n][t];
1179
1204
  }
1180
- function ue(n) {
1205
+ function he(n) {
1181
1206
  return n != null && typeof n == "object" && "texture" in n && n.texture instanceof WebGLTexture;
1182
1207
  }
1183
- function he(n) {
1208
+ function de(n) {
1184
1209
  return typeof GPUBuffer < "u" && n != null && typeof n == "object" && "buffer" in n && n.buffer instanceof GPUBuffer;
1185
1210
  }
1186
1211
  /**
@@ -1199,32 +1224,35 @@ function he(n) {
1199
1224
  * limitations under the License.
1200
1225
  * =============================================================================
1201
1226
  */
1202
- function V(n, t) {
1227
+ function q(n, t) {
1203
1228
  if (n.dtype === t.dtype)
1204
1229
  return [n, t];
1205
- const e = fn(n.dtype, t.dtype);
1230
+ const e = mn(n.dtype, t.dtype);
1206
1231
  return [n.cast(e), t.cast(e)];
1207
1232
  }
1233
+ function so(n, t) {
1234
+ return t.some((e) => e.id === n.id);
1235
+ }
1208
1236
  function fe(n) {
1209
1237
  const t = [];
1210
- return de(n, t, /* @__PURE__ */ new Set()), t;
1238
+ return ge(n, t, /* @__PURE__ */ new Set()), t;
1211
1239
  }
1212
- function de(n, t, e) {
1240
+ function ge(n, t, e) {
1213
1241
  if (n == null)
1214
1242
  return;
1215
- if (n instanceof x) {
1243
+ if (n instanceof D) {
1216
1244
  t.push(n);
1217
1245
  return;
1218
1246
  }
1219
- if (!dn(n))
1247
+ if (!pn(n))
1220
1248
  return;
1221
1249
  const s = n;
1222
1250
  for (const r in s) {
1223
- const i = s[r];
1224
- e.has(i) || (e.add(i), de(i, t, e));
1251
+ const a = s[r];
1252
+ e.has(a) || (e.add(a), ge(a, t, e));
1225
1253
  }
1226
1254
  }
1227
- function dn(n) {
1255
+ function pn(n) {
1228
1256
  return Array.isArray(n) || typeof n == "object";
1229
1257
  }
1230
1258
  /**
@@ -1264,7 +1292,7 @@ class qt {
1264
1292
  this.registeredVariables[t].dispose();
1265
1293
  }
1266
1294
  }
1267
- class tt {
1295
+ class et {
1268
1296
  constructor(t) {
1269
1297
  this.ENV = t, this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new qt();
1270
1298
  }
@@ -1312,7 +1340,7 @@ class tt {
1312
1340
  return t in this.registryFactory ? this.registryFactory[t].factory : null;
1313
1341
  }
1314
1342
  registerBackend(t, e, s = 1) {
1315
- return t in this.registryFactory ? (O(`${t} backend was already registered. Reusing existing backend factory.`), !1) : (this.registryFactory[t] = { factory: e, priority: s }, !0);
1343
+ return t in this.registryFactory ? (_(`${t} backend was already registered. Reusing existing backend factory.`), !1) : (this.registryFactory[t] = { factory: e, priority: s }, !0);
1316
1344
  }
1317
1345
  async setBackend(t) {
1318
1346
  if (this.registryFactory[t] == null)
@@ -1323,15 +1351,15 @@ class tt {
1323
1351
  if (!(s ? await e : e))
1324
1352
  return !1;
1325
1353
  }
1326
- return this.backendInstance = this.registry[t], this.setupRegisteredKernels(), this.profiler = new tn(this.backendInstance), !0;
1354
+ return this.backendInstance = this.registry[t], this.setupRegisteredKernels(), this.profiler = new sn(this.backendInstance), !0;
1327
1355
  }
1328
1356
  setupRegisteredKernels() {
1329
- Wt(this.backendName).forEach((e) => {
1357
+ Vt(this.backendName).forEach((e) => {
1330
1358
  e.setupFunc != null && e.setupFunc(this.backendInstance);
1331
1359
  });
1332
1360
  }
1333
1361
  disposeRegisteredKernels(t) {
1334
- Wt(t).forEach((s) => {
1362
+ Vt(t).forEach((s) => {
1335
1363
  s.disposeFunc != null && s.disposeFunc(this.registry[t]);
1336
1364
  });
1337
1365
  }
@@ -1347,13 +1375,13 @@ class tt {
1347
1375
  throw new Error(`Cannot initialize backend ${t}, no registration found.`);
1348
1376
  try {
1349
1377
  const s = e.factory();
1350
- if (s && !(s instanceof Be) && typeof s.then == "function") {
1351
- const r = ++this.pendingBackendInitId, i = s.then((o) => r < this.pendingBackendInitId ? !1 : (this.registry[t] = o, this.pendingBackendInit = null, !0)).catch((o) => (r < this.pendingBackendInitId || (this.pendingBackendInit = null, O(`Initialization of backend ${t} failed`), O(o.stack || o.message)), !1));
1352
- return this.pendingBackendInit = i, { success: i, asyncInit: !0 };
1378
+ if (s && !(s instanceof ve) && typeof s.then == "function") {
1379
+ const r = ++this.pendingBackendInitId, a = s.then((o) => r < this.pendingBackendInitId ? !1 : (this.registry[t] = o, this.pendingBackendInit = null, !0)).catch((o) => (r < this.pendingBackendInitId || (this.pendingBackendInit = null, _(`Initialization of backend ${t} failed`), _(o.stack || o.message)), !1));
1380
+ return this.pendingBackendInit = a, { success: a, asyncInit: !0 };
1353
1381
  } else
1354
1382
  return this.registry[t] = s, { success: !0, asyncInit: !1 };
1355
1383
  } catch (s) {
1356
- return O(`Initialization of backend ${t} failed`), O(s.stack || s.message), { success: !1, asyncInit: !1 };
1384
+ return _(`Initialization of backend ${t} failed`), _(s.stack || s.message), { success: !1, asyncInit: !1 };
1357
1385
  }
1358
1386
  }
1359
1387
  removeBackend(t) {
@@ -1369,15 +1397,15 @@ class tt {
1369
1397
  initializeBackendsAndReturnBest() {
1370
1398
  const t = this.getSortedBackends();
1371
1399
  for (let e = 0; e < t.length; e++) {
1372
- const s = t[e], { success: r, asyncInit: i } = this.initializeBackend(s);
1373
- if (i || r)
1374
- return { name: s, asyncInit: i };
1400
+ const s = t[e], { success: r, asyncInit: a } = this.initializeBackend(s);
1401
+ if (a || r)
1402
+ return { name: s, asyncInit: a };
1375
1403
  }
1376
1404
  throw new Error("Could not initialize any backends, all backend initializations failed.");
1377
1405
  }
1378
1406
  moveData(t, e) {
1379
- const s = this.state.tensorInfo.get(e), r = s.backend, i = this.readSync(e), o = r.refCount(e);
1380
- r.disposeData(e, !0), s.backend = t, t.move(e, i, s.shape, s.dtype, o), this.shouldCheckForMemLeaks() && this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1]++;
1407
+ const s = this.state.tensorInfo.get(e), r = s.backend, a = this.readSync(e), o = r.refCount(e);
1408
+ r.disposeData(e, !0), s.backend = t, t.move(e, a, s.shape, s.dtype, o), this.shouldCheckForMemLeaks() && this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1]++;
1381
1409
  }
1382
1410
  tidy(t, e) {
1383
1411
  let s = null;
@@ -1405,10 +1433,10 @@ class tt {
1405
1433
  }
1406
1434
  }
1407
1435
  nextTensorId() {
1408
- return tt.nextTensorId++;
1436
+ return et.nextTensorId++;
1409
1437
  }
1410
1438
  nextVariableId() {
1411
- return tt.nextVariableId++;
1439
+ return et.nextVariableId++;
1412
1440
  }
1413
1441
  /**
1414
1442
  * This method is called instead of the public-facing tensor.clone() when
@@ -1417,18 +1445,18 @@ class tt {
1417
1445
  * execution.
1418
1446
  */
1419
1447
  clone(t) {
1420
- const e = g.runKernel(re, { x: t }), s = { x: t }, r = (o) => ({
1448
+ const e = g.runKernel(ae, { x: t }), s = { x: t }, r = (o) => ({
1421
1449
  x: () => {
1422
- const a = "float32", c = { x: o }, l = { dtype: a };
1450
+ const i = "float32", c = { x: o }, l = { dtype: i };
1423
1451
  return g.runKernel(
1424
- se,
1452
+ re,
1425
1453
  c,
1426
1454
  // tslint:disable-next-line: no-unnecessary-type-assertion
1427
1455
  l
1428
1456
  );
1429
1457
  }
1430
- }), i = [];
1431
- return this.addTapeNode(this.state.activeScope.name, s, [e], r, i, {}), e;
1458
+ }), a = [];
1459
+ return this.addTapeNode(this.state.activeScope.name, s, [e], r, a, {}), e;
1432
1460
  }
1433
1461
  /**
1434
1462
  * Execute a kernel with the given name and return the output tensor.
@@ -1453,13 +1481,13 @@ class tt {
1453
1481
  }
1454
1482
  checkKernelForMemLeak(t, e, s) {
1455
1483
  const r = this.backend.numDataIds();
1456
- let i = 0;
1484
+ let a = 0;
1457
1485
  s.forEach((c) => {
1458
- i += c.dtype === "complex64" ? 3 : 1;
1486
+ a += c.dtype === "complex64" ? 3 : 1;
1459
1487
  });
1460
- const o = this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1], a = r - e - i - o;
1461
- if (a > 0)
1462
- throw new Error(`Backend '${this.backendName}' has an internal memory leak (${a} data ids) after running '${t}'`);
1488
+ const o = this.state.numDataMovesStack[this.state.numDataMovesStack.length - 1], i = r - e - a - o;
1489
+ if (i > 0)
1490
+ throw new Error(`Backend '${this.backendName}' has an internal memory leak (${i} data ids) after running '${t}'`);
1463
1491
  }
1464
1492
  /**
1465
1493
  * Internal helper method to execute a kernel Func
@@ -1468,56 +1496,56 @@ class tt {
1468
1496
  */
1469
1497
  runKernelFunc(t) {
1470
1498
  let e, s = [];
1471
- const r = this.isTapeOn(), i = this.state.numBytes, o = this.state.numTensors;
1499
+ const r = this.isTapeOn(), a = this.state.numBytes, o = this.state.numTensors;
1472
1500
  this.shouldCheckForMemLeaks() && this.state.numDataMovesStack.push(0);
1473
- let a;
1501
+ let i;
1474
1502
  this.backendName == null && this.backend;
1475
1503
  let c;
1476
1504
  const l = bt(t) ? t.kernelName : this.state.activeScope != null ? this.state.activeScope.name : "";
1477
1505
  if (bt(t)) {
1478
- const { kernelName: b, inputs: d, attrs: k } = t;
1506
+ const { kernelName: p, inputs: f, attrs: w } = t;
1479
1507
  this.backendName == null && this.backend;
1480
- const T = Gt(b, this.backendName);
1481
- y(T != null, () => `Cannot find registered kernel '${b}' for backend '${this.backendName}'`), a = () => {
1482
- const nt = this.backend.numDataIds();
1483
- c = T.kernelFunc({ inputs: d, attrs: k, backend: this.backend });
1484
- const H = Array.isArray(c) ? c : [c];
1485
- this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(b, nt, H);
1486
- const J = H.map((st) => st.rank != null ? st : this.makeTensorFromTensorInfo(st));
1508
+ const I = Gt(p, this.backendName);
1509
+ y(I != null, () => `Cannot find registered kernel '${p}' for backend '${this.backendName}'`), i = () => {
1510
+ const O = this.backend.numDataIds();
1511
+ c = I.kernelFunc({ inputs: f, attrs: w, backend: this.backend });
1512
+ const J = Array.isArray(c) ? c : [c];
1513
+ this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(p, O, J);
1514
+ const X = J.map((rt) => rt.rank != null ? rt : this.makeTensorFromTensorInfo(rt));
1487
1515
  if (r) {
1488
- const st = this.getTensorsForGradient(b, d, J);
1489
- s = this.saveTensorsForBackwardMode(st);
1516
+ const rt = this.getTensorsForGradient(p, f, X);
1517
+ s = this.saveTensorsForBackwardMode(rt);
1490
1518
  }
1491
- return J;
1519
+ return X;
1492
1520
  };
1493
1521
  } else {
1494
- const { forwardFunc: b } = t, d = (k) => {
1495
- r && (s = k.map((T) => this.keep(this.clone(T))));
1522
+ const { forwardFunc: p } = t, f = (w) => {
1523
+ r && (s = w.map((I) => this.keep(this.clone(I))));
1496
1524
  };
1497
- a = () => {
1498
- const k = this.backend.numDataIds();
1499
- c = this.tidy(() => b(this.backend, d));
1500
- const T = Array.isArray(c) ? c : [c];
1501
- return this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(l, k, T), T;
1525
+ i = () => {
1526
+ const w = this.backend.numDataIds();
1527
+ c = this.tidy(() => p(this.backend, f));
1528
+ const I = Array.isArray(c) ? c : [c];
1529
+ return this.shouldCheckForMemLeaks() && this.checkKernelForMemLeak(l, w, I), I;
1502
1530
  };
1503
1531
  }
1504
- const { inputs: u, attrs: h } = t, f = bt(t) ? null : t.backwardsFunc;
1532
+ const { inputs: u, attrs: h } = t, d = bt(t) ? null : t.backwardsFunc;
1505
1533
  let m;
1506
1534
  return this.scopedRun(
1507
1535
  // Stop recording to a tape when running a kernel.
1508
1536
  () => this.state.kernelDepth++,
1509
1537
  () => this.state.kernelDepth--,
1510
1538
  () => {
1511
- !this.ENV.getBool("DEBUG") && !this.state.profiling ? e = a() : (m = this.profiler.profileKernel(l, u, () => a()), this.ENV.getBool("DEBUG") && this.profiler.logKernelProfile(m), e = m.outputs);
1539
+ !this.ENV.getBool("DEBUG") && !this.state.profiling ? e = i() : (m = this.profiler.profileKernel(l, u, () => i()), this.ENV.getBool("DEBUG") && this.profiler.logKernelProfile(m), e = m.outputs);
1512
1540
  }
1513
- ), r && this.addTapeNode(l, u, e, f, s, h), this.state.profiling && this.state.activeProfile.kernels.push({
1541
+ ), r && this.addTapeNode(l, u, e, d, s, h), this.state.profiling && this.state.activeProfile.kernels.push({
1514
1542
  name: l,
1515
- bytesAdded: this.state.numBytes - i,
1543
+ bytesAdded: this.state.numBytes - a,
1516
1544
  totalBytesSnapshot: this.state.numBytes,
1517
1545
  tensorsAdded: this.state.numTensors - o,
1518
1546
  totalTensorsSnapshot: this.state.numTensors,
1519
- inputShapes: Object.keys(u).map((b) => u[b] != null ? u[b].shape : null),
1520
- outputShapes: e.map((b) => b.shape),
1547
+ inputShapes: Object.keys(u).map((p) => u[p] != null ? u[p].shape : null),
1548
+ outputShapes: e.map((p) => p.shape),
1521
1549
  kernelTimeMs: m.timeMs,
1522
1550
  extraInfo: m.extraInfo
1523
1551
  }), Array.isArray(c) ? e : e[0];
@@ -1540,11 +1568,11 @@ class tt {
1540
1568
  getTensorsForGradient(t, e, s) {
1541
1569
  const r = zt(t);
1542
1570
  if (r != null) {
1543
- const i = r.inputsToSave || [], o = r.outputsToSave || [];
1544
- let a;
1545
- r.saveAllInputs ? (y(Array.isArray(e), () => "saveAllInputs is true, expected inputs to be an array."), a = Object.keys(e).map((l) => e[l])) : a = i.map((l) => e[l]);
1571
+ const a = r.inputsToSave || [], o = r.outputsToSave || [];
1572
+ let i;
1573
+ r.saveAllInputs ? (y(Array.isArray(e), () => "saveAllInputs is true, expected inputs to be an array."), i = Object.keys(e).map((l) => e[l])) : i = a.map((l) => e[l]);
1546
1574
  const c = s.filter((l, u) => o[u]);
1547
- return a.concat(c);
1575
+ return i.concat(c);
1548
1576
  }
1549
1577
  return [];
1550
1578
  }
@@ -1557,14 +1585,14 @@ class tt {
1557
1585
  if (t == null)
1558
1586
  throw new Error("Values passed to engine.makeTensor() are null");
1559
1587
  s = s || "float32", r = r || this.backend;
1560
- let i = t;
1561
- s === "string" && xt(t[0]) && (i = t.map((c) => Ze(c)));
1562
- const o = r.write(i, e, s), a = new x(e, s, o, this.nextTensorId());
1563
- if (this.trackTensor(a, r), s === "string") {
1564
- const c = this.state.tensorInfo.get(o), l = Re(i);
1588
+ let a = t;
1589
+ s === "string" && Dt(t[0]) && (a = t.map((c) => nn(c)));
1590
+ const o = r.write(a, e, s), i = new D(e, s, o, this.nextTensorId());
1591
+ if (this.trackTensor(i, r), s === "string") {
1592
+ const c = this.state.tensorInfo.get(o), l = xe(a);
1565
1593
  this.state.numBytes += l - c.bytes, c.bytes = l;
1566
1594
  }
1567
- return a;
1595
+ return i;
1568
1596
  }
1569
1597
  /**
1570
1598
  * Internal method used by backends. Makes a new tensor
@@ -1574,8 +1602,8 @@ class tt {
1574
1602
  */
1575
1603
  makeTensorFromDataId(t, e, s, r) {
1576
1604
  s = s || "float32";
1577
- const i = { dataId: t, shape: e, dtype: s };
1578
- return this.makeTensorFromTensorInfo(i, r);
1605
+ const a = { dataId: t, shape: e, dtype: s };
1606
+ return this.makeTensorFromTensorInfo(a, r);
1579
1607
  }
1580
1608
  /**
1581
1609
  * Internal method used by backends. Makes a new tensor that is a wrapper
@@ -1583,15 +1611,15 @@ class tt {
1583
1611
  * only increments the ref count used in memory tracking.
1584
1612
  */
1585
1613
  makeTensorFromTensorInfo(t, e) {
1586
- const { dataId: s, shape: r, dtype: i } = t, o = new x(r, i, s, this.nextTensorId());
1614
+ const { dataId: s, shape: r, dtype: a } = t, o = new D(r, a, s, this.nextTensorId());
1587
1615
  return this.trackTensor(o, e), o;
1588
1616
  }
1589
1617
  makeVariable(t, e = !0, s, r) {
1590
1618
  s = s || this.nextVariableId().toString(), r != null && r !== t.dtype && (t = t.cast(r));
1591
- const i = new dt(t, e, s, this.nextTensorId());
1592
- if (this.state.registeredVariables[i.name] != null)
1593
- throw new Error(`Variable with name ${i.name} was already registered`);
1594
- return this.state.registeredVariables[i.name] = i, this.incRef(i, this.backend), i;
1619
+ const a = new ft(t, e, s, this.nextTensorId());
1620
+ if (this.state.registeredVariables[a.name] != null)
1621
+ throw new Error(`Variable with name ${a.name} was already registered`);
1622
+ return this.state.registeredVariables[a.name] = a, this.incRef(a, this.backend), a;
1595
1623
  }
1596
1624
  trackTensor(t, e) {
1597
1625
  this.state.numTensors++, t.dtype === "string" && this.state.numStringTensors++;
@@ -1601,7 +1629,7 @@ class tt {
1601
1629
  dtype: t.dtype,
1602
1630
  shape: t.shape,
1603
1631
  bytes: s
1604
- })), t instanceof dt || this.track(t);
1632
+ })), t instanceof ft || this.track(t);
1605
1633
  }
1606
1634
  // Track the tensor by dataId and increase the refCount for the dataId in the
1607
1635
  // backend.
@@ -1648,15 +1676,15 @@ class tt {
1648
1676
  isTapeOn() {
1649
1677
  return this.state.gradientDepth > 0 && this.state.kernelDepth === 0;
1650
1678
  }
1651
- addTapeNode(t, e, s, r, i, o) {
1652
- const a = { id: this.state.nextTapeNodeId++, kernelName: t, inputs: e, outputs: s, saved: i }, c = zt(t);
1653
- c != null && (r = c.gradFunc), r != null && (a.gradient = (l) => (l = l.map((u, h) => {
1679
+ addTapeNode(t, e, s, r, a, o) {
1680
+ const i = { id: this.state.nextTapeNodeId++, kernelName: t, inputs: e, outputs: s, saved: a }, c = zt(t);
1681
+ c != null && (r = c.gradFunc), r != null && (i.gradient = (l) => (l = l.map((u, h) => {
1654
1682
  if (u == null) {
1655
- const f = s[h], m = Zt(f.size, f.dtype);
1656
- return this.makeTensor(m, f.shape, f.dtype);
1683
+ const d = s[h], m = te(d.size, d.dtype);
1684
+ return this.makeTensor(m, d.shape, d.dtype);
1657
1685
  }
1658
1686
  return u;
1659
- }), r(l.length > 1 ? l : l[0], i, o))), this.state.activeTape.push(a);
1687
+ }), r(l.length > 1 ? l : l[0], a, o))), this.state.activeTape.push(i);
1660
1688
  }
1661
1689
  keep(t) {
1662
1690
  return t.kept = !0, t;
@@ -1684,14 +1712,14 @@ class tt {
1684
1712
  * as scope() without the need for a function closure.
1685
1713
  */
1686
1714
  endScope(t) {
1687
- const e = fe(t), s = new Set(e.map((i) => i.id));
1688
- for (let i = 0; i < this.state.activeScope.track.length; i++) {
1689
- const o = this.state.activeScope.track[i];
1715
+ const e = fe(t), s = new Set(e.map((a) => a.id));
1716
+ for (let a = 0; a < this.state.activeScope.track.length; a++) {
1717
+ const o = this.state.activeScope.track[a];
1690
1718
  !o.kept && !s.has(o.id) && o.dispose();
1691
1719
  }
1692
1720
  const r = this.state.scopeStack.pop();
1693
- this.state.activeScope = this.state.scopeStack.length === 0 ? null : this.state.scopeStack[this.state.scopeStack.length - 1], e.forEach((i) => {
1694
- !i.kept && i.scopeId === r.id && this.track(i);
1721
+ this.state.activeScope = this.state.scopeStack.length === 0 ? null : this.state.scopeStack[this.state.scopeStack.length - 1], e.forEach((a) => {
1722
+ !a.kept && a.scopeId === r.id && this.track(a);
1695
1723
  });
1696
1724
  }
1697
1725
  /**
@@ -1703,46 +1731,46 @@ class tt {
1703
1731
  gradients(t, e, s, r = !1) {
1704
1732
  if (y(e.length > 0, () => "gradients() received an empty list of xs."), s != null && s.dtype !== "float32")
1705
1733
  throw new Error(`dy must have 'float32' dtype, but has '${s.dtype}'`);
1706
- const i = this.scopedRun(() => this.startTape(), () => this.endTape(), () => this.tidy("forward", t));
1707
- y(i instanceof x, () => "The result y returned by f() must be a tensor.");
1708
- const o = sn(this.state.activeTape, e, i);
1734
+ const a = this.scopedRun(() => this.startTape(), () => this.endTape(), () => this.tidy("forward", t));
1735
+ y(a instanceof D, () => "The result y returned by f() must be a tensor.");
1736
+ const o = on(this.state.activeTape, e, a);
1709
1737
  if (!r && o.length === 0 && e.length > 0)
1710
1738
  throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");
1711
1739
  return this.tidy("backward", () => {
1712
- const a = {};
1713
- a[i.id] = s ?? gn(i.shape), rn(
1714
- a,
1740
+ const i = {};
1741
+ i[a.id] = s ?? yn(a.shape), cn(
1742
+ i,
1715
1743
  o,
1716
1744
  // Pass the tidy function to avoid circular dep with `tape.ts`.
1717
1745
  (l) => this.tidy(l),
1718
1746
  // Pass an add function to avoide a circular dep with `tape.ts`.
1719
- mn
1747
+ bn
1720
1748
  );
1721
- const c = e.map((l) => a[l.id]);
1749
+ const c = e.map((l) => i[l.id]);
1722
1750
  return this.state.gradientDepth === 0 && (this.state.activeTape.forEach((l) => {
1723
1751
  for (const u of l.saved)
1724
1752
  u.dispose();
1725
- }), this.state.activeTape = null), { value: i, grads: c };
1753
+ }), this.state.activeTape = null), { value: a, grads: c };
1726
1754
  });
1727
1755
  }
1728
1756
  customGrad(t) {
1729
1757
  return y(kt(t), () => "The f passed in customGrad(f) must be a function."), (...e) => {
1730
- y(e.every((a) => a instanceof x), () => "The args passed in customGrad(f)(x1, x2,...) must all be tensors");
1758
+ y(e.every((i) => i instanceof D), () => "The args passed in customGrad(f)(x1, x2,...) must all be tensors");
1731
1759
  let s;
1732
1760
  const r = {};
1733
- e.forEach((a, c) => {
1734
- r[c] = a;
1761
+ e.forEach((i, c) => {
1762
+ r[c] = i;
1735
1763
  });
1736
- const i = (a, c) => (s = t(...e, c), y(s.value instanceof x, () => "The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"), y(kt(s.gradFunc), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."), s.value), o = (a, c) => {
1737
- const l = s.gradFunc(a, c), u = Array.isArray(l) ? l : [l];
1738
- y(u.length === e.length, () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...)."), y(u.every((f) => f instanceof x), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors.");
1764
+ const a = (i, c) => (s = t(...e, c), y(s.value instanceof D, () => "The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"), y(kt(s.gradFunc), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."), s.value), o = (i, c) => {
1765
+ const l = s.gradFunc(i, c), u = Array.isArray(l) ? l : [l];
1766
+ y(u.length === e.length, () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...)."), y(u.every((d) => d instanceof D), () => "The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors.");
1739
1767
  const h = {};
1740
- return u.forEach((f, m) => {
1741
- h[m] = () => f;
1768
+ return u.forEach((d, m) => {
1769
+ h[m] = () => d;
1742
1770
  }), h;
1743
1771
  };
1744
1772
  return this.runKernelFunc({
1745
- forwardFunc: i,
1773
+ forwardFunc: a,
1746
1774
  backwardsFunc: o,
1747
1775
  inputs: r
1748
1776
  });
@@ -1758,8 +1786,8 @@ class tt {
1758
1786
  return this.state.tensorInfo.get(t).backend.readToGPU(t, e);
1759
1787
  }
1760
1788
  async time(t) {
1761
- const e = ft(), s = await this.backend.time(t);
1762
- return s.wallMs = ft() - e, s;
1789
+ const e = dt(), s = await this.backend.time(t);
1790
+ return s.wallMs = dt() - e, s;
1763
1791
  }
1764
1792
  /**
1765
1793
  * Tracks a Tensor in the current scope to be automatically cleaned up
@@ -1784,24 +1812,24 @@ class tt {
1784
1812
  this.backendName = null, this.backendInstance = null, this.pendingBackendInit = null;
1785
1813
  }
1786
1814
  }
1787
- tt.nextTensorId = 0;
1788
- tt.nextVariableId = 0;
1789
- function gn(n) {
1790
- const t = De(G(n), "float32");
1815
+ et.nextTensorId = 0;
1816
+ et.nextVariableId = 0;
1817
+ function yn(n) {
1818
+ const t = Le(z(n), "float32");
1791
1819
  return g.makeTensor(t, n, "float32");
1792
1820
  }
1793
- function ge() {
1794
- const n = ee();
1821
+ function me() {
1822
+ const n = ne();
1795
1823
  if (n._tfengine == null) {
1796
- const t = new Ce(n);
1797
- n._tfengine = new tt(t);
1824
+ const t = new Oe(n);
1825
+ n._tfengine = new et(t);
1798
1826
  }
1799
- return Le(n._tfengine.ENV), cn(() => n._tfengine), n._tfengine;
1827
+ return ze(n._tfengine.ENV), dn(() => n._tfengine), n._tfengine;
1800
1828
  }
1801
- const g = ge();
1802
- function mn(n, t) {
1829
+ const g = me();
1830
+ function bn(n, t) {
1803
1831
  const e = { a: n, b: t };
1804
- return g.runKernel(ne, e);
1832
+ return g.runKernel(se, e);
1805
1833
  }
1806
1834
  /**
1807
1835
  * @license
@@ -1819,16 +1847,16 @@ function mn(n, t) {
1819
1847
  * limitations under the License.
1820
1848
  * =============================================================================
1821
1849
  */
1822
- function pn() {
1850
+ function wn() {
1823
1851
  return typeof window < "u" && window.document != null || //@ts-ignore
1824
1852
  typeof WorkerGlobalScope < "u";
1825
1853
  }
1826
- const B = S();
1854
+ const B = k();
1827
1855
  B.registerFlag("DEBUG", () => !1, (n) => {
1828
1856
  n && console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.");
1829
1857
  });
1830
- B.registerFlag("IS_BROWSER", () => pn());
1831
- B.registerFlag("IS_NODE", () => typeof Q < "u" && typeof Q.versions < "u" && typeof Q.versions.node < "u");
1858
+ B.registerFlag("IS_BROWSER", () => wn());
1859
+ B.registerFlag("IS_NODE", () => typeof Z < "u" && typeof Z.versions < "u" && typeof Z.versions.node < "u");
1832
1860
  B.registerFlag("IS_CHROME", () => typeof navigator < "u" && navigator != null && navigator.userAgent != null && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor));
1833
1861
  B.registerFlag("IS_SAFARI", () => typeof navigator < "u" && navigator != null && navigator.userAgent != null && /Safari/.test(navigator.userAgent) && /Apple/.test(navigator.vendor));
1834
1862
  B.registerFlag("PROD", () => !1);
@@ -1855,31 +1883,31 @@ B.registerFlag("USE_SETTIMEOUTCUSTOM", () => !1);
1855
1883
  * limitations under the License.
1856
1884
  * =============================================================================
1857
1885
  */
1858
- function yn(n, t) {
1886
+ function Sn(n, t) {
1859
1887
  let e = n;
1860
- if ($(n))
1888
+ if (R(n))
1861
1889
  return t === "string" ? [] : [n.length];
1862
- if (ue(n)) {
1890
+ if (he(n)) {
1863
1891
  const r = n.channels || "RGBA";
1864
1892
  return [n.height, n.width * r.length];
1865
- } else if (he(n))
1893
+ } else if (de(n))
1866
1894
  return [n.buffer.size / (t == null ? 4 : St(t))];
1867
1895
  if (!Array.isArray(n))
1868
1896
  return [];
1869
1897
  const s = [];
1870
- for (; Array.isArray(e) || $(e) && t !== "string"; )
1898
+ for (; Array.isArray(e) || R(e) && t !== "string"; )
1871
1899
  s.push(e.length), e = e[0];
1872
- return Array.isArray(n) && S().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY") && me(n, s, []), s;
1900
+ return Array.isArray(n) && k().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY") && pe(n, s, []), s;
1873
1901
  }
1874
- function me(n, t, e) {
1875
- if (e = e || [], !Array.isArray(n) && !$(n)) {
1902
+ function pe(n, t, e) {
1903
+ if (e = e || [], !Array.isArray(n) && !R(n)) {
1876
1904
  y(t.length === 0, () => `Element arr[${e.join("][")}] is a primitive, but should be an array/TypedArray of ${t[0]} elements`);
1877
1905
  return;
1878
1906
  }
1879
1907
  y(t.length > 0, () => `Element arr[${e.join("][")}] should be a primitive, but is an array of ${n.length} elements`), y(n.length === t[0], () => `Element arr[${e.join("][")}] should have ${t[0]} elements, but has ${n.length} elements`);
1880
1908
  const s = t.slice(1);
1881
1909
  for (let r = 0; r < n.length; ++r)
1882
- me(n[r], s, e.concat(r));
1910
+ pe(n[r], s, e.concat(r));
1883
1911
  }
1884
1912
  function Ht(n, t, e, s) {
1885
1913
  if (n !== "string_or_numeric") {
@@ -1889,23 +1917,23 @@ function Ht(n, t, e, s) {
1889
1917
  throw new Error(`Argument '${e}' passed to '${s}' must be ${n} tensor, but got ${t} tensor`);
1890
1918
  }
1891
1919
  }
1892
- function I(n, t, e, s = "numeric") {
1893
- if (n instanceof ce())
1920
+ function T(n, t, e, s = "numeric") {
1921
+ if (n instanceof ue())
1894
1922
  return Ht(s, n.dtype, t, e), n;
1895
1923
  let r = mt(n);
1896
- if (r !== "string" && ["bool", "int32", "float32"].indexOf(s) >= 0 && (r = s), Ht(s, r, t, e), n == null || !$(n) && !Array.isArray(n) && typeof n != "number" && typeof n != "boolean" && typeof n != "string") {
1924
+ if (r !== "string" && ["bool", "int32", "float32"].indexOf(s) >= 0 && (r = s), Ht(s, r, t, e), n == null || !R(n) && !Array.isArray(n) && typeof n != "number" && typeof n != "boolean" && typeof n != "string") {
1897
1925
  const c = n == null ? "null" : n.constructor.name;
1898
1926
  throw new Error(`Argument '${t}' passed to '${e}' must be a Tensor or TensorLike, but got '${c}'`);
1899
1927
  }
1900
- const i = yn(n, r);
1901
- !$(n) && !Array.isArray(n) && (n = [n]);
1902
- const a = r !== "string" ? ae(n, r) : at(n, [], !0);
1903
- return g.makeTensor(a, i, r);
1928
+ const a = Sn(n, r);
1929
+ !R(n) && !Array.isArray(n) && (n = [n]);
1930
+ const i = r !== "string" ? ce(n, r) : ct(n, [], !0);
1931
+ return g.makeTensor(i, a, r);
1904
1932
  }
1905
- function Zs(n, t, e, s = "numeric") {
1933
+ function ro(n, t, e, s = "numeric") {
1906
1934
  if (!Array.isArray(n))
1907
1935
  throw new Error(`Argument ${t} passed to ${e} must be a \`Tensor[]\` or \`TensorLike[]\``);
1908
- return n.map((i, o) => I(i, `${t}[${o}]`, e, s));
1936
+ return n.map((a, o) => T(a, `${t}[${o}]`, e, s));
1909
1937
  }
1910
1938
  /**
1911
1939
  * @license
@@ -1923,18 +1951,18 @@ function Zs(n, t, e, s = "numeric") {
1923
1951
  * limitations under the License.
1924
1952
  * =============================================================================
1925
1953
  */
1926
- const bn = "__op";
1927
- function F(n) {
1954
+ const kn = "__op";
1955
+ function N(n) {
1928
1956
  const t = Object.keys(n);
1929
1957
  if (t.length !== 1)
1930
1958
  throw new Error(`Please provide an object with a single key (operation name) mapping to a function. Got an object with ${t.length} keys.`);
1931
1959
  let e = t[0];
1932
1960
  const s = n[e];
1933
- e.endsWith("_") && (e = e.substring(0, e.length - 1)), e = e + bn;
1934
- const r = (...i) => {
1961
+ e.endsWith("_") && (e = e.substring(0, e.length - 1)), e = e + kn;
1962
+ const r = (...a) => {
1935
1963
  g.startScope(e);
1936
1964
  try {
1937
- const o = s(...i);
1965
+ const o = s(...a);
1938
1966
  return Ct(o) && console.error("Cannot return a Promise inside of tidy."), g.endScope(o), o;
1939
1967
  } catch (o) {
1940
1968
  throw g.endScope(null), o;
@@ -1958,30 +1986,30 @@ function F(n) {
1958
1986
  * limitations under the License.
1959
1987
  * =============================================================================
1960
1988
  */
1961
- function wn(n, t, e, s) {
1989
+ function In(n, t, e, s) {
1962
1990
  if (s == null)
1963
1991
  s = mt(n);
1964
1992
  else if (s === "complex64")
1965
1993
  throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");
1966
- if (he(n) || ue(n)) {
1994
+ if (de(n) || he(n)) {
1967
1995
  if (s !== "float32" && s !== "int32")
1968
1996
  throw new Error(`Creating tensor from GPU data only supports 'float32'|'int32' dtype, while the dtype is ${s}.`);
1969
1997
  return g.backend.createTensorFromGPUData(n, t || e, s);
1970
1998
  }
1971
- if (!$(n) && !Array.isArray(n) && typeof n != "number" && typeof n != "boolean" && typeof n != "string")
1999
+ if (!R(n) && !Array.isArray(n) && typeof n != "number" && typeof n != "boolean" && typeof n != "string")
1972
2000
  throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");
1973
2001
  if (t != null) {
1974
- Dt(t);
1975
- const r = G(t), i = G(e);
1976
- y(r === i, () => `Based on the provided shape, [${t}], the tensor should have ${r} values but has ${i}`);
2002
+ xt(t);
2003
+ const r = z(t), a = z(e);
2004
+ y(r === a, () => `Based on the provided shape, [${t}], the tensor should have ${r} values but has ${a}`);
1977
2005
  for (let o = 0; o < e.length; ++o) {
1978
- const a = e[o], c = o === e.length - 1 ? a !== G(t.slice(o)) : !0;
2006
+ const i = e[o], c = o === e.length - 1 ? i !== z(t.slice(o)) : !0;
1979
2007
  y(e[o] === t[o] || !c, () => `Error creating a new Tensor. Inferred shape (${e}) does not match the provided shape (${t}). `);
1980
2008
  }
1981
2009
  }
1982
- return !$(n) && !Array.isArray(n) && (n = [n]), t = t || e, n = s !== "string" ? ae(n, s) : at(n, [], !0), g.makeTensor(n, t, s);
2010
+ return !R(n) && !Array.isArray(n) && (n = [n]), t = t || e, n = s !== "string" ? ce(n, s) : ct(n, [], !0), g.makeTensor(n, t, s);
1983
2011
  }
1984
- class lt {
2012
+ class st {
1985
2013
  /**
1986
2014
  * Concatenate a number of ArrayBuffers into one.
1987
2015
  *
@@ -1990,18 +2018,18 @@ class lt {
1990
2018
  * @returns Result of concatenating `buffers` in order.
1991
2019
  */
1992
2020
  static join(t) {
1993
- return new lt(t).slice();
2021
+ return new st(t).slice();
1994
2022
  }
1995
2023
  constructor(t) {
1996
- if (this.shards = [], this.previousShardIndex = 0, t == null || (t instanceof Array || (t = [t]), t = t.map((s) => $(s) ? s.buffer : s), t.length === 0))
2024
+ if (this.shards = [], this.previousShardIndex = 0, t == null || (t instanceof Array || (t = [t]), t = t.map((s) => R(s) ? s.buffer : s), t.length === 0))
1997
2025
  return;
1998
2026
  this.bufferUniformSize = t[0].byteLength;
1999
2027
  let e = 0;
2000
2028
  for (let s = 0; s < t.length; s++) {
2001
2029
  const r = t[s];
2002
2030
  s !== t.length - 1 && r.byteLength !== this.bufferUniformSize && (this.bufferUniformSize = void 0);
2003
- const i = e + r.byteLength;
2004
- this.shards.push({ buffer: r, start: e, end: i }), e = i;
2031
+ const a = e + r.byteLength;
2032
+ this.shards.push({ buffer: r, start: e, end: a }), e = a;
2005
2033
  }
2006
2034
  this.shards.length === 0 && (this.byteLength = 0), this.byteLength = this.shards[this.shards.length - 1].end;
2007
2035
  }
@@ -2013,14 +2041,14 @@ class lt {
2013
2041
  const s = this.findShardForByte(t);
2014
2042
  if (s === -1)
2015
2043
  throw new Error(`Could not find start shard for byte ${t}`);
2016
- const r = e - t, i = new ArrayBuffer(r), o = new Uint8Array(i);
2017
- let a = 0;
2044
+ const r = e - t, a = new ArrayBuffer(r), o = new Uint8Array(a);
2045
+ let i = 0;
2018
2046
  for (let c = s; c < this.shards.length; c++) {
2019
- const l = this.shards[c], h = t + a - l.start, f = a, b = Math.min(e, l.end) - l.start, d = new Uint8Array(l.buffer, h, b - h);
2020
- if (o.set(d, f), a += d.length, e < l.end)
2047
+ const l = this.shards[c], h = t + i - l.start, d = i, p = Math.min(e, l.end) - l.start, f = new Uint8Array(l.buffer, h, p - h);
2048
+ if (o.set(f, d), i += f.length, e < l.end)
2021
2049
  break;
2022
2050
  }
2023
- return i;
2051
+ return a;
2024
2052
  }
2025
2053
  /**
2026
2054
  * Get the index of the shard that contains the byte at `byteIndex`.
@@ -2035,17 +2063,17 @@ class lt {
2035
2063
  }
2036
2064
  if (e(this.shards[this.previousShardIndex]) === 0)
2037
2065
  return this.previousShardIndex;
2038
- const s = Sn(this.shards, e);
2066
+ const s = Tn(this.shards, e);
2039
2067
  return s === -1 ? -1 : (this.previousShardIndex = s, this.previousShardIndex);
2040
2068
  }
2041
2069
  }
2042
- function Sn(n, t) {
2070
+ function Tn(n, t) {
2043
2071
  let e = 0, s = n.length;
2044
2072
  for (; e <= s; ) {
2045
- const r = Math.floor((s - e) / 2) + e, i = t(n[r]);
2046
- if (i === 0)
2073
+ const r = Math.floor((s - e) / 2) + e, a = t(n[r]);
2074
+ if (a === 0)
2047
2075
  return r;
2048
- i < 0 ? s = r : e = r + 1;
2076
+ a < 0 ? s = r : e = r + 1;
2049
2077
  }
2050
2078
  return -1;
2051
2079
  }
@@ -2065,10 +2093,13 @@ function Sn(n, t) {
2065
2093
  * limitations under the License.
2066
2094
  * =============================================================================
2067
2095
  */
2068
- function tr() {
2096
+ function ao() {
2097
+ g.disposeVariables();
2098
+ }
2099
+ function oo() {
2069
2100
  return g;
2070
2101
  }
2071
- function er() {
2102
+ function io() {
2072
2103
  return g.memory();
2073
2104
  }
2074
2105
  function E(n, t) {
@@ -2077,15 +2108,59 @@ function E(n, t) {
2077
2108
  function M(n) {
2078
2109
  fe(n).forEach((e) => e.dispose());
2079
2110
  }
2080
- function kn(n) {
2111
+ function En(n) {
2081
2112
  return g.keep(n);
2082
2113
  }
2083
- const Pt = typeof gt < "u" && (typeof Blob > "u" || typeof atob > "u" || typeof btoa > "u");
2084
- function Jt(n) {
2085
- return Pt ? gt.byteLength(n, "utf8") : new Blob([n]).size;
2114
+ function co() {
2115
+ return g.backend;
2116
+ }
2117
+ const Jt = 4;
2118
+ async function lo(n, t) {
2119
+ const e = [], s = [], r = Array.isArray(n) ? n.map((o) => o.name) : Object.keys(n);
2120
+ for (let o = 0; o < r.length; ++o) {
2121
+ const i = r[o], c = Array.isArray(n) ? n[o].tensor : n[i];
2122
+ if (c.dtype !== "float32" && c.dtype !== "int32" && c.dtype !== "bool" && c.dtype !== "string" && c.dtype !== "complex64")
2123
+ throw new Error(`Unsupported dtype in weight '${i}': ${c.dtype}`);
2124
+ const l = { name: i, shape: c.shape, dtype: c.dtype };
2125
+ if (c.dtype === "string") {
2126
+ const u = new Promise(async (h) => {
2127
+ const d = await c.bytes(), m = d.reduce((w, I) => w + I.length, 0) + Jt * d.length, p = new Uint8Array(m);
2128
+ let f = 0;
2129
+ for (let w = 0; w < d.length; w++) {
2130
+ const I = d[w], O = new Uint8Array(new Uint32Array([I.length]).buffer);
2131
+ p.set(O, f), f += Jt, p.set(I, f), f += I.length;
2132
+ }
2133
+ h(p);
2134
+ });
2135
+ s.push(u);
2136
+ } else
2137
+ s.push(c.data());
2138
+ t != null && (l.group = t), e.push(l);
2139
+ }
2140
+ const a = await Promise.all(s);
2141
+ return { data: An(a), specs: e };
2086
2142
  }
2087
- function In(n) {
2088
- if (Pt)
2143
+ function An(n) {
2144
+ if (n === null)
2145
+ throw new Error(`Invalid input value: ${JSON.stringify(n)}`);
2146
+ let t = 0;
2147
+ const e = [];
2148
+ n.forEach((a) => {
2149
+ if (t += a.byteLength, e.push(a.byteLength === a.buffer.byteLength ? a : new a.constructor(a)), !(a instanceof Float32Array || a instanceof Int32Array || a instanceof Uint8Array))
2150
+ throw new Error(`Unsupported TypedArray subtype: ${a.constructor.name}`);
2151
+ });
2152
+ const s = new Uint8Array(t);
2153
+ let r = 0;
2154
+ return e.forEach((a) => {
2155
+ s.set(new Uint8Array(a.buffer), r), r += a.byteLength;
2156
+ }), s.buffer;
2157
+ }
2158
+ const Lt = typeof gt < "u" && (typeof Blob > "u" || typeof atob > "u" || typeof btoa > "u");
2159
+ function Xt(n) {
2160
+ return Lt ? gt.byteLength(n, "utf8") : new Blob([n]).size;
2161
+ }
2162
+ function Bn(n) {
2163
+ if (Lt)
2089
2164
  return gt.from(n).toString("base64");
2090
2165
  const t = new Uint8Array(n);
2091
2166
  let e = "";
@@ -2093,8 +2168,8 @@ function In(n) {
2093
2168
  e += String.fromCharCode(t[s]);
2094
2169
  return btoa(e);
2095
2170
  }
2096
- function Tn(n) {
2097
- if (Pt) {
2171
+ function vn(n) {
2172
+ if (Lt) {
2098
2173
  const s = gt.from(n, "base64");
2099
2174
  return s.buffer.slice(s.byteOffset, s.byteOffset + s.byteLength);
2100
2175
  }
@@ -2103,15 +2178,18 @@ function Tn(n) {
2103
2178
  e.set([t.charCodeAt(s)], s);
2104
2179
  return e.buffer;
2105
2180
  }
2106
- function pe(n) {
2181
+ function uo(n) {
2182
+ return st.join(n);
2183
+ }
2184
+ function ye(n) {
2107
2185
  if (n.modelTopology instanceof ArrayBuffer)
2108
2186
  throw new Error("Expected JSON model topology, received ArrayBuffer.");
2109
2187
  return {
2110
2188
  dateSaved: /* @__PURE__ */ new Date(),
2111
2189
  modelTopologyType: "JSON",
2112
- modelTopologyBytes: n.modelTopology == null ? 0 : Jt(JSON.stringify(n.modelTopology)),
2113
- weightSpecsBytes: n.weightSpecs == null ? 0 : Jt(JSON.stringify(n.weightSpecs)),
2114
- weightDataBytes: n.weightData == null ? 0 : new lt(n.weightData).byteLength
2190
+ modelTopologyBytes: n.modelTopology == null ? 0 : Xt(JSON.stringify(n.modelTopology)),
2191
+ weightSpecsBytes: n.weightSpecs == null ? 0 : Xt(JSON.stringify(n.weightSpecs)),
2192
+ weightDataBytes: n.weightData == null ? 0 : new st(n.weightData).byteLength
2115
2193
  };
2116
2194
  }
2117
2195
  /**
@@ -2180,11 +2258,12 @@ class A {
2180
2258
  static getHandlers(t, e, s) {
2181
2259
  const r = [];
2182
2260
  return (e === "load" ? A.getInstance().loadRouters : A.getInstance().saveRouters).forEach((o) => {
2183
- const a = o(t, s);
2184
- a !== null && r.push(a);
2261
+ const i = o(t, s);
2262
+ i !== null && r.push(i);
2185
2263
  }), r;
2186
2264
  }
2187
2265
  }
2266
+ const ho = (n) => A.getSaveHandlers(n);
2188
2267
  /**
2189
2268
  * @license
2190
2269
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -2201,22 +2280,22 @@ class A {
2201
2280
  * limitations under the License.
2202
2281
  * =============================================================================
2203
2282
  */
2204
- const vt = "tensorflowjs", Mt = 1, U = "models_store", P = "model_info_store";
2205
- function ye() {
2206
- if (!S().getBool("IS_BROWSER"))
2283
+ const vt = "tensorflowjs", Mt = 1, G = "models_store", L = "model_info_store";
2284
+ function be() {
2285
+ if (!k().getBool("IS_BROWSER"))
2207
2286
  throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");
2208
2287
  const n = typeof window > "u" ? self : window, t = n.indexedDB || n.mozIndexedDB || n.webkitIndexedDB || n.msIndexedDB || n.shimIndexedDB;
2209
2288
  if (t == null)
2210
2289
  throw new Error("The current browser does not appear to support IndexedDB.");
2211
2290
  return t;
2212
2291
  }
2213
- function Ft(n) {
2292
+ function Nt(n) {
2214
2293
  const t = n.result;
2215
- t.createObjectStore(U, { keyPath: "modelPath" }), t.createObjectStore(P, { keyPath: "modelPath" });
2294
+ t.createObjectStore(G, { keyPath: "modelPath" }), t.createObjectStore(L, { keyPath: "modelPath" });
2216
2295
  }
2217
2296
  class W {
2218
2297
  constructor(t) {
2219
- if (this.indexedDB = ye(), t == null || !t)
2298
+ if (this.indexedDB = be(), t == null || !t)
2220
2299
  throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");
2221
2300
  this.modelPath = t;
2222
2301
  }
@@ -2244,101 +2323,101 @@ class W {
2244
2323
  */
2245
2324
  databaseAction(t, e) {
2246
2325
  return new Promise((s, r) => {
2247
- const i = this.indexedDB.open(vt, Mt);
2248
- i.onupgradeneeded = () => Ft(i), i.onsuccess = () => {
2249
- const o = i.result;
2326
+ const a = this.indexedDB.open(vt, Mt);
2327
+ a.onupgradeneeded = () => Nt(a), a.onsuccess = () => {
2328
+ const o = a.result;
2250
2329
  if (e == null) {
2251
- const a = o.transaction(U, "readonly"), l = a.objectStore(U).get(this.modelPath);
2330
+ const i = o.transaction(G, "readonly"), l = i.objectStore(G).get(this.modelPath);
2252
2331
  l.onsuccess = () => {
2253
2332
  if (l.result == null)
2254
2333
  return o.close(), r(new Error(`Cannot find model with path '${this.modelPath}' in IndexedDB.`));
2255
2334
  s(l.result.modelArtifacts);
2256
- }, l.onerror = (u) => (o.close(), r(l.error)), a.oncomplete = () => o.close();
2335
+ }, l.onerror = (u) => (o.close(), r(l.error)), i.oncomplete = () => o.close();
2257
2336
  } else {
2258
- e.weightData = lt.join(e.weightData);
2259
- const a = pe(e), c = o.transaction(P, "readwrite");
2260
- let l = c.objectStore(P), u;
2337
+ e.weightData = st.join(e.weightData);
2338
+ const i = ye(e), c = o.transaction(L, "readwrite");
2339
+ let l = c.objectStore(L), u;
2261
2340
  try {
2262
- u = l.put({ modelPath: this.modelPath, modelArtifactsInfo: a });
2263
- } catch (f) {
2264
- return r(f);
2341
+ u = l.put({ modelPath: this.modelPath, modelArtifactsInfo: i });
2342
+ } catch (d) {
2343
+ return r(d);
2265
2344
  }
2266
2345
  let h;
2267
2346
  u.onsuccess = () => {
2268
- h = o.transaction(U, "readwrite");
2269
- const f = h.objectStore(U);
2347
+ h = o.transaction(G, "readwrite");
2348
+ const d = h.objectStore(G);
2270
2349
  let m;
2271
2350
  try {
2272
- m = f.put({
2351
+ m = d.put({
2273
2352
  modelPath: this.modelPath,
2274
2353
  modelArtifacts: e,
2275
- modelArtifactsInfo: a
2354
+ modelArtifactsInfo: i
2276
2355
  });
2277
- } catch (b) {
2278
- return r(b);
2356
+ } catch (p) {
2357
+ return r(p);
2279
2358
  }
2280
- m.onsuccess = () => s({ modelArtifactsInfo: a }), m.onerror = (b) => {
2281
- l = c.objectStore(P);
2282
- const d = l.delete(this.modelPath);
2283
- d.onsuccess = () => (o.close(), r(m.error)), d.onerror = (k) => (o.close(), r(m.error));
2359
+ m.onsuccess = () => s({ modelArtifactsInfo: i }), m.onerror = (p) => {
2360
+ l = c.objectStore(L);
2361
+ const f = l.delete(this.modelPath);
2362
+ f.onsuccess = () => (o.close(), r(m.error)), f.onerror = (w) => (o.close(), r(m.error));
2284
2363
  };
2285
- }, u.onerror = (f) => (o.close(), r(u.error)), c.oncomplete = () => {
2364
+ }, u.onerror = (d) => (o.close(), r(u.error)), c.oncomplete = () => {
2286
2365
  h == null ? o.close() : h.oncomplete = () => o.close();
2287
2366
  };
2288
2367
  }
2289
- }, i.onerror = (o) => r(i.error);
2368
+ }, a.onerror = (o) => r(a.error);
2290
2369
  });
2291
2370
  }
2292
2371
  }
2293
2372
  W.URL_SCHEME = "indexeddb://";
2294
- const be = (n) => S().getBool("IS_BROWSER") && !Array.isArray(n) && n.startsWith(W.URL_SCHEME) ? En(n.slice(W.URL_SCHEME.length)) : null;
2295
- A.registerSaveRouter(be);
2296
- A.registerLoadRouter(be);
2297
- function En(n) {
2373
+ const we = (n) => k().getBool("IS_BROWSER") && !Array.isArray(n) && n.startsWith(W.URL_SCHEME) ? Mn(n.slice(W.URL_SCHEME.length)) : null;
2374
+ A.registerSaveRouter(we);
2375
+ A.registerLoadRouter(we);
2376
+ function Mn(n) {
2298
2377
  return new W(n);
2299
2378
  }
2300
- function An(n) {
2379
+ function Nn(n) {
2301
2380
  return n.startsWith(W.URL_SCHEME) ? n.slice(W.URL_SCHEME.length) : n;
2302
2381
  }
2303
- class Bn {
2382
+ class Rn {
2304
2383
  constructor() {
2305
- this.indexedDB = ye();
2384
+ this.indexedDB = be();
2306
2385
  }
2307
2386
  async listModels() {
2308
2387
  return new Promise((t, e) => {
2309
2388
  const s = this.indexedDB.open(vt, Mt);
2310
- s.onupgradeneeded = () => Ft(s), s.onsuccess = () => {
2311
- const r = s.result, i = r.transaction(P, "readonly"), a = i.objectStore(P).getAll();
2312
- a.onsuccess = () => {
2389
+ s.onupgradeneeded = () => Nt(s), s.onsuccess = () => {
2390
+ const r = s.result, a = r.transaction(L, "readonly"), i = a.objectStore(L).getAll();
2391
+ i.onsuccess = () => {
2313
2392
  const c = {};
2314
- for (const l of a.result)
2393
+ for (const l of i.result)
2315
2394
  c[l.modelPath] = l.modelArtifactsInfo;
2316
2395
  t(c);
2317
- }, a.onerror = (c) => (r.close(), e(a.error)), i.oncomplete = () => r.close();
2396
+ }, i.onerror = (c) => (r.close(), e(i.error)), a.oncomplete = () => r.close();
2318
2397
  }, s.onerror = (r) => e(s.error);
2319
2398
  });
2320
2399
  }
2321
2400
  async removeModel(t) {
2322
- return t = An(t), new Promise((e, s) => {
2401
+ return t = Nn(t), new Promise((e, s) => {
2323
2402
  const r = this.indexedDB.open(vt, Mt);
2324
- r.onupgradeneeded = () => Ft(r), r.onsuccess = () => {
2325
- const i = r.result, o = i.transaction(P, "readwrite"), a = o.objectStore(P), c = a.get(t);
2403
+ r.onupgradeneeded = () => Nt(r), r.onsuccess = () => {
2404
+ const a = r.result, o = a.transaction(L, "readwrite"), i = o.objectStore(L), c = i.get(t);
2326
2405
  let l;
2327
2406
  c.onsuccess = () => {
2328
2407
  if (c.result == null)
2329
- return i.close(), s(new Error(`Cannot find model with path '${t}' in IndexedDB.`));
2408
+ return a.close(), s(new Error(`Cannot find model with path '${t}' in IndexedDB.`));
2330
2409
  {
2331
- const u = a.delete(t), h = () => {
2332
- l = i.transaction(U, "readwrite");
2333
- const m = l.objectStore(U).delete(t);
2334
- m.onsuccess = () => e(c.result.modelArtifactsInfo), m.onerror = (b) => s(c.error);
2410
+ const u = i.delete(t), h = () => {
2411
+ l = a.transaction(G, "readwrite");
2412
+ const m = l.objectStore(G).delete(t);
2413
+ m.onsuccess = () => e(c.result.modelArtifactsInfo), m.onerror = (p) => s(c.error);
2335
2414
  };
2336
- u.onsuccess = h, u.onerror = (f) => (h(), i.close(), s(c.error));
2415
+ u.onsuccess = h, u.onerror = (d) => (h(), a.close(), s(c.error));
2337
2416
  }
2338
- }, c.onerror = (u) => (i.close(), s(c.error)), o.oncomplete = () => {
2339
- l == null ? i.close() : l.oncomplete = () => i.close();
2417
+ }, c.onerror = (u) => (a.close(), s(c.error)), o.oncomplete = () => {
2418
+ l == null ? a.close() : l.oncomplete = () => a.close();
2340
2419
  };
2341
- }, r.onerror = (i) => s(r.error);
2420
+ }, r.onerror = (a) => s(r.error);
2342
2421
  });
2343
2422
  }
2344
2423
  }
@@ -2358,36 +2437,36 @@ class Bn {
2358
2437
  * limitations under the License.
2359
2438
  * =============================================================================
2360
2439
  */
2361
- const _ = "/", Y = "tensorflowjs_models", we = "info", vn = "model_topology", Mn = "weight_specs", Fn = "weight_data", $n = "model_metadata";
2362
- function Se(n) {
2440
+ const P = "/", Q = "tensorflowjs_models", Se = "info", Fn = "model_topology", Dn = "weight_specs", $n = "weight_data", xn = "model_metadata";
2441
+ function ke(n) {
2363
2442
  return {
2364
- info: [Y, n, we].join(_),
2365
- topology: [Y, n, vn].join(_),
2366
- weightSpecs: [Y, n, Mn].join(_),
2367
- weightData: [Y, n, Fn].join(_),
2368
- modelMetadata: [Y, n, $n].join(_)
2443
+ info: [Q, n, Se].join(P),
2444
+ topology: [Q, n, Fn].join(P),
2445
+ weightSpecs: [Q, n, Dn].join(P),
2446
+ weightData: [Q, n, $n].join(P),
2447
+ modelMetadata: [Q, n, xn].join(P)
2369
2448
  };
2370
2449
  }
2371
- function ke(n) {
2450
+ function Ie(n) {
2372
2451
  for (const t of Object.values(n))
2373
2452
  window.localStorage.removeItem(t);
2374
2453
  }
2375
- function Rn(n) {
2376
- const t = n.split(_);
2454
+ function Cn(n) {
2455
+ const t = n.split(P);
2377
2456
  if (t.length < 3)
2378
2457
  throw new Error(`Invalid key format: ${n}`);
2379
- return t.slice(1, t.length - 1).join(_);
2458
+ return t.slice(1, t.length - 1).join(P);
2380
2459
  }
2381
- function xn(n) {
2460
+ function Pn(n) {
2382
2461
  return n.startsWith(j.URL_SCHEME) ? n.slice(j.URL_SCHEME.length) : n;
2383
2462
  }
2384
2463
  class j {
2385
2464
  constructor(t) {
2386
- if (!S().getBool("IS_BROWSER") || typeof window > "u" || typeof window.localStorage > "u")
2465
+ if (!k().getBool("IS_BROWSER") || typeof window > "u" || typeof window.localStorage > "u")
2387
2466
  throw new Error("The current environment does not support local storage.");
2388
2467
  if (this.LS = window.localStorage, t == null || !t)
2389
2468
  throw new Error("For local storage, modelPath must not be null, undefined or empty.");
2390
- this.modelPath = t, this.keys = Se(this.modelPath);
2469
+ this.modelPath = t, this.keys = ke(this.modelPath);
2391
2470
  }
2392
2471
  /**
2393
2472
  * Save model artifacts to browser local storage.
@@ -2402,9 +2481,9 @@ class j {
2402
2481
  if (t.modelTopology instanceof ArrayBuffer)
2403
2482
  throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");
2404
2483
  {
2405
- const e = JSON.stringify(t.modelTopology), s = JSON.stringify(t.weightSpecs), r = pe(t), i = lt.join(t.weightData);
2484
+ const e = JSON.stringify(t.modelTopology), s = JSON.stringify(t.weightSpecs), r = ye(t), a = st.join(t.weightData);
2406
2485
  try {
2407
- this.LS.setItem(this.keys.info, JSON.stringify(r)), this.LS.setItem(this.keys.topology, e), this.LS.setItem(this.keys.weightSpecs, s), this.LS.setItem(this.keys.weightData, In(i));
2486
+ this.LS.setItem(this.keys.info, JSON.stringify(r)), this.LS.setItem(this.keys.topology, e), this.LS.setItem(this.keys.weightSpecs, s), this.LS.setItem(this.keys.weightData, Bn(a));
2408
2487
  const o = {
2409
2488
  format: t.format,
2410
2489
  generatedBy: t.generatedBy,
@@ -2417,7 +2496,7 @@ class j {
2417
2496
  };
2418
2497
  return this.LS.setItem(this.keys.modelMetadata, JSON.stringify(o)), { modelArtifactsInfo: r };
2419
2498
  } catch {
2420
- throw ke(this.keys), new Error(`Failed to save model '${this.modelPath}' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes=${r.modelTopologyBytes}, weightSpecsBytes=${r.weightSpecsBytes}, weightDataBytes=${r.weightDataBytes}.`);
2499
+ throw Ie(this.keys), new Error(`Failed to save model '${this.modelPath}' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes=${r.modelTopologyBytes}, weightSpecsBytes=${r.weightSpecsBytes}, weightDataBytes=${r.weightDataBytes}.`);
2421
2500
  }
2422
2501
  }
2423
2502
  }
@@ -2443,46 +2522,46 @@ class j {
2443
2522
  if (r == null)
2444
2523
  throw new Error(`In local storage, the weight specs of model '${this.modelPath}' are missing.`);
2445
2524
  e.weightSpecs = r;
2446
- const i = this.LS.getItem(this.keys.modelMetadata);
2447
- if (i != null) {
2448
- const a = JSON.parse(i);
2449
- e.format = a.format, e.generatedBy = a.generatedBy, e.convertedBy = a.convertedBy, a.signature != null && (e.signature = a.signature), a.userDefinedMetadata != null && (e.userDefinedMetadata = a.userDefinedMetadata), a.modelInitializer != null && (e.modelInitializer = a.modelInitializer), a.initializerSignature != null && (e.initializerSignature = a.initializerSignature), a.trainingConfig != null && (e.trainingConfig = a.trainingConfig);
2525
+ const a = this.LS.getItem(this.keys.modelMetadata);
2526
+ if (a != null) {
2527
+ const i = JSON.parse(a);
2528
+ e.format = i.format, e.generatedBy = i.generatedBy, e.convertedBy = i.convertedBy, i.signature != null && (e.signature = i.signature), i.userDefinedMetadata != null && (e.userDefinedMetadata = i.userDefinedMetadata), i.modelInitializer != null && (e.modelInitializer = i.modelInitializer), i.initializerSignature != null && (e.initializerSignature = i.initializerSignature), i.trainingConfig != null && (e.trainingConfig = i.trainingConfig);
2450
2529
  }
2451
2530
  const o = this.LS.getItem(this.keys.weightData);
2452
2531
  if (o == null)
2453
2532
  throw new Error(`In local storage, the binary weight values of model '${this.modelPath}' are missing.`);
2454
- return e.weightData = Tn(o), e;
2533
+ return e.weightData = vn(o), e;
2455
2534
  }
2456
2535
  }
2457
2536
  j.URL_SCHEME = "localstorage://";
2458
- const Ie = (n) => S().getBool("IS_BROWSER") && !Array.isArray(n) && n.startsWith(j.URL_SCHEME) ? Nn(n.slice(j.URL_SCHEME.length)) : null;
2459
- A.registerSaveRouter(Ie);
2460
- A.registerLoadRouter(Ie);
2461
- function Nn(n) {
2537
+ const Te = (n) => k().getBool("IS_BROWSER") && !Array.isArray(n) && n.startsWith(j.URL_SCHEME) ? Ln(n.slice(j.URL_SCHEME.length)) : null;
2538
+ A.registerSaveRouter(Te);
2539
+ A.registerLoadRouter(Te);
2540
+ function Ln(n) {
2462
2541
  return new j(n);
2463
2542
  }
2464
- class Dn {
2543
+ class On {
2465
2544
  constructor() {
2466
- y(S().getBool("IS_BROWSER"), () => "Current environment is not a web browser"), y(typeof window > "u" || typeof window.localStorage < "u", () => "Current browser does not appear to support localStorage"), this.LS = window.localStorage;
2545
+ y(k().getBool("IS_BROWSER"), () => "Current environment is not a web browser"), y(typeof window > "u" || typeof window.localStorage < "u", () => "Current browser does not appear to support localStorage"), this.LS = window.localStorage;
2467
2546
  }
2468
2547
  async listModels() {
2469
- const t = {}, e = Y + _, s = _ + we;
2548
+ const t = {}, e = Q + P, s = P + Se;
2470
2549
  for (let r = 0; r < this.LS.length; ++r) {
2471
- const i = this.LS.key(r);
2472
- if (i.startsWith(e) && i.endsWith(s)) {
2473
- const o = Rn(i);
2474
- t[o] = JSON.parse(this.LS.getItem(i));
2550
+ const a = this.LS.key(r);
2551
+ if (a.startsWith(e) && a.endsWith(s)) {
2552
+ const o = Cn(a);
2553
+ t[o] = JSON.parse(this.LS.getItem(a));
2475
2554
  }
2476
2555
  }
2477
2556
  return t;
2478
2557
  }
2479
2558
  async removeModel(t) {
2480
- t = xn(t);
2481
- const e = Se(t);
2559
+ t = Pn(t);
2560
+ const e = ke(t);
2482
2561
  if (this.LS.getItem(e.info) == null)
2483
2562
  throw new Error(`Cannot find model at path '${t}'`);
2484
2563
  const s = JSON.parse(this.LS.getItem(e.info));
2485
- return ke(e), s;
2564
+ return Ie(e), s;
2486
2565
  }
2487
2566
  }
2488
2567
  /**
@@ -2501,13 +2580,13 @@ class Dn {
2501
2580
  * limitations under the License.
2502
2581
  * =============================================================================
2503
2582
  */
2504
- const Xt = "://";
2505
- class N {
2583
+ const Yt = "://";
2584
+ class $ {
2506
2585
  constructor() {
2507
2586
  this.managers = {};
2508
2587
  }
2509
2588
  static getInstance() {
2510
- return N.instance == null && (N.instance = new N()), N.instance;
2589
+ return $.instance == null && ($.instance = new $()), $.instance;
2511
2590
  }
2512
2591
  /**
2513
2592
  * Register a save-handler router.
@@ -2516,18 +2595,18 @@ class N {
2516
2595
  * of `IOHandler` with the `save` method defined or `null`.
2517
2596
  */
2518
2597
  static registerManager(t, e) {
2519
- y(t != null, () => "scheme must not be undefined or null."), t.endsWith(Xt) && (t = t.slice(0, t.indexOf(Xt))), y(t.length > 0, () => "scheme must not be an empty string.");
2520
- const s = N.getInstance();
2598
+ y(t != null, () => "scheme must not be undefined or null."), t.endsWith(Yt) && (t = t.slice(0, t.indexOf(Yt))), y(t.length > 0, () => "scheme must not be an empty string.");
2599
+ const s = $.getInstance();
2521
2600
  y(s.managers[t] == null, () => `A model store manager is already registered for scheme '${t}'.`), s.managers[t] = e;
2522
2601
  }
2523
2602
  static getManager(t) {
2524
- const e = N.getInstance().managers[t];
2603
+ const e = $.getInstance().managers[t];
2525
2604
  if (e == null)
2526
2605
  throw new Error(`Cannot find model manager for scheme '${t}'`);
2527
2606
  return e;
2528
2607
  }
2529
2608
  static getSchemes() {
2530
- return Object.keys(N.getInstance().managers);
2609
+ return Object.keys($.getInstance().managers);
2531
2610
  }
2532
2611
  }
2533
2612
  /**
@@ -2546,7 +2625,7 @@ class N {
2546
2625
  * limitations under the License.
2547
2626
  * =============================================================================
2548
2627
  */
2549
- class Cn {
2628
+ class _n {
2550
2629
  constructor() {
2551
2630
  this.messageName = "setTimeoutCustom", this.functionRefs = [], this.handledMessageCount = 0, this.hasEventListener = !1;
2552
2631
  }
@@ -2569,7 +2648,7 @@ class Cn {
2569
2648
  // Interleaving window.postMessage and setTimeout will trick the browser and
2570
2649
  // avoid the clamp.
2571
2650
  setTimeoutCustom(t, e) {
2572
- if (typeof window > "u" || !S().getBool("USE_SETTIMEOUTCUSTOM")) {
2651
+ if (typeof window > "u" || !k().getBool("USE_SETTIMEOUTCUSTOM")) {
2573
2652
  setTimeout(t, e);
2574
2653
  return;
2575
2654
  }
@@ -2584,34 +2663,34 @@ class Cn {
2584
2663
  }, !0));
2585
2664
  }
2586
2665
  isTypedArray(t) {
2587
- return oe(t);
2666
+ return ie(t);
2588
2667
  }
2589
2668
  }
2590
- if (S().get("IS_BROWSER")) {
2591
- S().setPlatform("browser", new Cn());
2669
+ if (k().get("IS_BROWSER")) {
2670
+ k().setPlatform("browser", new _n());
2592
2671
  try {
2593
- N.registerManager(j.URL_SCHEME, new Dn());
2672
+ $.registerManager(j.URL_SCHEME, new On());
2594
2673
  } catch {
2595
2674
  }
2596
2675
  try {
2597
- N.registerManager(W.URL_SCHEME, new Bn());
2676
+ $.registerManager(W.URL_SCHEME, new Rn());
2598
2677
  } catch {
2599
2678
  }
2600
2679
  }
2601
- const _n = {
2680
+ const Un = {
2602
2681
  // tslint:disable-next-line:no-require-imports
2603
2682
  importFetch: () => require("node-fetch")
2604
2683
  };
2605
2684
  let wt;
2606
- class Pn {
2685
+ class Gn {
2607
2686
  constructor() {
2608
2687
  this.util = require("util"), this.textEncoder = new this.util.TextEncoder();
2609
2688
  }
2610
2689
  fetch(t, e) {
2611
- return S().global.fetch != null ? S().global.fetch(t, e) : (wt == null && (wt = _n.importFetch()), wt(t, e));
2690
+ return k().global.fetch != null ? k().global.fetch(t, e) : (wt == null && (wt = Un.importFetch()), wt(t, e));
2612
2691
  }
2613
2692
  now() {
2614
- const t = Q.hrtime();
2693
+ const t = Z.hrtime();
2615
2694
  return t[0] * 1e3 + t[1] / 1e6;
2616
2695
  }
2617
2696
  encode(t, e) {
@@ -2626,7 +2705,7 @@ class Pn {
2626
2705
  return this.util.types.isFloat32Array(t) || this.util.types.isInt32Array(t) || this.util.types.isUint8Array(t) || this.util.types.isUint8ClampedArray(t);
2627
2706
  }
2628
2707
  }
2629
- S().get("IS_NODE") && !S().get("IS_BROWSER") && S().setPlatform("node", new Pn());
2708
+ k().get("IS_NODE") && !k().get("IS_BROWSER") && k().setPlatform("node", new Gn());
2630
2709
  /**
2631
2710
  * @license
2632
2711
  * Copyright 2020 Google Inc. All Rights Reserved.
@@ -2643,8 +2722,8 @@ S().get("IS_NODE") && !S().get("IS_BROWSER") && S().setPlatform("node", new Pn()
2643
2722
  * limitations under the License.
2644
2723
  * =============================================================================
2645
2724
  */
2646
- function On(n, t = "float32", e) {
2647
- return t = t || "float32", Dt(n), new ln(n, t, e);
2725
+ function zn(n, t = "float32", e) {
2726
+ return t = t || "float32", xt(n), new hn(n, t, e);
2648
2727
  }
2649
2728
  /**
2650
2729
  * @license
@@ -2662,16 +2741,16 @@ function On(n, t = "float32", e) {
2662
2741
  * limitations under the License.
2663
2742
  * =============================================================================
2664
2743
  */
2665
- function Ln(n, t) {
2666
- const e = I(n, "x", "cast");
2744
+ function Vn(n, t) {
2745
+ const e = T(n, "x", "cast");
2667
2746
  if (!$e(t))
2668
2747
  throw new Error(`Failed to cast to unknown dtype ${t}`);
2669
2748
  if (t === "string" && e.dtype !== "string" || t !== "string" && e.dtype === "string")
2670
2749
  throw new Error("Only strings can be casted to strings");
2671
2750
  const s = { x: e }, r = { dtype: t };
2672
- return g.runKernel(se, s, r);
2751
+ return g.runKernel(re, s, r);
2673
2752
  }
2674
- const $t = /* @__PURE__ */ F({ cast_: Ln });
2753
+ const Rt = /* @__PURE__ */ N({ cast_: Vn });
2675
2754
  /**
2676
2755
  * @license
2677
2756
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -2688,11 +2767,11 @@ const $t = /* @__PURE__ */ F({ cast_: Ln });
2688
2767
  * limitations under the License.
2689
2768
  * =============================================================================
2690
2769
  */
2691
- function Un(n) {
2692
- const e = { x: I(n, "x", "clone", "string_or_numeric") };
2693
- return g.runKernel(re, e);
2770
+ function Wn(n) {
2771
+ const e = { x: T(n, "x", "clone", "string_or_numeric") };
2772
+ return g.runKernel(ae, e);
2694
2773
  }
2695
- const Gn = /* @__PURE__ */ F({ clone_: Un });
2774
+ const jn = /* @__PURE__ */ N({ clone_: Wn });
2696
2775
  /**
2697
2776
  * @license
2698
2777
  * Copyright 2020 Google Inc. All Rights Reserved.
@@ -2709,7 +2788,7 @@ const Gn = /* @__PURE__ */ F({ clone_: Un });
2709
2788
  * limitations under the License.
2710
2789
  * =============================================================================
2711
2790
  */
2712
- function zn(n, t = !1) {
2791
+ function Kn(n, t = !1) {
2713
2792
  console.log(n.toString(t));
2714
2793
  }
2715
2794
  /**
@@ -2728,14 +2807,14 @@ function zn(n, t = !1) {
2728
2807
  * limitations under the License.
2729
2808
  * =============================================================================
2730
2809
  */
2731
- ge();
2732
- const Wn = {
2733
- buffer: On,
2734
- cast: $t,
2735
- clone: Gn,
2736
- print: zn
2810
+ me();
2811
+ const qn = {
2812
+ buffer: zn,
2813
+ cast: Rt,
2814
+ clone: jn,
2815
+ print: Kn
2737
2816
  };
2738
- un(Wn);
2817
+ fn(qn);
2739
2818
  /**
2740
2819
  * @license
2741
2820
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -2752,13 +2831,13 @@ un(Wn);
2752
2831
  * limitations under the License.
2753
2832
  * =============================================================================
2754
2833
  */
2755
- function jn(n, t) {
2756
- let e = I(n, "a", "add"), s = I(t, "b", "add");
2757
- [e, s] = V(e, s);
2834
+ function Hn(n, t) {
2835
+ let e = T(n, "a", "add"), s = T(t, "b", "add");
2836
+ [e, s] = q(e, s);
2758
2837
  const r = { a: e, b: s };
2759
- return g.runKernel(ne, r);
2838
+ return g.runKernel(se, r);
2760
2839
  }
2761
- const w = /* @__PURE__ */ F({ add_: jn });
2840
+ const S = /* @__PURE__ */ N({ add_: Hn });
2762
2841
  /**
2763
2842
  * @license
2764
2843
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -2775,13 +2854,13 @@ const w = /* @__PURE__ */ F({ add_: jn });
2775
2854
  * limitations under the License.
2776
2855
  * =============================================================================
2777
2856
  */
2778
- function Kn(n, t) {
2779
- let e = I(n, "a", "floorDiv"), s = I(t, "b", "floorDiv");
2780
- [e, s] = V(e, s);
2857
+ function Jn(n, t) {
2858
+ let e = T(n, "a", "floorDiv"), s = T(t, "b", "floorDiv");
2859
+ [e, s] = q(e, s);
2781
2860
  const r = { a: e, b: s };
2782
- return g.runKernel(Ke, r);
2861
+ return g.runKernel(He, r);
2783
2862
  }
2784
- const Vn = /* @__PURE__ */ F({ floorDiv_: Kn });
2863
+ const Xn = /* @__PURE__ */ N({ floorDiv_: Jn });
2785
2864
  /**
2786
2865
  * @license
2787
2866
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -2798,14 +2877,14 @@ const Vn = /* @__PURE__ */ F({ floorDiv_: Kn });
2798
2877
  * limitations under the License.
2799
2878
  * =============================================================================
2800
2879
  */
2801
- function qn(n, t) {
2802
- let e = I(n, "a", "div"), s = I(t, "b", "div");
2803
- if ([e, s] = V(e, s), e.dtype === "int32" && s.dtype === "int32")
2804
- return Vn(e, s);
2805
- const r = { a: e, b: s }, i = {};
2806
- return g.runKernel(We, r, i);
2807
- }
2808
- const D = /* @__PURE__ */ F({ div_: qn });
2880
+ function Yn(n, t) {
2881
+ let e = T(n, "a", "div"), s = T(t, "b", "div");
2882
+ if ([e, s] = q(e, s), e.dtype === "int32" && s.dtype === "int32")
2883
+ return Xn(e, s);
2884
+ const r = { a: e, b: s }, a = {};
2885
+ return g.runKernel(Ke, r, a);
2886
+ }
2887
+ const x = /* @__PURE__ */ N({ div_: Yn });
2809
2888
  /**
2810
2889
  * @license
2811
2890
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -2822,13 +2901,13 @@ const D = /* @__PURE__ */ F({ div_: qn });
2822
2901
  * limitations under the License.
2823
2902
  * =============================================================================
2824
2903
  */
2825
- function Hn(n, t) {
2826
- let e = I(n, "a", "mul"), s = I(t, "b", "mul");
2827
- [e, s] = V(e, s);
2904
+ function Qn(n, t) {
2905
+ let e = T(n, "a", "mul"), s = T(t, "b", "mul");
2906
+ [e, s] = q(e, s);
2828
2907
  const r = { a: e, b: s };
2829
- return g.runKernel(qe, r);
2908
+ return g.runKernel(Xe, r);
2830
2909
  }
2831
- const p = /* @__PURE__ */ F({ mul_: Hn });
2910
+ const b = /* @__PURE__ */ N({ mul_: Qn });
2832
2911
  /**
2833
2912
  * @license
2834
2913
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -2845,17 +2924,17 @@ const p = /* @__PURE__ */ F({ mul_: Hn });
2845
2924
  * limitations under the License.
2846
2925
  * =============================================================================
2847
2926
  */
2848
- function Jn(n) {
2849
- const t = I(n, "x", "abs");
2927
+ function Zn(n) {
2928
+ const t = T(n, "x", "abs");
2850
2929
  if (t.dtype === "complex64") {
2851
2930
  const e = { x: t };
2852
- return g.runKernel(ze, e);
2931
+ return g.runKernel(je, e);
2853
2932
  } else {
2854
2933
  const e = { x: t };
2855
- return g.runKernel(Ge, e);
2934
+ return g.runKernel(We, e);
2856
2935
  }
2857
2936
  }
2858
- const Xn = /* @__PURE__ */ F({ abs_: Jn });
2937
+ const ts = /* @__PURE__ */ N({ abs_: Zn });
2859
2938
  /**
2860
2939
  * @license
2861
2940
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -2872,10 +2951,10 @@ const Xn = /* @__PURE__ */ F({ abs_: Jn });
2872
2951
  * limitations under the License.
2873
2952
  * =============================================================================
2874
2953
  */
2875
- function Yn(n, t, e) {
2876
- Dt(n), e = e || mt(t);
2954
+ function es(n, t, e) {
2955
+ xt(n), e = e || mt(t);
2877
2956
  const s = { shape: n, value: t, dtype: e };
2878
- return g.runKernel(je, {}, s);
2957
+ return g.runKernel(qe, {}, s);
2879
2958
  }
2880
2959
  /**
2881
2960
  * @license
@@ -2893,29 +2972,29 @@ function Yn(n, t, e) {
2893
2972
  * limitations under the License.
2894
2973
  * =============================================================================
2895
2974
  */
2896
- function nr(n, t) {
2975
+ function fo(n, t) {
2897
2976
  const e = [];
2898
2977
  for (let s = 0; s < t.length; s++) {
2899
- const r = n[n.length - s - 1], i = t.length - s - 1, o = t[i];
2900
- (r == null || r === 1 && o > 1) && e.unshift(i);
2978
+ const r = n[n.length - s - 1], a = t.length - s - 1, o = t[a];
2979
+ (r == null || r === 1 && o > 1) && e.unshift(a);
2901
2980
  }
2902
2981
  return e;
2903
2982
  }
2904
- function Qn(n, t) {
2983
+ function ns(n, t) {
2905
2984
  const e = Math.max(n.length, t.length), s = new Array(e);
2906
2985
  for (let r = 0; r < e; r++) {
2907
- let i = n[n.length - r - 1];
2908
- i == null && (i = 1);
2986
+ let a = n[n.length - r - 1];
2987
+ a == null && (a = 1);
2909
2988
  let o = t[t.length - r - 1];
2910
- if (o == null && (o = 1), i === 1)
2989
+ if (o == null && (o = 1), a === 1)
2911
2990
  s[e - r - 1] = o;
2912
2991
  else if (o === 1)
2913
- s[e - r - 1] = i;
2914
- else if (i !== o) {
2915
- const a = `Operands could not be broadcast together with shapes ${n} and ${t}.`;
2916
- throw Error(a);
2992
+ s[e - r - 1] = a;
2993
+ else if (a !== o) {
2994
+ const i = `Operands could not be broadcast together with shapes ${n} and ${t}.`;
2995
+ throw Error(i);
2917
2996
  } else
2918
- s[e - r - 1] = i;
2997
+ s[e - r - 1] = a;
2919
2998
  }
2920
2999
  return s;
2921
3000
  }
@@ -2935,11 +3014,11 @@ function Qn(n, t) {
2935
3014
  * limitations under the License.
2936
3015
  * =============================================================================
2937
3016
  */
2938
- function Zn(n) {
2939
- const e = { x: I(n, "x", "zerosLike") };
2940
- return g.runKernel(Ye, e);
3017
+ function ss(n) {
3018
+ const e = { x: T(n, "x", "zerosLike") };
3019
+ return g.runKernel(tn, e);
2941
3020
  }
2942
- const C = /* @__PURE__ */ F({ zerosLike_: Zn });
3021
+ const C = /* @__PURE__ */ N({ zerosLike_: ss });
2943
3022
  /**
2944
3023
  * @license
2945
3024
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -2956,13 +3035,13 @@ const C = /* @__PURE__ */ F({ zerosLike_: Zn });
2956
3035
  * limitations under the License.
2957
3036
  * =============================================================================
2958
3037
  */
2959
- function ts(n, t) {
2960
- let e = I(n, "base", "pow"), s = I(t, "exp", "pow");
2961
- [e, s] = V(e, s);
3038
+ function rs(n, t) {
3039
+ let e = T(n, "base", "pow"), s = T(t, "exp", "pow");
3040
+ [e, s] = q(e, s);
2962
3041
  const r = { a: e, b: s };
2963
- return g.runKernel(He, r);
3042
+ return g.runKernel(Ye, r);
2964
3043
  }
2965
- const Yt = /* @__PURE__ */ F({ pow_: ts });
3044
+ const Qt = /* @__PURE__ */ N({ pow_: rs });
2966
3045
  /**
2967
3046
  * @license
2968
3047
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -2980,11 +3059,11 @@ const Yt = /* @__PURE__ */ F({ pow_: ts });
2980
3059
  * =============================================================================
2981
3060
  */
2982
3061
  function K(n, t) {
2983
- if (($(n) && t !== "string" || Array.isArray(n)) && t !== "complex64")
3062
+ if ((R(n) && t !== "string" || Array.isArray(n)) && t !== "complex64")
2984
3063
  throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");
2985
- if (t === "string" && $(n) && !(n instanceof Uint8Array))
3064
+ if (t === "string" && R(n) && !(n instanceof Uint8Array))
2986
3065
  throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");
2987
- return wn(n, [], [], t);
3066
+ return In(n, [], [], t);
2988
3067
  }
2989
3068
  /**
2990
3069
  * @license
@@ -3002,11 +3081,11 @@ function K(n, t) {
3002
3081
  * limitations under the License.
3003
3082
  * =============================================================================
3004
3083
  */
3005
- function es(n) {
3006
- const e = { x: I(n, "x", "sqrt", "float32") };
3007
- return g.runKernel(Je, e);
3084
+ function as(n) {
3085
+ const e = { x: T(n, "x", "sqrt", "float32") };
3086
+ return g.runKernel(Qe, e);
3008
3087
  }
3009
- const et = /* @__PURE__ */ F({ sqrt_: es });
3088
+ const nt = /* @__PURE__ */ N({ sqrt_: as });
3010
3089
  /**
3011
3090
  * @license
3012
3091
  * Copyright 2019 Google LLC. All Rights Reserved.
@@ -3023,11 +3102,11 @@ const et = /* @__PURE__ */ F({ sqrt_: es });
3023
3102
  * limitations under the License.
3024
3103
  * =============================================================================
3025
3104
  */
3026
- function ns(n) {
3027
- const t = I(n, "x", "square"), e = {};
3105
+ function os(n) {
3106
+ const t = T(n, "x", "square"), e = {};
3028
3107
  return g.runKernel("Square", { x: t }, e);
3029
3108
  }
3030
- const z = /* @__PURE__ */ F({ square_: ns });
3109
+ const V = /* @__PURE__ */ N({ square_: os });
3031
3110
  /**
3032
3111
  * @license
3033
3112
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -3044,8 +3123,8 @@ const z = /* @__PURE__ */ F({ square_: ns });
3044
3123
  * limitations under the License.
3045
3124
  * =============================================================================
3046
3125
  */
3047
- function ss(n, t) {
3048
- y(kt(n), () => "The f passed in variableGrads(f) must be a function"), y(t == null || Array.isArray(t) && t.every((l) => l instanceof dt), () => "The varList passed in variableGrads(f, varList) must be an array of variables");
3126
+ function is(n, t) {
3127
+ y(kt(n), () => "The f passed in variableGrads(f) must be a function"), y(t == null || Array.isArray(t) && t.every((l) => l instanceof ft), () => "The varList passed in variableGrads(f, varList) must be an array of variables");
3049
3128
  const e = t != null;
3050
3129
  if (!e) {
3051
3130
  t = [];
@@ -3054,14 +3133,14 @@ function ss(n, t) {
3054
3133
  }
3055
3134
  const s = e ? t.filter((l) => !l.trainable) : null, r = t.length;
3056
3135
  t = t.filter((l) => l.trainable), y(t.length > 0, () => `variableGrads() expects at least one of the input variables to be trainable, but none of the ${r} variables is trainable.`);
3057
- const i = !0, { value: o, grads: a } = g.gradients(n, t, null, i);
3058
- y(a.some((l) => l != null), () => "Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."), y(o.rank === 0, () => `The f passed in variableGrads(f) must return a scalar, but it returned a rank-${o.rank} tensor`);
3136
+ const a = !0, { value: o, grads: i } = g.gradients(n, t, null, a);
3137
+ y(i.some((l) => l != null), () => "Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."), y(o.rank === 0, () => `The f passed in variableGrads(f) must return a scalar, but it returned a rank-${o.rank} tensor`);
3059
3138
  const c = {};
3060
3139
  return t.forEach((l, u) => {
3061
- a[u] != null && (c[l.name] = a[u]);
3140
+ i[u] != null && (c[l.name] = i[u]);
3062
3141
  }), s?.forEach((l) => c[l.name] = null), { value: o, grads: c };
3063
3142
  }
3064
- function sr(n) {
3143
+ function go(n) {
3065
3144
  return g.customGrad(n);
3066
3145
  }
3067
3146
  /**
@@ -3080,13 +3159,13 @@ function sr(n) {
3080
3159
  * limitations under the License.
3081
3160
  * =============================================================================
3082
3161
  */
3083
- function rs(n, t) {
3084
- let e = I(n, "a", "sub"), s = I(t, "b", "sub");
3085
- [e, s] = V(e, s);
3162
+ function cs(n, t) {
3163
+ let e = T(n, "a", "sub"), s = T(t, "b", "sub");
3164
+ [e, s] = q(e, s);
3086
3165
  const r = { a: e, b: s };
3087
- return g.runKernel(Xe, r);
3166
+ return g.runKernel(Ze, r);
3088
3167
  }
3089
- const Z = /* @__PURE__ */ F({ sub_: rs });
3168
+ const tt = /* @__PURE__ */ N({ sub_: cs });
3090
3169
  /**
3091
3170
  * @license
3092
3171
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -3103,13 +3182,13 @@ const Z = /* @__PURE__ */ F({ sub_: rs });
3103
3182
  * limitations under the License.
3104
3183
  * =============================================================================
3105
3184
  */
3106
- function is(n, t) {
3107
- let e = I(n, "a", "maximum"), s = I(t, "b", "maximum");
3108
- [e, s] = V(e, s), e.dtype === "bool" && (e = $t(e, "int32"), s = $t(s, "int32")), Qn(e.shape, s.shape);
3185
+ function ls(n, t) {
3186
+ let e = T(n, "a", "maximum"), s = T(t, "b", "maximum");
3187
+ [e, s] = q(e, s), e.dtype === "bool" && (e = Rt(e, "int32"), s = Rt(s, "int32")), ns(e.shape, s.shape);
3109
3188
  const r = { a: e, b: s };
3110
- return g.runKernel(Ve, r);
3189
+ return g.runKernel(Je, r);
3111
3190
  }
3112
- const os = /* @__PURE__ */ F({ maximum_: is });
3191
+ const us = /* @__PURE__ */ N({ maximum_: ls });
3113
3192
  /**
3114
3193
  * @license
3115
3194
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -3126,8 +3205,8 @@ const os = /* @__PURE__ */ F({ maximum_: is });
3126
3205
  * limitations under the License.
3127
3206
  * =============================================================================
3128
3207
  */
3129
- const as = /* @__PURE__ */ new Map(), ls = /* @__PURE__ */ new Map();
3130
- class cs {
3208
+ const hs = /* @__PURE__ */ new Map(), ds = /* @__PURE__ */ new Map();
3209
+ class fs {
3131
3210
  /**
3132
3211
  * Return the class name for this class to use in serialization contexts.
3133
3212
  *
@@ -3155,7 +3234,7 @@ class cs {
3155
3234
  return new t(e);
3156
3235
  }
3157
3236
  }
3158
- class L {
3237
+ class U {
3159
3238
  constructor() {
3160
3239
  this.classNameMap = {};
3161
3240
  }
@@ -3163,19 +3242,19 @@ class L {
3163
3242
  * Returns the singleton instance of the map.
3164
3243
  */
3165
3244
  static getMap() {
3166
- return L.instance == null && (L.instance = new L()), L.instance;
3245
+ return U.instance == null && (U.instance = new U()), U.instance;
3167
3246
  }
3168
3247
  /**
3169
3248
  * Registers the class as serializable.
3170
3249
  */
3171
3250
  static register(t) {
3172
- L.getMap().classNameMap[t.className] = [t, t.fromConfig];
3251
+ U.getMap().classNameMap[t.className] = [t, t.fromConfig];
3173
3252
  }
3174
3253
  }
3175
- function us(n, t, e) {
3254
+ function gs(n, t, e) {
3176
3255
  y(n.className != null, () => "Class being registered does not have the static className property defined."), y(typeof n.className == "string", () => "className is required to be a string, but got type " + typeof n.className), y(n.className.length > 0, () => "Class being registered has an empty-string as its className, which is disallowed."), typeof t > "u" && (t = "Custom"), typeof e > "u" && (e = n.className);
3177
3256
  const s = e, r = t + ">" + s;
3178
- return L.register(n), as.set(r, n), ls.set(n, r), n;
3257
+ return U.register(n), hs.set(r, n), ds.set(n, r), n;
3179
3258
  }
3180
3259
  /**
3181
3260
  * @license
@@ -3193,7 +3272,7 @@ function us(n, t, e) {
3193
3272
  * limitations under the License.
3194
3273
  * =============================================================================
3195
3274
  */
3196
- class q extends cs {
3275
+ class H extends fs {
3197
3276
  /**
3198
3277
  * Executes `f()` and minimizes the scalar output of `f()` by computing
3199
3278
  * gradients of y with respect to the list of trainable variables provided by
@@ -3209,13 +3288,13 @@ class q extends cs {
3209
3288
  * @doc {heading: 'Training', subheading: 'Optimizers'}
3210
3289
  */
3211
3290
  minimize(t, e = !1, s) {
3212
- const { value: r, grads: i } = this.computeGradients(t, s);
3291
+ const { value: r, grads: a } = this.computeGradients(t, s);
3213
3292
  if (s != null) {
3214
- const o = s.map((a) => ({ name: a.name, tensor: i[a.name] }));
3293
+ const o = s.map((i) => ({ name: i.name, tensor: a[i.name] }));
3215
3294
  this.applyGradients(o);
3216
3295
  } else
3217
- this.applyGradients(i);
3218
- return M(i), e ? r : (r.dispose(), null);
3296
+ this.applyGradients(a);
3297
+ return M(a), e ? r : (r.dispose(), null);
3219
3298
  }
3220
3299
  /**
3221
3300
  * The number of iterations that this optimizer instance has been invoked for.
@@ -3240,7 +3319,7 @@ class q extends cs {
3240
3319
  * @doc {heading: 'Training', subheading: 'Optimizers'}
3241
3320
  */
3242
3321
  computeGradients(t, e) {
3243
- return ss(t, e);
3322
+ return is(t, e);
3244
3323
  }
3245
3324
  /**
3246
3325
  * Dispose the variables (if any) owned by this optimizer instance.
@@ -3272,7 +3351,7 @@ class q extends cs {
3272
3351
  return this.iterations_ = (await t[0].tensor.data())[0], t.slice(1);
3273
3352
  }
3274
3353
  }
3275
- Object.defineProperty(q, Symbol.hasInstance, {
3354
+ Object.defineProperty(H, Symbol.hasInstance, {
3276
3355
  value: (n) => n.minimize != null && n.computeGradients != null && n.applyGradients != null
3277
3356
  });
3278
3357
  /**
@@ -3291,7 +3370,7 @@ Object.defineProperty(q, Symbol.hasInstance, {
3291
3370
  * limitations under the License.
3292
3371
  * =============================================================================
3293
3372
  */
3294
- class hs extends q {
3373
+ class ms extends H {
3295
3374
  /** @nocollapse */
3296
3375
  static get className() {
3297
3376
  return "Adadelta";
@@ -3301,23 +3380,23 @@ class hs extends q {
3301
3380
  }
3302
3381
  applyGradients(t) {
3303
3382
  (Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
3304
- const i = g.registeredVariables[s], o = !1;
3383
+ const a = g.registeredVariables[s], o = !1;
3305
3384
  this.accumulatedGrads[r] == null && (this.accumulatedGrads[r] = {
3306
3385
  originalName: `${s}/accum_grad`,
3307
- variable: E(() => C(i).variable(o))
3386
+ variable: E(() => C(a).variable(o))
3308
3387
  }), this.accumulatedUpdates[r] == null && (this.accumulatedUpdates[r] = {
3309
3388
  originalName: `${s}/accum_var`,
3310
- variable: E(() => C(i).variable(o))
3389
+ variable: E(() => C(a).variable(o))
3311
3390
  });
3312
- const a = Array.isArray(t) ? t[r].tensor : t[s];
3313
- if (a == null)
3391
+ const i = Array.isArray(t) ? t[r].tensor : t[s];
3392
+ if (i == null)
3314
3393
  return;
3315
3394
  const c = this.accumulatedGrads[r].variable, l = this.accumulatedUpdates[r].variable;
3316
3395
  E(() => {
3317
- const u = w(p(c, this.rho), p(z(a), 1 - this.rho)), h = p(D(et(w(l, this.epsilon)), et(w(c, this.epsilon))), a), f = w(p(l, this.rho), p(z(h), 1 - this.rho));
3318
- c.assign(u), l.assign(f);
3319
- const m = w(p(h, -this.learningRate), i);
3320
- i.assign(m);
3396
+ const u = S(b(c, this.rho), b(V(i), 1 - this.rho)), h = b(x(nt(S(l, this.epsilon)), nt(S(c, this.epsilon))), i), d = S(b(l, this.rho), b(V(h), 1 - this.rho));
3397
+ c.assign(u), l.assign(d);
3398
+ const m = S(b(h, -this.learningRate), a);
3399
+ a.assign(m);
3321
3400
  });
3322
3401
  }), this.incrementIterations();
3323
3402
  }
@@ -3367,7 +3446,7 @@ class hs extends q {
3367
3446
  * limitations under the License.
3368
3447
  * =============================================================================
3369
3448
  */
3370
- class fs extends q {
3449
+ class ps extends H {
3371
3450
  /** @nocollapse */
3372
3451
  static get className() {
3373
3452
  return "Adagrad";
@@ -3377,20 +3456,20 @@ class fs extends q {
3377
3456
  }
3378
3457
  applyGradients(t) {
3379
3458
  (Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
3380
- const i = g.registeredVariables[s];
3459
+ const a = g.registeredVariables[s];
3381
3460
  this.accumulatedGrads[r] == null && (this.accumulatedGrads[r] = {
3382
3461
  originalName: `${s}/accumulator`,
3383
- variable: E(() => Yn(i.shape, this.initialAccumulatorValue).variable(!1))
3462
+ variable: E(() => es(a.shape, this.initialAccumulatorValue).variable(!1))
3384
3463
  });
3385
3464
  const o = Array.isArray(t) ? t[r].tensor : t[s];
3386
3465
  if (o == null)
3387
3466
  return;
3388
- const a = this.accumulatedGrads[r].variable;
3467
+ const i = this.accumulatedGrads[r].variable;
3389
3468
  E(() => {
3390
- const c = w(a, z(o));
3391
- a.assign(c);
3392
- const l = w(p(D(o, et(w(c, g.backend.epsilon()))), -this.learningRate), i);
3393
- i.assign(l);
3469
+ const c = S(i, V(o));
3470
+ i.assign(c);
3471
+ const l = S(b(x(o, nt(S(c, g.backend.epsilon()))), -this.learningRate), a);
3472
+ a.assign(l);
3394
3473
  });
3395
3474
  }), this.incrementIterations();
3396
3475
  }
@@ -3432,7 +3511,7 @@ class fs extends q {
3432
3511
  * limitations under the License.
3433
3512
  * =============================================================================
3434
3513
  */
3435
- class ds extends q {
3514
+ class ys extends H {
3436
3515
  /** @nocollapse */
3437
3516
  static get className() {
3438
3517
  return "Adam";
@@ -3445,24 +3524,24 @@ class ds extends q {
3445
3524
  applyGradients(t) {
3446
3525
  const e = Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t);
3447
3526
  E(() => {
3448
- const s = Z(1, this.accBeta1), r = Z(1, this.accBeta2);
3449
- e.forEach((i, o) => {
3450
- const a = g.registeredVariables[i], c = !1;
3527
+ const s = tt(1, this.accBeta1), r = tt(1, this.accBeta2);
3528
+ e.forEach((a, o) => {
3529
+ const i = g.registeredVariables[a], c = !1;
3451
3530
  this.accumulatedFirstMoment[o] == null && (this.accumulatedFirstMoment[o] = {
3452
- originalName: `${i}/m`,
3453
- variable: E(() => C(a).variable(c))
3531
+ originalName: `${a}/m`,
3532
+ variable: E(() => C(i).variable(c))
3454
3533
  }), this.accumulatedSecondMoment[o] == null && (this.accumulatedSecondMoment[o] = {
3455
- originalName: `${i}/v`,
3456
- variable: E(() => C(a).variable(c))
3534
+ originalName: `${a}/v`,
3535
+ variable: E(() => C(i).variable(c))
3457
3536
  });
3458
- const l = Array.isArray(t) ? t[o].tensor : t[i];
3537
+ const l = Array.isArray(t) ? t[o].tensor : t[a];
3459
3538
  if (l == null)
3460
3539
  return;
3461
- const u = this.accumulatedFirstMoment[o].variable, h = this.accumulatedSecondMoment[o].variable, f = w(p(u, this.beta1), p(l, 1 - this.beta1)), m = w(p(h, this.beta2), p(z(l), 1 - this.beta2)), b = D(f, s), d = D(m, r);
3462
- u.assign(f), h.assign(m);
3463
- const k = w(p(D(b, w(et(d), this.epsilon)), -this.learningRate), a);
3464
- a.assign(k);
3465
- }), this.accBeta1.assign(p(this.accBeta1, this.beta1)), this.accBeta2.assign(p(this.accBeta2, this.beta2));
3540
+ const u = this.accumulatedFirstMoment[o].variable, h = this.accumulatedSecondMoment[o].variable, d = S(b(u, this.beta1), b(l, 1 - this.beta1)), m = S(b(h, this.beta2), b(V(l), 1 - this.beta2)), p = x(d, s), f = x(m, r);
3541
+ u.assign(d), h.assign(m);
3542
+ const w = S(b(x(p, S(nt(f), this.epsilon)), -this.learningRate), i);
3543
+ i.assign(w);
3544
+ }), this.accBeta1.assign(b(this.accBeta1, this.beta1)), this.accBeta2.assign(b(this.accBeta2, this.beta2));
3466
3545
  }), this.incrementIterations();
3467
3546
  }
3468
3547
  dispose() {
@@ -3474,7 +3553,7 @@ class ds extends q {
3474
3553
  }
3475
3554
  async setWeights(t) {
3476
3555
  t = await this.extractIterations(t), E(() => {
3477
- this.accBeta1.assign(Yt(this.beta1, this.iterations_ + 1)), this.accBeta2.assign(Yt(this.beta2, this.iterations_ + 1));
3556
+ this.accBeta1.assign(Qt(this.beta1, this.iterations_ + 1)), this.accBeta2.assign(Qt(this.beta2, this.iterations_ + 1));
3478
3557
  });
3479
3558
  const e = t.length / 2, s = !1;
3480
3559
  this.accumulatedFirstMoment = t.slice(0, e).map((r) => ({
@@ -3514,37 +3593,37 @@ class ds extends q {
3514
3593
  * limitations under the License.
3515
3594
  * =============================================================================
3516
3595
  */
3517
- class gs extends q {
3596
+ class bs extends H {
3518
3597
  /** @nocollapse */
3519
3598
  static get className() {
3520
3599
  return "Adamax";
3521
3600
  }
3522
- constructor(t, e, s, r = null, i = 0) {
3523
- super(), this.learningRate = t, this.beta1 = e, this.beta2 = s, this.epsilon = r, this.decay = i, this.accumulatedFirstMoment = [], this.accumulatedWeightedInfNorm = [], E(() => {
3601
+ constructor(t, e, s, r = null, a = 0) {
3602
+ super(), this.learningRate = t, this.beta1 = e, this.beta2 = s, this.epsilon = r, this.decay = a, this.accumulatedFirstMoment = [], this.accumulatedWeightedInfNorm = [], E(() => {
3524
3603
  this.iteration = K(0).variable(), this.accBeta1 = K(e).variable();
3525
3604
  }), r == null && (this.epsilon = g.backend.epsilon());
3526
3605
  }
3527
3606
  applyGradients(t) {
3528
3607
  const e = Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t);
3529
3608
  E(() => {
3530
- const s = Z(1, this.accBeta1), r = D(-this.learningRate, w(p(this.iteration, this.decay), 1));
3531
- e.forEach((i, o) => {
3532
- const a = g.registeredVariables[i], c = !1;
3609
+ const s = tt(1, this.accBeta1), r = x(-this.learningRate, S(b(this.iteration, this.decay), 1));
3610
+ e.forEach((a, o) => {
3611
+ const i = g.registeredVariables[a], c = !1;
3533
3612
  this.accumulatedFirstMoment[o] == null && (this.accumulatedFirstMoment[o] = {
3534
- originalName: `${i}/m`,
3535
- variable: C(a).variable(c)
3613
+ originalName: `${a}/m`,
3614
+ variable: C(i).variable(c)
3536
3615
  }), this.accumulatedWeightedInfNorm[o] == null && (this.accumulatedWeightedInfNorm[o] = {
3537
- originalName: `${i}/v`,
3538
- variable: C(a).variable(c)
3616
+ originalName: `${a}/v`,
3617
+ variable: C(i).variable(c)
3539
3618
  });
3540
- const l = Array.isArray(t) ? t[o].tensor : t[i];
3619
+ const l = Array.isArray(t) ? t[o].tensor : t[a];
3541
3620
  if (l == null)
3542
3621
  return;
3543
- const u = this.accumulatedFirstMoment[o].variable, h = this.accumulatedWeightedInfNorm[o].variable, f = w(p(u, this.beta1), p(l, 1 - this.beta1)), m = p(h, this.beta2), b = Xn(l), d = os(m, b);
3544
- u.assign(f), h.assign(d);
3545
- const k = w(p(D(r, s), D(f, w(d, this.epsilon))), a);
3546
- a.assign(k);
3547
- }), this.iteration.assign(w(this.iteration, 1)), this.accBeta1.assign(p(this.accBeta1, this.beta1));
3622
+ const u = this.accumulatedFirstMoment[o].variable, h = this.accumulatedWeightedInfNorm[o].variable, d = S(b(u, this.beta1), b(l, 1 - this.beta1)), m = b(h, this.beta2), p = ts(l), f = us(m, p);
3623
+ u.assign(d), h.assign(f);
3624
+ const w = S(b(x(r, s), x(d, S(f, this.epsilon))), i);
3625
+ i.assign(w);
3626
+ }), this.iteration.assign(S(this.iteration, 1)), this.accBeta1.assign(b(this.accBeta1, this.beta1));
3548
3627
  }), this.incrementIterations();
3549
3628
  }
3550
3629
  dispose() {
@@ -3586,7 +3665,7 @@ class gs extends q {
3586
3665
  * limitations under the License.
3587
3666
  * =============================================================================
3588
3667
  */
3589
- class Te extends q {
3668
+ class Ee extends H {
3590
3669
  /** @nocollapse */
3591
3670
  static get className() {
3592
3671
  return "SGD";
@@ -3596,13 +3675,13 @@ class Te extends q {
3596
3675
  }
3597
3676
  applyGradients(t) {
3598
3677
  (Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
3599
- const i = Array.isArray(t) ? t[r].tensor : t[s];
3600
- if (i == null)
3678
+ const a = Array.isArray(t) ? t[r].tensor : t[s];
3679
+ if (a == null)
3601
3680
  return;
3602
3681
  const o = g.registeredVariables[s];
3603
3682
  E(() => {
3604
- const a = w(p(this.c, i), o);
3605
- o.assign(a);
3683
+ const i = S(b(this.c, a), o);
3684
+ o.assign(i);
3606
3685
  });
3607
3686
  }), this.incrementIterations();
3608
3687
  }
@@ -3610,7 +3689,7 @@ class Te extends q {
3610
3689
  * Sets the learning rate of the optimizer.
3611
3690
  */
3612
3691
  setLearningRate(t) {
3613
- this.learningRate = t, this.c != null && this.c.dispose(), this.c = kn(K(-t));
3692
+ this.learningRate = t, this.c != null && this.c.dispose(), this.c = En(K(-t));
3614
3693
  }
3615
3694
  dispose() {
3616
3695
  this.c.dispose();
@@ -3646,7 +3725,7 @@ class Te extends q {
3646
3725
  * limitations under the License.
3647
3726
  * =============================================================================
3648
3727
  */
3649
- class ms extends Te {
3728
+ class ws extends Ee {
3650
3729
  /** @nocollapse */
3651
3730
  // Name matters for Python compatibility.
3652
3731
  static get className() {
@@ -3657,16 +3736,16 @@ class ms extends Te {
3657
3736
  }
3658
3737
  applyGradients(t) {
3659
3738
  (Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
3660
- const i = g.registeredVariables[s];
3739
+ const a = g.registeredVariables[s];
3661
3740
  this.accumulations[r] == null && (this.accumulations[r] = {
3662
3741
  originalName: `${s}/momentum`,
3663
- variable: E(() => C(i).variable(!1))
3742
+ variable: E(() => C(a).variable(!1))
3664
3743
  });
3665
- const o = this.accumulations[r].variable, a = Array.isArray(t) ? t[r].tensor : t[s];
3666
- a != null && E(() => {
3744
+ const o = this.accumulations[r].variable, i = Array.isArray(t) ? t[r].tensor : t[s];
3745
+ i != null && E(() => {
3667
3746
  let c;
3668
- const l = w(p(this.m, o), a);
3669
- this.useNesterov ? c = w(p(this.c, w(a, p(l, this.m))), i) : c = w(p(this.c, l), i), o.assign(l), i.assign(c);
3747
+ const l = S(b(this.m, o), i);
3748
+ this.useNesterov ? c = S(b(this.c, S(i, b(l, this.m))), a) : c = S(b(this.c, l), a), o.assign(l), a.assign(c);
3670
3749
  });
3671
3750
  }), this.incrementIterations();
3672
3751
  }
@@ -3717,44 +3796,44 @@ class ms extends Te {
3717
3796
  * limitations under the License.
3718
3797
  * =============================================================================
3719
3798
  */
3720
- class ps extends q {
3799
+ class Ss extends H {
3721
3800
  /** @nocollapse */
3722
3801
  static get className() {
3723
3802
  return "RMSProp";
3724
3803
  }
3725
- constructor(t, e = 0.9, s = 0, r = null, i = !1) {
3726
- if (super(), this.learningRate = t, this.decay = e, this.momentum = s, this.epsilon = r, this.accumulatedMeanSquares = [], this.accumulatedMoments = [], this.accumulatedMeanGrads = [], this.centered = i, r == null && (this.epsilon = g.backend.epsilon()), t == null)
3804
+ constructor(t, e = 0.9, s = 0, r = null, a = !1) {
3805
+ if (super(), this.learningRate = t, this.decay = e, this.momentum = s, this.epsilon = r, this.accumulatedMeanSquares = [], this.accumulatedMoments = [], this.accumulatedMeanGrads = [], this.centered = a, r == null && (this.epsilon = g.backend.epsilon()), t == null)
3727
3806
  throw new Error("learningRate for RMSPropOptimizer must be defined.");
3728
3807
  }
3729
3808
  applyGradients(t) {
3730
3809
  (Array.isArray(t) ? t.map((s) => s.name) : Object.keys(t)).forEach((s, r) => {
3731
- const i = g.registeredVariables[s], o = !1;
3810
+ const a = g.registeredVariables[s], o = !1;
3732
3811
  this.accumulatedMeanSquares[r] == null && (this.accumulatedMeanSquares[r] = {
3733
3812
  originalName: `${s}/rms`,
3734
- variable: E(() => C(i).variable(o))
3813
+ variable: E(() => C(a).variable(o))
3735
3814
  }), this.accumulatedMoments[r] == null && (this.accumulatedMoments[r] = {
3736
3815
  originalName: `${s}/momentum`,
3737
- variable: E(() => C(i).variable(o))
3816
+ variable: E(() => C(a).variable(o))
3738
3817
  }), this.accumulatedMeanGrads[r] == null && this.centered && (this.accumulatedMeanGrads[r] = {
3739
3818
  originalName: `${s}/mg`,
3740
- variable: E(() => C(i).variable(o))
3819
+ variable: E(() => C(a).variable(o))
3741
3820
  });
3742
- const a = Array.isArray(t) ? t[r].tensor : t[s];
3743
- if (a == null)
3821
+ const i = Array.isArray(t) ? t[r].tensor : t[s];
3822
+ if (i == null)
3744
3823
  return;
3745
3824
  const c = this.accumulatedMeanSquares[r].variable, l = this.accumulatedMoments[r].variable;
3746
3825
  E(() => {
3747
- const u = w(p(c, this.decay), p(z(a), 1 - this.decay));
3826
+ const u = S(b(c, this.decay), b(V(i), 1 - this.decay));
3748
3827
  if (this.centered) {
3749
- const h = this.accumulatedMeanGrads[r].variable, f = w(p(h, this.decay), p(a, 1 - this.decay)), m = D(p(a, this.learningRate), et(Z(u, w(z(f), this.epsilon)))), b = w(p(l, this.momentum), m);
3750
- c.assign(u), h.assign(f), l.assign(b);
3751
- const d = Z(i, b);
3752
- i.assign(d);
3828
+ const h = this.accumulatedMeanGrads[r].variable, d = S(b(h, this.decay), b(i, 1 - this.decay)), m = x(b(i, this.learningRate), nt(tt(u, S(V(d), this.epsilon)))), p = S(b(l, this.momentum), m);
3829
+ c.assign(u), h.assign(d), l.assign(p);
3830
+ const f = tt(a, p);
3831
+ a.assign(f);
3753
3832
  } else {
3754
- const h = w(p(c, this.decay), p(z(a), 1 - this.decay)), f = w(p(l, this.momentum), D(p(a, this.learningRate), et(w(h, this.epsilon))));
3755
- c.assign(h), l.assign(f);
3756
- const m = Z(i, f);
3757
- i.assign(m);
3833
+ const h = S(b(c, this.decay), b(V(i), 1 - this.decay)), d = S(b(l, this.momentum), x(b(i, this.learningRate), nt(S(h, this.epsilon))));
3834
+ c.assign(h), l.assign(d);
3835
+ const m = tt(a, d);
3836
+ a.assign(m);
3758
3837
  }
3759
3838
  });
3760
3839
  }), this.incrementIterations();
@@ -3810,18 +3889,18 @@ class ps extends q {
3810
3889
  * limitations under the License.
3811
3890
  * =============================================================================
3812
3891
  */
3813
- const ys = [
3814
- hs,
3815
- fs,
3816
- ds,
3817
- gs,
3892
+ const ks = [
3818
3893
  ms,
3819
3894
  ps,
3820
- Te
3895
+ ys,
3896
+ bs,
3897
+ ws,
3898
+ Ss,
3899
+ Ee
3821
3900
  ];
3822
- function bs() {
3823
- for (const n of ys)
3824
- us(n);
3901
+ function Is() {
3902
+ for (const n of ks)
3903
+ gs(n);
3825
3904
  }
3826
3905
  /**
3827
3906
  * @license
@@ -3839,61 +3918,220 @@ function bs() {
3839
3918
  * limitations under the License.
3840
3919
  * =============================================================================
3841
3920
  */
3842
- bs();
3921
+ Is();
3843
3922
  export {
3844
- Qn as $,
3845
- ds as A,
3846
- Es as B,
3847
- As as C,
3848
- w as D,
3923
+ Ur as $,
3924
+ ys as A,
3925
+ Ks as B,
3926
+ Zs as C,
3927
+ Sn as D,
3849
3928
  g as E,
3850
- qs as F,
3851
- $s as G,
3852
- sr as H,
3853
- E as I,
3854
- C as J,
3855
- js as K,
3856
- Ns as L,
3857
- Ds as M,
3858
- vs as N,
3859
- Rs as O,
3860
- _s as P,
3861
- xs as Q,
3862
- Gs as R,
3863
- Ks as S,
3864
- Cs as T,
3865
- Ps as U,
3866
- Ls as V,
3867
- Us as W,
3868
- zs as X,
3869
- Js as Y,
3870
- Hs as Z,
3871
- nr as _,
3872
- p as a,
3873
- Xs as a0,
3874
- Z as b,
3875
- Qs as c,
3876
- I as d,
3877
- tr as e,
3878
- V as f,
3879
- Is as g,
3880
- $t as h,
3881
- Vs as i,
3882
- Os as j,
3883
- Zs as k,
3884
- y as l,
3885
- er as m,
3886
- Gn as n,
3887
- F as o,
3888
- Bs as p,
3889
- Fs as q,
3890
- Ys as r,
3891
- K as s,
3892
- Dt as t,
3893
- Zt as u,
3894
- G as v,
3895
- De as w,
3896
- Ws as x,
3929
+ In as F,
3930
+ Nr as G,
3931
+ Rr as H,
3932
+ ya as I,
3933
+ Qt as J,
3934
+ or as K,
3935
+ Da as L,
3936
+ vs as M,
3937
+ Qs as N,
3938
+ te as O,
3939
+ ha as P,
3940
+ Ma as Q,
3941
+ ma as R,
3942
+ _a as S,
3943
+ qr as T,
3944
+ Rt as U,
3945
+ La as V,
3946
+ na as W,
3947
+ sa as X,
3948
+ Ka as Y,
3949
+ S as Z,
3950
+ Tr as _,
3951
+ M as a,
3952
+ Oa as a$,
3953
+ Re as a0,
3954
+ Ua as a1,
3955
+ Zr as a2,
3956
+ ts as a3,
3957
+ nt as a4,
3958
+ V as a5,
3959
+ Qr as a6,
3960
+ R as a7,
3961
+ D as a8,
3962
+ k as a9,
3963
+ ns as aA,
3964
+ Ir as aB,
3965
+ Na as aC,
3966
+ br as aD,
3967
+ wr as aE,
3968
+ kr as aF,
3969
+ Er as aG,
3970
+ zn as aH,
3971
+ vr as aI,
3972
+ Fr as aJ,
3973
+ Dr as aK,
3974
+ $r as aL,
3975
+ Lr as aM,
3976
+ Or as aN,
3977
+ _r as aO,
3978
+ Gr as aP,
3979
+ ra as aQ,
3980
+ Pa as aR,
3981
+ zr as aS,
3982
+ Vr as aT,
3983
+ Hr as aU,
3984
+ Xr as aV,
3985
+ ta as aW,
3986
+ aa as aX,
3987
+ ua as aY,
3988
+ la as aZ,
3989
+ da as a_,
3990
+ fe as aa,
3991
+ so as ab,
3992
+ dt as ac,
3993
+ $s as ad,
3994
+ xs as ae,
3995
+ Cs as af,
3996
+ Ne as ag,
3997
+ zs as ah,
3998
+ Ws as ai,
3999
+ Ca as aj,
4000
+ Fa as ak,
4001
+ Wa as al,
4002
+ qs as am,
4003
+ Mr as an,
4004
+ Hs as ao,
4005
+ ja as ap,
4006
+ Ys as aq,
4007
+ tr as ar,
4008
+ nr as as,
4009
+ sr as at,
4010
+ ar as au,
4011
+ ir as av,
4012
+ cr as aw,
4013
+ lr as ax,
4014
+ hr as ay,
4015
+ dr as az,
4016
+ b,
4017
+ Ar as b$,
4018
+ fa as b0,
4019
+ pa as b1,
4020
+ ba as b2,
4021
+ Ea as b3,
4022
+ Aa as b4,
4023
+ Ba as b5,
4024
+ va as b6,
4025
+ Ra as b7,
4026
+ $a as b8,
4027
+ Ns as b9,
4028
+ ps as bA,
4029
+ co as bB,
4030
+ gs as bC,
4031
+ fs as bD,
4032
+ U as bE,
4033
+ We as bF,
4034
+ Rs as bG,
4035
+ Fs as bH,
4036
+ se as bI,
4037
+ Ds as bJ,
4038
+ Ps as bK,
4039
+ Ls as bL,
4040
+ Os as bM,
4041
+ Gs as bN,
4042
+ _s as bO,
4043
+ Us as bP,
4044
+ js as bQ,
4045
+ Vs as bR,
4046
+ Js as bS,
4047
+ re as bT,
4048
+ Xs as bU,
4049
+ je as bV,
4050
+ rr as bW,
4051
+ mr as bX,
4052
+ yr as bY,
4053
+ pr as bZ,
4054
+ Sr as b_,
4055
+ Ya as ba,
4056
+ Xa as bb,
4057
+ Ja as bc,
4058
+ Ha as bd,
4059
+ Ft as be,
4060
+ x as bf,
4061
+ er as bg,
4062
+ fo as bh,
4063
+ to as bi,
4064
+ fr as bj,
4065
+ gr as bk,
4066
+ Za as bl,
4067
+ ur as bm,
4068
+ Br as bn,
4069
+ Qa as bo,
4070
+ oa as bp,
4071
+ ca as bq,
4072
+ ia as br,
4073
+ Ia as bs,
4074
+ Sa as bt,
4075
+ qa as bu,
4076
+ Ee as bv,
4077
+ ws as bw,
4078
+ Ss as bx,
4079
+ ms as by,
4080
+ bs as bz,
4081
+ go as c,
4082
+ He as c0,
4083
+ ae as c1,
4084
+ xr as c2,
4085
+ Cr as c3,
4086
+ Pr as c4,
4087
+ Wr as c5,
4088
+ Kr as c6,
4089
+ jr as c7,
4090
+ Je as c8,
4091
+ Yr as c9,
4092
+ Jr as ca,
4093
+ ea as cb,
4094
+ Xe as cc,
4095
+ Ye as cd,
4096
+ ga as ce,
4097
+ Ke as cf,
4098
+ Ta as cg,
4099
+ ka as ch,
4100
+ xa as ci,
4101
+ Qe as cj,
4102
+ za as ck,
4103
+ Ga as cl,
4104
+ Ze as cm,
4105
+ Va as cn,
4106
+ us as co,
4107
+ tn as cp,
4108
+ Pe as cq,
4109
+ H as cr,
4110
+ Bs as cs,
4111
+ ho as ct,
4112
+ lo as cu,
4113
+ uo as cv,
4114
+ ao as d,
4115
+ oo as e,
4116
+ K as f,
4117
+ no as g,
4118
+ T as h,
4119
+ ro as i,
4120
+ y as j,
4121
+ xt as k,
4122
+ Le as l,
4123
+ io as m,
4124
+ z as n,
4125
+ N as o,
4126
+ q as p,
4127
+ wa as q,
4128
+ eo as r,
4129
+ tt as s,
4130
+ E as t,
4131
+ jn as u,
4132
+ is as v,
4133
+ es as w,
4134
+ En as x,
3897
4135
  Ms as y,
3898
- Ts as z
4136
+ C as z
3899
4137
  };