@ac-kit/math-linear 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/README.md +63 -7
  3. package/dist/_euclidean-norm.d.ts +18 -0
  4. package/dist/_euclidean-norm.d.ts.map +1 -0
  5. package/dist/_euclidean-norm.js +73 -0
  6. package/dist/_euclidean-norm.js.map +1 -0
  7. package/dist/_invert.d.ts +209 -14
  8. package/dist/_invert.d.ts.map +1 -1
  9. package/dist/_invert.js +869 -33
  10. package/dist/_invert.js.map +1 -1
  11. package/dist/_matrix-shape.d.ts +4 -0
  12. package/dist/_matrix-shape.d.ts.map +1 -0
  13. package/dist/_matrix-shape.js +7 -0
  14. package/dist/_matrix-shape.js.map +1 -0
  15. package/dist/_slerp.d.ts +14 -0
  16. package/dist/_slerp.d.ts.map +1 -1
  17. package/dist/_slerp.js +56 -0
  18. package/dist/_slerp.js.map +1 -1
  19. package/dist/affine2.d.ts +17 -5
  20. package/dist/affine2.d.ts.map +1 -1
  21. package/dist/affine2.js +96 -34
  22. package/dist/affine2.js.map +1 -1
  23. package/dist/affine3.d.ts +17 -4
  24. package/dist/affine3.d.ts.map +1 -1
  25. package/dist/affine3.js +134 -60
  26. package/dist/affine3.js.map +1 -1
  27. package/dist/index.d.ts +5 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +5 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/lu-decomposition.d.ts +142 -0
  32. package/dist/lu-decomposition.d.ts.map +1 -0
  33. package/dist/lu-decomposition.js +416 -0
  34. package/dist/lu-decomposition.js.map +1 -0
  35. package/dist/mat2x2.d.ts +16 -4
  36. package/dist/mat2x2.d.ts.map +1 -1
  37. package/dist/mat2x2.js +76 -33
  38. package/dist/mat2x2.js.map +1 -1
  39. package/dist/mat3x3.d.ts +27 -5
  40. package/dist/mat3x3.d.ts.map +1 -1
  41. package/dist/mat3x3.js +71 -34
  42. package/dist/mat3x3.js.map +1 -1
  43. package/dist/mat4x4.d.ts +34 -8
  44. package/dist/mat4x4.d.ts.map +1 -1
  45. package/dist/mat4x4.js +180 -56
  46. package/dist/mat4x4.js.map +1 -1
  47. package/dist/matrix.d.ts +136 -0
  48. package/dist/matrix.d.ts.map +1 -0
  49. package/dist/matrix.js +308 -0
  50. package/dist/matrix.js.map +1 -0
  51. package/dist/projection.d.ts +16 -1
  52. package/dist/projection.d.ts.map +1 -1
  53. package/dist/projection.js +49 -0
  54. package/dist/projection.js.map +1 -1
  55. package/dist/qr-decomposition.d.ts +283 -0
  56. package/dist/qr-decomposition.d.ts.map +1 -0
  57. package/dist/qr-decomposition.js +1071 -0
  58. package/dist/qr-decomposition.js.map +1 -0
  59. package/dist/quaternion.d.ts +6 -4
  60. package/dist/quaternion.d.ts.map +1 -1
  61. package/dist/quaternion.js +8 -50
  62. package/dist/quaternion.js.map +1 -1
  63. package/dist/singular-value-decomposition.d.ts +154 -0
  64. package/dist/singular-value-decomposition.d.ts.map +1 -0
  65. package/dist/singular-value-decomposition.js +474 -0
  66. package/dist/singular-value-decomposition.js.map +1 -0
  67. package/dist/symmetric-eigen-decomposition.d.ts +92 -0
  68. package/dist/symmetric-eigen-decomposition.d.ts.map +1 -0
  69. package/dist/symmetric-eigen-decomposition.js +289 -0
  70. package/dist/symmetric-eigen-decomposition.js.map +1 -0
  71. package/dist/vec2-array-componentwise.d.ts +18 -0
  72. package/dist/vec2-array-componentwise.d.ts.map +1 -1
  73. package/dist/vec2-array-componentwise.js +48 -0
  74. package/dist/vec2-array-componentwise.js.map +1 -1
  75. package/dist/vec2-array.d.ts +16 -0
  76. package/dist/vec2-array.d.ts.map +1 -1
  77. package/dist/vec2-array.js +42 -0
  78. package/dist/vec2-array.js.map +1 -1
  79. package/dist/vec3-array-componentwise.d.ts +18 -0
  80. package/dist/vec3-array-componentwise.d.ts.map +1 -1
  81. package/dist/vec3-array-componentwise.js +52 -0
  82. package/dist/vec3-array-componentwise.js.map +1 -1
  83. package/dist/vec3.d.ts +5 -5
  84. package/dist/vec3.d.ts.map +1 -1
  85. package/dist/vec3.js +39 -13
  86. package/dist/vec3.js.map +1 -1
  87. package/dist/vec4-array-componentwise.d.ts +43 -0
  88. package/dist/vec4-array-componentwise.d.ts.map +1 -1
  89. package/dist/vec4-array-componentwise.js +120 -0
  90. package/dist/vec4-array-componentwise.js.map +1 -1
  91. package/dist/vec4.d.ts +4 -2
  92. package/dist/vec4.d.ts.map +1 -1
  93. package/dist/vec4.js +6 -29
  94. package/dist/vec4.js.map +1 -1
  95. package/package.json +11 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,152 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5c203e7: Dense matrices of any size and their least-squares decomposition.
8
+
9
+ - `Matrix`: `{ data, rows, columns }`, `rows · columns` entries in one
10
+ `Float64Array`, column-major like the fixed sizes (row `r`, column `c` at
11
+ `rows · c + r`). `matrixCreate`, `matrixView` (over existing storage, no
12
+ copy), `matrixOfRows`, `matrixGet`, `matrixSet`, `matrixCopy`,
13
+ `matrixIdentity`, `matrixTranspose`, `matrixMultiply`,
14
+ `matrixMultiplyVector`, `matrixTransposeMultiplyVector`, `matrixEquals`,
15
+ `matrixIsClose`, `matrixIsFinite`. `out` first, no allocation; a
16
+ `RangeError` for mismatched shapes, a `data` of the wrong length, an index
17
+ outside the matrix, or an `out` sharing storage with an input.
18
+ - `QrDecomposition(rows, columns)`: Householder QR with column pivoting
19
+ (LAPACK `xGEQP3`), reused across matrices of one shape and allocating
20
+ nothing after its constructor. `decompose(matrix, { weights, rankTolerance })`
21
+ factorises `√W·A` and decides the numerical `rank` by incremental condition
22
+ estimation (`xGELSY`), reporting `pivots` (independent columns first) and
23
+ `reciprocalCondition`; `false`, rank `0` and `NaN` results for a non-finite
24
+ entry, any finite magnitude scaled exactly by powers of two.
25
+ `solve(out, b, "basic" | "minimum-norm")` gives the weighted least-squares
26
+ coefficients — aliased ones `0`, or the minimum-norm answer by a complete
27
+ orthogonal decomposition — and `residualSumOfSquares`;
28
+ `covariance(out, { scale, solution })` gives `scale · (AᵀWA)⁻¹` (`NaN` on
29
+ aliased columns) or `scale · (AᵀWA)⁺`; `leverages(out)` the hat-matrix
30
+ diagonal; `applyQ`, `applyQTranspose`, `q`, `r` the factors. O(m·n·min(m, n))
31
+ to decompose, O(m·min(m, n) + rank²) to solve.
32
+ - 5c203e7: `vec2ArrayFindNearestXyAffine2(points, transform, x, y, maxDistance?)` finds
33
+ the point whose image under an affine transform is nearest to `(x, y)`, in one
34
+ pass and without transforming the buffer: the same answer, tie for tie, as
35
+ `vec2ArrayFindNearestXy` over the transformed points. A hit test of data-space
36
+ points under a view that just moved.
37
+ - 5c203e7: - `LuDecomposition(size)`: LU with partial pivoting as a reusable plan —
38
+ `decompose`, `solve`, `determinant`, `singular`, `pivots` and
39
+ `reciprocalCondition` (the 1-norm estimate of LAPACK `xGECON`).
40
+ - `matrixSolve(matrix, right)` solves a square system and returns the solution
41
+ with its reciprocal condition estimate.
42
+ - `CholeskyDecomposition(size)`: `A = L·Lᵀ` for symmetric positive-definite
43
+ matrices — `decompose` (`false` when not positive definite), `solve`,
44
+ `factor` and `logDeterminant`.
45
+ - 5c203e7: `SingularValueDecomposition(rows, columns)`: the thin SVD `A = U·diag(σ)·Vᵀ`
46
+ of any `Matrix` shape by one-sided Jacobi, as a plan allocating nothing after
47
+ construction. `decompose` (`false` on a non-finite entry), `singularValues`
48
+ (descending, small ones to high relative accuracy for column-graded matrices),
49
+ `u` and `v` with orthonormal columns (completed for zero singular values),
50
+ `rank`, `conditionNumber`, `solve` (minimum-norm least squares) and
51
+ `pseudoInverse`, truncated at `rcond · σ₀` (default `max(rows, columns) · ε`,
52
+ NumPy's).
53
+
54
+ ### Patch Changes
55
+
56
+ - Updated dependencies [5c203e7]
57
+ - Updated dependencies [5c203e7]
58
+ - Updated dependencies [5c203e7]
59
+ - Updated dependencies [5c203e7]
60
+ - Updated dependencies [5c203e7]
61
+ - Updated dependencies [5c203e7]
62
+ - Updated dependencies [5c203e7]
63
+ - Updated dependencies [5c203e7]
64
+ - Updated dependencies [5c203e7]
65
+ - Updated dependencies [5c203e7]
66
+ - @ac-kit/core@0.14.0
67
+ - @ac-kit/math-complex@0.3.0
68
+ - @ac-kit/math-scalar@0.5.0
69
+
70
+ ## 0.4.0
71
+
72
+ ### Minor Changes
73
+
74
+ - 0b4fe43: `mat4x4ConvertDepthRange(out, matrix, from, to)` re-expresses a projection
75
+ built for one `DepthRange` in another: the `x`, `y` and `w` rows are copied and
76
+ the depth row maps the near and far planes of `from` to those of `to`, with
77
+ exact coefficients (one rounding per depth-row element). A GL-style
78
+ `"negative-one-to-one"` projection then draws under WebGPU's `"zero-to-one"`
79
+ clip depth, and a forward projection turns reversed. `out` may be `matrix`; an
80
+ unknown range throws a `RangeError` and leaves `out` untouched.
81
+ - 0b4fe43: Add `vec2ArraySplitStrided`, `vec3ArraySplitStrided` and `vec4ArraySplitStrided`: one pass that writes each binary64 number as two binary32 parts into an interleaved buffer, `high = fround(x)` and `low = fround(x − high)` at their own offsets, with no allocation; the parts of one element must not overlap each other or another element's. `vec4ArrayNarrowRelative` and `vec4ArrayNarrowRelativeStrided` now exist too (an origin of four components, for boxes stored as two corners).
82
+
83
+ ### Patch Changes
84
+
85
+ - 0b4fe43: Wide-range inputs no longer fail or lose their result.
86
+
87
+ - `quaternionSlerp` and `vec4Slerp` take their angle from the tangent part, so
88
+ a tiny rotation extrapolated by a huge `t` stays on the unit sphere (`1e-16`
89
+ rad at `t = 1e16` gives the quaternion half a radian on) and a rounding off
90
+ the unit sphere does not grow with `t`. `vec3Slerp` between exact antipodes of
91
+ different lengths interpolates the lengths and turns on a perpendicular arc,
92
+ keeps a pair a rounding away from opposite in its own plane, and slerps
93
+ vectors of magnitude `1e±200`.
94
+ - `mat2x2Invert`, `mat3x3Invert`, `mat4x4Invert`, `affine2Invert` and
95
+ `affine3Invert` invert every matrix whose inverse is representable, however
96
+ widely its entries span (`diag(1e160, 1e160, 1e-160)`, scales of `2^600` with
97
+ a translation of `Number.MAX_VALUE`) and however its cofactors cancel: `false`
98
+ means singular, or an inverse entry beyond `Number.MAX_VALUE` once rounded,
99
+ never a loss to rounding, and `true` is never a rounding artefact
100
+ (`diag(2^-1024, 4237)` is refused). A nearly singular matrix is no longer
101
+ inverted from a rounding residue: its determinant is kept within `2^-41` of
102
+ itself, or its inverse is computed by a backward-stable elimination. A
103
+ well-conditioned matrix gives the same result as before, at about 1.4× its
104
+ former cost for a 4 × 4 view matrix. Inversion allocates nothing, except for
105
+ a matrix of condition number beyond about `2^52`, an inverse that overflows
106
+ or comes within its error bound of overflowing, or a matrix whose scaling
107
+ rounds an entry.
108
+ - Each translation component of an affine inverse is within `2^-41` of `−B · t`
109
+ for the inverse linear part `B`, and correctly rounded whenever plain
110
+ arithmetic cannot guarantee that (a linear part whose inverse starts with
111
+ `(1, 1, 1)` and a translation of `Number.MAX_VALUE`, `1` and
112
+ `-Number.MAX_VALUE` give `-1`, not `0`). Whether an affine inverse overflows
113
+ follows the exact translation `−A⁻¹ · t`, as for the equivalent homogeneous
114
+ matrix: an x scale of `161/256` with an x translation of `161 · 2^1016` is
115
+ refused, and a translation whose `−B · t` overflows while the exact one fits
116
+ is inverted.
117
+ - Updated dependencies [0b4fe43]
118
+ - Updated dependencies [0b4fe43]
119
+ - Updated dependencies [0b4fe43]
120
+ - Updated dependencies [0b4fe43]
121
+ - Updated dependencies [0b4fe43]
122
+ - Updated dependencies [0b4fe43]
123
+ - Updated dependencies [0b4fe43]
124
+ - Updated dependencies [0b4fe43]
125
+ - Updated dependencies [0b4fe43]
126
+ - Updated dependencies [0b4fe43]
127
+ - Updated dependencies [0b4fe43]
128
+ - Updated dependencies [0b4fe43]
129
+ - Updated dependencies [0b4fe43]
130
+ - Updated dependencies [0b4fe43]
131
+ - Updated dependencies [0b4fe43]
132
+ - Updated dependencies [0b4fe43]
133
+ - Updated dependencies [0b4fe43]
134
+ - Updated dependencies [0b4fe43]
135
+ - Updated dependencies [0b4fe43]
136
+ - Updated dependencies [0b4fe43]
137
+ - Updated dependencies [0b4fe43]
138
+ - Updated dependencies [0b4fe43]
139
+ - Updated dependencies [0b4fe43]
140
+ - Updated dependencies [0b4fe43]
141
+ - Updated dependencies [0b4fe43]
142
+ - Updated dependencies [0b4fe43]
143
+ - Updated dependencies [0b4fe43]
144
+ - Updated dependencies [0b4fe43]
145
+ - Updated dependencies [0b4fe43]
146
+ - @ac-kit/core@0.13.0
147
+ - @ac-kit/math-scalar@0.4.0
148
+ - @ac-kit/math-complex@0.2.1
149
+
3
150
  ## 0.3.0
4
151
 
5
152
  ### Minor Changes
package/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # @ac-kit/math-linear
2
2
 
3
3
  Linear algebra over IEEE 754 binary64: vectors, matrices and quaternions of
4
- fixed, small dimension.
4
+ fixed, small dimension, and dense matrices of any size with their
5
+ decompositions.
5
6
 
6
7
  ## Scope
7
8
 
@@ -11,8 +12,11 @@ The fixed-dimension types that 2D and 3D work needs — `Vec2`/`Vec3`/`Vec4`,
11
12
  type-level brand, and operated on by free functions.
12
13
 
13
14
  Dimension is part of the type, not a runtime property. That is what makes the
14
- operations inlineable and allocation-predictable, and it is why an arbitrary
15
- `Matrix<n, m>` is a different design rather than a generalisation of this one.
15
+ operations inlineable and allocation-predictable, and it is why the dense
16
+ `Matrix` of any size is a different design rather than a generalisation of
17
+ this one: `{ data, rows, columns }` over one column-major `Float64Array`, the
18
+ type that least squares, regression and the decompositions work on (see
19
+ [Dense matrices and least squares](#dense-matrices-and-least-squares)).
16
20
 
17
21
  ## Contents
18
22
 
@@ -24,12 +28,16 @@ operations inlineable and allocation-predictable, and it is why an arbitrary
24
28
  | `transform` | `Transform2`, `Transform3`: translate-rotate-scale records (glTF nodes, animation keys), their interpolation and their conversion to and from the affine forms |
25
29
  | `quaternion` | Rotations: axis and angle, shortest arc between two directions, matrices, `slerp` and `nlerp`, rotation about an axis, angle between rotations |
26
30
  | `euler` | Euler angles in the twelve intrinsic orders, to and from quaternions and matrices |
27
- | `projection` | `mat4x4Perspective`, `Frustum`, `Orthographic` (three depth ranges, an infinite far plane), `mat4x4LookAt`, `affine3TargetTo` |
31
+ | `projection` | `mat4x4Perspective`, `Frustum`, `Orthographic` (three depth ranges, an infinite far plane), `mat4x4ConvertDepthRange`, `mat4x4LookAt`, `affine3TargetTo` |
28
32
  | `view-basis` | `mat4x4ViewFromBasis`: a view matrix from a camera's right, up and back axes and its eye (exact looking straight up or down) |
29
33
  | `viewport` | Pixels (top left, y down) and normalised device coordinates (y up): `vec3ProjectToViewport`, `vec3UnprojectFromViewport`, a bulk kernel |
30
- | `vec2-array`, `vec3-array`, `vec4-array` | Buffers of vectors (a `Float64Array` of `count × N`): fused kernels (arithmetic, lerp, normalise, means, transforms by matrices and affine forms), strided kernels, narrowing to and widening from interleaved `Float32Array`, nearest point |
34
+ | `vec2-array`, `vec3-array`, `vec4-array` | Buffers of vectors (a `Float64Array` of `count × N`): fused kernels (arithmetic, lerp, normalise, means, transforms by matrices and affine forms), strided kernels, narrowing to and widening from interleaved `Float32Array`, nearest point (also under an affine transform, without transforming the buffer) |
31
35
  | `mat4x4-array`, `affine2-array`, `affine3-array`, `quaternion-array` | Instance buffers: `…ArrayCreate`, `…Load`, `…Store`, `…LoadStrided`, `…StoreStrided`, `…ArrayIsFinite` (also for `mat2x2` and `mat3x3`) |
32
36
  | `tridiagonal` | `tridiagonalSolve(out, lower, diagonal, upper, right, scratch)`: the Thomas algorithm in O(n), `false` on a zero pivot; stable for diagonally dominant or symmetric positive definite systems |
37
+ | `matrix` | `Matrix` of any size, column-major over a `Float64Array`: `matrixCreate`, `matrixView`, `matrixOfRows`, get and set, copy, identity, transpose, products with matrices and vectors, equality |
38
+ | `qr-decomposition` | `QrDecomposition`: Householder QR with column pivoting, rank by condition estimation, weighted least squares (basic or minimum-norm), covariances, leverages; 0 B after construction |
39
+ | `lu-decomposition` | `LuDecomposition` (partial pivoting, determinant, Hager–Higham reciprocal condition estimate), `matrixSolve(matrix, right)` with that estimate, and `CholeskyDecomposition` (positive-definite test, solve, log-determinant); plans, 0 B after construction |
40
+ | `singular-value-decomposition` | `SingularValueDecomposition`: thin SVD by one-sided Jacobi (high relative accuracy of small singular values), rank, condition number, minimum-norm least squares and pseudo-inverse with an `rcond` truncation; a plan, 0 B after construction |
33
41
  | `upload` | Unrolled `…StoreFloat32` of matrices and quaternions, and the padded `…StoreStd140Float32` of uniform blocks |
34
42
  | `checked` | The `@ac-kit/math-linear/checked` subpath: `assertFiniteValue`, `assertFiniteBuffer`, throwing assertions for the boundaries of a program |
35
43
  | `kl-activations` | `KlActivations`: KL-divergence NMF activations of a sparse fixed dictionary, with per-column L1 penalties, iterated across calls |
@@ -135,8 +143,9 @@ vec3ArrayNarrowStrided(vertices, 0, 6, moved);
135
143
  writes a tight binary64 buffer into an interleaved binary32 one,
136
144
  `…ArrayWidenStrided` reads one back (a glTF accessor, a readback), and
137
145
  `…ArrayNarrowRelative` subtracts an origin first so that large coordinates
138
- keep their precision. A whole array without stride is
139
- `Float32Array.prototype.set`.
146
+ keep their precision; `…ArraySplitStrided` writes each number as two
147
+ binary32 parts, high and low, for two-float positions on the GPU. A whole
148
+ array without stride is `Float32Array.prototype.set`.
140
149
  - **Instances.** `mat4x4ArrayCreate`, `affine2ArrayCreate`, `affine3ArrayCreate`
141
150
  and `quaternionArrayCreate` make instance buffers, written one element at a
142
151
  time with `…Store` and read with `…Load`.
@@ -197,6 +206,8 @@ mathematics, different purpose; neither is a substitute for the other.
197
206
  `"negative-one-to-one"` (OpenGL) or `"one-to-zero"` (reversed depth, near at
198
207
  1; its extra precision needs a floating-point depth buffer and depth produced
199
208
  in `[0, 1]`). `far` may be `Infinity` in all three.
209
+ `mat4x4ConvertDepthRange` re-expresses a projection built for one range in
210
+ another (a GL-style projection drawn under WebGPU's clip depth).
200
211
  `mat4x4Perspective`, `mat4x4Frustum`, `mat4x4Orthographic`, `mat4x4LookAt` and
201
212
  `affine3TargetTo` are built once per frame or resize, so they validate and
202
213
  throw a `RangeError` (leaving `out` untouched) where the operations return
@@ -229,6 +240,51 @@ and `assertFiniteBuffer(name, array, elementSize, count?)`, which throw a
229
240
  `RangeError` naming the argument and the first bad component. Call them after
230
241
  parsing untrusted data, before an upload in a development build, and in tests.
231
242
 
243
+ ## Dense matrices and least squares
244
+
245
+ A `Matrix` is `{ data, rows, columns }`: `rows · columns` entries in one
246
+ `Float64Array`, column-major like the fixed sizes (row `r`, column `c` at
247
+ `rows · c + r`, LAPACK's layout). `matrixView(data, rows, columns)` wraps
248
+ existing storage without a copy, `matrixOfRows([[1, 2], [3, 4]])` copies rows
249
+ as written. The operations take `out` first and allocate nothing, but at a
250
+ runtime size an alias-safe product would need scratch of that size, so an
251
+ `out` sharing storage with an input is a `RangeError` rather than a silent
252
+ wrong answer.
253
+
254
+ `QrDecomposition` is a plan for one shape: its constructor allocates the
255
+ factors and every working array, and `decompose`, `solve`, `covariance`,
256
+ `leverages` and the `Q` products allocate nothing after it. It factorises `A·P
257
+ = Q·R` by Householder reflections with column pivoting (LAPACK's `xGEQP3`), and
258
+ decides the **rank** by incremental condition estimation (`xGELSY`): the
259
+ leading triangle keeps a pivot column only while its estimated reciprocal
260
+ condition stays above `rankTolerance` — `max(rows, columns) · ε` by default,
261
+ `1e-7` for R's `lm` behaviour. `pivots` names the independent columns, the
262
+ others are aliased, and `reciprocalCondition` tells how many digits an answer
263
+ can have lost.
264
+
265
+ ```ts
266
+ import { matrixCreate, matrixOfRows, QrDecomposition } from "@ac-kit/math-linear";
267
+
268
+ // Weighted fit of y ≈ β₀ + β₁·t; the last observation has weight zero.
269
+ const design = matrixOfRows([[1, 0], [1, 1], [1, 2], [1, 3]]);
270
+ const qr = new QrDecomposition(4, 2);
271
+ qr.decompose(design, { weights: Float64Array.of(1, 2, 1, 0) });
272
+ const beta = qr.solve(new Float64Array(2), Float64Array.of(1, 3, 5, 100));
273
+ const sigma2 = qr.residualSumOfSquares / (3 - qr.rank);
274
+ const covariance = qr.covariance(matrixCreate(2, 2), { scale: sigma2 });
275
+ ```
276
+
277
+ A rank-deficient design gets either the **basic** solution (aliased
278
+ coefficients `0`, their covariance rows `NaN`, as a regression reports them)
279
+ or the **minimum-norm** one (`solve(out, b, "minimum-norm")`, the
280
+ pseudo-inverse answer through a complete orthogonal decomposition), with the
281
+ matching covariance `(AᵀWA)⁻¹` or `(AᵀWA)⁺`. Weights make it the inner step
282
+ of iteratively reweighted least squares; `leverages` gives the hat-matrix
283
+ diagonal for studentised residuals and robust weights. A non-finite entry
284
+ makes `decompose` return `false` and every result `NaN`; finite matrices of
285
+ any magnitude are scaled by powers of two first, so entries near `1e±300`
286
+ factorise exactly as entries near `1` do.
287
+
232
288
  ## Usage
233
289
 
234
290
  ```ts
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Writes the Euclidean norm of `count` entries of `data`, from `start`,
3
+ * `stride` apart, to `out[outIndex]`, right over the whole binary64 range: the
4
+ * plain `√Σx²` when its sum lies in `[2⁻⁹⁰⁰, ∞)`, and a second pass scaled by
5
+ * the largest magnitude otherwise (an overflowing or underflowing sum), so the
6
+ * scaled pass runs only for entries outside about `[1e−135, 1e150]`. `NaN` when
7
+ * an entry is `NaN`.
8
+ *
9
+ * The result goes through an array, never a return value: a double returned
10
+ * from a call the engine does not inline is boxed.
11
+ */
12
+ export declare function euclideanNorm_(out: Float64Array, outIndex: number, data: Float64Array, start: number, count: number, stride: number): void;
13
+ /**
14
+ * `√(a² + b²)` without overflow or underflow, never `Math.hypot`. Small enough
15
+ * for the engine to inline at its call sites, which a double return needs.
16
+ */
17
+ export declare function pairNorm_(a: number, b: number): number;
18
+ //# sourceMappingURL=_euclidean-norm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_euclidean-norm.d.ts","sourceRoot":"","sources":["../src/_euclidean-norm.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC7B,GAAG,EAAE,YAAY,EACjB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACZ,IAAI,CAsDN;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAatD"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Below this, a plain sum of squares may hold squares that underflowed to
3
+ * subnormals; their total error is then at most `count · 2⁻¹⁰⁷⁵`, which against
4
+ * a sum of at least `2⁻⁹⁰⁰` is below `count · 2⁻¹⁷⁵` relative.
5
+ */
6
+ const PLAIN_SUM_MINIMUM_ = 2 ** -900;
7
+ /**
8
+ * Writes the Euclidean norm of `count` entries of `data`, from `start`,
9
+ * `stride` apart, to `out[outIndex]`, right over the whole binary64 range: the
10
+ * plain `√Σx²` when its sum lies in `[2⁻⁹⁰⁰, ∞)`, and a second pass scaled by
11
+ * the largest magnitude otherwise (an overflowing or underflowing sum), so the
12
+ * scaled pass runs only for entries outside about `[1e−135, 1e150]`. `NaN` when
13
+ * an entry is `NaN`.
14
+ *
15
+ * The result goes through an array, never a return value: a double returned
16
+ * from a call the engine does not inline is boxed.
17
+ */
18
+ export function euclideanNorm_(out, outIndex, data, start, count, stride) {
19
+ let sum = 0;
20
+ let index = start;
21
+ for (let step = 0; step < count; step++) {
22
+ const value = data[index];
23
+ sum += value * value;
24
+ index += stride;
25
+ }
26
+ if (sum >= PLAIN_SUM_MINIMUM_ && sum < Number.POSITIVE_INFINITY) {
27
+ out[outIndex] = Math.sqrt(sum);
28
+ return;
29
+ }
30
+ if (sum !== sum) {
31
+ out[outIndex] = Number.NaN;
32
+ return;
33
+ }
34
+ let largest = 0;
35
+ index = start;
36
+ for (let step = 0; step < count; step++) {
37
+ const magnitude = Math.abs(data[index]);
38
+ if (magnitude > largest) {
39
+ largest = magnitude;
40
+ }
41
+ index += stride;
42
+ }
43
+ if (largest === 0 || largest === Number.POSITIVE_INFINITY) {
44
+ out[outIndex] = largest;
45
+ return;
46
+ }
47
+ // Divided, not multiplied by a reciprocal: the reciprocal of a subnormal
48
+ // largest entry overflows.
49
+ let scaled = 0;
50
+ index = start;
51
+ for (let step = 0; step < count; step++) {
52
+ const value = data[index] / largest;
53
+ scaled += value * value;
54
+ index += stride;
55
+ }
56
+ out[outIndex] = largest * Math.sqrt(scaled);
57
+ }
58
+ /**
59
+ * `√(a² + b²)` without overflow or underflow, never `Math.hypot`. Small enough
60
+ * for the engine to inline at its call sites, which a double return needs.
61
+ */
62
+ export function pairNorm_(a, b) {
63
+ const x = Math.abs(a);
64
+ const y = Math.abs(b);
65
+ const larger = x > y ? x : y;
66
+ const smaller = x > y ? y : x;
67
+ if (larger === 0 || larger === Number.POSITIVE_INFINITY) {
68
+ return larger;
69
+ }
70
+ const ratio = smaller / larger;
71
+ return larger * Math.sqrt(1 + ratio * ratio);
72
+ }
73
+ //# sourceMappingURL=_euclidean-norm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_euclidean-norm.js","sourceRoot":"","sources":["../src/_euclidean-norm.ts"],"names":[],"mappings":"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"}
package/dist/_invert.d.ts CHANGED
@@ -1,19 +1,214 @@
1
+ import { type Callable } from "@ac-kit/core";
1
2
  /**
2
- * The second chance of a matrix inversion. A matrix whose entries are all of
3
- * one very large or very small magnitude has a determinant that overflows or
4
- * underflows although its inverse is representable. Writes `m` scaled by `2^-k`
5
- * into `out` (exact: a power of two), where `2^k` is the power of two at or
6
- * below the largest entry, and returns `k`; the caller inverts `out` and passes
7
- * the result to {@link unscaleInverse_}. Returns `NaN`, writing nothing, when
8
- * an entry is not finite or every entry is zero, which no scaling helps. `out`
9
- * may be `m`.
3
+ * The second chance of a matrix inversion. A matrix whose entries span a range
4
+ * that the cofactors' products cannot (`diag(1e200, 1e200, 1e200, 1e-200)`: a
5
+ * determinant of `1e400`, an inverse of `1e-200` and `1e200`) is inverted in
6
+ * the scale where they do. Writes `m`, a square matrix of `size` rows in any
7
+ * layout, into `out` as `diag(2^-r) · m · diag(2^-c)` (exact: powers of two,
8
+ * unless an entry lands in or below the subnormal range, see below), where
9
+ * `2^r` of a row is the power of two at or below its largest entry and `2^c` of
10
+ * a column that of the same after the rows, so every row and column has an
11
+ * entry of magnitude in `[1/2, 2)`. The caller inverts `out` and passes the
12
+ * result to {@link unequilibrateInverse_}, which scales each entry of the
13
+ * inverse by its own power of two in one step, so no entry passes through a
14
+ * range its neighbours do not share. Returns `false`, writing nothing, when an
15
+ * entry is not finite or a row or a column is zero, which no scaling helps.
16
+ * When the entries of a column span more than the binary64 range once their
17
+ * rows are scaled (`[[2^900, 2^900, 0], [2^900, 2^900, 2^-200], [0, 2^900,
18
+ * 2^900]]`, whose `2^-200` becomes `2^-1100`), an entry rounds or vanishes, and
19
+ * {@link isEquilibrationLossy_} says so. `out` may be `m`.
10
20
  */
11
- export declare function scaleForInversion_(out: number[], m: ArrayLike<number>): number;
21
+ export declare function equilibrateForInversion_(out: number[], m: ArrayLike<number>, size: number): boolean;
12
22
  /**
13
- * Multiplies the inverse of the scaled matrix of {@link scaleForInversion_} by
14
- * `2^-k` in place, which gives the inverse of the original, and returns whether
15
- * every entry is finite (the inverse may still be beyond the range of a
16
- * binary64 number).
23
+ * Turns the inverse in `out` of the equilibrated matrix of
24
+ * {@link equilibrateForInversion_} into the inverse of the original, in place:
25
+ * its entry at row `i` and column `j` is scaled by `2^(-c_i - r_j)`. `path`,
26
+ * {@link COFACTOR_PATH_} or {@link PIVOTED_PATH_}, says which inversion wrote
27
+ * it, so how far its entries may be from the exact ones, as a fraction of the
28
+ * largest of them ({@link ERROR_SHARES_}). Returns whether every entry, plus
29
+ * its error so scaled, stays within `Number.MAX_VALUE`: only then is the exact
30
+ * inverse sure to round to finite numbers. A rounded entry just below the limit
31
+ * may stand for one past it (`1 / (4237 · 2^-1024)` rounded, times `4237`, is
32
+ * `Number.MAX_VALUE`, where the exact `2^1024` rounds to `Infinity`), and an
33
+ * entry rounded to zero may stand for one the scaling sends past it. `false`
34
+ * leaves `out` partly scaled.
17
35
  */
18
- export declare function unscaleInverse_(out: number[], exponent: number): boolean;
36
+ export declare function unequilibrateInverse_(out: number[], size: number, path: number): boolean;
37
+ /**
38
+ * The largest magnitude the binary64 paths of an inversion accept for an entry
39
+ * of their inverse (or of an affine inverse's translation): their error bounds,
40
+ * at most about `2^-39` of the largest entry, keep the exact entry below
41
+ * `Number.MAX_VALUE`, so that it rounds to a finite number. An entry at or past
42
+ * it is left to {@link invertRescaled_}, whose bound is checked entry by entry
43
+ * and whose overlap with the overflow threshold exact arithmetic settles.
44
+ */
45
+ export declare const INVERSE_LIMIT_: number;
46
+ /**
47
+ * The second chance of a matrix inversion, after its plain cofactor expansion
48
+ * failed. Inverts `m`, a square matrix of `size` rows (at most 4) in any
49
+ * layout, into `out` and returns `true`, or fills `out` with `NaN` and returns
50
+ * `false` exactly when `m` is singular, an entry is not finite, or an entry of
51
+ * the inverse, rounded to the nearest binary64, is beyond `Number.MAX_VALUE`.
52
+ * `out` may be `m`.
53
+ *
54
+ * The rows and columns are scaled by powers of two first
55
+ * ({@link equilibrateForInversion_}), and the inverse scaled back
56
+ * ({@link unequilibrateInverse_}). `invert` (writing only on success, its
57
+ * output may be its input) inverts the equilibrated matrix; when it refuses, LU
58
+ * factorisation with partial pivoting ({@link invertPivoted_}) does, which no
59
+ * cancellation of the cofactors stops. When `decisive`, a refusal of `invert`
60
+ * already means the equilibrated matrix, so `m`, is singular. Otherwise an
61
+ * exact elimination proves it singular or invertible. When the elimination
62
+ * rounded, when the inverse it found leaves the binary64 range once scaled
63
+ * back, or when the scaling itself rounded an entry (an entry far below the
64
+ * others of its column, which it sends below the subnormal range, so that the
65
+ * scaled matrix is no longer exactly `m` scaled, and may be singular when `m`
66
+ * is not), {@link invertExact_} settles `m` itself: `false` is never a rounding
67
+ * artefact. A scaling that rounded skips `invert` and the decisive shortcut,
68
+ * and the elimination counts it in its certificate. A zero row or column, or an
69
+ * entry that is not finite, is refused before any of them.
70
+ *
71
+ * Time complexity: O(size³), with no allocation unless the exact settlement
72
+ * runs: for a matrix whose determinant rounding takes to zero in both its
73
+ * cofactors and its rounded elimination, one with a condition number beyond
74
+ * about `2^52`, singular or not; for an inverse whose scaled-back entries
75
+ * overflow, or come within their error bound of overflowing; and for a matrix
76
+ * whose scaling rounded an entry and whose elimination cannot certify its
77
+ * inverse.
78
+ */
79
+ export declare function invertRescaled_(out: number[], m: ArrayLike<number>, size: number, invert: Callable<[number[], ArrayLike<number>, number], boolean>, decisive: boolean): boolean;
80
+ /**
81
+ * The last chance of a matrix inversion, for a matrix that every binary64
82
+ * elimination declared singular or out of range: `m`, a square matrix of `size`
83
+ * rows (at most 4) in any layout, inverted in exact `bigint` arithmetic and
84
+ * each entry rounded once to the nearest binary64. Writes the inverse into
85
+ * `out` and returns `true`, or returns `false`, writing nothing, exactly when
86
+ * `m` is singular, an entry is not finite, or an entry of the inverse is beyond
87
+ * the range of a binary64 number. `out` may be `m`.
88
+ *
89
+ * A matrix can be invertible with an inverse that fits and still lose its
90
+ * determinant to rounding in any floating-point elimination: rows that differ
91
+ * only in an entry far below their others (`[[1, 1, 0, 0], [1, 1, 2^-600, 0],
92
+ * …]` once its rows and columns are permuted and scaled) cancel to an exact
93
+ * zero. The entries are integers times one common power of two, so the adjugate
94
+ * and the determinant are exact integers (Laplace expansion), and each entry of
95
+ * the inverse is their quotient, rounded once.
96
+ *
97
+ * Allocates (`bigint` values): it runs only after the binary64 paths fail. Time
98
+ * complexity: O(size!) `bigint` products of up to `size` × 2,100 bits.
99
+ */
100
+ export declare function invertExact_(out: number[], m: ArrayLike<number>, size: number): boolean;
101
+ /**
102
+ * Inverts `m`, a column-major square matrix of `size` rows (at most 4), into
103
+ * `out` and returns {@link PIVOTED_INVERTED_}; otherwise writes nothing and
104
+ * returns {@link PIVOTED_SINGULAR_} when an entry of `m` is not finite or its
105
+ * elimination, exact throughout, meets a zero pivot, and
106
+ * {@link PIVOTED_UNSETTLED_} when the elimination rounded or an entry of the
107
+ * inverse is not finite: rounding can make a singular matrix look invertible
108
+ * and an invertible one singular, so neither is then proved. `out` may be `m`.
109
+ * Meant for the matrix {@link equilibrateForInversion_} wrote, whose every row
110
+ * and column has an entry of magnitude in `[1, 2)`, so the partial pivoting
111
+ * compares rows of one scale (Golub and Van Loan, §3.5.2), after a cofactor
112
+ * expansion of it found its determinant lost to rounding.
113
+ *
114
+ * LU factorisation with partial pivoting, `P · m = L · U` (Golub and Van Loan,
115
+ * "Matrix Computations", 4th ed., algorithm 3.4.1), then `L · U · x = P · e_j`
116
+ * solved for every column `e_j` of the identity by forward and back
117
+ * substitution (§3.1). Backward stable whatever the determinant: no product of
118
+ * more than two entries is formed, so a matrix whose cofactors cancel or whose
119
+ * determinant underflows while its inverse fits is inverted all the same. Every
120
+ * division, product and difference of the factorisation is checked for rounding
121
+ * (`twoProductErrorInRange`, `twoSumError`): when none rounds, `L · U` is
122
+ * exactly `P · m`, and its pivots decide whether `m` is singular.
123
+ *
124
+ * Time complexity: O(size³), with no allocation.
125
+ */
126
+ export declare function invertPivoted_(out: number[], m: ArrayLike<number>, size: number): number;
127
+ /** Half a unit in the last place of 1. */
128
+ export declare const UNIT_ROUNDOFF_: number;
129
+ /**
130
+ * The relative error a cofactor expansion's determinant, and its cofactors
131
+ * against the largest of them, may carry for its inverse to be accepted: a
132
+ * normwise backward error of at most about `2^-40`.
133
+ *
134
+ * An error bound `r · u + k · η` (rounding, then `k` products that may fall in
135
+ * the subnormal range, each adding at most `η = 2^-1073`) is accepted against a
136
+ * value `v` when `r · u ≤ ROUNDING_TOLERANCE_ · v` and `k · UNDERFLOW_UNIT_ ≤
137
+ * UNDERFLOW_TOLERANCE_ · v`: the first share is `(1 − 2^-20)` of
138
+ * `INVERSE_TOLERANCE_`, the second `2^-20` of it, both scaled by `2^1000` so
139
+ * that no operand is subnormal. Arithmetic on a subnormal number takes a
140
+ * microcode assist of about a hundred cycles on x86, which on every call would
141
+ * cost the plain path several times its own time.
142
+ */
143
+ export declare const INVERSE_TOLERANCE_: number;
144
+ /** `INVERSE_TOLERANCE_ · (1 − 2^-20)`, the share of the rounding errors. */
145
+ export declare const ROUNDING_TOLERANCE_: number;
146
+ /** `η · 2^1000`, the error of a product in the subnormal range, rounded up. */
147
+ export declare const UNDERFLOW_UNIT_: number;
148
+ /** `INVERSE_TOLERANCE_ · 2^-20 · 2^1000`, the share of the underflows. */
149
+ export declare const UNDERFLOW_TOLERANCE_: number;
150
+ /**
151
+ * The magnitude of the determinant {@link isWithinTolerance3_} judges: through
152
+ * typed storage, as a double passed to a call the engine does not inline is
153
+ * boxed.
154
+ */
155
+ export declare const BOUND_INPUT_: Float64Array<ArrayBuffer>;
156
+ /**
157
+ * Whether the forward error bound of a 3 × 3 cofactor expansion of the
158
+ * column-major `m` (its first nine entries) keeps the determinant, of the
159
+ * magnitude in {@link BOUND_INPUT_}, within `2^-41` of itself and every minor
160
+ * within `2^-41 / 3` of the largest of them (Higham, "Accuracy and Stability of
161
+ * Numerical Algorithms", §3.1): a minor `x·y − z·w` is within `3u·(|x·y| +
162
+ * |z·w|) + η` of its value, the determinant, along a row or a column, within
163
+ * `7u·P + (M₁ + 2)·2η`, `P` the permanent of `|m|` and `M₁` the sum of that row
164
+ * or column, at most the sum of all of `|m|`. The tight bound behind the cheap
165
+ * one of `mat3x3Invert` and `affine3Invert`, whose minors are the same products
166
+ * in either order, so of the same magnitudes.
167
+ *
168
+ * Time complexity: O(1), with no allocation.
169
+ */
170
+ export declare function isWithinTolerance3_(m: ArrayLike<number>): boolean;
171
+ /**
172
+ * Whether the cofactor expansion of `mat3x3Invert` (`size` 3) or `mat4x4Invert`
173
+ * (`size` 4) of the column-major `m` rounds nowhere: every product and sum of
174
+ * its minors, cofactors and determinant recomputed in the same order and
175
+ * checked (`twoProductErrorInRange`, `twoSumError`). Then the cofactors and the
176
+ * determinant are exact, and the inverse is each cofactor over the determinant,
177
+ * rounded at most twice, however they cancel (an integer matrix of determinant
178
+ * 1). The second chance of a cofactor expansion whose error bound refused it.
179
+ *
180
+ * Time complexity: O(1), with no allocation.
181
+ */
182
+ export declare function isCofactorExpansionExact_(m: ArrayLike<number>, size: number): boolean;
183
+ /**
184
+ * Writes the translation of the inverse of an affine transform `a` (its `size ×
185
+ * size` linear part `A`, `size` 2 or 3, column-major from `a[0]`, then its
186
+ * translation `t` from `a[offset]`, `offset` being `size²`), given the inverse
187
+ * `B` of `A`, to `out[offset]` and on, and returns `true`; or returns `false`,
188
+ * writing nothing there, exactly when an entry of the exact `−A⁻¹ · t` rounds
189
+ * past `Number.MAX_VALUE`.
190
+ *
191
+ * Each entry is the correctly rounded value of `−B · t` for the `B` given
192
+ * (`dotExactInto`), however its terms cancel, overflow or underflow. Whether it
193
+ * overflows is never read off that rounded value: a rigorous bound first proves
194
+ * the exact `−A⁻¹ · t` far enough from the threshold
195
+ * ({@link isTranslationCertain_}). When it cannot (a component within the bound
196
+ * of the threshold or past it, or a `B` too far from `A⁻¹`, as for an
197
+ * ill-conditioned `A`), `isHomogeneousInvertible(a)` decides: whether the
198
+ * inverse of the homogeneous matrix of `a`, whose linear block is `A⁻¹` and
199
+ * last column `−A⁻¹ · t`, rounds to finite numbers (`mat3x3Invert` or
200
+ * `mat4x4Invert`, exact about it). A component of `−B · t` that overflowed
201
+ * where the exact one does not is settled from `a` itself in exact arithmetic
202
+ * ({@link settleInverseTranslation_}): every component is then `−A⁻¹ · t`
203
+ * rounded once. So with a scale of `161/256` and a translation of `161 ·
204
+ * 2^1016`, where `−B · t` rounds to `−Number.MAX_VALUE`, the exact `−2^1024` is
205
+ * refused. `a` is read before anything is written, so `out` may be `a`; `B` is
206
+ * the already unscaled inverse, so no entry of it passes through the range of
207
+ * the scaled matrix.
208
+ *
209
+ * Time complexity: O(size³), with no allocation unless the exact settlement, or
210
+ * that of the homogeneous inversion, runs: for a translation near the overflow
211
+ * threshold.
212
+ */
213
+ export declare function writeInverseTranslation_(out: number[], offset: number, inverse: ArrayLike<number>, size: number, a: ArrayLike<number>, isHomogeneousInvertible: Callable<[ArrayLike<number>], boolean>): boolean;
19
214
  //# sourceMappingURL=_invert.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_invert.d.ts","sourceRoot":"","sources":["../src/_invert.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,MAAM,EAAE,EACb,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAClB,MAAM,CAoBR;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CASxE"}
1
+ {"version":3,"file":"_invert.d.ts","sourceRoot":"","sources":["../src/_invert.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,QAAQ,EAIb,MAAM,cAAc,CAAC;AAqCtB;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EAAE,EACb,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,IAAI,EAAE,MAAM,GACV,OAAO,CA2DT;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACpC,GAAG,EAAE,MAAM,EAAE,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACV,OAAO,CAuBT;AAKD;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,QAAoC,CAAC;AA0BhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,CAC9B,GAAG,EAAE,MAAM,EAAE,EACb,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAChE,QAAQ,EAAE,OAAO,GACf,OAAO,CAmCT;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAC3B,GAAG,EAAE,MAAM,EAAE,EACb,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,IAAI,EAAE,MAAM,GACV,OAAO,CA+DT;AA+CD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAC7B,GAAG,EAAE,MAAM,EAAE,EACb,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,IAAI,EAAE,MAAM,GACV,MAAM,CA4GR;AAmCD,0CAA0C;AAC1C,eAAO,MAAM,cAAc,QAAW,CAAC;AAEvC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,kBAAkB,QAAW,CAAC;AAE3C,4EAA4E;AAC5E,eAAO,MAAM,mBAAmB,QAAsC,CAAC;AAEvE,+EAA+E;AAC/E,eAAO,MAAM,eAAe,QAAW,CAAC;AAExC,0EAA0E;AAC1E,eAAO,MAAM,oBAAoB,QAAW,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,YAAY,2BAAsB,CAAC;AAEhD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,OAAO,CAsDjE;AA8GD;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CACxC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,IAAI,EAAE,MAAM,GACV,OAAO,CAoDT;AAwCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EAAE,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,EAC1B,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,uBAAuB,EAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,GAC7D,OAAO,CA2BT"}