@genai-fi/nanogpt 0.6.3 → 0.7.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 (169) hide show
  1. package/dist/Generator.js +17 -13
  2. package/dist/NanoGPTModel.d.ts +2 -2
  3. package/dist/NanoGPTModel.js +104 -136
  4. package/dist/{RealDiv-BYViZwhN.js → RealDiv-CVYNbZxu.js} +30 -29
  5. package/dist/{Reshape-t7Kcikjk.js → Reshape-CEsEp0AI.js} +5 -5
  6. package/dist/Reshape-Do18N3gO.js +30 -0
  7. package/dist/TeachableLLM.js +9 -5
  8. package/dist/{TiedEmbedding-9WeDwvjO.js → TiedEmbedding-ccLBFiZi.js} +4 -4
  9. package/dist/{axis_util-Bu4h7XWV.js → axis_util-5DTW2tFV.js} +3 -3
  10. package/dist/backend.d.ts +1 -0
  11. package/dist/backend.js +7 -0
  12. package/dist/backend_util-C9Ut8n0Q.js +749 -0
  13. package/dist/{broadcast_to-DARN-DBD.js → broadcast_to-Ba9h_8DO.js} +2 -2
  14. package/dist/{concat-5aPGqw3Z.js → concat-CbXTetof.js} +8 -8
  15. package/dist/{dataset-pgqp-YfL.js → dataset-U3PrjwgU.js} +7 -7
  16. package/dist/{dropout-Bciw46HT.js → dropout-DPfPgWWe.js} +8 -8
  17. package/dist/{gather-DjyCjmOD.js → gather-Bbh8DHhM.js} +1 -1
  18. package/dist/gelu-BFwVnd1r.js +26 -0
  19. package/dist/gpgpu_math-DffelNS-.js +2371 -0
  20. package/dist/index-DYD_yPa-.js +12076 -0
  21. package/dist/{index-BAzbokzv.js → index-UdZhlibC.js} +414 -398
  22. package/dist/{kernel_funcs_utils-CUxJCg0g.js → kernel_funcs_utils-CXDy3EN7.js} +31 -30
  23. package/dist/layers/BaseLayer.js +2 -2
  24. package/dist/layers/CausalSelfAttention.js +8 -8
  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 +11 -7
  32. package/dist/{log_sum_exp-YEo2h3gb.js → log_sum_exp-BnmCkHWl.js} +16 -16
  33. package/dist/main.d.ts +13 -0
  34. package/dist/main.js +44 -23
  35. package/dist/{mat_mul-7121rsJk.js → mat_mul-dwmZz69e.js} +4 -4
  36. package/dist/{max-DtlIuVeW.js → max-ByjEGoFx.js} +3 -3
  37. package/dist/{mulmat_packed_gpu-D4nKF7Je.js → mulmat_packed_gpu-IGPBp6h9.js} +1 -1
  38. package/dist/non_max_suppression_impl-CsEgBuMA.js +134 -0
  39. package/dist/{ones-BBlSRqn1.js → ones-C8Mfln6-.js} +2 -2
  40. package/dist/ops/adamAdjust.d.ts +2 -0
  41. package/dist/ops/adamAdjust.js +9 -0
  42. package/dist/ops/adamMoments.d.ts +2 -0
  43. package/dist/ops/adamMoments.js +9 -0
  44. package/dist/ops/appendCache.js +3 -3
  45. package/dist/ops/attentionMask.js +1 -1
  46. package/dist/ops/cpu/adamAdjust.d.ts +1 -0
  47. package/dist/ops/cpu/adamAdjust.js +18 -0
  48. package/dist/ops/cpu/adamMoments.d.ts +1 -0
  49. package/dist/ops/cpu/adamMoments.js +16 -0
  50. package/dist/ops/cpu/appendCache.js +8 -8
  51. package/dist/ops/cpu/attentionMask.js +9 -9
  52. package/dist/ops/cpu/fusedSoftmax.js +17 -11
  53. package/dist/ops/cpu/gatherSub.js +7 -7
  54. package/dist/ops/cpu/gelu.js +13 -13
  55. package/dist/ops/cpu/matMulGelu.js +36 -24
  56. package/dist/ops/cpu/matMulMul.js +14 -8
  57. package/dist/ops/cpu/mulDropout.js +9 -3
  58. package/dist/ops/cpu/normRMS.js +5 -5
  59. package/dist/ops/cpu/qkv.js +3 -3
  60. package/dist/ops/cpu/rope.js +5 -5
  61. package/dist/ops/cpu/scatterSub.js +11 -11
  62. package/dist/ops/fusedSoftmax.js +1 -1
  63. package/dist/ops/gatherSub.js +1 -1
  64. package/dist/ops/gelu.js +2 -2
  65. package/dist/ops/grads/attentionMask.js +1 -1
  66. package/dist/ops/grads/fusedSoftmax.js +2 -2
  67. package/dist/ops/grads/gelu.js +3 -24
  68. package/dist/ops/grads/matMulGelu.js +5 -5
  69. package/dist/ops/grads/normRMS.js +6 -6
  70. package/dist/ops/grads/qkv.js +1 -1
  71. package/dist/ops/grads/rope.js +3 -3
  72. package/dist/ops/matMulGelu.js +1 -1
  73. package/dist/ops/matMulMul.js +1 -1
  74. package/dist/ops/mulDrop.js +1 -1
  75. package/dist/ops/normRMS.js +1 -1
  76. package/dist/ops/qkv.js +1 -1
  77. package/dist/ops/rope.js +4 -4
  78. package/dist/ops/scatterSub.js +1 -1
  79. package/dist/ops/webgl/adamAdjust.d.ts +1 -0
  80. package/dist/ops/webgl/adamAdjust.js +50 -0
  81. package/dist/ops/webgl/adamMoments.d.ts +1 -0
  82. package/dist/ops/webgl/adamMoments.js +38 -0
  83. package/dist/ops/webgl/appendCache.js +1 -1
  84. package/dist/ops/webgl/attentionMask.js +1 -1
  85. package/dist/ops/webgl/fusedSoftmax.js +4 -4
  86. package/dist/ops/webgl/gatherSub.js +8 -8
  87. package/dist/ops/webgl/gelu.js +2 -2
  88. package/dist/ops/webgl/log.js +5 -5
  89. package/dist/ops/webgl/matMulGelu.js +17 -17
  90. package/dist/ops/webgl/matMulMul.js +1 -1
  91. package/dist/ops/webgl/mulDropout.js +4 -4
  92. package/dist/ops/webgl/normRMS.js +2 -2
  93. package/dist/ops/webgl/qkv.js +1 -1
  94. package/dist/ops/webgl/rope.js +1 -1
  95. package/dist/ops/webgl/scatterSub.js +1 -1
  96. package/dist/ops/webgpu/adamAdjust.d.ts +1 -0
  97. package/dist/ops/webgpu/adamAdjust.js +52 -0
  98. package/dist/ops/webgpu/adamMoments.d.ts +1 -0
  99. package/dist/ops/webgpu/adamMoments.js +51 -0
  100. package/dist/ops/webgpu/appendCache.d.ts +1 -0
  101. package/dist/ops/webgpu/appendCache.js +57 -0
  102. package/dist/ops/webgpu/attentionMask.d.ts +1 -0
  103. package/dist/ops/webgpu/attentionMask.js +65 -0
  104. package/dist/ops/webgpu/gatherSub.d.ts +1 -0
  105. package/dist/ops/webgpu/gatherSub.js +52 -0
  106. package/dist/ops/webgpu/gelu.d.ts +14 -0
  107. package/dist/ops/webgpu/gelu.js +87 -0
  108. package/dist/ops/webgpu/index.d.ts +0 -0
  109. package/dist/ops/webgpu/index.js +11 -0
  110. package/dist/ops/webgpu/normRMS.d.ts +1 -0
  111. package/dist/ops/webgpu/normRMS.js +41 -0
  112. package/dist/ops/webgpu/normRMSGrad.d.ts +1 -0
  113. package/dist/ops/webgpu/normRMSGrad.js +128 -0
  114. package/dist/ops/webgpu/qkv.d.ts +1 -0
  115. package/dist/ops/webgpu/qkv.js +57 -0
  116. package/dist/ops/webgpu/rope.d.ts +1 -0
  117. package/dist/ops/webgpu/rope.js +69 -0
  118. package/dist/ops/webgpu/scatterSub.d.ts +1 -0
  119. package/dist/ops/webgpu/scatterSub.js +38 -0
  120. package/dist/ops/webgpu/utils/reductions.d.ts +9 -0
  121. package/dist/ops/webgpu/utils/reductions.js +68 -0
  122. package/dist/{ops-C0sQEcPw.js → ops-aRTXR2Sr.js} +433 -508
  123. package/dist/{random_width-DWzaOgrn.js → random_width-DbSpgl4o.js} +144 -144
  124. package/dist/{range-DYsrnfiy.js → range-D9CZhVlR.js} +1 -1
  125. package/dist/{reciprocal-CJQeasVa.js → reciprocal-CGB48wZB.js} +1 -1
  126. package/dist/{register_all_kernels-BfFCQAqs.js → register_all_kernels-DnbAyBXt.js} +203 -200
  127. package/dist/{reshape-krWGKraP.js → reshape-BR0eoLYN.js} +1 -1
  128. package/dist/{scatter_nd_util-93ln7Hut.js → scatter_nd_util-OjyAxku2.js} +3 -3
  129. package/dist/{selu_util-sntGesxr.js → selu_util-Ce6pu9IM.js} +44 -44
  130. package/dist/{shared-Ca6iDobD.js → shared-Czipaeb6.js} +541 -606
  131. package/dist/shared-DS5waSIY.js +69 -0
  132. package/dist/{sin-D_h-qCSx.js → sin-CiBxrDqX.js} +1 -1
  133. package/dist/slice-BHbDHObE.js +28 -0
  134. package/dist/{softmax-fsdtf6JC.js → softmax-JMEIUo2J.js} +1 -1
  135. package/dist/{split-eiktj-6L.js → split-CRU0PjVV.js} +4 -4
  136. package/dist/{stack-dfEEz2OY.js → stack-ikk2Y8_P.js} +2 -2
  137. package/dist/{sum-BE_Irnim.js → sum-NLYbiDag.js} +3 -3
  138. package/dist/{tensor-Xyi595sG.js → tensor-Do9PKbIE.js} +1 -1
  139. package/dist/{tensor2d-CPEkynbH.js → tensor2d-CWHxHpLh.js} +1 -1
  140. package/dist/training/Adam.d.ts +22 -0
  141. package/dist/training/Adam.js +93 -0
  142. package/dist/training/AdamExt.d.ts +1 -1
  143. package/dist/training/AdamExt.js +13 -12
  144. package/dist/training/DatasetBuilder.js +2 -2
  145. package/dist/training/Evaluator.js +1 -1
  146. package/dist/training/FullTrainer.js +27 -27
  147. package/dist/training/Trainer.d.ts +5 -6
  148. package/dist/training/Trainer.js +54 -55
  149. package/dist/training/sparseCrossEntropy.d.ts +0 -4
  150. package/dist/training/sparseCrossEntropy.js +7 -7
  151. package/dist/utilities/arrayClose.d.ts +1 -0
  152. package/dist/utilities/arrayClose.js +11 -0
  153. package/dist/utilities/dummy.js +19 -19
  154. package/dist/utilities/generate.js +15 -16
  155. package/dist/utilities/multinomialCPU.d.ts +2 -0
  156. package/dist/utilities/multinomialCPU.js +13 -0
  157. package/dist/utilities/performance.d.ts +2 -0
  158. package/dist/utilities/performance.js +16 -0
  159. package/dist/utilities/profile.d.ts +1 -0
  160. package/dist/utilities/profile.js +9 -6
  161. package/dist/utilities/safetensors.js +2 -2
  162. package/dist/utilities/weights.js +2 -2
  163. package/dist/{variable-wSS22xj5.js → variable-BTBkayv_.js} +1 -1
  164. package/dist/webgpu_program-WaoMq-WD.js +548 -0
  165. package/dist/webgpu_util-DhSeP4b6.js +80 -0
  166. package/dist/{zeros-YJDE7oRb.js → zeros-DnPT2nD4.js} +10 -10
  167. package/package.json +2 -1
  168. package/dist/gpgpu_math-CNslybmD.js +0 -3115
  169. package/dist/norm-CzltS9Fz.js +0 -86
@@ -1,19 +1,22 @@
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 { B as m, C as u, l, E as f, aP as gn, k as S, aQ as $n, aR as kn, aS as yn, p as En, aT as w, q as rn, x as _n, b as pn, aU as In, aV as Nn, N as An, al as Tn, I as v, aW as xn, aX as wn, aY as Sn, aZ as Mn, a_ as zn, a$ as qn, b0 as Bn, X as K, b1 as Gn, b2 as Kn, b3 as Rn, aG as Dn, $ as vn, Z as Vn, _ as Pn, b4 as jn, t as Fn, b5 as L, b6 as Wn, b7 as Yn, b8 as On, b9 as Cn, ba as Ln, bb as Xn, bc as Zn, bd as Jn, a as $, o as U, n as q, h as Qn, c as A, be as Hn, M as X, d as Un } from "./index-UdZhlibC.js";
2
+ import { n as ne, a as ee, b as se } from "./non_max_suppression_impl-CsEgBuMA.js";
3
+ import { r as k } from "./reshape-BR0eoLYN.js";
4
+ import { s as mn } from "./split-CRU0PjVV.js";
5
+ import { s as E } from "./sum-NLYbiDag.js";
6
+ import { b as Z } from "./broadcast_to-Ba9h_8DO.js";
7
+ import { s as _ } from "./slice-BHbDHObE.js";
8
+ import { r as W } from "./range-D9CZhVlR.js";
9
+ import { t as te } from "./tensor-Do9PKbIE.js";
10
+ import { s as Y } from "./stack-ikk2Y8_P.js";
11
+ import { c as re, z as ae } from "./zeros-DnPT2nD4.js";
12
+ import { e as oe } from "./axis_util-5DTW2tFV.js";
13
+ import { m as J } from "./max-ByjEGoFx.js";
14
+ import { c as Q } from "./concat-CbXTetof.js";
15
+ import { m as N } from "./mat_mul-dwmZz69e.js";
16
+ import { t as H } from "./tensor2d-CWHxHpLh.js";
14
17
  /**
15
18
  * @license
16
- * Copyright 2018 Google LLC. All Rights Reserved.
19
+ * Copyright 2020 Google LLC. All Rights Reserved.
17
20
  * Licensed under the Apache License, Version 2.0 (the "License");
18
21
  * you may not use this file except in compliance with the License.
19
22
  * You may obtain a copy of the License at
@@ -27,14 +30,13 @@ import { t as H } from "./tensor2d-CPEkynbH.js";
27
30
  * limitations under the License.
28
31
  * =============================================================================
29
32
  */
30
- function Hn(r, t, n) {
31
- const e = l(r, "x", "slice", "string_or_numeric");
32
- if (e.rank === 0)
33
- 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);
33
+ function ie(s, e, n) {
34
+ const r = u(s, "x", "bincount"), t = u(e, "weights", "bincount");
35
+ 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}.`);
36
+ const a = { x: r, weights: t }, o = { size: n };
37
+ return f.runKernel(gn, a, o);
36
38
  }
37
- const M = /* @__PURE__ */ h({ slice_: Hn });
39
+ const ce = /* @__PURE__ */ m({ bincount_: ie });
38
40
  /**
39
41
  * @license
40
42
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -51,16 +53,18 @@ 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(e, "a", "where"), t = u(n, "b", "where"), a = u(s, "condition", "where", "bool"), o = S(S(a.shape, r.shape), t.shape), i = Z(a, o), p = Z(r, o), c = Z(t, o), b = {
58
+ condition: i,
59
+ t: p,
60
+ e: c
61
+ };
62
+ return f.runKernel($n, b);
59
63
  }
60
- const Un = /* @__PURE__ */ h({ bincount_: Zn });
64
+ const G = /* @__PURE__ */ m({ where_: ue });
61
65
  /**
62
66
  * @license
63
- * Copyright 2020 Google LLC. All Rights Reserved.
67
+ * Copyright 2021 Google LLC. All Rights Reserved.
64
68
  * Licensed under the Apache License, Version 2.0 (the "License");
65
69
  * you may not use this file except in compliance with the License.
66
70
  * You may obtain a copy of the License at
@@ -74,18 +78,14 @@ const Un = /* @__PURE__ */ h({ bincount_: Zn });
74
78
  * limitations under the License.
75
79
  * =============================================================================
76
80
  */
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
- condition: i,
80
- t: u,
81
- e: c
82
- };
83
- return f.runKernel(bn, b);
81
+ function le(s, ...e) {
82
+ const n = e.map((t, a) => u(t, `tensors${a}`, "einsum")), r = { equation: s };
83
+ return f.runKernel(kn, n, r);
84
84
  }
85
- const G = /* @__PURE__ */ h({ where_: ne });
85
+ const D = /* @__PURE__ */ m({ einsum_: le });
86
86
  /**
87
87
  * @license
88
- * Copyright 2021 Google LLC. All Rights Reserved.
88
+ * Copyright 2020 Google Inc. All Rights Reserved.
89
89
  * Licensed under the Apache License, Version 2.0 (the "License");
90
90
  * you may not use this file except in compliance with the License.
91
91
  * You may obtain a copy of the License at
@@ -99,11 +99,67 @@ const G = /* @__PURE__ */ h({ where_: ne });
99
99
  * limitations under the License.
100
100
  * =============================================================================
101
101
  */
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);
102
+ function pe(s, e = null, n = !1) {
103
+ const t = { x: u(s, "x", "min") }, a = { axis: e, keepDims: n };
104
+ return f.runKernel(yn, t, a);
105
105
  }
106
- const v = /* @__PURE__ */ h({ einsum_: ee });
106
+ const an = /* @__PURE__ */ m({ min_: pe });
107
+ /**
108
+ * @license
109
+ * Copyright 2018 Google LLC. All Rights Reserved.
110
+ * Licensed under the Apache License, Version 2.0 (the "License");
111
+ * you may not use this file except in compliance with the License.
112
+ * You may obtain a copy of the License at
113
+ *
114
+ * http://www.apache.org/licenses/LICENSE-2.0
115
+ *
116
+ * Unless required by applicable law or agreed to in writing, software
117
+ * distributed under the License is distributed on an "AS IS" BASIS,
118
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
119
+ * See the License for the specific language governing permissions and
120
+ * limitations under the License.
121
+ * =============================================================================
122
+ */
123
+ function me(s, e = "euclidean", n = null, r = !1) {
124
+ s = u(s, "x", "norm");
125
+ const t = fn(s, e, n);
126
+ let a = t.shape;
127
+ if (r) {
128
+ const o = En(n, s.shape);
129
+ a = oe(t.shape, o);
130
+ }
131
+ return k(t, a);
132
+ }
133
+ function fn(s, e, n = null) {
134
+ if (s.rank === 0)
135
+ return w(s);
136
+ if (s.rank !== 1 && n === null)
137
+ return fn(k(s, [-1]), e, n);
138
+ if (s.rank === 1 || typeof n == "number" || Array.isArray(n) && n.length === 1) {
139
+ if (e === 1)
140
+ return E(w(s), n);
141
+ if (e === 1 / 0)
142
+ return J(w(s), n);
143
+ if (e === -1 / 0)
144
+ return an(w(s), n);
145
+ if (e === "euclidean" || e === 2)
146
+ return rn(E(_n(w(s), pn(2, "int32")), n));
147
+ throw new Error(`Error in norm: invalid ord value: ${e}`);
148
+ }
149
+ if (Array.isArray(n) && n.length === 2) {
150
+ if (e === 1)
151
+ return J(E(w(s), n[0]), n[1] - 1);
152
+ if (e === 1 / 0)
153
+ return J(E(w(s), n[1]), n[0]);
154
+ if (e === -1 / 0)
155
+ return an(E(w(s), n[1]), n[0]);
156
+ if (e === "fro" || e === "euclidean")
157
+ return rn(E(In(s), n));
158
+ throw new Error(`Error in norm: invalid ord value: ${e}`);
159
+ }
160
+ throw new Error(`Error in norm: invalid axis: ${n}`);
161
+ }
162
+ const hn = /* @__PURE__ */ m({ norm_: me });
107
163
  /**
108
164
  * @license
109
165
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -120,13 +176,13 @@ const v = /* @__PURE__ */ h({ einsum_: ee });
120
176
  * limitations under the License.
121
177
  * =============================================================================
122
178
  */
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);
179
+ function fe(s, e = 0) {
180
+ const n = u(s, "x", "expandDims", "string_or_numeric");
181
+ l(e <= n.rank, () => "Axis must be <= rank of the tensor");
182
+ const r = { input: n }, t = { dim: e };
183
+ return f.runKernel(Nn, r, t);
128
184
  }
129
- const K = /* @__PURE__ */ h({ expandDims_: se });
185
+ const z = /* @__PURE__ */ m({ expandDims_: fe });
130
186
  /**
131
187
  * @license
132
188
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -143,13 +199,13 @@ const K = /* @__PURE__ */ h({ expandDims_: se });
143
199
  * limitations under the License.
144
200
  * =============================================================================
145
201
  */
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);
202
+ function he(s, e) {
203
+ const n = u(s, "x", "tile", "string_or_numeric");
204
+ l(n.rank === e.length, () => `Error in transpose: rank of input ${n.rank} must match length of reps ${e}.`);
205
+ const r = { x: n }, t = { reps: e };
206
+ return f.runKernel(An, r, t);
151
207
  }
152
- const O = /* @__PURE__ */ h({ tile_: te });
208
+ const F = /* @__PURE__ */ m({ tile_: he });
153
209
  /**
154
210
  * @license
155
211
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -166,20 +222,20 @@ const O = /* @__PURE__ */ h({ tile_: te });
166
222
  * limitations under the License.
167
223
  * =============================================================================
168
224
  */
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;
225
+ function be(s, e, n, r = "float32") {
226
+ e == null && (e = s);
227
+ const t = Tn([s, e], r), a = s <= e ? s : e;
172
228
  for (let i = 0; i < a; ++i)
173
- s.set(1, i, i);
174
- const o = _(s.toTensor(), [r, t]);
229
+ t.set(1, i, i);
230
+ const o = k(t.toTensor(), [s, e]);
175
231
  if (n == null)
176
232
  return o;
177
233
  if (n.length === 1)
178
- return O(K(o, 0), [n[0], 1, 1]);
234
+ return F(z(o, 0), [n[0], 1, 1]);
179
235
  if (n.length === 2)
180
- return O(K(K(o, 0), 0), [n[0], n[1], 1, 1]);
236
+ return F(z(z(o, 0), 0), [n[0], n[1], 1, 1]);
181
237
  if (n.length === 3)
182
- return O(K(K(K(o, 0), 0), 0), [
238
+ return F(z(z(z(o, 0), 0), 0), [
183
239
  n[0],
184
240
  n[1],
185
241
  n[2],
@@ -188,7 +244,7 @@ function re(r, t, n, e = "float32") {
188
244
  ]);
189
245
  throw new Error(`eye() currently supports only 1D and 2D batchShapes, but received ${n.length}D.`);
190
246
  }
191
- const ae = /* @__PURE__ */ h({ eye_: re });
247
+ const de = /* @__PURE__ */ m({ eye_: be });
192
248
  /**
193
249
  * @license
194
250
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -205,13 +261,13 @@ const ae = /* @__PURE__ */ h({ eye_: re });
205
261
  * limitations under the License.
206
262
  * =============================================================================
207
263
  */
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);
264
+ function ge(s, e) {
265
+ let n = u(s, "a", "greater", "string_or_numeric"), r = u(e, "b", "greater", "string_or_numeric");
266
+ [n, r] = v(n, r), S(n.shape, r.shape);
267
+ const t = { a: n, b: r };
268
+ return f.runKernel(xn, t);
213
269
  }
214
- const U = /* @__PURE__ */ h({ greater_: oe });
270
+ const nn = /* @__PURE__ */ m({ greater_: ge });
215
271
  /**
216
272
  * @license
217
273
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -228,13 +284,13 @@ const U = /* @__PURE__ */ h({ greater_: oe });
228
284
  * limitations under the License.
229
285
  * =============================================================================
230
286
  */
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);
287
+ function $e(s, e) {
288
+ let n = u(s, "a", "greaterEqual", "string_or_numeric"), r = u(e, "b", "greaterEqual", "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);
236
292
  }
237
- const ce = /* @__PURE__ */ h({ greaterEqual_: ie });
293
+ const ke = /* @__PURE__ */ m({ greaterEqual_: $e });
238
294
  /**
239
295
  * @license
240
296
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -251,11 +307,11 @@ const ce = /* @__PURE__ */ h({ greaterEqual_: ie });
251
307
  * limitations under the License.
252
308
  * =============================================================================
253
309
  */
254
- function ue(r) {
255
- const n = { input: l(r, "input", "imag") };
256
- return f.runKernel(In, n);
310
+ function ye(s) {
311
+ const n = { input: u(s, "input", "imag") };
312
+ return f.runKernel(Sn, n);
257
313
  }
258
- const le = /* @__PURE__ */ h({ imag_: ue });
314
+ const Ee = /* @__PURE__ */ m({ imag_: ye });
259
315
  /**
260
316
  * @license
261
317
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -272,13 +328,13 @@ const le = /* @__PURE__ */ h({ imag_: ue });
272
328
  * limitations under the License.
273
329
  * =============================================================================
274
330
  */
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);
331
+ function _e(s, e) {
332
+ let n = u(s, "a", "less", "string_or_numeric"), r = u(e, "b", "less", "string_or_numeric");
333
+ [n, r] = v(n, r), S(n.shape, r.shape);
334
+ const t = { a: n, b: r };
335
+ return f.runKernel(Mn, t);
280
336
  }
281
- const tn = /* @__PURE__ */ h({ less_: pe });
337
+ const on = /* @__PURE__ */ m({ less_: _e });
282
338
  /**
283
339
  * @license
284
340
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -295,13 +351,13 @@ const tn = /* @__PURE__ */ h({ less_: pe });
295
351
  * limitations under the License.
296
352
  * =============================================================================
297
353
  */
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);
354
+ function Ie(s, e) {
355
+ let n = u(s, "a", "lessEqual", "string_or_numeric"), r = u(e, "b", "lessEqual", "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);
303
359
  }
304
- const pn = /* @__PURE__ */ h({ lessEqual_: me });
360
+ const bn = /* @__PURE__ */ m({ lessEqual_: Ie });
305
361
  /**
306
362
  * @license
307
363
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -318,11 +374,11 @@ const pn = /* @__PURE__ */ h({ lessEqual_: me });
318
374
  * limitations under the License.
319
375
  * =============================================================================
320
376
  */
321
- function he(r) {
322
- const n = { x: l(r, "x", "neg") };
323
- return f.runKernel(Mn, n);
377
+ function Ne(s) {
378
+ const n = { x: u(s, "x", "neg") };
379
+ return f.runKernel(qn, n);
324
380
  }
325
- const nn = /* @__PURE__ */ h({ neg_: he });
381
+ const en = /* @__PURE__ */ m({ neg_: Ne });
326
382
  /**
327
383
  * @license
328
384
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -339,13 +395,13 @@ const nn = /* @__PURE__ */ h({ neg_: he });
339
395
  * limitations under the License.
340
396
  * =============================================================================
341
397
  */
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);
398
+ function Ae(s, e) {
399
+ const n = u(s, "a", "logicalAnd", "bool"), r = u(e, "b", "logicalAnd", "bool");
400
+ S(n.shape, r.shape);
401
+ const t = { a: n, b: r };
402
+ return f.runKernel(Bn, t);
347
403
  }
348
- const be = /* @__PURE__ */ h({ logicalAnd_: fe });
404
+ const Te = /* @__PURE__ */ m({ logicalAnd_: Ae });
349
405
  /**
350
406
  * @license
351
407
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -362,13 +418,13 @@ const be = /* @__PURE__ */ h({ logicalAnd_: fe });
362
418
  * limitations under the License.
363
419
  * =============================================================================
364
420
  */
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);
421
+ function xe(s, e) {
422
+ let n = u(s, "a", "minimum"), r = u(e, "b", "minimum");
423
+ [n, r] = v(n, r), n.dtype === "bool" && (n = K(n, "int32"), r = K(r, "int32")), S(n.shape, r.shape);
424
+ const t = { a: n, b: r };
425
+ return f.runKernel(Gn, t);
370
426
  }
371
- const rn = /* @__PURE__ */ h({ minimum_: de });
427
+ const cn = /* @__PURE__ */ m({ minimum_: xe });
372
428
  /**
373
429
  * @license
374
430
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -385,11 +441,11 @@ const rn = /* @__PURE__ */ h({ minimum_: de });
385
441
  * limitations under the License.
386
442
  * =============================================================================
387
443
  */
388
- function ge(r) {
389
- const n = { input: l(r, "input", "real") };
390
- return f.runKernel(Tn, n);
444
+ function we(s) {
445
+ const n = { input: u(s, "input", "real") };
446
+ return f.runKernel(Kn, n);
391
447
  }
392
- const $e = /* @__PURE__ */ h({ real_: ge });
448
+ const Se = /* @__PURE__ */ m({ real_: we });
393
449
  /**
394
450
  * @license
395
451
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -406,11 +462,11 @@ const $e = /* @__PURE__ */ h({ real_: ge });
406
462
  * limitations under the License.
407
463
  * =============================================================================
408
464
  */
409
- function xe(r) {
410
- const n = { x: l(r, "x", "round") };
411
- return f.runKernel(Sn, n);
465
+ function Me(s) {
466
+ const n = { x: u(s, "x", "round") };
467
+ return f.runKernel(Rn, n);
412
468
  }
413
- const ke = /* @__PURE__ */ h({ round_: xe });
469
+ const ze = /* @__PURE__ */ m({ round_: Me });
414
470
  /**
415
471
  * @license
416
472
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -427,11 +483,11 @@ const ke = /* @__PURE__ */ h({ round_: xe });
427
483
  * limitations under the License.
428
484
  * =============================================================================
429
485
  */
430
- function ye(r, t) {
431
- const n = l(r, "x", "squeeze", "string_or_numeric");
432
- return _(n, wn(n.shape, t).newShape);
486
+ function qe(s, e) {
487
+ const n = u(s, "x", "squeeze", "string_or_numeric");
488
+ return k(n, Dn(n.shape, e).newShape);
433
489
  }
434
- const Ie = /* @__PURE__ */ h({ squeeze_: ye });
490
+ const Be = /* @__PURE__ */ m({ squeeze_: qe });
435
491
  /**
436
492
  * @license
437
493
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -448,12 +504,12 @@ const Ie = /* @__PURE__ */ h({ squeeze_: ye });
448
504
  * limitations under the License.
449
505
  * =============================================================================
450
506
  */
451
- function N(r, t) {
452
- zn(r);
453
- const n = Bn(r, t);
507
+ function I(s, e) {
508
+ vn(s);
509
+ const n = Vn(s, e);
454
510
  if (n.length !== 1)
455
511
  throw new Error("tensor1d() requires values to be a flat/TypedArray");
456
- return qn(r, null, n, t);
512
+ return Pn(s, null, n, e);
457
513
  }
458
514
  /**
459
515
  * @license
@@ -471,13 +527,13 @@ function N(r, t) {
471
527
  * limitations under the License.
472
528
  * =============================================================================
473
529
  */
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);
530
+ function Ge(s, e = 0) {
531
+ const n = u(s, "x", "unstack", "string_or_numeric");
532
+ l(e >= -n.shape.length && e < n.shape.length, () => `Axis = ${e} is not in [-${n.shape.length}, ${n.shape.length})`);
533
+ const r = { value: n }, t = { axis: e };
534
+ return f.runKernel(jn, r, t);
479
535
  }
480
- const mn = /* @__PURE__ */ h({ unstack_: _e });
536
+ const dn = /* @__PURE__ */ m({ unstack_: Ge });
481
537
  /**
482
538
  * @license
483
539
  * Copyright 2018 Google LLC. All Rights Reserved.
@@ -494,19 +550,19 @@ const mn = /* @__PURE__ */ h({ unstack_: _e });
494
550
  * limitations under the License.
495
551
  * =============================================================================
496
552
  */
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);
553
+ function Ke(s, e, n) {
554
+ const r = u(s, "x", "transpose");
555
+ 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) => {
556
+ l(o >= 0 && o < r.rank, () => `All entries in 'perm' must be between 0 and ${r.rank - 1} but got ${e}`);
557
+ }), r.rank <= 1)
558
+ return r.clone();
559
+ const t = { x: r }, a = { perm: e };
560
+ return r.dtype === "complex64" ? Fn(() => {
561
+ let o = Se(r), i = Ee(r);
562
+ return o = f.runKernel(L, { x: o }, a), i = f.runKernel(L, { x: i }, a), n && (i = en(i)), re(o, i);
563
+ }) : f.runKernel(L, t, a);
508
564
  }
509
- const an = /* @__PURE__ */ h({ transpose_: Ee });
565
+ const un = /* @__PURE__ */ m({ transpose_: Ke });
510
566
  /**
511
567
  * @license
512
568
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -523,13 +579,13 @@ const an = /* @__PURE__ */ h({ transpose_: Ee });
523
579
  * limitations under the License.
524
580
  * =============================================================================
525
581
  */
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);
582
+ function Re(s, e, n, r, t = "bilinear", a = 0) {
583
+ const o = u(s, "image", "cropAndResize"), i = u(e, "boxes", "cropAndResize", "float32"), p = u(n, "boxInd", "cropAndResize", "int32"), c = i.shape[0];
584
+ 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}`);
585
+ const b = { image: o, boxes: i, boxInd: p }, h = { method: t, extrapolationValue: a, cropSize: r };
586
+ return f.runKernel(Wn, b, h);
531
587
  }
532
- const Ne = /* @__PURE__ */ h({ cropAndResize_: Me });
588
+ const De = /* @__PURE__ */ m({ cropAndResize_: Re });
533
589
  /**
534
590
  * @license
535
591
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -546,13 +602,13 @@ const Ne = /* @__PURE__ */ h({ cropAndResize_: Me });
546
602
  * limitations under the License.
547
603
  * =============================================================================
548
604
  */
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, {});
605
+ function ve(s) {
606
+ const e = u(s, "image", "flipLeftRight", "float32");
607
+ l(e.rank === 4, () => `Error in flipLeftRight: image must be rank 4,but got rank ${e.rank}.`);
608
+ const n = { image: e };
609
+ return f.runKernel(Yn, n, {});
554
610
  }
555
- const Te = /* @__PURE__ */ h({ flipLeftRight_: Ae });
611
+ const Ve = /* @__PURE__ */ m({ flipLeftRight_: ve });
556
612
  /**
557
613
  * @license
558
614
  * Copyright 2021 Google LLC. All Rights Reserved.
@@ -569,13 +625,13 @@ const Te = /* @__PURE__ */ h({ flipLeftRight_: Ae });
569
625
  * limitations under the License.
570
626
  * =============================================================================
571
627
  */
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);
628
+ function Pe(s) {
629
+ const e = u(s, "image", "grayscaleToRGB"), n = e.rank - 1, r = e.shape[n];
630
+ 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}.`);
631
+ const t = new Array(e.rank);
632
+ return t.fill(1, 0, n), t[n] = 3, F(e, t);
577
633
  }
578
- const we = /* @__PURE__ */ h({ grayscaleToRGB_: Se });
634
+ const je = /* @__PURE__ */ m({ grayscaleToRGB_: Pe });
579
635
  /**
580
636
  * @license
581
637
  * Copyright 2023 Google LLC.
@@ -592,56 +648,33 @@ const we = /* @__PURE__ */ h({ grayscaleToRGB_: Se });
592
648
  * limitations under the License.
593
649
  * =============================================================================
594
650
  */
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]);
651
+ function Fe(s) {
652
+ const e = u(s, "image", "RGBToGrayscale"), n = e.rank - 1, r = e.shape[n];
653
+ 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}.`);
654
+ const t = e.dtype, a = K(e, "float32"), o = I([0.2989, 0.587, 0.114]);
599
655
  let i;
600
- switch (t.rank) {
656
+ switch (e.rank) {
601
657
  case 2:
602
- i = v("ij,j->i", a, o);
658
+ i = D("ij,j->i", a, o);
603
659
  break;
604
660
  case 3:
605
- i = v("ijk,k->ij", a, o);
661
+ i = D("ijk,k->ij", a, o);
606
662
  break;
607
663
  case 4:
608
- i = v("ijkl,l->ijk", a, o);
664
+ i = D("ijkl,l->ijk", a, o);
609
665
  break;
610
666
  case 5:
611
- i = v("ijklm,m->ijkl", a, o);
667
+ i = D("ijklm,m->ijkl", a, o);
612
668
  break;
613
669
  case 6:
614
- i = v("ijklmn,n->ijklm", a, o);
670
+ i = D("ijklmn,n->ijklm", a, o);
615
671
  break;
616
672
  default:
617
673
  throw new Error("Not a valid tensor rank.");
618
674
  }
619
- return i = K(i, -1), V(i, s);
620
- }
621
- const Be = /* @__PURE__ */ h({ rgbToGrayscale_: ze });
622
- /**
623
- * @license
624
- * Copyright 2020 Google LLC. All Rights Reserved.
625
- * Licensed under the Apache License, Version 2.0 (the "License");
626
- * you may not use this file except in compliance with the License.
627
- * You may obtain a copy of the License at
628
- *
629
- * http://www.apache.org/licenses/LICENSE-2.0
630
- *
631
- * Unless required by applicable law or agreed to in writing, software
632
- * distributed under the License is distributed on an "AS IS" BASIS,
633
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
634
- * See the License for the specific language governing permissions and
635
- * limitations under the License.
636
- * =============================================================================
637
- */
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);
675
+ return i = z(i, -1), K(i, t);
643
676
  }
644
- const Ke = /* @__PURE__ */ h({ rotateWithOffset_: qe });
677
+ const We = /* @__PURE__ */ m({ rgbToGrayscale_: Fe });
645
678
  /**
646
679
  * @license
647
680
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -658,11 +691,13 @@ const Ke = /* @__PURE__ */ h({ rotateWithOffset_: qe });
658
691
  * limitations under the License.
659
692
  * =============================================================================
660
693
  */
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 };
694
+ function Ye(s, e, n = 0, r = 0.5) {
695
+ const t = u(s, "image", "rotateWithOffset", "float32");
696
+ l(t.rank === 4, () => `Error in rotateWithOffset: image must be rank 4,but got rank ${t.rank}.`);
697
+ const a = { image: t }, o = { radians: e, fillValue: n, center: r };
698
+ return f.runKernel(On, a, o);
665
699
  }
700
+ const Oe = /* @__PURE__ */ m({ rotateWithOffset_: Ye });
666
701
  /**
667
702
  * @license
668
703
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -679,47 +714,10 @@ function D(r, t, n, e, s, a) {
679
714
  * limitations under the License.
680
715
  * =============================================================================
681
716
  */
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;
717
+ function R(s, e, n, r, t, a) {
718
+ r == null && (r = 0.5), t == null && (t = Number.NEGATIVE_INFINITY), a == null && (a = 0);
719
+ const o = s.shape[0];
720
+ 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 };
723
721
  }
724
722
  /**
725
723
  * @license
@@ -737,84 +735,13 @@ function ve(r, t, n) {
737
735
  * limitations under the License.
738
736
  * =============================================================================
739
737
  */
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;
738
+ function Ce(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY) {
739
+ const a = u(s, "boxes", "nonMaxSuppression", "float32"), o = u(e, "scores", "nonMaxSuppression", "float32"), i = R(a, o, n, r, t);
740
+ n = i.maxOutputSize, r = i.iouThreshold, t = i.scoreThreshold;
741
+ const p = { maxOutputSize: n, iouThreshold: r, scoreThreshold: t };
742
+ return f.runKernel(Cn, { boxes: a, scores: o }, p);
817
743
  }
744
+ const Le = /* @__PURE__ */ m({ nonMaxSuppression_: Ce });
818
745
  /**
819
746
  * @license
820
747
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -831,13 +758,13 @@ function on(r, t) {
831
758
  * limitations under the License.
832
759
  * =============================================================================
833
760
  */
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");
761
+ async function Xe(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY) {
762
+ const a = u(s, "boxes", "nonMaxSuppressionAsync"), o = u(e, "scores", "nonMaxSuppressionAsync"), i = R(a, o, n, r, t);
763
+ n = i.maxOutputSize, r = i.iouThreshold, t = i.scoreThreshold;
764
+ const p = await Promise.all([a.data(), o.data()]), c = p[0], b = p[1], { selectedIndices: h } = ne(c, b, n, r, t);
765
+ return a !== s && a.dispose(), o !== e && o.dispose(), I(h, "int32");
839
766
  }
840
- const Je = Ce;
767
+ const Ze = Xe;
841
768
  /**
842
769
  * @license
843
770
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -854,13 +781,13 @@ const Je = Ce;
854
781
  * limitations under the License.
855
782
  * =============================================================================
856
783
  */
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] };
784
+ function Je(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = 0) {
785
+ const o = u(s, "boxes", "nonMaxSuppression"), i = u(e, "scores", "nonMaxSuppression"), p = R(o, i, n, r, t, a);
786
+ n = p.maxOutputSize, r = p.iouThreshold, t = p.scoreThreshold, a = p.softNmsSigma;
787
+ const c = { boxes: o, scores: i }, b = { maxOutputSize: n, iouThreshold: r, scoreThreshold: t, softNmsSigma: a }, h = f.runKernel(Ln, c, b);
788
+ return { selectedIndices: h[0], selectedScores: h[1] };
862
789
  }
863
- const Xe = /* @__PURE__ */ h({ nonMaxSuppressionWithScore_: Le });
790
+ const Qe = /* @__PURE__ */ m({ nonMaxSuppressionWithScore_: Je });
864
791
  /**
865
792
  * @license
866
793
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -877,16 +804,16 @@ const Xe = /* @__PURE__ */ h({ nonMaxSuppressionWithScore_: Le });
877
804
  * limitations under the License.
878
805
  * =============================================================================
879
806
  */
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)
807
+ async function He(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = 0) {
808
+ const o = u(s, "boxes", "nonMaxSuppressionAsync"), i = u(e, "scores", "nonMaxSuppressionAsync"), p = R(o, i, n, r, t, a);
809
+ n = p.maxOutputSize, r = p.iouThreshold, t = p.scoreThreshold, a = p.softNmsSigma;
810
+ const c = await Promise.all([o.data(), i.data()]), b = c[0], h = c[1], { selectedIndices: g, selectedScores: d } = ee(b, h, n, r, t, a);
811
+ return o !== s && o.dispose(), i !== e && i.dispose(), {
812
+ selectedIndices: I(g, "int32"),
813
+ selectedScores: I(d)
887
814
  };
888
815
  }
889
- const He = Qe;
816
+ const Ue = He;
890
817
  /**
891
818
  * @license
892
819
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -903,24 +830,24 @@ const He = Qe;
903
830
  * limitations under the License.
904
831
  * =============================================================================
905
832
  */
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(
833
+ function ns(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = !1) {
834
+ const o = u(s, "boxes", "nonMaxSuppression"), i = u(e, "scores", "nonMaxSuppression"), p = R(
908
835
  o,
909
836
  i,
910
837
  n,
911
- e,
912
- s,
838
+ r,
839
+ t,
913
840
  null
914
841
  /* softNmsSigma */
915
- ), c = u.maxOutputSize, b = u.iouThreshold, m = u.scoreThreshold, $ = { boxes: o, scores: i }, g = {
842
+ ), c = p.maxOutputSize, b = p.iouThreshold, h = p.scoreThreshold, g = { boxes: o, scores: i }, d = {
916
843
  maxOutputSize: c,
917
844
  iouThreshold: b,
918
- scoreThreshold: m,
845
+ scoreThreshold: h,
919
846
  padToMaxOutputSize: a
920
- }, x = f.runKernel(jn, $, g);
921
- return { selectedIndices: x[0], validOutputs: x[1] };
847
+ }, y = f.runKernel(Xn, g, d);
848
+ return { selectedIndices: y[0], validOutputs: y[1] };
922
849
  }
923
- const Ue = /* @__PURE__ */ h({ nonMaxSuppressionPadded_: Ze });
850
+ const es = /* @__PURE__ */ m({ nonMaxSuppressionPadded_: ns });
924
851
  /**
925
852
  * @license
926
853
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -937,22 +864,22 @@ const Ue = /* @__PURE__ */ h({ nonMaxSuppressionPadded_: Ze });
937
864
  * limitations under the License.
938
865
  * =============================================================================
939
866
  */
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(
867
+ async function ss(s, e, n, r = 0.5, t = Number.NEGATIVE_INFINITY, a = !1) {
868
+ const o = u(s, "boxes", "nonMaxSuppressionAsync"), i = u(e, "scores", "nonMaxSuppressionAsync"), p = R(
942
869
  o,
943
870
  i,
944
871
  n,
945
- e,
946
- s,
872
+ r,
873
+ t,
947
874
  null
948
875
  /* 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")
876
+ ), c = p.maxOutputSize, b = p.iouThreshold, h = p.scoreThreshold, [g, d] = await Promise.all([o.data(), i.data()]), { selectedIndices: y, validOutputs: M } = se(g, d, c, b, h, a);
877
+ return o !== s && o.dispose(), i !== e && i.dispose(), {
878
+ selectedIndices: I(y, "int32"),
879
+ validOutputs: pn(M, "int32")
953
880
  };
954
881
  }
955
- const es = ns;
882
+ const ts = ss;
956
883
  /**
957
884
  * @license
958
885
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -969,15 +896,15 @@ const es = ns;
969
896
  * limitations under the License.
970
897
  * =============================================================================
971
898
  */
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;
899
+ function rs(s, e, n = !1, r = !1) {
900
+ const t = u(s, "images", "resizeBilinear");
901
+ 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.");
902
+ let a = t, o = !1;
903
+ t.rank === 3 && (o = !0, a = k(t, [1, t.shape[0], t.shape[1], t.shape[2]]));
904
+ const i = { images: a }, p = { alignCorners: n, halfPixelCenters: r, size: e }, c = f.runKernel(Zn, i, p);
905
+ return o ? k(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
979
906
  }
980
- const ts = /* @__PURE__ */ h({ resizeBilinear_: ss });
907
+ const as = /* @__PURE__ */ m({ resizeBilinear_: rs });
981
908
  /**
982
909
  * @license
983
910
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -994,15 +921,15 @@ const ts = /* @__PURE__ */ h({ resizeBilinear_: ss });
994
921
  * limitations under the License.
995
922
  * =============================================================================
996
923
  */
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;
924
+ function os(s, e, n = !1, r = !1) {
925
+ const t = u(s, "images", "resizeNearestNeighbor");
926
+ 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.");
927
+ let a = t, o = !1;
928
+ t.rank === 3 && (o = !0, a = k(t, [1, t.shape[0], t.shape[1], t.shape[2]]));
929
+ const i = { images: a }, p = { alignCorners: n, halfPixelCenters: r, size: e }, c = f.runKernel(Jn, i, p);
930
+ return o ? k(c, [c.shape[1], c.shape[2], c.shape[3]]) : c;
1004
931
  }
1005
- const as = /* @__PURE__ */ h({ resizeNearestNeighbor_: rs });
932
+ const is = /* @__PURE__ */ m({ resizeNearestNeighbor_: os });
1006
933
  /**
1007
934
  * @license
1008
935
  * Copyright 2021 Google LLC. All Rights Reserved.
@@ -1019,38 +946,38 @@ const as = /* @__PURE__ */ h({ resizeNearestNeighbor_: rs });
1019
946
  * limitations under the License.
1020
947
  * =============================================================================
1021
948
  */
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);
949
+ function cs(s, e = "binary", n = !1, r = 0.5) {
950
+ const t = u(s, "image", "threshold"), a = 0.2989, o = 0.587, i = 0.114, p = t.shape[0] * t.shape[1];
951
+ let c = $(I([r]), 255), b, h, g, d;
952
+ 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) {
953
+ [b, h, g] = mn(t, [1, 1, 1], -1);
954
+ const T = $(b, a), B = $(h, o), x = $(g, i);
955
+ d = U(U(T, B), x);
1029
956
  } else
1030
- g = r;
1031
- if (t === "otsu") {
1032
- const d = Un(V(ke(g), "int32"), Ln([]), 256);
1033
- c = is(d, u);
957
+ d = s;
958
+ if (e === "otsu") {
959
+ const T = ce(K(ze(d), "int32"), te([]), 256);
960
+ c = us(T, p);
1034
961
  }
1035
- const x = n ? pn(g, c) : U(g, c);
1036
- return V(k(x, 255), "int32");
962
+ const y = n ? bn(d, c) : nn(d, c);
963
+ return K($(y, 255), "int32");
1037
964
  }
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);
965
+ function us(s, e) {
966
+ let n = I([-1]), r = I([0]), t = I([0]), a, o, i, p, c, b;
967
+ for (let h = 0; h < s.size - 1; h++) {
968
+ a = _(s, 0, h + 1), o = _(s, h + 1), c = q(E(a), e), b = q(E(o), e);
969
+ const g = E($(a, W(0, a.size)));
970
+ i = q(g, E(a));
971
+ const d = Qn(o.shape, a.size), y = U(W(0, o.size), d), M = $(o, y);
972
+ p = q(E(M), E(o));
973
+ const T = A(i, p), B = A(i, p), x = $(c, b);
974
+ t = $($(x, T), B);
975
+ const V = nn(t, r);
976
+ r = G(V, t, r), n = G(V, I([h]), n);
1050
977
  }
1051
978
  return n;
1052
979
  }
1053
- const cs = /* @__PURE__ */ h({ threshold_: os });
980
+ const ls = /* @__PURE__ */ m({ threshold_: cs });
1054
981
  /**
1055
982
  * @license
1056
983
  * Copyright 2021 Google LLC. All Rights Reserved.
@@ -1067,13 +994,13 @@ const cs = /* @__PURE__ */ h({ threshold_: os });
1067
994
  * limitations under the License.
1068
995
  * =============================================================================
1069
996
  */
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);
997
+ function ps(s, e, n = "nearest", r = "constant", t = 0, a) {
998
+ const o = u(s, "image", "transform", "float32"), i = u(e, "transforms", "transform", "float32");
999
+ 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}.`);
1000
+ const p = { image: o, transforms: i }, c = { interpolation: n, fillMode: r, fillValue: t, outputShape: a };
1001
+ return f.runKernel(Hn, p, c);
1075
1002
  }
1076
- const ls = /* @__PURE__ */ h({ transform_: us });
1003
+ const ms = /* @__PURE__ */ m({ transform_: ps });
1077
1004
  /**
1078
1005
  * @license
1079
1006
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -1090,16 +1017,16 @@ const ls = /* @__PURE__ */ h({ transform_: us });
1090
1017
  * limitations under the License.
1091
1018
  * =============================================================================
1092
1019
  */
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);
1020
+ function fs(s, e, n) {
1021
+ const r = u(s, "a", "bandPart");
1022
+ l(r.rank >= 2, () => `bandPart(): Rank must be at least 2, got ${r.rank}.`);
1023
+ const t = r.shape, [a, o] = r.shape.slice(-2);
1024
+ let i, p;
1025
+ 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 = G(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 = G(on(n, 0), o, cn(n, o)));
1026
+ const c = k(W(0, a, 1, "int32"), [-1, 1]), b = W(0, o, 1, "int32"), h = A(c, b), g = Te(bn(h, i), ke(h, en(p))), d = ae([a, o], r.dtype);
1027
+ return k(Y(dn(k(r, [-1, a, o])).map((y) => G(g, y, d))), t);
1101
1028
  }
1102
- const ms = /* @__PURE__ */ h({ bandPart_: ps });
1029
+ const hs = /* @__PURE__ */ m({ bandPart_: fs });
1103
1030
  /**
1104
1031
  * @license
1105
1032
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -1116,30 +1043,30 @@ const ms = /* @__PURE__ */ h({ bandPart_: ps });
1116
1043
  * limitations under the License.
1117
1044
  * =============================================================================
1118
1045
  */
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})`);
1046
+ function bs(s) {
1047
+ let e;
1048
+ if (Array.isArray(s)) {
1049
+ e = !1, l(s != null && s.length > 0, () => "Gram-Schmidt process: input must not be null, undefined, or empty");
1050
+ const t = s[0].shape[0];
1051
+ for (let a = 1; a < s.length; ++a)
1052
+ l(s[a].shape[0] === t, () => `Gram-Schmidt: Non-unique lengths found in the input vectors: (${s[a].shape[0]} vs. ${t})`);
1126
1053
  } 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)
1054
+ e = !0, s = mn(s, s.shape[0], 0).map((t) => Be(t, [0]));
1055
+ l(s.length <= s[0].shape[0], () => `Gram-Schmidt: Number of vectors (${s.length}) exceeds number of dimensions (${s[0].shape[0]}).`);
1056
+ const n = [], r = s;
1057
+ for (let t = 0; t < s.length; ++t)
1131
1058
  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);
1059
+ let a = r[t];
1060
+ if (t > 0)
1061
+ for (let o = 0; o < t; ++o) {
1062
+ const i = $(E($(n[o], a)), n[o]);
1063
+ a = A(a, i);
1137
1064
  }
1138
- return R(a, ln(a, "euclidean"));
1065
+ return q(a, hn(a, "euclidean"));
1139
1066
  }));
1140
- return t ? Y(n, 0) : n;
1067
+ return e ? Y(n, 0) : n;
1141
1068
  }
1142
- const fs = /* @__PURE__ */ h({ gramSchmidt_: hs });
1069
+ const ds = /* @__PURE__ */ m({ gramSchmidt_: bs });
1143
1070
  /**
1144
1071
  * @license
1145
1072
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -1156,60 +1083,60 @@ const fs = /* @__PURE__ */ h({ gramSchmidt_: hs });
1156
1083
  * limitations under the License.
1157
1084
  * =============================================================================
1158
1085
  */
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);
1086
+ function gs(s, e = !1) {
1087
+ if (l(s.rank >= 2, () => `qr() requires input tensor to have a rank >= 2, but got rank ${s.rank}`), s.rank === 2)
1088
+ return ln(s, e);
1162
1089
  {
1163
- const n = r.shape.slice(0, r.shape.length - 2).reduce((u, c) => u * c), e = mn(_(r, [
1090
+ const n = s.shape.slice(0, s.shape.length - 2).reduce((p, c) => p * c), r = dn(k(s, [
1164
1091
  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);
1092
+ s.shape[s.shape.length - 2],
1093
+ s.shape[s.shape.length - 1]
1094
+ ]), 0), t = [], a = [];
1095
+ r.forEach((p) => {
1096
+ const [c, b] = ln(p, e);
1097
+ t.push(c), a.push(b);
1171
1098
  });
1172
- const o = _(Y(s, 0), r.shape), i = _(Y(a, 0), r.shape);
1099
+ const o = k(Y(t, 0), s.shape), i = k(Y(a, 0), s.shape);
1173
1100
  return [o, i];
1174
1101
  }
1175
1102
  }
1176
- function cn(r, t = !1) {
1103
+ function ln(s, e = !1) {
1177
1104
  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);
1105
+ l(s.shape.length === 2, () => `qr2d() requires a 2D Tensor, but got a ${s.shape.length}D Tensor.`);
1106
+ const n = s.shape[0], r = s.shape[1];
1107
+ let t = de(n), a = X(s);
1181
1108
  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([
1109
+ let i = X(o);
1110
+ const p = n >= r ? r : n;
1111
+ for (let c = 0; c < p; ++c) {
1112
+ const b = a, h = i, g = t;
1113
+ [i, a, t] = f.tidy(() => {
1114
+ const d = _(a, [c, c], [n - c, 1]), y = hn(d), M = _(a, [c, c], [1, 1]), T = G(nn(M, 0), H([[-1]]), H([[1]])), B = A(M, $(T, y)), x = q(d, B);
1115
+ x.shape[0] === 1 ? i = X(o) : i = Q([
1189
1116
  o,
1190
- M(I, [1, 0], [I.shape[0] - 1, I.shape[1]])
1117
+ _(x, [1, 0], [x.shape[0] - 1, x.shape[1]])
1191
1118
  ], 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);
1119
+ const V = en(q(N(T, B), y)), P = _(a, [c, 0], [n - c, r]), O = $(V, i), sn = un(i);
1193
1120
  if (c === 0)
1194
- a = S(z, T(B, T(P, z)));
1121
+ a = A(P, N(O, N(sn, P)));
1195
1122
  else {
1196
- const C = S(z, T(B, T(P, z)));
1197
- a = Q([M(a, [0, 0], [c, e]), C], 0);
1123
+ const C = A(P, N(O, N(sn, P)));
1124
+ a = Q([_(a, [0, 0], [c, r]), C], 0);
1198
1125
  }
1199
- const sn = an(B), F = M(s, [0, c], [n, s.shape[1] - c]);
1126
+ const tn = un(O), j = _(t, [0, c], [n, t.shape[1] - c]);
1200
1127
  if (c === 0)
1201
- s = S(F, T(T(F, i), sn));
1128
+ t = A(j, N(N(j, i), tn));
1202
1129
  else {
1203
- const C = S(F, T(T(F, i), sn));
1204
- s = Q([M(s, [0, 0], [n, c]), C], 1);
1130
+ const C = A(j, N(N(j, i), tn));
1131
+ t = Q([_(t, [0, 0], [n, c]), C], 1);
1205
1132
  }
1206
- return [i, a, s];
1207
- }), Jn([b, m, $]);
1133
+ return [i, a, t];
1134
+ }), Un([b, h, g]);
1208
1135
  }
1209
- return !t && n > e && (s = M(s, [0, 0], [n, e]), a = M(a, [0, 0], [e, e])), [s, a];
1136
+ return !e && n > r && (t = _(t, [0, 0], [n, r]), a = _(a, [0, 0], [r, r])), [t, a];
1210
1137
  });
1211
1138
  }
1212
- const ds = /* @__PURE__ */ h({ qr_: bs });
1139
+ const $s = /* @__PURE__ */ m({ qr_: gs });
1213
1140
  /**
1214
1141
  * @license
1215
1142
  * Copyright 2020 Google LLC. All Rights Reserved.
@@ -1226,52 +1153,50 @@ const ds = /* @__PURE__ */ h({ qr_: bs });
1226
1153
  * limitations under the License.
1227
1154
  * =============================================================================
1228
1155
  */
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
1156
+ const Ks = {
1157
+ flipLeftRight: Ve,
1158
+ grayscaleToRGB: je,
1159
+ resizeNearestNeighbor: is,
1160
+ resizeBilinear: as,
1161
+ rgbToGrayscale: We,
1162
+ rotateWithOffset: Oe,
1163
+ cropAndResize: De,
1164
+ nonMaxSuppression: Le,
1165
+ nonMaxSuppressionAsync: Ze,
1166
+ nonMaxSuppressionWithScore: Qe,
1167
+ nonMaxSuppressionWithScoreAsync: Ue,
1168
+ nonMaxSuppressionPadded: es,
1169
+ nonMaxSuppressionPaddedAsync: ts,
1170
+ threshold: ls,
1171
+ transform: ms
1172
+ }, Rs = {
1173
+ bandPart: hs,
1174
+ gramSchmidt: ds,
1175
+ qr: $s
1249
1176
  };
1250
1177
  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,
1178
+ Te as a,
1179
+ bn as b,
1180
+ F as c,
1181
+ nn as d,
1182
+ on as e,
1183
+ z as f,
1184
+ ke as g,
1185
+ I as h,
1186
+ de as i,
1187
+ Ks as j,
1188
+ an as k,
1189
+ Rs as l,
1190
+ cn as m,
1191
+ en as n,
1192
+ hn as o,
1193
+ Ee as p,
1267
1194
  as as q,
1268
- $e as r,
1269
- M as s,
1270
- N as t,
1271
- mn as u,
1272
- ke as v,
1195
+ Se as r,
1196
+ Be as s,
1197
+ un as t,
1198
+ dn as u,
1199
+ is as v,
1273
1200
  G as w,
1274
- je as x,
1275
- Fe as y,
1276
- Oe as z
1201
+ ze as x
1277
1202
  };