@genai-fi/nanogpt 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist/Generator.js +11 -11
  2. package/dist/NanoGPTModel.d.ts +2 -2
  3. package/dist/NanoGPTModel.js +104 -136
  4. package/dist/{RealDiv-BYViZwhN.js → RealDiv-C4hOvYOZ.js} +26 -25
  5. package/dist/{Reshape-t7Kcikjk.js → Reshape-BLijOA8h.js} +5 -5
  6. package/dist/TeachableLLM.d.ts +3 -0
  7. package/dist/TeachableLLM.js +50 -47
  8. package/dist/{TiedEmbedding-9WeDwvjO.js → TiedEmbedding-BLltddza.js} +4 -4
  9. package/dist/{axis_util-Bu4h7XWV.js → axis_util-DaAl5MER.js} +3 -3
  10. package/dist/backend.d.ts +1 -0
  11. package/dist/backend.js +7 -0
  12. package/dist/backend_util-DWiwsi2N.js +749 -0
  13. package/dist/{broadcast_to-DARN-DBD.js → broadcast_to-C4v-j9yA.js} +2 -2
  14. package/dist/{concat-5aPGqw3Z.js → concat-CsHeR4zV.js} +8 -8
  15. package/dist/{dataset-pgqp-YfL.js → dataset-JDyjG3QR.js} +3 -3
  16. package/dist/{dropout-Bciw46HT.js → dropout-hpDwECTe.js} +7 -7
  17. package/dist/{gather-DjyCjmOD.js → gather-D0_gPiBz.js} +4 -4
  18. package/dist/gelu-uyHP1x1f.js +26 -0
  19. package/dist/gpgpu_math-DJm3ZTAf.js +2371 -0
  20. package/dist/index-BPPzKVdR.js +12099 -0
  21. package/dist/{index-BAzbokzv.js → index-C0dhsYom.js} +405 -389
  22. package/dist/{kernel_funcs_utils-CUxJCg0g.js → kernel_funcs_utils-CwRTFqrc.js} +31 -30
  23. package/dist/layers/BaseLayer.js +2 -2
  24. package/dist/layers/CausalSelfAttention.js +6 -6
  25. package/dist/layers/MLP.js +5 -5
  26. package/dist/layers/RMSNorm.js +3 -3
  27. package/dist/layers/RoPECache.js +4 -4
  28. package/dist/layers/TiedEmbedding.js +5 -5
  29. package/dist/layers/TransformerBlock.js +1 -1
  30. package/dist/loader/loadTransformers.js +1 -1
  31. package/dist/loader/oldZipLoad.js +5 -5
  32. package/dist/{log_sum_exp-YEo2h3gb.js → log_sum_exp-D086OgZJ.js} +15 -15
  33. package/dist/main.d.ts +2 -0
  34. package/dist/main.js +9 -5
  35. package/dist/{mat_mul-7121rsJk.js → mat_mul-1nwdPkQ_.js} +4 -4
  36. package/dist/{max-DtlIuVeW.js → max-BQc2Aj-I.js} +4 -4
  37. package/dist/{mulmat_packed_gpu-D4nKF7Je.js → mulmat_packed_gpu-Gzf3I9UV.js} +1 -1
  38. package/dist/non_max_suppression_impl-CsEgBuMA.js +134 -0
  39. package/dist/{ones-BBlSRqn1.js → ones-D63HpSF_.js} +2 -2
  40. package/dist/ops/appendCache.js +3 -3
  41. package/dist/ops/attentionMask.js +1 -1
  42. package/dist/ops/cpu/appendCache.js +8 -8
  43. package/dist/ops/cpu/attentionMask.js +9 -9
  44. package/dist/ops/cpu/fusedSoftmax.js +17 -11
  45. package/dist/ops/cpu/gatherSub.js +7 -7
  46. package/dist/ops/cpu/gelu.js +13 -13
  47. package/dist/ops/cpu/matMulGelu.js +36 -24
  48. package/dist/ops/cpu/matMulMul.js +14 -8
  49. package/dist/ops/cpu/mulDropout.js +9 -3
  50. package/dist/ops/cpu/normRMS.js +5 -5
  51. package/dist/ops/cpu/qkv.js +3 -3
  52. package/dist/ops/cpu/rope.js +5 -5
  53. package/dist/ops/cpu/scatterSub.js +11 -11
  54. package/dist/ops/fusedSoftmax.js +1 -1
  55. package/dist/ops/gatherSub.js +1 -1
  56. package/dist/ops/gelu.js +2 -2
  57. package/dist/ops/grads/attentionMask.js +1 -1
  58. package/dist/ops/grads/fusedSoftmax.js +2 -2
  59. package/dist/ops/grads/gelu.js +3 -24
  60. package/dist/ops/grads/matMulGelu.js +5 -5
  61. package/dist/ops/grads/normRMS.js +6 -6
  62. package/dist/ops/grads/qkv.js +1 -1
  63. package/dist/ops/grads/rope.js +3 -3
  64. package/dist/ops/matMulGelu.js +1 -1
  65. package/dist/ops/matMulMul.js +1 -1
  66. package/dist/ops/mulDrop.js +1 -1
  67. package/dist/ops/normRMS.js +1 -1
  68. package/dist/ops/qkv.js +1 -1
  69. package/dist/ops/rope.js +4 -4
  70. package/dist/ops/scatterSub.js +1 -1
  71. package/dist/ops/webgl/appendCache.js +1 -1
  72. package/dist/ops/webgl/attentionMask.js +1 -1
  73. package/dist/ops/webgl/fusedSoftmax.js +4 -4
  74. package/dist/ops/webgl/gatherSub.js +1 -1
  75. package/dist/ops/webgl/gelu.js +2 -2
  76. package/dist/ops/webgl/log.js +5 -5
  77. package/dist/ops/webgl/matMulGelu.js +17 -17
  78. package/dist/ops/webgl/matMulMul.js +1 -1
  79. package/dist/ops/webgl/mulDropout.js +4 -4
  80. package/dist/ops/webgl/normRMS.js +2 -2
  81. package/dist/ops/webgl/qkv.js +1 -1
  82. package/dist/ops/webgl/rope.js +1 -1
  83. package/dist/ops/webgl/scatterSub.js +1 -1
  84. package/dist/ops/webgpu/appendCache.js +56 -0
  85. package/dist/ops/webgpu/attentionMask.d.ts +1 -0
  86. package/dist/ops/webgpu/attentionMask.js +64 -0
  87. package/dist/ops/webgpu/gatherSub.d.ts +1 -0
  88. package/dist/ops/webgpu/gatherSub.js +37 -0
  89. package/dist/ops/webgpu/gelu.d.ts +14 -0
  90. package/dist/ops/webgpu/gelu.js +86 -0
  91. package/dist/ops/webgpu/index.d.ts +0 -0
  92. package/dist/ops/webgpu/index.js +8 -0
  93. package/dist/ops/webgpu/normRMS.d.ts +1 -0
  94. package/dist/ops/webgpu/normRMS.js +115 -0
  95. package/dist/ops/webgpu/qkv.d.ts +1 -0
  96. package/dist/ops/webgpu/qkv.js +56 -0
  97. package/dist/ops/webgpu/rope.d.ts +1 -0
  98. package/dist/ops/webgpu/rope.js +68 -0
  99. package/dist/ops/webgpu/scatterSub.d.ts +1 -0
  100. package/dist/ops/webgpu/scatterSub.js +37 -0
  101. package/dist/{ops-C0sQEcPw.js → ops-CIQLNshk.js} +452 -503
  102. package/dist/{random_width-DWzaOgrn.js → random_width-DkYP8W8N.js} +143 -144
  103. package/dist/{range-DYsrnfiy.js → range-CYzpQY53.js} +1 -1
  104. package/dist/{reciprocal-CJQeasVa.js → reciprocal-_A9yv27J.js} +1 -1
  105. package/dist/{register_all_kernels-BfFCQAqs.js → register_all_kernels-guvSxp7M.js} +202 -200
  106. package/dist/{reshape-krWGKraP.js → reshape-BMUzc1UY.js} +3 -3
  107. package/dist/{scatter_nd_util-93ln7Hut.js → scatter_nd_util-IRBqKz_b.js} +3 -3
  108. package/dist/{selu_util-sntGesxr.js → selu_util-Dt_iuXaq.js} +6 -6
  109. package/dist/shared-BNa2q6jD.js +69 -0
  110. package/dist/{shared-Ca6iDobD.js → shared-CDu9S76h.js} +541 -606
  111. package/dist/{sin-D_h-qCSx.js → sin-Cocju-BY.js} +6 -6
  112. package/dist/{softmax-fsdtf6JC.js → softmax-GPNK3o-U.js} +3 -3
  113. package/dist/{split-eiktj-6L.js → split-CHzJjxDv.js} +4 -4
  114. package/dist/{stack-dfEEz2OY.js → stack-Dpgg_1W1.js} +2 -2
  115. package/dist/{sum-BE_Irnim.js → sum-B8wEpKsg.js} +5 -5
  116. package/dist/{tensor-Xyi595sG.js → tensor-RvZVNmg0.js} +1 -1
  117. package/dist/{tensor2d-CPEkynbH.js → tensor2d-B_kyod7_.js} +1 -1
  118. package/dist/training/AdamExt.js +1 -1
  119. package/dist/training/DatasetBuilder.js +2 -2
  120. package/dist/training/Evaluator.js +1 -1
  121. package/dist/training/FullTrainer.js +20 -20
  122. package/dist/training/Trainer.d.ts +5 -6
  123. package/dist/training/Trainer.js +59 -60
  124. package/dist/training/sparseCrossEntropy.js +19 -26
  125. package/dist/utilities/dummy.js +19 -19
  126. package/dist/utilities/generate.js +15 -16
  127. package/dist/utilities/multinomialCPU.d.ts +2 -0
  128. package/dist/utilities/multinomialCPU.js +13 -0
  129. package/dist/utilities/performance.d.ts +2 -0
  130. package/dist/utilities/performance.js +16 -0
  131. package/dist/utilities/profile.d.ts +1 -0
  132. package/dist/utilities/profile.js +9 -6
  133. package/dist/utilities/safetensors.js +2 -2
  134. package/dist/utilities/weights.js +2 -2
  135. package/dist/{variable-wSS22xj5.js → variable-DXEUOwew.js} +1 -1
  136. package/dist/webgpu_util-g13LvDIv.js +625 -0
  137. package/dist/{zeros-YJDE7oRb.js → zeros-DCPCdFGq.js} +8 -8
  138. package/package.json +2 -1
  139. package/dist/gpgpu_math-CNslybmD.js +0 -3115
  140. package/dist/norm-CzltS9Fz.js +0 -86
  141. package/dist/ops/node/sparseCrossEntropy.js +0 -11
  142. /package/dist/ops/{node/sparseCrossEntropy.d.ts → webgpu/appendCache.d.ts} +0 -0
@@ -1,16 +1,18 @@
1
- import { o as h, q as l, E as f, aO as hn, i as p, aP as fn, h as w, aQ as bn, aR as dn, aS as gn, I as $n, ah as xn, B as j, aT as kn, aU as yn, aV as In, aW as _n, aX as En, aY as Mn, aZ as Nn, L as V, a_ as An, a$ as Tn, b0 as Sn, aK as wn, V as zn, O as Bn, Q as qn, b1 as Kn, t as Rn, b2 as J, b3 as Gn, b4 as Vn, b5 as Dn, b6 as Pn, b7 as vn, b8 as jn, s as Fn, b9 as On, ba as Wn, a as k, a7 as Z, aj as R, f as Yn, b as S, bb as Cn, H as L, d as Jn } from "./index-BAzbokzv.js";
2
- import { r as _ } from "./reshape-krWGKraP.js";
3
- import { s as un } from "./split-eiktj-6L.js";
4
- import { s as q } from "./sum-BE_Irnim.js";
5
- import { b as X } from "./broadcast_to-DARN-DBD.js";
6
- import { r as W } from "./range-DYsrnfiy.js";
7
- import { t as Ln } from "./tensor-Xyi595sG.js";
8
- import { s as Y } from "./stack-dfEEz2OY.js";
9
- import { c as Xn, z as Qn } from "./zeros-YJDE7oRb.js";
10
- import { n as ln } from "./norm-CzltS9Fz.js";
11
- import { c as Q } from "./concat-5aPGqw3Z.js";
12
- import { m as T } from "./mat_mul-7121rsJk.js";
13
- import { t as H } from "./tensor2d-CPEkynbH.js";
1
+ import { x as m, y as u, E as f, aN as gn, l, aO as $n, k as S, aP as kn, aQ as yn, aR as En, p as _n, aS as w, aT as rn, n as In, b as pn, aU as Nn, aV as An, L as Tn, ai as xn, F as v, aW as wn, aX as Sn, aY as Mn, aZ as zn, a_ as qn, a$ as Kn, b0 as Bn, Q as G, b1 as Gn, b2 as Rn, b3 as Dn, aE as vn, X as Vn, V as Pn, W as jn, b4 as Fn, t as Wn, b5 as C, b6 as On, b7 as Yn, b8 as Ln, b9 as Cn, ba as Xn, bb as Qn, bc as Jn, bd as Zn, a as $, a6 as U, aj as q, h as Hn, c as A, be as Un, K as X, d as ne } from "./index-C0dhsYom.js";
2
+ import { n as ee, a as se, b as te } from "./non_max_suppression_impl-CsEgBuMA.js";
3
+ import { r as k } from "./reshape-BMUzc1UY.js";
4
+ import { s as mn } from "./split-CHzJjxDv.js";
5
+ import { s as E } from "./sum-B8wEpKsg.js";
6
+ import { b as Q } from "./broadcast_to-C4v-j9yA.js";
7
+ import { r as W } from "./range-CYzpQY53.js";
8
+ import { t as re } from "./tensor-RvZVNmg0.js";
9
+ import { s as O } from "./stack-Dpgg_1W1.js";
10
+ import { c as ae, z as oe } from "./zeros-DCPCdFGq.js";
11
+ import { e as ie } from "./axis_util-DaAl5MER.js";
12
+ import { m as J } from "./max-BQc2Aj-I.js";
13
+ import { c as Z } from "./concat-CsHeR4zV.js";
14
+ import { m as N } from "./mat_mul-1nwdPkQ_.js";
15
+ import { t as H } from "./tensor2d-B_kyod7_.js";
14
16
  /**
15
17
  * @license
16
18
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -27,14 +29,14 @@ import { t as H } from "./tensor2d-CPEkynbH.js";
27
29
  * limitations under the License.
28
30
  * =============================================================================
29
31
  */
30
- function Hn(r, t, n) {
31
- const e = l(r, "x", "slice", "string_or_numeric");
32
- if (e.rank === 0)
32
+ function ce(s, e, n) {
33
+ const r = u(s, "x", "slice", "string_or_numeric");
34
+ if (r.rank === 0)
33
35
  throw new Error("Slicing scalar is not possible");
34
- const s = { x: e }, a = { begin: t, size: n };
35
- return f.runKernel(hn, s, a);
36
+ const t = { x: r }, a = { begin: e, size: n };
37
+ return f.runKernel(gn, t, a);
36
38
  }
37
- const M = /* @__PURE__ */ h({ slice_: Hn });
39
+ const _ = /* @__PURE__ */ m({ slice_: ce });
38
40
  /**
39
41
  * @license
40
42
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -51,13 +53,13 @@ const M = /* @__PURE__ */ h({ slice_: Hn });
51
53
  * limitations under the License.
52
54
  * =============================================================================
53
55
  */
54
- function Zn(r, t, n) {
55
- const e = l(r, "x", "bincount"), s = l(t, "weights", "bincount");
56
- p(e.dtype === "int32", () => `Error in bincount: input dtype must be int32, but got ${e.dtype}`), p(n >= 0, () => `size must be non-negative, but got ${n}.`), p(s.size === e.size || s.size === 0, () => `Error in bincount: weights must have the same size as input or0-length, but got input shape: ${e.shape}, weights shape: ${s.shape}.`);
57
- const a = { x: e, weights: s }, o = { size: n };
58
- return f.runKernel(fn, a, o);
56
+ function ue(s, e, n) {
57
+ const r = u(s, "x", "bincount"), t = u(e, "weights", "bincount");
58
+ l(r.dtype === "int32", () => `Error in bincount: input dtype must be int32, but got ${r.dtype}`), l(n >= 0, () => `size must be non-negative, but got ${n}.`), l(t.size === r.size || t.size === 0, () => `Error in bincount: weights must have the same size as input or0-length, but got input shape: ${r.shape}, weights shape: ${t.shape}.`);
59
+ const a = { x: r, weights: t }, o = { size: n };
60
+ return f.runKernel($n, a, o);
59
61
  }
60
- const Un = /* @__PURE__ */ h({ bincount_: Zn });
62
+ const le = /* @__PURE__ */ m({ bincount_: ue });
61
63
  /**
62
64
  * @license
63
65
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -74,15 +76,15 @@ const Un = /* @__PURE__ */ h({ bincount_: Zn });
74
76
  * limitations under the License.
75
77
  * =============================================================================
76
78
  */
77
- function ne(r, t, n) {
78
- const e = l(t, "a", "where"), s = l(n, "b", "where"), a = l(r, "condition", "where", "bool"), o = w(w(a.shape, e.shape), s.shape), i = X(a, o), u = X(e, o), c = X(s, o), b = {
79
+ function pe(s, e, n) {
80
+ const r = u(e, "a", "where"), t = u(n, "b", "where"), a = u(s, "condition", "where", "bool"), o = S(S(a.shape, r.shape), t.shape), i = Q(a, o), p = Q(r, o), c = Q(t, o), b = {
79
81
  condition: i,
80
- t: u,
82
+ t: p,
81
83
  e: c
82
84
  };
83
- return f.runKernel(bn, b);
85
+ return f.runKernel(kn, b);
84
86
  }
85
- const G = /* @__PURE__ */ h({ where_: ne });
87
+ const B = /* @__PURE__ */ m({ where_: pe });
86
88
  /**
87
89
  * @license
88
90
  * Copyright 2021 Google LLC. All Rights Reserved.
@@ -99,11 +101,88 @@ const G = /* @__PURE__ */ h({ where_: ne });
99
101
  * limitations under the License.
100
102
  * =============================================================================
101
103
  */
102
- function ee(r, ...t) {
103
- const n = t.map((s, a) => l(s, `tensors${a}`, "einsum")), e = { equation: r };
104
- return f.runKernel(dn, n, e);
104
+ function me(s, ...e) {
105
+ const n = e.map((t, a) => u(t, `tensors${a}`, "einsum")), r = { equation: s };
106
+ return f.runKernel(yn, n, r);
105
107
  }
106
- const v = /* @__PURE__ */ h({ einsum_: ee });
108
+ const D = /* @__PURE__ */ m({ einsum_: me });
109
+ /**
110
+ * @license
111
+ * Copyright 2020 Google Inc. All Rights Reserved.
112
+ * Licensed under the Apache License, Version 2.0 (the "License");
113
+ * you may not use this file except in compliance with the License.
114
+ * You may obtain a copy of the License at
115
+ *
116
+ * http://www.apache.org/licenses/LICENSE-2.0
117
+ *
118
+ * Unless required by applicable law or agreed to in writing, software
119
+ * distributed under the License is distributed on an "AS IS" BASIS,
120
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121
+ * See the License for the specific language governing permissions and
122
+ * limitations under the License.
123
+ * =============================================================================
124
+ */
125
+ function fe(s, e = null, n = !1) {
126
+ const t = { x: u(s, "x", "min") }, a = { axis: e, keepDims: n };
127
+ return f.runKernel(En, t, a);
128
+ }
129
+ const an = /* @__PURE__ */ m({ min_: fe });
130
+ /**
131
+ * @license
132
+ * Copyright 2018 Google LLC. All Rights Reserved.
133
+ * Licensed under the Apache License, Version 2.0 (the "License");
134
+ * you may not use this file except in compliance with the License.
135
+ * You may obtain a copy of the License at
136
+ *
137
+ * http://www.apache.org/licenses/LICENSE-2.0
138
+ *
139
+ * Unless required by applicable law or agreed to in writing, software
140
+ * distributed under the License is distributed on an "AS IS" BASIS,
141
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142
+ * See the License for the specific language governing permissions and
143
+ * limitations under the License.
144
+ * =============================================================================
145
+ */
146
+ function he(s, e = "euclidean", n = null, r = !1) {
147
+ s = u(s, "x", "norm");
148
+ const t = fn(s, e, n);
149
+ let a = t.shape;
150
+ if (r) {
151
+ const o = _n(n, s.shape);
152
+ a = ie(t.shape, o);
153
+ }
154
+ return k(t, a);
155
+ }
156
+ function fn(s, e, n = null) {
157
+ if (s.rank === 0)
158
+ return w(s);
159
+ if (s.rank !== 1 && n === null)
160
+ return fn(k(s, [-1]), e, n);
161
+ if (s.rank === 1 || typeof n == "number" || Array.isArray(n) && n.length === 1) {
162
+ if (e === 1)
163
+ return E(w(s), n);
164
+ if (e === 1 / 0)
165
+ return J(w(s), n);
166
+ if (e === -1 / 0)
167
+ return an(w(s), n);
168
+ if (e === "euclidean" || e === 2)
169
+ return rn(E(In(w(s), pn(2, "int32")), n));
170
+ throw new Error(`Error in norm: invalid ord value: ${e}`);
171
+ }
172
+ if (Array.isArray(n) && n.length === 2) {
173
+ if (e === 1)
174
+ return J(E(w(s), n[0]), n[1] - 1);
175
+ if (e === 1 / 0)
176
+ return J(E(w(s), n[1]), n[0]);
177
+ if (e === -1 / 0)
178
+ return an(E(w(s), n[1]), n[0]);
179
+ if (e === "fro" || e === "euclidean")
180
+ return rn(E(Nn(s), n));
181
+ throw new Error(`Error in norm: invalid ord value: ${e}`);
182
+ }
183
+ throw new Error(`Error in norm: invalid axis: ${n}`);
184
+ }
185
+ const hn = /* @__PURE__ */ m({ norm_: he });
107
186
  /**
108
187
  * @license
109
188
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -120,13 +199,13 @@ const v = /* @__PURE__ */ h({ einsum_: ee });
120
199
  * limitations under the License.
121
200
  * =============================================================================
122
201
  */
123
- function se(r, t = 0) {
124
- const n = l(r, "x", "expandDims", "string_or_numeric");
125
- p(t <= n.rank, () => "Axis must be <= rank of the tensor");
126
- const e = { input: n }, s = { dim: t };
127
- return f.runKernel(gn, e, s);
202
+ function be(s, e = 0) {
203
+ const n = u(s, "x", "expandDims", "string_or_numeric");
204
+ l(e <= n.rank, () => "Axis must be <= rank of the tensor");
205
+ const r = { input: n }, t = { dim: e };
206
+ return f.runKernel(An, r, t);
128
207
  }
129
- const K = /* @__PURE__ */ h({ expandDims_: se });
208
+ const z = /* @__PURE__ */ m({ expandDims_: be });
130
209
  /**
131
210
  * @license
132
211
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -143,13 +222,13 @@ const K = /* @__PURE__ */ h({ expandDims_: se });
143
222
  * limitations under the License.
144
223
  * =============================================================================
145
224
  */
146
- function te(r, t) {
147
- const n = l(r, "x", "tile", "string_or_numeric");
148
- p(n.rank === t.length, () => `Error in transpose: rank of input ${n.rank} must match length of reps ${t}.`);
149
- const e = { x: n }, s = { reps: t };
150
- return f.runKernel($n, e, s);
225
+ function de(s, e) {
226
+ const n = u(s, "x", "tile", "string_or_numeric");
227
+ l(n.rank === e.length, () => `Error in transpose: rank of input ${n.rank} must match length of reps ${e}.`);
228
+ const r = { x: n }, t = { reps: e };
229
+ return f.runKernel(Tn, r, t);
151
230
  }
152
- const O = /* @__PURE__ */ h({ tile_: te });
231
+ const F = /* @__PURE__ */ m({ tile_: de });
153
232
  /**
154
233
  * @license
155
234
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -166,20 +245,20 @@ const O = /* @__PURE__ */ h({ tile_: te });
166
245
  * limitations under the License.
167
246
  * =============================================================================
168
247
  */
169
- function re(r, t, n, e = "float32") {
170
- t == null && (t = r);
171
- const s = xn([r, t], e), a = r <= t ? r : t;
248
+ function ge(s, e, n, r = "float32") {
249
+ e == null && (e = s);
250
+ const t = xn([s, e], r), a = s <= e ? s : e;
172
251
  for (let i = 0; i < a; ++i)
173
- s.set(1, i, i);
174
- const o = _(s.toTensor(), [r, t]);
252
+ t.set(1, i, i);
253
+ const o = k(t.toTensor(), [s, e]);
175
254
  if (n == null)
176
255
  return o;
177
256
  if (n.length === 1)
178
- return O(K(o, 0), [n[0], 1, 1]);
257
+ return F(z(o, 0), [n[0], 1, 1]);
179
258
  if (n.length === 2)
180
- return O(K(K(o, 0), 0), [n[0], n[1], 1, 1]);
259
+ return F(z(z(o, 0), 0), [n[0], n[1], 1, 1]);
181
260
  if (n.length === 3)
182
- return O(K(K(K(o, 0), 0), 0), [
261
+ return F(z(z(z(o, 0), 0), 0), [
183
262
  n[0],
184
263
  n[1],
185
264
  n[2],
@@ -188,7 +267,7 @@ function re(r, t, n, e = "float32") {
188
267
  ]);
189
268
  throw new Error(`eye() currently supports only 1D and 2D batchShapes, but received ${n.length}D.`);
190
269
  }
191
- const ae = /* @__PURE__ */ h({ eye_: re });
270
+ const $e = /* @__PURE__ */ m({ eye_: ge });
192
271
  /**
193
272
  * @license
194
273
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -205,13 +284,13 @@ const ae = /* @__PURE__ */ h({ eye_: re });
205
284
  * limitations under the License.
206
285
  * =============================================================================
207
286
  */
208
- function oe(r, t) {
209
- let n = l(r, "a", "greater", "string_or_numeric"), e = l(t, "b", "greater", "string_or_numeric");
210
- [n, e] = j(n, e), w(n.shape, e.shape);
211
- const s = { a: n, b: e };
212
- return f.runKernel(kn, s);
287
+ function ke(s, e) {
288
+ let n = u(s, "a", "greater", "string_or_numeric"), r = u(e, "b", "greater", "string_or_numeric");
289
+ [n, r] = v(n, r), S(n.shape, r.shape);
290
+ const t = { a: n, b: r };
291
+ return f.runKernel(wn, t);
213
292
  }
214
- const U = /* @__PURE__ */ h({ greater_: oe });
293
+ const nn = /* @__PURE__ */ m({ greater_: ke });
215
294
  /**
216
295
  * @license
217
296
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -228,13 +307,13 @@ const U = /* @__PURE__ */ h({ greater_: oe });
228
307
  * limitations under the License.
229
308
  * =============================================================================
230
309
  */
231
- function ie(r, t) {
232
- let n = l(r, "a", "greaterEqual", "string_or_numeric"), e = l(t, "b", "greaterEqual", "string_or_numeric");
233
- [n, e] = j(n, e), w(n.shape, e.shape);
234
- const s = { a: n, b: e };
235
- return f.runKernel(yn, s);
310
+ function ye(s, e) {
311
+ let n = u(s, "a", "greaterEqual", "string_or_numeric"), r = u(e, "b", "greaterEqual", "string_or_numeric");
312
+ [n, r] = v(n, r), S(n.shape, r.shape);
313
+ const t = { a: n, b: r };
314
+ return f.runKernel(Sn, t);
236
315
  }
237
- const ce = /* @__PURE__ */ h({ greaterEqual_: ie });
316
+ const Ee = /* @__PURE__ */ m({ greaterEqual_: ye });
238
317
  /**
239
318
  * @license
240
319
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -251,11 +330,11 @@ const ce = /* @__PURE__ */ h({ greaterEqual_: ie });
251
330
  * limitations under the License.
252
331
  * =============================================================================
253
332
  */
254
- function ue(r) {
255
- const n = { input: l(r, "input", "imag") };
256
- return f.runKernel(In, n);
333
+ function _e(s) {
334
+ const n = { input: u(s, "input", "imag") };
335
+ return f.runKernel(Mn, n);
257
336
  }
258
- const le = /* @__PURE__ */ h({ imag_: ue });
337
+ const Ie = /* @__PURE__ */ m({ imag_: _e });
259
338
  /**
260
339
  * @license
261
340
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -272,13 +351,13 @@ const le = /* @__PURE__ */ h({ imag_: ue });
272
351
  * limitations under the License.
273
352
  * =============================================================================
274
353
  */
275
- function pe(r, t) {
276
- let n = l(r, "a", "less", "string_or_numeric"), e = l(t, "b", "less", "string_or_numeric");
277
- [n, e] = j(n, e), w(n.shape, e.shape);
278
- const s = { a: n, b: e };
279
- return f.runKernel(_n, s);
354
+ function Ne(s, e) {
355
+ let n = u(s, "a", "less", "string_or_numeric"), r = u(e, "b", "less", "string_or_numeric");
356
+ [n, r] = v(n, r), S(n.shape, r.shape);
357
+ const t = { a: n, b: r };
358
+ return f.runKernel(zn, t);
280
359
  }
281
- const tn = /* @__PURE__ */ h({ less_: pe });
360
+ const on = /* @__PURE__ */ m({ less_: Ne });
282
361
  /**
283
362
  * @license
284
363
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -295,13 +374,13 @@ const tn = /* @__PURE__ */ h({ less_: pe });
295
374
  * limitations under the License.
296
375
  * =============================================================================
297
376
  */
298
- function me(r, t) {
299
- let n = l(r, "a", "lessEqual", "string_or_numeric"), e = l(t, "b", "lessEqual", "string_or_numeric");
300
- [n, e] = j(n, e), w(n.shape, e.shape);
301
- const s = { a: n, b: e };
302
- return f.runKernel(En, s);
377
+ function Ae(s, e) {
378
+ let n = u(s, "a", "lessEqual", "string_or_numeric"), r = u(e, "b", "lessEqual", "string_or_numeric");
379
+ [n, r] = v(n, r), S(n.shape, r.shape);
380
+ const t = { a: n, b: r };
381
+ return f.runKernel(qn, t);
303
382
  }
304
- const pn = /* @__PURE__ */ h({ lessEqual_: me });
383
+ const bn = /* @__PURE__ */ m({ lessEqual_: Ae });
305
384
  /**
306
385
  * @license
307
386
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -318,11 +397,11 @@ const pn = /* @__PURE__ */ h({ lessEqual_: me });
318
397
  * limitations under the License.
319
398
  * =============================================================================
320
399
  */
321
- function he(r) {
322
- const n = { x: l(r, "x", "neg") };
323
- return f.runKernel(Mn, n);
400
+ function Te(s) {
401
+ const n = { x: u(s, "x", "neg") };
402
+ return f.runKernel(Kn, n);
324
403
  }
325
- const nn = /* @__PURE__ */ h({ neg_: he });
404
+ const en = /* @__PURE__ */ m({ neg_: Te });
326
405
  /**
327
406
  * @license
328
407
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -339,13 +418,13 @@ const nn = /* @__PURE__ */ h({ neg_: he });
339
418
  * limitations under the License.
340
419
  * =============================================================================
341
420
  */
342
- function fe(r, t) {
343
- const n = l(r, "a", "logicalAnd", "bool"), e = l(t, "b", "logicalAnd", "bool");
344
- w(n.shape, e.shape);
345
- const s = { a: n, b: e };
346
- return f.runKernel(Nn, s);
421
+ function xe(s, e) {
422
+ const n = u(s, "a", "logicalAnd", "bool"), r = u(e, "b", "logicalAnd", "bool");
423
+ S(n.shape, r.shape);
424
+ const t = { a: n, b: r };
425
+ return f.runKernel(Bn, t);
347
426
  }
348
- const be = /* @__PURE__ */ h({ logicalAnd_: fe });
427
+ const we = /* @__PURE__ */ m({ logicalAnd_: xe });
349
428
  /**
350
429
  * @license
351
430
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -362,13 +441,13 @@ const be = /* @__PURE__ */ h({ logicalAnd_: fe });
362
441
  * limitations under the License.
363
442
  * =============================================================================
364
443
  */
365
- function de(r, t) {
366
- let n = l(r, "a", "minimum"), e = l(t, "b", "minimum");
367
- [n, e] = j(n, e), n.dtype === "bool" && (n = V(n, "int32"), e = V(e, "int32")), w(n.shape, e.shape);
368
- const s = { a: n, b: e };
369
- return f.runKernel(An, s);
444
+ function Se(s, e) {
445
+ let n = u(s, "a", "minimum"), r = u(e, "b", "minimum");
446
+ [n, r] = v(n, r), n.dtype === "bool" && (n = G(n, "int32"), r = G(r, "int32")), S(n.shape, r.shape);
447
+ const t = { a: n, b: r };
448
+ return f.runKernel(Gn, t);
370
449
  }
371
- const rn = /* @__PURE__ */ h({ minimum_: de });
450
+ const cn = /* @__PURE__ */ m({ minimum_: Se });
372
451
  /**
373
452
  * @license
374
453
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -385,11 +464,11 @@ const rn = /* @__PURE__ */ h({ minimum_: de });
385
464
  * limitations under the License.
386
465
  * =============================================================================
387
466
  */
388
- function ge(r) {
389
- const n = { input: l(r, "input", "real") };
390
- return f.runKernel(Tn, n);
467
+ function Me(s) {
468
+ const n = { input: u(s, "input", "real") };
469
+ return f.runKernel(Rn, n);
391
470
  }
392
- const $e = /* @__PURE__ */ h({ real_: ge });
471
+ const ze = /* @__PURE__ */ m({ real_: Me });
393
472
  /**
394
473
  * @license
395
474
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -406,11 +485,11 @@ const $e = /* @__PURE__ */ h({ real_: ge });
406
485
  * limitations under the License.
407
486
  * =============================================================================
408
487
  */
409
- function xe(r) {
410
- const n = { x: l(r, "x", "round") };
411
- return f.runKernel(Sn, n);
488
+ function qe(s) {
489
+ const n = { x: u(s, "x", "round") };
490
+ return f.runKernel(Dn, n);
412
491
  }
413
- const ke = /* @__PURE__ */ h({ round_: xe });
492
+ const Ke = /* @__PURE__ */ m({ round_: qe });
414
493
  /**
415
494
  * @license
416
495
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -427,11 +506,11 @@ const ke = /* @__PURE__ */ h({ round_: xe });
427
506
  * limitations under the License.
428
507
  * =============================================================================
429
508
  */
430
- function ye(r, t) {
431
- const n = l(r, "x", "squeeze", "string_or_numeric");
432
- return _(n, wn(n.shape, t).newShape);
509
+ function Be(s, e) {
510
+ const n = u(s, "x", "squeeze", "string_or_numeric");
511
+ return k(n, vn(n.shape, e).newShape);
433
512
  }
434
- const Ie = /* @__PURE__ */ h({ squeeze_: ye });
513
+ const Ge = /* @__PURE__ */ m({ squeeze_: Be });
435
514
  /**
436
515
  * @license
437
516
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -448,12 +527,12 @@ const Ie = /* @__PURE__ */ h({ squeeze_: ye });
448
527
  * limitations under the License.
449
528
  * =============================================================================
450
529
  */
451
- function N(r, t) {
452
- zn(r);
453
- const n = Bn(r, t);
530
+ function I(s, e) {
531
+ Vn(s);
532
+ const n = Pn(s, e);
454
533
  if (n.length !== 1)
455
534
  throw new Error("tensor1d() requires values to be a flat/TypedArray");
456
- return qn(r, null, n, t);
535
+ return jn(s, null, n, e);
457
536
  }
458
537
  /**
459
538
  * @license
@@ -471,13 +550,13 @@ function N(r, t) {
471
550
  * limitations under the License.
472
551
  * =============================================================================
473
552
  */
474
- function _e(r, t = 0) {
475
- const n = l(r, "x", "unstack", "string_or_numeric");
476
- p(t >= -n.shape.length && t < n.shape.length, () => `Axis = ${t} is not in [-${n.shape.length}, ${n.shape.length})`);
477
- const e = { value: n }, s = { axis: t };
478
- return f.runKernel(Kn, e, s);
553
+ function Re(s, e = 0) {
554
+ const n = u(s, "x", "unstack", "string_or_numeric");
555
+ l(e >= -n.shape.length && e < n.shape.length, () => `Axis = ${e} is not in [-${n.shape.length}, ${n.shape.length})`);
556
+ const r = { value: n }, t = { axis: e };
557
+ return f.runKernel(Fn, r, t);
479
558
  }
480
- const mn = /* @__PURE__ */ h({ unstack_: _e });
559
+ const dn = /* @__PURE__ */ m({ unstack_: Re });
481
560
  /**
482
561
  * @license
483
562
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -494,19 +573,19 @@ const mn = /* @__PURE__ */ h({ unstack_: _e });
494
573
  * limitations under the License.
495
574
  * =============================================================================
496
575
  */
497
- function Ee(r, t, n) {
498
- const e = l(r, "x", "transpose");
499
- if (t == null && (t = e.shape.map((o, i) => i).reverse()), p(e.rank === t.length, () => `Error in transpose: rank of input ${e.rank} must match length of perm ${t}.`), t.forEach((o) => {
500
- p(o >= 0 && o < e.rank, () => `All entries in 'perm' must be between 0 and ${e.rank - 1} but got ${t}`);
501
- }), e.rank <= 1)
502
- return e.clone();
503
- const s = { x: e }, a = { perm: t };
504
- return e.dtype === "complex64" ? Rn(() => {
505
- let o = $e(e), i = le(e);
506
- return o = f.runKernel(J, { x: o }, a), i = f.runKernel(J, { x: i }, a), n && (i = nn(i)), Xn(o, i);
507
- }) : f.runKernel(J, s, a);
576
+ function De(s, e, n) {
577
+ const r = u(s, "x", "transpose");
578
+ if (e == null && (e = r.shape.map((o, i) => i).reverse()), l(r.rank === e.length, () => `Error in transpose: rank of input ${r.rank} must match length of perm ${e}.`), e.forEach((o) => {
579
+ l(o >= 0 && o < r.rank, () => `All entries in 'perm' must be between 0 and ${r.rank - 1} but got ${e}`);
580
+ }), r.rank <= 1)
581
+ return r.clone();
582
+ const t = { x: r }, a = { perm: e };
583
+ return r.dtype === "complex64" ? Wn(() => {
584
+ let o = ze(r), i = Ie(r);
585
+ return o = f.runKernel(C, { x: o }, a), i = f.runKernel(C, { x: i }, a), n && (i = en(i)), ae(o, i);
586
+ }) : f.runKernel(C, t, a);
508
587
  }
509
- const an = /* @__PURE__ */ h({ transpose_: Ee });
588
+ const un = /* @__PURE__ */ m({ transpose_: De });
510
589
  /**
511
590
  * @license
512
591
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -523,13 +602,13 @@ const an = /* @__PURE__ */ h({ transpose_: Ee });
523
602
  * limitations under the License.
524
603
  * =============================================================================
525
604
  */
526
- function Me(r, t, n, e, s = "bilinear", a = 0) {
527
- const o = l(r, "image", "cropAndResize"), i = l(t, "boxes", "cropAndResize", "float32"), u = l(n, "boxInd", "cropAndResize", "int32"), c = i.shape[0];
528
- p(o.rank === 4, () => `Error in cropAndResize: image must be rank 4,but got rank ${o.rank}.`), p(i.rank === 2 && i.shape[1] === 4, () => `Error in cropAndResize: boxes must be have size [${c},4] but had shape ${i.shape}.`), p(u.rank === 1 && u.shape[0] === c, () => `Error in cropAndResize: boxInd must be have size [${c}] but had shape ${i.shape}.`), p(e.length === 2, () => `Error in cropAndResize: cropSize must be of length 2, but got length ${e.length}.`), p(e[0] >= 1 && e[1] >= 1, () => `cropSize must be atleast [1,1], but was ${e}`), p(s === "bilinear" || s === "nearest", () => `method must be bilinear or nearest, but was ${s}`);
529
- const b = { image: o, boxes: i, boxInd: u }, m = { method: s, extrapolationValue: a, cropSize: e };
530
- return f.runKernel(Gn, b, m);
605
+ function ve(s, e, n, r, t = "bilinear", a = 0) {
606
+ const o = u(s, "image", "cropAndResize"), i = u(e, "boxes", "cropAndResize", "float32"), p = u(n, "boxInd", "cropAndResize", "int32"), c = i.shape[0];
607
+ l(o.rank === 4, () => `Error in cropAndResize: image must be rank 4,but got rank ${o.rank}.`), l(i.rank === 2 && i.shape[1] === 4, () => `Error in cropAndResize: boxes must be have size [${c},4] but had shape ${i.shape}.`), l(p.rank === 1 && p.shape[0] === c, () => `Error in cropAndResize: boxInd must be have size [${c}] but had shape ${i.shape}.`), l(r.length === 2, () => `Error in cropAndResize: cropSize must be of length 2, but got length ${r.length}.`), l(r[0] >= 1 && r[1] >= 1, () => `cropSize must be atleast [1,1], but was ${r}`), l(t === "bilinear" || t === "nearest", () => `method must be bilinear or nearest, but was ${t}`);
608
+ const b = { image: o, boxes: i, boxInd: p }, h = { method: t, extrapolationValue: a, cropSize: r };
609
+ return f.runKernel(On, b, h);
531
610
  }
532
- const Ne = /* @__PURE__ */ h({ cropAndResize_: Me });
611
+ const Ve = /* @__PURE__ */ m({ cropAndResize_: ve });
533
612
  /**
534
613
  * @license
535
614
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -546,13 +625,13 @@ const Ne = /* @__PURE__ */ h({ cropAndResize_: Me });
546
625
  * limitations under the License.
547
626
  * =============================================================================
548
627
  */
549
- function Ae(r) {
550
- const t = l(r, "image", "flipLeftRight", "float32");
551
- p(t.rank === 4, () => `Error in flipLeftRight: image must be rank 4,but got rank ${t.rank}.`);
552
- const n = { image: t };
553
- return f.runKernel(Vn, n, {});
628
+ function Pe(s) {
629
+ const e = u(s, "image", "flipLeftRight", "float32");
630
+ l(e.rank === 4, () => `Error in flipLeftRight: image must be rank 4,but got rank ${e.rank}.`);
631
+ const n = { image: e };
632
+ return f.runKernel(Yn, n, {});
554
633
  }
555
- const Te = /* @__PURE__ */ h({ flipLeftRight_: Ae });
634
+ const je = /* @__PURE__ */ m({ flipLeftRight_: Pe });
556
635
  /**
557
636
  * @license
558
637
  * Copyright 2021 Google LLC. All Rights Reserved.
@@ -569,13 +648,13 @@ const Te = /* @__PURE__ */ h({ flipLeftRight_: Ae });
569
648
  * limitations under the License.
570
649
  * =============================================================================
571
650
  */
572
- function Se(r) {
573
- const t = l(r, "image", "grayscaleToRGB"), n = t.rank - 1, e = t.shape[n];
574
- p(t.rank >= 2, () => `Error in grayscaleToRGB: images must be at least rank 2, but got rank ${t.rank}.`), p(e === 1, () => `Error in grayscaleToRGB: last dimension of a grayscale image should be size 1, but got size ${e}.`);
575
- const s = new Array(t.rank);
576
- return s.fill(1, 0, n), s[n] = 3, O(t, s);
651
+ function Fe(s) {
652
+ const e = u(s, "image", "grayscaleToRGB"), n = e.rank - 1, r = e.shape[n];
653
+ l(e.rank >= 2, () => `Error in grayscaleToRGB: images must be at least rank 2, but got rank ${e.rank}.`), l(r === 1, () => `Error in grayscaleToRGB: last dimension of a grayscale image should be size 1, but got size ${r}.`);
654
+ const t = new Array(e.rank);
655
+ return t.fill(1, 0, n), t[n] = 3, F(e, t);
577
656
  }
578
- const we = /* @__PURE__ */ h({ grayscaleToRGB_: Se });
657
+ const We = /* @__PURE__ */ m({ grayscaleToRGB_: Fe });
579
658
  /**
580
659
  * @license
581
660
  * Copyright 2023 Google LLC.
@@ -592,33 +671,33 @@ const we = /* @__PURE__ */ h({ grayscaleToRGB_: Se });
592
671
  * limitations under the License.
593
672
  * =============================================================================
594
673
  */
595
- function ze(r) {
596
- const t = l(r, "image", "RGBToGrayscale"), n = t.rank - 1, e = t.shape[n];
597
- p(t.rank >= 2, () => `Error in RGBToGrayscale: images must be at least rank 2, but got rank ${t.rank}.`), p(e === 3, () => `Error in RGBToGrayscale: last dimension of an RGB image should be size 3, but got size ${e}.`);
598
- const s = t.dtype, a = V(t, "float32"), o = N([0.2989, 0.587, 0.114]);
674
+ function Oe(s) {
675
+ const e = u(s, "image", "RGBToGrayscale"), n = e.rank - 1, r = e.shape[n];
676
+ l(e.rank >= 2, () => `Error in RGBToGrayscale: images must be at least rank 2, but got rank ${e.rank}.`), l(r === 3, () => `Error in RGBToGrayscale: last dimension of an RGB image should be size 3, but got size ${r}.`);
677
+ const t = e.dtype, a = G(e, "float32"), o = I([0.2989, 0.587, 0.114]);
599
678
  let i;
600
- switch (t.rank) {
679
+ switch (e.rank) {
601
680
  case 2:
602
- i = v("ij,j->i", a, o);
681
+ i = D("ij,j->i", a, o);
603
682
  break;
604
683
  case 3:
605
- i = v("ijk,k->ij", a, o);
684
+ i = D("ijk,k->ij", a, o);
606
685
  break;
607
686
  case 4:
608
- i = v("ijkl,l->ijk", a, o);
687
+ i = D("ijkl,l->ijk", a, o);
609
688
  break;
610
689
  case 5:
611
- i = v("ijklm,m->ijkl", a, o);
690
+ i = D("ijklm,m->ijkl", a, o);
612
691
  break;
613
692
  case 6:
614
- i = v("ijklmn,n->ijklm", a, o);
693
+ i = D("ijklmn,n->ijklm", a, o);
615
694
  break;
616
695
  default:
617
696
  throw new Error("Not a valid tensor rank.");
618
697
  }
619
- return i = K(i, -1), V(i, s);
698
+ return i = z(i, -1), G(i, t);
620
699
  }
621
- const Be = /* @__PURE__ */ h({ rgbToGrayscale_: ze });
700
+ const Ye = /* @__PURE__ */ m({ rgbToGrayscale_: Oe });
622
701
  /**
623
702
  * @license
624
703
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -635,13 +714,13 @@ const Be = /* @__PURE__ */ h({ rgbToGrayscale_: ze });
635
714
  * limitations under the License.
636
715
  * =============================================================================
637
716
  */
638
- function qe(r, t, n = 0, e = 0.5) {
639
- const s = l(r, "image", "rotateWithOffset", "float32");
640
- p(s.rank === 4, () => `Error in rotateWithOffset: image must be rank 4,but got rank ${s.rank}.`);
641
- const a = { image: s }, o = { radians: t, fillValue: n, center: e };
642
- return f.runKernel(Dn, a, o);
717
+ function Le(s, e, n = 0, r = 0.5) {
718
+ const t = u(s, "image", "rotateWithOffset", "float32");
719
+ l(t.rank === 4, () => `Error in rotateWithOffset: image must be rank 4,but got rank ${t.rank}.`);
720
+ const a = { image: t }, o = { radians: e, fillValue: n, center: r };
721
+ return f.runKernel(Ln, a, o);
643
722
  }
644
- const Ke = /* @__PURE__ */ h({ rotateWithOffset_: qe });
723
+ const Ce = /* @__PURE__ */ m({ rotateWithOffset_: Le });
645
724
  /**
646
725
  * @license
647
726
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -658,10 +737,10 @@ const Ke = /* @__PURE__ */ h({ rotateWithOffset_: qe });
658
737
  * limitations under the License.
659
738
  * =============================================================================
660
739
  */
661
- function D(r, t, n, e, s, a) {
662
- e == null && (e = 0.5), s == null && (s = Number.NEGATIVE_INFINITY), a == null && (a = 0);
663
- const o = r.shape[0];
664
- return n = Math.min(n, o), p(0 <= e && e <= 1, () => `iouThreshold must be in [0, 1], but was '${e}'`), p(r.rank === 2, () => `boxes must be a 2D tensor, but was of rank '${r.rank}'`), p(r.shape[1] === 4, () => `boxes must have 4 columns, but 2nd dimension was ${r.shape[1]}`), p(t.rank === 1, () => "scores must be a 1D tensor"), p(t.shape[0] === o, () => `scores has incompatible shape with boxes. Expected ${o}, but was ${t.shape[0]}`), p(0 <= a && a <= 1, () => `softNmsSigma must be in [0, 1], but was '${a}'`), { maxOutputSize: n, iouThreshold: e, scoreThreshold: s, softNmsSigma: a };
740
+ function R(s, e, n, r, t, a) {
741
+ r == null && (r = 0.5), t == null && (t = Number.NEGATIVE_INFINITY), a == null && (a = 0);
742
+ const o = s.shape[0];
743
+ return n = Math.min(n, o), l(0 <= r && r <= 1, () => `iouThreshold must be in [0, 1], but was '${r}'`), l(s.rank === 2, () => `boxes must be a 2D tensor, but was of rank '${s.rank}'`), l(s.shape[1] === 4, () => `boxes must have 4 columns, but 2nd dimension was ${s.shape[1]}`), l(e.rank === 1, () => "scores must be a 1D tensor"), l(e.shape[0] === o, () => `scores has incompatible shape with boxes. Expected ${o}, but was ${e.shape[0]}`), l(0 <= a && a <= 1, () => `softNmsSigma must be in [0, 1], but was '${a}'`), { maxOutputSize: n, iouThreshold: r, scoreThreshold: t, softNmsSigma: a };
665
744
  }
666
745
  /**
667
746
  * @license
@@ -679,142 +758,13 @@ function D(r, t, n, e, s, a) {
679
758
  * limitations under the License.
680
759
  * =============================================================================
681
760
  */
682
- function Re(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY) {
683
- const a = l(r, "boxes", "nonMaxSuppression", "float32"), o = l(t, "scores", "nonMaxSuppression", "float32"), i = D(a, o, n, e, s);
684
- n = i.maxOutputSize, e = i.iouThreshold, s = i.scoreThreshold;
685
- const u = { maxOutputSize: n, iouThreshold: e, scoreThreshold: s };
686
- return f.runKernel(Pn, { boxes: a, scores: o }, u);
687
- }
688
- const Ge = /* @__PURE__ */ h({ nonMaxSuppression_: Re });
689
- /**
690
- * @license
691
- * Copyright 2019 Google LLC. All Rights Reserved.
692
- * Licensed under the Apache License, Version 2.0 (the "License");
693
- * you may not use this file except in compliance with the License.
694
- * You may obtain a copy of the License at
695
- *
696
- * http://www.apache.org/licenses/LICENSE-2.0
697
- *
698
- * Unless required by applicable law or agreed to in writing, software
699
- * distributed under the License is distributed on an "AS IS" BASIS,
700
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
701
- * See the License for the specific language governing permissions and
702
- * limitations under the License.
703
- * =============================================================================
704
- */
705
- function Ve(r, t, n) {
706
- const e = De(r, t, n), s = e < 0 ? -(e + 1) : e;
707
- r.splice(s, 0, t);
708
- }
709
- function De(r, t, n) {
710
- return ve(r, t, n || Pe);
711
- }
712
- function Pe(r, t) {
713
- return r > t ? 1 : r < t ? -1 : 0;
714
- }
715
- function ve(r, t, n) {
716
- let e = 0, s = r.length, a = 0, o = !1;
717
- for (; e < s; ) {
718
- a = e + (s - e >>> 1);
719
- const i = n(t, r[a]);
720
- i > 0 ? e = a + 1 : (s = a, o = !i);
721
- }
722
- return o ? e : -e - 1;
723
- }
724
- /**
725
- * @license
726
- * Copyright 2020 Google LLC. All Rights Reserved.
727
- * Licensed under the Apache License, Version 2.0 (the "License");
728
- * you may not use this file except in compliance with the License.
729
- * You may obtain a copy of the License at
730
- *
731
- * http://www.apache.org/licenses/LICENSE-2.0
732
- *
733
- * Unless required by applicable law or agreed to in writing, software
734
- * distributed under the License is distributed on an "AS IS" BASIS,
735
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
736
- * See the License for the specific language governing permissions and
737
- * limitations under the License.
738
- * =============================================================================
739
- */
740
- function je(r, t, n, e, s) {
741
- return en(
742
- r,
743
- t,
744
- n,
745
- e,
746
- s,
747
- 0
748
- /* softNmsSigma */
749
- );
750
- }
751
- function Fe(r, t, n, e, s, a) {
752
- return en(
753
- r,
754
- t,
755
- n,
756
- e,
757
- s,
758
- 0,
759
- !1,
760
- a,
761
- !0
762
- /* returnValidOutputs */
763
- );
764
- }
765
- function Oe(r, t, n, e, s, a) {
766
- return en(
767
- r,
768
- t,
769
- n,
770
- e,
771
- s,
772
- a,
773
- !0
774
- /* returnScoresTensor */
775
- );
776
- }
777
- function en(r, t, n, e, s, a, o = !1, i = !1, u = !1) {
778
- const c = [];
779
- for (let d = 0; d < t.length; d++)
780
- t[d] > s && c.push({ score: t[d], boxIndex: d, suppressBeginIndex: 0 });
781
- c.sort(on);
782
- const b = a > 0 ? -0.5 / a : 0, m = [], $ = [];
783
- for (; m.length < n && c.length > 0; ) {
784
- const d = c.pop(), { score: E, boxIndex: I, suppressBeginIndex: A } = d;
785
- if (E < s)
786
- break;
787
- let z = !1;
788
- for (let B = m.length - 1; B >= A; --B) {
789
- const P = We(r, I, m[B]);
790
- if (P >= e) {
791
- z = !0;
792
- break;
793
- }
794
- if (d.score = d.score * Ye(e, b, P), d.score <= s)
795
- break;
796
- }
797
- d.suppressBeginIndex = m.length, z || (d.score === E ? (m.push(I), $.push(d.score)) : d.score > s && Ve(c, d, on));
798
- }
799
- const g = m.length, x = n - g;
800
- i && x > 0 && (m.push(...new Array(x).fill(0)), $.push(...new Array(x).fill(0)));
801
- const y = { selectedIndices: m };
802
- return o && (y.selectedScores = $), u && (y.validOutputs = g), y;
803
- }
804
- function We(r, t, n) {
805
- const e = r.subarray(t * 4, t * 4 + 4), s = r.subarray(n * 4, n * 4 + 4), a = Math.min(e[0], e[2]), o = Math.min(e[1], e[3]), i = Math.max(e[0], e[2]), u = Math.max(e[1], e[3]), c = Math.min(s[0], s[2]), b = Math.min(s[1], s[3]), m = Math.max(s[0], s[2]), $ = Math.max(s[1], s[3]), g = (i - a) * (u - o), x = (m - c) * ($ - b);
806
- if (g <= 0 || x <= 0)
807
- return 0;
808
- const y = Math.max(a, c), d = Math.max(o, b), E = Math.min(i, m), I = Math.min(u, $), A = Math.max(E - y, 0) * Math.max(I - d, 0);
809
- return A / (g + x - A);
810
- }
811
- function Ye(r, t, n) {
812
- const e = Math.exp(t * n * n);
813
- return n <= r ? e : 0;
814
- }
815
- function on(r, t) {
816
- return r.score - t.score || r.score === t.score && t.boxIndex - r.boxIndex;
761
+ function Xe(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY) {
762
+ const a = u(s, "boxes", "nonMaxSuppression", "float32"), o = u(e, "scores", "nonMaxSuppression", "float32"), i = R(a, o, n, r, t);
763
+ n = i.maxOutputSize, r = i.iouThreshold, t = i.scoreThreshold;
764
+ const p = { maxOutputSize: n, iouThreshold: r, scoreThreshold: t };
765
+ return f.runKernel(Cn, { boxes: a, scores: o }, p);
817
766
  }
767
+ const Qe = /* @__PURE__ */ m({ nonMaxSuppression_: Xe });
818
768
  /**
819
769
  * @license
820
770
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -831,13 +781,13 @@ function on(r, t) {
831
781
  * limitations under the License.
832
782
  * =============================================================================
833
783
  */
834
- async function Ce(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY) {
835
- const a = l(r, "boxes", "nonMaxSuppressionAsync"), o = l(t, "scores", "nonMaxSuppressionAsync"), i = D(a, o, n, e, s);
836
- n = i.maxOutputSize, e = i.iouThreshold, s = i.scoreThreshold;
837
- const u = await Promise.all([a.data(), o.data()]), c = u[0], b = u[1], { selectedIndices: m } = je(c, b, n, e, s);
838
- return a !== r && a.dispose(), o !== t && o.dispose(), N(m, "int32");
784
+ async function Je(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY) {
785
+ const a = u(s, "boxes", "nonMaxSuppressionAsync"), o = u(e, "scores", "nonMaxSuppressionAsync"), i = R(a, o, n, r, t);
786
+ n = i.maxOutputSize, r = i.iouThreshold, t = i.scoreThreshold;
787
+ const p = await Promise.all([a.data(), o.data()]), c = p[0], b = p[1], { selectedIndices: h } = ee(c, b, n, r, t);
788
+ return a !== s && a.dispose(), o !== e && o.dispose(), I(h, "int32");
839
789
  }
840
- const Je = Ce;
790
+ const Ze = Je;
841
791
  /**
842
792
  * @license
843
793
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -854,13 +804,13 @@ const Je = Ce;
854
804
  * limitations under the License.
855
805
  * =============================================================================
856
806
  */
857
- function Le(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY, a = 0) {
858
- const o = l(r, "boxes", "nonMaxSuppression"), i = l(t, "scores", "nonMaxSuppression"), u = D(o, i, n, e, s, a);
859
- n = u.maxOutputSize, e = u.iouThreshold, s = u.scoreThreshold, a = u.softNmsSigma;
860
- const c = { boxes: o, scores: i }, b = { maxOutputSize: n, iouThreshold: e, scoreThreshold: s, softNmsSigma: a }, m = f.runKernel(vn, c, b);
861
- return { selectedIndices: m[0], selectedScores: m[1] };
807
+ function He(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = 0) {
808
+ const o = u(s, "boxes", "nonMaxSuppression"), i = u(e, "scores", "nonMaxSuppression"), p = R(o, i, n, r, t, a);
809
+ n = p.maxOutputSize, r = p.iouThreshold, t = p.scoreThreshold, a = p.softNmsSigma;
810
+ const c = { boxes: o, scores: i }, b = { maxOutputSize: n, iouThreshold: r, scoreThreshold: t, softNmsSigma: a }, h = f.runKernel(Xn, c, b);
811
+ return { selectedIndices: h[0], selectedScores: h[1] };
862
812
  }
863
- const Xe = /* @__PURE__ */ h({ nonMaxSuppressionWithScore_: Le });
813
+ const Ue = /* @__PURE__ */ m({ nonMaxSuppressionWithScore_: He });
864
814
  /**
865
815
  * @license
866
816
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -877,16 +827,16 @@ const Xe = /* @__PURE__ */ h({ nonMaxSuppressionWithScore_: Le });
877
827
  * limitations under the License.
878
828
  * =============================================================================
879
829
  */
880
- async function Qe(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY, a = 0) {
881
- const o = l(r, "boxes", "nonMaxSuppressionAsync"), i = l(t, "scores", "nonMaxSuppressionAsync"), u = D(o, i, n, e, s, a);
882
- n = u.maxOutputSize, e = u.iouThreshold, s = u.scoreThreshold, a = u.softNmsSigma;
883
- const c = await Promise.all([o.data(), i.data()]), b = c[0], m = c[1], { selectedIndices: $, selectedScores: g } = Oe(b, m, n, e, s, a);
884
- return o !== r && o.dispose(), i !== t && i.dispose(), {
885
- selectedIndices: N($, "int32"),
886
- selectedScores: N(g)
830
+ async function ns(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = 0) {
831
+ const o = u(s, "boxes", "nonMaxSuppressionAsync"), i = u(e, "scores", "nonMaxSuppressionAsync"), p = R(o, i, n, r, t, a);
832
+ n = p.maxOutputSize, r = p.iouThreshold, t = p.scoreThreshold, a = p.softNmsSigma;
833
+ const c = await Promise.all([o.data(), i.data()]), b = c[0], h = c[1], { selectedIndices: g, selectedScores: d } = se(b, h, n, r, t, a);
834
+ return o !== s && o.dispose(), i !== e && i.dispose(), {
835
+ selectedIndices: I(g, "int32"),
836
+ selectedScores: I(d)
887
837
  };
888
838
  }
889
- const He = Qe;
839
+ const es = ns;
890
840
  /**
891
841
  * @license
892
842
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -903,24 +853,24 @@ const He = Qe;
903
853
  * limitations under the License.
904
854
  * =============================================================================
905
855
  */
906
- function Ze(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY, a = !1) {
907
- const o = l(r, "boxes", "nonMaxSuppression"), i = l(t, "scores", "nonMaxSuppression"), u = D(
856
+ function ss(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = !1) {
857
+ const o = u(s, "boxes", "nonMaxSuppression"), i = u(e, "scores", "nonMaxSuppression"), p = R(
908
858
  o,
909
859
  i,
910
860
  n,
911
- e,
912
- s,
861
+ r,
862
+ t,
913
863
  null
914
864
  /* softNmsSigma */
915
- ), c = u.maxOutputSize, b = u.iouThreshold, m = u.scoreThreshold, $ = { boxes: o, scores: i }, g = {
865
+ ), c = p.maxOutputSize, b = p.iouThreshold, h = p.scoreThreshold, g = { boxes: o, scores: i }, d = {
916
866
  maxOutputSize: c,
917
867
  iouThreshold: b,
918
- scoreThreshold: m,
868
+ scoreThreshold: h,
919
869
  padToMaxOutputSize: a
920
- }, x = f.runKernel(jn, $, g);
921
- return { selectedIndices: x[0], validOutputs: x[1] };
870
+ }, y = f.runKernel(Qn, g, d);
871
+ return { selectedIndices: y[0], validOutputs: y[1] };
922
872
  }
923
- const Ue = /* @__PURE__ */ h({ nonMaxSuppressionPadded_: Ze });
873
+ const ts = /* @__PURE__ */ m({ nonMaxSuppressionPadded_: ss });
924
874
  /**
925
875
  * @license
926
876
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -937,22 +887,22 @@ const Ue = /* @__PURE__ */ h({ nonMaxSuppressionPadded_: Ze });
937
887
  * limitations under the License.
938
888
  * =============================================================================
939
889
  */
940
- async function ns(r, t, n, e = 0.5, s = Number.NEGATIVE_INFINITY, a = !1) {
941
- const o = l(r, "boxes", "nonMaxSuppressionAsync"), i = l(t, "scores", "nonMaxSuppressionAsync"), u = D(
890
+ async function rs(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = !1) {
891
+ const o = u(s, "boxes", "nonMaxSuppressionAsync"), i = u(e, "scores", "nonMaxSuppressionAsync"), p = R(
942
892
  o,
943
893
  i,
944
894
  n,
945
- e,
946
- s,
895
+ r,
896
+ t,
947
897
  null
948
898
  /* softNmsSigma */
949
- ), c = u.maxOutputSize, b = u.iouThreshold, m = u.scoreThreshold, [$, g] = await Promise.all([o.data(), i.data()]), { selectedIndices: x, validOutputs: y } = Fe($, g, c, b, m, a);
950
- return o !== r && o.dispose(), i !== t && i.dispose(), {
951
- selectedIndices: N(x, "int32"),
952
- validOutputs: Fn(y, "int32")
899
+ ), c = p.maxOutputSize, b = p.iouThreshold, h = p.scoreThreshold, [g, d] = await Promise.all([o.data(), i.data()]), { selectedIndices: y, validOutputs: M } = te(g, d, c, b, h, a);
900
+ return o !== s && o.dispose(), i !== e && i.dispose(), {
901
+ selectedIndices: I(y, "int32"),
902
+ validOutputs: pn(M, "int32")
953
903
  };
954
904
  }
955
- const es = ns;
905
+ const as = rs;
956
906
  /**
957
907
  * @license
958
908
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -969,15 +919,15 @@ const es = ns;
969
919
  * limitations under the License.
970
920
  * =============================================================================
971
921
  */
972
- function ss(r, t, n = !1, e = !1) {
973
- const s = l(r, "images", "resizeBilinear");
974
- p(s.rank === 3 || s.rank === 4, () => `Error in resizeBilinear: x must be rank 3 or 4, but got rank ${s.rank}.`), p(t.length === 2, () => `Error in resizeBilinear: new shape must 2D, but got shape ${t}.`), p(e === !1 || n === !1, () => "Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false.");
975
- let a = s, o = !1;
976
- s.rank === 3 && (o = !0, a = _(s, [1, s.shape[0], s.shape[1], s.shape[2]]));
977
- const i = { images: a }, u = { alignCorners: n, halfPixelCenters: e, size: t }, c = f.runKernel(On, i, u);
978
- return o ? _(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
922
+ function os(s, e, n = !1, r = !1) {
923
+ const t = u(s, "images", "resizeBilinear");
924
+ l(t.rank === 3 || t.rank === 4, () => `Error in resizeBilinear: x must be rank 3 or 4, but got rank ${t.rank}.`), l(e.length === 2, () => `Error in resizeBilinear: new shape must 2D, but got shape ${e}.`), l(r === !1 || n === !1, () => "Error in resizeBilinear: If halfPixelCenters is true, alignCorners must be false.");
925
+ let a = t, o = !1;
926
+ t.rank === 3 && (o = !0, a = k(t, [1, t.shape[0], t.shape[1], t.shape[2]]));
927
+ const i = { images: a }, p = { alignCorners: n, halfPixelCenters: r, size: e }, c = f.runKernel(Jn, i, p);
928
+ return o ? k(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
979
929
  }
980
- const ts = /* @__PURE__ */ h({ resizeBilinear_: ss });
930
+ const is = /* @__PURE__ */ m({ resizeBilinear_: os });
981
931
  /**
982
932
  * @license
983
933
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -994,15 +944,15 @@ const ts = /* @__PURE__ */ h({ resizeBilinear_: ss });
994
944
  * limitations under the License.
995
945
  * =============================================================================
996
946
  */
997
- function rs(r, t, n = !1, e = !1) {
998
- const s = l(r, "images", "resizeNearestNeighbor");
999
- p(s.rank === 3 || s.rank === 4, () => `Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank ${s.rank}.`), p(t.length === 2, () => `Error in resizeNearestNeighbor: new shape must 2D, but got shape ${t}.`), p(s.dtype === "float32" || s.dtype === "int32", () => "`images` must have `int32` or `float32` as dtype"), p(e === !1 || n === !1, () => "Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false.");
1000
- let a = s, o = !1;
1001
- s.rank === 3 && (o = !0, a = _(s, [1, s.shape[0], s.shape[1], s.shape[2]]));
1002
- const i = { images: a }, u = { alignCorners: n, halfPixelCenters: e, size: t }, c = f.runKernel(Wn, i, u);
1003
- return o ? _(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
947
+ function cs(s, e, n = !1, r = !1) {
948
+ const t = u(s, "images", "resizeNearestNeighbor");
949
+ l(t.rank === 3 || t.rank === 4, () => `Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank ${t.rank}.`), l(e.length === 2, () => `Error in resizeNearestNeighbor: new shape must 2D, but got shape ${e}.`), l(t.dtype === "float32" || t.dtype === "int32", () => "`images` must have `int32` or `float32` as dtype"), l(r === !1 || n === !1, () => "Error in resizeNearestNeighbor: If halfPixelCenters is true, alignCorners must be false.");
950
+ let a = t, o = !1;
951
+ t.rank === 3 && (o = !0, a = k(t, [1, t.shape[0], t.shape[1], t.shape[2]]));
952
+ const i = { images: a }, p = { alignCorners: n, halfPixelCenters: r, size: e }, c = f.runKernel(Zn, i, p);
953
+ return o ? k(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
1004
954
  }
1005
- const as = /* @__PURE__ */ h({ resizeNearestNeighbor_: rs });
955
+ const us = /* @__PURE__ */ m({ resizeNearestNeighbor_: cs });
1006
956
  /**
1007
957
  * @license
1008
958
  * Copyright 2021 Google LLC. All Rights Reserved.
@@ -1019,38 +969,38 @@ const as = /* @__PURE__ */ h({ resizeNearestNeighbor_: rs });
1019
969
  * limitations under the License.
1020
970
  * =============================================================================
1021
971
  */
1022
- function os(r, t = "binary", n = !1, e = 0.5) {
1023
- const s = l(r, "image", "threshold"), a = 0.2989, o = 0.587, i = 0.114, u = s.shape[0] * s.shape[1];
1024
- let c = k(N([e]), 255), b, m, $, g;
1025
- if (p(s.rank === 3, () => `Error in threshold: image must be rank 3,but got rank ${s.rank}.`), p(s.shape[2] === 3 || s.shape[2] === 1, () => `Error in threshold: image color channel must be equal to 3 or 1but got ${s.shape[2]}.`), p(s.dtype === "int32" || s.dtype === "float32", () => `Error in dtype: image dtype must be int32 or float32,but got dtype ${s.dtype}.`), p(t === "otsu" || t === "binary", () => `Method must be binary or otsu, but was ${t}`), s.shape[2] === 3) {
1026
- [b, m, $] = un(s, [1, 1, 1], -1);
1027
- const d = k(b, a), E = k(m, o), I = k($, i);
1028
- g = Z(Z(d, E), I);
972
+ function ls(s, e = "binary", n = !1, r = 0.5) {
973
+ const t = u(s, "image", "threshold"), a = 0.2989, o = 0.587, i = 0.114, p = t.shape[0] * t.shape[1];
974
+ let c = $(I([r]), 255), b, h, g, d;
975
+ if (l(t.rank === 3, () => `Error in threshold: image must be rank 3,but got rank ${t.rank}.`), l(t.shape[2] === 3 || t.shape[2] === 1, () => `Error in threshold: image color channel must be equal to 3 or 1but got ${t.shape[2]}.`), l(t.dtype === "int32" || t.dtype === "float32", () => `Error in dtype: image dtype must be int32 or float32,but got dtype ${t.dtype}.`), l(e === "otsu" || e === "binary", () => `Method must be binary or otsu, but was ${e}`), t.shape[2] === 3) {
976
+ [b, h, g] = mn(t, [1, 1, 1], -1);
977
+ const T = $(b, a), K = $(h, o), x = $(g, i);
978
+ d = U(U(T, K), x);
1029
979
  } else
1030
- g = r;
1031
- if (t === "otsu") {
1032
- const d = Un(V(ke(g), "int32"), Ln([]), 256);
1033
- c = is(d, u);
980
+ d = s;
981
+ if (e === "otsu") {
982
+ const T = le(G(Ke(d), "int32"), re([]), 256);
983
+ c = ps(T, p);
1034
984
  }
1035
- const x = n ? pn(g, c) : U(g, c);
1036
- return V(k(x, 255), "int32");
985
+ const y = n ? bn(d, c) : nn(d, c);
986
+ return G($(y, 255), "int32");
1037
987
  }
1038
- function is(r, t) {
1039
- let n = N([-1]), e = N([0]), s = N([0]), a, o, i, u, c, b;
1040
- for (let m = 0; m < r.size - 1; m++) {
1041
- a = M(r, 0, m + 1), o = M(r, m + 1), c = R(q(a), t), b = R(q(o), t);
1042
- const $ = q(k(a, W(0, a.size)));
1043
- i = R($, q(a));
1044
- const g = Yn(o.shape, a.size), x = Z(W(0, o.size), g), y = k(o, x);
1045
- u = R(q(y), q(o));
1046
- const d = S(i, u), E = S(i, u), I = k(c, b);
1047
- s = k(k(I, d), E);
1048
- const A = U(s, e);
1049
- e = G(A, s, e), n = G(A, N([m]), n);
988
+ function ps(s, e) {
989
+ let n = I([-1]), r = I([0]), t = I([0]), a, o, i, p, c, b;
990
+ for (let h = 0; h < s.size - 1; h++) {
991
+ a = _(s, 0, h + 1), o = _(s, h + 1), c = q(E(a), e), b = q(E(o), e);
992
+ const g = E($(a, W(0, a.size)));
993
+ i = q(g, E(a));
994
+ const d = Hn(o.shape, a.size), y = U(W(0, o.size), d), M = $(o, y);
995
+ p = q(E(M), E(o));
996
+ const T = A(i, p), K = A(i, p), x = $(c, b);
997
+ t = $($(x, T), K);
998
+ const V = nn(t, r);
999
+ r = B(V, t, r), n = B(V, I([h]), n);
1050
1000
  }
1051
1001
  return n;
1052
1002
  }
1053
- const cs = /* @__PURE__ */ h({ threshold_: os });
1003
+ const ms = /* @__PURE__ */ m({ threshold_: ls });
1054
1004
  /**
1055
1005
  * @license
1056
1006
  * Copyright 2021 Google LLC. All Rights Reserved.
@@ -1067,13 +1017,13 @@ const cs = /* @__PURE__ */ h({ threshold_: os });
1067
1017
  * limitations under the License.
1068
1018
  * =============================================================================
1069
1019
  */
1070
- function us(r, t, n = "nearest", e = "constant", s = 0, a) {
1071
- const o = l(r, "image", "transform", "float32"), i = l(t, "transforms", "transform", "float32");
1072
- p(o.rank === 4, () => `Error in transform: image must be rank 4,but got rank ${o.rank}.`), p(i.rank === 2 && (i.shape[0] === o.shape[0] || i.shape[0] === 1) && i.shape[1] === 8, () => "Error in transform: Input transform should be batch x 8 or 1 x 8"), p(a == null || a.length === 2, () => `Error in transform: outputShape must be [height, width] or null, but got ${a}.`);
1073
- const u = { image: o, transforms: i }, c = { interpolation: n, fillMode: e, fillValue: s, outputShape: a };
1074
- return f.runKernel(Cn, u, c);
1020
+ function fs(s, e, n = "nearest", r = "constant", t = 0, a) {
1021
+ const o = u(s, "image", "transform", "float32"), i = u(e, "transforms", "transform", "float32");
1022
+ l(o.rank === 4, () => `Error in transform: image must be rank 4,but got rank ${o.rank}.`), l(i.rank === 2 && (i.shape[0] === o.shape[0] || i.shape[0] === 1) && i.shape[1] === 8, () => "Error in transform: Input transform should be batch x 8 or 1 x 8"), l(a == null || a.length === 2, () => `Error in transform: outputShape must be [height, width] or null, but got ${a}.`);
1023
+ const p = { image: o, transforms: i }, c = { interpolation: n, fillMode: r, fillValue: t, outputShape: a };
1024
+ return f.runKernel(Un, p, c);
1075
1025
  }
1076
- const ls = /* @__PURE__ */ h({ transform_: us });
1026
+ const hs = /* @__PURE__ */ m({ transform_: fs });
1077
1027
  /**
1078
1028
  * @license
1079
1029
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -1090,16 +1040,16 @@ const ls = /* @__PURE__ */ h({ transform_: us });
1090
1040
  * limitations under the License.
1091
1041
  * =============================================================================
1092
1042
  */
1093
- function ps(r, t, n) {
1094
- const e = l(r, "a", "bandPart");
1095
- p(e.rank >= 2, () => `bandPart(): Rank must be at least 2, got ${e.rank}.`);
1096
- const s = e.shape, [a, o] = e.shape.slice(-2);
1097
- let i, u;
1098
- typeof t == "number" ? (p(t % 1 === 0, () => `bandPart(): numLower must be an integer, got ${t}.`), p(t <= a, () => `bandPart(): numLower (${t}) must not be greater than the number of rows (${a}).`), i = l(t < 0 ? a : t, "numLower", "bandPart")) : (p(t.dtype === "int32", () => "bandPart(): numLower's dtype must be an int32."), i = G(tn(t, 0), a, rn(t, a))), typeof n == "number" ? (p(n % 1 === 0, () => `bandPart(): numUpper must be an integer, got ${n}.`), p(n <= o, () => `bandPart(): numUpper (${n}) must not be greater than the number of columns (${o}).`), u = l(n < 0 ? o : n, "numUpper", "bandPart")) : (p(n.dtype === "int32", () => "bandPart(): numUpper's dtype must be an int32."), u = G(tn(n, 0), o, rn(n, o)));
1099
- const c = _(W(0, a, 1, "int32"), [-1, 1]), b = W(0, o, 1, "int32"), m = S(c, b), $ = be(pn(m, i), ce(m, nn(u))), g = Qn([a, o], e.dtype);
1100
- return _(Y(mn(_(e, [-1, a, o])).map((x) => G($, x, g))), s);
1043
+ function bs(s, e, n) {
1044
+ const r = u(s, "a", "bandPart");
1045
+ l(r.rank >= 2, () => `bandPart(): Rank must be at least 2, got ${r.rank}.`);
1046
+ const t = r.shape, [a, o] = r.shape.slice(-2);
1047
+ let i, p;
1048
+ typeof e == "number" ? (l(e % 1 === 0, () => `bandPart(): numLower must be an integer, got ${e}.`), l(e <= a, () => `bandPart(): numLower (${e}) must not be greater than the number of rows (${a}).`), i = u(e < 0 ? a : e, "numLower", "bandPart")) : (l(e.dtype === "int32", () => "bandPart(): numLower's dtype must be an int32."), i = B(on(e, 0), a, cn(e, a))), typeof n == "number" ? (l(n % 1 === 0, () => `bandPart(): numUpper must be an integer, got ${n}.`), l(n <= o, () => `bandPart(): numUpper (${n}) must not be greater than the number of columns (${o}).`), p = u(n < 0 ? o : n, "numUpper", "bandPart")) : (l(n.dtype === "int32", () => "bandPart(): numUpper's dtype must be an int32."), p = B(on(n, 0), o, cn(n, o)));
1049
+ const c = k(W(0, a, 1, "int32"), [-1, 1]), b = W(0, o, 1, "int32"), h = A(c, b), g = we(bn(h, i), Ee(h, en(p))), d = oe([a, o], r.dtype);
1050
+ return k(O(dn(k(r, [-1, a, o])).map((y) => B(g, y, d))), t);
1101
1051
  }
1102
- const ms = /* @__PURE__ */ h({ bandPart_: ps });
1052
+ const ds = /* @__PURE__ */ m({ bandPart_: bs });
1103
1053
  /**
1104
1054
  * @license
1105
1055
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -1116,30 +1066,30 @@ const ms = /* @__PURE__ */ h({ bandPart_: ps });
1116
1066
  * limitations under the License.
1117
1067
  * =============================================================================
1118
1068
  */
1119
- function hs(r) {
1120
- let t;
1121
- if (Array.isArray(r)) {
1122
- t = !1, p(r != null && r.length > 0, () => "Gram-Schmidt process: input must not be null, undefined, or empty");
1123
- const s = r[0].shape[0];
1124
- for (let a = 1; a < r.length; ++a)
1125
- p(r[a].shape[0] === s, () => `Gram-Schmidt: Non-unique lengths found in the input vectors: (${r[a].shape[0]} vs. ${s})`);
1069
+ function gs(s) {
1070
+ let e;
1071
+ if (Array.isArray(s)) {
1072
+ e = !1, l(s != null && s.length > 0, () => "Gram-Schmidt process: input must not be null, undefined, or empty");
1073
+ const t = s[0].shape[0];
1074
+ for (let a = 1; a < s.length; ++a)
1075
+ l(s[a].shape[0] === t, () => `Gram-Schmidt: Non-unique lengths found in the input vectors: (${s[a].shape[0]} vs. ${t})`);
1126
1076
  } else
1127
- t = !0, r = un(r, r.shape[0], 0).map((s) => Ie(s, [0]));
1128
- p(r.length <= r[0].shape[0], () => `Gram-Schmidt: Number of vectors (${r.length}) exceeds number of dimensions (${r[0].shape[0]}).`);
1129
- const n = [], e = r;
1130
- for (let s = 0; s < r.length; ++s)
1077
+ e = !0, s = mn(s, s.shape[0], 0).map((t) => Ge(t, [0]));
1078
+ l(s.length <= s[0].shape[0], () => `Gram-Schmidt: Number of vectors (${s.length}) exceeds number of dimensions (${s[0].shape[0]}).`);
1079
+ const n = [], r = s;
1080
+ for (let t = 0; t < s.length; ++t)
1131
1081
  n.push(f.tidy(() => {
1132
- let a = e[s];
1133
- if (s > 0)
1134
- for (let o = 0; o < s; ++o) {
1135
- const i = k(q(k(n[o], a)), n[o]);
1136
- a = S(a, i);
1082
+ let a = r[t];
1083
+ if (t > 0)
1084
+ for (let o = 0; o < t; ++o) {
1085
+ const i = $(E($(n[o], a)), n[o]);
1086
+ a = A(a, i);
1137
1087
  }
1138
- return R(a, ln(a, "euclidean"));
1088
+ return q(a, hn(a, "euclidean"));
1139
1089
  }));
1140
- return t ? Y(n, 0) : n;
1090
+ return e ? O(n, 0) : n;
1141
1091
  }
1142
- const fs = /* @__PURE__ */ h({ gramSchmidt_: hs });
1092
+ const $s = /* @__PURE__ */ m({ gramSchmidt_: gs });
1143
1093
  /**
1144
1094
  * @license
1145
1095
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -1156,60 +1106,60 @@ const fs = /* @__PURE__ */ h({ gramSchmidt_: hs });
1156
1106
  * limitations under the License.
1157
1107
  * =============================================================================
1158
1108
  */
1159
- function bs(r, t = !1) {
1160
- if (p(r.rank >= 2, () => `qr() requires input tensor to have a rank >= 2, but got rank ${r.rank}`), r.rank === 2)
1161
- return cn(r, t);
1109
+ function ks(s, e = !1) {
1110
+ if (l(s.rank >= 2, () => `qr() requires input tensor to have a rank >= 2, but got rank ${s.rank}`), s.rank === 2)
1111
+ return ln(s, e);
1162
1112
  {
1163
- const n = r.shape.slice(0, r.shape.length - 2).reduce((u, c) => u * c), e = mn(_(r, [
1113
+ const n = s.shape.slice(0, s.shape.length - 2).reduce((p, c) => p * c), r = dn(k(s, [
1164
1114
  n,
1165
- r.shape[r.shape.length - 2],
1166
- r.shape[r.shape.length - 1]
1167
- ]), 0), s = [], a = [];
1168
- e.forEach((u) => {
1169
- const [c, b] = cn(u, t);
1170
- s.push(c), a.push(b);
1115
+ s.shape[s.shape.length - 2],
1116
+ s.shape[s.shape.length - 1]
1117
+ ]), 0), t = [], a = [];
1118
+ r.forEach((p) => {
1119
+ const [c, b] = ln(p, e);
1120
+ t.push(c), a.push(b);
1171
1121
  });
1172
- const o = _(Y(s, 0), r.shape), i = _(Y(a, 0), r.shape);
1122
+ const o = k(O(t, 0), s.shape), i = k(O(a, 0), s.shape);
1173
1123
  return [o, i];
1174
1124
  }
1175
1125
  }
1176
- function cn(r, t = !1) {
1126
+ function ln(s, e = !1) {
1177
1127
  return f.tidy(() => {
1178
- p(r.shape.length === 2, () => `qr2d() requires a 2D Tensor, but got a ${r.shape.length}D Tensor.`);
1179
- const n = r.shape[0], e = r.shape[1];
1180
- let s = ae(n), a = L(r);
1128
+ l(s.shape.length === 2, () => `qr2d() requires a 2D Tensor, but got a ${s.shape.length}D Tensor.`);
1129
+ const n = s.shape[0], r = s.shape[1];
1130
+ let t = $e(n), a = X(s);
1181
1131
  const o = H([[1]], [1, 1]);
1182
- let i = L(o);
1183
- const u = n >= e ? e : n;
1184
- for (let c = 0; c < u; ++c) {
1185
- const b = a, m = i, $ = s;
1186
- [i, a, s] = f.tidy(() => {
1187
- const g = M(a, [c, c], [n - c, 1]), x = ln(g), y = M(a, [c, c], [1, 1]), d = G(U(y, 0), H([[-1]]), H([[1]])), E = S(y, k(d, x)), I = R(g, E);
1188
- I.shape[0] === 1 ? i = L(o) : i = Q([
1132
+ let i = X(o);
1133
+ const p = n >= r ? r : n;
1134
+ for (let c = 0; c < p; ++c) {
1135
+ const b = a, h = i, g = t;
1136
+ [i, a, t] = f.tidy(() => {
1137
+ const d = _(a, [c, c], [n - c, 1]), y = hn(d), M = _(a, [c, c], [1, 1]), T = B(nn(M, 0), H([[-1]]), H([[1]])), K = A(M, $(T, y)), x = q(d, K);
1138
+ x.shape[0] === 1 ? i = X(o) : i = Z([
1189
1139
  o,
1190
- M(I, [1, 0], [I.shape[0] - 1, I.shape[1]])
1140
+ _(x, [1, 0], [x.shape[0] - 1, x.shape[1]])
1191
1141
  ], 0);
1192
- const A = nn(R(T(d, E), x)), z = M(a, [c, 0], [n - c, e]), B = k(A, i), P = an(i);
1142
+ const V = en(q(N(T, K), y)), P = _(a, [c, 0], [n - c, r]), Y = $(V, i), sn = un(i);
1193
1143
  if (c === 0)
1194
- a = S(z, T(B, T(P, z)));
1144
+ a = A(P, N(Y, N(sn, P)));
1195
1145
  else {
1196
- const C = S(z, T(B, T(P, z)));
1197
- a = Q([M(a, [0, 0], [c, e]), C], 0);
1146
+ const L = A(P, N(Y, N(sn, P)));
1147
+ a = Z([_(a, [0, 0], [c, r]), L], 0);
1198
1148
  }
1199
- const sn = an(B), F = M(s, [0, c], [n, s.shape[1] - c]);
1149
+ const tn = un(Y), j = _(t, [0, c], [n, t.shape[1] - c]);
1200
1150
  if (c === 0)
1201
- s = S(F, T(T(F, i), sn));
1151
+ t = A(j, N(N(j, i), tn));
1202
1152
  else {
1203
- const C = S(F, T(T(F, i), sn));
1204
- s = Q([M(s, [0, 0], [n, c]), C], 1);
1153
+ const L = A(j, N(N(j, i), tn));
1154
+ t = Z([_(t, [0, 0], [n, c]), L], 1);
1205
1155
  }
1206
- return [i, a, s];
1207
- }), Jn([b, m, $]);
1156
+ return [i, a, t];
1157
+ }), ne([b, h, g]);
1208
1158
  }
1209
- return !t && n > e && (s = M(s, [0, 0], [n, e]), a = M(a, [0, 0], [e, e])), [s, a];
1159
+ return !e && n > r && (t = _(t, [0, 0], [n, r]), a = _(a, [0, 0], [r, r])), [t, a];
1210
1160
  });
1211
1161
  }
1212
- const ds = /* @__PURE__ */ h({ qr_: bs });
1162
+ const ys = /* @__PURE__ */ m({ qr_: ks });
1213
1163
  /**
1214
1164
  * @license
1215
1165
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -1226,52 +1176,51 @@ const ds = /* @__PURE__ */ h({ qr_: bs });
1226
1176
  * limitations under the License.
1227
1177
  * =============================================================================
1228
1178
  */
1229
- const ws = {
1230
- flipLeftRight: Te,
1231
- grayscaleToRGB: we,
1232
- resizeNearestNeighbor: as,
1233
- resizeBilinear: ts,
1234
- rgbToGrayscale: Be,
1235
- rotateWithOffset: Ke,
1236
- cropAndResize: Ne,
1237
- nonMaxSuppression: Ge,
1238
- nonMaxSuppressionAsync: Je,
1239
- nonMaxSuppressionWithScore: Xe,
1240
- nonMaxSuppressionWithScoreAsync: He,
1241
- nonMaxSuppressionPadded: Ue,
1242
- nonMaxSuppressionPaddedAsync: es,
1243
- threshold: cs,
1244
- transform: ls
1245
- }, zs = {
1246
- bandPart: ms,
1247
- gramSchmidt: fs,
1248
- qr: ds
1179
+ const Rs = {
1180
+ flipLeftRight: je,
1181
+ grayscaleToRGB: We,
1182
+ resizeNearestNeighbor: us,
1183
+ resizeBilinear: is,
1184
+ rgbToGrayscale: Ye,
1185
+ rotateWithOffset: Ce,
1186
+ cropAndResize: Ve,
1187
+ nonMaxSuppression: Qe,
1188
+ nonMaxSuppressionAsync: Ze,
1189
+ nonMaxSuppressionWithScore: Ue,
1190
+ nonMaxSuppressionWithScoreAsync: es,
1191
+ nonMaxSuppressionPadded: ts,
1192
+ nonMaxSuppressionPaddedAsync: as,
1193
+ threshold: ms,
1194
+ transform: hs
1195
+ }, Ds = {
1196
+ bandPart: ds,
1197
+ gramSchmidt: $s,
1198
+ qr: ys
1249
1199
  };
1250
1200
  export {
1251
- be as a,
1252
- pn as b,
1253
- an as c,
1254
- O as d,
1255
- U as e,
1256
- tn as f,
1257
- ce as g,
1258
- K as h,
1259
- ae as i,
1260
- Ie as j,
1261
- ws as k,
1262
- zs as l,
1263
- rn as m,
1264
- nn as n,
1265
- le as o,
1266
- ts as p,
1267
- as as q,
1268
- $e as r,
1269
- M as s,
1270
- N as t,
1271
- mn as u,
1272
- ke as v,
1273
- G as w,
1274
- je as x,
1275
- Fe as y,
1276
- Oe as z
1201
+ we as a,
1202
+ bn as b,
1203
+ F as c,
1204
+ nn as d,
1205
+ on as e,
1206
+ z as f,
1207
+ Ee as g,
1208
+ I as h,
1209
+ $e as i,
1210
+ Ge as j,
1211
+ Rs as k,
1212
+ Ds as l,
1213
+ cn as m,
1214
+ en as n,
1215
+ an as o,
1216
+ hn as p,
1217
+ Ie as q,
1218
+ ze as r,
1219
+ _ as s,
1220
+ un as t,
1221
+ dn as u,
1222
+ is as v,
1223
+ B as w,
1224
+ us as x,
1225
+ Ke as y
1277
1226
  };