You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
67 KiB

4 months ago
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).mlMatrix={})}(this,(function(t){"use strict";const e=Object.prototype.toString;function r(t){const r=e.call(t);return r.endsWith("Array]")&&!r.includes("Big")}function s(t){var e,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!r(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==s.output){if(!r(s.output))throw new TypeError("output option must be an array if specified");e=s.output}else e=new Array(t.length);var o=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!r(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var s=e.fromIndex,o=void 0===s?0:s,i=e.toIndex,n=void 0===i?t.length:i;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 h=t[o],u=o+1;u<n;u++)t[u]<h&&(h=t[u]);return h}(t),i=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!r(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var s=e.fromIndex,o=void 0===s?0:s,i=e.toIndex,n=void 0===i?t.length:i;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 h=t[o],u=o+1;u<n;u++)t[u]>h&&(h=t[u]);return h}(t);if(o===i)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=s.min,h=void 0===n?s.autoMinMax?o:0:n,u=s.max,l=void 0===u?s.autoMinMax?i:1:u;if(h>=l)throw new RangeError("min option must be smaller than max option");for(var a=(l-h)/(i-o),f=0;f<t.length;f++)e[f]=(t[f]-o)*a+h;return e}const o=" ".repeat(2),i=" ".repeat(4);function n(t,e={}){const{maxRows:r=15,maxColumns:s=10,maxNumSize:n=8,padMinus:u="auto"}=e;return`${t.constructor.name} {\n${o}[\n${i}${function(t,e,r,s,o){const{rows:n,columns:u}=t,l=Math.min(n,e),a=Math.min(u,r),f=[];if("auto"===o){o=!1;t:for(let e=0;e<l;e++)for(let r=0;r<a;r++)if(t.get(e,r)<0){o=!0;break t}}for(let e=0;e<l;e++){let r=[];for(let i=0;i<a;i++)r.push(h(t.get(e,i),s,o));f.push(`${r.join(" ")}`)}a!==u&&(f[f.length-1]+=` ... ${u-r} more columns`);l!==n&&f.push(`... ${n-e} more rows`);return f.join(`\n${i}`)}(t,r,s,n,u)}\n${o}]\n${o}rows: ${t.rows}\n${o}columns: ${t.columns}\n}`}function h(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 s=t.toFixed(e);if(s.length>e&&(s=t.toFixed(Math.max(0,e-(s.length-e)))),s.length<=e&&!s.startsWith("0.000")&&!s.startsWith("-0.000"))return s;let o=t.toExponential(e);return o.length>e&&(o=t.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function l(t,e,r){let s=r?t.rows:t.rows-1;if(e<0||e>s)throw new RangeError("Row index out of range")}function a(t,e,r){let s=r?t.columns:t.columns-1;if(e<0||e>s)throw new RangeError("Column index out of range")}function f(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 c(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 m(t,e){if(!r(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")}function g(t,e){if(!r(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 r