@antv/layout 1.0.0-alpha.2 → 1.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -2
- package/dist/6215b31a5bc171c6c2a5.worker.js +2 -0
- package/dist/6215b31a5bc171c6c2a5.worker.js.map +1 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/esm/6215b31a5bc171c6c2a5.worker.js +2 -0
- package/esm/6215b31a5bc171c6c2a5.worker.js.map +1 -0
- package/esm/index.esm.js +1 -1
- package/esm/index.esm.js.map +1 -1
- package/package.json +2 -3
- package/dist/03710bc99fe066d705cb.worker.js +0 -2
- package/dist/03710bc99fe066d705cb.worker.js.map +0 -1
- package/esm/03710bc99fe066d705cb.worker.js +0 -2
- package/esm/03710bc99fe066d705cb.worker.js.map +0 -1
package/esm/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t={161:t=>{var e=Object.prototype.hasOwnProperty,r="~";function o(){}function s(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function n(t,e,o,n,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var a=new s(o,n||t,i),h=r?r+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],a]:t._events[h].push(a):(t._events[h]=a,t._eventsCount++),t}function i(t,e){0==--t._eventsCount?t._events=new o:delete t._events[e]}function a(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(r=!1)),a.prototype.eventNames=function(){var t,o,s=[];if(0===this._eventsCount)return s;for(o in t=this._events)e.call(t,o)&&s.push(r?o.slice(1):o);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(t)):s},a.prototype.listeners=function(t){var e=r?r+t:t,o=this._events[e];if(!o)return[];if(o.fn)return[o.fn];for(var s=0,n=o.length,i=new Array(n);s<n;s++)i[s]=o[s].fn;return i},a.prototype.listenerCount=function(t){var e=r?r+t:t,o=this._events[e];return o?o.fn?1:o.length:0},a.prototype.emit=function(t,e,o,s,n,i){var a=r?r+t:t;if(!this._events[a])return!1;var h,u,l=this._events[a],c=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),c){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,o),!0;case 4:return l.fn.call(l.context,e,o,s),!0;case 5:return l.fn.call(l.context,e,o,s,n),!0;case 6:return l.fn.call(l.context,e,o,s,n,i),!0}for(u=1,h=new Array(c-1);u<c;u++)h[u-1]=arguments[u];l.fn.apply(l.context,h)}else{var f,d=l.length;for(u=0;u<d;u++)switch(l[u].once&&this.removeListener(t,l[u].fn,void 0,!0),c){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,e);break;case 3:l[u].fn.call(l[u].context,e,o);break;case 4:l[u].fn.call(l[u].context,e,o,s);break;default:if(!h)for(f=1,h=new Array(c-1);f<c;f++)h[f-1]=arguments[f];l[u].fn.apply(l[u].context,h)}}return!0},a.prototype.on=function(t,e,r){return n(this,t,e,r,!1)},a.prototype.once=function(t,e,r){return n(this,t,e,r,!0)},a.prototype.removeListener=function(t,e,o,s){var n=r?r+t:t;if(!this._events[n])return this;if(!e)return i(this,n),this;var a=this._events[n];if(a.fn)a.fn!==e||s&&!a.once||o&&a.context!==o||i(this,n);else{for(var h=0,u=[],l=a.length;h<l;h++)(a[h].fn!==e||s&&!a[h].once||o&&a[h].context!==o)&&u.push(a[h]);u.length?this._events[n]=1===u.length?u[0]:u:i(this,n)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=r?r+t:t,this._events[e]&&i(this,e)):(this._events=new o,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,t.exports=a},190:(t,e,r)=>{var o=r(314),s=["calculateLayout"];t.exports=function(){var t=new Worker(URL.createObjectURL(new Blob(['var t={d:(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{calculateLayout:()=>yt});class r{nodeMap=new Map;edgeMap=new Map;inEdgesMap=new Map;outEdgesMap=new Map;treeIndices=new Map;changes=[];batchCount=0;onChanged=()=>{};constructor(t){t&&(t.nodes&&this.addNodes(t.nodes),t.edges&&this.addEdges(t.edges),t.tree&&this.addTree(t.tree),t.onChanged&&(this.onChanged=t.onChanged))}batch=t=>{this.batchCount+=1,t(),this.batchCount-=1,this.batchCount||this.commit()};commit(){const t=this.changes;this.changes=[],this.onChanged({graph:this,changes:t})}reduceChanges(t){let e=[];return t.forEach((t=>{switch(t.type){case"NodeRemoved":{let r=!1;e=e.filter((e=>{if("NodeAdded"===e.type){const o=e.value.id===t.value.id;return o&&(r=!0),!o}return"NodeDataUpdated"===e.type?e.id!==t.value.id:"TreeStructureChanged"!==e.type||e.nodeId!==t.value.id})),r||e.push(t);break}case"EdgeRemoved":{let r=!1;e=e.filter((e=>{if("EdgeAdded"===e.type){const o=e.value.id===t.value.id;return o&&(r=!0),!o}return"EdgeDataUpdated"!==e.type&&"EdgeUpdated"!==e.type||e.id!==t.value.id})),r||e.push(t);break}case"NodeDataUpdated":case"EdgeDataUpdated":case"EdgeUpdated":{const r=e.find((e=>e.type===t.type&&e.id===t.id&&e.propertyName===t.propertyName));r?r.newValue=t.newValue:e.push(t);break}case"TreeStructureDetached":e=e.filter((e=>"TreeStructureAttached"===e.type?e.treeKey!==t.treeKey:"TreeStructureChanged"!==e.type||e.treeKey!==t.treeKey)),e.push(t);break;case"TreeStructureChanged":{const r=e.find((e=>"TreeStructureChanged"===e.type&&e.treeKey===t.treeKey&&e.nodeId===t.nodeId));r?r.newParentId=t.newParentId:e.push(t);break}default:e.push(t)}})),e}checkNodeExistence(t){if(!this.hasNode(t))throw new Error("Node not found for id: "+t)}hasNode(t){return this.nodeMap.has(t)}areNeighbors(t,e){return this.checkNodeExistence(t),this.getNeighbors(e).some((e=>e.id===t))}getNode(t){return this.checkNodeExistence(t),this.nodeMap.get(t)}getRelatedEdges(t,e){this.checkNodeExistence(t);const r=this.inEdgesMap.get(t),o=this.outEdgesMap.get(t);if("in"===e)return Array.from(r);if("out"===e)return Array.from(o);const s=new Set([...r,...o]);return Array.from(s)}getDegree(t,e){return this.getRelatedEdges(t,e).length}getSuccessors(t){const e=this.getRelatedEdges(t,"out").map((t=>t.target));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getPredecessors(t){const e=this.getRelatedEdges(t,"in").map((t=>t.source));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getNeighbors(t){const e=this.getPredecessors(t),r=this.getSuccessors(t);return Array.from(new Set([...e,...r]))}doAddNode(t){if(this.hasNode(t.id))throw new Error("Node already exists: "+t.id);this.nodeMap.set(t.id,t),this.inEdgesMap.set(t.id,new Set),this.outEdgesMap.set(t.id,new Set),this.treeIndices.forEach((e=>{e.childrenMap.set(t.id,new Set)})),this.changes.push({type:"NodeAdded",value:t})}addNodes(t){this.batch((()=>{for(const e of t)this.doAddNode(e)}))}addNode(t){this.addNodes([t])}doRemoveNode(t){const e=this.getNode(t),r=this.inEdgesMap.get(t),o=this.outEdgesMap.get(t);r?.forEach((t=>this.doRemoveEdge(t.id))),o?.forEach((t=>this.doRemoveEdge(t.id))),this.nodeMap.delete(t),this.treeIndices.forEach((e=>{e.childrenMap.get(t)?.forEach((t=>{e.parentMap.delete(t.id)})),e.parentMap.delete(t),e.childrenMap.delete(t)})),this.changes.push({type:"NodeRemoved",value:e})}removeNodes(t){this.batch((()=>{t.forEach((t=>this.doRemoveNode(t)))}))}removeNode(t){this.removeNodes([t])}updateNodeData(t,e,r){const o=this.getNode(t);this.batch((()=>{const s=o.data[e],n=r;o.data[e]=n,this.changes.push({type:"NodeDataUpdated",id:t,propertyName:e,oldValue:s,newValue:n})}))}mergeNodeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateNodeData(t,e,r)}))}))}checkEdgeExistence(t){if(!this.hasEdge(t))throw new Error("Edge not found for id: "+t)}hasEdge(t){return this.edgeMap.has(t)}getEdge(t){return this.checkEdgeExistence(t),this.edgeMap.get(t)}getEdgeDetail(t){const e=this.getEdge(t);return{edge:e,source:this.getNode(e.source),target:this.getNode(e.target)}}doAddEdge(t){if(this.hasEdge(t.id))throw new Error("Edge already exists: "+t.id);this.checkNodeExistence(t.source),this.checkNodeExistence(t.target),this.edgeMap.set(t.id,t);const e=this.inEdgesMap.get(t.target),r=this.outEdgesMap.get(t.source);e.add(t),r.add(t),this.changes.push({type:"EdgeAdded",value:t})}addEdges(t){this.batch((()=>{for(const e of t)this.doAddEdge(e)}))}addEdge(t){this.addEdges([t])}doRemoveEdge(t){const e=this.getEdge(t),r=this.outEdgesMap.get(e.source),o=this.inEdgesMap.get(e.target);r.delete(e),o.delete(e),this.edgeMap.delete(t),this.changes.push({type:"EdgeRemoved",value:e})}removeEdges(t){this.batch((()=>{t.forEach((t=>this.doRemoveEdge(t)))}))}removeEdge(t){this.removeEdges([t])}updateEdgeSource(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const o=r.source,s=e;this.outEdgesMap.get(o).delete(r),this.outEdgesMap.get(s).add(r),r.source=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"source",oldValue:o,newValue:s})}))}updateEdgeTarget(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const o=r.target,s=e;this.inEdgesMap.get(o).delete(r),this.inEdgesMap.get(s).add(r),r.target=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"target",oldValue:o,newValue:s})}))}updateEdgeData(t,e,r){const o=this.getEdge(t);this.batch((()=>{const s=o.data[e],n=r;o.data[e]=n,this.changes.push({type:"EdgeDataUpdated",id:t,propertyName:e,oldValue:s,newValue:n})}))}mergeEdgeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateEdgeData(t,e,r)}))}))}checkTreeExistence(t){if(!this.treeIndices.has(t))throw new Error("Tree structure not found for treeKey: "+t)}attachTreeStructure(t){this.treeIndices.has(t)||(this.treeIndices.set(t,{parentMap:new Map,childrenMap:new Map}),this.batch((()=>{this.changes.push({type:"TreeStructureAttached",treeKey:t})})))}detachTreeStructure(t){this.checkTreeExistence(t),this.treeIndices.delete(t),this.batch((()=>{this.changes.push({type:"TreeStructureDetached",treeKey:t})}))}addTree(t,e){this.batch((()=>{this.attachTreeStructure(e);const r=[],o=Array.isArray(t)?t:[t];for(;o.length;){const t=o.shift();r.push(t),t.children&&o.push(...t.children)}this.addNodes(r),r.forEach((t=>{t.children?.forEach((r=>{this.setParent(r.id,t.id,e)}))}))}))}getRoots(t){return this.checkTreeExistence(t),this.getAllNodes().filter((e=>!this.getParent(e.id,t)))}getChildren(t,e){this.checkNodeExistence(t),this.checkTreeExistence(e);const r=this.treeIndices.get(e).childrenMap.get(t);return Array.from(r||[])}getParent(t,e){return this.checkNodeExistence(t),this.checkTreeExistence(e),this.treeIndices.get(e).parentMap.get(t)||null}setParent(t,e,r){this.checkTreeExistence(r);const o=this.treeIndices.get(r),s=this.getNode(t),n=o.parentMap.get(t),i=this.getNode(e);o.parentMap.set(t,i),n&&o.childrenMap.get(n.id)?.delete(s);let a=o.childrenMap.get(i.id);a||(a=new Set,o.childrenMap.set(i.id,a)),a.add(s),this.batch((()=>{this.changes.push({type:"TreeStructureChanged",treeKey:r,nodeId:t,oldParentId:n?.id,newParentId:i.id})}))}getAllNodes(){return Array.from(this.nodeMap.values())}getAllEdges(){return Array.from(this.edgeMap.values())}doBFS(t,e,r){for(;t.length;){const o=t.shift();r(o),e.add(o.id),this.getSuccessors(o.id).forEach((r=>{e.has(r.id)||(e.add(r.id),t.push(r))}))}}bfs(t,e){this.doBFS([this.getNode(t)],new Set,e)}doDFS(t,e,r){r(t),e.add(t.id),this.getSuccessors(t.id).forEach((t=>{e.has(t.id)||this.doDFS(t,e,r)}))}dfs(t,e){this.doDFS(this.getNode(t),new Set,e)}clone(){const t=this.getAllNodes().map((t=>({...t,data:{...t.data}}))),e=this.getAllEdges().map((t=>({...t,data:{...t.data}}))),o=new r({nodes:t,edges:e});return this.treeIndices.forEach((({parentMap:t,childrenMap:e},r)=>{const s=new Map;t.forEach(((t,e)=>{s.set(e,o.getNode(t.id))}));const n=new Map;e.forEach(((t,e)=>{n.set(e,new Set(Array.from(t).map((t=>o.getNode(t.id)))))})),o.treeIndices.set(r,{parentMap:s,childrenMap:n})})),o}toJSON(){return JSON.stringify({nodes:this.getAllNodes(),edges:this.getAllEdges()})}}var o=function(){return o=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++)for(var s in e=arguments[r])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},o.apply(this,arguments)};function s(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,s,n=r.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(t){s={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function n(t,e,r){if(r||2===arguments.length)for(var o,s=0,n=e.length;s<n;s++)!o&&s in e||(o||(o=Array.prototype.slice.call(e,0,s)),o[s]=e[s]);return t.concat(o||Array.prototype.slice.call(e))}Object.create,Object.create;var i=function(t){return"string"==typeof t},a=/-(\\w)/g,h=(function(t){return t.replace(a,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),u=function(t){return"number"==typeof t},l=function(t){for(var e=[],r=t.length,o=0;o<r;o+=1){e[o]=[];for(var s=0;s<r;s+=1)o===s?e[o][s]=0:0!==t[o][s]&&t[o][s]?e[o][s]=t[o][s]:e[o][s]=1/0}for(var n=0;n<r;n+=1)for(o=0;o<r;o+=1)for(s=0;s<r;s+=1)e[o][s]>e[o][n]+e[n][s]&&(e[o][s]=e[o][n]+e[n][s]);return e},c=function(t,e){var r=t.nodes,o=t.edges,s=[],n={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){n[t.id]=e,s.push([])})),null==o||o.forEach((function(t){var r=t.source,o=t.target,i=n[r],a=n[o];void 0!==i&&void 0!==a&&(s[i][a]=1,e||(s[a][i]=1))})),s},f=function(t){return null!==t&&"object"==typeof t},d=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var e=[];return t.forEach((function(t){e.push(t)})),e.map((function(t){return d(t)}))}if("object"==typeof t&&Object.keys(t).length){var r=o({},t);return Object.keys(r).forEach((function(t){r[t]=d(r[t])})),r}return t},g=function(t){return"function"==typeof t},m=function(t,e,r){return void 0===r&&(r=!0),e||0===e?g(e)?e:u(e)?function(){return e}:h(e)?function(){if(r){var o=Math.max.apply(Math,n([],s(e),!1));return isNaN(o)?t:o}return e}:f(e)?function(){if(r){var o=Math.max(e.width,e.height);return isNaN(o)?t:o}return[e.width,e.height]}:function(){return t}:function(e){return e.size?h(e.size)?e.size[0]>e.size[1]?e.size[0]:e.size[1]:f(e.size)?e.size.width>e.size.height?e.size.width:e.size.height:e.size:t}},p={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},w=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=o(o({},p),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){var r=this;t.batch((function(){r.genericCircularLayout(!0,t,e)}))},t.prototype.genericCircularLayout=function(t,e,r){var n=o(o({},this.options),r),i=n.width,a=n.height,h=n.center,u=n.divisions,l=n.startAngle,c=void 0===l?0:l,f=n.endAngle,g=void 0===f?2*Math.PI:f,p=n.angleRatio,w=n.ordering,M=n.clockwise,b=n.nodeSpacing,E=n.nodeSize,x=n.layoutInvisibles,S=n.onLayoutEnd,N=e.getAllNodes(),R=e.getAllEdges();x||(N=N.filter((function(t){return t.data.visible||void 0===t.data.visible})),R=R.filter((function(t){return t.data.visible||void 0===t.data.visible})));var I=N.length;if(0===I)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var k=s(v(i,a,h),3),A=k[0],T=k[1],D=k[2];if(1===I){t&&e.mergeNodeData(N[0].id,{x:D[0],y:D[1]});var C={nodes:[o(o({},N[0]),{data:o(o({},N[0].data),{x:D[0],y:D[1]})})],edges:R};return null==S||S(C),C}var z=(g-c)/I,P=n.radius,V=n.startRadius,q=n.endRadius;if(b){var j=m(10,b),O=m(10,E),F=-1/0;N.forEach((function(t){var e=O(t);F<e&&(F=e)}));var L=0;N.forEach((function(t,e){L+=0===e?F||10:(j(t)||0)+(F||10)})),P=L/(2*Math.PI)}else P||V||q?!V&&q?V=q:V&&!q&&(q=V):P=Math.min(T,A)/2;var $=z*p,U=[];U="topology"===w?y(e,N):"topology-directed"===w?y(e,N,!0):"degree"===w?function(t,e){var r=[];return e.forEach((function(t,e){r.push(d(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(e,N):N.map((function(t){return d(t)}));for(var B=Math.ceil(I/u),K=0;K<I;++K){var W=P;W||null===V||null===q||(W=V+K*(q-V)/(I-1)),W||(W=10+100*K/(I-1));var J=c+K%B*$+2*Math.PI/u*Math.floor(K/B);M||(J=g-K%B*$-2*Math.PI/u*Math.floor(K/B)),U[K].data.x=D[0]+Math.cos(J)*W,U[K].data.y=D[1]+Math.sin(J)*W}t&&U.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var _={nodes:U,edges:R};return null==S||S(_),_},t}(),y=function(t,e,r){void 0===r&&(r=!1);var o=[d(e[0])],s={},n=e.length;s[e[0].id]=!0;var i=0;return e.forEach((function(a,h){if(0!==h)if(h!==n-1&&t.getDegree(a.id,"both")===t.getDegree(e[h+1].id,"both")&&!t.areNeighbors(o[i].id,a.id)||s[a.id]){for(var u=r?t.getSuccessors(o[i].id):t.getNeighbors(o[i].id),l=!1,c=0;c<u.length;c++){var f=u[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!s[f.id]){o.push(d(f)),s[f.id]=!0,l=!0;break}}for(var g=0;!l&&(s[e[g].id]||(o.push(d(e[g])),s[e[g].id]=!0,l=!0),++g!==n););}else o.push(d(a)),s[a.id]=!0,i++})),o},v=function(t,e,r){var o=t,s=e,n=r;return o||"undefined"==typeof window||(o=window.innerWidth),s||"undefined"==typeof window||(s=window.innerHeight),n||(n=[o/2,s/2]),[o,s,n]},M={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},b=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",Object.assign(this.options,M,t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,a=s.width,l=s.height,c=s.sortBy,m=s.maxLevelDiff,p=s.sweep,w=s.clockwise,y=s.equidistant,v=s.minNodeSpacing,M=void 0===v?10:v,b=s.preventOverlap,E=s.startAngle,x=void 0===E?1.5*Math.PI:E,S=s.nodeSize,N=s.nodeSpacing,R=s.layoutInvisibles,I=s.onLayoutEnd,k=e.getAllNodes(),A=e.getAllEdges();R||(k=k.filter((function(t){return t.data.visible||void 0===t.data.visible})),A=A.filter((function(t){return t.data.visible||void 0===t.data.visible})));var T=k.length;if(0===T){var D={nodes:[],edges:A};return null==I||I(D),D}var C=a||"undefined"==typeof window?a:window.innerWidth,z=l||"undefined"==typeof window?l:window.innerHeight,P=n||[C/2,z/2];if(1===T){t&&e.mergeNodeData(k[0].id,{x:P[0],y:P[1]});var V={nodes:[o(o({},k[0]),{data:o(o({},k[0].data),{x:P[0],y:P[1]})})],edges:A};return null==I||I(V),V}var q,j=[],O=0;q=h(S)?Math.max(S[0],S[1]):S,h(N)?O=Math.max(N[0],N[1]):u(N)&&(O=N),k.forEach((function(t){j.push(d(t));var e=q;h(t.data.size)?e=Math.max(t.data.size[0],t.data.size[1]):u(t.data.size)?e=t.data.size:f(t.data.size)&&(e=Math.max(t.data.size.width,t.data.size.height)),q=Math.max(q,e),g(N)&&(O=Math.max(N(t),O))}));var F={};j.forEach((function(t,e){F[t.id]=e}));var L=c;i(L)&&void 0!==j[0].data[L]||(L="degree"),"degree"===L?j.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):j.sort((function(t,e){return e.data[L]-t.data[L]}));var $=j[0],U=m||$.data[L]/4,B=[{nodes:[]}],K=B[0];j.forEach((function(t){if(K.nodes.length>0){var e=Math.abs(K.nodes[0].data[L]-t.data[L]);U&&e>=U&&(K={nodes:[]},B.push(K))}K.nodes.push(t)}));var W=q+(O||M);if(!b){var J=B.length>0&&B[0].nodes.length>1,_=(Math.min(C,z)/2-W)/(B.length+(J?1:0));W=Math.min(W,_)}var G=0;if(B.forEach((function(t){var e=void 0===p?2*Math.PI-2*Math.PI/t.nodes.length:p;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&b){var r=Math.cos(t.dTheta)-Math.cos(0),o=Math.sin(t.dTheta)-Math.sin(0),s=Math.sqrt(W*W/(r*r+o*o));G=Math.max(s,G)}t.r=G,G+=W})),y){for(var H=0,Y=0,Q=0;Q<B.length;Q++){var X=(B[Q].r||0)-Y;H=Math.max(H,X)}Y=0,B.forEach((function(t,e){0===e&&(Y=t.r||0),t.r=Y,Y+=H}))}B.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,o){var s=x+(w?1:-1)*e*o;t.data.x=P[0]+r*Math.cos(s),t.data.y=P[1]+r*Math.sin(s)}))})),t&&j.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Z={nodes:j,edges:A};return null==I||I(Z),Z},t}(),E={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},x=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",Object.assign(this.options,E,t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.begin,a=void 0===n?[0,0]:n,u=s.condense,l=s.preventOverlapPadding,c=s.preventOverlap,f=s.columns,g=s.rows,p=s.cols,w=void 0===p?f:p,y=s.nodeSpacing,v=s.nodeSize,M=s.onLayoutEnd,b=s.position,E=s.sortBy,x=s.width,k=s.height,T=s.layoutInvisibles,D=e.getAllNodes(),C=e.getAllEdges();T||(D=D.filter((function(t){return t.data.visible||void 0===t.data.visible})),C=C.filter((function(t){return t.data.visible||void 0===t.data.visible})));var z=D.length;if(0===z){var P={nodes:[],edges:C};return null==M||M(P),P}if(1===z){t&&e.mergeNodeData(D[0].id,{x:a[0],y:a[1]});var V={nodes:[o(o({},D[0]),{data:o(o({},D[0].data),{x:a[0],y:a[1]})})],edges:C};return null==M||M(V),V}var q=D.map((function(t){return d(t)}));i(E)&&void 0!==q[0].data[E]||(E="degree"),"degree"===E?q.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):q.sort((function(t,e){return e.data[E]-t.data[E]}));var j=x||"undefined"==typeof window?x:window.innerWidth,O=k||"undefined"==typeof window?k:window.innerHeight,F=z,L={rows:g,cols:w};if(null!=g&&null!=w)L.rows=g,L.cols=w;else if(null!=g&&null==w)L.rows=g,L.cols=Math.ceil(F/L.rows);else if(null==g&&null!=w)L.cols=w,L.rows=Math.ceil(F/L.cols);else{var $=Math.sqrt(F*O/j);L.rows=Math.round($),L.cols=Math.round(j/O*$)}if(L.rows=Math.max(L.rows,1),L.cols=Math.max(L.cols,1),L.cols*L.rows>F)((B=S(L))-1)*(U=N(L))>=F?S(L,B-1):(U-1)*B>=F&&N(L,U-1);else for(;L.cols*L.rows<F;){var U,B=S(L);((U=N(L))+1)*B>=F?N(L,U+1):S(L,B+1)}var K=u?0:j/L.cols,W=u?0:O/L.rows;if(c||y){var J=m(10,y),_=m(30,v,!1);q.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var r,o,s=e.getNode(t.id),n=_(s)||30;h(n)?(r=n[0],o=n[1]):(r=n,o=n);var i=void 0!==J?J(t):l,a=r+i,u=o+i;K=Math.max(K,a),W=Math.max(W,u)}))}for(var G={},H={row:0,col:0},Y={},Q=0;Q<q.length;Q++){var X=q[Q],Z=void 0;if(b&&(Z=b(e.getNode(X.id))),Z&&(void 0!==Z.row||void 0!==Z.col)){var tt={row:Z.row,col:Z.col};if(void 0===tt.col)for(tt.col=0;R(G,tt);)tt.col++;else if(void 0===tt.row)for(tt.row=0;R(G,tt);)tt.row++;Y[X.id]=tt,I(G,tt)}A(X,a,K,W,Y,L,H,G)}var et={nodes:q,edges:C};return null==M||M(et),t&&q.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),et},t}(),S=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.min(o,s):Math.min(o,s)===t.rows?t.rows=e:t.cols=e,r},N=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.max(o,s):Math.max(o,s)===t.rows?t.rows=e:t.cols=e,r},R=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},I=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},k=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},A=function(t,e,r,o,s,n,i,a){var h,u,l=s[t.id];if(l)h=l.col*r+r/2+e[0],u=l.row*o+o/2+e[1];else{for(;R(a,i);)k(n,i);h=i.col*r+r/2+e[0],u=i.row*o+o/2+e[1],I(a,i),k(n,i)}t.data.x=h,t.data.y=u};const T=Object.prototype.toString;function D(t){return T.call(t).endsWith("Array]")}function C(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!D(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]>i&&(i=t[a]);return i}function z(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!D(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]<i&&(i=t[a]);return i}function P(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!D(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!D(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var o=z(t),s=C(t);if(o===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=r.min,i=void 0===n?r.autoMinMax?o:0:n,a=r.max,h=void 0===a?r.autoMinMax?s:1:a;if(i>=h)throw new RangeError("min option must be smaller than max option");for(var u=(h-i)/(s-o),l=0;l<t.length;l++)e[l]=(t[l]-o)*u+i;return e}const V=" ".repeat(2),q=" ".repeat(4);function j(t,e={}){const{maxRows:r=15,maxColumns:o=10,maxNumSize:s=8,padMinus:n="auto"}=e;return`${t.constructor.name} {\\n${V}[\\n${q}${function(t,e,r,o,s){const{rows:n,columns:i}=t,a=Math.min(n,e),h=Math.min(i,r),u=[];if("auto"===s){s=!1;t:for(let e=0;e<a;e++)for(let r=0;r<h;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let n=0;n<h;n++)r.push(O(t.get(e,n),o,s));u.push(`${r.join(" ")}`)}return h!==i&&(u[u.length-1]+=` ... ${i-r} more columns`),a!==n&&u.push(`... ${n-e} more rows`),u.join(`\\n${q}`)}(t,r,o,s,n)}\\n${V}]\\n${V}rows: ${t.rows}\\n${V}columns: ${t.columns}\\n}`}function O(t,e,r){return(t>=0&&r?` ${F(t,e-1)}`:F(t,e)).padEnd(e)}function F(t,e){let r=t.toString();if(r.length<=e)return r;let o=t.toFixed(e);if(o.length>e&&(o=t.toFixed(Math.max(0,e-(o.length-e)))),o.length<=e&&!o.startsWith("0.000")&&!o.startsWith("-0.000"))return o;let s=t.toExponential(e);return s.length>e&&(s=t.toExponential(Math.max(0,e-(s.length-e)))),s.slice(0)}function L(t,e,r){let o=r?t.rows:t.rows-1;if(e<0||e>o)throw new RangeError("Row index out of range")}function $(t,e,r){let o=r?t.columns:t.columns-1;if(e<0||e>o)throw new RangeError("Column index out of range")}function U(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function B(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function K(t,e,r,o,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(J("startRow",e),J("endRow",r),J("startColumn",o),J("endColumn",s),e>r||o>s||e<0||e>=t.rows||r<0||r>=t.rows||o<0||o>=t.columns||s<0||s>=t.columns)throw new RangeError("Submatrix indices are out of range")}function W(t,e=0){let r=[];for(let o=0;o<t;o++)r.push(e);return r}function J(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function _(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class G{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let o=new Y(t,e);for(let s=0;s<t;s++)for(let t=0;t<e;t++)o.set(s,t,r[s*e+t]);return o}static rowVector(t){let e=new Y(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new Y(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new Y(t,e)}static ones(t,e){return new Y(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:o=Math.random}=r;let s=new Y(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)s.set(r,t,o());return s}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:o=0,max:s=1e3,random:n=Math.random}=r;if(!Number.isInteger(o))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(o>=s)throw new RangeError("min must be smaller than max");let i=s-o,a=new Y(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=o+Math.round(n()*i);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let o=Math.min(t,e),s=this.zeros(t,e);for(let t=0;t<o;t++)s.set(t,t,r);return s}static diag(t,e,r){let o=t.length;void 0===e&&(e=o),void 0===r&&(r=e);let s=Math.min(o,e,r),n=this.zeros(e,r);for(let e=0;e<s;e++)n.set(e,e,t[e]);return n}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new Y(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.min(t.get(n,r),e.get(n,r)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new this(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.max(t.get(n,r),e.get(n,r)));return s}static checkMatrix(t){return G.isMatrix(t)?t:new Y(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);t++}return o}isReducedEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(o=!1);t++}return o}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let o=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(o,r)&&(o=s);if(0===t.get(o,r))r++;else{t.swapRows(e,o);let s=t.get(e,r);for(let o=r;o<t.columns;o++)t.set(e,o,t.get(e,o)/s);for(let o=e+1;o<t.rows;o++){let s=t.get(o,r)/t.get(e,r);t.set(o,r,0);for(let n=r+1;n<t.columns;n++)t.set(o,n,t.get(o,n)-t.get(e,n)*s)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,o=r-1;for(;o>=0;)if(0===t.maxRow(o))o--;else{let s=0,n=!1;for(;s<r&&!1===n;)1===t.get(o,s)?n=!0:s++;for(let r=0;r<o;r++){let n=t.get(r,s);for(let i=s;i<e;i++){let e=t.get(r,i)-n*t.get(o,i);t.set(r,i,e)}}o--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let o=new Y(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)o.setSubMatrix(this,this.rows*t,this.columns*e);return o}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){L(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return Y.rowVector(this.getRow(t))}setRow(t,e){L(this,t),e=U(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){L(this,t),L(this,e);for(let r=0;r<this.columns;r++){let o=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,o)}return this}getColumn(t){$(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return Y.columnVector(this.getColumn(t))}setColumn(t,e){$(this,t),e=B(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){$(this,t),$(this,e);for(let r=0;r<this.rows;r++){let o=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,o)}return this}addRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){L(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){$(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){_(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){_(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}maxRow(t){if(L(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){L(this,t),_(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)>e&&(e=this.get(t,o),r[1]=o);return r}minRow(t){if(L(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){L(this,t),_(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)<e&&(e=this.get(t,o),r[1]=o);return r}maxColumn(t){if($(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){$(this,t),_(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)>e&&(e=this.get(o,t),r[0]=o);return r}minColumn(t){if($(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){$(this,t),_(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)<e&&(e=this.get(o,t),r[0]=o);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){G.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let o=0;o<e.length;o++)r+=e[o]*t[o];return r}mmul(t){t=Y.checkMatrix(t);let e=this.rows,r=this.columns,o=t.columns,s=new Y(e,o),n=new Float64Array(r);for(let i=0;i<o;i++){for(let e=0;e<r;e++)n[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let o=0;o<r;o++)e+=this.get(t,o)*n[o];s.set(t,i,e)}}return s}strassen2x2(t){t=Y.checkMatrix(t);let e=new Y(2,2);const r=this.get(0,0),o=t.get(0,0),s=this.get(0,1),n=t.get(0,1),i=this.get(1,0),a=t.get(1,0),h=this.get(1,1),u=t.get(1,1),l=(r+h)*(o+u),c=(i+h)*o,f=r*(n-u),d=h*(a-o),g=(r+s)*u,m=l+d-g+(s-h)*(a+u),p=f+g,w=c+d,y=l-c+f+(i-r)*(o+n);return e.set(0,0,m),e.set(0,1,p),e.set(1,0,w),e.set(1,1,y),e}strassen3x3(t){t=Y.checkMatrix(t);let e=new Y(3,3);const r=this.get(0,0),o=this.get(0,1),s=this.get(0,2),n=this.get(1,0),i=this.get(1,1),a=this.get(1,2),h=this.get(2,0),u=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),m=t.get(1,1),p=t.get(1,2),w=t.get(2,0),y=t.get(2,1),v=t.get(2,2),M=(r-n)*(-f+m),b=(-r+n+i)*(c-f+m),E=(n+i)*(-c+f),x=r*c,S=(-r+h+u)*(c-d+p),N=(-r+h)*(d-p),R=(h+u)*(-c+d),I=(-s+u+l)*(m+w-y),k=(s-l)*(m-y),A=s*w,T=(u+l)*(-w+y),D=(-s+i+a)*(p+w-v),C=(s-a)*(p-v),z=(i+a)*(-w+v),P=x+A+o*g,V=(r+o+s-n-i-u-l)*m+b+E+x+I+A+T,q=x+S+R+(r+o+s-i-a-h-u)*p+A+D+z,j=M+i*(-c+f+g-m-p-w+v)+b+x+A+D+C,O=M+b+E+x+a*y,F=A+D+C+z+n*d,L=x+S+N+u*(-c+d+g-m-p-w+y)+I+k+A,$=I+k+A+T+h*f,U=x+S+N+R+l*v;return e.set(0,0,P),e.set(0,1,V),e.set(0,2,q),e.set(1,0,j),e.set(1,1,O),e.set(1,2,F),e.set(2,0,L),e.set(2,1,$),e.set(2,2,U),e}mmulStrassen(t){t=Y.checkMatrix(t);let e=this.clone(),r=e.rows,o=e.columns,s=t.rows,n=t.columns;function i(t,e,r){let o=t.rows,s=t.columns;if(o===e&&s===r)return t;{let o=G.zeros(e,r);return o=o.setSubMatrix(t,0,0),o}}o!==s&&console.warn(`Multiplying ${r} x ${o} and ${s} x ${n} matrix: dimensions do not match.`);let a=Math.max(r,s),h=Math.max(o,n);return e=i(e,a,h),function t(e,r,o,s){if(o<=512||s<=512)return e.mmul(r);o%2==1&&s%2==1?(e=i(e,o+1,s+1),r=i(r,o+1,s+1)):o%2==1?(e=i(e,o+1,s),r=i(r,o+1,s)):s%2==1&&(e=i(e,o,s+1),r=i(r,o,s+1));let n=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),h=e.subMatrix(0,n-1,0,a-1),u=r.subMatrix(0,n-1,0,a-1),l=e.subMatrix(0,n-1,a,e.columns-1),c=r.subMatrix(0,n-1,a,r.columns-1),f=e.subMatrix(n,e.rows-1,0,a-1),d=r.subMatrix(n,r.rows-1,0,a-1),g=e.subMatrix(n,e.rows-1,a,e.columns-1),m=r.subMatrix(n,r.rows-1,a,r.columns-1),p=t(G.add(h,g),G.add(u,m),n,a),w=t(G.add(f,g),u,n,a),y=t(h,G.sub(c,m),n,a),v=t(g,G.sub(d,u),n,a),M=t(G.add(h,l),m,n,a),b=t(G.sub(f,h),G.add(u,c),n,a),E=t(G.sub(l,g),G.add(d,m),n,a),x=G.add(p,v);x.sub(M),x.add(E);let S=G.add(y,M),N=G.add(w,v),R=G.sub(p,w);R.add(y),R.add(b);let I=G.zeros(2*x.rows,2*x.columns);return I=I.setSubMatrix(x,0,0),I=I.setSubMatrix(S,x.rows,0),I=I.setSubMatrix(N,0,x.columns),I=I.setSubMatrix(R,x.rows,x.columns),I.subMatrix(0,o-1,0,s-1)}(e,t=i(t,a,h),a,h)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new Y(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&P(s,{min:e,max:r,output:s}),o.setRow(t,s)}return o}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new Y(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&P(s,{min:e,max:r,output:s}),o.setColumn(t,s)}return o}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),o=this.get(e,this.columns-1-r);this.set(e,r,o),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),o=this.get(this.rows-1-r,e);this.set(r,e,o),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=Y.checkMatrix(t);let e=this.rows,r=this.columns,o=t.rows,s=t.columns,n=new Y(e*o,r*s);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<o;r++)for(let a=0;a<s;a++)n.set(o*i+r,s*e+a,this.get(i,e)*t.get(r,a));return n}kroneckerSum(t){if(t=Y.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,o=this.kroneckerProduct(Y.eye(r,r)),s=Y.eye(e,e).kroneckerProduct(t);return o.add(s)}transpose(){let t=new Y(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=H){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=H){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,o){K(this,t,e,r,o);let s=new Y(e-t+1,o-r+1);for(let n=t;n<=e;n++)for(let e=r;e<=o;e++)s.set(n-t,e-r,this.get(n,e));return s}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let o=new Y(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);o.set(s,n-e,this.get(t[s],n))}return o}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let o=new Y(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);o.set(n-e,s,this.get(n,t[s]))}return o}setSubMatrix(t,e,r){if((t=Y.checkMatrix(t)).isEmpty())return this;K(this,e,e+t.rows-1,r,r+t.columns-1);for(let o=0;o<t.rows;o++)for(let s=0;s<t.columns;s++)this.set(e+o,r+s,t.get(o,s));return this}selection(t,e){!function(t,e){if(!D(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!D(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new Y(t.length,e.length);for(let o=0;o<t.length;o++){let s=t[o];for(let t=0;t<e.length;t++){let n=e[t];r.set(o,t,this.get(s,n))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new Y(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=W(t.rows);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]+=t.get(r,o);return e}(this);case"column":return function(t){let e=W(t.columns);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]+=t.get(r,o);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e+=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=W(t.rows,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]*=t.get(r,o);return e}(this);case"column":return function(t){let e=W(t.columns,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]*=t.get(r,o);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e*=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:o=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!D(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<o;i++){let o=0,a=0,h=0;for(let e=0;e<s;e++)h=t.get(i,e)-r[i],o+=h,a+=h*h;e?n.push((a-o*o/s)/(s-1)):n.push((a-o*o/s)/s)}return n}(this,r,o);case"column":if(!D(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<s;i++){let s=0,a=0,h=0;for(let e=0;e<o;e++)h=t.get(e,i)-r[i],s+=h,a+=h*h;e?n.push((a-s*s/o)/(o-1)):n.push((a-s*s/o)/o)}return n}(this,r,o);case void 0:if("number"!=typeof o)throw new TypeError("mean must be a number");return function(t,e,r){const o=t.rows,s=t.columns,n=o*s;let i=0,a=0,h=0;for(let e=0;e<o;e++)for(let o=0;o<s;o++)h=t.get(e,o)-r,i+=h,a+=h*h;return e?(a-i*i/n)/(n-1):(a-i*i/n)/n}(this,r,o);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!D(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[r])}(this,r),this;case"column":if(!D(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[o])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let o=0;for(let e=0;e<t.columns;e++)o+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(o))}return e}(this);else if(!D(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let o=0;for(let e=0;e<t.rows;e++)o+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(o))}return e}(this);else if(!D(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[o])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let o=0;o<t.columns;o++)for(let s=0;s<t.rows;s++)r+=Math.pow(t.get(s,o),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return j(this,t)}}function H(t,e){return t-e}G.prototype.klass="Matrix","undefined"!=typeof Symbol&&(G.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return j(this)}),G.random=G.rand,G.randomInt=G.randInt,G.diagonal=G.diag,G.prototype.diagonal=G.prototype.diag,G.identity=G.eye,G.prototype.negate=G.prototype.neg,G.prototype.tensorProduct=G.prototype.kroneckerProduct;class Y extends G{constructor(t,e){if(super(),Y.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!D(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let o=0;o<t;o++){if(r[o].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[o].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[o]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return L(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),L(this,t,!0),e=Float64Array.from(U(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){$(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let o=0;o<t;o++)r[o]=this.data[e][o];for(let o=t+1;o<this.columns;o++)r[o-1]=this.data[e][o];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),$(this,t,!0),e=B(this,e);for(let r=0;r<this.rows;r++){const o=new Float64Array(this.columns+1);let s=0;for(;s<t;s++)o[s]=this.data[r][s];for(o[s++]=e[r];s<this.columns+1;s++)o[s]=this.data[r][s-1];this.data[r]=o}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(G,Y);class Q extends G{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function X(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class Z{constructor(t,e={}){if((t=Q.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,o=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:n=!0,autoTranspose:i=!1}=e;let a,h=Boolean(s),u=Boolean(n),l=!1;if(r<o)if(i){a=t.transpose(),r=a.rows,o=a.columns,l=!0;let e=h;h=u,u=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,o),f=Math.min(r+1,o),d=new Float64Array(f),g=new Y(r,c),m=new Y(o,o),p=new Float64Array(o),w=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let v=Math.min(r-1,o),M=Math.max(0,Math.min(o-2,r)),b=Math.max(v,M);for(let t=0;t<b;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=X(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<o;e++){if(t<v&&0!==d[t]){let o=0;for(let s=t;s<r;s++)o+=a.get(s,t)*a.get(s,e);o=-o/a.get(t,t);for(let s=t;s<r;s++)a.set(s,e,a.get(s,e)+o*a.get(s,t))}p[e]=a.get(t,e)}if(h&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<M){p[t]=0;for(let e=t+1;e<o;e++)p[t]=X(p[t],p[e]);if(0!==p[t]){p[t+1]<0&&(p[t]=0-p[t]);for(let e=t+1;e<o;e++)p[e]/=p[t];p[t+1]+=1}if(p[t]=-p[t],t+1<r&&0!==p[t]){for(let e=t+1;e<r;e++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<o;r++)w[e]+=p[r]*a.get(e,r);for(let e=t+1;e<o;e++){let o=-p[e]/p[t+1];for(let s=t+1;s<r;s++)a.set(s,e,a.get(s,e)+o*w[s])}}if(u)for(let e=t+1;e<o;e++)m.set(e,t,p[e])}}let E=Math.min(o,r+1);if(v<o&&(d[v]=a.get(v,v)),r<E&&(d[E-1]=0),M+1<E&&(p[M]=a.get(M,E-1)),p[E-1]=0,h){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let o=0;for(let s=t;s<r;s++)o+=g.get(s,t)*g.get(s,e);o=-o/g.get(t,t);for(let s=t;s<r;s++)g.set(s,e,g.get(s,e)+o*g.get(s,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(u)for(let t=o-1;t>=0;t--){if(t<M&&0!==p[t])for(let e=t+1;e<o;e++){let r=0;for(let s=t+1;s<o;s++)r+=m.get(s,t)*m.get(s,e);r=-r/m.get(t+1,t);for(let s=t+1;s<o;s++)m.set(s,e,m.get(s,e)+r*m.get(s,t))}for(let e=0;e<o;e++)m.set(e,t,0);m.set(t,t,1)}let x=E-1,S=0,N=Number.EPSILON;for(;E>0;){let t,e;for(t=E-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+N*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[t]=0;break}}if(t===E-2)e=4;else{let r;for(r=E-1;r>=t&&r!==t;r--){let e=(r!==E?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(d[r])<=N*e){d[r]=0;break}}r===t?e=3:r===E-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[E-2];p[E-2]=0;for(let r=E-2;r>=t;r--){let s=X(d[r],e),n=d[r]/s,i=e/s;if(d[r]=s,r!==t&&(e=-i*p[r-1],p[r-1]=n*p[r-1]),u)for(let t=0;t<o;t++)s=n*m.get(t,r)+i*m.get(t,E-1),m.set(t,E-1,-i*m.get(t,r)+n*m.get(t,E-1)),m.set(t,r,s)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let o=t;o<E;o++){let s=X(d[o],e),n=d[o]/s,i=e/s;if(d[o]=s,e=-i*p[o],p[o]=n*p[o],h)for(let e=0;e<r;e++)s=n*g.get(e,o)+i*g.get(e,t-1),g.set(e,t-1,-i*g.get(e,o)+n*g.get(e,t-1)),g.set(e,o,s)}break}case 3:{const e=Math.max(Math.abs(d[E-1]),Math.abs(d[E-2]),Math.abs(p[E-2]),Math.abs(d[t]),Math.abs(p[t])),s=d[E-1]/e,n=d[E-2]/e,i=p[E-2]/e,a=d[t]/e,l=p[t]/e,c=((n+s)*(n-s)+i*i)/2,f=s*i*(s*i);let w=0;0===c&&0===f||(w=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),w=f/(c+w));let y=(a+s)*(a-s)+w,v=a*l;for(let e=t;e<E-1;e++){let s=X(y,v);0===s&&(s=Number.MIN_VALUE);let n=y/s,i=v/s;if(e!==t&&(p[e-1]=s),y=n*d[e]+i*p[e],p[e]=n*p[e]-i*d[e],v=i*d[e+1],d[e+1]=n*d[e+1],u)for(let t=0;t<o;t++)s=n*m.get(t,e)+i*m.get(t,e+1),m.set(t,e+1,-i*m.get(t,e)+n*m.get(t,e+1)),m.set(t,e,s);if(s=X(y,v),0===s&&(s=Number.MIN_VALUE),n=y/s,i=v/s,d[e]=s,y=n*p[e]+i*d[e+1],d[e+1]=-i*p[e]+n*d[e+1],v=i*p[e+1],p[e+1]=n*p[e+1],h&&e<r-1)for(let t=0;t<r;t++)s=n*g.get(t,e)+i*g.get(t,e+1),g.set(t,e+1,-i*g.get(t,e)+n*g.get(t,e+1)),g.set(t,e,s)}p[E-2]=y,S+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,u))for(let e=0;e<=x;e++)m.set(e,t,-m.get(e,t));for(;t<x&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,u&&t<o-1)for(let r=0;r<o;r++)e=m.get(r,t+1),m.set(r,t+1,m.get(r,t)),m.set(r,t,e);if(h&&t<r-1)for(let o=0;o<r;o++)e=g.get(o,t+1),g.set(o,t+1,g.get(o,t)),g.set(o,t,e);t++}S=0,E--}}if(l){let t=m;m=g,g=t}this.m=r,this.n=o,this.s=d,this.U=g,this.V=m}solve(t){let e=t,r=this.threshold,o=this.s.length,s=Y.zeros(o,o);for(let t=0;t<o;t++)Math.abs(this.s[t])<=r?s.set(t,t,0):s.set(t,t,1/this.s[t]);let n=this.U,i=this.rightSingularVectors,a=i.mmul(s),h=i.rows,u=n.rows,l=Y.zeros(h,u);for(let t=0;t<h;t++)for(let e=0;e<u;e++){let r=0;for(let s=0;s<o;s++)r+=a.get(t,s)*n.get(e,s);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(Y.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,o=t.columns,s=new Y(r,this.s.length);for(let n=0;n<r;n++)for(let r=0;r<o;r++)Math.abs(this.s[r])>e&&s.set(n,r,t.get(n,r)/this.s[r]);let n=this.U,i=n.rows,a=n.columns,h=new Y(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let o=0;o<a;o++)r+=s.get(t,o)*n.get(e,o);h.set(t,e,r)}return h}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let o=0,s=r.length;o<s;o++)r[o]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return Y.diag(this.s)}}var tt={center:[0,0],linkDistance:50},et=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",Object.assign(this.options,tt,t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,i=void 0===n?[0,0]:n,a=s.linkDistance,h=void 0===a?50:a,u=s.layoutInvisibles,f=s.onLayoutEnd,g=e.getAllNodes(),m=e.getAllEdges();if(u||(g=g.filter((function(t){return t.data.visible||void 0===t.data.visible})),m=m.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!g||0===g.length){var p={nodes:[],edges:m};return null==f||f(p),p}if(1===g.length){t&&e.mergeNodeData(g[0].id,{x:i[0],y:i[1]});var w={nodes:[o(o({},g[0]),{data:o(o({},g[0].data),{x:i[0],y:i[1]})})],edges:m};return null==f||f(w),w}var y=c({nodes:g,edges:m},!1),v=l(y);rt(v);var M=function(t,e){var r=[];return t.forEach((function(t){var o=[];t.forEach((function(t){o.push(t*e)})),r.push(o)})),r}(v,h),b=ot(M),E=[];b.forEach((function(t,e){var r=d(g[e]);r.data.x=t[0]+i[0],r.data.y=t[1]+i[1],E.push(r)})),t&&E.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var x={nodes:E,edges:m};return null==f||f(x),x},t}(),rt=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,o){r.forEach((function(r,s){r===1/0&&(t[o][s]=e)}))}))},ot=function(t){var e=Y.mul(Y.pow(t,2),-.5),r=e.mean("row"),o=e.mean("column"),s=e.mean();e.add(s).subRowVector(r).subColumnVector(o);var n=new Z(e),i=Y.sqrt(n.diagonalMatrix).diagonal();return n.leftSingularVectors.toJSON().map((function(t){return Y.mul([t],[i]).toJSON()[0].splice(0,2)}))},st={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},nt=function(t,e,r,o,s,n){e.forEach((function(i,a){r[a]={x:0,y:0},e.forEach((function(e,h){if(a!==h&&s[a]===s[h]){var u=i.x-e.x,l=i.y-e.y,c=Math.sqrt(u*u+l*l);if(0===c){c=1;var f=a>h?1:-1;u=.01*f,l=.01*f}if(c<n(t[a])/2+n(t[h])/2){var d=o*o/c;r[a].x+=u/c*d,r[a].y+=l/c*d}}}))}))},it=function(t,e,r,o,s,n,i,a){var h=n||i/10;return o&&e.forEach((function(e,r){var o=t[r].x-t[s].x,n=t[r].y-t[s].y,i=Math.sqrt(o*o+n*n),a=n/i,h=-o/i,u=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+h*e.y)/u);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,h*=-1);var c=Math.cos(l)*u;e.x=a*c,e.y=h*c})),t.forEach((function(n,i){if(i!==s){var u=Math.sqrt(e[i].x*e[i].x+e[i].y*e[i].y);if(u>0&&i!==s){var l=Math.min(h*(r/800),u);if(n.x+=e[i].x/u*l,n.y+=e[i].y/u*l,o){var c=n.x-t[s].x,f=n.y-t[s].y,d=Math.sqrt(c*c+f*f);c=c/d*a[i],f=f/d*a[i],n.x=t[s].x+c,n.y=t[s].y+f}}}})),t},at={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,strictRadial:!0,maxPreventOverlapIteration:200,sortBy:void 0,sortStrength:10},ht=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",Object.assign(this.options,at,t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,e,r){var a=o(o({},this.options),r),h=a.width,u=a.height,f=a.center,d=a.focusNode,g=a.unitRadius,m=a.nodeSize,p=a.nodeSpacing,w=a.strictRadial,y=a.preventOverlap,v=a.maxPreventOverlapIteration,M=a.sortBy,b=a.linkDistance,E=void 0===b?50:b,x=a.sortStrength,S=void 0===x?10:x,N=a.maxIteration,R=void 0===N?1e3:N,I=a.layoutInvisibles,k=a.onLayoutEnd,A=e.getAllNodes(),T=e.getAllEdges();if(I||(A=A.filter((function(t){return t.data.visible||void 0===t.data.visible})),T=T.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!A||0===A.length){var D={nodes:[],edges:T};return null==k||k(D),D}var C=h||"undefined"==typeof window?h:window.innerWidth,z=u||"undefined"==typeof window?u:window.innerHeight,P=f||[C/2,z/2];if(1===A.length){t&&e.mergeNodeData(A[0].id,{x:P[0],y:P[1]});var V={nodes:[o(o({},A[0]),{data:o(o({},A[0].data),{x:P[0],y:P[1]})})],edges:T};return null==k||k(V),V}var q=A[0];if(i(d)){for(var j=0;j<A.length;j++)if(A[j].id===d){q=A[j];break}}else q=d||A[0];var O=ft(A,q.id),F=c({nodes:A,edges:T},!1),L=l(F),$=gt(L,O);dt(L,O,$+1);var U=L[O],B=C-P[0]>P[0]?P[0]:C-P[0],K=z-P[1]>P[1]?P[1]:z-P[1];0===B&&(B=C/2),0===K&&(K=z/2);var W=Math.min(B,K),J=Math.max.apply(Math,n([],s(U),!1)),_=[],G=g||W/J;U.forEach((function(t,e){_[e]=t*G}));var H,Q=ut(A,L,E,_,G,M,S),X=lt(Q),tt=function(t,e,r){try{var o=Y.mul(Y.pow(e,2),-.5),s=o.mean("row"),n=o.mean("column"),i=o.mean();o.add(i).subRowVector(s).subColumnVector(n);var a=new Z(o),h=Y.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return Y.mul([e],[h]).toJSON()[0].splice(0,t)}))}catch(t){for(var u=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;u.push([c,f])}return u}}(E,Q,E).map((function(t){var e=s(t,2),r=e[0],o=e[1];return{x:(isNaN(r)?Math.random()*E:r)-tt[O].x,y:(isNaN(o)?Math.random()*E:o)-tt[O].y}}));if(this.run(R,tt,X,Q,_,O),y){H=mt(m,p);var et={nodes:A,nodeSizeFunc:H,positions:tt,radii:_,height:z,width:C,strictRadial:Boolean(w),focusIdx:O,iterations:v||200,k:tt.length/4.5};tt=function(t,e){for(var r=o(o({},st),e),s=r.positions,n=r.iterations,i=r.width,a=r.k,h=r.speed,u=void 0===h?100:h,l=r.strictRadial,c=r.focusIdx,f=r.radii,d=void 0===f?[]:f,g=r.nodeSizeFunc,m=t.getAllNodes(),p=[],w=i/10,y=0;y<n;y++)s.forEach((function(t,e){p[e]={x:0,y:0}})),nt(m,s,p,a,d,g),it(s,p,u,l,c,w,i,d);return s}(e,et)}var rt=[];tt.forEach((function(t,e){rt.push(o(o({},A[e]),{data:o(o({},A[0].data),{x:t.x+P[0],y:t.y+P[1]})}))})),t&&rt.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var ot={nodes:rt,edges:T};return null==k||k(ot),ot},t.prototype.run=function(t,e,r,o,s,n){for(var i=0;i<=t;i++){var a=i/t;this.oneIteration(a,e,s,o,r,n)}},t.prototype.oneIteration=function(t,e,r,o,s,n){var i=1-t;e.forEach((function(a,h){var u=ct(a,{x:0,y:0}),l=0===u?0:1/u;if(h!==n){var c=0,f=0,d=0;e.forEach((function(t,e){if(h!==e){var r=ct(a,t),n=0===r?0:1/r,i=o[e][h];d+=s[h][e],c+=s[h][e]*(t.x+i*(a.x-t.x)*n),f+=s[h][e]*(t.y+i*(a.y-t.y)*n)}}));var g=0===r[h]?0:1/r[h];d*=i,d+=t*g*g,c*=i,c+=t*g*a.x*l,a.x=c/d,f*=i,f+=t*g*a.y*l,a.y=f/d}}))},t}(),ut=function(t,e,r,o,s,n,a){if(!t)return[];var h=[];return e&&e.forEach((function(e,u){var l=[];e.forEach((function(e,h){if(u===h)l.push(0);else if(o[u]===o[h])if("data"===n)l.push(e*(Math.abs(u-h)*a)/(o[u]/s));else if(n){var c=t[u][n]||0,f=t[h][n]||0;i(c)&&(c=c.charCodeAt(0)),i(f)&&(f=f.charCodeAt(0)),l.push(e*(Math.abs(c-f)*a)/(o[u]/s))}else l.push(e*r/(o[u]/s));else{var d=(r+s)/2;l.push(e*d)}})),h.push(l)})),h},lt=function(t){for(var e=t.length,r=t[0].length,o=[],s=0;s<e;s++){for(var n=[],i=0;i<r;i++)0!==t[s][i]?n.push(1/(t[s][i]*t[s][i])):n.push(0);o.push(n)}return o},ct=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},ft=function(t,e){var r=-1;return t.forEach((function(t,o){t.id===e&&(r=o)})),Math.max(r,0)},dt=function(t,e,r){for(var o=t.length,s=0;s<o;s++)if(t[e][s]===1/0){t[e][s]=r,t[s][e]=r;for(var n=0;n<o;n++)t[s][n]!==1/0&&t[e][n]===1/0&&(t[e][n]=r+t[s][n],t[n][e]=r+t[s][n])}for(s=0;s<o;s++)if(s!==e)for(n=0;n<o;n++)if(t[s][n]===1/0){var i=Math.abs(t[e][s]-t[e][n]);i=0===i?1:i,t[s][n]=i}},gt=function(t,e){for(var r=0,o=0;o<t[e].length;o++)t[e][o]!==1/0&&(r=t[e][o]>r?t[e][o]:r);return r},mt=function(t,e){var r;return r=u(e)?function(){return e}:g(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){return t.data.bboxSize?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):t.data.size?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):f(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},pt={center:[0,0],width:300,height:300},wt={circular:w,concentric:b,mds:et,random:function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",Object.assign(this.options,pt,t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,i=s.width,a=s.height,h=s.layoutInvisibles,u=s.onLayoutEnd,l=e.getAllNodes();h||(l=l.filter((function(t){return t.data.visible||void 0===t.data.visible})));var c=i||"undefined"==typeof window?i:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=n||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var m={nodes:g,edges:e.getAllEdges()};return null==u||u(m),m},t}(),grid:x,radial:ht};function yt(t,e){var o=t.layout,s=o.id,n=o.options,i=t.nodes,a=t.edges,h=new r({nodes:i,edges:a}),u=wt[s];if(!u)throw new Error("Unknown layout id: "+s);return[new u(n).execute(h),e]}addEventListener("message",(function(t){var r,o=t.data,s=o.type,n=o.method,i=o.id,a=o.params;"RPC"===s&&n&&((r=e[n])?Promise.resolve().then((function(){return r.apply(e,a)})):Promise.reject("No such method")).then((function(t){postMessage({type:"RPC",id:i,result:t})})).catch((function(t){var e={message:t};t.stack&&(e.message=t.message,e.stack=t.stack,e.name=t.name),postMessage({type:"RPC",id:i,error:e})}))})),postMessage({type:"RPC",method:"ready"});\n//# sourceMappingURL=03710bc99fe066d705cb.worker.js.map'])),{name:"[fullhash].worker.js"});return URL.revokeObjectURL(URL.createObjectURL(new Blob(['var t={d:(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{calculateLayout:()=>yt});class r{nodeMap=new Map;edgeMap=new Map;inEdgesMap=new Map;outEdgesMap=new Map;treeIndices=new Map;changes=[];batchCount=0;onChanged=()=>{};constructor(t){t&&(t.nodes&&this.addNodes(t.nodes),t.edges&&this.addEdges(t.edges),t.tree&&this.addTree(t.tree),t.onChanged&&(this.onChanged=t.onChanged))}batch=t=>{this.batchCount+=1,t(),this.batchCount-=1,this.batchCount||this.commit()};commit(){const t=this.changes;this.changes=[],this.onChanged({graph:this,changes:t})}reduceChanges(t){let e=[];return t.forEach((t=>{switch(t.type){case"NodeRemoved":{let r=!1;e=e.filter((e=>{if("NodeAdded"===e.type){const o=e.value.id===t.value.id;return o&&(r=!0),!o}return"NodeDataUpdated"===e.type?e.id!==t.value.id:"TreeStructureChanged"!==e.type||e.nodeId!==t.value.id})),r||e.push(t);break}case"EdgeRemoved":{let r=!1;e=e.filter((e=>{if("EdgeAdded"===e.type){const o=e.value.id===t.value.id;return o&&(r=!0),!o}return"EdgeDataUpdated"!==e.type&&"EdgeUpdated"!==e.type||e.id!==t.value.id})),r||e.push(t);break}case"NodeDataUpdated":case"EdgeDataUpdated":case"EdgeUpdated":{const r=e.find((e=>e.type===t.type&&e.id===t.id&&e.propertyName===t.propertyName));r?r.newValue=t.newValue:e.push(t);break}case"TreeStructureDetached":e=e.filter((e=>"TreeStructureAttached"===e.type?e.treeKey!==t.treeKey:"TreeStructureChanged"!==e.type||e.treeKey!==t.treeKey)),e.push(t);break;case"TreeStructureChanged":{const r=e.find((e=>"TreeStructureChanged"===e.type&&e.treeKey===t.treeKey&&e.nodeId===t.nodeId));r?r.newParentId=t.newParentId:e.push(t);break}default:e.push(t)}})),e}checkNodeExistence(t){if(!this.hasNode(t))throw new Error("Node not found for id: "+t)}hasNode(t){return this.nodeMap.has(t)}areNeighbors(t,e){return this.checkNodeExistence(t),this.getNeighbors(e).some((e=>e.id===t))}getNode(t){return this.checkNodeExistence(t),this.nodeMap.get(t)}getRelatedEdges(t,e){this.checkNodeExistence(t);const r=this.inEdgesMap.get(t),o=this.outEdgesMap.get(t);if("in"===e)return Array.from(r);if("out"===e)return Array.from(o);const s=new Set([...r,...o]);return Array.from(s)}getDegree(t,e){return this.getRelatedEdges(t,e).length}getSuccessors(t){const e=this.getRelatedEdges(t,"out").map((t=>t.target));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getPredecessors(t){const e=this.getRelatedEdges(t,"in").map((t=>t.source));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getNeighbors(t){const e=this.getPredecessors(t),r=this.getSuccessors(t);return Array.from(new Set([...e,...r]))}doAddNode(t){if(this.hasNode(t.id))throw new Error("Node already exists: "+t.id);this.nodeMap.set(t.id,t),this.inEdgesMap.set(t.id,new Set),this.outEdgesMap.set(t.id,new Set),this.treeIndices.forEach((e=>{e.childrenMap.set(t.id,new Set)})),this.changes.push({type:"NodeAdded",value:t})}addNodes(t){this.batch((()=>{for(const e of t)this.doAddNode(e)}))}addNode(t){this.addNodes([t])}doRemoveNode(t){const e=this.getNode(t),r=this.inEdgesMap.get(t),o=this.outEdgesMap.get(t);r?.forEach((t=>this.doRemoveEdge(t.id))),o?.forEach((t=>this.doRemoveEdge(t.id))),this.nodeMap.delete(t),this.treeIndices.forEach((e=>{e.childrenMap.get(t)?.forEach((t=>{e.parentMap.delete(t.id)})),e.parentMap.delete(t),e.childrenMap.delete(t)})),this.changes.push({type:"NodeRemoved",value:e})}removeNodes(t){this.batch((()=>{t.forEach((t=>this.doRemoveNode(t)))}))}removeNode(t){this.removeNodes([t])}updateNodeData(t,e,r){const o=this.getNode(t);this.batch((()=>{const s=o.data[e],n=r;o.data[e]=n,this.changes.push({type:"NodeDataUpdated",id:t,propertyName:e,oldValue:s,newValue:n})}))}mergeNodeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateNodeData(t,e,r)}))}))}checkEdgeExistence(t){if(!this.hasEdge(t))throw new Error("Edge not found for id: "+t)}hasEdge(t){return this.edgeMap.has(t)}getEdge(t){return this.checkEdgeExistence(t),this.edgeMap.get(t)}getEdgeDetail(t){const e=this.getEdge(t);return{edge:e,source:this.getNode(e.source),target:this.getNode(e.target)}}doAddEdge(t){if(this.hasEdge(t.id))throw new Error("Edge already exists: "+t.id);this.checkNodeExistence(t.source),this.checkNodeExistence(t.target),this.edgeMap.set(t.id,t);const e=this.inEdgesMap.get(t.target),r=this.outEdgesMap.get(t.source);e.add(t),r.add(t),this.changes.push({type:"EdgeAdded",value:t})}addEdges(t){this.batch((()=>{for(const e of t)this.doAddEdge(e)}))}addEdge(t){this.addEdges([t])}doRemoveEdge(t){const e=this.getEdge(t),r=this.outEdgesMap.get(e.source),o=this.inEdgesMap.get(e.target);r.delete(e),o.delete(e),this.edgeMap.delete(t),this.changes.push({type:"EdgeRemoved",value:e})}removeEdges(t){this.batch((()=>{t.forEach((t=>this.doRemoveEdge(t)))}))}removeEdge(t){this.removeEdges([t])}updateEdgeSource(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const o=r.source,s=e;this.outEdgesMap.get(o).delete(r),this.outEdgesMap.get(s).add(r),r.source=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"source",oldValue:o,newValue:s})}))}updateEdgeTarget(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const o=r.target,s=e;this.inEdgesMap.get(o).delete(r),this.inEdgesMap.get(s).add(r),r.target=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"target",oldValue:o,newValue:s})}))}updateEdgeData(t,e,r){const o=this.getEdge(t);this.batch((()=>{const s=o.data[e],n=r;o.data[e]=n,this.changes.push({type:"EdgeDataUpdated",id:t,propertyName:e,oldValue:s,newValue:n})}))}mergeEdgeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateEdgeData(t,e,r)}))}))}checkTreeExistence(t){if(!this.treeIndices.has(t))throw new Error("Tree structure not found for treeKey: "+t)}attachTreeStructure(t){this.treeIndices.has(t)||(this.treeIndices.set(t,{parentMap:new Map,childrenMap:new Map}),this.batch((()=>{this.changes.push({type:"TreeStructureAttached",treeKey:t})})))}detachTreeStructure(t){this.checkTreeExistence(t),this.treeIndices.delete(t),this.batch((()=>{this.changes.push({type:"TreeStructureDetached",treeKey:t})}))}addTree(t,e){this.batch((()=>{this.attachTreeStructure(e);const r=[],o=Array.isArray(t)?t:[t];for(;o.length;){const t=o.shift();r.push(t),t.children&&o.push(...t.children)}this.addNodes(r),r.forEach((t=>{t.children?.forEach((r=>{this.setParent(r.id,t.id,e)}))}))}))}getRoots(t){return this.checkTreeExistence(t),this.getAllNodes().filter((e=>!this.getParent(e.id,t)))}getChildren(t,e){this.checkNodeExistence(t),this.checkTreeExistence(e);const r=this.treeIndices.get(e).childrenMap.get(t);return Array.from(r||[])}getParent(t,e){return this.checkNodeExistence(t),this.checkTreeExistence(e),this.treeIndices.get(e).parentMap.get(t)||null}setParent(t,e,r){this.checkTreeExistence(r);const o=this.treeIndices.get(r),s=this.getNode(t),n=o.parentMap.get(t),i=this.getNode(e);o.parentMap.set(t,i),n&&o.childrenMap.get(n.id)?.delete(s);let a=o.childrenMap.get(i.id);a||(a=new Set,o.childrenMap.set(i.id,a)),a.add(s),this.batch((()=>{this.changes.push({type:"TreeStructureChanged",treeKey:r,nodeId:t,oldParentId:n?.id,newParentId:i.id})}))}getAllNodes(){return Array.from(this.nodeMap.values())}getAllEdges(){return Array.from(this.edgeMap.values())}doBFS(t,e,r){for(;t.length;){const o=t.shift();r(o),e.add(o.id),this.getSuccessors(o.id).forEach((r=>{e.has(r.id)||(e.add(r.id),t.push(r))}))}}bfs(t,e){this.doBFS([this.getNode(t)],new Set,e)}doDFS(t,e,r){r(t),e.add(t.id),this.getSuccessors(t.id).forEach((t=>{e.has(t.id)||this.doDFS(t,e,r)}))}dfs(t,e){this.doDFS(this.getNode(t),new Set,e)}clone(){const t=this.getAllNodes().map((t=>({...t,data:{...t.data}}))),e=this.getAllEdges().map((t=>({...t,data:{...t.data}}))),o=new r({nodes:t,edges:e});return this.treeIndices.forEach((({parentMap:t,childrenMap:e},r)=>{const s=new Map;t.forEach(((t,e)=>{s.set(e,o.getNode(t.id))}));const n=new Map;e.forEach(((t,e)=>{n.set(e,new Set(Array.from(t).map((t=>o.getNode(t.id)))))})),o.treeIndices.set(r,{parentMap:s,childrenMap:n})})),o}toJSON(){return JSON.stringify({nodes:this.getAllNodes(),edges:this.getAllEdges()})}}var o=function(){return o=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++)for(var s in e=arguments[r])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},o.apply(this,arguments)};function s(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,s,n=r.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(t){s={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function n(t,e,r){if(r||2===arguments.length)for(var o,s=0,n=e.length;s<n;s++)!o&&s in e||(o||(o=Array.prototype.slice.call(e,0,s)),o[s]=e[s]);return t.concat(o||Array.prototype.slice.call(e))}Object.create,Object.create;var i=function(t){return"string"==typeof t},a=/-(\\w)/g,h=(function(t){return t.replace(a,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),u=function(t){return"number"==typeof t},l=function(t){for(var e=[],r=t.length,o=0;o<r;o+=1){e[o]=[];for(var s=0;s<r;s+=1)o===s?e[o][s]=0:0!==t[o][s]&&t[o][s]?e[o][s]=t[o][s]:e[o][s]=1/0}for(var n=0;n<r;n+=1)for(o=0;o<r;o+=1)for(s=0;s<r;s+=1)e[o][s]>e[o][n]+e[n][s]&&(e[o][s]=e[o][n]+e[n][s]);return e},c=function(t,e){var r=t.nodes,o=t.edges,s=[],n={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){n[t.id]=e,s.push([])})),null==o||o.forEach((function(t){var r=t.source,o=t.target,i=n[r],a=n[o];void 0!==i&&void 0!==a&&(s[i][a]=1,e||(s[a][i]=1))})),s},f=function(t){return null!==t&&"object"==typeof t},d=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var e=[];return t.forEach((function(t){e.push(t)})),e.map((function(t){return d(t)}))}if("object"==typeof t&&Object.keys(t).length){var r=o({},t);return Object.keys(r).forEach((function(t){r[t]=d(r[t])})),r}return t},g=function(t){return"function"==typeof t},m=function(t,e,r){return void 0===r&&(r=!0),e||0===e?g(e)?e:u(e)?function(){return e}:h(e)?function(){if(r){var o=Math.max.apply(Math,n([],s(e),!1));return isNaN(o)?t:o}return e}:f(e)?function(){if(r){var o=Math.max(e.width,e.height);return isNaN(o)?t:o}return[e.width,e.height]}:function(){return t}:function(e){return e.size?h(e.size)?e.size[0]>e.size[1]?e.size[0]:e.size[1]:f(e.size)?e.size.width>e.size.height?e.size.width:e.size.height:e.size:t}},p={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},w=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=o(o({},p),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){var r=this;t.batch((function(){r.genericCircularLayout(!0,t,e)}))},t.prototype.genericCircularLayout=function(t,e,r){var n=o(o({},this.options),r),i=n.width,a=n.height,h=n.center,u=n.divisions,l=n.startAngle,c=void 0===l?0:l,f=n.endAngle,g=void 0===f?2*Math.PI:f,p=n.angleRatio,w=n.ordering,M=n.clockwise,b=n.nodeSpacing,E=n.nodeSize,x=n.layoutInvisibles,S=n.onLayoutEnd,N=e.getAllNodes(),R=e.getAllEdges();x||(N=N.filter((function(t){return t.data.visible||void 0===t.data.visible})),R=R.filter((function(t){return t.data.visible||void 0===t.data.visible})));var I=N.length;if(0===I)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var k=s(v(i,a,h),3),A=k[0],T=k[1],D=k[2];if(1===I){t&&e.mergeNodeData(N[0].id,{x:D[0],y:D[1]});var C={nodes:[o(o({},N[0]),{data:o(o({},N[0].data),{x:D[0],y:D[1]})})],edges:R};return null==S||S(C),C}var z=(g-c)/I,P=n.radius,V=n.startRadius,q=n.endRadius;if(b){var j=m(10,b),O=m(10,E),F=-1/0;N.forEach((function(t){var e=O(t);F<e&&(F=e)}));var L=0;N.forEach((function(t,e){L+=0===e?F||10:(j(t)||0)+(F||10)})),P=L/(2*Math.PI)}else P||V||q?!V&&q?V=q:V&&!q&&(q=V):P=Math.min(T,A)/2;var $=z*p,U=[];U="topology"===w?y(e,N):"topology-directed"===w?y(e,N,!0):"degree"===w?function(t,e){var r=[];return e.forEach((function(t,e){r.push(d(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(e,N):N.map((function(t){return d(t)}));for(var B=Math.ceil(I/u),K=0;K<I;++K){var W=P;W||null===V||null===q||(W=V+K*(q-V)/(I-1)),W||(W=10+100*K/(I-1));var J=c+K%B*$+2*Math.PI/u*Math.floor(K/B);M||(J=g-K%B*$-2*Math.PI/u*Math.floor(K/B)),U[K].data.x=D[0]+Math.cos(J)*W,U[K].data.y=D[1]+Math.sin(J)*W}t&&U.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var _={nodes:U,edges:R};return null==S||S(_),_},t}(),y=function(t,e,r){void 0===r&&(r=!1);var o=[d(e[0])],s={},n=e.length;s[e[0].id]=!0;var i=0;return e.forEach((function(a,h){if(0!==h)if(h!==n-1&&t.getDegree(a.id,"both")===t.getDegree(e[h+1].id,"both")&&!t.areNeighbors(o[i].id,a.id)||s[a.id]){for(var u=r?t.getSuccessors(o[i].id):t.getNeighbors(o[i].id),l=!1,c=0;c<u.length;c++){var f=u[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!s[f.id]){o.push(d(f)),s[f.id]=!0,l=!0;break}}for(var g=0;!l&&(s[e[g].id]||(o.push(d(e[g])),s[e[g].id]=!0,l=!0),++g!==n););}else o.push(d(a)),s[a.id]=!0,i++})),o},v=function(t,e,r){var o=t,s=e,n=r;return o||"undefined"==typeof window||(o=window.innerWidth),s||"undefined"==typeof window||(s=window.innerHeight),n||(n=[o/2,s/2]),[o,s,n]},M={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},b=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",Object.assign(this.options,M,t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,a=s.width,l=s.height,c=s.sortBy,m=s.maxLevelDiff,p=s.sweep,w=s.clockwise,y=s.equidistant,v=s.minNodeSpacing,M=void 0===v?10:v,b=s.preventOverlap,E=s.startAngle,x=void 0===E?1.5*Math.PI:E,S=s.nodeSize,N=s.nodeSpacing,R=s.layoutInvisibles,I=s.onLayoutEnd,k=e.getAllNodes(),A=e.getAllEdges();R||(k=k.filter((function(t){return t.data.visible||void 0===t.data.visible})),A=A.filter((function(t){return t.data.visible||void 0===t.data.visible})));var T=k.length;if(0===T){var D={nodes:[],edges:A};return null==I||I(D),D}var C=a||"undefined"==typeof window?a:window.innerWidth,z=l||"undefined"==typeof window?l:window.innerHeight,P=n||[C/2,z/2];if(1===T){t&&e.mergeNodeData(k[0].id,{x:P[0],y:P[1]});var V={nodes:[o(o({},k[0]),{data:o(o({},k[0].data),{x:P[0],y:P[1]})})],edges:A};return null==I||I(V),V}var q,j=[],O=0;q=h(S)?Math.max(S[0],S[1]):S,h(N)?O=Math.max(N[0],N[1]):u(N)&&(O=N),k.forEach((function(t){j.push(d(t));var e=q;h(t.data.size)?e=Math.max(t.data.size[0],t.data.size[1]):u(t.data.size)?e=t.data.size:f(t.data.size)&&(e=Math.max(t.data.size.width,t.data.size.height)),q=Math.max(q,e),g(N)&&(O=Math.max(N(t),O))}));var F={};j.forEach((function(t,e){F[t.id]=e}));var L=c;i(L)&&void 0!==j[0].data[L]||(L="degree"),"degree"===L?j.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):j.sort((function(t,e){return e.data[L]-t.data[L]}));var $=j[0],U=m||$.data[L]/4,B=[{nodes:[]}],K=B[0];j.forEach((function(t){if(K.nodes.length>0){var e=Math.abs(K.nodes[0].data[L]-t.data[L]);U&&e>=U&&(K={nodes:[]},B.push(K))}K.nodes.push(t)}));var W=q+(O||M);if(!b){var J=B.length>0&&B[0].nodes.length>1,_=(Math.min(C,z)/2-W)/(B.length+(J?1:0));W=Math.min(W,_)}var G=0;if(B.forEach((function(t){var e=void 0===p?2*Math.PI-2*Math.PI/t.nodes.length:p;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&b){var r=Math.cos(t.dTheta)-Math.cos(0),o=Math.sin(t.dTheta)-Math.sin(0),s=Math.sqrt(W*W/(r*r+o*o));G=Math.max(s,G)}t.r=G,G+=W})),y){for(var H=0,Y=0,Q=0;Q<B.length;Q++){var X=(B[Q].r||0)-Y;H=Math.max(H,X)}Y=0,B.forEach((function(t,e){0===e&&(Y=t.r||0),t.r=Y,Y+=H}))}B.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,o){var s=x+(w?1:-1)*e*o;t.data.x=P[0]+r*Math.cos(s),t.data.y=P[1]+r*Math.sin(s)}))})),t&&j.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Z={nodes:j,edges:A};return null==I||I(Z),Z},t}(),E={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},x=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",Object.assign(this.options,E,t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.begin,a=void 0===n?[0,0]:n,u=s.condense,l=s.preventOverlapPadding,c=s.preventOverlap,f=s.columns,g=s.rows,p=s.cols,w=void 0===p?f:p,y=s.nodeSpacing,v=s.nodeSize,M=s.onLayoutEnd,b=s.position,E=s.sortBy,x=s.width,k=s.height,T=s.layoutInvisibles,D=e.getAllNodes(),C=e.getAllEdges();T||(D=D.filter((function(t){return t.data.visible||void 0===t.data.visible})),C=C.filter((function(t){return t.data.visible||void 0===t.data.visible})));var z=D.length;if(0===z){var P={nodes:[],edges:C};return null==M||M(P),P}if(1===z){t&&e.mergeNodeData(D[0].id,{x:a[0],y:a[1]});var V={nodes:[o(o({},D[0]),{data:o(o({},D[0].data),{x:a[0],y:a[1]})})],edges:C};return null==M||M(V),V}var q=D.map((function(t){return d(t)}));i(E)&&void 0!==q[0].data[E]||(E="degree"),"degree"===E?q.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):q.sort((function(t,e){return e.data[E]-t.data[E]}));var j=x||"undefined"==typeof window?x:window.innerWidth,O=k||"undefined"==typeof window?k:window.innerHeight,F=z,L={rows:g,cols:w};if(null!=g&&null!=w)L.rows=g,L.cols=w;else if(null!=g&&null==w)L.rows=g,L.cols=Math.ceil(F/L.rows);else if(null==g&&null!=w)L.cols=w,L.rows=Math.ceil(F/L.cols);else{var $=Math.sqrt(F*O/j);L.rows=Math.round($),L.cols=Math.round(j/O*$)}if(L.rows=Math.max(L.rows,1),L.cols=Math.max(L.cols,1),L.cols*L.rows>F)((B=S(L))-1)*(U=N(L))>=F?S(L,B-1):(U-1)*B>=F&&N(L,U-1);else for(;L.cols*L.rows<F;){var U,B=S(L);((U=N(L))+1)*B>=F?N(L,U+1):S(L,B+1)}var K=u?0:j/L.cols,W=u?0:O/L.rows;if(c||y){var J=m(10,y),_=m(30,v,!1);q.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var r,o,s=e.getNode(t.id),n=_(s)||30;h(n)?(r=n[0],o=n[1]):(r=n,o=n);var i=void 0!==J?J(t):l,a=r+i,u=o+i;K=Math.max(K,a),W=Math.max(W,u)}))}for(var G={},H={row:0,col:0},Y={},Q=0;Q<q.length;Q++){var X=q[Q],Z=void 0;if(b&&(Z=b(e.getNode(X.id))),Z&&(void 0!==Z.row||void 0!==Z.col)){var tt={row:Z.row,col:Z.col};if(void 0===tt.col)for(tt.col=0;R(G,tt);)tt.col++;else if(void 0===tt.row)for(tt.row=0;R(G,tt);)tt.row++;Y[X.id]=tt,I(G,tt)}A(X,a,K,W,Y,L,H,G)}var et={nodes:q,edges:C};return null==M||M(et),t&&q.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),et},t}(),S=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.min(o,s):Math.min(o,s)===t.rows?t.rows=e:t.cols=e,r},N=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.max(o,s):Math.max(o,s)===t.rows?t.rows=e:t.cols=e,r},R=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},I=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},k=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},A=function(t,e,r,o,s,n,i,a){var h,u,l=s[t.id];if(l)h=l.col*r+r/2+e[0],u=l.row*o+o/2+e[1];else{for(;R(a,i);)k(n,i);h=i.col*r+r/2+e[0],u=i.row*o+o/2+e[1],I(a,i),k(n,i)}t.data.x=h,t.data.y=u};const T=Object.prototype.toString;function D(t){return T.call(t).endsWith("Array]")}function C(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!D(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]>i&&(i=t[a]);return i}function z(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!D(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]<i&&(i=t[a]);return i}function P(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!D(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!D(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var o=z(t),s=C(t);if(o===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=r.min,i=void 0===n?r.autoMinMax?o:0:n,a=r.max,h=void 0===a?r.autoMinMax?s:1:a;if(i>=h)throw new RangeError("min option must be smaller than max option");for(var u=(h-i)/(s-o),l=0;l<t.length;l++)e[l]=(t[l]-o)*u+i;return e}const V=" ".repeat(2),q=" ".repeat(4);function j(t,e={}){const{maxRows:r=15,maxColumns:o=10,maxNumSize:s=8,padMinus:n="auto"}=e;return`${t.constructor.name} {\\n${V}[\\n${q}${function(t,e,r,o,s){const{rows:n,columns:i}=t,a=Math.min(n,e),h=Math.min(i,r),u=[];if("auto"===s){s=!1;t:for(let e=0;e<a;e++)for(let r=0;r<h;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let n=0;n<h;n++)r.push(O(t.get(e,n),o,s));u.push(`${r.join(" ")}`)}return h!==i&&(u[u.length-1]+=` ... ${i-r} more columns`),a!==n&&u.push(`... ${n-e} more rows`),u.join(`\\n${q}`)}(t,r,o,s,n)}\\n${V}]\\n${V}rows: ${t.rows}\\n${V}columns: ${t.columns}\\n}`}function O(t,e,r){return(t>=0&&r?` ${F(t,e-1)}`:F(t,e)).padEnd(e)}function F(t,e){let r=t.toString();if(r.length<=e)return r;let o=t.toFixed(e);if(o.length>e&&(o=t.toFixed(Math.max(0,e-(o.length-e)))),o.length<=e&&!o.startsWith("0.000")&&!o.startsWith("-0.000"))return o;let s=t.toExponential(e);return s.length>e&&(s=t.toExponential(Math.max(0,e-(s.length-e)))),s.slice(0)}function L(t,e,r){let o=r?t.rows:t.rows-1;if(e<0||e>o)throw new RangeError("Row index out of range")}function $(t,e,r){let o=r?t.columns:t.columns-1;if(e<0||e>o)throw new RangeError("Column index out of range")}function U(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function B(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function K(t,e,r,o,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(J("startRow",e),J("endRow",r),J("startColumn",o),J("endColumn",s),e>r||o>s||e<0||e>=t.rows||r<0||r>=t.rows||o<0||o>=t.columns||s<0||s>=t.columns)throw new RangeError("Submatrix indices are out of range")}function W(t,e=0){let r=[];for(let o=0;o<t;o++)r.push(e);return r}function J(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function _(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class G{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let o=new Y(t,e);for(let s=0;s<t;s++)for(let t=0;t<e;t++)o.set(s,t,r[s*e+t]);return o}static rowVector(t){let e=new Y(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new Y(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new Y(t,e)}static ones(t,e){return new Y(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:o=Math.random}=r;let s=new Y(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)s.set(r,t,o());return s}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:o=0,max:s=1e3,random:n=Math.random}=r;if(!Number.isInteger(o))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(o>=s)throw new RangeError("min must be smaller than max");let i=s-o,a=new Y(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=o+Math.round(n()*i);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let o=Math.min(t,e),s=this.zeros(t,e);for(let t=0;t<o;t++)s.set(t,t,r);return s}static diag(t,e,r){let o=t.length;void 0===e&&(e=o),void 0===r&&(r=e);let s=Math.min(o,e,r),n=this.zeros(e,r);for(let e=0;e<s;e++)n.set(e,e,t[e]);return n}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new Y(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.min(t.get(n,r),e.get(n,r)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new this(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.max(t.get(n,r),e.get(n,r)));return s}static checkMatrix(t){return G.isMatrix(t)?t:new Y(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);t++}return o}isReducedEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(o=!1);t++}return o}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let o=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(o,r)&&(o=s);if(0===t.get(o,r))r++;else{t.swapRows(e,o);let s=t.get(e,r);for(let o=r;o<t.columns;o++)t.set(e,o,t.get(e,o)/s);for(let o=e+1;o<t.rows;o++){let s=t.get(o,r)/t.get(e,r);t.set(o,r,0);for(let n=r+1;n<t.columns;n++)t.set(o,n,t.get(o,n)-t.get(e,n)*s)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,o=r-1;for(;o>=0;)if(0===t.maxRow(o))o--;else{let s=0,n=!1;for(;s<r&&!1===n;)1===t.get(o,s)?n=!0:s++;for(let r=0;r<o;r++){let n=t.get(r,s);for(let i=s;i<e;i++){let e=t.get(r,i)-n*t.get(o,i);t.set(r,i,e)}}o--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let o=new Y(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)o.setSubMatrix(this,this.rows*t,this.columns*e);return o}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){L(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return Y.rowVector(this.getRow(t))}setRow(t,e){L(this,t),e=U(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){L(this,t),L(this,e);for(let r=0;r<this.columns;r++){let o=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,o)}return this}getColumn(t){$(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return Y.columnVector(this.getColumn(t))}setColumn(t,e){$(this,t),e=B(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){$(this,t),$(this,e);for(let r=0;r<this.rows;r++){let o=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,o)}return this}addRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){L(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){$(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){_(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){_(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}maxRow(t){if(L(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){L(this,t),_(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)>e&&(e=this.get(t,o),r[1]=o);return r}minRow(t){if(L(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){L(this,t),_(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)<e&&(e=this.get(t,o),r[1]=o);return r}maxColumn(t){if($(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){$(this,t),_(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)>e&&(e=this.get(o,t),r[0]=o);return r}minColumn(t){if($(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){$(this,t),_(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)<e&&(e=this.get(o,t),r[0]=o);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){G.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let o=0;o<e.length;o++)r+=e[o]*t[o];return r}mmul(t){t=Y.checkMatrix(t);let e=this.rows,r=this.columns,o=t.columns,s=new Y(e,o),n=new Float64Array(r);for(let i=0;i<o;i++){for(let e=0;e<r;e++)n[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let o=0;o<r;o++)e+=this.get(t,o)*n[o];s.set(t,i,e)}}return s}strassen2x2(t){t=Y.checkMatrix(t);let e=new Y(2,2);const r=this.get(0,0),o=t.get(0,0),s=this.get(0,1),n=t.get(0,1),i=this.get(1,0),a=t.get(1,0),h=this.get(1,1),u=t.get(1,1),l=(r+h)*(o+u),c=(i+h)*o,f=r*(n-u),d=h*(a-o),g=(r+s)*u,m=l+d-g+(s-h)*(a+u),p=f+g,w=c+d,y=l-c+f+(i-r)*(o+n);return e.set(0,0,m),e.set(0,1,p),e.set(1,0,w),e.set(1,1,y),e}strassen3x3(t){t=Y.checkMatrix(t);let e=new Y(3,3);const r=this.get(0,0),o=this.get(0,1),s=this.get(0,2),n=this.get(1,0),i=this.get(1,1),a=this.get(1,2),h=this.get(2,0),u=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),m=t.get(1,1),p=t.get(1,2),w=t.get(2,0),y=t.get(2,1),v=t.get(2,2),M=(r-n)*(-f+m),b=(-r+n+i)*(c-f+m),E=(n+i)*(-c+f),x=r*c,S=(-r+h+u)*(c-d+p),N=(-r+h)*(d-p),R=(h+u)*(-c+d),I=(-s+u+l)*(m+w-y),k=(s-l)*(m-y),A=s*w,T=(u+l)*(-w+y),D=(-s+i+a)*(p+w-v),C=(s-a)*(p-v),z=(i+a)*(-w+v),P=x+A+o*g,V=(r+o+s-n-i-u-l)*m+b+E+x+I+A+T,q=x+S+R+(r+o+s-i-a-h-u)*p+A+D+z,j=M+i*(-c+f+g-m-p-w+v)+b+x+A+D+C,O=M+b+E+x+a*y,F=A+D+C+z+n*d,L=x+S+N+u*(-c+d+g-m-p-w+y)+I+k+A,$=I+k+A+T+h*f,U=x+S+N+R+l*v;return e.set(0,0,P),e.set(0,1,V),e.set(0,2,q),e.set(1,0,j),e.set(1,1,O),e.set(1,2,F),e.set(2,0,L),e.set(2,1,$),e.set(2,2,U),e}mmulStrassen(t){t=Y.checkMatrix(t);let e=this.clone(),r=e.rows,o=e.columns,s=t.rows,n=t.columns;function i(t,e,r){let o=t.rows,s=t.columns;if(o===e&&s===r)return t;{let o=G.zeros(e,r);return o=o.setSubMatrix(t,0,0),o}}o!==s&&console.warn(`Multiplying ${r} x ${o} and ${s} x ${n} matrix: dimensions do not match.`);let a=Math.max(r,s),h=Math.max(o,n);return e=i(e,a,h),function t(e,r,o,s){if(o<=512||s<=512)return e.mmul(r);o%2==1&&s%2==1?(e=i(e,o+1,s+1),r=i(r,o+1,s+1)):o%2==1?(e=i(e,o+1,s),r=i(r,o+1,s)):s%2==1&&(e=i(e,o,s+1),r=i(r,o,s+1));let n=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),h=e.subMatrix(0,n-1,0,a-1),u=r.subMatrix(0,n-1,0,a-1),l=e.subMatrix(0,n-1,a,e.columns-1),c=r.subMatrix(0,n-1,a,r.columns-1),f=e.subMatrix(n,e.rows-1,0,a-1),d=r.subMatrix(n,r.rows-1,0,a-1),g=e.subMatrix(n,e.rows-1,a,e.columns-1),m=r.subMatrix(n,r.rows-1,a,r.columns-1),p=t(G.add(h,g),G.add(u,m),n,a),w=t(G.add(f,g),u,n,a),y=t(h,G.sub(c,m),n,a),v=t(g,G.sub(d,u),n,a),M=t(G.add(h,l),m,n,a),b=t(G.sub(f,h),G.add(u,c),n,a),E=t(G.sub(l,g),G.add(d,m),n,a),x=G.add(p,v);x.sub(M),x.add(E);let S=G.add(y,M),N=G.add(w,v),R=G.sub(p,w);R.add(y),R.add(b);let I=G.zeros(2*x.rows,2*x.columns);return I=I.setSubMatrix(x,0,0),I=I.setSubMatrix(S,x.rows,0),I=I.setSubMatrix(N,0,x.columns),I=I.setSubMatrix(R,x.rows,x.columns),I.subMatrix(0,o-1,0,s-1)}(e,t=i(t,a,h),a,h)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new Y(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&P(s,{min:e,max:r,output:s}),o.setRow(t,s)}return o}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new Y(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&P(s,{min:e,max:r,output:s}),o.setColumn(t,s)}return o}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),o=this.get(e,this.columns-1-r);this.set(e,r,o),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),o=this.get(this.rows-1-r,e);this.set(r,e,o),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=Y.checkMatrix(t);let e=this.rows,r=this.columns,o=t.rows,s=t.columns,n=new Y(e*o,r*s);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<o;r++)for(let a=0;a<s;a++)n.set(o*i+r,s*e+a,this.get(i,e)*t.get(r,a));return n}kroneckerSum(t){if(t=Y.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,o=this.kroneckerProduct(Y.eye(r,r)),s=Y.eye(e,e).kroneckerProduct(t);return o.add(s)}transpose(){let t=new Y(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=H){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=H){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,o){K(this,t,e,r,o);let s=new Y(e-t+1,o-r+1);for(let n=t;n<=e;n++)for(let e=r;e<=o;e++)s.set(n-t,e-r,this.get(n,e));return s}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let o=new Y(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);o.set(s,n-e,this.get(t[s],n))}return o}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let o=new Y(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);o.set(n-e,s,this.get(n,t[s]))}return o}setSubMatrix(t,e,r){if((t=Y.checkMatrix(t)).isEmpty())return this;K(this,e,e+t.rows-1,r,r+t.columns-1);for(let o=0;o<t.rows;o++)for(let s=0;s<t.columns;s++)this.set(e+o,r+s,t.get(o,s));return this}selection(t,e){!function(t,e){if(!D(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!D(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new Y(t.length,e.length);for(let o=0;o<t.length;o++){let s=t[o];for(let t=0;t<e.length;t++){let n=e[t];r.set(o,t,this.get(s,n))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new Y(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=W(t.rows);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]+=t.get(r,o);return e}(this);case"column":return function(t){let e=W(t.columns);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]+=t.get(r,o);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e+=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=W(t.rows,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]*=t.get(r,o);return e}(this);case"column":return function(t){let e=W(t.columns,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]*=t.get(r,o);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e*=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:o=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!D(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<o;i++){let o=0,a=0,h=0;for(let e=0;e<s;e++)h=t.get(i,e)-r[i],o+=h,a+=h*h;e?n.push((a-o*o/s)/(s-1)):n.push((a-o*o/s)/s)}return n}(this,r,o);case"column":if(!D(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<s;i++){let s=0,a=0,h=0;for(let e=0;e<o;e++)h=t.get(e,i)-r[i],s+=h,a+=h*h;e?n.push((a-s*s/o)/(o-1)):n.push((a-s*s/o)/o)}return n}(this,r,o);case void 0:if("number"!=typeof o)throw new TypeError("mean must be a number");return function(t,e,r){const o=t.rows,s=t.columns,n=o*s;let i=0,a=0,h=0;for(let e=0;e<o;e++)for(let o=0;o<s;o++)h=t.get(e,o)-r,i+=h,a+=h*h;return e?(a-i*i/n)/(n-1):(a-i*i/n)/n}(this,r,o);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!D(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[r])}(this,r),this;case"column":if(!D(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[o])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let o=0;for(let e=0;e<t.columns;e++)o+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(o))}return e}(this);else if(!D(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let o=0;for(let e=0;e<t.rows;e++)o+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(o))}return e}(this);else if(!D(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[o])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let o=0;o<t.columns;o++)for(let s=0;s<t.rows;s++)r+=Math.pow(t.get(s,o),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return j(this,t)}}function H(t,e){return t-e}G.prototype.klass="Matrix","undefined"!=typeof Symbol&&(G.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return j(this)}),G.random=G.rand,G.randomInt=G.randInt,G.diagonal=G.diag,G.prototype.diagonal=G.prototype.diag,G.identity=G.eye,G.prototype.negate=G.prototype.neg,G.prototype.tensorProduct=G.prototype.kroneckerProduct;class Y extends G{constructor(t,e){if(super(),Y.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!D(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let o=0;o<t;o++){if(r[o].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[o].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[o]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return L(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),L(this,t,!0),e=Float64Array.from(U(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){$(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let o=0;o<t;o++)r[o]=this.data[e][o];for(let o=t+1;o<this.columns;o++)r[o-1]=this.data[e][o];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),$(this,t,!0),e=B(this,e);for(let r=0;r<this.rows;r++){const o=new Float64Array(this.columns+1);let s=0;for(;s<t;s++)o[s]=this.data[r][s];for(o[s++]=e[r];s<this.columns+1;s++)o[s]=this.data[r][s-1];this.data[r]=o}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(G,Y);class Q extends G{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function X(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class Z{constructor(t,e={}){if((t=Q.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,o=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:n=!0,autoTranspose:i=!1}=e;let a,h=Boolean(s),u=Boolean(n),l=!1;if(r<o)if(i){a=t.transpose(),r=a.rows,o=a.columns,l=!0;let e=h;h=u,u=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,o),f=Math.min(r+1,o),d=new Float64Array(f),g=new Y(r,c),m=new Y(o,o),p=new Float64Array(o),w=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let v=Math.min(r-1,o),M=Math.max(0,Math.min(o-2,r)),b=Math.max(v,M);for(let t=0;t<b;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=X(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<o;e++){if(t<v&&0!==d[t]){let o=0;for(let s=t;s<r;s++)o+=a.get(s,t)*a.get(s,e);o=-o/a.get(t,t);for(let s=t;s<r;s++)a.set(s,e,a.get(s,e)+o*a.get(s,t))}p[e]=a.get(t,e)}if(h&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<M){p[t]=0;for(let e=t+1;e<o;e++)p[t]=X(p[t],p[e]);if(0!==p[t]){p[t+1]<0&&(p[t]=0-p[t]);for(let e=t+1;e<o;e++)p[e]/=p[t];p[t+1]+=1}if(p[t]=-p[t],t+1<r&&0!==p[t]){for(let e=t+1;e<r;e++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<o;r++)w[e]+=p[r]*a.get(e,r);for(let e=t+1;e<o;e++){let o=-p[e]/p[t+1];for(let s=t+1;s<r;s++)a.set(s,e,a.get(s,e)+o*w[s])}}if(u)for(let e=t+1;e<o;e++)m.set(e,t,p[e])}}let E=Math.min(o,r+1);if(v<o&&(d[v]=a.get(v,v)),r<E&&(d[E-1]=0),M+1<E&&(p[M]=a.get(M,E-1)),p[E-1]=0,h){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let o=0;for(let s=t;s<r;s++)o+=g.get(s,t)*g.get(s,e);o=-o/g.get(t,t);for(let s=t;s<r;s++)g.set(s,e,g.get(s,e)+o*g.get(s,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(u)for(let t=o-1;t>=0;t--){if(t<M&&0!==p[t])for(let e=t+1;e<o;e++){let r=0;for(let s=t+1;s<o;s++)r+=m.get(s,t)*m.get(s,e);r=-r/m.get(t+1,t);for(let s=t+1;s<o;s++)m.set(s,e,m.get(s,e)+r*m.get(s,t))}for(let e=0;e<o;e++)m.set(e,t,0);m.set(t,t,1)}let x=E-1,S=0,N=Number.EPSILON;for(;E>0;){let t,e;for(t=E-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+N*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[t]=0;break}}if(t===E-2)e=4;else{let r;for(r=E-1;r>=t&&r!==t;r--){let e=(r!==E?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(d[r])<=N*e){d[r]=0;break}}r===t?e=3:r===E-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[E-2];p[E-2]=0;for(let r=E-2;r>=t;r--){let s=X(d[r],e),n=d[r]/s,i=e/s;if(d[r]=s,r!==t&&(e=-i*p[r-1],p[r-1]=n*p[r-1]),u)for(let t=0;t<o;t++)s=n*m.get(t,r)+i*m.get(t,E-1),m.set(t,E-1,-i*m.get(t,r)+n*m.get(t,E-1)),m.set(t,r,s)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let o=t;o<E;o++){let s=X(d[o],e),n=d[o]/s,i=e/s;if(d[o]=s,e=-i*p[o],p[o]=n*p[o],h)for(let e=0;e<r;e++)s=n*g.get(e,o)+i*g.get(e,t-1),g.set(e,t-1,-i*g.get(e,o)+n*g.get(e,t-1)),g.set(e,o,s)}break}case 3:{const e=Math.max(Math.abs(d[E-1]),Math.abs(d[E-2]),Math.abs(p[E-2]),Math.abs(d[t]),Math.abs(p[t])),s=d[E-1]/e,n=d[E-2]/e,i=p[E-2]/e,a=d[t]/e,l=p[t]/e,c=((n+s)*(n-s)+i*i)/2,f=s*i*(s*i);let w=0;0===c&&0===f||(w=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),w=f/(c+w));let y=(a+s)*(a-s)+w,v=a*l;for(let e=t;e<E-1;e++){let s=X(y,v);0===s&&(s=Number.MIN_VALUE);let n=y/s,i=v/s;if(e!==t&&(p[e-1]=s),y=n*d[e]+i*p[e],p[e]=n*p[e]-i*d[e],v=i*d[e+1],d[e+1]=n*d[e+1],u)for(let t=0;t<o;t++)s=n*m.get(t,e)+i*m.get(t,e+1),m.set(t,e+1,-i*m.get(t,e)+n*m.get(t,e+1)),m.set(t,e,s);if(s=X(y,v),0===s&&(s=Number.MIN_VALUE),n=y/s,i=v/s,d[e]=s,y=n*p[e]+i*d[e+1],d[e+1]=-i*p[e]+n*d[e+1],v=i*p[e+1],p[e+1]=n*p[e+1],h&&e<r-1)for(let t=0;t<r;t++)s=n*g.get(t,e)+i*g.get(t,e+1),g.set(t,e+1,-i*g.get(t,e)+n*g.get(t,e+1)),g.set(t,e,s)}p[E-2]=y,S+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,u))for(let e=0;e<=x;e++)m.set(e,t,-m.get(e,t));for(;t<x&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,u&&t<o-1)for(let r=0;r<o;r++)e=m.get(r,t+1),m.set(r,t+1,m.get(r,t)),m.set(r,t,e);if(h&&t<r-1)for(let o=0;o<r;o++)e=g.get(o,t+1),g.set(o,t+1,g.get(o,t)),g.set(o,t,e);t++}S=0,E--}}if(l){let t=m;m=g,g=t}this.m=r,this.n=o,this.s=d,this.U=g,this.V=m}solve(t){let e=t,r=this.threshold,o=this.s.length,s=Y.zeros(o,o);for(let t=0;t<o;t++)Math.abs(this.s[t])<=r?s.set(t,t,0):s.set(t,t,1/this.s[t]);let n=this.U,i=this.rightSingularVectors,a=i.mmul(s),h=i.rows,u=n.rows,l=Y.zeros(h,u);for(let t=0;t<h;t++)for(let e=0;e<u;e++){let r=0;for(let s=0;s<o;s++)r+=a.get(t,s)*n.get(e,s);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(Y.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,o=t.columns,s=new Y(r,this.s.length);for(let n=0;n<r;n++)for(let r=0;r<o;r++)Math.abs(this.s[r])>e&&s.set(n,r,t.get(n,r)/this.s[r]);let n=this.U,i=n.rows,a=n.columns,h=new Y(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let o=0;o<a;o++)r+=s.get(t,o)*n.get(e,o);h.set(t,e,r)}return h}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let o=0,s=r.length;o<s;o++)r[o]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return Y.diag(this.s)}}var tt={center:[0,0],linkDistance:50},et=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",Object.assign(this.options,tt,t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,i=void 0===n?[0,0]:n,a=s.linkDistance,h=void 0===a?50:a,u=s.layoutInvisibles,f=s.onLayoutEnd,g=e.getAllNodes(),m=e.getAllEdges();if(u||(g=g.filter((function(t){return t.data.visible||void 0===t.data.visible})),m=m.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!g||0===g.length){var p={nodes:[],edges:m};return null==f||f(p),p}if(1===g.length){t&&e.mergeNodeData(g[0].id,{x:i[0],y:i[1]});var w={nodes:[o(o({},g[0]),{data:o(o({},g[0].data),{x:i[0],y:i[1]})})],edges:m};return null==f||f(w),w}var y=c({nodes:g,edges:m},!1),v=l(y);rt(v);var M=function(t,e){var r=[];return t.forEach((function(t){var o=[];t.forEach((function(t){o.push(t*e)})),r.push(o)})),r}(v,h),b=ot(M),E=[];b.forEach((function(t,e){var r=d(g[e]);r.data.x=t[0]+i[0],r.data.y=t[1]+i[1],E.push(r)})),t&&E.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var x={nodes:E,edges:m};return null==f||f(x),x},t}(),rt=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,o){r.forEach((function(r,s){r===1/0&&(t[o][s]=e)}))}))},ot=function(t){var e=Y.mul(Y.pow(t,2),-.5),r=e.mean("row"),o=e.mean("column"),s=e.mean();e.add(s).subRowVector(r).subColumnVector(o);var n=new Z(e),i=Y.sqrt(n.diagonalMatrix).diagonal();return n.leftSingularVectors.toJSON().map((function(t){return Y.mul([t],[i]).toJSON()[0].splice(0,2)}))},st={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},nt=function(t,e,r,o,s,n){e.forEach((function(i,a){r[a]={x:0,y:0},e.forEach((function(e,h){if(a!==h&&s[a]===s[h]){var u=i.x-e.x,l=i.y-e.y,c=Math.sqrt(u*u+l*l);if(0===c){c=1;var f=a>h?1:-1;u=.01*f,l=.01*f}if(c<n(t[a])/2+n(t[h])/2){var d=o*o/c;r[a].x+=u/c*d,r[a].y+=l/c*d}}}))}))},it=function(t,e,r,o,s,n,i,a){var h=n||i/10;return o&&e.forEach((function(e,r){var o=t[r].x-t[s].x,n=t[r].y-t[s].y,i=Math.sqrt(o*o+n*n),a=n/i,h=-o/i,u=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+h*e.y)/u);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,h*=-1);var c=Math.cos(l)*u;e.x=a*c,e.y=h*c})),t.forEach((function(n,i){if(i!==s){var u=Math.sqrt(e[i].x*e[i].x+e[i].y*e[i].y);if(u>0&&i!==s){var l=Math.min(h*(r/800),u);if(n.x+=e[i].x/u*l,n.y+=e[i].y/u*l,o){var c=n.x-t[s].x,f=n.y-t[s].y,d=Math.sqrt(c*c+f*f);c=c/d*a[i],f=f/d*a[i],n.x=t[s].x+c,n.y=t[s].y+f}}}})),t},at={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,strictRadial:!0,maxPreventOverlapIteration:200,sortBy:void 0,sortStrength:10},ht=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",Object.assign(this.options,at,t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,e,r){var a=o(o({},this.options),r),h=a.width,u=a.height,f=a.center,d=a.focusNode,g=a.unitRadius,m=a.nodeSize,p=a.nodeSpacing,w=a.strictRadial,y=a.preventOverlap,v=a.maxPreventOverlapIteration,M=a.sortBy,b=a.linkDistance,E=void 0===b?50:b,x=a.sortStrength,S=void 0===x?10:x,N=a.maxIteration,R=void 0===N?1e3:N,I=a.layoutInvisibles,k=a.onLayoutEnd,A=e.getAllNodes(),T=e.getAllEdges();if(I||(A=A.filter((function(t){return t.data.visible||void 0===t.data.visible})),T=T.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!A||0===A.length){var D={nodes:[],edges:T};return null==k||k(D),D}var C=h||"undefined"==typeof window?h:window.innerWidth,z=u||"undefined"==typeof window?u:window.innerHeight,P=f||[C/2,z/2];if(1===A.length){t&&e.mergeNodeData(A[0].id,{x:P[0],y:P[1]});var V={nodes:[o(o({},A[0]),{data:o(o({},A[0].data),{x:P[0],y:P[1]})})],edges:T};return null==k||k(V),V}var q=A[0];if(i(d)){for(var j=0;j<A.length;j++)if(A[j].id===d){q=A[j];break}}else q=d||A[0];var O=ft(A,q.id),F=c({nodes:A,edges:T},!1),L=l(F),$=gt(L,O);dt(L,O,$+1);var U=L[O],B=C-P[0]>P[0]?P[0]:C-P[0],K=z-P[1]>P[1]?P[1]:z-P[1];0===B&&(B=C/2),0===K&&(K=z/2);var W=Math.min(B,K),J=Math.max.apply(Math,n([],s(U),!1)),_=[],G=g||W/J;U.forEach((function(t,e){_[e]=t*G}));var H,Q=ut(A,L,E,_,G,M,S),X=lt(Q),tt=function(t,e,r){try{var o=Y.mul(Y.pow(e,2),-.5),s=o.mean("row"),n=o.mean("column"),i=o.mean();o.add(i).subRowVector(s).subColumnVector(n);var a=new Z(o),h=Y.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return Y.mul([e],[h]).toJSON()[0].splice(0,t)}))}catch(t){for(var u=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;u.push([c,f])}return u}}(E,Q,E).map((function(t){var e=s(t,2),r=e[0],o=e[1];return{x:(isNaN(r)?Math.random()*E:r)-tt[O].x,y:(isNaN(o)?Math.random()*E:o)-tt[O].y}}));if(this.run(R,tt,X,Q,_,O),y){H=mt(m,p);var et={nodes:A,nodeSizeFunc:H,positions:tt,radii:_,height:z,width:C,strictRadial:Boolean(w),focusIdx:O,iterations:v||200,k:tt.length/4.5};tt=function(t,e){for(var r=o(o({},st),e),s=r.positions,n=r.iterations,i=r.width,a=r.k,h=r.speed,u=void 0===h?100:h,l=r.strictRadial,c=r.focusIdx,f=r.radii,d=void 0===f?[]:f,g=r.nodeSizeFunc,m=t.getAllNodes(),p=[],w=i/10,y=0;y<n;y++)s.forEach((function(t,e){p[e]={x:0,y:0}})),nt(m,s,p,a,d,g),it(s,p,u,l,c,w,i,d);return s}(e,et)}var rt=[];tt.forEach((function(t,e){rt.push(o(o({},A[e]),{data:o(o({},A[0].data),{x:t.x+P[0],y:t.y+P[1]})}))})),t&&rt.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var ot={nodes:rt,edges:T};return null==k||k(ot),ot},t.prototype.run=function(t,e,r,o,s,n){for(var i=0;i<=t;i++){var a=i/t;this.oneIteration(a,e,s,o,r,n)}},t.prototype.oneIteration=function(t,e,r,o,s,n){var i=1-t;e.forEach((function(a,h){var u=ct(a,{x:0,y:0}),l=0===u?0:1/u;if(h!==n){var c=0,f=0,d=0;e.forEach((function(t,e){if(h!==e){var r=ct(a,t),n=0===r?0:1/r,i=o[e][h];d+=s[h][e],c+=s[h][e]*(t.x+i*(a.x-t.x)*n),f+=s[h][e]*(t.y+i*(a.y-t.y)*n)}}));var g=0===r[h]?0:1/r[h];d*=i,d+=t*g*g,c*=i,c+=t*g*a.x*l,a.x=c/d,f*=i,f+=t*g*a.y*l,a.y=f/d}}))},t}(),ut=function(t,e,r,o,s,n,a){if(!t)return[];var h=[];return e&&e.forEach((function(e,u){var l=[];e.forEach((function(e,h){if(u===h)l.push(0);else if(o[u]===o[h])if("data"===n)l.push(e*(Math.abs(u-h)*a)/(o[u]/s));else if(n){var c=t[u][n]||0,f=t[h][n]||0;i(c)&&(c=c.charCodeAt(0)),i(f)&&(f=f.charCodeAt(0)),l.push(e*(Math.abs(c-f)*a)/(o[u]/s))}else l.push(e*r/(o[u]/s));else{var d=(r+s)/2;l.push(e*d)}})),h.push(l)})),h},lt=function(t){for(var e=t.length,r=t[0].length,o=[],s=0;s<e;s++){for(var n=[],i=0;i<r;i++)0!==t[s][i]?n.push(1/(t[s][i]*t[s][i])):n.push(0);o.push(n)}return o},ct=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},ft=function(t,e){var r=-1;return t.forEach((function(t,o){t.id===e&&(r=o)})),Math.max(r,0)},dt=function(t,e,r){for(var o=t.length,s=0;s<o;s++)if(t[e][s]===1/0){t[e][s]=r,t[s][e]=r;for(var n=0;n<o;n++)t[s][n]!==1/0&&t[e][n]===1/0&&(t[e][n]=r+t[s][n],t[n][e]=r+t[s][n])}for(s=0;s<o;s++)if(s!==e)for(n=0;n<o;n++)if(t[s][n]===1/0){var i=Math.abs(t[e][s]-t[e][n]);i=0===i?1:i,t[s][n]=i}},gt=function(t,e){for(var r=0,o=0;o<t[e].length;o++)t[e][o]!==1/0&&(r=t[e][o]>r?t[e][o]:r);return r},mt=function(t,e){var r;return r=u(e)?function(){return e}:g(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){return t.data.bboxSize?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):t.data.size?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):f(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},pt={center:[0,0],width:300,height:300},wt={circular:w,concentric:b,mds:et,random:function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",Object.assign(this.options,pt,t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,i=s.width,a=s.height,h=s.layoutInvisibles,u=s.onLayoutEnd,l=e.getAllNodes();h||(l=l.filter((function(t){return t.data.visible||void 0===t.data.visible})));var c=i||"undefined"==typeof window?i:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=n||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var m={nodes:g,edges:e.getAllEdges()};return null==u||u(m),m},t}(),grid:x,radial:ht};function yt(t,e){var o=t.layout,s=o.id,n=o.options,i=t.nodes,a=t.edges,h=new r({nodes:i,edges:a}),u=wt[s];if(!u)throw new Error("Unknown layout id: "+s);return[new u(n).execute(h),e]}addEventListener("message",(function(t){var r,o=t.data,s=o.type,n=o.method,i=o.id,a=o.params;"RPC"===s&&n&&((r=e[n])?Promise.resolve().then((function(){return r.apply(e,a)})):Promise.reject("No such method")).then((function(t){postMessage({type:"RPC",id:i,result:t})})).catch((function(t){var e={message:t};t.stack&&(e.message=t.message,e.stack=t.stack,e.name=t.name),postMessage({type:"RPC",id:i,error:e})}))})),postMessage({type:"RPC",method:"ready"});\n//# sourceMappingURL=03710bc99fe066d705cb.worker.js.map']))),o(t,s),t}},314:t=>{t.exports=function(t,e){var r=0,o={};t.addEventListener("message",(function(e){var r=e.data;if("RPC"===r.type)if(r.id){var s=o[r.id];s&&(delete o[r.id],r.error?s[1](Object.assign(Error(r.error.message),r.error)):s[0](r.result))}else{var n=document.createEvent("Event");n.initEvent(r.method,!1,!1),n.data=r.params,t.dispatchEvent(n)}})),e.forEach((function(e){t[e]=function(){var s=arguments;return new Promise((function(n,i){var a=++r;o[a]=[n,i],t.postMessage({type:"RPC",id:a,method:e,params:[].slice.call(s)})}))}}))}}},e={};function r(o){var s=e[o];if(void 0!==s)return s.exports;var n=e[o]={exports:{}};return t[o](n,n.exports,r),n.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var o={};(()=>{r.d(o,{SB:()=>w,W1:()=>I,Me:()=>k,AI:()=>at,D4:()=>gt,_5:()=>Et,y9:()=>N,Xp:()=>S,qR:()=>Nt,i_:()=>St});var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)},e=function(){return e=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++)for(var s in e=arguments[r])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},e.apply(this,arguments)};function s(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,s,n=r.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(t){s={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function n(t,e,r){if(r||2===arguments.length)for(var o,s=0,n=e.length;s<n;s++)!o&&s in e||(o||(o=Array.prototype.slice.call(e,0,s)),o[s]=e[s]);return t.concat(o||Array.prototype.slice.call(e))}Object.create,Object.create;var i=function(t){return"string"==typeof t},a=/-(\w)/g,h=(function(t){return t.replace(a,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),u=function(t){return"number"==typeof t},l=function(t){for(var e=[],r=t.length,o=0;o<r;o+=1){e[o]=[];for(var s=0;s<r;s+=1)o===s?e[o][s]=0:0!==t[o][s]&&t[o][s]?e[o][s]=t[o][s]:e[o][s]=1/0}for(var n=0;n<r;n+=1)for(o=0;o<r;o+=1)for(s=0;s<r;s+=1)e[o][s]>e[o][n]+e[n][s]&&(e[o][s]=e[o][n]+e[n][s]);return e},c=function(t,e){var r=t.nodes,o=t.edges,s=[],n={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){n[t.id]=e,s.push([])})),null==o||o.forEach((function(t){var r=t.source,o=t.target,i=n[r],a=n[o];void 0!==i&&void 0!==a&&(s[i][a]=1,e||(s[a][i]=1))})),s},f=function(t){return null!==t&&"object"==typeof t},d=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var r=[];return t.forEach((function(t){r.push(t)})),r.map((function(t){return d(t)}))}if("object"==typeof t&&Object.keys(t).length){var o=e({},t);return Object.keys(o).forEach((function(t){o[t]=d(o[t])})),o}return t},g=function(t){return"function"==typeof t},m=function(t,e,r){return void 0===r&&(r=!0),e||0===e?g(e)?e:u(e)?function(){return e}:h(e)?function(){if(r){var o=Math.max.apply(Math,n([],s(e),!1));return isNaN(o)?t:o}return e}:f(e)?function(){if(r){var o=Math.max(e.width,e.height);return isNaN(o)?t:o}return[e.width,e.height]}:function(){return t}:function(e){return e.size?h(e.size)?e.size[0]>e.size[1]?e.size[0]:e.size[1]:f(e.size)?e.size.width>e.size.height?e.size.width:e.size.height:e.size:t}},p={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},w=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=e(e({},p),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){var r=this;t.batch((function(){r.genericCircularLayout(!0,t,e)}))},t.prototype.genericCircularLayout=function(t,r,o){var n=e(e({},this.options),o),i=n.width,a=n.height,h=n.center,u=n.divisions,l=n.startAngle,c=void 0===l?0:l,f=n.endAngle,g=void 0===f?2*Math.PI:f,p=n.angleRatio,w=n.ordering,b=n.clockwise,M=n.nodeSpacing,x=n.nodeSize,E=n.layoutInvisibles,S=n.onLayoutEnd,N=r.getAllNodes(),R=r.getAllEdges();E||(N=N.filter((function(t){return t.data.visible||void 0===t.data.visible})),R=R.filter((function(t){return t.data.visible||void 0===t.data.visible})));var I=N.length;if(0===I)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var A=s(v(i,a,h),3),k=A[0],D=A[1],T=A[2];if(1===I){t&&r.mergeNodeData(N[0].id,{x:T[0],y:T[1]});var L={nodes:[e(e({},N[0]),{data:e(e({},N[0].data),{x:T[0],y:T[1]})})],edges:R};return null==S||S(L),L}var z=(g-c)/I,C=n.radius,P=n.startRadius,q=n.endRadius;if(M){var j=m(10,M),O=m(10,x),V=-1/0;N.forEach((function(t){var e=O(t);V<e&&(V=e)}));var F=0;N.forEach((function(t,e){F+=0===e?V||10:(j(t)||0)+(V||10)})),C=F/(2*Math.PI)}else C||P||q?!P&&q?P=q:P&&!q&&(q=P):C=Math.min(D,k)/2;var $=z*p,Y=[];Y="topology"===w?y(r,N):"topology-directed"===w?y(r,N,!0):"degree"===w?function(t,e){var r=[];return e.forEach((function(t,e){r.push(d(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(r,N):N.map((function(t){return d(t)}));for(var G=Math.ceil(I/u),U=0;U<I;++U){var _=C;_||null===P||null===q||(_=P+U*(q-P)/(I-1)),_||(_=10+100*U/(I-1));var B=c+U%G*$+2*Math.PI/u*Math.floor(U/G);b||(B=g-U%G*$-2*Math.PI/u*Math.floor(U/G)),Y[U].data.x=T[0]+Math.cos(B)*_,Y[U].data.y=T[1]+Math.sin(B)*_}t&&Y.forEach((function(t){r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var K={nodes:Y,edges:R};return null==S||S(K),K},t}(),y=function(t,e,r){void 0===r&&(r=!1);var o=[d(e[0])],s={},n=e.length;s[e[0].id]=!0;var i=0;return e.forEach((function(a,h){if(0!==h)if(h!==n-1&&t.getDegree(a.id,"both")===t.getDegree(e[h+1].id,"both")&&!t.areNeighbors(o[i].id,a.id)||s[a.id]){for(var u=r?t.getSuccessors(o[i].id):t.getNeighbors(o[i].id),l=!1,c=0;c<u.length;c++){var f=u[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!s[f.id]){o.push(d(f)),s[f.id]=!0,l=!0;break}}for(var g=0;!l&&(s[e[g].id]||(o.push(d(e[g])),s[e[g].id]=!0,l=!0),++g!==n););}else o.push(d(a)),s[a.id]=!0,i++})),o},v=function(t,e,r){var o=t,s=e,n=r;return o||"undefined"==typeof window||(o=window.innerWidth),s||"undefined"==typeof window||(s=window.innerHeight),n||(n=[o/2,s/2]),[o,s,n]},b=r(161),M=r.n(b),x=r(190),E=r.n(x),S={LAYOUT_ITERATION:"tick",LAYOUT_END:"layoutend"},N=function(e){function r(t,r,o){var s=e.call(this)||this;return s.graph=t,s.layout=r,s.spawnWorker(),s}return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function o(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}(r,e),r.prototype.spawnWorker=function(){this.worker&&this.worker.terminate(),this.worker=E()(),this.running&&(this.running=!1,this.start())},r.prototype.start=function(){var t=this;if(this.running)return this;this.running=!0;var e={layout:{id:this.layout.id,options:this.layout.options},nodes:this.graph.getAllNodes(),edges:this.graph.getAllEdges()},r=new Float32Array([0]);return this.worker.calculateLayout(e,[r]).then((function(e){var r=s(e,2),o=r[0];r[1],t.emit(S.LAYOUT_END,o)})),this},r.prototype.stop=function(){return this.running=!1,this},r.prototype.kill=function(){this.worker&&this.worker.terminate()},r.prototype.isRunning=function(){return this.running},r}(M()),R={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},I=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",Object.assign(this.options,R,t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,r,o){var s=e(e({},this.options),o),n=s.center,a=s.width,l=s.height,c=s.sortBy,m=s.maxLevelDiff,p=s.sweep,w=s.clockwise,y=s.equidistant,v=s.minNodeSpacing,b=void 0===v?10:v,M=s.preventOverlap,x=s.startAngle,E=void 0===x?1.5*Math.PI:x,S=s.nodeSize,N=s.nodeSpacing,R=s.layoutInvisibles,I=s.onLayoutEnd,A=r.getAllNodes(),k=r.getAllEdges();R||(A=A.filter((function(t){return t.data.visible||void 0===t.data.visible})),k=k.filter((function(t){return t.data.visible||void 0===t.data.visible})));var D=A.length;if(0===D){var T={nodes:[],edges:k};return null==I||I(T),T}var L=a||"undefined"==typeof window?a:window.innerWidth,z=l||"undefined"==typeof window?l:window.innerHeight,C=n||[L/2,z/2];if(1===D){t&&r.mergeNodeData(A[0].id,{x:C[0],y:C[1]});var P={nodes:[e(e({},A[0]),{data:e(e({},A[0].data),{x:C[0],y:C[1]})})],edges:k};return null==I||I(P),P}var q,j=[],O=0;q=h(S)?Math.max(S[0],S[1]):S,h(N)?O=Math.max(N[0],N[1]):u(N)&&(O=N),A.forEach((function(t){j.push(d(t));var e=q;h(t.data.size)?e=Math.max(t.data.size[0],t.data.size[1]):u(t.data.size)?e=t.data.size:f(t.data.size)&&(e=Math.max(t.data.size.width,t.data.size.height)),q=Math.max(q,e),g(N)&&(O=Math.max(N(t),O))}));var V={};j.forEach((function(t,e){V[t.id]=e}));var F=c;i(F)&&void 0!==j[0].data[F]||(F="degree"),"degree"===F?j.sort((function(t,e){return r.getDegree(e.id,"both")-r.getDegree(t.id,"both")})):j.sort((function(t,e){return e.data[F]-t.data[F]}));var $=j[0],Y=m||$.data[F]/4,G=[{nodes:[]}],U=G[0];j.forEach((function(t){if(U.nodes.length>0){var e=Math.abs(U.nodes[0].data[F]-t.data[F]);Y&&e>=Y&&(U={nodes:[]},G.push(U))}U.nodes.push(t)}));var _=q+(O||b);if(!M){var B=G.length>0&&G[0].nodes.length>1,K=(Math.min(L,z)/2-_)/(G.length+(B?1:0));_=Math.min(_,K)}var W=0;if(G.forEach((function(t){var e=void 0===p?2*Math.PI-2*Math.PI/t.nodes.length:p;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&M){var r=Math.cos(t.dTheta)-Math.cos(0),o=Math.sin(t.dTheta)-Math.sin(0),s=Math.sqrt(_*_/(r*r+o*o));W=Math.max(s,W)}t.r=W,W+=_})),y){for(var J=0,H=0,X=0;X<G.length;X++){var Q=(G[X].r||0)-H;J=Math.max(J,Q)}H=0,G.forEach((function(t,e){0===e&&(H=t.r||0),t.r=H,H+=J}))}G.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,o){var s=E+(w?1:-1)*e*o;t.data.x=C[0]+r*Math.cos(s),t.data.y=C[1]+r*Math.sin(s)}))})),t&&j.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Z={nodes:j,edges:k};return null==I||I(Z),Z},t}(),A={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},k=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",Object.assign(this.options,A,t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,r,o){var s=e(e({},this.options),o),n=s.begin,a=void 0===n?[0,0]:n,u=s.condense,l=s.preventOverlapPadding,c=s.preventOverlap,f=s.columns,g=s.rows,p=s.cols,w=void 0===p?f:p,y=s.nodeSpacing,v=s.nodeSize,b=s.onLayoutEnd,M=s.position,x=s.sortBy,E=s.width,S=s.height,N=s.layoutInvisibles,R=r.getAllNodes(),I=r.getAllEdges();N||(R=R.filter((function(t){return t.data.visible||void 0===t.data.visible})),I=I.filter((function(t){return t.data.visible||void 0===t.data.visible})));var A=R.length;if(0===A){var k={nodes:[],edges:I};return null==b||b(k),k}if(1===A){t&&r.mergeNodeData(R[0].id,{x:a[0],y:a[1]});var C={nodes:[e(e({},R[0]),{data:e(e({},R[0].data),{x:a[0],y:a[1]})})],edges:I};return null==b||b(C),C}var q=R.map((function(t){return d(t)}));i(x)&&void 0!==q[0].data[x]||(x="degree"),"degree"===x?q.sort((function(t,e){return r.getDegree(e.id,"both")-r.getDegree(t.id,"both")})):q.sort((function(t,e){return e.data[x]-t.data[x]}));var j=E||"undefined"==typeof window?E:window.innerWidth,O=S||"undefined"==typeof window?S:window.innerHeight,V=A,F={rows:g,cols:w};if(null!=g&&null!=w)F.rows=g,F.cols=w;else if(null!=g&&null==w)F.rows=g,F.cols=Math.ceil(V/F.rows);else if(null==g&&null!=w)F.cols=w,F.rows=Math.ceil(V/F.cols);else{var $=Math.sqrt(V*O/j);F.rows=Math.round($),F.cols=Math.round(j/O*$)}if(F.rows=Math.max(F.rows,1),F.cols=Math.max(F.cols,1),F.cols*F.rows>V)((G=D(F))-1)*(Y=T(F))>=V?D(F,G-1):(Y-1)*G>=V&&T(F,Y-1);else for(;F.cols*F.rows<V;){var Y,G=D(F);((Y=T(F))+1)*G>=V?T(F,Y+1):D(F,G+1)}var U=u?0:j/F.cols,_=u?0:O/F.rows;if(c||y){var B=m(10,y),K=m(30,v,!1);q.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var e,o,s=r.getNode(t.id),n=K(s)||30;h(n)?(e=n[0],o=n[1]):(e=n,o=n);var i=void 0!==B?B(t):l,a=e+i,u=o+i;U=Math.max(U,a),_=Math.max(_,u)}))}for(var W={},J={row:0,col:0},H={},X=0;X<q.length;X++){var Q=q[X],Z=void 0;if(M&&(Z=M(r.getNode(Q.id))),Z&&(void 0!==Z.row||void 0!==Z.col)){var tt={row:Z.row,col:Z.col};if(void 0===tt.col)for(tt.col=0;L(W,tt);)tt.col++;else if(void 0===tt.row)for(tt.row=0;L(W,tt);)tt.row++;H[Q.id]=tt,z(W,tt)}P(Q,a,U,_,H,F,J,W)}var et={nodes:q,edges:I};return null==b||b(et),t&&q.forEach((function(t){r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),et},t}(),D=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.min(o,s):Math.min(o,s)===t.rows?t.rows=e:t.cols=e,r},T=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.max(o,s):Math.max(o,s)===t.rows?t.rows=e:t.cols=e,r},L=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},z=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},C=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},P=function(t,e,r,o,s,n,i,a){var h,u,l=s[t.id];if(l)h=l.col*r+r/2+e[0],u=l.row*o+o/2+e[1];else{for(;L(a,i);)C(n,i);h=i.col*r+r/2+e[0],u=i.row*o+o/2+e[1],z(a,i),C(n,i)}t.data.x=h,t.data.y=u};const q=Object.prototype.toString;function j(t){return q.call(t).endsWith("Array]")}function O(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!j(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]>i&&(i=t[a]);return i}function V(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!j(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]<i&&(i=t[a]);return i}function F(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!j(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!j(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var o=V(t),s=O(t);if(o===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=r.min,i=void 0===n?r.autoMinMax?o:0:n,a=r.max,h=void 0===a?r.autoMinMax?s:1:a;if(i>=h)throw new RangeError("min option must be smaller than max option");for(var u=(h-i)/(s-o),l=0;l<t.length;l++)e[l]=(t[l]-o)*u+i;return e}const $=" ".repeat(2),Y=" ".repeat(4);function G(t,e={}){const{maxRows:r=15,maxColumns:o=10,maxNumSize:s=8,padMinus:n="auto"}=e;return`${t.constructor.name} {\n${$}[\n${Y}${function(t,e,r,o,s){const{rows:n,columns:i}=t,a=Math.min(n,e),h=Math.min(i,r),u=[];if("auto"===s){s=!1;t:for(let e=0;e<a;e++)for(let r=0;r<h;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let n=0;n<h;n++)r.push(U(t.get(e,n),o,s));u.push(`${r.join(" ")}`)}return h!==i&&(u[u.length-1]+=` ... ${i-r} more columns`),a!==n&&u.push(`... ${n-e} more rows`),u.join(`\n${Y}`)}(t,r,o,s,n)}\n${$}]\n${$}rows: ${t.rows}\n${$}columns: ${t.columns}\n}`}function U(t,e,r){return(t>=0&&r?` ${_(t,e-1)}`:_(t,e)).padEnd(e)}function _(t,e){let r=t.toString();if(r.length<=e)return r;let o=t.toFixed(e);if(o.length>e&&(o=t.toFixed(Math.max(0,e-(o.length-e)))),o.length<=e&&!o.startsWith("0.000")&&!o.startsWith("-0.000"))return o;let s=t.toExponential(e);return s.length>e&&(s=t.toExponential(Math.max(0,e-(s.length-e)))),s.slice(0)}function B(t,e,r){let o=r?t.rows:t.rows-1;if(e<0||e>o)throw new RangeError("Row index out of range")}function K(t,e,r){let o=r?t.columns:t.columns-1;if(e<0||e>o)throw new RangeError("Column index out of range")}function W(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function J(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function H(t,e,r,o,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(Q("startRow",e),Q("endRow",r),Q("startColumn",o),Q("endColumn",s),e>r||o>s||e<0||e>=t.rows||r<0||r>=t.rows||o<0||o>=t.columns||s<0||s>=t.columns)throw new RangeError("Submatrix indices are out of range")}function X(t,e=0){let r=[];for(let o=0;o<t;o++)r.push(e);return r}function Q(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function Z(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class tt{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let o=new rt(t,e);for(let s=0;s<t;s++)for(let t=0;t<e;t++)o.set(s,t,r[s*e+t]);return o}static rowVector(t){let e=new rt(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new rt(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new rt(t,e)}static ones(t,e){return new rt(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:o=Math.random}=r;let s=new rt(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)s.set(r,t,o());return s}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:o=0,max:s=1e3,random:n=Math.random}=r;if(!Number.isInteger(o))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(o>=s)throw new RangeError("min must be smaller than max");let i=s-o,a=new rt(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=o+Math.round(n()*i);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let o=Math.min(t,e),s=this.zeros(t,e);for(let t=0;t<o;t++)s.set(t,t,r);return s}static diag(t,e,r){let o=t.length;void 0===e&&(e=o),void 0===r&&(r=e);let s=Math.min(o,e,r),n=this.zeros(e,r);for(let e=0;e<s;e++)n.set(e,e,t[e]);return n}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new rt(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.min(t.get(n,r),e.get(n,r)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new this(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.max(t.get(n,r),e.get(n,r)));return s}static checkMatrix(t){return tt.isMatrix(t)?t:new rt(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);t++}return o}isReducedEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(o=!1);t++}return o}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let o=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(o,r)&&(o=s);if(0===t.get(o,r))r++;else{t.swapRows(e,o);let s=t.get(e,r);for(let o=r;o<t.columns;o++)t.set(e,o,t.get(e,o)/s);for(let o=e+1;o<t.rows;o++){let s=t.get(o,r)/t.get(e,r);t.set(o,r,0);for(let n=r+1;n<t.columns;n++)t.set(o,n,t.get(o,n)-t.get(e,n)*s)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,o=r-1;for(;o>=0;)if(0===t.maxRow(o))o--;else{let s=0,n=!1;for(;s<r&&!1===n;)1===t.get(o,s)?n=!0:s++;for(let r=0;r<o;r++){let n=t.get(r,s);for(let i=s;i<e;i++){let e=t.get(r,i)-n*t.get(o,i);t.set(r,i,e)}}o--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let o=new rt(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)o.setSubMatrix(this,this.rows*t,this.columns*e);return o}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){B(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return rt.rowVector(this.getRow(t))}setRow(t,e){B(this,t),e=W(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){B(this,t),B(this,e);for(let r=0;r<this.columns;r++){let o=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,o)}return this}getColumn(t){K(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return rt.columnVector(this.getColumn(t))}setColumn(t,e){K(this,t),e=J(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){K(this,t),K(this,e);for(let r=0;r<this.rows;r++){let o=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,o)}return this}addRowVector(t){t=W(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=W(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=W(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=W(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=J(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=J(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=J(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=J(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){B(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){K(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){Z(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){Z(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}maxRow(t){if(B(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){B(this,t),Z(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)>e&&(e=this.get(t,o),r[1]=o);return r}minRow(t){if(B(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){B(this,t),Z(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)<e&&(e=this.get(t,o),r[1]=o);return r}maxColumn(t){if(K(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){K(this,t),Z(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)>e&&(e=this.get(o,t),r[0]=o);return r}minColumn(t){if(K(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){K(this,t),Z(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)<e&&(e=this.get(o,t),r[0]=o);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){tt.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let o=0;o<e.length;o++)r+=e[o]*t[o];return r}mmul(t){t=rt.checkMatrix(t);let e=this.rows,r=this.columns,o=t.columns,s=new rt(e,o),n=new Float64Array(r);for(let i=0;i<o;i++){for(let e=0;e<r;e++)n[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let o=0;o<r;o++)e+=this.get(t,o)*n[o];s.set(t,i,e)}}return s}strassen2x2(t){t=rt.checkMatrix(t);let e=new rt(2,2);const r=this.get(0,0),o=t.get(0,0),s=this.get(0,1),n=t.get(0,1),i=this.get(1,0),a=t.get(1,0),h=this.get(1,1),u=t.get(1,1),l=(r+h)*(o+u),c=(i+h)*o,f=r*(n-u),d=h*(a-o),g=(r+s)*u,m=l+d-g+(s-h)*(a+u),p=f+g,w=c+d,y=l-c+f+(i-r)*(o+n);return e.set(0,0,m),e.set(0,1,p),e.set(1,0,w),e.set(1,1,y),e}strassen3x3(t){t=rt.checkMatrix(t);let e=new rt(3,3);const r=this.get(0,0),o=this.get(0,1),s=this.get(0,2),n=this.get(1,0),i=this.get(1,1),a=this.get(1,2),h=this.get(2,0),u=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),m=t.get(1,1),p=t.get(1,2),w=t.get(2,0),y=t.get(2,1),v=t.get(2,2),b=(r-n)*(-f+m),M=(-r+n+i)*(c-f+m),x=(n+i)*(-c+f),E=r*c,S=(-r+h+u)*(c-d+p),N=(-r+h)*(d-p),R=(h+u)*(-c+d),I=(-s+u+l)*(m+w-y),A=(s-l)*(m-y),k=s*w,D=(u+l)*(-w+y),T=(-s+i+a)*(p+w-v),L=(s-a)*(p-v),z=(i+a)*(-w+v),C=E+k+o*g,P=(r+o+s-n-i-u-l)*m+M+x+E+I+k+D,q=E+S+R+(r+o+s-i-a-h-u)*p+k+T+z,j=b+i*(-c+f+g-m-p-w+v)+M+E+k+T+L,O=b+M+x+E+a*y,V=k+T+L+z+n*d,F=E+S+N+u*(-c+d+g-m-p-w+y)+I+A+k,$=I+A+k+D+h*f,Y=E+S+N+R+l*v;return e.set(0,0,C),e.set(0,1,P),e.set(0,2,q),e.set(1,0,j),e.set(1,1,O),e.set(1,2,V),e.set(2,0,F),e.set(2,1,$),e.set(2,2,Y),e}mmulStrassen(t){t=rt.checkMatrix(t);let e=this.clone(),r=e.rows,o=e.columns,s=t.rows,n=t.columns;function i(t,e,r){let o=t.rows,s=t.columns;if(o===e&&s===r)return t;{let o=tt.zeros(e,r);return o=o.setSubMatrix(t,0,0),o}}o!==s&&console.warn(`Multiplying ${r} x ${o} and ${s} x ${n} matrix: dimensions do not match.`);let a=Math.max(r,s),h=Math.max(o,n);return e=i(e,a,h),function t(e,r,o,s){if(o<=512||s<=512)return e.mmul(r);o%2==1&&s%2==1?(e=i(e,o+1,s+1),r=i(r,o+1,s+1)):o%2==1?(e=i(e,o+1,s),r=i(r,o+1,s)):s%2==1&&(e=i(e,o,s+1),r=i(r,o,s+1));let n=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),h=e.subMatrix(0,n-1,0,a-1),u=r.subMatrix(0,n-1,0,a-1),l=e.subMatrix(0,n-1,a,e.columns-1),c=r.subMatrix(0,n-1,a,r.columns-1),f=e.subMatrix(n,e.rows-1,0,a-1),d=r.subMatrix(n,r.rows-1,0,a-1),g=e.subMatrix(n,e.rows-1,a,e.columns-1),m=r.subMatrix(n,r.rows-1,a,r.columns-1),p=t(tt.add(h,g),tt.add(u,m),n,a),w=t(tt.add(f,g),u,n,a),y=t(h,tt.sub(c,m),n,a),v=t(g,tt.sub(d,u),n,a),b=t(tt.add(h,l),m,n,a),M=t(tt.sub(f,h),tt.add(u,c),n,a),x=t(tt.sub(l,g),tt.add(d,m),n,a),E=tt.add(p,v);E.sub(b),E.add(x);let S=tt.add(y,b),N=tt.add(w,v),R=tt.sub(p,w);R.add(y),R.add(M);let I=tt.zeros(2*E.rows,2*E.columns);return I=I.setSubMatrix(E,0,0),I=I.setSubMatrix(S,E.rows,0),I=I.setSubMatrix(N,0,E.columns),I=I.setSubMatrix(R,E.rows,E.columns),I.subMatrix(0,o-1,0,s-1)}(e,t=i(t,a,h),a,h)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new rt(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&F(s,{min:e,max:r,output:s}),o.setRow(t,s)}return o}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new rt(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&F(s,{min:e,max:r,output:s}),o.setColumn(t,s)}return o}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),o=this.get(e,this.columns-1-r);this.set(e,r,o),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),o=this.get(this.rows-1-r,e);this.set(r,e,o),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=rt.checkMatrix(t);let e=this.rows,r=this.columns,o=t.rows,s=t.columns,n=new rt(e*o,r*s);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<o;r++)for(let a=0;a<s;a++)n.set(o*i+r,s*e+a,this.get(i,e)*t.get(r,a));return n}kroneckerSum(t){if(t=rt.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,o=this.kroneckerProduct(rt.eye(r,r)),s=rt.eye(e,e).kroneckerProduct(t);return o.add(s)}transpose(){let t=new rt(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=et){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=et){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,o){H(this,t,e,r,o);let s=new rt(e-t+1,o-r+1);for(let n=t;n<=e;n++)for(let e=r;e<=o;e++)s.set(n-t,e-r,this.get(n,e));return s}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let o=new rt(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);o.set(s,n-e,this.get(t[s],n))}return o}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let o=new rt(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);o.set(n-e,s,this.get(n,t[s]))}return o}setSubMatrix(t,e,r){if((t=rt.checkMatrix(t)).isEmpty())return this;H(this,e,e+t.rows-1,r,r+t.columns-1);for(let o=0;o<t.rows;o++)for(let s=0;s<t.columns;s++)this.set(e+o,r+s,t.get(o,s));return this}selection(t,e){!function(t,e){if(!j(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!j(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new rt(t.length,e.length);for(let o=0;o<t.length;o++){let s=t[o];for(let t=0;t<e.length;t++){let n=e[t];r.set(o,t,this.get(s,n))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new rt(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=X(t.rows);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]+=t.get(r,o);return e}(this);case"column":return function(t){let e=X(t.columns);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]+=t.get(r,o);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e+=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=X(t.rows,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]*=t.get(r,o);return e}(this);case"column":return function(t){let e=X(t.columns,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]*=t.get(r,o);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e*=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:o=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!j(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<o;i++){let o=0,a=0,h=0;for(let e=0;e<s;e++)h=t.get(i,e)-r[i],o+=h,a+=h*h;e?n.push((a-o*o/s)/(s-1)):n.push((a-o*o/s)/s)}return n}(this,r,o);case"column":if(!j(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<s;i++){let s=0,a=0,h=0;for(let e=0;e<o;e++)h=t.get(e,i)-r[i],s+=h,a+=h*h;e?n.push((a-s*s/o)/(o-1)):n.push((a-s*s/o)/o)}return n}(this,r,o);case void 0:if("number"!=typeof o)throw new TypeError("mean must be a number");return function(t,e,r){const o=t.rows,s=t.columns,n=o*s;let i=0,a=0,h=0;for(let e=0;e<o;e++)for(let o=0;o<s;o++)h=t.get(e,o)-r,i+=h,a+=h*h;return e?(a-i*i/n)/(n-1):(a-i*i/n)/n}(this,r,o);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!j(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[r])}(this,r),this;case"column":if(!j(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[o])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let o=0;for(let e=0;e<t.columns;e++)o+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(o))}return e}(this);else if(!j(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let o=0;for(let e=0;e<t.rows;e++)o+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(o))}return e}(this);else if(!j(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[o])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let o=0;o<t.columns;o++)for(let s=0;s<t.rows;s++)r+=Math.pow(t.get(s,o),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return G(this,t)}}function et(t,e){return t-e}tt.prototype.klass="Matrix","undefined"!=typeof Symbol&&(tt.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return G(this)}),tt.random=tt.rand,tt.randomInt=tt.randInt,tt.diagonal=tt.diag,tt.prototype.diagonal=tt.prototype.diag,tt.identity=tt.eye,tt.prototype.negate=tt.prototype.neg,tt.prototype.tensorProduct=tt.prototype.kroneckerProduct;class rt extends tt{constructor(t,e){if(super(),rt.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!j(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let o=0;o<t;o++){if(r[o].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[o].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[o]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return B(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),B(this,t,!0),e=Float64Array.from(W(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){K(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let o=0;o<t;o++)r[o]=this.data[e][o];for(let o=t+1;o<this.columns;o++)r[o-1]=this.data[e][o];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),K(this,t,!0),e=J(this,e);for(let r=0;r<this.rows;r++){const o=new Float64Array(this.columns+1);let s=0;for(;s<t;s++)o[s]=this.data[r][s];for(o[s++]=e[r];s<this.columns+1;s++)o[s]=this.data[r][s-1];this.data[r]=o}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(tt,rt);class ot extends tt{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function st(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class nt{constructor(t,e={}){if((t=ot.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,o=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:n=!0,autoTranspose:i=!1}=e;let a,h=Boolean(s),u=Boolean(n),l=!1;if(r<o)if(i){a=t.transpose(),r=a.rows,o=a.columns,l=!0;let e=h;h=u,u=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,o),f=Math.min(r+1,o),d=new Float64Array(f),g=new rt(r,c),m=new rt(o,o),p=new Float64Array(o),w=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let v=Math.min(r-1,o),b=Math.max(0,Math.min(o-2,r)),M=Math.max(v,b);for(let t=0;t<M;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=st(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<o;e++){if(t<v&&0!==d[t]){let o=0;for(let s=t;s<r;s++)o+=a.get(s,t)*a.get(s,e);o=-o/a.get(t,t);for(let s=t;s<r;s++)a.set(s,e,a.get(s,e)+o*a.get(s,t))}p[e]=a.get(t,e)}if(h&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<b){p[t]=0;for(let e=t+1;e<o;e++)p[t]=st(p[t],p[e]);if(0!==p[t]){p[t+1]<0&&(p[t]=0-p[t]);for(let e=t+1;e<o;e++)p[e]/=p[t];p[t+1]+=1}if(p[t]=-p[t],t+1<r&&0!==p[t]){for(let e=t+1;e<r;e++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<o;r++)w[e]+=p[r]*a.get(e,r);for(let e=t+1;e<o;e++){let o=-p[e]/p[t+1];for(let s=t+1;s<r;s++)a.set(s,e,a.get(s,e)+o*w[s])}}if(u)for(let e=t+1;e<o;e++)m.set(e,t,p[e])}}let x=Math.min(o,r+1);if(v<o&&(d[v]=a.get(v,v)),r<x&&(d[x-1]=0),b+1<x&&(p[b]=a.get(b,x-1)),p[x-1]=0,h){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let o=0;for(let s=t;s<r;s++)o+=g.get(s,t)*g.get(s,e);o=-o/g.get(t,t);for(let s=t;s<r;s++)g.set(s,e,g.get(s,e)+o*g.get(s,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(u)for(let t=o-1;t>=0;t--){if(t<b&&0!==p[t])for(let e=t+1;e<o;e++){let r=0;for(let s=t+1;s<o;s++)r+=m.get(s,t)*m.get(s,e);r=-r/m.get(t+1,t);for(let s=t+1;s<o;s++)m.set(s,e,m.get(s,e)+r*m.get(s,t))}for(let e=0;e<o;e++)m.set(e,t,0);m.set(t,t,1)}let E=x-1,S=0,N=Number.EPSILON;for(;x>0;){let t,e;for(t=x-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+N*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[t]=0;break}}if(t===x-2)e=4;else{let r;for(r=x-1;r>=t&&r!==t;r--){let e=(r!==x?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(d[r])<=N*e){d[r]=0;break}}r===t?e=3:r===x-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[x-2];p[x-2]=0;for(let r=x-2;r>=t;r--){let s=st(d[r],e),n=d[r]/s,i=e/s;if(d[r]=s,r!==t&&(e=-i*p[r-1],p[r-1]=n*p[r-1]),u)for(let t=0;t<o;t++)s=n*m.get(t,r)+i*m.get(t,x-1),m.set(t,x-1,-i*m.get(t,r)+n*m.get(t,x-1)),m.set(t,r,s)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let o=t;o<x;o++){let s=st(d[o],e),n=d[o]/s,i=e/s;if(d[o]=s,e=-i*p[o],p[o]=n*p[o],h)for(let e=0;e<r;e++)s=n*g.get(e,o)+i*g.get(e,t-1),g.set(e,t-1,-i*g.get(e,o)+n*g.get(e,t-1)),g.set(e,o,s)}break}case 3:{const e=Math.max(Math.abs(d[x-1]),Math.abs(d[x-2]),Math.abs(p[x-2]),Math.abs(d[t]),Math.abs(p[t])),s=d[x-1]/e,n=d[x-2]/e,i=p[x-2]/e,a=d[t]/e,l=p[t]/e,c=((n+s)*(n-s)+i*i)/2,f=s*i*(s*i);let w=0;0===c&&0===f||(w=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),w=f/(c+w));let y=(a+s)*(a-s)+w,v=a*l;for(let e=t;e<x-1;e++){let s=st(y,v);0===s&&(s=Number.MIN_VALUE);let n=y/s,i=v/s;if(e!==t&&(p[e-1]=s),y=n*d[e]+i*p[e],p[e]=n*p[e]-i*d[e],v=i*d[e+1],d[e+1]=n*d[e+1],u)for(let t=0;t<o;t++)s=n*m.get(t,e)+i*m.get(t,e+1),m.set(t,e+1,-i*m.get(t,e)+n*m.get(t,e+1)),m.set(t,e,s);if(s=st(y,v),0===s&&(s=Number.MIN_VALUE),n=y/s,i=v/s,d[e]=s,y=n*p[e]+i*d[e+1],d[e+1]=-i*p[e]+n*d[e+1],v=i*p[e+1],p[e+1]=n*p[e+1],h&&e<r-1)for(let t=0;t<r;t++)s=n*g.get(t,e)+i*g.get(t,e+1),g.set(t,e+1,-i*g.get(t,e)+n*g.get(t,e+1)),g.set(t,e,s)}p[x-2]=y,S+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,u))for(let e=0;e<=E;e++)m.set(e,t,-m.get(e,t));for(;t<E&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,u&&t<o-1)for(let r=0;r<o;r++)e=m.get(r,t+1),m.set(r,t+1,m.get(r,t)),m.set(r,t,e);if(h&&t<r-1)for(let o=0;o<r;o++)e=g.get(o,t+1),g.set(o,t+1,g.get(o,t)),g.set(o,t,e);t++}S=0,x--}}if(l){let t=m;m=g,g=t}this.m=r,this.n=o,this.s=d,this.U=g,this.V=m}solve(t){let e=t,r=this.threshold,o=this.s.length,s=rt.zeros(o,o);for(let t=0;t<o;t++)Math.abs(this.s[t])<=r?s.set(t,t,0):s.set(t,t,1/this.s[t]);let n=this.U,i=this.rightSingularVectors,a=i.mmul(s),h=i.rows,u=n.rows,l=rt.zeros(h,u);for(let t=0;t<h;t++)for(let e=0;e<u;e++){let r=0;for(let s=0;s<o;s++)r+=a.get(t,s)*n.get(e,s);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(rt.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,o=t.columns,s=new rt(r,this.s.length);for(let n=0;n<r;n++)for(let r=0;r<o;r++)Math.abs(this.s[r])>e&&s.set(n,r,t.get(n,r)/this.s[r]);let n=this.U,i=n.rows,a=n.columns,h=new rt(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let o=0;o<a;o++)r+=s.get(t,o)*n.get(e,o);h.set(t,e,r)}return h}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let o=0,s=r.length;o<s;o++)r[o]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return rt.diag(this.s)}}var it={center:[0,0],linkDistance:50},at=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",Object.assign(this.options,it,t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,r,o){var s=e(e({},this.options),o),n=s.center,i=void 0===n?[0,0]:n,a=s.linkDistance,h=void 0===a?50:a,u=s.layoutInvisibles,f=s.onLayoutEnd,g=r.getAllNodes(),m=r.getAllEdges();if(u||(g=g.filter((function(t){return t.data.visible||void 0===t.data.visible})),m=m.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!g||0===g.length){var p={nodes:[],edges:m};return null==f||f(p),p}if(1===g.length){t&&r.mergeNodeData(g[0].id,{x:i[0],y:i[1]});var w={nodes:[e(e({},g[0]),{data:e(e({},g[0].data),{x:i[0],y:i[1]})})],edges:m};return null==f||f(w),w}var y=c({nodes:g,edges:m},!1),v=l(y);ht(v);var b=function(t,e){var r=[];return t.forEach((function(t){var o=[];t.forEach((function(t){o.push(t*e)})),r.push(o)})),r}(v,h),M=ut(b),x=[];M.forEach((function(t,e){var r=d(g[e]);r.data.x=t[0]+i[0],r.data.y=t[1]+i[1],x.push(r)})),t&&x.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var E={nodes:x,edges:m};return null==f||f(E),E},t}(),ht=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,o){r.forEach((function(r,s){r===1/0&&(t[o][s]=e)}))}))},ut=function(t){var e=rt.mul(rt.pow(t,2),-.5),r=e.mean("row"),o=e.mean("column"),s=e.mean();e.add(s).subRowVector(r).subColumnVector(o);var n=new nt(e),i=rt.sqrt(n.diagonalMatrix).diagonal();return n.leftSingularVectors.toJSON().map((function(t){return rt.mul([t],[i]).toJSON()[0].splice(0,2)}))},lt={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},ct=function(t,e,r,o,s,n){e.forEach((function(i,a){r[a]={x:0,y:0},e.forEach((function(e,h){if(a!==h&&s[a]===s[h]){var u=i.x-e.x,l=i.y-e.y,c=Math.sqrt(u*u+l*l);if(0===c){c=1;var f=a>h?1:-1;u=.01*f,l=.01*f}if(c<n(t[a])/2+n(t[h])/2){var d=o*o/c;r[a].x+=u/c*d,r[a].y+=l/c*d}}}))}))},ft=function(t,e,r,o,s,n,i,a){var h=n||i/10;return o&&e.forEach((function(e,r){var o=t[r].x-t[s].x,n=t[r].y-t[s].y,i=Math.sqrt(o*o+n*n),a=n/i,h=-o/i,u=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+h*e.y)/u);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,h*=-1);var c=Math.cos(l)*u;e.x=a*c,e.y=h*c})),t.forEach((function(n,i){if(i!==s){var u=Math.sqrt(e[i].x*e[i].x+e[i].y*e[i].y);if(u>0&&i!==s){var l=Math.min(h*(r/800),u);if(n.x+=e[i].x/u*l,n.y+=e[i].y/u*l,o){var c=n.x-t[s].x,f=n.y-t[s].y,d=Math.sqrt(c*c+f*f);c=c/d*a[i],f=f/d*a[i],n.x=t[s].x+c,n.y=t[s].y+f}}}})),t},dt={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,strictRadial:!0,maxPreventOverlapIteration:200,sortBy:void 0,sortStrength:10},gt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",Object.assign(this.options,dt,t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,r,o){var a=e(e({},this.options),o),h=a.width,u=a.height,f=a.center,d=a.focusNode,g=a.unitRadius,m=a.nodeSize,p=a.nodeSpacing,w=a.strictRadial,y=a.preventOverlap,v=a.maxPreventOverlapIteration,b=a.sortBy,M=a.linkDistance,x=void 0===M?50:M,E=a.sortStrength,S=void 0===E?10:E,N=a.maxIteration,R=void 0===N?1e3:N,I=a.layoutInvisibles,A=a.onLayoutEnd,k=r.getAllNodes(),D=r.getAllEdges();if(I||(k=k.filter((function(t){return t.data.visible||void 0===t.data.visible})),D=D.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!k||0===k.length){var T={nodes:[],edges:D};return null==A||A(T),T}var L=h||"undefined"==typeof window?h:window.innerWidth,z=u||"undefined"==typeof window?u:window.innerHeight,C=f||[L/2,z/2];if(1===k.length){t&&r.mergeNodeData(k[0].id,{x:C[0],y:C[1]});var P={nodes:[e(e({},k[0]),{data:e(e({},k[0].data),{x:C[0],y:C[1]})})],edges:D};return null==A||A(P),P}var q=k[0];if(i(d)){for(var j=0;j<k.length;j++)if(k[j].id===d){q=k[j];break}}else q=d||k[0];var O=yt(k,q.id),V=c({nodes:k,edges:D},!1),F=l(V),$=bt(F,O);vt(F,O,$+1);var Y=F[O],G=L-C[0]>C[0]?C[0]:L-C[0],U=z-C[1]>C[1]?C[1]:z-C[1];0===G&&(G=L/2),0===U&&(U=z/2);var _=Math.min(G,U),B=Math.max.apply(Math,n([],s(Y),!1)),K=[],W=g||_/B;Y.forEach((function(t,e){K[e]=t*W}));var J,H=mt(k,F,x,K,W,b,S),X=pt(H),Q=function(t,e,r){try{var o=rt.mul(rt.pow(e,2),-.5),s=o.mean("row"),n=o.mean("column"),i=o.mean();o.add(i).subRowVector(s).subColumnVector(n);var a=new nt(o),h=rt.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return rt.mul([e],[h]).toJSON()[0].splice(0,t)}))}catch(t){for(var u=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;u.push([c,f])}return u}}(x,H,x).map((function(t){var e=s(t,2),r=e[0],o=e[1];return{x:(isNaN(r)?Math.random()*x:r)-Q[O].x,y:(isNaN(o)?Math.random()*x:o)-Q[O].y}}));if(this.run(R,Q,X,H,K,O),y){J=Mt(m,p);var Z={nodes:k,nodeSizeFunc:J,positions:Q,radii:K,height:z,width:L,strictRadial:Boolean(w),focusIdx:O,iterations:v||200,k:Q.length/4.5};Q=function(t,r){for(var o=e(e({},lt),r),s=o.positions,n=o.iterations,i=o.width,a=o.k,h=o.speed,u=void 0===h?100:h,l=o.strictRadial,c=o.focusIdx,f=o.radii,d=void 0===f?[]:f,g=o.nodeSizeFunc,m=t.getAllNodes(),p=[],w=i/10,y=0;y<n;y++)s.forEach((function(t,e){p[e]={x:0,y:0}})),ct(m,s,p,a,d,g),ft(s,p,u,l,c,w,i,d);return s}(r,Z)}var tt=[];Q.forEach((function(t,r){tt.push(e(e({},k[r]),{data:e(e({},k[0].data),{x:t.x+C[0],y:t.y+C[1]})}))})),t&&tt.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var et={nodes:tt,edges:D};return null==A||A(et),et},t.prototype.run=function(t,e,r,o,s,n){for(var i=0;i<=t;i++){var a=i/t;this.oneIteration(a,e,s,o,r,n)}},t.prototype.oneIteration=function(t,e,r,o,s,n){var i=1-t;e.forEach((function(a,h){var u=wt(a,{x:0,y:0}),l=0===u?0:1/u;if(h!==n){var c=0,f=0,d=0;e.forEach((function(t,e){if(h!==e){var r=wt(a,t),n=0===r?0:1/r,i=o[e][h];d+=s[h][e],c+=s[h][e]*(t.x+i*(a.x-t.x)*n),f+=s[h][e]*(t.y+i*(a.y-t.y)*n)}}));var g=0===r[h]?0:1/r[h];d*=i,d+=t*g*g,c*=i,c+=t*g*a.x*l,a.x=c/d,f*=i,f+=t*g*a.y*l,a.y=f/d}}))},t}(),mt=function(t,e,r,o,s,n,a){if(!t)return[];var h=[];return e&&e.forEach((function(e,u){var l=[];e.forEach((function(e,h){if(u===h)l.push(0);else if(o[u]===o[h])if("data"===n)l.push(e*(Math.abs(u-h)*a)/(o[u]/s));else if(n){var c=t[u][n]||0,f=t[h][n]||0;i(c)&&(c=c.charCodeAt(0)),i(f)&&(f=f.charCodeAt(0)),l.push(e*(Math.abs(c-f)*a)/(o[u]/s))}else l.push(e*r/(o[u]/s));else{var d=(r+s)/2;l.push(e*d)}})),h.push(l)})),h},pt=function(t){for(var e=t.length,r=t[0].length,o=[],s=0;s<e;s++){for(var n=[],i=0;i<r;i++)0!==t[s][i]?n.push(1/(t[s][i]*t[s][i])):n.push(0);o.push(n)}return o},wt=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},yt=function(t,e){var r=-1;return t.forEach((function(t,o){t.id===e&&(r=o)})),Math.max(r,0)},vt=function(t,e,r){for(var o=t.length,s=0;s<o;s++)if(t[e][s]===1/0){t[e][s]=r,t[s][e]=r;for(var n=0;n<o;n++)t[s][n]!==1/0&&t[e][n]===1/0&&(t[e][n]=r+t[s][n],t[n][e]=r+t[s][n])}for(s=0;s<o;s++)if(s!==e)for(n=0;n<o;n++)if(t[s][n]===1/0){var i=Math.abs(t[e][s]-t[e][n]);i=0===i?1:i,t[s][n]=i}},bt=function(t,e){for(var r=0,o=0;o<t[e].length;o++)t[e][o]!==1/0&&(r=t[e][o]>r?t[e][o]:r);return r},Mt=function(t,e){var r;return r=u(e)?function(){return e}:g(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){return t.data.bboxSize?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):t.data.size?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):f(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},xt={center:[0,0],width:300,height:300},Et=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",Object.assign(this.options,xt,t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,r,o){var s=e(e({},this.options),o),n=s.center,i=s.width,a=s.height,h=s.layoutInvisibles,u=s.onLayoutEnd,l=r.getAllNodes();h||(l=l.filter((function(t){return t.data.visible||void 0===t.data.visible})));var c=i||"undefined"==typeof window?i:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=n||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var m={nodes:g,edges:r.getAllEdges()};return null==u||u(m),m},t}(),St={circular:w,concentric:I,mds:at,random:Et,grid:k,radial:gt};function Nt(t,e){St[t]=e}})();var s=o.SB,n=o.W1,i=o.Me,a=o.AI,h=o.D4,u=o._5,l=o.y9,c=o.Xp,f=o.qR,d=o.i_;export{s as CircularLayout,n as ConcentricLayout,i as GridLayout,a as MDSLayout,h as RadialLayout,u as RandomLayout,l as Supervisor,c as SupervisorEvent,f as registerLayout,d as registry};
|
|
1
|
+
var t={161:t=>{var e=Object.prototype.hasOwnProperty,r="~";function o(){}function s(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function n(t,e,o,n,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var a=new s(o,n||t,i),h=r?r+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],a]:t._events[h].push(a):(t._events[h]=a,t._eventsCount++),t}function i(t,e){0==--t._eventsCount?t._events=new o:delete t._events[e]}function a(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(r=!1)),a.prototype.eventNames=function(){var t,o,s=[];if(0===this._eventsCount)return s;for(o in t=this._events)e.call(t,o)&&s.push(r?o.slice(1):o);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(t)):s},a.prototype.listeners=function(t){var e=r?r+t:t,o=this._events[e];if(!o)return[];if(o.fn)return[o.fn];for(var s=0,n=o.length,i=new Array(n);s<n;s++)i[s]=o[s].fn;return i},a.prototype.listenerCount=function(t){var e=r?r+t:t,o=this._events[e];return o?o.fn?1:o.length:0},a.prototype.emit=function(t,e,o,s,n,i){var a=r?r+t:t;if(!this._events[a])return!1;var h,u,l=this._events[a],c=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),c){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,o),!0;case 4:return l.fn.call(l.context,e,o,s),!0;case 5:return l.fn.call(l.context,e,o,s,n),!0;case 6:return l.fn.call(l.context,e,o,s,n,i),!0}for(u=1,h=new Array(c-1);u<c;u++)h[u-1]=arguments[u];l.fn.apply(l.context,h)}else{var f,d=l.length;for(u=0;u<d;u++)switch(l[u].once&&this.removeListener(t,l[u].fn,void 0,!0),c){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,e);break;case 3:l[u].fn.call(l[u].context,e,o);break;case 4:l[u].fn.call(l[u].context,e,o,s);break;default:if(!h)for(f=1,h=new Array(c-1);f<c;f++)h[f-1]=arguments[f];l[u].fn.apply(l[u].context,h)}}return!0},a.prototype.on=function(t,e,r){return n(this,t,e,r,!1)},a.prototype.once=function(t,e,r){return n(this,t,e,r,!0)},a.prototype.removeListener=function(t,e,o,s){var n=r?r+t:t;if(!this._events[n])return this;if(!e)return i(this,n),this;var a=this._events[n];if(a.fn)a.fn!==e||s&&!a.once||o&&a.context!==o||i(this,n);else{for(var h=0,u=[],l=a.length;h<l;h++)(a[h].fn!==e||s&&!a[h].once||o&&a[h].context!==o)&&u.push(a[h]);u.length?this._events[n]=1===u.length?u[0]:u:i(this,n)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=r?r+t:t,this._events[e]&&i(this,e)):(this._events=new o,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,t.exports=a},825:(t,e,r)=>{var o=r(475),s=["calculateLayout"];t.exports=function(){var t=new Worker(URL.createObjectURL(new Blob(['var t={d:(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{calculateLayout:()=>yt});class r{nodeMap=new Map;edgeMap=new Map;inEdgesMap=new Map;outEdgesMap=new Map;treeIndices=new Map;changes=[];batchCount=0;onChanged=()=>{};constructor(t){t&&(t.nodes&&this.addNodes(t.nodes),t.edges&&this.addEdges(t.edges),t.tree&&this.addTree(t.tree),t.onChanged&&(this.onChanged=t.onChanged))}batch=t=>{this.batchCount+=1,t(),this.batchCount-=1,this.batchCount||this.commit()};commit(){const t=this.changes;this.changes=[],this.onChanged({graph:this,changes:t})}reduceChanges(t){let e=[];return t.forEach((t=>{switch(t.type){case"NodeRemoved":{let r=!1;e=e.filter((e=>{if("NodeAdded"===e.type){const o=e.value.id===t.value.id;return o&&(r=!0),!o}return"NodeDataUpdated"===e.type?e.id!==t.value.id:"TreeStructureChanged"!==e.type||e.nodeId!==t.value.id})),r||e.push(t);break}case"EdgeRemoved":{let r=!1;e=e.filter((e=>{if("EdgeAdded"===e.type){const o=e.value.id===t.value.id;return o&&(r=!0),!o}return"EdgeDataUpdated"!==e.type&&"EdgeUpdated"!==e.type||e.id!==t.value.id})),r||e.push(t);break}case"NodeDataUpdated":case"EdgeDataUpdated":case"EdgeUpdated":{const r=e.find((e=>e.type===t.type&&e.id===t.id&&e.propertyName===t.propertyName));r?r.newValue=t.newValue:e.push(t);break}case"TreeStructureDetached":e=e.filter((e=>"TreeStructureAttached"===e.type?e.treeKey!==t.treeKey:"TreeStructureChanged"!==e.type||e.treeKey!==t.treeKey)),e.push(t);break;case"TreeStructureChanged":{const r=e.find((e=>"TreeStructureChanged"===e.type&&e.treeKey===t.treeKey&&e.nodeId===t.nodeId));r?r.newParentId=t.newParentId:e.push(t);break}default:e.push(t)}})),e}checkNodeExistence(t){if(!this.hasNode(t))throw new Error("Node not found for id: "+t)}hasNode(t){return this.nodeMap.has(t)}areNeighbors(t,e){return this.checkNodeExistence(t),this.getNeighbors(e).some((e=>e.id===t))}getNode(t){return this.checkNodeExistence(t),this.nodeMap.get(t)}getRelatedEdges(t,e){this.checkNodeExistence(t);const r=this.inEdgesMap.get(t),o=this.outEdgesMap.get(t);if("in"===e)return Array.from(r);if("out"===e)return Array.from(o);const s=new Set([...r,...o]);return Array.from(s)}getDegree(t,e){return this.getRelatedEdges(t,e).length}getSuccessors(t){const e=this.getRelatedEdges(t,"out").map((t=>t.target));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getPredecessors(t){const e=this.getRelatedEdges(t,"in").map((t=>t.source));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getNeighbors(t){const e=this.getPredecessors(t),r=this.getSuccessors(t);return Array.from(new Set([...e,...r]))}doAddNode(t){if(this.hasNode(t.id))throw new Error("Node already exists: "+t.id);this.nodeMap.set(t.id,t),this.inEdgesMap.set(t.id,new Set),this.outEdgesMap.set(t.id,new Set),this.treeIndices.forEach((e=>{e.childrenMap.set(t.id,new Set)})),this.changes.push({type:"NodeAdded",value:t})}addNodes(t){this.batch((()=>{for(const e of t)this.doAddNode(e)}))}addNode(t){this.addNodes([t])}doRemoveNode(t){const e=this.getNode(t),r=this.inEdgesMap.get(t),o=this.outEdgesMap.get(t);r?.forEach((t=>this.doRemoveEdge(t.id))),o?.forEach((t=>this.doRemoveEdge(t.id))),this.nodeMap.delete(t),this.treeIndices.forEach((e=>{e.childrenMap.get(t)?.forEach((t=>{e.parentMap.delete(t.id)})),e.parentMap.delete(t),e.childrenMap.delete(t)})),this.changes.push({type:"NodeRemoved",value:e})}removeNodes(t){this.batch((()=>{t.forEach((t=>this.doRemoveNode(t)))}))}removeNode(t){this.removeNodes([t])}updateNodeData(t,e,r){const o=this.getNode(t);this.batch((()=>{const s=o.data[e],n=r;o.data[e]=n,this.changes.push({type:"NodeDataUpdated",id:t,propertyName:e,oldValue:s,newValue:n})}))}mergeNodeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateNodeData(t,e,r)}))}))}checkEdgeExistence(t){if(!this.hasEdge(t))throw new Error("Edge not found for id: "+t)}hasEdge(t){return this.edgeMap.has(t)}getEdge(t){return this.checkEdgeExistence(t),this.edgeMap.get(t)}getEdgeDetail(t){const e=this.getEdge(t);return{edge:e,source:this.getNode(e.source),target:this.getNode(e.target)}}doAddEdge(t){if(this.hasEdge(t.id))throw new Error("Edge already exists: "+t.id);this.checkNodeExistence(t.source),this.checkNodeExistence(t.target),this.edgeMap.set(t.id,t);const e=this.inEdgesMap.get(t.target),r=this.outEdgesMap.get(t.source);e.add(t),r.add(t),this.changes.push({type:"EdgeAdded",value:t})}addEdges(t){this.batch((()=>{for(const e of t)this.doAddEdge(e)}))}addEdge(t){this.addEdges([t])}doRemoveEdge(t){const e=this.getEdge(t),r=this.outEdgesMap.get(e.source),o=this.inEdgesMap.get(e.target);r.delete(e),o.delete(e),this.edgeMap.delete(t),this.changes.push({type:"EdgeRemoved",value:e})}removeEdges(t){this.batch((()=>{t.forEach((t=>this.doRemoveEdge(t)))}))}removeEdge(t){this.removeEdges([t])}updateEdgeSource(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const o=r.source,s=e;this.outEdgesMap.get(o).delete(r),this.outEdgesMap.get(s).add(r),r.source=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"source",oldValue:o,newValue:s})}))}updateEdgeTarget(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const o=r.target,s=e;this.inEdgesMap.get(o).delete(r),this.inEdgesMap.get(s).add(r),r.target=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"target",oldValue:o,newValue:s})}))}updateEdgeData(t,e,r){const o=this.getEdge(t);this.batch((()=>{const s=o.data[e],n=r;o.data[e]=n,this.changes.push({type:"EdgeDataUpdated",id:t,propertyName:e,oldValue:s,newValue:n})}))}mergeEdgeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateEdgeData(t,e,r)}))}))}checkTreeExistence(t){if(!this.treeIndices.has(t))throw new Error("Tree structure not found for treeKey: "+t)}attachTreeStructure(t){this.treeIndices.has(t)||(this.treeIndices.set(t,{parentMap:new Map,childrenMap:new Map}),this.batch((()=>{this.changes.push({type:"TreeStructureAttached",treeKey:t})})))}detachTreeStructure(t){this.checkTreeExistence(t),this.treeIndices.delete(t),this.batch((()=>{this.changes.push({type:"TreeStructureDetached",treeKey:t})}))}addTree(t,e){this.batch((()=>{this.attachTreeStructure(e);const r=[],o=Array.isArray(t)?t:[t];for(;o.length;){const t=o.shift();r.push(t),t.children&&o.push(...t.children)}this.addNodes(r),r.forEach((t=>{t.children?.forEach((r=>{this.setParent(r.id,t.id,e)}))}))}))}getRoots(t){return this.checkTreeExistence(t),this.getAllNodes().filter((e=>!this.getParent(e.id,t)))}getChildren(t,e){this.checkNodeExistence(t),this.checkTreeExistence(e);const r=this.treeIndices.get(e).childrenMap.get(t);return Array.from(r||[])}getParent(t,e){return this.checkNodeExistence(t),this.checkTreeExistence(e),this.treeIndices.get(e).parentMap.get(t)||null}setParent(t,e,r){this.checkTreeExistence(r);const o=this.treeIndices.get(r),s=this.getNode(t),n=o.parentMap.get(t),i=this.getNode(e);o.parentMap.set(t,i),n&&o.childrenMap.get(n.id)?.delete(s);let a=o.childrenMap.get(i.id);a||(a=new Set,o.childrenMap.set(i.id,a)),a.add(s),this.batch((()=>{this.changes.push({type:"TreeStructureChanged",treeKey:r,nodeId:t,oldParentId:n?.id,newParentId:i.id})}))}getAllNodes(){return Array.from(this.nodeMap.values())}getAllEdges(){return Array.from(this.edgeMap.values())}doBFS(t,e,r){for(;t.length;){const o=t.shift();r(o),e.add(o.id),this.getSuccessors(o.id).forEach((r=>{e.has(r.id)||(e.add(r.id),t.push(r))}))}}bfs(t,e){this.doBFS([this.getNode(t)],new Set,e)}doDFS(t,e,r){r(t),e.add(t.id),this.getSuccessors(t.id).forEach((t=>{e.has(t.id)||this.doDFS(t,e,r)}))}dfs(t,e){this.doDFS(this.getNode(t),new Set,e)}clone(){const t=this.getAllNodes().map((t=>({...t,data:{...t.data}}))),e=this.getAllEdges().map((t=>({...t,data:{...t.data}}))),o=new r({nodes:t,edges:e});return this.treeIndices.forEach((({parentMap:t,childrenMap:e},r)=>{const s=new Map;t.forEach(((t,e)=>{s.set(e,o.getNode(t.id))}));const n=new Map;e.forEach(((t,e)=>{n.set(e,new Set(Array.from(t).map((t=>o.getNode(t.id)))))})),o.treeIndices.set(r,{parentMap:s,childrenMap:n})})),o}toJSON(){return JSON.stringify({nodes:this.getAllNodes(),edges:this.getAllEdges()})}}var o=function(){return o=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++)for(var s in e=arguments[r])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},o.apply(this,arguments)};function s(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,s,n=r.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(t){s={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function n(t,e,r){if(r||2===arguments.length)for(var o,s=0,n=e.length;s<n;s++)!o&&s in e||(o||(o=Array.prototype.slice.call(e,0,s)),o[s]=e[s]);return t.concat(o||Array.prototype.slice.call(e))}Object.create,Object.create;var i=function(t){return"string"==typeof t},a=/-(\\w)/g,h=(function(t){return t.replace(a,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),u=function(t){return"number"==typeof t},l=function(t){for(var e=[],r=t.length,o=0;o<r;o+=1){e[o]=[];for(var s=0;s<r;s+=1)o===s?e[o][s]=0:0!==t[o][s]&&t[o][s]?e[o][s]=t[o][s]:e[o][s]=1/0}for(var n=0;n<r;n+=1)for(o=0;o<r;o+=1)for(s=0;s<r;s+=1)e[o][s]>e[o][n]+e[n][s]&&(e[o][s]=e[o][n]+e[n][s]);return e},c=function(t,e){var r=t.nodes,o=t.edges,s=[],n={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){n[t.id]=e,s.push([])})),null==o||o.forEach((function(t){var r=t.source,o=t.target,i=n[r],a=n[o];void 0!==i&&void 0!==a&&(s[i][a]=1,e||(s[a][i]=1))})),s},f=function(t){return null!==t&&"object"==typeof t},d=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var e=[];return t.forEach((function(t){e.push(t)})),e.map((function(t){return d(t)}))}if("object"==typeof t&&Object.keys(t).length){var r=o({},t);return Object.keys(r).forEach((function(t){r[t]=d(r[t])})),r}return t},g=function(t){return"function"==typeof t},m=function(t,e,r){return void 0===r&&(r=!0),e||0===e?g(e)?e:u(e)?function(){return e}:h(e)?function(){if(r){var o=Math.max.apply(Math,n([],s(e),!1));return isNaN(o)?t:o}return e}:f(e)?function(){if(r){var o=Math.max(e.width,e.height);return isNaN(o)?t:o}return[e.width,e.height]}:function(){return t}:function(e){return e.size?h(e.size)?e.size[0]>e.size[1]?e.size[0]:e.size[1]:f(e.size)?e.size.width>e.size.height?e.size.width:e.size.height:e.size:t}},p={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},w=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=o(o({},p),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){var r=this;t.batch((function(){r.genericCircularLayout(!0,t,e)}))},t.prototype.genericCircularLayout=function(t,e,r){var n=o(o({},this.options),r),i=n.width,a=n.height,h=n.center,u=n.divisions,l=n.startAngle,c=void 0===l?0:l,f=n.endAngle,g=void 0===f?2*Math.PI:f,p=n.angleRatio,w=n.ordering,M=n.clockwise,b=n.nodeSpacing,E=n.nodeSize,x=n.layoutInvisibles,S=n.onLayoutEnd,N=e.getAllNodes(),R=e.getAllEdges();x||(N=N.filter((function(t){return t.data.visible||void 0===t.data.visible})),R=R.filter((function(t){return t.data.visible||void 0===t.data.visible})));var I=N.length;if(0===I)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var k=s(v(i,a,h),3),A=k[0],T=k[1],C=k[2];if(1===I){t&&e.mergeNodeData(N[0].id,{x:C[0],y:C[1]});var D={nodes:[o(o({},N[0]),{data:o(o({},N[0].data),{x:C[0],y:C[1]})})],edges:R};return null==S||S(D),D}var z=(g-c)/I,P=n.radius,V=n.startRadius,q=n.endRadius;if(b){var j=m(10,b),F=m(10,E),O=-1/0;N.forEach((function(t){var e=F(t);O<e&&(O=e)}));var L=0;N.forEach((function(t,e){L+=0===e?O||10:(j(t)||0)+(O||10)})),P=L/(2*Math.PI)}else P||V||q?!V&&q?V=q:V&&!q&&(q=V):P=Math.min(T,A)/2;var $=z*p,U=[];U="topology"===w?y(e,N):"topology-directed"===w?y(e,N,!0):"degree"===w?function(t,e){var r=[];return e.forEach((function(t,e){r.push(d(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(e,N):N.map((function(t){return d(t)}));for(var B=Math.ceil(I/u),K=0;K<I;++K){var W=P;W||null===V||null===q||(W=V+K*(q-V)/(I-1)),W||(W=10+100*K/(I-1));var J=c+K%B*$+2*Math.PI/u*Math.floor(K/B);M||(J=g-K%B*$-2*Math.PI/u*Math.floor(K/B)),U[K].data.x=C[0]+Math.cos(J)*W,U[K].data.y=C[1]+Math.sin(J)*W}t&&U.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var _={nodes:U,edges:R};return null==S||S(_),_},t}(),y=function(t,e,r){void 0===r&&(r=!1);var o=[d(e[0])],s={},n=e.length;s[e[0].id]=!0;var i=0;return e.forEach((function(a,h){if(0!==h)if(h!==n-1&&t.getDegree(a.id,"both")===t.getDegree(e[h+1].id,"both")&&!t.areNeighbors(o[i].id,a.id)||s[a.id]){for(var u=r?t.getSuccessors(o[i].id):t.getNeighbors(o[i].id),l=!1,c=0;c<u.length;c++){var f=u[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!s[f.id]){o.push(d(f)),s[f.id]=!0,l=!0;break}}for(var g=0;!l&&(s[e[g].id]||(o.push(d(e[g])),s[e[g].id]=!0,l=!0),++g!==n););}else o.push(d(a)),s[a.id]=!0,i++})),o},v=function(t,e,r){var o=t,s=e,n=r;return o||"undefined"==typeof window||(o=window.innerWidth),s||"undefined"==typeof window||(s=window.innerHeight),n||(n=[o/2,s/2]),[o,s,n]},M={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},b=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",this.options=o(o({},M),t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,a=s.width,l=s.height,c=s.sortBy,m=s.maxLevelDiff,p=s.sweep,w=s.clockwise,y=s.equidistant,v=s.minNodeSpacing,M=void 0===v?10:v,b=s.preventOverlap,E=s.startAngle,x=void 0===E?1.5*Math.PI:E,S=s.nodeSize,N=s.nodeSpacing,R=s.layoutInvisibles,I=s.onLayoutEnd,k=e.getAllNodes(),A=e.getAllEdges();R||(k=k.filter((function(t){return t.data.visible||void 0===t.data.visible})),A=A.filter((function(t){return t.data.visible||void 0===t.data.visible})));var T=k.length;if(0===T){var C={nodes:[],edges:A};return null==I||I(C),C}var D=a||"undefined"==typeof window?a:window.innerWidth,z=l||"undefined"==typeof window?l:window.innerHeight,P=n||[D/2,z/2];if(1===T){t&&e.mergeNodeData(k[0].id,{x:P[0],y:P[1]});var V={nodes:[o(o({},k[0]),{data:o(o({},k[0].data),{x:P[0],y:P[1]})})],edges:A};return null==I||I(V),V}var q,j=[],F=0;q=h(S)?Math.max(S[0],S[1]):S,h(N)?F=Math.max(N[0],N[1]):u(N)&&(F=N),k.forEach((function(t){j.push(d(t));var e=q;h(t.data.size)?e=Math.max(t.data.size[0],t.data.size[1]):u(t.data.size)?e=t.data.size:f(t.data.size)&&(e=Math.max(t.data.size.width,t.data.size.height)),q=Math.max(q,e),g(N)&&(F=Math.max(N(t),F))}));var O={};j.forEach((function(t,e){O[t.id]=e}));var L=c;i(L)&&void 0!==j[0].data[L]||(L="degree"),"degree"===L?j.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):j.sort((function(t,e){return e.data[L]-t.data[L]}));var $=j[0],U=m||$.data[L]/4,B=[{nodes:[]}],K=B[0];j.forEach((function(t){if(K.nodes.length>0){var e=Math.abs(K.nodes[0].data[L]-t.data[L]);U&&e>=U&&(K={nodes:[]},B.push(K))}K.nodes.push(t)}));var W=q+(F||M);if(!b){var J=B.length>0&&B[0].nodes.length>1,_=(Math.min(D,z)/2-W)/(B.length+(J?1:0));W=Math.min(W,_)}var G=0;if(B.forEach((function(t){var e=void 0===p?2*Math.PI-2*Math.PI/t.nodes.length:p;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&b){var r=Math.cos(t.dTheta)-Math.cos(0),o=Math.sin(t.dTheta)-Math.sin(0),s=Math.sqrt(W*W/(r*r+o*o));G=Math.max(s,G)}t.r=G,G+=W})),y){for(var H=0,Y=0,Q=0;Q<B.length;Q++){var X=(B[Q].r||0)-Y;H=Math.max(H,X)}Y=0,B.forEach((function(t,e){0===e&&(Y=t.r||0),t.r=Y,Y+=H}))}B.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,o){var s=x+(w?1:-1)*e*o;t.data.x=P[0]+r*Math.cos(s),t.data.y=P[1]+r*Math.sin(s)}))})),t&&j.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Z={nodes:j,edges:A};return null==I||I(Z),Z},t}(),E={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},x=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",this.options=o(o({},E),t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.begin,a=void 0===n?[0,0]:n,l=s.condense,c=s.preventOverlapPadding,f=s.preventOverlap,g=s.columns,p=s.rows,w=s.cols,y=void 0===w?g:w,v=s.nodeSpacing,M=s.nodeSize,b=s.width,E=s.height,x=s.layoutInvisibles,k=s.onLayoutEnd,T=s.position,C=s.sortBy,D=e.getAllNodes(),z=e.getAllEdges();x||(D=D.filter((function(t){return t.data.visible||void 0===t.data.visible})),z=z.filter((function(t){return t.data.visible||void 0===t.data.visible})));var P=D.length;if(0===P){var V={nodes:[],edges:z};return null==k||k(V),V}if(1===P){t&&e.mergeNodeData(D[0].id,{x:a[0],y:a[1]});var q={nodes:[o(o({},D[0]),{data:o(o({},D[0].data),{x:a[0],y:a[1]})})],edges:z};return null==k||k(q),q}var j=D.map((function(t){return d(t)}));"id"===C||i(C)&&void 0!==j[0].data[C]||(C="degree"),"degree"===C?j.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):"id"===C?j.sort((function(t,e){return u(e.id)&&u(t.id)?e.id-t.id:"".concat(e.id).localeCompare("".concat(t.id))})):j.sort((function(t,e){return e.data[C]-t.data[C]}));var F=b||"undefined"==typeof window?b:window.innerWidth,O=E||"undefined"==typeof window?E:window.innerHeight,L=P,$={rows:p,cols:y};if(null!=p&&null!=y)$.rows=p,$.cols=y;else if(null!=p&&null==y)$.rows=p,$.cols=Math.ceil(L/$.rows);else if(null==p&&null!=y)$.cols=y,$.rows=Math.ceil(L/$.cols);else{var U=Math.sqrt(L*O/F);$.rows=Math.round(U),$.cols=Math.round(F/O*U)}if($.rows=Math.max($.rows,1),$.cols=Math.max($.cols,1),$.cols*$.rows>L)((K=S($))-1)*(B=N($))>=L?S($,K-1):(B-1)*K>=L&&N($,B-1);else for(;$.cols*$.rows<L;){var B,K=S($);((B=N($))+1)*K>=L?N($,B+1):S($,K+1)}var W=l?0:F/$.cols,J=l?0:O/$.rows;if(f||v){var _=m(10,v),G=m(30,M,!1);j.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var r,o,s=e.getNode(t.id),n=G(s)||30;h(n)?(r=n[0],o=n[1]):(r=n,o=n);var i=void 0!==_?_(t):c,a=r+i,u=o+i;W=Math.max(W,a),J=Math.max(J,u)}))}for(var H={},Y={row:0,col:0},Q={},X=0;X<j.length;X++){var Z=j[X],tt=void 0;if(T&&(tt=T(e.getNode(Z.id))),tt&&(void 0!==tt.row||void 0!==tt.col)){var et={row:tt.row,col:tt.col};if(void 0===et.col)for(et.col=0;R(H,et);)et.col++;else if(void 0===et.row)for(et.row=0;R(H,et);)et.row++;Q[Z.id]=et,I(H,et)}A(Z,a,W,J,Q,$,Y,H)}var rt={nodes:j,edges:z};return null==k||k(rt),t&&j.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),rt},t}(),S=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.min(o,s):Math.min(o,s)===t.rows?t.rows=e:t.cols=e,r},N=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.max(o,s):Math.max(o,s)===t.rows?t.rows=e:t.cols=e,r},R=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},I=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},k=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},A=function(t,e,r,o,s,n,i,a){var h,u,l=s[t.id];if(l)h=l.col*r+r/2+e[0],u=l.row*o+o/2+e[1];else{for(;R(a,i);)k(n,i);h=i.col*r+r/2+e[0],u=i.row*o+o/2+e[1],I(a,i),k(n,i)}t.data.x=h,t.data.y=u};const T=Object.prototype.toString;function C(t){return T.call(t).endsWith("Array]")}function D(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!C(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]>i&&(i=t[a]);return i}function z(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!C(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]<i&&(i=t[a]);return i}function P(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!C(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!C(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var o=z(t),s=D(t);if(o===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=r.min,i=void 0===n?r.autoMinMax?o:0:n,a=r.max,h=void 0===a?r.autoMinMax?s:1:a;if(i>=h)throw new RangeError("min option must be smaller than max option");for(var u=(h-i)/(s-o),l=0;l<t.length;l++)e[l]=(t[l]-o)*u+i;return e}const V=" ".repeat(2),q=" ".repeat(4);function j(t,e={}){const{maxRows:r=15,maxColumns:o=10,maxNumSize:s=8,padMinus:n="auto"}=e;return`${t.constructor.name} {\\n${V}[\\n${q}${function(t,e,r,o,s){const{rows:n,columns:i}=t,a=Math.min(n,e),h=Math.min(i,r),u=[];if("auto"===s){s=!1;t:for(let e=0;e<a;e++)for(let r=0;r<h;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let n=0;n<h;n++)r.push(F(t.get(e,n),o,s));u.push(`${r.join(" ")}`)}return h!==i&&(u[u.length-1]+=` ... ${i-r} more columns`),a!==n&&u.push(`... ${n-e} more rows`),u.join(`\\n${q}`)}(t,r,o,s,n)}\\n${V}]\\n${V}rows: ${t.rows}\\n${V}columns: ${t.columns}\\n}`}function F(t,e,r){return(t>=0&&r?` ${O(t,e-1)}`:O(t,e)).padEnd(e)}function O(t,e){let r=t.toString();if(r.length<=e)return r;let o=t.toFixed(e);if(o.length>e&&(o=t.toFixed(Math.max(0,e-(o.length-e)))),o.length<=e&&!o.startsWith("0.000")&&!o.startsWith("-0.000"))return o;let s=t.toExponential(e);return s.length>e&&(s=t.toExponential(Math.max(0,e-(s.length-e)))),s.slice(0)}function L(t,e,r){let o=r?t.rows:t.rows-1;if(e<0||e>o)throw new RangeError("Row index out of range")}function $(t,e,r){let o=r?t.columns:t.columns-1;if(e<0||e>o)throw new RangeError("Column index out of range")}function U(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function B(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function K(t,e,r,o,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(J("startRow",e),J("endRow",r),J("startColumn",o),J("endColumn",s),e>r||o>s||e<0||e>=t.rows||r<0||r>=t.rows||o<0||o>=t.columns||s<0||s>=t.columns)throw new RangeError("Submatrix indices are out of range")}function W(t,e=0){let r=[];for(let o=0;o<t;o++)r.push(e);return r}function J(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function _(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class G{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let o=new Y(t,e);for(let s=0;s<t;s++)for(let t=0;t<e;t++)o.set(s,t,r[s*e+t]);return o}static rowVector(t){let e=new Y(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new Y(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new Y(t,e)}static ones(t,e){return new Y(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:o=Math.random}=r;let s=new Y(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)s.set(r,t,o());return s}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:o=0,max:s=1e3,random:n=Math.random}=r;if(!Number.isInteger(o))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(o>=s)throw new RangeError("min must be smaller than max");let i=s-o,a=new Y(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=o+Math.round(n()*i);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let o=Math.min(t,e),s=this.zeros(t,e);for(let t=0;t<o;t++)s.set(t,t,r);return s}static diag(t,e,r){let o=t.length;void 0===e&&(e=o),void 0===r&&(r=e);let s=Math.min(o,e,r),n=this.zeros(e,r);for(let e=0;e<s;e++)n.set(e,e,t[e]);return n}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new Y(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.min(t.get(n,r),e.get(n,r)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new this(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.max(t.get(n,r),e.get(n,r)));return s}static checkMatrix(t){return G.isMatrix(t)?t:new Y(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);t++}return o}isReducedEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(o=!1);t++}return o}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let o=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(o,r)&&(o=s);if(0===t.get(o,r))r++;else{t.swapRows(e,o);let s=t.get(e,r);for(let o=r;o<t.columns;o++)t.set(e,o,t.get(e,o)/s);for(let o=e+1;o<t.rows;o++){let s=t.get(o,r)/t.get(e,r);t.set(o,r,0);for(let n=r+1;n<t.columns;n++)t.set(o,n,t.get(o,n)-t.get(e,n)*s)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,o=r-1;for(;o>=0;)if(0===t.maxRow(o))o--;else{let s=0,n=!1;for(;s<r&&!1===n;)1===t.get(o,s)?n=!0:s++;for(let r=0;r<o;r++){let n=t.get(r,s);for(let i=s;i<e;i++){let e=t.get(r,i)-n*t.get(o,i);t.set(r,i,e)}}o--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let o=new Y(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)o.setSubMatrix(this,this.rows*t,this.columns*e);return o}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){L(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return Y.rowVector(this.getRow(t))}setRow(t,e){L(this,t),e=U(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){L(this,t),L(this,e);for(let r=0;r<this.columns;r++){let o=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,o)}return this}getColumn(t){$(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return Y.columnVector(this.getColumn(t))}setColumn(t,e){$(this,t),e=B(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){$(this,t),$(this,e);for(let r=0;r<this.rows;r++){let o=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,o)}return this}addRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){L(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){$(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){_(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){_(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}maxRow(t){if(L(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){L(this,t),_(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)>e&&(e=this.get(t,o),r[1]=o);return r}minRow(t){if(L(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){L(this,t),_(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)<e&&(e=this.get(t,o),r[1]=o);return r}maxColumn(t){if($(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){$(this,t),_(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)>e&&(e=this.get(o,t),r[0]=o);return r}minColumn(t){if($(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){$(this,t),_(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)<e&&(e=this.get(o,t),r[0]=o);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){G.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let o=0;o<e.length;o++)r+=e[o]*t[o];return r}mmul(t){t=Y.checkMatrix(t);let e=this.rows,r=this.columns,o=t.columns,s=new Y(e,o),n=new Float64Array(r);for(let i=0;i<o;i++){for(let e=0;e<r;e++)n[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let o=0;o<r;o++)e+=this.get(t,o)*n[o];s.set(t,i,e)}}return s}strassen2x2(t){t=Y.checkMatrix(t);let e=new Y(2,2);const r=this.get(0,0),o=t.get(0,0),s=this.get(0,1),n=t.get(0,1),i=this.get(1,0),a=t.get(1,0),h=this.get(1,1),u=t.get(1,1),l=(r+h)*(o+u),c=(i+h)*o,f=r*(n-u),d=h*(a-o),g=(r+s)*u,m=l+d-g+(s-h)*(a+u),p=f+g,w=c+d,y=l-c+f+(i-r)*(o+n);return e.set(0,0,m),e.set(0,1,p),e.set(1,0,w),e.set(1,1,y),e}strassen3x3(t){t=Y.checkMatrix(t);let e=new Y(3,3);const r=this.get(0,0),o=this.get(0,1),s=this.get(0,2),n=this.get(1,0),i=this.get(1,1),a=this.get(1,2),h=this.get(2,0),u=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),m=t.get(1,1),p=t.get(1,2),w=t.get(2,0),y=t.get(2,1),v=t.get(2,2),M=(r-n)*(-f+m),b=(-r+n+i)*(c-f+m),E=(n+i)*(-c+f),x=r*c,S=(-r+h+u)*(c-d+p),N=(-r+h)*(d-p),R=(h+u)*(-c+d),I=(-s+u+l)*(m+w-y),k=(s-l)*(m-y),A=s*w,T=(u+l)*(-w+y),C=(-s+i+a)*(p+w-v),D=(s-a)*(p-v),z=(i+a)*(-w+v),P=x+A+o*g,V=(r+o+s-n-i-u-l)*m+b+E+x+I+A+T,q=x+S+R+(r+o+s-i-a-h-u)*p+A+C+z,j=M+i*(-c+f+g-m-p-w+v)+b+x+A+C+D,F=M+b+E+x+a*y,O=A+C+D+z+n*d,L=x+S+N+u*(-c+d+g-m-p-w+y)+I+k+A,$=I+k+A+T+h*f,U=x+S+N+R+l*v;return e.set(0,0,P),e.set(0,1,V),e.set(0,2,q),e.set(1,0,j),e.set(1,1,F),e.set(1,2,O),e.set(2,0,L),e.set(2,1,$),e.set(2,2,U),e}mmulStrassen(t){t=Y.checkMatrix(t);let e=this.clone(),r=e.rows,o=e.columns,s=t.rows,n=t.columns;function i(t,e,r){let o=t.rows,s=t.columns;if(o===e&&s===r)return t;{let o=G.zeros(e,r);return o=o.setSubMatrix(t,0,0),o}}o!==s&&console.warn(`Multiplying ${r} x ${o} and ${s} x ${n} matrix: dimensions do not match.`);let a=Math.max(r,s),h=Math.max(o,n);return e=i(e,a,h),function t(e,r,o,s){if(o<=512||s<=512)return e.mmul(r);o%2==1&&s%2==1?(e=i(e,o+1,s+1),r=i(r,o+1,s+1)):o%2==1?(e=i(e,o+1,s),r=i(r,o+1,s)):s%2==1&&(e=i(e,o,s+1),r=i(r,o,s+1));let n=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),h=e.subMatrix(0,n-1,0,a-1),u=r.subMatrix(0,n-1,0,a-1),l=e.subMatrix(0,n-1,a,e.columns-1),c=r.subMatrix(0,n-1,a,r.columns-1),f=e.subMatrix(n,e.rows-1,0,a-1),d=r.subMatrix(n,r.rows-1,0,a-1),g=e.subMatrix(n,e.rows-1,a,e.columns-1),m=r.subMatrix(n,r.rows-1,a,r.columns-1),p=t(G.add(h,g),G.add(u,m),n,a),w=t(G.add(f,g),u,n,a),y=t(h,G.sub(c,m),n,a),v=t(g,G.sub(d,u),n,a),M=t(G.add(h,l),m,n,a),b=t(G.sub(f,h),G.add(u,c),n,a),E=t(G.sub(l,g),G.add(d,m),n,a),x=G.add(p,v);x.sub(M),x.add(E);let S=G.add(y,M),N=G.add(w,v),R=G.sub(p,w);R.add(y),R.add(b);let I=G.zeros(2*x.rows,2*x.columns);return I=I.setSubMatrix(x,0,0),I=I.setSubMatrix(S,x.rows,0),I=I.setSubMatrix(N,0,x.columns),I=I.setSubMatrix(R,x.rows,x.columns),I.subMatrix(0,o-1,0,s-1)}(e,t=i(t,a,h),a,h)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new Y(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&P(s,{min:e,max:r,output:s}),o.setRow(t,s)}return o}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new Y(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&P(s,{min:e,max:r,output:s}),o.setColumn(t,s)}return o}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),o=this.get(e,this.columns-1-r);this.set(e,r,o),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),o=this.get(this.rows-1-r,e);this.set(r,e,o),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=Y.checkMatrix(t);let e=this.rows,r=this.columns,o=t.rows,s=t.columns,n=new Y(e*o,r*s);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<o;r++)for(let a=0;a<s;a++)n.set(o*i+r,s*e+a,this.get(i,e)*t.get(r,a));return n}kroneckerSum(t){if(t=Y.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,o=this.kroneckerProduct(Y.eye(r,r)),s=Y.eye(e,e).kroneckerProduct(t);return o.add(s)}transpose(){let t=new Y(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=H){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=H){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,o){K(this,t,e,r,o);let s=new Y(e-t+1,o-r+1);for(let n=t;n<=e;n++)for(let e=r;e<=o;e++)s.set(n-t,e-r,this.get(n,e));return s}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let o=new Y(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);o.set(s,n-e,this.get(t[s],n))}return o}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let o=new Y(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);o.set(n-e,s,this.get(n,t[s]))}return o}setSubMatrix(t,e,r){if((t=Y.checkMatrix(t)).isEmpty())return this;K(this,e,e+t.rows-1,r,r+t.columns-1);for(let o=0;o<t.rows;o++)for(let s=0;s<t.columns;s++)this.set(e+o,r+s,t.get(o,s));return this}selection(t,e){!function(t,e){if(!C(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!C(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new Y(t.length,e.length);for(let o=0;o<t.length;o++){let s=t[o];for(let t=0;t<e.length;t++){let n=e[t];r.set(o,t,this.get(s,n))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new Y(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=W(t.rows);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]+=t.get(r,o);return e}(this);case"column":return function(t){let e=W(t.columns);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]+=t.get(r,o);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e+=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=W(t.rows,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]*=t.get(r,o);return e}(this);case"column":return function(t){let e=W(t.columns,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]*=t.get(r,o);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e*=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:o=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!C(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<o;i++){let o=0,a=0,h=0;for(let e=0;e<s;e++)h=t.get(i,e)-r[i],o+=h,a+=h*h;e?n.push((a-o*o/s)/(s-1)):n.push((a-o*o/s)/s)}return n}(this,r,o);case"column":if(!C(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<s;i++){let s=0,a=0,h=0;for(let e=0;e<o;e++)h=t.get(e,i)-r[i],s+=h,a+=h*h;e?n.push((a-s*s/o)/(o-1)):n.push((a-s*s/o)/o)}return n}(this,r,o);case void 0:if("number"!=typeof o)throw new TypeError("mean must be a number");return function(t,e,r){const o=t.rows,s=t.columns,n=o*s;let i=0,a=0,h=0;for(let e=0;e<o;e++)for(let o=0;o<s;o++)h=t.get(e,o)-r,i+=h,a+=h*h;return e?(a-i*i/n)/(n-1):(a-i*i/n)/n}(this,r,o);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!C(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[r])}(this,r),this;case"column":if(!C(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[o])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let o=0;for(let e=0;e<t.columns;e++)o+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(o))}return e}(this);else if(!C(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let o=0;for(let e=0;e<t.rows;e++)o+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(o))}return e}(this);else if(!C(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[o])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let o=0;o<t.columns;o++)for(let s=0;s<t.rows;s++)r+=Math.pow(t.get(s,o),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return j(this,t)}}function H(t,e){return t-e}G.prototype.klass="Matrix","undefined"!=typeof Symbol&&(G.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return j(this)}),G.random=G.rand,G.randomInt=G.randInt,G.diagonal=G.diag,G.prototype.diagonal=G.prototype.diag,G.identity=G.eye,G.prototype.negate=G.prototype.neg,G.prototype.tensorProduct=G.prototype.kroneckerProduct;class Y extends G{constructor(t,e){if(super(),Y.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!C(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let o=0;o<t;o++){if(r[o].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[o].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[o]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return L(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),L(this,t,!0),e=Float64Array.from(U(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){$(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let o=0;o<t;o++)r[o]=this.data[e][o];for(let o=t+1;o<this.columns;o++)r[o-1]=this.data[e][o];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),$(this,t,!0),e=B(this,e);for(let r=0;r<this.rows;r++){const o=new Float64Array(this.columns+1);let s=0;for(;s<t;s++)o[s]=this.data[r][s];for(o[s++]=e[r];s<this.columns+1;s++)o[s]=this.data[r][s-1];this.data[r]=o}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(G,Y);class Q extends G{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function X(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class Z{constructor(t,e={}){if((t=Q.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,o=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:n=!0,autoTranspose:i=!1}=e;let a,h=Boolean(s),u=Boolean(n),l=!1;if(r<o)if(i){a=t.transpose(),r=a.rows,o=a.columns,l=!0;let e=h;h=u,u=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,o),f=Math.min(r+1,o),d=new Float64Array(f),g=new Y(r,c),m=new Y(o,o),p=new Float64Array(o),w=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let v=Math.min(r-1,o),M=Math.max(0,Math.min(o-2,r)),b=Math.max(v,M);for(let t=0;t<b;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=X(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<o;e++){if(t<v&&0!==d[t]){let o=0;for(let s=t;s<r;s++)o+=a.get(s,t)*a.get(s,e);o=-o/a.get(t,t);for(let s=t;s<r;s++)a.set(s,e,a.get(s,e)+o*a.get(s,t))}p[e]=a.get(t,e)}if(h&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<M){p[t]=0;for(let e=t+1;e<o;e++)p[t]=X(p[t],p[e]);if(0!==p[t]){p[t+1]<0&&(p[t]=0-p[t]);for(let e=t+1;e<o;e++)p[e]/=p[t];p[t+1]+=1}if(p[t]=-p[t],t+1<r&&0!==p[t]){for(let e=t+1;e<r;e++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<o;r++)w[e]+=p[r]*a.get(e,r);for(let e=t+1;e<o;e++){let o=-p[e]/p[t+1];for(let s=t+1;s<r;s++)a.set(s,e,a.get(s,e)+o*w[s])}}if(u)for(let e=t+1;e<o;e++)m.set(e,t,p[e])}}let E=Math.min(o,r+1);if(v<o&&(d[v]=a.get(v,v)),r<E&&(d[E-1]=0),M+1<E&&(p[M]=a.get(M,E-1)),p[E-1]=0,h){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let o=0;for(let s=t;s<r;s++)o+=g.get(s,t)*g.get(s,e);o=-o/g.get(t,t);for(let s=t;s<r;s++)g.set(s,e,g.get(s,e)+o*g.get(s,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(u)for(let t=o-1;t>=0;t--){if(t<M&&0!==p[t])for(let e=t+1;e<o;e++){let r=0;for(let s=t+1;s<o;s++)r+=m.get(s,t)*m.get(s,e);r=-r/m.get(t+1,t);for(let s=t+1;s<o;s++)m.set(s,e,m.get(s,e)+r*m.get(s,t))}for(let e=0;e<o;e++)m.set(e,t,0);m.set(t,t,1)}let x=E-1,S=0,N=Number.EPSILON;for(;E>0;){let t,e;for(t=E-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+N*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[t]=0;break}}if(t===E-2)e=4;else{let r;for(r=E-1;r>=t&&r!==t;r--){let e=(r!==E?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(d[r])<=N*e){d[r]=0;break}}r===t?e=3:r===E-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[E-2];p[E-2]=0;for(let r=E-2;r>=t;r--){let s=X(d[r],e),n=d[r]/s,i=e/s;if(d[r]=s,r!==t&&(e=-i*p[r-1],p[r-1]=n*p[r-1]),u)for(let t=0;t<o;t++)s=n*m.get(t,r)+i*m.get(t,E-1),m.set(t,E-1,-i*m.get(t,r)+n*m.get(t,E-1)),m.set(t,r,s)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let o=t;o<E;o++){let s=X(d[o],e),n=d[o]/s,i=e/s;if(d[o]=s,e=-i*p[o],p[o]=n*p[o],h)for(let e=0;e<r;e++)s=n*g.get(e,o)+i*g.get(e,t-1),g.set(e,t-1,-i*g.get(e,o)+n*g.get(e,t-1)),g.set(e,o,s)}break}case 3:{const e=Math.max(Math.abs(d[E-1]),Math.abs(d[E-2]),Math.abs(p[E-2]),Math.abs(d[t]),Math.abs(p[t])),s=d[E-1]/e,n=d[E-2]/e,i=p[E-2]/e,a=d[t]/e,l=p[t]/e,c=((n+s)*(n-s)+i*i)/2,f=s*i*(s*i);let w=0;0===c&&0===f||(w=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),w=f/(c+w));let y=(a+s)*(a-s)+w,v=a*l;for(let e=t;e<E-1;e++){let s=X(y,v);0===s&&(s=Number.MIN_VALUE);let n=y/s,i=v/s;if(e!==t&&(p[e-1]=s),y=n*d[e]+i*p[e],p[e]=n*p[e]-i*d[e],v=i*d[e+1],d[e+1]=n*d[e+1],u)for(let t=0;t<o;t++)s=n*m.get(t,e)+i*m.get(t,e+1),m.set(t,e+1,-i*m.get(t,e)+n*m.get(t,e+1)),m.set(t,e,s);if(s=X(y,v),0===s&&(s=Number.MIN_VALUE),n=y/s,i=v/s,d[e]=s,y=n*p[e]+i*d[e+1],d[e+1]=-i*p[e]+n*d[e+1],v=i*p[e+1],p[e+1]=n*p[e+1],h&&e<r-1)for(let t=0;t<r;t++)s=n*g.get(t,e)+i*g.get(t,e+1),g.set(t,e+1,-i*g.get(t,e)+n*g.get(t,e+1)),g.set(t,e,s)}p[E-2]=y,S+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,u))for(let e=0;e<=x;e++)m.set(e,t,-m.get(e,t));for(;t<x&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,u&&t<o-1)for(let r=0;r<o;r++)e=m.get(r,t+1),m.set(r,t+1,m.get(r,t)),m.set(r,t,e);if(h&&t<r-1)for(let o=0;o<r;o++)e=g.get(o,t+1),g.set(o,t+1,g.get(o,t)),g.set(o,t,e);t++}S=0,E--}}if(l){let t=m;m=g,g=t}this.m=r,this.n=o,this.s=d,this.U=g,this.V=m}solve(t){let e=t,r=this.threshold,o=this.s.length,s=Y.zeros(o,o);for(let t=0;t<o;t++)Math.abs(this.s[t])<=r?s.set(t,t,0):s.set(t,t,1/this.s[t]);let n=this.U,i=this.rightSingularVectors,a=i.mmul(s),h=i.rows,u=n.rows,l=Y.zeros(h,u);for(let t=0;t<h;t++)for(let e=0;e<u;e++){let r=0;for(let s=0;s<o;s++)r+=a.get(t,s)*n.get(e,s);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(Y.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,o=t.columns,s=new Y(r,this.s.length);for(let n=0;n<r;n++)for(let r=0;r<o;r++)Math.abs(this.s[r])>e&&s.set(n,r,t.get(n,r)/this.s[r]);let n=this.U,i=n.rows,a=n.columns,h=new Y(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let o=0;o<a;o++)r+=s.get(t,o)*n.get(e,o);h.set(t,e,r)}return h}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let o=0,s=r.length;o<s;o++)r[o]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return Y.diag(this.s)}}var tt={center:[0,0],linkDistance:50},et=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",this.options=o(o({},tt),t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,i=void 0===n?[0,0]:n,a=s.linkDistance,h=void 0===a?50:a,u=s.layoutInvisibles,f=s.onLayoutEnd,g=e.getAllNodes(),m=e.getAllEdges();if(u||(g=g.filter((function(t){return t.data.visible||void 0===t.data.visible})),m=m.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!g||0===g.length){var p={nodes:[],edges:m};return null==f||f(p),p}if(1===g.length){t&&e.mergeNodeData(g[0].id,{x:i[0],y:i[1]});var w={nodes:[o(o({},g[0]),{data:o(o({},g[0].data),{x:i[0],y:i[1]})})],edges:m};return null==f||f(w),w}var y=c({nodes:g,edges:m},!1),v=l(y);rt(v);var M=function(t,e){var r=[];return t.forEach((function(t){var o=[];t.forEach((function(t){o.push(t*e)})),r.push(o)})),r}(v,h),b=ot(M),E=[];b.forEach((function(t,e){var r=d(g[e]);r.data.x=t[0]+i[0],r.data.y=t[1]+i[1],E.push(r)})),t&&E.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var x={nodes:E,edges:m};return null==f||f(x),x},t}(),rt=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,o){r.forEach((function(r,s){r===1/0&&(t[o][s]=e)}))}))},ot=function(t){var e=Y.mul(Y.pow(t,2),-.5),r=e.mean("row"),o=e.mean("column"),s=e.mean();e.add(s).subRowVector(r).subColumnVector(o);var n=new Z(e),i=Y.sqrt(n.diagonalMatrix).diagonal();return n.leftSingularVectors.toJSON().map((function(t){return Y.mul([t],[i]).toJSON()[0].splice(0,2)}))},st={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},nt=function(t,e,r,o,s,n){e.forEach((function(i,a){r[a]={x:0,y:0},e.forEach((function(e,h){if(a!==h&&s[a]===s[h]){var u=i.x-e.x,l=i.y-e.y,c=Math.sqrt(u*u+l*l);if(0===c){c=1;var f=a>h?1:-1;u=.01*f,l=.01*f}if(c<n(t[a])/2+n(t[h])/2){var d=o*o/c;r[a].x+=u/c*d,r[a].y+=l/c*d}}}))}))},it=function(t,e,r,o,s,n,i,a){var h=n||i/10;return o&&e.forEach((function(e,r){var o=t[r].x-t[s].x,n=t[r].y-t[s].y,i=Math.sqrt(o*o+n*n),a=n/i,h=-o/i,u=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+h*e.y)/u);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,h*=-1);var c=Math.cos(l)*u;e.x=a*c,e.y=h*c})),t.forEach((function(n,i){if(i!==s){var u=Math.sqrt(e[i].x*e[i].x+e[i].y*e[i].y);if(u>0&&i!==s){var l=Math.min(h*(r/800),u);if(n.x+=e[i].x/u*l,n.y+=e[i].y/u*l,o){var c=n.x-t[s].x,f=n.y-t[s].y,d=Math.sqrt(c*c+f*f);c=c/d*a[i],f=f/d*a[i],n.x=t[s].x+c,n.y=t[s].y+f}}}})),t},at={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,strictRadial:!0,maxPreventOverlapIteration:200,sortBy:void 0,sortStrength:10},ht=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",this.options=o(o({},at),t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,e,r){var a=o(o({},this.options),r),h=a.width,u=a.height,f=a.center,d=a.focusNode,g=a.unitRadius,m=a.nodeSize,p=a.nodeSpacing,w=a.strictRadial,y=a.preventOverlap,v=a.maxPreventOverlapIteration,M=a.sortBy,b=a.linkDistance,E=void 0===b?50:b,x=a.sortStrength,S=void 0===x?10:x,N=a.maxIteration,R=void 0===N?1e3:N,I=a.layoutInvisibles,k=a.onLayoutEnd,A=e.getAllNodes(),T=e.getAllEdges();if(I||(A=A.filter((function(t){return t.data.visible||void 0===t.data.visible})),T=T.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!A||0===A.length){var C={nodes:[],edges:T};return null==k||k(C),C}var D=h||"undefined"==typeof window?h:window.innerWidth,z=u||"undefined"==typeof window?u:window.innerHeight,P=f||[D/2,z/2];if(1===A.length){t&&e.mergeNodeData(A[0].id,{x:P[0],y:P[1]});var V={nodes:[o(o({},A[0]),{data:o(o({},A[0].data),{x:P[0],y:P[1]})})],edges:T};return null==k||k(V),V}var q=A[0];if(i(d)){for(var j=0;j<A.length;j++)if(A[j].id===d){q=A[j];break}}else q=d||A[0];var F=ft(A,q.id),O=c({nodes:A,edges:T},!1),L=l(O),$=gt(L,F);dt(L,F,$+1);var U=L[F],B=D-P[0]>P[0]?P[0]:D-P[0],K=z-P[1]>P[1]?P[1]:z-P[1];0===B&&(B=D/2),0===K&&(K=z/2);var W=Math.min(B,K),J=Math.max.apply(Math,n([],s(U),!1)),_=[],G=g||W/J;U.forEach((function(t,e){_[e]=t*G}));var H,Q=ut(A,L,E,_,G,M,S),X=lt(Q),tt=function(t,e,r){try{var o=Y.mul(Y.pow(e,2),-.5),s=o.mean("row"),n=o.mean("column"),i=o.mean();o.add(i).subRowVector(s).subColumnVector(n);var a=new Z(o),h=Y.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return Y.mul([e],[h]).toJSON()[0].splice(0,t)}))}catch(t){for(var u=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;u.push([c,f])}return u}}(E,Q,E).map((function(t){var e=s(t,2),r=e[0],o=e[1];return{x:(isNaN(r)?Math.random()*E:r)-tt[F].x,y:(isNaN(o)?Math.random()*E:o)-tt[F].y}}));if(this.run(R,tt,X,Q,_,F),y){H=mt(m,p);var et={nodes:A,nodeSizeFunc:H,positions:tt,radii:_,height:z,width:D,strictRadial:Boolean(w),focusIdx:F,iterations:v||200,k:tt.length/4.5};tt=function(t,e){for(var r=o(o({},st),e),s=r.positions,n=r.iterations,i=r.width,a=r.k,h=r.speed,u=void 0===h?100:h,l=r.strictRadial,c=r.focusIdx,f=r.radii,d=void 0===f?[]:f,g=r.nodeSizeFunc,m=t.getAllNodes(),p=[],w=i/10,y=0;y<n;y++)s.forEach((function(t,e){p[e]={x:0,y:0}})),nt(m,s,p,a,d,g),it(s,p,u,l,c,w,i,d);return s}(e,et)}var rt=[];tt.forEach((function(t,e){rt.push(o(o({},A[e]),{data:o(o({},A[0].data),{x:t.x+P[0],y:t.y+P[1]})}))})),t&&rt.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var ot={nodes:rt,edges:T};return null==k||k(ot),ot},t.prototype.run=function(t,e,r,o,s,n){for(var i=0;i<=t;i++){var a=i/t;this.oneIteration(a,e,s,o,r,n)}},t.prototype.oneIteration=function(t,e,r,o,s,n){var i=1-t;e.forEach((function(a,h){var u=ct(a,{x:0,y:0}),l=0===u?0:1/u;if(h!==n){var c=0,f=0,d=0;e.forEach((function(t,e){if(h!==e){var r=ct(a,t),n=0===r?0:1/r,i=o[e][h];d+=s[h][e],c+=s[h][e]*(t.x+i*(a.x-t.x)*n),f+=s[h][e]*(t.y+i*(a.y-t.y)*n)}}));var g=0===r[h]?0:1/r[h];d*=i,d+=t*g*g,c*=i,c+=t*g*a.x*l,a.x=c/d,f*=i,f+=t*g*a.y*l,a.y=f/d}}))},t}(),ut=function(t,e,r,o,s,n,a){if(!t)return[];var h=[];return e&&e.forEach((function(e,u){var l=[];e.forEach((function(e,h){if(u===h)l.push(0);else if(o[u]===o[h])if("data"===n)l.push(e*(Math.abs(u-h)*a)/(o[u]/s));else if(n){var c=t[u][n]||0,f=t[h][n]||0;i(c)&&(c=c.charCodeAt(0)),i(f)&&(f=f.charCodeAt(0)),l.push(e*(Math.abs(c-f)*a)/(o[u]/s))}else l.push(e*r/(o[u]/s));else{var d=(r+s)/2;l.push(e*d)}})),h.push(l)})),h},lt=function(t){for(var e=t.length,r=t[0].length,o=[],s=0;s<e;s++){for(var n=[],i=0;i<r;i++)0!==t[s][i]?n.push(1/(t[s][i]*t[s][i])):n.push(0);o.push(n)}return o},ct=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},ft=function(t,e){var r=-1;return t.forEach((function(t,o){t.id===e&&(r=o)})),Math.max(r,0)},dt=function(t,e,r){for(var o=t.length,s=0;s<o;s++)if(t[e][s]===1/0){t[e][s]=r,t[s][e]=r;for(var n=0;n<o;n++)t[s][n]!==1/0&&t[e][n]===1/0&&(t[e][n]=r+t[s][n],t[n][e]=r+t[s][n])}for(s=0;s<o;s++)if(s!==e)for(n=0;n<o;n++)if(t[s][n]===1/0){var i=Math.abs(t[e][s]-t[e][n]);i=0===i?1:i,t[s][n]=i}},gt=function(t,e){for(var r=0,o=0;o<t[e].length;o++)t[e][o]!==1/0&&(r=t[e][o]>r?t[e][o]:r);return r},mt=function(t,e){var r;return r=u(e)?function(){return e}:g(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){return t.data.bboxSize?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):t.data.size?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):f(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},pt={center:[0,0],width:300,height:300},wt={circular:w,concentric:b,mds:et,random:function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",this.options=o(o({},pt),t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,i=s.width,a=s.height,h=s.layoutInvisibles,u=s.onLayoutEnd,l=e.getAllNodes();h||(l=l.filter((function(t){return t.data.visible||void 0===t.data.visible})));var c=i||"undefined"==typeof window?i:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=n||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var m={nodes:g,edges:e.getAllEdges()};return null==u||u(m),m},t}(),grid:x,radial:ht};function yt(t,e){var o=t.layout,s=o.id,n=o.options,i=t.nodes,a=t.edges,h=new r({nodes:i,edges:a}),u=wt[s];if(!u)throw new Error("Unknown layout id: ".concat(s));return[new u(n).execute(h),e]}addEventListener("message",(function(t){var r,o=t.data,s=o.type,n=o.method,i=o.id,a=o.params;"RPC"===s&&n&&((r=e[n])?Promise.resolve().then((function(){return r.apply(e,a)})):Promise.reject("No such method")).then((function(t){postMessage({type:"RPC",id:i,result:t})})).catch((function(t){var e={message:t};t.stack&&(e.message=t.message,e.stack=t.stack,e.name=t.name),postMessage({type:"RPC",id:i,error:e})}))})),postMessage({type:"RPC",method:"ready"});\n//# sourceMappingURL=6215b31a5bc171c6c2a5.worker.js.map'])),{name:"[fullhash].worker.js"});return URL.revokeObjectURL(URL.createObjectURL(new Blob(['var t={d:(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{calculateLayout:()=>yt});class r{nodeMap=new Map;edgeMap=new Map;inEdgesMap=new Map;outEdgesMap=new Map;treeIndices=new Map;changes=[];batchCount=0;onChanged=()=>{};constructor(t){t&&(t.nodes&&this.addNodes(t.nodes),t.edges&&this.addEdges(t.edges),t.tree&&this.addTree(t.tree),t.onChanged&&(this.onChanged=t.onChanged))}batch=t=>{this.batchCount+=1,t(),this.batchCount-=1,this.batchCount||this.commit()};commit(){const t=this.changes;this.changes=[],this.onChanged({graph:this,changes:t})}reduceChanges(t){let e=[];return t.forEach((t=>{switch(t.type){case"NodeRemoved":{let r=!1;e=e.filter((e=>{if("NodeAdded"===e.type){const o=e.value.id===t.value.id;return o&&(r=!0),!o}return"NodeDataUpdated"===e.type?e.id!==t.value.id:"TreeStructureChanged"!==e.type||e.nodeId!==t.value.id})),r||e.push(t);break}case"EdgeRemoved":{let r=!1;e=e.filter((e=>{if("EdgeAdded"===e.type){const o=e.value.id===t.value.id;return o&&(r=!0),!o}return"EdgeDataUpdated"!==e.type&&"EdgeUpdated"!==e.type||e.id!==t.value.id})),r||e.push(t);break}case"NodeDataUpdated":case"EdgeDataUpdated":case"EdgeUpdated":{const r=e.find((e=>e.type===t.type&&e.id===t.id&&e.propertyName===t.propertyName));r?r.newValue=t.newValue:e.push(t);break}case"TreeStructureDetached":e=e.filter((e=>"TreeStructureAttached"===e.type?e.treeKey!==t.treeKey:"TreeStructureChanged"!==e.type||e.treeKey!==t.treeKey)),e.push(t);break;case"TreeStructureChanged":{const r=e.find((e=>"TreeStructureChanged"===e.type&&e.treeKey===t.treeKey&&e.nodeId===t.nodeId));r?r.newParentId=t.newParentId:e.push(t);break}default:e.push(t)}})),e}checkNodeExistence(t){if(!this.hasNode(t))throw new Error("Node not found for id: "+t)}hasNode(t){return this.nodeMap.has(t)}areNeighbors(t,e){return this.checkNodeExistence(t),this.getNeighbors(e).some((e=>e.id===t))}getNode(t){return this.checkNodeExistence(t),this.nodeMap.get(t)}getRelatedEdges(t,e){this.checkNodeExistence(t);const r=this.inEdgesMap.get(t),o=this.outEdgesMap.get(t);if("in"===e)return Array.from(r);if("out"===e)return Array.from(o);const s=new Set([...r,...o]);return Array.from(s)}getDegree(t,e){return this.getRelatedEdges(t,e).length}getSuccessors(t){const e=this.getRelatedEdges(t,"out").map((t=>t.target));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getPredecessors(t){const e=this.getRelatedEdges(t,"in").map((t=>t.source));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getNeighbors(t){const e=this.getPredecessors(t),r=this.getSuccessors(t);return Array.from(new Set([...e,...r]))}doAddNode(t){if(this.hasNode(t.id))throw new Error("Node already exists: "+t.id);this.nodeMap.set(t.id,t),this.inEdgesMap.set(t.id,new Set),this.outEdgesMap.set(t.id,new Set),this.treeIndices.forEach((e=>{e.childrenMap.set(t.id,new Set)})),this.changes.push({type:"NodeAdded",value:t})}addNodes(t){this.batch((()=>{for(const e of t)this.doAddNode(e)}))}addNode(t){this.addNodes([t])}doRemoveNode(t){const e=this.getNode(t),r=this.inEdgesMap.get(t),o=this.outEdgesMap.get(t);r?.forEach((t=>this.doRemoveEdge(t.id))),o?.forEach((t=>this.doRemoveEdge(t.id))),this.nodeMap.delete(t),this.treeIndices.forEach((e=>{e.childrenMap.get(t)?.forEach((t=>{e.parentMap.delete(t.id)})),e.parentMap.delete(t),e.childrenMap.delete(t)})),this.changes.push({type:"NodeRemoved",value:e})}removeNodes(t){this.batch((()=>{t.forEach((t=>this.doRemoveNode(t)))}))}removeNode(t){this.removeNodes([t])}updateNodeData(t,e,r){const o=this.getNode(t);this.batch((()=>{const s=o.data[e],n=r;o.data[e]=n,this.changes.push({type:"NodeDataUpdated",id:t,propertyName:e,oldValue:s,newValue:n})}))}mergeNodeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateNodeData(t,e,r)}))}))}checkEdgeExistence(t){if(!this.hasEdge(t))throw new Error("Edge not found for id: "+t)}hasEdge(t){return this.edgeMap.has(t)}getEdge(t){return this.checkEdgeExistence(t),this.edgeMap.get(t)}getEdgeDetail(t){const e=this.getEdge(t);return{edge:e,source:this.getNode(e.source),target:this.getNode(e.target)}}doAddEdge(t){if(this.hasEdge(t.id))throw new Error("Edge already exists: "+t.id);this.checkNodeExistence(t.source),this.checkNodeExistence(t.target),this.edgeMap.set(t.id,t);const e=this.inEdgesMap.get(t.target),r=this.outEdgesMap.get(t.source);e.add(t),r.add(t),this.changes.push({type:"EdgeAdded",value:t})}addEdges(t){this.batch((()=>{for(const e of t)this.doAddEdge(e)}))}addEdge(t){this.addEdges([t])}doRemoveEdge(t){const e=this.getEdge(t),r=this.outEdgesMap.get(e.source),o=this.inEdgesMap.get(e.target);r.delete(e),o.delete(e),this.edgeMap.delete(t),this.changes.push({type:"EdgeRemoved",value:e})}removeEdges(t){this.batch((()=>{t.forEach((t=>this.doRemoveEdge(t)))}))}removeEdge(t){this.removeEdges([t])}updateEdgeSource(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const o=r.source,s=e;this.outEdgesMap.get(o).delete(r),this.outEdgesMap.get(s).add(r),r.source=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"source",oldValue:o,newValue:s})}))}updateEdgeTarget(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const o=r.target,s=e;this.inEdgesMap.get(o).delete(r),this.inEdgesMap.get(s).add(r),r.target=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"target",oldValue:o,newValue:s})}))}updateEdgeData(t,e,r){const o=this.getEdge(t);this.batch((()=>{const s=o.data[e],n=r;o.data[e]=n,this.changes.push({type:"EdgeDataUpdated",id:t,propertyName:e,oldValue:s,newValue:n})}))}mergeEdgeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateEdgeData(t,e,r)}))}))}checkTreeExistence(t){if(!this.treeIndices.has(t))throw new Error("Tree structure not found for treeKey: "+t)}attachTreeStructure(t){this.treeIndices.has(t)||(this.treeIndices.set(t,{parentMap:new Map,childrenMap:new Map}),this.batch((()=>{this.changes.push({type:"TreeStructureAttached",treeKey:t})})))}detachTreeStructure(t){this.checkTreeExistence(t),this.treeIndices.delete(t),this.batch((()=>{this.changes.push({type:"TreeStructureDetached",treeKey:t})}))}addTree(t,e){this.batch((()=>{this.attachTreeStructure(e);const r=[],o=Array.isArray(t)?t:[t];for(;o.length;){const t=o.shift();r.push(t),t.children&&o.push(...t.children)}this.addNodes(r),r.forEach((t=>{t.children?.forEach((r=>{this.setParent(r.id,t.id,e)}))}))}))}getRoots(t){return this.checkTreeExistence(t),this.getAllNodes().filter((e=>!this.getParent(e.id,t)))}getChildren(t,e){this.checkNodeExistence(t),this.checkTreeExistence(e);const r=this.treeIndices.get(e).childrenMap.get(t);return Array.from(r||[])}getParent(t,e){return this.checkNodeExistence(t),this.checkTreeExistence(e),this.treeIndices.get(e).parentMap.get(t)||null}setParent(t,e,r){this.checkTreeExistence(r);const o=this.treeIndices.get(r),s=this.getNode(t),n=o.parentMap.get(t),i=this.getNode(e);o.parentMap.set(t,i),n&&o.childrenMap.get(n.id)?.delete(s);let a=o.childrenMap.get(i.id);a||(a=new Set,o.childrenMap.set(i.id,a)),a.add(s),this.batch((()=>{this.changes.push({type:"TreeStructureChanged",treeKey:r,nodeId:t,oldParentId:n?.id,newParentId:i.id})}))}getAllNodes(){return Array.from(this.nodeMap.values())}getAllEdges(){return Array.from(this.edgeMap.values())}doBFS(t,e,r){for(;t.length;){const o=t.shift();r(o),e.add(o.id),this.getSuccessors(o.id).forEach((r=>{e.has(r.id)||(e.add(r.id),t.push(r))}))}}bfs(t,e){this.doBFS([this.getNode(t)],new Set,e)}doDFS(t,e,r){r(t),e.add(t.id),this.getSuccessors(t.id).forEach((t=>{e.has(t.id)||this.doDFS(t,e,r)}))}dfs(t,e){this.doDFS(this.getNode(t),new Set,e)}clone(){const t=this.getAllNodes().map((t=>({...t,data:{...t.data}}))),e=this.getAllEdges().map((t=>({...t,data:{...t.data}}))),o=new r({nodes:t,edges:e});return this.treeIndices.forEach((({parentMap:t,childrenMap:e},r)=>{const s=new Map;t.forEach(((t,e)=>{s.set(e,o.getNode(t.id))}));const n=new Map;e.forEach(((t,e)=>{n.set(e,new Set(Array.from(t).map((t=>o.getNode(t.id)))))})),o.treeIndices.set(r,{parentMap:s,childrenMap:n})})),o}toJSON(){return JSON.stringify({nodes:this.getAllNodes(),edges:this.getAllEdges()})}}var o=function(){return o=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++)for(var s in e=arguments[r])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},o.apply(this,arguments)};function s(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,s,n=r.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(t){s={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function n(t,e,r){if(r||2===arguments.length)for(var o,s=0,n=e.length;s<n;s++)!o&&s in e||(o||(o=Array.prototype.slice.call(e,0,s)),o[s]=e[s]);return t.concat(o||Array.prototype.slice.call(e))}Object.create,Object.create;var i=function(t){return"string"==typeof t},a=/-(\\w)/g,h=(function(t){return t.replace(a,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),u=function(t){return"number"==typeof t},l=function(t){for(var e=[],r=t.length,o=0;o<r;o+=1){e[o]=[];for(var s=0;s<r;s+=1)o===s?e[o][s]=0:0!==t[o][s]&&t[o][s]?e[o][s]=t[o][s]:e[o][s]=1/0}for(var n=0;n<r;n+=1)for(o=0;o<r;o+=1)for(s=0;s<r;s+=1)e[o][s]>e[o][n]+e[n][s]&&(e[o][s]=e[o][n]+e[n][s]);return e},c=function(t,e){var r=t.nodes,o=t.edges,s=[],n={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){n[t.id]=e,s.push([])})),null==o||o.forEach((function(t){var r=t.source,o=t.target,i=n[r],a=n[o];void 0!==i&&void 0!==a&&(s[i][a]=1,e||(s[a][i]=1))})),s},f=function(t){return null!==t&&"object"==typeof t},d=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var e=[];return t.forEach((function(t){e.push(t)})),e.map((function(t){return d(t)}))}if("object"==typeof t&&Object.keys(t).length){var r=o({},t);return Object.keys(r).forEach((function(t){r[t]=d(r[t])})),r}return t},g=function(t){return"function"==typeof t},m=function(t,e,r){return void 0===r&&(r=!0),e||0===e?g(e)?e:u(e)?function(){return e}:h(e)?function(){if(r){var o=Math.max.apply(Math,n([],s(e),!1));return isNaN(o)?t:o}return e}:f(e)?function(){if(r){var o=Math.max(e.width,e.height);return isNaN(o)?t:o}return[e.width,e.height]}:function(){return t}:function(e){return e.size?h(e.size)?e.size[0]>e.size[1]?e.size[0]:e.size[1]:f(e.size)?e.size.width>e.size.height?e.size.width:e.size.height:e.size:t}},p={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},w=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=o(o({},p),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){var r=this;t.batch((function(){r.genericCircularLayout(!0,t,e)}))},t.prototype.genericCircularLayout=function(t,e,r){var n=o(o({},this.options),r),i=n.width,a=n.height,h=n.center,u=n.divisions,l=n.startAngle,c=void 0===l?0:l,f=n.endAngle,g=void 0===f?2*Math.PI:f,p=n.angleRatio,w=n.ordering,M=n.clockwise,b=n.nodeSpacing,E=n.nodeSize,x=n.layoutInvisibles,S=n.onLayoutEnd,N=e.getAllNodes(),R=e.getAllEdges();x||(N=N.filter((function(t){return t.data.visible||void 0===t.data.visible})),R=R.filter((function(t){return t.data.visible||void 0===t.data.visible})));var I=N.length;if(0===I)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var k=s(v(i,a,h),3),A=k[0],T=k[1],C=k[2];if(1===I){t&&e.mergeNodeData(N[0].id,{x:C[0],y:C[1]});var D={nodes:[o(o({},N[0]),{data:o(o({},N[0].data),{x:C[0],y:C[1]})})],edges:R};return null==S||S(D),D}var z=(g-c)/I,P=n.radius,V=n.startRadius,q=n.endRadius;if(b){var j=m(10,b),F=m(10,E),O=-1/0;N.forEach((function(t){var e=F(t);O<e&&(O=e)}));var L=0;N.forEach((function(t,e){L+=0===e?O||10:(j(t)||0)+(O||10)})),P=L/(2*Math.PI)}else P||V||q?!V&&q?V=q:V&&!q&&(q=V):P=Math.min(T,A)/2;var $=z*p,U=[];U="topology"===w?y(e,N):"topology-directed"===w?y(e,N,!0):"degree"===w?function(t,e){var r=[];return e.forEach((function(t,e){r.push(d(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(e,N):N.map((function(t){return d(t)}));for(var B=Math.ceil(I/u),K=0;K<I;++K){var W=P;W||null===V||null===q||(W=V+K*(q-V)/(I-1)),W||(W=10+100*K/(I-1));var J=c+K%B*$+2*Math.PI/u*Math.floor(K/B);M||(J=g-K%B*$-2*Math.PI/u*Math.floor(K/B)),U[K].data.x=C[0]+Math.cos(J)*W,U[K].data.y=C[1]+Math.sin(J)*W}t&&U.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var _={nodes:U,edges:R};return null==S||S(_),_},t}(),y=function(t,e,r){void 0===r&&(r=!1);var o=[d(e[0])],s={},n=e.length;s[e[0].id]=!0;var i=0;return e.forEach((function(a,h){if(0!==h)if(h!==n-1&&t.getDegree(a.id,"both")===t.getDegree(e[h+1].id,"both")&&!t.areNeighbors(o[i].id,a.id)||s[a.id]){for(var u=r?t.getSuccessors(o[i].id):t.getNeighbors(o[i].id),l=!1,c=0;c<u.length;c++){var f=u[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!s[f.id]){o.push(d(f)),s[f.id]=!0,l=!0;break}}for(var g=0;!l&&(s[e[g].id]||(o.push(d(e[g])),s[e[g].id]=!0,l=!0),++g!==n););}else o.push(d(a)),s[a.id]=!0,i++})),o},v=function(t,e,r){var o=t,s=e,n=r;return o||"undefined"==typeof window||(o=window.innerWidth),s||"undefined"==typeof window||(s=window.innerHeight),n||(n=[o/2,s/2]),[o,s,n]},M={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},b=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",this.options=o(o({},M),t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,a=s.width,l=s.height,c=s.sortBy,m=s.maxLevelDiff,p=s.sweep,w=s.clockwise,y=s.equidistant,v=s.minNodeSpacing,M=void 0===v?10:v,b=s.preventOverlap,E=s.startAngle,x=void 0===E?1.5*Math.PI:E,S=s.nodeSize,N=s.nodeSpacing,R=s.layoutInvisibles,I=s.onLayoutEnd,k=e.getAllNodes(),A=e.getAllEdges();R||(k=k.filter((function(t){return t.data.visible||void 0===t.data.visible})),A=A.filter((function(t){return t.data.visible||void 0===t.data.visible})));var T=k.length;if(0===T){var C={nodes:[],edges:A};return null==I||I(C),C}var D=a||"undefined"==typeof window?a:window.innerWidth,z=l||"undefined"==typeof window?l:window.innerHeight,P=n||[D/2,z/2];if(1===T){t&&e.mergeNodeData(k[0].id,{x:P[0],y:P[1]});var V={nodes:[o(o({},k[0]),{data:o(o({},k[0].data),{x:P[0],y:P[1]})})],edges:A};return null==I||I(V),V}var q,j=[],F=0;q=h(S)?Math.max(S[0],S[1]):S,h(N)?F=Math.max(N[0],N[1]):u(N)&&(F=N),k.forEach((function(t){j.push(d(t));var e=q;h(t.data.size)?e=Math.max(t.data.size[0],t.data.size[1]):u(t.data.size)?e=t.data.size:f(t.data.size)&&(e=Math.max(t.data.size.width,t.data.size.height)),q=Math.max(q,e),g(N)&&(F=Math.max(N(t),F))}));var O={};j.forEach((function(t,e){O[t.id]=e}));var L=c;i(L)&&void 0!==j[0].data[L]||(L="degree"),"degree"===L?j.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):j.sort((function(t,e){return e.data[L]-t.data[L]}));var $=j[0],U=m||$.data[L]/4,B=[{nodes:[]}],K=B[0];j.forEach((function(t){if(K.nodes.length>0){var e=Math.abs(K.nodes[0].data[L]-t.data[L]);U&&e>=U&&(K={nodes:[]},B.push(K))}K.nodes.push(t)}));var W=q+(F||M);if(!b){var J=B.length>0&&B[0].nodes.length>1,_=(Math.min(D,z)/2-W)/(B.length+(J?1:0));W=Math.min(W,_)}var G=0;if(B.forEach((function(t){var e=void 0===p?2*Math.PI-2*Math.PI/t.nodes.length:p;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&b){var r=Math.cos(t.dTheta)-Math.cos(0),o=Math.sin(t.dTheta)-Math.sin(0),s=Math.sqrt(W*W/(r*r+o*o));G=Math.max(s,G)}t.r=G,G+=W})),y){for(var H=0,Y=0,Q=0;Q<B.length;Q++){var X=(B[Q].r||0)-Y;H=Math.max(H,X)}Y=0,B.forEach((function(t,e){0===e&&(Y=t.r||0),t.r=Y,Y+=H}))}B.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,o){var s=x+(w?1:-1)*e*o;t.data.x=P[0]+r*Math.cos(s),t.data.y=P[1]+r*Math.sin(s)}))})),t&&j.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Z={nodes:j,edges:A};return null==I||I(Z),Z},t}(),E={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},x=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",this.options=o(o({},E),t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.begin,a=void 0===n?[0,0]:n,l=s.condense,c=s.preventOverlapPadding,f=s.preventOverlap,g=s.columns,p=s.rows,w=s.cols,y=void 0===w?g:w,v=s.nodeSpacing,M=s.nodeSize,b=s.width,E=s.height,x=s.layoutInvisibles,k=s.onLayoutEnd,T=s.position,C=s.sortBy,D=e.getAllNodes(),z=e.getAllEdges();x||(D=D.filter((function(t){return t.data.visible||void 0===t.data.visible})),z=z.filter((function(t){return t.data.visible||void 0===t.data.visible})));var P=D.length;if(0===P){var V={nodes:[],edges:z};return null==k||k(V),V}if(1===P){t&&e.mergeNodeData(D[0].id,{x:a[0],y:a[1]});var q={nodes:[o(o({},D[0]),{data:o(o({},D[0].data),{x:a[0],y:a[1]})})],edges:z};return null==k||k(q),q}var j=D.map((function(t){return d(t)}));"id"===C||i(C)&&void 0!==j[0].data[C]||(C="degree"),"degree"===C?j.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):"id"===C?j.sort((function(t,e){return u(e.id)&&u(t.id)?e.id-t.id:"".concat(e.id).localeCompare("".concat(t.id))})):j.sort((function(t,e){return e.data[C]-t.data[C]}));var F=b||"undefined"==typeof window?b:window.innerWidth,O=E||"undefined"==typeof window?E:window.innerHeight,L=P,$={rows:p,cols:y};if(null!=p&&null!=y)$.rows=p,$.cols=y;else if(null!=p&&null==y)$.rows=p,$.cols=Math.ceil(L/$.rows);else if(null==p&&null!=y)$.cols=y,$.rows=Math.ceil(L/$.cols);else{var U=Math.sqrt(L*O/F);$.rows=Math.round(U),$.cols=Math.round(F/O*U)}if($.rows=Math.max($.rows,1),$.cols=Math.max($.cols,1),$.cols*$.rows>L)((K=S($))-1)*(B=N($))>=L?S($,K-1):(B-1)*K>=L&&N($,B-1);else for(;$.cols*$.rows<L;){var B,K=S($);((B=N($))+1)*K>=L?N($,B+1):S($,K+1)}var W=l?0:F/$.cols,J=l?0:O/$.rows;if(f||v){var _=m(10,v),G=m(30,M,!1);j.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var r,o,s=e.getNode(t.id),n=G(s)||30;h(n)?(r=n[0],o=n[1]):(r=n,o=n);var i=void 0!==_?_(t):c,a=r+i,u=o+i;W=Math.max(W,a),J=Math.max(J,u)}))}for(var H={},Y={row:0,col:0},Q={},X=0;X<j.length;X++){var Z=j[X],tt=void 0;if(T&&(tt=T(e.getNode(Z.id))),tt&&(void 0!==tt.row||void 0!==tt.col)){var et={row:tt.row,col:tt.col};if(void 0===et.col)for(et.col=0;R(H,et);)et.col++;else if(void 0===et.row)for(et.row=0;R(H,et);)et.row++;Q[Z.id]=et,I(H,et)}A(Z,a,W,J,Q,$,Y,H)}var rt={nodes:j,edges:z};return null==k||k(rt),t&&j.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),rt},t}(),S=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.min(o,s):Math.min(o,s)===t.rows?t.rows=e:t.cols=e,r},N=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.max(o,s):Math.max(o,s)===t.rows?t.rows=e:t.cols=e,r},R=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},I=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},k=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},A=function(t,e,r,o,s,n,i,a){var h,u,l=s[t.id];if(l)h=l.col*r+r/2+e[0],u=l.row*o+o/2+e[1];else{for(;R(a,i);)k(n,i);h=i.col*r+r/2+e[0],u=i.row*o+o/2+e[1],I(a,i),k(n,i)}t.data.x=h,t.data.y=u};const T=Object.prototype.toString;function C(t){return T.call(t).endsWith("Array]")}function D(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!C(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]>i&&(i=t[a]);return i}function z(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!C(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]<i&&(i=t[a]);return i}function P(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!C(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!C(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var o=z(t),s=D(t);if(o===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=r.min,i=void 0===n?r.autoMinMax?o:0:n,a=r.max,h=void 0===a?r.autoMinMax?s:1:a;if(i>=h)throw new RangeError("min option must be smaller than max option");for(var u=(h-i)/(s-o),l=0;l<t.length;l++)e[l]=(t[l]-o)*u+i;return e}const V=" ".repeat(2),q=" ".repeat(4);function j(t,e={}){const{maxRows:r=15,maxColumns:o=10,maxNumSize:s=8,padMinus:n="auto"}=e;return`${t.constructor.name} {\\n${V}[\\n${q}${function(t,e,r,o,s){const{rows:n,columns:i}=t,a=Math.min(n,e),h=Math.min(i,r),u=[];if("auto"===s){s=!1;t:for(let e=0;e<a;e++)for(let r=0;r<h;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let n=0;n<h;n++)r.push(F(t.get(e,n),o,s));u.push(`${r.join(" ")}`)}return h!==i&&(u[u.length-1]+=` ... ${i-r} more columns`),a!==n&&u.push(`... ${n-e} more rows`),u.join(`\\n${q}`)}(t,r,o,s,n)}\\n${V}]\\n${V}rows: ${t.rows}\\n${V}columns: ${t.columns}\\n}`}function F(t,e,r){return(t>=0&&r?` ${O(t,e-1)}`:O(t,e)).padEnd(e)}function O(t,e){let r=t.toString();if(r.length<=e)return r;let o=t.toFixed(e);if(o.length>e&&(o=t.toFixed(Math.max(0,e-(o.length-e)))),o.length<=e&&!o.startsWith("0.000")&&!o.startsWith("-0.000"))return o;let s=t.toExponential(e);return s.length>e&&(s=t.toExponential(Math.max(0,e-(s.length-e)))),s.slice(0)}function L(t,e,r){let o=r?t.rows:t.rows-1;if(e<0||e>o)throw new RangeError("Row index out of range")}function $(t,e,r){let o=r?t.columns:t.columns-1;if(e<0||e>o)throw new RangeError("Column index out of range")}function U(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function B(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function K(t,e,r,o,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(J("startRow",e),J("endRow",r),J("startColumn",o),J("endColumn",s),e>r||o>s||e<0||e>=t.rows||r<0||r>=t.rows||o<0||o>=t.columns||s<0||s>=t.columns)throw new RangeError("Submatrix indices are out of range")}function W(t,e=0){let r=[];for(let o=0;o<t;o++)r.push(e);return r}function J(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function _(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class G{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let o=new Y(t,e);for(let s=0;s<t;s++)for(let t=0;t<e;t++)o.set(s,t,r[s*e+t]);return o}static rowVector(t){let e=new Y(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new Y(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new Y(t,e)}static ones(t,e){return new Y(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:o=Math.random}=r;let s=new Y(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)s.set(r,t,o());return s}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:o=0,max:s=1e3,random:n=Math.random}=r;if(!Number.isInteger(o))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(o>=s)throw new RangeError("min must be smaller than max");let i=s-o,a=new Y(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=o+Math.round(n()*i);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let o=Math.min(t,e),s=this.zeros(t,e);for(let t=0;t<o;t++)s.set(t,t,r);return s}static diag(t,e,r){let o=t.length;void 0===e&&(e=o),void 0===r&&(r=e);let s=Math.min(o,e,r),n=this.zeros(e,r);for(let e=0;e<s;e++)n.set(e,e,t[e]);return n}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new Y(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.min(t.get(n,r),e.get(n,r)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new this(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.max(t.get(n,r),e.get(n,r)));return s}static checkMatrix(t){return G.isMatrix(t)?t:new Y(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);t++}return o}isReducedEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(o=!1);t++}return o}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let o=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(o,r)&&(o=s);if(0===t.get(o,r))r++;else{t.swapRows(e,o);let s=t.get(e,r);for(let o=r;o<t.columns;o++)t.set(e,o,t.get(e,o)/s);for(let o=e+1;o<t.rows;o++){let s=t.get(o,r)/t.get(e,r);t.set(o,r,0);for(let n=r+1;n<t.columns;n++)t.set(o,n,t.get(o,n)-t.get(e,n)*s)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,o=r-1;for(;o>=0;)if(0===t.maxRow(o))o--;else{let s=0,n=!1;for(;s<r&&!1===n;)1===t.get(o,s)?n=!0:s++;for(let r=0;r<o;r++){let n=t.get(r,s);for(let i=s;i<e;i++){let e=t.get(r,i)-n*t.get(o,i);t.set(r,i,e)}}o--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let o=new Y(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)o.setSubMatrix(this,this.rows*t,this.columns*e);return o}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){L(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return Y.rowVector(this.getRow(t))}setRow(t,e){L(this,t),e=U(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){L(this,t),L(this,e);for(let r=0;r<this.columns;r++){let o=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,o)}return this}getColumn(t){$(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return Y.columnVector(this.getColumn(t))}setColumn(t,e){$(this,t),e=B(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){$(this,t),$(this,e);for(let r=0;r<this.rows;r++){let o=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,o)}return this}addRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=U(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=B(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){L(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){$(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){_(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){_(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}maxRow(t){if(L(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){L(this,t),_(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)>e&&(e=this.get(t,o),r[1]=o);return r}minRow(t){if(L(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){L(this,t),_(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)<e&&(e=this.get(t,o),r[1]=o);return r}maxColumn(t){if($(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){$(this,t),_(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)>e&&(e=this.get(o,t),r[0]=o);return r}minColumn(t){if($(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){$(this,t),_(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)<e&&(e=this.get(o,t),r[0]=o);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){G.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let o=0;o<e.length;o++)r+=e[o]*t[o];return r}mmul(t){t=Y.checkMatrix(t);let e=this.rows,r=this.columns,o=t.columns,s=new Y(e,o),n=new Float64Array(r);for(let i=0;i<o;i++){for(let e=0;e<r;e++)n[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let o=0;o<r;o++)e+=this.get(t,o)*n[o];s.set(t,i,e)}}return s}strassen2x2(t){t=Y.checkMatrix(t);let e=new Y(2,2);const r=this.get(0,0),o=t.get(0,0),s=this.get(0,1),n=t.get(0,1),i=this.get(1,0),a=t.get(1,0),h=this.get(1,1),u=t.get(1,1),l=(r+h)*(o+u),c=(i+h)*o,f=r*(n-u),d=h*(a-o),g=(r+s)*u,m=l+d-g+(s-h)*(a+u),p=f+g,w=c+d,y=l-c+f+(i-r)*(o+n);return e.set(0,0,m),e.set(0,1,p),e.set(1,0,w),e.set(1,1,y),e}strassen3x3(t){t=Y.checkMatrix(t);let e=new Y(3,3);const r=this.get(0,0),o=this.get(0,1),s=this.get(0,2),n=this.get(1,0),i=this.get(1,1),a=this.get(1,2),h=this.get(2,0),u=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),m=t.get(1,1),p=t.get(1,2),w=t.get(2,0),y=t.get(2,1),v=t.get(2,2),M=(r-n)*(-f+m),b=(-r+n+i)*(c-f+m),E=(n+i)*(-c+f),x=r*c,S=(-r+h+u)*(c-d+p),N=(-r+h)*(d-p),R=(h+u)*(-c+d),I=(-s+u+l)*(m+w-y),k=(s-l)*(m-y),A=s*w,T=(u+l)*(-w+y),C=(-s+i+a)*(p+w-v),D=(s-a)*(p-v),z=(i+a)*(-w+v),P=x+A+o*g,V=(r+o+s-n-i-u-l)*m+b+E+x+I+A+T,q=x+S+R+(r+o+s-i-a-h-u)*p+A+C+z,j=M+i*(-c+f+g-m-p-w+v)+b+x+A+C+D,F=M+b+E+x+a*y,O=A+C+D+z+n*d,L=x+S+N+u*(-c+d+g-m-p-w+y)+I+k+A,$=I+k+A+T+h*f,U=x+S+N+R+l*v;return e.set(0,0,P),e.set(0,1,V),e.set(0,2,q),e.set(1,0,j),e.set(1,1,F),e.set(1,2,O),e.set(2,0,L),e.set(2,1,$),e.set(2,2,U),e}mmulStrassen(t){t=Y.checkMatrix(t);let e=this.clone(),r=e.rows,o=e.columns,s=t.rows,n=t.columns;function i(t,e,r){let o=t.rows,s=t.columns;if(o===e&&s===r)return t;{let o=G.zeros(e,r);return o=o.setSubMatrix(t,0,0),o}}o!==s&&console.warn(`Multiplying ${r} x ${o} and ${s} x ${n} matrix: dimensions do not match.`);let a=Math.max(r,s),h=Math.max(o,n);return e=i(e,a,h),function t(e,r,o,s){if(o<=512||s<=512)return e.mmul(r);o%2==1&&s%2==1?(e=i(e,o+1,s+1),r=i(r,o+1,s+1)):o%2==1?(e=i(e,o+1,s),r=i(r,o+1,s)):s%2==1&&(e=i(e,o,s+1),r=i(r,o,s+1));let n=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),h=e.subMatrix(0,n-1,0,a-1),u=r.subMatrix(0,n-1,0,a-1),l=e.subMatrix(0,n-1,a,e.columns-1),c=r.subMatrix(0,n-1,a,r.columns-1),f=e.subMatrix(n,e.rows-1,0,a-1),d=r.subMatrix(n,r.rows-1,0,a-1),g=e.subMatrix(n,e.rows-1,a,e.columns-1),m=r.subMatrix(n,r.rows-1,a,r.columns-1),p=t(G.add(h,g),G.add(u,m),n,a),w=t(G.add(f,g),u,n,a),y=t(h,G.sub(c,m),n,a),v=t(g,G.sub(d,u),n,a),M=t(G.add(h,l),m,n,a),b=t(G.sub(f,h),G.add(u,c),n,a),E=t(G.sub(l,g),G.add(d,m),n,a),x=G.add(p,v);x.sub(M),x.add(E);let S=G.add(y,M),N=G.add(w,v),R=G.sub(p,w);R.add(y),R.add(b);let I=G.zeros(2*x.rows,2*x.columns);return I=I.setSubMatrix(x,0,0),I=I.setSubMatrix(S,x.rows,0),I=I.setSubMatrix(N,0,x.columns),I=I.setSubMatrix(R,x.rows,x.columns),I.subMatrix(0,o-1,0,s-1)}(e,t=i(t,a,h),a,h)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new Y(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&P(s,{min:e,max:r,output:s}),o.setRow(t,s)}return o}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new Y(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&P(s,{min:e,max:r,output:s}),o.setColumn(t,s)}return o}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),o=this.get(e,this.columns-1-r);this.set(e,r,o),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),o=this.get(this.rows-1-r,e);this.set(r,e,o),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=Y.checkMatrix(t);let e=this.rows,r=this.columns,o=t.rows,s=t.columns,n=new Y(e*o,r*s);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<o;r++)for(let a=0;a<s;a++)n.set(o*i+r,s*e+a,this.get(i,e)*t.get(r,a));return n}kroneckerSum(t){if(t=Y.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,o=this.kroneckerProduct(Y.eye(r,r)),s=Y.eye(e,e).kroneckerProduct(t);return o.add(s)}transpose(){let t=new Y(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=H){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=H){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,o){K(this,t,e,r,o);let s=new Y(e-t+1,o-r+1);for(let n=t;n<=e;n++)for(let e=r;e<=o;e++)s.set(n-t,e-r,this.get(n,e));return s}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let o=new Y(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);o.set(s,n-e,this.get(t[s],n))}return o}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let o=new Y(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);o.set(n-e,s,this.get(n,t[s]))}return o}setSubMatrix(t,e,r){if((t=Y.checkMatrix(t)).isEmpty())return this;K(this,e,e+t.rows-1,r,r+t.columns-1);for(let o=0;o<t.rows;o++)for(let s=0;s<t.columns;s++)this.set(e+o,r+s,t.get(o,s));return this}selection(t,e){!function(t,e){if(!C(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!C(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new Y(t.length,e.length);for(let o=0;o<t.length;o++){let s=t[o];for(let t=0;t<e.length;t++){let n=e[t];r.set(o,t,this.get(s,n))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new Y(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=W(t.rows);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]+=t.get(r,o);return e}(this);case"column":return function(t){let e=W(t.columns);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]+=t.get(r,o);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e+=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=W(t.rows,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]*=t.get(r,o);return e}(this);case"column":return function(t){let e=W(t.columns,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]*=t.get(r,o);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e*=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:o=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!C(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<o;i++){let o=0,a=0,h=0;for(let e=0;e<s;e++)h=t.get(i,e)-r[i],o+=h,a+=h*h;e?n.push((a-o*o/s)/(s-1)):n.push((a-o*o/s)/s)}return n}(this,r,o);case"column":if(!C(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<s;i++){let s=0,a=0,h=0;for(let e=0;e<o;e++)h=t.get(e,i)-r[i],s+=h,a+=h*h;e?n.push((a-s*s/o)/(o-1)):n.push((a-s*s/o)/o)}return n}(this,r,o);case void 0:if("number"!=typeof o)throw new TypeError("mean must be a number");return function(t,e,r){const o=t.rows,s=t.columns,n=o*s;let i=0,a=0,h=0;for(let e=0;e<o;e++)for(let o=0;o<s;o++)h=t.get(e,o)-r,i+=h,a+=h*h;return e?(a-i*i/n)/(n-1):(a-i*i/n)/n}(this,r,o);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!C(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[r])}(this,r),this;case"column":if(!C(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[o])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let o=0;for(let e=0;e<t.columns;e++)o+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(o))}return e}(this);else if(!C(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let o=0;for(let e=0;e<t.rows;e++)o+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(o))}return e}(this);else if(!C(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[o])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let o=0;o<t.columns;o++)for(let s=0;s<t.rows;s++)r+=Math.pow(t.get(s,o),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return j(this,t)}}function H(t,e){return t-e}G.prototype.klass="Matrix","undefined"!=typeof Symbol&&(G.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return j(this)}),G.random=G.rand,G.randomInt=G.randInt,G.diagonal=G.diag,G.prototype.diagonal=G.prototype.diag,G.identity=G.eye,G.prototype.negate=G.prototype.neg,G.prototype.tensorProduct=G.prototype.kroneckerProduct;class Y extends G{constructor(t,e){if(super(),Y.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!C(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let o=0;o<t;o++){if(r[o].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[o].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[o]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return L(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),L(this,t,!0),e=Float64Array.from(U(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){$(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let o=0;o<t;o++)r[o]=this.data[e][o];for(let o=t+1;o<this.columns;o++)r[o-1]=this.data[e][o];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),$(this,t,!0),e=B(this,e);for(let r=0;r<this.rows;r++){const o=new Float64Array(this.columns+1);let s=0;for(;s<t;s++)o[s]=this.data[r][s];for(o[s++]=e[r];s<this.columns+1;s++)o[s]=this.data[r][s-1];this.data[r]=o}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(G,Y);class Q extends G{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function X(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class Z{constructor(t,e={}){if((t=Q.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,o=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:n=!0,autoTranspose:i=!1}=e;let a,h=Boolean(s),u=Boolean(n),l=!1;if(r<o)if(i){a=t.transpose(),r=a.rows,o=a.columns,l=!0;let e=h;h=u,u=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,o),f=Math.min(r+1,o),d=new Float64Array(f),g=new Y(r,c),m=new Y(o,o),p=new Float64Array(o),w=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let v=Math.min(r-1,o),M=Math.max(0,Math.min(o-2,r)),b=Math.max(v,M);for(let t=0;t<b;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=X(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<o;e++){if(t<v&&0!==d[t]){let o=0;for(let s=t;s<r;s++)o+=a.get(s,t)*a.get(s,e);o=-o/a.get(t,t);for(let s=t;s<r;s++)a.set(s,e,a.get(s,e)+o*a.get(s,t))}p[e]=a.get(t,e)}if(h&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<M){p[t]=0;for(let e=t+1;e<o;e++)p[t]=X(p[t],p[e]);if(0!==p[t]){p[t+1]<0&&(p[t]=0-p[t]);for(let e=t+1;e<o;e++)p[e]/=p[t];p[t+1]+=1}if(p[t]=-p[t],t+1<r&&0!==p[t]){for(let e=t+1;e<r;e++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<o;r++)w[e]+=p[r]*a.get(e,r);for(let e=t+1;e<o;e++){let o=-p[e]/p[t+1];for(let s=t+1;s<r;s++)a.set(s,e,a.get(s,e)+o*w[s])}}if(u)for(let e=t+1;e<o;e++)m.set(e,t,p[e])}}let E=Math.min(o,r+1);if(v<o&&(d[v]=a.get(v,v)),r<E&&(d[E-1]=0),M+1<E&&(p[M]=a.get(M,E-1)),p[E-1]=0,h){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let o=0;for(let s=t;s<r;s++)o+=g.get(s,t)*g.get(s,e);o=-o/g.get(t,t);for(let s=t;s<r;s++)g.set(s,e,g.get(s,e)+o*g.get(s,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(u)for(let t=o-1;t>=0;t--){if(t<M&&0!==p[t])for(let e=t+1;e<o;e++){let r=0;for(let s=t+1;s<o;s++)r+=m.get(s,t)*m.get(s,e);r=-r/m.get(t+1,t);for(let s=t+1;s<o;s++)m.set(s,e,m.get(s,e)+r*m.get(s,t))}for(let e=0;e<o;e++)m.set(e,t,0);m.set(t,t,1)}let x=E-1,S=0,N=Number.EPSILON;for(;E>0;){let t,e;for(t=E-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+N*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[t]=0;break}}if(t===E-2)e=4;else{let r;for(r=E-1;r>=t&&r!==t;r--){let e=(r!==E?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(d[r])<=N*e){d[r]=0;break}}r===t?e=3:r===E-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[E-2];p[E-2]=0;for(let r=E-2;r>=t;r--){let s=X(d[r],e),n=d[r]/s,i=e/s;if(d[r]=s,r!==t&&(e=-i*p[r-1],p[r-1]=n*p[r-1]),u)for(let t=0;t<o;t++)s=n*m.get(t,r)+i*m.get(t,E-1),m.set(t,E-1,-i*m.get(t,r)+n*m.get(t,E-1)),m.set(t,r,s)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let o=t;o<E;o++){let s=X(d[o],e),n=d[o]/s,i=e/s;if(d[o]=s,e=-i*p[o],p[o]=n*p[o],h)for(let e=0;e<r;e++)s=n*g.get(e,o)+i*g.get(e,t-1),g.set(e,t-1,-i*g.get(e,o)+n*g.get(e,t-1)),g.set(e,o,s)}break}case 3:{const e=Math.max(Math.abs(d[E-1]),Math.abs(d[E-2]),Math.abs(p[E-2]),Math.abs(d[t]),Math.abs(p[t])),s=d[E-1]/e,n=d[E-2]/e,i=p[E-2]/e,a=d[t]/e,l=p[t]/e,c=((n+s)*(n-s)+i*i)/2,f=s*i*(s*i);let w=0;0===c&&0===f||(w=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),w=f/(c+w));let y=(a+s)*(a-s)+w,v=a*l;for(let e=t;e<E-1;e++){let s=X(y,v);0===s&&(s=Number.MIN_VALUE);let n=y/s,i=v/s;if(e!==t&&(p[e-1]=s),y=n*d[e]+i*p[e],p[e]=n*p[e]-i*d[e],v=i*d[e+1],d[e+1]=n*d[e+1],u)for(let t=0;t<o;t++)s=n*m.get(t,e)+i*m.get(t,e+1),m.set(t,e+1,-i*m.get(t,e)+n*m.get(t,e+1)),m.set(t,e,s);if(s=X(y,v),0===s&&(s=Number.MIN_VALUE),n=y/s,i=v/s,d[e]=s,y=n*p[e]+i*d[e+1],d[e+1]=-i*p[e]+n*d[e+1],v=i*p[e+1],p[e+1]=n*p[e+1],h&&e<r-1)for(let t=0;t<r;t++)s=n*g.get(t,e)+i*g.get(t,e+1),g.set(t,e+1,-i*g.get(t,e)+n*g.get(t,e+1)),g.set(t,e,s)}p[E-2]=y,S+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,u))for(let e=0;e<=x;e++)m.set(e,t,-m.get(e,t));for(;t<x&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,u&&t<o-1)for(let r=0;r<o;r++)e=m.get(r,t+1),m.set(r,t+1,m.get(r,t)),m.set(r,t,e);if(h&&t<r-1)for(let o=0;o<r;o++)e=g.get(o,t+1),g.set(o,t+1,g.get(o,t)),g.set(o,t,e);t++}S=0,E--}}if(l){let t=m;m=g,g=t}this.m=r,this.n=o,this.s=d,this.U=g,this.V=m}solve(t){let e=t,r=this.threshold,o=this.s.length,s=Y.zeros(o,o);for(let t=0;t<o;t++)Math.abs(this.s[t])<=r?s.set(t,t,0):s.set(t,t,1/this.s[t]);let n=this.U,i=this.rightSingularVectors,a=i.mmul(s),h=i.rows,u=n.rows,l=Y.zeros(h,u);for(let t=0;t<h;t++)for(let e=0;e<u;e++){let r=0;for(let s=0;s<o;s++)r+=a.get(t,s)*n.get(e,s);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(Y.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,o=t.columns,s=new Y(r,this.s.length);for(let n=0;n<r;n++)for(let r=0;r<o;r++)Math.abs(this.s[r])>e&&s.set(n,r,t.get(n,r)/this.s[r]);let n=this.U,i=n.rows,a=n.columns,h=new Y(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let o=0;o<a;o++)r+=s.get(t,o)*n.get(e,o);h.set(t,e,r)}return h}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let o=0,s=r.length;o<s;o++)r[o]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return Y.diag(this.s)}}var tt={center:[0,0],linkDistance:50},et=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",this.options=o(o({},tt),t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,i=void 0===n?[0,0]:n,a=s.linkDistance,h=void 0===a?50:a,u=s.layoutInvisibles,f=s.onLayoutEnd,g=e.getAllNodes(),m=e.getAllEdges();if(u||(g=g.filter((function(t){return t.data.visible||void 0===t.data.visible})),m=m.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!g||0===g.length){var p={nodes:[],edges:m};return null==f||f(p),p}if(1===g.length){t&&e.mergeNodeData(g[0].id,{x:i[0],y:i[1]});var w={nodes:[o(o({},g[0]),{data:o(o({},g[0].data),{x:i[0],y:i[1]})})],edges:m};return null==f||f(w),w}var y=c({nodes:g,edges:m},!1),v=l(y);rt(v);var M=function(t,e){var r=[];return t.forEach((function(t){var o=[];t.forEach((function(t){o.push(t*e)})),r.push(o)})),r}(v,h),b=ot(M),E=[];b.forEach((function(t,e){var r=d(g[e]);r.data.x=t[0]+i[0],r.data.y=t[1]+i[1],E.push(r)})),t&&E.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var x={nodes:E,edges:m};return null==f||f(x),x},t}(),rt=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,o){r.forEach((function(r,s){r===1/0&&(t[o][s]=e)}))}))},ot=function(t){var e=Y.mul(Y.pow(t,2),-.5),r=e.mean("row"),o=e.mean("column"),s=e.mean();e.add(s).subRowVector(r).subColumnVector(o);var n=new Z(e),i=Y.sqrt(n.diagonalMatrix).diagonal();return n.leftSingularVectors.toJSON().map((function(t){return Y.mul([t],[i]).toJSON()[0].splice(0,2)}))},st={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},nt=function(t,e,r,o,s,n){e.forEach((function(i,a){r[a]={x:0,y:0},e.forEach((function(e,h){if(a!==h&&s[a]===s[h]){var u=i.x-e.x,l=i.y-e.y,c=Math.sqrt(u*u+l*l);if(0===c){c=1;var f=a>h?1:-1;u=.01*f,l=.01*f}if(c<n(t[a])/2+n(t[h])/2){var d=o*o/c;r[a].x+=u/c*d,r[a].y+=l/c*d}}}))}))},it=function(t,e,r,o,s,n,i,a){var h=n||i/10;return o&&e.forEach((function(e,r){var o=t[r].x-t[s].x,n=t[r].y-t[s].y,i=Math.sqrt(o*o+n*n),a=n/i,h=-o/i,u=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+h*e.y)/u);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,h*=-1);var c=Math.cos(l)*u;e.x=a*c,e.y=h*c})),t.forEach((function(n,i){if(i!==s){var u=Math.sqrt(e[i].x*e[i].x+e[i].y*e[i].y);if(u>0&&i!==s){var l=Math.min(h*(r/800),u);if(n.x+=e[i].x/u*l,n.y+=e[i].y/u*l,o){var c=n.x-t[s].x,f=n.y-t[s].y,d=Math.sqrt(c*c+f*f);c=c/d*a[i],f=f/d*a[i],n.x=t[s].x+c,n.y=t[s].y+f}}}})),t},at={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,strictRadial:!0,maxPreventOverlapIteration:200,sortBy:void 0,sortStrength:10},ht=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",this.options=o(o({},at),t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,e,r){var a=o(o({},this.options),r),h=a.width,u=a.height,f=a.center,d=a.focusNode,g=a.unitRadius,m=a.nodeSize,p=a.nodeSpacing,w=a.strictRadial,y=a.preventOverlap,v=a.maxPreventOverlapIteration,M=a.sortBy,b=a.linkDistance,E=void 0===b?50:b,x=a.sortStrength,S=void 0===x?10:x,N=a.maxIteration,R=void 0===N?1e3:N,I=a.layoutInvisibles,k=a.onLayoutEnd,A=e.getAllNodes(),T=e.getAllEdges();if(I||(A=A.filter((function(t){return t.data.visible||void 0===t.data.visible})),T=T.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!A||0===A.length){var C={nodes:[],edges:T};return null==k||k(C),C}var D=h||"undefined"==typeof window?h:window.innerWidth,z=u||"undefined"==typeof window?u:window.innerHeight,P=f||[D/2,z/2];if(1===A.length){t&&e.mergeNodeData(A[0].id,{x:P[0],y:P[1]});var V={nodes:[o(o({},A[0]),{data:o(o({},A[0].data),{x:P[0],y:P[1]})})],edges:T};return null==k||k(V),V}var q=A[0];if(i(d)){for(var j=0;j<A.length;j++)if(A[j].id===d){q=A[j];break}}else q=d||A[0];var F=ft(A,q.id),O=c({nodes:A,edges:T},!1),L=l(O),$=gt(L,F);dt(L,F,$+1);var U=L[F],B=D-P[0]>P[0]?P[0]:D-P[0],K=z-P[1]>P[1]?P[1]:z-P[1];0===B&&(B=D/2),0===K&&(K=z/2);var W=Math.min(B,K),J=Math.max.apply(Math,n([],s(U),!1)),_=[],G=g||W/J;U.forEach((function(t,e){_[e]=t*G}));var H,Q=ut(A,L,E,_,G,M,S),X=lt(Q),tt=function(t,e,r){try{var o=Y.mul(Y.pow(e,2),-.5),s=o.mean("row"),n=o.mean("column"),i=o.mean();o.add(i).subRowVector(s).subColumnVector(n);var a=new Z(o),h=Y.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return Y.mul([e],[h]).toJSON()[0].splice(0,t)}))}catch(t){for(var u=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;u.push([c,f])}return u}}(E,Q,E).map((function(t){var e=s(t,2),r=e[0],o=e[1];return{x:(isNaN(r)?Math.random()*E:r)-tt[F].x,y:(isNaN(o)?Math.random()*E:o)-tt[F].y}}));if(this.run(R,tt,X,Q,_,F),y){H=mt(m,p);var et={nodes:A,nodeSizeFunc:H,positions:tt,radii:_,height:z,width:D,strictRadial:Boolean(w),focusIdx:F,iterations:v||200,k:tt.length/4.5};tt=function(t,e){for(var r=o(o({},st),e),s=r.positions,n=r.iterations,i=r.width,a=r.k,h=r.speed,u=void 0===h?100:h,l=r.strictRadial,c=r.focusIdx,f=r.radii,d=void 0===f?[]:f,g=r.nodeSizeFunc,m=t.getAllNodes(),p=[],w=i/10,y=0;y<n;y++)s.forEach((function(t,e){p[e]={x:0,y:0}})),nt(m,s,p,a,d,g),it(s,p,u,l,c,w,i,d);return s}(e,et)}var rt=[];tt.forEach((function(t,e){rt.push(o(o({},A[e]),{data:o(o({},A[0].data),{x:t.x+P[0],y:t.y+P[1]})}))})),t&&rt.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var ot={nodes:rt,edges:T};return null==k||k(ot),ot},t.prototype.run=function(t,e,r,o,s,n){for(var i=0;i<=t;i++){var a=i/t;this.oneIteration(a,e,s,o,r,n)}},t.prototype.oneIteration=function(t,e,r,o,s,n){var i=1-t;e.forEach((function(a,h){var u=ct(a,{x:0,y:0}),l=0===u?0:1/u;if(h!==n){var c=0,f=0,d=0;e.forEach((function(t,e){if(h!==e){var r=ct(a,t),n=0===r?0:1/r,i=o[e][h];d+=s[h][e],c+=s[h][e]*(t.x+i*(a.x-t.x)*n),f+=s[h][e]*(t.y+i*(a.y-t.y)*n)}}));var g=0===r[h]?0:1/r[h];d*=i,d+=t*g*g,c*=i,c+=t*g*a.x*l,a.x=c/d,f*=i,f+=t*g*a.y*l,a.y=f/d}}))},t}(),ut=function(t,e,r,o,s,n,a){if(!t)return[];var h=[];return e&&e.forEach((function(e,u){var l=[];e.forEach((function(e,h){if(u===h)l.push(0);else if(o[u]===o[h])if("data"===n)l.push(e*(Math.abs(u-h)*a)/(o[u]/s));else if(n){var c=t[u][n]||0,f=t[h][n]||0;i(c)&&(c=c.charCodeAt(0)),i(f)&&(f=f.charCodeAt(0)),l.push(e*(Math.abs(c-f)*a)/(o[u]/s))}else l.push(e*r/(o[u]/s));else{var d=(r+s)/2;l.push(e*d)}})),h.push(l)})),h},lt=function(t){for(var e=t.length,r=t[0].length,o=[],s=0;s<e;s++){for(var n=[],i=0;i<r;i++)0!==t[s][i]?n.push(1/(t[s][i]*t[s][i])):n.push(0);o.push(n)}return o},ct=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},ft=function(t,e){var r=-1;return t.forEach((function(t,o){t.id===e&&(r=o)})),Math.max(r,0)},dt=function(t,e,r){for(var o=t.length,s=0;s<o;s++)if(t[e][s]===1/0){t[e][s]=r,t[s][e]=r;for(var n=0;n<o;n++)t[s][n]!==1/0&&t[e][n]===1/0&&(t[e][n]=r+t[s][n],t[n][e]=r+t[s][n])}for(s=0;s<o;s++)if(s!==e)for(n=0;n<o;n++)if(t[s][n]===1/0){var i=Math.abs(t[e][s]-t[e][n]);i=0===i?1:i,t[s][n]=i}},gt=function(t,e){for(var r=0,o=0;o<t[e].length;o++)t[e][o]!==1/0&&(r=t[e][o]>r?t[e][o]:r);return r},mt=function(t,e){var r;return r=u(e)?function(){return e}:g(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){return t.data.bboxSize?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):t.data.size?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):f(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},pt={center:[0,0],width:300,height:300},wt={circular:w,concentric:b,mds:et,random:function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",this.options=o(o({},pt),t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,e,r){var s=o(o({},this.options),r),n=s.center,i=s.width,a=s.height,h=s.layoutInvisibles,u=s.onLayoutEnd,l=e.getAllNodes();h||(l=l.filter((function(t){return t.data.visible||void 0===t.data.visible})));var c=i||"undefined"==typeof window?i:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=n||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var m={nodes:g,edges:e.getAllEdges()};return null==u||u(m),m},t}(),grid:x,radial:ht};function yt(t,e){var o=t.layout,s=o.id,n=o.options,i=t.nodes,a=t.edges,h=new r({nodes:i,edges:a}),u=wt[s];if(!u)throw new Error("Unknown layout id: ".concat(s));return[new u(n).execute(h),e]}addEventListener("message",(function(t){var r,o=t.data,s=o.type,n=o.method,i=o.id,a=o.params;"RPC"===s&&n&&((r=e[n])?Promise.resolve().then((function(){return r.apply(e,a)})):Promise.reject("No such method")).then((function(t){postMessage({type:"RPC",id:i,result:t})})).catch((function(t){var e={message:t};t.stack&&(e.message=t.message,e.stack=t.stack,e.name=t.name),postMessage({type:"RPC",id:i,error:e})}))})),postMessage({type:"RPC",method:"ready"});\n//# sourceMappingURL=6215b31a5bc171c6c2a5.worker.js.map']))),o(t,s),t}},475:t=>{t.exports=function(t,e){var r=0,o={};t.addEventListener("message",(function(e){var r=e.data;if("RPC"===r.type)if(r.id){var s=o[r.id];s&&(delete o[r.id],r.error?s[1](Object.assign(Error(r.error.message),r.error)):s[0](r.result))}else{var n=document.createEvent("Event");n.initEvent(r.method,!1,!1),n.data=r.params,t.dispatchEvent(n)}})),e.forEach((function(e){t[e]=function(){var s=arguments;return new Promise((function(n,i){var a=++r;o[a]=[n,i],t.postMessage({type:"RPC",id:a,method:e,params:[].slice.call(s)})}))}}))}}},e={};function r(o){var s=e[o];if(void 0!==s)return s.exports;var n=e[o]={exports:{}};return t[o](n,n.exports,r),n.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var o={};(()=>{r.d(o,{SB:()=>w,W1:()=>I,Me:()=>k,AI:()=>at,D4:()=>gt,_5:()=>Et,y9:()=>N,Xp:()=>S,qR:()=>Nt,i_:()=>St});var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)},e=function(){return e=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++)for(var s in e=arguments[r])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t},e.apply(this,arguments)};function s(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,s,n=r.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(t){s={error:t}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function n(t,e,r){if(r||2===arguments.length)for(var o,s=0,n=e.length;s<n;s++)!o&&s in e||(o||(o=Array.prototype.slice.call(e,0,s)),o[s]=e[s]);return t.concat(o||Array.prototype.slice.call(e))}Object.create,Object.create;var i=function(t){return"string"==typeof t},a=/-(\w)/g,h=(function(t){return t.replace(a,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),u=function(t){return"number"==typeof t},l=function(t){for(var e=[],r=t.length,o=0;o<r;o+=1){e[o]=[];for(var s=0;s<r;s+=1)o===s?e[o][s]=0:0!==t[o][s]&&t[o][s]?e[o][s]=t[o][s]:e[o][s]=1/0}for(var n=0;n<r;n+=1)for(o=0;o<r;o+=1)for(s=0;s<r;s+=1)e[o][s]>e[o][n]+e[n][s]&&(e[o][s]=e[o][n]+e[n][s]);return e},c=function(t,e){var r=t.nodes,o=t.edges,s=[],n={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){n[t.id]=e,s.push([])})),null==o||o.forEach((function(t){var r=t.source,o=t.target,i=n[r],a=n[o];void 0!==i&&void 0!==a&&(s[i][a]=1,e||(s[a][i]=1))})),s},f=function(t){return null!==t&&"object"==typeof t},d=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var r=[];return t.forEach((function(t){r.push(t)})),r.map((function(t){return d(t)}))}if("object"==typeof t&&Object.keys(t).length){var o=e({},t);return Object.keys(o).forEach((function(t){o[t]=d(o[t])})),o}return t},g=function(t){return"function"==typeof t},m=function(t,e,r){return void 0===r&&(r=!0),e||0===e?g(e)?e:u(e)?function(){return e}:h(e)?function(){if(r){var o=Math.max.apply(Math,n([],s(e),!1));return isNaN(o)?t:o}return e}:f(e)?function(){if(r){var o=Math.max(e.width,e.height);return isNaN(o)?t:o}return[e.width,e.height]}:function(){return t}:function(e){return e.size?h(e.size)?e.size[0]>e.size[1]?e.size[0]:e.size[1]:f(e.size)?e.size.width>e.size.height?e.size.width:e.size.height:e.size:t}},p={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},w=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=e(e({},p),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){var r=this;t.batch((function(){r.genericCircularLayout(!0,t,e)}))},t.prototype.genericCircularLayout=function(t,r,o){var n=e(e({},this.options),o),i=n.width,a=n.height,h=n.center,u=n.divisions,l=n.startAngle,c=void 0===l?0:l,f=n.endAngle,g=void 0===f?2*Math.PI:f,p=n.angleRatio,w=n.ordering,b=n.clockwise,M=n.nodeSpacing,x=n.nodeSize,E=n.layoutInvisibles,S=n.onLayoutEnd,N=r.getAllNodes(),R=r.getAllEdges();E||(N=N.filter((function(t){return t.data.visible||void 0===t.data.visible})),R=R.filter((function(t){return t.data.visible||void 0===t.data.visible})));var I=N.length;if(0===I)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var A=s(v(i,a,h),3),k=A[0],C=A[1],T=A[2];if(1===I){t&&r.mergeNodeData(N[0].id,{x:T[0],y:T[1]});var z={nodes:[e(e({},N[0]),{data:e(e({},N[0].data),{x:T[0],y:T[1]})})],edges:R};return null==S||S(z),z}var D=(g-c)/I,P=n.radius,L=n.startRadius,q=n.endRadius;if(M){var $=m(10,M),j=m(10,x),V=-1/0;N.forEach((function(t){var e=j(t);V<e&&(V=e)}));var O=0;N.forEach((function(t,e){O+=0===e?V||10:($(t)||0)+(V||10)})),P=O/(2*Math.PI)}else P||L||q?!L&&q?L=q:L&&!q&&(q=L):P=Math.min(C,k)/2;var F=D*p,Y=[];Y="topology"===w?y(r,N):"topology-directed"===w?y(r,N,!0):"degree"===w?function(t,e){var r=[];return e.forEach((function(t,e){r.push(d(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(r,N):N.map((function(t){return d(t)}));for(var G=Math.ceil(I/u),_=0;_<I;++_){var U=P;U||null===L||null===q||(U=L+_*(q-L)/(I-1)),U||(U=10+100*_/(I-1));var B=c+_%G*F+2*Math.PI/u*Math.floor(_/G);b||(B=g-_%G*F-2*Math.PI/u*Math.floor(_/G)),Y[_].data.x=T[0]+Math.cos(B)*U,Y[_].data.y=T[1]+Math.sin(B)*U}t&&Y.forEach((function(t){r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var K={nodes:Y,edges:R};return null==S||S(K),K},t}(),y=function(t,e,r){void 0===r&&(r=!1);var o=[d(e[0])],s={},n=e.length;s[e[0].id]=!0;var i=0;return e.forEach((function(a,h){if(0!==h)if(h!==n-1&&t.getDegree(a.id,"both")===t.getDegree(e[h+1].id,"both")&&!t.areNeighbors(o[i].id,a.id)||s[a.id]){for(var u=r?t.getSuccessors(o[i].id):t.getNeighbors(o[i].id),l=!1,c=0;c<u.length;c++){var f=u[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!s[f.id]){o.push(d(f)),s[f.id]=!0,l=!0;break}}for(var g=0;!l&&(s[e[g].id]||(o.push(d(e[g])),s[e[g].id]=!0,l=!0),++g!==n););}else o.push(d(a)),s[a.id]=!0,i++})),o},v=function(t,e,r){var o=t,s=e,n=r;return o||"undefined"==typeof window||(o=window.innerWidth),s||"undefined"==typeof window||(s=window.innerHeight),n||(n=[o/2,s/2]),[o,s,n]},b=r(161),M=r.n(b),x=r(825),E=r.n(x),S={LAYOUT_ITERATION:"tick",LAYOUT_END:"layoutend"},N=function(e){function r(t,r,o){var s=e.call(this)||this;return s.graph=t,s.layout=r,s.spawnWorker(),s}return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function o(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}(r,e),r.prototype.spawnWorker=function(){this.worker&&this.worker.terminate(),this.worker=E()(),this.running&&(this.running=!1,this.start())},r.prototype.start=function(){var t=this;if(this.running)return this;this.running=!0;var e={layout:{id:this.layout.id,options:this.layout.options},nodes:this.graph.getAllNodes(),edges:this.graph.getAllEdges()},r=new Float32Array([0]);return this.worker.calculateLayout(e,[r]).then((function(e){var r=s(e,2),o=r[0];r[1],t.emit(S.LAYOUT_END,o)})),this},r.prototype.stop=function(){return this.running=!1,this},r.prototype.kill=function(){this.worker&&this.worker.terminate()},r.prototype.isRunning=function(){return this.running},r}(M()),R={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},I=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",this.options=e(e({},R),t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,r,o){var s=e(e({},this.options),o),n=s.center,a=s.width,l=s.height,c=s.sortBy,m=s.maxLevelDiff,p=s.sweep,w=s.clockwise,y=s.equidistant,v=s.minNodeSpacing,b=void 0===v?10:v,M=s.preventOverlap,x=s.startAngle,E=void 0===x?1.5*Math.PI:x,S=s.nodeSize,N=s.nodeSpacing,R=s.layoutInvisibles,I=s.onLayoutEnd,A=r.getAllNodes(),k=r.getAllEdges();R||(A=A.filter((function(t){return t.data.visible||void 0===t.data.visible})),k=k.filter((function(t){return t.data.visible||void 0===t.data.visible})));var C=A.length;if(0===C){var T={nodes:[],edges:k};return null==I||I(T),T}var z=a||"undefined"==typeof window?a:window.innerWidth,D=l||"undefined"==typeof window?l:window.innerHeight,P=n||[z/2,D/2];if(1===C){t&&r.mergeNodeData(A[0].id,{x:P[0],y:P[1]});var L={nodes:[e(e({},A[0]),{data:e(e({},A[0].data),{x:P[0],y:P[1]})})],edges:k};return null==I||I(L),L}var q,$=[],j=0;q=h(S)?Math.max(S[0],S[1]):S,h(N)?j=Math.max(N[0],N[1]):u(N)&&(j=N),A.forEach((function(t){$.push(d(t));var e=q;h(t.data.size)?e=Math.max(t.data.size[0],t.data.size[1]):u(t.data.size)?e=t.data.size:f(t.data.size)&&(e=Math.max(t.data.size.width,t.data.size.height)),q=Math.max(q,e),g(N)&&(j=Math.max(N(t),j))}));var V={};$.forEach((function(t,e){V[t.id]=e}));var O=c;i(O)&&void 0!==$[0].data[O]||(O="degree"),"degree"===O?$.sort((function(t,e){return r.getDegree(e.id,"both")-r.getDegree(t.id,"both")})):$.sort((function(t,e){return e.data[O]-t.data[O]}));var F=$[0],Y=m||F.data[O]/4,G=[{nodes:[]}],_=G[0];$.forEach((function(t){if(_.nodes.length>0){var e=Math.abs(_.nodes[0].data[O]-t.data[O]);Y&&e>=Y&&(_={nodes:[]},G.push(_))}_.nodes.push(t)}));var U=q+(j||b);if(!M){var B=G.length>0&&G[0].nodes.length>1,K=(Math.min(z,D)/2-U)/(G.length+(B?1:0));U=Math.min(U,K)}var W=0;if(G.forEach((function(t){var e=void 0===p?2*Math.PI-2*Math.PI/t.nodes.length:p;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&M){var r=Math.cos(t.dTheta)-Math.cos(0),o=Math.sin(t.dTheta)-Math.sin(0),s=Math.sqrt(U*U/(r*r+o*o));W=Math.max(s,W)}t.r=W,W+=U})),y){for(var J=0,H=0,X=0;X<G.length;X++){var Q=(G[X].r||0)-H;J=Math.max(J,Q)}H=0,G.forEach((function(t,e){0===e&&(H=t.r||0),t.r=H,H+=J}))}G.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,o){var s=E+(w?1:-1)*e*o;t.data.x=P[0]+r*Math.cos(s),t.data.y=P[1]+r*Math.sin(s)}))})),t&&$.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Z={nodes:$,edges:k};return null==I||I(Z),Z},t}(),A={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},k=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",this.options=e(e({},A),t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,r,o){var s=e(e({},this.options),o),n=s.begin,a=void 0===n?[0,0]:n,l=s.condense,c=s.preventOverlapPadding,f=s.preventOverlap,g=s.columns,p=s.rows,w=s.cols,y=void 0===w?g:w,v=s.nodeSpacing,b=s.nodeSize,M=s.width,x=s.height,E=s.layoutInvisibles,S=s.onLayoutEnd,N=s.position,R=s.sortBy,I=r.getAllNodes(),A=r.getAllEdges();E||(I=I.filter((function(t){return t.data.visible||void 0===t.data.visible})),A=A.filter((function(t){return t.data.visible||void 0===t.data.visible})));var k=I.length;if(0===k){var P={nodes:[],edges:A};return null==S||S(P),P}if(1===k){t&&r.mergeNodeData(I[0].id,{x:a[0],y:a[1]});var q={nodes:[e(e({},I[0]),{data:e(e({},I[0].data),{x:a[0],y:a[1]})})],edges:A};return null==S||S(q),q}var $=I.map((function(t){return d(t)}));"id"===R||i(R)&&void 0!==$[0].data[R]||(R="degree"),"degree"===R?$.sort((function(t,e){return r.getDegree(e.id,"both")-r.getDegree(t.id,"both")})):"id"===R?$.sort((function(t,e){return u(e.id)&&u(t.id)?e.id-t.id:"".concat(e.id).localeCompare("".concat(t.id))})):$.sort((function(t,e){return e.data[R]-t.data[R]}));var j=M||"undefined"==typeof window?M:window.innerWidth,V=x||"undefined"==typeof window?x:window.innerHeight,O=k,F={rows:p,cols:y};if(null!=p&&null!=y)F.rows=p,F.cols=y;else if(null!=p&&null==y)F.rows=p,F.cols=Math.ceil(O/F.rows);else if(null==p&&null!=y)F.cols=y,F.rows=Math.ceil(O/F.cols);else{var Y=Math.sqrt(O*V/j);F.rows=Math.round(Y),F.cols=Math.round(j/V*Y)}if(F.rows=Math.max(F.rows,1),F.cols=Math.max(F.cols,1),F.cols*F.rows>O)((_=C(F))-1)*(G=T(F))>=O?C(F,_-1):(G-1)*_>=O&&T(F,G-1);else for(;F.cols*F.rows<O;){var G,_=C(F);((G=T(F))+1)*_>=O?T(F,G+1):C(F,_+1)}var U=l?0:j/F.cols,B=l?0:V/F.rows;if(f||v){var K=m(10,v),W=m(30,b,!1);$.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var e,o,s=r.getNode(t.id),n=W(s)||30;h(n)?(e=n[0],o=n[1]):(e=n,o=n);var i=void 0!==K?K(t):c,a=e+i,u=o+i;U=Math.max(U,a),B=Math.max(B,u)}))}for(var J={},H={row:0,col:0},X={},Q=0;Q<$.length;Q++){var Z=$[Q],tt=void 0;if(N&&(tt=N(r.getNode(Z.id))),tt&&(void 0!==tt.row||void 0!==tt.col)){var et={row:tt.row,col:tt.col};if(void 0===et.col)for(et.col=0;z(J,et);)et.col++;else if(void 0===et.row)for(et.row=0;z(J,et);)et.row++;X[Z.id]=et,D(J,et)}L(Z,a,U,B,X,F,H,J)}var rt={nodes:$,edges:A};return null==S||S(rt),t&&$.forEach((function(t){r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),rt},t}(),C=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.min(o,s):Math.min(o,s)===t.rows?t.rows=e:t.cols=e,r},T=function(t,e){var r,o=t.rows||5,s=t.cols||5;return null==e?r=Math.max(o,s):Math.max(o,s)===t.rows?t.rows=e:t.cols=e,r},z=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},D=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},P=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},L=function(t,e,r,o,s,n,i,a){var h,u,l=s[t.id];if(l)h=l.col*r+r/2+e[0],u=l.row*o+o/2+e[1];else{for(;z(a,i);)P(n,i);h=i.col*r+r/2+e[0],u=i.row*o+o/2+e[1],D(a,i),P(n,i)}t.data.x=h,t.data.y=u};const q=Object.prototype.toString;function $(t){return q.call(t).endsWith("Array]")}function j(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!$(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]>i&&(i=t[a]);return i}function V(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!$(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,n=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[o],a=o+1;a<n;a++)t[a]<i&&(i=t[a]);return i}function O(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!$(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!$(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var o=V(t),s=j(t);if(o===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=r.min,i=void 0===n?r.autoMinMax?o:0:n,a=r.max,h=void 0===a?r.autoMinMax?s:1:a;if(i>=h)throw new RangeError("min option must be smaller than max option");for(var u=(h-i)/(s-o),l=0;l<t.length;l++)e[l]=(t[l]-o)*u+i;return e}const F=" ".repeat(2),Y=" ".repeat(4);function G(t,e={}){const{maxRows:r=15,maxColumns:o=10,maxNumSize:s=8,padMinus:n="auto"}=e;return`${t.constructor.name} {\n${F}[\n${Y}${function(t,e,r,o,s){const{rows:n,columns:i}=t,a=Math.min(n,e),h=Math.min(i,r),u=[];if("auto"===s){s=!1;t:for(let e=0;e<a;e++)for(let r=0;r<h;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let n=0;n<h;n++)r.push(_(t.get(e,n),o,s));u.push(`${r.join(" ")}`)}return h!==i&&(u[u.length-1]+=` ... ${i-r} more columns`),a!==n&&u.push(`... ${n-e} more rows`),u.join(`\n${Y}`)}(t,r,o,s,n)}\n${F}]\n${F}rows: ${t.rows}\n${F}columns: ${t.columns}\n}`}function _(t,e,r){return(t>=0&&r?` ${U(t,e-1)}`:U(t,e)).padEnd(e)}function U(t,e){let r=t.toString();if(r.length<=e)return r;let o=t.toFixed(e);if(o.length>e&&(o=t.toFixed(Math.max(0,e-(o.length-e)))),o.length<=e&&!o.startsWith("0.000")&&!o.startsWith("-0.000"))return o;let s=t.toExponential(e);return s.length>e&&(s=t.toExponential(Math.max(0,e-(s.length-e)))),s.slice(0)}function B(t,e,r){let o=r?t.rows:t.rows-1;if(e<0||e>o)throw new RangeError("Row index out of range")}function K(t,e,r){let o=r?t.columns:t.columns-1;if(e<0||e>o)throw new RangeError("Column index out of range")}function W(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function J(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function H(t,e,r,o,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(Q("startRow",e),Q("endRow",r),Q("startColumn",o),Q("endColumn",s),e>r||o>s||e<0||e>=t.rows||r<0||r>=t.rows||o<0||o>=t.columns||s<0||s>=t.columns)throw new RangeError("Submatrix indices are out of range")}function X(t,e=0){let r=[];for(let o=0;o<t;o++)r.push(e);return r}function Q(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function Z(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class tt{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let o=new rt(t,e);for(let s=0;s<t;s++)for(let t=0;t<e;t++)o.set(s,t,r[s*e+t]);return o}static rowVector(t){let e=new rt(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new rt(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new rt(t,e)}static ones(t,e){return new rt(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:o=Math.random}=r;let s=new rt(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)s.set(r,t,o());return s}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:o=0,max:s=1e3,random:n=Math.random}=r;if(!Number.isInteger(o))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(o>=s)throw new RangeError("min must be smaller than max");let i=s-o,a=new rt(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=o+Math.round(n()*i);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let o=Math.min(t,e),s=this.zeros(t,e);for(let t=0;t<o;t++)s.set(t,t,r);return s}static diag(t,e,r){let o=t.length;void 0===e&&(e=o),void 0===r&&(r=e);let s=Math.min(o,e,r),n=this.zeros(e,r);for(let e=0;e<s;e++)n.set(e,e,t[e]);return n}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new rt(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.min(t.get(n,r),e.get(n,r)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,s=new this(r,o);for(let n=0;n<r;n++)for(let r=0;r<o;r++)s.set(n,r,Math.max(t.get(n,r),e.get(n,r)));return s}static checkMatrix(t){return tt.isMatrix(t)?t:new rt(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);t++}return o}isReducedEchelonForm(){let t=0,e=0,r=-1,o=!0,s=!1;for(;t<this.rows&&o;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(o=!1,s=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(o=!1);t++}return o}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let o=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(o,r)&&(o=s);if(0===t.get(o,r))r++;else{t.swapRows(e,o);let s=t.get(e,r);for(let o=r;o<t.columns;o++)t.set(e,o,t.get(e,o)/s);for(let o=e+1;o<t.rows;o++){let s=t.get(o,r)/t.get(e,r);t.set(o,r,0);for(let n=r+1;n<t.columns;n++)t.set(o,n,t.get(o,n)-t.get(e,n)*s)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,o=r-1;for(;o>=0;)if(0===t.maxRow(o))o--;else{let s=0,n=!1;for(;s<r&&!1===n;)1===t.get(o,s)?n=!0:s++;for(let r=0;r<o;r++){let n=t.get(r,s);for(let i=s;i<e;i++){let e=t.get(r,i)-n*t.get(o,i);t.set(r,i,e)}}o--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let o=new rt(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)o.setSubMatrix(this,this.rows*t,this.columns*e);return o}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){B(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return rt.rowVector(this.getRow(t))}setRow(t,e){B(this,t),e=W(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){B(this,t),B(this,e);for(let r=0;r<this.columns;r++){let o=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,o)}return this}getColumn(t){K(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return rt.columnVector(this.getColumn(t))}setColumn(t,e){K(this,t),e=J(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){K(this,t),K(this,e);for(let r=0;r<this.rows;r++){let o=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,o)}return this}addRowVector(t){t=W(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=W(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=W(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=W(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=J(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=J(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=J(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=J(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){B(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){K(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){Z(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){Z(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}maxRow(t){if(B(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){B(this,t),Z(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)>e&&(e=this.get(t,o),r[1]=o);return r}minRow(t){if(B(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){B(this,t),Z(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)<e&&(e=this.get(t,o),r[1]=o);return r}maxColumn(t){if(K(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){K(this,t),Z(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)>e&&(e=this.get(o,t),r[0]=o);return r}minColumn(t){if(K(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){K(this,t),Z(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)<e&&(e=this.get(o,t),r[0]=o);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){tt.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let o=0;o<e.length;o++)r+=e[o]*t[o];return r}mmul(t){t=rt.checkMatrix(t);let e=this.rows,r=this.columns,o=t.columns,s=new rt(e,o),n=new Float64Array(r);for(let i=0;i<o;i++){for(let e=0;e<r;e++)n[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let o=0;o<r;o++)e+=this.get(t,o)*n[o];s.set(t,i,e)}}return s}strassen2x2(t){t=rt.checkMatrix(t);let e=new rt(2,2);const r=this.get(0,0),o=t.get(0,0),s=this.get(0,1),n=t.get(0,1),i=this.get(1,0),a=t.get(1,0),h=this.get(1,1),u=t.get(1,1),l=(r+h)*(o+u),c=(i+h)*o,f=r*(n-u),d=h*(a-o),g=(r+s)*u,m=l+d-g+(s-h)*(a+u),p=f+g,w=c+d,y=l-c+f+(i-r)*(o+n);return e.set(0,0,m),e.set(0,1,p),e.set(1,0,w),e.set(1,1,y),e}strassen3x3(t){t=rt.checkMatrix(t);let e=new rt(3,3);const r=this.get(0,0),o=this.get(0,1),s=this.get(0,2),n=this.get(1,0),i=this.get(1,1),a=this.get(1,2),h=this.get(2,0),u=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),m=t.get(1,1),p=t.get(1,2),w=t.get(2,0),y=t.get(2,1),v=t.get(2,2),b=(r-n)*(-f+m),M=(-r+n+i)*(c-f+m),x=(n+i)*(-c+f),E=r*c,S=(-r+h+u)*(c-d+p),N=(-r+h)*(d-p),R=(h+u)*(-c+d),I=(-s+u+l)*(m+w-y),A=(s-l)*(m-y),k=s*w,C=(u+l)*(-w+y),T=(-s+i+a)*(p+w-v),z=(s-a)*(p-v),D=(i+a)*(-w+v),P=E+k+o*g,L=(r+o+s-n-i-u-l)*m+M+x+E+I+k+C,q=E+S+R+(r+o+s-i-a-h-u)*p+k+T+D,$=b+i*(-c+f+g-m-p-w+v)+M+E+k+T+z,j=b+M+x+E+a*y,V=k+T+z+D+n*d,O=E+S+N+u*(-c+d+g-m-p-w+y)+I+A+k,F=I+A+k+C+h*f,Y=E+S+N+R+l*v;return e.set(0,0,P),e.set(0,1,L),e.set(0,2,q),e.set(1,0,$),e.set(1,1,j),e.set(1,2,V),e.set(2,0,O),e.set(2,1,F),e.set(2,2,Y),e}mmulStrassen(t){t=rt.checkMatrix(t);let e=this.clone(),r=e.rows,o=e.columns,s=t.rows,n=t.columns;function i(t,e,r){let o=t.rows,s=t.columns;if(o===e&&s===r)return t;{let o=tt.zeros(e,r);return o=o.setSubMatrix(t,0,0),o}}o!==s&&console.warn(`Multiplying ${r} x ${o} and ${s} x ${n} matrix: dimensions do not match.`);let a=Math.max(r,s),h=Math.max(o,n);return e=i(e,a,h),function t(e,r,o,s){if(o<=512||s<=512)return e.mmul(r);o%2==1&&s%2==1?(e=i(e,o+1,s+1),r=i(r,o+1,s+1)):o%2==1?(e=i(e,o+1,s),r=i(r,o+1,s)):s%2==1&&(e=i(e,o,s+1),r=i(r,o,s+1));let n=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),h=e.subMatrix(0,n-1,0,a-1),u=r.subMatrix(0,n-1,0,a-1),l=e.subMatrix(0,n-1,a,e.columns-1),c=r.subMatrix(0,n-1,a,r.columns-1),f=e.subMatrix(n,e.rows-1,0,a-1),d=r.subMatrix(n,r.rows-1,0,a-1),g=e.subMatrix(n,e.rows-1,a,e.columns-1),m=r.subMatrix(n,r.rows-1,a,r.columns-1),p=t(tt.add(h,g),tt.add(u,m),n,a),w=t(tt.add(f,g),u,n,a),y=t(h,tt.sub(c,m),n,a),v=t(g,tt.sub(d,u),n,a),b=t(tt.add(h,l),m,n,a),M=t(tt.sub(f,h),tt.add(u,c),n,a),x=t(tt.sub(l,g),tt.add(d,m),n,a),E=tt.add(p,v);E.sub(b),E.add(x);let S=tt.add(y,b),N=tt.add(w,v),R=tt.sub(p,w);R.add(y),R.add(M);let I=tt.zeros(2*E.rows,2*E.columns);return I=I.setSubMatrix(E,0,0),I=I.setSubMatrix(S,E.rows,0),I=I.setSubMatrix(N,0,E.columns),I=I.setSubMatrix(R,E.rows,E.columns),I.subMatrix(0,o-1,0,s-1)}(e,t=i(t,a,h),a,h)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new rt(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&O(s,{min:e,max:r,output:s}),o.setRow(t,s)}return o}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let o=new rt(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&O(s,{min:e,max:r,output:s}),o.setColumn(t,s)}return o}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),o=this.get(e,this.columns-1-r);this.set(e,r,o),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),o=this.get(this.rows-1-r,e);this.set(r,e,o),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=rt.checkMatrix(t);let e=this.rows,r=this.columns,o=t.rows,s=t.columns,n=new rt(e*o,r*s);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<o;r++)for(let a=0;a<s;a++)n.set(o*i+r,s*e+a,this.get(i,e)*t.get(r,a));return n}kroneckerSum(t){if(t=rt.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,o=this.kroneckerProduct(rt.eye(r,r)),s=rt.eye(e,e).kroneckerProduct(t);return o.add(s)}transpose(){let t=new rt(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=et){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=et){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,o){H(this,t,e,r,o);let s=new rt(e-t+1,o-r+1);for(let n=t;n<=e;n++)for(let e=r;e<=o;e++)s.set(n-t,e-r,this.get(n,e));return s}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let o=new rt(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);o.set(s,n-e,this.get(t[s],n))}return o}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let o=new rt(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let n=e;n<=r;n++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);o.set(n-e,s,this.get(n,t[s]))}return o}setSubMatrix(t,e,r){if((t=rt.checkMatrix(t)).isEmpty())return this;H(this,e,e+t.rows-1,r,r+t.columns-1);for(let o=0;o<t.rows;o++)for(let s=0;s<t.columns;s++)this.set(e+o,r+s,t.get(o,s));return this}selection(t,e){!function(t,e){if(!$(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!$(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new rt(t.length,e.length);for(let o=0;o<t.length;o++){let s=t[o];for(let t=0;t<e.length;t++){let n=e[t];r.set(o,t,this.get(s,n))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new rt(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=X(t.rows);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]+=t.get(r,o);return e}(this);case"column":return function(t){let e=X(t.columns);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]+=t.get(r,o);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e+=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=X(t.rows,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]*=t.get(r,o);return e}(this);case"column":return function(t){let e=X(t.columns,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]*=t.get(r,o);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e*=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:o=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!$(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<o;i++){let o=0,a=0,h=0;for(let e=0;e<s;e++)h=t.get(i,e)-r[i],o+=h,a+=h*h;e?n.push((a-o*o/s)/(s-1)):n.push((a-o*o/s)/s)}return n}(this,r,o);case"column":if(!$(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,s=t.columns,n=[];for(let i=0;i<s;i++){let s=0,a=0,h=0;for(let e=0;e<o;e++)h=t.get(e,i)-r[i],s+=h,a+=h*h;e?n.push((a-s*s/o)/(o-1)):n.push((a-s*s/o)/o)}return n}(this,r,o);case void 0:if("number"!=typeof o)throw new TypeError("mean must be a number");return function(t,e,r){const o=t.rows,s=t.columns,n=o*s;let i=0,a=0,h=0;for(let e=0;e<o;e++)for(let o=0;o<s;o++)h=t.get(e,o)-r,i+=h,a+=h*h;return e?(a-i*i/n)/(n-1):(a-i*i/n)/n}(this,r,o);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!$(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[r])}(this,r),this;case"column":if(!$(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[o])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let o=0;for(let e=0;e<t.columns;e++)o+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(o))}return e}(this);else if(!$(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let o=0;for(let e=0;e<t.rows;e++)o+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(o))}return e}(this);else if(!$(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[o])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let o=0;o<t.columns;o++)for(let s=0;s<t.rows;s++)r+=Math.pow(t.get(s,o),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return G(this,t)}}function et(t,e){return t-e}tt.prototype.klass="Matrix","undefined"!=typeof Symbol&&(tt.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return G(this)}),tt.random=tt.rand,tt.randomInt=tt.randInt,tt.diagonal=tt.diag,tt.prototype.diagonal=tt.prototype.diag,tt.identity=tt.eye,tt.prototype.negate=tt.prototype.neg,tt.prototype.tensorProduct=tt.prototype.kroneckerProduct;class rt extends tt{constructor(t,e){if(super(),rt.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!$(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let o=0;o<t;o++){if(r[o].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[o].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[o]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return B(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),B(this,t,!0),e=Float64Array.from(W(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){K(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let o=0;o<t;o++)r[o]=this.data[e][o];for(let o=t+1;o<this.columns;o++)r[o-1]=this.data[e][o];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),K(this,t,!0),e=J(this,e);for(let r=0;r<this.rows;r++){const o=new Float64Array(this.columns+1);let s=0;for(;s<t;s++)o[s]=this.data[r][s];for(o[s++]=e[r];s<this.columns+1;s++)o[s]=this.data[r][s-1];this.data[r]=o}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(tt,rt);class ot extends tt{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function st(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class nt{constructor(t,e={}){if((t=ot.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,o=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:n=!0,autoTranspose:i=!1}=e;let a,h=Boolean(s),u=Boolean(n),l=!1;if(r<o)if(i){a=t.transpose(),r=a.rows,o=a.columns,l=!0;let e=h;h=u,u=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,o),f=Math.min(r+1,o),d=new Float64Array(f),g=new rt(r,c),m=new rt(o,o),p=new Float64Array(o),w=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let v=Math.min(r-1,o),b=Math.max(0,Math.min(o-2,r)),M=Math.max(v,b);for(let t=0;t<M;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=st(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<o;e++){if(t<v&&0!==d[t]){let o=0;for(let s=t;s<r;s++)o+=a.get(s,t)*a.get(s,e);o=-o/a.get(t,t);for(let s=t;s<r;s++)a.set(s,e,a.get(s,e)+o*a.get(s,t))}p[e]=a.get(t,e)}if(h&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<b){p[t]=0;for(let e=t+1;e<o;e++)p[t]=st(p[t],p[e]);if(0!==p[t]){p[t+1]<0&&(p[t]=0-p[t]);for(let e=t+1;e<o;e++)p[e]/=p[t];p[t+1]+=1}if(p[t]=-p[t],t+1<r&&0!==p[t]){for(let e=t+1;e<r;e++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<o;r++)w[e]+=p[r]*a.get(e,r);for(let e=t+1;e<o;e++){let o=-p[e]/p[t+1];for(let s=t+1;s<r;s++)a.set(s,e,a.get(s,e)+o*w[s])}}if(u)for(let e=t+1;e<o;e++)m.set(e,t,p[e])}}let x=Math.min(o,r+1);if(v<o&&(d[v]=a.get(v,v)),r<x&&(d[x-1]=0),b+1<x&&(p[b]=a.get(b,x-1)),p[x-1]=0,h){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let o=0;for(let s=t;s<r;s++)o+=g.get(s,t)*g.get(s,e);o=-o/g.get(t,t);for(let s=t;s<r;s++)g.set(s,e,g.get(s,e)+o*g.get(s,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(u)for(let t=o-1;t>=0;t--){if(t<b&&0!==p[t])for(let e=t+1;e<o;e++){let r=0;for(let s=t+1;s<o;s++)r+=m.get(s,t)*m.get(s,e);r=-r/m.get(t+1,t);for(let s=t+1;s<o;s++)m.set(s,e,m.get(s,e)+r*m.get(s,t))}for(let e=0;e<o;e++)m.set(e,t,0);m.set(t,t,1)}let E=x-1,S=0,N=Number.EPSILON;for(;x>0;){let t,e;for(t=x-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+N*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[t]=0;break}}if(t===x-2)e=4;else{let r;for(r=x-1;r>=t&&r!==t;r--){let e=(r!==x?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(d[r])<=N*e){d[r]=0;break}}r===t?e=3:r===x-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[x-2];p[x-2]=0;for(let r=x-2;r>=t;r--){let s=st(d[r],e),n=d[r]/s,i=e/s;if(d[r]=s,r!==t&&(e=-i*p[r-1],p[r-1]=n*p[r-1]),u)for(let t=0;t<o;t++)s=n*m.get(t,r)+i*m.get(t,x-1),m.set(t,x-1,-i*m.get(t,r)+n*m.get(t,x-1)),m.set(t,r,s)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let o=t;o<x;o++){let s=st(d[o],e),n=d[o]/s,i=e/s;if(d[o]=s,e=-i*p[o],p[o]=n*p[o],h)for(let e=0;e<r;e++)s=n*g.get(e,o)+i*g.get(e,t-1),g.set(e,t-1,-i*g.get(e,o)+n*g.get(e,t-1)),g.set(e,o,s)}break}case 3:{const e=Math.max(Math.abs(d[x-1]),Math.abs(d[x-2]),Math.abs(p[x-2]),Math.abs(d[t]),Math.abs(p[t])),s=d[x-1]/e,n=d[x-2]/e,i=p[x-2]/e,a=d[t]/e,l=p[t]/e,c=((n+s)*(n-s)+i*i)/2,f=s*i*(s*i);let w=0;0===c&&0===f||(w=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),w=f/(c+w));let y=(a+s)*(a-s)+w,v=a*l;for(let e=t;e<x-1;e++){let s=st(y,v);0===s&&(s=Number.MIN_VALUE);let n=y/s,i=v/s;if(e!==t&&(p[e-1]=s),y=n*d[e]+i*p[e],p[e]=n*p[e]-i*d[e],v=i*d[e+1],d[e+1]=n*d[e+1],u)for(let t=0;t<o;t++)s=n*m.get(t,e)+i*m.get(t,e+1),m.set(t,e+1,-i*m.get(t,e)+n*m.get(t,e+1)),m.set(t,e,s);if(s=st(y,v),0===s&&(s=Number.MIN_VALUE),n=y/s,i=v/s,d[e]=s,y=n*p[e]+i*d[e+1],d[e+1]=-i*p[e]+n*d[e+1],v=i*p[e+1],p[e+1]=n*p[e+1],h&&e<r-1)for(let t=0;t<r;t++)s=n*g.get(t,e)+i*g.get(t,e+1),g.set(t,e+1,-i*g.get(t,e)+n*g.get(t,e+1)),g.set(t,e,s)}p[x-2]=y,S+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,u))for(let e=0;e<=E;e++)m.set(e,t,-m.get(e,t));for(;t<E&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,u&&t<o-1)for(let r=0;r<o;r++)e=m.get(r,t+1),m.set(r,t+1,m.get(r,t)),m.set(r,t,e);if(h&&t<r-1)for(let o=0;o<r;o++)e=g.get(o,t+1),g.set(o,t+1,g.get(o,t)),g.set(o,t,e);t++}S=0,x--}}if(l){let t=m;m=g,g=t}this.m=r,this.n=o,this.s=d,this.U=g,this.V=m}solve(t){let e=t,r=this.threshold,o=this.s.length,s=rt.zeros(o,o);for(let t=0;t<o;t++)Math.abs(this.s[t])<=r?s.set(t,t,0):s.set(t,t,1/this.s[t]);let n=this.U,i=this.rightSingularVectors,a=i.mmul(s),h=i.rows,u=n.rows,l=rt.zeros(h,u);for(let t=0;t<h;t++)for(let e=0;e<u;e++){let r=0;for(let s=0;s<o;s++)r+=a.get(t,s)*n.get(e,s);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(rt.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,o=t.columns,s=new rt(r,this.s.length);for(let n=0;n<r;n++)for(let r=0;r<o;r++)Math.abs(this.s[r])>e&&s.set(n,r,t.get(n,r)/this.s[r]);let n=this.U,i=n.rows,a=n.columns,h=new rt(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let o=0;o<a;o++)r+=s.get(t,o)*n.get(e,o);h.set(t,e,r)}return h}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let o=0,s=r.length;o<s;o++)r[o]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return rt.diag(this.s)}}var it={center:[0,0],linkDistance:50},at=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",this.options=e(e({},it),t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,r,o){var s=e(e({},this.options),o),n=s.center,i=void 0===n?[0,0]:n,a=s.linkDistance,h=void 0===a?50:a,u=s.layoutInvisibles,f=s.onLayoutEnd,g=r.getAllNodes(),m=r.getAllEdges();if(u||(g=g.filter((function(t){return t.data.visible||void 0===t.data.visible})),m=m.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!g||0===g.length){var p={nodes:[],edges:m};return null==f||f(p),p}if(1===g.length){t&&r.mergeNodeData(g[0].id,{x:i[0],y:i[1]});var w={nodes:[e(e({},g[0]),{data:e(e({},g[0].data),{x:i[0],y:i[1]})})],edges:m};return null==f||f(w),w}var y=c({nodes:g,edges:m},!1),v=l(y);ht(v);var b=function(t,e){var r=[];return t.forEach((function(t){var o=[];t.forEach((function(t){o.push(t*e)})),r.push(o)})),r}(v,h),M=ut(b),x=[];M.forEach((function(t,e){var r=d(g[e]);r.data.x=t[0]+i[0],r.data.y=t[1]+i[1],x.push(r)})),t&&x.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var E={nodes:x,edges:m};return null==f||f(E),E},t}(),ht=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,o){r.forEach((function(r,s){r===1/0&&(t[o][s]=e)}))}))},ut=function(t){var e=rt.mul(rt.pow(t,2),-.5),r=e.mean("row"),o=e.mean("column"),s=e.mean();e.add(s).subRowVector(r).subColumnVector(o);var n=new nt(e),i=rt.sqrt(n.diagonalMatrix).diagonal();return n.leftSingularVectors.toJSON().map((function(t){return rt.mul([t],[i]).toJSON()[0].splice(0,2)}))},lt={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},ct=function(t,e,r,o,s,n){e.forEach((function(i,a){r[a]={x:0,y:0},e.forEach((function(e,h){if(a!==h&&s[a]===s[h]){var u=i.x-e.x,l=i.y-e.y,c=Math.sqrt(u*u+l*l);if(0===c){c=1;var f=a>h?1:-1;u=.01*f,l=.01*f}if(c<n(t[a])/2+n(t[h])/2){var d=o*o/c;r[a].x+=u/c*d,r[a].y+=l/c*d}}}))}))},ft=function(t,e,r,o,s,n,i,a){var h=n||i/10;return o&&e.forEach((function(e,r){var o=t[r].x-t[s].x,n=t[r].y-t[s].y,i=Math.sqrt(o*o+n*n),a=n/i,h=-o/i,u=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+h*e.y)/u);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,h*=-1);var c=Math.cos(l)*u;e.x=a*c,e.y=h*c})),t.forEach((function(n,i){if(i!==s){var u=Math.sqrt(e[i].x*e[i].x+e[i].y*e[i].y);if(u>0&&i!==s){var l=Math.min(h*(r/800),u);if(n.x+=e[i].x/u*l,n.y+=e[i].y/u*l,o){var c=n.x-t[s].x,f=n.y-t[s].y,d=Math.sqrt(c*c+f*f);c=c/d*a[i],f=f/d*a[i],n.x=t[s].x+c,n.y=t[s].y+f}}}})),t},dt={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,strictRadial:!0,maxPreventOverlapIteration:200,sortBy:void 0,sortStrength:10},gt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",this.options=e(e({},dt),t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,r,o){var a=e(e({},this.options),o),h=a.width,u=a.height,f=a.center,d=a.focusNode,g=a.unitRadius,m=a.nodeSize,p=a.nodeSpacing,w=a.strictRadial,y=a.preventOverlap,v=a.maxPreventOverlapIteration,b=a.sortBy,M=a.linkDistance,x=void 0===M?50:M,E=a.sortStrength,S=void 0===E?10:E,N=a.maxIteration,R=void 0===N?1e3:N,I=a.layoutInvisibles,A=a.onLayoutEnd,k=r.getAllNodes(),C=r.getAllEdges();if(I||(k=k.filter((function(t){return t.data.visible||void 0===t.data.visible})),C=C.filter((function(t){return t.data.visible||void 0===t.data.visible}))),!k||0===k.length){var T={nodes:[],edges:C};return null==A||A(T),T}var z=h||"undefined"==typeof window?h:window.innerWidth,D=u||"undefined"==typeof window?u:window.innerHeight,P=f||[z/2,D/2];if(1===k.length){t&&r.mergeNodeData(k[0].id,{x:P[0],y:P[1]});var L={nodes:[e(e({},k[0]),{data:e(e({},k[0].data),{x:P[0],y:P[1]})})],edges:C};return null==A||A(L),L}var q=k[0];if(i(d)){for(var $=0;$<k.length;$++)if(k[$].id===d){q=k[$];break}}else q=d||k[0];var j=yt(k,q.id),V=c({nodes:k,edges:C},!1),O=l(V),F=bt(O,j);vt(O,j,F+1);var Y=O[j],G=z-P[0]>P[0]?P[0]:z-P[0],_=D-P[1]>P[1]?P[1]:D-P[1];0===G&&(G=z/2),0===_&&(_=D/2);var U=Math.min(G,_),B=Math.max.apply(Math,n([],s(Y),!1)),K=[],W=g||U/B;Y.forEach((function(t,e){K[e]=t*W}));var J,H=mt(k,O,x,K,W,b,S),X=pt(H),Q=function(t,e,r){try{var o=rt.mul(rt.pow(e,2),-.5),s=o.mean("row"),n=o.mean("column"),i=o.mean();o.add(i).subRowVector(s).subColumnVector(n);var a=new nt(o),h=rt.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return rt.mul([e],[h]).toJSON()[0].splice(0,t)}))}catch(t){for(var u=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;u.push([c,f])}return u}}(x,H,x).map((function(t){var e=s(t,2),r=e[0],o=e[1];return{x:(isNaN(r)?Math.random()*x:r)-Q[j].x,y:(isNaN(o)?Math.random()*x:o)-Q[j].y}}));if(this.run(R,Q,X,H,K,j),y){J=Mt(m,p);var Z={nodes:k,nodeSizeFunc:J,positions:Q,radii:K,height:D,width:z,strictRadial:Boolean(w),focusIdx:j,iterations:v||200,k:Q.length/4.5};Q=function(t,r){for(var o=e(e({},lt),r),s=o.positions,n=o.iterations,i=o.width,a=o.k,h=o.speed,u=void 0===h?100:h,l=o.strictRadial,c=o.focusIdx,f=o.radii,d=void 0===f?[]:f,g=o.nodeSizeFunc,m=t.getAllNodes(),p=[],w=i/10,y=0;y<n;y++)s.forEach((function(t,e){p[e]={x:0,y:0}})),ct(m,s,p,a,d,g),ft(s,p,u,l,c,w,i,d);return s}(r,Z)}var tt=[];Q.forEach((function(t,r){tt.push(e(e({},k[r]),{data:e(e({},k[0].data),{x:t.x+P[0],y:t.y+P[1]})}))})),t&&tt.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var et={nodes:tt,edges:C};return null==A||A(et),et},t.prototype.run=function(t,e,r,o,s,n){for(var i=0;i<=t;i++){var a=i/t;this.oneIteration(a,e,s,o,r,n)}},t.prototype.oneIteration=function(t,e,r,o,s,n){var i=1-t;e.forEach((function(a,h){var u=wt(a,{x:0,y:0}),l=0===u?0:1/u;if(h!==n){var c=0,f=0,d=0;e.forEach((function(t,e){if(h!==e){var r=wt(a,t),n=0===r?0:1/r,i=o[e][h];d+=s[h][e],c+=s[h][e]*(t.x+i*(a.x-t.x)*n),f+=s[h][e]*(t.y+i*(a.y-t.y)*n)}}));var g=0===r[h]?0:1/r[h];d*=i,d+=t*g*g,c*=i,c+=t*g*a.x*l,a.x=c/d,f*=i,f+=t*g*a.y*l,a.y=f/d}}))},t}(),mt=function(t,e,r,o,s,n,a){if(!t)return[];var h=[];return e&&e.forEach((function(e,u){var l=[];e.forEach((function(e,h){if(u===h)l.push(0);else if(o[u]===o[h])if("data"===n)l.push(e*(Math.abs(u-h)*a)/(o[u]/s));else if(n){var c=t[u][n]||0,f=t[h][n]||0;i(c)&&(c=c.charCodeAt(0)),i(f)&&(f=f.charCodeAt(0)),l.push(e*(Math.abs(c-f)*a)/(o[u]/s))}else l.push(e*r/(o[u]/s));else{var d=(r+s)/2;l.push(e*d)}})),h.push(l)})),h},pt=function(t){for(var e=t.length,r=t[0].length,o=[],s=0;s<e;s++){for(var n=[],i=0;i<r;i++)0!==t[s][i]?n.push(1/(t[s][i]*t[s][i])):n.push(0);o.push(n)}return o},wt=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},yt=function(t,e){var r=-1;return t.forEach((function(t,o){t.id===e&&(r=o)})),Math.max(r,0)},vt=function(t,e,r){for(var o=t.length,s=0;s<o;s++)if(t[e][s]===1/0){t[e][s]=r,t[s][e]=r;for(var n=0;n<o;n++)t[s][n]!==1/0&&t[e][n]===1/0&&(t[e][n]=r+t[s][n],t[n][e]=r+t[s][n])}for(s=0;s<o;s++)if(s!==e)for(n=0;n<o;n++)if(t[s][n]===1/0){var i=Math.abs(t[e][s]-t[e][n]);i=0===i?1:i,t[s][n]=i}},bt=function(t,e){for(var r=0,o=0;o<t[e].length;o++)t[e][o]!==1/0&&(r=t[e][o]>r?t[e][o]:r);return r},Mt=function(t,e){var r;return r=u(e)?function(){return e}:g(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){return t.data.bboxSize?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):t.data.size?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):f(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},xt={center:[0,0],width:300,height:300},Et=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",this.options=e(e({},xt),t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,r,o){var s=e(e({},this.options),o),n=s.center,i=s.width,a=s.height,h=s.layoutInvisibles,u=s.onLayoutEnd,l=r.getAllNodes();h||(l=l.filter((function(t){return t.data.visible||void 0===t.data.visible})));var c=i||"undefined"==typeof window?i:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=n||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var m={nodes:g,edges:r.getAllEdges()};return null==u||u(m),m},t}(),St={circular:w,concentric:I,mds:at,random:Et,grid:k,radial:gt};function Nt(t,e){St[t]=e}})();var s=o.SB,n=o.W1,i=o.Me,a=o.AI,h=o.D4,u=o._5,l=o.y9,c=o.Xp,f=o.qR,d=o.i_;export{s as CircularLayout,n as ConcentricLayout,i as GridLayout,a as MDSLayout,h as RadialLayout,u as RandomLayout,l as Supervisor,c as SupervisorEvent,f as registerLayout,d as registry};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|