@woosh/meep-engine 2.135.1 → 2.138.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/package.json +1 -1
- package/src/core/geom/2d/aabb/aabb2_intersects_ray.d.ts.map +1 -1
- package/src/core/geom/2d/aabb/aabb2_intersects_ray.js +5 -7
- package/src/core/geom/2d/hash-grid/shg_query_elements_circle.d.ts.map +1 -1
- package/src/core/geom/2d/hash-grid/shg_query_elements_circle.js +2 -3
- package/src/core/geom/3d/aabb/aabb3_intersects_line_segment.d.ts.map +1 -1
- package/src/core/geom/3d/aabb/aabb3_intersects_line_segment.js +9 -11
- package/src/core/geom/3d/tetrahedra/tetrahedron_compute_circumsphere.d.ts.map +1 -1
- package/src/core/geom/3d/tetrahedra/tetrahedron_compute_circumsphere.js +6 -4
- package/src/core/geom/3d/topology/simplify/quadratic/Quadric3.d.ts.map +1 -1
- package/src/core/geom/3d/topology/simplify/quadratic/Quadric3.js +1 -2
- package/src/core/geom/packing/miniball/Miniball.d.ts.map +1 -1
- package/src/core/geom/packing/miniball/Miniball.js +4 -11
- package/src/core/geom/packing/miniball/Subspan.d.ts +14 -39
- package/src/core/geom/packing/miniball/Subspan.d.ts.map +1 -1
- package/src/core/geom/packing/miniball/Subspan.js +105 -158
- package/src/core/geom/packing/miniball/miniball_compute_quality.d.ts.map +1 -1
- package/src/core/geom/packing/miniball/miniball_compute_quality.js +2 -6
- package/src/core/geom/vec/vector_axpy.d.ts +12 -0
- package/src/core/geom/vec/vector_axpy.d.ts.map +1 -0
- package/src/core/geom/vec/vector_axpy.js +15 -0
- package/src/core/geom/vec/vector_axpy_offset.d.ts +17 -0
- package/src/core/geom/vec/vector_axpy_offset.d.ts.map +1 -0
- package/src/core/geom/vec/vector_axpy_offset.js +20 -0
- package/src/core/geom/vec/vector_dot_offset.d.ts +18 -0
- package/src/core/geom/vec/vector_dot_offset.d.ts.map +1 -0
- package/src/core/geom/vec/vector_dot_offset.js +25 -0
- package/src/core/math/complex/complex_horner_eval.d.ts +2 -2
- package/src/core/math/complex/complex_horner_eval.d.ts.map +1 -1
- package/src/core/math/complex/complex_horner_eval.js +4 -1
- package/src/core/math/fabsf.d.ts +2 -3
- package/src/core/math/fabsf.d.ts.map +1 -1
- package/src/core/math/fabsf.js +3 -5
- package/src/core/math/linalg/cubic_residual_times_derivative_accumulate.d.ts +26 -0
- package/src/core/math/linalg/cubic_residual_times_derivative_accumulate.d.ts.map +1 -0
- package/src/core/math/linalg/cubic_residual_times_derivative_accumulate.js +43 -0
- package/src/core/math/linalg/eigen/matrix_eigenvalues_in_place.d.ts +2 -1
- package/src/core/math/linalg/eigen/matrix_eigenvalues_in_place.d.ts.map +1 -1
- package/src/core/math/linalg/eigen/matrix_eigenvalues_in_place.js +2 -1
- package/src/core/math/linalg/eigen/matrix_householder_in_place.d.ts +10 -4
- package/src/core/math/linalg/eigen/matrix_householder_in_place.d.ts.map +1 -1
- package/src/core/math/linalg/eigen/matrix_householder_in_place.js +122 -98
- package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts +2 -2
- package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts.map +1 -1
- package/src/core/math/linalg/eigen/matrix_qr_in_place.js +144 -124
- package/src/core/math/linalg/givens/givens_apply_rows.d.ts +22 -0
- package/src/core/math/linalg/givens/givens_apply_rows.d.ts.map +1 -0
- package/src/core/math/linalg/givens/givens_apply_rows.js +28 -0
- package/src/core/math/linalg/givens/givens_apply_rows_offset.d.ts +24 -0
- package/src/core/math/linalg/givens/givens_apply_rows_offset.d.ts.map +1 -0
- package/src/core/math/linalg/givens/givens_apply_rows_offset.js +30 -0
- package/src/core/math/linalg/givens/givens_rotation_coefficients.d.ts +25 -0
- package/src/core/math/linalg/givens/givens_rotation_coefficients.d.ts.map +1 -0
- package/src/core/math/linalg/givens/givens_rotation_coefficients.js +39 -0
- package/src/core/math/linalg/lu_factor_linear_system.d.ts +1 -1
- package/src/core/math/linalg/lu_factor_linear_system.d.ts.map +1 -1
- package/src/core/math/linalg/lu_factor_linear_system.js +108 -117
- package/src/core/math/linalg/lu_solve_linear_system.d.ts +1 -1
- package/src/core/math/linalg/lu_solve_linear_system.js +53 -53
- package/src/core/math/linalg/polynomial_add_into.d.ts +18 -0
- package/src/core/math/linalg/polynomial_add_into.d.ts.map +1 -0
- package/src/core/math/linalg/polynomial_add_into.js +29 -0
- package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.d.ts +6 -1
- package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.d.ts.map +1 -1
- package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.js +19 -12
- package/src/core/math/linalg/polynomial_cubic_derivative_eval.d.ts +15 -0
- package/src/core/math/linalg/polynomial_cubic_derivative_eval.d.ts.map +1 -0
- package/src/core/math/linalg/polynomial_cubic_derivative_eval.js +16 -0
- package/src/core/math/linalg/polynomial_cubic_horner_eval.d.ts +18 -0
- package/src/core/math/linalg/polynomial_cubic_horner_eval.d.ts.map +1 -0
- package/src/core/math/linalg/polynomial_cubic_horner_eval.js +19 -0
- package/src/core/math/linalg/polynomial_cubic_second_derivative_eval.d.ts +13 -0
- package/src/core/math/linalg/polynomial_cubic_second_derivative_eval.d.ts.map +1 -0
- package/src/core/math/linalg/polynomial_cubic_second_derivative_eval.js +14 -0
- package/src/core/math/linalg/polynomial_multiply.d.ts +21 -0
- package/src/core/math/linalg/polynomial_multiply.d.ts.map +1 -0
- package/src/core/math/linalg/polynomial_multiply.js +41 -0
- package/src/core/math/linalg/polynomial_real_roots_in_interval.d.ts +6 -1
- package/src/core/math/linalg/polynomial_real_roots_in_interval.d.ts.map +1 -1
- package/src/core/math/linalg/polynomial_real_roots_in_interval.js +9 -2
- package/src/core/math/linalg/polynomial_scale_into.d.ts +14 -0
- package/src/core/math/linalg/polynomial_scale_into.d.ts.map +1 -0
- package/src/core/math/linalg/polynomial_scale_into.js +17 -0
- package/src/core/math/linalg/polynomial_sub_into.d.ts +18 -0
- package/src/core/math/linalg/polynomial_sub_into.d.ts.map +1 -0
- package/src/core/math/linalg/polynomial_sub_into.js +29 -0
- package/src/core/math/linalg/solve_linear_system.d.ts +1 -1
- package/src/core/math/linalg/solve_linear_system.js +1 -1
- package/src/core/math/linalg/solve_linear_system_GEPP_2x2.d.ts +4 -4
- package/src/core/math/linalg/solve_linear_system_GEPP_2x2.d.ts.map +1 -1
- package/src/core/math/linalg/solve_linear_system_GEPP_2x2.js +96 -91
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.d.ts +18 -10
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.d.ts.map +1 -1
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.js +18 -10
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.d.ts +13 -6
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.d.ts.map +1 -1
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.js +16 -11
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts +25 -3
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts.map +1 -1
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.js +78 -135
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.d.ts +30 -4
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.d.ts.map +1 -1
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.js +188 -132
- package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.d.ts +7 -3
- package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.d.ts.map +1 -1
- package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.js +35 -6
- package/src/engine/graphics/geometry/MikkT/CalcTexArea.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/CalcTexArea.js +1 -2
- package/src/engine/graphics/geometry/MikkT/InitTriInfo.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/InitTriInfo.js +6 -7
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies a Givens rotation (c, s) to two row vectors in place:
|
|
3
|
+
*
|
|
4
|
+
* row_i' = c * row_i + s * row_j
|
|
5
|
+
* row_j' = -s * row_i + c * row_j
|
|
6
|
+
*
|
|
7
|
+
* Each row is treated as a length-n vector and rotated element-by-element.
|
|
8
|
+
*
|
|
9
|
+
* Accepts plain arrays or typed arrays. The two row arguments can be
|
|
10
|
+
* standalone arrays or subarray views into a larger flat matrix — useful
|
|
11
|
+
* for row-major QR/Hessenberg maintenance where the matrix is a single
|
|
12
|
+
* Float64Array and the caller hands in `M.subarray(i*n, (i+1)*n)` and
|
|
13
|
+
* `M.subarray(j*n, (j+1)*n)`.
|
|
14
|
+
*
|
|
15
|
+
* @param {Float64Array|number[]} row_i length >= n
|
|
16
|
+
* @param {Float64Array|number[]} row_j length >= n
|
|
17
|
+
* @param {number} c
|
|
18
|
+
* @param {number} s
|
|
19
|
+
* @param {number} n number of elements to rotate
|
|
20
|
+
*/
|
|
21
|
+
export function givens_apply_rows(row_i, row_j, c, s, n) {
|
|
22
|
+
for (let i = 0; i < n; ++i) {
|
|
23
|
+
const a = row_i[i];
|
|
24
|
+
const b = row_j[i];
|
|
25
|
+
row_i[i] = c * a + s * b;
|
|
26
|
+
row_j[i] = c * b - s * a;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies a Givens rotation (c, s) to two length-n vectors stored in the
|
|
3
|
+
* same flat buffer at the given offsets. In-place:
|
|
4
|
+
*
|
|
5
|
+
* v_i' = c * v_i + s * v_j
|
|
6
|
+
* v_j' = -s * v_i + c * v_j
|
|
7
|
+
*
|
|
8
|
+
* Naming reflects the original use case (rotating two rows of a matrix),
|
|
9
|
+
* but the helper is layout-agnostic: pass the offsets to two rows of a
|
|
10
|
+
* row-major matrix, or to two columns of a column-major matrix — anything
|
|
11
|
+
* where the pair of vectors lives in a single buffer.
|
|
12
|
+
*
|
|
13
|
+
* Avoids the header allocation that `.subarray(...)` would cost on every
|
|
14
|
+
* call when this is invoked inside a tight QR-update loop.
|
|
15
|
+
*
|
|
16
|
+
* @param {Float64Array|Float32Array|number[]} buf flat buffer holding both vectors
|
|
17
|
+
* @param {number} off_i starting offset of the first vector
|
|
18
|
+
* @param {number} off_j starting offset of the second vector
|
|
19
|
+
* @param {number} c
|
|
20
|
+
* @param {number} s
|
|
21
|
+
* @param {number} n number of elements to rotate
|
|
22
|
+
*/
|
|
23
|
+
export function givens_apply_rows_offset(buf: Float64Array | Float32Array | number[], off_i: number, off_j: number, c: number, s: number, n: number): void;
|
|
24
|
+
//# sourceMappingURL=givens_apply_rows_offset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"givens_apply_rows_offset.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/linalg/givens/givens_apply_rows_offset.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,8CAPW,YAAY,GAAC,YAAY,GAAC,MAAM,EAAE,SAClC,MAAM,SACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,QAShB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies a Givens rotation (c, s) to two length-n vectors stored in the
|
|
3
|
+
* same flat buffer at the given offsets. In-place:
|
|
4
|
+
*
|
|
5
|
+
* v_i' = c * v_i + s * v_j
|
|
6
|
+
* v_j' = -s * v_i + c * v_j
|
|
7
|
+
*
|
|
8
|
+
* Naming reflects the original use case (rotating two rows of a matrix),
|
|
9
|
+
* but the helper is layout-agnostic: pass the offsets to two rows of a
|
|
10
|
+
* row-major matrix, or to two columns of a column-major matrix — anything
|
|
11
|
+
* where the pair of vectors lives in a single buffer.
|
|
12
|
+
*
|
|
13
|
+
* Avoids the header allocation that `.subarray(...)` would cost on every
|
|
14
|
+
* call when this is invoked inside a tight QR-update loop.
|
|
15
|
+
*
|
|
16
|
+
* @param {Float64Array|Float32Array|number[]} buf flat buffer holding both vectors
|
|
17
|
+
* @param {number} off_i starting offset of the first vector
|
|
18
|
+
* @param {number} off_j starting offset of the second vector
|
|
19
|
+
* @param {number} c
|
|
20
|
+
* @param {number} s
|
|
21
|
+
* @param {number} n number of elements to rotate
|
|
22
|
+
*/
|
|
23
|
+
export function givens_apply_rows_offset(buf, off_i, off_j, c, s, n) {
|
|
24
|
+
for (let i = 0; i < n; ++i) {
|
|
25
|
+
const a = buf[off_i + i];
|
|
26
|
+
const b = buf[off_j + i];
|
|
27
|
+
buf[off_i + i] = c * a + s * b;
|
|
28
|
+
buf[off_j + i] = c * b - s * a;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the Givens rotation coefficients (c, s) such that
|
|
3
|
+
*
|
|
4
|
+
* [ c s ] [ a ] [ r ]
|
|
5
|
+
* [ -s c ] [ b ] = [ 0 ]
|
|
6
|
+
*
|
|
7
|
+
* with c^2 + s^2 = 1 (so the matrix is a proper rotation).
|
|
8
|
+
*
|
|
9
|
+
* Signs are not pinned down — `r` may be either +sqrt(a^2 + b^2) or its
|
|
10
|
+
* negation depending on the branch taken. Callers that care about the sign
|
|
11
|
+
* of `r` must apply the rotation explicitly and read the rotated value.
|
|
12
|
+
*
|
|
13
|
+
* Writes c to out[0] and s to out[1]. Designed to take an out-param rather
|
|
14
|
+
* than return an object: returning a freshly-allocated {c, s} pair would
|
|
15
|
+
* cost an allocation per call, which matters when this is invoked inside a
|
|
16
|
+
* tight QR-update loop.
|
|
17
|
+
*
|
|
18
|
+
* Source: Golub & Van Loan, Matrix Computations 2nd ed., p. 216.
|
|
19
|
+
*
|
|
20
|
+
* @param {number} a
|
|
21
|
+
* @param {number} b
|
|
22
|
+
* @param {Float64Array|number[]} out length >= 2; receives [c, s]
|
|
23
|
+
*/
|
|
24
|
+
export function givens_rotation_coefficients(a: number, b: number, out: Float64Array | number[]): void;
|
|
25
|
+
//# sourceMappingURL=givens_rotation_coefficients.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"givens_rotation_coefficients.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/linalg/givens/givens_rotation_coefficients.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,gDAJW,MAAM,KACN,MAAM,OACN,YAAY,GAAC,MAAM,EAAE,QAiB/B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the Givens rotation coefficients (c, s) such that
|
|
3
|
+
*
|
|
4
|
+
* [ c s ] [ a ] [ r ]
|
|
5
|
+
* [ -s c ] [ b ] = [ 0 ]
|
|
6
|
+
*
|
|
7
|
+
* with c^2 + s^2 = 1 (so the matrix is a proper rotation).
|
|
8
|
+
*
|
|
9
|
+
* Signs are not pinned down — `r` may be either +sqrt(a^2 + b^2) or its
|
|
10
|
+
* negation depending on the branch taken. Callers that care about the sign
|
|
11
|
+
* of `r` must apply the rotation explicitly and read the rotated value.
|
|
12
|
+
*
|
|
13
|
+
* Writes c to out[0] and s to out[1]. Designed to take an out-param rather
|
|
14
|
+
* than return an object: returning a freshly-allocated {c, s} pair would
|
|
15
|
+
* cost an allocation per call, which matters when this is invoked inside a
|
|
16
|
+
* tight QR-update loop.
|
|
17
|
+
*
|
|
18
|
+
* Source: Golub & Van Loan, Matrix Computations 2nd ed., p. 216.
|
|
19
|
+
*
|
|
20
|
+
* @param {number} a
|
|
21
|
+
* @param {number} b
|
|
22
|
+
* @param {Float64Array|number[]} out length >= 2; receives [c, s]
|
|
23
|
+
*/
|
|
24
|
+
export function givens_rotation_coefficients(a, b, out) {
|
|
25
|
+
if (b === 0.0) {
|
|
26
|
+
out[0] = 1.0;
|
|
27
|
+
out[1] = 0.0;
|
|
28
|
+
} else if (Math.abs(b) > Math.abs(a)) {
|
|
29
|
+
const t = a / b;
|
|
30
|
+
const s = 1 / Math.sqrt(1 + t * t);
|
|
31
|
+
out[0] = s * t;
|
|
32
|
+
out[1] = s;
|
|
33
|
+
} else {
|
|
34
|
+
const t = b / a;
|
|
35
|
+
const c = 1 / Math.sqrt(1 + t * t);
|
|
36
|
+
out[0] = c;
|
|
37
|
+
out[1] = c * t;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Output factorization LU is in matrix A.
|
|
5
5
|
* If error is found, method returns false.
|
|
6
6
|
*
|
|
7
|
-
* @param {number[]} A Square matrix,
|
|
7
|
+
* @param {number[]} A Square matrix, column-major flat layout (A[j*size + i] = element at row i, col j); modified in place to hold the LU factorization
|
|
8
8
|
* @param {number[]|Uint32Array} index will be written to
|
|
9
9
|
* @param {number} size Size of the matrix ( 4x4 matrix has size 4 )
|
|
10
10
|
* @returns {boolean} true if factorization succeeded, false otherwise
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lu_factor_linear_system.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/linalg/lu_factor_linear_system.js"],"names":[],"mappings":"AAYA;;;;;;;;;;GAUG;AACH,2CALW,MAAM,EAAE,SACR,MAAM,EAAE,GAAC,WAAW,QACpB,MAAM,GACJ,OAAO,
|
|
1
|
+
{"version":3,"file":"lu_factor_linear_system.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/linalg/lu_factor_linear_system.js"],"names":[],"mappings":"AAYA;;;;;;;;;;GAUG;AACH,2CALW,MAAM,EAAE,SACR,MAAM,EAAE,GAAC,WAAW,QACpB,MAAM,GACJ,OAAO,CAsFnB"}
|
|
@@ -1,117 +1,108 @@
|
|
|
1
|
-
import { assert } from "../../assert.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Error bound during calculations, must be something reasonably large to avoid floating point rounding errors
|
|
5
|
-
* @type {number}
|
|
6
|
-
*/
|
|
7
|
-
const SMALL_NUMBER = 1e-12;
|
|
8
|
-
|
|
9
|
-
const SCRATCH_SIZE = 16;
|
|
10
|
-
// avoid allocation for smaller systems by using a scratch
|
|
11
|
-
const scratch = new Float64Array(SCRATCH_SIZE);
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Factor linear equations Ax = b using LU decomposition A = LU where L is lower triangular matrix and U is upper triangular matrix.
|
|
15
|
-
* Input is square matrix A, integer array of pivot indices index[0->n-1], and size of square matrix n.
|
|
16
|
-
* Output factorization LU is in matrix A.
|
|
17
|
-
* If error is found, method returns false.
|
|
18
|
-
*
|
|
19
|
-
* @param {number[]} A Square matrix,
|
|
20
|
-
* @param {number[]|Uint32Array} index will be written to
|
|
21
|
-
* @param {number} size Size of the matrix ( 4x4 matrix has size 4 )
|
|
22
|
-
* @returns {boolean} true if factorization succeeded, false otherwise
|
|
23
|
-
*/
|
|
24
|
-
export function lu_factor_linear_system(A, index, size) {
|
|
25
|
-
assert.isNonNegativeInteger(size,'size');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
for (i =
|
|
66
|
-
sum = A[
|
|
67
|
-
for (k = 0; k <
|
|
68
|
-
sum -= A[
|
|
69
|
-
}
|
|
70
|
-
A[
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
maxI =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
temp1 = 1.0 / A[j * size + j];
|
|
110
|
-
for (i = j + 1; i < size; ++i) {
|
|
111
|
-
A[i * size + j] *= temp1;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
1
|
+
import { assert } from "../../assert.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error bound during calculations, must be something reasonably large to avoid floating point rounding errors
|
|
5
|
+
* @type {number}
|
|
6
|
+
*/
|
|
7
|
+
const SMALL_NUMBER = 1e-12;
|
|
8
|
+
|
|
9
|
+
const SCRATCH_SIZE = 16;
|
|
10
|
+
// avoid allocation for smaller systems by using a scratch
|
|
11
|
+
const scratch = new Float64Array(SCRATCH_SIZE);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Factor linear equations Ax = b using LU decomposition A = LU where L is lower triangular matrix and U is upper triangular matrix.
|
|
15
|
+
* Input is square matrix A, integer array of pivot indices index[0->n-1], and size of square matrix n.
|
|
16
|
+
* Output factorization LU is in matrix A.
|
|
17
|
+
* If error is found, method returns false.
|
|
18
|
+
*
|
|
19
|
+
* @param {number[]} A Square matrix, column-major flat layout (A[j*size + i] = element at row i, col j); modified in place to hold the LU factorization
|
|
20
|
+
* @param {number[]|Uint32Array} index will be written to
|
|
21
|
+
* @param {number} size Size of the matrix ( 4x4 matrix has size 4 )
|
|
22
|
+
* @returns {boolean} true if factorization succeeded, false otherwise
|
|
23
|
+
*/
|
|
24
|
+
export function lu_factor_linear_system(A, index, size) {
|
|
25
|
+
assert.isNonNegativeInteger(size,'size');
|
|
26
|
+
|
|
27
|
+
let i, j, k;
|
|
28
|
+
let maxI = 0;
|
|
29
|
+
let largest, temp1, temp2, sum;
|
|
30
|
+
|
|
31
|
+
const scale = size <= SCRATCH_SIZE ? scratch : new Float64Array(size);
|
|
32
|
+
|
|
33
|
+
// Loop over rows to get implicit scaling information
|
|
34
|
+
//
|
|
35
|
+
for (i = 0; i < size; ++i) {
|
|
36
|
+
for (largest = 0.0, j = 0; j < size; ++j) {
|
|
37
|
+
if ((temp2 = Math.abs(A[j * size + i])) > largest) {
|
|
38
|
+
largest = temp2;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (largest === 0.0) {
|
|
43
|
+
// Unable to factor linear system
|
|
44
|
+
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
scale[i] = 1.0 / largest;
|
|
48
|
+
}
|
|
49
|
+
//
|
|
50
|
+
// Loop over all columns using Crout's method
|
|
51
|
+
//
|
|
52
|
+
for (j = 0; j < size; ++j) {
|
|
53
|
+
const jOff = j * size;
|
|
54
|
+
|
|
55
|
+
for (i = 0; i < j; ++i) {
|
|
56
|
+
sum = A[jOff + i];
|
|
57
|
+
for (k = 0; k < i; ++k) {
|
|
58
|
+
sum -= A[k * size + i] * A[jOff + k];
|
|
59
|
+
}
|
|
60
|
+
A[jOff + i] = sum;
|
|
61
|
+
}
|
|
62
|
+
//
|
|
63
|
+
// Begin search for largest pivot element
|
|
64
|
+
//
|
|
65
|
+
for (largest = 0.0, i = j; i < size; ++i) {
|
|
66
|
+
sum = A[jOff + i];
|
|
67
|
+
for (k = 0; k < j; ++k) {
|
|
68
|
+
sum -= A[k * size + i] * A[jOff + k];
|
|
69
|
+
}
|
|
70
|
+
A[jOff + i] = sum;
|
|
71
|
+
|
|
72
|
+
if ((temp1 = scale[i] * Math.abs(sum)) >= largest) {
|
|
73
|
+
largest = temp1;
|
|
74
|
+
maxI = i;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//
|
|
78
|
+
// Check for row interchange
|
|
79
|
+
//
|
|
80
|
+
if (j !== maxI) {
|
|
81
|
+
for (k = 0; k < size; ++k) {
|
|
82
|
+
const kOff = k * size;
|
|
83
|
+
temp1 = A[kOff + maxI];
|
|
84
|
+
A[kOff + maxI] = A[kOff + j];
|
|
85
|
+
A[kOff + j] = temp1;
|
|
86
|
+
}
|
|
87
|
+
scale[maxI] = scale[j];
|
|
88
|
+
}
|
|
89
|
+
//
|
|
90
|
+
// Divide by pivot element and perform elimination
|
|
91
|
+
//
|
|
92
|
+
index[j] = maxI;
|
|
93
|
+
|
|
94
|
+
if (Math.abs(A[jOff + j]) <= SMALL_NUMBER) {
|
|
95
|
+
// Unable to factor linear system
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (j !== (size - 1)) {
|
|
100
|
+
temp1 = 1.0 / A[jOff + j];
|
|
101
|
+
for (i = j + 1; i < size; ++i) {
|
|
102
|
+
A[jOff + i] *= temp1;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Note that A=LU and index[] are generated from method LUFactorLinearSystem.
|
|
6
6
|
* Also, solution vector is written directly over input load vector.
|
|
7
7
|
*
|
|
8
|
-
* @param {number[]} A Square matrix (
|
|
8
|
+
* @param {number[]} A Square matrix, column-major flat layout (pre-factored LU as produced by lu_factor_linear_system)
|
|
9
9
|
* @param {number[]|Uint32Array} index
|
|
10
10
|
* @param {number[]} x Load vector
|
|
11
11
|
* @param {number} size matrix size ( 4x4 matrix has size 4)
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { assert } from "../../assert.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Assumes the system is factorized already. Use {@link lu_factor_linear_system} before if it isn't
|
|
5
|
-
* Solve linear equations Ax = b using LU decomposition A = LU where L is lower triangular matrix and U is upper triangular matrix.
|
|
6
|
-
* Input is factored matrix A=LU, integer array of pivot indices index[0->n-1], load vector x[0->n-1], and size of square matrix n.
|
|
7
|
-
* Note that A=LU and index[] are generated from method LUFactorLinearSystem.
|
|
8
|
-
* Also, solution vector is written directly over input load vector.
|
|
9
|
-
*
|
|
10
|
-
* @param {number[]} A Square matrix (
|
|
11
|
-
* @param {number[]|Uint32Array} index
|
|
12
|
-
* @param {number[]} x Load vector
|
|
13
|
-
* @param {number} size matrix size ( 4x4 matrix has size 4)
|
|
14
|
-
*/
|
|
15
|
-
export function lu_solve_linear_system(A, index, x, size) {
|
|
16
|
-
assert.isNonNegativeInteger(size, 'size');
|
|
17
|
-
|
|
18
|
-
let i = 0, j, ii = -1;
|
|
19
|
-
|
|
20
|
-
let sum;
|
|
21
|
-
|
|
22
|
-
// Proceed with forward and back-substitution for L and U matrices.
|
|
23
|
-
|
|
24
|
-
// First, forward substitution.
|
|
25
|
-
for (; i < size; ++i) {
|
|
26
|
-
const idx = index[i];
|
|
27
|
-
sum = x[idx];
|
|
28
|
-
x[idx] = x[i];
|
|
29
|
-
|
|
30
|
-
if (ii >= 0) {
|
|
31
|
-
|
|
32
|
-
for (j = ii; j <= i - 1; ++j) {
|
|
33
|
-
sum -= A[
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
} else if (sum !== 0.0) {
|
|
37
|
-
ii = i;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
x[i] = sum;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Now, back substitution
|
|
44
|
-
for (i = size - 1; i >= 0; i--) {
|
|
45
|
-
sum = x[i];
|
|
46
|
-
|
|
47
|
-
for (j = i + 1; j < size; ++j) {
|
|
48
|
-
sum -= A[
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
x[i] = sum / A[i * size + i];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
import { assert } from "../../assert.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Assumes the system is factorized already. Use {@link lu_factor_linear_system} before if it isn't
|
|
5
|
+
* Solve linear equations Ax = b using LU decomposition A = LU where L is lower triangular matrix and U is upper triangular matrix.
|
|
6
|
+
* Input is factored matrix A=LU, integer array of pivot indices index[0->n-1], load vector x[0->n-1], and size of square matrix n.
|
|
7
|
+
* Note that A=LU and index[] are generated from method LUFactorLinearSystem.
|
|
8
|
+
* Also, solution vector is written directly over input load vector.
|
|
9
|
+
*
|
|
10
|
+
* @param {number[]} A Square matrix, column-major flat layout (pre-factored LU as produced by lu_factor_linear_system)
|
|
11
|
+
* @param {number[]|Uint32Array} index
|
|
12
|
+
* @param {number[]} x Load vector
|
|
13
|
+
* @param {number} size matrix size ( 4x4 matrix has size 4)
|
|
14
|
+
*/
|
|
15
|
+
export function lu_solve_linear_system(A, index, x, size) {
|
|
16
|
+
assert.isNonNegativeInteger(size, 'size');
|
|
17
|
+
|
|
18
|
+
let i = 0, j, ii = -1;
|
|
19
|
+
|
|
20
|
+
let sum;
|
|
21
|
+
|
|
22
|
+
// Proceed with forward and back-substitution for L and U matrices.
|
|
23
|
+
|
|
24
|
+
// First, forward substitution.
|
|
25
|
+
for (; i < size; ++i) {
|
|
26
|
+
const idx = index[i];
|
|
27
|
+
sum = x[idx];
|
|
28
|
+
x[idx] = x[i];
|
|
29
|
+
|
|
30
|
+
if (ii >= 0) {
|
|
31
|
+
|
|
32
|
+
for (j = ii; j <= i - 1; ++j) {
|
|
33
|
+
sum -= A[j * size + i] * x[j];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
} else if (sum !== 0.0) {
|
|
37
|
+
ii = i;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
x[i] = sum;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Now, back substitution
|
|
44
|
+
for (i = size - 1; i >= 0; i--) {
|
|
45
|
+
sum = x[i];
|
|
46
|
+
|
|
47
|
+
for (j = i + 1; j < size; ++j) {
|
|
48
|
+
sum -= A[j * size + i] * x[j];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
x[i] = sum / A[i * size + i];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds polynomial `a` into `target` in place.
|
|
3
|
+
*
|
|
4
|
+
* target(x) := target(x) + a(x)
|
|
5
|
+
*
|
|
6
|
+
* Coefficient layout: index i is the coefficient of x^i (ascending). If
|
|
7
|
+
* `a_len > target_len`, the excess coefficients in `target` at indices
|
|
8
|
+
* [target_len, a_len) are first cleared to zero, so the returned length
|
|
9
|
+
* (max of the two input lengths) reflects valid coefficients.
|
|
10
|
+
*
|
|
11
|
+
* @param {number[]|Float64Array|Float32Array} target receives the sum, length >= max(target_len, a_len)
|
|
12
|
+
* @param {number} target_len current number of coefficients in target
|
|
13
|
+
* @param {number[]|Float64Array|Float32Array} a
|
|
14
|
+
* @param {number} a_len number of coefficients in a
|
|
15
|
+
* @returns {number} new logical length of target = max(target_len, a_len)
|
|
16
|
+
*/
|
|
17
|
+
export function polynomial_add_into(target: number[] | Float64Array | Float32Array, target_len: number, a: number[] | Float64Array | Float32Array, a_len: number): number;
|
|
18
|
+
//# sourceMappingURL=polynomial_add_into.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polynomial_add_into.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/linalg/polynomial_add_into.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,4CANW,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,cAClC,MAAM,KACN,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,SAClC,MAAM,GACJ,MAAM,CAclB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds polynomial `a` into `target` in place.
|
|
3
|
+
*
|
|
4
|
+
* target(x) := target(x) + a(x)
|
|
5
|
+
*
|
|
6
|
+
* Coefficient layout: index i is the coefficient of x^i (ascending). If
|
|
7
|
+
* `a_len > target_len`, the excess coefficients in `target` at indices
|
|
8
|
+
* [target_len, a_len) are first cleared to zero, so the returned length
|
|
9
|
+
* (max of the two input lengths) reflects valid coefficients.
|
|
10
|
+
*
|
|
11
|
+
* @param {number[]|Float64Array|Float32Array} target receives the sum, length >= max(target_len, a_len)
|
|
12
|
+
* @param {number} target_len current number of coefficients in target
|
|
13
|
+
* @param {number[]|Float64Array|Float32Array} a
|
|
14
|
+
* @param {number} a_len number of coefficients in a
|
|
15
|
+
* @returns {number} new logical length of target = max(target_len, a_len)
|
|
16
|
+
*/
|
|
17
|
+
export function polynomial_add_into(target, target_len, a, a_len) {
|
|
18
|
+
const n = a_len > target_len ? a_len : target_len;
|
|
19
|
+
|
|
20
|
+
for (let i = target_len; i < n; i++) {
|
|
21
|
+
target[i] = 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < a_len; i++) {
|
|
25
|
+
target[i] += a[i];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return n;
|
|
29
|
+
}
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
* @param {Float64Array|number[]} roots_re real parts, length ≥ offset + degree
|
|
15
15
|
* @param {Float64Array|number[]} roots_im imaginary parts, length ≥ offset + degree
|
|
16
16
|
* @param {number} offset
|
|
17
|
+
* @param {number} [max_iterations=80] outer iteration cap. Lower values
|
|
18
|
+
* trade worst-case convergence accuracy for speed; the per-iteration
|
|
19
|
+
* convergence check still fires early in the common case. A low cap
|
|
20
|
+
* (~24-32) is appropriate for well-conditioned low-degree polynomials
|
|
21
|
+
* where Aberth typically converges in 15-25 iterations.
|
|
17
22
|
*/
|
|
18
|
-
export function polynomial_complex_roots_aberth_ehrlich(coeffs: Float64Array | number[], degree: number, roots_re: Float64Array | number[], roots_im: Float64Array | number[], offset: number): void;
|
|
23
|
+
export function polynomial_complex_roots_aberth_ehrlich(coeffs: Float64Array | number[], degree: number, roots_re: Float64Array | number[], roots_im: Float64Array | number[], offset: number, max_iterations?: number): void;
|
|
19
24
|
//# sourceMappingURL=polynomial_complex_roots_aberth_ehrlich.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polynomial_complex_roots_aberth_ehrlich.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"polynomial_complex_roots_aberth_ehrlich.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.js"],"names":[],"mappings":"AA8BA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,gEAXW,YAAY,GAAC,MAAM,EAAE,UACrB,MAAM,YACN,YAAY,GAAC,MAAM,EAAE,YACrB,YAAY,GAAC,MAAM,EAAE,UACrB,MAAM,mBACN,MAAM,QAgHhB"}
|