@ac-kit/math-linear 0.3.0 → 0.4.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/CHANGELOG.md +80 -0
- package/README.md +6 -3
- package/dist/_invert.d.ts +209 -14
- package/dist/_invert.d.ts.map +1 -1
- package/dist/_invert.js +869 -33
- package/dist/_invert.js.map +1 -1
- package/dist/_slerp.d.ts +14 -0
- package/dist/_slerp.d.ts.map +1 -1
- package/dist/_slerp.js +56 -0
- package/dist/_slerp.js.map +1 -1
- package/dist/affine2.d.ts +17 -5
- package/dist/affine2.d.ts.map +1 -1
- package/dist/affine2.js +96 -34
- package/dist/affine2.js.map +1 -1
- package/dist/affine3.d.ts +17 -4
- package/dist/affine3.d.ts.map +1 -1
- package/dist/affine3.js +134 -60
- package/dist/affine3.js.map +1 -1
- package/dist/mat2x2.d.ts +16 -4
- package/dist/mat2x2.d.ts.map +1 -1
- package/dist/mat2x2.js +76 -33
- package/dist/mat2x2.js.map +1 -1
- package/dist/mat3x3.d.ts +27 -5
- package/dist/mat3x3.d.ts.map +1 -1
- package/dist/mat3x3.js +71 -34
- package/dist/mat3x3.js.map +1 -1
- package/dist/mat4x4.d.ts +34 -8
- package/dist/mat4x4.d.ts.map +1 -1
- package/dist/mat4x4.js +180 -56
- package/dist/mat4x4.js.map +1 -1
- package/dist/projection.d.ts +16 -1
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +49 -0
- package/dist/projection.js.map +1 -1
- package/dist/quaternion.d.ts +6 -4
- package/dist/quaternion.d.ts.map +1 -1
- package/dist/quaternion.js +8 -50
- package/dist/quaternion.js.map +1 -1
- package/dist/vec2-array-componentwise.d.ts +18 -0
- package/dist/vec2-array-componentwise.d.ts.map +1 -1
- package/dist/vec2-array-componentwise.js +48 -0
- package/dist/vec2-array-componentwise.js.map +1 -1
- package/dist/vec3-array-componentwise.d.ts +18 -0
- package/dist/vec3-array-componentwise.d.ts.map +1 -1
- package/dist/vec3-array-componentwise.js +52 -0
- package/dist/vec3-array-componentwise.js.map +1 -1
- package/dist/vec3.d.ts +5 -5
- package/dist/vec3.d.ts.map +1 -1
- package/dist/vec3.js +39 -13
- package/dist/vec3.js.map +1 -1
- package/dist/vec4-array-componentwise.d.ts +43 -0
- package/dist/vec4-array-componentwise.d.ts.map +1 -1
- package/dist/vec4-array-componentwise.js +120 -0
- package/dist/vec4-array-componentwise.js.map +1 -1
- package/dist/vec4.d.ts +4 -2
- package/dist/vec4.d.ts.map +1 -1
- package/dist/vec4.js +6 -29
- package/dist/vec4.js.map +1 -1
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,85 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0b4fe43: `mat4x4ConvertDepthRange(out, matrix, from, to)` re-expresses a projection
|
|
8
|
+
built for one `DepthRange` in another: the `x`, `y` and `w` rows are copied and
|
|
9
|
+
the depth row maps the near and far planes of `from` to those of `to`, with
|
|
10
|
+
exact coefficients (one rounding per depth-row element). A GL-style
|
|
11
|
+
`"negative-one-to-one"` projection then draws under WebGPU's `"zero-to-one"`
|
|
12
|
+
clip depth, and a forward projection turns reversed. `out` may be `matrix`; an
|
|
13
|
+
unknown range throws a `RangeError` and leaves `out` untouched.
|
|
14
|
+
- 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).
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 0b4fe43: Wide-range inputs no longer fail or lose their result.
|
|
19
|
+
|
|
20
|
+
- `quaternionSlerp` and `vec4Slerp` take their angle from the tangent part, so
|
|
21
|
+
a tiny rotation extrapolated by a huge `t` stays on the unit sphere (`1e-16`
|
|
22
|
+
rad at `t = 1e16` gives the quaternion half a radian on) and a rounding off
|
|
23
|
+
the unit sphere does not grow with `t`. `vec3Slerp` between exact antipodes of
|
|
24
|
+
different lengths interpolates the lengths and turns on a perpendicular arc,
|
|
25
|
+
keeps a pair a rounding away from opposite in its own plane, and slerps
|
|
26
|
+
vectors of magnitude `1e±200`.
|
|
27
|
+
- `mat2x2Invert`, `mat3x3Invert`, `mat4x4Invert`, `affine2Invert` and
|
|
28
|
+
`affine3Invert` invert every matrix whose inverse is representable, however
|
|
29
|
+
widely its entries span (`diag(1e160, 1e160, 1e-160)`, scales of `2^600` with
|
|
30
|
+
a translation of `Number.MAX_VALUE`) and however its cofactors cancel: `false`
|
|
31
|
+
means singular, or an inverse entry beyond `Number.MAX_VALUE` once rounded,
|
|
32
|
+
never a loss to rounding, and `true` is never a rounding artefact
|
|
33
|
+
(`diag(2^-1024, 4237)` is refused). A nearly singular matrix is no longer
|
|
34
|
+
inverted from a rounding residue: its determinant is kept within `2^-41` of
|
|
35
|
+
itself, or its inverse is computed by a backward-stable elimination. A
|
|
36
|
+
well-conditioned matrix gives the same result as before, at about 1.4× its
|
|
37
|
+
former cost for a 4 × 4 view matrix. Inversion allocates nothing, except for
|
|
38
|
+
a matrix of condition number beyond about `2^52`, an inverse that overflows
|
|
39
|
+
or comes within its error bound of overflowing, or a matrix whose scaling
|
|
40
|
+
rounds an entry.
|
|
41
|
+
- Each translation component of an affine inverse is within `2^-41` of `−B · t`
|
|
42
|
+
for the inverse linear part `B`, and correctly rounded whenever plain
|
|
43
|
+
arithmetic cannot guarantee that (a linear part whose inverse starts with
|
|
44
|
+
`(1, 1, 1)` and a translation of `Number.MAX_VALUE`, `1` and
|
|
45
|
+
`-Number.MAX_VALUE` give `-1`, not `0`). Whether an affine inverse overflows
|
|
46
|
+
follows the exact translation `−A⁻¹ · t`, as for the equivalent homogeneous
|
|
47
|
+
matrix: an x scale of `161/256` with an x translation of `161 · 2^1016` is
|
|
48
|
+
refused, and a translation whose `−B · t` overflows while the exact one fits
|
|
49
|
+
is inverted.
|
|
50
|
+
- Updated dependencies [0b4fe43]
|
|
51
|
+
- Updated dependencies [0b4fe43]
|
|
52
|
+
- Updated dependencies [0b4fe43]
|
|
53
|
+
- Updated dependencies [0b4fe43]
|
|
54
|
+
- Updated dependencies [0b4fe43]
|
|
55
|
+
- Updated dependencies [0b4fe43]
|
|
56
|
+
- Updated dependencies [0b4fe43]
|
|
57
|
+
- Updated dependencies [0b4fe43]
|
|
58
|
+
- Updated dependencies [0b4fe43]
|
|
59
|
+
- Updated dependencies [0b4fe43]
|
|
60
|
+
- Updated dependencies [0b4fe43]
|
|
61
|
+
- Updated dependencies [0b4fe43]
|
|
62
|
+
- Updated dependencies [0b4fe43]
|
|
63
|
+
- Updated dependencies [0b4fe43]
|
|
64
|
+
- Updated dependencies [0b4fe43]
|
|
65
|
+
- Updated dependencies [0b4fe43]
|
|
66
|
+
- Updated dependencies [0b4fe43]
|
|
67
|
+
- Updated dependencies [0b4fe43]
|
|
68
|
+
- Updated dependencies [0b4fe43]
|
|
69
|
+
- Updated dependencies [0b4fe43]
|
|
70
|
+
- Updated dependencies [0b4fe43]
|
|
71
|
+
- Updated dependencies [0b4fe43]
|
|
72
|
+
- Updated dependencies [0b4fe43]
|
|
73
|
+
- Updated dependencies [0b4fe43]
|
|
74
|
+
- Updated dependencies [0b4fe43]
|
|
75
|
+
- Updated dependencies [0b4fe43]
|
|
76
|
+
- Updated dependencies [0b4fe43]
|
|
77
|
+
- Updated dependencies [0b4fe43]
|
|
78
|
+
- Updated dependencies [0b4fe43]
|
|
79
|
+
- @ac-kit/core@0.13.0
|
|
80
|
+
- @ac-kit/math-scalar@0.4.0
|
|
81
|
+
- @ac-kit/math-complex@0.2.1
|
|
82
|
+
|
|
3
83
|
## 0.3.0
|
|
4
84
|
|
|
5
85
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ operations inlineable and allocation-predictable, and it is why an arbitrary
|
|
|
24
24
|
| `transform` | `Transform2`, `Transform3`: translate-rotate-scale records (glTF nodes, animation keys), their interpolation and their conversion to and from the affine forms |
|
|
25
25
|
| `quaternion` | Rotations: axis and angle, shortest arc between two directions, matrices, `slerp` and `nlerp`, rotation about an axis, angle between rotations |
|
|
26
26
|
| `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`
|
|
27
|
+
| `projection` | `mat4x4Perspective`, `Frustum`, `Orthographic` (three depth ranges, an infinite far plane), `mat4x4ConvertDepthRange`, `mat4x4LookAt`, `affine3TargetTo` |
|
|
28
28
|
| `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
29
|
| `viewport` | Pixels (top left, y down) and normalised device coordinates (y up): `vec3ProjectToViewport`, `vec3UnprojectFromViewport`, a bulk kernel |
|
|
30
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 |
|
|
@@ -135,8 +135,9 @@ vec3ArrayNarrowStrided(vertices, 0, 6, moved);
|
|
|
135
135
|
writes a tight binary64 buffer into an interleaved binary32 one,
|
|
136
136
|
`…ArrayWidenStrided` reads one back (a glTF accessor, a readback), and
|
|
137
137
|
`…ArrayNarrowRelative` subtracts an origin first so that large coordinates
|
|
138
|
-
keep their precision
|
|
139
|
-
|
|
138
|
+
keep their precision; `…ArraySplitStrided` writes each number as two
|
|
139
|
+
binary32 parts, high and low, for two-float positions on the GPU. A whole
|
|
140
|
+
array without stride is `Float32Array.prototype.set`.
|
|
140
141
|
- **Instances.** `mat4x4ArrayCreate`, `affine2ArrayCreate`, `affine3ArrayCreate`
|
|
141
142
|
and `quaternionArrayCreate` make instance buffers, written one element at a
|
|
142
143
|
time with `…Store` and read with `…Load`.
|
|
@@ -197,6 +198,8 @@ mathematics, different purpose; neither is a substitute for the other.
|
|
|
197
198
|
`"negative-one-to-one"` (OpenGL) or `"one-to-zero"` (reversed depth, near at
|
|
198
199
|
1; its extra precision needs a floating-point depth buffer and depth produced
|
|
199
200
|
in `[0, 1]`). `far` may be `Infinity` in all three.
|
|
201
|
+
`mat4x4ConvertDepthRange` re-expresses a projection built for one range in
|
|
202
|
+
another (a GL-style projection drawn under WebGPU's clip depth).
|
|
200
203
|
`mat4x4Perspective`, `mat4x4Frustum`, `mat4x4Orthographic`, `mat4x4LookAt` and
|
|
201
204
|
`affine3TargetTo` are built once per frame or resize, so they validate and
|
|
202
205
|
throw a `RangeError` (leaving `out` untouched) where the operations return
|
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
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
21
|
+
export declare function equilibrateForInversion_(out: number[], m: ArrayLike<number>, size: number): boolean;
|
|
12
22
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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
|
|
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
|
package/dist/_invert.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_invert.d.ts","sourceRoot":"","sources":["../src/_invert.ts"],"names":[],"mappings":"
|
|
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"}
|