@descix/egpt-math-sdk 0.1.0

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.
Files changed (114) hide show
  1. package/README.md +224 -0
  2. package/dist/egpt-math-sdk.browser.js +5 -0
  3. package/dist/index.d.ts +100 -0
  4. package/dist/index.js +985 -0
  5. package/dist/notebooks/arithmetic-basics.html +166 -0
  6. package/dist/notebooks/complex-twiddle.html +148 -0
  7. package/dist/notebooks/double-slit-rosetta-qft.html +154 -0
  8. package/dist/notebooks/egpt-fft-test.html +202 -0
  9. package/dist/notebooks/egpt-matrix-test.html +241 -0
  10. package/dist/notebooks/egpt-polynomial-test.html +703 -0
  11. package/dist/notebooks/egpt-prime-composite-test.html +561 -0
  12. package/dist/notebooks/egpt-test-suite.html +1387 -0
  13. package/dist/notebooks/egpt-topology-test.html +410 -0
  14. package/dist/notebooks/factorization-basics.html +131 -0
  15. package/dist/notebooks/fft.html +155 -0
  16. package/dist/notebooks/frqtl-qft-benchmark.html +207 -0
  17. package/dist/notebooks/gallery-atomic-model.html +51 -0
  18. package/dist/notebooks/gallery-big-bang.html +62 -0
  19. package/dist/notebooks/gallery-blackbody.html +52 -0
  20. package/dist/notebooks/gallery-circuit-sat.html +104 -0
  21. package/dist/notebooks/gallery-collision-matrix-3d.html +51 -0
  22. package/dist/notebooks/gallery-double-slit.html +53 -0
  23. package/dist/notebooks/gallery-gun-chamber.html +62 -0
  24. package/dist/notebooks/gallery-particle-walk-3d.html +53 -0
  25. package/dist/notebooks/gallery-wave-interference.html +52 -0
  26. package/dist/notebooks/getting-started-hello-frqtl.html +53 -0
  27. package/dist/notebooks/iso-canonical-chain.html +203 -0
  28. package/dist/notebooks/iso-entropy-log.html +127 -0
  29. package/dist/notebooks/iso-fft-polynomial.html +136 -0
  30. package/dist/notebooks/iso-matrix-four-views.html +131 -0
  31. package/dist/notebooks/iso-number-theory-four-views.html +99 -0
  32. package/dist/notebooks/iso-pi-log-fraction-loop.html +140 -0
  33. package/dist/notebooks/matrix.html +202 -0
  34. package/dist/notebooks/notebooks.json +240 -0
  35. package/dist/notebooks/polynomials.html +201 -0
  36. package/dist/notebooks/prime-composite.html +268 -0
  37. package/dist/notebooks/rational-core.html +179 -0
  38. package/dist/notebooks/reference-egpt-fft-test.html +187 -0
  39. package/dist/notebooks/reference-order-finder-test.html +196 -0
  40. package/dist/notebooks/reference-prime-atom-polynomial-test.html +542 -0
  41. package/dist/notebooks/reference-solve-polynomial-system-test.html +471 -0
  42. package/dist/notebooks/scaled-vectors.html +112 -0
  43. package/dist/notebooks/stats.html +206 -0
  44. package/dist/notebooks/transcendentals.html +195 -0
  45. package/dist/notebooks/view-vendored-d3.html +78 -0
  46. package/dist/vendor/d3-array/src/array.js +4 -0
  47. package/dist/vendor/d3-array/src/ascending.js +3 -0
  48. package/dist/vendor/d3-array/src/bin.js +125 -0
  49. package/dist/vendor/d3-array/src/bisect.js +9 -0
  50. package/dist/vendor/d3-array/src/bisector.js +56 -0
  51. package/dist/vendor/d3-array/src/blur.js +115 -0
  52. package/dist/vendor/d3-array/src/constant.js +3 -0
  53. package/dist/vendor/d3-array/src/count.js +18 -0
  54. package/dist/vendor/d3-array/src/cross.js +33 -0
  55. package/dist/vendor/d3-array/src/cumsum.js +6 -0
  56. package/dist/vendor/d3-array/src/descending.js +7 -0
  57. package/dist/vendor/d3-array/src/deviation.js +6 -0
  58. package/dist/vendor/d3-array/src/difference.js +11 -0
  59. package/dist/vendor/d3-array/src/disjoint.js +15 -0
  60. package/dist/vendor/d3-array/src/every.js +10 -0
  61. package/dist/vendor/d3-array/src/extent.js +29 -0
  62. package/dist/vendor/d3-array/src/filter.js +11 -0
  63. package/dist/vendor/d3-array/src/fsum.js +69 -0
  64. package/dist/vendor/d3-array/src/greatest.js +29 -0
  65. package/dist/vendor/d3-array/src/greatestIndex.js +19 -0
  66. package/dist/vendor/d3-array/src/group.js +65 -0
  67. package/dist/vendor/d3-array/src/groupSort.js +10 -0
  68. package/dist/vendor/d3-array/src/identity.js +3 -0
  69. package/dist/vendor/d3-array/src/index.js +57 -0
  70. package/dist/vendor/d3-array/src/intersection.js +19 -0
  71. package/dist/vendor/d3-array/src/least.js +29 -0
  72. package/dist/vendor/d3-array/src/leastIndex.js +19 -0
  73. package/dist/vendor/d3-array/src/map.js +5 -0
  74. package/dist/vendor/d3-array/src/max.js +20 -0
  75. package/dist/vendor/d3-array/src/maxIndex.js +22 -0
  76. package/dist/vendor/d3-array/src/mean.js +19 -0
  77. package/dist/vendor/d3-array/src/median.js +9 -0
  78. package/dist/vendor/d3-array/src/merge.js +9 -0
  79. package/dist/vendor/d3-array/src/min.js +20 -0
  80. package/dist/vendor/d3-array/src/minIndex.js +22 -0
  81. package/dist/vendor/d3-array/src/mode.js +28 -0
  82. package/dist/vendor/d3-array/src/nice.js +18 -0
  83. package/dist/vendor/d3-array/src/number.js +20 -0
  84. package/dist/vendor/d3-array/src/pairs.js +15 -0
  85. package/dist/vendor/d3-array/src/permute.js +3 -0
  86. package/dist/vendor/d3-array/src/quantile.js +47 -0
  87. package/dist/vendor/d3-array/src/quickselect.js +53 -0
  88. package/dist/vendor/d3-array/src/range.js +13 -0
  89. package/dist/vendor/d3-array/src/rank.js +24 -0
  90. package/dist/vendor/d3-array/src/reduce.js +14 -0
  91. package/dist/vendor/d3-array/src/reverse.js +4 -0
  92. package/dist/vendor/d3-array/src/scan.js +6 -0
  93. package/dist/vendor/d3-array/src/shuffle.js +13 -0
  94. package/dist/vendor/d3-array/src/some.js +10 -0
  95. package/dist/vendor/d3-array/src/sort.js +39 -0
  96. package/dist/vendor/d3-array/src/subset.js +5 -0
  97. package/dist/vendor/d3-array/src/sum.js +18 -0
  98. package/dist/vendor/d3-array/src/superset.js +19 -0
  99. package/dist/vendor/d3-array/src/threshold/freedmanDiaconis.js +7 -0
  100. package/dist/vendor/d3-array/src/threshold/scott.js +7 -0
  101. package/dist/vendor/d3-array/src/threshold/sturges.js +5 -0
  102. package/dist/vendor/d3-array/src/ticks.js +55 -0
  103. package/dist/vendor/d3-array/src/transpose.js +15 -0
  104. package/dist/vendor/d3-array/src/union.js +11 -0
  105. package/dist/vendor/d3-array/src/variance.js +25 -0
  106. package/dist/vendor/d3-array/src/zip.js +5 -0
  107. package/dist/vendor/internmap/src/index.js +61 -0
  108. package/dist/vendor/manifest.json +11 -0
  109. package/dist/wasm/egpt_math_sdk_wasm.d.ts +214 -0
  110. package/dist/wasm/egpt_math_sdk_wasm.js +1120 -0
  111. package/dist/wasm/egpt_math_sdk_wasm_bg.wasm +0 -0
  112. package/dist/wasm/egpt_math_sdk_wasm_bg.wasm.d.ts +66 -0
  113. package/dist/wasm/manifest.json +5 -0
  114. package/package.json +53 -0
@@ -0,0 +1,19 @@
1
+ export default function mean(values, valueof) {
2
+ let count = 0;
3
+ let sum = 0;
4
+ if (valueof === undefined) {
5
+ for (let value of values) {
6
+ if (value != null && (value = +value) >= value) {
7
+ ++count, sum += value;
8
+ }
9
+ }
10
+ } else {
11
+ let index = -1;
12
+ for (let value of values) {
13
+ if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
14
+ ++count, sum += value;
15
+ }
16
+ }
17
+ }
18
+ if (count) return sum / count;
19
+ }
@@ -0,0 +1,9 @@
1
+ import quantile, {quantileIndex} from "./quantile.js";
2
+
3
+ export default function median(values, valueof) {
4
+ return quantile(values, 0.5, valueof);
5
+ }
6
+
7
+ export function medianIndex(values, valueof) {
8
+ return quantileIndex(values, 0.5, valueof);
9
+ }
@@ -0,0 +1,9 @@
1
+ function* flatten(arrays) {
2
+ for (const array of arrays) {
3
+ yield* array;
4
+ }
5
+ }
6
+
7
+ export default function merge(arrays) {
8
+ return Array.from(flatten(arrays));
9
+ }
@@ -0,0 +1,20 @@
1
+ export default function min(values, valueof) {
2
+ let min;
3
+ if (valueof === undefined) {
4
+ for (const value of values) {
5
+ if (value != null
6
+ && (min > value || (min === undefined && value >= value))) {
7
+ min = value;
8
+ }
9
+ }
10
+ } else {
11
+ let index = -1;
12
+ for (let value of values) {
13
+ if ((value = valueof(value, ++index, values)) != null
14
+ && (min > value || (min === undefined && value >= value))) {
15
+ min = value;
16
+ }
17
+ }
18
+ }
19
+ return min;
20
+ }
@@ -0,0 +1,22 @@
1
+ export default function minIndex(values, valueof) {
2
+ let min;
3
+ let minIndex = -1;
4
+ let index = -1;
5
+ if (valueof === undefined) {
6
+ for (const value of values) {
7
+ ++index;
8
+ if (value != null
9
+ && (min > value || (min === undefined && value >= value))) {
10
+ min = value, minIndex = index;
11
+ }
12
+ }
13
+ } else {
14
+ for (let value of values) {
15
+ if ((value = valueof(value, ++index, values)) != null
16
+ && (min > value || (min === undefined && value >= value))) {
17
+ min = value, minIndex = index;
18
+ }
19
+ }
20
+ }
21
+ return minIndex;
22
+ }
@@ -0,0 +1,28 @@
1
+ import {InternMap} from "internmap";
2
+
3
+ export default function mode(values, valueof) {
4
+ const counts = new InternMap();
5
+ if (valueof === undefined) {
6
+ for (let value of values) {
7
+ if (value != null && value >= value) {
8
+ counts.set(value, (counts.get(value) || 0) + 1);
9
+ }
10
+ }
11
+ } else {
12
+ let index = -1;
13
+ for (let value of values) {
14
+ if ((value = valueof(value, ++index, values)) != null && value >= value) {
15
+ counts.set(value, (counts.get(value) || 0) + 1);
16
+ }
17
+ }
18
+ }
19
+ let modeValue;
20
+ let modeCount = 0;
21
+ for (const [value, count] of counts) {
22
+ if (count > modeCount) {
23
+ modeCount = count;
24
+ modeValue = value;
25
+ }
26
+ }
27
+ return modeValue;
28
+ }
@@ -0,0 +1,18 @@
1
+ import {tickIncrement} from "./ticks.js";
2
+
3
+ export default function nice(start, stop, count) {
4
+ let prestep;
5
+ while (true) {
6
+ const step = tickIncrement(start, stop, count);
7
+ if (step === prestep || step === 0 || !isFinite(step)) {
8
+ return [start, stop];
9
+ } else if (step > 0) {
10
+ start = Math.floor(start / step) * step;
11
+ stop = Math.ceil(stop / step) * step;
12
+ } else if (step < 0) {
13
+ start = Math.ceil(start * step) / step;
14
+ stop = Math.floor(stop * step) / step;
15
+ }
16
+ prestep = step;
17
+ }
18
+ }
@@ -0,0 +1,20 @@
1
+ export default function number(x) {
2
+ return x === null ? NaN : +x;
3
+ }
4
+
5
+ export function* numbers(values, valueof) {
6
+ if (valueof === undefined) {
7
+ for (let value of values) {
8
+ if (value != null && (value = +value) >= value) {
9
+ yield value;
10
+ }
11
+ }
12
+ } else {
13
+ let index = -1;
14
+ for (let value of values) {
15
+ if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
16
+ yield value;
17
+ }
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,15 @@
1
+ export default function pairs(values, pairof = pair) {
2
+ const pairs = [];
3
+ let previous;
4
+ let first = false;
5
+ for (const value of values) {
6
+ if (first) pairs.push(pairof(previous, value));
7
+ previous = value;
8
+ first = true;
9
+ }
10
+ return pairs;
11
+ }
12
+
13
+ export function pair(a, b) {
14
+ return [a, b];
15
+ }
@@ -0,0 +1,3 @@
1
+ export default function permute(source, keys) {
2
+ return Array.from(keys, key => source[key]);
3
+ }
@@ -0,0 +1,47 @@
1
+ import max from "./max.js";
2
+ import maxIndex from "./maxIndex.js";
3
+ import min from "./min.js";
4
+ import minIndex from "./minIndex.js";
5
+ import quickselect from "./quickselect.js";
6
+ import number, {numbers} from "./number.js";
7
+ import {ascendingDefined} from "./sort.js";
8
+ import greatest from "./greatest.js";
9
+
10
+ export default function quantile(values, p, valueof) {
11
+ values = Float64Array.from(numbers(values, valueof));
12
+ if (!(n = values.length) || isNaN(p = +p)) return;
13
+ if (p <= 0 || n < 2) return min(values);
14
+ if (p >= 1) return max(values);
15
+ var n,
16
+ i = (n - 1) * p,
17
+ i0 = Math.floor(i),
18
+ value0 = max(quickselect(values, i0).subarray(0, i0 + 1)),
19
+ value1 = min(values.subarray(i0 + 1));
20
+ return value0 + (value1 - value0) * (i - i0);
21
+ }
22
+
23
+ export function quantileSorted(values, p, valueof = number) {
24
+ if (!(n = values.length) || isNaN(p = +p)) return;
25
+ if (p <= 0 || n < 2) return +valueof(values[0], 0, values);
26
+ if (p >= 1) return +valueof(values[n - 1], n - 1, values);
27
+ var n,
28
+ i = (n - 1) * p,
29
+ i0 = Math.floor(i),
30
+ value0 = +valueof(values[i0], i0, values),
31
+ value1 = +valueof(values[i0 + 1], i0 + 1, values);
32
+ return value0 + (value1 - value0) * (i - i0);
33
+ }
34
+
35
+ export function quantileIndex(values, p, valueof = number) {
36
+ if (isNaN(p = +p)) return;
37
+ numbers = Float64Array.from(values, (_, i) => number(valueof(values[i], i, values)));
38
+ if (p <= 0) return minIndex(numbers);
39
+ if (p >= 1) return maxIndex(numbers);
40
+ var numbers,
41
+ index = Uint32Array.from(values, (_, i) => i),
42
+ j = numbers.length - 1,
43
+ i = Math.floor(j * p);
44
+ quickselect(index, i, 0, j, (i, j) => ascendingDefined(numbers[i], numbers[j]));
45
+ i = greatest(index.subarray(0, i + 1), (i) => numbers[i]);
46
+ return i >= 0 ? i : -1;
47
+ }
@@ -0,0 +1,53 @@
1
+ import {ascendingDefined, compareDefined} from "./sort.js";
2
+
3
+ // Based on https://github.com/mourner/quickselect
4
+ // ISC license, Copyright 2018 Vladimir Agafonkin.
5
+ export default function quickselect(array, k, left = 0, right = Infinity, compare) {
6
+ k = Math.floor(k);
7
+ left = Math.floor(Math.max(0, left));
8
+ right = Math.floor(Math.min(array.length - 1, right));
9
+
10
+ if (!(left <= k && k <= right)) return array;
11
+
12
+ compare = compare === undefined ? ascendingDefined : compareDefined(compare);
13
+
14
+ while (right > left) {
15
+ if (right - left > 600) {
16
+ const n = right - left + 1;
17
+ const m = k - left + 1;
18
+ const z = Math.log(n);
19
+ const s = 0.5 * Math.exp(2 * z / 3);
20
+ const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
21
+ const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
22
+ const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
23
+ quickselect(array, k, newLeft, newRight, compare);
24
+ }
25
+
26
+ const t = array[k];
27
+ let i = left;
28
+ let j = right;
29
+
30
+ swap(array, left, k);
31
+ if (compare(array[right], t) > 0) swap(array, left, right);
32
+
33
+ while (i < j) {
34
+ swap(array, i, j), ++i, --j;
35
+ while (compare(array[i], t) < 0) ++i;
36
+ while (compare(array[j], t) > 0) --j;
37
+ }
38
+
39
+ if (compare(array[left], t) === 0) swap(array, left, j);
40
+ else ++j, swap(array, j, right);
41
+
42
+ if (j <= k) left = j + 1;
43
+ if (k <= j) right = j - 1;
44
+ }
45
+
46
+ return array;
47
+ }
48
+
49
+ function swap(array, i, j) {
50
+ const t = array[i];
51
+ array[i] = array[j];
52
+ array[j] = t;
53
+ }
@@ -0,0 +1,13 @@
1
+ export default function range(start, stop, step) {
2
+ start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
3
+
4
+ var i = -1,
5
+ n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
6
+ range = new Array(n);
7
+
8
+ while (++i < n) {
9
+ range[i] = start + i * step;
10
+ }
11
+
12
+ return range;
13
+ }
@@ -0,0 +1,24 @@
1
+ import ascending from "./ascending.js";
2
+ import {ascendingDefined, compareDefined} from "./sort.js";
3
+
4
+ export default function rank(values, valueof = ascending) {
5
+ if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
6
+ let V = Array.from(values);
7
+ const R = new Float64Array(V.length);
8
+ if (valueof.length !== 2) V = V.map(valueof), valueof = ascending;
9
+ const compareIndex = (i, j) => valueof(V[i], V[j]);
10
+ let k, r;
11
+ values = Uint32Array.from(V, (_, i) => i);
12
+ // Risky chaining due to Safari 14 https://github.com/d3/d3-array/issues/123
13
+ values.sort(valueof === ascending ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex));
14
+ values.forEach((j, i) => {
15
+ const c = compareIndex(j, k === undefined ? j : k);
16
+ if (c >= 0) {
17
+ if (k === undefined || c > 0) k = j, r = i;
18
+ R[j] = r;
19
+ } else {
20
+ R[j] = NaN;
21
+ }
22
+ });
23
+ return R;
24
+ }
@@ -0,0 +1,14 @@
1
+ export default function reduce(values, reducer, value) {
2
+ if (typeof reducer !== "function") throw new TypeError("reducer is not a function");
3
+ const iterator = values[Symbol.iterator]();
4
+ let done, next, index = -1;
5
+ if (arguments.length < 3) {
6
+ ({done, value} = iterator.next());
7
+ if (done) return;
8
+ ++index;
9
+ }
10
+ while (({done, value: next} = iterator.next()), !done) {
11
+ value = reducer(value, next, ++index, values);
12
+ }
13
+ return value;
14
+ }
@@ -0,0 +1,4 @@
1
+ export default function reverse(values) {
2
+ if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
3
+ return Array.from(values).reverse();
4
+ }
@@ -0,0 +1,6 @@
1
+ import leastIndex from "./leastIndex.js";
2
+
3
+ export default function scan(values, compare) {
4
+ const index = leastIndex(values, compare);
5
+ return index < 0 ? undefined : index;
6
+ }
@@ -0,0 +1,13 @@
1
+ export default shuffler(Math.random);
2
+
3
+ export function shuffler(random) {
4
+ return function shuffle(array, i0 = 0, i1 = array.length) {
5
+ let m = i1 - (i0 = +i0);
6
+ while (m) {
7
+ const i = random() * m-- | 0, t = array[m + i0];
8
+ array[m + i0] = array[i + i0];
9
+ array[i + i0] = t;
10
+ }
11
+ return array;
12
+ };
13
+ }
@@ -0,0 +1,10 @@
1
+ export default function some(values, test) {
2
+ if (typeof test !== "function") throw new TypeError("test is not a function");
3
+ let index = -1;
4
+ for (const value of values) {
5
+ if (test(value, ++index, values)) {
6
+ return true;
7
+ }
8
+ }
9
+ return false;
10
+ }
@@ -0,0 +1,39 @@
1
+ import ascending from "./ascending.js";
2
+ import permute from "./permute.js";
3
+
4
+ export default function sort(values, ...F) {
5
+ if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
6
+ values = Array.from(values);
7
+ let [f] = F;
8
+ if ((f && f.length !== 2) || F.length > 1) {
9
+ const index = Uint32Array.from(values, (d, i) => i);
10
+ if (F.length > 1) {
11
+ F = F.map(f => values.map(f));
12
+ index.sort((i, j) => {
13
+ for (const f of F) {
14
+ const c = ascendingDefined(f[i], f[j]);
15
+ if (c) return c;
16
+ }
17
+ });
18
+ } else {
19
+ f = values.map(f);
20
+ index.sort((i, j) => ascendingDefined(f[i], f[j]));
21
+ }
22
+ return permute(values, index);
23
+ }
24
+ return values.sort(compareDefined(f));
25
+ }
26
+
27
+ export function compareDefined(compare = ascending) {
28
+ if (compare === ascending) return ascendingDefined;
29
+ if (typeof compare !== "function") throw new TypeError("compare is not a function");
30
+ return (a, b) => {
31
+ const x = compare(a, b);
32
+ if (x || x === 0) return x;
33
+ return (compare(b, b) === 0) - (compare(a, a) === 0);
34
+ };
35
+ }
36
+
37
+ export function ascendingDefined(a, b) {
38
+ return (a == null || !(a >= a)) - (b == null || !(b >= b)) || (a < b ? -1 : a > b ? 1 : 0);
39
+ }
@@ -0,0 +1,5 @@
1
+ import superset from "./superset.js";
2
+
3
+ export default function subset(values, other) {
4
+ return superset(other, values);
5
+ }
@@ -0,0 +1,18 @@
1
+ export default function sum(values, valueof) {
2
+ let sum = 0;
3
+ if (valueof === undefined) {
4
+ for (let value of values) {
5
+ if (value = +value) {
6
+ sum += value;
7
+ }
8
+ }
9
+ } else {
10
+ let index = -1;
11
+ for (let value of values) {
12
+ if (value = +valueof(value, ++index, values)) {
13
+ sum += value;
14
+ }
15
+ }
16
+ }
17
+ return sum;
18
+ }
@@ -0,0 +1,19 @@
1
+ export default function superset(values, other) {
2
+ const iterator = values[Symbol.iterator](), set = new Set();
3
+ for (const o of other) {
4
+ const io = intern(o);
5
+ if (set.has(io)) continue;
6
+ let value, done;
7
+ while (({value, done} = iterator.next())) {
8
+ if (done) return false;
9
+ const ivalue = intern(value);
10
+ set.add(ivalue);
11
+ if (Object.is(io, ivalue)) break;
12
+ }
13
+ }
14
+ return true;
15
+ }
16
+
17
+ function intern(value) {
18
+ return value !== null && typeof value === "object" ? value.valueOf() : value;
19
+ }
@@ -0,0 +1,7 @@
1
+ import count from "../count.js";
2
+ import quantile from "../quantile.js";
3
+
4
+ export default function thresholdFreedmanDiaconis(values, min, max) {
5
+ const c = count(values), d = quantile(values, 0.75) - quantile(values, 0.25);
6
+ return c && d ? Math.ceil((max - min) / (2 * d * Math.pow(c, -1 / 3))) : 1;
7
+ }
@@ -0,0 +1,7 @@
1
+ import count from "../count.js";
2
+ import deviation from "../deviation.js";
3
+
4
+ export default function thresholdScott(values, min, max) {
5
+ const c = count(values), d = deviation(values);
6
+ return c && d ? Math.ceil((max - min) * Math.cbrt(c) / (3.49 * d)) : 1;
7
+ }
@@ -0,0 +1,5 @@
1
+ import count from "../count.js";
2
+
3
+ export default function thresholdSturges(values) {
4
+ return Math.max(1, Math.ceil(Math.log(count(values)) / Math.LN2) + 1);
5
+ }
@@ -0,0 +1,55 @@
1
+ const e10 = Math.sqrt(50),
2
+ e5 = Math.sqrt(10),
3
+ e2 = Math.sqrt(2);
4
+
5
+ function tickSpec(start, stop, count) {
6
+ const step = (stop - start) / Math.max(0, count),
7
+ power = Math.floor(Math.log10(step)),
8
+ error = step / Math.pow(10, power),
9
+ factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1;
10
+ let i1, i2, inc;
11
+ if (power < 0) {
12
+ inc = Math.pow(10, -power) / factor;
13
+ i1 = Math.round(start * inc);
14
+ i2 = Math.round(stop * inc);
15
+ if (i1 / inc < start) ++i1;
16
+ if (i2 / inc > stop) --i2;
17
+ inc = -inc;
18
+ } else {
19
+ inc = Math.pow(10, power) * factor;
20
+ i1 = Math.round(start / inc);
21
+ i2 = Math.round(stop / inc);
22
+ if (i1 * inc < start) ++i1;
23
+ if (i2 * inc > stop) --i2;
24
+ }
25
+ if (i2 < i1 && 0.5 <= count && count < 2) return tickSpec(start, stop, count * 2);
26
+ return [i1, i2, inc];
27
+ }
28
+
29
+ export default function ticks(start, stop, count) {
30
+ stop = +stop, start = +start, count = +count;
31
+ if (!(count > 0)) return [];
32
+ if (start === stop) return [start];
33
+ const reverse = stop < start, [i1, i2, inc] = reverse ? tickSpec(stop, start, count) : tickSpec(start, stop, count);
34
+ if (!(i2 >= i1)) return [];
35
+ const n = i2 - i1 + 1, ticks = new Array(n);
36
+ if (reverse) {
37
+ if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) / -inc;
38
+ else for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) * inc;
39
+ } else {
40
+ if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) / -inc;
41
+ else for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) * inc;
42
+ }
43
+ return ticks;
44
+ }
45
+
46
+ export function tickIncrement(start, stop, count) {
47
+ stop = +stop, start = +start, count = +count;
48
+ return tickSpec(start, stop, count)[2];
49
+ }
50
+
51
+ export function tickStep(start, stop, count) {
52
+ stop = +stop, start = +start, count = +count;
53
+ const reverse = stop < start, inc = reverse ? tickIncrement(stop, start, count) : tickIncrement(start, stop, count);
54
+ return (reverse ? -1 : 1) * (inc < 0 ? 1 / -inc : inc);
55
+ }
@@ -0,0 +1,15 @@
1
+ import min from "./min.js";
2
+
3
+ export default function transpose(matrix) {
4
+ if (!(n = matrix.length)) return [];
5
+ for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
6
+ for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
7
+ row[j] = matrix[j][i];
8
+ }
9
+ }
10
+ return transpose;
11
+ }
12
+
13
+ function length(d) {
14
+ return d.length;
15
+ }
@@ -0,0 +1,11 @@
1
+ import {InternSet} from "internmap";
2
+
3
+ export default function union(...others) {
4
+ const set = new InternSet();
5
+ for (const other of others) {
6
+ for (const o of other) {
7
+ set.add(o);
8
+ }
9
+ }
10
+ return set;
11
+ }
@@ -0,0 +1,25 @@
1
+ export default function variance(values, valueof) {
2
+ let count = 0;
3
+ let delta;
4
+ let mean = 0;
5
+ let sum = 0;
6
+ if (valueof === undefined) {
7
+ for (let value of values) {
8
+ if (value != null && (value = +value) >= value) {
9
+ delta = value - mean;
10
+ mean += delta / ++count;
11
+ sum += delta * (value - mean);
12
+ }
13
+ }
14
+ } else {
15
+ let index = -1;
16
+ for (let value of values) {
17
+ if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
18
+ delta = value - mean;
19
+ mean += delta / ++count;
20
+ sum += delta * (value - mean);
21
+ }
22
+ }
23
+ }
24
+ if (count > 1) return sum / (count - 1);
25
+ }
@@ -0,0 +1,5 @@
1
+ import transpose from "./transpose.js";
2
+
3
+ export default function zip() {
4
+ return transpose(arguments);
5
+ }
@@ -0,0 +1,61 @@
1
+ export class InternMap extends Map {
2
+ constructor(entries, key = keyof) {
3
+ super();
4
+ Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
5
+ if (entries != null) for (const [key, value] of entries) this.set(key, value);
6
+ }
7
+ get(key) {
8
+ return super.get(intern_get(this, key));
9
+ }
10
+ has(key) {
11
+ return super.has(intern_get(this, key));
12
+ }
13
+ set(key, value) {
14
+ return super.set(intern_set(this, key), value);
15
+ }
16
+ delete(key) {
17
+ return super.delete(intern_delete(this, key));
18
+ }
19
+ }
20
+
21
+ export class InternSet extends Set {
22
+ constructor(values, key = keyof) {
23
+ super();
24
+ Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
25
+ if (values != null) for (const value of values) this.add(value);
26
+ }
27
+ has(value) {
28
+ return super.has(intern_get(this, value));
29
+ }
30
+ add(value) {
31
+ return super.add(intern_set(this, value));
32
+ }
33
+ delete(value) {
34
+ return super.delete(intern_delete(this, value));
35
+ }
36
+ }
37
+
38
+ function intern_get({_intern, _key}, value) {
39
+ const key = _key(value);
40
+ return _intern.has(key) ? _intern.get(key) : value;
41
+ }
42
+
43
+ function intern_set({_intern, _key}, value) {
44
+ const key = _key(value);
45
+ if (_intern.has(key)) return _intern.get(key);
46
+ _intern.set(key, value);
47
+ return value;
48
+ }
49
+
50
+ function intern_delete({_intern, _key}, value) {
51
+ const key = _key(value);
52
+ if (_intern.has(key)) {
53
+ value = _intern.get(key);
54
+ _intern.delete(key);
55
+ }
56
+ return value;
57
+ }
58
+
59
+ function keyof(value) {
60
+ return value !== null && typeof value === "object" ? value.valueOf() : value;
61
+ }