@genai-fi/nanogpt 0.3.2 → 0.4.1

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 (98) hide show
  1. package/dist/Generator.js +22 -22
  2. package/dist/MLP-KHhikThU.js +83 -0
  3. package/dist/NanoGPTModel.d.ts +2 -3
  4. package/dist/NanoGPTModel.js +79 -79
  5. package/dist/TeachableLLM.js +16 -13
  6. package/dist/axis_util-DeydwOoC.js +69 -0
  7. package/dist/{concat-BIZS_td9.js → concat-DS_qH7MI.js} +5 -5
  8. package/dist/config.js +7 -8
  9. package/dist/{gather-BPGW8RsB.js → gather-BUmJIS8n.js} +1 -1
  10. package/dist/{index-pWA4_lUh.js → index-XjBAhiFO.js} +1272 -1174
  11. package/dist/layers/BaseLayer.d.ts +14 -2
  12. package/dist/layers/BaseLayer.js +9 -9
  13. package/dist/layers/CausalSelfAttention.d.ts +4 -8
  14. package/dist/layers/CausalSelfAttention.js +106 -80
  15. package/dist/layers/MLP.d.ts +2 -3
  16. package/dist/layers/MLP.js +5 -62
  17. package/dist/layers/RMSNorm.d.ts +2 -2
  18. package/dist/layers/RMSNorm.js +11 -11
  19. package/dist/layers/RoPECache.js +3 -3
  20. package/dist/layers/TiedEmbedding.js +7 -6
  21. package/dist/layers/TransformerBlock.d.ts +2 -6
  22. package/dist/layers/TransformerBlock.js +9 -12
  23. package/dist/{sum-C7Mgy9Bw.js → log_sum_exp-DJPkVZZn.js} +32 -54
  24. package/dist/main.js +22 -19
  25. package/dist/{mat_mul-D7_a4KJn.js → mat_mul-CKwFEV1Q.js} +1 -1
  26. package/dist/max-DJvEiCAJ.js +25 -0
  27. package/dist/moments-CrWRPcR3.js +53 -0
  28. package/dist/norm-BzY929B_.js +86 -0
  29. package/dist/{ones-Cog-G2ag.js → ones-BO01zpJG.js} +2 -2
  30. package/dist/ops/appendCache.js +1 -1
  31. package/dist/ops/attentionMask.js +1 -1
  32. package/dist/ops/cpu/appendCache.js +2 -2
  33. package/dist/ops/cpu/attentionMask.js +2 -2
  34. package/dist/ops/cpu/fusedSoftmax.d.ts +9 -0
  35. package/dist/ops/cpu/fusedSoftmax.js +23 -0
  36. package/dist/ops/cpu/gatherSub.js +3 -3
  37. package/dist/ops/cpu/mulDropout.d.ts +1 -0
  38. package/dist/ops/cpu/mulDropout.js +17 -0
  39. package/dist/ops/cpu/qkv.js +3 -3
  40. package/dist/ops/cpu/rope.js +5 -5
  41. package/dist/ops/cpu/scatterSub.js +27 -27
  42. package/dist/ops/fusedSoftmax.d.ts +2 -0
  43. package/dist/ops/fusedSoftmax.js +10 -0
  44. package/dist/ops/gatherSub.js +1 -1
  45. package/dist/ops/grads/attentionMask.js +1 -1
  46. package/dist/ops/grads/fusedSoftmax.d.ts +2 -0
  47. package/dist/ops/grads/fusedSoftmax.js +17 -0
  48. package/dist/ops/grads/qkv.js +1 -1
  49. package/dist/ops/grads/rope.js +1 -1
  50. package/dist/ops/mulDrop.d.ts +2 -0
  51. package/dist/ops/mulDrop.js +9 -0
  52. package/dist/ops/node/sparseCrossEntropy.js +1 -1
  53. package/dist/ops/qkv.js +1 -1
  54. package/dist/ops/scatterSub.js +1 -1
  55. package/dist/ops/webgl/appendCache.js +1 -1
  56. package/dist/ops/webgl/attentionMask.js +1 -1
  57. package/dist/ops/webgl/fusedSoftmax.d.ts +11 -0
  58. package/dist/ops/webgl/fusedSoftmax.js +3930 -0
  59. package/dist/ops/webgl/gatherSub.js +1 -1
  60. package/dist/ops/webgl/mulDropout.d.ts +1 -0
  61. package/dist/ops/webgl/mulDropout.js +41 -0
  62. package/dist/ops/webgl/qkv.js +1 -1
  63. package/dist/ops/webgl/rope.js +1 -1
  64. package/dist/ops/webgl/scatterSub.js +1 -1
  65. package/dist/{random_width-oeUIlUZj.js → random_width-CMHmdbSu.js} +4212 -6630
  66. package/dist/{range-CcDl05lo.js → range-DQMNzBWs.js} +1 -1
  67. package/dist/{reshape-C8CR_Bad.js → reshape-DFzh97Sc.js} +1 -1
  68. package/dist/{sin-BJIrfnj7.js → sin-BYM-U4Ut.js} +1 -1
  69. package/dist/slice_util-CnVNPQI-.js +90 -0
  70. package/dist/softmax-4DOn6cPq.js +28 -0
  71. package/dist/{split-DZbvruEP.js → split-CkbeVdF8.js} +3 -3
  72. package/dist/{stack-BMm-efee.js → stack-DaIMO5iX.js} +1 -1
  73. package/dist/sum-C6u3xMi3.js +27 -0
  74. package/dist/{tensor-DJVbYhh1.js → tensor-Cu1fU7H7.js} +1 -1
  75. package/dist/{tensor2d-ZuQSh2D-.js → tensor2d-D0CKdG6B.js} +1 -1
  76. package/dist/tfjs_backend-Bzl2SrRo.js +2460 -0
  77. package/dist/training/AdamExt.js +1 -1
  78. package/dist/training/DatasetBuilder.js +3 -3
  79. package/dist/training/FullTrainer.js +1 -1
  80. package/dist/training/Trainer.js +13 -12
  81. package/dist/training/sparseCrossEntropy.js +12 -11
  82. package/dist/utilities/dummy.js +8 -8
  83. package/dist/utilities/generate.js +11 -11
  84. package/dist/utilities/load.js +1 -1
  85. package/dist/utilities/profile.js +1 -1
  86. package/dist/utilities/weights.js +2 -2
  87. package/dist/{variable-Dl_ub3pk.js → variable-BS4AKqNU.js} +1 -1
  88. package/dist/{zeros-CCy9C3uU.js → zeros-CmJFiC84.js} +1 -1
  89. package/package.json +1 -1
  90. package/dist/exports_layers-tbTBcwMM.js +0 -25
  91. package/dist/layers/LayerNorm.d.ts +0 -13
  92. package/dist/layers/LayerNorm.js +0 -33
  93. package/dist/moments-DfcpfwKi.js +0 -132
  94. package/dist/softmax-Be_lsqUc.js +0 -105
  95. package/dist/training/LayerTrainer.d.ts +0 -29
  96. package/dist/training/LayerTrainer.js +0 -95
  97. package/dist/training/lwSchedule.d.ts +0 -7
  98. package/dist/training/lwSchedule.js +0 -162
@@ -0,0 +1,2460 @@
1
+ import { o as p, h as l, E as d, af as oe, ag as ae, j as f, ah as ie, D as Cn, ai as ce, aj as v, ak as ue, al as le, am as fe, an as pe, a1 as he, ao as In, ap as de, p as Y, aq as me, ar as ge, as as $e, at as be, au as ke, av as xe, aw as we, ax as ye, x as L, ay as _e, az as Ae, k as zn, aA as Ie, aB as Ee, aC as Te, aD as Se, aE as Ne, aF as De, I as Me, J as Oe, K as Ve, aG as ve, t as P, aH as dn, aI as Pe, aa as Be, aJ as K, a5 as C, b as A, aK as Re, n as Vn, c as vn, aL as Pn, aM as Ke, aN as qe, aO as Fe, aP as je, aQ as Ge, aR as Le, f as Ce, aS as ze, aT as Ue, s as R, aU as Je, w as mn, a as We, ae as Bn, aV as Ye, $ as Xe } from "./index-XjBAhiFO.js";
2
+ import { r as $ } from "./reshape-DFzh97Sc.js";
3
+ import { s as Un } from "./split-CkbeVdF8.js";
4
+ import { s as j } from "./sum-C6u3xMi3.js";
5
+ import { b as gn } from "./slice_util-CnVNPQI-.js";
6
+ import { r as ln } from "./range-DQMNzBWs.js";
7
+ import { t as Ze } from "./tensor-Cu1fU7H7.js";
8
+ import { s as fn } from "./stack-DaIMO5iX.js";
9
+ import { c as He, z as Qe } from "./zeros-CmJFiC84.js";
10
+ import { n as Jn } from "./norm-BzY929B_.js";
11
+ import { c as G } from "./concat-DS_qH7MI.js";
12
+ import { m as _ } from "./mat_mul-CKwFEV1Q.js";
13
+ import { t as $n } from "./tensor2d-D0CKdG6B.js";
14
+ import { s as Wn } from "./index-C4L8Cm77.js";
15
+ import { g as nt } from "./gather-BUmJIS8n.js";
16
+ /**
17
+ * @license
18
+ * Copyright 2018 Google LLC. All Rights Reserved.
19
+ * Licensed under the Apache License, Version 2.0 (the "License");
20
+ * you may not use this file except in compliance with the License.
21
+ * You may obtain a copy of the License at
22
+ *
23
+ * http://www.apache.org/licenses/LICENSE-2.0
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ * =============================================================================
31
+ */
32
+ function et(n) {
33
+ const t = { x: l(n, "x", "sigmoid", "float32") };
34
+ return d.runKernel(oe, t);
35
+ }
36
+ const tt = /* @__PURE__ */ p({ sigmoid_: et });
37
+ /**
38
+ * @license
39
+ * Copyright 2018 Google LLC. All Rights Reserved.
40
+ * Licensed under the Apache License, Version 2.0 (the "License");
41
+ * you may not use this file except in compliance with the License.
42
+ * You may obtain a copy of the License at
43
+ *
44
+ * http://www.apache.org/licenses/LICENSE-2.0
45
+ *
46
+ * Unless required by applicable law or agreed to in writing, software
47
+ * distributed under the License is distributed on an "AS IS" BASIS,
48
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49
+ * See the License for the specific language governing permissions and
50
+ * limitations under the License.
51
+ * =============================================================================
52
+ */
53
+ function st(n, e, t) {
54
+ const s = l(n, "x", "slice", "string_or_numeric");
55
+ if (s.rank === 0)
56
+ throw new Error("Slicing scalar is not possible");
57
+ const r = { x: s }, o = { begin: e, size: t };
58
+ return d.runKernel(ae, r, o);
59
+ }
60
+ const I = /* @__PURE__ */ p({ slice_: st });
61
+ /**
62
+ * @license
63
+ * Copyright 2020 Google LLC. All Rights Reserved.
64
+ * Licensed under the Apache License, Version 2.0 (the "License");
65
+ * you may not use this file except in compliance with the License.
66
+ * You may obtain a copy of the License at
67
+ *
68
+ * http://www.apache.org/licenses/LICENSE-2.0
69
+ *
70
+ * Unless required by applicable law or agreed to in writing, software
71
+ * distributed under the License is distributed on an "AS IS" BASIS,
72
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
73
+ * See the License for the specific language governing permissions and
74
+ * limitations under the License.
75
+ * =============================================================================
76
+ */
77
+ function rt(n, e, t) {
78
+ const s = l(n, "x", "bincount"), r = l(e, "weights", "bincount");
79
+ f(s.dtype === "int32", () => `Error in bincount: input dtype must be int32, but got ${s.dtype}`), f(t >= 0, () => `size must be non-negative, but got ${t}.`), f(r.size === s.size || r.size === 0, () => `Error in bincount: weights must have the same size as input or0-length, but got input shape: ${s.shape}, weights shape: ${r.shape}.`);
80
+ const o = { x: s, weights: r }, a = { size: t };
81
+ return d.runKernel(ie, o, a);
82
+ }
83
+ const ot = /* @__PURE__ */ p({ bincount_: rt });
84
+ /**
85
+ * @license
86
+ * Copyright 2018 Google LLC. All Rights Reserved.
87
+ * Licensed under the Apache License, Version 2.0 (the "License");
88
+ * you may not use this file except in compliance with the License.
89
+ * You may obtain a copy of the License at
90
+ *
91
+ * http://www.apache.org/licenses/LICENSE-2.0
92
+ *
93
+ * Unless required by applicable law or agreed to in writing, software
94
+ * distributed under the License is distributed on an "AS IS" BASIS,
95
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96
+ * See the License for the specific language governing permissions and
97
+ * limitations under the License.
98
+ * =============================================================================
99
+ */
100
+ function at(n, e, t) {
101
+ const s = l(n, "x", "clipByValue");
102
+ if (f(e <= t, () => `Error in clip: min (${e}) must be less than or equal to max (${t}).`), e === t)
103
+ return Cn(s.shape, e, s.dtype);
104
+ const r = { x: s }, o = { clipValueMin: e, clipValueMax: t };
105
+ return d.runKernel(ce, r, o);
106
+ }
107
+ const it = /* @__PURE__ */ p({ clipByValue_: at });
108
+ function ct(n) {
109
+ return G(
110
+ n,
111
+ 0
112
+ /* axis */
113
+ );
114
+ }
115
+ const ut = /* @__PURE__ */ p({ concat1d_: ct });
116
+ function lt(n, e) {
117
+ return G(n, e);
118
+ }
119
+ const ft = /* @__PURE__ */ p({ concat2d_: lt });
120
+ function pt(n, e) {
121
+ return G(n, e);
122
+ }
123
+ const ht = /* @__PURE__ */ p({ concat3d_: pt });
124
+ function dt(n, e) {
125
+ return G(n, e);
126
+ }
127
+ const mt = /* @__PURE__ */ p({ concat4d_: dt });
128
+ /**
129
+ * @license
130
+ * Copyright 2020 Google LLC. All Rights Reserved.
131
+ * Licensed under the Apache License, Version 2.0 (the "License");
132
+ * you may not use this file except in compliance with the License.
133
+ * You may obtain a copy of the License at
134
+ *
135
+ * http://www.apache.org/licenses/LICENSE-2.0
136
+ *
137
+ * Unless required by applicable law or agreed to in writing, software
138
+ * distributed under the License is distributed on an "AS IS" BASIS,
139
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140
+ * See the License for the specific language governing permissions and
141
+ * limitations under the License.
142
+ * =============================================================================
143
+ */
144
+ function gt(n, e, t) {
145
+ const s = l(e, "a", "where"), r = l(t, "b", "where"), o = l(n, "condition", "where", "bool"), a = v(v(o.shape, s.shape), r.shape), i = gn(o, a), u = gn(s, a), c = gn(r, a), m = {
146
+ condition: i,
147
+ t: u,
148
+ e: c
149
+ };
150
+ return d.runKernel(ue, m);
151
+ }
152
+ const nn = /* @__PURE__ */ p({ where_: gt });
153
+ /**
154
+ * @license
155
+ * Copyright 2021 Google LLC. All Rights Reserved.
156
+ * Licensed under the Apache License, Version 2.0 (the "License");
157
+ * you may not use this file except in compliance with the License.
158
+ * You may obtain a copy of the License at
159
+ *
160
+ * http://www.apache.org/licenses/LICENSE-2.0
161
+ *
162
+ * Unless required by applicable law or agreed to in writing, software
163
+ * distributed under the License is distributed on an "AS IS" BASIS,
164
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
165
+ * See the License for the specific language governing permissions and
166
+ * limitations under the License.
167
+ * =============================================================================
168
+ */
169
+ function $t(n, ...e) {
170
+ const t = e.map((r, o) => l(r, `tensors${o}`, "einsum")), s = { equation: n };
171
+ return d.runKernel(le, t, s);
172
+ }
173
+ const rn = /* @__PURE__ */ p({ einsum_: $t });
174
+ /**
175
+ * @license
176
+ * Copyright 2020 Google LLC. All Rights Reserved.
177
+ * Licensed under the Apache License, Version 2.0 (the "License");
178
+ * you may not use this file except in compliance with the License.
179
+ * You may obtain a copy of the License at
180
+ *
181
+ * http://www.apache.org/licenses/LICENSE-2.0
182
+ *
183
+ * Unless required by applicable law or agreed to in writing, software
184
+ * distributed under the License is distributed on an "AS IS" BASIS,
185
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
186
+ * See the License for the specific language governing permissions and
187
+ * limitations under the License.
188
+ * =============================================================================
189
+ */
190
+ function bt(n) {
191
+ const t = { x: l(n, "x", "elu", "float32") };
192
+ return d.runKernel(fe, t);
193
+ }
194
+ const Yn = /* @__PURE__ */ p({ elu_: bt });
195
+ /**
196
+ * @license
197
+ * Copyright 2020 Google LLC. All Rights Reserved.
198
+ * Licensed under the Apache License, Version 2.0 (the "License");
199
+ * you may not use this file except in compliance with the License.
200
+ * You may obtain a copy of the License at
201
+ *
202
+ * http://www.apache.org/licenses/LICENSE-2.0
203
+ *
204
+ * Unless required by applicable law or agreed to in writing, software
205
+ * distributed under the License is distributed on an "AS IS" BASIS,
206
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
207
+ * See the License for the specific language governing permissions and
208
+ * limitations under the License.
209
+ * =============================================================================
210
+ */
211
+ function kt(n, e = 0) {
212
+ const t = l(n, "x", "expandDims", "string_or_numeric");
213
+ f(e <= t.rank, () => "Axis must be <= rank of the tensor");
214
+ const s = { input: t }, r = { dim: e };
215
+ return d.runKernel(pe, s, r);
216
+ }
217
+ const W = /* @__PURE__ */ p({ expandDims_: kt });
218
+ /**
219
+ * @license
220
+ * Copyright 2020 Google LLC. All Rights Reserved.
221
+ * Licensed under the Apache License, Version 2.0 (the "License");
222
+ * you may not use this file except in compliance with the License.
223
+ * You may obtain a copy of the License at
224
+ *
225
+ * http://www.apache.org/licenses/LICENSE-2.0
226
+ *
227
+ * Unless required by applicable law or agreed to in writing, software
228
+ * distributed under the License is distributed on an "AS IS" BASIS,
229
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
230
+ * See the License for the specific language governing permissions and
231
+ * limitations under the License.
232
+ * =============================================================================
233
+ */
234
+ function xt(n, e) {
235
+ const t = l(n, "x", "tile", "string_or_numeric");
236
+ f(t.rank === e.length, () => `Error in transpose: rank of input ${t.rank} must match length of reps ${e}.`);
237
+ const s = { x: t }, r = { reps: e };
238
+ return d.runKernel(he, s, r);
239
+ }
240
+ const on = /* @__PURE__ */ p({ tile_: xt });
241
+ /**
242
+ * @license
243
+ * Copyright 2020 Google LLC. All Rights Reserved.
244
+ * Licensed under the Apache License, Version 2.0 (the "License");
245
+ * you may not use this file except in compliance with the License.
246
+ * You may obtain a copy of the License at
247
+ *
248
+ * http://www.apache.org/licenses/LICENSE-2.0
249
+ *
250
+ * Unless required by applicable law or agreed to in writing, software
251
+ * distributed under the License is distributed on an "AS IS" BASIS,
252
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
253
+ * See the License for the specific language governing permissions and
254
+ * limitations under the License.
255
+ * =============================================================================
256
+ */
257
+ function wt(n, e, t, s = "float32") {
258
+ e == null && (e = n);
259
+ const r = In([n, e], s), o = n <= e ? n : e;
260
+ for (let i = 0; i < o; ++i)
261
+ r.set(1, i, i);
262
+ const a = $(r.toTensor(), [n, e]);
263
+ if (t == null)
264
+ return a;
265
+ if (t.length === 1)
266
+ return on(W(a, 0), [t[0], 1, 1]);
267
+ if (t.length === 2)
268
+ return on(W(W(a, 0), 0), [t[0], t[1], 1, 1]);
269
+ if (t.length === 3)
270
+ return on(W(W(W(a, 0), 0), 0), [
271
+ t[0],
272
+ t[1],
273
+ t[2],
274
+ 1,
275
+ 1
276
+ ]);
277
+ throw new Error(`eye() currently supports only 1D and 2D batchShapes, but received ${t.length}D.`);
278
+ }
279
+ const yt = /* @__PURE__ */ p({ eye_: wt });
280
+ /**
281
+ * @license
282
+ * Copyright 2018 Google LLC. All Rights Reserved.
283
+ * Licensed under the Apache License, Version 2.0 (the "License");
284
+ * you may not use this file except in compliance with the License.
285
+ * You may obtain a copy of the License at
286
+ *
287
+ * http://www.apache.org/licenses/LICENSE-2.0
288
+ *
289
+ * Unless required by applicable law or agreed to in writing, software
290
+ * distributed under the License is distributed on an "AS IS" BASIS,
291
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
292
+ * See the License for the specific language governing permissions and
293
+ * limitations under the License.
294
+ * =============================================================================
295
+ */
296
+ function _t(n) {
297
+ const t = { x: l(n, "x", "floor", "float32") };
298
+ return d.runKernel(de, t);
299
+ }
300
+ const At = /* @__PURE__ */ p({ floor_: _t });
301
+ /**
302
+ * @license
303
+ * Copyright 2020 Google LLC. All Rights Reserved.
304
+ * Licensed under the Apache License, Version 2.0 (the "License");
305
+ * you may not use this file except in compliance with the License.
306
+ * You may obtain a copy of the License at
307
+ *
308
+ * http://www.apache.org/licenses/LICENSE-2.0
309
+ *
310
+ * Unless required by applicable law or agreed to in writing, software
311
+ * distributed under the License is distributed on an "AS IS" BASIS,
312
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
313
+ * See the License for the specific language governing permissions and
314
+ * limitations under the License.
315
+ * =============================================================================
316
+ */
317
+ function It(n, e) {
318
+ let t = l(n, "a", "greater", "string_or_numeric"), s = l(e, "b", "greater", "string_or_numeric");
319
+ [t, s] = Y(t, s), v(t.shape, s.shape);
320
+ const r = { a: t, b: s };
321
+ return d.runKernel(me, r);
322
+ }
323
+ const En = /* @__PURE__ */ p({ greater_: It });
324
+ /**
325
+ * @license
326
+ * Copyright 2020 Google LLC. All Rights Reserved.
327
+ * Licensed under the Apache License, Version 2.0 (the "License");
328
+ * you may not use this file except in compliance with the License.
329
+ * You may obtain a copy of the License at
330
+ *
331
+ * http://www.apache.org/licenses/LICENSE-2.0
332
+ *
333
+ * Unless required by applicable law or agreed to in writing, software
334
+ * distributed under the License is distributed on an "AS IS" BASIS,
335
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
336
+ * See the License for the specific language governing permissions and
337
+ * limitations under the License.
338
+ * =============================================================================
339
+ */
340
+ function Et(n, e) {
341
+ let t = l(n, "a", "greaterEqual", "string_or_numeric"), s = l(e, "b", "greaterEqual", "string_or_numeric");
342
+ [t, s] = Y(t, s), v(t.shape, s.shape);
343
+ const r = { a: t, b: s };
344
+ return d.runKernel(ge, r);
345
+ }
346
+ const Tt = /* @__PURE__ */ p({ greaterEqual_: Et });
347
+ /**
348
+ * @license
349
+ * Copyright 2020 Google LLC. All Rights Reserved.
350
+ * Licensed under the Apache License, Version 2.0 (the "License");
351
+ * you may not use this file except in compliance with the License.
352
+ * You may obtain a copy of the License at
353
+ *
354
+ * http://www.apache.org/licenses/LICENSE-2.0
355
+ *
356
+ * Unless required by applicable law or agreed to in writing, software
357
+ * distributed under the License is distributed on an "AS IS" BASIS,
358
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
359
+ * See the License for the specific language governing permissions and
360
+ * limitations under the License.
361
+ * =============================================================================
362
+ */
363
+ function St(n) {
364
+ const t = { input: l(n, "input", "imag") };
365
+ return d.runKernel($e, t);
366
+ }
367
+ const Nt = /* @__PURE__ */ p({ imag_: St });
368
+ /**
369
+ * @license
370
+ * Copyright 2020 Google LLC. All Rights Reserved.
371
+ * Licensed under the Apache License, Version 2.0 (the "License");
372
+ * you may not use this file except in compliance with the License.
373
+ * You may obtain a copy of the License at
374
+ *
375
+ * http://www.apache.org/licenses/LICENSE-2.0
376
+ *
377
+ * Unless required by applicable law or agreed to in writing, software
378
+ * distributed under the License is distributed on an "AS IS" BASIS,
379
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
380
+ * See the License for the specific language governing permissions and
381
+ * limitations under the License.
382
+ * =============================================================================
383
+ */
384
+ function Dt(n, e = 0.2) {
385
+ const s = { x: l(n, "x", "leakyRelu") }, r = { alpha: e };
386
+ return d.runKernel(be, s, r);
387
+ }
388
+ const Mt = /* @__PURE__ */ p({ leakyRelu_: Dt });
389
+ /**
390
+ * @license
391
+ * Copyright 2020 Google LLC. All Rights Reserved.
392
+ * Licensed under the Apache License, Version 2.0 (the "License");
393
+ * you may not use this file except in compliance with the License.
394
+ * You may obtain a copy of the License at
395
+ *
396
+ * http://www.apache.org/licenses/LICENSE-2.0
397
+ *
398
+ * Unless required by applicable law or agreed to in writing, software
399
+ * distributed under the License is distributed on an "AS IS" BASIS,
400
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
401
+ * See the License for the specific language governing permissions and
402
+ * limitations under the License.
403
+ * =============================================================================
404
+ */
405
+ function Ot(n, e) {
406
+ let t = l(n, "a", "less", "string_or_numeric"), s = l(e, "b", "less", "string_or_numeric");
407
+ [t, s] = Y(t, s), v(t.shape, s.shape);
408
+ const r = { a: t, b: s };
409
+ return d.runKernel(ke, r);
410
+ }
411
+ const Rn = /* @__PURE__ */ p({ less_: Ot });
412
+ /**
413
+ * @license
414
+ * Copyright 2020 Google LLC. All Rights Reserved.
415
+ * Licensed under the Apache License, Version 2.0 (the "License");
416
+ * you may not use this file except in compliance with the License.
417
+ * You may obtain a copy of the License at
418
+ *
419
+ * http://www.apache.org/licenses/LICENSE-2.0
420
+ *
421
+ * Unless required by applicable law or agreed to in writing, software
422
+ * distributed under the License is distributed on an "AS IS" BASIS,
423
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
424
+ * See the License for the specific language governing permissions and
425
+ * limitations under the License.
426
+ * =============================================================================
427
+ */
428
+ function Vt(n, e) {
429
+ let t = l(n, "a", "lessEqual", "string_or_numeric"), s = l(e, "b", "lessEqual", "string_or_numeric");
430
+ [t, s] = Y(t, s), v(t.shape, s.shape);
431
+ const r = { a: t, b: s };
432
+ return d.runKernel(xe, r);
433
+ }
434
+ const Xn = /* @__PURE__ */ p({ lessEqual_: Vt });
435
+ /**
436
+ * @license
437
+ * Copyright 2018 Google LLC. All Rights Reserved.
438
+ * Licensed under the Apache License, Version 2.0 (the "License");
439
+ * you may not use this file except in compliance with the License.
440
+ * You may obtain a copy of the License at
441
+ *
442
+ * http://www.apache.org/licenses/LICENSE-2.0
443
+ *
444
+ * Unless required by applicable law or agreed to in writing, software
445
+ * distributed under the License is distributed on an "AS IS" BASIS,
446
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
447
+ * See the License for the specific language governing permissions and
448
+ * limitations under the License.
449
+ * =============================================================================
450
+ */
451
+ function vt(n) {
452
+ const t = { x: l(n, "x", "neg") };
453
+ return d.runKernel(we, t);
454
+ }
455
+ const Tn = /* @__PURE__ */ p({ neg_: vt });
456
+ /**
457
+ * @license
458
+ * Copyright 2020 Google LLC. All Rights Reserved.
459
+ * Licensed under the Apache License, Version 2.0 (the "License");
460
+ * you may not use this file except in compliance with the License.
461
+ * You may obtain a copy of the License at
462
+ *
463
+ * http://www.apache.org/licenses/LICENSE-2.0
464
+ *
465
+ * Unless required by applicable law or agreed to in writing, software
466
+ * distributed under the License is distributed on an "AS IS" BASIS,
467
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
468
+ * See the License for the specific language governing permissions and
469
+ * limitations under the License.
470
+ * =============================================================================
471
+ */
472
+ function Pt(n, e) {
473
+ const t = l(n, "a", "logicalAnd", "bool"), s = l(e, "b", "logicalAnd", "bool");
474
+ v(t.shape, s.shape);
475
+ const r = { a: t, b: s };
476
+ return d.runKernel(ye, r);
477
+ }
478
+ const Bt = /* @__PURE__ */ p({ logicalAnd_: Pt });
479
+ /**
480
+ * @license
481
+ * Copyright 2020 Google LLC. All Rights Reserved.
482
+ * Licensed under the Apache License, Version 2.0 (the "License");
483
+ * you may not use this file except in compliance with the License.
484
+ * You may obtain a copy of the License at
485
+ *
486
+ * http://www.apache.org/licenses/LICENSE-2.0
487
+ *
488
+ * Unless required by applicable law or agreed to in writing, software
489
+ * distributed under the License is distributed on an "AS IS" BASIS,
490
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
491
+ * See the License for the specific language governing permissions and
492
+ * limitations under the License.
493
+ * =============================================================================
494
+ */
495
+ function Rt(n, e) {
496
+ let t = l(n, "a", "minimum"), s = l(e, "b", "minimum");
497
+ [t, s] = Y(t, s), t.dtype === "bool" && (t = L(t, "int32"), s = L(s, "int32")), v(t.shape, s.shape);
498
+ const r = { a: t, b: s };
499
+ return d.runKernel(_e, r);
500
+ }
501
+ const Kn = /* @__PURE__ */ p({ minimum_: Rt });
502
+ /**
503
+ * @license
504
+ * Copyright 2020 Google LLC. All Rights Reserved.
505
+ * Licensed under the Apache License, Version 2.0 (the "License");
506
+ * you may not use this file except in compliance with the License.
507
+ * You may obtain a copy of the License at
508
+ *
509
+ * http://www.apache.org/licenses/LICENSE-2.0
510
+ *
511
+ * Unless required by applicable law or agreed to in writing, software
512
+ * distributed under the License is distributed on an "AS IS" BASIS,
513
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
514
+ * See the License for the specific language governing permissions and
515
+ * limitations under the License.
516
+ * =============================================================================
517
+ */
518
+ function Kt(n, e) {
519
+ const t = l(n, "x", "prelu"), s = l(e, "alpha", "prelu"), r = { x: t, alpha: s };
520
+ return d.runKernel(Ae, r);
521
+ }
522
+ const qt = /* @__PURE__ */ p({ prelu_: Kt });
523
+ /**
524
+ * @license
525
+ * Copyright 2018 Google LLC. All Rights Reserved.
526
+ * Licensed under the Apache License, Version 2.0 (the "License");
527
+ * you may not use this file except in compliance with the License.
528
+ * You may obtain a copy of the License at
529
+ *
530
+ * http://www.apache.org/licenses/LICENSE-2.0
531
+ *
532
+ * Unless required by applicable law or agreed to in writing, software
533
+ * distributed under the License is distributed on an "AS IS" BASIS,
534
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
535
+ * See the License for the specific language governing permissions and
536
+ * limitations under the License.
537
+ * =============================================================================
538
+ */
539
+ class Ft {
540
+ constructor(e, t, s, r, o) {
541
+ this.mean = e, this.stdDev = t, this.dtype = s, this.nextVal = NaN, this.truncated = r, this.truncated && (this.upper = this.mean + this.stdDev * 2, this.lower = this.mean - this.stdDev * 2);
542
+ const a = o || Math.random();
543
+ this.random = Wn.alea(a.toString());
544
+ }
545
+ /** Returns next sample from a Gaussian distribution. */
546
+ nextValue() {
547
+ if (!isNaN(this.nextVal)) {
548
+ const r = this.nextVal;
549
+ return this.nextVal = NaN, r;
550
+ }
551
+ let e, t, s = !1;
552
+ for (; !s; ) {
553
+ let r, o, a;
554
+ do
555
+ r = 2 * this.random() - 1, o = 2 * this.random() - 1, a = r * r + o * o;
556
+ while (a >= 1 || a === 0);
557
+ const i = Math.sqrt(-2 * Math.log(a) / a);
558
+ e = this.mean + this.stdDev * r * i, t = this.mean + this.stdDev * o * i, (!this.truncated || this.isValidTruncated(e)) && (s = !0);
559
+ }
560
+ return (!this.truncated || this.isValidTruncated(t)) && (this.nextVal = this.convertValue(t)), this.convertValue(e);
561
+ }
562
+ /** Handles proper rounding for non-floating-point numbers. */
563
+ convertValue(e) {
564
+ return this.dtype == null || this.dtype === "float32" ? e : Math.round(e);
565
+ }
566
+ /** Returns true if less than 2-standard-deviations from the mean. */
567
+ isValidTruncated(e) {
568
+ return e <= this.upper && e >= this.lower;
569
+ }
570
+ }
571
+ class jt {
572
+ constructor(e = 0, t = 1, s, r) {
573
+ if (this.canReturnFloat = () => this.dtype == null || this.dtype === "float32", this.min = e, this.range = t - e, this.dtype = s, r == null && (r = Math.random()), typeof r == "number" && (r = r.toString()), !this.canReturnFloat() && this.range <= 1)
574
+ throw new Error(`The difference between ${e} - ${t} <= 1 and dtype is not float`);
575
+ this.random = Wn.alea(r);
576
+ }
577
+ convertValue(e) {
578
+ return this.canReturnFloat() ? e : Math.round(e);
579
+ }
580
+ nextValue() {
581
+ return this.convertValue(this.min + this.range * this.random());
582
+ }
583
+ }
584
+ /**
585
+ * @license
586
+ * Copyright 2020 Google LLC. All Rights Reserved.
587
+ * Licensed under the Apache License, Version 2.0 (the "License");
588
+ * you may not use this file except in compliance with the License.
589
+ * You may obtain a copy of the License at
590
+ *
591
+ * http://www.apache.org/licenses/LICENSE-2.0
592
+ *
593
+ * Unless required by applicable law or agreed to in writing, software
594
+ * distributed under the License is distributed on an "AS IS" BASIS,
595
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
596
+ * See the License for the specific language governing permissions and
597
+ * limitations under the License.
598
+ * =============================================================================
599
+ */
600
+ function Gt(n, e = 0, t = 1, s, r) {
601
+ if (zn(n), s != null && s === "bool")
602
+ throw new Error(`Unsupported data type ${s}`);
603
+ const o = new Ft(e, t, s, !1, r), a = In(n, s);
604
+ for (let i = 0; i < a.values.length; i++)
605
+ a.values[i] = o.nextValue();
606
+ return a.toTensor();
607
+ }
608
+ const Lt = /* @__PURE__ */ p({ randomNormal_: Gt });
609
+ /**
610
+ * @license
611
+ * Copyright 2020 Google LLC. All Rights Reserved.
612
+ * Licensed under the Apache License, Version 2.0 (the "License");
613
+ * you may not use this file except in compliance with the License.
614
+ * You may obtain a copy of the License at
615
+ *
616
+ * http://www.apache.org/licenses/LICENSE-2.0
617
+ *
618
+ * Unless required by applicable law or agreed to in writing, software
619
+ * distributed under the License is distributed on an "AS IS" BASIS,
620
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
621
+ * See the License for the specific language governing permissions and
622
+ * limitations under the License.
623
+ * =============================================================================
624
+ */
625
+ function Ct(n, e = 0, t = 1, s = "float32", r) {
626
+ zn(n);
627
+ const o = In(n, s), a = new jt(e, t, null, r);
628
+ for (let i = 0; i < o.values.length; i++)
629
+ o.values[i] = a.nextValue();
630
+ return o.toTensor();
631
+ }
632
+ const zt = /* @__PURE__ */ p({ randomUniform_: Ct });
633
+ /**
634
+ * @license
635
+ * Copyright 2020 Google LLC. All Rights Reserved.
636
+ * Licensed under the Apache License, Version 2.0 (the "License");
637
+ * you may not use this file except in compliance with the License.
638
+ * You may obtain a copy of the License at
639
+ *
640
+ * http://www.apache.org/licenses/LICENSE-2.0
641
+ *
642
+ * Unless required by applicable law or agreed to in writing, software
643
+ * distributed under the License is distributed on an "AS IS" BASIS,
644
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
645
+ * See the License for the specific language governing permissions and
646
+ * limitations under the License.
647
+ * =============================================================================
648
+ */
649
+ function Ut(n) {
650
+ const t = { input: l(n, "input", "real") };
651
+ return d.runKernel(Ie, t);
652
+ }
653
+ const Jt = /* @__PURE__ */ p({ real_: Ut });
654
+ /**
655
+ * @license
656
+ * Copyright 2020 Google LLC. All Rights Reserved.
657
+ * Licensed under the Apache License, Version 2.0 (the "License");
658
+ * you may not use this file except in compliance with the License.
659
+ * You may obtain a copy of the License at
660
+ *
661
+ * http://www.apache.org/licenses/LICENSE-2.0
662
+ *
663
+ * Unless required by applicable law or agreed to in writing, software
664
+ * distributed under the License is distributed on an "AS IS" BASIS,
665
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
666
+ * See the License for the specific language governing permissions and
667
+ * limitations under the License.
668
+ * =============================================================================
669
+ */
670
+ function Wt(n) {
671
+ const t = { x: l(n, "x", "relu") };
672
+ return d.runKernel(Ee, t);
673
+ }
674
+ const Yt = /* @__PURE__ */ p({ relu_: Wt });
675
+ /**
676
+ * @license
677
+ * Copyright 2020 Google LLC. All Rights Reserved.
678
+ * Licensed under the Apache License, Version 2.0 (the "License");
679
+ * you may not use this file except in compliance with the License.
680
+ * You may obtain a copy of the License at
681
+ *
682
+ * http://www.apache.org/licenses/LICENSE-2.0
683
+ *
684
+ * Unless required by applicable law or agreed to in writing, software
685
+ * distributed under the License is distributed on an "AS IS" BASIS,
686
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
687
+ * See the License for the specific language governing permissions and
688
+ * limitations under the License.
689
+ * =============================================================================
690
+ */
691
+ function Xt(n) {
692
+ const t = { x: l(n, "x", "relu6") };
693
+ return d.runKernel(Te, t);
694
+ }
695
+ const Zt = /* @__PURE__ */ p({ relu6_: Xt });
696
+ /**
697
+ * @license
698
+ * Copyright 2018 Google LLC. All Rights Reserved.
699
+ * Licensed under the Apache License, Version 2.0 (the "License");
700
+ * you may not use this file except in compliance with the License.
701
+ * You may obtain a copy of the License at
702
+ *
703
+ * http://www.apache.org/licenses/LICENSE-2.0
704
+ *
705
+ * Unless required by applicable law or agreed to in writing, software
706
+ * distributed under the License is distributed on an "AS IS" BASIS,
707
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
708
+ * See the License for the specific language governing permissions and
709
+ * limitations under the License.
710
+ * =============================================================================
711
+ */
712
+ function Ht(n) {
713
+ const t = { x: l(n, "x", "round") };
714
+ return d.runKernel(Se, t);
715
+ }
716
+ const Qt = /* @__PURE__ */ p({ round_: Ht });
717
+ /**
718
+ * @license
719
+ * Copyright 2018 Google LLC. All Rights Reserved.
720
+ * Licensed under the Apache License, Version 2.0 (the "License");
721
+ * you may not use this file except in compliance with the License.
722
+ * You may obtain a copy of the License at
723
+ *
724
+ * http://www.apache.org/licenses/LICENSE-2.0
725
+ *
726
+ * Unless required by applicable law or agreed to in writing, software
727
+ * distributed under the License is distributed on an "AS IS" BASIS,
728
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
729
+ * See the License for the specific language governing permissions and
730
+ * limitations under the License.
731
+ * =============================================================================
732
+ */
733
+ function ns(n, e, t) {
734
+ const s = l(n, "x", "slice1d");
735
+ return f(s.rank === 1, () => `slice1d expects a rank-1 tensor, but got a rank-${s.rank} tensor`), I(s, [e], [t]);
736
+ }
737
+ const Sn = /* @__PURE__ */ p({ slice1d_: ns });
738
+ /**
739
+ * @license
740
+ * Copyright 2018 Google LLC. All Rights Reserved.
741
+ * Licensed under the Apache License, Version 2.0 (the "License");
742
+ * you may not use this file except in compliance with the License.
743
+ * You may obtain a copy of the License at
744
+ *
745
+ * http://www.apache.org/licenses/LICENSE-2.0
746
+ *
747
+ * Unless required by applicable law or agreed to in writing, software
748
+ * distributed under the License is distributed on an "AS IS" BASIS,
749
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
750
+ * See the License for the specific language governing permissions and
751
+ * limitations under the License.
752
+ * =============================================================================
753
+ */
754
+ function es(n, e, t) {
755
+ const s = l(n, "x", "slice2d");
756
+ return f(s.rank === 2, () => `slice2d expects a rank-2 tensor, but got a rank-${s.rank} tensor`), I(s, e, t);
757
+ }
758
+ const Zn = /* @__PURE__ */ p({ slice2d_: es });
759
+ /**
760
+ * @license
761
+ * Copyright 2018 Google LLC. All Rights Reserved.
762
+ * Licensed under the Apache License, Version 2.0 (the "License");
763
+ * you may not use this file except in compliance with the License.
764
+ * You may obtain a copy of the License at
765
+ *
766
+ * http://www.apache.org/licenses/LICENSE-2.0
767
+ *
768
+ * Unless required by applicable law or agreed to in writing, software
769
+ * distributed under the License is distributed on an "AS IS" BASIS,
770
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
771
+ * See the License for the specific language governing permissions and
772
+ * limitations under the License.
773
+ * =============================================================================
774
+ */
775
+ function ts(n, e, t) {
776
+ const s = l(n, "x", "slice3d");
777
+ return f(s.rank === 3, () => `slice3d expects a rank-3 tensor, but got a rank-${s.rank} tensor`), I(s, e, t);
778
+ }
779
+ const Nn = /* @__PURE__ */ p({ slice3d_: ts });
780
+ /**
781
+ * @license
782
+ * Copyright 2018 Google LLC. All Rights Reserved.
783
+ * Licensed under the Apache License, Version 2.0 (the "License");
784
+ * you may not use this file except in compliance with the License.
785
+ * You may obtain a copy of the License at
786
+ *
787
+ * http://www.apache.org/licenses/LICENSE-2.0
788
+ *
789
+ * Unless required by applicable law or agreed to in writing, software
790
+ * distributed under the License is distributed on an "AS IS" BASIS,
791
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
792
+ * See the License for the specific language governing permissions and
793
+ * limitations under the License.
794
+ * =============================================================================
795
+ */
796
+ function ss(n, e, t) {
797
+ const s = l(n, "x", "slice4d");
798
+ return f(s.rank === 4, () => `slice4d expects a rank-4 tensor, but got a rank-${s.rank} tensor`), I(s, e, t);
799
+ }
800
+ const pn = /* @__PURE__ */ p({ slice4d_: ss });
801
+ /**
802
+ * @license
803
+ * Copyright 2020 Google LLC. All Rights Reserved.
804
+ * Licensed under the Apache License, Version 2.0 (the "License");
805
+ * you may not use this file except in compliance with the License.
806
+ * You may obtain a copy of the License at
807
+ *
808
+ * http://www.apache.org/licenses/LICENSE-2.0
809
+ *
810
+ * Unless required by applicable law or agreed to in writing, software
811
+ * distributed under the License is distributed on an "AS IS" BASIS,
812
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
813
+ * See the License for the specific language governing permissions and
814
+ * limitations under the License.
815
+ * =============================================================================
816
+ */
817
+ function rs(n, e) {
818
+ const t = l(n, "x", "squeeze", "string_or_numeric");
819
+ return $(t, Ne(t.shape, e).newShape);
820
+ }
821
+ const os = /* @__PURE__ */ p({ squeeze_: rs });
822
+ /**
823
+ * @license
824
+ * Copyright 2018 Google LLC. All Rights Reserved.
825
+ * Licensed under the Apache License, Version 2.0 (the "License");
826
+ * you may not use this file except in compliance with the License.
827
+ * You may obtain a copy of the License at
828
+ *
829
+ * http://www.apache.org/licenses/LICENSE-2.0
830
+ *
831
+ * Unless required by applicable law or agreed to in writing, software
832
+ * distributed under the License is distributed on an "AS IS" BASIS,
833
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
834
+ * See the License for the specific language governing permissions and
835
+ * limitations under the License.
836
+ * =============================================================================
837
+ */
838
+ function as(n, e = 0) {
839
+ const s = { x: l(n, "x", "step") }, r = { alpha: e };
840
+ return d.runKernel(De, s, r);
841
+ }
842
+ const is = /* @__PURE__ */ p({ step_: as });
843
+ /**
844
+ * @license
845
+ * Copyright 2018 Google LLC. All Rights Reserved.
846
+ * Licensed under the Apache License, Version 2.0 (the "License");
847
+ * you may not use this file except in compliance with the License.
848
+ * You may obtain a copy of the License at
849
+ *
850
+ * http://www.apache.org/licenses/LICENSE-2.0
851
+ *
852
+ * Unless required by applicable law or agreed to in writing, software
853
+ * distributed under the License is distributed on an "AS IS" BASIS,
854
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
855
+ * See the License for the specific language governing permissions and
856
+ * limitations under the License.
857
+ * =============================================================================
858
+ */
859
+ function V(n, e) {
860
+ Me(n);
861
+ const t = Oe(n, e);
862
+ if (t.length !== 1)
863
+ throw new Error("tensor1d() requires values to be a flat/TypedArray");
864
+ return Ve(n, null, t, e);
865
+ }
866
+ /**
867
+ * @license
868
+ * Copyright 2020 Google LLC. All Rights Reserved.
869
+ * Licensed under the Apache License, Version 2.0 (the "License");
870
+ * you may not use this file except in compliance with the License.
871
+ * You may obtain a copy of the License at
872
+ *
873
+ * http://www.apache.org/licenses/LICENSE-2.0
874
+ *
875
+ * Unless required by applicable law or agreed to in writing, software
876
+ * distributed under the License is distributed on an "AS IS" BASIS,
877
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
878
+ * See the License for the specific language governing permissions and
879
+ * limitations under the License.
880
+ * =============================================================================
881
+ */
882
+ function cs(n, e = 0) {
883
+ const t = l(n, "x", "unstack", "string_or_numeric");
884
+ f(e >= -t.shape.length && e < t.shape.length, () => `Axis = ${e} is not in [-${t.shape.length}, ${t.shape.length})`);
885
+ const s = { value: t }, r = { axis: e };
886
+ return d.runKernel(ve, s, r);
887
+ }
888
+ const Hn = /* @__PURE__ */ p({ unstack_: cs });
889
+ /**
890
+ * @license
891
+ * Copyright 2018 Google LLC. All Rights Reserved.
892
+ * Licensed under the Apache License, Version 2.0 (the "License");
893
+ * you may not use this file except in compliance with the License.
894
+ * You may obtain a copy of the License at
895
+ *
896
+ * http://www.apache.org/licenses/LICENSE-2.0
897
+ *
898
+ * Unless required by applicable law or agreed to in writing, software
899
+ * distributed under the License is distributed on an "AS IS" BASIS,
900
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
901
+ * See the License for the specific language governing permissions and
902
+ * limitations under the License.
903
+ * =============================================================================
904
+ */
905
+ function us(n, e, t) {
906
+ const s = l(n, "x", "transpose");
907
+ if (e == null && (e = s.shape.map((a, i) => i).reverse()), f(s.rank === e.length, () => `Error in transpose: rank of input ${s.rank} must match length of perm ${e}.`), e.forEach((a) => {
908
+ f(a >= 0 && a < s.rank, () => `All entries in 'perm' must be between 0 and ${s.rank - 1} but got ${e}`);
909
+ }), s.rank <= 1)
910
+ return s.clone();
911
+ const r = { x: s }, o = { perm: e };
912
+ return s.dtype === "complex64" ? P(() => {
913
+ let a = Jt(s), i = Nt(s);
914
+ return a = d.runKernel(dn, { x: a }, o), i = d.runKernel(dn, { x: i }, o), t && (i = Tn(i)), He(a, i);
915
+ }) : d.runKernel(dn, r, o);
916
+ }
917
+ const wn = /* @__PURE__ */ p({ transpose_: us });
918
+ /**
919
+ * @license
920
+ * Copyright 2019 Google LLC. All Rights Reserved.
921
+ * Licensed under the Apache License, Version 2.0 (the "License");
922
+ * you may not use this file except in compliance with the License.
923
+ * You may obtain a copy of the License at
924
+ *
925
+ * http://www.apache.org/licenses/LICENSE-2.0
926
+ *
927
+ * Unless required by applicable law or agreed to in writing, software
928
+ * distributed under the License is distributed on an "AS IS" BASIS,
929
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
930
+ * See the License for the specific language governing permissions and
931
+ * limitations under the License.
932
+ * =============================================================================
933
+ */
934
+ function ls(n, e) {
935
+ if (e == null)
936
+ return n.shape.slice();
937
+ if (Pe(n.shape, e))
938
+ return e;
939
+ if (n.shape.length === e.length) {
940
+ const t = [];
941
+ for (let s = 0; s < n.shape.length; s++)
942
+ e[s] == null && n.shape[s] != null ? t.push(n.shape[s]) : t.push(e[s]);
943
+ return t;
944
+ }
945
+ return e;
946
+ }
947
+ /**
948
+ * @license
949
+ * Copyright 2018 Google LLC. All Rights Reserved.
950
+ * Licensed under the Apache License, Version 2.0 (the "License");
951
+ * you may not use this file except in compliance with the License.
952
+ * You may obtain a copy of the License at
953
+ *
954
+ * http://www.apache.org/licenses/LICENSE-2.0
955
+ *
956
+ * Unless required by applicable law or agreed to in writing, software
957
+ * distributed under the License is distributed on an "AS IS" BASIS,
958
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
959
+ * See the License for the specific language governing permissions and
960
+ * limitations under the License.
961
+ * =============================================================================
962
+ */
963
+ function fs(n, e, t, s) {
964
+ const r = l(n, "x", "dropout");
965
+ if (f(r.dtype === "float32", () => `x has to be a floating point tensor since it's going to be scaled, but got a ${r.dtype} tensor instead.`), f(e >= 0 && e < 1, () => `rate must be a float in the range [0, 1), but got ${e}.`), e === 0)
966
+ return n instanceof Be ? r.clone() : r;
967
+ const o = ls(r, t), a = 1 - e, i = K(At(C(zt(o, 0, 1, "float32", s), a)), a);
968
+ return A(r, i);
969
+ }
970
+ const ps = /* @__PURE__ */ p({ dropout_: fs });
971
+ /**
972
+ * @license
973
+ * Copyright 2019 Google LLC. All Rights Reserved.
974
+ * Licensed under the Apache License, Version 2.0 (the "License");
975
+ * you may not use this file except in compliance with the License.
976
+ * You may obtain a copy of the License at
977
+ *
978
+ * http://www.apache.org/licenses/LICENSE-2.0
979
+ *
980
+ * Unless required by applicable law or agreed to in writing, software
981
+ * distributed under the License is distributed on an "AS IS" BASIS,
982
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
983
+ * See the License for the specific language governing permissions and
984
+ * limitations under the License.
985
+ * =============================================================================
986
+ */
987
+ function hs(n, e, t) {
988
+ if (t == null || t === "linear")
989
+ return n;
990
+ if (t === "relu")
991
+ return A(n, is(e));
992
+ throw new Error(`Cannot compute gradient for fused activation ${t}.`);
993
+ }
994
+ function ds(n, e) {
995
+ let t = e;
996
+ const s = Re(n.shape, e.shape);
997
+ return s.length > 0 && (t = j(t, s)), $(t, n.shape);
998
+ }
999
+ function ms(n, e, t, s) {
1000
+ if (e === "linear")
1001
+ return n;
1002
+ if (e === "relu")
1003
+ return Yt(n);
1004
+ if (e === "elu")
1005
+ return Yn(n);
1006
+ if (e === "relu6")
1007
+ return Zt(n);
1008
+ if (e === "prelu")
1009
+ return qt(n, t);
1010
+ if (e === "leakyrelu")
1011
+ return Mt(n, s);
1012
+ if (e === "sigmoid")
1013
+ return tt(n);
1014
+ throw new Error(`Unknown fused activation ${e}.`);
1015
+ }
1016
+ const gs = (n, e) => !(n > 0) || e === "linear";
1017
+ /**
1018
+ * @license
1019
+ * Copyright 2019 Google LLC. All Rights Reserved.
1020
+ * Licensed under the Apache License, Version 2.0 (the "License");
1021
+ * you may not use this file except in compliance with the License.
1022
+ * You may obtain a copy of the License at
1023
+ *
1024
+ * http://www.apache.org/licenses/LICENSE-2.0
1025
+ *
1026
+ * Unless required by applicable law or agreed to in writing, software
1027
+ * distributed under the License is distributed on an "AS IS" BASIS,
1028
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1029
+ * See the License for the specific language governing permissions and
1030
+ * limitations under the License.
1031
+ * =============================================================================
1032
+ */
1033
+ function $s({ a: n, b: e, transposeA: t = !1, transposeB: s = !1, bias: r, activation: o = "linear", preluActivationWeights: a, leakyreluAlpha: i = 0.2 }) {
1034
+ if (gs(d.state.gradientDepth, o) === !1) {
1035
+ let U = _(n, e, t, s);
1036
+ return r != null && (U = C(U, r)), ms(U, o, a, i);
1037
+ }
1038
+ let u = l(n, "a", "fused matMul"), c = l(e, "b", "fused matMul");
1039
+ [u, c] = Y(u, c);
1040
+ const m = t ? u.shape[u.rank - 2] : u.shape[u.rank - 1], h = s ? c.shape[c.rank - 1] : c.shape[c.rank - 2], b = t ? u.shape[u.rank - 1] : u.shape[u.rank - 2], g = s ? c.shape[c.rank - 2] : c.shape[c.rank - 1], x = u.shape.slice(0, -2), w = c.shape.slice(0, -2), k = Vn(x), E = Vn(w);
1041
+ f(m === h, () => `Error in fused matMul: inner shapes (${m}) and (${h}) of Tensors with shapes ${u.shape} and ${c.shape} and transposeA=${t} and transposeB=${s} must match.`);
1042
+ const S = v(u.shape.slice(0, -2), c.shape.slice(0, -2)).concat([b, g]), M = t ? $(u, [k, m, b]) : $(u, [k, b, m]), O = s ? $(c, [E, g, h]) : $(c, [E, h, g]);
1043
+ let N;
1044
+ r != null && (N = l(r, "bias", "fused matMul"), [N] = Y(N, u), v(S, N.shape));
1045
+ let tn;
1046
+ a != null && (tn = l(a, "prelu weights", "fused matMul"));
1047
+ const z = (U, sn) => {
1048
+ const [q, F, J, un] = sn, B = hs($(U, J.shape), J, o);
1049
+ let Z, H;
1050
+ if (!t && !s ? (Z = _(B, F, !1, !0), H = _(q, B, !0, !1)) : !t && s ? (Z = _(B, F, !1, !1), H = _(B, q, !0, !1)) : t && !s ? (Z = _(F, B, !1, !0), H = _(q, B, !1, !1)) : (Z = _(F, B, !0, !0), H = _(B, q, !0, !0)), r != null) {
1051
+ const re = ds(un, B);
1052
+ return [Z, H, re];
1053
+ } else
1054
+ return [Z, H];
1055
+ }, X = {
1056
+ a: M,
1057
+ b: O,
1058
+ bias: N,
1059
+ preluActivationWeights: tn
1060
+ }, On = { transposeA: t, transposeB: s, activation: o, leakyreluAlpha: i };
1061
+ return r == null ? vn((sn, q, F) => {
1062
+ const J = (
1063
+ // tslint:disable-next-line: no-unnecessary-type-assertion
1064
+ d.runKernel(Pn, X, On)
1065
+ );
1066
+ return F([sn, q, J]), { value: $(J, S), gradFunc: z };
1067
+ })(M, O) : vn((sn, q, F, J) => {
1068
+ const un = (
1069
+ // tslint:disable-next-line: no-unnecessary-type-assertion
1070
+ d.runKernel(Pn, X, On)
1071
+ );
1072
+ return J([sn, q, un, F]), { value: $(un, S), gradFunc: z };
1073
+ })(M, O, N);
1074
+ }
1075
+ const qn = /* @__PURE__ */ p({ fusedMatMul_: $s });
1076
+ /**
1077
+ * @license
1078
+ * Copyright 2020 Google LLC. All Rights Reserved.
1079
+ * Licensed under the Apache License, Version 2.0 (the "License");
1080
+ * you may not use this file except in compliance with the License.
1081
+ * You may obtain a copy of the License at
1082
+ *
1083
+ * http://www.apache.org/licenses/LICENSE-2.0
1084
+ *
1085
+ * Unless required by applicable law or agreed to in writing, software
1086
+ * distributed under the License is distributed on an "AS IS" BASIS,
1087
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1088
+ * See the License for the specific language governing permissions and
1089
+ * limitations under the License.
1090
+ * =============================================================================
1091
+ */
1092
+ function bs(n, e, t, s, r = "bilinear", o = 0) {
1093
+ const a = l(n, "image", "cropAndResize"), i = l(e, "boxes", "cropAndResize", "float32"), u = l(t, "boxInd", "cropAndResize", "int32"), c = i.shape[0];
1094
+ f(a.rank === 4, () => `Error in cropAndResize: image must be rank 4,but got rank ${a.rank}.`), f(i.rank === 2 && i.shape[1] === 4, () => `Error in cropAndResize: boxes must be have size [${c},4] but had shape ${i.shape}.`), f(u.rank === 1 && u.shape[0] === c, () => `Error in cropAndResize: boxInd must be have size [${c}] but had shape ${i.shape}.`), f(s.length === 2, () => `Error in cropAndResize: cropSize must be of length 2, but got length ${s.length}.`), f(s[0] >= 1 && s[1] >= 1, () => `cropSize must be atleast [1,1], but was ${s}`), f(r === "bilinear" || r === "nearest", () => `method must be bilinear or nearest, but was ${r}`);
1095
+ const m = { image: a, boxes: i, boxInd: u }, h = { method: r, extrapolationValue: o, cropSize: s };
1096
+ return d.runKernel(Ke, m, h);
1097
+ }
1098
+ const ks = /* @__PURE__ */ p({ cropAndResize_: bs });
1099
+ /**
1100
+ * @license
1101
+ * Copyright 2020 Google LLC. All Rights Reserved.
1102
+ * Licensed under the Apache License, Version 2.0 (the "License");
1103
+ * you may not use this file except in compliance with the License.
1104
+ * You may obtain a copy of the License at
1105
+ *
1106
+ * http://www.apache.org/licenses/LICENSE-2.0
1107
+ *
1108
+ * Unless required by applicable law or agreed to in writing, software
1109
+ * distributed under the License is distributed on an "AS IS" BASIS,
1110
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
+ * See the License for the specific language governing permissions and
1112
+ * limitations under the License.
1113
+ * =============================================================================
1114
+ */
1115
+ function xs(n) {
1116
+ const e = l(n, "image", "flipLeftRight", "float32");
1117
+ f(e.rank === 4, () => `Error in flipLeftRight: image must be rank 4,but got rank ${e.rank}.`);
1118
+ const t = { image: e };
1119
+ return d.runKernel(qe, t, {});
1120
+ }
1121
+ const ws = /* @__PURE__ */ p({ flipLeftRight_: xs });
1122
+ /**
1123
+ * @license
1124
+ * Copyright 2021 Google LLC. All Rights Reserved.
1125
+ * Licensed under the Apache License, Version 2.0 (the "License");
1126
+ * you may not use this file except in compliance with the License.
1127
+ * You may obtain a copy of the License at
1128
+ *
1129
+ * http://www.apache.org/licenses/LICENSE-2.0
1130
+ *
1131
+ * Unless required by applicable law or agreed to in writing, software
1132
+ * distributed under the License is distributed on an "AS IS" BASIS,
1133
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1134
+ * See the License for the specific language governing permissions and
1135
+ * limitations under the License.
1136
+ * =============================================================================
1137
+ */
1138
+ function ys(n) {
1139
+ const e = l(n, "image", "grayscaleToRGB"), t = e.rank - 1, s = e.shape[t];
1140
+ f(e.rank >= 2, () => `Error in grayscaleToRGB: images must be at least rank 2, but got rank ${e.rank}.`), f(s === 1, () => `Error in grayscaleToRGB: last dimension of a grayscale image should be size 1, but got size ${s}.`);
1141
+ const r = new Array(e.rank);
1142
+ return r.fill(1, 0, t), r[t] = 3, on(e, r);
1143
+ }
1144
+ const _s = /* @__PURE__ */ p({ grayscaleToRGB_: ys });
1145
+ /**
1146
+ * @license
1147
+ * Copyright 2023 Google LLC.
1148
+ * Licensed under the Apache License, Version 2.0 (the "License");
1149
+ * you may not use this file except in compliance with the License.
1150
+ * You may obtain a copy of the License at
1151
+ *
1152
+ * http://www.apache.org/licenses/LICENSE-2.0
1153
+ *
1154
+ * Unless required by applicable law or agreed to in writing, software
1155
+ * distributed under the License is distributed on an "AS IS" BASIS,
1156
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1157
+ * See the License for the specific language governing permissions and
1158
+ * limitations under the License.
1159
+ * =============================================================================
1160
+ */
1161
+ function As(n) {
1162
+ const e = l(n, "image", "RGBToGrayscale"), t = e.rank - 1, s = e.shape[t];
1163
+ f(e.rank >= 2, () => `Error in RGBToGrayscale: images must be at least rank 2, but got rank ${e.rank}.`), f(s === 3, () => `Error in RGBToGrayscale: last dimension of an RGB image should be size 3, but got size ${s}.`);
1164
+ const r = e.dtype, o = L(e, "float32"), a = V([0.2989, 0.587, 0.114]);
1165
+ let i;
1166
+ switch (e.rank) {
1167
+ case 2:
1168
+ i = rn("ij,j->i", o, a);
1169
+ break;
1170
+ case 3:
1171
+ i = rn("ijk,k->ij", o, a);
1172
+ break;
1173
+ case 4:
1174
+ i = rn("ijkl,l->ijk", o, a);
1175
+ break;
1176
+ case 5:
1177
+ i = rn("ijklm,m->ijkl", o, a);
1178
+ break;
1179
+ case 6:
1180
+ i = rn("ijklmn,n->ijklm", o, a);
1181
+ break;
1182
+ default:
1183
+ throw new Error("Not a valid tensor rank.");
1184
+ }
1185
+ return i = W(i, -1), L(i, r);
1186
+ }
1187
+ const Is = /* @__PURE__ */ p({ rgbToGrayscale_: As });
1188
+ /**
1189
+ * @license
1190
+ * Copyright 2020 Google LLC. All Rights Reserved.
1191
+ * Licensed under the Apache License, Version 2.0 (the "License");
1192
+ * you may not use this file except in compliance with the License.
1193
+ * You may obtain a copy of the License at
1194
+ *
1195
+ * http://www.apache.org/licenses/LICENSE-2.0
1196
+ *
1197
+ * Unless required by applicable law or agreed to in writing, software
1198
+ * distributed under the License is distributed on an "AS IS" BASIS,
1199
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1200
+ * See the License for the specific language governing permissions and
1201
+ * limitations under the License.
1202
+ * =============================================================================
1203
+ */
1204
+ function Es(n, e, t = 0, s = 0.5) {
1205
+ const r = l(n, "image", "rotateWithOffset", "float32");
1206
+ f(r.rank === 4, () => `Error in rotateWithOffset: image must be rank 4,but got rank ${r.rank}.`);
1207
+ const o = { image: r }, a = { radians: e, fillValue: t, center: s };
1208
+ return d.runKernel(Fe, o, a);
1209
+ }
1210
+ const Ts = /* @__PURE__ */ p({ rotateWithOffset_: Es });
1211
+ /**
1212
+ * @license
1213
+ * Copyright 2020 Google LLC. All Rights Reserved.
1214
+ * Licensed under the Apache License, Version 2.0 (the "License");
1215
+ * you may not use this file except in compliance with the License.
1216
+ * You may obtain a copy of the License at
1217
+ *
1218
+ * http://www.apache.org/licenses/LICENSE-2.0
1219
+ *
1220
+ * Unless required by applicable law or agreed to in writing, software
1221
+ * distributed under the License is distributed on an "AS IS" BASIS,
1222
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1223
+ * See the License for the specific language governing permissions and
1224
+ * limitations under the License.
1225
+ * =============================================================================
1226
+ */
1227
+ function en(n, e, t, s, r, o) {
1228
+ s == null && (s = 0.5), r == null && (r = Number.NEGATIVE_INFINITY), o == null && (o = 0);
1229
+ const a = n.shape[0];
1230
+ return t = Math.min(t, a), f(0 <= s && s <= 1, () => `iouThreshold must be in [0, 1], but was '${s}'`), f(n.rank === 2, () => `boxes must be a 2D tensor, but was of rank '${n.rank}'`), f(n.shape[1] === 4, () => `boxes must have 4 columns, but 2nd dimension was ${n.shape[1]}`), f(e.rank === 1, () => "scores must be a 1D tensor"), f(e.shape[0] === a, () => `scores has incompatible shape with boxes. Expected ${a}, but was ${e.shape[0]}`), f(0 <= o && o <= 1, () => `softNmsSigma must be in [0, 1], but was '${o}'`), { maxOutputSize: t, iouThreshold: s, scoreThreshold: r, softNmsSigma: o };
1231
+ }
1232
+ /**
1233
+ * @license
1234
+ * Copyright 2020 Google LLC. All Rights Reserved.
1235
+ * Licensed under the Apache License, Version 2.0 (the "License");
1236
+ * you may not use this file except in compliance with the License.
1237
+ * You may obtain a copy of the License at
1238
+ *
1239
+ * http://www.apache.org/licenses/LICENSE-2.0
1240
+ *
1241
+ * Unless required by applicable law or agreed to in writing, software
1242
+ * distributed under the License is distributed on an "AS IS" BASIS,
1243
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1244
+ * See the License for the specific language governing permissions and
1245
+ * limitations under the License.
1246
+ * =============================================================================
1247
+ */
1248
+ function Ss(n, e, t, s = 0.5, r = Number.NEGATIVE_INFINITY) {
1249
+ const o = l(n, "boxes", "nonMaxSuppression", "float32"), a = l(e, "scores", "nonMaxSuppression", "float32"), i = en(o, a, t, s, r);
1250
+ t = i.maxOutputSize, s = i.iouThreshold, r = i.scoreThreshold;
1251
+ const u = { maxOutputSize: t, iouThreshold: s, scoreThreshold: r };
1252
+ return d.runKernel(je, { boxes: o, scores: a }, u);
1253
+ }
1254
+ const Ns = /* @__PURE__ */ p({ nonMaxSuppression_: Ss });
1255
+ /**
1256
+ * @license
1257
+ * Copyright 2019 Google LLC. All Rights Reserved.
1258
+ * Licensed under the Apache License, Version 2.0 (the "License");
1259
+ * you may not use this file except in compliance with the License.
1260
+ * You may obtain a copy of the License at
1261
+ *
1262
+ * http://www.apache.org/licenses/LICENSE-2.0
1263
+ *
1264
+ * Unless required by applicable law or agreed to in writing, software
1265
+ * distributed under the License is distributed on an "AS IS" BASIS,
1266
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1267
+ * See the License for the specific language governing permissions and
1268
+ * limitations under the License.
1269
+ * =============================================================================
1270
+ */
1271
+ function Ds(n, e, t) {
1272
+ const s = Ms(n, e, t), r = s < 0 ? -(s + 1) : s;
1273
+ n.splice(r, 0, e);
1274
+ }
1275
+ function Ms(n, e, t) {
1276
+ return Vs(n, e, t || Os);
1277
+ }
1278
+ function Os(n, e) {
1279
+ return n > e ? 1 : n < e ? -1 : 0;
1280
+ }
1281
+ function Vs(n, e, t) {
1282
+ let s = 0, r = n.length, o = 0, a = !1;
1283
+ for (; s < r; ) {
1284
+ o = s + (r - s >>> 1);
1285
+ const i = t(e, n[o]);
1286
+ i > 0 ? s = o + 1 : (r = o, a = !i);
1287
+ }
1288
+ return a ? s : -s - 1;
1289
+ }
1290
+ /**
1291
+ * @license
1292
+ * Copyright 2020 Google LLC. All Rights Reserved.
1293
+ * Licensed under the Apache License, Version 2.0 (the "License");
1294
+ * you may not use this file except in compliance with the License.
1295
+ * You may obtain a copy of the License at
1296
+ *
1297
+ * http://www.apache.org/licenses/LICENSE-2.0
1298
+ *
1299
+ * Unless required by applicable law or agreed to in writing, software
1300
+ * distributed under the License is distributed on an "AS IS" BASIS,
1301
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1302
+ * See the License for the specific language governing permissions and
1303
+ * limitations under the License.
1304
+ * =============================================================================
1305
+ */
1306
+ function vs(n, e, t, s, r) {
1307
+ return Dn(
1308
+ n,
1309
+ e,
1310
+ t,
1311
+ s,
1312
+ r,
1313
+ 0
1314
+ /* softNmsSigma */
1315
+ );
1316
+ }
1317
+ function Ps(n, e, t, s, r, o) {
1318
+ return Dn(
1319
+ n,
1320
+ e,
1321
+ t,
1322
+ s,
1323
+ r,
1324
+ 0,
1325
+ !1,
1326
+ o,
1327
+ !0
1328
+ /* returnValidOutputs */
1329
+ );
1330
+ }
1331
+ function Bs(n, e, t, s, r, o) {
1332
+ return Dn(
1333
+ n,
1334
+ e,
1335
+ t,
1336
+ s,
1337
+ r,
1338
+ o,
1339
+ !0
1340
+ /* returnScoresTensor */
1341
+ );
1342
+ }
1343
+ function Dn(n, e, t, s, r, o, a = !1, i = !1, u = !1) {
1344
+ const c = [];
1345
+ for (let k = 0; k < e.length; k++)
1346
+ e[k] > r && c.push({ score: e[k], boxIndex: k, suppressBeginIndex: 0 });
1347
+ c.sort(Fn);
1348
+ const m = o > 0 ? -0.5 / o : 0, h = [], b = [];
1349
+ for (; h.length < t && c.length > 0; ) {
1350
+ const k = c.pop(), { score: E, boxIndex: T, suppressBeginIndex: S } = k;
1351
+ if (E < r)
1352
+ break;
1353
+ let M = !1;
1354
+ for (let O = h.length - 1; O >= S; --O) {
1355
+ const N = Rs(n, T, h[O]);
1356
+ if (N >= s) {
1357
+ M = !0;
1358
+ break;
1359
+ }
1360
+ if (k.score = k.score * Ks(s, m, N), k.score <= r)
1361
+ break;
1362
+ }
1363
+ k.suppressBeginIndex = h.length, M || (k.score === E ? (h.push(T), b.push(k.score)) : k.score > r && Ds(c, k, Fn));
1364
+ }
1365
+ const g = h.length, x = t - g;
1366
+ i && x > 0 && (h.push(...new Array(x).fill(0)), b.push(...new Array(x).fill(0)));
1367
+ const w = { selectedIndices: h };
1368
+ return a && (w.selectedScores = b), u && (w.validOutputs = g), w;
1369
+ }
1370
+ function Rs(n, e, t) {
1371
+ const s = n.subarray(e * 4, e * 4 + 4), r = n.subarray(t * 4, t * 4 + 4), o = Math.min(s[0], s[2]), a = Math.min(s[1], s[3]), i = Math.max(s[0], s[2]), u = Math.max(s[1], s[3]), c = Math.min(r[0], r[2]), m = Math.min(r[1], r[3]), h = Math.max(r[0], r[2]), b = Math.max(r[1], r[3]), g = (i - o) * (u - a), x = (h - c) * (b - m);
1372
+ if (g <= 0 || x <= 0)
1373
+ return 0;
1374
+ const w = Math.max(o, c), k = Math.max(a, m), E = Math.min(i, h), T = Math.min(u, b), S = Math.max(E - w, 0) * Math.max(T - k, 0);
1375
+ return S / (g + x - S);
1376
+ }
1377
+ function Ks(n, e, t) {
1378
+ const s = Math.exp(e * t * t);
1379
+ return t <= n ? s : 0;
1380
+ }
1381
+ function Fn(n, e) {
1382
+ return n.score - e.score || n.score === e.score && e.boxIndex - n.boxIndex;
1383
+ }
1384
+ /**
1385
+ * @license
1386
+ * Copyright 2020 Google LLC. All Rights Reserved.
1387
+ * Licensed under the Apache License, Version 2.0 (the "License");
1388
+ * you may not use this file except in compliance with the License.
1389
+ * You may obtain a copy of the License at
1390
+ *
1391
+ * http://www.apache.org/licenses/LICENSE-2.0
1392
+ *
1393
+ * Unless required by applicable law or agreed to in writing, software
1394
+ * distributed under the License is distributed on an "AS IS" BASIS,
1395
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1396
+ * See the License for the specific language governing permissions and
1397
+ * limitations under the License.
1398
+ * =============================================================================
1399
+ */
1400
+ async function qs(n, e, t, s = 0.5, r = Number.NEGATIVE_INFINITY) {
1401
+ const o = l(n, "boxes", "nonMaxSuppressionAsync"), a = l(e, "scores", "nonMaxSuppressionAsync"), i = en(o, a, t, s, r);
1402
+ t = i.maxOutputSize, s = i.iouThreshold, r = i.scoreThreshold;
1403
+ const u = await Promise.all([o.data(), a.data()]), c = u[0], m = u[1], { selectedIndices: h } = vs(c, m, t, s, r);
1404
+ return o !== n && o.dispose(), a !== e && a.dispose(), V(h, "int32");
1405
+ }
1406
+ const Fs = qs;
1407
+ /**
1408
+ * @license
1409
+ * Copyright 2020 Google LLC. All Rights Reserved.
1410
+ * Licensed under the Apache License, Version 2.0 (the "License");
1411
+ * you may not use this file except in compliance with the License.
1412
+ * You may obtain a copy of the License at
1413
+ *
1414
+ * http://www.apache.org/licenses/LICENSE-2.0
1415
+ *
1416
+ * Unless required by applicable law or agreed to in writing, software
1417
+ * distributed under the License is distributed on an "AS IS" BASIS,
1418
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1419
+ * See the License for the specific language governing permissions and
1420
+ * limitations under the License.
1421
+ * =============================================================================
1422
+ */
1423
+ function js(n, e, t, s = 0.5, r = Number.NEGATIVE_INFINITY, o = 0) {
1424
+ const a = l(n, "boxes", "nonMaxSuppression"), i = l(e, "scores", "nonMaxSuppression"), u = en(a, i, t, s, r, o);
1425
+ t = u.maxOutputSize, s = u.iouThreshold, r = u.scoreThreshold, o = u.softNmsSigma;
1426
+ const c = { boxes: a, scores: i }, m = { maxOutputSize: t, iouThreshold: s, scoreThreshold: r, softNmsSigma: o }, h = d.runKernel(Ge, c, m);
1427
+ return { selectedIndices: h[0], selectedScores: h[1] };
1428
+ }
1429
+ const Gs = /* @__PURE__ */ p({ nonMaxSuppressionWithScore_: js });
1430
+ /**
1431
+ * @license
1432
+ * Copyright 2020 Google LLC. All Rights Reserved.
1433
+ * Licensed under the Apache License, Version 2.0 (the "License");
1434
+ * you may not use this file except in compliance with the License.
1435
+ * You may obtain a copy of the License at
1436
+ *
1437
+ * http://www.apache.org/licenses/LICENSE-2.0
1438
+ *
1439
+ * Unless required by applicable law or agreed to in writing, software
1440
+ * distributed under the License is distributed on an "AS IS" BASIS,
1441
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1442
+ * See the License for the specific language governing permissions and
1443
+ * limitations under the License.
1444
+ * =============================================================================
1445
+ */
1446
+ async function Ls(n, e, t, s = 0.5, r = Number.NEGATIVE_INFINITY, o = 0) {
1447
+ const a = l(n, "boxes", "nonMaxSuppressionAsync"), i = l(e, "scores", "nonMaxSuppressionAsync"), u = en(a, i, t, s, r, o);
1448
+ t = u.maxOutputSize, s = u.iouThreshold, r = u.scoreThreshold, o = u.softNmsSigma;
1449
+ const c = await Promise.all([a.data(), i.data()]), m = c[0], h = c[1], { selectedIndices: b, selectedScores: g } = Bs(m, h, t, s, r, o);
1450
+ return a !== n && a.dispose(), i !== e && i.dispose(), {
1451
+ selectedIndices: V(b, "int32"),
1452
+ selectedScores: V(g)
1453
+ };
1454
+ }
1455
+ const Cs = Ls;
1456
+ /**
1457
+ * @license
1458
+ * Copyright 2020 Google LLC. All Rights Reserved.
1459
+ * Licensed under the Apache License, Version 2.0 (the "License");
1460
+ * you may not use this file except in compliance with the License.
1461
+ * You may obtain a copy of the License at
1462
+ *
1463
+ * http://www.apache.org/licenses/LICENSE-2.0
1464
+ *
1465
+ * Unless required by applicable law or agreed to in writing, software
1466
+ * distributed under the License is distributed on an "AS IS" BASIS,
1467
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1468
+ * See the License for the specific language governing permissions and
1469
+ * limitations under the License.
1470
+ * =============================================================================
1471
+ */
1472
+ function zs(n, e, t, s = 0.5, r = Number.NEGATIVE_INFINITY, o = !1) {
1473
+ const a = l(n, "boxes", "nonMaxSuppression"), i = l(e, "scores", "nonMaxSuppression"), u = en(
1474
+ a,
1475
+ i,
1476
+ t,
1477
+ s,
1478
+ r,
1479
+ null
1480
+ /* softNmsSigma */
1481
+ ), c = u.maxOutputSize, m = u.iouThreshold, h = u.scoreThreshold, b = { boxes: a, scores: i }, g = {
1482
+ maxOutputSize: c,
1483
+ iouThreshold: m,
1484
+ scoreThreshold: h,
1485
+ padToMaxOutputSize: o
1486
+ }, x = d.runKernel(Le, b, g);
1487
+ return { selectedIndices: x[0], validOutputs: x[1] };
1488
+ }
1489
+ const Us = /* @__PURE__ */ p({ nonMaxSuppressionPadded_: zs });
1490
+ /**
1491
+ * @license
1492
+ * Copyright 2020 Google LLC. All Rights Reserved.
1493
+ * Licensed under the Apache License, Version 2.0 (the "License");
1494
+ * you may not use this file except in compliance with the License.
1495
+ * You may obtain a copy of the License at
1496
+ *
1497
+ * http://www.apache.org/licenses/LICENSE-2.0
1498
+ *
1499
+ * Unless required by applicable law or agreed to in writing, software
1500
+ * distributed under the License is distributed on an "AS IS" BASIS,
1501
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1502
+ * See the License for the specific language governing permissions and
1503
+ * limitations under the License.
1504
+ * =============================================================================
1505
+ */
1506
+ async function Js(n, e, t, s = 0.5, r = Number.NEGATIVE_INFINITY, o = !1) {
1507
+ const a = l(n, "boxes", "nonMaxSuppressionAsync"), i = l(e, "scores", "nonMaxSuppressionAsync"), u = en(
1508
+ a,
1509
+ i,
1510
+ t,
1511
+ s,
1512
+ r,
1513
+ null
1514
+ /* softNmsSigma */
1515
+ ), c = u.maxOutputSize, m = u.iouThreshold, h = u.scoreThreshold, [b, g] = await Promise.all([a.data(), i.data()]), { selectedIndices: x, validOutputs: w } = Ps(b, g, c, m, h, o);
1516
+ return a !== n && a.dispose(), i !== e && i.dispose(), {
1517
+ selectedIndices: V(x, "int32"),
1518
+ validOutputs: Ce(w, "int32")
1519
+ };
1520
+ }
1521
+ const Ws = Js;
1522
+ /**
1523
+ * @license
1524
+ * Copyright 2020 Google LLC. All Rights Reserved.
1525
+ * Licensed under the Apache License, Version 2.0 (the "License");
1526
+ * you may not use this file except in compliance with the License.
1527
+ * You may obtain a copy of the License at
1528
+ *
1529
+ * http://www.apache.org/licenses/LICENSE-2.0
1530
+ *
1531
+ * Unless required by applicable law or agreed to in writing, software
1532
+ * distributed under the License is distributed on an "AS IS" BASIS,
1533
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1534
+ * See the License for the specific language governing permissions and
1535
+ * limitations under the License.
1536
+ * =============================================================================
1537
+ */
1538
+ function Ys(n, e, t = !1, s = !1) {
1539
+ const r = l(n, "images", "resizeBilinear");
1540
+ f(r.rank === 3 || r.rank === 4, () => `Error in resizeBilinear: x must be rank 3 or 4, but got rank ${r.rank}.`), f(e.length === 2, () => `Error in resizeBilinear: new shape must 2D, but got shape ${e}.`), f(s === !1 || t === !1, () => "Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false.");
1541
+ let o = r, a = !1;
1542
+ r.rank === 3 && (a = !0, o = $(r, [1, r.shape[0], r.shape[1], r.shape[2]]));
1543
+ const i = { images: o }, u = { alignCorners: t, halfPixelCenters: s, size: e }, c = d.runKernel(ze, i, u);
1544
+ return a ? $(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
1545
+ }
1546
+ const Xs = /* @__PURE__ */ p({ resizeBilinear_: Ys });
1547
+ /**
1548
+ * @license
1549
+ * Copyright 2020 Google LLC. All Rights Reserved.
1550
+ * Licensed under the Apache License, Version 2.0 (the "License");
1551
+ * you may not use this file except in compliance with the License.
1552
+ * You may obtain a copy of the License at
1553
+ *
1554
+ * http://www.apache.org/licenses/LICENSE-2.0
1555
+ *
1556
+ * Unless required by applicable law or agreed to in writing, software
1557
+ * distributed under the License is distributed on an "AS IS" BASIS,
1558
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1559
+ * See the License for the specific language governing permissions and
1560
+ * limitations under the License.
1561
+ * =============================================================================
1562
+ */
1563
+ function Zs(n, e, t = !1, s = !1) {
1564
+ const r = l(n, "images", "resizeNearestNeighbor");
1565
+ f(r.rank === 3 || r.rank === 4, () => `Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank ${r.rank}.`), f(e.length === 2, () => `Error in resizeNearestNeighbor: new shape must 2D, but got shape ${e}.`), f(r.dtype === "float32" || r.dtype === "int32", () => "`images` must have `int32` or `float32` as dtype"), f(s === !1 || t === !1, () => "Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false.");
1566
+ let o = r, a = !1;
1567
+ r.rank === 3 && (a = !0, o = $(r, [1, r.shape[0], r.shape[1], r.shape[2]]));
1568
+ const i = { images: o }, u = { alignCorners: t, halfPixelCenters: s, size: e }, c = d.runKernel(Ue, i, u);
1569
+ return a ? $(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
1570
+ }
1571
+ const Hs = /* @__PURE__ */ p({ resizeNearestNeighbor_: Zs });
1572
+ /**
1573
+ * @license
1574
+ * Copyright 2021 Google LLC. All Rights Reserved.
1575
+ * Licensed under the Apache License, Version 2.0 (the "License");
1576
+ * you may not use this file except in compliance with the License.
1577
+ * You may obtain a copy of the License at
1578
+ *
1579
+ * https://www.apache.org/licenses/LICENSE-2.0
1580
+ *
1581
+ * Unless required by applicable law or agreed to in writing, software
1582
+ * distributed under the License is distributed on an "AS IS" BASIS,
1583
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1584
+ * See the License for the specific language governing permissions and
1585
+ * limitations under the License.
1586
+ * =============================================================================
1587
+ */
1588
+ function Qs(n, e = "binary", t = !1, s = 0.5) {
1589
+ const r = l(n, "image", "threshold"), o = 0.2989, a = 0.587, i = 0.114, u = r.shape[0] * r.shape[1];
1590
+ let c = A(V([s]), 255), m, h, b, g;
1591
+ if (f(r.rank === 3, () => `Error in threshold: image must be rank 3,but got rank ${r.rank}.`), f(r.shape[2] === 3 || r.shape[2] === 1, () => `Error in threshold: image color channel must be equal to 3 or 1but got ${r.shape[2]}.`), f(r.dtype === "int32" || r.dtype === "float32", () => `Error in dtype: image dtype must be int32 or float32,but got dtype ${r.dtype}.`), f(e === "otsu" || e === "binary", () => `Method must be binary or otsu, but was ${e}`), r.shape[2] === 3) {
1592
+ [m, h, b] = Un(r, [1, 1, 1], -1);
1593
+ const k = A(m, o), E = A(h, a), T = A(b, i);
1594
+ g = C(C(k, E), T);
1595
+ } else
1596
+ g = n;
1597
+ if (e === "otsu") {
1598
+ const k = ot(L(Qt(g), "int32"), Ze([]), 256);
1599
+ c = nr(k, u);
1600
+ }
1601
+ const x = t ? Xn(g, c) : En(g, c);
1602
+ return L(A(x, 255), "int32");
1603
+ }
1604
+ function nr(n, e) {
1605
+ let t = V([-1]), s = V([0]), r = V([0]), o, a, i, u, c, m;
1606
+ for (let h = 0; h < n.size - 1; h++) {
1607
+ o = I(n, 0, h + 1), a = I(n, h + 1), c = K(j(o), e), m = K(j(a), e);
1608
+ const b = j(A(o, ln(0, o.size)));
1609
+ i = K(b, j(o));
1610
+ const g = Cn(a.shape, o.size), x = C(ln(0, a.size), g), w = A(a, x);
1611
+ u = K(j(w), j(a));
1612
+ const k = R(i, u), E = R(i, u), T = A(c, m);
1613
+ r = A(A(T, k), E);
1614
+ const S = En(r, s);
1615
+ s = nn(S, r, s), t = nn(S, V([h]), t);
1616
+ }
1617
+ return t;
1618
+ }
1619
+ const er = /* @__PURE__ */ p({ threshold_: Qs });
1620
+ /**
1621
+ * @license
1622
+ * Copyright 2021 Google LLC. All Rights Reserved.
1623
+ * Licensed under the Apache License, Version 2.0 (the "License");
1624
+ * you may not use this file except in compliance with the License.
1625
+ * You may obtain a copy of the License at
1626
+ *
1627
+ * http://www.apache.org/licenses/LICENSE-2.0
1628
+ *
1629
+ * Unless required by applicable law or agreed to in writing, software
1630
+ * distributed under the License is distributed on an "AS IS" BASIS,
1631
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1632
+ * See the License for the specific language governing permissions and
1633
+ * limitations under the License.
1634
+ * =============================================================================
1635
+ */
1636
+ function tr(n, e, t = "nearest", s = "constant", r = 0, o) {
1637
+ const a = l(n, "image", "transform", "float32"), i = l(e, "transforms", "transform", "float32");
1638
+ f(a.rank === 4, () => `Error in transform: image must be rank 4,but got rank ${a.rank}.`), f(i.rank === 2 && (i.shape[0] === a.shape[0] || i.shape[0] === 1) && i.shape[1] === 8, () => "Error in transform: Input transform should be batch x 8 or 1 x 8"), f(o == null || o.length === 2, () => `Error in transform: outputShape must be [height, width] or null, but got ${o}.`);
1639
+ const u = { image: a, transforms: i }, c = { interpolation: t, fillMode: s, fillValue: r, outputShape: o };
1640
+ return d.runKernel(Je, u, c);
1641
+ }
1642
+ const sr = /* @__PURE__ */ p({ transform_: tr });
1643
+ /**
1644
+ * @license
1645
+ * Copyright 2020 Google LLC. All Rights Reserved.
1646
+ * Licensed under the Apache License, Version 2.0 (the "License");
1647
+ * you may not use this file except in compliance with the License.
1648
+ * You may obtain a copy of the License at
1649
+ *
1650
+ * http://www.apache.org/licenses/LICENSE-2.0
1651
+ *
1652
+ * Unless required by applicable law or agreed to in writing, software
1653
+ * distributed under the License is distributed on an "AS IS" BASIS,
1654
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1655
+ * See the License for the specific language governing permissions and
1656
+ * limitations under the License.
1657
+ * =============================================================================
1658
+ */
1659
+ function rr(n, e, t) {
1660
+ const s = l(n, "a", "bandPart");
1661
+ f(s.rank >= 2, () => `bandPart(): Rank must be at least 2, got ${s.rank}.`);
1662
+ const r = s.shape, [o, a] = s.shape.slice(-2);
1663
+ let i, u;
1664
+ typeof e == "number" ? (f(e % 1 === 0, () => `bandPart(): numLower must be an integer, got ${e}.`), f(e <= o, () => `bandPart(): numLower (${e}) must not be greater than the number of rows (${o}).`), i = l(e < 0 ? o : e, "numLower", "bandPart")) : (f(e.dtype === "int32", () => "bandPart(): numLower's dtype must be an int32."), i = nn(Rn(e, 0), o, Kn(e, o))), typeof t == "number" ? (f(t % 1 === 0, () => `bandPart(): numUpper must be an integer, got ${t}.`), f(t <= a, () => `bandPart(): numUpper (${t}) must not be greater than the number of columns (${a}).`), u = l(t < 0 ? a : t, "numUpper", "bandPart")) : (f(t.dtype === "int32", () => "bandPart(): numUpper's dtype must be an int32."), u = nn(Rn(t, 0), a, Kn(t, a)));
1665
+ const c = $(ln(0, o, 1, "int32"), [-1, 1]), m = ln(0, a, 1, "int32"), h = R(c, m), b = Bt(Xn(h, i), Tt(h, Tn(u))), g = Qe([o, a], s.dtype);
1666
+ return $(fn(Hn($(s, [-1, o, a])).map((x) => nn(b, x, g))), r);
1667
+ }
1668
+ const or = /* @__PURE__ */ p({ bandPart_: rr });
1669
+ /**
1670
+ * @license
1671
+ * Copyright 2020 Google LLC. All Rights Reserved.
1672
+ * Licensed under the Apache License, Version 2.0 (the "License");
1673
+ * you may not use this file except in compliance with the License.
1674
+ * You may obtain a copy of the License at
1675
+ *
1676
+ * http://www.apache.org/licenses/LICENSE-2.0
1677
+ *
1678
+ * Unless required by applicable law or agreed to in writing, software
1679
+ * distributed under the License is distributed on an "AS IS" BASIS,
1680
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1681
+ * See the License for the specific language governing permissions and
1682
+ * limitations under the License.
1683
+ * =============================================================================
1684
+ */
1685
+ function ar(n) {
1686
+ let e;
1687
+ if (Array.isArray(n)) {
1688
+ e = !1, f(n != null && n.length > 0, () => "Gram-Schmidt process: input must not be null, undefined, or empty");
1689
+ const r = n[0].shape[0];
1690
+ for (let o = 1; o < n.length; ++o)
1691
+ f(n[o].shape[0] === r, () => `Gram-Schmidt: Non-unique lengths found in the input vectors: (${n[o].shape[0]} vs. ${r})`);
1692
+ } else
1693
+ e = !0, n = Un(n, n.shape[0], 0).map((r) => os(r, [0]));
1694
+ f(n.length <= n[0].shape[0], () => `Gram-Schmidt: Number of vectors (${n.length}) exceeds number of dimensions (${n[0].shape[0]}).`);
1695
+ const t = [], s = n;
1696
+ for (let r = 0; r < n.length; ++r)
1697
+ t.push(d.tidy(() => {
1698
+ let o = s[r];
1699
+ if (r > 0)
1700
+ for (let a = 0; a < r; ++a) {
1701
+ const i = A(j(A(t[a], o)), t[a]);
1702
+ o = R(o, i);
1703
+ }
1704
+ return K(o, Jn(o, "euclidean"));
1705
+ }));
1706
+ return e ? fn(t, 0) : t;
1707
+ }
1708
+ const ir = /* @__PURE__ */ p({ gramSchmidt_: ar });
1709
+ /**
1710
+ * @license
1711
+ * Copyright 2020 Google LLC. All Rights Reserved.
1712
+ * Licensed under the Apache License, Version 2.0 (the "License");
1713
+ * you may not use this file except in compliance with the License.
1714
+ * You may obtain a copy of the License at
1715
+ *
1716
+ * http://www.apache.org/licenses/LICENSE-2.0
1717
+ *
1718
+ * Unless required by applicable law or agreed to in writing, software
1719
+ * distributed under the License is distributed on an "AS IS" BASIS,
1720
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1721
+ * See the License for the specific language governing permissions and
1722
+ * limitations under the License.
1723
+ * =============================================================================
1724
+ */
1725
+ function cr(n, e = !1) {
1726
+ if (f(n.rank >= 2, () => `qr() requires input tensor to have a rank >= 2, but got rank ${n.rank}`), n.rank === 2)
1727
+ return jn(n, e);
1728
+ {
1729
+ const t = n.shape.slice(0, n.shape.length - 2).reduce((u, c) => u * c), s = Hn($(n, [
1730
+ t,
1731
+ n.shape[n.shape.length - 2],
1732
+ n.shape[n.shape.length - 1]
1733
+ ]), 0), r = [], o = [];
1734
+ s.forEach((u) => {
1735
+ const [c, m] = jn(u, e);
1736
+ r.push(c), o.push(m);
1737
+ });
1738
+ const a = $(fn(r, 0), n.shape), i = $(fn(o, 0), n.shape);
1739
+ return [a, i];
1740
+ }
1741
+ }
1742
+ function jn(n, e = !1) {
1743
+ return d.tidy(() => {
1744
+ f(n.shape.length === 2, () => `qr2d() requires a 2D Tensor, but got a ${n.shape.length}D Tensor.`);
1745
+ const t = n.shape[0], s = n.shape[1];
1746
+ let r = yt(t), o = mn(n);
1747
+ const a = $n([[1]], [1, 1]);
1748
+ let i = mn(a);
1749
+ const u = t >= s ? s : t;
1750
+ for (let c = 0; c < u; ++c) {
1751
+ const m = o, h = i, b = r;
1752
+ [i, o, r] = d.tidy(() => {
1753
+ const g = I(o, [c, c], [t - c, 1]), x = Jn(g), w = I(o, [c, c], [1, 1]), k = nn(En(w, 0), $n([[-1]]), $n([[1]])), E = R(w, A(k, x)), T = K(g, E);
1754
+ T.shape[0] === 1 ? i = mn(a) : i = G([
1755
+ a,
1756
+ I(T, [1, 0], [T.shape[0] - 1, T.shape[1]])
1757
+ ], 0);
1758
+ const S = Tn(K(_(k, E), x)), M = I(o, [c, 0], [t - c, s]), O = A(S, i), N = wn(i);
1759
+ if (c === 0)
1760
+ o = R(M, _(O, _(N, M)));
1761
+ else {
1762
+ const X = R(M, _(O, _(N, M)));
1763
+ o = G([I(o, [0, 0], [c, s]), X], 0);
1764
+ }
1765
+ const tn = wn(O), z = I(r, [0, c], [t, r.shape[1] - c]);
1766
+ if (c === 0)
1767
+ r = R(z, _(_(z, i), tn));
1768
+ else {
1769
+ const X = R(z, _(_(z, i), tn));
1770
+ r = G([I(r, [0, 0], [t, c]), X], 1);
1771
+ }
1772
+ return [i, o, r];
1773
+ }), We([m, h, b]);
1774
+ }
1775
+ return !e && t > s && (r = I(r, [0, 0], [t, s]), o = I(o, [0, 0], [s, s])), [r, o];
1776
+ });
1777
+ }
1778
+ const ur = /* @__PURE__ */ p({ qr_: cr });
1779
+ /**
1780
+ * @license
1781
+ * Copyright 2020 Google LLC. All Rights Reserved.
1782
+ * Licensed under the Apache License, Version 2.0 (the "License");
1783
+ * you may not use this file except in compliance with the License.
1784
+ * You may obtain a copy of the License at
1785
+ *
1786
+ * http://www.apache.org/licenses/LICENSE-2.0
1787
+ *
1788
+ * Unless required by applicable law or agreed to in writing, software
1789
+ * distributed under the License is distributed on an "AS IS" BASIS,
1790
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1791
+ * See the License for the specific language governing permissions and
1792
+ * limitations under the License.
1793
+ * =============================================================================
1794
+ */
1795
+ const Br = {
1796
+ flipLeftRight: ws,
1797
+ grayscaleToRGB: _s,
1798
+ resizeNearestNeighbor: Hs,
1799
+ resizeBilinear: Xs,
1800
+ rgbToGrayscale: Is,
1801
+ rotateWithOffset: Ts,
1802
+ cropAndResize: ks,
1803
+ nonMaxSuppression: Ns,
1804
+ nonMaxSuppressionAsync: Fs,
1805
+ nonMaxSuppressionWithScore: Gs,
1806
+ nonMaxSuppressionWithScoreAsync: Cs,
1807
+ nonMaxSuppressionPadded: Us,
1808
+ nonMaxSuppressionPaddedAsync: Ws,
1809
+ threshold: er,
1810
+ transform: sr
1811
+ }, Rr = {
1812
+ bandPart: or,
1813
+ gramSchmidt: ir,
1814
+ qr: ur
1815
+ };
1816
+ /**
1817
+ * @license
1818
+ * Copyright 2018 Google LLC
1819
+ *
1820
+ * Use of this source code is governed by an MIT-style
1821
+ * license that can be found in the LICENSE file or at
1822
+ * https://opensource.org/licenses/MIT.
1823
+ * =============================================================================
1824
+ */
1825
+ const lr = ["channelsFirst", "channelsLast"], fr = ["nearest", "bilinear"], pr = ["valid", "same", "causal"], hr = ["max", "avg"], Kr = ["sum", "mul", "concat", "ave"];
1826
+ /**
1827
+ * @license
1828
+ * Copyright 2018 Google LLC
1829
+ *
1830
+ * Use of this source code is governed by an MIT-style
1831
+ * license that can be found in the LICENSE file or at
1832
+ * https://opensource.org/licenses/MIT.
1833
+ * =============================================================================
1834
+ */
1835
+ class Qn extends Error {
1836
+ constructor(e) {
1837
+ super(e), Object.setPrototypeOf(this, Qn.prototype);
1838
+ }
1839
+ }
1840
+ class ne extends Error {
1841
+ constructor(e) {
1842
+ super(e), Object.setPrototypeOf(this, ne.prototype);
1843
+ }
1844
+ }
1845
+ class y extends Error {
1846
+ constructor(e) {
1847
+ super(e), Object.setPrototypeOf(this, y.prototype);
1848
+ }
1849
+ }
1850
+ class cn extends Error {
1851
+ constructor(e) {
1852
+ super(e), Object.setPrototypeOf(this, cn.prototype);
1853
+ }
1854
+ }
1855
+ class Mn extends Error {
1856
+ constructor(e) {
1857
+ super(e), Object.setPrototypeOf(this, Mn.prototype);
1858
+ }
1859
+ }
1860
+ /**
1861
+ * @license
1862
+ * Copyright 2018 Google LLC
1863
+ *
1864
+ * Use of this source code is governed by an MIT-style
1865
+ * license that can be found in the LICENSE file or at
1866
+ * https://opensource.org/licenses/MIT.
1867
+ * =============================================================================
1868
+ */
1869
+ function qr(n, e) {
1870
+ if (Array.isArray(n)) {
1871
+ let t = [];
1872
+ for (let s = 0; s < e; s++)
1873
+ t = t.concat(n);
1874
+ return t;
1875
+ } else {
1876
+ const t = new Array(e);
1877
+ return t.fill(n), t;
1878
+ }
1879
+ }
1880
+ function Gn(n, e) {
1881
+ if (!n)
1882
+ throw new Mn(e);
1883
+ }
1884
+ function Fr(n, e) {
1885
+ let t = 0;
1886
+ for (const s of n)
1887
+ s === e && t++;
1888
+ return t;
1889
+ }
1890
+ function jr(n) {
1891
+ return n.length === 1 ? n[0] : n;
1892
+ }
1893
+ function Gr(n) {
1894
+ return Array.isArray(n) ? n : [n];
1895
+ }
1896
+ function Lr(n) {
1897
+ const t = n.replace(/(.)([A-Z][a-z0-9]+)/g, "$1_$2").replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
1898
+ return t[0] !== "_" ? t : "private" + t;
1899
+ }
1900
+ function Cr(n) {
1901
+ return n.length <= 1 || n.indexOf("_") === -1 ? n : n.replace(/[_]+(\w|$)/g, (e, t) => t.toUpperCase());
1902
+ }
1903
+ let D = {};
1904
+ function zr(n) {
1905
+ if (n == null)
1906
+ return null;
1907
+ const e = {};
1908
+ return e.className = n.getClassName(), e.config = n.getConfig(), e;
1909
+ }
1910
+ function yn(n) {
1911
+ if (!(n == null || typeof n != "object"))
1912
+ if (Array.isArray(n))
1913
+ n.forEach((e) => yn(e));
1914
+ else {
1915
+ const e = Object.keys(n);
1916
+ for (const t of e) {
1917
+ const s = n[t];
1918
+ s != null && typeof s == "object" && (!Array.isArray(s) && s.type === "ndarray" && typeof s.value == "number" ? n[t] = s.value : yn(s));
1919
+ }
1920
+ }
1921
+ }
1922
+ function Ur(n, e = {}, t = {}, s = "object", r = !1) {
1923
+ if (typeof n == "string") {
1924
+ const o = n;
1925
+ let a;
1926
+ if (o in t)
1927
+ a = t[o];
1928
+ else if (o in D)
1929
+ a = D[o];
1930
+ else if (a = e[o], a == null)
1931
+ throw new y(`Unknown ${s}: ${n}. This may be due to one of the following reasons:
1932
+ 1. The ${s} is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
1933
+ 2. The custom ${s} is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().`);
1934
+ return a;
1935
+ } else {
1936
+ const o = n;
1937
+ if (o.className == null || o.config == null)
1938
+ throw new y(`${s}: Improper config format: ${JSON.stringify(o)}.
1939
+ 'className' and 'config' must set.`);
1940
+ const a = o.className;
1941
+ let i, u;
1942
+ if (a in t ? [i, u] = t[a] : a in D ? [i, u] = D.className : a in e && ([i, u] = e[a]), i == null)
1943
+ throw new y(`Unknown ${s}: ${a}. This may be due to one of the following reasons:
1944
+ 1. The ${s} is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
1945
+ 2. The custom ${s} is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().`);
1946
+ if (u != null) {
1947
+ const c = {};
1948
+ for (const g of Object.keys(D))
1949
+ c[g] = D[g];
1950
+ for (const g of Object.keys(t))
1951
+ c[g] = t[g];
1952
+ const m = o.config;
1953
+ m.customObjects = c;
1954
+ const h = Object.assign({}, D);
1955
+ for (const g of Object.keys(t))
1956
+ D[g] = t[g];
1957
+ yn(o.config);
1958
+ const b = u(i, o.config, t, r);
1959
+ return D = Object.assign({}, h), b;
1960
+ } else {
1961
+ const c = Object.assign({}, D);
1962
+ for (const h of Object.keys(t))
1963
+ D[h] = t[h];
1964
+ const m = new i(o.config);
1965
+ return D = Object.assign({}, c), m;
1966
+ }
1967
+ }
1968
+ }
1969
+ function dr(n, e) {
1970
+ return n < e ? -1 : n > e ? 1 : 0;
1971
+ }
1972
+ function Jr(n, e) {
1973
+ return -1 * dr(n, e);
1974
+ }
1975
+ function Wr(n) {
1976
+ if (n == null)
1977
+ return n;
1978
+ const e = [];
1979
+ for (const t of n)
1980
+ e.indexOf(t) === -1 && e.push(t);
1981
+ return e;
1982
+ }
1983
+ function Yr(n) {
1984
+ if (n == null)
1985
+ throw new y(`Invalid value in obj: ${JSON.stringify(n)}`);
1986
+ for (const e in n)
1987
+ if (n.hasOwnProperty(e))
1988
+ return !1;
1989
+ return !0;
1990
+ }
1991
+ function hn(n, e, t) {
1992
+ if (t != null && n.indexOf(t) < 0)
1993
+ throw new y(`${t} is not a valid ${e}. Valid values are ${n} or null/undefined.`);
1994
+ }
1995
+ function Xr(n, e, t = 0, s = 1 / 0) {
1996
+ return Gn(t >= 0), Gn(s >= t), Array.isArray(n) && n.length >= t && n.length <= s && n.every((r) => typeof r === e);
1997
+ }
1998
+ function mr(n, e) {
1999
+ Array.isArray(n) ? (f(n.length > 0, () => `${e} is unexpectedly an empty array.`), n.forEach((t, s) => mr(t, `element ${s + 1} of ${e}`))) : f(Number.isInteger(n) && n > 0, () => `Expected ${e} to be a positive integer, but got ${ee(n)}.`);
2000
+ }
2001
+ function ee(n) {
2002
+ return n === null ? "null" : Array.isArray(n) ? "[" + n.map((e) => ee(e)).join(",") + "]" : typeof n == "string" ? `"${n}"` : `${n}`;
2003
+ }
2004
+ function Zr(n, e, t) {
2005
+ let s = t != null ? t() : Bn(), r;
2006
+ return (...a) => {
2007
+ const i = t != null ? t() : Bn();
2008
+ return i - s < e || (s = i, r = n(...a)), r;
2009
+ };
2010
+ }
2011
+ function Hr(n) {
2012
+ return n === "relu" ? "relu" : n === "linear" ? "linear" : n === "elu" ? "elu" : null;
2013
+ }
2014
+ /**
2015
+ * @license
2016
+ * Copyright 2018 Google LLC
2017
+ *
2018
+ * Use of this source code is governed by an MIT-style
2019
+ * license that can be found in the LICENSE file or at
2020
+ * https://opensource.org/licenses/MIT.
2021
+ * =============================================================================
2022
+ */
2023
+ const Q = /* @__PURE__ */ new Map();
2024
+ function gr(n) {
2025
+ hn(lr, "DataFormat", n);
2026
+ }
2027
+ function Qr(n) {
2028
+ hn(fr, "InterpolationFormat", n);
2029
+ }
2030
+ function no(n) {
2031
+ hn(pr, "PaddingMode", n);
2032
+ }
2033
+ function eo(n) {
2034
+ hn(hr, "PoolMode", n);
2035
+ }
2036
+ const an = [], Ln = "/";
2037
+ function to(n, e) {
2038
+ an.push(n);
2039
+ try {
2040
+ const t = e();
2041
+ return an.pop(), t;
2042
+ } catch (t) {
2043
+ throw an.pop(), t;
2044
+ }
2045
+ }
2046
+ function $r() {
2047
+ return an.length === 0 ? "" : an.join(Ln) + Ln;
2048
+ }
2049
+ function so(n) {
2050
+ if (!te(n))
2051
+ throw new Error("Not a valid tensor name: '" + n + "'");
2052
+ return $r() + n;
2053
+ }
2054
+ function ro(n) {
2055
+ if (!te(n))
2056
+ throw new Error("Not a valid tensor name: '" + n + "'");
2057
+ Q.has(n) || Q.set(n, 0);
2058
+ const e = Q.get(n);
2059
+ if (Q.set(n, Q.get(n) + 1), e > 0) {
2060
+ const t = `${n}_${e}`;
2061
+ return Q.set(t, 1), t;
2062
+ } else
2063
+ return n;
2064
+ }
2065
+ const br = new RegExp(/^[A-Za-z0-9][-A-Za-z0-9\._\/]*$/);
2066
+ function te(n) {
2067
+ return !!n.match(br);
2068
+ }
2069
+ /**
2070
+ * @license
2071
+ * Copyright 2018 Google LLC
2072
+ *
2073
+ * Use of this source code is governed by an MIT-style
2074
+ * license that can be found in the LICENSE file or at
2075
+ * https://opensource.org/licenses/MIT.
2076
+ * =============================================================================
2077
+ */
2078
+ function oo(n) {
2079
+ return n === parseInt(n.toString(), 10);
2080
+ }
2081
+ function se(n, e, t) {
2082
+ e == null && (e = 0), t == null && (t = n.length);
2083
+ let s = 1;
2084
+ for (let r = e; r < t; ++r)
2085
+ s *= n[r];
2086
+ return s;
2087
+ }
2088
+ function ao(n) {
2089
+ if (n.length === 0)
2090
+ return Number.NaN;
2091
+ let e = Number.POSITIVE_INFINITY;
2092
+ for (let t = 0; t < n.length; t++) {
2093
+ const s = n[t];
2094
+ s < e && (e = s);
2095
+ }
2096
+ return e;
2097
+ }
2098
+ function io(n) {
2099
+ if (n.length === 0)
2100
+ return Number.NaN;
2101
+ let e = Number.NEGATIVE_INFINITY;
2102
+ for (let t = 0; t < n.length; t++) {
2103
+ const s = n[t];
2104
+ s > e && (e = s);
2105
+ }
2106
+ return e;
2107
+ }
2108
+ function co(n, e) {
2109
+ if (e < n)
2110
+ throw new y(`end (${e}) < begin (${n}) is forbidden.`);
2111
+ const t = [];
2112
+ for (let s = n; s < e; ++s)
2113
+ t.push(s);
2114
+ return t;
2115
+ }
2116
+ /**
2117
+ * @license
2118
+ * Copyright 2018 Google LLC
2119
+ *
2120
+ * Use of this source code is governed by an MIT-style
2121
+ * license that can be found in the LICENSE file or at
2122
+ * https://opensource.org/licenses/MIT.
2123
+ * =============================================================================
2124
+ */
2125
+ let bn;
2126
+ function uo() {
2127
+ return bn == null && (bn = Ye().epsilon()), bn;
2128
+ }
2129
+ function _n() {
2130
+ return "channelsLast";
2131
+ }
2132
+ /**
2133
+ * @license
2134
+ * Copyright 2018 Google LLC
2135
+ *
2136
+ * Use of this source code is governed by an MIT-style
2137
+ * license that can be found in the LICENSE file or at
2138
+ * https://opensource.org/licenses/MIT.
2139
+ * =============================================================================
2140
+ */
2141
+ function lo(n, e) {
2142
+ return L(n, e);
2143
+ }
2144
+ function kr(n, e = -1) {
2145
+ const t = n.shape.slice();
2146
+ return e < 0 && (e = t.length + e + 1), t.splice(e, 0, 1), $(n, t);
2147
+ }
2148
+ function fo(n, e) {
2149
+ return P(() => {
2150
+ if (n.shape.length !== 2)
2151
+ throw new y(`repeat() expects a rank-2 tensor, but received a rank-${n.shape.length} tensor.`);
2152
+ const t = kr(n, 1);
2153
+ return xr(t, [1, e, 1]);
2154
+ });
2155
+ }
2156
+ function po(n) {
2157
+ const e = [se(n.shape)];
2158
+ return $(n, e);
2159
+ }
2160
+ function ho(n) {
2161
+ if (n.rank <= 1)
2162
+ throw new y(`batchFlatten requires a minimum rank of 2. Got rank: ${n.rank}.`);
2163
+ const e = [n.shape[0], se(n.shape, 1)];
2164
+ return $(n, e);
2165
+ }
2166
+ function kn(n, e, t) {
2167
+ return P(() => {
2168
+ switch (n.rank) {
2169
+ case 1:
2170
+ return Sn(n, e, t);
2171
+ case 2:
2172
+ return Zn(n, [e, 0], [t, n.shape[1]]);
2173
+ case 3:
2174
+ return Nn(n, [e, 0, 0], [t, n.shape[1], n.shape[2]]);
2175
+ case 4:
2176
+ return pn(n, [e, 0, 0, 0], [t, n.shape[1], n.shape[2], n.shape[3]]);
2177
+ case 5:
2178
+ return I(n, [e, 0, 0, 0, 0], [
2179
+ t,
2180
+ n.shape[1],
2181
+ n.shape[2],
2182
+ n.shape[3],
2183
+ n.shape[4]
2184
+ ]);
2185
+ case 6:
2186
+ return I(n, [e, 0, 0, 0, 0, 0], [
2187
+ t,
2188
+ n.shape[1],
2189
+ n.shape[2],
2190
+ n.shape[3],
2191
+ n.shape[4],
2192
+ n.shape[5]
2193
+ ]);
2194
+ default:
2195
+ throw new y(`sliceAlongFirstAxis() received an unsupported tensor rank: ${n.rank}`);
2196
+ }
2197
+ });
2198
+ }
2199
+ function xn(n, e, t) {
2200
+ return P(() => {
2201
+ switch (n.rank) {
2202
+ case 1:
2203
+ return Sn(n, e, t);
2204
+ case 2:
2205
+ return Zn(n, [0, e], [n.shape[0], t]);
2206
+ case 3:
2207
+ return Nn(n, [0, 0, e], [n.shape[0], n.shape[1], t]);
2208
+ case 4:
2209
+ return pn(n, [0, 0, 0, e], [n.shape[0], n.shape[1], n.shape[2], t]);
2210
+ default:
2211
+ throw new y(`sliceAlongLastAxis() received an unsupported tensor rank: ${n.rank}`);
2212
+ }
2213
+ });
2214
+ }
2215
+ function mo(n, e, t, s) {
2216
+ return P(() => {
2217
+ switch (n.rank) {
2218
+ case 1:
2219
+ return Sn(n, e, t);
2220
+ case 2:
2221
+ switch (s) {
2222
+ case 1:
2223
+ return kn(n, e, t);
2224
+ case 2:
2225
+ return xn(n, e, t);
2226
+ default:
2227
+ throw new y(`The axis is not within the rank of the tensor ${s}`);
2228
+ }
2229
+ case 3:
2230
+ switch (s) {
2231
+ case 1:
2232
+ return kn(n, e, t);
2233
+ case 2:
2234
+ return Nn(n, [0, e, 0], [n.shape[0], t, n.shape[2]]);
2235
+ case 3:
2236
+ return xn(n, e, t);
2237
+ default:
2238
+ throw new y(`The axis is not within the rank of the tensor ${s}`);
2239
+ }
2240
+ case 4:
2241
+ switch (s) {
2242
+ case 1:
2243
+ return kn(n, e, t);
2244
+ case 2:
2245
+ return pn(n, [0, e, 0, 0], [n.shape[0], t, n.shape[2], n.shape[3]]);
2246
+ case 3:
2247
+ return pn(n, [0, 0, e, 0], [n.shape[0], n.shape[1], t, n.shape[3]]);
2248
+ case 4:
2249
+ return xn(n, e, t);
2250
+ default:
2251
+ throw new y(`The axis is not within the rank of the tensor ${s}`);
2252
+ }
2253
+ default:
2254
+ throw new y(`sliceAlongLastAxis() received an unsupported tensor rank: ${n.rank}`);
2255
+ }
2256
+ });
2257
+ }
2258
+ function go(n, e = -1) {
2259
+ let t;
2260
+ return e < 0 && (t = n[0].rank, t !== 0 ? e = t : e = 0), e === n[0].rank && (e = -1), G(n, e);
2261
+ }
2262
+ function $o(n, e) {
2263
+ switch (n.rank) {
2264
+ case 1:
2265
+ return ut([n, e]);
2266
+ case 2:
2267
+ return ft([n, e], 0);
2268
+ case 3:
2269
+ return ht([n, e], 0);
2270
+ case 4:
2271
+ return mt([n, e], 0);
2272
+ default:
2273
+ throw new y(`concatAlongFirstAxis() received an unsupported tensor rank: ${n.rank}`);
2274
+ }
2275
+ }
2276
+ function xr(n, e) {
2277
+ if (Array.isArray(e) || (e = [e]), n.rank !== e.length)
2278
+ throw new y(`The length of input n (${e.length}) does not match the number of dimensions in input x (${n.rank})`);
2279
+ return on(n, e);
2280
+ }
2281
+ function bo(n, e = 0, t = 1, s, r) {
2282
+ return Lt(n, e, t, s, r);
2283
+ }
2284
+ function ko(n, e, t, s) {
2285
+ if (n.rank < 2 || e.rank < 2)
2286
+ throw new cn(`dot requires both inputs to be rank >= 2 but got x shape = ${n.shape} and y shape = ${e.shape}`);
2287
+ if (e.rank >= 3) {
2288
+ const r = n.shape.slice(-1)[0], o = e.shape.slice(-2)[0];
2289
+ if (r !== o)
2290
+ throw new cn(`If rank y >= 3, then the second last dim of y must equal the last dim of x but got x shape = ${n.shape} and y shape = ${e.shape}`);
2291
+ }
2292
+ if (n.rank === 2 && e.rank === 2)
2293
+ return qn({
2294
+ a: n,
2295
+ b: e,
2296
+ transposeA: !1,
2297
+ transposeB: !1,
2298
+ bias: s ? An(n.rank, s, _n()) : null,
2299
+ activation: t
2300
+ });
2301
+ {
2302
+ const r = n.shape.slice(), o = r.pop();
2303
+ n = $(n, [-1, o]);
2304
+ const a = e.shape.slice(), i = a.pop(), u = a.pop(), c = [...a, i], m = Array.from({ length: e.rank }, (x, w) => w === 0 ? e.rank - 2 : w <= e.rank - 2 ? w - 1 : w);
2305
+ e = $(wn(e, m), [u, -1]);
2306
+ const h = [...r, ...c];
2307
+ return $(qn({
2308
+ a: n,
2309
+ b: e,
2310
+ transposeA: !1,
2311
+ transposeB: !1,
2312
+ bias: s ? An(n.rank, s, _n()) : null,
2313
+ activation: t
2314
+ }), h);
2315
+ }
2316
+ }
2317
+ function xo(n, e, t) {
2318
+ return P(() => (Array.isArray(e) ? e = V(e, "int32") : e = L(e, "int32"), nt(n, e, t)));
2319
+ }
2320
+ function wo(n) {
2321
+ return A(n, n);
2322
+ }
2323
+ function An(n, e, t) {
2324
+ const s = e.shape;
2325
+ if (e.rank !== 1 && e.rank !== n)
2326
+ throw new y(`Unexpected bias dimensions: ${e.rank}; expected it to be 1 or ${n}`);
2327
+ if (n === 5) {
2328
+ if (t === "channelsFirst")
2329
+ return s.length === 1 ? $(e, [1, s[0], 1, 1, 1]) : $(e, [1, s[3], s[0], s[1], s[2]]);
2330
+ if (t === "channelsLast")
2331
+ return s.length === 1 ? $(e, [1, 1, 1, 1, s[0]]) : $(e, [1].concat(s));
2332
+ } else if (n === 4) {
2333
+ if (t === "channelsFirst")
2334
+ return s.length === 1 ? $(e, [1, s[0], 1, 1]) : $(e, [1, s[2], s[0], s[1]]);
2335
+ if (t === "channelsLast")
2336
+ return s.length === 1 ? $(e, [1, 1, 1, s[0]]) : $(e, [1].concat(s));
2337
+ } else if (n === 3) {
2338
+ if (t === "channelsFirst")
2339
+ return s.length === 1 ? $(e, [1, s[0], 1]) : $(e, [1, s[1], s[0]]);
2340
+ if (t === "channelsLast")
2341
+ return s.length === 1 ? $(e, [1, 1, s[0]]) : $(e, [1].concat(s));
2342
+ } else if (n < 3)
2343
+ return e;
2344
+ throw new y(`Unsupported input rank by biasAdd: ${e.rank}`);
2345
+ }
2346
+ function yo(n, e, t) {
2347
+ return P(() => (t == null && (t = _n()), gr(t), C(n, An(n.rank, e, t))));
2348
+ }
2349
+ function _o(n, e = 1) {
2350
+ if (e !== 1)
2351
+ throw new cn(`Support for alpha values other than 1 (${e}) is not implemented yet.`);
2352
+ return Yn(n);
2353
+ }
2354
+ function Ao(n) {
2355
+ return P(() => K(n, C(Xe(n), 1)));
2356
+ }
2357
+ function Io(n, e, t, s) {
2358
+ return P(() => ps(n, e, t, s));
2359
+ }
2360
+ function Eo(n) {
2361
+ return P(() => {
2362
+ const e = C(0.5, A(0.2, n));
2363
+ return it(e, 0, 1);
2364
+ });
2365
+ }
2366
+ function To(n, e, t = !1) {
2367
+ return t ? n() : e();
2368
+ }
2369
+ export {
2370
+ Jr as $,
2371
+ Qn as A,
2372
+ Tt as B,
2373
+ Xn as C,
2374
+ wn as D,
2375
+ on as E,
2376
+ En as F,
2377
+ Rn as G,
2378
+ I as H,
2379
+ At as I,
2380
+ Hn as J,
2381
+ tt as K,
2382
+ W as L,
2383
+ Ft as M,
2384
+ cn as N,
2385
+ it as O,
2386
+ uo as P,
2387
+ Yt as Q,
2388
+ ne as R,
2389
+ Zr as S,
2390
+ po as T,
2391
+ wo as U,
2392
+ y as V,
2393
+ Gn as W,
2394
+ lo as X,
2395
+ os as Y,
2396
+ Cr as Z,
2397
+ Wr as _,
2398
+ ps as a,
2399
+ qr as a0,
2400
+ Yr as a1,
2401
+ V as a2,
2402
+ kn as a3,
2403
+ kr as a4,
2404
+ xo as a5,
2405
+ co as a6,
2406
+ Fr as a7,
2407
+ _o as a8,
2408
+ Kn as a9,
2409
+ Eo as aa,
2410
+ Ao as ab,
2411
+ Mt as ac,
2412
+ qt as ad,
2413
+ Yn as ae,
2414
+ io as af,
2415
+ oo as ag,
2416
+ Xr as ah,
2417
+ yo as ai,
2418
+ mo as aj,
2419
+ Qr as ak,
2420
+ Br as al,
2421
+ mr as am,
2422
+ Hr as an,
2423
+ no as ao,
2424
+ _n as ap,
2425
+ xr as aq,
2426
+ ao as ar,
2427
+ $o as as,
2428
+ To as at,
2429
+ Io as au,
2430
+ go as av,
2431
+ ho as aw,
2432
+ fo as ax,
2433
+ eo as ay,
2434
+ Kr as az,
2435
+ ms as b,
2436
+ ds as c,
2437
+ ko as d,
2438
+ yt as e,
2439
+ zt as f,
2440
+ hs as g,
2441
+ bo as h,
2442
+ hn as i,
2443
+ gr as j,
2444
+ se as k,
2445
+ Rr as l,
2446
+ Ur as m,
2447
+ zr as n,
2448
+ so as o,
2449
+ ro as p,
2450
+ jr as q,
2451
+ Lt as r,
2452
+ gs as s,
2453
+ Lr as t,
2454
+ Gr as u,
2455
+ to as v,
2456
+ nn as w,
2457
+ is as x,
2458
+ Tn as y,
2459
+ Bt as z
2460
+ };