@ac-kit/math-linear 0.4.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 (39) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +57 -4
  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/_matrix-shape.d.ts +4 -0
  8. package/dist/_matrix-shape.d.ts.map +1 -0
  9. package/dist/_matrix-shape.js +7 -0
  10. package/dist/_matrix-shape.js.map +1 -0
  11. package/dist/index.d.ts +5 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +5 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/lu-decomposition.d.ts +142 -0
  16. package/dist/lu-decomposition.d.ts.map +1 -0
  17. package/dist/lu-decomposition.js +416 -0
  18. package/dist/lu-decomposition.js.map +1 -0
  19. package/dist/matrix.d.ts +136 -0
  20. package/dist/matrix.d.ts.map +1 -0
  21. package/dist/matrix.js +308 -0
  22. package/dist/matrix.js.map +1 -0
  23. package/dist/qr-decomposition.d.ts +283 -0
  24. package/dist/qr-decomposition.d.ts.map +1 -0
  25. package/dist/qr-decomposition.js +1071 -0
  26. package/dist/qr-decomposition.js.map +1 -0
  27. package/dist/singular-value-decomposition.d.ts +154 -0
  28. package/dist/singular-value-decomposition.d.ts.map +1 -0
  29. package/dist/singular-value-decomposition.js +474 -0
  30. package/dist/singular-value-decomposition.js.map +1 -0
  31. package/dist/symmetric-eigen-decomposition.d.ts +92 -0
  32. package/dist/symmetric-eigen-decomposition.d.ts.map +1 -0
  33. package/dist/symmetric-eigen-decomposition.js +289 -0
  34. package/dist/symmetric-eigen-decomposition.js.map +1 -0
  35. package/dist/vec2-array.d.ts +16 -0
  36. package/dist/vec2-array.d.ts.map +1 -1
  37. package/dist/vec2-array.js +42 -0
  38. package/dist/vec2-array.js.map +1 -1
  39. package/package.json +11 -10
@@ -0,0 +1,416 @@
1
+ function assertSquare_(name, matrix, size) {
2
+ if (matrix.rows !== size ||
3
+ matrix.columns !== size ||
4
+ matrix.data.length !== size * size) {
5
+ throw new RangeError(`${name}: expected a ${size} × ${size} matrix, got ${matrix.rows} × ${matrix.columns}`);
6
+ }
7
+ }
8
+ /**
9
+ * An LU decomposition with partial pivoting, `P·A = L·U` (LAPACK `xGETRF`), as
10
+ * a plan for one size: the factors and scratch are allocated once by the
11
+ * constructor, and `decompose`, `solve`, `determinant` and
12
+ * `reciprocalCondition` allocate nothing afterwards.
13
+ *
14
+ * The general solver for a square system: about `⅔n³` operations, half of a
15
+ * QR's. Partial pivoting is backward stable in practice (Wilkinson's growth
16
+ * factor is rarely large); for symmetric positive-definite matrices
17
+ * {@link CholeskyDecomposition} is twice as fast again, and for least squares or
18
+ * rank-deficient matrices `QrDecomposition` is the right tool.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const lu = new LuDecomposition(2);
23
+ * lu.decompose(matrixOfRows([[4, 3], [6, 3]])); // true
24
+ * lu.solve(new Float64Array(2), Float64Array.of(10, 12)); // [1, 2]
25
+ * lu.determinant; // -6
26
+ * ```;
27
+ */
28
+ export class LuDecomposition {
29
+ /** The order of the matrices this decomposition takes. */
30
+ size;
31
+ factors_;
32
+ pivots_;
33
+ work_;
34
+ work2_;
35
+ sign_ = 1;
36
+ singular_ = true;
37
+ norm1_ = 0;
38
+ /** @throws {RangeError} When `size` is not a non-negative safe integer. */
39
+ constructor(size) {
40
+ if (!Number.isSafeInteger(size) ||
41
+ size < 0 ||
42
+ !Number.isSafeInteger(size * size)) {
43
+ throw new RangeError(`LuDecomposition: size must be a non-negative integer, got ${size}`);
44
+ }
45
+ this.size = size;
46
+ this.factors_ = new Float64Array(size * size);
47
+ this.pivots_ = new Int32Array(size);
48
+ this.work_ = new Float64Array(size);
49
+ this.work2_ = new Float64Array(size);
50
+ }
51
+ /**
52
+ * The row interchanges: row `i` of `U` came from row `pivots[i]` after the
53
+ * earlier interchanges (LAPACK's `ipiv`, 0-based). Read, never write.
54
+ */
55
+ get pivots() {
56
+ return this.pivots_;
57
+ }
58
+ /** `det A`, the product of `U`'s diagonal with the permutation's sign. */
59
+ get determinant() {
60
+ const n = this.size;
61
+ let product = this.sign_;
62
+ for (let k = 0; k < n; k++) {
63
+ product *= this.factors_[k * n + k];
64
+ }
65
+ return product;
66
+ }
67
+ /** Whether `U` has an exactly zero pivot (or a non-finite entry). */
68
+ get singular() {
69
+ return this.singular_;
70
+ }
71
+ /**
72
+ * Factorises `matrix`. Returns `false` when a pivot is exactly zero or an
73
+ * entry not finite; the factors are then incomplete and `solve` answers
74
+ * `NaN`.
75
+ *
76
+ * @throws {RangeError} When `matrix` is not `size × size`.
77
+ */
78
+ decompose(matrix) {
79
+ const n = this.size;
80
+ assertSquare_("LuDecomposition.decompose", matrix, n);
81
+ const a = this.factors_;
82
+ a.set(matrix.data);
83
+ let norm = 0;
84
+ let finite = true;
85
+ for (let column = 0; column < n; column++) {
86
+ let sum = 0;
87
+ for (let row = 0; row < n; row++) {
88
+ const value = a[column * n + row];
89
+ finite &&= value - value === 0;
90
+ sum += Math.abs(value);
91
+ }
92
+ norm = Math.max(norm, sum);
93
+ }
94
+ this.norm1_ = norm;
95
+ this.sign_ = 1;
96
+ this.singular_ = !finite;
97
+ if (!finite) {
98
+ return false;
99
+ }
100
+ for (let k = 0; k < n; k++) {
101
+ let pivot = k;
102
+ let largest = Math.abs(a[k * n + k]);
103
+ for (let row = k + 1; row < n; row++) {
104
+ const magnitude = Math.abs(a[k * n + row]);
105
+ if (magnitude > largest) {
106
+ largest = magnitude;
107
+ pivot = row;
108
+ }
109
+ }
110
+ this.pivots_[k] = pivot;
111
+ if (pivot !== k) {
112
+ for (let column = 0; column < n; column++) {
113
+ const index = column * n;
114
+ const swap = a[index + k];
115
+ a[index + k] = a[index + pivot];
116
+ a[index + pivot] = swap;
117
+ }
118
+ this.sign_ = -this.sign_;
119
+ }
120
+ const diagonal = a[k * n + k];
121
+ if (diagonal === 0) {
122
+ this.singular_ = true;
123
+ continue;
124
+ }
125
+ for (let row = k + 1; row < n; row++) {
126
+ a[k * n + row] = a[k * n + row] / diagonal;
127
+ }
128
+ for (let column = k + 1; column < n; column++) {
129
+ const factor = a[column * n + k];
130
+ if (factor === 0) {
131
+ continue;
132
+ }
133
+ for (let row = k + 1; row < n; row++) {
134
+ a[column * n + row] = a[column * n + row] - a[k * n + row] * factor;
135
+ }
136
+ }
137
+ }
138
+ return !this.singular_;
139
+ }
140
+ /**
141
+ * Solves `A·x = b` for the last decomposed `A` into `out`, which may be
142
+ * `right`. All `NaN` after a singular matrix.
143
+ *
144
+ * @throws {RangeError} When `out` or `right` does not hold `size` numbers.
145
+ */
146
+ solve(out, right) {
147
+ const n = this.size;
148
+ if (out.length !== n || right.length !== n) {
149
+ throw new RangeError(`LuDecomposition.solve: out and right need ${n} numbers, got ${out.length} and ${right.length}`);
150
+ }
151
+ if (this.singular_) {
152
+ return out.fill(Number.NaN);
153
+ }
154
+ if (out !== right) {
155
+ out.set(right);
156
+ }
157
+ this.solveInPlace_(out, false);
158
+ return out;
159
+ }
160
+ /** `A·x = b` (or `Aᵀ·x = b`) in place on `x`. */
161
+ solveInPlace_(x, transposed) {
162
+ const n = this.size;
163
+ const a = this.factors_;
164
+ const pivots = this.pivots_;
165
+ if (!transposed) {
166
+ for (let k = 0; k < n; k++) {
167
+ const pivot = pivots[k];
168
+ if (pivot !== k) {
169
+ const swap = x[k];
170
+ x[k] = x[pivot];
171
+ x[pivot] = swap;
172
+ }
173
+ }
174
+ for (let column = 0; column < n; column++) {
175
+ const value = x[column];
176
+ for (let row = column + 1; row < n; row++) {
177
+ x[row] = x[row] - a[column * n + row] * value;
178
+ }
179
+ }
180
+ for (let column = n - 1; column >= 0; column--) {
181
+ const value = x[column] / a[column * n + column];
182
+ x[column] = value;
183
+ for (let row = 0; row < column; row++) {
184
+ x[row] = x[row] - a[column * n + row] * value;
185
+ }
186
+ }
187
+ return;
188
+ }
189
+ // Uᵀ·y = b, then Lᵀ·z = y, then x = Pᵀ·z.
190
+ for (let column = 0; column < n; column++) {
191
+ let sum = x[column];
192
+ for (let row = 0; row < column; row++) {
193
+ sum -= a[column * n + row] * x[row];
194
+ }
195
+ x[column] = sum / a[column * n + column];
196
+ }
197
+ for (let column = n - 1; column >= 0; column--) {
198
+ let sum = x[column];
199
+ for (let row = column + 1; row < n; row++) {
200
+ sum -= a[column * n + row] * x[row];
201
+ }
202
+ x[column] = sum;
203
+ }
204
+ for (let k = n - 1; k >= 0; k--) {
205
+ const pivot = pivots[k];
206
+ if (pivot !== k) {
207
+ const swap = x[k];
208
+ x[k] = x[pivot];
209
+ x[pivot] = swap;
210
+ }
211
+ }
212
+ }
213
+ /**
214
+ * An estimate of `1 / (‖A‖₁ ‖A⁻¹‖₁)`, the reciprocal condition number in the
215
+ * 1-norm (LAPACK `xGECON`, Hager's estimator as refined by Higham): near 1
216
+ * for a well-conditioned matrix, near `ε` when the solution has no correct
217
+ * digit, `0` for a singular one. A lower bound on `‖A⁻¹‖₁` in at most five
218
+ * pairs of solves, almost always within a factor of three.
219
+ */
220
+ get reciprocalCondition() {
221
+ const n = this.size;
222
+ if (n === 0) {
223
+ return 1;
224
+ }
225
+ if (this.singular_) {
226
+ return 0;
227
+ }
228
+ const x = this.work_;
229
+ const sign = this.work2_;
230
+ x.fill(1 / n);
231
+ let estimate = 0;
232
+ let previousIndex = -1;
233
+ for (let iteration = 0; iteration < 5; iteration++) {
234
+ this.solveInPlace_(x, false);
235
+ let norm = 0;
236
+ for (let i = 0; i < n; i++) {
237
+ norm += Math.abs(x[i]);
238
+ sign[i] = x[i] >= 0 ? 1 : -1;
239
+ }
240
+ if (norm <= estimate && iteration > 0) {
241
+ break;
242
+ }
243
+ estimate = norm;
244
+ x.set(sign);
245
+ this.solveInPlace_(x, true);
246
+ let index = 0;
247
+ for (let i = 1; i < n; i++) {
248
+ if (Math.abs(x[i]) > Math.abs(x[index])) {
249
+ index = i;
250
+ }
251
+ }
252
+ if (index === previousIndex) {
253
+ break;
254
+ }
255
+ previousIndex = index;
256
+ x.fill(0);
257
+ x[index] = 1;
258
+ }
259
+ // Higham's alternative vector guards against the estimator's blind spots.
260
+ for (let i = 0; i < n; i++) {
261
+ x[i] = (i % 2 === 0 ? 1 : -1) * (1 + i / Math.max(n - 1, 1));
262
+ }
263
+ this.solveInPlace_(x, false);
264
+ let alternative = 0;
265
+ for (let i = 0; i < n; i++) {
266
+ alternative += Math.abs(x[i]);
267
+ }
268
+ estimate = Math.max(estimate, (2 * alternative) / (3 * n));
269
+ const value = 1 / (this.norm1_ * estimate);
270
+ return value === value ? Math.min(value, 1) : 0;
271
+ }
272
+ }
273
+ /**
274
+ * Solves the square system `A·x = b` by LU decomposition with partial pivoting,
275
+ * and estimates the reciprocal condition number so a caller can tell an answer
276
+ * that is right from one that only looks right. The one-shot form of
277
+ * {@link LuDecomposition}: it allocates the plan.
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * matrixSolve(matrixOfRows([[2, 1], [1, 3]]), Float64Array.of(3, 5)); // { solution: [0.8, 1.4], reciprocalCondition: ≈ 0.4 }
282
+ * ```;
283
+ *
284
+ * @throws {RangeError} When `matrix` is not square or `right` has another
285
+ * length.
286
+ */
287
+ export function matrixSolve(matrix, right) {
288
+ const lu = new LuDecomposition(matrix.rows);
289
+ lu.decompose(matrix);
290
+ const solution = lu.solve(new Float64Array(matrix.rows), right);
291
+ return { solution, reciprocalCondition: lu.reciprocalCondition };
292
+ }
293
+ /**
294
+ * A Cholesky decomposition `A = L·Lᵀ` of a symmetric positive-definite matrix
295
+ * (LAPACK `xPOTRF`, lower triangle), as a plan for one size: half the work of
296
+ * LU, no pivoting, and the decomposition itself is the test of positive
297
+ * definiteness — what a covariance matrix, a Gram matrix or the normal
298
+ * equations of a well-posed fit need.
299
+ *
300
+ * Only the lower triangle of the matrix is read.
301
+ *
302
+ * @example
303
+ * ```ts
304
+ * const cholesky = new CholeskyDecomposition(2);
305
+ * cholesky.decompose(matrixOfRows([[4, 2], [2, 3]])); // true
306
+ * cholesky.solve(new Float64Array(2), Float64Array.of(2, 1)); // [0.5, 0]
307
+ * ```;
308
+ */
309
+ export class CholeskyDecomposition {
310
+ /** The order of the matrices this decomposition takes. */
311
+ size;
312
+ factor_;
313
+ positive_ = false;
314
+ /** @throws {RangeError} When `size` is not a non-negative safe integer. */
315
+ constructor(size) {
316
+ if (!Number.isSafeInteger(size) ||
317
+ size < 0 ||
318
+ !Number.isSafeInteger(size * size)) {
319
+ throw new RangeError(`CholeskyDecomposition: size must be a non-negative integer, got ${size}`);
320
+ }
321
+ this.size = size;
322
+ this.factor_ = new Float64Array(size * size);
323
+ }
324
+ /** Whether the last decomposed matrix was positive definite. */
325
+ get positiveDefinite() {
326
+ return this.positive_;
327
+ }
328
+ /**
329
+ * `L`, column-major `size × size` with zeros above the diagonal. Read, never
330
+ * write.
331
+ */
332
+ get factor() {
333
+ return this.factor_;
334
+ }
335
+ /** `ln det A = 2 Σ ln Lₖₖ`, without the overflow of the determinant. */
336
+ get logDeterminant() {
337
+ if (!this.positive_) {
338
+ return Number.NaN;
339
+ }
340
+ const n = this.size;
341
+ let sum = 0;
342
+ for (let k = 0; k < n; k++) {
343
+ sum += Math.log(this.factor_[k * n + k]);
344
+ }
345
+ return 2 * sum;
346
+ }
347
+ /**
348
+ * Factorises the lower triangle of `matrix`. Returns `false` when it is not
349
+ * positive definite (a pivot is not positive) or not finite.
350
+ *
351
+ * @throws {RangeError} When `matrix` is not `size × size`.
352
+ */
353
+ decompose(matrix) {
354
+ const n = this.size;
355
+ assertSquare_("CholeskyDecomposition.decompose", matrix, n);
356
+ const l = this.factor_;
357
+ const a = matrix.data;
358
+ l.fill(0);
359
+ this.positive_ = false;
360
+ for (let column = 0; column < n; column++) {
361
+ let diagonal = a[column * n + column];
362
+ for (let k = 0; k < column; k++) {
363
+ diagonal -= l[k * n + column] ** 2;
364
+ }
365
+ if (!(diagonal > 0) || diagonal === Infinity) {
366
+ return false;
367
+ }
368
+ const root = Math.sqrt(diagonal);
369
+ l[column * n + column] = root;
370
+ for (let row = column + 1; row < n; row++) {
371
+ let sum = a[column * n + row];
372
+ for (let k = 0; k < column; k++) {
373
+ sum -= l[k * n + row] * l[k * n + column];
374
+ }
375
+ l[column * n + row] = sum / root;
376
+ }
377
+ }
378
+ this.positive_ = true;
379
+ return true;
380
+ }
381
+ /**
382
+ * Solves `A·x = b` for the last decomposed `A` into `out`, which may be
383
+ * `right`; all `NaN` when it was not positive definite.
384
+ *
385
+ * @throws {RangeError} When `out` or `right` does not hold `size` numbers.
386
+ */
387
+ solve(out, right) {
388
+ const n = this.size;
389
+ if (out.length !== n || right.length !== n) {
390
+ throw new RangeError(`CholeskyDecomposition.solve: out and right need ${n} numbers, got ${out.length} and ${right.length}`);
391
+ }
392
+ if (!this.positive_) {
393
+ return out.fill(Number.NaN);
394
+ }
395
+ if (out !== right) {
396
+ out.set(right);
397
+ }
398
+ const l = this.factor_;
399
+ for (let column = 0; column < n; column++) {
400
+ const value = out[column] / l[column * n + column];
401
+ out[column] = value;
402
+ for (let row = column + 1; row < n; row++) {
403
+ out[row] = out[row] - l[column * n + row] * value;
404
+ }
405
+ }
406
+ for (let column = n - 1; column >= 0; column--) {
407
+ let sum = out[column];
408
+ for (let row = column + 1; row < n; row++) {
409
+ sum -= l[column * n + row] * out[row];
410
+ }
411
+ out[column] = sum / l[column * n + column];
412
+ }
413
+ return out;
414
+ }
415
+ }
416
+ //# sourceMappingURL=lu-decomposition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lu-decomposition.js","sourceRoot":"","sources":["../src/lu-decomposition.ts"],"names":[],"mappings":"AAEA,SAAS,aAAa,CAAC,IAAY,EAAE,MAAc,EAAE,IAAY;IAChE,IACC,MAAM,CAAC,IAAI,KAAK,IAAI;QACpB,MAAM,CAAC,OAAO,KAAK,IAAI;QACvB,MAA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E,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;YAC3C,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAE,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,CAAE,CAAC;YACrD,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;YACpB,KAAK,IAAI,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;gBAC3C,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAE,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG,CAAE,GAAG,KAAK,CAAC;YACrD,CAAC;QACF,CAAC;QACD,KAAK,IAAI,MAAM,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;YAChD,IAAI,GAAG,GAAG,GAAG,CAAC,MAAM,CAAE,CAAC;YACvB,KAAK,IAAI,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;gBAC3C,GAAG,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG,CAAE,GAAG,GAAG,CAAC,GAAG,CAAE,CAAC;YACzC,CAAC;YACD,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,CAAE,CAAC;QAC7C,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC;CACD"}
@@ -0,0 +1,136 @@
1
+ import { type IsCloseToOptions } from "@ac-kit/core";
2
+ /**
3
+ * A dense matrix of any size: `rows × columns` binary64 entries in one packed
4
+ * `Float64Array`, **column-major** like every matrix of this package — the
5
+ * entry of row `r`, column `c` is `data[rows · c + r]` — so the 16 entries of a
6
+ * `Mat4x4` stored with `mat4x4Store` are a valid 4 × 4 `data`, and LAPACK's
7
+ * layout with a leading dimension of `rows`.
8
+ *
9
+ * A separate type from the fixed sizes, which get their speed from having no
10
+ * runtime dimension: this one is for the decompositions, solvers and statistics
11
+ * beyond 4 × 4 (see `QrDecomposition`).
12
+ *
13
+ * Invariant: `data.length === rows · columns`, which every creator and
14
+ * {@link matrixView} check and every operation checks again (a `RangeError`),
15
+ * since the three fields are plain data. The fields are read-only; the entries
16
+ * are not.
17
+ */
18
+ export type Matrix = {
19
+ /** The entries, column after column. */
20
+ readonly data: Float64Array;
21
+ /** Number of rows, a non-negative integer. */
22
+ readonly rows: number;
23
+ /** Number of columns, a non-negative integer. */
24
+ readonly columns: number;
25
+ };
26
+ /**
27
+ * A `rows × columns` matrix of zeros, over a new `Float64Array`.
28
+ *
29
+ * @throws {RangeError} When `rows` or `columns` is not a non-negative safe
30
+ * integer, or their product is not a safe integer.
31
+ */
32
+ export declare function matrixCreate(rows: number, columns: number): Matrix;
33
+ /**
34
+ * A matrix over existing storage, without a copy: `data` must hold exactly
35
+ * `rows · columns` entries in column-major order (a `subarray` selects part of
36
+ * a larger buffer). Writes through the matrix change `data`, and the reverse.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * // [[1, 3], [2, 4]]: columns (1, 2) and (3, 4).
41
+ * const m = matrixView(Float64Array.of(1, 2, 3, 4), 2, 2);
42
+ * matrixGet(m, 0, 1); // 3
43
+ * ```;
44
+ *
45
+ * @throws {RangeError} When `rows` or `columns` is not a non-negative safe
46
+ * integer, or `data.length` is not their product.
47
+ */
48
+ export declare function matrixView(data: Float64Array, rows: number, columns: number): Matrix;
49
+ /**
50
+ * A matrix from its rows in reading order, copied: `matrixOfRows([[1, 2], [3,
51
+ * 4]])` has `1, 2` on its first row. An entry that is not a number is stored as
52
+ * `NaN`, as `…FromArray` does.
53
+ *
54
+ * @throws {RangeError} When the rows are not all of one length; an empty list
55
+ * gives a 0 × 0 matrix.
56
+ */
57
+ export declare function matrixOfRows(rows: readonly (readonly number[])[]): Matrix;
58
+ /**
59
+ * The entry of row `row`, column `column`. Loops over many entries read `data`
60
+ * directly at `rows · column + row`.
61
+ *
62
+ * @throws {RangeError} When the index is not an integer inside the matrix.
63
+ */
64
+ export declare function matrixGet(m: Matrix, row: number, column: number): number;
65
+ /**
66
+ * Stores `value` at row `row`, column `column`, and returns `m`.
67
+ *
68
+ * @throws {RangeError} When the index is not an integer inside the matrix.
69
+ */
70
+ export declare function matrixSet(m: Matrix, row: number, column: number, value: number): Matrix;
71
+ /**
72
+ * Copies `m` into `out` (same shape) and returns `out`; `out` may be `m`.
73
+ *
74
+ * @throws {RangeError} When the shapes differ or a matrix breaks the
75
+ * {@link Matrix} invariant.
76
+ */
77
+ export declare function matrixCopy(out: Matrix, m: Matrix): Matrix;
78
+ /**
79
+ * Writes the identity into `out` — ones on the main diagonal, zeros elsewhere,
80
+ * for a rectangular matrix too — and returns it.
81
+ *
82
+ * @throws {RangeError} When `out` breaks the {@link Matrix} invariant.
83
+ */
84
+ export declare function matrixIdentity(out: Matrix): Matrix;
85
+ /**
86
+ * Writes `mᵀ` into `out` (`columns × rows`) and returns it.
87
+ *
88
+ * @throws {RangeError} When `out` is not `m.columns × m.rows`, shares storage
89
+ * with `m` (a transpose in place is not offered: it is only cheap for square
90
+ * matrices), or a matrix breaks the {@link Matrix} invariant.
91
+ */
92
+ export declare function matrixTranspose(out: Matrix, m: Matrix): Matrix;
93
+ /**
94
+ * Writes the product `a · b` into `out` (`a.rows × b.columns`) and returns it.
95
+ * Plain arithmetic, summed in index order; O(a.rows · a.columns · b.columns).
96
+ *
97
+ * @throws {RangeError} When `a.columns !== b.rows`, `out` has the wrong shape
98
+ * or shares storage with `a` or `b`, or a matrix breaks the {@link Matrix}
99
+ * invariant.
100
+ */
101
+ export declare function matrixMultiply(out: Matrix, a: Matrix, b: Matrix): Matrix;
102
+ /**
103
+ * Writes `m · x` into `out` (`m.rows` numbers) and returns it. Plain
104
+ * arithmetic; O(rows · columns).
105
+ *
106
+ * @throws {RangeError} When `x` does not hold `m.columns` numbers, `out` does
107
+ * not hold `m.rows`, `out` shares storage with `x` or `m`, or `m` breaks the
108
+ * {@link Matrix} invariant.
109
+ */
110
+ export declare function matrixMultiplyVector(out: Float64Array, m: Matrix, x: Float64Array): Float64Array;
111
+ /**
112
+ * Writes `mᵀ · x` into `out` (`m.columns` numbers) and returns it: one dot
113
+ * product per column, in index order. O(rows · columns).
114
+ *
115
+ * @throws {RangeError} When `x` does not hold `m.rows` numbers, `out` does not
116
+ * hold `m.columns`, `out` shares storage with `x` or `m`, or `m` breaks the
117
+ * {@link Matrix} invariant.
118
+ */
119
+ export declare function matrixTransposeMultiplyVector(out: Float64Array, m: Matrix, x: Float64Array): Float64Array;
120
+ /**
121
+ * Exact equality of shape and entries: `−0` equals `+0`, and `NaN` equals
122
+ * nothing. See {@link matrixIsClose} for a tolerant test.
123
+ */
124
+ export declare function matrixEquals(a: Matrix, b: Matrix): boolean;
125
+ /**
126
+ * Same shape and every pair of entries close by `@ac-kit/core`'s `isCloseTo`
127
+ * with `options` (none means exact). The tolerance is required: a matrix has no
128
+ * units of its own.
129
+ */
130
+ export declare function matrixIsClose(a: Matrix, b: Matrix, options: IsCloseToOptions): boolean;
131
+ /**
132
+ * Whether every entry is finite: the check to run on data of unknown origin
133
+ * (operations never check values).
134
+ */
135
+ export declare function matrixIsFinite(m: Matrix): boolean;
136
+ //# sourceMappingURL=matrix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matrix.d.ts","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,gBAAgB,EAErB,MAAM,cAAc,CAAC;AAItB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,MAAM,GAAG;IACpB,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAE5B,8CAA8C;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,iDAAiD;IACjD,QAAQ,CAAC,O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