mind-ar
Version:
web augmented reality framework
1,749 lines • 2.21 MB
JavaScript
import { c as Qs, g as yw, O as ww } from "./ui-56ede774.js";
function Iw(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 Cw = 1e-7, vw = 1e-4;
class Zg {
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 Zh {
refCount(t) {
return yn("refCount");
}
incRef(t) {
return yn("incRef");
}
timerAvailable() {
return !0;
}
time(t) {
return yn("time");
}
read(t) {
return yn("read");
}
readSync(t) {
return yn("readSync");
}
readToGPU(t, e) {
return yn("readToGPU");
}
numDataIds() {
return yn("numDataIds");
}
disposeData(t, e) {
return yn("disposeData");
}
write(t, e, s) {
return yn("write");
}
move(t, e, s, o, r) {
return yn("move");
}
memory() {
return yn("memory");
}
/** Returns the highest precision for floats in bits (e.g. 16 or 32) */
floatPrecision() {
return yn("floatPrecision");
}
/** Returns the smallest representable number. */
epsilon() {
return this.floatPrecision() === 32 ? Cw : vw;
}
dispose() {
return yn("dispose");
}
}
function yn(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 Kh(n) {
let t = n.length, e = 0;
for (; t > 0; )
e = Math.random() * t | 0, t--, cn(n, t, e);
}
function Sw(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--, cn(n, e, s), cn(t, e, s);
}
function Ks(n, t, e) {
return Math.max(n, Math.min(t, e));
}
function Ml(n) {
return n % 2 === 0 ? n : n + 1;
}
function cn(n, t, e) {
const s = n[t];
n[t] = n[e], n[e] = s;
}
function Kg(n) {
let t = 0;
for (let e = 0; e < n.length; e++)
t += n[e];
return t;
}
function kw(n, t) {
const e = Math.random();
return t * e + (1 - e) * n;
}
function Tw(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 S(n, t) {
if (!n)
throw new Error(typeof t == "string" ? t : t());
}
function Qe(n, t, e = "") {
S(At(n, t), () => e + ` Shapes ${n} and ${t} must match`);
}
function Dl(n) {
S(n != null, () => "The input to the tensor constructor must be a non-null value.");
}
function vo(n, t = [], e = !1) {
if (t == null && (t = []), Array.isArray(n) || Zn(n) && !e)
for (let s = 0; s < n.length; ++s)
vo(n[s], t, e);
else
t.push(n);
return t;
}
function H(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 Nw(n) {
return n.length === 0;
}
function At(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 So(n) {
return n % 1 === 0;
}
function $w(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 qa(n) {
const t = Math.ceil(Math.sqrt(n));
return [t, Math.ceil(n / t)];
}
function Rw(n) {
const t = new Uint32Array(n);
for (let e = 0; e < n; ++e)
t[e] = e;
return Kh(t), t;
}
function xo(n, t) {
return t <= n.length ? n : n + " ".repeat(t - n.length);
}
function Yu(n, t = (o) => 0, e, s = setTimeout) {
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(a, l);
};
a();
});
}
function Bh(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 Dt(n, t) {
const e = t.length;
return n = n == null ? t.map((s, o) => o) : [].concat(n), S(n.every((s) => s >= -e && s < e), () => `All values in axis param must be in range [-${e}, ${e}) but got axis ${n}`), S(n.every((s) => So(s)), () => `All values in axis param must be integers but got axis ${n}`), n.map((s) => s < 0 ? e + s : s);
}
function Gs(n, t) {
const e = [], s = [], o = t != null && Array.isArray(t) && t.length === 0, r = t == null || o ? null : Dt(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 he(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
throw new Error(`Unknown data type ${n}`);
return e;
}
function Ot(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 Bg(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 Hg(n) {
return n === "bool" || n === "complex64" || n === "float32" || n === "int32" || n === "string";
}
function Hh(n, t) {
return !(t === "complex64" || t === "float32" && n !== "complex64" || t === "int32" && n !== "float32" && n !== "complex64" || t === "bool" && n === "bool");
}
function Zn(n) {
return n instanceof Float32Array || n instanceof Int32Array || n instanceof Uint8Array || n instanceof Uint8ClampedArray;
}
function tl(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 _g(n) {
if (n == null)
return 0;
let t = 0;
return n.forEach((e) => t += e.length), t;
}
function br(n) {
return typeof n == "string" || n instanceof String;
}
function Ug(n) {
return typeof n == "boolean";
}
function el(n) {
return typeof n == "number";
}
function xr(n) {
return Array.isArray(n) ? xr(n[0]) : n instanceof Float32Array ? "float32" : n instanceof Int32Array || n instanceof Uint8Array || n instanceof Uint8ClampedArray ? "int32" : el(n) ? "float32" : br(n) ? "string" : Ug(n) ? "bool" : "float32";
}
function Bs(n) {
return !!(n && n.constructor && n.call && n.apply);
}
function nl(n, t) {
for (let e = t; e < n; ++e)
if (n % e === 0)
return e;
return n;
}
function gt(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 Yg(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] = Yg(n + l * a, i, e, s);
}
return o;
}
function On(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 Yg(0, n, t, e);
}
function Fl(n, t) {
const e = be(n, t);
for (let s = 0; s < e.length; s++)
e[s] = 1;
return e;
}
function be(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 _h(n, t) {
const e = n.reduce((s, o) => s * o, 1);
if (t == null || t === "float32")
return On(n, new Float32Array(e));
if (t === "int32")
return On(n, new Int32Array(e));
if (t === "bool")
return On(n, new Uint8Array(e));
throw new Error(`Unknown data type ${t}`);
}
function Uh(n) {
n.forEach((t) => {
S(Number.isInteger(t) && t >= 0, () => `Tensor must have a shape comprised of positive integers but got shape [${n}].`);
});
}
function pn(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 ys(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 zl(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 rm = "tfjsflags";
class Gw {
// tslint:disable-next-line: no-any
constructor(t) {
this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.getQueryParams = Lw, this.populateURLFlags();
}
setPlatform(t, e) {
this.platform != null && (B().getBool("IS_TEST") || B().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];
B().getBool("IS_TEST") || B().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 (zl(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);
}
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);
rm in t && t[rm].split(",").forEach((s) => {
const [o, r] = s.split(":");
this.urlFlags[o] = Ww(o, r);
});
}
}
function Lw(n) {
const t = {};
return n.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, (e, ...s) => (Ew(t, s[0], s[1]), s.join("="))), t;
}
function Ew(n, t, e) {
n[decodeURIComponent(t)] = decodeURIComponent(e || "");
}
function Ww(n, t) {
if (t = t.toLowerCase(), t === "true" || t === "false")
return t === "true";
if (`${+t}` === t)
return +t;
throw new Error(`Could not parse value flag value ${t} for flag ${n}.`);
}
function B() {
return jg;
}
let jg = null;
function Mw(n) {
jg = 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 wu;
function Qg() {
if (wu == 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");
wu = n;
}
return wu;
}
function Dw() {
const n = Qg();
return n._tfGlobals == null && (n._tfGlobals = /* @__PURE__ */ new Map()), n._tfGlobals;
}
function Yh(n, t) {
const e = Dw();
if (e.has(n))
return e.get(n);
{
const s = t();
return e.set(n, s), e.get(n);
}
}
const Vl = "Abs", ci = "Acos", ui = "Acosh", yr = "Add", jh = "AddN", Qh = "All", Jh = "Any", Pl = "ArgMax", Xl = "ArgMin", hi = "Asin", di = "Asinh", pi = "Atan", fi = "Atanh", mi = "Atan2", Ol = "AvgPool", qh = "AvgPoolGrad", Al = "AvgPool3D", td = "AvgPool3DGrad", Zl = "BatchMatMul", Kl = "BatchToSpaceND", ed = "Bincount", Fw = "BroadcastTo", Jg = "BroadcastArgs", gi = "Cast", bi = "Ceil", xi = "ClipByValue", nd = "Complex", Bl = "ComplexAbs", Hl = "Concat", _l = "Conv2D", sd = "Conv2DBackpropFilter", Ul = "Conv2DBackpropInput", Yl = "Conv3D", od = "Conv3DBackpropFilterV2", rd = "Conv3DBackpropInputV2", yi = "Cos", wi = "Cosh", id = "Cumprod", jl = "Cumsum", ad = "CropAndResize", qg = "DenseBincount", ld = "DepthToSpace", Ql = "DepthwiseConv2dNative", cd = "DepthwiseConv2dNativeBackpropFilter", ud = "DepthwiseConv2dNativeBackpropInput", tb = "Diag", Jl = "Dilation2D", ju = "Dilation2DBackpropInput", Qu = "Dilation2DBackpropFilter", Ii = "RealDiv", eb = "Einsum", Ci = "Elu", hd = "EluGrad", vi = "Erf", ql = "Equal", Si = "Exp", tc = "ExpandDims", ki = "Expm1", dd = "FFT", pd = "Fill", fd = "FlipLeftRight", Ti = "Floor", Ni = "FloorDiv", ec = "FusedBatchNorm", nc = "GatherV2", nb = "GatherNd", sc = "Greater", $i = "GreaterEqual", Ri = "Identity", md = "IFFT", gd = "Imag", Gi = "IsFinite", Li = "IsInf", Ei = "IsNan", oc = "LeakyRelu", rc = "Less", ic = "LessEqual", sb = "LinSpace", Wi = "Log", Mi = "Log1p", ac = "LogicalAnd", lc = "LogicalNot", cc = "LogicalOr", h4 = "LogicalXor", zw = "LogSoftmax", d4 = "LowerBound", uc = "LRN", bd = "LRNGrad", hc = "Max", Di = "Maximum", dc = "MaxPool", xd = "MaxPoolGrad", pc = "MaxPool3D", yd = "MaxPool3DGrad", ob = "MaxPoolWithArgmax", fc = "Mean", mc = "Min", Fi = "Minimum", gc = "MirrorPad", zi = "Mod", rb = "Multinomial", Vi = "Multiply", bc = "Neg", xc = "NotEqual", wd = "NonMaxSuppressionV3", Id = "NonMaxSuppressionV4", Cd = "NonMaxSuppressionV5", yc = "OnesLike", wc = "OneHot", Ic = "Pack", Cc = "PadV2", p4 = "Pool", Pi = "Pow", vc = "Prelu", Sc = "Prod", ib = "RaggedGather", ab = "RaggedTensorToTensor", vd = "Range", Sd = "Real", Xi = "Reciprocal", Oi = "Relu", kc = "Reshape", Tc = "ResizeNearestNeighbor", kd = "ResizeNearestNeighborGrad", Nc = "ResizeBilinear", Td = "ResizeBilinearGrad", Ai = "Relu6", $c = "Reverse", Zi = "Round", Ki = "Rsqrt", lb = "ScatterNd", cb = "SearchSorted", Rc = "Select", Bi = "Selu", Gc = "Slice", Hi = "Sin", _i = "Sinh", Ui = "Sign", Yi = "Sigmoid", ji = "Softplus", Qi = "Sqrt", Lc = "Sum", Ec = "SpaceToBatchND", Wc = "SplitV", Mc = "Softmax", Nd = "SparseFillEmptyRows", $d = "SparseReshape", Rd = "SparseSegmentMean", Gd = "SparseSegmentSum", ub = "SparseToDense", Ji = "SquaredDifference", Ld = "Square", Ed = "StridedSlice", Wd = "StringNGrams", Md = "StringSplit", Dd = "StringToHashBucketFast", qi = "Sub", ta = "Tan", ea = "Tanh", na = "Tile", Fd = "TopK", zd = "Transform", Jo = "Transpose", Vd = "Unique", Dc = "Unpack", Fc = "UnsortedSegmentSum", f4 = "UpperBound", zc = "ZerosLike", sa = "Step", Ju = "FromPixels", Pd = "RotateWithOffset", sl = "_FusedMatMul", ol = "FusedConv2D", hb = "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 wn(...n) {
B().getBool("IS_TEST") || B().getBool("PROD") || console.warn(...n);
}
function Vw(...n) {
B().getBool("IS_TEST") || B().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 or = Yh("kernelRegistry", () => /* @__PURE__ */ new Map()), jr = Yh("gradRegistry", () => /* @__PURE__ */ new Map());
function qu(n, t) {
const e = Xd(n, t);
return or.get(e);
}
function im(n) {
return jr.get(n);
}
function th(n) {
const t = or.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 bn(n) {
const { kernelName: t, backendName: e } = n, s = Xd(t, e);
or.has(s) && wn(`The kernel '${t}' for backend '${e}' is already registered`), or.set(s, n);
}
function Pw(n) {
const { kernelName: t } = n;
jr.has(t) && B().getBool("DEBUG") && wn(`Overriding the gradient for '${t}'`), jr.set(t, n);
}
function m4(n, t) {
const e = Xd(n, t);
if (!or.has(e))
throw new Error(`The kernel '${n}' for backend '${t}' is not registered`);
or.delete(e);
}
function g4(n) {
if (!jr.has(n))
throw new Error(`The gradient '${n}' for backend is not registered`);
jr.delete(n);
}
function b4(n, t) {
th(n).forEach((s) => {
const o = Object.assign({}, s, { backendName: t });
bn(o);
});
}
function Xd(n, t) {
return `${t}_${n}`;
}
var eh = re, Fn = null;
try {
Fn = 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 re(n, t, e) {
this.low = n | 0, this.high = t | 0, this.unsigned = !!e;
}
re.prototype.__isLong__;
Object.defineProperty(re.prototype, "__isLong__", { value: !0 });
function xn(n) {
return (n && n.__isLong__) === !0;
}
re.isLong = xn;
var am = {}, lm = {};
function Fo(n, t) {
var e, s, o;
return t ? (n >>>= 0, (o = 0 <= n && n < 256) && (s = lm[n], s) ? s : (e = ie(n, (n | 0) < 0 ? -1 : 0, !0), o && (lm[n] = e), e)) : (n |= 0, (o = -128 <= n && n < 128) && (s = am[n], s) ? s : (e = ie(n, n < 0 ? -1 : 0, !1), o && (am[n] = e), e));
}
re.fromInt = Fo;
function zn(n, t) {
if (isNaN(n))
return t ? mo : Vn;
if (t) {
if (n < 0)
return mo;
if (n >= db)
return mb;
} else {
if (n <= -um)
return hn;
if (n + 1 >= um)
return fb;
}
return n < 0 ? zn(-n, t).neg() : ie(n % rr | 0, n / rr | 0, t);
}
re.fromNumber = zn;
function ie(n, t, e) {
return new re(n, t, e);
}
re.fromBits = ie;
var rl = Math.pow;
function Od(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 Od(n.substring(1), t, e).neg();
for (var o = zn(rl(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 = zn(rl(e, a));
r = r.mul(c).add(zn(l));
} else
r = r.mul(o), r = r.add(zn(l));
}
return r.unsigned = t, r;
}
re.fromString = Od;
function as(n, t) {
return typeof n == "number" ? zn(n, t) : typeof n == "string" ? Od(n, t) : ie(n.low, n.high, typeof t == "boolean" ? t : n.unsigned);
}
re.fromValue = as;
var cm = 1 << 16, Xw = 1 << 24, rr = cm * cm, db = rr * rr, um = db / 2, hm = Fo(Xw), Vn = Fo(0);
re.ZERO = Vn;
var mo = Fo(0, !0);
re.UZERO = mo;
var Qo = Fo(1);
re.ONE = Qo;
var pb = Fo(1, !0);
re.UONE = pb;
var nh = Fo(-1);
re.NEG_ONE = nh;
var fb = ie(-1, 2147483647, !1);
re.MAX_VALUE = fb;
var mb = ie(-1, -1, !0);
re.MAX_UNSIGNED_VALUE = mb;
var hn = ie(0, -2147483648, !1);
re.MIN_VALUE = hn;
var ut = re.prototype;
ut.toInt = function() {
return this.unsigned ? this.low >>> 0 : this.low;
};
ut.toNumber = function() {
return this.unsigned ? (this.high >>> 0) * rr + (this.low >>> 0) : this.high * rr + (this.low >>> 0);
};
ut.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(hn)) {
var e = zn(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 = zn(rl(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;
}
};
ut.getHighBits = function() {
return this.high;
};
ut.getHighBitsUnsigned = function() {
return this.high >>> 0;
};
ut.getLowBits = function() {
return this.low;
};
ut.getLowBitsUnsigned = function() {
return this.low >>> 0;
};
ut.getNumBitsAbs = function() {
if (this.isNegative())
return this.eq(hn) ? 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;
};
ut.isZero = function() {
return this.high === 0 && this.low === 0;
};
ut.eqz = ut.isZero;
ut.isNegative = function() {
return !this.unsigned && this.high < 0;
};
ut.isPositive = function() {
return this.unsigned || this.high >= 0;
};
ut.isOdd = function() {
return (this.low & 1) === 1;
};
ut.isEven = function() {
return (this.low & 1) === 0;
};
ut.equals = function(t) {
return xn(t) || (t = as(t)), this.unsigned !== t.unsigned && this.high >>> 31 === 1 && t.high >>> 31 === 1 ? !1 : this.high === t.high && this.low === t.low;
};
ut.eq = ut.equals;
ut.notEquals = function(t) {
return !this.eq(
/* validates */
t
);
};
ut.neq = ut.notEquals;
ut.ne = ut.notEquals;
ut.lessThan = function(t) {
return this.comp(
/* validates */
t
) < 0;
};
ut.lt = ut.lessThan;
ut.lessThanOrEqual = function(t) {
return this.comp(
/* validates */
t
) <= 0;
};
ut.lte = ut.lessThanOrEqual;
ut.le = ut.lessThanOrEqual;
ut.greaterThan = function(t) {
return this.comp(
/* validates */
t
) > 0;
};
ut.gt = ut.greaterThan;
ut.greaterThanOrEqual = function(t) {
return this.comp(
/* validates */
t
) >= 0;
};
ut.gte = ut.greaterThanOrEqual;
ut.ge = ut.greaterThanOrEqual;
ut.compare = function(t) {
if (xn(t) || (t = as(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;
};
ut.comp = ut.compare;
ut.negate = function() {
return !this.unsigned && this.eq(hn) ? hn : this.not().add(Qo);
};
ut.neg = ut.negate;
ut.add = function(t) {
xn(t) || (t = as(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, h = 0, d = 0, p = 0;
return p += r + c, d += p >>> 16, p &= 65535, d += o + l, h += d >>> 16, d &= 65535, h += s + a, u += h >>> 16, h &= 65535, u += e + i, u &= 65535, ie(d << 16 | p, u << 16 | h, this.unsigned);
};
ut.subtract = function(t) {
return xn(t) || (t = as(t)), this.add(t.neg());
};
ut.sub = ut.subtract;
ut.multiply = function(t) {
if (this.isZero())
return Vn;
if (xn(t) || (t = as(t)), Fn) {
var e = Fn.mul(
this.low,
this.high,
t.low,
t.high
);
return ie(e, Fn.get_high(), this.unsigned);
}
if (t.isZero())
return Vn;
if (this.eq(hn))
return t.isOdd() ? hn : Vn;
if (t.eq(hn))
return this.isOdd() ? hn : 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(hm) && t.lt(hm))
return zn(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, h = 0, d = 0, p = 0, f = 0;
return f += i * u, p += f >>> 16, f &= 65535, p += r * u, d += p >>> 16, p &= 65535, p += i * c, d += p >>> 16, p &= 65535, d += o * u, h += d >>> 16, d &= 65535, d += r * c, h += d >>> 16, d &= 65535, d += i * l, h += d >>> 16, d &= 65535, h += s * u + o * c + r * l + i * a, h &= 65535, ie(p << 16 | f, h << 16 | d, this.unsigned);
};
ut.mul = ut.multiply;
ut.divide = function(t) {
if (xn(t) || (t = as(t)), t.isZero())
throw Error("division by zero");
if (Fn) {
if (!this.unsigned && this.high === -2147483648 && t.low === -1 && t.high === -1)
return this;
var e = (this.unsigned ? Fn.div_u : Fn.div_s)(
this.low,
this.high,
t.low,
t.high
);
return ie(e, Fn.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 pb;
r = mo;
} else {
if (this.eq(hn)) {
if (t.eq(Qo) || t.eq(nh))
return hn;
if (t.eq(hn))
return Qo;
var i = this.shr(1);
return s = i.div(t).shl(1), s.eq(Vn) ? t.isNegative() ? Qo : nh : (o = this.sub(t.mul(s)), r = s.add(o.div(t)), r);
} else if (t.eq(hn))
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 : rl(2, a - 48), c = zn(s), u = c.mul(t); u.isNegative() || u.gt(o); )
s -= l, c = zn(s, this.unsigned), u = c.mul(t);
c.isZero() && (c = Qo), r = r.add(c), o = o.sub(u);
}
return r;
};
ut.div = ut.divide;
ut.modulo = function(t) {
if (xn(t) || (t = as(t)), Fn) {
var e = (this.unsigned ? Fn.rem_u : Fn.rem_s)(
this.low,
this.high,
t.low,
t.high
);
return ie(e, Fn.get_high(), this.unsigned);
}
return this.sub(this.div(t).mul(t));
};
ut.mod = ut.modulo;
ut.rem = ut.modulo;
ut.not = function() {
return ie(~this.low, ~this.high, this.unsigned);
};
ut.and = function(t) {
return xn(t) || (t = as(t)), ie(this.low & t.low, this.high & t.high, this.unsigned);
};
ut.or = function(t) {
return xn(t) || (t = as(t)), ie(this.low | t.low, this.high | t.high, this.unsigned);
};
ut.xor = function(t) {
return xn(t) || (t = as(t)), ie(this.low ^ t.low, this.high ^ t.high, this.unsigned);
};
ut.shiftLeft = function(t) {
return xn(t) && (t = t.toInt()), (t &= 63) === 0 ? this : t < 32 ? ie(this.low << t, this.high << t | this.low >>> 32 - t, this.unsigned) : ie(0, this.low << t - 32, this.unsigned);
};
ut.shl = ut.shiftLeft;
ut.shiftRight = function(t) {
return xn(t) && (t = t.toInt()), (t &= 63) === 0 ? this : t < 32 ? ie(this.low >>> t | this.high << 32 - t, this.high >> t, this.unsigned) : ie(this.high >> t - 32, this.high >= 0 ? 0 : -1, this.unsigned);
};
ut.shr = ut.shiftRight;
ut.shiftRightUnsigned = function(t) {
if (xn(t) && (t = t.toInt()), t &= 63, t === 0)
return this;
var e = this.high;
if (t < 32) {
var s = this.low;
return ie(s >>> t | e << 32 - t, e >>> t, this.unsigned);
} else
return t === 32 ? ie(e, 0, this.unsigned) : ie(e >>> t - 32, 0, this.unsigned);
};
ut.shru = ut.shiftRightUnsigned;
ut.shr_u = ut.shiftRightUnsigned;
ut.toSigned = function() {
return this.unsigned ? ie(this.low, this.high, !1) : this;
};
ut.toUnsigned = function() {
return this.unsigned ? this : ie(this.low, this.high, !0);
};
ut.toBytes = function(t) {
return t ? this.toBytesLE() : this.toBytesBE();
};
ut.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
];
};
ut.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
];
};
re.fromBytes = function(t, e, s) {
return s ? re.fromBytesLE(t, e) : re.fromBytesBE(t, e);
};
re.fromBytesLE = function(t, e) {
return new re(
t[0] | t[1] << 8 | t[2] << 16 | t[3] << 24,
t[4] | t[5] << 8 | t[6] << 16 | t[7] << 24,
e
);
};
re.fromBytesBE = function(t, e) {
return new re(
t[4] << 24 | t[5] << 16 | t[6] << 8 | t[7],
t[0] << 24 | t[1] << 16 | t[2] << 8 | t[3],
e
);
};
const Ow = /* @__PURE__ */ Iw({
__proto__: null,
default: eh
}, [eh]);
/**
* @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 ho = (
// tslint:disable-next-line
eh || Ow
);
function oa(n) {
return ho.fromString(n, !0, 16);
}
const gb = oa("c3a5c85c97cb3127"), uo = oa("b492b66fbe98f273"), He = oa("9ae16a3b2f90404f");
function sh(n) {
return n.xor(n.shru(47));
}
function bb(n, t, e) {
const s = n.slice(t, t + e);
return ho.fromBytes(Array.from(s), !0, !0);
}
function te(n, t) {
return bb(n, t, 8);
}
function dm(n, t) {
return bb(n, t, 4);
}
function We(n, t) {
return t === 0 ? n : n.shru(t).or(n.shl(64 - t));
}
function Os(n, t, e = oa("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 Aw(n, t, e, s, o, r) {
o = o.add(n), r = We(r.add(o).add(s), 21);
const i = o;
return o = o.add(t), o = o.add(e), r = r.add(We(o, 44)), [o.add(s), r.add(i)];
}
function Wa(n, t, e, s) {
return Aw(te(n, t), te(n, t + 8), te(n, t + 16), te(n, t + 24), e, s);
}
function Zw(n, t = n.length) {
if (t >= 8) {
const e = He.add(t * 2), s = te(n, 0).add(He), o = te(n, t - 8), r = We(o, 37).mul(e).add(s), i = We(s, 25).add(o).mul(e);
return Os(r, i, e);
}
if (t >= 4) {
const e = He.add(t * 2), s = dm(n, 0);
return Os(s.shl(3).add(t), dm(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 sh(He.mul(r).xor(gb.mul(i))).mul(He);
}
return He;
}
function Kw(n, t = n.length) {
const e = He.add(t * 2), s = te(n, 0).mul(uo), o = te(n, 8), r = te(n, t - 8).mul(e), i = te(n, t - 16).mul(He);
return Os(We(s.add(o), 43).add(We(r, 30)).add(i), s.add(We(o.add(He), 18)).add(r), e);
}
function Bw(n, t = n.length) {
const e = He.add(t * 2), s = te(n, 0).mul(He), o = te(n, 8), r = te(n, t - 8).mul(e), i = te(n, t - 16).mul(He), a = We(s.add(o), 43).add(We(r, 30)).add(i), l = Os(a, s.add(We(o.add(He), 18)).add(r), e), c = te(n, 16).mul(e), u = te(n, 24), h = a.add(te(n, t - 32)).mul(e), d = l.add(te(n, t - 24)).mul(e);
return Os(We(c.add(u), 43).add(We(h, 30)).add(d), c.add(We(u.add(s), 18)).add(h), e);
}
function Ad(n, t = n.length) {
const e = ho.fromNumber(81, !0);
if (t <= 32)
return t <= 16 ? Zw(n, t) : Kw(n, t);
if (t <= 64)
return Bw(n, t);
let s = e, o = e.mul(uo).add(113), r = sh(o.mul(He).add(113)).mul(He), i = [ho.UZERO, ho.UZERO], a = [ho.UZERO, ho.UZERO];
s = s.mul(He).add(te(n, 0));
let l = 0;
const c = (t - 1 >> 6) * 64, u = c + (t - 1 & 63) - 63;
do
s = We(s.add(o).add(i[0]).add(te(n, l + 8)), 37).mul(uo), o = We(o.add(i[1]).add(te(n, l + 48)), 42).mul(uo), s = s.xor(a[1]), o = o.add(i[0]).add(te(n, l + 40)), r = We(r.add(a[0]), 33).mul(uo), i = Wa(n, l, i[1].mul(uo), s.add(a[0])), a = Wa(n, l + 32, r.add(a[1]), o.add(te(n, l + 16))), [r, s] = [s, r], l += 64;
while (l !== c);
const h = uo.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 = We(s.add(o).add(i[0]).add(te(n, l + 8)), 37).mul(h), o = We(o.add(i[1]).add(te(n, l + 48)), 42).mul(h), s = s.xor(a[1].mul(9)), o = o.add(i[0].mul(9).add(te(n, l + 40))), r = We(r.add(a[0]), 33).mul(h), i = Wa(n, l, i[1].mul(h), s.add(a[0])), a = Wa(n, l + 32, r.add(a[1]), o.add(te(n, l + 16))), [r, s] = [s, r], Os(Os(i[0], a[0], h).add(sh(o).mul(gb)).add(r), Os(i[1], a[1], h).add(s), h);
}
/**
* @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 ws(n, t) {
return t === "string" ? An(n) : Ls([n], t);
}
function Hw(n, t) {
return n instanceof Float32Array && t === "float32" || n instanceof Int32Array && t === "int32" || n instanceof Uint8Array && t === "bool";
}
function Ls(n, t) {
if (t === "string")
throw new Error("Cannot convert a string[] to a TypedArray");
if (Array.isArray(n) && (n = vo(n)), B().getBool("DEBUG") && Bg(n, t), Hw(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 Ve() {
return B().platform.now();
}
function _w(n, t) {
return B().platform.fetch(n, t);
}
function An(n, t = "utf-8") {
return t = t || "utf-8", B().platform.encode(n, t);
}
function Ss(n, t = "utf-8") {
return t = t || "utf-8", B().platform.decode(n, t);
}
const x4 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
__proto__: null,
arraysEqual: At,
assert: S,
assertNonNegativeIntegerDimensions: Uh,
assertNonNull: Dl,
assertShapesMatch: Qe,
bytesFromStringArray: _g,
bytesPerElement: tl,
checkConversionForErrors: Bg,
clamp: Ks,
computeStrides: gt,
createScalarValue: ws,
createShuffledIndices: Rw,
decodeString: Ss,
distSquared: Tw,
encodeString: An,
fetch: _w,
fingerPrint64: Ad,
flatten: vo,
getArrayFromDType: Ot,
getTypedArrayFromDType: he,
hasEncodingLoss: Hh,
hexToLong: oa,
indexToLoc: ys,
inferDtype: xr,
inferFromImplicitShape: Bh,
isBoolean: Ug,
isFunction: Bs,
isInt: So,
isNumber: el,
isPromise: zl,
isScalarShape: Nw,
isString: br,
isTypedArray: Zn,
isValidDtype: Hg,
locToIndex: pn,
makeOnesTypedArray: Fl,
makeZerosNestedTypedArray: _h,
makeZerosTypedArray: be,
nearestDivisor: nl,
nearestLargerEven: Ml,
now: Ve,
parseAxisParam: Dt,
randUniform: kw,
repeatedTry: Yu,
rightPad: xo,
shuffle: Kh,
shuffleCombo: Sw,
sizeFromShape: H,
sizeToSquarishShape: qa,
squeezeShape: Gs,
sum: Kg,
swap: cn,
tanh: $w,
toNestedArray: On,
toTypedArray: Ls
}, 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 Uw {
constructor(t, e) {
this.backendTimer = t, this.logger = e, e == null && (this.logger = new jw());
}
profileKernel(t, e, s) {
let o;
const r = () => {
o = s();
};
let i;
const a = Ve();
if (this.backendTimer.timerAvailable())
i = this.backendTimer.time(r);
else {
r();
for (const c of o)
c.dataSync();
i = Promise.resolve({ kernelMs: Ve() - a });
}
if (B().getBool("CHECK_COMPUTATION_FOR_ERRORS"))
for (let c = 0; c < o.length; c++) {
const u = o[c];
u.data().then((h) => {
Yw(h, 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 Yw(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 jw {
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, h = xo(e.shape.toString(), 14);
let d = "";
for (const p in r) {
const f = r[p];
if (f != null) {
const g = f.shape || e.shape, m = g.length;
d += `${p}: ${m}D ${m > 0 ? g : ""} `;
}
}
console.log(`%c${l} %c${a} %c${c}D ${h} %c${u} %c${d} %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 Qw(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 h in u) {
const d = u[h];
let p = !1;
for (let f = 0; f < t.length; f++)
if (s[d.id]) {
c.outputs.forEach((g) => s[g.id] = !0), p = !0, o[c.id] = !0;
break;
}
if (p)
break;
}
}
const r = {};
r[e.id] = !0;
const i = {};
for (let l = n.length - 1; l >= 0; l--) {
const c = n[l], u = c.inputs;
for (let h = 0; h < c.outputs.length; h++)
if (r[c.outputs[h].id]) {
for (const d in u)
r[u[d].id] = !0, i[c.id] = !0;
break;
}
}
const a = [];
for (let l = 0; l < n.length; l++) {
const c = n[l];
if (o[c.id] && i[c.id]) {
const u = {};
for (const d in c.inputs) {
const p = c.inputs[d];
s[p.id] && (u[d] = p);
}
const h = Object.assign({}, c);
h.inputs = u, h.outputs = c.outputs, a.push(h);
}
}
return a;
}
function Jw(n, t, e, s) {
for (let o = t.length - 1; o >= 0; o--) {
const r = t[o], i = [];
if (r.outputs.forEach((l) => {
const c = n[l.id];
c != null ? i.push(c) : i.push(null);
}), r.gradient == null)
throw new Error(`Cannot compute gradient: gradient function not found for ${r.kernelName}.`);
const a = r.gradient(i);
for (const l in r.inputs) {
if (!(l in a))
throw new Error(`Cannot backprop through input ${l}. Available gradients found: ${Object.keys(a)}.`);
const c = e(() => a[l]());
if (c.dtype !== "float32")
throw new Error(`Error in gradient for op ${r.kernelName}. The gradient of input ${l} must have 'float32' dtype, but has '${c.dtype}'`);
const u = r.inputs[l];
if (!At(c.shape, u.shape))
throw new Error(`Error in gradient for op ${r.kernelName}. The gradient of input '${l}' has shape '${c.shape}', which does not match the shape of the input '${u.shape}'`);
if (n[u.id] == null)
n[u.id] = c;
else {
const h = n[u.id];
n[u.id] = s(h, c), h.dispose();
}
}
}
}
/**
* @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.
* ===========================