mind-ar
Version:
web augmented reality framework
1,741 lines • 2.2 MB
JavaScript
import { O as WC } from "./ui-fBadYuor.js";
function DC(n, t) {
for (var e = 0; e < t.length; e++) {
const s = t[e];
if (typeof s != "string" && !Array.isArray(s)) {
for (const o in s)
if (o !== "default" && !(o in n)) {
const r = Object.getOwnPropertyDescriptor(s, o);
r && Object.defineProperty(n, o, r.get ? r : {
enumerable: !0,
get: () => s[o]
});
}
}
}
return Object.freeze(Object.defineProperty(n, Symbol.toStringTag, { value: "Module" }));
}
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
const FC = 1e-7, VC = 1e-4;
class qg {
constructor(t, e) {
this.backend = t, this.dataMover = e, this.data = /* @__PURE__ */ new WeakMap(), this.dataIdsCount = 0;
}
get(t) {
return this.data.has(t) || this.dataMover.moveData(this.backend, t), this.data.get(t);
}
set(t, e) {
this.dataIdsCount++, this.data.set(t, e);
}
has(t) {
return this.data.has(t);
}
delete(t) {
return this.dataIdsCount--, this.data.delete(t);
}
numDataIds() {
return this.dataIdsCount;
}
}
class _d {
refCount(t) {
return Qe("refCount");
}
incRef(t) {
return Qe("incRef");
}
timerAvailable() {
return !0;
}
time(t) {
return Qe("time");
}
read(t) {
return Qe("read");
}
readSync(t) {
return Qe("readSync");
}
readToGPU(t, e) {
return Qe("readToGPU");
}
numDataIds() {
return Qe("numDataIds");
}
disposeData(t, e) {
return Qe("disposeData");
}
write(t, e, s) {
return Qe("write");
}
move(t, e, s, o, r) {
return Qe("move");
}
createTensorFromGPUData(t, e, s) {
return Qe("createTensorFromGPUData");
}
memory() {
return Qe("memory");
}
/** Returns the highest precision for floats in bits (e.g. 16 or 32) */
floatPrecision() {
return Qe("floatPrecision");
}
/** Returns the smallest representable number. */
epsilon() {
return this.floatPrecision() === 32 ? FC : VC;
}
dispose() {
return Qe("dispose");
}
}
function Qe(n) {
throw new Error(`'${n}' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen`);
}
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
function Ud(n) {
let t = n.length, e = 0;
for (; t > 0; )
e = Math.random() * t | 0, t--, ds(n, t, e);
}
function zC(n, t) {
if (n.length !== t.length)
throw new Error(`Array sizes must match to be shuffled together First array length was ${n.length}Second array length was ${t.length}`);
let e = n.length, s = 0;
for (; e > 0; )
s = Math.random() * e | 0, e--, ds(n, e, s), ds(t, e, s);
}
function Os(n, t, e) {
return Math.max(n, Math.min(t, e));
}
function Bl(n) {
return n % 2 === 0 ? n : n + 1;
}
function ds(n, t, e) {
const s = n[t];
n[t] = n[e], n[e] = s;
}
function tb(n) {
let t = 0;
for (let e = 0; e < n.length; e++)
t += n[e];
return t;
}
function PC(n, t) {
const e = Math.random();
return t * e + (1 - e) * n;
}
function AC(n, t) {
let e = 0;
for (let s = 0; s < n.length; s++) {
const o = Number(n[s]) - Number(t[s]);
e += o * o;
}
return e;
}
function C(n, t) {
if (!n)
throw new Error(typeof t == "string" ? t : t());
}
function Pe(n, t, e = "") {
C($t(n, t), () => e + ` Shapes ${n} and ${t} must match`);
}
function Hl(n) {
C(n != null, () => "The input to the tensor constructor must be a non-null value.");
}
function X(n) {
if (n.length === 0)
return 1;
let t = n[0];
for (let e = 1; e < n.length; e++)
t *= n[e];
return t;
}
function OC(n) {
return n.length === 0;
}
function XC(n, t) {
if (n === t)
return !0;
if (n == null || t == null || n.length !== t.length)
return !1;
for (let e = 0; e < n.length; e++)
if (n[e] !== null && t[e] !== null && n[e] !== t[e])
return !1;
return !0;
}
function $t(n, t) {
if (n === t)
return !0;
if (n == null || t == null || n.length !== t.length)
return !1;
for (let e = 0; e < n.length; e++)
if (n[e] !== t[e])
return !1;
return !0;
}
function Co(n) {
return n % 1 === 0;
}
function KC(n) {
if (Math.tanh != null)
return Math.tanh(n);
if (n === 1 / 0)
return 1;
if (n === -1 / 0)
return -1;
{
const t = Math.exp(2 * n);
return (t - 1) / (t + 1);
}
}
function hl(n) {
const t = Math.ceil(Math.sqrt(n));
return [t, Math.ceil(n / t)];
}
function ZC(n) {
const t = new Uint32Array(n);
for (let e = 0; e < n; ++e)
t[e] = e;
return Ud(t), t;
}
function xo(n, t) {
return t <= n.length ? n : n + " ".repeat(t - n.length);
}
function id(n, t = (o) => 0, e, s) {
return new Promise((o, r) => {
let i = 0;
const a = () => {
if (n()) {
o();
return;
}
i++;
const l = t(i);
if (e != null && i >= e) {
r();
return;
}
s != null ? s(a, l) : setTimeout(a, l);
};
a();
});
}
function Yd(n, t) {
let e = 1, s = -1;
for (let r = 0; r < n.length; ++r)
if (n[r] >= 0)
e *= n[r];
else if (n[r] === -1) {
if (s !== -1)
throw Error(`Shapes can only have 1 implicit size. Found -1 at dim ${s} and dim ${r}`);
s = r;
} else if (n[r] < 0)
throw Error(`Shapes can not be < 0. Found ${n[r]} at dim ${r}`);
if (s === -1) {
if (t > 0 && t !== e)
throw Error(`Size(${t}) must match the product of shape ${n}`);
return n;
}
if (e === 0)
throw Error(`Cannot infer the missing size in [${n}] when there are 0 elements`);
if (t % e !== 0)
throw Error(`The implicit shape can't be a fractional number. Got ${t} / ${e}`);
const o = n.slice();
return o[s] = t / e, o;
}
function Ct(n, t) {
const e = t.length;
return n = n == null ? t.map((s, o) => o) : [].concat(n), C(n.every((s) => s >= -e && s < e), () => `All values in axis param must be in range [-${e}, ${e}) but got axis ${n}`), C(n.every((s) => Co(s)), () => `All values in axis param must be integers but got axis ${n}`), n.map((s) => s < 0 ? e + s : s);
}
function ws(n, t) {
const e = [], s = [], o = t != null && Array.isArray(t) && t.length === 0, r = t == null || o ? null : Ct(t, n).sort();
let i = 0;
for (let a = 0; a < n.length; ++a) {
if (r != null) {
if (r[i] === a && n[a] !== 1)
throw new Error(`Can't squeeze axis ${a} since its dim '${n[a]}' is not 1`);
(r[i] == null || r[i] > a) && n[a] === 1 && (e.push(n[a]), s.push(a)), r[i] <= a && i++;
}
n[a] !== 1 && (e.push(n[a]), s.push(a));
}
return { newShape: e, keptDims: s };
}
function Se(n, t) {
return ne(n, t);
}
function ne(n, t) {
let e = null;
if (n == null || n === "float32")
e = new Float32Array(t);
else if (n === "int32")
e = new Int32Array(t);
else if (n === "bool")
e = new Uint8Array(t);
else if (n === "string")
e = new Array(t);
else
throw new Error(`Unknown data type ${n}`);
return e;
}
function eb(n, t) {
for (let e = 0; e < n.length; e++) {
const s = n[e];
if (isNaN(s) || !isFinite(s))
throw Error(`A tensor of type ${t} being uploaded contains ${s}.`);
}
}
function nb(n) {
return n === "bool" || n === "complex64" || n === "float32" || n === "int32" || n === "string";
}
function Qd(n, t) {
return !(t === "complex64" || t === "float32" && n !== "complex64" || t === "int32" && n !== "float32" && n !== "complex64" || t === "bool" && n === "bool");
}
function ri(n) {
if (n === "float32" || n === "int32")
return 4;
if (n === "complex64")
return 8;
if (n === "bool")
return 1;
throw new Error(`Unknown dtype ${n}`);
}
function sb(n) {
if (n == null)
return 0;
let t = 0;
return n.forEach((e) => t += e.length), t;
}
function vr(n) {
return typeof n == "string" || n instanceof String;
}
function ob(n) {
return typeof n == "boolean";
}
function pl(n) {
return typeof n == "number";
}
function Oo(n) {
return Array.isArray(n) ? Oo(n[0]) : n instanceof Float32Array ? "float32" : n instanceof Int32Array || n instanceof Uint8Array || n instanceof Uint8ClampedArray ? "int32" : pl(n) ? "float32" : vr(n) ? "string" : ob(n) ? "bool" : "float32";
}
function Xs(n) {
return !!(n && n.constructor && n.call && n.apply);
}
function fl(n, t) {
for (let e = t; e < n; ++e)
if (n % e === 0)
return e;
return n;
}
function dt(n) {
const t = n.length;
if (t < 2)
return [];
const e = new Array(t - 1);
e[t - 2] = n[t - 1];
for (let s = t - 3; s >= 0; --s)
e[s] = e[s + 1] * n[s + 1];
return e;
}
function rb(n, t, e, s = !1) {
const o = new Array();
if (t.length === 1) {
const r = t[0] * (s ? 2 : 1);
for (let i = 0; i < r; i++)
o[i] = e[n + i];
} else {
const r = t[0], i = t.slice(1), a = i.reduce((l, c) => l * c) * (s ? 2 : 1);
for (let l = 0; l < r; l++)
o[l] = rb(n + l * a, i, e, s);
}
return o;
}
function kn(n, t, e = !1) {
if (n.length === 0)
return t[0];
const s = n.reduce((o, r) => o * r) * (e ? 2 : 1);
if (s === 0)
return [];
if (s !== t.length)
throw new Error(`[${n}] does not match the input size ${t.length}${e ? " for a complex tensor" : ""}.`);
return rb(0, n, t, e);
}
function ib(n, t) {
if (Array.isArray(n))
return n;
if (t === "float32")
return n instanceof Float32Array ? n : new Float32Array(n);
if (t === "int32")
return n instanceof Int32Array ? n : new Int32Array(n);
if (t === "bool" || t === "string")
return Uint8Array.from(new Int32Array(n));
throw new Error(`Unknown dtype ${t}`);
}
function _l(n, t) {
const e = ke(n, t);
for (let s = 0; s < e.length; s++)
e[s] = 1;
return e;
}
function ke(n, t) {
if (t == null || t === "float32" || t === "complex64")
return new Float32Array(n);
if (t === "int32")
return new Int32Array(n);
if (t === "bool")
return new Uint8Array(n);
throw new Error(`Unknown data type ${t}`);
}
function Jd(n, t) {
const e = n.reduce((s, o) => s * o, 1);
if (t == null || t === "float32")
return kn(n, new Float32Array(e));
if (t === "int32")
return kn(n, new Int32Array(e));
if (t === "bool")
return kn(n, new Uint8Array(e));
throw new Error(`Unknown data type ${t}`);
}
function is(n) {
n.forEach((t) => {
C(Number.isInteger(t) && t >= 0, () => `Tensor must have a shape comprised of positive integers but got shape [${n}].`);
});
}
function zn(n, t, e) {
if (t === 0)
return 0;
if (t === 1)
return n[0];
let s = n[n.length - 1];
for (let o = 0; o < n.length - 1; ++o)
s += e[o] * n[o];
return s;
}
function Xo(n, t, e) {
if (t === 0)
return [];
if (t === 1)
return [n];
const s = new Array(t);
for (let o = 0; o < s.length - 1; ++o)
s[o] = Math.floor(n / e[o]), n -= s[o] * e[o];
return s[s.length - 1] = n, s;
}
function Ci(n) {
return n && n.then && typeof n.then == "function";
}
/**
* @license
* Copyright 2017 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
const um = "tfjsflags";
class BC {
// tslint:disable-next-line: no-any
constructor(t) {
this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.getQueryParams = HC, this.populateURLFlags();
}
setPlatform(t, e) {
this.platform != null && (F().getBool("IS_TEST") || F().getBool("PROD") || console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${t}.`)), this.platformName = t, this.platform = e;
}
registerFlag(t, e, s) {
if (this.flagRegistry[t] = { evaluationFn: e, setHook: s }, this.urlFlags[t] != null) {
const o = this.urlFlags[t];
F().getBool("IS_TEST") || F().getBool("PROD") || console.warn(`Setting feature override from URL ${t}: ${o}.`), this.set(t, o);
}
}
async getAsync(t) {
return t in this.flags ? this.flags[t] : (this.flags[t] = await this.evaluateFlag(t), this.flags[t]);
}
get(t) {
if (t in this.flags)
return this.flags[t];
const e = this.evaluateFlag(t);
if (Ci(e))
throw new Error(`Flag ${t} cannot be synchronously evaluated. Please use getAsync() instead.`);
return this.flags[t] = e, this.flags[t];
}
getNumber(t) {
return this.get(t);
}
getBool(t) {
return this.get(t);
}
getString(t) {
return this.get(t);
}
getFlags() {
return this.flags;
}
// For backwards compatibility.
get features() {
return this.flags;
}
set(t, e) {
if (this.flagRegistry[t] == null)
throw new Error(`Cannot set flag ${t} as it has not been registered.`);
this.flags[t] = e, this.flagRegistry[t].setHook != null && this.flagRegistry[t].setHook(e);
}
evaluateFlag(t) {
if (this.flagRegistry[t] == null)
throw new Error(`Cannot evaluate flag '${t}': no evaluation function found.`);
return this.flagRegistry[t].evaluationFn();
}
setFlags(t) {
this.flags = Object.assign({}, t);
}
reset() {
this.flags = {}, this.urlFlags = {}, this.populateURLFlags();
}
populateURLFlags() {
if (typeof this.global > "u" || typeof this.global.location > "u" || typeof this.global.location.search > "u")
return;
const t = this.getQueryParams(this.global.location.search);
um in t && t[um].split(",").forEach((s) => {
const [o, r] = s.split(":");
this.urlFlags[o] = UC(o, r);
});
}
}
function HC(n) {
const t = {};
return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, (e, ...s) => (_C(t, s[0], s[1]), s.join("="))), t;
}
function _C(n, t, e) {
n[decodeURIComponent(t)] = decodeURIComponent(e || "");
}
function UC(n, t) {
const e = t.toLowerCase();
return e === "true" || e === "false" ? e === "true" : `${+e}` === e ? +e : t;
}
function F() {
return ab;
}
let ab = null;
function YC(n) {
ab = n;
}
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
let $u;
function lb() {
if ($u == null) {
let n;
if (typeof window < "u")
n = window;
else if (typeof global < "u")
n = global;
else if (typeof process < "u")
n = process;
else if (typeof self < "u")
n = self;
else
throw new Error("Could not find a global object");
$u = n;
}
return $u;
}
function QC() {
const n = lb();
return n._tfGlobals == null && (n._tfGlobals = /* @__PURE__ */ new Map()), n._tfGlobals;
}
function jd(n, t) {
const e = QC();
if (e.has(n))
return e.get(n);
{
const s = t();
return e.set(n, s), e.get(n);
}
}
const Ul = "Abs", vi = "Acos", Si = "Acosh", Sr = "Add", qd = "AddN", th = "All", eh = "Any", Yl = "ArgMax", Ql = "ArgMin", ki = "Asin", Ti = "Asinh", Ni = "Atan", Ri = "Atanh", $i = "Atan2", Jl = "AvgPool", nh = "AvgPoolGrad", jl = "AvgPool3D", sh = "AvgPool3DGrad", ql = "BatchMatMul", tc = "BatchToSpaceND", oh = "Bincount", rh = "BitwiseAnd", JC = "BroadcastTo", cb = "BroadcastArgs", Gi = "Cast", Ei = "Ceil", Li = "ClipByValue", ih = "Complex", ec = "ComplexAbs", nc = "Concat", sc = "Conv2D", ah = "Conv2DBackpropFilter", oc = "Conv2DBackpropInput", rc = "Conv3D", lh = "Conv3DBackpropFilterV2", ch = "Conv3DBackpropInputV2", Mi = "Cos", Wi = "Cosh", uh = "Cumprod", ic = "Cumsum", dh = "CropAndResize", hh = "DenseBincount", ph = "DepthToSpace", ac = "DepthwiseConv2dNative", fh = "DepthwiseConv2dNativeBackpropFilter", mh = "DepthwiseConv2dNativeBackpropInput", ub = "Diag", lc = "Dilation2D", ad = "Dilation2DBackpropInput", ld = "Dilation2DBackpropFilter", gh = "Draw", Di = "RealDiv", bh = "Einsum", Fi = "Elu", xh = "EluGrad", Vi = "Erf", cc = "Equal", zi = "Exp", uc = "ExpandDims", Pi = "Expm1", yh = "FFT", wh = "Fill", Ih = "FlipLeftRight", Ai = "Floor", Oi = "FloorDiv", dc = "FusedBatchNorm", hc = "GatherV2", db = "GatherNd", pc = "Greater", Xi = "GreaterEqual", Ki = "Identity", Ch = "IFFT", vh = "Imag", Zi = "IsFinite", Bi = "IsInf", Hi = "IsNan", fc = "LeakyRelu", mc = "Less", gc = "LessEqual", hb = "LinSpace", _i = "Log", Ui = "Log1p", bc = "LogicalAnd", xc = "LogicalNot", yc = "LogicalOr", XY = "LogicalXor", jC = "LogSoftmax", KY = "LowerBound", wc = "LRN", Sh = "LRNGrad", ZY = "MatrixBandPart", Ic = "Max", Yi = "Maximum", Cc = "MaxPool", kh = "MaxPoolGrad", vc = "MaxPool3D", Th = "MaxPool3DGrad", pb = "MaxPoolWithArgmax", Sc = "Mean", kc = "Min", Qi = "Minimum", Tc = "MirrorPad", Ji = "Mod", fb = "Multinomial", ji = "Multiply", Nc = "Neg", Rc = "NotEqual", Nh = "NonMaxSuppressionV3", Rh = "NonMaxSuppressionV4", $h = "NonMaxSuppressionV5", $c = "OnesLike", Gc = "OneHot", Ec = "Pack", Lc = "PadV2", BY = "Pool", qi = "Pow", Mc = "Prelu", Wc = "Prod", mb = "RaggedGather", gb = "RaggedRange", bb = "RaggedTensorToTensor", Gh = "Range", Eh = "Real", ta = "Reciprocal", ea = "Relu", Dc = "Reshape", Fc = "ResizeNearestNeighbor", Lh = "ResizeNearestNeighborGrad", Vc = "ResizeBilinear", Mh = "ResizeBilinearGrad", na = "Relu6", zc = "Reverse", sa = "Round", oa = "Rsqrt", xb = "ScatterNd", yb = "TensorScatterUpdate", wb = "SearchSorted", Pc = "Select", ra = "Selu", Ac = "Slice", ia = "Sin", aa = "Sinh", la = "Sign", ca = "Sigmoid", ua = "Softplus", da = "Sqrt", Oc = "Sum", Xc = "SpaceToBatchND", Kc = "SplitV", Zc = "Softmax", Wh = "SparseFillEmptyRows", Dh = "SparseReshape", Fh = "SparseSegmentMean", Vh = "SparseSegmentSum", Ib = "SparseToDense", ha = "SquaredDifference", zh = "Square", Bc = "StaticRegexReplace", Ph = "StridedSlice", Ah = "StringNGrams", Oh = "StringSplit", Xh = "StringToHashBucketFast", pa = "Sub", fa = "Tan", ma = "Tanh", ga = "Tile", Kh = "TopK", Zh = "Transform", ar = "Transpose", Bh = "Unique", Hc = "Unpack", _c = "UnsortedSegmentSum", HY = "UpperBound", Uc = "ZerosLike", ba = "Step", cd = "FromPixels", Hh = "RotateWithOffset", ml = "_FusedMatMul", gl = "FusedConv2D", Cb = "FusedDepthwiseConv2D";
/**
* @license
* Copyright 2018 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
function ln(...n) {
F().getBool("IS_TEST") || F().getBool("PROD") || console.warn(...n);
}
function qC(...n) {
F().getBool("IS_TEST") || F().getBool("PROD") || console.log(...n);
}
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
const pr = jd("kernelRegistry", () => /* @__PURE__ */ new Map()), ii = jd("gradRegistry", () => /* @__PURE__ */ new Map());
function bl(n, t) {
const e = _h(n, t);
return pr.get(e);
}
function dm(n) {
return ii.get(n);
}
function ud(n) {
const t = pr.entries(), e = [];
for (; ; ) {
const { done: s, value: o } = t.next();
if (s)
break;
const [r, i] = o, [a] = r.split("_");
a === n && e.push(i);
}
return e;
}
function sn(n) {
const { kernelName: t, backendName: e } = n, s = _h(t, e);
pr.has(s) && ln(`The kernel '${t}' for backend '${e}' is already registered`), pr.set(s, n);
}
function t2(n) {
const { kernelName: t } = n;
ii.has(t) && F().getBool("DEBUG") && ln(`Overriding the gradient for '${t}'`), ii.set(t, n);
}
function _Y(n, t) {
const e = _h(n, t);
if (!pr.has(e))
throw new Error(`The kernel '${n}' for backend '${t}' is not registered`);
pr.delete(e);
}
function UY(n) {
if (!ii.has(n))
throw new Error(`The gradient '${n}' for backend is not registered`);
ii.delete(n);
}
function YY(n, t) {
ud(n).forEach((s) => {
const o = Object.assign({}, s, { backendName: t });
sn(o);
});
}
function _h(n, t) {
return `${t}_${n}`;
}
/**
* @license
* Copyright 2023 Google LLC.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
function vb(n) {
return n instanceof Float32Array || n instanceof Int32Array || n instanceof Uint8Array || n instanceof Uint8ClampedArray;
}
var Ko = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
function e2(n) {
return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
}
function n2(n) {
if (n.__esModule)
return n;
var t = n.default;
if (typeof t == "function") {
var e = function s() {
return this instanceof s ? Reflect.construct(t, arguments, this.constructor) : t.apply(this, arguments);
};
e.prototype = t.prototype;
} else
e = {};
return Object.defineProperty(e, "__esModule", { value: !0 }), Object.keys(n).forEach(function(s) {
var o = Object.getOwnPropertyDescriptor(n, s);
Object.defineProperty(e, s, o.get ? o : {
enumerable: !0,
get: function() {
return n[s];
}
});
}), e;
}
var Sb = Bt, In = null;
try {
In = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
0,
97,
115,
109,
1,
0,
0,
0,
1,
13,
2,
96,
0,
1,
127,
96,
4,
127,
127,
127,
127,
1,
127,
3,
7,
6,
0,
1,
1,
1,
1,
1,
6,
6,
1,
127,
1,
65,
0,
11,
7,
50,
6,
3,
109,
117,
108,
0,
1,
5,
100,
105,
118,
95,
115,
0,
2,
5,
100,
105,
118,
95,
117,
0,
3,
5,
114,
101,
109,
95,
115,
0,
4,
5,
114,
101,
109,
95,
117,
0,
5,
8,
103,
101,
116,
95,
104,
105,
103,
104,
0,
0,
10,
191,
1,
6,
4,
0,
35,
0,
11,
36,
1,
1,
126,
32,
0,
173,
32,
1,
173,
66,
32,
134,
132,
32,
2,
173,
32,
3,
173,
66,
32,
134,
132,
126,
34,
4,
66,
32,
135,
167,
36,
0,
32,
4,
167,
11,
36,
1,
1,
126,
32,
0,
173,
32,
1,
173,
66,
32,
134,
132,
32,
2,
173,
32,
3,
173,
66,
32,
134,
132,
127,
34,
4,
66,
32,
135,
167,
36,
0,
32,
4,
167,
11,
36,
1,
1,
126,
32,
0,
173,
32,
1,
173,
66,
32,
134,
132,
32,
2,
173,
32,
3,
173,
66,
32,
134,
132,
128,
34,
4,
66,
32,
135,
167,
36,
0,
32,
4,
167,
11,
36,
1,
1,
126,
32,
0,
173,
32,
1,
173,
66,
32,
134,
132,
32,
2,
173,
32,
3,
173,
66,
32,
134,
132,
129,
34,
4,
66,
32,
135,
167,
36,
0,
32,
4,
167,
11,
36,
1,
1,
126,
32,
0,
173,
32,
1,
173,
66,
32,
134,
132,
32,
2,
173,
32,
3,
173,
66,
32,
134,
132,
130,
34,
4,
66,
32,
135,
167,
36,
0,
32,
4,
167,
11
])), {}).exports;
} catch {
}
function Bt(n, t, e) {
this.low = n | 0, this.high = t | 0, this.unsigned = !!e;
}
Bt.prototype.__isLong__;
Object.defineProperty(Bt.prototype, "__isLong__", { value: !0 });
function on(n) {
return (n && n.__isLong__) === !0;
}
Bt.isLong = on;
var hm = {}, pm = {};
function Zo(n, t) {
var e, s, o;
return t ? (n >>>= 0, (o = 0 <= n && n < 256) && (s = pm[n], s) ? s : (e = Ht(n, (n | 0) < 0 ? -1 : 0, !0), o && (pm[n] = e), e)) : (n |= 0, (o = -128 <= n && n < 128) && (s = hm[n], s) ? s : (e = Ht(n, n < 0 ? -1 : 0, !1), o && (hm[n] = e), e));
}
Bt.fromInt = Zo;
function Cn(n, t) {
if (isNaN(n))
return t ? mo : vn;
if (t) {
if (n < 0)
return mo;
if (n >= kb)
return Rb;
} else {
if (n <= -mm)
return je;
if (n + 1 >= mm)
return Nb;
}
return n < 0 ? Cn(-n, t).neg() : Ht(n % fr | 0, n / fr | 0, t);
}
Bt.fromNumber = Cn;
function Ht(n, t, e) {
return new Bt(n, t, e);
}
Bt.fromBits = Ht;
var xl = Math.pow;
function Uh(n, t, e) {
if (n.length === 0)
throw Error("empty string");
if (n === "NaN" || n === "Infinity" || n === "+Infinity" || n === "-Infinity")
return vn;
if (typeof t == "number" ? (e = t, t = !1) : t = !!t, e = e || 10, e < 2 || 36 < e)
throw RangeError("radix");
var s;
if ((s = n.indexOf("-")) > 0)
throw Error("interior hyphen");
if (s === 0)
return Uh(n.substring(1), t, e).neg();
for (var o = Cn(xl(e, 8)), r = vn, i = 0; i < n.length; i += 8) {
var a = Math.min(8, n.length - i), l = parseInt(n.substring(i, i + a), e);
if (a < 8) {
var c = Cn(xl(e, a));
r = r.mul(c).add(Cn(l));
} else
r = r.mul(o), r = r.add(Cn(l));
}
return r.unsigned = t, r;
}
Bt.fromString = Uh;
function Hn(n, t) {
return typeof n == "number" ? Cn(n, t) : typeof n == "string" ? Uh(n, t) : Ht(n.low, n.high, typeof t == "boolean" ? t : n.unsigned);
}
Bt.fromValue = Hn;
var fm = 65536, s2 = 1 << 24, fr = fm * fm, kb = fr * fr, mm = kb / 2, gm = Zo(s2), vn = Zo(0);
Bt.ZERO = vn;
var mo = Zo(0, !0);
Bt.UZERO = mo;
var ir = Zo(1);
Bt.ONE = ir;
var Tb = Zo(1, !0);
Bt.UONE = Tb;
var dd = Zo(-1);
Bt.NEG_ONE = dd;
var Nb = Ht(-1, 2147483647, !1);
Bt.MAX_VALUE = Nb;
var Rb = Ht(-1, -1, !0);
Bt.MAX_UNSIGNED_VALUE = Rb;
var je = Ht(0, -2147483648, !1);
Bt.MIN_VALUE = je;
var st = Bt.prototype;
st.toInt = function() {
return this.unsigned ? this.low >>> 0 : this.low;
};
st.toNumber = function() {
return this.unsigned ? (this.high >>> 0) * fr + (this.low >>> 0) : this.high * fr + (this.low >>> 0);
};
st.toString = function(t) {
if (t = t || 10, t < 2 || 36 < t)
throw RangeError("radix");
if (this.isZero())
return "0";
if (this.isNegative())
if (this.eq(je)) {
var e = Cn(t), s = this.div(e), o = s.mul(e).sub(this);
return s.toString(t) + o.toInt().toString(t);
} else
return "-" + this.neg().toString(t);
for (var r = Cn(xl(t, 6), this.unsigned), i = this, a = ""; ; ) {
var l = i.div(r), c = i.sub(l.mul(r)).toInt() >>> 0, u = c.toString(t);
if (i = l, i.isZero())
return u + a;
for (; u.length < 6; )
u = "0" + u;
a = "" + u + a;
}
};
st.getHighBits = function() {
return this.high;
};
st.getHighBitsUnsigned = function() {
return this.high >>> 0;
};
st.getLowBits = function() {
return this.low;
};
st.getLowBitsUnsigned = function() {
return this.low >>> 0;
};
st.getNumBitsAbs = function() {
if (this.isNegative())
return this.eq(je) ? 64 : this.neg().getNumBitsAbs();
for (var t = this.high != 0 ? this.high : this.low, e = 31; e > 0 && !(t & 1 << e); e--)
;
return this.high != 0 ? e + 33 : e + 1;
};
st.isZero = function() {
return this.high === 0 && this.low === 0;
};
st.eqz = st.isZero;
st.isNegative = function() {
return !this.unsigned && this.high < 0;
};
st.isPositive = function() {
return this.unsigned || this.high >= 0;
};
st.isOdd = function() {
return (this.low & 1) === 1;
};
st.isEven = function() {
return (this.low & 1) === 0;
};
st.equals = function(t) {
return on(t) || (t = Hn(t)), this.unsigned !== t.unsigned && this.high >>> 31 === 1 && t.high >>> 31 === 1 ? !1 : this.high === t.high && this.low === t.low;
};
st.eq = st.equals;
st.notEquals = function(t) {
return !this.eq(
/* validates */
t
);
};
st.neq = st.notEquals;
st.ne = st.notEquals;
st.lessThan = function(t) {
return this.comp(
/* validates */
t
) < 0;
};
st.lt = st.lessThan;
st.lessThanOrEqual = function(t) {
return this.comp(
/* validates */
t
) <= 0;
};
st.lte = st.lessThanOrEqual;
st.le = st.lessThanOrEqual;
st.greaterThan = function(t) {
return this.comp(
/* validates */
t
) > 0;
};
st.gt = st.greaterThan;
st.greaterThanOrEqual = function(t) {
return this.comp(
/* validates */
t
) >= 0;
};
st.gte = st.greaterThanOrEqual;
st.ge = st.greaterThanOrEqual;
st.compare = function(t) {
if (on(t) || (t = Hn(t)), this.eq(t))
return 0;
var e = this.isNegative(), s = t.isNegative();
return e && !s ? -1 : !e && s ? 1 : this.unsigned ? t.high >>> 0 > this.high >>> 0 || t.high === this.high && t.low >>> 0 > this.low >>> 0 ? -1 : 1 : this.sub(t).isNegative() ? -1 : 1;
};
st.comp = st.compare;
st.negate = function() {
return !this.unsigned && this.eq(je) ? je : this.not().add(ir);
};
st.neg = st.negate;
st.add = function(t) {
on(t) || (t = Hn(t));
var e = this.high >>> 16, s = this.high & 65535, o = this.low >>> 16, r = this.low & 65535, i = t.high >>> 16, a = t.high & 65535, l = t.low >>> 16, c = t.low & 65535, u = 0, d = 0, h = 0, p = 0;
return p += r + c, h += p >>> 16, p &= 65535, h += o + l, d += h >>> 16, h &= 65535, d += s + a, u += d >>> 16, d &= 65535, u += e + i, u &= 65535, Ht(h << 16 | p, u << 16 | d, this.unsigned);
};
st.subtract = function(t) {
return on(t) || (t = Hn(t)), this.add(t.neg());
};
st.sub = st.subtract;
st.multiply = function(t) {
if (this.isZero())
return vn;
if (on(t) || (t = Hn(t)), In) {
var e = In.mul(
this.low,
this.high,
t.low,
t.high
);
return Ht(e, In.get_high(), this.unsigned);
}
if (t.isZero())
return vn;
if (this.eq(je))
return t.isOdd() ? je : vn;
if (t.eq(je))
return this.isOdd() ? je : vn;
if (this.isNegative())
return t.isNegative() ? this.neg().mul(t.neg()) : this.neg().mul(t).neg();
if (t.isNegative())
return this.mul(t.neg()).neg();
if (this.lt(gm) && t.lt(gm))
return Cn(this.toNumber() * t.toNumber(), this.unsigned);
var s = this.high >>> 16, o = this.high & 65535, r = this.low >>> 16, i = this.low & 65535, a = t.high >>> 16, l = t.high & 65535, c = t.low >>> 16, u = t.low & 65535, d = 0, h = 0, p = 0, f = 0;
return f += i * u, p += f >>> 16, f &= 65535, p += r * u, h += p >>> 16, p &= 65535, p += i * c, h += p >>> 16, p &= 65535, h += o * u, d += h >>> 16, h &= 65535, h += r * c, d += h >>> 16, h &= 65535, h += i * l, d += h >>> 16, h &= 65535, d += s * u + o * c + r * l + i * a, d &= 65535, Ht(p << 16 | f, d << 16 | h, this.unsigned);
};
st.mul = st.multiply;
st.divide = function(t) {
if (on(t) || (t = Hn(t)), t.isZero())
throw Error("division by zero");
if (In) {
if (!this.unsigned && this.high === -2147483648 && t.low === -1 && t.high === -1)
return this;
var e = (this.unsigned ? In.div_u : In.div_s)(
this.low,
this.high,
t.low,
t.high
);
return Ht(e, In.get_high(), this.unsigned);
}
if (this.isZero())
return this.unsigned ? mo : vn;
var s, o, r;
if (this.unsigned) {
if (t.unsigned || (t = t.toUnsigned()), t.gt(this))
return mo;
if (t.gt(this.shru(1)))
return Tb;
r = mo;
} else {
if (this.eq(je)) {
if (t.eq(ir) || t.eq(dd))
return je;
if (t.eq(je))
return ir;
var i = this.shr(1);
return s = i.div(t).shl(1), s.eq(vn) ? t.isNegative() ? ir : dd : (o = this.sub(t.mul(s)), r = s.add(o.div(t)), r);
} else if (t.eq(je))
return this.unsigned ? mo : vn;
if (this.isNegative())
return t.isNegative() ? this.neg().div(t.neg()) : this.neg().div(t).neg();
if (t.isNegative())
return this.div(t.neg()).neg();
r = vn;
}
for (o = this; o.gte(t); ) {
s = Math.max(1, Math.floor(o.toNumber() / t.toNumber()));
for (var a = Math.ceil(Math.log(s) / Math.LN2), l = a <= 48 ? 1 : xl(2, a - 48), c = Cn(s), u = c.mul(t); u.isNegative() || u.gt(o); )
s -= l, c = Cn(s, this.unsigned), u = c.mul(t);
c.isZero() && (c = ir), r = r.add(c), o = o.sub(u);
}
return r;
};
st.div = st.divide;
st.modulo = function(t) {
if (on(t) || (t = Hn(t)), In) {
var e = (this.unsigned ? In.rem_u : In.rem_s)(
this.low,
this.high,
t.low,
t.high
);
return Ht(e, In.get_high(), this.unsigned);
}
return this.sub(this.div(t).mul(t));
};
st.mod = st.modulo;
st.rem = st.modulo;
st.not = function() {
return Ht(~this.low, ~this.high, this.unsigned);
};
st.and = function(t) {
return on(t) || (t = Hn(t)), Ht(this.low & t.low, this.high & t.high, this.unsigned);
};
st.or = function(t) {
return on(t) || (t = Hn(t)), Ht(this.low | t.low, this.high | t.high, this.unsigned);
};
st.xor = function(t) {
return on(t) || (t = Hn(t)), Ht(this.low ^ t.low, this.high ^ t.high, this.unsigned);
};
st.shiftLeft = function(t) {
return on(t) && (t = t.toInt()), (t &= 63) === 0 ? this : t < 32 ? Ht(this.low << t, this.high << t | this.low >>> 32 - t, this.unsigned) : Ht(0, this.low << t - 32, this.unsigned);
};
st.shl = st.shiftLeft;
st.shiftRight = function(t) {
return on(t) && (t = t.toInt()), (t &= 63) === 0 ? this : t < 32 ? Ht(this.low >>> t | this.high << 32 - t, this.high >> t, this.unsigned) : Ht(this.high >> t - 32, this.high >= 0 ? 0 : -1, this.unsigned);
};
st.shr = st.shiftRight;
st.shiftRightUnsigned = function(t) {
if (on(t) && (t = t.toInt()), t &= 63, t === 0)
return this;
var e = this.high;
if (t < 32) {
var s = this.low;
return Ht(s >>> t | e << 32 - t, e >>> t, this.unsigned);
} else
return t === 32 ? Ht(e, 0, this.unsigned) : Ht(e >>> t - 32, 0, this.unsigned);
};
st.shru = st.shiftRightUnsigned;
st.shr_u = st.shiftRightUnsigned;
st.toSigned = function() {
return this.unsigned ? Ht(this.low, this.high, !1) : this;
};
st.toUnsigned = function() {
return this.unsigned ? this : Ht(this.low, this.high, !0);
};
st.toBytes = function(t) {
return t ? this.toBytesLE() : this.toBytesBE();
};
st.toBytesLE = function() {
var t = this.high, e = this.low;
return [
e & 255,
e >>> 8 & 255,
e >>> 16 & 255,
e >>> 24,
t & 255,
t >>> 8 & 255,
t >>> 16 & 255,
t >>> 24
];
};
st.toBytesBE = function() {
var t = this.high, e = this.low;
return [
t >>> 24,
t >>> 16 & 255,
t >>> 8 & 255,
t & 255,
e >>> 24,
e >>> 16 & 255,
e >>> 8 & 255,
e & 255
];
};
Bt.fromBytes = function(t, e, s) {
return s ? Bt.fromBytesLE(t, e) : Bt.fromBytesBE(t, e);
};
Bt.fromBytesLE = function(t, e) {
return new Bt(
t[0] | t[1] << 8 | t[2] << 16 | t[3] << 24,
t[4] | t[5] << 8 | t[6] << 16 | t[7] << 24,
e
);
};
Bt.fromBytesBE = function(t, e) {
return new Bt(
t[4] << 24 | t[5] << 16 | t[6] << 8 | t[7],
t[0] << 24 | t[1] << 16 | t[2] << 8 | t[3],
e
);
};
const $b = /* @__PURE__ */ e2(Sb), o2 = /* @__PURE__ */ DC({
__proto__: null,
default: $b
}, [Sb]);
/**
* @license
* Copyright 2021 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
const uo = (
// tslint:disable-next-line
$b || o2
);
function xa(n) {
return uo.fromString(n, !0, 16);
}
const Gb = xa("c3a5c85c97cb3127"), co = xa("b492b66fbe98f273"), De = xa("9ae16a3b2f90404f");
function hd(n) {
return n.xor(n.shru(47));
}
function Eb(n, t, e) {
const s = n.slice(t, t + e);
return uo.fromBytes(Array.from(s), !0, !0);
}
function Xt(n, t) {
return Eb(n, t, 8);
}
function bm(n, t) {
return Eb(n, t, 4);
}
function ge(n, t) {
return t === 0 ? n : n.shru(t).or(n.shl(64 - t));
}
function zs(n, t, e = xa("9ddfea08eb382d69")) {
let s = n.xor(t).mul(e);
s = s.xor(s.shru(47));
let o = t.xor(s).mul(e);
return o = o.xor(o.shru(47)), o = o.mul(e), o;
}
function r2(n, t, e, s, o, r) {
o = o.add(n), r = ge(r.add(o).add(s), 21);
const i = o;
return o = o.add(t), o = o.add(e), r = r.add(ge(o, 44)), [o.add(s), r.add(i)];
}
function Za(n, t, e, s) {
return r2(Xt(n, t), Xt(n, t + 8), Xt(n, t + 16), Xt(n, t + 24), e, s);
}
function i2(n, t = n.length) {
if (t >= 8) {
const e = De.add(t * 2), s = Xt(n, 0).add(De), o = Xt(n, t - 8), r = ge(o, 37).mul(e).add(s), i = ge(s, 25).add(o).mul(e);
return zs(r, i, e);
}
if (t >= 4) {
const e = De.add(t * 2), s = bm(n, 0);
return zs(s.shl(3).add(t), bm(n, t - 4), e);
}
if (t > 0) {
const e = n[0], s = n[t >> 1], o = n[t - 1], r = e + (s << 8), i = t + (o << 2);
return hd(De.mul(r).xor(Gb.mul(i))).mul(De);
}
return De;
}
function a2(n, t = n.length) {
const e = De.add(t * 2), s = Xt(n, 0).mul(co), o = Xt(n, 8), r = Xt(n, t - 8).mul(e), i = Xt(n, t - 16).mul(De);
return zs(ge(s.add(o), 43).add(ge(r, 30)).add(i), s.add(ge(o.add(De), 18)).add(r), e);
}
function l2(n, t = n.length) {
const e = De.add(t * 2), s = Xt(n, 0).mul(De), o = Xt(n, 8), r = Xt(n, t - 8).mul(e), i = Xt(n, t - 16).mul(De), a = ge(s.add(o), 43).add(ge(r, 30)).add(i), l = zs(a, s.add(ge(o.add(De), 18)).add(r), e), c = Xt(n, 16).mul(e), u = Xt(n, 24), d = a.add(Xt(n, t - 32)).mul(e), h = l.add(Xt(n, t - 24)).mul(e);
return zs(ge(c.add(u), 43).add(ge(d, 30)).add(h), c.add(ge(u.add(s), 18)).add(d), e);
}
function Lb(n, t = n.length) {
const e = uo.fromNumber(81, !0);
if (t <= 32)
return t <= 16 ? i2(n, t) : a2(n, t);
if (t <= 64)
return l2(n, t);
let s = e, o = e.mul(co).add(113), r = hd(o.mul(De).add(113)).mul(De), i = [uo.UZERO, uo.UZERO], a = [uo.UZERO, uo.UZERO];
s = s.mul(De).add(Xt(n, 0));
let l = 0;
const c = (t - 1 >> 6) * 64, u = c + (t - 1 & 63) - 63;
do
s = ge(s.add(o).add(i[0]).add(Xt(n, l + 8)), 37).mul(co), o = ge(o.add(i[1]).add(Xt(n, l + 48)), 42).mul(co), s = s.xor(a[1]), o = o.add(i[0]).add(Xt(n, l + 40)), r = ge(r.add(a[0]), 33).mul(co), i = Za(n, l, i[1].mul(co), s.add(a[0])), a = Za(n, l + 32, r.add(a[1]), o.add(Xt(n, l + 16))), [r, s] = [s, r], l += 64;
while (l !== c);
const d = co.add(r.and(255).shl(1));
return l = u, a[0] = a[0].add(t - 1 & 63), i[0] = i[0].add(a[0]), a[0] = a[0].add(i[0]), s = ge(s.add(o).add(i[0]).add(Xt(n, l + 8)), 37).mul(d), o = ge(o.add(i[1]).add(Xt(n, l + 48)), 42).mul(d), s = s.xor(a[1].mul(9)), o = o.add(i[0].mul(9).add(Xt(n, l + 40))), r = ge(r.add(a[0]), 33).mul(d), i = Za(n, l, i[1].mul(d), s.add(a[0])), a = Za(n, l + 32, r.add(a[1]), o.add(Xt(n, l + 16))), [r, s] = [s, r], zs(zs(i[0], a[0], d).add(hd(o).mul(Gb)).add(r), zs(i[1], a[1], d).add(s), d);
}
/**
* @license
* Copyright 2017 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
function Is(n, t) {
return t === "string" ? ms(n) : Qs([n], t);
}
function c2(n, t) {
return n instanceof Float32Array && t === "float32" || n instanceof Int32Array && t === "int32" || n instanceof Uint8Array && t === "bool";
}
function Qs(n, t) {
if (t === "string")
throw new Error("Cannot convert a string[] to a TypedArray");
if (Array.isArray(n) && (n = Ks(n)), F().getBool("DEBUG") && eb(n, t), c2(n, t))
return n;
if (t == null || t === "float32" || t === "complex64")
return new Float32Array(n);
if (t === "int32")
return new Int32Array(n);
if (t === "bool") {
const e = new Uint8Array(n.length);
for (let s = 0; s < e.length; ++s)
Math.round(n[s]) !== 0 && (e[s] = 1);
return e;
} else
throw new Error(`Unknown data type ${t}`);
}
function Ie() {
return F().platform.now();
}
function u2(n, t) {
return F().platform.fetch(n, t);
}
function ms(n, t = "utf-8") {
return t = t || "utf-8", F().platform.encode(n, t);
}
function gs(n, t = "utf-8") {
return t = t || "utf-8", F().platform.decode(n, t);
}
function qe(n) {
return F().platform.isTypedArray != null ? F().platform.isTypedArray(n) : vb(n);
}
function Ks(n, t = [], e = !1) {
if (t == null && (t = []), typeof n == "boolean" || typeof n == "number" || typeof n == "string" || Ci(n) || n == null || qe(n) && e)
t.push(n);
else if (Array.isArray(n) || qe(n))
for (let s = 0; s < n.length; ++s)
Ks(n[s], t, e);
else {
let s = -1;
for (const o of Object.keys(n))
/^([1-9]+[0-9]*|0)$/.test(o) && (s = Math.max(s, Number(o)));
for (let o = 0; o <= s; o++)
Ks(n[o], t, e);
}
return t;
}
const QY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
__proto__: null,
arraysEqual: $t,
arraysEqualWithNull: XC,
assert: C,
assertNonNegativeIntegerDimensions: is,
assertNonNull: Hl,
assertShapesMatch: Pe,
bytesFromStringArray: sb,
bytesPerElement: ri,
checkConversionForErrors: eb,
clamp: Os,
computeStrides: dt,
convertBackendValuesAndArrayBuffer: ib,
createScalarValue: Is,
createShuffledIndices: ZC,
decodeString: gs,
distSquared: AC,
encodeString: ms,
fetch: u2,
fingerPrint64: Lb,
flatten: Ks,
getArrayFromDType: ne,
getTypedArrayFromDType: Se,
hasEncodingLoss: Qd,
hexToLong: xa,
indexToLoc: Xo,
inferDtype: Oo,
inferFromImplicitShape: Yd,
isBoolean: ob,
isFunction: Xs,
isInt: Co,
isNumber: pl,
isPromise: Ci,
isScalarShape: OC,
isString: vr,
isTypedArray: qe,
isValidDtype: nb,
locToIndex: zn,
makeOnesTypedArray: _l,
makeZerosNestedTypedArray: Jd,
makeZerosTypedArray: ke,
nearestDivisor: fl,
nearestLargerEven: Bl,
now: Ie,
parseAxisParam: Ct,
randUniform: PC,
repeatedTry: id,
rightPad: xo,
shuffle: Ud,
shuffleCombo: zC,
sizeFromShape: X,
sizeToSquarishShape: hl,
squeezeShape: ws,
sum: tb,
swap: ds,
tanh: KC,
toNestedArray: kn,
toTypedArray: Qs
}, Symbol.toStringTag, { value: "Module" }));
/**
* @license
* Copyright 2018 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
class d2 {
constructor(t, e) {
this.backendTimer = t, this.logger = e, e == null && (this.logger = new p2());
}
profileKernel(t, e, s) {
let o;
const r = () => {
o = s();
};
let i;
const a = Ie();
if (this.backendTimer.timerAvailable())
i = this.backendTimer.time(r);
else {
r();
for (const c of o)
c.dataSync();
i = Promise.resolve({ kernelMs: Ie() - a });
}
if (F().getBool("CHECK_COMPUTATION_FOR_ERRORS"))
for (let c = 0; c < o.length; c++) {
const u = o[c];
u.data().then((d) => {
h2(d, u.dtype, t);
});
}
return {
kernelName: t,
outputs: o,
inputs: e,
timeMs: i.then((c) => c.kernelMs),
extraInfo: i.then((c) => c.getExtraProfileInfo != null ? c.getExtraProfileInfo() : "")
};
}
logKernelProfile(t) {
const { kernelName: e, outputs: s, timeMs: o, inputs: r, extraInfo: i } = t;
s.forEach((a) => {
Promise.all([a.data(), o, i]).then((l) => {
this.logger.logKernelProfile(e, a, l[0], l[1], r, l[2]);
});
});
}
}
function h2(n, t, e) {
if (t !== "float32")
return !1;
for (let s = 0; s < n.length; s++) {
const o = n[s];
if (isNaN(o) || !isFinite(o))
return console.warn(`Found ${o} in the result of '${e}'`), !0;
}
return !1;
}
class p2 {
logKernelProfile(t, e, s, o, r, i) {
const a = typeof o == "number" ? xo(`${o}ms`, 9) : o.error, l = xo(t, 25), c = e.rank, u = e.size, d = xo(e.shape.toString(), 14);
let h = "";
for (const p in r) {
const f = r[p];
if (f != null) {
const m = f.shape || e.shape, g = m.length;
h += `${p}: ${g}D ${g > 0 ? m : ""} `;
}
}
console.log(`%c${l} %c${a} %c${c}D ${d} %c${u} %c${h} %c${i}`, "font-weight:bold", "color:red", "color:blue", "color: orange", "color: green", "color: steelblue");
}
}
/**
* @license
* Copyright 2017 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
function f2(n, t, e) {
const s = {}, o = {};
for (let l = 0; l < t.length; l++)
s[t[l].id] = !0;
for (let l = 0; l < n.length; l++) {
const c = n[l], u = c.inputs;
for (const d in u) {
const h = u[d];
let p = !1;
for (let f = 0; f < t.length; f++)
if (