-
Notifications
You must be signed in to change notification settings - Fork 10
/
umap-js.min.js
1 lines (1 loc) · 73.5 KB
/
umap-js.min.js
1
!function(t,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var e=r();for(var n in e)("object"==typeof exports?exports:t)[n]=e[n]}}(window,function(){return function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(n,i,function(r){return t[r]}.bind(null,i));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=5)}([function(t,r,e){"use strict";const n=Object.prototype.toString;t.exports=function(t){return n.call(t).endsWith("Array]")}},function(t,r,e){"use strict";var n=this&&this.__values||function(t){var r="function"==typeof Symbol&&t[Symbol.iterator],e=0;return r?r.call(t):{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}}};function i(t,r){return Math.floor(r()*t)}function o(t){for(var r=[],e=0;e<t;e++)r.push(void 0);return r}function s(t,r){return o(t).map(function(){return r})}function a(t){return s(t,0)}function h(t){return t.reduce(function(t,r){return t+r})}Object.defineProperty(r,"__esModule",{value:!0}),r.tauRandInt=i,r.tauRand=function(t){return t()},r.norm=function(t){var r,e,i=0;try{for(var o=n(t),s=o.next();!s.done;s=o.next()){var a=s.value;i+=Math.pow(a,2)}}catch(t){r={error:t}}finally{try{s&&!s.done&&(e=o.return)&&e.call(o)}finally{if(r)throw r.error}}return Math.sqrt(i)},r.empty=o,r.range=function(t){return o(t).map(function(t,r){return r})},r.filled=s,r.zeros=a,r.ones=function(t){return s(t,1)},r.linear=function(t,r,e){return o(e).map(function(n,i){return t+i*((r-t)/(e-1))})},r.sum=h,r.mean=function(t){return h(t)/t.length},r.max=function(t){for(var r=0,e=0;e<t.length;e++)r=t[e]>r?t[e]:r;return r},r.max2d=function(t){for(var r=0,e=0;e<t.length;e++)for(var n=0;n<t[e].length;n++)r=t[e][n]>r?t[e][n]:r;return r},r.rejectionSample=function(t,r,e){for(var n=a(t),o=0;o<t;o++)for(var s=!0;s;){for(var h=i(r,e),u=!1,l=0;l<o;l++)if(h===n[l]){u=!0;break}u||(s=!1),n[o]=h}return n},r.reshape2d=function(t,r,e){var n=[],i=0;if(t.length!==r*e)throw new Error("Array dimensions must match input length.");for(var o=0;o<r;o++){for(var s=[],a=0;a<e;a++)s.push(t[i]),i+=1;n.push(s)}return n}},function(t,r,e){"use strict";var n=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var e in t)Object.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r.default=t,r};Object.defineProperty(r,"__esModule",{value:!0});var i=n(e(1));function o(t,r){var e=function(e){return i.empty(t).map(function(){return i.filled(r,e)})},n=[];return n.push(e(-1)),n.push(e(1/0)),n.push(e(0)),n}function s(t,r,e,n,i){r=Math.floor(r);var o=t[0][r],s=t[1][r];t[2][r];if(e>=s[0])return 0;for(var h=0;h<o.length;h++)if(n===o[h])return 0;return a(t,r,e,n,i)}function a(t,r,e,n,i){var o=t[0][r],s=t[1][r],a=t[2][r];if(e>=s[0])return 0;s[0]=e,o[0]=n,a[0]=i;for(var h=0,u=0;;){var l=2*h+1,c=l+1,f=t[0][0].length;if(l>=f)break;if(c>=f){if(!(s[l]>e))break;u=l}else if(s[l]>=s[c]){if(!(e<s[l]))break;u=l}else{if(!(e<s[c]))break;u=c}s[h]=s[u],o[h]=o[u],a[h]=a[u],h=u}return s[h]=e,o[h]=n,a[h]=i,1}function h(t,r,e,n){for(;2*n+1<e;){var i=2*n+1,o=i+1,s=n;if(t[s]<t[i]&&(s=i),o<e&&t[s]<t[o]&&(s=o),s===n)break;var a=t[n];t[n]=t[s],t[s]=a;var h=r[n];r[n]=r[s],r[s]=h,n=s}}r.makeHeap=o,r.rejectionSample=function(t,r,e){for(var n=i.zeros(t),o=0;o<t;o++){for(var s=!0,a=0;s;){a=i.tauRandInt(r,e);for(var h=!1,u=0;u<o;u++)if(a===n[u]){h=!0;break}h||(s=!1)}n[o]=a}return n},r.heapPush=s,r.uncheckedHeapPush=a,r.buildCandidates=function(t,r,e,n,a){for(var h=o(r,n),u=0;u<r;u++)for(var l=0;l<e;l++)if(!(t[0][u][l]<0)){var c=t[0][u][l],f=t[2][u][l],m=i.tauRand(a);s(h,u,m,c,f),s(h,c,m,u,f),t[2][u][l]=0}return h},r.deheapSort=function(t){for(var r=t[0],e=t[1],n=0;n<r.length;n++)for(var i=r[n],o=e[n],s=0;s<i.length-1;s++){var a=i.length-s-1,u=o.length-s-1,l=i[0];i[0]=i[a],i[a]=l;var c=o[0];o[0]=o[u],o[u]=c,h(o,i,u,0)}return{indices:r,weights:e}},r.smallestFlagged=function(t,r){for(var e=t[0][r],n=t[1][r],i=t[2][r],o=1/0,s=-1,a=0;a>e.length;a++)1===i[a]&&n[a]<o&&(o=n[a],s=a);return s>=0?(i[s]=0,Math.floor(e[s])):-1}},function(t,r,e){"use strict";var n,i=this&&this.__read||function(t,r){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var n,i,o=e.call(t),s=[];try{for(;(void 0===r||r-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return s},o=this&&this.__values||function(t){var r="function"==typeof Symbol&&t[Symbol.iterator],e=0;return r?r.call(t):{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}}},s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var e in t)Object.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r.default=t,r};Object.defineProperty(r,"__esModule",{value:!0});var a=s(e(1)),h=function(){function t(t,r,e,n){if(this.entries=new Map,this.nRows=0,this.nCols=0,t.length!==r.length||t.length!==e.length)throw new Error("rows, cols and values arrays must all have the same length");this.nRows=n[0],this.nCols=n[1];for(var i=0;i<e.length;i++){var o=t[i],s=r[i];this.checkDims(o,s);var a=this.makeKey(o,s);this.entries.set(a,{value:e[i],row:o,col:s})}}return t.prototype.makeKey=function(t,r){return t+":"+r},t.prototype.checkDims=function(t,r){if(!(t<this.nRows&&r<this.nCols))throw new Error("row and/or col specified outside of matrix dimensions")},t.prototype.set=function(t,r,e){this.checkDims(t,r);var n=this.makeKey(t,r);this.entries.has(n)?this.entries.get(n).value=e:this.entries.set(n,{value:e,row:t,col:r})},t.prototype.get=function(t,r,e){void 0===e&&(e=0),this.checkDims(t,r);var n=this.makeKey(t,r);return this.entries.has(n)?this.entries.get(n).value:e},t.prototype.getAll=function(t){void 0===t&&(t=!0);var r=[];return this.entries.forEach(function(t){r.push(t)}),t&&r.sort(function(t,r){return t.row===r.row?t.col-r.col:t.row-r.row}),r},t.prototype.getDims=function(){return[this.nRows,this.nCols]},t.prototype.getRows=function(){return Array.from(this.entries,function(t){var r=i(t,2);r[0];return r[1].row})},t.prototype.getCols=function(){return Array.from(this.entries,function(t){var r=i(t,2);r[0];return r[1].col})},t.prototype.getValues=function(){return Array.from(this.entries,function(t){var r=i(t,2);r[0];return r[1].value})},t.prototype.forEach=function(t){this.entries.forEach(function(r){return t(r.value,r.row,r.col)})},t.prototype.map=function(r){var e=[];this.entries.forEach(function(t){e.push(r(t.value,t.row,t.col))});var n=[this.nRows,this.nCols];return new t(this.getRows(),this.getCols(),e,n)},t.prototype.toArray=function(){var t=this,r=a.empty(this.nRows).map(function(){return a.zeros(t.nCols)});return this.entries.forEach(function(t){r[t.row][t.col]=t.value}),r},t}();r.SparseMatrix=h,r.transpose=function(t){var r=[],e=[],n=[];t.forEach(function(t,i,o){r.push(i),e.push(o),n.push(t)});var i=[t.nCols,t.nRows];return new h(e,r,n,i)},r.identity=function(t){for(var r=i(t,1)[0],e=new h([],[],[],t),n=0;n<r;n++)e.set(n,n,1);return e},r.pairwiseMultiply=function(t,r){return l(t,r,function(t,r){return t*r})},r.add=function(t,r){return l(t,r,function(t,r){return t+r})},r.subtract=function(t,r){return l(t,r,function(t,r){return t-r})},r.maximum=function(t,r){return l(t,r,function(t,r){return t>r?t:r})},r.multiplyScalar=function(t,r){return t.map(function(t){return t*r})},r.eliminateZeros=function(t){for(var r=new Set,e=t.getValues(),n=t.getRows(),i=t.getCols(),o=0;o<e.length;o++)0===e[o]&&r.add(o);var s=function(t,e){return!r.has(e)},a=e.filter(s),u=n.filter(s),l=i.filter(s);return new h(u,l,a,t.getDims())},r.normalize=function(t,r){var e,n;void 0===r&&(r="l2");var i=u[r],s=new Map;t.forEach(function(t,r,e){var n=s.get(r)||[];n.push(e),s.set(r,n)});var a=new h([],[],[],t.getDims()),l=function(r){for(var e=s.get(r).sort(),n=e.map(function(e){return t.get(r,e)}),o=i(n),h=0;h<o.length;h++)a.set(r,e[h],o[h])};try{for(var c=o(s.keys()),f=c.next();!f.done;f=c.next())l(f.value)}catch(t){e={error:t}}finally{try{f&&!f.done&&(n=c.return)&&n.call(c)}finally{if(e)throw e.error}}return a};var u=((n={}).max=function(t){for(var r=-1/0,e=0;e<t.length;e++)r=t[e]>r?t[e]:r;return t.map(function(t){return t/r})},n.l1=function(t){for(var r=0,e=0;e<t.length;e++)r+=t[e];return t.map(function(t){return t/r})},n.l2=function(t){for(var r=0,e=0;e<t.length;e++)r+=Math.pow(t[e],2);return t.map(function(t){return Math.sqrt(Math.pow(t,2)/r)})},n);function l(t,r,e){for(var n=new Set,i=[],o=[],s=[],a=function(n,a){i.push(n),o.push(a);var h=e(t.get(n,a),r.get(n,a));s.push(h)},u=t.getValues(),l=t.getRows(),c=t.getCols(),f=0;f<u.length;f++){var m=(d=l[f])+":"+(w=c[f]);n.add(m),a(d,w)}var g=r.getValues(),p=r.getRows(),v=r.getCols();for(f=0;f<g.length;f++){var d,w;m=(d=p[f])+":"+(w=v[f]);n.has(m)||a(d,w)}var y=[t.nRows,t.nCols];return new h(i,o,s,y)}r.getCSR=function(t){var r=[];t.forEach(function(t,e,n){r.push({value:t,row:e,col:n})}),r.sort(function(t,r){return t.row===r.row?t.col-r.col:t.row-r.row});for(var e=[],n=[],i=[],o=-1,s=0;s<r.length;s++){var a=r[s],h=a.row,u=a.col,l=a.value;h!==o&&(o=h,i.push(s)),e.push(u),n.push(l)}return{indices:e,values:n,indptr:i}}},function(t,r,e){"use strict";var n=this&&this.__read||function(t,r){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var n,i,o=e.call(t),s=[];try{for(;(void 0===r||r-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return s},i=this&&this.__spread||function(){for(var t=[],r=0;r<arguments.length;r++)t=t.concat(n(arguments[r]));return t},o=this&&this.__values||function(t){var r="function"==typeof Symbol&&t[Symbol.iterator],e=0;return r?r.call(t):{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}}},s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var e in t)Object.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r.default=t,r};Object.defineProperty(r,"__esModule",{value:!0});var a=s(e(1)),h=function(){return function(t,r,e,n){this.hyperplanes=t,this.offsets=r,this.children=e,this.indices=n}}();function u(t,r,e,n){for(var i=r,o=0;o<e.length;o++)i+=t[o]*e[o];return 0===i?a.tauRandInt(2,n):i>0?0:1}r.FlatTree=h,r.makeForest=function(t,r,e,n){var o=Math.max(10,r);return a.range(e).map(function(r,e){return function(t,r,e,n){void 0===r&&(r=30);var i=a.range(t.length);return function t(r,e,n,i,o){if(void 0===n&&(n=30),e.length>n){var s=function(t,r,e){var n=t[0].length,i=a.tauRandInt(r.length,e),o=a.tauRandInt(r.length,e);o=(o+=i===o?1:0)%r.length;for(var s=r[i],h=r[o],u=0,l=a.zeros(n),c=0;c<l.length;c++)l[c]=t[s][c]-t[h][c],u-=l[c]*(t[s][c]+t[h][c])/2;for(var f=0,m=0,g=a.zeros(r.length),c=0;c<r.length;c++){for(var p=u,v=0;v<n;v++)p+=l[v]*t[r[c]][v];0===p?(g[c]=a.tauRandInt(2,e),0===g[c]?f+=1:m+=1):p>0?(g[c]=0,f+=1):(g[c]=1,m+=1)}var d=a.zeros(f),w=a.zeros(m);for(var c in f=0,m=0,a.range(g.length))0===g[c]?(d[f]=r[c],f+=1):(w[m]=r[c],m+=1);return{indicesLeft:d,indicesRight:w,hyperplane:l,offset:u}}(r,e,o),h=s.indicesLeft,u=s.indicesRight,l=s.hyperplane,c=s.offset,f=t(r,h,n,i+1,o),m=t(r,u,n,i+1,o),g={leftChild:f,rightChild:m,isLeaf:!1,hyperplane:l,offset:c};return g}var g={indices:e,isLeaf:!0};return g}(t,i,r,e,n)}(t,o,e,n)}).map(function(t){return function(t,r){var e=function t(r){return r.isLeaf?1:1+t(r.leftChild)+t(r.rightChild)}(t),n=function t(r){return r.isLeaf?1:t(r.leftChild)+t(r.rightChild)}(t),o=a.range(e).map(function(){return a.zeros(t.hyperplane?t.hyperplane.length:0)}),s=a.zeros(e),u=a.range(e).map(function(){return[-1,-1]}),l=a.range(n).map(function(){return a.range(r).map(function(){return-1})});return function t(r,e,n,o,s,a,h){var u;if(r.isLeaf)return o[a][0]=-h,(u=s[h]).splice.apply(u,i([0,r.indices.length],r.indices)),{nodeNum:a,leafNum:h+=1};e[a]=r.hyperplane,n[a]=r.offset,o[a][0]=a+1;var l=a,c=t(r.leftChild,e,n,o,s,a+1,h);return a=c.nodeNum,h=c.leafNum,o[l][1]=a+1,{nodeNum:(c=t(r.rightChild,e,n,o,s,a+1,h)).nodeNum,leafNum:c.leafNum}}(t,o,s,u,l,0,0),new h(o,s,u,l)}(t,o)})},r.makeLeafArray=function(t){var r,e;if(t.length>0){var n=[];try{for(var s=o(t),a=s.next();!a.done;a=s.next()){var h=a.value;n.push.apply(n,i(h.indices))}}catch(t){r={error:t}}finally{try{a&&!a.done&&(e=s.return)&&e.call(s)}finally{if(r)throw r.error}}return n}return[[-1]]},r.searchFlatTree=function(t,r,e){for(var n=0;r.children[n][0]>0;)n=0===u(r.hyperplanes[n],r.offsets[n],t,e)?r.children[n][0]:r.children[n][1];var i=-1*r.children[n][0];return r.indices[i]}},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e(6);r.UMAP=n.UMAP},function(t,r,e){"use strict";var n=this&&this.__awaiter||function(t,r,e,n){return new(e||(e=Promise))(function(i,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){t.done?i(t.value):new e(function(r){r(t.value)}).then(s,a)}h((n=n.apply(t,r||[])).next())})},i=this&&this.__generator||function(t,r){var e,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;s;)try{if(e=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=r.call(t,s)}catch(t){o=[6,t],n=0}finally{e=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},o=this&&this.__read||function(t,r){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var n,i,o=e.call(t),s=[];try{for(;(void 0===r||r-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return s},s=this&&this.__spread||function(){for(var t=[],r=0;r<arguments.length;r++)t=t.concat(o(arguments[r]));return t},a=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var e in t)Object.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r.default=t,r},h=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(r,"__esModule",{value:!0});var u=a(e(2)),l=a(e(3)),c=a(e(7)),f=a(e(4)),m=a(e(1)),g=h(e(8)),p=function(){function t(t){void 0===t&&(t={});var r=this;this.learningRate=1,this.localConnectivity=1,this.minDist=.1,this.nComponents=2,this.nEpochs=0,this.nNeighbors=15,this.negativeSampleRate=5,this.random=Math.random,this.repulsionStrength=1,this.setOpMixRatio=1,this.spread=1,this.transformQueueSize=4,this.targetMetric="categorical",this.targetWeight=.5,this.targetNNeighbors=this.nNeighbors,this.distanceFn=v,this.isInitialized=!1,this.rpForest=[],this.embedding=[],this.optimizationState=new d;var e=function(e){void 0!==t[e]&&(r[e]=t[e])};e("distanceFn"),e("learningRate"),e("localConnectivity"),e("minDist"),e("nComponents"),e("nEpochs"),e("nNeighbors"),e("negativeSampleRate"),e("random"),e("repulsionStrength"),e("setOpMixRatio"),e("spread"),e("transformQueueSize")}return t.prototype.fit=function(t){return this.initializeFit(t),this.optimizeLayout(),this.embedding},t.prototype.fitAsync=function(t,r){return void 0===r&&(r=function(){return!0}),n(this,void 0,void 0,function(){return i(this,function(e){switch(e.label){case 0:return this.initializeFit(t),[4,this.optimizeLayoutAsync(r)];case 1:return e.sent(),[2,this.embedding]}})})},t.prototype.setSupervisedProjection=function(t,r){void 0===r&&(r={}),this.Y=t,this.targetMetric=r.targetMetric||this.targetMetric,this.targetWeight=r.targetWeight||this.targetWeight,this.targetNNeighbors=r.targetNNeighbors||this.targetNNeighbors},t.prototype.setPrecomputedKNN=function(t,r){this.knnIndices=t,this.knnDistances=r},t.prototype.initializeFit=function(t){if(t.length<=this.nNeighbors)throw new Error("Not enough data points ("+t.length+") to create nNeighbors: "+this.nNeighbors+". Add more data points or adjust the configuration.");if(this.X===t&&this.isInitialized)return this.getNEpochs();if(this.X=t,!this.knnIndices&&!this.knnDistances){var r=this.nearestNeighbors(t);this.knnIndices=r.knnIndices,this.knnDistances=r.knnDistances}this.graph=this.fuzzySimplicialSet(t,this.nNeighbors,this.setOpMixRatio),this.makeSearchFns(),this.searchGraph=this.makeSearchGraph(t),this.processGraphForSupervisedProjection();var e=this.initializeSimplicialSetEmbedding(),n=e.head,i=e.tail,o=e.epochsPerSample;return this.optimizationState.head=n,this.optimizationState.tail=i,this.optimizationState.epochsPerSample=o,this.initializeOptimization(),this.prepareForOptimizationLoop(),this.isInitialized=!0,this.getNEpochs()},t.prototype.makeSearchFns=function(){var t=c.makeInitializations(this.distanceFn),r=t.initFromTree,e=t.initFromRandom;this.initFromTree=r,this.initFromRandom=e,this.search=c.makeInitializedNNSearch(this.distanceFn)},t.prototype.makeSearchGraph=function(t){for(var r=this.knnIndices,e=this.knnDistances,n=[t.length,t.length],i=new l.SparseMatrix([],[],[],n),o=0;o<r.length;o++)for(var s=r[o],a=e[o],h=0;h<s.length;h++){var u=s[h],c=a[h];c>0&&i.set(o,u,c)}var f=l.transpose(i);return l.maximum(i,f)},t.prototype.transform=function(t){var r=this,e=this.X;if(void 0===e||0===e.length)throw new Error("No data has been fit.");var n=Math.floor(this.nNeighbors*this.transformQueueSize);n=Math.min(e.length,n);var i=c.initializeSearch(this.rpForest,e,t,n,this.initFromRandom,this.initFromTree,this.random),o=this.search(e,this.searchGraph,i,t),s=u.deheapSort(o),a=s.indices,h=s.weights;a=a.map(function(t){return t.slice(0,r.nNeighbors)}),h=h.map(function(t){return t.slice(0,r.nNeighbors)});var f=Math.max(0,this.localConnectivity-1),g=this.smoothKNNDistance(h,this.nNeighbors,f),p=g.sigmas,v=g.rhos,d=this.computeMembershipStrengths(a,h,p,v),w=d.rows,y=d.cols,b=d.vals,M=[t.length,e.length],x=new l.SparseMatrix(w,y,b,M),E=l.normalize(x,"l1"),R=l.getCSR(E),k=t.length,z=S(m.reshape2d(R.indices,k,this.nNeighbors),m.reshape2d(R.values,k,this.nNeighbors),this.embedding),N=this.nEpochs?this.nEpochs/3:x.nRows<=1e4?100:30,A=x.getValues().reduce(function(t,r){return r>t?r:t},0);x=x.map(function(t){return t<A/N?0:t}),x=l.eliminateZeros(x);var V=this.makeEpochsPerSample(x.getValues(),N),C=x.getRows(),_=x.getCols();return this.assignOptimizationStateParameters({headEmbedding:z,tailEmbedding:this.embedding,head:C,tail:_,currentEpoch:0,nEpochs:N,nVertices:x.getDims()[1],epochsPerSample:V}),this.prepareForOptimizationLoop(),this.optimizeLayout()},t.prototype.processGraphForSupervisedProjection=function(){var t=this.Y,r=this.X;if(t){if(t.length!==r.length)throw new Error("Length of X and y must be equal");if("categorical"===this.targetMetric){var e=this.targetWeight<1?1/(1-this.targetWeight)*2.5:1e12;this.graph=this.categoricalSimplicialSetIntersection(this.graph,t,e)}}},t.prototype.step=function(){var t=this.optimizationState.currentEpoch;return t<this.getNEpochs()&&this.optimizeLayoutStep(t),this.optimizationState.currentEpoch},t.prototype.getEmbedding=function(){return this.embedding},t.prototype.nearestNeighbors=function(t){var r,e=this.distanceFn,n=this.nNeighbors,i=c.makeNNDescent(e,this.random),o=5+Math.floor(.5===(r=Math.pow(t.length,.5)/20)?0:Math.round(r)),s=Math.max(5,Math.floor(Math.round(function(t){return Math.log(t)/Math.log(2)}(t.length))));this.rpForest=f.makeForest(t,n,o,this.random);var a=i(t,f.makeLeafArray(this.rpForest),n,s);return{knnIndices:a.indices,knnDistances:a.weights}},t.prototype.fuzzySimplicialSet=function(t,r,e){void 0===e&&(e=1);var n=this.knnIndices,i=void 0===n?[]:n,o=this.knnDistances,s=void 0===o?[]:o,a=this.localConnectivity,h=this.smoothKNNDistance(s,r,a),u=h.sigmas,c=h.rhos,f=this.computeMembershipStrengths(i,s,u,c),m=f.rows,g=f.cols,p=f.vals,v=[t.length,t.length],d=new l.SparseMatrix(m,g,p,v),w=l.transpose(d),y=l.pairwiseMultiply(d,w),b=l.subtract(l.add(d,w),y),M=l.multiplyScalar(b,e),x=l.multiplyScalar(y,1-e);return l.add(M,x)},t.prototype.categoricalSimplicialSetIntersection=function(t,r,e,n){void 0===n&&(n=1);var i=M(t,r,n,e);return x(i=l.eliminateZeros(i))},t.prototype.smoothKNNDistance=function(t,r,e,n,i){void 0===e&&(e=1),void 0===n&&(n=64),void 0===i&&(i=1);for(var o=Math.log(r)/Math.log(2)*i,s=m.zeros(t.length),a=m.zeros(t.length),h=0;h<t.length;h++){var u=0,l=1/0,c=1,f=t[h],g=f.filter(function(t){return t>0});if(g.length>=e){var p=Math.floor(e),v=e-p;p>0?(s[h]=g[p-1],v>1e-5&&(s[h]+=v*(g[p]-g[p-1]))):s[h]=v*g[0]}else g.length>0&&(s[h]=m.max(g));for(var d=0;d<n;d++){for(var w=0,y=1;y<t[h].length;y++){var b=t[h][y]-s[h];w+=b>0?Math.exp(-b/c):1}if(Math.abs(w-o)<1e-5)break;w>o?c=(u+(l=c))/2:(u=c,l===1/0?c*=2:c=(u+l)/2)}if(a[h]=c,s[h]>0){var M=m.mean(f);a[h]<.001*M&&(a[h]=.001*M)}else{var x=m.mean(t.map(m.mean));a[h]<.001*x&&(a[h]=.001*x)}}return{sigmas:a,rhos:s}},t.prototype.computeMembershipStrengths=function(t,r,e,n){for(var i=t.length,o=t[0].length,s=m.zeros(i*o),a=m.zeros(i*o),h=m.zeros(i*o),u=0;u<i;u++)for(var l=0;l<o;l++){var c=0;-1!==t[u][l]&&(c=t[u][l]===u?0:r[u][l]-n[u]<=0?1:Math.exp(-(r[u][l]-n[u])/e[u]),s[u*o+l]=u,a[u*o+l]=t[u][l],h[u*o+l]=c)}return{rows:s,cols:a,vals:h}},t.prototype.initializeSimplicialSetEmbedding=function(){for(var t=this,r=this.getNEpochs(),e=this.nComponents,n=this.graph.getValues(),i=0,o=0;o<n.length;o++){var s=n[o];i<n[o]&&(i=s)}var a=this.graph.map(function(t){return t<i/r?0:t});this.embedding=m.zeros(a.nRows).map(function(){return m.zeros(e).map(function(){return 20*m.tauRand(t.random)-10})});var h=[],u=[],l=[],c=a.getAll();for(o=0;o<c.length;o++){var f=c[o];f.value&&(h.push(f.value),l.push(f.row),u.push(f.col))}return{head:u,tail:l,epochsPerSample:this.makeEpochsPerSample(h,r)}},t.prototype.makeEpochsPerSample=function(t,r){var e=m.filled(t.length,-1),n=m.max(t),i=t.map(function(t){return t/n*r});return i.forEach(function(t,n){t>0&&(e[n]=r/i[n])}),e},t.prototype.assignOptimizationStateParameters=function(t){Object.assign(this.optimizationState,t)},t.prototype.prepareForOptimizationLoop=function(){var t=this.repulsionStrength,r=this.learningRate,e=this.negativeSampleRate,n=this.optimizationState,i=n.epochsPerSample,o=n.headEmbedding,a=n.tailEmbedding,h=o[0].length,u=o.length===a.length,l=i.map(function(t){return t/e}),c=s(l),f=s(i);this.assignOptimizationStateParameters({epochOfNextSample:f,epochOfNextNegativeSample:c,epochsPerNegativeSample:l,moveOther:u,initialAlpha:r,alpha:r,gamma:t,dim:h})},t.prototype.initializeOptimization=function(){var t=this.embedding,r=this.embedding,e=this.optimizationState,n=e.head,i=e.tail,o=e.epochsPerSample,s=this.getNEpochs(),a=this.graph.nCols,h=b(this.spread,this.minDist),u=h.a,l=h.b;this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:r,head:n,tail:i,epochsPerSample:o,a:u,b:l,nEpochs:s,nVertices:a})},t.prototype.optimizeLayoutStep=function(t){for(var r=this.optimizationState,e=r.head,n=r.tail,i=r.headEmbedding,o=r.tailEmbedding,s=r.epochsPerSample,a=r.epochOfNextSample,h=r.epochOfNextNegativeSample,u=r.epochsPerNegativeSample,l=r.moveOther,c=r.initialAlpha,f=r.alpha,g=r.gamma,p=r.a,v=r.b,d=r.dim,b=r.nEpochs,M=r.nVertices,x=0;x<s.length;x++)if(!(a[x]>t)){var S=e[x],E=n[x],R=i[S],k=o[E],z=y(R,k),N=0;z>0&&(N=-2*p*v*Math.pow(z,v-1),N/=p*Math.pow(z,v)+1);for(var A=0;A<d;A++){var V=w(N*(R[A]-k[A]),4);R[A]+=V*f,l&&(k[A]+=-V*f)}a[x]+=s[x];for(var C=Math.floor((t-h[x])/u[x]),_=0;_<C;_++){var P=m.tauRandInt(M,this.random),j=o[P],I=y(R,j),O=0;if(I>0)O=2*g*v,O/=(.001+I)*(p*Math.pow(I,v)+1);else if(S===P)continue;for(A=0;A<d;A++){V=4;O>0&&(V=w(O*(R[A]-j[A]),4)),R[A]+=V*f}}h[x]+=C*u[x]}return r.alpha=c*(1-t/b),r.currentEpoch+=1,i},t.prototype.optimizeLayoutAsync=function(t){var r=this;return void 0===t&&(t=function(){return!0}),new Promise(function(e,o){var s=function(){return n(r,void 0,void 0,function(){var r,n,a,h,u,l;return i(this,function(i){try{if(r=this.optimizationState,n=r.nEpochs,a=r.currentEpoch,this.embedding=this.optimizeLayoutStep(a),h=this.optimizationState.currentEpoch,u=!1===t(h),l=h===n,u||l)return[2,e(l)];setTimeout(function(){return s()},0)}catch(t){o(t)}return[2]})})};setTimeout(function(){return s()},0)})},t.prototype.optimizeLayout=function(t){void 0===t&&(t=function(){return!0});for(var r=!1,e=[];!r;){var n=this.optimizationState,i=n.nEpochs,o=n.currentEpoch;e=this.optimizeLayoutStep(o);var s=this.optimizationState.currentEpoch,a=!1===t(s);r=s===i||a}return e},t.prototype.getNEpochs=function(){var t=this.graph;if(this.nEpochs>0)return this.nEpochs;var r=t.nRows;return r<=2500?500:r<=5e3?400:r<=7500?300:200},t}();function v(t,r){for(var e=0,n=0;n<t.length;n++)e+=Math.pow(t[n]-r[n],2);return Math.sqrt(e)}r.UMAP=p,r.euclidean=v,r.cosine=function(t,r){for(var e=0,n=0,i=0,o=0;o<t.length;o++)e+=t[o]*r[o],n+=Math.pow(t[o],2),i+=Math.pow(r[o],2);return 0===n&&0===i?0:0===n||0===i?1:1-e/Math.sqrt(n*i)};var d=function(){return function(){this.currentEpoch=0,this.headEmbedding=[],this.tailEmbedding=[],this.head=[],this.tail=[],this.epochsPerSample=[],this.epochOfNextSample=[],this.epochOfNextNegativeSample=[],this.epochsPerNegativeSample=[],this.moveOther=!0,this.initialAlpha=1,this.alpha=1,this.gamma=1,this.a=1.5769434603113077,this.b=.8950608779109733,this.dim=2,this.nEpochs=500,this.nVertices=0}}();function w(t,r){return t>r?r:t<-r?-r:t}function y(t,r){for(var e=0,n=0;n<t.length;n++)e+=Math.pow(t[n]-r[n],2);return e}function b(t,r){var e=m.linear(0,3*t,300).map(function(t){return t<r?1:t}),n=m.zeros(e.length).map(function(n,i){return e[i]>=r?Math.exp(-(e[i]-r)/t):n}),i={x:e,y:n},s={damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01},a=g.default(i,function(t){var r=o(t,2),e=r[0],n=r[1];return function(t){return 1/(1+e*Math.pow(t,2*n))}},s).parameterValues,h=o(a,2);return{a:h[0],b:h[1]}}function M(t,r,e,n){return void 0===e&&(e=1),void 0===n&&(n=5),t.map(function(t,i,o){return-1===r[i]||-1===r[o]?t*Math.exp(-e):r[i]!==r[o]?t*Math.exp(-n):t})}function x(t){t=l.normalize(t,"max");var r=l.transpose(t),e=l.pairwiseMultiply(r,t);return t=l.add(t,l.subtract(r,e)),l.eliminateZeros(t)}function S(t,r,e){for(var n=m.zeros(t.length).map(function(t){return m.zeros(e[0].length)}),i=0;i<t.length;i++)for(var o=0;o<t[0].length;o++)for(var s=0;s<e[0].length;s++){var a=t[i][o];n[i][s]+=r[i][o]*e[a][s]}return n}r.findABParams=b,r.fastIntersection=M,r.resetLocalConnectivity=x,r.initTransform=S},function(t,r,e){"use strict";var n=this&&this.__values||function(t){var r="function"==typeof Symbol&&t[Symbol.iterator],e=0;return r?r.call(t):{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}}},i=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var e in t)Object.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r.default=t,r};Object.defineProperty(r,"__esModule",{value:!0});var o=i(e(2)),s=i(e(3)),a=i(e(4)),h=i(e(1));r.makeNNDescent=function(t,r){return function(e,n,i,s,a,u,l,c){void 0===s&&(s=10),void 0===a&&(a=50),void 0===u&&(u=.001),void 0===l&&(l=.5),void 0===c&&(c=!0);for(var f=e.length,m=o.makeHeap(e.length,i),g=0;g<e.length;g++)for(var p=o.rejectionSample(i,e.length,r),v=0;v<p.length;v++){var d=t(e[g],e[p[v]]);o.heapPush(m,g,d,p[v],1),o.heapPush(m,p[v],d,g,1)}if(c)for(var w=0;w<n.length;w++)for(g=0;g<n[w].length&&!(n[w][g]<0);g++)for(v=g+1;v<n[w].length&&!(n[w][v]<0);v++)d=t(e[n[w][g]],e[n[w][v]]),o.heapPush(m,n[w][g],d,n[w][v],1),o.heapPush(m,n[w][v],d,n[w][g],1);for(w=0;w<s;w++){var y=o.buildCandidates(m,f,i,a,r),b=0;for(g=0;g<f;g++)for(v=0;v<a;v++){var M=Math.floor(y[0][g][v]);if(!(M<0||h.tauRand(r)<l))for(var x=0;x<a;x++){var S=Math.floor(y[0][g][x]),E=y[2][g][v],R=y[2][g][x];S<0||!E&&!R||(d=t(e[M],e[S]),b+=o.heapPush(m,M,d,S,1),b+=o.heapPush(m,S,d,M,1))}}if(b<=u*i*e.length)break}return o.deheapSort(m)}},r.makeInitializations=function(t){return{initFromRandom:function(r,e,n,i,s){for(var a=0;a<n.length;a++)for(var u=h.rejectionSample(r,e.length,s),l=0;l<u.length;l++)if(!(u[l]<0)){var c=t(e[u[l]],n[a]);o.heapPush(i,a,c,u[l],1)}},initFromTree:function(r,e,n,i,s){for(var h=0;h<n.length;h++)for(var u=a.searchFlatTree(n[h],r,s),l=0;l<u.length;l++){if(u[l]<0)return;var c=t(e[u[l]],n[h]);o.heapPush(i,h,c,u[l],1)}}}},r.makeInitializedNNSearch=function(t){return function(r,e,i,a){for(var h,u,l=s.getCSR(e),c=l.indices,f=l.indptr,m=0;m<a.length;m++)for(var g=new Set(i[0][m]);;){var p=o.smallestFlagged(i,m);if(-1===p)break;var v=c.slice(f[p],f[p+1]);try{for(var d=n(v),w=d.next();!w.done;w=d.next()){var y=w.value;if(y!==p&&-1!==y&&!g.has(y)){var b=t(r[y],a[m]);o.uncheckedHeapPush(i,m,b,y,1),g.add(y)}}}catch(t){h={error:t}}finally{try{w&&!w.done&&(u=d.return)&&u.call(d)}finally{if(h)throw h.error}}}return i}},r.initializeSearch=function(t,r,e,i,s,a,h){var u,l,c=o.makeHeap(e.length,i);if(s(i,r,e,c,h),t)try{for(var f=n(t),m=f.next();!m.done;m=f.next())a(m.value,r,e,c,h)}catch(t){u={error:t}}finally{try{m&&!m.done&&(l=f.return)&&l.call(f)}finally{if(u)throw u.error}}return c}},function(t,r,e){"use strict";var n=e(9);function i(t,r,e){var n=0;const i=e(r);for(var o=0;o<t.x.length;o++)n+=Math.abs(t.y[o]-i(t.x[o]));return n}function o(t,r,e,i,o){var s=n.Matrix.eye(r.length).mul(e*i*i),a=t.x.length,h=new Array(a);const u=o(r);for(var l=0;l<a;l++)h[l]=u(t.x[l]);var c=function(t,r,e,i,o){const s=e.length,a=t.x.length;for(var h=new Array(s),u=0;u<s;u++){h[u]=new Array(a);var l=e.concat();l[u]+=i;for(var c=o(l),f=0;f<a;f++)h[u][f]=r[f]-c(t.x[f])}return new n.Matrix(h)}(t,h,r,i,o),f=function(t,r){const e=t.x.length;for(var i=new Array(e),o=0;o<e;o++)i[o]=t.y[o]-r[o];return new n.Matrix([i])}(t,h).transposeView(),m=n.inverse(s.add(c.mmul(c.transposeView())));return(r=(r=new n.Matrix([r])).sub(m.mmul(c).mmul(f).mul(i).transposeView())).to1DArray()}t.exports=function(t,r,e={}){let{maxIterations:n=100,gradientDifference:s=.1,damping:a=0,errorTolerance:h=.01,initialValues:u}=e;if(a<=0)throw new Error("The damping option must be a positive number");if(!t.x||!t.y)throw new Error("The data parameter must have x and y elements");if(!Array.isArray(t.x)||t.x.length<2||!Array.isArray(t.y)||t.y.length<2)throw new Error("The data parameter elements must be an array with more than 2 points");if(t.x.length!==t.y.length)throw new Error("The data parameter elements must have the same size");var l=u||new Array(r.length).fill(1);if(!Array.isArray(l))throw new Error("initialValues must be an array");for(var c=i(t,l,r),f=c<=h,m=0;m<n&&!f;m++)f=(c=i(t,l=o(t,l,a,s,r),r))<=h;return{parameterValues:l,parameterError:c,iterations:m}}},function(t,r,e){"use strict";e.r(r);var n=e(0),i=e.n(n);var o=function(t){if(!i()(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");for(var r=t[0],e=1;e<t.length;e++)t[e]>r&&(r=t[e]);return r};var s=function(t){if(!i()(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");for(var r=t[0],e=1;e<t.length;e++)t[e]<r&&(r=t[e]);return r};var a=function(t){var r,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!i()(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==e.output){if(!i()(e.output))throw new TypeError("output option must be an array if specified");r=e.output}else r=new Array(t.length);var n=s(t),a=o(t);if(n===a)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var h=e.min,u=void 0===h?e.autoMinMax?n:0:h,l=e.max,c=void 0===l?e.autoMinMax?a:1:l;if(u>=c)throw new RangeError("min option must be smaller than max option");for(var f=(c-u)/(a-n),m=0;m<t.length;m++)r[m]=(t[m]-n)*f+u;return r};class h{constructor(t){var r,e,n,i,o,s,a,h,u,l=(t=j.checkMatrix(t)).clone(),c=l.rows,f=l.columns,m=new Array(c),g=1;for(r=0;r<c;r++)m[r]=r;for(h=new Array(c),e=0;e<f;e++){for(r=0;r<c;r++)h[r]=l.get(r,e);for(r=0;r<c;r++){for(u=Math.min(r,e),o=0,n=0;n<u;n++)o+=l.get(r,n)*h[n];h[r]-=o,l.set(r,e,h[r])}for(i=e,r=e+1;r<c;r++)Math.abs(h[r])>Math.abs(h[i])&&(i=r);if(i!==e){for(n=0;n<f;n++)s=l.get(i,n),l.set(i,n,l.get(e,n)),l.set(e,n,s);a=m[i],m[i]=m[e],m[e]=a,g=-g}if(e<c&&0!==l.get(e,e))for(r=e+1;r<c;r++)l.set(r,e,l.get(r,e)/l.get(e,e))}this.LU=l,this.pivotVector=m,this.pivotSign=g}isSingular(){for(var t=this.LU,r=t.columns,e=0;e<r;e++)if(0===t[e][e])return!0;return!1}solve(t){t=_.checkMatrix(t);var r=this.LU;if(r.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");var e,n,i,o=t.columns,s=t.subMatrixRow(this.pivotVector,0,o-1),a=r.columns;for(i=0;i<a;i++)for(e=i+1;e<a;e++)for(n=0;n<o;n++)s[e][n]-=s[i][n]*r[e][i];for(i=a-1;i>=0;i--){for(n=0;n<o;n++)s[i][n]/=r[i][i];for(e=0;e<i;e++)for(n=0;n<o;n++)s[e][n]-=s[i][n]*r[e][i]}return s}get determinant(){var t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");for(var r=this.pivotSign,e=t.columns,n=0;n<e;n++)r*=t[n][n];return r}get lowerTriangularMatrix(){for(var t=this.LU,r=t.rows,e=t.columns,n=new _(r,e),i=0;i<r;i++)for(var o=0;o<e;o++)n[i][o]=i>o?t[i][o]:i===o?1:0;return n}get upperTriangularMatrix(){for(var t=this.LU,r=t.rows,e=t.columns,n=new _(r,e),i=0;i<r;i++)for(var o=0;o<e;o++)n[i][o]=i<=o?t[i][o]:0;return n}get pivotPermutationVector(){return this.pivotVector.slice()}}function u(t,r){var e=0;return Math.abs(t)>Math.abs(r)?(e=r/t,Math.abs(t)*Math.sqrt(1+e*e)):0!==r?(e=t/r,Math.abs(r)*Math.sqrt(1+e*e)):0}function l(t,r,e){for(var n=new Array(t),i=0;i<t;i++){n[i]=new Array(r);for(var o=0;o<r;o++)n[i][o]=e}return n}class c{constructor(t,r={}){var e=(t=j.checkMatrix(t)).rows,n=t.columns;const{computeLeftSingularVectors:i=!0,computeRightSingularVectors:o=!0,autoTranspose:s=!1}=r;var a,h=Boolean(i),c=Boolean(o),f=!1;if(e<n)if(s){e=(a=t.transpose()).rows,n=a.columns,f=!0;var m=h;h=c,c=m}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();var g=Math.min(e,n),p=Math.min(e+1,n),v=new Array(p),d=l(e,g,0),w=l(n,n,0),y=new Array(n),b=new Array(e),M=new Array(p);for(let t=0;t<p;t++)M[t]=t;var x=Math.min(e-1,n),S=Math.max(0,Math.min(n-2,e)),E=Math.max(x,S);for(let t=0;t<E;t++){if(t<x){v[t]=0;for(let r=t;r<e;r++)v[t]=u(v[t],a[r][t]);if(0!==v[t]){a[t][t]<0&&(v[t]=-v[t]);for(let r=t;r<e;r++)a[r][t]/=v[t];a[t][t]+=1}v[t]=-v[t]}for(let r=t+1;r<n;r++){if(t<x&&0!==v[t]){let n=0;for(let i=t;i<e;i++)n+=a[i][t]*a[i][r];n=-n/a[t][t];for(let i=t;i<e;i++)a[i][r]+=n*a[i][t]}y[r]=a[t][r]}if(h&&t<x)for(let r=t;r<e;r++)d[r][t]=a[r][t];if(t<S){y[t]=0;for(let r=t+1;r<n;r++)y[t]=u(y[t],y[r]);if(0!==y[t]){y[t+1]<0&&(y[t]=0-y[t]);for(let r=t+1;r<n;r++)y[r]/=y[t];y[t+1]+=1}if(y[t]=-y[t],t+1<e&&0!==y[t]){for(let r=t+1;r<e;r++)b[r]=0;for(let r=t+1;r<e;r++)for(let e=t+1;e<n;e++)b[r]+=y[e]*a[r][e];for(let r=t+1;r<n;r++){let n=-y[r]/y[t+1];for(let i=t+1;i<e;i++)a[i][r]+=n*b[i]}}if(c)for(let r=t+1;r<n;r++)w[r][t]=y[r]}}let R=Math.min(n,e+1);if(x<n&&(v[x]=a[x][x]),e<R&&(v[R-1]=0),S+1<R&&(y[S]=a[S][R-1]),y[R-1]=0,h){for(let t=x;t<g;t++){for(let r=0;r<e;r++)d[r][t]=0;d[t][t]=1}for(let t=x-1;t>=0;t--)if(0!==v[t]){for(let r=t+1;r<g;r++){let n=0;for(let i=t;i<e;i++)n+=d[i][t]*d[i][r];n=-n/d[t][t];for(let i=t;i<e;i++)d[i][r]+=n*d[i][t]}for(let r=t;r<e;r++)d[r][t]=-d[r][t];d[t][t]=1+d[t][t];for(let r=0;r<t-1;r++)d[r][t]=0}else{for(let r=0;r<e;r++)d[r][t]=0;d[t][t]=1}}if(c)for(let t=n-1;t>=0;t--){if(t<S&&0!==y[t])for(let r=t+1;r<n;r++){let e=0;for(let i=t+1;i<n;i++)e+=w[i][t]*w[i][r];e=-e/w[t+1][t];for(let i=t+1;i<n;i++)w[i][r]+=e*w[i][t]}for(let r=0;r<n;r++)w[r][t]=0;w[t][t]=1}for(var k=R-1,z=Number.EPSILON;R>0;){let t,r;for(t=R-2;t>=-1&&-1!==t;t--){const r=Number.MIN_VALUE+z*Math.abs(v[t]+Math.abs(v[t+1]));if(Math.abs(y[t])<=r||Number.isNaN(y[t])){y[t]=0;break}}if(t===R-2)r=4;else{let e;for(e=R-1;e>=t&&e!==t;e--){let r=(e!==R?Math.abs(y[e]):0)+(e!==t+1?Math.abs(y[e-1]):0);if(Math.abs(v[e])<=z*r){v[e]=0;break}}e===t?r=3:e===R-1?r=1:(r=2,t=e)}switch(t++,r){case 1:{let r=y[R-2];y[R-2]=0;for(let e=R-2;e>=t;e--){let i=u(v[e],r),o=v[e]/i,s=r/i;if(v[e]=i,e!==t&&(r=-s*y[e-1],y[e-1]=o*y[e-1]),c)for(let t=0;t<n;t++)i=o*w[t][e]+s*w[t][R-1],w[t][R-1]=-s*w[t][e]+o*w[t][R-1],w[t][e]=i}break}case 2:{let r=y[t-1];y[t-1]=0;for(let n=t;n<R;n++){let i=u(v[n],r),o=v[n]/i,s=r/i;if(v[n]=i,r=-s*y[n],y[n]=o*y[n],h)for(let r=0;r<e;r++)i=o*d[r][n]+s*d[r][t-1],d[r][t-1]=-s*d[r][n]+o*d[r][t-1],d[r][n]=i}break}case 3:{const r=Math.max(Math.abs(v[R-1]),Math.abs(v[R-2]),Math.abs(y[R-2]),Math.abs(v[t]),Math.abs(y[t])),i=v[R-1]/r,o=v[R-2]/r,s=y[R-2]/r,a=v[t]/r,l=y[t]/r,f=((o+i)*(o-i)+s*s)/2,m=i*s*(i*s);let g=0;0===f&&0===m||(g=m/(f+(g=f<0?0-Math.sqrt(f*f+m):Math.sqrt(f*f+m))));let p=(a+i)*(a-i)+g,b=a*l;for(let r=t;r<R-1;r++){let i=u(p,b);0===i&&(i=Number.MIN_VALUE);let o=p/i,s=b/i;if(r!==t&&(y[r-1]=i),p=o*v[r]+s*y[r],y[r]=o*y[r]-s*v[r],b=s*v[r+1],v[r+1]=o*v[r+1],c)for(let t=0;t<n;t++)i=o*w[t][r]+s*w[t][r+1],w[t][r+1]=-s*w[t][r]+o*w[t][r+1],w[t][r]=i;if(0===(i=u(p,b))&&(i=Number.MIN_VALUE),o=p/i,s=b/i,v[r]=i,p=o*y[r]+s*v[r+1],v[r+1]=-s*y[r]+o*v[r+1],b=s*y[r+1],y[r+1]=o*y[r+1],h&&r<e-1)for(let t=0;t<e;t++)i=o*d[t][r]+s*d[t][r+1],d[t][r+1]=-s*d[t][r]+o*d[t][r+1],d[t][r]=i}y[R-2]=p,1;break}case 4:if(v[t]<=0&&(v[t]=v[t]<0?-v[t]:0,c))for(let r=0;r<=k;r++)w[r][t]=-w[r][t];for(;t<k&&!(v[t]>=v[t+1]);){let r=v[t];if(v[t]=v[t+1],v[t+1]=r,c&&t<n-1)for(let e=0;e<n;e++)r=w[e][t+1],w[e][t+1]=w[e][t],w[e][t]=r;if(h&&t<e-1)for(let n=0;n<e;n++)r=d[n][t+1],d[n][t+1]=d[n][t],d[n][t]=r;t++}0,R--}}if(f){var N=w;w=d,d=N}this.m=e,this.n=n,this.s=v,this.U=d,this.V=w}solve(t){var r=t,e=this.threshold,n=this.s.length,i=_.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=e?i[t][t]=0:i[t][t]=1/this.s[t];var o=this.U,s=this.rightSingularVectors,a=s.mmul(i),h=s.rows,u=o.length,l=_.zeros(h,u);for(let t=0;t<h;t++)for(let r=0;r<u;r++){let e=0;for(let i=0;i<n;i++)e+=a[t][i]*o[r][i];l[t][r]=e}return l.mmul(r)}solveForDiagonal(t){return this.solve(_.diag(t))}inverse(){var t=this.V,r=this.threshold,e=t.length,n=t[0].length,i=new _(e,this.s.length);for(let o=0;o<e;o++)for(let e=0;e<n;e++)Math.abs(this.s[e])>r?i[o][e]=t[o][e]/this.s[e]:i[o][e]=0;var o=this.U,s=o.length,a=o[0].length,h=new _(e,s);for(let t=0;t<e;t++)for(let r=0;r<s;r++){let e=0;for(let n=0;n<a;n++)e+=i[t][n]*o[r][n];h[t][r]=e}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(){for(var t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,r=0,e=this.s,n=0,i=e.length;n<i;n++)e[n]>t&&r++;return r}get diagonal(){return this.s}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return _.isMatrix(this.U)||(this.U=new _(this.U)),this.U}get rightSingularVectors(){return _.isMatrix(this.V)||(this.V=new _(this.V)),this.V}get diagonalMatrix(){return _.diag(this.s)}}function f(t,r,e){var n=e?t.rows:t.rows-1;if(r<0||r>n)throw new RangeError("Row index out of range")}function m(t,r,e){var n=e?t.columns:t.columns-1;if(r<0||r>n)throw new RangeError("Column index out of range")}function g(t,r){if(r.to1DArray&&(r=r.to1DArray()),r.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return r}function p(t,r){if(r.to1DArray&&(r=r.to1DArray()),r.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return r}function v(t,r,e){return{row:d(t,r),column:w(t,e)}}function d(t,r){if("object"!=typeof r)throw new TypeError("unexpected type for row indices");if(r.some(r=>r<0||r>=t.rows))throw new RangeError("row indices are out of range");return Array.isArray(r)||(r=Array.from(r)),r}function w(t,r){if("object"!=typeof r)throw new TypeError("unexpected type for column indices");if(r.some(r=>r<0||r>=t.columns))throw new RangeError("column indices are out of range");return Array.isArray(r)||(r=Array.from(r)),r}function y(t,r,e,n,i){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(b("startRow",r),b("endRow",e),b("startColumn",n),b("endColumn",i),r>e||n>i||r<0||r>=t.rows||e<0||e>=t.rows||n<0||n>=t.columns||i<0||i>=t.columns)throw new RangeError("Submatrix indices are out of range")}function b(t,r){if("number"!=typeof r)throw new TypeError(`${t} must be a number`)}class M extends(C()){constructor(t,r,e){super(),this.matrix=t,this.rows=r,this.columns=e}static get[Symbol.species](){return _}}class x extends M{constructor(t){super(t,t.columns,t.rows)}set(t,r,e){return this.matrix.set(r,t,e),this}get(t,r){return this.matrix.get(r,t)}}class S extends M{constructor(t,r){super(t,1,t.columns),this.row=r}set(t,r,e){return this.matrix.set(this.row,r,e),this}get(t,r){return this.matrix.get(this.row,r)}}class E extends M{constructor(t,r,e,n,i){y(t,r,e,n,i),super(t,e-r+1,i-n+1),this.startRow=r,this.startColumn=n}set(t,r,e){return this.matrix.set(this.startRow+t,this.startColumn+r,e),this}get(t,r){return this.matrix.get(this.startRow+t,this.startColumn+r)}}class R extends M{constructor(t,r,e){var n=v(t,r,e);super(t,n.row.length,n.column.length),this.rowIndices=n.row,this.columnIndices=n.column}set(t,r,e){return this.matrix.set(this.rowIndices[t],this.columnIndices[r],e),this}get(t,r){return this.matrix.get(this.rowIndices[t],this.columnIndices[r])}}class k extends M{constructor(t,r){super(t,(r=d(t,r)).length,t.columns),this.rowIndices=r}set(t,r,e){return this.matrix.set(this.rowIndices[t],r,e),this}get(t,r){return this.matrix.get(this.rowIndices[t],r)}}class z extends M{constructor(t,r){r=w(t,r),super(t,t.rows,r.length),this.columnIndices=r}set(t,r,e){return this.matrix.set(t,this.columnIndices[r],e),this}get(t,r){return this.matrix.get(t,this.columnIndices[r])}}class N extends M{constructor(t,r){super(t,t.rows,1),this.column=r}set(t,r,e){return this.matrix.set(t,this.column,e),this}get(t){return this.matrix.get(t,this.column)}}class A extends M{constructor(t){super(t,t.rows,t.columns)}set(t,r,e){return this.matrix.set(this.rows-t-1,r,e),this}get(t,r){return this.matrix.get(this.rows-t-1,r)}}class V extends M{constructor(t){super(t,t.rows,t.columns)}set(t,r,e){return this.matrix.set(t,this.columns-r-1,e),this}get(t,r){return this.matrix.get(t,this.columns-r-1)}}function C(t){void 0===t&&(t=Object);class r extends t{static get[Symbol.species](){return this}static from1DArray(t,r,e){if(t*r!==e.length)throw new RangeError("Data length does not match given dimensions");for(var n=new this(t,r),i=0;i<t;i++)for(var o=0;o<r;o++)n.set(i,o,e[i*r+o]);return n}static rowVector(t){for(var r=new this(1,t.length),e=0;e<t.length;e++)r.set(0,e,t[e]);return r}static columnVector(t){for(var r=new this(t.length,1),e=0;e<t.length;e++)r.set(e,0,t[e]);return r}static empty(t,r){return new this(t,r)}static zeros(t,r){return this.empty(t,r).fill(0)}static ones(t,r){return this.empty(t,r).fill(1)}static rand(t,r,e){void 0===e&&(e=Math.random);for(var n=this.empty(t,r),i=0;i<t;i++)for(var o=0;o<r;o++)n.set(i,o,e());return n}static randInt(t,r,e,n){void 0===e&&(e=1e3),void 0===n&&(n=Math.random);for(var i=this.empty(t,r),o=0;o<t;o++)for(var s=0;s<r;s++){var a=Math.floor(n()*e);i.set(o,s,a)}return i}static eye(t,r,e){void 0===r&&(r=t),void 0===e&&(e=1);for(var n=Math.min(t,r),i=this.zeros(t,r),o=0;o<n;o++)i.set(o,o,e);return i}static diag(t,r,e){var n=t.length;void 0===r&&(r=n),void 0===e&&(e=r);for(var i=Math.min(n,r,e),o=this.zeros(r,e),s=0;s<i;s++)o.set(s,s,t[s]);return o}static min(t,r){t=this.checkMatrix(t),r=this.checkMatrix(r);for(var e=t.rows,n=t.columns,i=new this(e,n),o=0;o<e;o++)for(var s=0;s<n;s++)i.set(o,s,Math.min(t.get(o,s),r.get(o,s)));return i}static max(t,r){t=this.checkMatrix(t),r=this.checkMatrix(r);for(var e=t.rows,n=t.columns,i=new this(e,n),o=0;o<e;o++)for(var s=0;s<n;s++)i.set(o,s,Math.max(t.get(o,s),r.get(o,s)));return i}static checkMatrix(t){return r.isMatrix(t)?t:new this(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(var r=this.rows,e=this.columns,n=0;n<r;n++)for(var i=0;i<e;i++)t.call(this,n,i);return this}to1DArray(){for(var t=new Array(this.size),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t[r*this.columns+e]=this.get(r,e);return t}to2DArray(){for(var t=new Array(this.rows),r=0;r<this.rows;r++){t[r]=new Array(this.columns);for(var e=0;e<this.columns;e++)t[r][e]=this.get(r,e)}return t}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isSymmetric(){if(this.isSquare()){for(var t=0;t<this.rows;t++)for(var r=0;r<=t;r++)if(this.get(t,r)!==this.get(r,t))return!1;return!0}return!1}set(t,r,e){throw new Error("set method is unimplemented")}get(t,r){throw new Error("get method is unimplemented")}repeat(t,r){t=t||1,r=r||1;for(var e=new this.constructor[Symbol.species](this.rows*t,this.columns*r),n=0;n<t;n++)for(var i=0;i<r;i++)e.setSubMatrix(this,this.rows*n,this.columns*i);return e}fill(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,t);return this}neg(){return this.mulS(-1)}getRow(t){f(this,t);for(var r=new Array(this.columns),e=0;e<this.columns;e++)r[e]=this.get(t,e);return r}getRowVector(t){return this.constructor.rowVector(this.getRow(t))}setRow(t,r){f(this,t),r=g(this,r);for(var e=0;e<this.columns;e++)this.set(t,e,r[e]);return this}swapRows(t,r){f(this,t),f(this,r);for(var e=0;e<this.columns;e++){var n=this.get(t,e);this.set(t,e,this.get(r,e)),this.set(r,e,n)}return this}getColumn(t){m(this,t);for(var r=new Array(this.rows),e=0;e<this.rows;e++)r[e]=this.get(e,t);return r}getColumnVector(t){return this.constructor.columnVector(this.getColumn(t))}setColumn(t,r){m(this,t),r=p(this,r);for(var e=0;e<this.rows;e++)this.set(e,t,r[e]);return this}swapColumns(t,r){m(this,t),m(this,r);for(var e=0;e<this.rows;e++){var n=this.get(e,t);this.set(e,t,this.get(e,r)),this.set(e,r,n)}return this}addRowVector(t){t=g(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t[e]);return this}subRowVector(t){t=g(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t[e]);return this}mulRowVector(t){t=g(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t[e]);return this}divRowVector(t){t=g(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t[e]);return this}addColumnVector(t){t=p(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t[r]);return this}subColumnVector(t){t=p(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t[r]);return this}mulColumnVector(t){t=p(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t[r]);return this}divColumnVector(t){t=p(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t[r]);return this}mulRow(t,r){f(this,t);for(var e=0;e<this.columns;e++)this.set(t,e,this.get(t,e)*r);return this}mulColumn(t,r){m(this,t);for(var e=0;e<this.rows;e++)this.set(e,t,this.get(e,t)*r);return this}max(){for(var t=this.get(0,0),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.get(r,e)>t&&(t=this.get(r,e));return t}maxIndex(){for(var t=this.get(0,0),r=[0,0],e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.get(e,n)>t&&(t=this.get(e,n),r[0]=e,r[1]=n);return r}min(){for(var t=this.get(0,0),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.get(r,e)<t&&(t=this.get(r,e));return t}minIndex(){for(var t=this.get(0,0),r=[0,0],e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.get(e,n)<t&&(t=this.get(e,n),r[0]=e,r[1]=n);return r}maxRow(t){f(this,t);for(var r=this.get(t,0),e=1;e<this.columns;e++)this.get(t,e)>r&&(r=this.get(t,e));return r}maxRowIndex(t){f(this,t);for(var r=this.get(t,0),e=[t,0],n=1;n<this.columns;n++)this.get(t,n)>r&&(r=this.get(t,n),e[1]=n);return e}minRow(t){f(this,t);for(var r=this.get(t,0),e=1;e<this.columns;e++)this.get(t,e)<r&&(r=this.get(t,e));return r}minRowIndex(t){f(this,t);for(var r=this.get(t,0),e=[t,0],n=1;n<this.columns;n++)this.get(t,n)<r&&(r=this.get(t,n),e[1]=n);return e}maxColumn(t){m(this,t);for(var r=this.get(0,t),e=1;e<this.rows;e++)this.get(e,t)>r&&(r=this.get(e,t));return r}maxColumnIndex(t){m(this,t);for(var r=this.get(0,t),e=[0,t],n=1;n<this.rows;n++)this.get(n,t)>r&&(r=this.get(n,t),e[0]=n);return e}minColumn(t){m(this,t);for(var r=this.get(0,t),e=1;e<this.rows;e++)this.get(e,t)<r&&(r=this.get(e,t));return r}minColumnIndex(t){m(this,t);for(var r=this.get(0,t),e=[0,t],n=1;n<this.rows;n++)this.get(n,t)<r&&(r=this.get(n,t),e[0]=n);return e}diag(){for(var t=Math.min(this.rows,this.columns),r=new Array(t),e=0;e<t;e++)r[e]=this.get(e,e);return r}sum(t){switch(t){case"row":return function(t){for(var r=_.zeros(t.rows,1),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r.set(e,0,r.get(e,0)+t.get(e,n));return r}(this);case"column":return function(t){for(var r=_.zeros(1,t.columns),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r.set(0,n,r.get(0,n)+t.get(e,n));return r}(this);default:return function(t){for(var r=0,e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)r+=t.get(e,n);return r}(this)}}mean(){return this.sum()/this.size}prod(){for(var t=1,r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t*=this.get(r,e);return t}norm(t="frobenius"){var r=0;if("max"===t)return this.max();if("frobenius"===t){for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)r+=this.get(e,n)*this.get(e,n);return Math.sqrt(r)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){for(var t=0,r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t+=this.get(r,e),this.set(r,e,t);return this}dot(t){r.isMatrix(t)&&(t=t.to1DArray());var e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");for(var n=0,i=0;i<e.length;i++)n+=e[i]*t[i];return n}mmul(t){t=this.constructor.checkMatrix(t),this.columns!==t.rows&&console.warn("Number of columns of left matrix are not equal to number of rows of right matrix.");for(var r=this.rows,e=this.columns,n=t.columns,i=new this.constructor[Symbol.species](r,n),o=new Array(e),s=0;s<n;s++){for(var a=0;a<e;a++)o[a]=t.get(a,s);for(var h=0;h<r;h++){var u=0;for(a=0;a<e;a++)u+=this.get(h,a)*o[a];i.set(h,s,u)}}return i}strassen2x2(t){var r=new this.constructor[Symbol.species](2,2);const e=this.get(0,0),n=t.get(0,0),i=this.get(0,1),o=t.get(0,1),s=this.get(1,0),a=t.get(1,0),h=this.get(1,1),u=t.get(1,1),l=(e+h)*(n+u),c=(s+h)*n,f=e*(o-u),m=h*(a-n),g=(e+i)*u,p=l+m-g+(i-h)*(a+u),v=f+g,d=c+m,w=l-c+f+(s-e)*(n+o);return r.set(0,0,p),r.set(0,1,v),r.set(1,0,d),r.set(1,1,w),r}strassen3x3(t){var r=new this.constructor[Symbol.species](3,3);const e=this.get(0,0),n=this.get(0,1),i=this.get(0,2),o=this.get(1,0),s=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),m=t.get(0,2),g=t.get(1,0),p=t.get(1,1),v=t.get(1,2),d=t.get(2,0),w=t.get(2,1),y=t.get(2,2),b=(e-o)*(-f+p),M=(-e+o+s)*(c-f+p),x=(o+s)*(-c+f),S=e*c,E=(-e+h+u)*(c-m+v),R=(-e+h)*(m-v),k=(h+u)*(-c+m),z=(-i+u+l)*(p+d-w),N=(i-l)*(p-w),A=i*d,V=(u+l)*(-d+w),C=(-i+s+a)*(v+d-y),_=(i-a)*(v-y),P=(s+a)*(-d+y),j=S+A+n*g,I=(e+n+i-o-s-u-l)*p+M+x+S+z+A+V,O=S+E+k+(e+n+i-s-a-h-u)*v+A+C+P,D=b+s*(-c+f+g-p-v-d+y)+M+S+A+C+_,L=b+M+x+S+a*w,T=A+C+_+P+o*m,F=S+E+R+u*(-c+m+g-p-v-d+w)+z+N+A,q=z+N+A+V+h*f,U=S+E+R+k+l*y;return r.set(0,0,j),r.set(0,1,I),r.set(0,2,O),r.set(1,0,D),r.set(1,1,L),r.set(1,2,T),r.set(2,0,F),r.set(2,1,q),r.set(2,2,U),r}mmulStrassen(t){var e=this.clone(),n=e.rows,i=e.columns,o=t.rows,s=t.columns;function a(t,e,n){var i=t.rows,o=t.columns;if(i===e&&o===n)return t;var s=r.zeros(e,n);return s=s.setSubMatrix(t,0,0)}i!==o&&console.warn(`Multiplying ${n} x ${i} and ${o} x ${s} matrix: dimensions do not match.`);var h=Math.max(n,o),u=Math.max(i,s);return function t(e,n,i,o){if(i<=512||o<=512)return e.mmul(n);i%2==1&&o%2==1?(e=a(e,i+1,o+1),n=a(n,i+1,o+1)):i%2==1?(e=a(e,i+1,o),n=a(n,i+1,o)):o%2==1&&(e=a(e,i,o+1),n=a(n,i,o+1));var s=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),u=e.subMatrix(0,s-1,0,h-1),l=n.subMatrix(0,s-1,0,h-1),c=e.subMatrix(0,s-1,h,e.columns-1),f=n.subMatrix(0,s-1,h,n.columns-1),m=e.subMatrix(s,e.rows-1,0,h-1),g=n.subMatrix(s,n.rows-1,0,h-1),p=e.subMatrix(s,e.rows-1,h,e.columns-1),v=n.subMatrix(s,n.rows-1,h,n.columns-1),d=t(r.add(u,p),r.add(l,v),s,h),w=t(r.add(m,p),l,s,h),y=t(u,r.sub(f,v),s,h),b=t(p,r.sub(g,l),s,h),M=t(r.add(u,c),v,s,h),x=t(r.sub(m,u),r.add(l,f),s,h),S=t(r.sub(c,p),r.add(g,v),s,h),E=r.add(d,b);E.sub(M),E.add(S);var R=r.add(y,M),k=r.add(w,b),z=r.sub(d,w);z.add(y),z.add(x);var N=r.zeros(2*E.rows,2*E.columns);return(N=(N=(N=(N=N.setSubMatrix(E,0,0)).setSubMatrix(R,E.rows,0)).setSubMatrix(k,0,E.columns)).setSubMatrix(z,E.rows,E.columns)).subMatrix(0,i-1,0,o-1)}(e=a(e,h,u),t=a(t,h,u),h,u)}scaleRows(t,r){if((t=void 0===t?0:t)>=(r=void 0===r?1:r))throw new RangeError("min should be strictly smaller than max");for(var e=this.constructor.empty(this.rows,this.columns),n=0;n<this.rows;n++){var i=a(this.getRow(n),{min:t,max:r});e.setRow(n,i)}return e}scaleColumns(t,r){if((t=void 0===t?0:t)>=(r=void 0===r?1:r))throw new RangeError("min should be strictly smaller than max");for(var e=this.constructor.empty(this.rows,this.columns),n=0;n<this.columns;n++){var i=a(this.getColumn(n),{min:t,max:r});e.setColumn(n,i)}return e}kroneckerProduct(t){t=this.constructor.checkMatrix(t);for(var r=this.rows,e=this.columns,n=t.rows,i=t.columns,o=new this.constructor[Symbol.species](r*n,e*i),s=0;s<r;s++)for(var a=0;a<e;a++)for(var h=0;h<n;h++)for(var u=0;u<i;u++)o[n*s+h][i*a+u]=this.get(s,a)*t.get(h,u);return o}transpose(){for(var t=new this.constructor[Symbol.species](this.columns,this.rows),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.set(e,r,this.get(r,e));return t}sortRows(t){void 0===t&&(t=e);for(var r=0;r<this.rows;r++)this.setRow(r,this.getRow(r).sort(t));return this}sortColumns(t){void 0===t&&(t=e);for(var r=0;r<this.columns;r++)this.setColumn(r,this.getColumn(r).sort(t));return this}subMatrix(t,r,e,n){y(this,t,r,e,n);for(var i=new this.constructor[Symbol.species](r-t+1,n-e+1),o=t;o<=r;o++)for(var s=e;s<=n;s++)i[o-t][s-e]=this.get(o,s);return i}subMatrixRow(t,r,e){if(void 0===r&&(r=0),void 0===e&&(e=this.columns-1),r>e||r<0||r>=this.columns||e<0||e>=this.columns)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](t.length,e-r+1),i=0;i<t.length;i++)for(var o=r;o<=e;o++){if(t[i]<0||t[i]>=this.rows)throw new RangeError(`Row index out of range: ${t[i]}`);n.set(i,o-r,this.get(t[i],o))}return n}subMatrixColumn(t,r,e){if(void 0===r&&(r=0),void 0===e&&(e=this.rows-1),r>e||r<0||r>=this.rows||e<0||e>=this.rows)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](e-r+1,t.length),i=0;i<t.length;i++)for(var o=r;o<=e;o++){if(t[i]<0||t[i]>=this.columns)throw new RangeError(`Column index out of range: ${t[i]}`);n.set(o-r,i,this.get(o,t[i]))}return n}setSubMatrix(t,r,e){y(this,r,r+(t=this.constructor.checkMatrix(t)).rows-1,e,e+t.columns-1);for(var n=0;n<t.rows;n++)for(var i=0;i<t.columns;i++)this[r+n][e+i]=t.get(n,i);return this}selection(t,r){for(var e=v(this,t,r),n=new this.constructor[Symbol.species](t.length,r.length),i=0;i<e.row.length;i++)for(var o=e.row[i],s=0;s<e.column.length;s++){var a=e.column[s];n[i][s]=this.get(o,a)}return n}trace(){for(var t=Math.min(this.rows,this.columns),r=0,e=0;e<t;e++)r+=this.get(e,e);return r}transposeView(){return new x(this)}rowView(t){return f(this,t),new S(this,t)}columnView(t){return m(this,t),new N(this,t)}flipRowView(){return new A(this)}flipColumnView(){return new V(this)}subMatrixView(t,r,e,n){return new E(this,t,r,e,n)}selectionView(t,r){return new R(this,t,r)}rowSelectionView(t){return new k(this,t)}columnSelectionView(t){return new z(this,t)}det(){var t,r,e,n,i,o;if(this.isSquare())return 2===this.columns?(t=this.get(0,0),r=this.get(0,1),e=this.get(1,0),t*this.get(1,1)-r*e):3===this.columns?(n=this.selectionView([1,2],[1,2]),i=this.selectionView([1,2],[0,2]),o=this.selectionView([1,2],[0,1]),t=this.get(0,0),r=this.get(0,1),e=this.get(0,2),t*n.det()-r*i.det()+e*o.det()):new h(this).determinant;throw Error("Determinant can only be calculated for a square matrix.")}pseudoInverse(t){void 0===t&&(t=Number.EPSILON);for(var r=new c(this,{autoTranspose:!0}),e=r.leftSingularVectors,n=r.rightSingularVectors,i=r.diagonal,o=0;o<i.length;o++)Math.abs(i[o])>t?i[o]=1/i[o]:i[o]=0;return i=this.constructor[Symbol.species].diag(i),n.mmul(i.mmul(e.transposeView()))}clone(){for(var t=new this.constructor[Symbol.species](this.rows,this.columns),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.set(r,e,this.get(r,e));return t}}function e(t,r){return t-r}r.prototype.klass="Matrix",r.random=r.rand,r.diagonal=r.diag,r.prototype.diagonal=r.prototype.diag,r.identity=r.eye,r.prototype.negate=r.prototype.neg,r.prototype.tensorProduct=r.prototype.kroneckerProduct,r.prototype.determinant=r.prototype.det;var n,i="\n(function %name%(matrix, %args%) {\n var newMatrix = new this[Symbol.species](matrix);\n return newMatrix.%name%(%args%);\n})\n",o=eval;for(var s of[["+","add"],["-","sub","subtract"],["*","mul","multiply"],["/","div","divide"],["%","mod","modulus"],["&","and"],["|","or"],["^","xor"],["<<","leftShift"],[">>","signPropagatingRightShift"],[">>>","rightShift","zeroFillRightShift"]]){var u=o($("\n(function %name%(value) {\n if (typeof value === 'number') return this.%name%S(value);\n return this.%name%M(value);\n})\n",{name:s[1],op:s[0]})),l=o($("\n(function %name%S(value) {\n for (var i = 0; i < this.rows; i++) {\n for (var j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) %op% value);\n }\n }\n return this;\n})\n",{name:`${s[1]}S`,op:s[0]})),d=o($("\n(function %name%M(matrix) {\n matrix = this.constructor.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (var i = 0; i < this.rows; i++) {\n for (var j = 0; j < this.columns; j++) {\n this.set(i, j, this.get(i, j) %op% matrix.get(i, j));\n }\n }\n return this;\n})\n",{name:`${s[1]}M`,op:s[0]})),w=o($("\n(function %name%(matrix, value) {\n var newMatrix = new this[Symbol.species](matrix);\n return newMatrix.%name%(value);\n})\n",{name:s[1]}));for(n=1;n<s.length;n++)r.prototype[s[n]]=u,r.prototype[`${s[n]}S`]=l,r.prototype[`${s[n]}M`]=d,r[s[n]]=w}var b=[["~","not"]];for(var M of(["abs","acos","acosh","asin","asinh","atan","atanh","cbrt","ceil","clz32","cos","cosh","exp","expm1","floor","fround","log","log1p","log10","log2","round","sign","sin","sinh","sqrt","tan","tanh","trunc"].forEach(function(t){b.push([`Math.${t}`,t])}),b)){var C=o($("\n(function %name%() {\n for (var i = 0; i < this.rows; i++) {\n for (var j = 0; j < this.columns; j++) {\n this.set(i, j, %method%(this.get(i, j)));\n }\n }\n return this;\n})\n",{name:M[1],method:M[0]})),P=o($("\n(function %name%(matrix) {\n var newMatrix = new this[Symbol.species](matrix);\n return newMatrix.%name%();\n})\n",{name:M[1]}));for(n=1;n<M.length;n++)r.prototype[M[n]]=C,r[M[n]]=P}for(var j of[["Math.pow",1,"pow"]]){var I="arg0";for(n=1;n<j[1];n++)I+=`, arg${n}`;if(1!==j[1]){var O=o($("\n(function %name%(%args%) {\n for (var i = 0; i < this.rows; i++) {\n for (var j = 0; j < this.columns; j++) {\n this.set(i, j, %method%(this.get(i, j), %args%));\n }\n }\n return this;\n})\n",{name:j[2],method:j[0],args:I})),D=o($(i,{name:j[2],args:I}));for(n=2;n<j.length;n++)r.prototype[j[n]]=O,r[j[n]]=D}else{var L={name:j[2],args:I,method:j[0]},T=o($("\n(function %name%(value) {\n if (typeof value === 'number') return this.%name%S(value);\n return this.%name%M(value);\n})\n",L)),F=o($("\n(function %name%S(value) {\n for (var i = 0; i < this.rows; i++) {\n for (var j = 0; j < this.columns; j++) {\n this.set(i, j, %method%(this.get(i, j), value));\n }\n }\n return this;\n})\n",L)),q=o($("\n(function %name%M(matrix) {\n matrix = this.constructor.checkMatrix(matrix);\n if (this.rows !== matrix.rows ||\n this.columns !== matrix.columns) {\n throw new RangeError('Matrices dimensions must be equal');\n }\n for (var i = 0; i < this.rows; i++) {\n for (var j = 0; j < this.columns; j++) {\n this.set(i, j, %method%(this.get(i, j), matrix.get(i, j)));\n }\n }\n return this;\n})\n",L)),U=o($("\n(function %name%(matrix, %args%) {\n var newMatrix = new this[Symbol.species](matrix);\n return newMatrix.%name%(%args%);\n})\n",L));for(n=2;n<j.length;n++)r.prototype[j[n]]=T,r.prototype[`${j[n]}M`]=q,r.prototype[`${j[n]}S`]=F,r[j[n]]=U}}function $(t,r){for(var e in r)t=t.replace(new RegExp(`%${e}%`,"g"),r[e]);return t}return r}class _ extends(C(Array)){constructor(t,r){var e;if(1===arguments.length&&"number"==typeof t)return new Array(t);if(_.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>0){if(super(t),!(Number.isInteger(r)&&r>0))throw new TypeError("nColumns must be a positive integer");for(e=0;e<t;e++)this[e]=new Array(r)}else{if(!Array.isArray(t))throw new TypeError("First argument must be a positive number or an array");{const n=t;if(t=n.length,"number"!=typeof(r=n[0].length)||0===r)throw new TypeError("Data must be a 2D array with at least one element");for(super(t),e=0;e<t;e++){if(n[e].length!==r)throw new RangeError("Inconsistent array dimensions");this[e]=[].concat(n[e])}}}return this.rows=t,this.columns=r,this}set(t,r,e){return this[t][r]=e,this}get(t,r){return this[t][r]}removeRow(t){if(f(this,t),1===this.rows)throw new RangeError("A matrix cannot have less than one row");return this.splice(t,1),this.rows-=1,this}addRow(t,r){return void 0===r&&(r=t,t=this.rows),f(this,t,!0),r=g(this,r),this.splice(t,0,r),this.rows+=1,this}removeColumn(t){if(m(this,t),1===this.columns)throw new RangeError("A matrix cannot have less than one column");for(var r=0;r<this.rows;r++)this[r].splice(t,1);return this.columns-=1,this}addColumn(t,r){void 0===r&&(r=t,t=this.columns),m(this,t,!0),r=p(this,r);for(var e=0;e<this.rows;e++)this[e].splice(t,0,r[e]);return this.columns+=1,this}}class P extends(C()){constructor(t,r={}){const{rows:e=1}=r;if(t.length%e!=0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=e,this.columns=t.length/e,this.data=t}set(t,r,e){var n=this._calculateIndex(t,r);return this.data[n]=e,this}get(t,r){var e=this._calculateIndex(t,r);return this.data[e]}_calculateIndex(t,r){return t*this.columns+r}static get[Symbol.species](){return _}}class j extends(C()){constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,r,e){return this.data[t][r]=e,this}get(t,r){return this.data[t][r]}static get[Symbol.species](){return _}}function I(t,r){if(Array.isArray(t))return t[0]&&Array.isArray(t[0])?new j(t):new P(t,r);throw new Error("the argument is not an array")}class O{constructor(t){var r,e,n,i,o=(t=j.checkMatrix(t)).clone(),s=t.rows,a=t.columns,h=new Array(a);for(n=0;n<a;n++){var l=0;for(r=n;r<s;r++)l=u(l,o.get(r,n));if(0!==l){for(o.get(n,n)<0&&(l=-l),r=n;r<s;r++)o.set(r,n,o.get(r,n)/l);for(o.set(n,n,o.get(n,n)+1),e=n+1;e<a;e++){for(i=0,r=n;r<s;r++)i+=o.get(r,n)*o.get(r,e);for(i=-i/o.get(n,n),r=n;r<s;r++)o.set(r,e,o.get(r,e)+i*o.get(r,n))}}h[n]=-l}this.QR=o,this.Rdiag=h}solve(t){t=_.checkMatrix(t);var r=this.QR,e=r.rows;if(t.rows!==e)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");var n,i,o,s,a=t.columns,h=t.clone(),u=r.columns;for(o=0;o<u;o++)for(i=0;i<a;i++){for(s=0,n=o;n<e;n++)s+=r[n][o]*h[n][i];for(s=-s/r[o][o],n=o;n<e;n++)h[n][i]+=s*r[n][o]}for(o=u-1;o>=0;o--){for(i=0;i<a;i++)h[o][i]/=this.Rdiag[o];for(n=0;n<o;n++)for(i=0;i<a;i++)h[n][i]-=h[o][i]*r[n][o]}return h.subMatrix(0,u-1,0,a-1)}isFullRank(){for(var t=this.QR.columns,r=0;r<t;r++)if(0===this.Rdiag[r])return!1;return!0}get upperTriangularMatrix(){var t,r,e=this.QR,n=e.columns,i=new _(n,n);for(t=0;t<n;t++)for(r=0;r<n;r++)i[t][r]=t<r?e[t][r]:t===r?this.Rdiag[t]:0;return i}get orthogonalMatrix(){var t,r,e,n,i=this.QR,o=i.rows,s=i.columns,a=new _(o,s);for(e=s-1;e>=0;e--){for(t=0;t<o;t++)a[t][e]=0;for(a[e][e]=1,r=e;r<s;r++)if(0!==i[e][e]){for(n=0,t=e;t<o;t++)n+=i[t][e]*a[t][r];for(n=-n/i[e][e],t=e;t<o;t++)a[t][r]+=n*i[t][e]}}return a}}function D(t,r=!1){return t=j.checkMatrix(t),r?new c(t).inverse():L(t,_.eye(t.rows))}function L(t,r,e=!1){return t=j.checkMatrix(t),r=j.checkMatrix(r),e?new c(t).solve(r):t.isSquare()?new h(t).solve(r):new O(t).solve(r)}function T(t,r){for(var e=[],n=0;n<t;n++)n!==r&&e.push(n);return e}function F(t,r,e,n=1e-9,i=1e-9){if(t>i)return new Array(r.rows+1).fill(0);for(var o=r.addRow(e,[0]),s=0;s<o.rows;s++)Math.abs(o.get(s,0))<n&&o.set(s,0,0);return o.to1DArray()}function q(t,r={}){const{thresholdValue:e=1e-9,thresholdError:n=1e-9}=r;for(var i=t.rows,s=new _(i,i),a=0;a<i;a++){var h=_.columnVector(t.getRow(a)),u=t.subMatrixRow(T(i,a)).transposeView(),l=new c(u).solve(h),f=o(_.sub(h,u.mmul(l)).abs().to1DArray());s.setRow(a,F(f,l,a,e,n))}return s}class U{constructor(t,r={}){const{assumeSymmetric:e=!1}=r;if(!(t=j.checkMatrix(t)).isSquare())throw new Error("Matrix is not a square matrix");var n,i,o=t.columns,s=l(o,o,0),a=new Array(o),h=new Array(o),c=t;if(!!e||t.isSymmetric()){for(n=0;n<o;n++)for(i=0;i<o;i++)s[n][i]=c.get(n,i);!function(t,r,e,n){var i,o,s,a,h,u,l,c;for(h=0;h<t;h++)e[h]=n[t-1][h];for(a=t-1;a>0;a--){for(c=0,s=0,u=0;u<a;u++)c+=Math.abs(e[u]);if(0===c)for(r[a]=e[a-1],h=0;h<a;h++)e[h]=n[a-1][h],n[a][h]=0,n[h][a]=0;else{for(u=0;u<a;u++)e[u]/=c,s+=e[u]*e[u];for(i=e[a-1],o=Math.sqrt(s),i>0&&(o=-o),r[a]=c*o,s-=i*o,e[a-1]=i-o,h=0;h<a;h++)r[h]=0;for(h=0;h<a;h++){for(i=e[h],n[h][a]=i,o=r[h]+n[h][h]*i,u=h+1;u<=a-1;u++)o+=n[u][h]*e[u],r[u]+=n[u][h]*i;r[h]=o}for(i=0,h=0;h<a;h++)r[h]/=s,i+=r[h]*e[h];for(l=i/(s+s),h=0;h<a;h++)r[h]-=l*e[h];for(h=0;h<a;h++){for(i=e[h],o=r[h],u=h;u<=a-1;u++)n[u][h]-=i*r[u]+o*e[u];e[h]=n[a-1][h],n[a][h]=0}}e[a]=s}for(a=0;a<t-1;a++){if(n[t-1][a]=n[a][a],n[a][a]=1,0!==(s=e[a+1])){for(u=0;u<=a;u++)e[u]=n[u][a+1]/s;for(h=0;h<=a;h++){for(o=0,u=0;u<=a;u++)o+=n[u][a+1]*n[u][h];for(u=0;u<=a;u++)n[u][h]-=o*e[u]}}for(u=0;u<=a;u++)n[u][a+1]=0}for(h=0;h<t;h++)e[h]=n[t-1][h],n[t-1][h]=0;n[t-1][t-1]=1,r[0]=0}(o,h,a,s),function(t,r,e,n){var i,o,s,a,h,l,c,f,m,g,p,v,d,w,y,b;for(s=1;s<t;s++)r[s-1]=r[s];r[t-1]=0;var M=0,x=0,S=Number.EPSILON;for(l=0;l<t;l++){for(x=Math.max(x,Math.abs(e[l])+Math.abs(r[l])),c=l;c<t&&!(Math.abs(r[c])<=S*x);)c++;if(c>l){0;do{for(1,i=e[l],f=(e[l+1]-i)/(2*r[l]),m=u(f,1),f<0&&(m=-m),e[l]=r[l]/(f+m),e[l+1]=r[l]*(f+m),g=e[l+1],o=i-e[l],s=l+2;s<t;s++)e[s]-=o;for(M+=o,f=e[c],v=p=1,d=p,w=r[l+1],y=0,b=0,s=c-1;s>=l;s--)for(d=v,v=p,b=y,i=p*r[s],o=p*f,m=u(f,r[s]),r[s+1]=y*m,y=r[s]/m,f=(p=f/m)*e[s]-y*i,e[s+1]=o+y*(p*i+y*e[s]),h=0;h<t;h++)o=n[h][s+1],n[h][s+1]=y*n[h][s]+p*o,n[h][s]=p*n[h][s]-y*o;f=-y*b*d*w*r[l]/g,r[l]=y*f,e[l]=p*f}while(Math.abs(r[l])>S*x)}e[l]=e[l]+M,r[l]=0}for(s=0;s<t-1;s++){for(h=s,f=e[s],a=s+1;a<t;a++)e[a]<f&&(h=a,f=e[a]);if(h!==s)for(e[h]=e[s],e[s]=f,a=0;a<t;a++)f=n[a][s],n[a][s]=n[a][h],n[a][h]=f}}(o,h,a,s)}else{var f=l(o,o,0),m=new Array(o);for(i=0;i<o;i++)for(n=0;n<o;n++)f[n][i]=c.get(n,i);!function(t,r,e,n){var i,o,s,a,h,u,l,c=t-1;for(u=1;u<=c-1;u++){for(l=0,a=u;a<=c;a++)l+=Math.abs(r[a][u-1]);if(0!==l){for(s=0,a=c;a>=u;a--)e[a]=r[a][u-1]/l,s+=e[a]*e[a];for(o=Math.sqrt(s),e[u]>0&&(o=-o),s-=e[u]*o,e[u]=e[u]-o,h=u;h<t;h++){for(i=0,a=c;a>=u;a--)i+=e[a]*r[a][h];for(i/=s,a=u;a<=c;a++)r[a][h]-=i*e[a]}for(a=0;a<=c;a++){for(i=0,h=c;h>=u;h--)i+=e[h]*r[a][h];for(i/=s,h=u;h<=c;h++)r[a][h]-=i*e[h]}e[u]=l*e[u],r[u][u-1]=l*o}}for(a=0;a<t;a++)for(h=0;h<t;h++)n[a][h]=a===h?1:0;for(u=c-1;u>=1;u--)if(0!==r[u][u-1]){for(a=u+1;a<=c;a++)e[a]=r[a][u-1];for(h=u;h<=c;h++){for(o=0,a=u;a<=c;a++)o+=e[a]*n[a][h];for(o=o/e[u]/r[u][u-1],a=u;a<=c;a++)n[a][h]+=o*e[a]}}}(o,f,m,s),function(t,r,e,n,i){var o,s,a,h,u,l,c,f,m,g,p,v,d,w,y,b=t-1,M=t-1,x=Number.EPSILON,S=0,E=0,R=0,k=0,z=0,N=0,A=0,V=0;for(o=0;o<t;o++)for((o<0||o>M)&&(e[o]=i[o][o],r[o]=0),s=Math.max(o-1,0);s<t;s++)E+=Math.abs(i[o][s]);for(;b>=0;){for(h=b;h>0&&(0===(N=Math.abs(i[h-1][h-1])+Math.abs(i[h][h]))&&(N=E),!(Math.abs(i[h][h-1])<x*N));)h--;if(h===b)i[b][b]=i[b][b]+S,e[b]=i[b][b],r[b]=0,b--,V=0;else if(h===b-1){if(c=i[b][b-1]*i[b-1][b],R=(i[b-1][b-1]-i[b][b])/2,k=R*R+c,A=Math.sqrt(Math.abs(k)),i[b][b]=i[b][b]+S,i[b-1][b-1]=i[b-1][b-1]+S,f=i[b][b],k>=0){for(A=R>=0?R+A:R-A,e[b-1]=f+A,e[b]=e[b-1],0!==A&&(e[b]=f-c/A),r[b-1]=0,r[b]=0,f=i[b][b-1],N=Math.abs(f)+Math.abs(A),R=f/N,k=A/N,z=Math.sqrt(R*R+k*k),R/=z,k/=z,s=b-1;s<t;s++)A=i[b-1][s],i[b-1][s]=k*A+R*i[b][s],i[b][s]=k*i[b][s]-R*A;for(o=0;o<=b;o++)A=i[o][b-1],i[o][b-1]=k*A+R*i[o][b],i[o][b]=k*i[o][b]-R*A;for(o=0;o<=M;o++)A=n[o][b-1],n[o][b-1]=k*A+R*n[o][b],n[o][b]=k*n[o][b]-R*A}else e[b-1]=f+R,e[b]=f+R,r[b-1]=A,r[b]=-A;b-=2,V=0}else{if(f=i[b][b],m=0,c=0,h<b&&(m=i[b-1][b-1],c=i[b][b-1]*i[b-1][b]),10===V){for(S+=f,o=0;o<=b;o++)i[o][o]-=f;N=Math.abs(i[b][b-1])+Math.abs(i[b-1][b-2]),f=m=.75*N,c=-.4375*N*N}if(30===V&&(N=(N=(m-f)/2)*N+c)>0){for(N=Math.sqrt(N),m<f&&(N=-N),N=f-c/((m-f)/2+N),o=0;o<=b;o++)i[o][o]-=N;S+=N,f=m=c=.964}for(V+=1,u=b-2;u>=h&&(A=i[u][u],R=((z=f-A)*(N=m-A)-c)/i[u+1][u]+i[u][u+1],k=i[u+1][u+1]-A-z-N,z=i[u+2][u+1],N=Math.abs(R)+Math.abs(k)+Math.abs(z),R/=N,k/=N,z/=N,u!==h)&&!(Math.abs(i[u][u-1])*(Math.abs(k)+Math.abs(z))<x*(Math.abs(R)*(Math.abs(i[u-1][u-1])+Math.abs(A)+Math.abs(i[u+1][u+1]))));)u--;for(o=u+2;o<=b;o++)i[o][o-2]=0,o>u+2&&(i[o][o-3]=0);for(a=u;a<=b-1&&(w=a!==b-1,a!==u&&(R=i[a][a-1],k=i[a+1][a-1],z=w?i[a+2][a-1]:0,0!==(f=Math.abs(R)+Math.abs(k)+Math.abs(z))&&(R/=f,k/=f,z/=f)),0!==f);a++)if(N=Math.sqrt(R*R+k*k+z*z),R<0&&(N=-N),0!==N){for(a!==u?i[a][a-1]=-N*f:h!==u&&(i[a][a-1]=-i[a][a-1]),f=(R+=N)/N,m=k/N,A=z/N,k/=R,z/=R,s=a;s<t;s++)R=i[a][s]+k*i[a+1][s],w&&(R+=z*i[a+2][s],i[a+2][s]=i[a+2][s]-R*A),i[a][s]=i[a][s]-R*f,i[a+1][s]=i[a+1][s]-R*m;for(o=0;o<=Math.min(b,a+3);o++)R=f*i[o][a]+m*i[o][a+1],w&&(R+=A*i[o][a+2],i[o][a+2]=i[o][a+2]-R*z),i[o][a]=i[o][a]-R,i[o][a+1]=i[o][a+1]-R*k;for(o=0;o<=M;o++)R=f*n[o][a]+m*n[o][a+1],w&&(R+=A*n[o][a+2],n[o][a+2]=n[o][a+2]-R*z),n[o][a]=n[o][a]-R,n[o][a+1]=n[o][a+1]-R*k}}}if(0===E)return;for(b=t-1;b>=0;b--)if(R=e[b],0===(k=r[b]))for(h=b,i[b][b]=1,o=b-1;o>=0;o--){for(c=i[o][o]-R,z=0,s=h;s<=b;s++)z+=i[o][s]*i[s][b];if(r[o]<0)A=c,N=z;else if(h=o,0===r[o]?i[o][b]=0!==c?-z/c:-z/(x*E):(f=i[o][o+1],m=i[o+1][o],k=(e[o]-R)*(e[o]-R)+r[o]*r[o],l=(f*N-A*z)/k,i[o][b]=l,i[o+1][b]=Math.abs(f)>Math.abs(A)?(-z-c*l)/f:(-N-m*l)/A),l=Math.abs(i[o][b]),x*l*l>1)for(s=o;s<=b;s++)i[s][b]=i[s][b]/l}else if(k<0)for(h=b-1,Math.abs(i[b][b-1])>Math.abs(i[b-1][b])?(i[b-1][b-1]=k/i[b][b-1],i[b-1][b]=-(i[b][b]-R)/i[b][b-1]):(y=$(0,-i[b-1][b],i[b-1][b-1]-R,k),i[b-1][b-1]=y[0],i[b-1][b]=y[1]),i[b][b-1]=0,i[b][b]=1,o=b-2;o>=0;o--){for(g=0,p=0,s=h;s<=b;s++)g+=i[o][s]*i[s][b-1],p+=i[o][s]*i[s][b];if(c=i[o][o]-R,r[o]<0)A=c,z=g,N=p;else if(h=o,0===r[o]?(y=$(-g,-p,c,k),i[o][b-1]=y[0],i[o][b]=y[1]):(f=i[o][o+1],m=i[o+1][o],v=(e[o]-R)*(e[o]-R)+r[o]*r[o]-k*k,d=2*(e[o]-R)*k,0===v&&0===d&&(v=x*E*(Math.abs(c)+Math.abs(k)+Math.abs(f)+Math.abs(m)+Math.abs(A))),y=$(f*z-A*g+k*p,f*N-A*p-k*g,v,d),i[o][b-1]=y[0],i[o][b]=y[1],Math.abs(f)>Math.abs(A)+Math.abs(k)?(i[o+1][b-1]=(-g-c*i[o][b-1]+k*i[o][b])/f,i[o+1][b]=(-p-c*i[o][b]-k*i[o][b-1])/f):(y=$(-z-m*i[o][b-1],-N-m*i[o][b],A,k),i[o+1][b-1]=y[0],i[o+1][b]=y[1])),l=Math.max(Math.abs(i[o][b-1]),Math.abs(i[o][b])),x*l*l>1)for(s=o;s<=b;s++)i[s][b-1]=i[s][b-1]/l,i[s][b]=i[s][b]/l}for(o=0;o<t;o++)if(o<0||o>M)for(s=o;s<t;s++)n[o][s]=i[o][s];for(s=t-1;s>=0;s--)for(o=0;o<=M;o++){for(A=0,a=0;a<=Math.min(s,M);a++)A+=n[o][a]*i[a][s];n[o][s]=A}}(o,h,a,s,f)}this.n=o,this.e=h,this.d=a,this.V=s}get realEigenvalues(){return this.d}get imaginaryEigenvalues(){return this.e}get eigenvectorMatrix(){return _.isMatrix(this.V)||(this.V=new _(this.V)),this.V}get diagonalMatrix(){var t,r,e=this.n,n=this.e,i=this.d,o=new _(e,e);for(t=0;t<e;t++){for(r=0;r<e;r++)o[t][r]=0;o[t][t]=i[t],n[t]>0?o[t][t+1]=n[t]:n[t]<0&&(o[t][t-1]=n[t])}return o}}function $(t,r,e,n){var i,o;return Math.abs(e)>Math.abs(n)?[(t+(i=n/e)*r)/(o=e+i*n),(r-i*t)/o]:[((i=e/n)*t+r)/(o=n+i*e),(i*r-t)/o]}class Q{constructor(t){if(!(t=j.checkMatrix(t)).isSymmetric())throw new Error("Matrix is not symmetric");var r,e,n,i=t,o=i.rows,s=new _(o,o),a=!0;for(e=0;e<o;e++){var h=s[e],u=0;for(n=0;n<e;n++){var l=s[n],c=0;for(r=0;r<n;r++)c+=l[r]*h[r];h[n]=c=(i.get(e,n)-c)/s[n][n],u+=c*c}for(a&=(u=i.get(e,e)-u)>0,s[e][e]=Math.sqrt(Math.max(u,0)),n=e+1;n<o;n++)s[e][n]=0}if(!a)throw new Error("Matrix is not positive definite");this.L=s}solve(t){t=j.checkMatrix(t);var r=this.L,e=r.rows;if(t.rows!==e)throw new Error("Matrix dimensions do not match");var n,i,o,s=t.columns,a=t.clone();for(o=0;o<e;o++)for(i=0;i<s;i++){for(n=0;n<o;n++)a[o][i]-=a[n][i]*r[o][n];a[o][i]/=r[o][o]}for(o=e-1;o>=0;o--)for(i=0;i<s;i++){for(n=o+1;n<e;n++)a[o][i]-=a[n][i]*r[n][o];a[o][i]/=r[o][o]}return a}get lowerTriangularMatrix(){return this.L}}e.d(r,"default",function(){return _}),e.d(r,"Matrix",function(){return _}),e.d(r,"abstractMatrix",function(){return C}),e.d(r,"wrap",function(){return I}),e.d(r,"WrapperMatrix2D",function(){return j}),e.d(r,"WrapperMatrix1D",function(){return P}),e.d(r,"solve",function(){return L}),e.d(r,"inverse",function(){return D}),e.d(r,"linearDependencies",function(){return q}),e.d(r,"SingularValueDecomposition",function(){return c}),e.d(r,"SVD",function(){return c}),e.d(r,"EigenvalueDecomposition",function(){return U}),e.d(r,"EVD",function(){return U}),e.d(r,"CholeskyDecomposition",function(){return Q}),e.d(r,"CHO",function(){return Q}),e.d(r,"LuDecomposition",function(){return h}),e.d(r,"LU",function(){return h}),e.d(r,"QrDecomposition",function(){return O}),e.d(r,"QR",function(){return O})}])});