@danielsimonjr/mathts-functions 0.32.0 → 0.34.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.
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2182 -583
- package/dist/numbertheory/extra.d.ts +142 -0
- package/dist/numbertheory/extra.d.ts.map +1 -0
- package/dist/numeric/gauss-nodes.d.ts +35 -0
- package/dist/numeric/gauss-nodes.d.ts.map +1 -0
- package/dist/signal/conv.d.ts +113 -0
- package/dist/signal/conv.d.ts.map +1 -0
- package/dist/signal/fft-helpers.d.ts +56 -0
- package/dist/signal/fft-helpers.d.ts.map +1 -0
- package/dist/signal/fft.d.ts +136 -0
- package/dist/signal/fft.d.ts.map +1 -0
- package/dist/signal/fir-smoothing.d.ts +62 -0
- package/dist/signal/fir-smoothing.d.ts.map +1 -0
- package/dist/signal/iir-design.d.ts +94 -0
- package/dist/signal/iir-design.d.ts.map +1 -0
- package/dist/signal/spectral-peaks.d.ts +115 -0
- package/dist/signal/spectral-peaks.d.ts.map +1 -0
- package/dist/signal/wavelets.d.ts +55 -0
- package/dist/signal/wavelets.d.ts.map +1 -0
- package/dist/signal-filter-extra.d.ts +42 -3
- package/dist/signal-filter-extra.d.ts.map +1 -1
- package/dist/special/hypergeometric.d.ts +91 -0
- package/dist/special/hypergeometric.d.ts.map +1 -0
- package/dist/special/jacobi-elliptic.d.ts +60 -0
- package/dist/special/jacobi-elliptic.d.ts.map +1 -0
- package/dist/special/polygamma-orthopoly.d.ts +79 -0
- package/dist/special/polygamma-orthopoly.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2021,16 +2021,16 @@ var xgcd = mathTyped2("xgcd", {
|
|
|
2021
2021
|
return a < 0n ? [-a, -lastX, -lastY] : [a, lastX, lastY];
|
|
2022
2022
|
}
|
|
2023
2023
|
});
|
|
2024
|
-
function is2DArray(
|
|
2025
|
-
return Array.isArray(
|
|
2026
|
-
}
|
|
2027
|
-
function vectorNorm(
|
|
2028
|
-
if (p === Infinity) return Math.max(...
|
|
2029
|
-
if (p === -Infinity) return Math.min(...
|
|
2030
|
-
if (p === 0) return
|
|
2031
|
-
if (p === 2) return norm2(
|
|
2032
|
-
const terms = new Array(
|
|
2033
|
-
for (let i = 0; i <
|
|
2024
|
+
function is2DArray(arr10) {
|
|
2025
|
+
return Array.isArray(arr10[0]);
|
|
2026
|
+
}
|
|
2027
|
+
function vectorNorm(arr10, p = 2) {
|
|
2028
|
+
if (p === Infinity) return Math.max(...arr10.map((x) => Math.abs(x)));
|
|
2029
|
+
if (p === -Infinity) return Math.min(...arr10.map((x) => Math.abs(x)));
|
|
2030
|
+
if (p === 0) return arr10.filter((x) => x !== 0).length;
|
|
2031
|
+
if (p === 2) return norm2(arr10);
|
|
2032
|
+
const terms = new Array(arr10.length);
|
|
2033
|
+
for (let i = 0; i < arr10.length; i++) terms[i] = Math.pow(Math.abs(arr10[i]), p);
|
|
2034
2034
|
return Math.pow(pairwiseSum(terms), 1 / p);
|
|
2035
2035
|
}
|
|
2036
2036
|
function matrixNorm(data, p = "fro") {
|
|
@@ -2071,9 +2071,9 @@ var norm = mathTyped2("norm", {
|
|
|
2071
2071
|
Complex: (a) => a.abs(),
|
|
2072
2072
|
BigNumber: (a) => a.abs(),
|
|
2073
2073
|
// Array: a flat vector uses the vector 2-norm; a 2-D array is a matrix (Frobenius).
|
|
2074
|
-
Array: (
|
|
2075
|
-
"Array, number": (
|
|
2076
|
-
"Array, string": (
|
|
2074
|
+
Array: (arr10) => is2DArray(arr10) ? matrixNorm(arr10) : vectorNorm(arr10),
|
|
2075
|
+
"Array, number": (arr10, p) => is2DArray(arr10) ? matrixNorm(arr10, p) : vectorNorm(arr10, p),
|
|
2076
|
+
"Array, string": (arr10, p) => matrixNorm(arr10, p),
|
|
2077
2077
|
// Matrix norms (mathjs parity): Frobenius / 1 / 2 / ∞.
|
|
2078
2078
|
DenseMatrix: (m) => matrixNorm(matrixLike(m)),
|
|
2079
2079
|
"DenseMatrix, number": (m, p) => matrixNorm(matrixLike(m), p),
|
|
@@ -2187,7 +2187,7 @@ var min = mathTyped2("min", {
|
|
|
2187
2187
|
"bigint, bigint": (a, b) => a < b ? a : b,
|
|
2188
2188
|
"Fraction, Fraction": (a, b) => a.compare(b) < 0 ? a : b,
|
|
2189
2189
|
"BigNumber, BigNumber": (a, b) => a.compare(b) < 0 ? a : b,
|
|
2190
|
-
Array: (
|
|
2190
|
+
Array: (arr10) => Math.min(...arr10),
|
|
2191
2191
|
number: (a) => a,
|
|
2192
2192
|
"number, number": (a, b) => Math.min(a, b),
|
|
2193
2193
|
"number, number, ...number": (a, b, rest) => Math.min(a, b, ...rest),
|
|
@@ -2206,7 +2206,7 @@ var max = mathTyped2("max", {
|
|
|
2206
2206
|
"bigint, bigint": (a, b) => a > b ? a : b,
|
|
2207
2207
|
"Fraction, Fraction": (a, b) => a.compare(b) > 0 ? a : b,
|
|
2208
2208
|
"BigNumber, BigNumber": (a, b) => a.compare(b) > 0 ? a : b,
|
|
2209
|
-
Array: (
|
|
2209
|
+
Array: (arr10) => Math.max(...arr10),
|
|
2210
2210
|
number: (a) => a,
|
|
2211
2211
|
"number, number": (a, b) => Math.max(a, b),
|
|
2212
2212
|
"number, number, ...number": (a, b, rest) => Math.max(a, b, ...rest),
|
|
@@ -2221,7 +2221,7 @@ var max = mathTyped2("max", {
|
|
|
2221
2221
|
}
|
|
2222
2222
|
});
|
|
2223
2223
|
var fsum = mathTyped2("fsum", {
|
|
2224
|
-
Array: (
|
|
2224
|
+
Array: (arr10) => neumaierSum(arr10),
|
|
2225
2225
|
Float64Array: (a) => neumaierSum(a)
|
|
2226
2226
|
});
|
|
2227
2227
|
var sum = mathTyped2("sum", {
|
|
@@ -2238,7 +2238,7 @@ var sum = mathTyped2("sum", {
|
|
|
2238
2238
|
// all inherit it. Pairwise costs the same number of additions — the naive loop was simply worse.
|
|
2239
2239
|
// For catastrophic cancellation (e.g. [1e16, 1, -1e16], which pairwise AND np.sum both
|
|
2240
2240
|
// annihilate to 0) use `fsum`.
|
|
2241
|
-
Array: (
|
|
2241
|
+
Array: (arr10) => pairwiseSum(arr10),
|
|
2242
2242
|
// Float64Array: the pool's sequential branch is pairwise too (see ComputePool.sum), and its
|
|
2243
2243
|
// parallel branch sums per-chunk then combines — blocked summation, which is pairwise-like.
|
|
2244
2244
|
// Either way the O(n) drift is gone.
|
|
@@ -2248,9 +2248,9 @@ var sum = mathTyped2("sum", {
|
|
|
2248
2248
|
}
|
|
2249
2249
|
});
|
|
2250
2250
|
var mean = mathTyped2("mean", {
|
|
2251
|
-
Array: (
|
|
2252
|
-
if (
|
|
2253
|
-
return pairwiseSum(
|
|
2251
|
+
Array: (arr10) => {
|
|
2252
|
+
if (arr10.length === 0) return NaN;
|
|
2253
|
+
return pairwiseSum(arr10) / arr10.length;
|
|
2254
2254
|
},
|
|
2255
2255
|
// Parallel Float64Array mean
|
|
2256
2256
|
Float64Array: async (a) => {
|
|
@@ -2270,12 +2270,12 @@ function varianceFromM2(m2, n, norm4) {
|
|
|
2270
2270
|
return n > 1 ? m2 / (n - 1) : 0;
|
|
2271
2271
|
}
|
|
2272
2272
|
}
|
|
2273
|
-
function m2OfArray(
|
|
2274
|
-
return sumSquaredDeviations(
|
|
2273
|
+
function m2OfArray(arr10) {
|
|
2274
|
+
return sumSquaredDeviations(arr10);
|
|
2275
2275
|
}
|
|
2276
2276
|
var variance = mathTyped2("variance", {
|
|
2277
|
-
Array: (
|
|
2278
|
-
"Array, string": (
|
|
2277
|
+
Array: (arr10) => varianceFromM2(m2OfArray(arr10), arr10.length, "unbiased"),
|
|
2278
|
+
"Array, string": (arr10, norm4) => varianceFromM2(m2OfArray(arr10), arr10.length, norm4),
|
|
2279
2279
|
// Parallel Float64Array variance. computePool returns POPULATION variance
|
|
2280
2280
|
// (sum2/n); recover sum2 = pop·n and renormalize for the requested convention.
|
|
2281
2281
|
Float64Array: async (a) => {
|
|
@@ -2288,8 +2288,8 @@ var variance = mathTyped2("variance", {
|
|
|
2288
2288
|
}
|
|
2289
2289
|
});
|
|
2290
2290
|
var std = mathTyped2("std", {
|
|
2291
|
-
Array: (
|
|
2292
|
-
"Array, string": (
|
|
2291
|
+
Array: (arr10) => Math.sqrt(varianceFromM2(m2OfArray(arr10), arr10.length, "unbiased")),
|
|
2292
|
+
"Array, string": (arr10, norm4) => Math.sqrt(varianceFromM2(m2OfArray(arr10), arr10.length, norm4)),
|
|
2293
2293
|
// Parallel Float64Array std — derive from the (renormalized) variance so the
|
|
2294
2294
|
// convention matches the Array path and parallelStatStd.
|
|
2295
2295
|
Float64Array: async (a) => {
|
|
@@ -2642,7 +2642,7 @@ var hypot = mathTyped3("hypot", {
|
|
|
2642
2642
|
number: (a) => Math.abs(a),
|
|
2643
2643
|
"number, number": (a, b) => Math.hypot(a, b),
|
|
2644
2644
|
"number, number, ...number": (a, b, rest) => Math.hypot(a, b, ...rest),
|
|
2645
|
-
Array: (
|
|
2645
|
+
Array: (arr10) => Math.hypot(...arr10)
|
|
2646
2646
|
});
|
|
2647
2647
|
var typedTrigonometry = {
|
|
2648
2648
|
// Basic
|
|
@@ -2673,8 +2673,8 @@ var typedTrigonometry = {
|
|
|
2673
2673
|
// src/typed/statistics.ts
|
|
2674
2674
|
import { mathTyped as mathTyped4, neumaierCumsum } from "@danielsimonjr/mathts-core";
|
|
2675
2675
|
import { computePool as computePool3 } from "@danielsimonjr/mathts-parallel";
|
|
2676
|
-
function toFloat64Array(
|
|
2677
|
-
return new Float64Array(
|
|
2676
|
+
function toFloat64Array(arr10) {
|
|
2677
|
+
return new Float64Array(arr10);
|
|
2678
2678
|
}
|
|
2679
2679
|
var parallelStatSum = mathTyped4("parallelStatSum", {
|
|
2680
2680
|
// Float64Array - parallel execution
|
|
@@ -2683,8 +2683,8 @@ var parallelStatSum = mathTyped4("parallelStatSum", {
|
|
|
2683
2683
|
return result.result;
|
|
2684
2684
|
},
|
|
2685
2685
|
// Number array
|
|
2686
|
-
Array: async (
|
|
2687
|
-
const data = toFloat64Array(
|
|
2686
|
+
Array: async (arr10) => {
|
|
2687
|
+
const data = toFloat64Array(arr10);
|
|
2688
2688
|
const result = await computePool3.sum(data);
|
|
2689
2689
|
return result.result;
|
|
2690
2690
|
},
|
|
@@ -2700,9 +2700,9 @@ var parallelStatMean = mathTyped4("parallelStatMean", {
|
|
|
2700
2700
|
return result.result;
|
|
2701
2701
|
},
|
|
2702
2702
|
// Number array - parallel execution
|
|
2703
|
-
Array: async (
|
|
2704
|
-
if (
|
|
2705
|
-
const data = toFloat64Array(
|
|
2703
|
+
Array: async (arr10) => {
|
|
2704
|
+
if (arr10.length === 0) return NaN;
|
|
2705
|
+
const data = toFloat64Array(arr10);
|
|
2706
2706
|
const result = await computePool3.mean(data);
|
|
2707
2707
|
return result.result;
|
|
2708
2708
|
},
|
|
@@ -2737,15 +2737,15 @@ var parallelStatVariance = mathTyped4("parallelStatVariance", {
|
|
|
2737
2737
|
}
|
|
2738
2738
|
},
|
|
2739
2739
|
// Number array
|
|
2740
|
-
Array: async (
|
|
2741
|
-
if (
|
|
2742
|
-
const data = toFloat64Array(
|
|
2740
|
+
Array: async (arr10) => {
|
|
2741
|
+
if (arr10.length === 0) return NaN;
|
|
2742
|
+
const data = toFloat64Array(arr10);
|
|
2743
2743
|
return parallelStatVariance(data);
|
|
2744
2744
|
},
|
|
2745
2745
|
// Number array with normalization
|
|
2746
|
-
"Array, string": async (
|
|
2747
|
-
if (
|
|
2748
|
-
const data = toFloat64Array(
|
|
2746
|
+
"Array, string": async (arr10, normalization) => {
|
|
2747
|
+
if (arr10.length === 0) return NaN;
|
|
2748
|
+
const data = toFloat64Array(arr10);
|
|
2749
2749
|
return parallelStatVariance(data, normalization);
|
|
2750
2750
|
},
|
|
2751
2751
|
// Variadic form
|
|
@@ -2772,15 +2772,15 @@ var parallelStatStd = mathTyped4("parallelStatStd", {
|
|
|
2772
2772
|
return Math.sqrt(variance2);
|
|
2773
2773
|
},
|
|
2774
2774
|
// Number array
|
|
2775
|
-
Array: async (
|
|
2776
|
-
if (
|
|
2777
|
-
const data = toFloat64Array(
|
|
2775
|
+
Array: async (arr10) => {
|
|
2776
|
+
if (arr10.length === 0) return NaN;
|
|
2777
|
+
const data = toFloat64Array(arr10);
|
|
2778
2778
|
return parallelStatStd(data);
|
|
2779
2779
|
},
|
|
2780
2780
|
// Number array with normalization
|
|
2781
|
-
"Array, string": async (
|
|
2782
|
-
if (
|
|
2783
|
-
const data = toFloat64Array(
|
|
2781
|
+
"Array, string": async (arr10, normalization) => {
|
|
2782
|
+
if (arr10.length === 0) return NaN;
|
|
2783
|
+
const data = toFloat64Array(arr10);
|
|
2784
2784
|
return parallelStatStd(data, normalization);
|
|
2785
2785
|
}
|
|
2786
2786
|
});
|
|
@@ -2791,9 +2791,9 @@ var parallelStatMin = mathTyped4("parallelStatMin", {
|
|
|
2791
2791
|
return result.result;
|
|
2792
2792
|
},
|
|
2793
2793
|
// Number array
|
|
2794
|
-
Array: async (
|
|
2795
|
-
if (
|
|
2796
|
-
const data = toFloat64Array(
|
|
2794
|
+
Array: async (arr10) => {
|
|
2795
|
+
if (arr10.length === 0) return Infinity;
|
|
2796
|
+
const data = toFloat64Array(arr10);
|
|
2797
2797
|
const result = await computePool3.min(data);
|
|
2798
2798
|
return result.result;
|
|
2799
2799
|
},
|
|
@@ -2811,9 +2811,9 @@ var parallelStatMax = mathTyped4("parallelStatMax", {
|
|
|
2811
2811
|
return result.result;
|
|
2812
2812
|
},
|
|
2813
2813
|
// Number array
|
|
2814
|
-
Array: async (
|
|
2815
|
-
if (
|
|
2816
|
-
const data = toFloat64Array(
|
|
2814
|
+
Array: async (arr10) => {
|
|
2815
|
+
if (arr10.length === 0) return -Infinity;
|
|
2816
|
+
const data = toFloat64Array(arr10);
|
|
2817
2817
|
const result = await computePool3.max(data);
|
|
2818
2818
|
return result.result;
|
|
2819
2819
|
},
|
|
@@ -2831,8 +2831,8 @@ var parallelStatMinMax = mathTyped4("parallelStatMinMax", {
|
|
|
2831
2831
|
return result.result;
|
|
2832
2832
|
},
|
|
2833
2833
|
// Number array
|
|
2834
|
-
Array: async (
|
|
2835
|
-
const data = toFloat64Array(
|
|
2834
|
+
Array: async (arr10) => {
|
|
2835
|
+
const data = toFloat64Array(arr10);
|
|
2836
2836
|
const result = await computePool3.minMax(data);
|
|
2837
2837
|
return result.result;
|
|
2838
2838
|
}
|
|
@@ -2852,25 +2852,25 @@ var parallelStatMedian = mathTyped4("parallelStatMedian", {
|
|
|
2852
2852
|
return sorted[mid];
|
|
2853
2853
|
},
|
|
2854
2854
|
// Number array
|
|
2855
|
-
Array: async (
|
|
2856
|
-
if (
|
|
2857
|
-
return parallelStatMedian(toFloat64Array(
|
|
2855
|
+
Array: async (arr10) => {
|
|
2856
|
+
if (arr10.length === 0) return NaN;
|
|
2857
|
+
return parallelStatMedian(toFloat64Array(arr10));
|
|
2858
2858
|
},
|
|
2859
2859
|
// Variadic form
|
|
2860
2860
|
"number, number": (a, b) => (a + b) / 2,
|
|
2861
2861
|
"number, number, number": (a, b, c) => {
|
|
2862
|
-
const
|
|
2863
|
-
return
|
|
2862
|
+
const arr10 = [a, b, c].sort((x, y) => x - y);
|
|
2863
|
+
return arr10[1];
|
|
2864
2864
|
}
|
|
2865
2865
|
});
|
|
2866
2866
|
var parallelStatMode = mathTyped4("parallelStatMode", {
|
|
2867
2867
|
// Number array
|
|
2868
|
-
Array: (
|
|
2869
|
-
if (
|
|
2868
|
+
Array: (arr10) => {
|
|
2869
|
+
if (arr10.length === 0) return [];
|
|
2870
2870
|
const counts = /* @__PURE__ */ new Map();
|
|
2871
2871
|
let maxCount = 0;
|
|
2872
|
-
for (let i = 0; i <
|
|
2873
|
-
const val =
|
|
2872
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
2873
|
+
const val = arr10[i];
|
|
2874
2874
|
const count2 = (counts.get(val) || 0) + 1;
|
|
2875
2875
|
counts.set(val, count2);
|
|
2876
2876
|
if (count2 > maxCount) maxCount = count2;
|
|
@@ -2888,11 +2888,11 @@ var parallelStatMode = mathTyped4("parallelStatMode", {
|
|
|
2888
2888
|
});
|
|
2889
2889
|
var parallelStatProd = mathTyped4("parallelStatProd", {
|
|
2890
2890
|
// Number array
|
|
2891
|
-
Array: (
|
|
2892
|
-
if (
|
|
2891
|
+
Array: (arr10) => {
|
|
2892
|
+
if (arr10.length === 0) return 1;
|
|
2893
2893
|
let prod2 = 1;
|
|
2894
|
-
for (let i = 0; i <
|
|
2895
|
-
prod2 *=
|
|
2894
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
2895
|
+
prod2 *= arr10[i];
|
|
2896
2896
|
}
|
|
2897
2897
|
return prod2;
|
|
2898
2898
|
},
|
|
@@ -2920,8 +2920,8 @@ var parallelStatNorm = mathTyped4("parallelStatNorm", {
|
|
|
2920
2920
|
return result.result;
|
|
2921
2921
|
},
|
|
2922
2922
|
// Number array
|
|
2923
|
-
Array: async (
|
|
2924
|
-
const data = toFloat64Array(
|
|
2923
|
+
Array: async (arr10) => {
|
|
2924
|
+
const data = toFloat64Array(arr10);
|
|
2925
2925
|
const result = await computePool3.norm(data);
|
|
2926
2926
|
return result.result;
|
|
2927
2927
|
},
|
|
@@ -2962,8 +2962,8 @@ var parallelStatNorm = mathTyped4("parallelStatNorm", {
|
|
|
2962
2962
|
}
|
|
2963
2963
|
},
|
|
2964
2964
|
// Number array with p-norm
|
|
2965
|
-
"Array, number": (
|
|
2966
|
-
return parallelStatNorm(toFloat64Array(
|
|
2965
|
+
"Array, number": (arr10, p) => {
|
|
2966
|
+
return parallelStatNorm(toFloat64Array(arr10), p);
|
|
2967
2967
|
}
|
|
2968
2968
|
});
|
|
2969
2969
|
var parallelStatDistance = mathTyped4("parallelStatDistance", {
|
|
@@ -3020,8 +3020,8 @@ var parallelStatMAD = mathTyped4("parallelStatMAD", {
|
|
|
3020
3020
|
return mad2 / n;
|
|
3021
3021
|
},
|
|
3022
3022
|
// Number array
|
|
3023
|
-
Array: async (
|
|
3024
|
-
return parallelStatMAD(toFloat64Array(
|
|
3023
|
+
Array: async (arr10) => {
|
|
3024
|
+
return parallelStatMAD(toFloat64Array(arr10));
|
|
3025
3025
|
}
|
|
3026
3026
|
});
|
|
3027
3027
|
var parallelStatCumsum = mathTyped4("parallelStatCumsum", {
|
|
@@ -3032,9 +3032,9 @@ var parallelStatCumsum = mathTyped4("parallelStatCumsum", {
|
|
|
3032
3032
|
return result;
|
|
3033
3033
|
},
|
|
3034
3034
|
// Number array
|
|
3035
|
-
Array: (
|
|
3036
|
-
const result = new Array(
|
|
3037
|
-
neumaierCumsum(
|
|
3035
|
+
Array: (arr10) => {
|
|
3036
|
+
const result = new Array(arr10.length);
|
|
3037
|
+
neumaierCumsum(arr10, result);
|
|
3038
3038
|
return result;
|
|
3039
3039
|
}
|
|
3040
3040
|
});
|
|
@@ -3056,8 +3056,8 @@ var parallelStatQuantile = mathTyped4("parallelStatQuantile", {
|
|
|
3056
3056
|
return sorted[lower] * (1 - frac) + sorted[upper] * frac;
|
|
3057
3057
|
},
|
|
3058
3058
|
// Number array
|
|
3059
|
-
"Array, number": (
|
|
3060
|
-
return parallelStatQuantile(toFloat64Array(
|
|
3059
|
+
"Array, number": (arr10, q) => {
|
|
3060
|
+
return parallelStatQuantile(toFloat64Array(arr10), q);
|
|
3061
3061
|
},
|
|
3062
3062
|
// Multiple quantiles
|
|
3063
3063
|
"Float64Array, Array": (data, quantiles) => {
|
|
@@ -3080,15 +3080,15 @@ var parallelStatHistogram = mathTyped4("parallelStatHistogram", {
|
|
|
3080
3080
|
return result.result;
|
|
3081
3081
|
},
|
|
3082
3082
|
// Number array
|
|
3083
|
-
"Array, number": async (
|
|
3084
|
-
return parallelStatHistogram(toFloat64Array(
|
|
3083
|
+
"Array, number": async (arr10, bins) => {
|
|
3084
|
+
return parallelStatHistogram(toFloat64Array(arr10), bins);
|
|
3085
3085
|
}
|
|
3086
3086
|
});
|
|
3087
|
-
function quickSelect(
|
|
3088
|
-
if (k < 0 || k >=
|
|
3089
|
-
throw new RangeError(`k=${k} is out of range for array of length ${
|
|
3087
|
+
function quickSelect(arr10, k) {
|
|
3088
|
+
if (k < 0 || k >= arr10.length) {
|
|
3089
|
+
throw new RangeError(`k=${k} is out of range for array of length ${arr10.length}`);
|
|
3090
3090
|
}
|
|
3091
|
-
const a =
|
|
3091
|
+
const a = arr10.slice();
|
|
3092
3092
|
return _quickSelect(a, 0, a.length - 1, k);
|
|
3093
3093
|
}
|
|
3094
3094
|
function _quickSelect(a, lo, hi, k) {
|
|
@@ -3131,32 +3131,32 @@ function _quickSelect(a, lo, hi, k) {
|
|
|
3131
3131
|
}
|
|
3132
3132
|
return a[lo];
|
|
3133
3133
|
}
|
|
3134
|
-
function medianSelect(
|
|
3135
|
-
const n =
|
|
3134
|
+
function medianSelect(arr10) {
|
|
3135
|
+
const n = arr10.length;
|
|
3136
3136
|
if (n === 0) return NaN;
|
|
3137
|
-
if (n === 1) return
|
|
3137
|
+
if (n === 1) return arr10[0];
|
|
3138
3138
|
const mid = Math.floor(n / 2);
|
|
3139
3139
|
if (n % 2 === 1) {
|
|
3140
|
-
return quickSelect(
|
|
3140
|
+
return quickSelect(arr10, mid);
|
|
3141
3141
|
}
|
|
3142
|
-
const a =
|
|
3142
|
+
const a = arr10.slice();
|
|
3143
3143
|
const lower = _quickSelect(a, 0, a.length - 1, mid - 1);
|
|
3144
3144
|
const upper = _quickSelect(a, 0, a.length - 1, mid);
|
|
3145
3145
|
return (lower + upper) / 2;
|
|
3146
3146
|
}
|
|
3147
|
-
function minSelect(
|
|
3147
|
+
function minSelect(arr10, k) {
|
|
3148
3148
|
if (k <= 0) return [];
|
|
3149
|
-
if (k >=
|
|
3150
|
-
const a =
|
|
3149
|
+
if (k >= arr10.length) return arr10.slice().sort((a2, b) => a2 - b);
|
|
3150
|
+
const a = arr10.slice();
|
|
3151
3151
|
_quickSelect(a, 0, a.length - 1, k - 1);
|
|
3152
3152
|
const result = a.slice(0, k);
|
|
3153
3153
|
result.sort((x, y) => x - y);
|
|
3154
3154
|
return result;
|
|
3155
3155
|
}
|
|
3156
|
-
function maxSelect(
|
|
3156
|
+
function maxSelect(arr10, k) {
|
|
3157
3157
|
if (k <= 0) return [];
|
|
3158
|
-
if (k >=
|
|
3159
|
-
const a =
|
|
3158
|
+
if (k >= arr10.length) return arr10.slice().sort((a2, b) => b - a2);
|
|
3159
|
+
const a = arr10.slice();
|
|
3160
3160
|
const pivot = a.length - k;
|
|
3161
3161
|
_quickSelect(a, 0, a.length - 1, pivot);
|
|
3162
3162
|
const result = a.slice(pivot);
|
|
@@ -5110,8 +5110,8 @@ var typedLogical = {
|
|
|
5110
5110
|
|
|
5111
5111
|
// src/typed/complex.ts
|
|
5112
5112
|
import { mathTyped as mathTyped8, BigNumber as BigNumber5 } from "@danielsimonjr/mathts-core";
|
|
5113
|
-
function deepMapArray(
|
|
5114
|
-
return
|
|
5113
|
+
function deepMapArray(arr10, fn) {
|
|
5114
|
+
return arr10.map(
|
|
5115
5115
|
(item) => Array.isArray(item) ? deepMapArray(item, fn) : fn(item)
|
|
5116
5116
|
);
|
|
5117
5117
|
}
|
|
@@ -5161,9 +5161,9 @@ var typedComplex = {
|
|
|
5161
5161
|
|
|
5162
5162
|
// src/typed/set.ts
|
|
5163
5163
|
import { mathTyped as mathTyped9 } from "@danielsimonjr/mathts-core";
|
|
5164
|
-
function flattenArray(
|
|
5164
|
+
function flattenArray(arr10) {
|
|
5165
5165
|
const result = [];
|
|
5166
|
-
const stack = [...
|
|
5166
|
+
const stack = [...arr10];
|
|
5167
5167
|
while (stack.length > 0) {
|
|
5168
5168
|
const item = stack.shift();
|
|
5169
5169
|
if (Array.isArray(item)) {
|
|
@@ -9894,11 +9894,11 @@ function discriminant(coeffs) {
|
|
|
9894
9894
|
const sign3 = deg * (deg - 1) / 2 % 2 === 0 ? 1 : -1;
|
|
9895
9895
|
return sign3 * res / an;
|
|
9896
9896
|
}
|
|
9897
|
-
function differences(
|
|
9897
|
+
function differences(arr10, n = 1) {
|
|
9898
9898
|
if (n < 0 || !Number.isInteger(n)) {
|
|
9899
9899
|
throw new Error("Difference order must be a non-negative integer");
|
|
9900
9900
|
}
|
|
9901
|
-
let result = [...
|
|
9901
|
+
let result = [...arr10];
|
|
9902
9902
|
for (let k = 0; k < n; k++) {
|
|
9903
9903
|
if (result.length <= 1) return [];
|
|
9904
9904
|
const next = new Array(result.length - 1);
|
|
@@ -10167,11 +10167,11 @@ function fullSimplify(expr) {
|
|
|
10167
10167
|
result = reduce(result);
|
|
10168
10168
|
return result;
|
|
10169
10169
|
}
|
|
10170
|
-
function element(
|
|
10171
|
-
if (index < 0 || index >=
|
|
10172
|
-
throw new Error("Index " + index + " out of bounds for array of length " +
|
|
10170
|
+
function element(arr10, index) {
|
|
10171
|
+
if (index < 0 || index >= arr10.length) {
|
|
10172
|
+
throw new Error("Index " + index + " out of bounds for array of length " + arr10.length);
|
|
10173
10173
|
}
|
|
10174
|
-
return
|
|
10174
|
+
return arr10[index];
|
|
10175
10175
|
}
|
|
10176
10176
|
function eliminate(system, variable) {
|
|
10177
10177
|
const symbols = /* @__PURE__ */ new Set();
|
|
@@ -11549,22 +11549,22 @@ var createSolveODE = /* @__PURE__ */ factory(
|
|
|
11549
11549
|
const stageAlloc = wasmLoader.allocateFloat64ArrayEmpty(numStages * dim);
|
|
11550
11550
|
try {
|
|
11551
11551
|
let readVec2 = function(alloc) {
|
|
11552
|
-
const
|
|
11552
|
+
const arr10 = new Float64Array(wasm.memory.buffer, alloc.ptr, dim);
|
|
11553
11553
|
const result = new Array(dim);
|
|
11554
11554
|
for (let i = 0; i < dim; i++) {
|
|
11555
|
-
result[i] =
|
|
11555
|
+
result[i] = arr10[i];
|
|
11556
11556
|
}
|
|
11557
11557
|
return result;
|
|
11558
11558
|
}, writeVec2 = function(alloc, data) {
|
|
11559
|
-
const
|
|
11559
|
+
const arr10 = new Float64Array(wasm.memory.buffer, alloc.ptr, dim);
|
|
11560
11560
|
for (let i = 0; i < dim; i++) {
|
|
11561
|
-
|
|
11561
|
+
arr10[i] = data[i];
|
|
11562
11562
|
}
|
|
11563
11563
|
}, writeStage2 = function(stageIdx, data) {
|
|
11564
11564
|
const offset = stageIdx * dim;
|
|
11565
|
-
const
|
|
11565
|
+
const arr10 = new Float64Array(wasm.memory.buffer, stageAlloc.ptr, numStages * dim);
|
|
11566
11566
|
for (let i = 0; i < dim; i++) {
|
|
11567
|
-
|
|
11567
|
+
arr10[offset + i] = data[i];
|
|
11568
11568
|
}
|
|
11569
11569
|
}, trimStepNum2 = function(tn, tfn, hn) {
|
|
11570
11570
|
const next = tn + hn;
|
|
@@ -12960,7 +12960,7 @@ function nullspace(A) {
|
|
|
12960
12960
|
}
|
|
12961
12961
|
function residue(p, q) {
|
|
12962
12962
|
const poles = polyRoots(q);
|
|
12963
|
-
function
|
|
12963
|
+
function evalPoly2(coeffs, x) {
|
|
12964
12964
|
let s = 0;
|
|
12965
12965
|
for (let i = coeffs.length - 1; i >= 0; i--) {
|
|
12966
12966
|
s = s * x + coeffs[i];
|
|
@@ -12974,7 +12974,7 @@ function residue(p, q) {
|
|
|
12974
12974
|
}
|
|
12975
12975
|
return s;
|
|
12976
12976
|
}
|
|
12977
|
-
const residues = poles.map((pole) =>
|
|
12977
|
+
const residues = poles.map((pole) => evalPoly2(p, pole) / evalPolyDeriv(q, pole));
|
|
12978
12978
|
return { residues, poles };
|
|
12979
12979
|
}
|
|
12980
12980
|
function polyRoots(coeffs) {
|
|
@@ -15509,12 +15509,12 @@ function _makeMulberry322(seed) {
|
|
|
15509
15509
|
return z / 4294967296;
|
|
15510
15510
|
};
|
|
15511
15511
|
}
|
|
15512
|
-
function _shuffle(
|
|
15513
|
-
for (let i =
|
|
15512
|
+
function _shuffle(arr10, rng) {
|
|
15513
|
+
for (let i = arr10.length - 1; i > 0; i--) {
|
|
15514
15514
|
const j = Math.floor(rng() * (i + 1));
|
|
15515
|
-
const tmp =
|
|
15516
|
-
|
|
15517
|
-
|
|
15515
|
+
const tmp = arr10[i];
|
|
15516
|
+
arr10[i] = arr10[j];
|
|
15517
|
+
arr10[j] = tmp;
|
|
15518
15518
|
}
|
|
15519
15519
|
}
|
|
15520
15520
|
function _bootstrapSummary(stats) {
|
|
@@ -15528,16 +15528,16 @@ function _bootstrapSummary(stats) {
|
|
|
15528
15528
|
const std2 = n > 1 ? Math.sqrt(sq / (n - 1)) : 0;
|
|
15529
15529
|
return { bootstrapMean: mean7, bootstrapStd: std2 };
|
|
15530
15530
|
}
|
|
15531
|
-
function _mean(
|
|
15531
|
+
function _mean(arr10) {
|
|
15532
15532
|
let sum3 = 0;
|
|
15533
|
-
for (let i = 0; i <
|
|
15534
|
-
return sum3 /
|
|
15533
|
+
for (let i = 0; i < arr10.length; i++) sum3 += arr10[i];
|
|
15534
|
+
return sum3 / arr10.length;
|
|
15535
15535
|
}
|
|
15536
|
-
function _variance(
|
|
15537
|
-
const m = _mean(
|
|
15536
|
+
function _variance(arr10, ddof = 1) {
|
|
15537
|
+
const m = _mean(arr10);
|
|
15538
15538
|
let sum3 = 0;
|
|
15539
|
-
for (let i = 0; i <
|
|
15540
|
-
return sum3 / (
|
|
15539
|
+
for (let i = 0; i < arr10.length; i++) sum3 += (arr10[i] - m) ** 2;
|
|
15540
|
+
return sum3 / (arr10.length - ddof);
|
|
15541
15541
|
}
|
|
15542
15542
|
function _erf(x) {
|
|
15543
15543
|
if (x === 0) return 0;
|
|
@@ -15928,9 +15928,9 @@ function _mwUCounts(n16, n26) {
|
|
|
15928
15928
|
const row2 = [];
|
|
15929
15929
|
for (let j = 0; j <= n26; j++) {
|
|
15930
15930
|
const maxU = i * j;
|
|
15931
|
-
const
|
|
15931
|
+
const arr10 = new Float64Array(maxU + 1);
|
|
15932
15932
|
if (i === 0 || j === 0) {
|
|
15933
|
-
|
|
15933
|
+
arr10[0] = 1;
|
|
15934
15934
|
} else {
|
|
15935
15935
|
const prevI = table[i - 1][j];
|
|
15936
15936
|
const prevJ = row2[j - 1];
|
|
@@ -15939,10 +15939,10 @@ function _mwUCounts(n16, n26) {
|
|
|
15939
15939
|
const uShift = u - j;
|
|
15940
15940
|
if (uShift >= 0 && uShift < prevI.length) val += prevI[uShift];
|
|
15941
15941
|
if (u < prevJ.length) val += prevJ[u];
|
|
15942
|
-
|
|
15942
|
+
arr10[u] = val;
|
|
15943
15943
|
}
|
|
15944
15944
|
}
|
|
15945
|
-
row2.push(
|
|
15945
|
+
row2.push(arr10);
|
|
15946
15946
|
}
|
|
15947
15947
|
table.push(row2);
|
|
15948
15948
|
}
|
|
@@ -16359,8 +16359,8 @@ function kolmogorovSmirnov2Test(sample1, sample2, opts) {
|
|
|
16359
16359
|
const en = Math.sqrt(n16 * n26 / (n16 + n26));
|
|
16360
16360
|
return { statistic: d, pValue: _kstwobignSf(en * d) };
|
|
16361
16361
|
}
|
|
16362
|
-
function _median(
|
|
16363
|
-
const s =
|
|
16362
|
+
function _median(arr10) {
|
|
16363
|
+
const s = arr10.slice().sort((a, b) => a - b);
|
|
16364
16364
|
const n = s.length;
|
|
16365
16365
|
const m = n >> 1;
|
|
16366
16366
|
return n % 2 === 1 ? s[m] : (s[m - 1] + s[m]) / 2;
|
|
@@ -18150,19 +18150,19 @@ var randomInt = mathTyped16("randomInt", {
|
|
|
18150
18150
|
}
|
|
18151
18151
|
});
|
|
18152
18152
|
var pickRandom = mathTyped16("pickRandom", {
|
|
18153
|
-
Array: (
|
|
18154
|
-
"Array, number": (
|
|
18155
|
-
"Array, Array": (
|
|
18156
|
-
"Array, number, Array": (
|
|
18157
|
-
"Array, Array, number": (
|
|
18153
|
+
Array: (arr10) => _pick(arr10, 1, void 0)[0],
|
|
18154
|
+
"Array, number": (arr10, n) => _pick(arr10, n, void 0),
|
|
18155
|
+
"Array, Array": (arr10, weights) => _pick(arr10, 1, weights)[0],
|
|
18156
|
+
"Array, number, Array": (arr10, n, weights) => _pick(arr10, n, weights),
|
|
18157
|
+
"Array, Array, number": (arr10, weights, n) => _pick(arr10, n, weights)
|
|
18158
18158
|
});
|
|
18159
|
-
function _pick(
|
|
18160
|
-
if (
|
|
18159
|
+
function _pick(arr10, n, weights) {
|
|
18160
|
+
if (arr10.length === 0) throw new RangeError("Cannot pick from an empty array");
|
|
18161
18161
|
if (!Number.isInteger(n) || n < 1) {
|
|
18162
18162
|
throw new RangeError("number of picks must be a positive integer");
|
|
18163
18163
|
}
|
|
18164
18164
|
if (weights !== void 0) {
|
|
18165
|
-
if (weights.length !==
|
|
18165
|
+
if (weights.length !== arr10.length) {
|
|
18166
18166
|
throw new RangeError("weights must have the same length as the array");
|
|
18167
18167
|
}
|
|
18168
18168
|
let total = 0;
|
|
@@ -18176,20 +18176,20 @@ function _pick(arr8, n, weights) {
|
|
|
18176
18176
|
const result2 = [];
|
|
18177
18177
|
for (let i = 0; i < n; i++) {
|
|
18178
18178
|
let r = _rng() * total;
|
|
18179
|
-
for (let j = 0; j <
|
|
18179
|
+
for (let j = 0; j < arr10.length; j++) {
|
|
18180
18180
|
r -= weights[j];
|
|
18181
18181
|
if (r < 0) {
|
|
18182
|
-
result2.push(
|
|
18182
|
+
result2.push(arr10[j]);
|
|
18183
18183
|
break;
|
|
18184
18184
|
}
|
|
18185
18185
|
}
|
|
18186
|
-
if (result2.length < i + 1) result2.push(
|
|
18186
|
+
if (result2.length < i + 1) result2.push(arr10[arr10.length - 1]);
|
|
18187
18187
|
}
|
|
18188
18188
|
return result2;
|
|
18189
18189
|
}
|
|
18190
18190
|
const result = [];
|
|
18191
18191
|
for (let i = 0; i < n; i++) {
|
|
18192
|
-
result.push(
|
|
18192
|
+
result.push(arr10[Math.floor(_rng() * arr10.length)]);
|
|
18193
18193
|
}
|
|
18194
18194
|
return result;
|
|
18195
18195
|
}
|
|
@@ -18841,13 +18841,13 @@ function resize(array, size2, defaultValue) {
|
|
|
18841
18841
|
);
|
|
18842
18842
|
}
|
|
18843
18843
|
});
|
|
18844
|
-
let
|
|
18844
|
+
let arr10 = array;
|
|
18845
18845
|
if (isNumber(array) || isBigNumber(array)) {
|
|
18846
|
-
|
|
18846
|
+
arr10 = [array];
|
|
18847
18847
|
}
|
|
18848
18848
|
const _defaultValue = defaultValue !== void 0 ? defaultValue : 0;
|
|
18849
|
-
_resize(
|
|
18850
|
-
return
|
|
18849
|
+
_resize(arr10, size2, 0, _defaultValue);
|
|
18850
|
+
return arr10;
|
|
18851
18851
|
}
|
|
18852
18852
|
function _resize(array, size2, dim, defaultValue) {
|
|
18853
18853
|
let i;
|
|
@@ -18948,9 +18948,9 @@ function _reshape(array, sizes) {
|
|
|
18948
18948
|
}
|
|
18949
18949
|
function squeeze(array, size2) {
|
|
18950
18950
|
const s = size2 || arraySize(array);
|
|
18951
|
-
let
|
|
18952
|
-
while (Array.isArray(
|
|
18953
|
-
|
|
18951
|
+
let arr10 = array;
|
|
18952
|
+
while (Array.isArray(arr10) && arr10.length === 1) {
|
|
18953
|
+
arr10 = arr10[0];
|
|
18954
18954
|
s.shift();
|
|
18955
18955
|
}
|
|
18956
18956
|
let dims = s.length;
|
|
@@ -18958,19 +18958,19 @@ function squeeze(array, size2) {
|
|
|
18958
18958
|
dims--;
|
|
18959
18959
|
}
|
|
18960
18960
|
if (dims < s.length) {
|
|
18961
|
-
|
|
18961
|
+
arr10 = _squeeze(arr10, dims, 0);
|
|
18962
18962
|
s.length = dims;
|
|
18963
18963
|
}
|
|
18964
|
-
return
|
|
18964
|
+
return arr10;
|
|
18965
18965
|
}
|
|
18966
18966
|
function _squeeze(array, dims, dim) {
|
|
18967
18967
|
if (dim < dims) {
|
|
18968
18968
|
const next = dim + 1;
|
|
18969
|
-
const
|
|
18970
|
-
for (let i = 0, ii =
|
|
18971
|
-
|
|
18969
|
+
const arr10 = array;
|
|
18970
|
+
for (let i = 0, ii = arr10.length; i < ii; i++) {
|
|
18971
|
+
arr10[i] = _squeeze(arr10[i], dims, next);
|
|
18972
18972
|
}
|
|
18973
|
-
return
|
|
18973
|
+
return arr10;
|
|
18974
18974
|
} else {
|
|
18975
18975
|
let result = array;
|
|
18976
18976
|
while (Array.isArray(result)) {
|
|
@@ -18993,9 +18993,9 @@ function flatten2(array, isRectangular = false) {
|
|
|
18993
18993
|
_flatten(array);
|
|
18994
18994
|
}
|
|
18995
18995
|
return flat;
|
|
18996
|
-
function _flatten(
|
|
18997
|
-
for (let i = 0; i <
|
|
18998
|
-
const item =
|
|
18996
|
+
function _flatten(arr10) {
|
|
18997
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
18998
|
+
const item = arr10[i];
|
|
18999
18999
|
if (Array.isArray(item)) {
|
|
19000
19000
|
_flatten(item);
|
|
19001
19001
|
} else {
|
|
@@ -19003,14 +19003,14 @@ function flatten2(array, isRectangular = false) {
|
|
|
19003
19003
|
}
|
|
19004
19004
|
}
|
|
19005
19005
|
}
|
|
19006
|
-
function _flattenRectangular(
|
|
19007
|
-
if (Array.isArray(
|
|
19008
|
-
for (let i = 0; i <
|
|
19009
|
-
_flattenRectangular(
|
|
19006
|
+
function _flattenRectangular(arr10) {
|
|
19007
|
+
if (Array.isArray(arr10[0])) {
|
|
19008
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
19009
|
+
_flattenRectangular(arr10[i]);
|
|
19010
19010
|
}
|
|
19011
19011
|
} else {
|
|
19012
|
-
for (let i = 0; i <
|
|
19013
|
-
flat.push(
|
|
19012
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
19013
|
+
flat.push(arr10[i]);
|
|
19014
19014
|
}
|
|
19015
19015
|
}
|
|
19016
19016
|
}
|
|
@@ -19506,12 +19506,12 @@ var dependencies6 = ["typed", "Complex"];
|
|
|
19506
19506
|
var createExpm1 = /* @__PURE__ */ factory(
|
|
19507
19507
|
name6,
|
|
19508
19508
|
dependencies6,
|
|
19509
|
-
({ typed: typed3, Complex:
|
|
19509
|
+
({ typed: typed3, Complex: Complex13 }) => {
|
|
19510
19510
|
return typed3(name6, {
|
|
19511
19511
|
number: expm1Number,
|
|
19512
19512
|
Complex: function(x) {
|
|
19513
19513
|
const r = Math.exp(x.re);
|
|
19514
|
-
return new
|
|
19514
|
+
return new Complex13(r * Math.cos(x.im) - 1, r * Math.sin(x.im));
|
|
19515
19515
|
},
|
|
19516
19516
|
BigNumber: function(x) {
|
|
19517
19517
|
return x.exp().minus(1);
|
|
@@ -19540,12 +19540,12 @@ var log16 = log10Number(16);
|
|
|
19540
19540
|
var createLog10 = /* @__PURE__ */ factory(
|
|
19541
19541
|
name7,
|
|
19542
19542
|
dependencies7,
|
|
19543
|
-
({ typed: typed3, config: config2, Complex:
|
|
19543
|
+
({ typed: typed3, config: config2, Complex: Complex13 }) => {
|
|
19544
19544
|
function complexLog(c) {
|
|
19545
19545
|
return c.log().div(Math.LN10);
|
|
19546
19546
|
}
|
|
19547
19547
|
function complexLogNumber(x) {
|
|
19548
|
-
return complexLog(new
|
|
19548
|
+
return complexLog(new Complex13(x, 0));
|
|
19549
19549
|
}
|
|
19550
19550
|
return typed3(name7, {
|
|
19551
19551
|
number: function(x) {
|
|
@@ -19577,9 +19577,9 @@ var dependencies8 = ["typed", "config", "Complex"];
|
|
|
19577
19577
|
var createLog2 = /* @__PURE__ */ factory(
|
|
19578
19578
|
name8,
|
|
19579
19579
|
dependencies8,
|
|
19580
|
-
({ typed: typed3, config: config2, Complex:
|
|
19580
|
+
({ typed: typed3, config: config2, Complex: Complex13 }) => {
|
|
19581
19581
|
function complexLog2Number(x) {
|
|
19582
|
-
return _log2Complex(new
|
|
19582
|
+
return _log2Complex(new Complex13(x, 0));
|
|
19583
19583
|
}
|
|
19584
19584
|
return typed3(name8, {
|
|
19585
19585
|
number: function(x) {
|
|
@@ -19604,7 +19604,7 @@ var createLog2 = /* @__PURE__ */ factory(
|
|
|
19604
19604
|
});
|
|
19605
19605
|
function _log2Complex(x) {
|
|
19606
19606
|
const newX = Math.sqrt(x.re * x.re + x.im * x.im);
|
|
19607
|
-
return new
|
|
19607
|
+
return new Complex13(
|
|
19608
19608
|
Math.log2 ? Math.log2(newX) : Math.log(newX) / Math.LN2,
|
|
19609
19609
|
Math.atan2(x.im, x.re) / Math.LN2
|
|
19610
19610
|
);
|
|
@@ -19645,11 +19645,11 @@ var dependencies10 = ["typed", "BigNumber", "complex", "Fraction"];
|
|
|
19645
19645
|
var createSign = /* @__PURE__ */ factory(
|
|
19646
19646
|
name10,
|
|
19647
19647
|
dependencies10,
|
|
19648
|
-
({ typed: typed3, BigNumber: BigNumber9, complex:
|
|
19648
|
+
({ typed: typed3, BigNumber: BigNumber9, complex: complex3, Fraction: Fraction5 }) => {
|
|
19649
19649
|
return typed3(name10, {
|
|
19650
19650
|
number: signNumber,
|
|
19651
19651
|
Complex: function(x) {
|
|
19652
|
-
return x.im === 0 ?
|
|
19652
|
+
return x.im === 0 ? complex3(signNumber(x.re)) : x.sign();
|
|
19653
19653
|
},
|
|
19654
19654
|
BigNumber: function(x) {
|
|
19655
19655
|
return new BigNumber9(x.cmp(0));
|
|
@@ -19680,7 +19680,7 @@ var dependencies11 = ["config", "typed", "Complex"];
|
|
|
19680
19680
|
var createSqrt = /* @__PURE__ */ factory(
|
|
19681
19681
|
name11,
|
|
19682
19682
|
dependencies11,
|
|
19683
|
-
({ config: config2, typed: typed3, Complex:
|
|
19683
|
+
({ config: config2, typed: typed3, Complex: Complex13 }) => {
|
|
19684
19684
|
return typed3("sqrt", {
|
|
19685
19685
|
number: _sqrtNumber,
|
|
19686
19686
|
Complex: function(x) {
|
|
@@ -19703,7 +19703,7 @@ var createSqrt = /* @__PURE__ */ factory(
|
|
|
19703
19703
|
} else if (x >= 0 || config2.predictable) {
|
|
19704
19704
|
return Math.sqrt(x);
|
|
19705
19705
|
} else {
|
|
19706
|
-
return new
|
|
19706
|
+
return new Complex13(x, 0).sqrt();
|
|
19707
19707
|
}
|
|
19708
19708
|
}
|
|
19709
19709
|
}
|
|
@@ -19990,24 +19990,24 @@ function decCoefficientToBinaryString(x) {
|
|
|
19990
19990
|
str = str.slice(0, xe) + "." + str.slice(xe);
|
|
19991
19991
|
}
|
|
19992
19992
|
}
|
|
19993
|
-
const
|
|
19993
|
+
const arr10 = [0];
|
|
19994
19994
|
for (let i = 0; i < str.length; ) {
|
|
19995
|
-
let arrL =
|
|
19995
|
+
let arrL = arr10.length;
|
|
19996
19996
|
while (arrL--) {
|
|
19997
|
-
|
|
19997
|
+
arr10[arrL] *= 10;
|
|
19998
19998
|
}
|
|
19999
|
-
|
|
20000
|
-
for (let j2 = 0; j2 <
|
|
20001
|
-
if (
|
|
20002
|
-
if (
|
|
20003
|
-
|
|
19999
|
+
arr10[0] += parseInt(str.charAt(i++));
|
|
20000
|
+
for (let j2 = 0; j2 < arr10.length; ++j2) {
|
|
20001
|
+
if (arr10[j2] > 1) {
|
|
20002
|
+
if (arr10[j2 + 1] === null || arr10[j2 + 1] === void 0) {
|
|
20003
|
+
arr10[j2 + 1] = 0;
|
|
20004
20004
|
}
|
|
20005
|
-
|
|
20006
|
-
|
|
20005
|
+
arr10[j2 + 1] += arr10[j2] >> 1;
|
|
20006
|
+
arr10[j2] &= 1;
|
|
20007
20007
|
}
|
|
20008
20008
|
}
|
|
20009
20009
|
}
|
|
20010
|
-
return
|
|
20010
|
+
return arr10.reverse();
|
|
20011
20011
|
}
|
|
20012
20012
|
function bitXor2(x, y) {
|
|
20013
20013
|
if (x.isFinite() && !x.isInteger() || y.isFinite() && !y.isInteger()) {
|
|
@@ -20507,8 +20507,8 @@ var createMap = /* @__PURE__ */ factory(
|
|
|
20507
20507
|
if (index) index[depth] = i;
|
|
20508
20508
|
result[i] = iterate(
|
|
20509
20509
|
arrays2.map((array, arrayIndex) => {
|
|
20510
|
-
const
|
|
20511
|
-
return offsets[arrayIndex] > depth ? array :
|
|
20510
|
+
const arr10 = array;
|
|
20511
|
+
return offsets[arrayIndex] > depth ? array : arr10.length === 1 ? arr10[0] : arr10[i];
|
|
20512
20512
|
}),
|
|
20513
20513
|
depth + 1
|
|
20514
20514
|
);
|
|
@@ -20518,8 +20518,8 @@ var createMap = /* @__PURE__ */ factory(
|
|
|
20518
20518
|
if (index) index[depth] = i;
|
|
20519
20519
|
result[i] = callback(
|
|
20520
20520
|
arrays2.map((a) => {
|
|
20521
|
-
const
|
|
20522
|
-
return
|
|
20521
|
+
const arr10 = a;
|
|
20522
|
+
return arr10.length === 1 ? arr10[0] : arr10[i];
|
|
20523
20523
|
}),
|
|
20524
20524
|
index ? index.slice() : void 0
|
|
20525
20525
|
);
|
|
@@ -20715,7 +20715,7 @@ var dependencies30 = ["Complex", "typed"];
|
|
|
20715
20715
|
var createLgamma = /* @__PURE__ */ factory(
|
|
20716
20716
|
name30,
|
|
20717
20717
|
dependencies30,
|
|
20718
|
-
({ Complex:
|
|
20718
|
+
({ Complex: Complex13, typed: typed3 }) => {
|
|
20719
20719
|
const SMALL_RE = 7;
|
|
20720
20720
|
const SMALL_IM = 7;
|
|
20721
20721
|
const coeffs = [
|
|
@@ -20729,15 +20729,15 @@ var createLgamma = /* @__PURE__ */ factory(
|
|
|
20729
20729
|
0.08333333333333333
|
|
20730
20730
|
];
|
|
20731
20731
|
return typed3(name30, {
|
|
20732
|
-
Array: function(
|
|
20732
|
+
Array: function(arr10) {
|
|
20733
20733
|
const wasm = wasmLoader.getModule();
|
|
20734
|
-
if (wasm &&
|
|
20734
|
+
if (wasm && arr10.length >= 100 && arr10.every((x) => typeof x === "number")) {
|
|
20735
20735
|
try {
|
|
20736
|
-
const input = new Float64Array(
|
|
20736
|
+
const input = new Float64Array(arr10);
|
|
20737
20737
|
const inputAlloc = wasmLoader.allocateFloat64Array(input);
|
|
20738
|
-
const resultAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
20738
|
+
const resultAlloc = wasmLoader.allocateFloat64ArrayEmpty(arr10.length);
|
|
20739
20739
|
try {
|
|
20740
|
-
wasm.lgammaArray(inputAlloc.ptr,
|
|
20740
|
+
wasm.lgammaArray(inputAlloc.ptr, arr10.length, resultAlloc.ptr);
|
|
20741
20741
|
return Array.from(resultAlloc.array);
|
|
20742
20742
|
} finally {
|
|
20743
20743
|
wasmLoader.free(inputAlloc.ptr);
|
|
@@ -20746,7 +20746,7 @@ var createLgamma = /* @__PURE__ */ factory(
|
|
|
20746
20746
|
} catch {
|
|
20747
20747
|
}
|
|
20748
20748
|
}
|
|
20749
|
-
return
|
|
20749
|
+
return arr10.map((x) => lgammaNumber(x));
|
|
20750
20750
|
},
|
|
20751
20751
|
number: lgammaNumber,
|
|
20752
20752
|
Complex: lgammaComplex2,
|
|
@@ -20761,16 +20761,16 @@ var createLgamma = /* @__PURE__ */ factory(
|
|
|
20761
20761
|
const LOGPI = 1.1447298858494002;
|
|
20762
20762
|
const REFLECTION = 0.1;
|
|
20763
20763
|
if (n.isNaN()) {
|
|
20764
|
-
return new
|
|
20764
|
+
return new Complex13(NaN, NaN);
|
|
20765
20765
|
} else if (n.im === 0) {
|
|
20766
|
-
return new
|
|
20766
|
+
return new Complex13(lgammaNumber(n.re), 0);
|
|
20767
20767
|
} else if (n.re >= SMALL_RE || Math.abs(n.im) >= SMALL_IM) {
|
|
20768
20768
|
return lgammaStirling(n);
|
|
20769
20769
|
} else if (n.re <= REFLECTION) {
|
|
20770
20770
|
const tmp = copysign(TWOPI, n.im) * Math.floor(0.5 * n.re + 0.25);
|
|
20771
20771
|
const a = n.mul(Math.PI).sin().log();
|
|
20772
|
-
const b = lgammaComplex2(new
|
|
20773
|
-
return new
|
|
20772
|
+
const b = lgammaComplex2(new Complex13(1 - n.re, -n.im));
|
|
20773
|
+
return new Complex13(LOGPI, tmp).sub(a).sub(b);
|
|
20774
20774
|
} else if (n.im >= 0) {
|
|
20775
20775
|
return lgammaRecurrence(n);
|
|
20776
20776
|
} else {
|
|
@@ -20779,7 +20779,7 @@ var createLgamma = /* @__PURE__ */ factory(
|
|
|
20779
20779
|
}
|
|
20780
20780
|
function lgammaStirling(z) {
|
|
20781
20781
|
const leftPart = z.sub(0.5).mul(z.log()).sub(z).add(lnSqrt2PI);
|
|
20782
|
-
const rz = new
|
|
20782
|
+
const rz = new Complex13(1, 0).div(z);
|
|
20783
20783
|
const rzz = rz.div(z);
|
|
20784
20784
|
let a = coeffs[0];
|
|
20785
20785
|
let b = coeffs[1];
|
|
@@ -20805,7 +20805,7 @@ var createLgamma = /* @__PURE__ */ factory(
|
|
|
20805
20805
|
sb = nsb;
|
|
20806
20806
|
z = z.add(1);
|
|
20807
20807
|
}
|
|
20808
|
-
return lgammaStirling(z).sub(shiftprod.log()).sub(new
|
|
20808
|
+
return lgammaStirling(z).sub(shiftprod.log()).sub(new Complex13(0, signflips * 2 * Math.PI * 1));
|
|
20809
20809
|
}
|
|
20810
20810
|
}
|
|
20811
20811
|
);
|
|
@@ -21243,13 +21243,13 @@ var dependencies37 = ["typed", "config", "Complex"];
|
|
|
21243
21243
|
var createAcos = /* @__PURE__ */ factory(
|
|
21244
21244
|
name37,
|
|
21245
21245
|
dependencies37,
|
|
21246
|
-
({ typed: typed3, config: config2, Complex:
|
|
21246
|
+
({ typed: typed3, config: config2, Complex: Complex13 }) => {
|
|
21247
21247
|
return typed3(name37, {
|
|
21248
21248
|
number: function(x) {
|
|
21249
21249
|
if (x >= -1 && x <= 1 || config2.predictable) {
|
|
21250
21250
|
return Math.acos(x);
|
|
21251
21251
|
} else {
|
|
21252
|
-
return new
|
|
21252
|
+
return new Complex13(x, 0).acos();
|
|
21253
21253
|
}
|
|
21254
21254
|
},
|
|
21255
21255
|
Complex: function(x) {
|
|
@@ -21268,16 +21268,16 @@ var dependencies38 = ["typed", "config", "Complex"];
|
|
|
21268
21268
|
var createAcosh = /* @__PURE__ */ factory(
|
|
21269
21269
|
name38,
|
|
21270
21270
|
dependencies38,
|
|
21271
|
-
({ typed: typed3, config: config2, Complex:
|
|
21271
|
+
({ typed: typed3, config: config2, Complex: Complex13 }) => {
|
|
21272
21272
|
return typed3(name38, {
|
|
21273
21273
|
number: function(x) {
|
|
21274
21274
|
if (x >= 1 || config2.predictable) {
|
|
21275
21275
|
return acoshNumber(x);
|
|
21276
21276
|
}
|
|
21277
21277
|
if (x <= -1) {
|
|
21278
|
-
return new
|
|
21278
|
+
return new Complex13(Math.log(Math.sqrt(x * x - 1) - x), Math.PI);
|
|
21279
21279
|
}
|
|
21280
|
-
return new
|
|
21280
|
+
return new Complex13(x, 0).acosh();
|
|
21281
21281
|
},
|
|
21282
21282
|
Complex: function(x) {
|
|
21283
21283
|
return x.acosh();
|
|
@@ -21314,13 +21314,13 @@ var dependencies40 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
21314
21314
|
var createAcoth = /* @__PURE__ */ factory(
|
|
21315
21315
|
name40,
|
|
21316
21316
|
dependencies40,
|
|
21317
|
-
({ typed: typed3, config: config2, Complex:
|
|
21317
|
+
({ typed: typed3, config: config2, Complex: Complex13, BigNumber: BigNumber9 }) => {
|
|
21318
21318
|
return typed3(name40, {
|
|
21319
21319
|
number: function(x) {
|
|
21320
21320
|
if (x >= 1 || x <= -1 || config2.predictable) {
|
|
21321
21321
|
return acothNumber(x);
|
|
21322
21322
|
}
|
|
21323
|
-
return new
|
|
21323
|
+
return new Complex13(x, 0).acoth();
|
|
21324
21324
|
},
|
|
21325
21325
|
Complex: function(x) {
|
|
21326
21326
|
return x.acoth();
|
|
@@ -21338,13 +21338,13 @@ var dependencies41 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
21338
21338
|
var createAcsc = /* @__PURE__ */ factory(
|
|
21339
21339
|
name41,
|
|
21340
21340
|
dependencies41,
|
|
21341
|
-
({ typed: typed3, config: config2, Complex:
|
|
21341
|
+
({ typed: typed3, config: config2, Complex: Complex13, BigNumber: BigNumber9 }) => {
|
|
21342
21342
|
return typed3(name41, {
|
|
21343
21343
|
number: function(x) {
|
|
21344
21344
|
if (x <= -1 || x >= 1 || config2.predictable) {
|
|
21345
21345
|
return acscNumber(x);
|
|
21346
21346
|
}
|
|
21347
|
-
return new
|
|
21347
|
+
return new Complex13(x, 0).acsc();
|
|
21348
21348
|
},
|
|
21349
21349
|
Complex: function(x) {
|
|
21350
21350
|
return x.acsc();
|
|
@@ -21381,13 +21381,13 @@ var dependencies43 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
21381
21381
|
var createAsec = /* @__PURE__ */ factory(
|
|
21382
21382
|
name43,
|
|
21383
21383
|
dependencies43,
|
|
21384
|
-
({ typed: typed3, config: config2, Complex:
|
|
21384
|
+
({ typed: typed3, config: config2, Complex: Complex13, BigNumber: BigNumber9 }) => {
|
|
21385
21385
|
return typed3(name43, {
|
|
21386
21386
|
number: function(x) {
|
|
21387
21387
|
if (x <= -1 || x >= 1 || config2.predictable) {
|
|
21388
21388
|
return asecNumber(x);
|
|
21389
21389
|
}
|
|
21390
|
-
return new
|
|
21390
|
+
return new Complex13(x, 0).asec();
|
|
21391
21391
|
},
|
|
21392
21392
|
Complex: function(x) {
|
|
21393
21393
|
return x.asec();
|
|
@@ -21405,7 +21405,7 @@ var dependencies44 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
21405
21405
|
var createAsech = /* @__PURE__ */ factory(
|
|
21406
21406
|
name44,
|
|
21407
21407
|
dependencies44,
|
|
21408
|
-
({ typed: typed3, config: config2, Complex:
|
|
21408
|
+
({ typed: typed3, config: config2, Complex: Complex13, BigNumber: BigNumber9 }) => {
|
|
21409
21409
|
return typed3(name44, {
|
|
21410
21410
|
number: function(x) {
|
|
21411
21411
|
if (x <= 1 && x >= -1 || config2.predictable) {
|
|
@@ -21414,9 +21414,9 @@ var createAsech = /* @__PURE__ */ factory(
|
|
|
21414
21414
|
return asechNumber(x);
|
|
21415
21415
|
}
|
|
21416
21416
|
const ret = Math.sqrt(xInv * xInv - 1);
|
|
21417
|
-
return new
|
|
21417
|
+
return new Complex13(Math.log(ret - xInv), Math.PI);
|
|
21418
21418
|
}
|
|
21419
|
-
return new
|
|
21419
|
+
return new Complex13(x, 0).asech();
|
|
21420
21420
|
},
|
|
21421
21421
|
Complex: function(x) {
|
|
21422
21422
|
return x.asech();
|
|
@@ -21434,13 +21434,13 @@ var dependencies45 = ["typed", "config", "Complex"];
|
|
|
21434
21434
|
var createAsin = /* @__PURE__ */ factory(
|
|
21435
21435
|
name45,
|
|
21436
21436
|
dependencies45,
|
|
21437
|
-
({ typed: typed3, config: config2, Complex:
|
|
21437
|
+
({ typed: typed3, config: config2, Complex: Complex13 }) => {
|
|
21438
21438
|
return typed3(name45, {
|
|
21439
21439
|
number: function(x) {
|
|
21440
21440
|
if (x >= -1 && x <= 1 || config2.predictable) {
|
|
21441
21441
|
return Math.asin(x);
|
|
21442
21442
|
} else {
|
|
21443
|
-
return new
|
|
21443
|
+
return new Complex13(x, 0).asin();
|
|
21444
21444
|
}
|
|
21445
21445
|
},
|
|
21446
21446
|
Complex: function(x) {
|
|
@@ -21499,13 +21499,13 @@ var dependencies48 = ["typed", "config", "Complex"];
|
|
|
21499
21499
|
var createAtanh = /* @__PURE__ */ factory(
|
|
21500
21500
|
name48,
|
|
21501
21501
|
dependencies48,
|
|
21502
|
-
({ typed: typed3, config: config2, Complex:
|
|
21502
|
+
({ typed: typed3, config: config2, Complex: Complex13 }) => {
|
|
21503
21503
|
return typed3(name48, {
|
|
21504
21504
|
number: function(x) {
|
|
21505
21505
|
if (x <= 1 && x >= -1 || config2.predictable) {
|
|
21506
21506
|
return atanhNumber(x);
|
|
21507
21507
|
}
|
|
21508
|
-
return new
|
|
21508
|
+
return new Complex13(x, 0).atanh();
|
|
21509
21509
|
},
|
|
21510
21510
|
Complex: function(x) {
|
|
21511
21511
|
return x.atanh();
|
|
@@ -21783,8 +21783,8 @@ var createIsBounded = /* @__PURE__ */ factory(
|
|
|
21783
21783
|
),
|
|
21784
21784
|
"Array | Matrix": typed3.referToSelf(
|
|
21785
21785
|
(self) => (A) => {
|
|
21786
|
-
const
|
|
21787
|
-
return
|
|
21786
|
+
const arr10 = Array.isArray(A) ? A : A.valueOf();
|
|
21787
|
+
return arr10.every((entry) => self(entry));
|
|
21788
21788
|
}
|
|
21789
21789
|
)
|
|
21790
21790
|
});
|
|
@@ -22120,9 +22120,9 @@ var createUnaryPlus = /* @__PURE__ */ factory(
|
|
|
22120
22120
|
|
|
22121
22121
|
// src/matrix/dot.ts
|
|
22122
22122
|
import { pairwiseDot as pairwiseDot2 } from "@danielsimonjr/mathts-core";
|
|
22123
|
-
function _isFlatNumbers(
|
|
22124
|
-
for (let i = 0; i <
|
|
22125
|
-
if (typeof
|
|
22123
|
+
function _isFlatNumbers(arr10) {
|
|
22124
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
22125
|
+
if (typeof arr10[i] !== "number") return false;
|
|
22126
22126
|
}
|
|
22127
22127
|
return true;
|
|
22128
22128
|
}
|
|
@@ -22362,9 +22362,9 @@ function improveErrorMessage(err, fnName, value) {
|
|
|
22362
22362
|
|
|
22363
22363
|
// src/statistics/prod.ts
|
|
22364
22364
|
var WASM_PROD_THRESHOLD = 100;
|
|
22365
|
-
function isFlatNumberArray(
|
|
22366
|
-
for (let i = 0; i <
|
|
22367
|
-
if (typeof
|
|
22365
|
+
function isFlatNumberArray(arr10) {
|
|
22366
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
22367
|
+
if (typeof arr10[i] !== "number") {
|
|
22368
22368
|
return false;
|
|
22369
22369
|
}
|
|
22370
22370
|
}
|
|
@@ -22882,19 +22882,19 @@ function createZerosAndOnes(name254, defaultValue, { typed: typed3, config: conf
|
|
|
22882
22882
|
}
|
|
22883
22883
|
return m;
|
|
22884
22884
|
} else {
|
|
22885
|
-
const
|
|
22885
|
+
const arr10 = [];
|
|
22886
22886
|
if (size2.length > 0) {
|
|
22887
|
-
return resize(
|
|
22887
|
+
return resize(arr10, size2, dflt);
|
|
22888
22888
|
}
|
|
22889
|
-
return
|
|
22889
|
+
return arr10;
|
|
22890
22890
|
}
|
|
22891
22891
|
}
|
|
22892
22892
|
function _normalize(size2) {
|
|
22893
22893
|
let hasBigNumbers = false;
|
|
22894
|
-
size2.forEach(function(value, index,
|
|
22894
|
+
size2.forEach(function(value, index, arr10) {
|
|
22895
22895
|
if (isBigNumber(value)) {
|
|
22896
22896
|
hasBigNumbers = true;
|
|
22897
|
-
|
|
22897
|
+
arr10[index] = value.toNumber();
|
|
22898
22898
|
}
|
|
22899
22899
|
});
|
|
22900
22900
|
return hasBigNumbers;
|
|
@@ -23021,9 +23021,9 @@ var createDiag = /* @__PURE__ */ factory(
|
|
|
23021
23021
|
|
|
23022
23022
|
// src/matrix/kron.ts
|
|
23023
23023
|
var WASM_KRON_THRESHOLD = 64;
|
|
23024
|
-
function isPlainNumber2D(
|
|
23025
|
-
for (let i = 0; i <
|
|
23026
|
-
const row2 =
|
|
23024
|
+
function isPlainNumber2D(arr10) {
|
|
23025
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
23026
|
+
const row2 = arr10[i];
|
|
23027
23027
|
for (let j = 0; j < row2.length; j++) {
|
|
23028
23028
|
if (typeof row2[j] !== "number") {
|
|
23029
23029
|
return false;
|
|
@@ -23032,11 +23032,11 @@ function isPlainNumber2D(arr8) {
|
|
|
23032
23032
|
}
|
|
23033
23033
|
return true;
|
|
23034
23034
|
}
|
|
23035
|
-
function flatten2D(
|
|
23035
|
+
function flatten2D(arr10, rows, cols) {
|
|
23036
23036
|
const result = new Float64Array(rows * cols);
|
|
23037
23037
|
for (let i = 0; i < rows; i++) {
|
|
23038
23038
|
for (let j = 0; j < cols; j++) {
|
|
23039
|
-
result[i * cols + j] =
|
|
23039
|
+
result[i * cols + j] = arr10[i][j];
|
|
23040
23040
|
}
|
|
23041
23041
|
}
|
|
23042
23042
|
return result;
|
|
@@ -23178,15 +23178,15 @@ var createMatrixFromColumns = /* @__PURE__ */ factory(
|
|
|
23178
23178
|
({ typed: typed3, matrix: matrix2, flatten: flatten4, size: size2 }) => {
|
|
23179
23179
|
return typed3(name92, {
|
|
23180
23180
|
// Single variadic handler for arrays, matrices, and mixed types
|
|
23181
|
-
"...": function(
|
|
23182
|
-
if (
|
|
23181
|
+
"...": function(arr10) {
|
|
23182
|
+
if (arr10.length === 0) {
|
|
23183
23183
|
throw new TypeError("At least one column is needed to construct a matrix.");
|
|
23184
23184
|
}
|
|
23185
|
-
const allMatrix =
|
|
23185
|
+
const allMatrix = arr10.every(
|
|
23186
23186
|
(item) => typeof item.toArray === "function"
|
|
23187
23187
|
);
|
|
23188
|
-
const hasArray =
|
|
23189
|
-
const arrays =
|
|
23188
|
+
const hasArray = arr10.some((item) => Array.isArray(item));
|
|
23189
|
+
const arrays = arr10.map(
|
|
23190
23190
|
(item) => typeof item.toArray === "function" ? item.toArray() : item
|
|
23191
23191
|
);
|
|
23192
23192
|
const result = _createArray(arrays);
|
|
@@ -23197,15 +23197,15 @@ var createMatrixFromColumns = /* @__PURE__ */ factory(
|
|
|
23197
23197
|
}
|
|
23198
23198
|
// TODO implement this properly for SparseMatrix
|
|
23199
23199
|
});
|
|
23200
|
-
function _createArray(
|
|
23201
|
-
if (
|
|
23200
|
+
function _createArray(arr10) {
|
|
23201
|
+
if (arr10.length === 0)
|
|
23202
23202
|
throw new TypeError("At least one column is needed to construct a matrix.");
|
|
23203
|
-
const N = checkVectorTypeAndReturnLength(
|
|
23203
|
+
const N = checkVectorTypeAndReturnLength(arr10[0]);
|
|
23204
23204
|
const result = [];
|
|
23205
23205
|
for (let i = 0; i < N; i++) {
|
|
23206
23206
|
result[i] = [];
|
|
23207
23207
|
}
|
|
23208
|
-
for (const col of
|
|
23208
|
+
for (const col of arr10) {
|
|
23209
23209
|
const colLength = checkVectorTypeAndReturnLength(col);
|
|
23210
23210
|
if (colLength !== N) {
|
|
23211
23211
|
throw new TypeError(
|
|
@@ -23247,15 +23247,15 @@ var createMatrixFromRows = /* @__PURE__ */ factory(
|
|
|
23247
23247
|
({ typed: typed3, matrix: matrix2, flatten: flatten4, size: size2 }) => {
|
|
23248
23248
|
return typed3(name93, {
|
|
23249
23249
|
// Single variadic handler for arrays, matrices, and mixed types
|
|
23250
|
-
"...": function(
|
|
23251
|
-
if (
|
|
23250
|
+
"...": function(arr10) {
|
|
23251
|
+
if (arr10.length === 0) {
|
|
23252
23252
|
throw new TypeError("At least one row is needed to construct a matrix.");
|
|
23253
23253
|
}
|
|
23254
|
-
const allMatrix =
|
|
23254
|
+
const allMatrix = arr10.every(
|
|
23255
23255
|
(item) => typeof item.toArray === "function"
|
|
23256
23256
|
);
|
|
23257
|
-
const hasArray =
|
|
23258
|
-
const arrays =
|
|
23257
|
+
const hasArray = arr10.some((item) => Array.isArray(item));
|
|
23258
|
+
const arrays = arr10.map(
|
|
23259
23259
|
(item) => typeof item.toArray === "function" ? item.toArray() : item
|
|
23260
23260
|
);
|
|
23261
23261
|
const result = _createArray(arrays);
|
|
@@ -23266,12 +23266,12 @@ var createMatrixFromRows = /* @__PURE__ */ factory(
|
|
|
23266
23266
|
}
|
|
23267
23267
|
// TODO implement this properly for SparseMatrix
|
|
23268
23268
|
});
|
|
23269
|
-
function _createArray(
|
|
23270
|
-
if (
|
|
23269
|
+
function _createArray(arr10) {
|
|
23270
|
+
if (arr10.length === 0)
|
|
23271
23271
|
throw new TypeError("At least one row is needed to construct a matrix.");
|
|
23272
|
-
const N = checkVectorTypeAndReturnLength(
|
|
23272
|
+
const N = checkVectorTypeAndReturnLength(arr10[0]);
|
|
23273
23273
|
const result = [];
|
|
23274
|
-
for (const row2 of
|
|
23274
|
+
for (const row2 of arr10) {
|
|
23275
23275
|
const rowLength = checkVectorTypeAndReturnLength(row2);
|
|
23276
23276
|
if (rowLength !== N) {
|
|
23277
23277
|
throw new TypeError(
|
|
@@ -25340,7 +25340,7 @@ var createCbrt = /* @__PURE__ */ factory(
|
|
|
25340
25340
|
isNegative: isNegative2,
|
|
25341
25341
|
unaryMinus: unaryMinus2,
|
|
25342
25342
|
matrix: matrix2,
|
|
25343
|
-
Complex:
|
|
25343
|
+
Complex: Complex13,
|
|
25344
25344
|
BigNumber: BigNumber9,
|
|
25345
25345
|
Fraction: Fraction5
|
|
25346
25346
|
}) => {
|
|
@@ -25352,7 +25352,7 @@ var createCbrt = /* @__PURE__ */ factory(
|
|
|
25352
25352
|
// through the complex cube-root path (all three roots when allRoots, the
|
|
25353
25353
|
// principal Complex root otherwise) — matching mathjs `cbrt(8, true)`.
|
|
25354
25354
|
"number, boolean": function(x, allRoots) {
|
|
25355
|
-
return _cbrtComplex(new
|
|
25355
|
+
return _cbrtComplex(new Complex13(x, 0), allRoots);
|
|
25356
25356
|
},
|
|
25357
25357
|
Complex: _cbrtComplex,
|
|
25358
25358
|
"Complex, boolean": _cbrtComplex,
|
|
@@ -25364,12 +25364,12 @@ var createCbrt = /* @__PURE__ */ factory(
|
|
|
25364
25364
|
function _cbrtComplex(x, allRoots) {
|
|
25365
25365
|
const arg3 = x.arg() / 3;
|
|
25366
25366
|
const abs2 = x.abs();
|
|
25367
|
-
const principal = new
|
|
25367
|
+
const principal = new Complex13(cbrtNumber(abs2), 0).mul(new Complex13(0, arg3).exp());
|
|
25368
25368
|
if (allRoots) {
|
|
25369
25369
|
const all = [
|
|
25370
25370
|
principal,
|
|
25371
|
-
new
|
|
25372
|
-
new
|
|
25371
|
+
new Complex13(cbrtNumber(abs2), 0).mul(new Complex13(0, arg3 + Math.PI * 2 / 3).exp()),
|
|
25372
|
+
new Complex13(cbrtNumber(abs2), 0).mul(new Complex13(0, arg3 - Math.PI * 2 / 3).exp())
|
|
25373
25373
|
];
|
|
25374
25374
|
return config2.matrix === "Array" ? all : matrix2(all);
|
|
25375
25375
|
} else {
|
|
@@ -25418,27 +25418,27 @@ var createNthRoots = /* @__PURE__ */ factory(
|
|
|
25418
25418
|
typed: typed3,
|
|
25419
25419
|
config: _config,
|
|
25420
25420
|
divideScalar: _divideScalar,
|
|
25421
|
-
Complex:
|
|
25421
|
+
Complex: Complex13
|
|
25422
25422
|
}) => {
|
|
25423
25423
|
const _calculateExactResult = [
|
|
25424
25424
|
function realPos(val) {
|
|
25425
|
-
return new
|
|
25425
|
+
return new Complex13(val, 0);
|
|
25426
25426
|
},
|
|
25427
25427
|
function imagPos(val) {
|
|
25428
|
-
return new
|
|
25428
|
+
return new Complex13(0, val);
|
|
25429
25429
|
},
|
|
25430
25430
|
function realNeg(val) {
|
|
25431
|
-
return new
|
|
25431
|
+
return new Complex13(-val, 0);
|
|
25432
25432
|
},
|
|
25433
25433
|
function imagNeg(val) {
|
|
25434
|
-
return new
|
|
25434
|
+
return new Complex13(0, -val);
|
|
25435
25435
|
}
|
|
25436
25436
|
];
|
|
25437
25437
|
function _nthComplexRoots(a, root2) {
|
|
25438
25438
|
if (root2 < 0) throw new Error("Root must be greater than zero");
|
|
25439
25439
|
if (root2 === 0) throw new Error("Root must be non-zero");
|
|
25440
25440
|
if (root2 % 1 !== 0) throw new Error("Root must be an integer");
|
|
25441
|
-
if (a === 0 || a.abs() === 0) return [new
|
|
25441
|
+
if (a === 0 || a.abs() === 0) return [new Complex13(0, 0)];
|
|
25442
25442
|
const aIsNumeric = typeof a === "number";
|
|
25443
25443
|
let offset = NaN;
|
|
25444
25444
|
if (aIsNumeric || a.re === 0 || a.im === 0) {
|
|
@@ -25460,7 +25460,7 @@ var createNthRoots = /* @__PURE__ */ factory(
|
|
|
25460
25460
|
roots.push(_calculateExactResult[halfPiFactor % 4](r));
|
|
25461
25461
|
continue;
|
|
25462
25462
|
}
|
|
25463
|
-
roots.push(new
|
|
25463
|
+
roots.push(new Complex13({ r, phi: (arg3 + 2 * Math.PI * k) / root2 }));
|
|
25464
25464
|
}
|
|
25465
25465
|
return roots;
|
|
25466
25466
|
}
|
|
@@ -25847,12 +25847,12 @@ var nlg16 = Math.log(16);
|
|
|
25847
25847
|
var createLog = /* @__PURE__ */ factory(
|
|
25848
25848
|
name113,
|
|
25849
25849
|
dependencies113,
|
|
25850
|
-
({ typed: typed3, typeOf: typeOf3, config: config2, divideScalar: divideScalar2, Complex:
|
|
25850
|
+
({ typed: typed3, typeOf: typeOf3, config: config2, divideScalar: divideScalar2, Complex: Complex13 }) => {
|
|
25851
25851
|
function complexLog(c) {
|
|
25852
25852
|
return c.log();
|
|
25853
25853
|
}
|
|
25854
25854
|
function complexLogNumber(x) {
|
|
25855
|
-
return complexLog(new
|
|
25855
|
+
return complexLog(new Complex13(x, 0));
|
|
25856
25856
|
}
|
|
25857
25857
|
return typed3(name113, {
|
|
25858
25858
|
number: function(x) {
|
|
@@ -26283,9 +26283,9 @@ var createResize = /* @__PURE__ */ factory(
|
|
|
26283
26283
|
}
|
|
26284
26284
|
return clone(scalar);
|
|
26285
26285
|
} else {
|
|
26286
|
-
let
|
|
26287
|
-
|
|
26288
|
-
const res = resize(
|
|
26286
|
+
let arr10 = !Array.isArray(x) ? [x] : x;
|
|
26287
|
+
arr10 = clone(arr10);
|
|
26288
|
+
const res = resize(arr10, sz, defaultValue);
|
|
26289
26289
|
return asMatrix ? matrix2(res) : res;
|
|
26290
26290
|
}
|
|
26291
26291
|
}
|
|
@@ -27127,7 +27127,7 @@ var dependencies127 = ["typed", "add", "multiply", "Complex", "number"];
|
|
|
27127
27127
|
var createZpk2tf = /* @__PURE__ */ factory(
|
|
27128
27128
|
name127,
|
|
27129
27129
|
dependencies127,
|
|
27130
|
-
({ typed: typed3, add: add2, multiply: multiply2, Complex:
|
|
27130
|
+
({ typed: typed3, add: add2, multiply: multiply2, Complex: Complex13, number: number2 }) => {
|
|
27131
27131
|
return typed3(name127, {
|
|
27132
27132
|
"Array,Array,number": function(z, p, k) {
|
|
27133
27133
|
return _zpk2tf(z, p, k);
|
|
@@ -27149,17 +27149,17 @@ var createZpk2tf = /* @__PURE__ */ factory(
|
|
|
27149
27149
|
if (p.some((el) => el.type === "BigNumber")) {
|
|
27150
27150
|
p = p.map((el) => number2(el));
|
|
27151
27151
|
}
|
|
27152
|
-
let num2 = [
|
|
27153
|
-
let den = [
|
|
27152
|
+
let num2 = [Complex13(1, 0)];
|
|
27153
|
+
let den = [Complex13(1, 0)];
|
|
27154
27154
|
for (let i = 0; i < z.length; i++) {
|
|
27155
27155
|
let zero = z[i];
|
|
27156
|
-
if (typeof zero === "number") zero =
|
|
27157
|
-
num2 = _multiply2(num2, [
|
|
27156
|
+
if (typeof zero === "number") zero = Complex13(zero, 0);
|
|
27157
|
+
num2 = _multiply2(num2, [Complex13(1, 0), Complex13(-zero.re, -zero.im)]);
|
|
27158
27158
|
}
|
|
27159
27159
|
for (let i = 0; i < p.length; i++) {
|
|
27160
27160
|
let pole = p[i];
|
|
27161
|
-
if (typeof pole === "number") pole =
|
|
27162
|
-
den = _multiply2(den, [
|
|
27161
|
+
if (typeof pole === "number") pole = Complex13(pole, 0);
|
|
27162
|
+
den = _multiply2(den, [Complex13(1, 0), Complex13(-pole.re, -pole.im)]);
|
|
27163
27163
|
}
|
|
27164
27164
|
for (let i = 0; i < num2.length; i++) {
|
|
27165
27165
|
num2[i] = multiply2(num2[i], k);
|
|
@@ -27169,7 +27169,7 @@ var createZpk2tf = /* @__PURE__ */ factory(
|
|
|
27169
27169
|
function _multiply2(a, b) {
|
|
27170
27170
|
const c = [];
|
|
27171
27171
|
for (let i = 0; i < a.length + b.length - 1; i++) {
|
|
27172
|
-
c[i] =
|
|
27172
|
+
c[i] = Complex13(0, 0);
|
|
27173
27173
|
for (let j = 0; j < a.length; j++) {
|
|
27174
27174
|
if (i - j >= 0 && i - j < b.length) {
|
|
27175
27175
|
c[i] = add2(c[i], multiply2(a[j], b[i - j]));
|
|
@@ -27183,9 +27183,9 @@ var createZpk2tf = /* @__PURE__ */ factory(
|
|
|
27183
27183
|
|
|
27184
27184
|
// src/statistics/cumsum.ts
|
|
27185
27185
|
import { neumaierCumsum as neumaierCumsum2 } from "@danielsimonjr/mathts-core";
|
|
27186
|
-
function isFlatNumberArray2(
|
|
27187
|
-
for (let i = 0; i <
|
|
27188
|
-
if (typeof
|
|
27186
|
+
function isFlatNumberArray2(arr10) {
|
|
27187
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
27188
|
+
if (typeof arr10[i] !== "number") {
|
|
27189
27189
|
return false;
|
|
27190
27190
|
}
|
|
27191
27191
|
}
|
|
@@ -27282,9 +27282,9 @@ var createCumSum = /* @__PURE__ */ factory(
|
|
|
27282
27282
|
|
|
27283
27283
|
// src/statistics/sum.ts
|
|
27284
27284
|
import { pairwiseSum as pairwiseSum2 } from "@danielsimonjr/mathts-core";
|
|
27285
|
-
function isFlatNumberArray3(
|
|
27286
|
-
for (let i = 0; i <
|
|
27287
|
-
if (typeof
|
|
27285
|
+
function isFlatNumberArray3(arr10) {
|
|
27286
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
27287
|
+
if (typeof arr10[i] !== "number") {
|
|
27288
27288
|
return false;
|
|
27289
27289
|
}
|
|
27290
27290
|
}
|
|
@@ -28385,13 +28385,13 @@ var dependencies143 = ["typed", "config", "divideScalar", "log", "Complex"];
|
|
|
28385
28385
|
var createLog1p = /* @__PURE__ */ factory(
|
|
28386
28386
|
name143,
|
|
28387
28387
|
dependencies143,
|
|
28388
|
-
({ typed: typed3, config: config2, divideScalar: divideScalar2, log: log3, Complex:
|
|
28388
|
+
({ typed: typed3, config: config2, divideScalar: divideScalar2, log: log3, Complex: Complex13 }) => {
|
|
28389
28389
|
return typed3(name143, {
|
|
28390
28390
|
number: function(x) {
|
|
28391
28391
|
if (x >= -1 || config2.predictable) {
|
|
28392
28392
|
return log1p2(x);
|
|
28393
28393
|
} else {
|
|
28394
|
-
return _log1pComplex(new
|
|
28394
|
+
return _log1pComplex(new Complex13(x, 0));
|
|
28395
28395
|
}
|
|
28396
28396
|
},
|
|
28397
28397
|
Complex: _log1pComplex,
|
|
@@ -28400,7 +28400,7 @@ var createLog1p = /* @__PURE__ */ factory(
|
|
|
28400
28400
|
if (!y.isNegative() || config2.predictable) {
|
|
28401
28401
|
return y.ln();
|
|
28402
28402
|
} else {
|
|
28403
|
-
return _log1pComplex(new
|
|
28403
|
+
return _log1pComplex(new Complex13(x.toNumber(), 0));
|
|
28404
28404
|
}
|
|
28405
28405
|
},
|
|
28406
28406
|
"Array | Matrix": typed3.referToSelf(
|
|
@@ -28414,7 +28414,7 @@ var createLog1p = /* @__PURE__ */ factory(
|
|
|
28414
28414
|
});
|
|
28415
28415
|
function _log1pComplex(x) {
|
|
28416
28416
|
const xRe1p = x.re + 1;
|
|
28417
|
-
return new
|
|
28417
|
+
return new Complex13(Math.log(Math.sqrt(xRe1p * xRe1p + x.im * x.im)), Math.atan2(x.im, xRe1p));
|
|
28418
28418
|
}
|
|
28419
28419
|
}
|
|
28420
28420
|
);
|
|
@@ -28566,7 +28566,7 @@ var createPow = /* @__PURE__ */ factory(
|
|
|
28566
28566
|
inv: inv2,
|
|
28567
28567
|
number: number2,
|
|
28568
28568
|
fraction: fraction2,
|
|
28569
|
-
Complex:
|
|
28569
|
+
Complex: Complex13
|
|
28570
28570
|
}) => {
|
|
28571
28571
|
return typed3(name145, {
|
|
28572
28572
|
"number, number": _pow,
|
|
@@ -28577,7 +28577,7 @@ var createPow = /* @__PURE__ */ factory(
|
|
|
28577
28577
|
if (y.isInteger() || x.gte(0) || config2.predictable) {
|
|
28578
28578
|
return x.pow(y);
|
|
28579
28579
|
} else {
|
|
28580
|
-
return new
|
|
28580
|
+
return new Complex13(x.toNumber(), 0).pow(y.toNumber(), 0);
|
|
28581
28581
|
}
|
|
28582
28582
|
},
|
|
28583
28583
|
"bigint, bigint": (x, y) => x ** y,
|
|
@@ -28626,7 +28626,7 @@ var createPow = /* @__PURE__ */ factory(
|
|
|
28626
28626
|
if (isPowZeroAtInfinity(x, y)) {
|
|
28627
28627
|
return 0;
|
|
28628
28628
|
}
|
|
28629
|
-
return new
|
|
28629
|
+
return new Complex13(x, 0).pow(y, 0);
|
|
28630
28630
|
}
|
|
28631
28631
|
}
|
|
28632
28632
|
function _powArray(x, y) {
|
|
@@ -29897,7 +29897,7 @@ var createFixNumber = /* @__PURE__ */ factory(
|
|
|
29897
29897
|
var createFix = /* @__PURE__ */ factory(
|
|
29898
29898
|
name167,
|
|
29899
29899
|
dependencies167,
|
|
29900
|
-
({ typed: typed3, Complex:
|
|
29900
|
+
({ typed: typed3, Complex: Complex13, matrix: matrix2, ceil: ceil2, floor: floor2, equalScalar: equalScalar3, zeros: zeros2, DenseMatrix: DenseMatrix6 }) => {
|
|
29901
29901
|
const matAlgo12xSfs = createMatAlgo12xSfs({ typed: typed3, DenseMatrix: DenseMatrix6 });
|
|
29902
29902
|
const matAlgo14xDs = createMatAlgo14xDs({ typed: typed3 });
|
|
29903
29903
|
const fixNumber = createFixNumber({ typed: typed3, ceil: ceil2, floor: floor2 });
|
|
@@ -29905,20 +29905,20 @@ var createFix = /* @__PURE__ */ factory(
|
|
|
29905
29905
|
number: fixNumber.signatures.number,
|
|
29906
29906
|
"number, number | BigNumber": fixNumber.signatures["number,number"],
|
|
29907
29907
|
Complex: function(x) {
|
|
29908
|
-
return new
|
|
29908
|
+
return new Complex13(
|
|
29909
29909
|
x.re > 0 ? Math.floor(x.re) : Math.ceil(x.re),
|
|
29910
29910
|
x.im > 0 ? Math.floor(x.im) : Math.ceil(x.im)
|
|
29911
29911
|
);
|
|
29912
29912
|
},
|
|
29913
29913
|
"Complex, number": function(x, n) {
|
|
29914
|
-
return new
|
|
29914
|
+
return new Complex13(
|
|
29915
29915
|
x.re > 0 ? floor2(x.re, n) : ceil2(x.re, n),
|
|
29916
29916
|
x.im > 0 ? floor2(x.im, n) : ceil2(x.im, n)
|
|
29917
29917
|
);
|
|
29918
29918
|
},
|
|
29919
29919
|
"Complex, BigNumber": function(x, bn) {
|
|
29920
29920
|
const n = bn.toNumber();
|
|
29921
|
-
return new
|
|
29921
|
+
return new Complex13(
|
|
29922
29922
|
x.re > 0 ? floor2(x.re, n) : ceil2(x.re, n),
|
|
29923
29923
|
x.im > 0 ? floor2(x.im, n) : ceil2(x.im, n)
|
|
29924
29924
|
);
|
|
@@ -30138,9 +30138,9 @@ var createComposition = /* @__PURE__ */ factory(
|
|
|
30138
30138
|
|
|
30139
30139
|
// src/matrix/partitionSelect.ts
|
|
30140
30140
|
var WASM_PARTITION_SELECT_THRESHOLD = 100;
|
|
30141
|
-
function isFlatNumberArray4(
|
|
30142
|
-
for (let i = 0; i <
|
|
30143
|
-
if (typeof
|
|
30141
|
+
function isFlatNumberArray4(arr10) {
|
|
30142
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
30143
|
+
if (typeof arr10[i] !== "number") {
|
|
30144
30144
|
return false;
|
|
30145
30145
|
}
|
|
30146
30146
|
}
|
|
@@ -30182,28 +30182,28 @@ var createPartitionSelect = /* @__PURE__ */ factory(
|
|
|
30182
30182
|
}
|
|
30183
30183
|
return quickSelect2(x, k, compare3);
|
|
30184
30184
|
}
|
|
30185
|
-
function quickSelect2(
|
|
30186
|
-
if (k >=
|
|
30185
|
+
function quickSelect2(arr10, k, compare3) {
|
|
30186
|
+
if (k >= arr10.length) {
|
|
30187
30187
|
throw new Error("k out of bounds");
|
|
30188
30188
|
}
|
|
30189
|
-
for (let i = 0; i <
|
|
30190
|
-
if (isNumeric2(
|
|
30191
|
-
return
|
|
30189
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
30190
|
+
if (isNumeric2(arr10[i]) && mathIsNaN(arr10[i])) {
|
|
30191
|
+
return arr10[i];
|
|
30192
30192
|
}
|
|
30193
30193
|
}
|
|
30194
30194
|
const wasm = wasmLoader.getModule();
|
|
30195
|
-
if (wasm &&
|
|
30195
|
+
if (wasm && arr10.length >= WASM_PARTITION_SELECT_THRESHOLD && isFlatNumberArray4(arr10)) {
|
|
30196
30196
|
const isAsc = compare3 === asc;
|
|
30197
30197
|
const isDesc = compare3 === desc;
|
|
30198
30198
|
if (isAsc || isDesc) {
|
|
30199
30199
|
try {
|
|
30200
|
-
const effectiveK = isDesc ?
|
|
30201
|
-
const data = wasmLoader.allocateFloat64Array(
|
|
30202
|
-
const work = wasmLoader.allocateFloat64ArrayEmpty(
|
|
30200
|
+
const effectiveK = isDesc ? arr10.length - 1 - k : k;
|
|
30201
|
+
const data = wasmLoader.allocateFloat64Array(arr10);
|
|
30202
|
+
const work = wasmLoader.allocateFloat64ArrayEmpty(arr10.length);
|
|
30203
30203
|
try {
|
|
30204
|
-
const result = wasm.partitionSelect(data.ptr,
|
|
30205
|
-
for (let i = 0; i <
|
|
30206
|
-
|
|
30204
|
+
const result = wasm.partitionSelect(data.ptr, arr10.length, effectiveK, work.ptr);
|
|
30205
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
30206
|
+
arr10[i] = work.array[i];
|
|
30207
30207
|
}
|
|
30208
30208
|
return result;
|
|
30209
30209
|
} finally {
|
|
@@ -30215,22 +30215,22 @@ var createPartitionSelect = /* @__PURE__ */ factory(
|
|
|
30215
30215
|
}
|
|
30216
30216
|
}
|
|
30217
30217
|
let from = 0;
|
|
30218
|
-
let to3 =
|
|
30218
|
+
let to3 = arr10.length - 1;
|
|
30219
30219
|
while (from < to3) {
|
|
30220
30220
|
let r = from;
|
|
30221
30221
|
let w = to3;
|
|
30222
|
-
const pivot =
|
|
30222
|
+
const pivot = arr10[Math.floor(Math.random() * (to3 - from + 1)) + from];
|
|
30223
30223
|
while (r < w) {
|
|
30224
|
-
if (compare3(
|
|
30225
|
-
const tmp =
|
|
30226
|
-
|
|
30227
|
-
|
|
30224
|
+
if (compare3(arr10[r], pivot) >= 0) {
|
|
30225
|
+
const tmp = arr10[w];
|
|
30226
|
+
arr10[w] = arr10[r];
|
|
30227
|
+
arr10[r] = tmp;
|
|
30228
30228
|
--w;
|
|
30229
30229
|
} else {
|
|
30230
30230
|
++r;
|
|
30231
30231
|
}
|
|
30232
30232
|
}
|
|
30233
|
-
if (compare3(
|
|
30233
|
+
if (compare3(arr10[r], pivot) > 0) {
|
|
30234
30234
|
--r;
|
|
30235
30235
|
}
|
|
30236
30236
|
if (k <= r) {
|
|
@@ -30239,7 +30239,7 @@ var createPartitionSelect = /* @__PURE__ */ factory(
|
|
|
30239
30239
|
from = r + 1;
|
|
30240
30240
|
}
|
|
30241
30241
|
}
|
|
30242
|
-
return
|
|
30242
|
+
return arr10[k];
|
|
30243
30243
|
}
|
|
30244
30244
|
}
|
|
30245
30245
|
);
|
|
@@ -30275,7 +30275,7 @@ var createPinv = /* @__PURE__ */ factory(
|
|
|
30275
30275
|
divideScalar: divideScalar2,
|
|
30276
30276
|
multiply: multiply2,
|
|
30277
30277
|
add: add2,
|
|
30278
|
-
Complex:
|
|
30278
|
+
Complex: Complex13
|
|
30279
30279
|
}) => {
|
|
30280
30280
|
return typed3(name172, {
|
|
30281
30281
|
"Array | Matrix": function(x) {
|
|
@@ -30370,12 +30370,12 @@ var createPinv = /* @__PURE__ */ factory(
|
|
|
30370
30370
|
return { C, F };
|
|
30371
30371
|
}
|
|
30372
30372
|
function _isZero(x) {
|
|
30373
|
-
return equal2(add2(x,
|
|
30373
|
+
return equal2(add2(x, Complex13(1, 1)), add2(0, Complex13(1, 1)));
|
|
30374
30374
|
}
|
|
30375
|
-
function _isZeros(
|
|
30375
|
+
function _isZeros(arr10) {
|
|
30376
30376
|
return deepEqual3(
|
|
30377
|
-
add2(
|
|
30378
|
-
add2(multiply2(
|
|
30377
|
+
add2(arr10, Complex13(1, 1)),
|
|
30378
|
+
add2(multiply2(arr10, 0), Complex13(1, 1))
|
|
30379
30379
|
);
|
|
30380
30380
|
}
|
|
30381
30381
|
}
|
|
@@ -30439,7 +30439,7 @@ var createQr = /* @__PURE__ */ factory(
|
|
|
30439
30439
|
divideScalar: divideScalar2,
|
|
30440
30440
|
multiplyScalar: multiplyScalar2,
|
|
30441
30441
|
subtractScalar: subtractScalar2,
|
|
30442
|
-
complex:
|
|
30442
|
+
complex: complex3
|
|
30443
30443
|
}) => {
|
|
30444
30444
|
const qrTyped = typed3(name173, {
|
|
30445
30445
|
DenseMatrix: function(m) {
|
|
@@ -30563,7 +30563,7 @@ var createQr = /* @__PURE__ */ factory(
|
|
|
30563
30563
|
const ret = _denseQRimpl(m);
|
|
30564
30564
|
const Rdata = ret.R._data;
|
|
30565
30565
|
if (m._data.length > 0) {
|
|
30566
|
-
const zero = Rdata[0][0].type === "Complex" ?
|
|
30566
|
+
const zero = Rdata[0][0].type === "Complex" ? complex3(0) : 0;
|
|
30567
30567
|
for (let i = 0; i < Rdata.length; ++i) {
|
|
30568
30568
|
for (let j = 0; j < i && j < (Rdata[0] || []).length; ++j) {
|
|
30569
30569
|
Rdata[i][j] = zero;
|
|
@@ -30692,11 +30692,11 @@ var createRange = /* @__PURE__ */ factory(
|
|
|
30692
30692
|
return _out(_range(start, end, step, includeEnd));
|
|
30693
30693
|
}
|
|
30694
30694
|
});
|
|
30695
|
-
function _out(
|
|
30695
|
+
function _out(arr10) {
|
|
30696
30696
|
if (config2.matrix === "Matrix") {
|
|
30697
|
-
return matrix2 ? matrix2(
|
|
30697
|
+
return matrix2 ? matrix2(arr10) : noMatrix();
|
|
30698
30698
|
}
|
|
30699
|
-
return
|
|
30699
|
+
return arr10;
|
|
30700
30700
|
}
|
|
30701
30701
|
function _strRange(str, includeEnd) {
|
|
30702
30702
|
const r = _parse2(str);
|
|
@@ -30765,25 +30765,25 @@ var createGamma = /* @__PURE__ */ factory(
|
|
|
30765
30765
|
multiplyScalar: _multiplyScalar,
|
|
30766
30766
|
pow: _pow,
|
|
30767
30767
|
BigNumber: BigNumber9,
|
|
30768
|
-
Complex:
|
|
30768
|
+
Complex: Complex13
|
|
30769
30769
|
}) => {
|
|
30770
30770
|
function gammaComplex(n) {
|
|
30771
30771
|
if (n.im === 0) {
|
|
30772
30772
|
return gammaNumber(n.re);
|
|
30773
30773
|
}
|
|
30774
30774
|
if (n.re < 0.5) {
|
|
30775
|
-
const t2 = new
|
|
30776
|
-
const r = new
|
|
30775
|
+
const t2 = new Complex13(1 - n.re, -n.im);
|
|
30776
|
+
const r = new Complex13(Math.PI * n.re, Math.PI * n.im);
|
|
30777
30777
|
const gammaT = gammaComplex(t2);
|
|
30778
|
-
return new
|
|
30778
|
+
return new Complex13(Math.PI).div(r.sin()).div(gammaT);
|
|
30779
30779
|
}
|
|
30780
|
-
const z = new
|
|
30781
|
-
let x = new
|
|
30780
|
+
const z = new Complex13(n.re - 1, n.im);
|
|
30781
|
+
let x = new Complex13(gammaP[0], 0);
|
|
30782
30782
|
for (let i = 1; i < gammaP.length; ++i) {
|
|
30783
|
-
const gammaPval = new
|
|
30783
|
+
const gammaPval = new Complex13(gammaP[i], 0);
|
|
30784
30784
|
x = x.add(gammaPval.div(z.add(i)));
|
|
30785
30785
|
}
|
|
30786
|
-
const t = new
|
|
30786
|
+
const t = new Complex13(z.re + gammaG + 0.5, z.im);
|
|
30787
30787
|
const twoPiSqrt = Math.sqrt(2 * Math.PI);
|
|
30788
30788
|
const tpow = t.pow(z.add(0.5));
|
|
30789
30789
|
const expt = t.neg().exp();
|
|
@@ -30993,9 +30993,9 @@ var createEqualText = /* @__PURE__ */ factory(
|
|
|
30993
30993
|
|
|
30994
30994
|
// src/statistics/max.ts
|
|
30995
30995
|
var WASM_MAX_THRESHOLD = 100;
|
|
30996
|
-
function isFlatNumberArray5(
|
|
30997
|
-
for (let i = 0; i <
|
|
30998
|
-
if (typeof
|
|
30996
|
+
function isFlatNumberArray5(arr10) {
|
|
30997
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
30998
|
+
if (typeof arr10[i] !== "number") {
|
|
30999
30999
|
return false;
|
|
31000
31000
|
}
|
|
31001
31001
|
}
|
|
@@ -31072,9 +31072,9 @@ var createMax = /* @__PURE__ */ factory(
|
|
|
31072
31072
|
|
|
31073
31073
|
// src/statistics/min.ts
|
|
31074
31074
|
var WASM_MIN_THRESHOLD = 100;
|
|
31075
|
-
function isFlatNumberArray6(
|
|
31076
|
-
for (let i = 0; i <
|
|
31077
|
-
if (typeof
|
|
31075
|
+
function isFlatNumberArray6(arr10) {
|
|
31076
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
31077
|
+
if (typeof arr10[i] !== "number") {
|
|
31078
31078
|
return false;
|
|
31079
31079
|
}
|
|
31080
31080
|
}
|
|
@@ -31159,8 +31159,8 @@ var createNullish = /* @__PURE__ */ factory(
|
|
|
31159
31159
|
const matAlgo03xDSf = createMatAlgo03xDSf({ typed: typed3 });
|
|
31160
31160
|
const matAlgo14xDs = createMatAlgo14xDs({ typed: typed3 });
|
|
31161
31161
|
const matAlgo13xDD = createMatAlgo13xDD({ typed: typed3 });
|
|
31162
|
-
const toMatrix = (
|
|
31163
|
-
return matrix2(
|
|
31162
|
+
const toMatrix = (arr10) => {
|
|
31163
|
+
return matrix2(arr10);
|
|
31164
31164
|
};
|
|
31165
31165
|
return typed3(name180, {
|
|
31166
31166
|
// Scalar and SparseMatrix-first short-circuit handlers
|
|
@@ -31472,11 +31472,11 @@ var createDistance = /* @__PURE__ */ factory(
|
|
|
31472
31472
|
throw new TypeError("Invalid Arguments: Try again");
|
|
31473
31473
|
}
|
|
31474
31474
|
},
|
|
31475
|
-
Array: function(
|
|
31476
|
-
if (!_pairwise(
|
|
31475
|
+
Array: function(arr10) {
|
|
31476
|
+
if (!_pairwise(arr10)) {
|
|
31477
31477
|
throw new TypeError("Incorrect array format entered for pairwise distance calculation");
|
|
31478
31478
|
}
|
|
31479
|
-
return _distancePairwise(
|
|
31479
|
+
return _distancePairwise(arr10);
|
|
31480
31480
|
}
|
|
31481
31481
|
});
|
|
31482
31482
|
function _isNumber(a) {
|
|
@@ -31486,15 +31486,15 @@ var createDistance = /* @__PURE__ */ factory(
|
|
|
31486
31486
|
if (!Array.isArray(a)) {
|
|
31487
31487
|
a = _objectToArray(a);
|
|
31488
31488
|
}
|
|
31489
|
-
const
|
|
31490
|
-
return _isNumber(
|
|
31489
|
+
const arr10 = a;
|
|
31490
|
+
return _isNumber(arr10[0]) && _isNumber(arr10[1]);
|
|
31491
31491
|
}
|
|
31492
31492
|
function _3d(a) {
|
|
31493
31493
|
if (!Array.isArray(a)) {
|
|
31494
31494
|
a = _objectToArray(a);
|
|
31495
31495
|
}
|
|
31496
|
-
const
|
|
31497
|
-
return _isNumber(
|
|
31496
|
+
const arr10 = a;
|
|
31497
|
+
return _isNumber(arr10[0]) && _isNumber(arr10[1]) && _isNumber(arr10[2]);
|
|
31498
31498
|
}
|
|
31499
31499
|
function _containsOnlyNumbers(a) {
|
|
31500
31500
|
if (!Array.isArray(a)) {
|
|
@@ -31506,8 +31506,8 @@ var createDistance = /* @__PURE__ */ factory(
|
|
|
31506
31506
|
if (!Array.isArray(a)) {
|
|
31507
31507
|
a = _objectToArray(a);
|
|
31508
31508
|
}
|
|
31509
|
-
const
|
|
31510
|
-
return _isNumber(
|
|
31509
|
+
const arr10 = a;
|
|
31510
|
+
return _isNumber(arr10[0]) && _isNumber(arr10[1]) && _isNumber(arr10[2]) && _isNumber(arr10[3]) && _isNumber(arr10[4]) && _isNumber(arr10[5]);
|
|
31511
31511
|
}
|
|
31512
31512
|
function _objectToArray(o) {
|
|
31513
31513
|
const keys = Object.keys(o);
|
|
@@ -31837,9 +31837,9 @@ var dependencies187 = ["typed", "factorial"];
|
|
|
31837
31837
|
var createPermutations = /* @__PURE__ */ factory(
|
|
31838
31838
|
name187,
|
|
31839
31839
|
dependencies187,
|
|
31840
|
-
({ typed: typed3, factorial:
|
|
31840
|
+
({ typed: typed3, factorial: factorial5 }) => {
|
|
31841
31841
|
return typed3(name187, {
|
|
31842
|
-
"number | BigNumber":
|
|
31842
|
+
"number | BigNumber": factorial5,
|
|
31843
31843
|
"number, number": function(n, k) {
|
|
31844
31844
|
if (!isInteger(n) || n < 0) {
|
|
31845
31845
|
throw new TypeError("Positive integer value expected in function permutations");
|
|
@@ -32826,11 +32826,11 @@ var FAST_FFT_THRESHOLD = 64;
|
|
|
32826
32826
|
function isPowerOf23(n) {
|
|
32827
32827
|
return n > 0 && (n & n - 1) === 0;
|
|
32828
32828
|
}
|
|
32829
|
-
function complexToInterleaved(
|
|
32830
|
-
const n =
|
|
32829
|
+
function complexToInterleaved(arr10, _complex) {
|
|
32830
|
+
const n = arr10.length;
|
|
32831
32831
|
const result = new Float64Array(n * 2);
|
|
32832
32832
|
for (let i = 0; i < n; i++) {
|
|
32833
|
-
const val =
|
|
32833
|
+
const val = arr10[i];
|
|
32834
32834
|
if (typeof val === "number") {
|
|
32835
32835
|
result[i * 2] = val;
|
|
32836
32836
|
result[i * 2 + 1] = 0;
|
|
@@ -32843,10 +32843,10 @@ function complexToInterleaved(arr8, _complex) {
|
|
|
32843
32843
|
}
|
|
32844
32844
|
return result;
|
|
32845
32845
|
}
|
|
32846
|
-
function interleavedToComplex(data, n,
|
|
32846
|
+
function interleavedToComplex(data, n, complex3) {
|
|
32847
32847
|
const result = [];
|
|
32848
32848
|
for (let i = 0; i < n; i++) {
|
|
32849
|
-
result.push(
|
|
32849
|
+
result.push(complex3(data[i * 2], data[i * 2 + 1]));
|
|
32850
32850
|
}
|
|
32851
32851
|
return result;
|
|
32852
32852
|
}
|
|
@@ -32884,7 +32884,7 @@ var createFft = /* @__PURE__ */ factory(
|
|
|
32884
32884
|
pow: pow2,
|
|
32885
32885
|
ceil: ceil2,
|
|
32886
32886
|
log2: log23,
|
|
32887
|
-
complex:
|
|
32887
|
+
complex: complex3
|
|
32888
32888
|
}) => {
|
|
32889
32889
|
return typed3(name196, {
|
|
32890
32890
|
Array: _ndFft,
|
|
@@ -32892,40 +32892,40 @@ var createFft = /* @__PURE__ */ factory(
|
|
|
32892
32892
|
return matrix2.create(_ndFft(matrix2.valueOf()), matrix2._datatype);
|
|
32893
32893
|
}
|
|
32894
32894
|
});
|
|
32895
|
-
function _ndFft(
|
|
32896
|
-
const size2 = arraySize(
|
|
32897
|
-
if (size2.length === 1) return _fft(
|
|
32895
|
+
function _ndFft(arr10) {
|
|
32896
|
+
const size2 = arraySize(arr10);
|
|
32897
|
+
if (size2.length === 1) return _fft(arr10, size2[0]);
|
|
32898
32898
|
return _1dFft(
|
|
32899
|
-
|
|
32899
|
+
arr10.map((slice) => _ndFft(slice)),
|
|
32900
32900
|
0
|
|
32901
32901
|
);
|
|
32902
32902
|
}
|
|
32903
|
-
function _1dFft(
|
|
32904
|
-
const size2 = arraySize(
|
|
32903
|
+
function _1dFft(arr10, dim) {
|
|
32904
|
+
const size2 = arraySize(arr10);
|
|
32905
32905
|
if (dim !== 0) {
|
|
32906
32906
|
const result = [];
|
|
32907
32907
|
for (let i = 0; i < size2[0]; i++) {
|
|
32908
|
-
result.push(_1dFft(
|
|
32908
|
+
result.push(_1dFft(arr10[i], dim - 1));
|
|
32909
32909
|
}
|
|
32910
32910
|
return result;
|
|
32911
32911
|
}
|
|
32912
|
-
if (size2.length === 1) return _fft(
|
|
32913
|
-
function _transpose(
|
|
32914
|
-
const size3 = arraySize(
|
|
32912
|
+
if (size2.length === 1) return _fft(arr10);
|
|
32913
|
+
function _transpose(arr11) {
|
|
32914
|
+
const size3 = arraySize(arr11);
|
|
32915
32915
|
const result = [];
|
|
32916
32916
|
for (let j = 0; j < size3[1]; j++) {
|
|
32917
32917
|
const row2 = [];
|
|
32918
32918
|
for (let i = 0; i < size3[0]; i++) {
|
|
32919
|
-
row2.push(
|
|
32919
|
+
row2.push(arr11[i][j]);
|
|
32920
32920
|
}
|
|
32921
32921
|
result.push(row2);
|
|
32922
32922
|
}
|
|
32923
32923
|
return result;
|
|
32924
32924
|
}
|
|
32925
|
-
return _transpose(_1dFft(_transpose(
|
|
32925
|
+
return _transpose(_1dFft(_transpose(arr10), 1));
|
|
32926
32926
|
}
|
|
32927
|
-
function _czt(
|
|
32928
|
-
const n =
|
|
32927
|
+
function _czt(arr10) {
|
|
32928
|
+
const n = arr10.length;
|
|
32929
32929
|
const w = exp2(divideScalar2(multiplyScalar2(-1, multiplyScalar2(I2, tau2)), n));
|
|
32930
32930
|
const chirp = [];
|
|
32931
32931
|
for (let i = 1 - n; i < n; i++) {
|
|
@@ -32934,7 +32934,7 @@ var createFft = /* @__PURE__ */ factory(
|
|
|
32934
32934
|
const N2 = pow2(2, ceil2(log23(n + n - 1)));
|
|
32935
32935
|
const xp = [];
|
|
32936
32936
|
for (let i = 0; i < n; i++) {
|
|
32937
|
-
xp.push(multiplyScalar2(
|
|
32937
|
+
xp.push(multiplyScalar2(arr10[i], chirp[n - 1 + i]));
|
|
32938
32938
|
}
|
|
32939
32939
|
for (let i = 0; i < N2 - n; i++) {
|
|
32940
32940
|
xp.push(0);
|
|
@@ -32959,11 +32959,11 @@ var createFft = /* @__PURE__ */ factory(
|
|
|
32959
32959
|
}
|
|
32960
32960
|
return ret;
|
|
32961
32961
|
}
|
|
32962
|
-
function _fft(
|
|
32963
|
-
const length = len ??
|
|
32964
|
-
if (length === 1) return [
|
|
32965
|
-
if (length ===
|
|
32966
|
-
const interleaved = complexToInterleaved(
|
|
32962
|
+
function _fft(arr10, len) {
|
|
32963
|
+
const length = len ?? arr10.length;
|
|
32964
|
+
if (length === 1) return [arr10[0]];
|
|
32965
|
+
if (length === arr10.length && length >= FAST_FFT_THRESHOLD && isPowerOf23(length)) {
|
|
32966
|
+
const interleaved = complexToInterleaved(arr10, complex3);
|
|
32967
32967
|
if (interleaved) {
|
|
32968
32968
|
const real = new Float64Array(length);
|
|
32969
32969
|
const imag = new Float64Array(length);
|
|
@@ -32977,17 +32977,17 @@ var createFft = /* @__PURE__ */ factory(
|
|
|
32977
32977
|
result[i * 2] = out.real[i];
|
|
32978
32978
|
result[i * 2 + 1] = out.imag[i];
|
|
32979
32979
|
}
|
|
32980
|
-
return interleavedToComplex(result, length,
|
|
32980
|
+
return interleavedToComplex(result, length, complex3);
|
|
32981
32981
|
}
|
|
32982
32982
|
}
|
|
32983
32983
|
if (length % 2 === 0) {
|
|
32984
32984
|
const ret = [
|
|
32985
32985
|
..._fft(
|
|
32986
|
-
|
|
32986
|
+
arr10.filter((_, i) => i % 2 === 0),
|
|
32987
32987
|
length / 2
|
|
32988
32988
|
),
|
|
32989
32989
|
..._fft(
|
|
32990
|
-
|
|
32990
|
+
arr10.filter((_, i) => i % 2 === 1),
|
|
32991
32991
|
length / 2
|
|
32992
32992
|
)
|
|
32993
32993
|
];
|
|
@@ -33002,7 +33002,7 @@ var createFft = /* @__PURE__ */ factory(
|
|
|
33002
33002
|
}
|
|
33003
33003
|
return ret;
|
|
33004
33004
|
} else {
|
|
33005
|
-
return _czt(
|
|
33005
|
+
return _czt(arr10);
|
|
33006
33006
|
}
|
|
33007
33007
|
}
|
|
33008
33008
|
}
|
|
@@ -33273,11 +33273,11 @@ var FAST_IFFT_THRESHOLD = 64;
|
|
|
33273
33273
|
function isPowerOf24(n) {
|
|
33274
33274
|
return n > 0 && (n & n - 1) === 0;
|
|
33275
33275
|
}
|
|
33276
|
-
function complexToInterleaved2(
|
|
33277
|
-
const n =
|
|
33276
|
+
function complexToInterleaved2(arr10, _complex) {
|
|
33277
|
+
const n = arr10.length;
|
|
33278
33278
|
const result = new Float64Array(n * 2);
|
|
33279
33279
|
for (let i = 0; i < n; i++) {
|
|
33280
|
-
const val =
|
|
33280
|
+
const val = arr10[i];
|
|
33281
33281
|
if (typeof val === "number") {
|
|
33282
33282
|
result[i * 2] = val;
|
|
33283
33283
|
result[i * 2 + 1] = 0;
|
|
@@ -33291,10 +33291,10 @@ function complexToInterleaved2(arr8, _complex) {
|
|
|
33291
33291
|
}
|
|
33292
33292
|
return result;
|
|
33293
33293
|
}
|
|
33294
|
-
function interleavedToComplex2(data, n,
|
|
33294
|
+
function interleavedToComplex2(data, n, complex3) {
|
|
33295
33295
|
const result = [];
|
|
33296
33296
|
for (let i = 0; i < n; i++) {
|
|
33297
|
-
result.push(
|
|
33297
|
+
result.push(complex3(data[i * 2], data[i * 2 + 1]));
|
|
33298
33298
|
}
|
|
33299
33299
|
return result;
|
|
33300
33300
|
}
|
|
@@ -33303,16 +33303,16 @@ var dependencies200 = ["typed", "fft", "dotDivide", "conj", "complex"];
|
|
|
33303
33303
|
var createIfft = /* @__PURE__ */ factory(
|
|
33304
33304
|
name200,
|
|
33305
33305
|
dependencies200,
|
|
33306
|
-
({ typed: typed3, fft:
|
|
33306
|
+
({ typed: typed3, fft: fft3, dotDivide: dotDivide2, conj: conj3, complex: complex3 }) => {
|
|
33307
33307
|
return typed3(name200, {
|
|
33308
|
-
"Array | Matrix": function(
|
|
33309
|
-
const size2 = isMatrix(
|
|
33308
|
+
"Array | Matrix": function(arr10) {
|
|
33309
|
+
const size2 = isMatrix(arr10) ? arr10.size() : arraySize(arr10);
|
|
33310
33310
|
const totalSize = size2.reduce((acc, curr) => acc * curr, 1);
|
|
33311
33311
|
if (size2.length === 1) {
|
|
33312
33312
|
const length = size2[0];
|
|
33313
33313
|
if (length >= FAST_IFFT_THRESHOLD && isPowerOf24(length)) {
|
|
33314
|
-
const arrData = isMatrix(
|
|
33315
|
-
const interleaved = complexToInterleaved2(arrData,
|
|
33314
|
+
const arrData = isMatrix(arr10) ? arr10.valueOf() : arr10;
|
|
33315
|
+
const interleaved = complexToInterleaved2(arrData, complex3);
|
|
33316
33316
|
if (interleaved) {
|
|
33317
33317
|
const real = new Float64Array(length);
|
|
33318
33318
|
const imag = new Float64Array(length);
|
|
@@ -33326,15 +33326,15 @@ var createIfft = /* @__PURE__ */ factory(
|
|
|
33326
33326
|
packed[i * 2] = out.real[i];
|
|
33327
33327
|
packed[i * 2 + 1] = out.imag[i];
|
|
33328
33328
|
}
|
|
33329
|
-
const result = interleavedToComplex2(packed, length,
|
|
33330
|
-
if (isMatrix(
|
|
33331
|
-
return
|
|
33329
|
+
const result = interleavedToComplex2(packed, length, complex3);
|
|
33330
|
+
if (isMatrix(arr10)) {
|
|
33331
|
+
return arr10.create(result);
|
|
33332
33332
|
}
|
|
33333
33333
|
return result;
|
|
33334
33334
|
}
|
|
33335
33335
|
}
|
|
33336
33336
|
}
|
|
33337
|
-
return dotDivide2(conj3(
|
|
33337
|
+
return dotDivide2(conj3(fft3(conj3(arr10))), totalSize);
|
|
33338
33338
|
}
|
|
33339
33339
|
});
|
|
33340
33340
|
}
|
|
@@ -34298,51 +34298,51 @@ var createDiff = /* @__PURE__ */ factory(
|
|
|
34298
34298
|
number: number2
|
|
34299
34299
|
}) => {
|
|
34300
34300
|
return typed3(name210, {
|
|
34301
|
-
"Array | Matrix": function(
|
|
34302
|
-
if (isMatrix(
|
|
34303
|
-
return matrix2(_diff(
|
|
34301
|
+
"Array | Matrix": function(arr10) {
|
|
34302
|
+
if (isMatrix(arr10)) {
|
|
34303
|
+
return matrix2(_diff(arr10.toArray()));
|
|
34304
34304
|
} else {
|
|
34305
|
-
return _diff(
|
|
34305
|
+
return _diff(arr10);
|
|
34306
34306
|
}
|
|
34307
34307
|
},
|
|
34308
|
-
"Array | Matrix, number": function(
|
|
34308
|
+
"Array | Matrix, number": function(arr10, dim) {
|
|
34309
34309
|
if (!isInteger(dim)) throw new RangeError("Dimension must be a whole number");
|
|
34310
|
-
if (isMatrix(
|
|
34311
|
-
return matrix2(_recursive(
|
|
34310
|
+
if (isMatrix(arr10)) {
|
|
34311
|
+
return matrix2(_recursive(arr10.toArray(), dim));
|
|
34312
34312
|
} else {
|
|
34313
|
-
return _recursive(
|
|
34313
|
+
return _recursive(arr10, dim);
|
|
34314
34314
|
}
|
|
34315
34315
|
},
|
|
34316
34316
|
// typed-function's runtime `referTo` is single-call variadic
|
|
34317
34317
|
// (`referTo(...signatures, callback)`); the imported TypedFunction interface
|
|
34318
34318
|
// models it curried, so narrow to the real contract via `unknown`.
|
|
34319
|
-
"Array, BigNumber": typed3.referTo("Array,number", (selfAn) => (
|
|
34320
|
-
"Matrix, BigNumber": typed3.referTo("Matrix,number", (selfMn) => (
|
|
34319
|
+
"Array, BigNumber": typed3.referTo("Array,number", (selfAn) => (arr10, dim) => selfAn(arr10, number2(dim))),
|
|
34320
|
+
"Matrix, BigNumber": typed3.referTo("Matrix,number", (selfMn) => (arr10, dim) => selfMn(arr10, number2(dim)))
|
|
34321
34321
|
});
|
|
34322
|
-
function _recursive(
|
|
34323
|
-
if (isMatrix(
|
|
34324
|
-
|
|
34322
|
+
function _recursive(arr10, dim) {
|
|
34323
|
+
if (isMatrix(arr10)) {
|
|
34324
|
+
arr10 = arr10.toArray();
|
|
34325
34325
|
}
|
|
34326
|
-
if (!Array.isArray(
|
|
34326
|
+
if (!Array.isArray(arr10)) {
|
|
34327
34327
|
throw RangeError("Array/Matrix does not have that many dimensions");
|
|
34328
34328
|
}
|
|
34329
34329
|
if (dim > 0) {
|
|
34330
34330
|
const result = [];
|
|
34331
|
-
|
|
34331
|
+
arr10.forEach((element2) => {
|
|
34332
34332
|
result.push(_recursive(element2, dim - 1));
|
|
34333
34333
|
});
|
|
34334
34334
|
return result;
|
|
34335
34335
|
} else if (dim === 0) {
|
|
34336
|
-
return _diff(
|
|
34336
|
+
return _diff(arr10);
|
|
34337
34337
|
} else {
|
|
34338
34338
|
throw RangeError("Cannot have negative dimension");
|
|
34339
34339
|
}
|
|
34340
34340
|
}
|
|
34341
|
-
function _diff(
|
|
34341
|
+
function _diff(arr10) {
|
|
34342
34342
|
const result = [];
|
|
34343
|
-
const size2 =
|
|
34343
|
+
const size2 = arr10.length;
|
|
34344
34344
|
for (let i = 1; i < size2; i++) {
|
|
34345
|
-
result.push(_ElementDiff(
|
|
34345
|
+
result.push(_ElementDiff(arr10[i - 1], arr10[i]));
|
|
34346
34346
|
}
|
|
34347
34347
|
return result;
|
|
34348
34348
|
}
|
|
@@ -35428,21 +35428,21 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
35428
35428
|
"Array, Array, Array": _AAA,
|
|
35429
35429
|
"Array, Array, Array, Array": _AAAA,
|
|
35430
35430
|
"Matrix, Matrix, Matrix": function(x, y, plane) {
|
|
35431
|
-
const
|
|
35431
|
+
const arr10 = _AAA(
|
|
35432
35432
|
x.valueOf(),
|
|
35433
35433
|
y.valueOf(),
|
|
35434
35434
|
plane.valueOf()
|
|
35435
35435
|
);
|
|
35436
|
-
return
|
|
35436
|
+
return arr10 === null ? null : matrix2(arr10);
|
|
35437
35437
|
},
|
|
35438
35438
|
"Matrix, Matrix, Matrix, Matrix": function(w, x, y, z) {
|
|
35439
|
-
const
|
|
35439
|
+
const arr10 = _AAAA(
|
|
35440
35440
|
w.valueOf(),
|
|
35441
35441
|
x.valueOf(),
|
|
35442
35442
|
y.valueOf(),
|
|
35443
35443
|
z.valueOf()
|
|
35444
35444
|
);
|
|
35445
|
-
return
|
|
35445
|
+
return arr10 === null ? null : matrix2(arr10);
|
|
35446
35446
|
}
|
|
35447
35447
|
});
|
|
35448
35448
|
function _AAA(x, y, plane) {
|
|
@@ -35508,13 +35508,13 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
35508
35508
|
throw new TypeError("Arrays with two or thee dimensional points expected");
|
|
35509
35509
|
}
|
|
35510
35510
|
}
|
|
35511
|
-
function _coerceArr(
|
|
35512
|
-
if (
|
|
35513
|
-
if (
|
|
35514
|
-
if (
|
|
35515
|
-
return flatten4(
|
|
35511
|
+
function _coerceArr(arr10) {
|
|
35512
|
+
if (arr10.length === 1 && Array.isArray(arr10[0])) return arr10[0];
|
|
35513
|
+
if (arr10.length > 1 && Array.isArray(arr10[0])) {
|
|
35514
|
+
if (arr10.every((el) => Array.isArray(el) && el.length === 1))
|
|
35515
|
+
return flatten4(arr10);
|
|
35516
35516
|
}
|
|
35517
|
-
return
|
|
35517
|
+
return arr10;
|
|
35518
35518
|
}
|
|
35519
35519
|
function _2d(x) {
|
|
35520
35520
|
return x.length === 2 && isNumeric2(x[0]) && isNumeric2(x[1]);
|
|
@@ -35654,9 +35654,9 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
35654
35654
|
|
|
35655
35655
|
// src/statistics/mean.ts
|
|
35656
35656
|
var WASM_MEAN_THRESHOLD = 100;
|
|
35657
|
-
function isFlatNumberArray7(
|
|
35658
|
-
for (let i = 0; i <
|
|
35659
|
-
if (typeof
|
|
35657
|
+
function isFlatNumberArray7(arr10) {
|
|
35658
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
35659
|
+
if (typeof arr10[i] !== "number") {
|
|
35660
35660
|
return false;
|
|
35661
35661
|
}
|
|
35662
35662
|
}
|
|
@@ -35788,9 +35788,9 @@ var createMedian = /* @__PURE__ */ factory(
|
|
|
35788
35788
|
|
|
35789
35789
|
// src/statistics/variance.ts
|
|
35790
35790
|
import { sumSquaredDeviations as sumSquaredDeviations2 } from "@danielsimonjr/mathts-core";
|
|
35791
|
-
function isFlatNumberArray8(
|
|
35792
|
-
for (let i = 0; i <
|
|
35793
|
-
if (typeof
|
|
35791
|
+
function isFlatNumberArray8(arr10) {
|
|
35792
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
35793
|
+
if (typeof arr10[i] !== "number") {
|
|
35794
35794
|
return false;
|
|
35795
35795
|
}
|
|
35796
35796
|
}
|
|
@@ -36105,7 +36105,7 @@ var dependencies224 = ["typed", "add", "divide", "multiply", "factorial", "isInt
|
|
|
36105
36105
|
var createMultinomial = /* @__PURE__ */ factory(
|
|
36106
36106
|
name224,
|
|
36107
36107
|
dependencies224,
|
|
36108
|
-
({ typed: typed3, add: add2, divide: divide2, multiply: multiply2, factorial:
|
|
36108
|
+
({ typed: typed3, add: add2, divide: divide2, multiply: multiply2, factorial: factorial5, isInteger: isInteger3, isPositive: isPositive2 }) => {
|
|
36109
36109
|
return typed3(name224, {
|
|
36110
36110
|
"Array | Matrix": function(a) {
|
|
36111
36111
|
let sum3 = 0;
|
|
@@ -36115,9 +36115,9 @@ var createMultinomial = /* @__PURE__ */ factory(
|
|
|
36115
36115
|
throw new TypeError("Positive integer value expected in function multinomial");
|
|
36116
36116
|
}
|
|
36117
36117
|
sum3 = add2(sum3, ai);
|
|
36118
|
-
denom = multiply2(denom,
|
|
36118
|
+
denom = multiply2(denom, factorial5(ai));
|
|
36119
36119
|
});
|
|
36120
|
-
return divide2(
|
|
36120
|
+
return divide2(factorial5(sum3), denom);
|
|
36121
36121
|
}
|
|
36122
36122
|
});
|
|
36123
36123
|
}
|
|
@@ -36130,7 +36130,7 @@ var dependencies225 = ["typed", "add", "multiply", "Complex", "divide", "matrix"
|
|
|
36130
36130
|
var createFreqz = /* @__PURE__ */ factory(
|
|
36131
36131
|
name225,
|
|
36132
36132
|
dependencies225,
|
|
36133
|
-
({ typed: typed3, add: add2, multiply: multiply2, Complex:
|
|
36133
|
+
({ typed: typed3, add: add2, multiply: multiply2, Complex: Complex13, divide: divide2, matrix: matrix2 }) => {
|
|
36134
36134
|
return typed3(name225, {
|
|
36135
36135
|
"Array, Array": function(b, a) {
|
|
36136
36136
|
const w = createBins(512);
|
|
@@ -36199,7 +36199,7 @@ var createFreqz = /* @__PURE__ */ factory(
|
|
|
36199
36199
|
);
|
|
36200
36200
|
const h = [];
|
|
36201
36201
|
for (let i = 0; i < w.length; i++) {
|
|
36202
|
-
h.push(
|
|
36202
|
+
h.push(Complex13(hRealAlloc.array[i], hImagAlloc.array[i]));
|
|
36203
36203
|
}
|
|
36204
36204
|
return { h, w };
|
|
36205
36205
|
} finally {
|
|
@@ -36221,18 +36221,18 @@ var createFreqz = /* @__PURE__ */ factory(
|
|
|
36221
36221
|
const num2 = [];
|
|
36222
36222
|
const den = [];
|
|
36223
36223
|
for (let i = 0; i < w.length; i++) {
|
|
36224
|
-
let sumNum =
|
|
36225
|
-
let sumDen =
|
|
36224
|
+
let sumNum = Complex13(0, 0);
|
|
36225
|
+
let sumDen = Complex13(0, 0);
|
|
36226
36226
|
for (let j = 0; j < b.length; j++) {
|
|
36227
36227
|
sumNum = add2(
|
|
36228
36228
|
sumNum,
|
|
36229
|
-
multiply2(b[j],
|
|
36229
|
+
multiply2(b[j], Complex13(Math.cos(-j * w[i]), Math.sin(-j * w[i])))
|
|
36230
36230
|
);
|
|
36231
36231
|
}
|
|
36232
36232
|
for (let j = 0; j < a.length; j++) {
|
|
36233
36233
|
sumDen = add2(
|
|
36234
36234
|
sumDen,
|
|
36235
|
-
multiply2(a[j],
|
|
36235
|
+
multiply2(a[j], Complex13(Math.cos(-j * w[i]), Math.sin(-j * w[i])))
|
|
36236
36236
|
);
|
|
36237
36237
|
}
|
|
36238
36238
|
num2.push(sumNum);
|
|
@@ -37174,7 +37174,7 @@ var createZeta = /* @__PURE__ */ factory(
|
|
|
37174
37174
|
multiply: multiply2,
|
|
37175
37175
|
pow: pow2,
|
|
37176
37176
|
divide: divide2,
|
|
37177
|
-
factorial:
|
|
37177
|
+
factorial: factorial5,
|
|
37178
37178
|
equal: equal2,
|
|
37179
37179
|
smallerEq: smallerEq2,
|
|
37180
37180
|
isBounded: isBounded2,
|
|
@@ -37183,7 +37183,7 @@ var createZeta = /* @__PURE__ */ factory(
|
|
|
37183
37183
|
sin: sin2,
|
|
37184
37184
|
subtract: subtract2,
|
|
37185
37185
|
add: add2,
|
|
37186
|
-
Complex:
|
|
37186
|
+
Complex: Complex13,
|
|
37187
37187
|
BigNumber: BigNumber9,
|
|
37188
37188
|
pi
|
|
37189
37189
|
}) => {
|
|
@@ -37219,16 +37219,16 @@ var createZeta = /* @__PURE__ */ factory(
|
|
|
37219
37219
|
}
|
|
37220
37220
|
function zetaComplex(s) {
|
|
37221
37221
|
if (s.re === 0 && s.im === 0) {
|
|
37222
|
-
return new
|
|
37222
|
+
return new Complex13(-0.5);
|
|
37223
37223
|
}
|
|
37224
37224
|
if (s.re === 1 && s.im === 0) {
|
|
37225
|
-
return new
|
|
37225
|
+
return new Complex13(NaN, NaN);
|
|
37226
37226
|
}
|
|
37227
37227
|
if (s.re === Infinity && s.im === 0) {
|
|
37228
|
-
return new
|
|
37228
|
+
return new Complex13(1);
|
|
37229
37229
|
}
|
|
37230
37230
|
if (s.im === Infinity || s.re === -Infinity) {
|
|
37231
|
-
return new
|
|
37231
|
+
return new Complex13(NaN, NaN);
|
|
37232
37232
|
}
|
|
37233
37233
|
return zeta2(
|
|
37234
37234
|
s,
|
|
@@ -37252,8 +37252,8 @@ var createZeta = /* @__PURE__ */ factory(
|
|
|
37252
37252
|
let S = k;
|
|
37253
37253
|
for (let j = k; smallerEq2(j, n); j = add2(j, 1)) {
|
|
37254
37254
|
const factor2 = divide2(
|
|
37255
|
-
multiply2(
|
|
37256
|
-
multiply2(
|
|
37255
|
+
multiply2(factorial5(add2(n, subtract2(j, 1))), pow2(4, j)),
|
|
37256
|
+
multiply2(factorial5(subtract2(n, j)), factorial5(multiply2(2, j)))
|
|
37257
37257
|
);
|
|
37258
37258
|
S = add2(S, factor2);
|
|
37259
37259
|
}
|
|
@@ -37325,18 +37325,18 @@ function createComplexEigs({
|
|
|
37325
37325
|
usolve: usolve2,
|
|
37326
37326
|
usolveAll: usolveAll2,
|
|
37327
37327
|
equal: equal2,
|
|
37328
|
-
complex:
|
|
37328
|
+
complex: complex3,
|
|
37329
37329
|
larger: larger2,
|
|
37330
37330
|
smaller: smaller2,
|
|
37331
37331
|
matrixFromColumns: _matrixFromColumns,
|
|
37332
37332
|
dot: dot5
|
|
37333
37333
|
}) {
|
|
37334
|
-
function complexEigs(
|
|
37334
|
+
function complexEigs(arr10, N, prec, type, findVectors = true) {
|
|
37335
37335
|
if (!findVectors && type === "number" && N * N >= WASM_EIGS_THRESHOLD) {
|
|
37336
37336
|
const wasm = wasmLoader.getModule();
|
|
37337
37337
|
if (wasm) {
|
|
37338
37338
|
try {
|
|
37339
|
-
const flat = flattenToFloat648(
|
|
37339
|
+
const flat = flattenToFloat648(arr10, N, N);
|
|
37340
37340
|
const matrixAlloc = wasmLoader.allocateFloat64Array(flat);
|
|
37341
37341
|
const eigenvaluesRealAlloc = wasmLoader.allocateFloat64ArrayEmpty(N);
|
|
37342
37342
|
const eigenvaluesImagAlloc = wasmLoader.allocateFloat64ArrayEmpty(N);
|
|
@@ -37360,7 +37360,7 @@ function createComplexEigs({
|
|
|
37360
37360
|
if (Math.abs(im3) < 1e-14) {
|
|
37361
37361
|
values2.push(re3);
|
|
37362
37362
|
} else {
|
|
37363
|
-
values2.push(
|
|
37363
|
+
values2.push(complex3(re3, im3));
|
|
37364
37364
|
}
|
|
37365
37365
|
}
|
|
37366
37366
|
values2.sort((a, b) => {
|
|
@@ -37380,20 +37380,20 @@ function createComplexEigs({
|
|
|
37380
37380
|
}
|
|
37381
37381
|
}
|
|
37382
37382
|
}
|
|
37383
|
-
const R = balance(
|
|
37384
|
-
reduceToHessenberg(
|
|
37385
|
-
const { values, C } = iterateUntilTriangular(
|
|
37383
|
+
const R = balance(arr10, N, prec, type, findVectors);
|
|
37384
|
+
reduceToHessenberg(arr10, N, prec, type, findVectors, R);
|
|
37385
|
+
const { values, C } = iterateUntilTriangular(arr10, N, prec, type, findVectors);
|
|
37386
37386
|
if (findVectors) {
|
|
37387
|
-
const eigenvectors = findEigenvectors(
|
|
37387
|
+
const eigenvectors = findEigenvectors(arr10, N, C, R, values, prec, type);
|
|
37388
37388
|
return { values, eigenvectors };
|
|
37389
37389
|
}
|
|
37390
37390
|
return { values };
|
|
37391
37391
|
}
|
|
37392
|
-
function balance(
|
|
37392
|
+
function balance(arr10, N, _prec, type, findVectors) {
|
|
37393
37393
|
const big = type === "BigNumber";
|
|
37394
37394
|
const cplx = type === "Complex";
|
|
37395
37395
|
const realzero = big ? bignumber2(0) : 0;
|
|
37396
|
-
const one = big ? bignumber2(1) : cplx ?
|
|
37396
|
+
const one = big ? bignumber2(1) : cplx ? complex3(1) : 1;
|
|
37397
37397
|
const realone = big ? bignumber2(1) : 1;
|
|
37398
37398
|
const radix = big ? bignumber2(10) : 2;
|
|
37399
37399
|
const radixSq = multiplyScalar2(radix, radix);
|
|
@@ -37409,8 +37409,8 @@ function createComplexEigs({
|
|
|
37409
37409
|
let rowNorm = realzero;
|
|
37410
37410
|
for (let j = 0; j < N; j++) {
|
|
37411
37411
|
if (i === j) continue;
|
|
37412
|
-
colNorm = addScalar2(colNorm, abs2(
|
|
37413
|
-
rowNorm = addScalar2(rowNorm, abs2(
|
|
37412
|
+
colNorm = addScalar2(colNorm, abs2(arr10[j][i]));
|
|
37413
|
+
rowNorm = addScalar2(rowNorm, abs2(arr10[i][j]));
|
|
37414
37414
|
}
|
|
37415
37415
|
if (!equal2(colNorm, 0) && !equal2(rowNorm, 0)) {
|
|
37416
37416
|
let f = realone;
|
|
@@ -37436,8 +37436,8 @@ function createComplexEigs({
|
|
|
37436
37436
|
if (i === j) {
|
|
37437
37437
|
continue;
|
|
37438
37438
|
}
|
|
37439
|
-
|
|
37440
|
-
|
|
37439
|
+
arr10[i][j] = multiplyScalar2(arr10[i][j], g);
|
|
37440
|
+
arr10[j][i] = multiplyScalar2(arr10[j][i], f);
|
|
37441
37441
|
}
|
|
37442
37442
|
if (findVectors) {
|
|
37443
37443
|
Rdiag[i] = multiplyScalar2(Rdiag[i], g);
|
|
@@ -37448,10 +37448,10 @@ function createComplexEigs({
|
|
|
37448
37448
|
}
|
|
37449
37449
|
return findVectors ? diag2(Rdiag) : null;
|
|
37450
37450
|
}
|
|
37451
|
-
function reduceToHessenberg(
|
|
37451
|
+
function reduceToHessenberg(arr10, N, prec, type, findVectors, R) {
|
|
37452
37452
|
const big = type === "BigNumber";
|
|
37453
37453
|
const cplx = type === "Complex";
|
|
37454
|
-
const zero = big ? bignumber2(0) : cplx ?
|
|
37454
|
+
const zero = big ? bignumber2(0) : cplx ? complex3(0) : 0;
|
|
37455
37455
|
if (big) {
|
|
37456
37456
|
prec = bignumber2(prec);
|
|
37457
37457
|
}
|
|
@@ -37459,7 +37459,7 @@ function createComplexEigs({
|
|
|
37459
37459
|
let maxIndex = 0;
|
|
37460
37460
|
let max2 = zero;
|
|
37461
37461
|
for (let j = i + 1; j < N; j++) {
|
|
37462
|
-
const el =
|
|
37462
|
+
const el = arr10[j][i];
|
|
37463
37463
|
if (smaller2(abs2(max2), abs2(el))) {
|
|
37464
37464
|
max2 = el;
|
|
37465
37465
|
maxIndex = j;
|
|
@@ -37469,13 +37469,13 @@ function createComplexEigs({
|
|
|
37469
37469
|
continue;
|
|
37470
37470
|
}
|
|
37471
37471
|
if (maxIndex !== i + 1) {
|
|
37472
|
-
const tmp1 =
|
|
37473
|
-
|
|
37474
|
-
|
|
37472
|
+
const tmp1 = arr10[maxIndex];
|
|
37473
|
+
arr10[maxIndex] = arr10[i + 1];
|
|
37474
|
+
arr10[i + 1] = tmp1;
|
|
37475
37475
|
for (let j = 0; j < N; j++) {
|
|
37476
|
-
const tmp2 =
|
|
37477
|
-
|
|
37478
|
-
|
|
37476
|
+
const tmp2 = arr10[j][maxIndex];
|
|
37477
|
+
arr10[j][maxIndex] = arr10[j][i + 1];
|
|
37478
|
+
arr10[j][i + 1] = tmp2;
|
|
37479
37479
|
}
|
|
37480
37480
|
if (findVectors) {
|
|
37481
37481
|
const tmp3 = R[maxIndex];
|
|
@@ -37484,15 +37484,15 @@ function createComplexEigs({
|
|
|
37484
37484
|
}
|
|
37485
37485
|
}
|
|
37486
37486
|
for (let j = i + 2; j < N; j++) {
|
|
37487
|
-
const n = divideScalar2(
|
|
37487
|
+
const n = divideScalar2(arr10[j][i], max2);
|
|
37488
37488
|
if (n === 0) {
|
|
37489
37489
|
continue;
|
|
37490
37490
|
}
|
|
37491
37491
|
for (let k = 0; k < N; k++) {
|
|
37492
|
-
|
|
37492
|
+
arr10[j][k] = subtract2(arr10[j][k], multiplyScalar2(n, arr10[i + 1][k]));
|
|
37493
37493
|
}
|
|
37494
37494
|
for (let k = 0; k < N; k++) {
|
|
37495
|
-
|
|
37495
|
+
arr10[k][i + 1] = addScalar2(arr10[k][i + 1], multiplyScalar2(n, arr10[k][j]));
|
|
37496
37496
|
}
|
|
37497
37497
|
if (findVectors) {
|
|
37498
37498
|
for (let k = 0; k < N; k++) {
|
|
@@ -37505,11 +37505,11 @@ function createComplexEigs({
|
|
|
37505
37505
|
function iterateUntilTriangular(A, N, prec, type, findVectors) {
|
|
37506
37506
|
const big = type === "BigNumber";
|
|
37507
37507
|
const cplx = type === "Complex";
|
|
37508
|
-
const one = big ? bignumber2(1) : cplx ?
|
|
37508
|
+
const one = big ? bignumber2(1) : cplx ? complex3(1) : 1;
|
|
37509
37509
|
if (big) {
|
|
37510
37510
|
prec = bignumber2(prec);
|
|
37511
37511
|
}
|
|
37512
|
-
let
|
|
37512
|
+
let arr10 = clone(A);
|
|
37513
37513
|
const lambdas = [];
|
|
37514
37514
|
let n = N;
|
|
37515
37515
|
const Sdiag = [];
|
|
@@ -37518,21 +37518,21 @@ function createComplexEigs({
|
|
|
37518
37518
|
let lastConvergenceBefore = 0;
|
|
37519
37519
|
while (lastConvergenceBefore <= 100) {
|
|
37520
37520
|
lastConvergenceBefore += 1;
|
|
37521
|
-
const k =
|
|
37521
|
+
const k = arr10[n - 1][n - 1];
|
|
37522
37522
|
for (let i = 0; i < n; i++) {
|
|
37523
|
-
|
|
37523
|
+
arr10[i][i] = subtract2(arr10[i][i], k);
|
|
37524
37524
|
}
|
|
37525
|
-
const { Q: Q2, R } = qr2(
|
|
37526
|
-
|
|
37525
|
+
const { Q: Q2, R } = qr2(arr10);
|
|
37526
|
+
arr10 = multiply2(R, Q2);
|
|
37527
37527
|
for (let i = 0; i < n; i++) {
|
|
37528
|
-
|
|
37528
|
+
arr10[i][i] = addScalar2(arr10[i][i], k);
|
|
37529
37529
|
}
|
|
37530
37530
|
if (findVectors) {
|
|
37531
37531
|
Qpartial = multiply2(Qpartial, Q2);
|
|
37532
37532
|
}
|
|
37533
|
-
if (n === 1 || smaller2(abs2(
|
|
37533
|
+
if (n === 1 || smaller2(abs2(arr10[n - 1][n - 2]), prec)) {
|
|
37534
37534
|
lastConvergenceBefore = 0;
|
|
37535
|
-
lambdas.push(
|
|
37535
|
+
lambdas.push(arr10[n - 1][n - 1]);
|
|
37536
37536
|
if (findVectors) {
|
|
37537
37537
|
Sdiag.unshift([[1]]);
|
|
37538
37538
|
inflateMatrix(Qpartial, N);
|
|
@@ -37542,26 +37542,26 @@ function createComplexEigs({
|
|
|
37542
37542
|
}
|
|
37543
37543
|
}
|
|
37544
37544
|
n -= 1;
|
|
37545
|
-
|
|
37545
|
+
arr10.pop();
|
|
37546
37546
|
for (let i = 0; i < n; i++) {
|
|
37547
|
-
|
|
37547
|
+
arr10[i].pop();
|
|
37548
37548
|
}
|
|
37549
|
-
} else if (n === 2 || smaller2(abs2(
|
|
37549
|
+
} else if (n === 2 || smaller2(abs2(arr10[n - 2][n - 3]), prec)) {
|
|
37550
37550
|
lastConvergenceBefore = 0;
|
|
37551
37551
|
const ll = eigenvalues2x2(
|
|
37552
|
-
|
|
37553
|
-
|
|
37554
|
-
|
|
37555
|
-
|
|
37552
|
+
arr10[n - 2][n - 2],
|
|
37553
|
+
arr10[n - 2][n - 1],
|
|
37554
|
+
arr10[n - 1][n - 2],
|
|
37555
|
+
arr10[n - 1][n - 1]
|
|
37556
37556
|
);
|
|
37557
37557
|
lambdas.push(...ll);
|
|
37558
37558
|
if (findVectors) {
|
|
37559
37559
|
Sdiag.unshift(
|
|
37560
37560
|
jordanBase2x2(
|
|
37561
|
-
|
|
37562
|
-
|
|
37563
|
-
|
|
37564
|
-
|
|
37561
|
+
arr10[n - 2][n - 2],
|
|
37562
|
+
arr10[n - 2][n - 1],
|
|
37563
|
+
arr10[n - 1][n - 2],
|
|
37564
|
+
arr10[n - 1][n - 1],
|
|
37565
37565
|
ll[0],
|
|
37566
37566
|
ll[1],
|
|
37567
37567
|
prec,
|
|
@@ -37575,11 +37575,11 @@ function createComplexEigs({
|
|
|
37575
37575
|
}
|
|
37576
37576
|
}
|
|
37577
37577
|
n -= 2;
|
|
37578
|
-
|
|
37579
|
-
|
|
37578
|
+
arr10.pop();
|
|
37579
|
+
arr10.pop();
|
|
37580
37580
|
for (let i = 0; i < n; i++) {
|
|
37581
|
-
|
|
37582
|
-
|
|
37581
|
+
arr10[i].pop();
|
|
37582
|
+
arr10[i].pop();
|
|
37583
37583
|
}
|
|
37584
37584
|
}
|
|
37585
37585
|
if (n === 0) {
|
|
@@ -37603,8 +37603,8 @@ function createComplexEigs({
|
|
|
37603
37603
|
const U = multiply2(multiply2(Cinv, A), C);
|
|
37604
37604
|
const big = type === "BigNumber";
|
|
37605
37605
|
const cplx = type === "Complex";
|
|
37606
|
-
const zero = big ? bignumber2(0) : cplx ?
|
|
37607
|
-
const one = big ? bignumber2(1) : cplx ?
|
|
37606
|
+
const zero = big ? bignumber2(0) : cplx ? complex3(0) : 0;
|
|
37607
|
+
const one = big ? bignumber2(1) : cplx ? complex3(1) : 1;
|
|
37608
37608
|
const uniqueValues = [];
|
|
37609
37609
|
const multiplicities = [];
|
|
37610
37610
|
for (const lambda of values) {
|
|
@@ -37656,8 +37656,8 @@ function createComplexEigs({
|
|
|
37656
37656
|
function jordanBase2x2(a, b, c, d, l1, l2, prec, type) {
|
|
37657
37657
|
const big = type === "BigNumber";
|
|
37658
37658
|
const cplx = type === "Complex";
|
|
37659
|
-
const zero = big ? bignumber2(0) : cplx ?
|
|
37660
|
-
const one = big ? bignumber2(1) : cplx ?
|
|
37659
|
+
const zero = big ? bignumber2(0) : cplx ? complex3(0) : 0;
|
|
37660
|
+
const one = big ? bignumber2(1) : cplx ? complex3(1) : 1;
|
|
37661
37661
|
if (smaller2(abs2(c), prec)) {
|
|
37662
37662
|
return [
|
|
37663
37663
|
[one, zero],
|
|
@@ -37684,23 +37684,23 @@ function createComplexEigs({
|
|
|
37684
37684
|
];
|
|
37685
37685
|
}
|
|
37686
37686
|
}
|
|
37687
|
-
function inflateMatrix(
|
|
37688
|
-
for (let i = 0; i <
|
|
37689
|
-
|
|
37687
|
+
function inflateMatrix(arr10, N) {
|
|
37688
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
37689
|
+
arr10[i].push(...Array(N - arr10[i].length).fill(0));
|
|
37690
37690
|
}
|
|
37691
|
-
for (let i =
|
|
37692
|
-
|
|
37693
|
-
|
|
37691
|
+
for (let i = arr10.length; i < N; i++) {
|
|
37692
|
+
arr10.push(Array(N).fill(0));
|
|
37693
|
+
arr10[i][i] = 1;
|
|
37694
37694
|
}
|
|
37695
|
-
return
|
|
37695
|
+
return arr10;
|
|
37696
37696
|
}
|
|
37697
|
-
function blockDiag(
|
|
37697
|
+
function blockDiag(arr10, N) {
|
|
37698
37698
|
const M = [];
|
|
37699
37699
|
for (let i = 0; i < N; i++) {
|
|
37700
37700
|
M[i] = Array(N).fill(0);
|
|
37701
37701
|
}
|
|
37702
37702
|
let I2 = 0;
|
|
37703
|
-
for (const sub of
|
|
37703
|
+
for (const sub of arr10) {
|
|
37704
37704
|
const n = sub.length;
|
|
37705
37705
|
for (let i = 0; i < n; i++) {
|
|
37706
37706
|
for (let j = 0; j < n; j++) {
|
|
@@ -37711,9 +37711,9 @@ function createComplexEigs({
|
|
|
37711
37711
|
}
|
|
37712
37712
|
return M;
|
|
37713
37713
|
}
|
|
37714
|
-
function indexOf(
|
|
37715
|
-
for (let i = 0; i <
|
|
37716
|
-
if (fn(
|
|
37714
|
+
function indexOf(arr10, el, fn) {
|
|
37715
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
37716
|
+
if (fn(arr10[i], el)) {
|
|
37717
37717
|
return i;
|
|
37718
37718
|
}
|
|
37719
37719
|
}
|
|
@@ -37758,7 +37758,7 @@ function createComplexEigs({
|
|
|
37758
37758
|
v = v.map((n) => bignumber2(n));
|
|
37759
37759
|
}
|
|
37760
37760
|
if (cplx) {
|
|
37761
|
-
v = v.map((n) =>
|
|
37761
|
+
v = v.map((n) => complex3(n));
|
|
37762
37762
|
}
|
|
37763
37763
|
v = orthogonalComplement(v, orthog);
|
|
37764
37764
|
return normalize2(v, type);
|
|
@@ -37783,7 +37783,7 @@ function createComplexEigs({
|
|
|
37783
37783
|
function normalize2(v, type) {
|
|
37784
37784
|
const big = type === "BigNumber";
|
|
37785
37785
|
const cplx = type === "Complex";
|
|
37786
|
-
const one = big ? bignumber2(1) : cplx ?
|
|
37786
|
+
const one = big ? bignumber2(1) : cplx ? complex3(1) : 1;
|
|
37787
37787
|
return multiply2(divideScalar2(one, norm4(v)), v);
|
|
37788
37788
|
}
|
|
37789
37789
|
return complexEigs;
|
|
@@ -37826,12 +37826,12 @@ function createRealSymmetric({
|
|
|
37826
37826
|
if (typeof a === "number" && typeof b === "number") return a <= b;
|
|
37827
37827
|
return a.lte(b);
|
|
37828
37828
|
}
|
|
37829
|
-
function main(
|
|
37829
|
+
function main(arr10, _N, prec = config2.relTol, type, computeVectors) {
|
|
37830
37830
|
if (type === "number") {
|
|
37831
|
-
return diag2(
|
|
37831
|
+
return diag2(arr10, prec, computeVectors);
|
|
37832
37832
|
}
|
|
37833
37833
|
if (type === "BigNumber") {
|
|
37834
|
-
return diagBig(
|
|
37834
|
+
return diagBig(arr10, prec, computeVectors);
|
|
37835
37835
|
}
|
|
37836
37836
|
throw TypeError("Unsupported data type: " + type);
|
|
37837
37837
|
}
|
|
@@ -38186,7 +38186,7 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
38186
38186
|
column: _column,
|
|
38187
38187
|
flatten: flatten4,
|
|
38188
38188
|
number: number2,
|
|
38189
|
-
complex:
|
|
38189
|
+
complex: complex3,
|
|
38190
38190
|
sqrt: sqrt2,
|
|
38191
38191
|
diag: diag2,
|
|
38192
38192
|
size: size2,
|
|
@@ -38211,7 +38211,7 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
38211
38211
|
multiplyScalar: multiplyScalar2,
|
|
38212
38212
|
inv: inv2,
|
|
38213
38213
|
bignumber: bignumber2,
|
|
38214
|
-
complex:
|
|
38214
|
+
complex: complex3,
|
|
38215
38215
|
multiply: multiply2,
|
|
38216
38216
|
add: add2
|
|
38217
38217
|
});
|
|
@@ -38233,7 +38233,7 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
38233
38233
|
usolve: usolve2,
|
|
38234
38234
|
usolveAll: usolveAll2,
|
|
38235
38235
|
equal: equal2,
|
|
38236
|
-
complex:
|
|
38236
|
+
complex: complex3,
|
|
38237
38237
|
larger: larger2,
|
|
38238
38238
|
smaller: smaller2,
|
|
38239
38239
|
matrixFromColumns: matrixFromColumns2,
|
|
@@ -38293,18 +38293,18 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
38293
38293
|
return result;
|
|
38294
38294
|
}
|
|
38295
38295
|
function computeValuesAndVectors(mat, prec, computeVectors) {
|
|
38296
|
-
const
|
|
38296
|
+
const arr10 = mat.toArray();
|
|
38297
38297
|
const asize = mat.size();
|
|
38298
38298
|
if (asize.length !== 2 || asize[0] !== asize[1]) {
|
|
38299
38299
|
throw new RangeError(`Matrix must be square (size: ${format3(asize, {})})`);
|
|
38300
38300
|
}
|
|
38301
38301
|
const N = asize[0];
|
|
38302
|
-
if (isReal(
|
|
38303
|
-
coerceReal(
|
|
38304
|
-
if (isSymmetric(
|
|
38305
|
-
const type2 = coerceTypes(mat,
|
|
38302
|
+
if (isReal(arr10, N, prec)) {
|
|
38303
|
+
coerceReal(arr10, N);
|
|
38304
|
+
if (isSymmetric(arr10, N, prec)) {
|
|
38305
|
+
const type2 = coerceTypes(mat, arr10, N);
|
|
38306
38306
|
return doRealSymmetric(
|
|
38307
|
-
|
|
38307
|
+
arr10,
|
|
38308
38308
|
N,
|
|
38309
38309
|
prec,
|
|
38310
38310
|
type2,
|
|
@@ -38312,37 +38312,37 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
38312
38312
|
);
|
|
38313
38313
|
}
|
|
38314
38314
|
}
|
|
38315
|
-
const type = coerceTypes(mat,
|
|
38316
|
-
return doComplexEigs(
|
|
38315
|
+
const type = coerceTypes(mat, arr10, N);
|
|
38316
|
+
return doComplexEigs(arr10, N, prec, type, computeVectors);
|
|
38317
38317
|
}
|
|
38318
|
-
function isSymmetric(
|
|
38318
|
+
function isSymmetric(arr10, N, prec) {
|
|
38319
38319
|
for (let i = 0; i < N; i++) {
|
|
38320
38320
|
for (let j = i; j < N; j++) {
|
|
38321
|
-
if (larger2(bignumber2(abs2(subtract2(
|
|
38321
|
+
if (larger2(bignumber2(abs2(subtract2(arr10[i][j], arr10[j][i]))), prec)) {
|
|
38322
38322
|
return false;
|
|
38323
38323
|
}
|
|
38324
38324
|
}
|
|
38325
38325
|
}
|
|
38326
38326
|
return true;
|
|
38327
38327
|
}
|
|
38328
|
-
function isReal(
|
|
38328
|
+
function isReal(arr10, N, prec) {
|
|
38329
38329
|
for (let i = 0; i < N; i++) {
|
|
38330
38330
|
for (let j = 0; j < N; j++) {
|
|
38331
|
-
if (larger2(bignumber2(abs2(im3(
|
|
38331
|
+
if (larger2(bignumber2(abs2(im3(arr10[i][j]))), prec)) {
|
|
38332
38332
|
return false;
|
|
38333
38333
|
}
|
|
38334
38334
|
}
|
|
38335
38335
|
}
|
|
38336
38336
|
return true;
|
|
38337
38337
|
}
|
|
38338
|
-
function coerceReal(
|
|
38338
|
+
function coerceReal(arr10, N) {
|
|
38339
38339
|
for (let i = 0; i < N; i++) {
|
|
38340
38340
|
for (let j = 0; j < N; j++) {
|
|
38341
|
-
|
|
38341
|
+
arr10[i][j] = re3(arr10[i][j]);
|
|
38342
38342
|
}
|
|
38343
38343
|
}
|
|
38344
38344
|
}
|
|
38345
|
-
function coerceTypes(mat,
|
|
38345
|
+
function coerceTypes(mat, arr10, N) {
|
|
38346
38346
|
const type = mat.datatype();
|
|
38347
38347
|
if (type === "number" || type === "BigNumber" || type === "Complex") {
|
|
38348
38348
|
return type;
|
|
@@ -38352,7 +38352,7 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
38352
38352
|
let hasComplex = false;
|
|
38353
38353
|
for (let i = 0; i < N; i++) {
|
|
38354
38354
|
for (let j = 0; j < N; j++) {
|
|
38355
|
-
const el =
|
|
38355
|
+
const el = arr10[i][j];
|
|
38356
38356
|
if (isNumber(el) || isFraction(el)) {
|
|
38357
38357
|
hasNumber = true;
|
|
38358
38358
|
} else if (isBigNumber(el)) {
|
|
@@ -38370,7 +38370,7 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
38370
38370
|
if (hasComplex) {
|
|
38371
38371
|
for (let i = 0; i < N; i++) {
|
|
38372
38372
|
for (let j = 0; j < N; j++) {
|
|
38373
|
-
|
|
38373
|
+
arr10[i][j] = complex3(arr10[i][j]);
|
|
38374
38374
|
}
|
|
38375
38375
|
}
|
|
38376
38376
|
return "Complex";
|
|
@@ -38378,7 +38378,7 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
38378
38378
|
if (hasBig) {
|
|
38379
38379
|
for (let i = 0; i < N; i++) {
|
|
38380
38380
|
for (let j = 0; j < N; j++) {
|
|
38381
|
-
|
|
38381
|
+
arr10[i][j] = bignumber2(arr10[i][j]);
|
|
38382
38382
|
}
|
|
38383
38383
|
}
|
|
38384
38384
|
return "BigNumber";
|
|
@@ -38386,7 +38386,7 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
38386
38386
|
if (hasNumber) {
|
|
38387
38387
|
for (let i = 0; i < N; i++) {
|
|
38388
38388
|
for (let j = 0; j < N; j++) {
|
|
38389
|
-
|
|
38389
|
+
arr10[i][j] = number2(arr10[i][j]);
|
|
38390
38390
|
}
|
|
38391
38391
|
}
|
|
38392
38392
|
return "number";
|
|
@@ -38604,9 +38604,9 @@ var createLusolve = /* @__PURE__ */ factory(
|
|
|
38604
38604
|
|
|
38605
38605
|
// src/statistics/corr.ts
|
|
38606
38606
|
import { pairwiseSum as pairwiseSum3, pairwiseDot as pairwiseDot3 } from "@danielsimonjr/mathts-core";
|
|
38607
|
-
function isPlainNumberArray(
|
|
38608
|
-
for (let i = 0; i <
|
|
38609
|
-
if (typeof
|
|
38607
|
+
function isPlainNumberArray(arr10) {
|
|
38608
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
38609
|
+
if (typeof arr10[i] !== "number") {
|
|
38610
38610
|
return false;
|
|
38611
38611
|
}
|
|
38612
38612
|
}
|
|
@@ -38681,9 +38681,9 @@ var createCorr = /* @__PURE__ */ factory(
|
|
|
38681
38681
|
|
|
38682
38682
|
// src/statistics/mad.ts
|
|
38683
38683
|
var WASM_MAD_THRESHOLD = 500;
|
|
38684
|
-
function isPlainNumberArray2(
|
|
38685
|
-
for (let i = 0; i <
|
|
38686
|
-
if (typeof
|
|
38684
|
+
function isPlainNumberArray2(arr10) {
|
|
38685
|
+
for (let i = 0; i < arr10.length; i++) {
|
|
38686
|
+
if (typeof arr10[i] !== "number") {
|
|
38687
38687
|
return false;
|
|
38688
38688
|
}
|
|
38689
38689
|
}
|
|
@@ -40280,12 +40280,12 @@ var createNorm = /* @__PURE__ */ factory(
|
|
|
40280
40280
|
if (size2.length !== 1 || size2[0] < WASM_NORM_THRESHOLD) return null;
|
|
40281
40281
|
const wasm = wasmLoader.getModule();
|
|
40282
40282
|
if (!wasm) return null;
|
|
40283
|
-
const
|
|
40284
|
-
const n =
|
|
40283
|
+
const arr10 = x.toArray();
|
|
40284
|
+
const n = arr10.length;
|
|
40285
40285
|
const data = new Float64Array(n);
|
|
40286
40286
|
for (let i = 0; i < n; i++) {
|
|
40287
|
-
if (typeof
|
|
40288
|
-
data[i] =
|
|
40287
|
+
if (typeof arr10[i] !== "number") return null;
|
|
40288
|
+
data[i] = arr10[i];
|
|
40289
40289
|
}
|
|
40290
40290
|
const alloc = wasmLoader.allocateFloat64Array(data);
|
|
40291
40291
|
try {
|
|
@@ -44400,6 +44400,262 @@ function help(search) {
|
|
|
44400
44400
|
return new Help(doc);
|
|
44401
44401
|
}
|
|
44402
44402
|
|
|
44403
|
+
// src/numbertheory/extra.ts
|
|
44404
|
+
function continuedFraction(x, maxTerms = 20) {
|
|
44405
|
+
if (!Number.isFinite(x)) {
|
|
44406
|
+
throw new Error("continuedFraction requires a finite number");
|
|
44407
|
+
}
|
|
44408
|
+
const terms = [];
|
|
44409
|
+
let r = x;
|
|
44410
|
+
for (let i = 0; i < maxTerms; i++) {
|
|
44411
|
+
const a = Math.floor(r);
|
|
44412
|
+
terms.push(a);
|
|
44413
|
+
const frac = r - a;
|
|
44414
|
+
if (frac < 1e-12) break;
|
|
44415
|
+
r = 1 / frac;
|
|
44416
|
+
}
|
|
44417
|
+
return terms;
|
|
44418
|
+
}
|
|
44419
|
+
function binomialExact(n, k) {
|
|
44420
|
+
if (k < 0 || k > n) return 0;
|
|
44421
|
+
const kk = Math.min(k, n - k);
|
|
44422
|
+
let result = 1;
|
|
44423
|
+
for (let i = 0; i < kk; i++) {
|
|
44424
|
+
result = result * (n - i) / (i + 1);
|
|
44425
|
+
}
|
|
44426
|
+
return Math.round(result);
|
|
44427
|
+
}
|
|
44428
|
+
function eulerNumbers(n) {
|
|
44429
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
44430
|
+
throw new Error("eulerNumbers requires a non-negative integer");
|
|
44431
|
+
}
|
|
44432
|
+
const E = new Array(n + 1).fill(0);
|
|
44433
|
+
E[0] = 1;
|
|
44434
|
+
for (let m = 1; m <= n; m++) {
|
|
44435
|
+
if (m % 2 === 1) {
|
|
44436
|
+
E[m] = 0;
|
|
44437
|
+
continue;
|
|
44438
|
+
}
|
|
44439
|
+
let sum3 = 0;
|
|
44440
|
+
for (let k = 0; k < m / 2; k++) {
|
|
44441
|
+
sum3 += binomialExact(m, 2 * k) * E[2 * k];
|
|
44442
|
+
}
|
|
44443
|
+
E[m] = -sum3;
|
|
44444
|
+
}
|
|
44445
|
+
return E;
|
|
44446
|
+
}
|
|
44447
|
+
function stirlingS1(n, k) {
|
|
44448
|
+
if (!Number.isInteger(n) || !Number.isInteger(k) || n < 0 || k < 0) {
|
|
44449
|
+
throw new Error("stirlingS1 requires non-negative integers");
|
|
44450
|
+
}
|
|
44451
|
+
if (k > n) return 0;
|
|
44452
|
+
const s = Array.from({ length: n + 1 }, () => new Array(n + 1).fill(0));
|
|
44453
|
+
s[0][0] = 1;
|
|
44454
|
+
for (let i = 1; i <= n; i++) {
|
|
44455
|
+
for (let j = 0; j <= i; j++) {
|
|
44456
|
+
const prevDiag = j > 0 ? s[i - 1][j - 1] : 0;
|
|
44457
|
+
const prevSame = s[i - 1][j];
|
|
44458
|
+
s[i][j] = prevDiag - (i - 1) * prevSame;
|
|
44459
|
+
}
|
|
44460
|
+
}
|
|
44461
|
+
return s[n][k];
|
|
44462
|
+
}
|
|
44463
|
+
function modPowBig(base, exp2, mod2) {
|
|
44464
|
+
let b = (base % mod2 + mod2) % mod2;
|
|
44465
|
+
let e = exp2;
|
|
44466
|
+
let result = 1n;
|
|
44467
|
+
while (e > 0n) {
|
|
44468
|
+
if (e & 1n) result = result * b % mod2;
|
|
44469
|
+
b = b * b % mod2;
|
|
44470
|
+
e >>= 1n;
|
|
44471
|
+
}
|
|
44472
|
+
return result;
|
|
44473
|
+
}
|
|
44474
|
+
function modInverseBig(a, mod2) {
|
|
44475
|
+
let oldR = a;
|
|
44476
|
+
let r = mod2;
|
|
44477
|
+
let oldS = 1n;
|
|
44478
|
+
let s = 0n;
|
|
44479
|
+
while (r !== 0n) {
|
|
44480
|
+
const q = oldR / r;
|
|
44481
|
+
[oldR, r] = [r, oldR - q * r];
|
|
44482
|
+
[oldS, s] = [s, oldS - q * s];
|
|
44483
|
+
}
|
|
44484
|
+
return (oldS % mod2 + mod2) % mod2;
|
|
44485
|
+
}
|
|
44486
|
+
function discreteLog(g, h, p) {
|
|
44487
|
+
if (!Number.isInteger(g) || !Number.isInteger(h) || !Number.isInteger(p) || p < 2) {
|
|
44488
|
+
throw new Error("discreteLog requires integer g, h and a modulus p >= 2");
|
|
44489
|
+
}
|
|
44490
|
+
const P2 = BigInt(p);
|
|
44491
|
+
const G = (BigInt(g) % P2 + P2) % P2;
|
|
44492
|
+
const H = (BigInt(h) % P2 + P2) % P2;
|
|
44493
|
+
const m = BigInt(Math.max(1, Math.ceil(Math.sqrt(p - 1))));
|
|
44494
|
+
const table = /* @__PURE__ */ new Map();
|
|
44495
|
+
let cur = 1n;
|
|
44496
|
+
for (let j = 0n; j < m; j++) {
|
|
44497
|
+
const key = cur.toString();
|
|
44498
|
+
if (!table.has(key)) table.set(key, j);
|
|
44499
|
+
cur = cur * G % P2;
|
|
44500
|
+
}
|
|
44501
|
+
const gm = modPowBig(G, m, P2);
|
|
44502
|
+
const gInvM = modInverseBig(gm, P2);
|
|
44503
|
+
let gamma2 = H;
|
|
44504
|
+
for (let i = 0n; i < m; i++) {
|
|
44505
|
+
const key = gamma2.toString();
|
|
44506
|
+
const j = table.get(key);
|
|
44507
|
+
if (j !== void 0) {
|
|
44508
|
+
return Number(i * m + j);
|
|
44509
|
+
}
|
|
44510
|
+
gamma2 = gamma2 * gInvM % P2;
|
|
44511
|
+
}
|
|
44512
|
+
return -1;
|
|
44513
|
+
}
|
|
44514
|
+
function distinctPrimeFactors(nIn) {
|
|
44515
|
+
let n = nIn;
|
|
44516
|
+
const primes = [];
|
|
44517
|
+
for (let d = 2; d * d <= n; d++) {
|
|
44518
|
+
if (n % d === 0) {
|
|
44519
|
+
primes.push(d);
|
|
44520
|
+
while (n % d === 0) n /= d;
|
|
44521
|
+
}
|
|
44522
|
+
}
|
|
44523
|
+
if (n > 1) primes.push(n);
|
|
44524
|
+
return primes;
|
|
44525
|
+
}
|
|
44526
|
+
function primitiveRoot(p) {
|
|
44527
|
+
if (!Number.isInteger(p) || p < 2) {
|
|
44528
|
+
throw new Error("primitiveRoot requires an integer p >= 2");
|
|
44529
|
+
}
|
|
44530
|
+
if (p === 2) return 1;
|
|
44531
|
+
const phi = p - 1;
|
|
44532
|
+
const phiFactors = distinctPrimeFactors(phi);
|
|
44533
|
+
const P2 = BigInt(p);
|
|
44534
|
+
for (let g = 2; g < p; g++) {
|
|
44535
|
+
let isRoot = true;
|
|
44536
|
+
for (const q of phiFactors) {
|
|
44537
|
+
if (modPowBig(BigInt(g), BigInt(phi / q), P2) === 1n) {
|
|
44538
|
+
isRoot = false;
|
|
44539
|
+
break;
|
|
44540
|
+
}
|
|
44541
|
+
}
|
|
44542
|
+
if (isRoot) return g;
|
|
44543
|
+
}
|
|
44544
|
+
throw new Error("primitiveRoot: no primitive root found (p may not be prime)");
|
|
44545
|
+
}
|
|
44546
|
+
function gcdInt(aIn, bIn) {
|
|
44547
|
+
let a = Math.abs(aIn);
|
|
44548
|
+
let b = Math.abs(bIn);
|
|
44549
|
+
while (b !== 0) {
|
|
44550
|
+
[a, b] = [b, a % b];
|
|
44551
|
+
}
|
|
44552
|
+
return a;
|
|
44553
|
+
}
|
|
44554
|
+
function multiplicativeOrder(a, n) {
|
|
44555
|
+
if (!Number.isInteger(a) || !Number.isInteger(n) || n < 1) {
|
|
44556
|
+
throw new Error("multiplicativeOrder requires integers with modulus n >= 1");
|
|
44557
|
+
}
|
|
44558
|
+
const amod = (a % n + n) % n;
|
|
44559
|
+
if (gcdInt(amod, n) !== 1) return -1;
|
|
44560
|
+
if (n === 1) return 1;
|
|
44561
|
+
let cur = amod;
|
|
44562
|
+
let k = 1;
|
|
44563
|
+
while (cur !== 1) {
|
|
44564
|
+
cur = cur * amod % n;
|
|
44565
|
+
k++;
|
|
44566
|
+
}
|
|
44567
|
+
return k;
|
|
44568
|
+
}
|
|
44569
|
+
function kroneckerTwo(a) {
|
|
44570
|
+
if (a % 2 === 0) return 0;
|
|
44571
|
+
const r = (a % 8 + 8) % 8;
|
|
44572
|
+
return r === 1 || r === 7 ? 1 : -1;
|
|
44573
|
+
}
|
|
44574
|
+
function kroneckerSymbol(a, n) {
|
|
44575
|
+
if (!Number.isInteger(a) || !Number.isInteger(n)) {
|
|
44576
|
+
throw new Error("kroneckerSymbol requires integers");
|
|
44577
|
+
}
|
|
44578
|
+
if (n === 0) {
|
|
44579
|
+
return Math.abs(a) === 1 ? 1 : 0;
|
|
44580
|
+
}
|
|
44581
|
+
let sign3 = 1;
|
|
44582
|
+
let nn = n;
|
|
44583
|
+
if (nn < 0) {
|
|
44584
|
+
nn = -nn;
|
|
44585
|
+
if (a < 0) sign3 = -1;
|
|
44586
|
+
}
|
|
44587
|
+
let v = 0;
|
|
44588
|
+
while (nn % 2 === 0) {
|
|
44589
|
+
nn /= 2;
|
|
44590
|
+
v++;
|
|
44591
|
+
}
|
|
44592
|
+
if (v > 0) {
|
|
44593
|
+
const k2 = kroneckerTwo(a);
|
|
44594
|
+
if (k2 === 0) return 0;
|
|
44595
|
+
sign3 *= Math.pow(k2, v);
|
|
44596
|
+
}
|
|
44597
|
+
if (nn === 1) return sign3;
|
|
44598
|
+
let aa = (a % nn + nn) % nn;
|
|
44599
|
+
let N = nn;
|
|
44600
|
+
let jac = 1;
|
|
44601
|
+
while (aa !== 0) {
|
|
44602
|
+
while (aa % 2 === 0) {
|
|
44603
|
+
aa /= 2;
|
|
44604
|
+
if (N % 8 === 3 || N % 8 === 5) jac = -jac;
|
|
44605
|
+
}
|
|
44606
|
+
[aa, N] = [N, aa];
|
|
44607
|
+
if (aa % 4 === 3 && N % 4 === 3) jac = -jac;
|
|
44608
|
+
aa = aa % N;
|
|
44609
|
+
}
|
|
44610
|
+
return sign3 * (N === 1 ? jac : 0);
|
|
44611
|
+
}
|
|
44612
|
+
function combinationsGen(arr10, k) {
|
|
44613
|
+
const n = arr10.length;
|
|
44614
|
+
if (!Number.isInteger(k) || k < 0 || k > n) {
|
|
44615
|
+
throw new Error("combinationsGen: k must be an integer in [0, arr.length]");
|
|
44616
|
+
}
|
|
44617
|
+
const result = [];
|
|
44618
|
+
const combo = [];
|
|
44619
|
+
function backtrack(start) {
|
|
44620
|
+
if (combo.length === k) {
|
|
44621
|
+
result.push(combo.slice());
|
|
44622
|
+
return;
|
|
44623
|
+
}
|
|
44624
|
+
for (let i = start; i < n; i++) {
|
|
44625
|
+
combo.push(arr10[i]);
|
|
44626
|
+
backtrack(i + 1);
|
|
44627
|
+
combo.pop();
|
|
44628
|
+
}
|
|
44629
|
+
}
|
|
44630
|
+
backtrack(0);
|
|
44631
|
+
return result;
|
|
44632
|
+
}
|
|
44633
|
+
function permutationsGen(arr10, k = arr10.length) {
|
|
44634
|
+
const n = arr10.length;
|
|
44635
|
+
if (!Number.isInteger(k) || k < 0 || k > n) {
|
|
44636
|
+
throw new Error("permutationsGen: k must be an integer in [0, arr.length]");
|
|
44637
|
+
}
|
|
44638
|
+
const result = [];
|
|
44639
|
+
const used = new Array(n).fill(false);
|
|
44640
|
+
const perm = [];
|
|
44641
|
+
function backtrack() {
|
|
44642
|
+
if (perm.length === k) {
|
|
44643
|
+
result.push(perm.slice());
|
|
44644
|
+
return;
|
|
44645
|
+
}
|
|
44646
|
+
for (let i = 0; i < n; i++) {
|
|
44647
|
+
if (used[i]) continue;
|
|
44648
|
+
used[i] = true;
|
|
44649
|
+
perm.push(arr10[i]);
|
|
44650
|
+
backtrack();
|
|
44651
|
+
perm.pop();
|
|
44652
|
+
used[i] = false;
|
|
44653
|
+
}
|
|
44654
|
+
}
|
|
44655
|
+
backtrack();
|
|
44656
|
+
return result;
|
|
44657
|
+
}
|
|
44658
|
+
|
|
44403
44659
|
// src/grad-forward.ts
|
|
44404
44660
|
import { Dual as Dual3 } from "@danielsimonjr/mathts-core";
|
|
44405
44661
|
function derivativeAt(fn, x0) {
|
|
@@ -44587,9 +44843,9 @@ function kendallTau(x, y) {
|
|
|
44587
44843
|
}
|
|
44588
44844
|
}
|
|
44589
44845
|
const n0 = n * (n - 1) / 2;
|
|
44590
|
-
const tiePairs = (
|
|
44846
|
+
const tiePairs = (arr10) => {
|
|
44591
44847
|
const counts = /* @__PURE__ */ new Map();
|
|
44592
|
-
for (const v of
|
|
44848
|
+
for (const v of arr10) counts.set(v, (counts.get(v) ?? 0) + 1);
|
|
44593
44849
|
let s = 0;
|
|
44594
44850
|
for (const c of counts.values()) s += c * (c - 1) / 2;
|
|
44595
44851
|
return s;
|
|
@@ -46901,7 +47157,9 @@ function lfilterZi(b, a) {
|
|
|
46901
47157
|
try {
|
|
46902
47158
|
Minv = _inv3(M);
|
|
46903
47159
|
} catch {
|
|
46904
|
-
throw new Error(
|
|
47160
|
+
throw new Error(
|
|
47161
|
+
"lfilterZi: filter has a pole at z=1 (singular I \u2212 A\u1D40); steady-state zi is undefined"
|
|
47162
|
+
);
|
|
46905
47163
|
}
|
|
46906
47164
|
const zi = Minv.map((row2) => row2.reduce((s, v, k) => s + v * B[k], 0));
|
|
46907
47165
|
if (zi.some((v) => !Number.isFinite(v)))
|
|
@@ -46922,15 +47180,26 @@ function filtfilt(b, a, x) {
|
|
|
46922
47180
|
for (let k = 1; k <= pad; k++) right.push(2 * xx[n - 1] - xx[n - 1 - k]);
|
|
46923
47181
|
const ext = [...left, ...xx, ...right];
|
|
46924
47182
|
const zi = lfilterZi(bb, aa);
|
|
46925
|
-
const fwd = lfilterState(
|
|
47183
|
+
const fwd = lfilterState(
|
|
47184
|
+
bb,
|
|
47185
|
+
aa,
|
|
47186
|
+
ext,
|
|
47187
|
+
zi.map((v) => v * ext[0])
|
|
47188
|
+
).y;
|
|
46926
47189
|
const rev = fwd.slice().reverse();
|
|
46927
|
-
const back = lfilterState(
|
|
47190
|
+
const back = lfilterState(
|
|
47191
|
+
bb,
|
|
47192
|
+
aa,
|
|
47193
|
+
rev,
|
|
47194
|
+
zi.map((v) => v * rev[0])
|
|
47195
|
+
).y.reverse();
|
|
46928
47196
|
return back.slice(pad, pad + n);
|
|
46929
47197
|
}
|
|
46930
47198
|
var cAdd = (p, q) => p.add(q);
|
|
46931
47199
|
var cSub = (p, q) => p.sub(q);
|
|
46932
47200
|
var cMul = (p, q) => p.multiply(q);
|
|
46933
47201
|
var cDiv = (p, q) => p.divide(q);
|
|
47202
|
+
var cScale = (p, s) => cMul(p, new Complex11(s, 0));
|
|
46934
47203
|
function polyFromRoots(roots) {
|
|
46935
47204
|
let c = [new Complex11(1, 0)];
|
|
46936
47205
|
for (const r of roots) {
|
|
@@ -46943,29 +47212,1167 @@ function polyFromRoots(roots) {
|
|
|
46943
47212
|
}
|
|
46944
47213
|
return c.map((z) => z.re);
|
|
46945
47214
|
}
|
|
46946
|
-
function
|
|
46947
|
-
|
|
46948
|
-
if (
|
|
46949
|
-
|
|
46950
|
-
|
|
47215
|
+
function relativeDegree(z, p) {
|
|
47216
|
+
const degree2 = p.length - z.length;
|
|
47217
|
+
if (degree2 < 0) throw new Error("Improper transfer function: fewer poles than zeros");
|
|
47218
|
+
return degree2;
|
|
47219
|
+
}
|
|
47220
|
+
function lp2lpZpk(z, p, k, wo) {
|
|
47221
|
+
const degree2 = relativeDegree(z, p);
|
|
47222
|
+
return {
|
|
47223
|
+
z: z.map((zv) => cScale(zv, wo)),
|
|
47224
|
+
p: p.map((pv) => cScale(pv, wo)),
|
|
47225
|
+
k: k * Math.pow(wo, degree2)
|
|
47226
|
+
};
|
|
47227
|
+
}
|
|
47228
|
+
function lp2hpZpk(z, p, k, wo) {
|
|
47229
|
+
const degree2 = relativeDegree(z, p);
|
|
47230
|
+
const woC = new Complex11(wo, 0);
|
|
47231
|
+
const zHp = z.map((zv) => cDiv(woC, zv));
|
|
47232
|
+
for (let i = 0; i < degree2; i++) zHp.push(new Complex11(0, 0));
|
|
47233
|
+
let prodZ = new Complex11(1, 0);
|
|
47234
|
+
for (const zv of z) prodZ = cMul(prodZ, zv.negate());
|
|
47235
|
+
let prodP = new Complex11(1, 0);
|
|
47236
|
+
for (const pv of p) prodP = cMul(prodP, pv.negate());
|
|
47237
|
+
return { z: zHp, p: p.map((pv) => cDiv(woC, pv)), k: k * cDiv(prodZ, prodP).re };
|
|
47238
|
+
}
|
|
47239
|
+
function lp2bpZpk(z, p, k, wo, bw) {
|
|
47240
|
+
const degree2 = relativeDegree(z, p);
|
|
47241
|
+
const wo2 = new Complex11(wo * wo, 0);
|
|
47242
|
+
const shift = (roots) => {
|
|
47243
|
+
const lp = roots.map((r) => cScale(r, bw / 2));
|
|
47244
|
+
const plus = lp.map((r) => cAdd(r, cSub(cMul(r, r), wo2).sqrt()));
|
|
47245
|
+
const minus = lp.map((r) => cSub(r, cSub(cMul(r, r), wo2).sqrt()));
|
|
47246
|
+
return plus.concat(minus);
|
|
47247
|
+
};
|
|
47248
|
+
const zBp = shift(z);
|
|
47249
|
+
for (let i = 0; i < degree2; i++) zBp.push(new Complex11(0, 0));
|
|
47250
|
+
return { z: zBp, p: shift(p), k: k * Math.pow(bw, degree2) };
|
|
47251
|
+
}
|
|
47252
|
+
function lp2bsZpk(z, p, k, wo, bw) {
|
|
47253
|
+
const degree2 = relativeDegree(z, p);
|
|
47254
|
+
const wo2 = new Complex11(wo * wo, 0);
|
|
47255
|
+
const bw2 = new Complex11(bw / 2, 0);
|
|
47256
|
+
const shift = (roots) => {
|
|
47257
|
+
const hp = roots.map((r) => cDiv(bw2, r));
|
|
47258
|
+
const plus = hp.map((r) => cAdd(r, cSub(cMul(r, r), wo2).sqrt()));
|
|
47259
|
+
const minus = hp.map((r) => cSub(r, cSub(cMul(r, r), wo2).sqrt()));
|
|
47260
|
+
return plus.concat(minus);
|
|
47261
|
+
};
|
|
47262
|
+
const zBs = shift(z);
|
|
47263
|
+
for (let i = 0; i < degree2; i++) zBs.push(new Complex11(0, wo));
|
|
47264
|
+
for (let i = 0; i < degree2; i++) zBs.push(new Complex11(0, -wo));
|
|
47265
|
+
let prodZ = new Complex11(1, 0);
|
|
47266
|
+
for (const zv of z) prodZ = cMul(prodZ, zv.negate());
|
|
47267
|
+
let prodP = new Complex11(1, 0);
|
|
47268
|
+
for (const pv of p) prodP = cMul(prodP, pv.negate());
|
|
47269
|
+
return { z: zBs, p: shift(p), k: k * cDiv(prodZ, prodP).re };
|
|
47270
|
+
}
|
|
47271
|
+
function bilinearZpk(z, p, k, fs) {
|
|
47272
|
+
const degree2 = relativeDegree(z, p);
|
|
47273
|
+
const fs2 = new Complex11(2 * fs, 0);
|
|
47274
|
+
const zZ = z.map((zv) => cDiv(cAdd(fs2, zv), cSub(fs2, zv)));
|
|
47275
|
+
for (let i = 0; i < degree2; i++) zZ.push(new Complex11(-1, 0));
|
|
47276
|
+
let prodZ = new Complex11(1, 0);
|
|
47277
|
+
for (const zv of z) prodZ = cMul(prodZ, cSub(fs2, zv));
|
|
47278
|
+
let prodP = new Complex11(1, 0);
|
|
47279
|
+
for (const pv of p) prodP = cMul(prodP, cSub(fs2, pv));
|
|
47280
|
+
return {
|
|
47281
|
+
z: zZ,
|
|
47282
|
+
p: p.map((pv) => cDiv(cAdd(fs2, pv), cSub(fs2, pv))),
|
|
47283
|
+
k: k * cDiv(prodZ, prodP).re
|
|
47284
|
+
};
|
|
47285
|
+
}
|
|
47286
|
+
function zpkToTf(z, p, k) {
|
|
47287
|
+
return { b: polyFromRoots(z).map((v) => v * k), a: polyFromRoots(p) };
|
|
47288
|
+
}
|
|
47289
|
+
function validateWn(Wn, btype) {
|
|
47290
|
+
const needsPair = btype === "bandpass" || btype === "bandstop";
|
|
47291
|
+
const arr10 = Array.isArray(Wn) ? Wn.slice() : [Wn];
|
|
47292
|
+
if (needsPair && arr10.length !== 2)
|
|
47293
|
+
throw new Error(`${btype} filter design requires Wn = [low, high]`);
|
|
47294
|
+
if (!needsPair && arr10.length !== 1)
|
|
47295
|
+
throw new Error(`${btype} filter design requires a scalar Wn`);
|
|
47296
|
+
for (const w of arr10) {
|
|
47297
|
+
if (!(w > 0 && w < 1)) throw new Error("Wn must satisfy 0 < Wn < 1 (normalized to Nyquist)");
|
|
47298
|
+
}
|
|
47299
|
+
if (needsPair && !(arr10[0] < arr10[1])) throw new Error("Wn[0] must be less than Wn[1]");
|
|
47300
|
+
return arr10;
|
|
47301
|
+
}
|
|
47302
|
+
function analogToDigital(proto, Wn, btype) {
|
|
47303
|
+
const WnArr = validateWn(Wn, btype);
|
|
47304
|
+
const fs = 2;
|
|
47305
|
+
const warped = WnArr.map((w) => 2 * fs * Math.tan(Math.PI * w / fs));
|
|
47306
|
+
let { z, p, k } = proto;
|
|
47307
|
+
if (btype === "low") {
|
|
47308
|
+
({ z, p, k } = lp2lpZpk(z, p, k, warped[0]));
|
|
47309
|
+
} else if (btype === "high") {
|
|
47310
|
+
({ z, p, k } = lp2hpZpk(z, p, k, warped[0]));
|
|
47311
|
+
} else {
|
|
47312
|
+
const bw = warped[1] - warped[0];
|
|
47313
|
+
const wo = Math.sqrt(warped[0] * warped[1]);
|
|
47314
|
+
({ z, p, k } = btype === "bandpass" ? lp2bpZpk(z, p, k, wo, bw) : lp2bsZpk(z, p, k, wo, bw));
|
|
47315
|
+
}
|
|
47316
|
+
({ z, p, k } = bilinearZpk(z, p, k, fs));
|
|
47317
|
+
return zpkToTf(z, p, k);
|
|
47318
|
+
}
|
|
47319
|
+
function buttap(N) {
|
|
47320
|
+
const p = [];
|
|
46951
47321
|
for (let k = 0; k < N; k++) {
|
|
46952
47322
|
const m = -N + 1 + 2 * k;
|
|
46953
47323
|
const theta = Math.PI * m / (2 * N);
|
|
46954
|
-
|
|
47324
|
+
p.push(new Complex11(-Math.cos(theta), -Math.sin(theta)));
|
|
47325
|
+
}
|
|
47326
|
+
return { z: [], p, k: 1 };
|
|
47327
|
+
}
|
|
47328
|
+
function butter(N, Wn, btype = "low") {
|
|
47329
|
+
if (!Number.isInteger(N) || N < 1) throw new Error("butter: order N must be a positive integer");
|
|
47330
|
+
return analogToDigital(buttap(N), Wn, btype);
|
|
47331
|
+
}
|
|
47332
|
+
|
|
47333
|
+
// src/signal/fft-helpers.ts
|
|
47334
|
+
var callFft = fft;
|
|
47335
|
+
var callIfft = ifft;
|
|
47336
|
+
function toReIm(value) {
|
|
47337
|
+
if (typeof value === "number") {
|
|
47338
|
+
return { re: value, im: 0 };
|
|
47339
|
+
}
|
|
47340
|
+
const c = value;
|
|
47341
|
+
return { re: c.re, im: c.im };
|
|
47342
|
+
}
|
|
47343
|
+
function rfft(x) {
|
|
47344
|
+
const n = x.length;
|
|
47345
|
+
const full = callFft(x);
|
|
47346
|
+
const keep = Math.floor(n / 2) + 1;
|
|
47347
|
+
const re3 = new Array(keep);
|
|
47348
|
+
const im3 = new Array(keep);
|
|
47349
|
+
for (let i = 0; i < keep; i++) {
|
|
47350
|
+
const c = toReIm(full[i]);
|
|
47351
|
+
re3[i] = c.re;
|
|
47352
|
+
im3[i] = c.im;
|
|
47353
|
+
}
|
|
47354
|
+
return { re: re3, im: im3 };
|
|
47355
|
+
}
|
|
47356
|
+
function irfft(spec, n) {
|
|
47357
|
+
const halfLen = Math.floor(n / 2) + 1;
|
|
47358
|
+
const full = new Array(n);
|
|
47359
|
+
for (let i = 0; i < halfLen; i++) {
|
|
47360
|
+
full[i] = complex(spec.re[i], spec.im[i]);
|
|
47361
|
+
}
|
|
47362
|
+
for (let i = halfLen; i < n; i++) {
|
|
47363
|
+
const mirror = toReIm(full[n - i]);
|
|
47364
|
+
full[i] = complex(mirror.re, -mirror.im);
|
|
47365
|
+
}
|
|
47366
|
+
const result = callIfft(full);
|
|
47367
|
+
return result.map((v) => toReIm(v).re);
|
|
47368
|
+
}
|
|
47369
|
+
function fftshift(x) {
|
|
47370
|
+
const n = x.length;
|
|
47371
|
+
const half = Math.floor(n / 2);
|
|
47372
|
+
return [...x.slice(half), ...x.slice(0, half)];
|
|
47373
|
+
}
|
|
47374
|
+
function ifftshift(x) {
|
|
47375
|
+
const n = x.length;
|
|
47376
|
+
const half = Math.ceil(n / 2);
|
|
47377
|
+
return [...x.slice(half), ...x.slice(0, half)];
|
|
47378
|
+
}
|
|
47379
|
+
function fftfreq(n, d = 1) {
|
|
47380
|
+
const result = new Array(n);
|
|
47381
|
+
const posCount = Math.ceil(n / 2);
|
|
47382
|
+
const negCount = Math.floor(n / 2);
|
|
47383
|
+
for (let k = 0; k < posCount; k++) {
|
|
47384
|
+
result[k] = k / (n * d);
|
|
47385
|
+
}
|
|
47386
|
+
for (let k = 0; k < negCount; k++) {
|
|
47387
|
+
result[posCount + k] = (k - negCount) / (n * d);
|
|
47388
|
+
}
|
|
47389
|
+
return result;
|
|
47390
|
+
}
|
|
47391
|
+
function rfftfreq(n, d = 1) {
|
|
47392
|
+
const half = Math.floor(n / 2);
|
|
47393
|
+
const result = new Array(half + 1);
|
|
47394
|
+
for (let k = 0; k <= half; k++) {
|
|
47395
|
+
result[k] = k / (n * d);
|
|
47396
|
+
}
|
|
47397
|
+
return result;
|
|
47398
|
+
}
|
|
47399
|
+
function fftn(x) {
|
|
47400
|
+
const full = callFft(x);
|
|
47401
|
+
const re3 = full.map((row2) => row2.map((v) => toReIm(v).re));
|
|
47402
|
+
const im3 = full.map((row2) => row2.map((v) => toReIm(v).im));
|
|
47403
|
+
return { re: re3, im: im3 };
|
|
47404
|
+
}
|
|
47405
|
+
|
|
47406
|
+
// src/signal/iir-design.ts
|
|
47407
|
+
import { Complex as Complex12 } from "@danielsimonjr/mathts-core";
|
|
47408
|
+
|
|
47409
|
+
// src/special/jacobi-elliptic.ts
|
|
47410
|
+
var MAX_AGM_ITERATIONS = 12;
|
|
47411
|
+
var AGM_TOLERANCE = 1e-16;
|
|
47412
|
+
function jacobiElliptic(u, m) {
|
|
47413
|
+
if (m < 0 || m > 1) {
|
|
47414
|
+
throw new Error("jacobiElliptic: m (=k^2) must be in [0, 1]");
|
|
47415
|
+
}
|
|
47416
|
+
if (m === 0) {
|
|
47417
|
+
return { sn: Math.sin(u), cn: Math.cos(u), dn: 1 };
|
|
47418
|
+
}
|
|
47419
|
+
if (m === 1) {
|
|
47420
|
+
const sn2 = Math.tanh(u);
|
|
47421
|
+
const sech2 = 1 / Math.cosh(u);
|
|
47422
|
+
return { sn: sn2, cn: sech2, dn: sech2 };
|
|
47423
|
+
}
|
|
47424
|
+
const a = [1];
|
|
47425
|
+
const b = [Math.sqrt(1 - m)];
|
|
47426
|
+
const c = [Math.sqrt(m)];
|
|
47427
|
+
let n = 0;
|
|
47428
|
+
while (n < MAX_AGM_ITERATIONS && Math.abs(c[n]) > AGM_TOLERANCE) {
|
|
47429
|
+
a.push((a[n] + b[n]) / 2);
|
|
47430
|
+
b.push(Math.sqrt(a[n] * b[n]));
|
|
47431
|
+
c.push((a[n] - b[n]) / 2);
|
|
47432
|
+
n++;
|
|
47433
|
+
}
|
|
47434
|
+
let phi = Math.pow(2, n) * a[n] * u;
|
|
47435
|
+
for (let i = n; i >= 1; i--) {
|
|
47436
|
+
phi = (phi + Math.asin(c[i] / a[i] * Math.sin(phi))) / 2;
|
|
47437
|
+
}
|
|
47438
|
+
const sn = Math.sin(phi);
|
|
47439
|
+
const cn = Math.cos(phi);
|
|
47440
|
+
const dn = Math.sqrt(1 - m * sn * sn);
|
|
47441
|
+
return { sn, cn, dn };
|
|
47442
|
+
}
|
|
47443
|
+
function jacobiSN(u, m) {
|
|
47444
|
+
return jacobiElliptic(u, m).sn;
|
|
47445
|
+
}
|
|
47446
|
+
function jacobiCN(u, m) {
|
|
47447
|
+
return jacobiElliptic(u, m).cn;
|
|
47448
|
+
}
|
|
47449
|
+
function jacobiDN(u, m) {
|
|
47450
|
+
return jacobiElliptic(u, m).dn;
|
|
47451
|
+
}
|
|
47452
|
+
|
|
47453
|
+
// src/signal/iir-design.ts
|
|
47454
|
+
var arr8 = (x) => Array.isArray(x) ? x : Array.from(x);
|
|
47455
|
+
function cheb1ap(N, rp) {
|
|
47456
|
+
const eps = Math.sqrt(Math.pow(10, 0.1 * rp) - 1);
|
|
47457
|
+
const mu = 1 / N * Math.asinh(1 / eps);
|
|
47458
|
+
const p = [];
|
|
47459
|
+
for (let m = -N + 1; m < N; m += 2) {
|
|
47460
|
+
const theta = Math.PI * m / (2 * N);
|
|
47461
|
+
p.push(new Complex12(-Math.sinh(mu) * Math.cos(theta), -Math.cosh(mu) * Math.sin(theta)));
|
|
47462
|
+
}
|
|
47463
|
+
let prod2 = new Complex12(1, 0);
|
|
47464
|
+
for (const pv of p) prod2 = cMul(prod2, pv.negate());
|
|
47465
|
+
let k = prod2.re;
|
|
47466
|
+
if (N % 2 === 0) k /= Math.sqrt(1 + eps * eps);
|
|
47467
|
+
return { z: [], p, k };
|
|
47468
|
+
}
|
|
47469
|
+
function cheby1(N, rp, Wn, btype = "low") {
|
|
47470
|
+
if (!Number.isInteger(N) || N < 1) throw new Error("cheby1: order N must be a positive integer");
|
|
47471
|
+
if (!(rp > 0)) throw new Error("cheby1: rp (passband ripple, dB) must be positive");
|
|
47472
|
+
return analogToDigital(cheb1ap(N, rp), Wn, btype);
|
|
47473
|
+
}
|
|
47474
|
+
function cheb2ap(N, rs) {
|
|
47475
|
+
const de = 1 / Math.sqrt(Math.pow(10, 0.1 * rs) - 1);
|
|
47476
|
+
const mu = Math.asinh(1 / de) / N;
|
|
47477
|
+
const mVals = [];
|
|
47478
|
+
if (N % 2) {
|
|
47479
|
+
for (let m = -N + 1; m < 0; m += 2) mVals.push(m);
|
|
47480
|
+
for (let m = 2; m < N; m += 2) mVals.push(m);
|
|
47481
|
+
} else {
|
|
47482
|
+
for (let m = -N + 1; m < N; m += 2) mVals.push(m);
|
|
47483
|
+
}
|
|
47484
|
+
const z = mVals.map((m) => new Complex12(0, 1 / Math.sin(m * Math.PI / (2 * N))));
|
|
47485
|
+
const p = [];
|
|
47486
|
+
for (let m = -N + 1; m < N; m += 2) {
|
|
47487
|
+
const theta = Math.PI * m / (2 * N);
|
|
47488
|
+
const s = new Complex12(Math.sinh(mu) * Math.cos(theta), Math.cosh(mu) * Math.sin(theta));
|
|
47489
|
+
p.push(cDiv(new Complex12(1, 0), s).negate());
|
|
47490
|
+
}
|
|
47491
|
+
let prodP = new Complex12(1, 0);
|
|
47492
|
+
for (const pv of p) prodP = cMul(prodP, pv.negate());
|
|
47493
|
+
let prodZ = new Complex12(1, 0);
|
|
47494
|
+
for (const zv of z) prodZ = cMul(prodZ, zv.negate());
|
|
47495
|
+
const k = cDiv(prodP, prodZ).re;
|
|
47496
|
+
return { z, p, k };
|
|
47497
|
+
}
|
|
47498
|
+
function cheby2(N, rs, Wn, btype = "low") {
|
|
47499
|
+
if (!Number.isInteger(N) || N < 1) throw new Error("cheby2: order N must be a positive integer");
|
|
47500
|
+
if (!(rs > 0)) throw new Error("cheby2: rs (stopband attenuation, dB) must be positive");
|
|
47501
|
+
return analogToDigital(cheb2ap(N, rs), Wn, btype);
|
|
47502
|
+
}
|
|
47503
|
+
var ELLIPDEG_MMAX = 7;
|
|
47504
|
+
function ellipdeg(N, m1) {
|
|
47505
|
+
const K1 = ellipticKScalar(m1);
|
|
47506
|
+
const K1p = ellipticKScalar(1 - m1);
|
|
47507
|
+
const q1 = Math.exp(-Math.PI * K1p / K1);
|
|
47508
|
+
const q = Math.pow(q1, 1 / N);
|
|
47509
|
+
let num2 = 0;
|
|
47510
|
+
for (let i = 0; i <= ELLIPDEG_MMAX; i++) num2 += Math.pow(q, i * (i + 1));
|
|
47511
|
+
let den = 1;
|
|
47512
|
+
for (let i = 1; i <= ELLIPDEG_MMAX + 1; i++) den += 2 * Math.pow(q, i * i);
|
|
47513
|
+
return 16 * q * Math.pow(num2 / den, 4);
|
|
47514
|
+
}
|
|
47515
|
+
function complementReal(kx) {
|
|
47516
|
+
return Math.sqrt((1 - kx) * (1 + kx));
|
|
47517
|
+
}
|
|
47518
|
+
function complementComplex(kx) {
|
|
47519
|
+
const one = new Complex12(1, 0);
|
|
47520
|
+
return one.sub(kx).mul(one.add(kx)).sqrt();
|
|
47521
|
+
}
|
|
47522
|
+
var ARC_JAC_SN_MAX_ITER = 100;
|
|
47523
|
+
function arcJacSn(w, m) {
|
|
47524
|
+
const k = Math.sqrt(m);
|
|
47525
|
+
if (k > 1) throw new Error("arcJacSn: modulus out of range");
|
|
47526
|
+
if (k === 1) return w.atanh();
|
|
47527
|
+
const ks = [k];
|
|
47528
|
+
let niter = 0;
|
|
47529
|
+
while (ks[ks.length - 1] !== 0) {
|
|
47530
|
+
const kCur = ks[ks.length - 1];
|
|
47531
|
+
const kp = complementReal(kCur);
|
|
47532
|
+
const next = (1 - kp) / (1 + kp);
|
|
47533
|
+
ks.push(next);
|
|
47534
|
+
niter++;
|
|
47535
|
+
if (niter > ARC_JAC_SN_MAX_ITER)
|
|
47536
|
+
throw new Error("arcJacSn: Landen transformation did not converge");
|
|
47537
|
+
if (next < 1e-18) {
|
|
47538
|
+
ks[ks.length - 1] = 0;
|
|
47539
|
+
break;
|
|
47540
|
+
}
|
|
47541
|
+
}
|
|
47542
|
+
let K = 1;
|
|
47543
|
+
for (let i = 1; i < ks.length; i++) K *= 1 + ks[i];
|
|
47544
|
+
K *= Math.PI / 2;
|
|
47545
|
+
let wn = w;
|
|
47546
|
+
for (let i = 0; i < ks.length - 1; i++) {
|
|
47547
|
+
const knext = ks[i + 1];
|
|
47548
|
+
const comp = complementComplex(cScale(wn, ks[i]));
|
|
47549
|
+
wn = cDiv(cScale(wn, 2), cMul(new Complex12(1 + knext, 0), new Complex12(1, 0).add(comp)));
|
|
47550
|
+
}
|
|
47551
|
+
return cScale(cScale(wn.asin(), 2 / Math.PI), K);
|
|
47552
|
+
}
|
|
47553
|
+
function arcJacSc1(w, m) {
|
|
47554
|
+
const z = arcJacSn(new Complex12(0, w), m);
|
|
47555
|
+
if (Math.abs(z.re) > 1e-9)
|
|
47556
|
+
throw new Error("ellip: elliptic filter design failed to converge (arcJacSc1)");
|
|
47557
|
+
return z.im;
|
|
47558
|
+
}
|
|
47559
|
+
function ellipap(N, rp, rs) {
|
|
47560
|
+
if (N === 1) {
|
|
47561
|
+
const p = -Math.sqrt(1 / (Math.pow(10, 0.1 * rp) - 1));
|
|
47562
|
+
return { z: [], p: [new Complex12(p, 0)], k: -p };
|
|
47563
|
+
}
|
|
47564
|
+
const epsSq = Math.pow(10, 0.1 * rp) - 1;
|
|
47565
|
+
const eps = Math.sqrt(epsSq);
|
|
47566
|
+
const ck1Sq = epsSq / (Math.pow(10, 0.1 * rs) - 1);
|
|
47567
|
+
if (ck1Sq <= 0) throw new Error("ellip: cannot design a filter with the given rp/rs");
|
|
47568
|
+
const val0 = ellipticKScalar(ck1Sq);
|
|
47569
|
+
const m = ellipdeg(N, ck1Sq);
|
|
47570
|
+
const capk = ellipticKScalar(m);
|
|
47571
|
+
const j = [];
|
|
47572
|
+
for (let v = 1 - N % 2; v < N; v += 2) j.push(v);
|
|
47573
|
+
const EPSILON = 2e-16;
|
|
47574
|
+
const s = [];
|
|
47575
|
+
const c = [];
|
|
47576
|
+
const d = [];
|
|
47577
|
+
for (const jv of j) {
|
|
47578
|
+
const u = jv * capk / N;
|
|
47579
|
+
s.push(jacobiSN(u, m));
|
|
47580
|
+
c.push(jacobiCN(u, m));
|
|
47581
|
+
d.push(jacobiDN(u, m));
|
|
47582
|
+
}
|
|
47583
|
+
const zHalf = [];
|
|
47584
|
+
for (let i = 0; i < j.length; i++) {
|
|
47585
|
+
if (Math.abs(s[i]) > EPSILON) zHalf.push(new Complex12(0, 1 / (Math.sqrt(m) * s[i])));
|
|
47586
|
+
}
|
|
47587
|
+
const zFull = zHalf.concat(zHalf.map((zv) => new Complex12(zv.re, -zv.im)));
|
|
47588
|
+
const rr = arcJacSc1(1 / eps, ck1Sq);
|
|
47589
|
+
const v0 = capk * rr / (N * val0);
|
|
47590
|
+
const sv = jacobiSN(v0, 1 - m);
|
|
47591
|
+
const cv = jacobiCN(v0, 1 - m);
|
|
47592
|
+
const dv = jacobiDN(v0, 1 - m);
|
|
47593
|
+
const pHalf = [];
|
|
47594
|
+
for (let i = 0; i < j.length; i++) {
|
|
47595
|
+
const num2 = new Complex12(c[i] * d[i] * sv * cv, s[i] * dv).negate();
|
|
47596
|
+
const den = 1 - Math.pow(d[i] * sv, 2);
|
|
47597
|
+
pHalf.push(new Complex12(num2.re / den, num2.im / den));
|
|
47598
|
+
}
|
|
47599
|
+
let pFull;
|
|
47600
|
+
if (N % 2) {
|
|
47601
|
+
const sumP2 = pHalf.reduce((acc, pv) => acc + pv.re * pv.re + pv.im * pv.im, 0);
|
|
47602
|
+
const thresh = EPSILON * Math.sqrt(sumP2);
|
|
47603
|
+
const newp = pHalf.filter((pv) => Math.abs(pv.im) > thresh);
|
|
47604
|
+
pFull = pHalf.concat(newp.map((pv) => new Complex12(pv.re, -pv.im)));
|
|
47605
|
+
} else {
|
|
47606
|
+
pFull = pHalf.concat(pHalf.map((pv) => new Complex12(pv.re, -pv.im)));
|
|
47607
|
+
}
|
|
47608
|
+
let prodP = new Complex12(1, 0);
|
|
47609
|
+
for (const pv of pFull) prodP = cMul(prodP, pv.negate());
|
|
47610
|
+
let prodZ = new Complex12(1, 0);
|
|
47611
|
+
for (const zv of zFull) prodZ = cMul(prodZ, zv.negate());
|
|
47612
|
+
let k = cDiv(prodP, prodZ).re;
|
|
47613
|
+
if (N % 2 === 0) k /= Math.sqrt(1 + epsSq);
|
|
47614
|
+
return { z: zFull, p: pFull, k };
|
|
47615
|
+
}
|
|
47616
|
+
function ellip(N, rp, rs, Wn, btype = "low") {
|
|
47617
|
+
if (!Number.isInteger(N) || N < 1) throw new Error("ellip: order N must be a positive integer");
|
|
47618
|
+
if (!(rp > 0)) throw new Error("ellip: rp (passband ripple, dB) must be positive");
|
|
47619
|
+
if (!(rs > 0)) throw new Error("ellip: rs (stopband attenuation, dB) must be positive");
|
|
47620
|
+
return analogToDigital(ellipap(N, rp, rs), Wn, btype);
|
|
47621
|
+
}
|
|
47622
|
+
function polyMul2(p, q) {
|
|
47623
|
+
const res = new Array(p.length + q.length - 1).fill(0);
|
|
47624
|
+
for (let i = 0; i < p.length; i++) for (let j = 0; j < q.length; j++) res[i + j] += p[i] * q[j];
|
|
47625
|
+
return res;
|
|
47626
|
+
}
|
|
47627
|
+
function polyAdd2(p, q) {
|
|
47628
|
+
const res = new Array(Math.max(p.length, q.length)).fill(0);
|
|
47629
|
+
for (let i = 0; i < p.length; i++) res[i] += p[i];
|
|
47630
|
+
for (let i = 0; i < q.length; i++) res[i] += q[i];
|
|
47631
|
+
return res;
|
|
47632
|
+
}
|
|
47633
|
+
function polyPow2(p, n) {
|
|
47634
|
+
let res = [1];
|
|
47635
|
+
for (let i = 0; i < n; i++) res = polyMul2(res, p);
|
|
47636
|
+
return res;
|
|
47637
|
+
}
|
|
47638
|
+
function trimLeadingZeros(coeffs) {
|
|
47639
|
+
let i = 0;
|
|
47640
|
+
while (i < coeffs.length - 1 && coeffs[i] === 0) i++;
|
|
47641
|
+
return coeffs.slice(i);
|
|
47642
|
+
}
|
|
47643
|
+
function bilinear(bIn, aIn, fs) {
|
|
47644
|
+
const bTrim = trimLeadingZeros(arr8(bIn));
|
|
47645
|
+
const aTrim = trimLeadingZeros(arr8(aIn));
|
|
47646
|
+
const Q2 = bTrim.length - 1;
|
|
47647
|
+
const P2 = aTrim.length - 1;
|
|
47648
|
+
const N = Math.max(P2, Q2);
|
|
47649
|
+
const kappa = 2 * fs;
|
|
47650
|
+
const zp1 = [1, 1];
|
|
47651
|
+
const zm1 = [-kappa, kappa];
|
|
47652
|
+
let numerator = [0];
|
|
47653
|
+
for (let q = 0; q <= Q2; q++) {
|
|
47654
|
+
const bq = bTrim[Q2 - q];
|
|
47655
|
+
numerator = polyAdd2(
|
|
47656
|
+
numerator,
|
|
47657
|
+
polyMul2(polyPow2(zp1, N - q), polyPow2(zm1, q)).map((v) => v * bq)
|
|
47658
|
+
);
|
|
47659
|
+
}
|
|
47660
|
+
let denominator = [0];
|
|
47661
|
+
for (let p = 0; p <= P2; p++) {
|
|
47662
|
+
const ap = aTrim[P2 - p];
|
|
47663
|
+
denominator = polyAdd2(
|
|
47664
|
+
denominator,
|
|
47665
|
+
polyMul2(polyPow2(zp1, N - p), polyPow2(zm1, p)).map((v) => v * ap)
|
|
47666
|
+
);
|
|
47667
|
+
}
|
|
47668
|
+
const bDesc = numerator.slice().reverse();
|
|
47669
|
+
const aDesc = denominator.slice().reverse();
|
|
47670
|
+
const a0 = aDesc[0];
|
|
47671
|
+
return { b: bDesc.map((v) => v / a0), a: aDesc.map((v) => v / a0) };
|
|
47672
|
+
}
|
|
47673
|
+
function buttord(wp, ws, gpass, gstop) {
|
|
47674
|
+
if (!(wp > 0 && wp < 1)) throw new Error("buttord: wp must satisfy 0 < wp < 1");
|
|
47675
|
+
if (!(ws > 0 && ws < 1)) throw new Error("buttord: ws must satisfy 0 < ws < 1");
|
|
47676
|
+
if (wp === ws) throw new Error("buttord: wp and ws must differ");
|
|
47677
|
+
const isLow = wp < ws;
|
|
47678
|
+
const passb = Math.tan(Math.PI * wp / 2);
|
|
47679
|
+
const stopb = Math.tan(Math.PI * ws / 2);
|
|
47680
|
+
const nat = isLow ? stopb / passb : passb / stopb;
|
|
47681
|
+
const GSTOP = Math.pow(10, 0.1 * Math.abs(gstop));
|
|
47682
|
+
const GPASS = Math.pow(10, 0.1 * Math.abs(gpass));
|
|
47683
|
+
const N = Math.ceil(Math.log10((GSTOP - 1) / (GPASS - 1)) / (2 * Math.log10(nat)));
|
|
47684
|
+
const W0 = Math.pow(GPASS - 1, -1 / (2 * N));
|
|
47685
|
+
const WN = isLow ? W0 * passb : passb / W0;
|
|
47686
|
+
return { N, Wn: Math.atan(WN) * 2 / Math.PI };
|
|
47687
|
+
}
|
|
47688
|
+
function toComplex(x) {
|
|
47689
|
+
return x instanceof Complex12 ? x : new Complex12(x, 0);
|
|
47690
|
+
}
|
|
47691
|
+
function groupConjugatePairs(rootsIn) {
|
|
47692
|
+
const roots = rootsIn.map(toComplex);
|
|
47693
|
+
const n = roots.length;
|
|
47694
|
+
const used = new Array(n).fill(false);
|
|
47695
|
+
const groups = [];
|
|
47696
|
+
const tol = 1e-6;
|
|
47697
|
+
for (let i = 0; i < n; i++) {
|
|
47698
|
+
if (used[i] || Math.abs(roots[i].im) <= tol) continue;
|
|
47699
|
+
const mag = Math.max(1, Math.abs(roots[i].re), Math.abs(roots[i].im));
|
|
47700
|
+
let match = -1;
|
|
47701
|
+
for (let j = i + 1; j < n; j++) {
|
|
47702
|
+
if (used[j]) continue;
|
|
47703
|
+
if (Math.abs(roots[j].re - roots[i].re) < tol * mag && Math.abs(roots[j].im + roots[i].im) < tol * mag) {
|
|
47704
|
+
match = j;
|
|
47705
|
+
break;
|
|
47706
|
+
}
|
|
47707
|
+
}
|
|
47708
|
+
if (match === -1)
|
|
47709
|
+
throw new Error(
|
|
47710
|
+
"zpk2sos: complex root has no matching conjugate (input must have real coefficients)"
|
|
47711
|
+
);
|
|
47712
|
+
used[i] = true;
|
|
47713
|
+
used[match] = true;
|
|
47714
|
+
groups.push([roots[i], roots[match]]);
|
|
47715
|
+
}
|
|
47716
|
+
const reals = [];
|
|
47717
|
+
for (let i = 0; i < n; i++) if (!used[i]) reals.push(new Complex12(roots[i].re, 0));
|
|
47718
|
+
for (let i = 0; i + 1 < reals.length; i += 2) groups.push([reals[i], reals[i + 1]]);
|
|
47719
|
+
if (reals.length % 2 === 1) groups.push([reals[reals.length - 1]]);
|
|
47720
|
+
return groups;
|
|
47721
|
+
}
|
|
47722
|
+
function quadraticFromRoots(roots) {
|
|
47723
|
+
const poly = polyFromRoots(roots);
|
|
47724
|
+
return poly.length === 2 ? [poly[0], poly[1], 0] : [poly[0], poly[1], poly[2]];
|
|
47725
|
+
}
|
|
47726
|
+
function zpk2sos(z, p, k) {
|
|
47727
|
+
if (z.length > p.length)
|
|
47728
|
+
throw new Error("zpk2sos: more zeros than poles (improper transfer function)");
|
|
47729
|
+
const zPadded = z.slice();
|
|
47730
|
+
while (zPadded.length < p.length) zPadded.push(0);
|
|
47731
|
+
const zGroups = groupConjugatePairs(zPadded);
|
|
47732
|
+
const pGroups = groupConjugatePairs(p);
|
|
47733
|
+
if (zGroups.length !== pGroups.length)
|
|
47734
|
+
throw new Error("zpk2sos: zero/pole group-count mismatch (roots must be conjugate-symmetric)");
|
|
47735
|
+
const sos = [];
|
|
47736
|
+
for (let i = 0; i < pGroups.length; i++) {
|
|
47737
|
+
const [b0, b1, b2] = quadraticFromRoots(zGroups[i]);
|
|
47738
|
+
const [a0, a1, a2] = quadraticFromRoots(pGroups[i]);
|
|
47739
|
+
const gain = i === 0 ? k : 1;
|
|
47740
|
+
sos.push([b0 * gain, b1 * gain, b2 * gain, a0, a1, a2]);
|
|
47741
|
+
}
|
|
47742
|
+
return sos;
|
|
47743
|
+
}
|
|
47744
|
+
function sosfilt(sos, x) {
|
|
47745
|
+
let y = arr8(x);
|
|
47746
|
+
for (const section of sos) {
|
|
47747
|
+
if (section.length !== 6)
|
|
47748
|
+
throw new Error("sosfilt: each section must have 6 coefficients [b0,b1,b2,a0,a1,a2]");
|
|
47749
|
+
const [b0, b1, b2, a0, a1, a2] = section;
|
|
47750
|
+
y = lfilter([b0, b1, b2], [a0, a1, a2], y);
|
|
47751
|
+
}
|
|
47752
|
+
return y;
|
|
47753
|
+
}
|
|
47754
|
+
|
|
47755
|
+
// src/signal/fft.ts
|
|
47756
|
+
function complex2(re3, im3 = 0) {
|
|
47757
|
+
return { re: re3, im: im3 };
|
|
47758
|
+
}
|
|
47759
|
+
function isPowerOf25(n) {
|
|
47760
|
+
return n > 0 && (n & n - 1) === 0;
|
|
47761
|
+
}
|
|
47762
|
+
function nextPowerOf22(n) {
|
|
47763
|
+
if (n <= 1) return 1;
|
|
47764
|
+
return Math.pow(2, Math.ceil(Math.log2(n)));
|
|
47765
|
+
}
|
|
47766
|
+
function fftCore(data, inverse = false) {
|
|
47767
|
+
const n = data.length;
|
|
47768
|
+
if (!isPowerOf25(n)) {
|
|
47769
|
+
throw new Error(`FFT length must be power of 2, got ${n}`);
|
|
47770
|
+
}
|
|
47771
|
+
if (n === 1) {
|
|
47772
|
+
return [{ ...data[0] }];
|
|
47773
|
+
}
|
|
47774
|
+
const real = new Float64Array(n);
|
|
47775
|
+
const imag = new Float64Array(n);
|
|
47776
|
+
for (let i = 0; i < n; i++) {
|
|
47777
|
+
real[i] = data[i].re;
|
|
47778
|
+
imag[i] = data[i].im;
|
|
47779
|
+
}
|
|
47780
|
+
const out = fftCoreFloat64(real, imag, inverse);
|
|
47781
|
+
const spectrum = new Array(n);
|
|
47782
|
+
for (let i = 0; i < n; i++) {
|
|
47783
|
+
spectrum[i] = { re: out.real[i], im: out.imag[i] };
|
|
47784
|
+
}
|
|
47785
|
+
return spectrum;
|
|
47786
|
+
}
|
|
47787
|
+
function fft2(signal) {
|
|
47788
|
+
const originalLength = signal.length;
|
|
47789
|
+
if (originalLength === 0) {
|
|
47790
|
+
return {
|
|
47791
|
+
spectrum: [],
|
|
47792
|
+
originalLength: 0,
|
|
47793
|
+
paddedLength: 0
|
|
47794
|
+
};
|
|
47795
|
+
}
|
|
47796
|
+
let complexSignal;
|
|
47797
|
+
if (signal instanceof Float64Array) {
|
|
47798
|
+
complexSignal = Array.from(signal).map((x) => complex2(x, 0));
|
|
47799
|
+
} else if (typeof signal[0] === "number") {
|
|
47800
|
+
complexSignal = signal.map((x) => complex2(x, 0));
|
|
47801
|
+
} else {
|
|
47802
|
+
complexSignal = signal;
|
|
47803
|
+
}
|
|
47804
|
+
const paddedLength = nextPowerOf22(originalLength);
|
|
47805
|
+
if (paddedLength > originalLength) {
|
|
47806
|
+
const padding = new Array(paddedLength - originalLength).fill(complex2(0, 0));
|
|
47807
|
+
complexSignal = [...complexSignal, ...padding];
|
|
47808
|
+
}
|
|
47809
|
+
const spectrum = fftCore(complexSignal, false);
|
|
47810
|
+
return {
|
|
47811
|
+
spectrum,
|
|
47812
|
+
originalLength,
|
|
47813
|
+
paddedLength
|
|
47814
|
+
};
|
|
47815
|
+
}
|
|
47816
|
+
function ifft2(spectrum, originalLength) {
|
|
47817
|
+
if (spectrum.length === 0) {
|
|
47818
|
+
return [];
|
|
47819
|
+
}
|
|
47820
|
+
const paddedLength = nextPowerOf22(spectrum.length);
|
|
47821
|
+
let paddedSpectrum = spectrum;
|
|
47822
|
+
if (paddedLength > spectrum.length) {
|
|
47823
|
+
const padding = new Array(paddedLength - spectrum.length).fill(complex2(0, 0));
|
|
47824
|
+
paddedSpectrum = [...spectrum, ...padding];
|
|
47825
|
+
}
|
|
47826
|
+
const result = fftCore(paddedSpectrum, true);
|
|
47827
|
+
if (originalLength !== void 0 && originalLength < result.length) {
|
|
47828
|
+
return result.slice(0, originalLength);
|
|
47829
|
+
}
|
|
47830
|
+
return result;
|
|
47831
|
+
}
|
|
47832
|
+
function ifftReal(spectrum, originalLength) {
|
|
47833
|
+
const complex3 = ifft2(spectrum, originalLength);
|
|
47834
|
+
return complex3.map((c) => c.re);
|
|
47835
|
+
}
|
|
47836
|
+
|
|
47837
|
+
// src/signal/conv.ts
|
|
47838
|
+
function convDirect(x, h, mode2 = "full") {
|
|
47839
|
+
const xArr = Array.isArray(x) ? x : Array.from(x);
|
|
47840
|
+
const hArr = Array.isArray(h) ? h : Array.from(h);
|
|
47841
|
+
const n = xArr.length;
|
|
47842
|
+
const m = hArr.length;
|
|
47843
|
+
if (n === 0 || m === 0) {
|
|
47844
|
+
return [];
|
|
47845
|
+
}
|
|
47846
|
+
const fullLength = n + m - 1;
|
|
47847
|
+
const result = new Array(fullLength).fill(0);
|
|
47848
|
+
for (let i = 0; i < n; i++) {
|
|
47849
|
+
for (let j = 0; j < m; j++) {
|
|
47850
|
+
result[i + j] += xArr[i] * hArr[j];
|
|
47851
|
+
}
|
|
47852
|
+
}
|
|
47853
|
+
switch (mode2) {
|
|
47854
|
+
case "full":
|
|
47855
|
+
return result;
|
|
47856
|
+
case "same": {
|
|
47857
|
+
const startSame = Math.floor((m - 1) / 2);
|
|
47858
|
+
return result.slice(startSame, startSame + n);
|
|
47859
|
+
}
|
|
47860
|
+
case "valid": {
|
|
47861
|
+
if (m > n) {
|
|
47862
|
+
return [];
|
|
47863
|
+
}
|
|
47864
|
+
const startValid = m - 1;
|
|
47865
|
+
const validLength = Math.max(0, n - m + 1);
|
|
47866
|
+
return result.slice(startValid, startValid + validLength);
|
|
47867
|
+
}
|
|
47868
|
+
default:
|
|
47869
|
+
return result;
|
|
46955
47870
|
}
|
|
46956
|
-
|
|
46957
|
-
|
|
46958
|
-
|
|
46959
|
-
|
|
46960
|
-
|
|
46961
|
-
const
|
|
46962
|
-
const
|
|
46963
|
-
|
|
46964
|
-
for (
|
|
46965
|
-
|
|
46966
|
-
|
|
46967
|
-
|
|
46968
|
-
|
|
47871
|
+
}
|
|
47872
|
+
|
|
47873
|
+
// src/signal/fir-smoothing.ts
|
|
47874
|
+
var arr9 = (x) => Array.isArray(x) ? x : Array.from(x);
|
|
47875
|
+
function solveLinearSystem(Ain, bin2) {
|
|
47876
|
+
const n = bin2.length;
|
|
47877
|
+
const A = Ain.map((row2) => row2.slice());
|
|
47878
|
+
const b = bin2.slice();
|
|
47879
|
+
for (let col = 0; col < n; col++) {
|
|
47880
|
+
let piv = col;
|
|
47881
|
+
for (let r = col + 1; r < n; r++) if (Math.abs(A[r][col]) > Math.abs(A[piv][col])) piv = r;
|
|
47882
|
+
if (piv !== col) {
|
|
47883
|
+
[A[col], A[piv]] = [A[piv], A[col]];
|
|
47884
|
+
[b[col], b[piv]] = [b[piv], b[col]];
|
|
47885
|
+
}
|
|
47886
|
+
const pivotVal = A[col][col];
|
|
47887
|
+
if (Math.abs(pivotVal) < 1e-14) throw new Error("solveLinearSystem: singular matrix");
|
|
47888
|
+
for (let r = col + 1; r < n; r++) {
|
|
47889
|
+
const factor2 = A[r][col] / pivotVal;
|
|
47890
|
+
if (factor2 === 0) continue;
|
|
47891
|
+
for (let c = col; c < n; c++) A[r][c] -= factor2 * A[col][c];
|
|
47892
|
+
b[r] -= factor2 * b[col];
|
|
47893
|
+
}
|
|
47894
|
+
}
|
|
47895
|
+
const x = new Array(n).fill(0);
|
|
47896
|
+
for (let row2 = n - 1; row2 >= 0; row2--) {
|
|
47897
|
+
let sum3 = b[row2];
|
|
47898
|
+
for (let c = row2 + 1; c < n; c++) sum3 -= A[row2][c] * x[c];
|
|
47899
|
+
x[row2] = sum3 / A[row2][row2];
|
|
47900
|
+
}
|
|
47901
|
+
return x;
|
|
47902
|
+
}
|
|
47903
|
+
function firwinBandpass(numtaps, cutoffs) {
|
|
47904
|
+
if (!Number.isInteger(numtaps) || numtaps < 2)
|
|
47905
|
+
throw new Error("firwinBandpass: numtaps must be an integer >= 2");
|
|
47906
|
+
const [f1, f2] = cutoffs;
|
|
47907
|
+
if (!(f1 > 0 && f1 < f2 && f2 < 1))
|
|
47908
|
+
throw new Error("firwinBandpass: require 0 < f1 < f2 < 1 (normalized to Nyquist)");
|
|
47909
|
+
const M = numtaps - 1;
|
|
47910
|
+
const h = new Array(numtaps);
|
|
47911
|
+
for (let n = 0; n <= M; n++) {
|
|
47912
|
+
const w = 0.54 - 0.46 * Math.cos(2 * Math.PI * n / M);
|
|
47913
|
+
h[n] = (f2 * sinc(f2 * (n - M / 2)) - f1 * sinc(f1 * (n - M / 2))) * w;
|
|
47914
|
+
}
|
|
47915
|
+
return h;
|
|
47916
|
+
}
|
|
47917
|
+
function polyFitCoeffs(offsets, values, polyorder) {
|
|
47918
|
+
const p = polyorder + 1;
|
|
47919
|
+
const A = offsets.map((t) => Array.from({ length: p }, (_, k) => Math.pow(t, k)));
|
|
47920
|
+
const AtA = Array.from(
|
|
47921
|
+
{ length: p },
|
|
47922
|
+
(_, i) => Array.from({ length: p }, (_2, j) => A.reduce((s, row2) => s + row2[i] * row2[j], 0))
|
|
47923
|
+
);
|
|
47924
|
+
const Atb = Array.from(
|
|
47925
|
+
{ length: p },
|
|
47926
|
+
(_, i) => A.reduce((s, row2, idx) => s + row2[i] * values[idx], 0)
|
|
47927
|
+
);
|
|
47928
|
+
return solveLinearSystem(AtA, Atb);
|
|
47929
|
+
}
|
|
47930
|
+
function evalPoly(c, t) {
|
|
47931
|
+
let s = 0;
|
|
47932
|
+
let tk = 1;
|
|
47933
|
+
for (let k = 0; k < c.length; k++) {
|
|
47934
|
+
s += c[k] * tk;
|
|
47935
|
+
tk *= t;
|
|
47936
|
+
}
|
|
47937
|
+
return s;
|
|
47938
|
+
}
|
|
47939
|
+
function savgol(x, windowLength, polyorder) {
|
|
47940
|
+
const xx = arr9(x);
|
|
47941
|
+
const n = xx.length;
|
|
47942
|
+
if (!Number.isInteger(windowLength) || windowLength < 1 || windowLength % 2 === 0)
|
|
47943
|
+
throw new Error("savgol: windowLength must be a positive odd integer");
|
|
47944
|
+
if (!Number.isInteger(polyorder) || polyorder < 0 || polyorder >= windowLength)
|
|
47945
|
+
throw new Error("savgol: polyorder must satisfy 0 <= polyorder < windowLength");
|
|
47946
|
+
if (windowLength > n) throw new Error("savgol: windowLength must not exceed the signal length");
|
|
47947
|
+
const half = (windowLength - 1) / 2;
|
|
47948
|
+
const offsets = Array.from({ length: windowLength }, (_, j) => j - half);
|
|
47949
|
+
const out = new Array(n);
|
|
47950
|
+
for (let i = half; i <= n - 1 - half; i++) {
|
|
47951
|
+
const values = offsets.map((_, j) => xx[i - half + j]);
|
|
47952
|
+
out[i] = polyFitCoeffs(offsets, values, polyorder)[0];
|
|
47953
|
+
}
|
|
47954
|
+
if (half > 0) {
|
|
47955
|
+
const cLeft = polyFitCoeffs(offsets, xx.slice(0, windowLength), polyorder);
|
|
47956
|
+
for (let i = 0; i < half; i++) out[i] = evalPoly(cLeft, i - half);
|
|
47957
|
+
const cRight = polyFitCoeffs(offsets, xx.slice(n - windowLength, n), polyorder);
|
|
47958
|
+
const rightCenter = n - 1 - half;
|
|
47959
|
+
for (let i = n - half; i < n; i++) out[i] = evalPoly(cRight, i - rightCenter);
|
|
47960
|
+
}
|
|
47961
|
+
return out;
|
|
47962
|
+
}
|
|
47963
|
+
function deconvolve(signal, divisor) {
|
|
47964
|
+
const s = arr9(signal);
|
|
47965
|
+
const d = arr9(divisor);
|
|
47966
|
+
const N = s.length;
|
|
47967
|
+
const D = d.length;
|
|
47968
|
+
if (D === 0) throw new Error("deconvolve: divisor must be non-empty");
|
|
47969
|
+
if (d[0] === 0) throw new Error("deconvolve: divisor[0] (leading coefficient) must be nonzero");
|
|
47970
|
+
if (D > N) return { quotient: [], remainder: s.slice() };
|
|
47971
|
+
const remainder = s.slice();
|
|
47972
|
+
const quotient = new Array(N - D + 1).fill(0);
|
|
47973
|
+
for (let i = 0; i < quotient.length; i++) {
|
|
47974
|
+
const c = remainder[i] / d[0];
|
|
47975
|
+
quotient[i] = c;
|
|
47976
|
+
for (let j = 0; j < D; j++) remainder[i + j] -= c * d[j];
|
|
47977
|
+
}
|
|
47978
|
+
return { quotient, remainder };
|
|
47979
|
+
}
|
|
47980
|
+
function wiener(x, mysize = 3) {
|
|
47981
|
+
const xx = arr9(x);
|
|
47982
|
+
const n = xx.length;
|
|
47983
|
+
if (!Number.isInteger(mysize) || mysize < 1)
|
|
47984
|
+
throw new Error("wiener: mysize must be a positive integer");
|
|
47985
|
+
const kernel = new Array(mysize).fill(1 / mysize);
|
|
47986
|
+
const lMean = convDirect(xx, kernel, "same");
|
|
47987
|
+
const lMeanSq = convDirect(
|
|
47988
|
+
xx.map((v) => v * v),
|
|
47989
|
+
kernel,
|
|
47990
|
+
"same"
|
|
47991
|
+
);
|
|
47992
|
+
const lVar = lMeanSq.map((v, i) => Math.max(0, v - lMean[i] * lMean[i]));
|
|
47993
|
+
const noise = lVar.reduce((a, b) => a + b, 0) / n;
|
|
47994
|
+
return xx.map((xi, i) => {
|
|
47995
|
+
const v = lVar[i];
|
|
47996
|
+
const denom = Math.max(v, noise);
|
|
47997
|
+
if (denom === 0) return lMean[i];
|
|
47998
|
+
return lMean[i] + Math.max(0, v - noise) / denom * (xi - lMean[i]);
|
|
47999
|
+
});
|
|
48000
|
+
}
|
|
48001
|
+
function makeBasis(numtaps) {
|
|
48002
|
+
const type1 = numtaps % 2 === 1;
|
|
48003
|
+
const M = type1 ? (numtaps - 1) / 2 : numtaps / 2;
|
|
48004
|
+
const nBasis = type1 ? M + 1 : M;
|
|
48005
|
+
return {
|
|
48006
|
+
type1,
|
|
48007
|
+
M,
|
|
48008
|
+
nBasis,
|
|
48009
|
+
phi: (k, w) => type1 ? Math.cos(k * Math.PI * w) : Math.cos((k + 0.5) * Math.PI * w)
|
|
48010
|
+
};
|
|
48011
|
+
}
|
|
48012
|
+
function coeffsToTaps(numtaps, basis, coeffs) {
|
|
48013
|
+
const h = new Array(numtaps).fill(0);
|
|
48014
|
+
const { M, type1 } = basis;
|
|
48015
|
+
if (type1) {
|
|
48016
|
+
h[M] = coeffs[0];
|
|
48017
|
+
for (let k = 1; k <= M; k++) {
|
|
48018
|
+
h[M - k] = coeffs[k] / 2;
|
|
48019
|
+
h[M + k] = coeffs[k] / 2;
|
|
48020
|
+
}
|
|
48021
|
+
} else {
|
|
48022
|
+
for (let k = 1; k <= M; k++) {
|
|
48023
|
+
const v = coeffs[k - 1] / 2;
|
|
48024
|
+
h[M - k] = v;
|
|
48025
|
+
h[M - 1 + k] = v;
|
|
48026
|
+
}
|
|
48027
|
+
}
|
|
48028
|
+
return h;
|
|
48029
|
+
}
|
|
48030
|
+
function validateBandsDesired(numtaps, bands, desired) {
|
|
48031
|
+
if (!Number.isInteger(numtaps) || numtaps < 3)
|
|
48032
|
+
throw new Error("firls/remez: numtaps must be an integer >= 3");
|
|
48033
|
+
if (bands.length < 2 || bands.length % 2 !== 0)
|
|
48034
|
+
throw new Error("firls/remez: bands must be a non-empty list of [lo, hi] pairs");
|
|
48035
|
+
if (desired.length !== bands.length)
|
|
48036
|
+
throw new Error("firls/remez: desired must have the same length as bands");
|
|
48037
|
+
for (let i = 0; i < bands.length; i += 2) {
|
|
48038
|
+
if (!(bands[i] >= 0 && bands[i] < bands[i + 1] && bands[i + 1] <= 1))
|
|
48039
|
+
throw new Error("firls/remez: each band pair must satisfy 0 <= lo < hi <= 1");
|
|
48040
|
+
}
|
|
48041
|
+
}
|
|
48042
|
+
function sampleBands(bands, desired, samplesPerBand = 400) {
|
|
48043
|
+
const pts = [];
|
|
48044
|
+
for (let band = 0; band < bands.length; band += 2) {
|
|
48045
|
+
const w0 = bands[band];
|
|
48046
|
+
const w1 = bands[band + 1];
|
|
48047
|
+
const d0 = desired[band];
|
|
48048
|
+
const d1 = desired[band + 1];
|
|
48049
|
+
const dw = (w1 - w0) / samplesPerBand;
|
|
48050
|
+
for (let s = 0; s <= samplesPerBand; s++) {
|
|
48051
|
+
const w = w0 + s * dw;
|
|
48052
|
+
const D = d0 + (d1 - d0) * (w - w0) / (w1 - w0);
|
|
48053
|
+
const weight = s === 0 || s === samplesPerBand ? 0.5 * dw : dw;
|
|
48054
|
+
pts.push({ w, D, dw: weight });
|
|
48055
|
+
}
|
|
48056
|
+
}
|
|
48057
|
+
return pts;
|
|
48058
|
+
}
|
|
48059
|
+
function solveWeightedBasis(basis, pts, weights) {
|
|
48060
|
+
const n = basis.nBasis;
|
|
48061
|
+
const A = Array.from({ length: n }, () => new Array(n).fill(0));
|
|
48062
|
+
const b = new Array(n).fill(0);
|
|
48063
|
+
for (let i = 0; i < pts.length; i++) {
|
|
48064
|
+
const { w, D, dw } = pts[i];
|
|
48065
|
+
const wt = weights[i] * dw;
|
|
48066
|
+
const phis = Array.from({ length: n }, (_, k) => basis.phi(k, w));
|
|
48067
|
+
for (let a = 0; a < n; a++) {
|
|
48068
|
+
b[a] += wt * phis[a] * D;
|
|
48069
|
+
for (let c = 0; c < n; c++) A[a][c] += wt * phis[a] * phis[c];
|
|
48070
|
+
}
|
|
48071
|
+
}
|
|
48072
|
+
return solveLinearSystem(A, b);
|
|
48073
|
+
}
|
|
48074
|
+
function evalBasis(basis, coeffs, w) {
|
|
48075
|
+
let s = 0;
|
|
48076
|
+
for (let k = 0; k < basis.nBasis; k++) s += coeffs[k] * basis.phi(k, w);
|
|
48077
|
+
return s;
|
|
48078
|
+
}
|
|
48079
|
+
function firls(numtaps, bands, desired) {
|
|
48080
|
+
validateBandsDesired(numtaps, bands, desired);
|
|
48081
|
+
const basis = makeBasis(numtaps);
|
|
48082
|
+
const pts = sampleBands(bands, desired);
|
|
48083
|
+
const coeffs = solveWeightedBasis(
|
|
48084
|
+
basis,
|
|
48085
|
+
pts,
|
|
48086
|
+
pts.map(() => 1)
|
|
48087
|
+
);
|
|
48088
|
+
return coeffsToTaps(numtaps, basis, coeffs);
|
|
48089
|
+
}
|
|
48090
|
+
function remez(numtaps, bands, desired) {
|
|
48091
|
+
validateBandsDesired(numtaps, bands, desired);
|
|
48092
|
+
const basis = makeBasis(numtaps);
|
|
48093
|
+
const pts = sampleBands(bands, desired);
|
|
48094
|
+
let weights = pts.map(() => 1);
|
|
48095
|
+
let coeffs = solveWeightedBasis(basis, pts, weights);
|
|
48096
|
+
const ITERATIONS = 15;
|
|
48097
|
+
for (let iter = 1; iter < ITERATIONS; iter++) {
|
|
48098
|
+
const errs = pts.map((pt) => Math.abs(evalBasis(basis, coeffs, pt.w) - pt.D));
|
|
48099
|
+
const maxErr = Math.max(...errs, 1e-12);
|
|
48100
|
+
const reweighted = weights.map((wgt, i) => wgt * Math.pow(errs[i] / maxErr + 1e-6, 0.5));
|
|
48101
|
+
const meanW = reweighted.reduce((a, b) => a + b, 0) / reweighted.length;
|
|
48102
|
+
weights = reweighted.map((wgt) => wgt / meanW);
|
|
48103
|
+
coeffs = solveWeightedBasis(basis, pts, weights);
|
|
48104
|
+
}
|
|
48105
|
+
return coeffsToTaps(numtaps, basis, coeffs);
|
|
48106
|
+
}
|
|
48107
|
+
|
|
48108
|
+
// src/signal/wavelets.ts
|
|
48109
|
+
function idwt(approx, detail, wavelet = "haar") {
|
|
48110
|
+
if (wavelet !== "haar" && wavelet !== "db1") {
|
|
48111
|
+
throw new Error(`idwt: unsupported wavelet "${wavelet}"`);
|
|
48112
|
+
}
|
|
48113
|
+
if (approx.length !== detail.length) {
|
|
48114
|
+
throw new Error("idwt: approx and detail must have equal length");
|
|
48115
|
+
}
|
|
48116
|
+
const half = approx.length;
|
|
48117
|
+
const s = 1 / Math.SQRT2;
|
|
48118
|
+
const x = new Array(half * 2);
|
|
48119
|
+
for (let i = 0; i < half; i++) {
|
|
48120
|
+
x[2 * i] = s * (approx[i] + detail[i]);
|
|
48121
|
+
x[2 * i + 1] = s * (approx[i] - detail[i]);
|
|
48122
|
+
}
|
|
48123
|
+
return x;
|
|
48124
|
+
}
|
|
48125
|
+
function wavedec(x, wavelet = "haar", level = 1) {
|
|
48126
|
+
if (!Number.isInteger(level) || level < 1) {
|
|
48127
|
+
throw new Error("wavedec: level must be an integer >= 1");
|
|
48128
|
+
}
|
|
48129
|
+
const coeffs = [];
|
|
48130
|
+
let approx = x.slice();
|
|
48131
|
+
for (let l = 0; l < level; l++) {
|
|
48132
|
+
const { approx: a, detail: d } = dwt(approx, wavelet);
|
|
48133
|
+
coeffs.unshift(d);
|
|
48134
|
+
approx = a;
|
|
48135
|
+
}
|
|
48136
|
+
coeffs.unshift(approx);
|
|
48137
|
+
return coeffs;
|
|
48138
|
+
}
|
|
48139
|
+
function waverec(coeffs, wavelet = "haar") {
|
|
48140
|
+
if (coeffs.length < 2) {
|
|
48141
|
+
throw new Error("waverec: coeffs must contain at least [cA, cD]");
|
|
48142
|
+
}
|
|
48143
|
+
let approx = coeffs[0].slice();
|
|
48144
|
+
for (let i = 1; i < coeffs.length; i++) {
|
|
48145
|
+
approx = idwt(approx, coeffs[i], wavelet);
|
|
48146
|
+
}
|
|
48147
|
+
return approx;
|
|
48148
|
+
}
|
|
48149
|
+
function rickerWavelet(points, scale) {
|
|
48150
|
+
const amplitude = 2 / (Math.sqrt(3 * scale) * Math.pow(Math.PI, 0.25));
|
|
48151
|
+
const out = new Array(points);
|
|
48152
|
+
const center2 = (points - 1) / 2;
|
|
48153
|
+
for (let i = 0; i < points; i++) {
|
|
48154
|
+
const t = (i - center2) / scale;
|
|
48155
|
+
const t2 = t * t;
|
|
48156
|
+
out[i] = amplitude * (1 - t2) * Math.exp(-t2 / 2);
|
|
48157
|
+
}
|
|
48158
|
+
return out;
|
|
48159
|
+
}
|
|
48160
|
+
function morletWavelet(points, scale) {
|
|
48161
|
+
const norm4 = 1 / (Math.sqrt(scale) * Math.pow(Math.PI, 0.25));
|
|
48162
|
+
const out = new Array(points);
|
|
48163
|
+
const center2 = (points - 1) / 2;
|
|
48164
|
+
for (let i = 0; i < points; i++) {
|
|
48165
|
+
const t = (i - center2) / scale;
|
|
48166
|
+
out[i] = norm4 * Math.cos(5 * t) * Math.exp(-(t * t) / 2);
|
|
48167
|
+
}
|
|
48168
|
+
return out;
|
|
48169
|
+
}
|
|
48170
|
+
function cwt(x, scales, wavelet = "ricker") {
|
|
48171
|
+
if (wavelet !== "ricker" && wavelet !== "morlet") {
|
|
48172
|
+
throw new Error(`cwt: unsupported wavelet "${wavelet}"`);
|
|
48173
|
+
}
|
|
48174
|
+
const n = x.length;
|
|
48175
|
+
return scales.map((scale) => {
|
|
48176
|
+
if (scale <= 0) throw new Error("cwt: scales must be positive");
|
|
48177
|
+
const points = Math.max(1, Math.min(Math.round(10 * scale), n));
|
|
48178
|
+
const psi = wavelet === "ricker" ? rickerWavelet(points, scale) : morletWavelet(points, scale);
|
|
48179
|
+
return convDirect(x, psi, "same");
|
|
48180
|
+
});
|
|
48181
|
+
}
|
|
48182
|
+
|
|
48183
|
+
// src/signal/spectral-peaks.ts
|
|
48184
|
+
function peakProminence(x, i) {
|
|
48185
|
+
const n = x.length;
|
|
48186
|
+
const peakHeight = x[i];
|
|
48187
|
+
let leftMin = peakHeight;
|
|
48188
|
+
let j = i;
|
|
48189
|
+
while (j > 0) {
|
|
48190
|
+
j--;
|
|
48191
|
+
if (x[j] > peakHeight) break;
|
|
48192
|
+
if (x[j] < leftMin) leftMin = x[j];
|
|
48193
|
+
}
|
|
48194
|
+
let rightMin = peakHeight;
|
|
48195
|
+
let k = i;
|
|
48196
|
+
while (k < n - 1) {
|
|
48197
|
+
k++;
|
|
48198
|
+
if (x[k] > peakHeight) break;
|
|
48199
|
+
if (x[k] < rightMin) rightMin = x[k];
|
|
48200
|
+
}
|
|
48201
|
+
return peakHeight - Math.max(leftMin, rightMin);
|
|
48202
|
+
}
|
|
48203
|
+
function filterByDistance(x, peaks, distance2) {
|
|
48204
|
+
const order = peaks.map((_, idx) => idx).sort((a, b) => x[peaks[b]] - x[peaks[a]]);
|
|
48205
|
+
const keep = new Array(peaks.length).fill(true);
|
|
48206
|
+
for (const idx of order) {
|
|
48207
|
+
if (!keep[idx]) continue;
|
|
48208
|
+
let j = idx - 1;
|
|
48209
|
+
while (j >= 0 && peaks[idx] - peaks[j] < distance2) {
|
|
48210
|
+
keep[j] = false;
|
|
48211
|
+
j--;
|
|
48212
|
+
}
|
|
48213
|
+
let k = idx + 1;
|
|
48214
|
+
while (k < peaks.length && peaks[k] - peaks[idx] < distance2) {
|
|
48215
|
+
keep[k] = false;
|
|
48216
|
+
k++;
|
|
48217
|
+
}
|
|
48218
|
+
}
|
|
48219
|
+
return peaks.filter((_, idx) => keep[idx]);
|
|
48220
|
+
}
|
|
48221
|
+
function findPeaks(x, opts) {
|
|
48222
|
+
let peaks = [];
|
|
48223
|
+
for (let i = 1; i < x.length - 1; i++) {
|
|
48224
|
+
if (x[i - 1] < x[i] && x[i] > x[i + 1]) peaks.push(i);
|
|
48225
|
+
}
|
|
48226
|
+
if (opts?.height !== void 0) {
|
|
48227
|
+
const h = opts.height;
|
|
48228
|
+
peaks = peaks.filter((i) => x[i] >= h);
|
|
48229
|
+
}
|
|
48230
|
+
if (opts?.prominence !== void 0) {
|
|
48231
|
+
const p = opts.prominence;
|
|
48232
|
+
peaks = peaks.filter((i) => peakProminence(x, i) >= p);
|
|
48233
|
+
}
|
|
48234
|
+
if (opts?.distance !== void 0 && peaks.length > 1) {
|
|
48235
|
+
peaks = filterByDistance(x, peaks, opts.distance);
|
|
48236
|
+
}
|
|
48237
|
+
return peaks;
|
|
48238
|
+
}
|
|
48239
|
+
function interpolateCrossing(x, start, dir, refHeight) {
|
|
48240
|
+
const n = x.length;
|
|
48241
|
+
let j = start;
|
|
48242
|
+
while (j + dir >= 0 && j + dir < n && x[j + dir] > refHeight) j += dir;
|
|
48243
|
+
const j2 = j + dir;
|
|
48244
|
+
if (j2 < 0 || j2 >= n) return j;
|
|
48245
|
+
const v1 = x[j];
|
|
48246
|
+
const v2 = x[j2];
|
|
48247
|
+
if (v1 === v2) return j;
|
|
48248
|
+
const frac = (v1 - refHeight) / (v1 - v2);
|
|
48249
|
+
return j + dir * frac;
|
|
48250
|
+
}
|
|
48251
|
+
function peakWidths(x, peaks, relHeight = 0.5) {
|
|
48252
|
+
return peaks.map((i) => {
|
|
48253
|
+
const prom = peakProminence(x, i);
|
|
48254
|
+
const refHeight = x[i] - relHeight * prom;
|
|
48255
|
+
const left = interpolateCrossing(x, i, -1, refHeight);
|
|
48256
|
+
const right = interpolateCrossing(x, i, 1, refHeight);
|
|
48257
|
+
return right - left;
|
|
48258
|
+
});
|
|
48259
|
+
}
|
|
48260
|
+
function segmentSpectra(sig, nperseg, noverlap, winType) {
|
|
48261
|
+
const step = nperseg - noverlap;
|
|
48262
|
+
if (step <= 0) throw new Error("csd/coherence: noverlap must be less than nperseg");
|
|
48263
|
+
const win = windowFunction(nperseg, winType);
|
|
48264
|
+
const winSum2 = win.reduce((s, w) => s + w * w, 0);
|
|
48265
|
+
const segments = [];
|
|
48266
|
+
for (let start = 0; start + nperseg <= sig.length; start += step) {
|
|
48267
|
+
const seg = new Array(nperseg);
|
|
48268
|
+
for (let i = 0; i < nperseg; i++) seg[i] = sig[start + i] * win[i];
|
|
48269
|
+
segments.push(fft2(seg).spectrum);
|
|
48270
|
+
}
|
|
48271
|
+
if (segments.length === 0) {
|
|
48272
|
+
throw new Error(`csd/coherence: signal length ${sig.length} shorter than nperseg ${nperseg}`);
|
|
48273
|
+
}
|
|
48274
|
+
return { segments, winSum2 };
|
|
48275
|
+
}
|
|
48276
|
+
function crossPower(x, y, opts) {
|
|
48277
|
+
const nperseg = opts?.nperseg ?? Math.min(256, x.length, y.length);
|
|
48278
|
+
const noverlap = opts?.noverlap ?? Math.floor(nperseg / 2);
|
|
48279
|
+
const winType = opts?.window ?? "hann";
|
|
48280
|
+
const fs = opts?.fs ?? 1;
|
|
48281
|
+
const { segments: Xs, winSum2 } = segmentSpectra(x, nperseg, noverlap, winType);
|
|
48282
|
+
const { segments: Ys } = segmentSpectra(y, nperseg, noverlap, winType);
|
|
48283
|
+
const nSeg = Math.min(Xs.length, Ys.length);
|
|
48284
|
+
const nfft = Xs[0].length;
|
|
48285
|
+
const half = Math.floor(nfft / 2) + 1;
|
|
48286
|
+
const re3 = new Array(half).fill(0);
|
|
48287
|
+
const im3 = new Array(half).fill(0);
|
|
48288
|
+
for (let s = 0; s < nSeg; s++) {
|
|
48289
|
+
for (let k = 0; k < half; k++) {
|
|
48290
|
+
const X = Xs[s][k];
|
|
48291
|
+
const Y = Ys[s][k];
|
|
48292
|
+
re3[k] += X.re * Y.re + X.im * Y.im;
|
|
48293
|
+
im3[k] += X.im * Y.re - X.re * Y.im;
|
|
48294
|
+
}
|
|
48295
|
+
}
|
|
48296
|
+
const scale = 1 / (fs * winSum2 * nSeg);
|
|
48297
|
+
for (let k = 0; k < half; k++) {
|
|
48298
|
+
re3[k] *= scale;
|
|
48299
|
+
im3[k] *= scale;
|
|
48300
|
+
}
|
|
48301
|
+
const frequencies = Array.from({ length: half }, (_, k) => k * fs / nfft);
|
|
48302
|
+
return { frequencies, re: re3, im: im3 };
|
|
48303
|
+
}
|
|
48304
|
+
function csd(x, y, opts) {
|
|
48305
|
+
const { frequencies, re: re3, im: im3 } = crossPower(x, y, opts);
|
|
48306
|
+
const power = re3.map((r, k) => Math.hypot(r, im3[k]));
|
|
48307
|
+
return { frequencies, power };
|
|
48308
|
+
}
|
|
48309
|
+
function coherence(x, y, opts) {
|
|
48310
|
+
const pxy = crossPower(x, y, opts);
|
|
48311
|
+
const pxx = crossPower(x, x, opts);
|
|
48312
|
+
const pyy = crossPower(y, y, opts);
|
|
48313
|
+
const coh = pxy.re.map((r, k) => {
|
|
48314
|
+
const num2 = r * r + pxy.im[k] * pxy.im[k];
|
|
48315
|
+
const den = pxx.re[k] * pyy.re[k];
|
|
48316
|
+
if (den <= 0) return 0;
|
|
48317
|
+
return Math.min(1, num2 / den);
|
|
48318
|
+
});
|
|
48319
|
+
return { frequencies: pxy.frequencies, coherence: coh };
|
|
48320
|
+
}
|
|
48321
|
+
function stft(x, opts) {
|
|
48322
|
+
const nperseg = opts?.nperseg ?? 256;
|
|
48323
|
+
const noverlap = opts?.noverlap ?? Math.floor(nperseg / 2);
|
|
48324
|
+
const winType = opts?.window ?? "hann";
|
|
48325
|
+
const step = nperseg - noverlap;
|
|
48326
|
+
if (step <= 0) throw new Error("stft: noverlap must be less than nperseg");
|
|
48327
|
+
const win = windowFunction(nperseg, winType);
|
|
48328
|
+
const re3 = [];
|
|
48329
|
+
const im3 = [];
|
|
48330
|
+
for (let start = 0; start + nperseg <= x.length; start += step) {
|
|
48331
|
+
const seg = new Array(nperseg);
|
|
48332
|
+
for (let i = 0; i < nperseg; i++) seg[i] = x[start + i] * win[i];
|
|
48333
|
+
const spectrum = fft2(seg).spectrum;
|
|
48334
|
+
re3.push(spectrum.map((c) => c.re));
|
|
48335
|
+
im3.push(spectrum.map((c) => c.im));
|
|
48336
|
+
}
|
|
48337
|
+
return { re: re3, im: im3 };
|
|
48338
|
+
}
|
|
48339
|
+
function istft(S, opts) {
|
|
48340
|
+
const nperseg = opts?.nperseg ?? 256;
|
|
48341
|
+
const noverlap = opts?.noverlap ?? Math.floor(nperseg / 2);
|
|
48342
|
+
const winType = opts?.window ?? "hann";
|
|
48343
|
+
const step = nperseg - noverlap;
|
|
48344
|
+
if (step <= 0) throw new Error("istft: noverlap must be less than nperseg");
|
|
48345
|
+
const win = windowFunction(nperseg, winType);
|
|
48346
|
+
const nFrames = S.re.length;
|
|
48347
|
+
const outLength = nFrames > 0 ? (nFrames - 1) * step + nperseg : 0;
|
|
48348
|
+
const output = new Array(outLength).fill(0);
|
|
48349
|
+
const normalizer = new Array(outLength).fill(0);
|
|
48350
|
+
for (let f = 0; f < nFrames; f++) {
|
|
48351
|
+
const spectrum = S.re[f].map((r, i) => ({ re: r, im: S.im[f][i] }));
|
|
48352
|
+
const frame = ifftReal(spectrum, nperseg);
|
|
48353
|
+
const start = f * step;
|
|
48354
|
+
for (let i = 0; i < nperseg; i++) {
|
|
48355
|
+
output[start + i] += frame[i] * win[i];
|
|
48356
|
+
normalizer[start + i] += win[i] * win[i];
|
|
48357
|
+
}
|
|
48358
|
+
}
|
|
48359
|
+
for (let i = 0; i < outLength; i++) {
|
|
48360
|
+
if (normalizer[i] > 1e-12) output[i] /= normalizer[i];
|
|
48361
|
+
}
|
|
48362
|
+
return output;
|
|
48363
|
+
}
|
|
48364
|
+
function decimate(x, q) {
|
|
48365
|
+
if (!Number.isInteger(q) || q < 1) {
|
|
48366
|
+
throw new Error("decimate: q must be a positive integer");
|
|
48367
|
+
}
|
|
48368
|
+
if (q === 1) return x.slice();
|
|
48369
|
+
const order = 4;
|
|
48370
|
+
const wn = Math.min(0.8 / q, 0.99);
|
|
48371
|
+
const { b, a } = butter(order, wn);
|
|
48372
|
+
const filtered = filtfilt(b, a, x);
|
|
48373
|
+
const out = [];
|
|
48374
|
+
for (let i = 0; i < filtered.length; i += q) out.push(filtered[i]);
|
|
48375
|
+
return out;
|
|
46969
48376
|
}
|
|
46970
48377
|
|
|
46971
48378
|
// src/geometry-extra.ts
|
|
@@ -47170,6 +48577,146 @@ function cochranQ(data) {
|
|
|
47170
48577
|
const pValue = 1 - chiSquaredCDF(Q2, dof);
|
|
47171
48578
|
return { Q: Q2, pValue, dof };
|
|
47172
48579
|
}
|
|
48580
|
+
|
|
48581
|
+
// src/special/hypergeometric.ts
|
|
48582
|
+
var MAX_TERMS = 500;
|
|
48583
|
+
var RELTOL = 1e-16;
|
|
48584
|
+
function pFq(a, b, z) {
|
|
48585
|
+
let sum3 = 1;
|
|
48586
|
+
let term = 1;
|
|
48587
|
+
for (let n = 0; n < MAX_TERMS; n++) {
|
|
48588
|
+
let ratio = z / (n + 1);
|
|
48589
|
+
for (const ai of a) ratio *= ai + n;
|
|
48590
|
+
for (const bj of b) ratio /= bj + n;
|
|
48591
|
+
term *= ratio;
|
|
48592
|
+
sum3 += term;
|
|
48593
|
+
if (Math.abs(term) < RELTOL * Math.abs(sum3)) break;
|
|
48594
|
+
}
|
|
48595
|
+
return sum3;
|
|
48596
|
+
}
|
|
48597
|
+
function hyp0f1(b, z) {
|
|
48598
|
+
return pFq([], [b], z);
|
|
48599
|
+
}
|
|
48600
|
+
function hyp1f1(a, b, z) {
|
|
48601
|
+
return pFq([a], [b], z);
|
|
48602
|
+
}
|
|
48603
|
+
function hyp2f1(a, b, c, z) {
|
|
48604
|
+
if (Math.abs(z) >= 1) {
|
|
48605
|
+
throw new Error("hyp2f1: |z| must be < 1 (analytic continuation not yet implemented)");
|
|
48606
|
+
}
|
|
48607
|
+
return pFq([a, b], [c], z);
|
|
48608
|
+
}
|
|
48609
|
+
|
|
48610
|
+
// src/special/polygamma-orthopoly.ts
|
|
48611
|
+
var SHIFT_THRESHOLD = 12;
|
|
48612
|
+
var BERNOULLI_EVEN = [1 / 6, -1 / 30, 1 / 42, -1 / 30];
|
|
48613
|
+
function factorial4(n) {
|
|
48614
|
+
let result = 1;
|
|
48615
|
+
for (let i = 2; i <= n; i++) result *= i;
|
|
48616
|
+
return result;
|
|
48617
|
+
}
|
|
48618
|
+
function polygamma(n, x) {
|
|
48619
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
48620
|
+
throw new Error("polygamma: n must be a nonnegative integer");
|
|
48621
|
+
}
|
|
48622
|
+
if (n === 0) {
|
|
48623
|
+
return digamma(x);
|
|
48624
|
+
}
|
|
48625
|
+
if (x <= 0 && Number.isInteger(x)) {
|
|
48626
|
+
return NaN;
|
|
48627
|
+
}
|
|
48628
|
+
const sign3 = n % 2 === 1 ? 1 : -1;
|
|
48629
|
+
const nFactorial = factorial4(n);
|
|
48630
|
+
let recurrenceSum = 0;
|
|
48631
|
+
let shifted = x;
|
|
48632
|
+
while (shifted < SHIFT_THRESHOLD) {
|
|
48633
|
+
recurrenceSum += 1 / Math.pow(shifted, n + 1);
|
|
48634
|
+
shifted += 1;
|
|
48635
|
+
}
|
|
48636
|
+
let bracket = factorial4(n - 1) / Math.pow(shifted, n) + nFactorial / (2 * Math.pow(shifted, n + 1));
|
|
48637
|
+
for (let j = 1; j <= BERNOULLI_EVEN.length; j++) {
|
|
48638
|
+
const twoJ = 2 * j;
|
|
48639
|
+
const term = BERNOULLI_EVEN[j - 1] * factorial4(twoJ + n - 1) / factorial4(twoJ) / Math.pow(shifted, twoJ + n);
|
|
48640
|
+
bracket += term;
|
|
48641
|
+
}
|
|
48642
|
+
return sign3 * (nFactorial * recurrenceSum + bracket);
|
|
48643
|
+
}
|
|
48644
|
+
function trigamma(x) {
|
|
48645
|
+
return polygamma(1, x);
|
|
48646
|
+
}
|
|
48647
|
+
function jacobiP(n, alpha, beta2, x) {
|
|
48648
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
48649
|
+
throw new Error("jacobiP: n must be a nonnegative integer");
|
|
48650
|
+
}
|
|
48651
|
+
if (n === 0) return 1;
|
|
48652
|
+
let pPrev = 1;
|
|
48653
|
+
let pCurr = alpha + 1 + (alpha + beta2 + 2) * (x - 1) / 2;
|
|
48654
|
+
if (n === 1) return pCurr;
|
|
48655
|
+
for (let k = 2; k <= n; k++) {
|
|
48656
|
+
const a1 = 2 * k * (k + alpha + beta2) * (2 * k + alpha + beta2 - 2);
|
|
48657
|
+
const a2 = (2 * k + alpha + beta2 - 1) * ((2 * k + alpha + beta2) * (2 * k + alpha + beta2 - 2) * x + alpha * alpha - beta2 * beta2);
|
|
48658
|
+
const a3 = 2 * (k + alpha - 1) * (k + beta2 - 1) * (2 * k + alpha + beta2);
|
|
48659
|
+
const pNext = (a2 * pCurr - a3 * pPrev) / a1;
|
|
48660
|
+
pPrev = pCurr;
|
|
48661
|
+
pCurr = pNext;
|
|
48662
|
+
}
|
|
48663
|
+
return pCurr;
|
|
48664
|
+
}
|
|
48665
|
+
function gegenbauerC(n, alpha, x) {
|
|
48666
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
48667
|
+
throw new Error("gegenbauerC: n must be a nonnegative integer");
|
|
48668
|
+
}
|
|
48669
|
+
if (n === 0) return 1;
|
|
48670
|
+
let cPrev = 1;
|
|
48671
|
+
let cCurr = 2 * alpha * x;
|
|
48672
|
+
if (n === 1) return cCurr;
|
|
48673
|
+
for (let k = 2; k <= n; k++) {
|
|
48674
|
+
const cNext = (2 * x * (k + alpha - 1) * cCurr - (k + 2 * alpha - 2) * cPrev) / k;
|
|
48675
|
+
cPrev = cCurr;
|
|
48676
|
+
cCurr = cNext;
|
|
48677
|
+
}
|
|
48678
|
+
return cCurr;
|
|
48679
|
+
}
|
|
48680
|
+
|
|
48681
|
+
// src/numeric/gauss-nodes.ts
|
|
48682
|
+
var NEWTON_MAX_ITERATIONS = 100;
|
|
48683
|
+
var NEWTON_TOLERANCE = 1e-15;
|
|
48684
|
+
function legendrePair(n, x) {
|
|
48685
|
+
let pPrev = 1;
|
|
48686
|
+
let pCurr = x;
|
|
48687
|
+
if (n === 0) return [1, x];
|
|
48688
|
+
for (let k = 2; k <= n; k++) {
|
|
48689
|
+
const pNext = ((2 * k - 1) * x * pCurr - (k - 1) * pPrev) / k;
|
|
48690
|
+
pPrev = pCurr;
|
|
48691
|
+
pCurr = pNext;
|
|
48692
|
+
}
|
|
48693
|
+
return [pCurr, pPrev];
|
|
48694
|
+
}
|
|
48695
|
+
function rootsLegendre(n) {
|
|
48696
|
+
if (!Number.isInteger(n) || n < 1) {
|
|
48697
|
+
throw new Error("rootsLegendre: n must be a positive integer");
|
|
48698
|
+
}
|
|
48699
|
+
const nodes = [];
|
|
48700
|
+
const weights = [];
|
|
48701
|
+
for (let i = 0; i < n; i++) {
|
|
48702
|
+
let x = Math.cos(Math.PI * (i + 0.75) / (n + 0.5));
|
|
48703
|
+
let pn = 0;
|
|
48704
|
+
let dpn = 0;
|
|
48705
|
+
for (let iter = 0; iter < NEWTON_MAX_ITERATIONS; iter++) {
|
|
48706
|
+
const [pCurr, pPrev] = legendrePair(n, x);
|
|
48707
|
+
pn = pCurr;
|
|
48708
|
+
dpn = n * (x * pCurr - pPrev) / (x * x - 1);
|
|
48709
|
+
const dx = pn / dpn;
|
|
48710
|
+
x -= dx;
|
|
48711
|
+
if (Math.abs(dx) < NEWTON_TOLERANCE) break;
|
|
48712
|
+
}
|
|
48713
|
+
nodes.push(x);
|
|
48714
|
+
weights.push(2 / ((1 - x * x) * dpn * dpn));
|
|
48715
|
+
}
|
|
48716
|
+
nodes.reverse();
|
|
48717
|
+
weights.reverse();
|
|
48718
|
+
return { nodes, weights };
|
|
48719
|
+
}
|
|
47173
48720
|
export {
|
|
47174
48721
|
ARRAY_WORKER_THRESHOLD,
|
|
47175
48722
|
CAS_BATCH_THRESHOLD,
|
|
@@ -47243,6 +48790,7 @@ export {
|
|
|
47243
48790
|
bfgs,
|
|
47244
48791
|
bigint,
|
|
47245
48792
|
bignumber,
|
|
48793
|
+
bilinear,
|
|
47246
48794
|
bin,
|
|
47247
48795
|
binomialDist,
|
|
47248
48796
|
binomialPMF,
|
|
@@ -47258,6 +48806,7 @@ export {
|
|
|
47258
48806
|
bootstrapCI,
|
|
47259
48807
|
bspline,
|
|
47260
48808
|
butter,
|
|
48809
|
+
buttord,
|
|
47261
48810
|
cancel,
|
|
47262
48811
|
carlsonRC,
|
|
47263
48812
|
carlsonRD,
|
|
@@ -47277,6 +48826,8 @@ export {
|
|
|
47277
48826
|
centroid,
|
|
47278
48827
|
chain,
|
|
47279
48828
|
characteristicPolynomial,
|
|
48829
|
+
cheby1,
|
|
48830
|
+
cheby2,
|
|
47280
48831
|
chebyshevApprox,
|
|
47281
48832
|
chebyshevDistance,
|
|
47282
48833
|
chebyshevFit,
|
|
@@ -47299,9 +48850,11 @@ export {
|
|
|
47299
48850
|
clone3 as clone,
|
|
47300
48851
|
cochranQ,
|
|
47301
48852
|
coefficientList,
|
|
48853
|
+
coherence,
|
|
47302
48854
|
collect,
|
|
47303
48855
|
column,
|
|
47304
48856
|
combinations,
|
|
48857
|
+
combinationsGen,
|
|
47305
48858
|
combinationsWithRep,
|
|
47306
48859
|
combine,
|
|
47307
48860
|
companion,
|
|
@@ -47319,6 +48872,7 @@ export {
|
|
|
47319
48872
|
config,
|
|
47320
48873
|
conj,
|
|
47321
48874
|
connectedComponents,
|
|
48875
|
+
continuedFraction,
|
|
47322
48876
|
convexHull,
|
|
47323
48877
|
convexHull3D,
|
|
47324
48878
|
convolve,
|
|
@@ -47348,6 +48902,7 @@ export {
|
|
|
47348
48902
|
csSymperm,
|
|
47349
48903
|
csc,
|
|
47350
48904
|
csch,
|
|
48905
|
+
csd,
|
|
47351
48906
|
cspline,
|
|
47352
48907
|
ctranspose,
|
|
47353
48908
|
cube,
|
|
@@ -47359,9 +48914,12 @@ export {
|
|
|
47359
48914
|
cumtrapz,
|
|
47360
48915
|
curl,
|
|
47361
48916
|
curvefit,
|
|
48917
|
+
cwt,
|
|
47362
48918
|
dagostinoTest,
|
|
47363
48919
|
dbscan,
|
|
47364
48920
|
dct,
|
|
48921
|
+
decimate,
|
|
48922
|
+
deconvolve,
|
|
47365
48923
|
deepEqual,
|
|
47366
48924
|
degree,
|
|
47367
48925
|
delaunayTriangulation,
|
|
@@ -47377,6 +48935,7 @@ export {
|
|
|
47377
48935
|
digamma,
|
|
47378
48936
|
directionalDerivative,
|
|
47379
48937
|
disableGpu,
|
|
48938
|
+
discreteLog,
|
|
47380
48939
|
discreteUniformDist,
|
|
47381
48940
|
discriminant,
|
|
47382
48941
|
distance,
|
|
@@ -47410,6 +48969,7 @@ export {
|
|
|
47410
48969
|
elementwiseChainGpuDispatch,
|
|
47411
48970
|
elementwiseChainReduceGpuDispatch,
|
|
47412
48971
|
eliminate,
|
|
48972
|
+
ellip,
|
|
47413
48973
|
ellipticE,
|
|
47414
48974
|
ellipticEIncomplete,
|
|
47415
48975
|
ellipticF,
|
|
@@ -47424,6 +48984,7 @@ export {
|
|
|
47424
48984
|
erfc,
|
|
47425
48985
|
erfcScalar,
|
|
47426
48986
|
erfi,
|
|
48987
|
+
eulerNumbers,
|
|
47427
48988
|
eulerPhi,
|
|
47428
48989
|
evaluate,
|
|
47429
48990
|
eventDetection,
|
|
@@ -47514,13 +49075,19 @@ export {
|
|
|
47514
49075
|
fft,
|
|
47515
49076
|
fft2d,
|
|
47516
49077
|
fftGpuDispatch,
|
|
49078
|
+
fftfreq,
|
|
49079
|
+
fftn,
|
|
49080
|
+
fftshift,
|
|
47517
49081
|
fibonacci,
|
|
47518
49082
|
filter2 as filter,
|
|
47519
49083
|
filtfilt,
|
|
49084
|
+
findPeaks,
|
|
47520
49085
|
findRoot,
|
|
47521
49086
|
fineStructure,
|
|
49087
|
+
firls,
|
|
47522
49088
|
firstRadiation,
|
|
47523
49089
|
firwin,
|
|
49090
|
+
firwinBandpass,
|
|
47524
49091
|
fisherExact,
|
|
47525
49092
|
fitDistribution,
|
|
47526
49093
|
fix,
|
|
@@ -47553,6 +49120,7 @@ export {
|
|
|
47553
49120
|
gaussQuad,
|
|
47554
49121
|
gaussianKDE,
|
|
47555
49122
|
gcd,
|
|
49123
|
+
gegenbauerC,
|
|
47556
49124
|
generalizedEig,
|
|
47557
49125
|
geometricPMF,
|
|
47558
49126
|
getAssumptions,
|
|
@@ -47592,12 +49160,17 @@ export {
|
|
|
47592
49160
|
histogram,
|
|
47593
49161
|
hmean,
|
|
47594
49162
|
hotellingT2,
|
|
49163
|
+
hyp0f1,
|
|
49164
|
+
hyp1f1,
|
|
49165
|
+
hyp2f1,
|
|
47595
49166
|
hypergeometricDist,
|
|
47596
49167
|
hypot,
|
|
47597
49168
|
idct,
|
|
47598
49169
|
identity,
|
|
47599
49170
|
idst,
|
|
49171
|
+
idwt,
|
|
47600
49172
|
ifft,
|
|
49173
|
+
ifftshift,
|
|
47601
49174
|
im,
|
|
47602
49175
|
implicitDiff,
|
|
47603
49176
|
indexFn as index,
|
|
@@ -47619,6 +49192,7 @@ export {
|
|
|
47619
49192
|
inverseLaplaceTransform,
|
|
47620
49193
|
invmod,
|
|
47621
49194
|
iqr,
|
|
49195
|
+
irfft,
|
|
47622
49196
|
isBounded,
|
|
47623
49197
|
isConnected,
|
|
47624
49198
|
isFinite2 as isFinite,
|
|
@@ -47631,6 +49205,11 @@ export {
|
|
|
47631
49205
|
isPositive,
|
|
47632
49206
|
isPrime,
|
|
47633
49207
|
isZero,
|
|
49208
|
+
istft,
|
|
49209
|
+
jacobiCN,
|
|
49210
|
+
jacobiDN,
|
|
49211
|
+
jacobiP,
|
|
49212
|
+
jacobiSN,
|
|
47634
49213
|
jacobiSymbol,
|
|
47635
49214
|
jacobian,
|
|
47636
49215
|
jarqueBera,
|
|
@@ -47650,6 +49229,7 @@ export {
|
|
|
47650
49229
|
kolmogorovSmirnov2Test,
|
|
47651
49230
|
kolmogorovSmirnovTest,
|
|
47652
49231
|
kron,
|
|
49232
|
+
kroneckerSymbol,
|
|
47653
49233
|
kruskalWallis,
|
|
47654
49234
|
kurtosis,
|
|
47655
49235
|
lagrangeInterp,
|
|
@@ -47756,6 +49336,7 @@ export {
|
|
|
47756
49336
|
multinomial,
|
|
47757
49337
|
multipleComparison,
|
|
47758
49338
|
multipleTest,
|
|
49339
|
+
multiplicativeOrder,
|
|
47759
49340
|
multiply,
|
|
47760
49341
|
multiplyScalar,
|
|
47761
49342
|
multivariateNormal,
|
|
@@ -47799,6 +49380,7 @@ export {
|
|
|
47799
49380
|
or,
|
|
47800
49381
|
orth,
|
|
47801
49382
|
outer,
|
|
49383
|
+
pFq,
|
|
47802
49384
|
pacf,
|
|
47803
49385
|
padeApproximant,
|
|
47804
49386
|
pageRank,
|
|
@@ -47836,10 +49418,12 @@ export {
|
|
|
47836
49418
|
partitions,
|
|
47837
49419
|
pchip,
|
|
47838
49420
|
pchipInterp,
|
|
49421
|
+
peakWidths,
|
|
47839
49422
|
pearsonr,
|
|
47840
49423
|
periodogram,
|
|
47841
49424
|
permutationTest,
|
|
47842
49425
|
permutations,
|
|
49426
|
+
permutationsGen,
|
|
47843
49427
|
pickRandom,
|
|
47844
49428
|
piecewise,
|
|
47845
49429
|
pinv,
|
|
@@ -47856,6 +49440,7 @@ export {
|
|
|
47856
49440
|
polyFit,
|
|
47857
49441
|
polyadd,
|
|
47858
49442
|
polyder,
|
|
49443
|
+
polygamma,
|
|
47859
49444
|
polygonArea,
|
|
47860
49445
|
polygonPerimeter,
|
|
47861
49446
|
polymul,
|
|
@@ -47871,6 +49456,7 @@ export {
|
|
|
47871
49456
|
prime,
|
|
47872
49457
|
primeFactors,
|
|
47873
49458
|
primePi,
|
|
49459
|
+
primitiveRoot,
|
|
47874
49460
|
principalComponentAnalysis,
|
|
47875
49461
|
print,
|
|
47876
49462
|
prod,
|
|
@@ -47904,6 +49490,7 @@ export {
|
|
|
47904
49490
|
reduce,
|
|
47905
49491
|
reducedPlanckConstant,
|
|
47906
49492
|
reflectVector,
|
|
49493
|
+
remez,
|
|
47907
49494
|
replacer,
|
|
47908
49495
|
resample,
|
|
47909
49496
|
resetGpuElementwise,
|
|
@@ -47914,12 +49501,15 @@ export {
|
|
|
47914
49501
|
resolve,
|
|
47915
49502
|
resultant,
|
|
47916
49503
|
reviver,
|
|
49504
|
+
rfft,
|
|
49505
|
+
rfftfreq,
|
|
47917
49506
|
ridge,
|
|
47918
49507
|
rightArithShift,
|
|
47919
49508
|
rightLogShift,
|
|
47920
49509
|
risingFactorial,
|
|
47921
49510
|
romberg,
|
|
47922
49511
|
root,
|
|
49512
|
+
rootsLegendre,
|
|
47923
49513
|
rotate,
|
|
47924
49514
|
rotateVector2D,
|
|
47925
49515
|
rotateVector3D,
|
|
@@ -47929,6 +49519,7 @@ export {
|
|
|
47929
49519
|
rowReduce,
|
|
47930
49520
|
rydberg,
|
|
47931
49521
|
sackurTetrode,
|
|
49522
|
+
savgol,
|
|
47932
49523
|
schur,
|
|
47933
49524
|
sec,
|
|
47934
49525
|
secant,
|
|
@@ -47977,6 +49568,7 @@ export {
|
|
|
47977
49568
|
solveODESystem,
|
|
47978
49569
|
solvePDE,
|
|
47979
49570
|
sort,
|
|
49571
|
+
sosfilt,
|
|
47980
49572
|
sparse,
|
|
47981
49573
|
spearman,
|
|
47982
49574
|
spearmanr,
|
|
@@ -47990,7 +49582,9 @@ export {
|
|
|
47990
49582
|
squeeze2 as squeeze,
|
|
47991
49583
|
std,
|
|
47992
49584
|
stefanBoltzmann,
|
|
49585
|
+
stft,
|
|
47993
49586
|
stiffODESolver,
|
|
49587
|
+
stirlingS1,
|
|
47994
49588
|
stirlingS2,
|
|
47995
49589
|
string,
|
|
47996
49590
|
stronglyConnectedComponents,
|
|
@@ -48040,6 +49634,7 @@ export {
|
|
|
48040
49634
|
trigExpand,
|
|
48041
49635
|
trigReduce,
|
|
48042
49636
|
trigToExp,
|
|
49637
|
+
trigamma,
|
|
48043
49638
|
tril,
|
|
48044
49639
|
trimmedMean,
|
|
48045
49640
|
triu,
|
|
@@ -48078,10 +49673,13 @@ export {
|
|
|
48078
49673
|
variation,
|
|
48079
49674
|
vonMisesPDF,
|
|
48080
49675
|
voronoiDiagram,
|
|
49676
|
+
wavedec,
|
|
49677
|
+
waverec,
|
|
48081
49678
|
weakMixingAngle,
|
|
48082
49679
|
weibullDist,
|
|
48083
49680
|
welchPSD,
|
|
48084
49681
|
wienDisplacement,
|
|
49682
|
+
wiener,
|
|
48085
49683
|
wilcoxon,
|
|
48086
49684
|
windowFunction,
|
|
48087
49685
|
xgcd,
|
|
@@ -48089,6 +49687,7 @@ export {
|
|
|
48089
49687
|
zTransform,
|
|
48090
49688
|
zeros,
|
|
48091
49689
|
zeta,
|
|
49690
|
+
zpk2sos,
|
|
48092
49691
|
zpk2tf,
|
|
48093
49692
|
zscore
|
|
48094
49693
|
};
|