@danielsimonjr/mathts-functions 0.54.0 → 0.56.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 +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +603 -331
- package/dist/numeric/solveDDE.d.ts +107 -0
- package/dist/numeric/solveDDE.d.ts.map +1 -0
- package/dist/special/mathieu.d.ts +67 -0
- package/dist/special/mathieu.d.ts.map +1 -0
- package/dist/typed/numeric.d.ts +1 -0
- package/dist/typed/numeric.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -440,6 +440,7 @@ __export(typed_exports, {
|
|
|
440
440
|
smallerEq: () => smallerEq,
|
|
441
441
|
solveBVP: () => solveBVP,
|
|
442
442
|
solveDAE: () => solveDAE,
|
|
443
|
+
solveDDE: () => solveDDE,
|
|
443
444
|
solveODESystem: () => solveODESystem,
|
|
444
445
|
solvePDE: () => solvePDE,
|
|
445
446
|
solveParabolicPDE: () => solveParabolicPDE,
|
|
@@ -3917,32 +3918,32 @@ function nextPowerOf2(n) {
|
|
|
3917
3918
|
return Math.pow(2, Math.ceil(Math.log2(n)));
|
|
3918
3919
|
}
|
|
3919
3920
|
async function fourStepFFT(real, imag, inverse) {
|
|
3920
|
-
const
|
|
3921
|
-
if (
|
|
3921
|
+
const N2 = real.length;
|
|
3922
|
+
if (N2 < 4 || !isPowerOf22(N2)) {
|
|
3922
3923
|
return fftCoreFloat64(real, imag, inverse);
|
|
3923
3924
|
}
|
|
3924
|
-
const bits = Math.round(Math.log2(
|
|
3925
|
+
const bits = Math.round(Math.log2(N2));
|
|
3925
3926
|
const bits1 = bits >> 1;
|
|
3926
3927
|
const N1 = 1 << bits1;
|
|
3927
|
-
const
|
|
3928
|
+
const N22 = N2 / N1;
|
|
3928
3929
|
const sign3 = inverse ? 1 : -1;
|
|
3929
|
-
const aReal = new Float64Array(
|
|
3930
|
-
const aImag = new Float64Array(
|
|
3931
|
-
for (let n26 = 0; n26 <
|
|
3930
|
+
const aReal = new Float64Array(N22 * N1);
|
|
3931
|
+
const aImag = new Float64Array(N22 * N1);
|
|
3932
|
+
for (let n26 = 0; n26 < N22; n26++) {
|
|
3932
3933
|
const base = n26 * N1;
|
|
3933
3934
|
for (let n16 = 0; n16 < N1; n16++) {
|
|
3934
|
-
const src =
|
|
3935
|
+
const src = N22 * n16 + n26;
|
|
3935
3936
|
aReal[base + n16] = real[src];
|
|
3936
3937
|
aImag[base + n16] = imag[src];
|
|
3937
3938
|
}
|
|
3938
3939
|
}
|
|
3939
|
-
const stepA = await computePool4.fftBatch(aReal, aImag,
|
|
3940
|
+
const stepA = await computePool4.fftBatch(aReal, aImag, N22, N1, inverse);
|
|
3940
3941
|
const aOutReal = stepA.result.real;
|
|
3941
3942
|
const aOutImag = stepA.result.imag;
|
|
3942
|
-
const cReal = new Float64Array(N1 *
|
|
3943
|
-
const cImag = new Float64Array(N1 *
|
|
3944
|
-
const twN = sign3 * 2 * Math.PI /
|
|
3945
|
-
for (let n26 = 0; n26 <
|
|
3943
|
+
const cReal = new Float64Array(N1 * N22);
|
|
3944
|
+
const cImag = new Float64Array(N1 * N22);
|
|
3945
|
+
const twN = sign3 * 2 * Math.PI / N2;
|
|
3946
|
+
for (let n26 = 0; n26 < N22; n26++) {
|
|
3946
3947
|
const aBase = n26 * N1;
|
|
3947
3948
|
for (let k1 = 0; k1 < N1; k1++) {
|
|
3948
3949
|
const ar = aOutReal[aBase + k1];
|
|
@@ -3950,19 +3951,19 @@ async function fourStepFFT(real, imag, inverse) {
|
|
|
3950
3951
|
const ang = twN * n26 * k1;
|
|
3951
3952
|
const wr = Math.cos(ang);
|
|
3952
3953
|
const wi = Math.sin(ang);
|
|
3953
|
-
const dst2 = k1 *
|
|
3954
|
+
const dst2 = k1 * N22 + n26;
|
|
3954
3955
|
cReal[dst2] = ar * wr - ai * wi;
|
|
3955
3956
|
cImag[dst2] = ar * wi + ai * wr;
|
|
3956
3957
|
}
|
|
3957
3958
|
}
|
|
3958
|
-
const stepC = await computePool4.fftBatch(cReal, cImag, N1,
|
|
3959
|
+
const stepC = await computePool4.fftBatch(cReal, cImag, N1, N22, inverse);
|
|
3959
3960
|
const cOutReal = stepC.result.real;
|
|
3960
3961
|
const cOutImag = stepC.result.imag;
|
|
3961
|
-
const outReal = new Float64Array(
|
|
3962
|
-
const outImag = new Float64Array(
|
|
3962
|
+
const outReal = new Float64Array(N2);
|
|
3963
|
+
const outImag = new Float64Array(N2);
|
|
3963
3964
|
for (let k1 = 0; k1 < N1; k1++) {
|
|
3964
|
-
const cBase = k1 *
|
|
3965
|
-
for (let k2 = 0; k2 <
|
|
3965
|
+
const cBase = k1 * N22;
|
|
3966
|
+
for (let k2 = 0; k2 < N22; k2++) {
|
|
3966
3967
|
const dst2 = N1 * k2 + k1;
|
|
3967
3968
|
outReal[dst2] = cOutReal[cBase + k2];
|
|
3968
3969
|
outImag[dst2] = cOutImag[cBase + k2];
|
|
@@ -4188,15 +4189,15 @@ function unwrapPhase(phase) {
|
|
|
4188
4189
|
return result;
|
|
4189
4190
|
}
|
|
4190
4191
|
function dct(x) {
|
|
4191
|
-
const
|
|
4192
|
-
if (
|
|
4192
|
+
const N2 = x.length;
|
|
4193
|
+
if (N2 >= WASM_THRESHOLD) {
|
|
4193
4194
|
const wasm = wasmLoader.getModule();
|
|
4194
4195
|
if (wasm) {
|
|
4195
4196
|
try {
|
|
4196
4197
|
const inAlloc = wasmLoader.allocateFloat64Array(x);
|
|
4197
|
-
const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
4198
|
+
const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
|
|
4198
4199
|
try {
|
|
4199
|
-
wasm.dct_wasm(inAlloc.ptr, outAlloc.ptr,
|
|
4200
|
+
wasm.dct_wasm(inAlloc.ptr, outAlloc.ptr, N2);
|
|
4200
4201
|
return Array.from(outAlloc.array);
|
|
4201
4202
|
} finally {
|
|
4202
4203
|
wasmLoader.free(inAlloc.ptr);
|
|
@@ -4206,26 +4207,26 @@ function dct(x) {
|
|
|
4206
4207
|
}
|
|
4207
4208
|
}
|
|
4208
4209
|
}
|
|
4209
|
-
const result = new Array(
|
|
4210
|
-
for (let k = 0; k <
|
|
4210
|
+
const result = new Array(N2);
|
|
4211
|
+
for (let k = 0; k < N2; k++) {
|
|
4211
4212
|
let sum3 = 0;
|
|
4212
|
-
for (let n = 0; n <
|
|
4213
|
-
sum3 += x[n] * Math.cos(Math.PI /
|
|
4213
|
+
for (let n = 0; n < N2; n++) {
|
|
4214
|
+
sum3 += x[n] * Math.cos(Math.PI / N2 * (n + 0.5) * k);
|
|
4214
4215
|
}
|
|
4215
|
-
result[k] = sum3 * (k === 0 ? Math.sqrt(1 /
|
|
4216
|
+
result[k] = sum3 * (k === 0 ? Math.sqrt(1 / N2) : Math.sqrt(2 / N2));
|
|
4216
4217
|
}
|
|
4217
4218
|
return result;
|
|
4218
4219
|
}
|
|
4219
4220
|
function idct(X) {
|
|
4220
|
-
const
|
|
4221
|
-
if (
|
|
4221
|
+
const N2 = X.length;
|
|
4222
|
+
if (N2 >= WASM_THRESHOLD) {
|
|
4222
4223
|
const wasm = wasmLoader.getModule();
|
|
4223
4224
|
if (wasm) {
|
|
4224
4225
|
try {
|
|
4225
4226
|
const inAlloc = wasmLoader.allocateFloat64Array(X);
|
|
4226
|
-
const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
4227
|
+
const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
|
|
4227
4228
|
try {
|
|
4228
|
-
wasm.idct_wasm(inAlloc.ptr, outAlloc.ptr,
|
|
4229
|
+
wasm.idct_wasm(inAlloc.ptr, outAlloc.ptr, N2);
|
|
4229
4230
|
return Array.from(outAlloc.array);
|
|
4230
4231
|
} finally {
|
|
4231
4232
|
wasmLoader.free(inAlloc.ptr);
|
|
@@ -4235,26 +4236,26 @@ function idct(X) {
|
|
|
4235
4236
|
}
|
|
4236
4237
|
}
|
|
4237
4238
|
}
|
|
4238
|
-
const result = new Array(
|
|
4239
|
-
for (let n = 0; n <
|
|
4240
|
-
let sum3 = X[0] * Math.sqrt(1 /
|
|
4241
|
-
for (let k = 1; k <
|
|
4242
|
-
sum3 += X[k] * Math.sqrt(2 /
|
|
4239
|
+
const result = new Array(N2);
|
|
4240
|
+
for (let n = 0; n < N2; n++) {
|
|
4241
|
+
let sum3 = X[0] * Math.sqrt(1 / N2);
|
|
4242
|
+
for (let k = 1; k < N2; k++) {
|
|
4243
|
+
sum3 += X[k] * Math.sqrt(2 / N2) * Math.cos(Math.PI / N2 * (n + 0.5) * k);
|
|
4243
4244
|
}
|
|
4244
4245
|
result[n] = sum3;
|
|
4245
4246
|
}
|
|
4246
4247
|
return result;
|
|
4247
4248
|
}
|
|
4248
4249
|
function dst(x) {
|
|
4249
|
-
const
|
|
4250
|
-
if (
|
|
4250
|
+
const N2 = x.length;
|
|
4251
|
+
if (N2 >= WASM_THRESHOLD) {
|
|
4251
4252
|
const wasm = wasmLoader.getModule();
|
|
4252
4253
|
if (wasm) {
|
|
4253
4254
|
try {
|
|
4254
4255
|
const inAlloc = wasmLoader.allocateFloat64Array(x);
|
|
4255
|
-
const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
4256
|
+
const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
|
|
4256
4257
|
try {
|
|
4257
|
-
wasm.dst_wasm(inAlloc.ptr, outAlloc.ptr,
|
|
4258
|
+
wasm.dst_wasm(inAlloc.ptr, outAlloc.ptr, N2);
|
|
4258
4259
|
return Array.from(outAlloc.array);
|
|
4259
4260
|
} finally {
|
|
4260
4261
|
wasmLoader.free(inAlloc.ptr);
|
|
@@ -4264,26 +4265,26 @@ function dst(x) {
|
|
|
4264
4265
|
}
|
|
4265
4266
|
}
|
|
4266
4267
|
}
|
|
4267
|
-
const result = new Array(
|
|
4268
|
-
for (let k = 0; k <
|
|
4268
|
+
const result = new Array(N2);
|
|
4269
|
+
for (let k = 0; k < N2; k++) {
|
|
4269
4270
|
let sum3 = 0;
|
|
4270
|
-
for (let n = 0; n <
|
|
4271
|
-
sum3 += x[n] * Math.sin(Math.PI /
|
|
4271
|
+
for (let n = 0; n < N2; n++) {
|
|
4272
|
+
sum3 += x[n] * Math.sin(Math.PI / N2 * (n + 0.5) * (k + 1));
|
|
4272
4273
|
}
|
|
4273
|
-
result[k] = sum3 * Math.sqrt(2 /
|
|
4274
|
+
result[k] = sum3 * Math.sqrt(2 / N2);
|
|
4274
4275
|
}
|
|
4275
4276
|
return result;
|
|
4276
4277
|
}
|
|
4277
4278
|
function idst(X) {
|
|
4278
|
-
const
|
|
4279
|
-
if (
|
|
4279
|
+
const N2 = X.length;
|
|
4280
|
+
if (N2 >= WASM_THRESHOLD) {
|
|
4280
4281
|
const wasm = wasmLoader.getModule();
|
|
4281
4282
|
if (wasm) {
|
|
4282
4283
|
try {
|
|
4283
4284
|
const inAlloc = wasmLoader.allocateFloat64Array(X);
|
|
4284
|
-
const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
4285
|
+
const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
|
|
4285
4286
|
try {
|
|
4286
|
-
wasm.idst_wasm(inAlloc.ptr, outAlloc.ptr,
|
|
4287
|
+
wasm.idst_wasm(inAlloc.ptr, outAlloc.ptr, N2);
|
|
4287
4288
|
return Array.from(outAlloc.array);
|
|
4288
4289
|
} finally {
|
|
4289
4290
|
wasmLoader.free(inAlloc.ptr);
|
|
@@ -4293,12 +4294,12 @@ function idst(X) {
|
|
|
4293
4294
|
}
|
|
4294
4295
|
}
|
|
4295
4296
|
}
|
|
4296
|
-
const result = new Array(
|
|
4297
|
-
for (let n = 0; n <
|
|
4297
|
+
const result = new Array(N2);
|
|
4298
|
+
for (let n = 0; n < N2; n++) {
|
|
4298
4299
|
let sum3 = 0;
|
|
4299
|
-
for (let k = 0; k <
|
|
4300
|
-
const factor2 = k ===
|
|
4301
|
-
sum3 += X[k] * factor2 * Math.sin(Math.PI /
|
|
4300
|
+
for (let k = 0; k < N2; k++) {
|
|
4301
|
+
const factor2 = k === N2 - 1 ? Math.sqrt(1 / N2) : Math.sqrt(2 / N2);
|
|
4302
|
+
sum3 += X[k] * factor2 * Math.sin(Math.PI / N2 * (n + 0.5) * (k + 1));
|
|
4302
4303
|
}
|
|
4303
4304
|
result[n] = sum3;
|
|
4304
4305
|
}
|
|
@@ -4445,20 +4446,20 @@ function invFourier(F, omega, t) {
|
|
|
4445
4446
|
}
|
|
4446
4447
|
function hilbertTransform(x) {
|
|
4447
4448
|
const n = x.length;
|
|
4448
|
-
const
|
|
4449
|
-
if (
|
|
4449
|
+
const N2 = nextPowerOf2(n);
|
|
4450
|
+
if (N2 >= WASM_THRESHOLD) {
|
|
4450
4451
|
const wasm = wasmLoader.getModule();
|
|
4451
4452
|
if (wasm) {
|
|
4452
4453
|
try {
|
|
4453
|
-
const paddedInput = new Array(
|
|
4454
|
+
const paddedInput = new Array(N2).fill(0);
|
|
4454
4455
|
for (let i = 0; i < n; i++) paddedInput[i] = x[i];
|
|
4455
|
-
const zeros4 = new Array(
|
|
4456
|
+
const zeros4 = new Array(N2).fill(0);
|
|
4456
4457
|
const inReAlloc = wasmLoader.allocateFloat64Array(paddedInput);
|
|
4457
4458
|
const inImAlloc = wasmLoader.allocateFloat64Array(zeros4);
|
|
4458
|
-
const outReAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
4459
|
-
const outImAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
4459
|
+
const outReAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
|
|
4460
|
+
const outImAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
|
|
4460
4461
|
try {
|
|
4461
|
-
wasm.hilbert_wasm(inReAlloc.ptr, inImAlloc.ptr, outReAlloc.ptr, outImAlloc.ptr,
|
|
4462
|
+
wasm.hilbert_wasm(inReAlloc.ptr, inImAlloc.ptr, outReAlloc.ptr, outImAlloc.ptr, N2);
|
|
4462
4463
|
return Array.from(outImAlloc.array.slice(0, n));
|
|
4463
4464
|
} finally {
|
|
4464
4465
|
wasmLoader.free(inReAlloc.ptr);
|
|
@@ -4470,16 +4471,16 @@ function hilbertTransform(x) {
|
|
|
4470
4471
|
}
|
|
4471
4472
|
}
|
|
4472
4473
|
}
|
|
4473
|
-
const real = new Float64Array(
|
|
4474
|
-
const imag = new Float64Array(
|
|
4474
|
+
const real = new Float64Array(N2);
|
|
4475
|
+
const imag = new Float64Array(N2);
|
|
4475
4476
|
for (let i = 0; i < n; i++) real[i] = x[i];
|
|
4476
4477
|
const spectrum = fftCoreFloat64(real, imag, false);
|
|
4477
|
-
const hReal = new Float64Array(
|
|
4478
|
-
const hImag = new Float64Array(
|
|
4478
|
+
const hReal = new Float64Array(N2);
|
|
4479
|
+
const hImag = new Float64Array(N2);
|
|
4479
4480
|
hReal[0] = spectrum.real[0];
|
|
4480
4481
|
hImag[0] = spectrum.imag[0];
|
|
4481
|
-
if (
|
|
4482
|
-
const half =
|
|
4482
|
+
if (N2 > 1) {
|
|
4483
|
+
const half = N2 / 2;
|
|
4483
4484
|
for (let i = 1; i < half; i++) {
|
|
4484
4485
|
hReal[i] = 2 * spectrum.real[i];
|
|
4485
4486
|
hImag[i] = 2 * spectrum.imag[i];
|
|
@@ -10399,10 +10400,10 @@ function cancel(expr) {
|
|
|
10399
10400
|
if (dens.length > 0) {
|
|
10400
10401
|
const numStr = nums.length ? nums.join("*") : "1";
|
|
10401
10402
|
const denStr = dens.join("*");
|
|
10402
|
-
const
|
|
10403
|
+
const N2 = polyToDense(polyFromExpression(numStr, [v]));
|
|
10403
10404
|
const D = polyToDense(polyFromExpression(denStr, [v]));
|
|
10404
|
-
if (
|
|
10405
|
-
const Nint =
|
|
10405
|
+
if (N2.every(isNearInt) && D.every(isNearInt)) {
|
|
10406
|
+
const Nint = N2.map((c) => Math.round(c));
|
|
10406
10407
|
const Dint = D.map((c) => Math.round(c));
|
|
10407
10408
|
const g = polynomialGCD(Nint, Dint);
|
|
10408
10409
|
if (degree(g) >= 1) {
|
|
@@ -10500,10 +10501,10 @@ function apart(expr) {
|
|
|
10500
10501
|
if (dens.length > 0) {
|
|
10501
10502
|
const numStr = nums.length ? nums.join("*") : "1";
|
|
10502
10503
|
const denStr = dens.join("*");
|
|
10503
|
-
const
|
|
10504
|
+
const N2 = polyToDense(polyFromExpression(numStr, [v]));
|
|
10504
10505
|
const D = polyToDense(polyFromExpression(denStr, [v]));
|
|
10505
|
-
if (degree(D) >= 1 &&
|
|
10506
|
-
let Nint =
|
|
10506
|
+
if (degree(D) >= 1 && N2.every(isNearInt) && D.every(isNearInt)) {
|
|
10507
|
+
let Nint = N2.map((c) => Math.round(c));
|
|
10507
10508
|
const Dint = D.map((c) => Math.round(c));
|
|
10508
10509
|
let quotientPrefix = "";
|
|
10509
10510
|
if (degree(Nint) >= degree(Dint)) {
|
|
@@ -13507,6 +13508,172 @@ function solveDAE(f, g, tspan, y0, z0, options = {}) {
|
|
|
13507
13508
|
};
|
|
13508
13509
|
}
|
|
13509
13510
|
|
|
13511
|
+
// src/numeric/solveDDE.ts
|
|
13512
|
+
function _arr2(v) {
|
|
13513
|
+
return Array.isArray(v) ? v.slice() : [v];
|
|
13514
|
+
}
|
|
13515
|
+
function _hermite2(ta, tb, ya, yb, fa, fb, t) {
|
|
13516
|
+
const h = tb - ta;
|
|
13517
|
+
const theta = h === 0 ? 0 : (t - ta) / h;
|
|
13518
|
+
const th2 = theta * theta;
|
|
13519
|
+
const th3 = th2 * theta;
|
|
13520
|
+
const h00 = 2 * th3 - 3 * th2 + 1;
|
|
13521
|
+
const h10 = th3 - 2 * th2 + theta;
|
|
13522
|
+
const h01 = -2 * th3 + 3 * th2;
|
|
13523
|
+
const h11 = th3 - th2;
|
|
13524
|
+
return ya.map((_, i) => h00 * ya[i] + h10 * h * fa[i] + h01 * yb[i] + h11 * h * fb[i]);
|
|
13525
|
+
}
|
|
13526
|
+
function _wrms2(v, scale4) {
|
|
13527
|
+
let s = 0;
|
|
13528
|
+
for (let i = 0; i < v.length; i++) {
|
|
13529
|
+
const q = v[i] / scale4[i];
|
|
13530
|
+
s += q * q;
|
|
13531
|
+
}
|
|
13532
|
+
return Math.sqrt(s / v.length);
|
|
13533
|
+
}
|
|
13534
|
+
var _BS23_B = [2 / 9, 1 / 3, 4 / 9, 0];
|
|
13535
|
+
var _BS23_BP = [7 / 24, 1 / 4, 1 / 3, 1 / 8];
|
|
13536
|
+
var _BS23_DB = _BS23_B.map((b, i) => b - _BS23_BP[i]);
|
|
13537
|
+
function solveDDE(f, tspan, history, delays, options = {}) {
|
|
13538
|
+
const t0 = tspan[0];
|
|
13539
|
+
const tf = tspan[1];
|
|
13540
|
+
if (!(typeof t0 === "number" && typeof tf === "number")) {
|
|
13541
|
+
throw new Error("solveDDE: tspan must be [t0, T] numbers");
|
|
13542
|
+
}
|
|
13543
|
+
if (!(tf > t0)) {
|
|
13544
|
+
throw new Error("solveDDE: require T > t0 (forward integration)");
|
|
13545
|
+
}
|
|
13546
|
+
if (!Array.isArray(delays) || delays.length === 0) {
|
|
13547
|
+
throw new Error("solveDDE: at least one delay \u03C4 must be given");
|
|
13548
|
+
}
|
|
13549
|
+
if (!delays.every((d) => typeof d === "number" && d > 0)) {
|
|
13550
|
+
throw new Error("solveDDE: every delay \u03C4 must be a positive number");
|
|
13551
|
+
}
|
|
13552
|
+
const histFn = typeof history === "function" ? (s) => _arr2(history(s)) : () => _arr2(history);
|
|
13553
|
+
const y0raw = typeof history === "function" ? history(t0) : history;
|
|
13554
|
+
const yScalar = !Array.isArray(y0raw);
|
|
13555
|
+
const y0 = _arr2(y0raw);
|
|
13556
|
+
const n = y0.length;
|
|
13557
|
+
const minTau = Math.min(...delays);
|
|
13558
|
+
const rtol = options.tol ?? 1e-6;
|
|
13559
|
+
const atol = options.atol ?? rtol * 1e-3;
|
|
13560
|
+
const maxIter = options.maxIter ?? 1e5;
|
|
13561
|
+
const maxStep = options.maxStep ?? Infinity;
|
|
13562
|
+
const minStepOpt = options.minStep ?? 0;
|
|
13563
|
+
const Ts = [t0];
|
|
13564
|
+
const Ys = [y0.slice()];
|
|
13565
|
+
const Fs = [];
|
|
13566
|
+
function _locate(s) {
|
|
13567
|
+
let lo = 0;
|
|
13568
|
+
let hi = Ts.length - 1;
|
|
13569
|
+
if (s <= Ts[0]) return 0;
|
|
13570
|
+
if (s >= Ts[hi]) return hi - 1;
|
|
13571
|
+
while (hi - lo > 1) {
|
|
13572
|
+
const mid = lo + hi >> 1;
|
|
13573
|
+
if (Ts[mid] <= s) lo = mid;
|
|
13574
|
+
else hi = mid;
|
|
13575
|
+
}
|
|
13576
|
+
return lo;
|
|
13577
|
+
}
|
|
13578
|
+
function delayedState(s) {
|
|
13579
|
+
if (s <= t0) return histFn(s);
|
|
13580
|
+
const i = _locate(s);
|
|
13581
|
+
return _hermite2(Ts[i], Ts[i + 1], Ys[i], Ys[i + 1], Fs[i], Fs[i + 1], s);
|
|
13582
|
+
}
|
|
13583
|
+
function fEval(t2, y2) {
|
|
13584
|
+
const yd = delays.map((tau2) => delayedState(t2 - tau2));
|
|
13585
|
+
const r = f(t2, y2, yd);
|
|
13586
|
+
const out = Array.isArray(r) ? r : [r];
|
|
13587
|
+
if (out.length !== n) {
|
|
13588
|
+
throw new Error(
|
|
13589
|
+
`solveDDE: f must return ${n} value(s) (matching the state); got ${out.length}`
|
|
13590
|
+
);
|
|
13591
|
+
}
|
|
13592
|
+
return out;
|
|
13593
|
+
}
|
|
13594
|
+
function nextBreakpoint(t2) {
|
|
13595
|
+
let best = Infinity;
|
|
13596
|
+
for (const tau2 of delays) {
|
|
13597
|
+
let m = Math.floor((t2 - t0) / tau2) + 1;
|
|
13598
|
+
let cand = t0 + m * tau2;
|
|
13599
|
+
while (cand <= t2 + 1e-12 * Math.max(1, Math.abs(t2))) {
|
|
13600
|
+
m += 1;
|
|
13601
|
+
cand = t0 + m * tau2;
|
|
13602
|
+
}
|
|
13603
|
+
if (cand < best) best = cand;
|
|
13604
|
+
}
|
|
13605
|
+
return best;
|
|
13606
|
+
}
|
|
13607
|
+
Fs[0] = fEval(t0, y0);
|
|
13608
|
+
const rms = (v) => Math.sqrt(v.reduce((a, x) => a + x * x, 0) / Math.max(1, v.length));
|
|
13609
|
+
let h;
|
|
13610
|
+
if (options.firstStep !== void 0) {
|
|
13611
|
+
h = Math.abs(options.firstStep);
|
|
13612
|
+
} else {
|
|
13613
|
+
const d0 = rms(y0);
|
|
13614
|
+
const d1 = rms(Fs[0]);
|
|
13615
|
+
h = d0 < 1e-5 || d1 < 1e-5 ? 1e-6 : 0.01 * (d0 / d1);
|
|
13616
|
+
}
|
|
13617
|
+
h = Math.min(h, minTau, maxStep, tf - t0);
|
|
13618
|
+
let t = t0;
|
|
13619
|
+
let y = y0.slice();
|
|
13620
|
+
let f0 = Fs[0];
|
|
13621
|
+
let iter = 0;
|
|
13622
|
+
while (t < tf && iter < maxIter) {
|
|
13623
|
+
iter += 1;
|
|
13624
|
+
const nb = nextBreakpoint(t);
|
|
13625
|
+
let hmax = Math.min(minTau, maxStep, tf - t);
|
|
13626
|
+
if (nb < tf) hmax = Math.min(hmax, nb - t);
|
|
13627
|
+
if (h > hmax) h = hmax;
|
|
13628
|
+
const minStep = Math.max(minStepOpt, 1e-13 * Math.max(1, Math.abs(t)));
|
|
13629
|
+
if (h < minStep) h = Math.min(minStep, hmax);
|
|
13630
|
+
const k1 = f0;
|
|
13631
|
+
const k2 = fEval(
|
|
13632
|
+
t + 0.5 * h,
|
|
13633
|
+
y.map((yi, i) => yi + 0.5 * h * k1[i])
|
|
13634
|
+
);
|
|
13635
|
+
const k3 = fEval(
|
|
13636
|
+
t + 0.75 * h,
|
|
13637
|
+
y.map((yi, i) => yi + 0.75 * h * k2[i])
|
|
13638
|
+
);
|
|
13639
|
+
const yNew = y.map(
|
|
13640
|
+
(yi, i) => yi + h * (_BS23_B[0] * k1[i] + _BS23_B[1] * k2[i] + _BS23_B[2] * k3[i])
|
|
13641
|
+
);
|
|
13642
|
+
const k4 = fEval(t + h, yNew);
|
|
13643
|
+
const scale4 = y.map((yi, i) => atol + rtol * Math.max(Math.abs(yi), Math.abs(yNew[i])));
|
|
13644
|
+
const err = yNew.map(
|
|
13645
|
+
(_, i) => h * (_BS23_DB[0] * k1[i] + _BS23_DB[1] * k2[i] + _BS23_DB[2] * k3[i] + _BS23_DB[3] * k4[i])
|
|
13646
|
+
);
|
|
13647
|
+
const errNorm = _wrms2(err, scale4);
|
|
13648
|
+
if (errNorm <= 1 || h <= minStep) {
|
|
13649
|
+
t += h;
|
|
13650
|
+
y = yNew;
|
|
13651
|
+
f0 = k4;
|
|
13652
|
+
Ts.push(t);
|
|
13653
|
+
Ys.push(y.slice());
|
|
13654
|
+
Fs.push(f0);
|
|
13655
|
+
}
|
|
13656
|
+
const factor2 = errNorm === 0 ? 5 : 0.9 * Math.pow(errNorm, -1 / 3);
|
|
13657
|
+
h *= Math.min(5, Math.max(0.2, factor2));
|
|
13658
|
+
}
|
|
13659
|
+
if (iter >= maxIter) {
|
|
13660
|
+
throw new Error(
|
|
13661
|
+
"solveDDE: maximum number of steps reached \u2014 try loosening tol or raising maxIter"
|
|
13662
|
+
);
|
|
13663
|
+
}
|
|
13664
|
+
const yInterp = (tq) => {
|
|
13665
|
+
const s = tq <= t0 ? t0 : tq >= t ? t : tq;
|
|
13666
|
+
const i = _locate(s);
|
|
13667
|
+
const val = _hermite2(Ts[i], Ts[i + 1], Ys[i], Ys[i + 1], Fs[i], Fs[i + 1], s);
|
|
13668
|
+
return yScalar ? val[0] : val;
|
|
13669
|
+
};
|
|
13670
|
+
return {
|
|
13671
|
+
t: Ts,
|
|
13672
|
+
y: yScalar ? Ys.map((v) => v[0]) : Ys,
|
|
13673
|
+
yInterp
|
|
13674
|
+
};
|
|
13675
|
+
}
|
|
13676
|
+
|
|
13510
13677
|
// src/typed/numeric.ts
|
|
13511
13678
|
var NUMERIC_WASM_THRESHOLD = 16;
|
|
13512
13679
|
function findRoot(f, a, b, opts) {
|
|
@@ -16851,13 +17018,13 @@ function hypergeometricDist(population, successes, draws) {
|
|
|
16851
17018
|
}
|
|
16852
17019
|
const M = population;
|
|
16853
17020
|
const K = successes;
|
|
16854
|
-
const
|
|
16855
|
-
const kMin = Math.max(0,
|
|
16856
|
-
const kMax = Math.min(K,
|
|
17021
|
+
const N2 = draws;
|
|
17022
|
+
const kMin = Math.max(0, N2 - (M - K));
|
|
17023
|
+
const kMax = Math.min(K, N2);
|
|
16857
17024
|
const useExact = M <= 1e3;
|
|
16858
17025
|
const pmf = (k) => {
|
|
16859
17026
|
if (!Number.isInteger(k) || k < kMin || k > kMax) return 0;
|
|
16860
|
-
return useExact ? _choose(K, k) * _choose(M - K,
|
|
17027
|
+
return useExact ? _choose(K, k) * _choose(M - K, N2 - k) / _choose(M, N2) : Math.exp(_logChoose(K, k) + _logChoose(M - K, N2 - k) - _logChoose(M, N2));
|
|
16861
17028
|
};
|
|
16862
17029
|
const cdf = (k) => {
|
|
16863
17030
|
if (k < kMin) return 0;
|
|
@@ -16866,8 +17033,8 @@ function hypergeometricDist(population, successes, draws) {
|
|
|
16866
17033
|
for (let i = kMin; i <= kk; i++) sum3 += pmf(i);
|
|
16867
17034
|
return Math.min(1, sum3);
|
|
16868
17035
|
};
|
|
16869
|
-
const mean7 =
|
|
16870
|
-
const variance2 =
|
|
17036
|
+
const mean7 = N2 * K / M;
|
|
17037
|
+
const variance2 = N2 * (K / M) * ((M - K) / M) * ((M - N2) / (M - 1));
|
|
16871
17038
|
return {
|
|
16872
17039
|
pdf: pmf,
|
|
16873
17040
|
cdf,
|
|
@@ -17534,19 +17701,19 @@ async function chiSquareTest(observed, expected, opts) {
|
|
|
17534
17701
|
function anova(groups) {
|
|
17535
17702
|
if (groups.length < 2) throw new Error("anova: need at least 2 groups");
|
|
17536
17703
|
const k = groups.length;
|
|
17537
|
-
let
|
|
17704
|
+
let N2 = 0;
|
|
17538
17705
|
let grandSum = 0;
|
|
17539
17706
|
const groupMeans = [];
|
|
17540
17707
|
const groupSizes = [];
|
|
17541
17708
|
for (const group of groups) {
|
|
17542
17709
|
if (group.length < 1) throw new Error("anova: each group must have at least 1 element");
|
|
17543
17710
|
groupSizes.push(group.length);
|
|
17544
|
-
|
|
17711
|
+
N2 += group.length;
|
|
17545
17712
|
const m = _mean(group);
|
|
17546
17713
|
groupMeans.push(m);
|
|
17547
17714
|
for (const x of group) grandSum += x;
|
|
17548
17715
|
}
|
|
17549
|
-
const grandMean = grandSum /
|
|
17716
|
+
const grandMean = grandSum / N2;
|
|
17550
17717
|
let ssBetween = 0;
|
|
17551
17718
|
for (let i = 0; i < k; i++) {
|
|
17552
17719
|
ssBetween += groupSizes[i] * (groupMeans[i] - grandMean) ** 2;
|
|
@@ -17558,7 +17725,7 @@ function anova(groups) {
|
|
|
17558
17725
|
}
|
|
17559
17726
|
}
|
|
17560
17727
|
const dfBetween = k - 1;
|
|
17561
|
-
const dfWithin =
|
|
17728
|
+
const dfWithin = N2 - k;
|
|
17562
17729
|
if (dfWithin <= 0) throw new Error("anova: insufficient degrees of freedom");
|
|
17563
17730
|
const msBetween = ssBetween / dfBetween;
|
|
17564
17731
|
const msWithin = ssWithin / dfWithin;
|
|
@@ -18089,10 +18256,10 @@ function _median(arr10) {
|
|
|
18089
18256
|
function leveneTest(groups, center3 = "median") {
|
|
18090
18257
|
const k = groups.length;
|
|
18091
18258
|
if (k < 2) throw new Error("leveneTest: need at least 2 groups");
|
|
18092
|
-
let
|
|
18259
|
+
let N2 = 0;
|
|
18093
18260
|
for (const g of groups) {
|
|
18094
18261
|
if (g.length < 1) throw new Error("leveneTest: every group must be non-empty");
|
|
18095
|
-
|
|
18262
|
+
N2 += g.length;
|
|
18096
18263
|
}
|
|
18097
18264
|
const z = groups.map((g) => {
|
|
18098
18265
|
const c = center3 === "median" ? _median(g) : _mean(g);
|
|
@@ -18108,16 +18275,16 @@ function leveneTest(groups, center3 = "median") {
|
|
|
18108
18275
|
num2 += zi.length * (zBarI - zBarAll) * (zBarI - zBarAll);
|
|
18109
18276
|
for (const v of zi) den += (v - zBarI) * (v - zBarI);
|
|
18110
18277
|
}
|
|
18111
|
-
const W = (
|
|
18112
|
-
return { statistic: W, pValue: _fPValue(W, k - 1,
|
|
18278
|
+
const W = (N2 - k) / (k - 1) * (num2 / den);
|
|
18279
|
+
return { statistic: W, pValue: _fPValue(W, k - 1, N2 - k), degreesOfFreedom: [k - 1, N2 - k] };
|
|
18113
18280
|
}
|
|
18114
18281
|
function bartlettTest(groups) {
|
|
18115
18282
|
const k = groups.length;
|
|
18116
18283
|
if (k < 2) throw new Error("bartlettTest: need at least 2 groups");
|
|
18117
|
-
let
|
|
18284
|
+
let N2 = 0;
|
|
18118
18285
|
for (const g of groups) {
|
|
18119
18286
|
if (g.length < 2) throw new Error("bartlettTest: every group needs \u22652 observations");
|
|
18120
|
-
|
|
18287
|
+
N2 += g.length;
|
|
18121
18288
|
}
|
|
18122
18289
|
let pooledNum = 0;
|
|
18123
18290
|
let sumLnVar = 0;
|
|
@@ -18129,9 +18296,9 @@ function bartlettTest(groups) {
|
|
|
18129
18296
|
sumLnVar += (ni - 1) * Math.log(si2);
|
|
18130
18297
|
sumInv += 1 / (ni - 1);
|
|
18131
18298
|
}
|
|
18132
|
-
const sp2 = pooledNum / (
|
|
18133
|
-
const numerator = (
|
|
18134
|
-
const C = 1 + (sumInv - 1 / (
|
|
18299
|
+
const sp2 = pooledNum / (N2 - k);
|
|
18300
|
+
const numerator = (N2 - k) * Math.log(sp2) - sumLnVar;
|
|
18301
|
+
const C = 1 + (sumInv - 1 / (N2 - k)) / (3 * (k - 1));
|
|
18135
18302
|
const T = numerator / C;
|
|
18136
18303
|
return { statistic: T, pValue: _chiSquaredPValue(T, k - 1), degreesOfFreedom: k - 1 };
|
|
18137
18304
|
}
|
|
@@ -22952,7 +23119,7 @@ var createDot = /* @__PURE__ */ factory(
|
|
|
22952
23119
|
return xLen;
|
|
22953
23120
|
}
|
|
22954
23121
|
function _denseDot(a, b) {
|
|
22955
|
-
const
|
|
23122
|
+
const N2 = _validateDim(a, b);
|
|
22956
23123
|
const adata = isMatrix(a) ? a._data : a;
|
|
22957
23124
|
const adt = isMatrix(a) ? a._datatype || a.getDataType() : void 0;
|
|
22958
23125
|
const bdata = isMatrix(b) ? b._data : b;
|
|
@@ -22971,28 +23138,28 @@ var createDot = /* @__PURE__ */ factory(
|
|
|
22971
23138
|
}
|
|
22972
23139
|
if (!aIsColumn && !bIsColumn) {
|
|
22973
23140
|
let c = mul(conj3(adata[0]), bdata[0]);
|
|
22974
|
-
for (let i = 1; i <
|
|
23141
|
+
for (let i = 1; i < N2; i++) {
|
|
22975
23142
|
c = add4(c, mul(conj3(adata[i]), bdata[i]));
|
|
22976
23143
|
}
|
|
22977
23144
|
return c;
|
|
22978
23145
|
}
|
|
22979
23146
|
if (!aIsColumn && bIsColumn) {
|
|
22980
23147
|
let c = mul(conj3(adata[0]), bdata[0][0]);
|
|
22981
|
-
for (let i = 1; i <
|
|
23148
|
+
for (let i = 1; i < N2; i++) {
|
|
22982
23149
|
c = add4(c, mul(conj3(adata[i]), bdata[i][0]));
|
|
22983
23150
|
}
|
|
22984
23151
|
return c;
|
|
22985
23152
|
}
|
|
22986
23153
|
if (aIsColumn && !bIsColumn) {
|
|
22987
23154
|
let c = mul(conj3(adata[0][0]), bdata[0]);
|
|
22988
|
-
for (let i = 1; i <
|
|
23155
|
+
for (let i = 1; i < N2; i++) {
|
|
22989
23156
|
c = add4(c, mul(conj3(adata[i][0]), bdata[i]));
|
|
22990
23157
|
}
|
|
22991
23158
|
return c;
|
|
22992
23159
|
}
|
|
22993
23160
|
{
|
|
22994
23161
|
let c = mul(conj3(adata[0][0]), bdata[0][0]);
|
|
22995
|
-
for (let i = 1; i <
|
|
23162
|
+
for (let i = 1; i < N2; i++) {
|
|
22996
23163
|
c = add4(c, mul(conj3(adata[i][0]), bdata[i][0]));
|
|
22997
23164
|
}
|
|
22998
23165
|
return c;
|
|
@@ -23988,20 +24155,20 @@ var createMatrixFromColumns = /* @__PURE__ */ factory(
|
|
|
23988
24155
|
function _createArray(arr10) {
|
|
23989
24156
|
if (arr10.length === 0)
|
|
23990
24157
|
throw new TypeError("At least one column is needed to construct a matrix.");
|
|
23991
|
-
const
|
|
24158
|
+
const N2 = checkVectorTypeAndReturnLength(arr10[0]);
|
|
23992
24159
|
const result = [];
|
|
23993
|
-
for (let i = 0; i <
|
|
24160
|
+
for (let i = 0; i < N2; i++) {
|
|
23994
24161
|
result[i] = [];
|
|
23995
24162
|
}
|
|
23996
24163
|
for (const col of arr10) {
|
|
23997
24164
|
const colLength = checkVectorTypeAndReturnLength(col);
|
|
23998
|
-
if (colLength !==
|
|
24165
|
+
if (colLength !== N2) {
|
|
23999
24166
|
throw new TypeError(
|
|
24000
|
-
"The vectors had different length: " + (
|
|
24167
|
+
"The vectors had different length: " + (N2 | 0) + " \u2260 " + (colLength | 0)
|
|
24001
24168
|
);
|
|
24002
24169
|
}
|
|
24003
24170
|
const f = flatten5(col);
|
|
24004
|
-
for (let i = 0; i <
|
|
24171
|
+
for (let i = 0; i < N2; i++) {
|
|
24005
24172
|
result[i].push(f[i]);
|
|
24006
24173
|
}
|
|
24007
24174
|
}
|
|
@@ -24057,13 +24224,13 @@ var createMatrixFromRows = /* @__PURE__ */ factory(
|
|
|
24057
24224
|
function _createArray(arr10) {
|
|
24058
24225
|
if (arr10.length === 0)
|
|
24059
24226
|
throw new TypeError("At least one row is needed to construct a matrix.");
|
|
24060
|
-
const
|
|
24227
|
+
const N2 = checkVectorTypeAndReturnLength(arr10[0]);
|
|
24061
24228
|
const result = [];
|
|
24062
24229
|
for (const row2 of arr10) {
|
|
24063
24230
|
const rowLength = checkVectorTypeAndReturnLength(row2);
|
|
24064
|
-
if (rowLength !==
|
|
24231
|
+
if (rowLength !== N2) {
|
|
24065
24232
|
throw new TypeError(
|
|
24066
|
-
"The vectors had different length: " + (
|
|
24233
|
+
"The vectors had different length: " + (N2 | 0) + " \u2260 " + (rowLength | 0)
|
|
24067
24234
|
);
|
|
24068
24235
|
}
|
|
24069
24236
|
result.push(flatten5(row2));
|
|
@@ -38086,20 +38253,20 @@ function createComplexEigs({
|
|
|
38086
38253
|
matrixFromColumns: _matrixFromColumns,
|
|
38087
38254
|
dot: dot9
|
|
38088
38255
|
}) {
|
|
38089
|
-
function complexEigs(arr10,
|
|
38090
|
-
if (!findVectors && type === "number" &&
|
|
38256
|
+
function complexEigs(arr10, N2, prec, type, findVectors = true) {
|
|
38257
|
+
if (!findVectors && type === "number" && N2 * N2 >= WASM_EIGS_THRESHOLD) {
|
|
38091
38258
|
const wasm = wasmLoader.getModule();
|
|
38092
38259
|
if (wasm) {
|
|
38093
38260
|
try {
|
|
38094
|
-
const flat = flattenToFloat648(arr10,
|
|
38261
|
+
const flat = flattenToFloat648(arr10, N2, N2);
|
|
38095
38262
|
const matrixAlloc = wasmLoader.allocateFloat64Array(flat);
|
|
38096
|
-
const eigenvaluesRealAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
38097
|
-
const eigenvaluesImagAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
38098
|
-
const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
38263
|
+
const eigenvaluesRealAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
|
|
38264
|
+
const eigenvaluesImagAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
|
|
38265
|
+
const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2 * N2);
|
|
38099
38266
|
try {
|
|
38100
38267
|
const iterations = wasm.qrAlgorithm(
|
|
38101
38268
|
matrixAlloc.ptr,
|
|
38102
|
-
|
|
38269
|
+
N2,
|
|
38103
38270
|
eigenvaluesRealAlloc.ptr,
|
|
38104
38271
|
eigenvaluesImagAlloc.ptr,
|
|
38105
38272
|
workAlloc.ptr,
|
|
@@ -38109,7 +38276,7 @@ function createComplexEigs({
|
|
|
38109
38276
|
);
|
|
38110
38277
|
if (iterations >= 0) {
|
|
38111
38278
|
const values2 = [];
|
|
38112
|
-
for (let i = 0; i <
|
|
38279
|
+
for (let i = 0; i < N2; i++) {
|
|
38113
38280
|
const re3 = eigenvaluesRealAlloc.array[i];
|
|
38114
38281
|
const im3 = eigenvaluesImagAlloc.array[i];
|
|
38115
38282
|
if (Math.abs(im3) < 1e-14) {
|
|
@@ -38135,16 +38302,16 @@ function createComplexEigs({
|
|
|
38135
38302
|
}
|
|
38136
38303
|
}
|
|
38137
38304
|
}
|
|
38138
|
-
const R = balance(arr10,
|
|
38139
|
-
reduceToHessenberg(arr10,
|
|
38140
|
-
const { values, C } = iterateUntilTriangular(arr10,
|
|
38305
|
+
const R = balance(arr10, N2, prec, type, findVectors);
|
|
38306
|
+
reduceToHessenberg(arr10, N2, prec, type, findVectors, R);
|
|
38307
|
+
const { values, C } = iterateUntilTriangular(arr10, N2, prec, type, findVectors);
|
|
38141
38308
|
if (findVectors) {
|
|
38142
|
-
const eigenvectors = findEigenvectors(arr10,
|
|
38309
|
+
const eigenvectors = findEigenvectors(arr10, N2, C, R, values, prec, type);
|
|
38143
38310
|
return { values, eigenvectors };
|
|
38144
38311
|
}
|
|
38145
38312
|
return { values };
|
|
38146
38313
|
}
|
|
38147
|
-
function balance(arr10,
|
|
38314
|
+
function balance(arr10, N2, _prec, type, findVectors) {
|
|
38148
38315
|
const big = type === "BigNumber";
|
|
38149
38316
|
const cplx = type === "Complex";
|
|
38150
38317
|
const realzero = big ? bignumber2(0) : 0;
|
|
@@ -38154,15 +38321,15 @@ function createComplexEigs({
|
|
|
38154
38321
|
const radixSq = multiplyScalar2(radix, radix);
|
|
38155
38322
|
let Rdiag;
|
|
38156
38323
|
if (findVectors) {
|
|
38157
|
-
Rdiag = Array(
|
|
38324
|
+
Rdiag = Array(N2).fill(one);
|
|
38158
38325
|
}
|
|
38159
38326
|
let last2 = false;
|
|
38160
38327
|
while (!last2) {
|
|
38161
38328
|
last2 = true;
|
|
38162
|
-
for (let i = 0; i <
|
|
38329
|
+
for (let i = 0; i < N2; i++) {
|
|
38163
38330
|
let colNorm = realzero;
|
|
38164
38331
|
let rowNorm = realzero;
|
|
38165
|
-
for (let j = 0; j <
|
|
38332
|
+
for (let j = 0; j < N2; j++) {
|
|
38166
38333
|
if (i === j) continue;
|
|
38167
38334
|
colNorm = addScalar2(colNorm, abs2(arr10[j][i]));
|
|
38168
38335
|
rowNorm = addScalar2(rowNorm, abs2(arr10[i][j]));
|
|
@@ -38187,7 +38354,7 @@ function createComplexEigs({
|
|
|
38187
38354
|
if (condition) {
|
|
38188
38355
|
last2 = false;
|
|
38189
38356
|
const g = divideScalar2(1, f);
|
|
38190
|
-
for (let j = 0; j <
|
|
38357
|
+
for (let j = 0; j < N2; j++) {
|
|
38191
38358
|
if (i === j) {
|
|
38192
38359
|
continue;
|
|
38193
38360
|
}
|
|
@@ -38203,17 +38370,17 @@ function createComplexEigs({
|
|
|
38203
38370
|
}
|
|
38204
38371
|
return findVectors ? diag2(Rdiag) : null;
|
|
38205
38372
|
}
|
|
38206
|
-
function reduceToHessenberg(arr10,
|
|
38373
|
+
function reduceToHessenberg(arr10, N2, prec, type, findVectors, R) {
|
|
38207
38374
|
const big = type === "BigNumber";
|
|
38208
38375
|
const cplx = type === "Complex";
|
|
38209
38376
|
const zero = big ? bignumber2(0) : cplx ? complex3(0) : 0;
|
|
38210
38377
|
if (big) {
|
|
38211
38378
|
prec = bignumber2(prec);
|
|
38212
38379
|
}
|
|
38213
|
-
for (let i = 0; i <
|
|
38380
|
+
for (let i = 0; i < N2 - 2; i++) {
|
|
38214
38381
|
let maxIndex = 0;
|
|
38215
38382
|
let max2 = zero;
|
|
38216
|
-
for (let j = i + 1; j <
|
|
38383
|
+
for (let j = i + 1; j < N2; j++) {
|
|
38217
38384
|
const el = arr10[j][i];
|
|
38218
38385
|
if (smaller2(abs2(max2), abs2(el))) {
|
|
38219
38386
|
max2 = el;
|
|
@@ -38227,7 +38394,7 @@ function createComplexEigs({
|
|
|
38227
38394
|
const tmp1 = arr10[maxIndex];
|
|
38228
38395
|
arr10[maxIndex] = arr10[i + 1];
|
|
38229
38396
|
arr10[i + 1] = tmp1;
|
|
38230
|
-
for (let j = 0; j <
|
|
38397
|
+
for (let j = 0; j < N2; j++) {
|
|
38231
38398
|
const tmp2 = arr10[j][maxIndex];
|
|
38232
38399
|
arr10[j][maxIndex] = arr10[j][i + 1];
|
|
38233
38400
|
arr10[j][i + 1] = tmp2;
|
|
@@ -38238,26 +38405,26 @@ function createComplexEigs({
|
|
|
38238
38405
|
R[i + 1] = tmp3;
|
|
38239
38406
|
}
|
|
38240
38407
|
}
|
|
38241
|
-
for (let j = i + 2; j <
|
|
38408
|
+
for (let j = i + 2; j < N2; j++) {
|
|
38242
38409
|
const n = divideScalar2(arr10[j][i], max2);
|
|
38243
38410
|
if (n === 0) {
|
|
38244
38411
|
continue;
|
|
38245
38412
|
}
|
|
38246
|
-
for (let k = 0; k <
|
|
38413
|
+
for (let k = 0; k < N2; k++) {
|
|
38247
38414
|
arr10[j][k] = subtract3(arr10[j][k], multiplyScalar2(n, arr10[i + 1][k]));
|
|
38248
38415
|
}
|
|
38249
|
-
for (let k = 0; k <
|
|
38416
|
+
for (let k = 0; k < N2; k++) {
|
|
38250
38417
|
arr10[k][i + 1] = addScalar2(arr10[k][i + 1], multiplyScalar2(n, arr10[k][j]));
|
|
38251
38418
|
}
|
|
38252
38419
|
if (findVectors) {
|
|
38253
|
-
for (let k = 0; k <
|
|
38420
|
+
for (let k = 0; k < N2; k++) {
|
|
38254
38421
|
R[j][k] = subtract3(R[j][k], multiplyScalar2(n, R[i + 1][k]));
|
|
38255
38422
|
}
|
|
38256
38423
|
}
|
|
38257
38424
|
}
|
|
38258
38425
|
}
|
|
38259
38426
|
}
|
|
38260
|
-
function iterateUntilTriangular(A,
|
|
38427
|
+
function iterateUntilTriangular(A, N2, prec, type, findVectors) {
|
|
38261
38428
|
const big = type === "BigNumber";
|
|
38262
38429
|
const cplx = type === "Complex";
|
|
38263
38430
|
const one = big ? bignumber2(1) : cplx ? complex3(1) : 1;
|
|
@@ -38266,9 +38433,9 @@ function createComplexEigs({
|
|
|
38266
38433
|
}
|
|
38267
38434
|
let arr10 = clone(A);
|
|
38268
38435
|
const lambdas = [];
|
|
38269
|
-
let n =
|
|
38436
|
+
let n = N2;
|
|
38270
38437
|
const Sdiag = [];
|
|
38271
|
-
let Qtotal = findVectors ? diag2(Array(
|
|
38438
|
+
let Qtotal = findVectors ? diag2(Array(N2).fill(one)) : void 0;
|
|
38272
38439
|
let Qpartial = findVectors ? diag2(Array(n).fill(one)) : void 0;
|
|
38273
38440
|
let lastConvergenceBefore = 0;
|
|
38274
38441
|
while (lastConvergenceBefore <= 100) {
|
|
@@ -38290,7 +38457,7 @@ function createComplexEigs({
|
|
|
38290
38457
|
lambdas.push(arr10[n - 1][n - 1]);
|
|
38291
38458
|
if (findVectors) {
|
|
38292
38459
|
Sdiag.unshift([[1]]);
|
|
38293
|
-
inflateMatrix(Qpartial,
|
|
38460
|
+
inflateMatrix(Qpartial, N2);
|
|
38294
38461
|
Qtotal = multiply2(Qtotal, Qpartial);
|
|
38295
38462
|
if (n > 1) {
|
|
38296
38463
|
Qpartial = diag2(Array(n - 1).fill(one));
|
|
@@ -38323,7 +38490,7 @@ function createComplexEigs({
|
|
|
38323
38490
|
type
|
|
38324
38491
|
)
|
|
38325
38492
|
);
|
|
38326
|
-
inflateMatrix(Qpartial,
|
|
38493
|
+
inflateMatrix(Qpartial, N2);
|
|
38327
38494
|
Qtotal = multiply2(Qtotal, Qpartial);
|
|
38328
38495
|
if (n > 2) {
|
|
38329
38496
|
Qpartial = diag2(Array(n - 2).fill(one));
|
|
@@ -38350,10 +38517,10 @@ function createComplexEigs({
|
|
|
38350
38517
|
err.vectors = [];
|
|
38351
38518
|
throw err;
|
|
38352
38519
|
}
|
|
38353
|
-
const C = findVectors ? multiply2(Qtotal, blockDiag(Sdiag,
|
|
38520
|
+
const C = findVectors ? multiply2(Qtotal, blockDiag(Sdiag, N2)) : void 0;
|
|
38354
38521
|
return { values: lambdas, C };
|
|
38355
38522
|
}
|
|
38356
|
-
function findEigenvectors(A,
|
|
38523
|
+
function findEigenvectors(A, N2, C, R, values, prec, type) {
|
|
38357
38524
|
const Cinv = inv3(C);
|
|
38358
38525
|
const U = multiply2(multiply2(Cinv, A), C);
|
|
38359
38526
|
const big = type === "BigNumber";
|
|
@@ -38373,8 +38540,8 @@ function createComplexEigs({
|
|
|
38373
38540
|
}
|
|
38374
38541
|
const vectors = [];
|
|
38375
38542
|
const len = uniqueValues.length;
|
|
38376
|
-
const b = Array(
|
|
38377
|
-
const E = diag2(Array(
|
|
38543
|
+
const b = Array(N2).fill(zero);
|
|
38544
|
+
const E = diag2(Array(N2).fill(one));
|
|
38378
38545
|
for (let i = 0; i < len; i++) {
|
|
38379
38546
|
const lambda = uniqueValues[i];
|
|
38380
38547
|
const S = subtract3(
|
|
@@ -38384,7 +38551,7 @@ function createComplexEigs({
|
|
|
38384
38551
|
let solutions = usolveAll2(S, b);
|
|
38385
38552
|
solutions.shift();
|
|
38386
38553
|
while (solutions.length < multiplicities[i]) {
|
|
38387
|
-
const approxVec = inverseIterate(S,
|
|
38554
|
+
const approxVec = inverseIterate(S, N2, solutions, prec, type);
|
|
38388
38555
|
if (approxVec === null) {
|
|
38389
38556
|
break;
|
|
38390
38557
|
}
|
|
@@ -38439,20 +38606,20 @@ function createComplexEigs({
|
|
|
38439
38606
|
];
|
|
38440
38607
|
}
|
|
38441
38608
|
}
|
|
38442
|
-
function inflateMatrix(arr10,
|
|
38609
|
+
function inflateMatrix(arr10, N2) {
|
|
38443
38610
|
for (let i = 0; i < arr10.length; i++) {
|
|
38444
|
-
arr10[i].push(...Array(
|
|
38611
|
+
arr10[i].push(...Array(N2 - arr10[i].length).fill(0));
|
|
38445
38612
|
}
|
|
38446
|
-
for (let i = arr10.length; i <
|
|
38447
|
-
arr10.push(Array(
|
|
38613
|
+
for (let i = arr10.length; i < N2; i++) {
|
|
38614
|
+
arr10.push(Array(N2).fill(0));
|
|
38448
38615
|
arr10[i][i] = 1;
|
|
38449
38616
|
}
|
|
38450
38617
|
return arr10;
|
|
38451
38618
|
}
|
|
38452
|
-
function blockDiag(arr10,
|
|
38619
|
+
function blockDiag(arr10, N2) {
|
|
38453
38620
|
const M = [];
|
|
38454
|
-
for (let i = 0; i <
|
|
38455
|
-
M[i] = Array(
|
|
38621
|
+
for (let i = 0; i < N2; i++) {
|
|
38622
|
+
M[i] = Array(N2).fill(0);
|
|
38456
38623
|
}
|
|
38457
38624
|
let I2 = 0;
|
|
38458
38625
|
for (const sub3 of arr10) {
|
|
@@ -38474,12 +38641,12 @@ function createComplexEigs({
|
|
|
38474
38641
|
}
|
|
38475
38642
|
return -1;
|
|
38476
38643
|
}
|
|
38477
|
-
function inverseIterate(A,
|
|
38644
|
+
function inverseIterate(A, N2, orthog, prec, type) {
|
|
38478
38645
|
const largeNum = type === "BigNumber" ? bignumber2(1e3) : 1e3;
|
|
38479
38646
|
let b;
|
|
38480
38647
|
let i = 0;
|
|
38481
38648
|
for (; i < 5; ++i) {
|
|
38482
|
-
b = randomOrthogonalVector(
|
|
38649
|
+
b = randomOrthogonalVector(N2, orthog, type);
|
|
38483
38650
|
try {
|
|
38484
38651
|
b = usolve2(A, b);
|
|
38485
38652
|
} catch {
|
|
@@ -38505,10 +38672,10 @@ function createComplexEigs({
|
|
|
38505
38672
|
}
|
|
38506
38673
|
return b;
|
|
38507
38674
|
}
|
|
38508
|
-
function randomOrthogonalVector(
|
|
38675
|
+
function randomOrthogonalVector(N2, orthog, type) {
|
|
38509
38676
|
const big = type === "BigNumber";
|
|
38510
38677
|
const cplx = type === "Complex";
|
|
38511
|
-
let v = Array(
|
|
38678
|
+
let v = Array(N2).fill(0).map(() => 2 * Math.random() - 1);
|
|
38512
38679
|
if (big) {
|
|
38513
38680
|
v = v.map((n) => bignumber2(n));
|
|
38514
38681
|
}
|
|
@@ -38591,19 +38758,19 @@ function createRealSymmetric({
|
|
|
38591
38758
|
throw TypeError("Unsupported data type: " + type);
|
|
38592
38759
|
}
|
|
38593
38760
|
function diag2(x, precision, computeVectors) {
|
|
38594
|
-
const
|
|
38761
|
+
const N2 = x.length;
|
|
38595
38762
|
const wasm = wasmLoader.getModule();
|
|
38596
|
-
if (wasm &&
|
|
38763
|
+
if (wasm && N2 * N2 >= WASM_EIGS_THRESHOLD2) {
|
|
38597
38764
|
try {
|
|
38598
|
-
const flat = flattenToFloat649(x,
|
|
38765
|
+
const flat = flattenToFloat649(x, N2, N2);
|
|
38599
38766
|
const matrixAlloc = wasmLoader.allocateFloat64Array(flat);
|
|
38600
|
-
const eigenvaluesAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
38601
|
-
const eigenvectorsAlloc = computeVectors ? wasmLoader.allocateFloat64ArrayEmpty(
|
|
38602
|
-
const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(
|
|
38767
|
+
const eigenvaluesAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
|
|
38768
|
+
const eigenvectorsAlloc = computeVectors ? wasmLoader.allocateFloat64ArrayEmpty(N2 * N2) : { ptr: 0, array: new Float64Array(0) };
|
|
38769
|
+
const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2 * N2);
|
|
38603
38770
|
try {
|
|
38604
38771
|
const iterations = wasm.eigsSymmetric(
|
|
38605
38772
|
matrixAlloc.ptr,
|
|
38606
|
-
|
|
38773
|
+
N2,
|
|
38607
38774
|
eigenvaluesAlloc.ptr,
|
|
38608
38775
|
eigenvectorsAlloc.ptr,
|
|
38609
38776
|
workAlloc.ptr,
|
|
@@ -38612,8 +38779,8 @@ function createRealSymmetric({
|
|
|
38612
38779
|
precision
|
|
38613
38780
|
);
|
|
38614
38781
|
if (iterations >= 0) {
|
|
38615
|
-
const values = Array(
|
|
38616
|
-
for (let i = 0; i <
|
|
38782
|
+
const values = Array(N2);
|
|
38783
|
+
for (let i = 0; i < N2; i++) {
|
|
38617
38784
|
values[i] = eigenvaluesAlloc.array[i];
|
|
38618
38785
|
}
|
|
38619
38786
|
if (!computeVectors) {
|
|
@@ -38623,9 +38790,9 @@ function createRealSymmetric({
|
|
|
38623
38790
|
const eigenvectors = [];
|
|
38624
38791
|
const sortedIndices = values.map((v, i) => ({ v, i })).sort((a, b) => Math.abs(a.v) - Math.abs(b.v)).map((x2) => x2.i);
|
|
38625
38792
|
for (const origIdx of sortedIndices) {
|
|
38626
|
-
const vector = Array(
|
|
38627
|
-
for (let i = 0; i <
|
|
38628
|
-
vector[i] = eigenvectorsAlloc.array[i *
|
|
38793
|
+
const vector = Array(N2);
|
|
38794
|
+
for (let i = 0; i < N2; i++) {
|
|
38795
|
+
vector[i] = eigenvectorsAlloc.array[i * N2 + origIdx];
|
|
38629
38796
|
}
|
|
38630
38797
|
eigenvectors.push({
|
|
38631
38798
|
value: values[origIdx],
|
|
@@ -38648,13 +38815,13 @@ function createRealSymmetric({
|
|
|
38648
38815
|
} catch {
|
|
38649
38816
|
}
|
|
38650
38817
|
}
|
|
38651
|
-
const e0 = Math.abs(precision /
|
|
38818
|
+
const e0 = Math.abs(precision / N2);
|
|
38652
38819
|
let psi;
|
|
38653
38820
|
let Sij;
|
|
38654
38821
|
if (computeVectors) {
|
|
38655
|
-
Sij = new Array(
|
|
38656
|
-
for (let i = 0; i <
|
|
38657
|
-
Sij[i] = Array(
|
|
38822
|
+
Sij = new Array(N2);
|
|
38823
|
+
for (let i = 0; i < N2; i++) {
|
|
38824
|
+
Sij[i] = Array(N2).fill(0);
|
|
38658
38825
|
Sij[i][i] = 1;
|
|
38659
38826
|
}
|
|
38660
38827
|
}
|
|
@@ -38667,21 +38834,21 @@ function createRealSymmetric({
|
|
|
38667
38834
|
if (computeVectors) Sij = Sij1(Sij, psi, i, j);
|
|
38668
38835
|
Vab = getAij(x);
|
|
38669
38836
|
}
|
|
38670
|
-
const Ei = Array(
|
|
38671
|
-
for (let i = 0; i <
|
|
38837
|
+
const Ei = Array(N2).fill(0);
|
|
38838
|
+
for (let i = 0; i < N2; i++) {
|
|
38672
38839
|
Ei[i] = x[i][i];
|
|
38673
38840
|
}
|
|
38674
38841
|
return sorting(clone(Ei), Sij, computeVectors);
|
|
38675
38842
|
}
|
|
38676
38843
|
function diagBig(x, precision, computeVectors) {
|
|
38677
|
-
const
|
|
38678
|
-
const e0 = abs2(multiplyScalar2(precision, bignumber2(1 /
|
|
38844
|
+
const N2 = x.length;
|
|
38845
|
+
const e0 = abs2(multiplyScalar2(precision, bignumber2(1 / N2)));
|
|
38679
38846
|
let psi;
|
|
38680
38847
|
let Sij;
|
|
38681
38848
|
if (computeVectors) {
|
|
38682
|
-
Sij = new Array(
|
|
38683
|
-
for (let i = 0; i <
|
|
38684
|
-
Sij[i] = Array(
|
|
38849
|
+
Sij = new Array(N2);
|
|
38850
|
+
for (let i = 0; i < N2; i++) {
|
|
38851
|
+
Sij[i] = Array(N2).fill(bignumber2(0));
|
|
38685
38852
|
Sij[i][i] = bignumber2(1);
|
|
38686
38853
|
}
|
|
38687
38854
|
}
|
|
@@ -38694,8 +38861,8 @@ function createRealSymmetric({
|
|
|
38694
38861
|
if (computeVectors) Sij = Sij1Big(Sij, psi, i, j);
|
|
38695
38862
|
Vab = getAijBig(x);
|
|
38696
38863
|
}
|
|
38697
|
-
const Ei = Array(
|
|
38698
|
-
for (let i = 0; i <
|
|
38864
|
+
const Ei = Array(N2).fill(bignumber2(0));
|
|
38865
|
+
for (let i = 0; i < N2; i++) {
|
|
38699
38866
|
Ei[i] = x[i][i];
|
|
38700
38867
|
}
|
|
38701
38868
|
return sorting(clone(Ei), Sij, computeVectors);
|
|
@@ -38720,45 +38887,45 @@ function createRealSymmetric({
|
|
|
38720
38887
|
}
|
|
38721
38888
|
}
|
|
38722
38889
|
function Sij1(Sij, theta, i, j) {
|
|
38723
|
-
const
|
|
38890
|
+
const N2 = Sij.length;
|
|
38724
38891
|
const c = Math.cos(theta);
|
|
38725
38892
|
const s = Math.sin(theta);
|
|
38726
|
-
const Ski = Array(
|
|
38727
|
-
const Skj = Array(
|
|
38728
|
-
for (let k = 0; k <
|
|
38893
|
+
const Ski = Array(N2).fill(0);
|
|
38894
|
+
const Skj = Array(N2).fill(0);
|
|
38895
|
+
for (let k = 0; k < N2; k++) {
|
|
38729
38896
|
Ski[k] = c * Sij[k][i] - s * Sij[k][j];
|
|
38730
38897
|
Skj[k] = s * Sij[k][i] + c * Sij[k][j];
|
|
38731
38898
|
}
|
|
38732
|
-
for (let k = 0; k <
|
|
38899
|
+
for (let k = 0; k < N2; k++) {
|
|
38733
38900
|
Sij[k][i] = Ski[k];
|
|
38734
38901
|
Sij[k][j] = Skj[k];
|
|
38735
38902
|
}
|
|
38736
38903
|
return Sij;
|
|
38737
38904
|
}
|
|
38738
38905
|
function Sij1Big(Sij, theta, i, j) {
|
|
38739
|
-
const
|
|
38906
|
+
const N2 = Sij.length;
|
|
38740
38907
|
const c = cos2(theta);
|
|
38741
38908
|
const s = sin2(theta);
|
|
38742
|
-
const Ski = Array(
|
|
38743
|
-
const Skj = Array(
|
|
38744
|
-
for (let k = 0; k <
|
|
38909
|
+
const Ski = Array(N2).fill(bignumber2(0));
|
|
38910
|
+
const Skj = Array(N2).fill(bignumber2(0));
|
|
38911
|
+
for (let k = 0; k < N2; k++) {
|
|
38745
38912
|
Ski[k] = subtract3(multiplyScalar2(c, Sij[k][i]), multiplyScalar2(s, Sij[k][j]));
|
|
38746
38913
|
Skj[k] = addScalar2(multiplyScalar2(s, Sij[k][i]), multiplyScalar2(c, Sij[k][j]));
|
|
38747
38914
|
}
|
|
38748
|
-
for (let k = 0; k <
|
|
38915
|
+
for (let k = 0; k < N2; k++) {
|
|
38749
38916
|
Sij[k][i] = Ski[k];
|
|
38750
38917
|
Sij[k][j] = Skj[k];
|
|
38751
38918
|
}
|
|
38752
38919
|
return Sij;
|
|
38753
38920
|
}
|
|
38754
38921
|
function x1Big(Hij, theta, i, j) {
|
|
38755
|
-
const
|
|
38922
|
+
const N2 = Hij.length;
|
|
38756
38923
|
const c = bignumber2(cos2(theta).toString());
|
|
38757
38924
|
const s = bignumber2(sin2(theta).toString());
|
|
38758
38925
|
const c2 = multiplyScalar2(c, c);
|
|
38759
38926
|
const s2 = multiplyScalar2(s, s);
|
|
38760
|
-
const Aki = Array(
|
|
38761
|
-
const Akj = Array(
|
|
38927
|
+
const Aki = Array(N2).fill(bignumber2(0));
|
|
38928
|
+
const Akj = Array(N2).fill(bignumber2(0));
|
|
38762
38929
|
const csHij = multiply2(bignumber2(2), c, s, Hij[i][j]);
|
|
38763
38930
|
const Aii = addScalar2(
|
|
38764
38931
|
subtract3(multiplyScalar2(c2, Hij[i][i]), csHij),
|
|
@@ -38769,7 +38936,7 @@ function createRealSymmetric({
|
|
|
38769
38936
|
csHij,
|
|
38770
38937
|
multiplyScalar2(c2, Hij[j][j])
|
|
38771
38938
|
);
|
|
38772
|
-
for (let k = 0; k <
|
|
38939
|
+
for (let k = 0; k < N2; k++) {
|
|
38773
38940
|
Aki[k] = subtract3(multiplyScalar2(c, Hij[i][k]), multiplyScalar2(s, Hij[j][k]));
|
|
38774
38941
|
Akj[k] = addScalar2(multiplyScalar2(s, Hij[i][k]), multiplyScalar2(c, Hij[j][k]));
|
|
38775
38942
|
}
|
|
@@ -38777,7 +38944,7 @@ function createRealSymmetric({
|
|
|
38777
38944
|
Hij[j][j] = Ajj;
|
|
38778
38945
|
Hij[i][j] = bignumber2(0);
|
|
38779
38946
|
Hij[j][i] = bignumber2(0);
|
|
38780
|
-
for (let k = 0; k <
|
|
38947
|
+
for (let k = 0; k < N2; k++) {
|
|
38781
38948
|
if (k !== i && k !== j) {
|
|
38782
38949
|
Hij[i][k] = Aki[k];
|
|
38783
38950
|
Hij[k][i] = Aki[k];
|
|
@@ -38788,16 +38955,16 @@ function createRealSymmetric({
|
|
|
38788
38955
|
return Hij;
|
|
38789
38956
|
}
|
|
38790
38957
|
function x1(Hij, theta, i, j) {
|
|
38791
|
-
const
|
|
38958
|
+
const N2 = Hij.length;
|
|
38792
38959
|
const c = Math.cos(theta);
|
|
38793
38960
|
const s = Math.sin(theta);
|
|
38794
38961
|
const c2 = c * c;
|
|
38795
38962
|
const s2 = s * s;
|
|
38796
|
-
const Aki = Array(
|
|
38797
|
-
const Akj = Array(
|
|
38963
|
+
const Aki = Array(N2).fill(0);
|
|
38964
|
+
const Akj = Array(N2).fill(0);
|
|
38798
38965
|
const Aii = c2 * Hij[i][i] - 2 * c * s * Hij[i][j] + s2 * Hij[j][j];
|
|
38799
38966
|
const Ajj = s2 * Hij[i][i] + 2 * c * s * Hij[i][j] + c2 * Hij[j][j];
|
|
38800
|
-
for (let k = 0; k <
|
|
38967
|
+
for (let k = 0; k < N2; k++) {
|
|
38801
38968
|
Aki[k] = c * Hij[i][k] - s * Hij[j][k];
|
|
38802
38969
|
Akj[k] = s * Hij[i][k] + c * Hij[j][k];
|
|
38803
38970
|
}
|
|
@@ -38805,7 +38972,7 @@ function createRealSymmetric({
|
|
|
38805
38972
|
Hij[j][j] = Ajj;
|
|
38806
38973
|
Hij[i][j] = 0;
|
|
38807
38974
|
Hij[j][i] = 0;
|
|
38808
|
-
for (let k = 0; k <
|
|
38975
|
+
for (let k = 0; k < N2; k++) {
|
|
38809
38976
|
if (k !== i && k !== j) {
|
|
38810
38977
|
Hij[i][k] = Aki[k];
|
|
38811
38978
|
Hij[k][i] = Aki[k];
|
|
@@ -38816,11 +38983,11 @@ function createRealSymmetric({
|
|
|
38816
38983
|
return Hij;
|
|
38817
38984
|
}
|
|
38818
38985
|
function getAij(Mij) {
|
|
38819
|
-
const
|
|
38986
|
+
const N2 = Mij.length;
|
|
38820
38987
|
let maxMij = 0;
|
|
38821
38988
|
let maxIJ = [0, 1];
|
|
38822
|
-
for (let i = 0; i <
|
|
38823
|
-
for (let j = i + 1; j <
|
|
38989
|
+
for (let i = 0; i < N2; i++) {
|
|
38990
|
+
for (let j = i + 1; j < N2; j++) {
|
|
38824
38991
|
if (Math.abs(maxMij) < Math.abs(Mij[i][j])) {
|
|
38825
38992
|
maxMij = Math.abs(Mij[i][j]);
|
|
38826
38993
|
maxIJ = [i, j];
|
|
@@ -38830,11 +38997,11 @@ function createRealSymmetric({
|
|
|
38830
38997
|
return [maxIJ, maxMij];
|
|
38831
38998
|
}
|
|
38832
38999
|
function getAijBig(Mij) {
|
|
38833
|
-
const
|
|
39000
|
+
const N2 = Mij.length;
|
|
38834
39001
|
let maxMij = bignumber2(0);
|
|
38835
39002
|
let maxIJ = [0, 1];
|
|
38836
|
-
for (let i = 0; i <
|
|
38837
|
-
for (let j = i + 1; j <
|
|
39003
|
+
for (let i = 0; i < N2; i++) {
|
|
39004
|
+
for (let j = i + 1; j < N2; j++) {
|
|
38838
39005
|
if (bigLt(abs2(maxMij), abs2(Mij[i][j]))) {
|
|
38839
39006
|
maxMij = abs2(Mij[i][j]);
|
|
38840
39007
|
maxIJ = [i, j];
|
|
@@ -38844,16 +39011,16 @@ function createRealSymmetric({
|
|
|
38844
39011
|
return [maxIJ, maxMij];
|
|
38845
39012
|
}
|
|
38846
39013
|
function sorting(E, S, computeVectors) {
|
|
38847
|
-
const
|
|
38848
|
-
const values = Array(
|
|
39014
|
+
const N2 = E.length;
|
|
39015
|
+
const values = Array(N2);
|
|
38849
39016
|
let vecs;
|
|
38850
39017
|
if (computeVectors) {
|
|
38851
|
-
vecs = Array(
|
|
38852
|
-
for (let k = 0; k <
|
|
38853
|
-
vecs[k] = Array(
|
|
39018
|
+
vecs = Array(N2);
|
|
39019
|
+
for (let k = 0; k < N2; k++) {
|
|
39020
|
+
vecs[k] = Array(N2);
|
|
38854
39021
|
}
|
|
38855
39022
|
}
|
|
38856
|
-
for (let i = 0; i <
|
|
39023
|
+
for (let i = 0; i < N2; i++) {
|
|
38857
39024
|
let minID = 0;
|
|
38858
39025
|
let minE = E[0];
|
|
38859
39026
|
for (let j = 0; j < E.length; j++) {
|
|
@@ -38864,7 +39031,7 @@ function createRealSymmetric({
|
|
|
38864
39031
|
}
|
|
38865
39032
|
values[i] = E.splice(minID, 1)[0];
|
|
38866
39033
|
if (computeVectors) {
|
|
38867
|
-
for (let k = 0; k <
|
|
39034
|
+
for (let k = 0; k < N2; k++) {
|
|
38868
39035
|
vecs[i][k] = S[k][minID];
|
|
38869
39036
|
S[k].splice(minID, 1);
|
|
38870
39037
|
}
|
|
@@ -39053,26 +39220,26 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
39053
39220
|
if (asize.length !== 2 || asize[0] !== asize[1]) {
|
|
39054
39221
|
throw new RangeError(`Matrix must be square (size: ${formatGeneric(asize, {})})`);
|
|
39055
39222
|
}
|
|
39056
|
-
const
|
|
39057
|
-
if (isReal(arr10,
|
|
39058
|
-
coerceReal(arr10,
|
|
39059
|
-
if (isSymmetric(arr10,
|
|
39060
|
-
const type2 = coerceTypes(mat, arr10,
|
|
39223
|
+
const N2 = asize[0];
|
|
39224
|
+
if (isReal(arr10, N2, prec)) {
|
|
39225
|
+
coerceReal(arr10, N2);
|
|
39226
|
+
if (isSymmetric(arr10, N2, prec)) {
|
|
39227
|
+
const type2 = coerceTypes(mat, arr10, N2);
|
|
39061
39228
|
return doRealSymmetric(
|
|
39062
39229
|
arr10,
|
|
39063
|
-
|
|
39230
|
+
N2,
|
|
39064
39231
|
prec,
|
|
39065
39232
|
type2,
|
|
39066
39233
|
computeVectors
|
|
39067
39234
|
);
|
|
39068
39235
|
}
|
|
39069
39236
|
}
|
|
39070
|
-
const type = coerceTypes(mat, arr10,
|
|
39071
|
-
return doComplexEigs(arr10,
|
|
39237
|
+
const type = coerceTypes(mat, arr10, N2);
|
|
39238
|
+
return doComplexEigs(arr10, N2, prec, type, computeVectors);
|
|
39072
39239
|
}
|
|
39073
|
-
function isSymmetric(arr10,
|
|
39074
|
-
for (let i = 0; i <
|
|
39075
|
-
for (let j = i; j <
|
|
39240
|
+
function isSymmetric(arr10, N2, prec) {
|
|
39241
|
+
for (let i = 0; i < N2; i++) {
|
|
39242
|
+
for (let j = i; j < N2; j++) {
|
|
39076
39243
|
if (larger2(bignumber2(abs2(subtract3(arr10[i][j], arr10[j][i]))), prec)) {
|
|
39077
39244
|
return false;
|
|
39078
39245
|
}
|
|
@@ -39080,9 +39247,9 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
39080
39247
|
}
|
|
39081
39248
|
return true;
|
|
39082
39249
|
}
|
|
39083
|
-
function isReal(arr10,
|
|
39084
|
-
for (let i = 0; i <
|
|
39085
|
-
for (let j = 0; j <
|
|
39250
|
+
function isReal(arr10, N2, prec) {
|
|
39251
|
+
for (let i = 0; i < N2; i++) {
|
|
39252
|
+
for (let j = 0; j < N2; j++) {
|
|
39086
39253
|
if (larger2(bignumber2(abs2(im3(arr10[i][j]))), prec)) {
|
|
39087
39254
|
return false;
|
|
39088
39255
|
}
|
|
@@ -39090,14 +39257,14 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
39090
39257
|
}
|
|
39091
39258
|
return true;
|
|
39092
39259
|
}
|
|
39093
|
-
function coerceReal(arr10,
|
|
39094
|
-
for (let i = 0; i <
|
|
39095
|
-
for (let j = 0; j <
|
|
39260
|
+
function coerceReal(arr10, N2) {
|
|
39261
|
+
for (let i = 0; i < N2; i++) {
|
|
39262
|
+
for (let j = 0; j < N2; j++) {
|
|
39096
39263
|
arr10[i][j] = re3(arr10[i][j]);
|
|
39097
39264
|
}
|
|
39098
39265
|
}
|
|
39099
39266
|
}
|
|
39100
|
-
function coerceTypes(mat, arr10,
|
|
39267
|
+
function coerceTypes(mat, arr10, N2) {
|
|
39101
39268
|
const type = mat.datatype();
|
|
39102
39269
|
if (type === "number" || type === "BigNumber" || type === "Complex") {
|
|
39103
39270
|
return type;
|
|
@@ -39105,8 +39272,8 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
39105
39272
|
let hasNumber = false;
|
|
39106
39273
|
let hasBig = false;
|
|
39107
39274
|
let hasComplex = false;
|
|
39108
|
-
for (let i = 0; i <
|
|
39109
|
-
for (let j = 0; j <
|
|
39275
|
+
for (let i = 0; i < N2; i++) {
|
|
39276
|
+
for (let j = 0; j < N2; j++) {
|
|
39110
39277
|
const el = arr10[i][j];
|
|
39111
39278
|
if (isNumber(el) || isFraction(el)) {
|
|
39112
39279
|
hasNumber = true;
|
|
@@ -39123,24 +39290,24 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
39123
39290
|
console.warn("Complex BigNumbers not supported, this operation will lose precission.");
|
|
39124
39291
|
}
|
|
39125
39292
|
if (hasComplex) {
|
|
39126
|
-
for (let i = 0; i <
|
|
39127
|
-
for (let j = 0; j <
|
|
39293
|
+
for (let i = 0; i < N2; i++) {
|
|
39294
|
+
for (let j = 0; j < N2; j++) {
|
|
39128
39295
|
arr10[i][j] = complex3(arr10[i][j]);
|
|
39129
39296
|
}
|
|
39130
39297
|
}
|
|
39131
39298
|
return "Complex";
|
|
39132
39299
|
}
|
|
39133
39300
|
if (hasBig) {
|
|
39134
|
-
for (let i = 0; i <
|
|
39135
|
-
for (let j = 0; j <
|
|
39301
|
+
for (let i = 0; i < N2; i++) {
|
|
39302
|
+
for (let j = 0; j < N2; j++) {
|
|
39136
39303
|
arr10[i][j] = bignumber2(arr10[i][j]);
|
|
39137
39304
|
}
|
|
39138
39305
|
}
|
|
39139
39306
|
return "BigNumber";
|
|
39140
39307
|
}
|
|
39141
39308
|
if (hasNumber) {
|
|
39142
|
-
for (let i = 0; i <
|
|
39143
|
-
for (let j = 0; j <
|
|
39309
|
+
for (let i = 0; i < N2; i++) {
|
|
39310
|
+
for (let j = 0; j < N2; j++) {
|
|
39144
39311
|
arr10[i][j] = number2(arr10[i][j]);
|
|
39145
39312
|
}
|
|
39146
39313
|
}
|
|
@@ -43418,12 +43585,12 @@ function numericalDerivative(expr, varName, x0, k, h = 1e-4, scope) {
|
|
|
43418
43585
|
return (deriv1 - deriv2) / (2 * h);
|
|
43419
43586
|
}
|
|
43420
43587
|
function taylorCoefficients(expr, varName, x0, n) {
|
|
43421
|
-
const
|
|
43588
|
+
const N2 = Math.max(1 << Math.ceil(Math.log2(2 * (n + 1))), 16);
|
|
43422
43589
|
const r = 0.5;
|
|
43423
|
-
const fRe = new Array(
|
|
43424
|
-
const fIm = new Array(
|
|
43425
|
-
for (let j = 0; j <
|
|
43426
|
-
const ang = 2 * Math.PI * j /
|
|
43590
|
+
const fRe = new Array(N2);
|
|
43591
|
+
const fIm = new Array(N2);
|
|
43592
|
+
for (let j = 0; j < N2; j++) {
|
|
43593
|
+
const ang = 2 * Math.PI * j / N2;
|
|
43427
43594
|
const z = new Complex10(x0 + r * Math.cos(ang), r * Math.sin(ang));
|
|
43428
43595
|
const val = evaluate(expr, { [varName]: z });
|
|
43429
43596
|
if (typeof val === "number") {
|
|
@@ -43437,11 +43604,11 @@ function taylorCoefficients(expr, varName, x0, n) {
|
|
|
43437
43604
|
const a = new Array(n + 1);
|
|
43438
43605
|
for (let k = 0; k <= n; k++) {
|
|
43439
43606
|
let sRe = 0;
|
|
43440
|
-
for (let j = 0; j <
|
|
43441
|
-
const ang = -2 * Math.PI * j * k /
|
|
43607
|
+
for (let j = 0; j < N2; j++) {
|
|
43608
|
+
const ang = -2 * Math.PI * j * k / N2;
|
|
43442
43609
|
sRe += fRe[j] * Math.cos(ang) - fIm[j] * Math.sin(ang);
|
|
43443
43610
|
}
|
|
43444
|
-
a[k] = sRe / (
|
|
43611
|
+
a[k] = sRe / (N2 * Math.pow(r, k));
|
|
43445
43612
|
}
|
|
43446
43613
|
return a;
|
|
43447
43614
|
}
|
|
@@ -43768,10 +43935,10 @@ function inverseLaplace(expr, s, t) {
|
|
|
43768
43935
|
return `L^-1{${trimmed}}(${t})`;
|
|
43769
43936
|
}
|
|
43770
43937
|
function fourierSeries(expr, varName, n) {
|
|
43771
|
-
const
|
|
43772
|
-
const dx = 2 * Math.PI /
|
|
43938
|
+
const N2 = 1e3;
|
|
43939
|
+
const dx = 2 * Math.PI / N2;
|
|
43773
43940
|
let a0Sum = 0;
|
|
43774
|
-
for (let i = 0; i <
|
|
43941
|
+
for (let i = 0; i < N2; i++) {
|
|
43775
43942
|
const x = -Math.PI + i * dx;
|
|
43776
43943
|
a0Sum += evalAt(expr, varName, x);
|
|
43777
43944
|
}
|
|
@@ -43781,7 +43948,7 @@ function fourierSeries(expr, varName, n) {
|
|
|
43781
43948
|
for (let k = 1; k <= n; k++) {
|
|
43782
43949
|
let akSum = 0;
|
|
43783
43950
|
let bkSum = 0;
|
|
43784
|
-
for (let i = 0; i <
|
|
43951
|
+
for (let i = 0; i < N2; i++) {
|
|
43785
43952
|
const x = -Math.PI + i * dx;
|
|
43786
43953
|
const fx = evalAt(expr, varName, x);
|
|
43787
43954
|
akSum += fx * Math.cos(k * x);
|
|
@@ -45231,18 +45398,18 @@ function kroneckerSymbol(a, n) {
|
|
|
45231
45398
|
}
|
|
45232
45399
|
if (nn === 1) return sign3;
|
|
45233
45400
|
let aa = (a % nn + nn) % nn;
|
|
45234
|
-
let
|
|
45401
|
+
let N2 = nn;
|
|
45235
45402
|
let jac = 1;
|
|
45236
45403
|
while (aa !== 0) {
|
|
45237
45404
|
while (aa % 2 === 0) {
|
|
45238
45405
|
aa /= 2;
|
|
45239
|
-
if (
|
|
45406
|
+
if (N2 % 8 === 3 || N2 % 8 === 5) jac = -jac;
|
|
45240
45407
|
}
|
|
45241
|
-
[aa,
|
|
45242
|
-
if (aa % 4 === 3 &&
|
|
45243
|
-
aa = aa %
|
|
45408
|
+
[aa, N2] = [N2, aa];
|
|
45409
|
+
if (aa % 4 === 3 && N2 % 4 === 3) jac = -jac;
|
|
45410
|
+
aa = aa % N2;
|
|
45244
45411
|
}
|
|
45245
|
-
return sign3 * (
|
|
45412
|
+
return sign3 * (N2 === 1 ? jac : 0);
|
|
45246
45413
|
}
|
|
45247
45414
|
function combinationsGen(arr10, k) {
|
|
45248
45415
|
const n = arr10.length;
|
|
@@ -45787,7 +45954,7 @@ function kruskalWallis(...groups) {
|
|
|
45787
45954
|
const arrs = groups.map(arr2).filter((g) => g.length > 0);
|
|
45788
45955
|
if (arrs.length < 2) throw new Error("kruskalWallis: need at least 2 non-empty groups");
|
|
45789
45956
|
const pooled = arrs.flat();
|
|
45790
|
-
const
|
|
45957
|
+
const N2 = pooled.length;
|
|
45791
45958
|
const ranks = rankdata(pooled);
|
|
45792
45959
|
let offset = 0;
|
|
45793
45960
|
let sumRanksSq = 0;
|
|
@@ -45797,8 +45964,8 @@ function kruskalWallis(...groups) {
|
|
|
45797
45964
|
sumRanksSq += rsum * rsum / g.length;
|
|
45798
45965
|
offset += g.length;
|
|
45799
45966
|
}
|
|
45800
|
-
let H = 12 / (
|
|
45801
|
-
const correction = 1 - tieTerm(pooled) / (
|
|
45967
|
+
let H = 12 / (N2 * (N2 + 1)) * sumRanksSq - 3 * (N2 + 1);
|
|
45968
|
+
const correction = 1 - tieTerm(pooled) / (N2 * N2 * N2 - N2);
|
|
45802
45969
|
if (correction !== 0) H /= correction;
|
|
45803
45970
|
const df = arrs.length - 1;
|
|
45804
45971
|
return { statistic: H, pValue: 1 - chiSquaredCDF(H, df), df };
|
|
@@ -45835,8 +46002,8 @@ function fisherExact(table) {
|
|
|
45835
46002
|
const r1 = a + b;
|
|
45836
46003
|
const r2 = c + d;
|
|
45837
46004
|
const c1 = a + c;
|
|
45838
|
-
const
|
|
45839
|
-
const logHyper = (k) => logChoose(r1, k) + logChoose(r2, c1 - k) - logChoose(
|
|
46005
|
+
const N2 = a + b + c + d;
|
|
46006
|
+
const logHyper = (k) => logChoose(r1, k) + logChoose(r2, c1 - k) - logChoose(N2, c1);
|
|
45840
46007
|
const logPObs = logHyper(a);
|
|
45841
46008
|
const lo = Math.max(0, c1 - r2);
|
|
45842
46009
|
const hi = Math.min(r1, c1);
|
|
@@ -45886,8 +46053,8 @@ function tukeyHSD(groups, alpha = 0.05) {
|
|
|
45886
46053
|
const k = gs.length;
|
|
45887
46054
|
if (k < 2) throw new Error("tukeyHSD: need at least 2 groups");
|
|
45888
46055
|
const means = gs.map(mean3);
|
|
45889
|
-
const
|
|
45890
|
-
const dfErr =
|
|
46056
|
+
const N2 = gs.reduce((s, g) => s + g.length, 0);
|
|
46057
|
+
const dfErr = N2 - k;
|
|
45891
46058
|
if (dfErr <= 0)
|
|
45892
46059
|
throw new Error("tukeyHSD: residual df must be > 0 (groups must hold more observations than groups)");
|
|
45893
46060
|
const sse = gs.reduce((s, g) => s + sampleVar(g) * (g.length - 1), 0);
|
|
@@ -45936,9 +46103,9 @@ function triu(A, k = 0) {
|
|
|
45936
46103
|
}
|
|
45937
46104
|
function vander(x, n, increasing = false) {
|
|
45938
46105
|
const v = arr3(x);
|
|
45939
|
-
const
|
|
46106
|
+
const N2 = n ?? v.length;
|
|
45940
46107
|
return v.map(
|
|
45941
|
-
(xi) => Array.from({ length:
|
|
46108
|
+
(xi) => Array.from({ length: N2 }, (_, j) => Math.pow(xi, increasing ? j : N2 - 1 - j))
|
|
45942
46109
|
);
|
|
45943
46110
|
}
|
|
45944
46111
|
function toeplitz(c, r) {
|
|
@@ -47417,7 +47584,7 @@ function maxAbsDiff(A, B) {
|
|
|
47417
47584
|
for (let j = 0; j < m; j++) d = Math.max(d, Math.abs(A[i][j] - B[i][j]));
|
|
47418
47585
|
return d;
|
|
47419
47586
|
}
|
|
47420
|
-
function sylvesterOperator(M,
|
|
47587
|
+
function sylvesterOperator(M, N2) {
|
|
47421
47588
|
const n = M.length;
|
|
47422
47589
|
const n26 = n * n;
|
|
47423
47590
|
const L = zeros3(n26, n26);
|
|
@@ -47428,7 +47595,7 @@ function sylvesterOperator(M, N) {
|
|
|
47428
47595
|
const mip = M[i][p];
|
|
47429
47596
|
if (mip === 0) continue;
|
|
47430
47597
|
for (let q = 0; q < n; q++) {
|
|
47431
|
-
L[row2][p * n + q] = mip *
|
|
47598
|
+
L[row2][p * n + q] = mip * N2[q][j];
|
|
47432
47599
|
}
|
|
47433
47600
|
}
|
|
47434
47601
|
}
|
|
@@ -47703,8 +47870,8 @@ function findSpan(n, p, u, U) {
|
|
|
47703
47870
|
return mid;
|
|
47704
47871
|
}
|
|
47705
47872
|
function basisFuns(span, u, p, U) {
|
|
47706
|
-
const
|
|
47707
|
-
|
|
47873
|
+
const N2 = new Array(p + 1);
|
|
47874
|
+
N2[0] = 1;
|
|
47708
47875
|
const left = new Array(p + 1);
|
|
47709
47876
|
const right = new Array(p + 1);
|
|
47710
47877
|
for (let j = 1; j <= p; j++) {
|
|
@@ -47712,13 +47879,13 @@ function basisFuns(span, u, p, U) {
|
|
|
47712
47879
|
right[j] = U[span + j] - u;
|
|
47713
47880
|
let saved = 0;
|
|
47714
47881
|
for (let r = 0; r < j; r++) {
|
|
47715
|
-
const temp =
|
|
47716
|
-
|
|
47882
|
+
const temp = N2[r] / (right[r + 1] + left[j - r]);
|
|
47883
|
+
N2[r] = saved + right[r + 1] * temp;
|
|
47717
47884
|
saved = left[j - r] * temp;
|
|
47718
47885
|
}
|
|
47719
|
-
|
|
47886
|
+
N2[j] = saved;
|
|
47720
47887
|
}
|
|
47721
|
-
return
|
|
47888
|
+
return N2;
|
|
47722
47889
|
}
|
|
47723
47890
|
function validateXY(x, y) {
|
|
47724
47891
|
if (x.length !== y.length) throw new Error("bsplineFit: x and y must have the same length");
|
|
@@ -47731,8 +47898,8 @@ function buildDesignMatrix(x, t, k, numCoef) {
|
|
|
47731
47898
|
const A = Array.from({ length: n }, () => new Array(numCoef).fill(0));
|
|
47732
47899
|
for (let i = 0; i < n; i++) {
|
|
47733
47900
|
const span = findSpan(numCoef - 1, k, x[i], t);
|
|
47734
|
-
const
|
|
47735
|
-
for (let j = 0; j <= k; j++) A[i][span - k + j] =
|
|
47901
|
+
const N2 = basisFuns(span, x[i], k, t);
|
|
47902
|
+
for (let j = 0; j <= k; j++) A[i][span - k + j] = N2[j];
|
|
47736
47903
|
}
|
|
47737
47904
|
return A;
|
|
47738
47905
|
}
|
|
@@ -47781,9 +47948,9 @@ function bsplineEval(spline, xnew) {
|
|
|
47781
47948
|
const nLast = c.length - 1;
|
|
47782
47949
|
const evalOne = (x) => {
|
|
47783
47950
|
const span = findSpan(nLast, k, x, t);
|
|
47784
|
-
const
|
|
47951
|
+
const N2 = basisFuns(span, x, k, t);
|
|
47785
47952
|
let val = 0;
|
|
47786
|
-
for (let j = 0; j <= k; j++) val +=
|
|
47953
|
+
for (let j = 0; j <= k; j++) val += N2[j] * c[span - k + j];
|
|
47787
47954
|
return val;
|
|
47788
47955
|
};
|
|
47789
47956
|
return Array.isArray(xnew) ? xnew.map(evalOne) : evalOne(xnew);
|
|
@@ -49591,18 +49758,18 @@ function analogToDigital(proto, Wn, btype) {
|
|
|
49591
49758
|
({ z, p, k } = bilinearZpk(z, p, k, fs));
|
|
49592
49759
|
return zpkToTf(z, p, k);
|
|
49593
49760
|
}
|
|
49594
|
-
function buttap(
|
|
49761
|
+
function buttap(N2) {
|
|
49595
49762
|
const p = [];
|
|
49596
|
-
for (let k = 0; k <
|
|
49597
|
-
const m = -
|
|
49598
|
-
const theta = Math.PI * m / (2 *
|
|
49763
|
+
for (let k = 0; k < N2; k++) {
|
|
49764
|
+
const m = -N2 + 1 + 2 * k;
|
|
49765
|
+
const theta = Math.PI * m / (2 * N2);
|
|
49599
49766
|
p.push(new Complex11(-Math.cos(theta), -Math.sin(theta)));
|
|
49600
49767
|
}
|
|
49601
49768
|
return { z: [], p, k: 1 };
|
|
49602
49769
|
}
|
|
49603
|
-
function butter(
|
|
49604
|
-
if (!Number.isInteger(
|
|
49605
|
-
return analogToDigital(buttap(
|
|
49770
|
+
function butter(N2, Wn, btype = "low") {
|
|
49771
|
+
if (!Number.isInteger(N2) || N2 < 1) throw new Error("butter: order N must be a positive integer");
|
|
49772
|
+
return analogToDigital(buttap(N2), Wn, btype);
|
|
49606
49773
|
}
|
|
49607
49774
|
|
|
49608
49775
|
// src/signal/fft.ts
|
|
@@ -49814,39 +49981,39 @@ function jacobiDN(u, m) {
|
|
|
49814
49981
|
|
|
49815
49982
|
// src/signal/iir-design.ts
|
|
49816
49983
|
var arr8 = (x) => Array.isArray(x) ? x : Array.from(x);
|
|
49817
|
-
function cheb1ap(
|
|
49984
|
+
function cheb1ap(N2, rp) {
|
|
49818
49985
|
const eps = Math.sqrt(Math.pow(10, 0.1 * rp) - 1);
|
|
49819
|
-
const mu = 1 /
|
|
49986
|
+
const mu = 1 / N2 * Math.asinh(1 / eps);
|
|
49820
49987
|
const p = [];
|
|
49821
|
-
for (let m = -
|
|
49822
|
-
const theta = Math.PI * m / (2 *
|
|
49988
|
+
for (let m = -N2 + 1; m < N2; m += 2) {
|
|
49989
|
+
const theta = Math.PI * m / (2 * N2);
|
|
49823
49990
|
p.push(new Complex12(-Math.sinh(mu) * Math.cos(theta), -Math.cosh(mu) * Math.sin(theta)));
|
|
49824
49991
|
}
|
|
49825
49992
|
let prod2 = new Complex12(1, 0);
|
|
49826
49993
|
for (const pv of p) prod2 = cMul2(prod2, pv.negate());
|
|
49827
49994
|
let k = prod2.re;
|
|
49828
|
-
if (
|
|
49995
|
+
if (N2 % 2 === 0) k /= Math.sqrt(1 + eps * eps);
|
|
49829
49996
|
return { z: [], p, k };
|
|
49830
49997
|
}
|
|
49831
|
-
function cheby1(
|
|
49832
|
-
if (!Number.isInteger(
|
|
49998
|
+
function cheby1(N2, rp, Wn, btype = "low") {
|
|
49999
|
+
if (!Number.isInteger(N2) || N2 < 1) throw new Error("cheby1: order N must be a positive integer");
|
|
49833
50000
|
if (!(rp > 0)) throw new Error("cheby1: rp (passband ripple, dB) must be positive");
|
|
49834
|
-
return analogToDigital(cheb1ap(
|
|
50001
|
+
return analogToDigital(cheb1ap(N2, rp), Wn, btype);
|
|
49835
50002
|
}
|
|
49836
|
-
function cheb2ap(
|
|
50003
|
+
function cheb2ap(N2, rs) {
|
|
49837
50004
|
const de = 1 / Math.sqrt(Math.pow(10, 0.1 * rs) - 1);
|
|
49838
|
-
const mu = Math.asinh(1 / de) /
|
|
50005
|
+
const mu = Math.asinh(1 / de) / N2;
|
|
49839
50006
|
const mVals = [];
|
|
49840
|
-
if (
|
|
49841
|
-
for (let m = -
|
|
49842
|
-
for (let m = 2; m <
|
|
50007
|
+
if (N2 % 2) {
|
|
50008
|
+
for (let m = -N2 + 1; m < 0; m += 2) mVals.push(m);
|
|
50009
|
+
for (let m = 2; m < N2; m += 2) mVals.push(m);
|
|
49843
50010
|
} else {
|
|
49844
|
-
for (let m = -
|
|
50011
|
+
for (let m = -N2 + 1; m < N2; m += 2) mVals.push(m);
|
|
49845
50012
|
}
|
|
49846
|
-
const z = mVals.map((m) => new Complex12(0, 1 / Math.sin(m * Math.PI / (2 *
|
|
50013
|
+
const z = mVals.map((m) => new Complex12(0, 1 / Math.sin(m * Math.PI / (2 * N2))));
|
|
49847
50014
|
const p = [];
|
|
49848
|
-
for (let m = -
|
|
49849
|
-
const theta = Math.PI * m / (2 *
|
|
50015
|
+
for (let m = -N2 + 1; m < N2; m += 2) {
|
|
50016
|
+
const theta = Math.PI * m / (2 * N2);
|
|
49850
50017
|
const s = new Complex12(Math.sinh(mu) * Math.cos(theta), Math.cosh(mu) * Math.sin(theta));
|
|
49851
50018
|
p.push(cDiv2(new Complex12(1, 0), s).negate());
|
|
49852
50019
|
}
|
|
@@ -49857,17 +50024,17 @@ function cheb2ap(N, rs) {
|
|
|
49857
50024
|
const k = cDiv2(prodP, prodZ).re;
|
|
49858
50025
|
return { z, p, k };
|
|
49859
50026
|
}
|
|
49860
|
-
function cheby2(
|
|
49861
|
-
if (!Number.isInteger(
|
|
50027
|
+
function cheby2(N2, rs, Wn, btype = "low") {
|
|
50028
|
+
if (!Number.isInteger(N2) || N2 < 1) throw new Error("cheby2: order N must be a positive integer");
|
|
49862
50029
|
if (!(rs > 0)) throw new Error("cheby2: rs (stopband attenuation, dB) must be positive");
|
|
49863
|
-
return analogToDigital(cheb2ap(
|
|
50030
|
+
return analogToDigital(cheb2ap(N2, rs), Wn, btype);
|
|
49864
50031
|
}
|
|
49865
50032
|
var ELLIPDEG_MMAX = 7;
|
|
49866
|
-
function ellipdeg(
|
|
50033
|
+
function ellipdeg(N2, m1) {
|
|
49867
50034
|
const K1 = ellipticKScalar(m1);
|
|
49868
50035
|
const K1p = ellipticKScalar(1 - m1);
|
|
49869
50036
|
const q1 = Math.exp(-Math.PI * K1p / K1);
|
|
49870
|
-
const q = Math.pow(q1, 1 /
|
|
50037
|
+
const q = Math.pow(q1, 1 / N2);
|
|
49871
50038
|
let num2 = 0;
|
|
49872
50039
|
for (let i = 0; i <= ELLIPDEG_MMAX; i++) num2 += Math.pow(q, i * (i + 1));
|
|
49873
50040
|
let den = 1;
|
|
@@ -49918,8 +50085,8 @@ function arcJacSc1(w, m) {
|
|
|
49918
50085
|
throw new Error("ellip: elliptic filter design failed to converge (arcJacSc1)");
|
|
49919
50086
|
return z.im;
|
|
49920
50087
|
}
|
|
49921
|
-
function ellipap(
|
|
49922
|
-
if (
|
|
50088
|
+
function ellipap(N2, rp, rs) {
|
|
50089
|
+
if (N2 === 1) {
|
|
49923
50090
|
const p = -Math.sqrt(1 / (Math.pow(10, 0.1 * rp) - 1));
|
|
49924
50091
|
return { z: [], p: [new Complex12(p, 0)], k: -p };
|
|
49925
50092
|
}
|
|
@@ -49928,16 +50095,16 @@ function ellipap(N, rp, rs) {
|
|
|
49928
50095
|
const ck1Sq = epsSq / (Math.pow(10, 0.1 * rs) - 1);
|
|
49929
50096
|
if (ck1Sq <= 0) throw new Error("ellip: cannot design a filter with the given rp/rs");
|
|
49930
50097
|
const val0 = ellipticKScalar(ck1Sq);
|
|
49931
|
-
const m = ellipdeg(
|
|
50098
|
+
const m = ellipdeg(N2, ck1Sq);
|
|
49932
50099
|
const capk = ellipticKScalar(m);
|
|
49933
50100
|
const j = [];
|
|
49934
|
-
for (let v = 1 -
|
|
50101
|
+
for (let v = 1 - N2 % 2; v < N2; v += 2) j.push(v);
|
|
49935
50102
|
const EPSILON = 2e-16;
|
|
49936
50103
|
const s = [];
|
|
49937
50104
|
const c = [];
|
|
49938
50105
|
const d = [];
|
|
49939
50106
|
for (const jv of j) {
|
|
49940
|
-
const u = jv * capk /
|
|
50107
|
+
const u = jv * capk / N2;
|
|
49941
50108
|
s.push(jacobiSN(u, m));
|
|
49942
50109
|
c.push(jacobiCN(u, m));
|
|
49943
50110
|
d.push(jacobiDN(u, m));
|
|
@@ -49948,7 +50115,7 @@ function ellipap(N, rp, rs) {
|
|
|
49948
50115
|
}
|
|
49949
50116
|
const zFull = zHalf.concat(zHalf.map((zv) => new Complex12(zv.re, -zv.im)));
|
|
49950
50117
|
const rr = arcJacSc1(1 / eps, ck1Sq);
|
|
49951
|
-
const v0 = capk * rr / (
|
|
50118
|
+
const v0 = capk * rr / (N2 * val0);
|
|
49952
50119
|
const sv = jacobiSN(v0, 1 - m);
|
|
49953
50120
|
const cv = jacobiCN(v0, 1 - m);
|
|
49954
50121
|
const dv = jacobiDN(v0, 1 - m);
|
|
@@ -49959,7 +50126,7 @@ function ellipap(N, rp, rs) {
|
|
|
49959
50126
|
pHalf.push(new Complex12(num2.re / den, num2.im / den));
|
|
49960
50127
|
}
|
|
49961
50128
|
let pFull;
|
|
49962
|
-
if (
|
|
50129
|
+
if (N2 % 2) {
|
|
49963
50130
|
const sumP2 = pHalf.reduce((acc, pv) => acc + pv.re * pv.re + pv.im * pv.im, 0);
|
|
49964
50131
|
const thresh = EPSILON * Math.sqrt(sumP2);
|
|
49965
50132
|
const newp = pHalf.filter((pv) => Math.abs(pv.im) > thresh);
|
|
@@ -49972,14 +50139,14 @@ function ellipap(N, rp, rs) {
|
|
|
49972
50139
|
let prodZ = new Complex12(1, 0);
|
|
49973
50140
|
for (const zv of zFull) prodZ = cMul2(prodZ, zv.negate());
|
|
49974
50141
|
let k = cDiv2(prodP, prodZ).re;
|
|
49975
|
-
if (
|
|
50142
|
+
if (N2 % 2 === 0) k /= Math.sqrt(1 + epsSq);
|
|
49976
50143
|
return { z: zFull, p: pFull, k };
|
|
49977
50144
|
}
|
|
49978
|
-
function ellip(
|
|
49979
|
-
if (!Number.isInteger(
|
|
50145
|
+
function ellip(N2, rp, rs, Wn, btype = "low") {
|
|
50146
|
+
if (!Number.isInteger(N2) || N2 < 1) throw new Error("ellip: order N must be a positive integer");
|
|
49980
50147
|
if (!(rp > 0)) throw new Error("ellip: rp (passband ripple, dB) must be positive");
|
|
49981
50148
|
if (!(rs > 0)) throw new Error("ellip: rs (stopband attenuation, dB) must be positive");
|
|
49982
|
-
return analogToDigital(ellipap(
|
|
50149
|
+
return analogToDigital(ellipap(N2, rp, rs), Wn, btype);
|
|
49983
50150
|
}
|
|
49984
50151
|
function polyMul2(p, q) {
|
|
49985
50152
|
const res = new Array(p.length + q.length - 1).fill(0);
|
|
@@ -50007,7 +50174,7 @@ function bilinear(bIn, aIn, fs) {
|
|
|
50007
50174
|
const aTrim = trimLeadingZeros(arr8(aIn));
|
|
50008
50175
|
const Q2 = bTrim.length - 1;
|
|
50009
50176
|
const P2 = aTrim.length - 1;
|
|
50010
|
-
const
|
|
50177
|
+
const N2 = Math.max(P2, Q2);
|
|
50011
50178
|
const kappa = 2 * fs;
|
|
50012
50179
|
const zp1 = [1, 1];
|
|
50013
50180
|
const zm1 = [-kappa, kappa];
|
|
@@ -50016,7 +50183,7 @@ function bilinear(bIn, aIn, fs) {
|
|
|
50016
50183
|
const bq = bTrim[Q2 - q];
|
|
50017
50184
|
numerator = polyAdd2(
|
|
50018
50185
|
numerator,
|
|
50019
|
-
polyMul2(polyPow2(zp1,
|
|
50186
|
+
polyMul2(polyPow2(zp1, N2 - q), polyPow2(zm1, q)).map((v) => v * bq)
|
|
50020
50187
|
);
|
|
50021
50188
|
}
|
|
50022
50189
|
let denominator = [0];
|
|
@@ -50024,7 +50191,7 @@ function bilinear(bIn, aIn, fs) {
|
|
|
50024
50191
|
const ap = aTrim[P2 - p];
|
|
50025
50192
|
denominator = polyAdd2(
|
|
50026
50193
|
denominator,
|
|
50027
|
-
polyMul2(polyPow2(zp1,
|
|
50194
|
+
polyMul2(polyPow2(zp1, N2 - p), polyPow2(zm1, p)).map((v) => v * ap)
|
|
50028
50195
|
);
|
|
50029
50196
|
}
|
|
50030
50197
|
const bDesc = numerator.slice().reverse();
|
|
@@ -50165,23 +50332,23 @@ function buttord(wp, ws, gpass, gstop) {
|
|
|
50165
50332
|
const nat1 = (stopb[1] * stopb[1] - passb[0] * passb[1]) / (stopb[1] * (passb[0] - passb[1]));
|
|
50166
50333
|
nat = Math.min(Math.abs(nat0), Math.abs(nat1));
|
|
50167
50334
|
}
|
|
50168
|
-
const
|
|
50169
|
-
const W0 = Math.pow(GPASS - 1, -1 / (2 *
|
|
50335
|
+
const N2 = Math.ceil(Math.log10((GSTOP - 1) / (GPASS - 1)) / (2 * Math.log10(nat)));
|
|
50336
|
+
const W0 = Math.pow(GPASS - 1, -1 / (2 * N2));
|
|
50170
50337
|
const toDigital = (WN) => Math.atan(WN) * 2 / Math.PI;
|
|
50171
|
-
if (filterType === 1) return { N, Wn: toDigital(W0 * passb[0]) };
|
|
50172
|
-
if (filterType === 2) return { N, Wn: toDigital(passb[0] / W0) };
|
|
50338
|
+
if (filterType === 1) return { N: N2, Wn: toDigital(W0 * passb[0]) };
|
|
50339
|
+
if (filterType === 2) return { N: N2, Wn: toDigital(passb[0] / W0) };
|
|
50173
50340
|
if (filterType === 3) {
|
|
50174
50341
|
const discr = Math.sqrt(Math.pow(passb[1] - passb[0], 2) + 4 * W0 * W0 * passb[0] * passb[1]);
|
|
50175
50342
|
const wn0 = (passb[1] - passb[0] + discr) / (2 * W0);
|
|
50176
50343
|
const wn1 = (passb[1] - passb[0] - discr) / (2 * W0);
|
|
50177
50344
|
const sorted2 = [Math.abs(wn0), Math.abs(wn1)].sort((x, y) => x - y);
|
|
50178
|
-
return { N, Wn: [toDigital(sorted2[0]), toDigital(sorted2[1])] };
|
|
50345
|
+
return { N: N2, Wn: [toDigital(sorted2[0]), toDigital(sorted2[1])] };
|
|
50179
50346
|
}
|
|
50180
50347
|
const w0s = [-W0, W0].map(
|
|
50181
50348
|
(s) => -s * ((passb[1] - passb[0]) / 2) + Math.sqrt(s * s / 4 * Math.pow(passb[1] - passb[0], 2) + passb[0] * passb[1])
|
|
50182
50349
|
);
|
|
50183
50350
|
const sorted = w0s.map(Math.abs).sort((x, y) => x - y);
|
|
50184
|
-
return { N, Wn: [toDigital(sorted[0]), toDigital(sorted[1])] };
|
|
50351
|
+
return { N: N2, Wn: [toDigital(sorted[0]), toDigital(sorted[1])] };
|
|
50185
50352
|
}
|
|
50186
50353
|
function toComplex(x) {
|
|
50187
50354
|
return x instanceof Complex12 ? x : new Complex12(x, 0);
|
|
@@ -50924,13 +51091,13 @@ function savgol(x, windowLength, polyorder) {
|
|
|
50924
51091
|
function deconvolve(signal, divisor) {
|
|
50925
51092
|
const s = arr9(signal);
|
|
50926
51093
|
const d = arr9(divisor);
|
|
50927
|
-
const
|
|
51094
|
+
const N2 = s.length;
|
|
50928
51095
|
const D = d.length;
|
|
50929
51096
|
if (D === 0) throw new Error("deconvolve: divisor must be non-empty");
|
|
50930
51097
|
if (d[0] === 0) throw new Error("deconvolve: divisor[0] (leading coefficient) must be nonzero");
|
|
50931
|
-
if (D >
|
|
51098
|
+
if (D > N2) return { quotient: [], remainder: s.slice() };
|
|
50932
51099
|
const remainder = s.slice();
|
|
50933
|
-
const quotient = new Array(
|
|
51100
|
+
const quotient = new Array(N2 - D + 1).fill(0);
|
|
50934
51101
|
for (let i = 0; i < quotient.length; i++) {
|
|
50935
51102
|
const c = remainder[i] / d[0];
|
|
50936
51103
|
quotient[i] = c;
|
|
@@ -52015,7 +52182,7 @@ function cochranQ(data) {
|
|
|
52015
52182
|
if (k < 2) throw new Error("cochranQ: need at least 2 treatments (columns)");
|
|
52016
52183
|
const colSums = new Array(k).fill(0);
|
|
52017
52184
|
const rowSums = new Array(n).fill(0);
|
|
52018
|
-
let
|
|
52185
|
+
let N2 = 0;
|
|
52019
52186
|
for (let i = 0; i < n; i++) {
|
|
52020
52187
|
if (data[i].length !== k) throw new Error("cochranQ: data must be rectangular");
|
|
52021
52188
|
let rowSum = 0;
|
|
@@ -52024,15 +52191,15 @@ function cochranQ(data) {
|
|
|
52024
52191
|
rowSum += data[i][j];
|
|
52025
52192
|
}
|
|
52026
52193
|
rowSums[i] = rowSum;
|
|
52027
|
-
|
|
52194
|
+
N2 += rowSum;
|
|
52028
52195
|
}
|
|
52029
52196
|
let sumC2 = 0;
|
|
52030
52197
|
for (let j = 0; j < k; j++) sumC2 += colSums[j] * colSums[j];
|
|
52031
52198
|
let sumR2 = 0;
|
|
52032
52199
|
for (let i = 0; i < n; i++) sumR2 += rowSums[i] * rowSums[i];
|
|
52033
52200
|
const dof = k - 1;
|
|
52034
|
-
const denominator = k *
|
|
52035
|
-
const Q2 = denominator !== 0 ? dof * (k * sumC2 -
|
|
52201
|
+
const denominator = k * N2 - sumR2;
|
|
52202
|
+
const Q2 = denominator !== 0 ? dof * (k * sumC2 - N2 * N2) / denominator : 0;
|
|
52036
52203
|
const pValue = 1 - chiSquaredCDF(Q2, dof);
|
|
52037
52204
|
return { Q: Q2, pValue, dof };
|
|
52038
52205
|
}
|
|
@@ -52515,6 +52682,106 @@ function coulombFG(L, eta, rho) {
|
|
|
52515
52682
|
return coulombSteed(L, eta, rho);
|
|
52516
52683
|
}
|
|
52517
52684
|
|
|
52685
|
+
// src/special/mathieu.ts
|
|
52686
|
+
import { eig as eig4 } from "@danielsimonjr/mathts-matrix";
|
|
52687
|
+
var N = 50;
|
|
52688
|
+
function harmonicsFor(cls) {
|
|
52689
|
+
const h = new Int32Array(N);
|
|
52690
|
+
for (let k = 0; k < N; k++) {
|
|
52691
|
+
switch (cls) {
|
|
52692
|
+
case "even-cos":
|
|
52693
|
+
h[k] = 2 * k;
|
|
52694
|
+
break;
|
|
52695
|
+
case "odd-cos":
|
|
52696
|
+
case "odd-sin":
|
|
52697
|
+
h[k] = 2 * k + 1;
|
|
52698
|
+
break;
|
|
52699
|
+
case "even-sin":
|
|
52700
|
+
h[k] = 2 * k + 2;
|
|
52701
|
+
break;
|
|
52702
|
+
}
|
|
52703
|
+
}
|
|
52704
|
+
return h;
|
|
52705
|
+
}
|
|
52706
|
+
function buildMatrix(cls, q) {
|
|
52707
|
+
const A = Array.from({ length: N }, () => new Array(N).fill(0));
|
|
52708
|
+
const h = harmonicsFor(cls);
|
|
52709
|
+
for (let k = 0; k < N; k++) A[k][k] = h[k] * h[k];
|
|
52710
|
+
if (cls === "odd-cos") A[0][0] = 1 + q;
|
|
52711
|
+
else if (cls === "odd-sin") A[0][0] = 1 - q;
|
|
52712
|
+
for (let k = 0; k < N - 1; k++) {
|
|
52713
|
+
const off = cls === "even-cos" && k === 0 ? q * Math.SQRT2 : q;
|
|
52714
|
+
A[k][k + 1] = off;
|
|
52715
|
+
A[k + 1][k] = off;
|
|
52716
|
+
}
|
|
52717
|
+
return A;
|
|
52718
|
+
}
|
|
52719
|
+
var modeCache = /* @__PURE__ */ new Map();
|
|
52720
|
+
function solveClass(cls, q) {
|
|
52721
|
+
const key = `${cls}:${q}`;
|
|
52722
|
+
const cached = modeCache.get(key);
|
|
52723
|
+
if (cached) return cached;
|
|
52724
|
+
const harmonics = harmonicsFor(cls);
|
|
52725
|
+
const { values, vectors } = eig4(buildMatrix(cls, q));
|
|
52726
|
+
const order = values.map((_, i) => i).sort((i, j) => values[i].re - values[j].re);
|
|
52727
|
+
const modes = order.map((idx, m) => {
|
|
52728
|
+
const g = vectors[idx];
|
|
52729
|
+
const coeffs = new Float64Array(N);
|
|
52730
|
+
if (cls === "even-cos") {
|
|
52731
|
+
coeffs[0] = g[0];
|
|
52732
|
+
for (let k = 1; k < N; k++) coeffs[k] = Math.SQRT2 * g[k];
|
|
52733
|
+
} else {
|
|
52734
|
+
for (let k = 0; k < N; k++) coeffs[k] = g[k];
|
|
52735
|
+
}
|
|
52736
|
+
let norm28 = 0;
|
|
52737
|
+
for (let k = 0; k < N; k++) {
|
|
52738
|
+
const w = cls === "even-cos" && k === 0 ? 2 : 1;
|
|
52739
|
+
norm28 += w * coeffs[k] * coeffs[k];
|
|
52740
|
+
}
|
|
52741
|
+
const scale4 = 1 / Math.sqrt(norm28);
|
|
52742
|
+
const sign3 = coeffs[m] < 0 ? -scale4 : scale4;
|
|
52743
|
+
for (let k = 0; k < N; k++) coeffs[k] *= sign3;
|
|
52744
|
+
return { a: values[idx].re, coeffs, harmonics };
|
|
52745
|
+
});
|
|
52746
|
+
modeCache.set(key, modes);
|
|
52747
|
+
return modes;
|
|
52748
|
+
}
|
|
52749
|
+
function checkOrder(n, min2, name254) {
|
|
52750
|
+
if (!Number.isInteger(n) || n < min2) {
|
|
52751
|
+
throw new Error(`${name254}: order n must be an integer \u2265 ${min2}, got ${n}`);
|
|
52752
|
+
}
|
|
52753
|
+
}
|
|
52754
|
+
function mathieuA(n, q) {
|
|
52755
|
+
checkOrder(n, 0, "mathieuA");
|
|
52756
|
+
const cls = n % 2 === 0 ? "even-cos" : "odd-cos";
|
|
52757
|
+
const m = Math.floor(n / 2);
|
|
52758
|
+
return solveClass(cls, q)[m].a;
|
|
52759
|
+
}
|
|
52760
|
+
function mathieuB(n, q) {
|
|
52761
|
+
checkOrder(n, 1, "mathieuB");
|
|
52762
|
+
const cls = n % 2 === 0 ? "even-sin" : "odd-sin";
|
|
52763
|
+
const m = Math.floor((n - (n % 2 === 0 ? 2 : 1)) / 2);
|
|
52764
|
+
return solveClass(cls, q)[m].a;
|
|
52765
|
+
}
|
|
52766
|
+
function evalSeries(mode2, x, basis) {
|
|
52767
|
+
let s = 0;
|
|
52768
|
+
const { coeffs, harmonics } = mode2;
|
|
52769
|
+
for (let k = 0; k < N; k++) s += coeffs[k] * basis(harmonics[k] * x);
|
|
52770
|
+
return s;
|
|
52771
|
+
}
|
|
52772
|
+
function mathieuCe(n, q, x) {
|
|
52773
|
+
checkOrder(n, 0, "mathieuCe");
|
|
52774
|
+
const cls = n % 2 === 0 ? "even-cos" : "odd-cos";
|
|
52775
|
+
const m = Math.floor(n / 2);
|
|
52776
|
+
return evalSeries(solveClass(cls, q)[m], x, Math.cos);
|
|
52777
|
+
}
|
|
52778
|
+
function mathieuSe(n, q, x) {
|
|
52779
|
+
checkOrder(n, 1, "mathieuSe");
|
|
52780
|
+
const cls = n % 2 === 0 ? "even-sin" : "odd-sin";
|
|
52781
|
+
const m = Math.floor((n - (n % 2 === 0 ? 2 : 1)) / 2);
|
|
52782
|
+
return evalSeries(solveClass(cls, q)[m], x, Math.sin);
|
|
52783
|
+
}
|
|
52784
|
+
|
|
52518
52785
|
// src/graph/traversal-centrality.ts
|
|
52519
52786
|
function bfs(adj, start) {
|
|
52520
52787
|
const n = adj.length;
|
|
@@ -54345,6 +54612,10 @@ export {
|
|
|
54345
54612
|
mannWhitneyTest,
|
|
54346
54613
|
map2 as map,
|
|
54347
54614
|
mapSlices,
|
|
54615
|
+
mathieuA,
|
|
54616
|
+
mathieuB,
|
|
54617
|
+
mathieuCe,
|
|
54618
|
+
mathieuSe,
|
|
54348
54619
|
matmul,
|
|
54349
54620
|
matrix,
|
|
54350
54621
|
matrixExpm,
|
|
@@ -54641,6 +54912,7 @@ export {
|
|
|
54641
54912
|
solveBVP,
|
|
54642
54913
|
solveBanded,
|
|
54643
54914
|
solveDAE,
|
|
54915
|
+
solveDDE,
|
|
54644
54916
|
solveODE,
|
|
54645
54917
|
solveODESystem,
|
|
54646
54918
|
solvePDE,
|