bry-biometric-collector
Version:
BRy web-collector component for biometric capture.
1,444 lines • 493 kB
JavaScript
import { l as vu, L as Au, r as se } from "./___vite-browser-external_commonjs-proxy_be4e9a04_3.0.0.js";
import { bo as Xa, bp as hr } from "./main_379f7152_3.0.0.js";
import "./face_api_0e3ce8c8_3.0.0.js";
function gr(e, t) {
for (var n = 0; n < t.length; n++) {
const s = t[n];
if (typeof s != "string" && !Array.isArray(s)) {
for (const o in s)
if (o !== "default" && !(o in e)) {
const a = Object.getOwnPropertyDescriptor(s, o);
a && Object.defineProperty(e, o, a.get ? a : {
enumerable: !0,
get: () => s[o]
});
}
}
}
return Object.freeze(Object.defineProperty(e, 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 xu = 1e-7, Nu = 1e-4;
class Du {
constructor(t, n) {
this.backend = t, this.dataMover = n, 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, n) {
this.dataIdsCount++, this.data.set(t, n);
}
has(t) {
return this.data.has(t);
}
delete(t) {
return this.dataIdsCount--, this.data.delete(t);
}
numDataIds() {
return this.dataIdsCount;
}
}
class br {
refCount(t) {
return Mt("refCount");
}
incRef(t) {
return Mt("incRef");
}
timerAvailable() {
return !0;
}
time(t) {
return Mt("time");
}
read(t) {
return Mt("read");
}
readSync(t) {
return Mt("readSync");
}
readToGPU(t, n) {
return Mt("readToGPU");
}
numDataIds() {
return Mt("numDataIds");
}
disposeData(t, n) {
return Mt("disposeData");
}
write(t, n, s) {
return Mt("write");
}
move(t, n, s, o, a) {
return Mt("move");
}
createTensorFromGPUData(t, n, s) {
return Mt("createTensorFromGPUData");
}
memory() {
return Mt("memory");
}
/** Returns the highest precision for floats in bits (e.g. 16 or 32) */
floatPrecision() {
return Mt("floatPrecision");
}
/** Returns the smallest representable number. */
epsilon() {
return this.floatPrecision() === 32 ? xu : Nu;
}
dispose() {
return Mt("dispose");
}
}
function Mt(e) {
throw new Error(`'${e}' 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 R(e, t) {
if (!e)
throw new Error(typeof t == "string" ? t : t());
}
function Eu(e, t, n = "") {
R(_a(e, t), () => n + ` Shapes ${e} and ${t} must match`);
}
function D(e) {
if (e.length === 0)
return 1;
let t = e[0];
for (let n = 1; n < e.length; n++)
t *= e[n];
return t;
}
function _a(e, t) {
if (e === t)
return !0;
if (e == null || t == null || e.length !== t.length)
return !1;
for (let n = 0; n < e.length; n++)
if (e[n] !== t[n])
return !1;
return !0;
}
function Fu(e) {
return e % 1 === 0;
}
function Nn(e, t) {
return t <= e.length ? e : e + " ".repeat(t - e.length);
}
function Cu(e, t) {
let n = 1, s = -1;
for (let a = 0; a < e.length; ++a)
if (e[a] >= 0)
n *= e[a];
else if (e[a] === -1) {
if (s !== -1)
throw Error(`Shapes can only have 1 implicit size. Found -1 at dim ${s} and dim ${a}`);
s = a;
} else if (e[a] < 0)
throw Error(`Shapes can not be < 0. Found ${e[a]} at dim ${a}`);
if (s === -1) {
if (t > 0 && t !== n)
throw Error(`Size(${t}) must match the product of shape ${e}`);
return e;
}
if (n === 0)
throw Error(`Cannot infer the missing size in [${e}] when there are 0 elements`);
if (t % n !== 0)
throw Error(`The implicit shape can't be a fractional number. Got ${t} / ${n}`);
const o = e.slice();
return o[s] = t / n, o;
}
function Te(e, t) {
const n = t.length;
return e = e == null ? t.map((s, o) => o) : [].concat(e), R(e.every((s) => s >= -n && s < n), () => `All values in axis param must be in range [-${n}, ${n}) but got axis ${e}`), R(e.every((s) => Fu(s)), () => `All values in axis param must be integers but got axis ${e}`), e.map((s) => s < 0 ? n + s : s);
}
function Ze(e, t) {
let n = null;
if (e == null || e === "float32")
n = new Float32Array(t);
else if (e === "int32")
n = new Int32Array(t);
else if (e === "bool")
n = new Uint8Array(t);
else if (e === "string")
n = new Array(t);
else
throw new Error(`Unknown data type ${e}`);
return n;
}
function Ru(e, t) {
for (let n = 0; n < e.length; n++) {
const s = e[n];
if (isNaN(s) || !isFinite(s))
throw Error(`A tensor of type ${t} being uploaded contains ${s}.`);
}
}
function Tu(e) {
return e === "bool" || e === "complex64" || e === "float32" || e === "int32" || e === "string";
}
function Xe(e) {
if (e === "float32" || e === "int32")
return 4;
if (e === "complex64")
return 8;
if (e === "bool")
return 1;
throw new Error(`Unknown dtype ${e}`);
}
function Bu(e) {
if (e == null)
return 0;
let t = 0;
return e.forEach((n) => t += n.length), t;
}
function ka(e) {
return typeof e == "string" || e instanceof String;
}
function Pu(e) {
return typeof e == "boolean";
}
function $u(e) {
return typeof e == "number";
}
function tn(e) {
return Array.isArray(e) ? tn(e[0]) : e instanceof Float32Array ? "float32" : e instanceof Int32Array || e instanceof Uint8Array || e instanceof Uint8ClampedArray ? "int32" : $u(e) ? "float32" : ka(e) ? "string" : Pu(e) ? "bool" : "float32";
}
function na(e) {
return !!(e && e.constructor && e.call && e.apply);
}
function mt(e) {
const t = e.length;
if (t < 2)
return [];
const n = new Array(t - 1);
n[t - 2] = e[t - 1];
for (let s = t - 3; s >= 0; --s)
n[s] = n[s + 1] * e[s + 1];
return n;
}
function yr(e, t, n, s = !1) {
const o = new Array();
if (t.length === 1) {
const a = t[0] * (s ? 2 : 1);
for (let i = 0; i < a; i++)
o[i] = n[e + i];
} else {
const a = t[0], i = t.slice(1), c = i.reduce((l, u) => l * u) * (s ? 2 : 1);
for (let l = 0; l < a; l++)
o[l] = yr(e + l * c, i, n, s);
}
return o;
}
function Ja(e, t, n = !1) {
if (e.length === 0)
return t[0];
const s = e.reduce((o, a) => o * a) * (n ? 2 : 1);
if (s === 0)
return [];
if (s !== t.length)
throw new Error(`[${e}] does not match the input size ${t.length}${n ? " for a complex tensor" : ""}.`);
return yr(0, e, t, n);
}
function Ou(e, t) {
const n = Fn(e, t);
for (let s = 0; s < n.length; s++)
n[s] = 1;
return n;
}
function Fn(e, t) {
if (t == null || t === "float32" || t === "complex64")
return new Float32Array(e);
if (t === "int32")
return new Int32Array(e);
if (t === "bool")
return new Uint8Array(e);
throw new Error(`Unknown data type ${t}`);
}
function Sa(e) {
e.forEach((t) => {
R(Number.isInteger(t) && t >= 0, () => `Tensor must have a shape comprised of positive integers but got shape [${e}].`);
});
}
function Ma(e) {
return e && e.then && typeof e.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 Qa = "tfjsflags";
class Wu {
// tslint:disable-next-line: no-any
constructor(t) {
this.global = t, this.flags = {}, this.flagRegistry = {}, this.urlFlags = {}, this.getQueryParams = Lu, this.populateURLFlags();
}
setPlatform(t, n) {
this.platform != null && (X().getBool("IS_TEST") || X().getBool("PROD") || console.warn(`Platform ${this.platformName} has already been set. Overwriting the platform with ${t}.`)), this.platformName = t, this.platform = n;
}
registerFlag(t, n, s) {
if (this.flagRegistry[t] = { evaluationFn: n, setHook: s }, this.urlFlags[t] != null) {
const o = this.urlFlags[t];
X().getBool("IS_TEST") || X().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 n = this.evaluateFlag(t);
if (Ma(n))
throw new Error(`Flag ${t} cannot be synchronously evaluated. Please use getAsync() instead.`);
return this.flags[t] = n, 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, n) {
if (this.flagRegistry[t] == null)
throw new Error(`Cannot set flag ${t} as it has not been registered.`);
this.flags[t] = n, this.flagRegistry[t].setHook != null && this.flagRegistry[t].setHook(n);
}
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);
Qa in t && t[Qa].split(",").forEach((s) => {
const [o, a] = s.split(":");
this.urlFlags[o] = Hu(o, a);
});
}
}
function Lu(e) {
const t = {};
return e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, (n, ...s) => (Gu(t, s[0], s[1]), s.join("="))), t;
}
function Gu(e, t, n) {
e[decodeURIComponent(t)] = decodeURIComponent(n || "");
}
function Hu(e, t) {
const n = t.toLowerCase();
return n === "true" || n === "false" ? n === "true" : `${+n}` === n ? +n : t;
}
function X() {
return wr;
}
let wr = null;
function Uu(e) {
wr = e;
}
/**
* @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 Qn;
function Ir() {
if (Qn == null) {
let e;
if (typeof window < "u")
e = window;
else if (typeof global < "u")
e = global;
else if (typeof process < "u")
e = process;
else if (typeof self < "u")
e = self;
else
throw new Error("Could not find a global object");
Qn = e;
}
return Qn;
}
function zu() {
const e = Ir();
return e._tfGlobals == null && (e._tfGlobals = /* @__PURE__ */ new Map()), e._tfGlobals;
}
function va(e, t) {
const n = zu();
if (n.has(e))
return n.get(e);
{
const s = t();
return n.set(e, s), n.get(e);
}
}
const _r = "Abs", Vu = "Acos", ju = "Acosh", Aa = "Add", kr = "AddN", Sr = "All", Mr = "Any", qu = "ArgMax", Ku = "ArgMin", Xu = "Asin", Ju = "Asinh", Qu = "Atan", Yu = "Atanh", Zu = "Atan2", vr = "AvgPool", tc = "AvgPoolGrad", ec = "AvgPool3D", nc = "AvgPool3DGrad", Ar = "BatchMatMul", ac = "BatchToSpaceND", xr = "Bincount", rc = "BitwiseAnd", sc = "BroadcastArgs", xa = "Cast", oc = "Ceil", Nr = "ClipByValue", ic = "ComplexAbs", uc = "Concat", Dr = "Conv2D", Er = "Conv2DBackpropInput", Fr = "Conv3D", Cr = "Conv3DBackpropFilterV2", Rr = "Conv3DBackpropInputV2", cc = "Cos", lc = "Cosh", Tr = "Cumprod", Br = "Cumsum", Pr = "CropAndResize", dc = "DenseBincount", $r = "DepthToSpace", Or = "DepthwiseConv2dNative", pc = "Diag", Wr = "Dilation2D", Lr = "Dilation2DBackpropInput", Gr = "Dilation2DBackpropFilter", Hr = "RealDiv", mc = "Elu", Ur = "EluGrad", fc = "Erf", hc = "Equal", gc = "Exp", bc = "ExpandDims", yc = "Expm1", zr = "Fill", Vr = "FlipLeftRight", wc = "Floor", jr = "FloorDiv", qr = "FusedBatchNorm", Ic = "GatherV2", Kr = "GatherNd", _c = "Greater", kc = "GreaterEqual", Na = "Identity", Sc = "IsFinite", Mc = "IsInf", vc = "IsNan", Xr = "LeakyRelu", Ac = "Less", xc = "LessEqual", Jr = "LinSpace", Nc = "Log", Dc = "Log1p", Ec = "LogicalAnd", Fc = "LogicalNot", Cc = "LogicalOr", Rc = "LogicalXor", Qr = "LRN", Yr = "LRNGrad", Zr = "Max", ts = "Maximum", es = "MaxPool", Tc = "MaxPoolGrad", Bc = "MaxPool3D", Pc = "MaxPool3DGrad", $c = "MaxPoolWithArgmax", ns = "Mean", as = "Min", Oc = "Minimum", rs = "MirrorPad", Wc = "Mod", ss = "Multinomial", os = "Multiply", Lc = "Neg", Gc = "NotEqual", is = "NonMaxSuppressionV3", us = "NonMaxSuppressionV4", cs = "NonMaxSuppressionV5", Hc = "OnesLike", ls = "OneHot", Uc = "Pack", ds = "PadV2", ps = "Pow", ms = "Prelu", fs = "Prod", zc = "Range", Vc = "Reciprocal", jc = "Relu", qc = "Reshape", hs = "ResizeNearestNeighbor", gs = "ResizeNearestNeighborGrad", bs = "ResizeBilinear", ys = "ResizeBilinearGrad", Kc = "Relu6", ws = "Reverse", Xc = "Round", Jc = "Rsqrt", Is = "ScatterNd", _s = "TensorScatterUpdate", ks = "SearchSorted", Qc = "Select", Yc = "Selu", Zc = "Slice", tl = "Sin", el = "Sinh", nl = "Sign", al = "Sigmoid", rl = "Softplus", Ss = "Sqrt", Ms = "Sum", sl = "SpaceToBatchND", ol = "SplitV", vs = "Softmax", il = "SparseFillEmptyRows", As = "SparseReshape", ul = "SparseSegmentMean", cl = "SparseSegmentSum", xs = "SparseToDense", ll = "SquaredDifference", dl = "Square", Ns = "StridedSlice", pl = "StringNGrams", ml = "StringSplit", fl = "StringToHashBucketFast", Ds = "Sub", hl = "Tan", gl = "Tanh", Es = "Tile", Fs = "TopK", Cs = "Transform", Rs = "Transpose", bl = "Unique", yl = "Unpack", Ts = "ZerosLike", Bs = "Step", Ps = "RotateWithOffset", $s = "_FusedMatMul", Os = "FusedConv2D", Ws = "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 Ae(...e) {
X().getBool("IS_TEST") || X().getBool("PROD") || console.warn(...e);
}
/**
* @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 Cn = va("kernelRegistry", () => /* @__PURE__ */ new Map()), wl = va("gradRegistry", () => /* @__PURE__ */ new Map());
function Ya(e, t) {
const n = Ls(e, t);
return Cn.get(n);
}
function Za(e) {
return wl.get(e);
}
function tr(e) {
const t = Cn.entries(), n = [];
for (; ; ) {
const { done: s, value: o } = t.next();
if (s)
break;
const [a, i] = o, [c] = a.split("_");
c === e && n.push(i);
}
return n;
}
function Il(e) {
const { kernelName: t, backendName: n } = e, s = Ls(t, n);
Cn.has(s) && Ae(`The kernel '${t}' for backend '${n}' is already registered`), Cn.set(s, e);
}
function Ls(e, t) {
return `${t}_${e}`;
}
/**
* @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 Gs(e) {
return e instanceof Float32Array || e instanceof Int32Array || e instanceof Uint8Array || e instanceof Uint8ClampedArray;
}
/**
* @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 oe = (
// tslint:disable-next-line
vu || Au
);
function Bn(e) {
return oe.fromString(e, !0, 16);
}
const Hs = Bn("c3a5c85c97cb3127"), re = Bn("b492b66fbe98f273"), bt = Bn("9ae16a3b2f90404f");
function aa(e) {
return e.xor(e.shru(47));
}
function Us(e, t, n) {
const s = e.slice(t, t + n);
return oe.fromBytes(Array.from(s), !0, !0);
}
function tt(e, t) {
return Us(e, t, 8);
}
function er(e, t) {
return Us(e, t, 4);
}
function lt(e, t) {
return t === 0 ? e : e.shru(t).or(e.shl(64 - t));
}
function Kt(e, t, n = Bn("9ddfea08eb382d69")) {
let s = e.xor(t).mul(n);
s = s.xor(s.shru(47));
let o = t.xor(s).mul(n);
return o = o.xor(o.shru(47)), o = o.mul(n), o;
}
function _l(e, t, n, s, o, a) {
o = o.add(e), a = lt(a.add(o).add(s), 21);
const i = o;
return o = o.add(t), o = o.add(n), a = a.add(lt(o, 44)), [o.add(s), a.add(i)];
}
function xn(e, t, n, s) {
return _l(tt(e, t), tt(e, t + 8), tt(e, t + 16), tt(e, t + 24), n, s);
}
function kl(e, t = e.length) {
if (t >= 8) {
const n = bt.add(t * 2), s = tt(e, 0).add(bt), o = tt(e, t - 8), a = lt(o, 37).mul(n).add(s), i = lt(s, 25).add(o).mul(n);
return Kt(a, i, n);
}
if (t >= 4) {
const n = bt.add(t * 2), s = er(e, 0);
return Kt(s.shl(3).add(t), er(e, t - 4), n);
}
if (t > 0) {
const n = e[0], s = e[t >> 1], o = e[t - 1], a = n + (s << 8), i = t + (o << 2);
return aa(bt.mul(a).xor(Hs.mul(i))).mul(bt);
}
return bt;
}
function Sl(e, t = e.length) {
const n = bt.add(t * 2), s = tt(e, 0).mul(re), o = tt(e, 8), a = tt(e, t - 8).mul(n), i = tt(e, t - 16).mul(bt);
return Kt(lt(s.add(o), 43).add(lt(a, 30)).add(i), s.add(lt(o.add(bt), 18)).add(a), n);
}
function Ml(e, t = e.length) {
const n = bt.add(t * 2), s = tt(e, 0).mul(bt), o = tt(e, 8), a = tt(e, t - 8).mul(n), i = tt(e, t - 16).mul(bt), c = lt(s.add(o), 43).add(lt(a, 30)).add(i), l = Kt(c, s.add(lt(o.add(bt), 18)).add(a), n), u = tt(e, 16).mul(n), r = tt(e, 24), d = c.add(tt(e, t - 32)).mul(n), p = l.add(tt(e, t - 24)).mul(n);
return Kt(lt(u.add(r), 43).add(lt(d, 30)).add(p), u.add(lt(r.add(s), 18)).add(d), n);
}
function vl(e, t = e.length) {
const n = oe.fromNumber(81, !0);
if (t <= 32)
return t <= 16 ? kl(e, t) : Sl(e, t);
if (t <= 64)
return Ml(e, t);
let s = n, o = n.mul(re).add(113), a = aa(o.mul(bt).add(113)).mul(bt), i = [oe.UZERO, oe.UZERO], c = [oe.UZERO, oe.UZERO];
s = s.mul(bt).add(tt(e, 0));
let l = 0;
const u = (t - 1 >> 6) * 64, r = u + (t - 1 & 63) - 63;
do
s = lt(s.add(o).add(i[0]).add(tt(e, l + 8)), 37).mul(re), o = lt(o.add(i[1]).add(tt(e, l + 48)), 42).mul(re), s = s.xor(c[1]), o = o.add(i[0]).add(tt(e, l + 40)), a = lt(a.add(c[0]), 33).mul(re), i = xn(e, l, i[1].mul(re), s.add(c[0])), c = xn(e, l + 32, a.add(c[1]), o.add(tt(e, l + 16))), [a, s] = [s, a], l += 64;
while (l !== u);
const d = re.add(a.and(255).shl(1));
return l = r, c[0] = c[0].add(t - 1 & 63), i[0] = i[0].add(c[0]), c[0] = c[0].add(i[0]), s = lt(s.add(o).add(i[0]).add(tt(e, l + 8)), 37).mul(d), o = lt(o.add(i[1]).add(tt(e, l + 48)), 42).mul(d), s = s.xor(c[1].mul(9)), o = o.add(i[0].mul(9).add(tt(e, l + 40))), a = lt(a.add(c[0]), 33).mul(d), i = xn(e, l, i[1].mul(d), s.add(c[0])), c = xn(e, l + 32, a.add(c[1]), o.add(tt(e, l + 16))), [a, s] = [s, a], Kt(Kt(i[0], c[0], d).add(aa(o).mul(Hs)).add(a), Kt(i[1], c[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 Al(e, t) {
return e instanceof Float32Array && t === "float32" || e instanceof Int32Array && t === "int32" || e instanceof Uint8Array && t === "bool";
}
function zs(e, t) {
if (t === "string")
throw new Error("Cannot convert a string[] to a TypedArray");
if (Array.isArray(e) && (e = Je(e)), X().getBool("DEBUG") && Ru(e, t), Al(e, t))
return e;
if (t == null || t === "float32" || t === "complex64")
return new Float32Array(e);
if (t === "int32")
return new Int32Array(e);
if (t === "bool") {
const n = new Uint8Array(e.length);
for (let s = 0; s < n.length; ++s)
Math.round(e[s]) !== 0 && (n[s] = 1);
return n;
} else
throw new Error(`Unknown data type ${t}`);
}
function Fe() {
return X().platform.now();
}
function xl(e, t) {
return X().platform.fetch(e, t);
}
function qe(e, t = "utf-8") {
return t = t || "utf-8", X().platform.encode(e, t);
}
function ra(e, t = "utf-8") {
return t = t || "utf-8", X().platform.decode(e, t);
}
function Et(e) {
return X().platform.isTypedArray != null ? X().platform.isTypedArray(e) : Gs(e);
}
function Je(e, t = [], n = !1) {
if (t == null && (t = []), typeof e == "boolean" || typeof e == "number" || typeof e == "string" || Ma(e) || e == null || Et(e) && n)
t.push(e);
else if (Array.isArray(e) || Et(e))
for (let s = 0; s < e.length; ++s)
Je(e[s], t, n);
else {
let s = -1;
for (const o of Object.keys(e))
/^([1-9]+[0-9]*|0)$/.test(o) && (s = Math.max(s, Number(o)));
for (let o = 0; o <= s; o++)
Je(e[o], t, n);
}
return t;
}
/**
* @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 Nl {
constructor(t, n) {
this.backendTimer = t, this.logger = n, n == null && (this.logger = new El());
}
profileKernel(t, n, s) {
let o;
const a = () => {
o = s();
};
let i;
const c = Fe();
if (this.backendTimer.timerAvailable())
i = this.backendTimer.time(a);
else {
a();
for (const u of o)
u.dataSync();
i = Promise.resolve({ kernelMs: Fe() - c });
}
if (X().getBool("CHECK_COMPUTATION_FOR_ERRORS"))
for (let u = 0; u < o.length; u++) {
const r = o[u];
r.data().then((d) => {
Dl(d, r.dtype, t);
});
}
return {
kernelName: t,
outputs: o,
inputs: n,
timeMs: i.then((u) => u.kernelMs),
extraInfo: i.then((u) => u.getExtraProfileInfo != null ? u.getExtraProfileInfo() : "")
};
}
logKernelProfile(t) {
const { kernelName: n, outputs: s, timeMs: o, inputs: a, extraInfo: i } = t;
s.forEach((c) => {
Promise.all([c.data(), o, i]).then((l) => {
this.logger.logKernelProfile(n, c, l[0], l[1], a, l[2]);
});
});
}
}
function Dl(e, t, n) {
if (t !== "float32")
return !1;
for (let s = 0; s < e.length; s++) {
const o = e[s];
if (isNaN(o) || !isFinite(o))
return console.warn(`Found ${o} in the result of '${n}'`), !0;
}
return !1;
}
class El {
logKernelProfile(t, n, s, o, a, i) {
const c = typeof o == "number" ? Nn(`${o}ms`, 9) : o.error, l = Nn(t, 25), u = n.rank, r = n.size, d = Nn(n.shape.toString(), 14);
let p = "";
for (const m in a) {
const f = a[m];
if (f != null) {
const g = f.shape || n.shape, y = g.length;
p += `${m}: ${y}D ${y > 0 ? g : ""} `;
}
}
console.log(`%c${l} %c${c} %c${u}D ${d} %c${r} %c${p} %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 Fl(e, t, n) {
const s = {}, o = {};
for (let l = 0; l < t.length; l++)
s[t[l].id] = !0;
for (let l = 0; l < e.length; l++) {
const u = e[l], r = u.inputs;
for (const d in r) {
const p = r[d];
let m = !1;
for (let f = 0; f < t.length; f++)
if (s[p.id]) {
u.outputs.forEach((g) => s[g.id] = !0), m = !0, o[u.id] = !0;
break;
}
if (m)
break;
}
}
const a = {};
a[n.id] = !0;
const i = {};
for (let l = e.length - 1; l >= 0; l--) {
const u = e[l], r = u.inputs;
for (let d = 0; d < u.outputs.length; d++)
if (a[u.outputs[d].id]) {
for (const p in r)
a[r[p].id] = !0, i[u.id] = !0;
break;
}
}
const c = [];
for (let l = 0; l < e.length; l++) {
const u = e[l];
if (o[u.id] && i[u.id]) {
const r = {};
for (const p in u.inputs) {
const m = u.inputs[p];
s[m.id] && (r[p] = m);
}
const d = Object.assign({}, u);
d.inputs = r, d.outputs = u.outputs, c.push(d);
}
}
return c;
}
function Cl(e, t, n, s) {
for (let o = t.length - 1; o >= 0; o--) {
const a = t[o], i = [];
if (a.outputs.forEach((l) => {
const u = e[l.id];
u != null ? i.push(u) : i.push(null);
}), a.gradient == null)
throw new Error(`Cannot compute gradient: gradient function not found for ${a.kernelName}.`);
const c = a.gradient(i);
for (const l in a.inputs) {
if (!(l in c))
throw new Error(`Cannot backprop through input ${l}. Available gradients found: ${Object.keys(c)}.`);
const u = n(() => c[l]());
if (u.dtype !== "float32")
throw new Error(`Error in gradient for op ${a.kernelName}. The gradient of input ${l} must have 'float32' dtype, but has '${u.dtype}'`);
const r = a.inputs[l];
if (!_a(u.shape, r.shape))
throw new Error(`Error in gradient for op ${a.kernelName}. The gradient of input '${l}' has shape '${u.shape}', which does not match the shape of the input '${r.shape}'`);
if (e[r.id] == null)
e[r.id] = u;
else {
const d = e[r.id];
e[r.id] = s(d, u), d.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.
* =============================================================================
*/
const nr = 20, Ue = 3, Yn = 7;
function Rl(e, t, n, s) {
const o = mt(t), a = Tl(e, t, n, o), i = t.length, c = Dn(e, t, n, o, a), l = ["Tensor"];
return s && (l.push(` dtype: ${n}`), l.push(` rank: ${i}`), l.push(` shape: [${t}]`), l.push(" values:")), l.push(c.map((u) => " " + u).join(`
`)), l.join(`
`);
}
function Tl(e, t, n, s) {
const o = D(t), a = s[s.length - 1], i = new Array(a).fill(0), c = t.length, l = n === "complex64" ? Ve(e) : e;
if (c > 1)
for (let u = 0; u < o / a; u++) {
const r = u * a;
for (let d = 0; d < a; d++)
i[d] = Math.max(i[d], ze(l[r + d], 0, n).length);
}
return i;
}
function ze(e, t, n) {
let s;
return Array.isArray(e) ? s = `${parseFloat(e[0].toFixed(Yn))} + ${parseFloat(e[1].toFixed(Yn))}j` : ka(e) ? s = `'${e}'` : n === "bool" ? s = Vs(e) : s = parseFloat(e.toFixed(Yn)).toString(), Nn(s, t);
}
function Vs(e) {
return e === 0 ? "false" : "true";
}
function Dn(e, t, n, s, o, a = !0) {
const i = n === "complex64" ? 2 : 1, c = t[0], l = t.length;
if (l === 0) {
if (n === "complex64") {
const g = Ve(e);
return [ze(g[0], 0, n)];
}
return n === "bool" ? [Vs(e[0])] : [e[0].toString()];
}
if (l === 1) {
if (c > nr) {
const y = Ue * i;
let I = Array.from(e.slice(0, y)), w = Array.from(e.slice((c - Ue) * i, c * i));
return n === "complex64" && (I = Ve(I), w = Ve(w)), [
"[" + I.map((b, S) => ze(b, o[S], n)).join(", ") + ", ..., " + w.map((b, S) => ze(b, o[c - Ue + S], n)).join(", ") + "]"
];
}
return [
"[" + (n === "complex64" ? Ve(e) : Array.from(e)).map((y, I) => ze(y, o[I], n)).join(", ") + "]"
];
}
const u = t.slice(1), r = s.slice(1), d = s[0] * i, p = [];
if (c > nr) {
for (let g = 0; g < Ue; g++) {
const y = g * d, I = y + d;
p.push(...Dn(
e.slice(y, I),
u,
n,
r,
o,
!1
/* isLast */
));
}
p.push("...");
for (let g = c - Ue; g < c; g++) {
const y = g * d, I = y + d;
p.push(...Dn(
e.slice(y, I),
u,
n,
r,
o,
g === c - 1
/* isLast */
));
}
} else
for (let g = 0; g < c; g++) {
const y = g * d, I = y + d;
p.push(...Dn(
e.slice(y, I),
u,
n,
r,
o,
g === c - 1
/* isLast */
));
}
const m = l === 2 ? "," : "";
p[0] = "[" + (c > 0 ? p[0] + m : "");
for (let g = 1; g < p.length - 1; g++)
p[g] = " " + p[g] + m;
let f = `,
`;
for (let g = 2; g < l; g++)
f += `
`;
return p[p.length - 1] = " " + p[p.length - 1] + "]" + (a ? "" : f), p;
}
function Ve(e) {
const t = [];
for (let n = 0; n < e.length; n += 2)
t.push([e[n], e[n + 1]]);
return t;
}
/**
* @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.
* =============================================================================
*/
class sa {
constructor(t, n, s) {
if (this.dtype = n, this.shape = t.slice(), this.size = D(t), s != null) {
const o = s.length;
R(o === this.size, () => `Length of values '${o}' does not match the size inferred by the shape '${this.size}'.`);
}
if (n === "complex64")
throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");
this.values = s || Ze(n, this.size), this.strides = mt(t);
}
/**
* Sets a value in the buffer at a given location.
*
* @param value The value to set.
* @param locs The location indices.
*
* @doc {heading: 'Tensors', subheading: 'Creation'}
*/
set(t, ...n) {
n.length === 0 && (n = [0]), R(n.length === this.rank, () => `The number of provided coordinates (${n.length}) must match the rank (${this.rank})`);
const s = this.locToIndex(n);
this.values[s] = t;
}
/**
* Returns the value in the buffer at the provided location.
*
* @param locs The location indices.
*
* @doc {heading: 'Tensors', subheading: 'Creation'}
*/
get(...t) {
t.length === 0 && (t = [0]);
let n = 0;
for (const o of t) {
if (o < 0 || o >= this.shape[n]) {
const a = `Requested out of range element at ${t}. Buffer shape=${this.shape}`;
throw new Error(a);
}
n++;
}
let s = t[t.length - 1];
for (let o = 0; o < t.length - 1; ++o)
s += this.strides[o] * t[o];
return this.values[s];
}
locToIndex(t) {
if (this.rank === 0)
return 0;
if (this.rank === 1)
return t[0];
let n = t[t.length - 1];
for (let s = 0; s < t.length - 1; ++s)
n += this.strides[s] * t[s];
return n;
}
indexToLoc(t) {
if (this.rank === 0)
return [];
if (this.rank === 1)
return [t];
const n = new Array(this.shape.length);
for (let s = 0; s < n.length - 1; ++s)
n[s] = Math.floor(t / this.strides[s]), t -= n[s] * this.strides[s];
return n[n.length - 1] = t, n;
}
get rank() {
return this.shape.length;
}
/**
* Creates an immutable `tf.Tensor` object from the buffer.
*
* @doc {heading: 'Tensors', subheading: 'Creation'}
*/
toTensor() {
return Ct().makeTensor(this.values, this.shape, this.dtype);
}
}
let Ct = null, xe = null;
function Bl(e) {
Ct = e;
}
function Pl(e) {
xe = e;
}
class Rt {
constructor(t, n, s, o) {
this.kept = !1, this.isDisposedInternal = !1, this.shape = t.slice(), this.dtype = n || "float32", this.size = D(t), this.strides = mt(t), this.dataId = s, this.id = o, this.rankType = this.rank < 5 ? this.rank.toString() : "higher";
}
get rank() {
return this.shape.length;
}
/**
* Returns a promise of `tf.TensorBuffer` that holds the underlying data.
*
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
async buffer() {
const t = await this.data();
return xe.buffer(this.shape, this.dtype, t);
}
/**
* Returns a `tf.TensorBuffer` that holds the underlying data.
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
bufferSync() {
return xe.buffer(this.shape, this.dtype, this.dataSync());
}
/**
* Returns the tensor data as a nested array. The transfer of data is done
* asynchronously.
*
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
async array() {
const t = await this.data();
return Ja(this.shape, t, this.dtype === "complex64");
}
/**
* Returns the tensor data as a nested array. The transfer of data is done
* synchronously.
*
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
arraySync() {
return Ja(this.shape, this.dataSync(), this.dtype === "complex64");
}
/**
* Asynchronously downloads the values from the `tf.Tensor`. Returns a
* promise of `TypedArray` that resolves when the computation has finished.
*
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
async data() {
this.throwIfDisposed();
const t = Ct().read(this.dataId);
if (this.dtype === "string") {
const n = await t;
try {
return n.map((s) => ra(s));
} catch {
throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
}
}
return t;
}
/**
* Copy the tensor's data to a new GPU resource. Comparing to the `dataSync()`
* and `data()`, this method prevents data from being downloaded to CPU.
*
* For WebGL backend, the data will be stored on a densely packed texture.
* This means that the texture will use the RGBA channels to store value.
*
* For WebGPU backend, the data will be stored on a buffer. There is no
* parameter, so can not use a user-defined size to create the buffer.
*
* @param options:
* For WebGL,
* - customTexShape: Optional. If set, will use the user defined
* texture shape to create the texture.
*
* @returns For WebGL backend, a GPUData contains the new texture and
* its information.
* {
* tensorRef: The tensor that is associated with this texture,
* texture: WebGLTexture,
* texShape: [number, number] // [height, width]
* }
*
* For WebGPU backend, a GPUData contains the new buffer.
* {
* tensorRef: The tensor that is associated with this buffer,
* buffer: GPUBuffer,
* }
*
* Remember to dispose the GPUData after it is used by
* `res.tensorRef.dispose()`.
*
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
dataToGPU(t) {
return this.throwIfDisposed(), Ct().readToGPU(this.dataId, t);
}
/**
* Synchronously downloads the values from the `tf.Tensor`. This blocks the
* UI thread until the values are ready, which can cause performance issues.
*
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
dataSync() {
this.throwIfDisposed();
const t = Ct().readSync(this.dataId);
if (this.dtype === "string")
try {
return t.map((n) => ra(n));
} catch {
throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().");
}
return t;
}
/** Returns the underlying bytes of the tensor's data. */
async bytes() {
this.throwIfDisposed();
const t = await Ct().read(this.dataId);
return this.dtype === "string" ? t : new Uint8Array(t.buffer);
}
/**
* Disposes `tf.Tensor` from memory.
*
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
dispose() {
this.isDisposed || (this.kerasMask && this.kerasMask.dispose(), Ct().disposeTensor(this), this.isDisposedInternal = !0);
}
get isDisposed() {
return this.isDisposedInternal;
}
throwIfDisposed() {
if (this.isDisposed)
throw new Error("Tensor is disposed.");
}
/**
* Prints the `tf.Tensor`. See `tf.print` for details.
*
* @param verbose Whether to print verbose information about the tensor,
* including dtype and size.
*
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
print(t = !1) {
return xe.print(this, t);
}
/**
* Returns a copy of the tensor. See `tf.clone` for details.
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
clone() {
return this.throwIfDisposed(), xe.clone(this);
}
/**
* Returns a human-readable description of the tensor. Useful for logging.
*
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
toString(t = !1) {
const n = this.dataSync();
return Rl(n, this.shape, this.dtype, t);
}
cast(t) {
return this.throwIfDisposed(), xe.cast(this, t);
}
variable(t = !0, n, s) {
return this.throwIfDisposed(), Ct().makeVariable(this, t, n, s);
}
}
Object.defineProperty(Rt, Symbol.hasInstance, {
value: (e) => !!e && e.data != null && e.dataSync != null && e.throwIfDisposed != null
});
function js() {
return va("Tensor", () => Rt);
}
js();
class Rn extends Rt {
constructor(t, n, s, o) {
super(t.shape, t.dtype, t.dataId, o), this.trainable = n, this.name = s;
}
/**
* Assign a new `tf.Tensor` to this variable. The new `tf.Tensor` must have
* the same shape and dtype as the old `tf.Tensor`.
*
* @param newValue New tensor to be assigned to this variable.
*
* @doc {heading: 'Tensors', subheading: 'Classes'}
*/
assign(t) {
if (t.dtype !== this.dtype)
throw new Error(`dtype of the new value (${t.dtype}) and previous value (${this.dtype}) must match`);
if (!_a(t.shape, this.shape))
throw new Error(`shape of the new value (${t.shape}) and previous value (${this.shape}) must match`);
Ct().disposeTensor(this), this.dataId = t.dataId, Ct().incRef(
this,
null
/* backend */
);
}
dispose() {
Ct().disposeVariable(this), this.isDisposedInternal = !0;
}
}
Object.defineProperty(Rn, Symbol.hasInstance, {
value: (e) => e instanceof Rt && e.assign != null && e.assign instanceof 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.
* =============================================================================
*/
var ar;
(function(e) {
e.R0 = "R0", e.R1 = "R1", e.R2 = "R2", e.R3 = "R3", e.R4 = "R4", e.R5 = "R5", e.R6 = "R6";
})(ar || (ar = {}));
var oa;
(function(e) {
e.float32 = "float32", e.int32 = "int32", e.bool = "int32", e.complex64 = "complex64";
})(oa || (oa = {}));
var ia;
(function(e) {
e.float32 = "float32", e.int32 = "int32", e.bool = "bool", e.complex64 = "complex64";
})(ia || (ia = {}));
var ua;
(function(e) {
e.float32 = "float32", e.int32 = "float32", e.bool = "float32", e.complex64 = "complex64";
})(ua || (ua = {}));
var ca;
(function(e) {
e.float32 = "complex64", e.int32 = "complex64", e.bool = "complex64", e.complex64 = "complex64";
})(ca || (ca = {}));
const $l = {
float32: ua,
int32: oa,
bool: ia,
complex64: ca
};
function Ol(e, t) {
if (e === "string" || t === "string") {
if (e === "string" && t === "string")
return "string";
throw new Error(`Can not upcast ${e} with ${t}`);
}
return $l[e][t];
}
function qs(e) {
return e != null && typeof e == "object" && "texture" in e && e.texture instanceof WebGLTexture;
}
function Ks(e) {
return typeof GPUBuffer < "u" && e != null && typeof e == "object" && "buffer" in e && e.buffer instanceof GPUBuffer;
}
/**
* @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 fe(e, t) {
if (e.dtype === t.dtype)
return [e, t];
const n = Ol(e.dtype, t.dtype);
return [e.cast(n), t.cast(n)];
}
function Xs(e) {
const t = [];
return Js(e, t, /* @__PURE__ */ new Set()), t;
}
function Js(e, t, n) {
if (e == null)
return;
if (e instanceof Rt) {
t.push(e);
return;
}
if (!Wl(e))
return;
const s = e;
for (const o in s) {
const a = s[o];
n.has(a) || (n.add(a), Js(a, t, n));
}
}
function Wl(e) {
return Array.isArray(e) || typeof e == "object";
}
/**
* @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 Zn(e) {
return e.kernelName != null;
}
class rr {
constructor() {
this.registeredVariables = {}, this.nextTapeNodeId = 0, this.numBytes = 0, this.numTensors = 0, this.numStringTensors = 0, this.numDataBuffers = 0, this.gradientDepth = 0, this.kernelDepth = 0, this.scopeStack = [], this.numDataMovesStack = [], this.nextScopeId = 0, this.tensorInfo = /* @__PURE__ */ new WeakMap(), this.profiling = !1, this.activeProfile = {
newBytes: 0,
newTensors: 0,
peakBytes: 0,
kernels: [],
result: null,
get kernelNames() {
return Array.from(new Set(this.kernels.map((t) => t.name)));
}
};
}
dispose() {
for (const t in this.registeredVariables)
this.registeredVariables[t].dispose();
}
}
class Ce {
constructor(t) {
this.ENV = t, this.registry = {}, this.registryFactory = {}, this.pendingBackendInitId = 0, this.state = new rr();
}
async ready() {
if (this.pendingBackendInit != null)
return this.pendingBackendInit.then(() => {
});
if (this.backendInstance != null)
return;
const t = this.getSortedBackends();
for (let n = 0; n < t.length; n++) {
const s = t[n];
if (await this.initializeBackend(s).success) {
await this.setBackend(s);
return;
}
}
throw new Error("Could not initialize any backends, all backend initializations failed.");
}
get backend() {
if (this.pendingBackendInit != null)
throw new Error(`Backend '${this.backendName}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods`);
if (this.backendInstance == null) {
const { name: t, asyncInit: n } = this.initializeBackendsAndReturnBest();
if (n)
throw new Error(`The highest priority backend '${t}' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other method