@tangent.to/lina 0.1.4 → 0.1.5

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/llms-full.txt ADDED
@@ -0,0 +1,604 @@
1
+ # @tangent.to/lina 0.1.5
2
+
3
+ > Linear algebra for JavaScript (ESM): LU, QR, Cholesky, SVD, symmetric eigen, least squares. scipy.linalg-validated.
4
+
5
+ Linear algebra for JavaScript in browsers, Node.js and Deno. This
6
+ dependency-free package provides the matrix solvers used by Tangent's
7
+ statistics, autodiff and differential-equation packages.
8
+
9
+ Matrices are plain nested row-major arrays (`number[][]`) at the API
10
+ boundary; computation runs on flat `Float64Array` storage internally.
11
+
12
+ ## What's in it
13
+
14
+ - **Factorizations**: `lu` (partial pivoting), `qr` (Householder,
15
+ reduced/full), `cholesky`, `svd` (one-sided Jacobi — high relative
16
+ accuracy), `eigSym` (cyclic Jacobi, symmetric matrices)
17
+ - **Generalized eigenproblem**: `eigSymGeneralized` (`A x = λ B x` by
18
+ Cholesky reduction, with a truncated fallback when `B` is singular),
19
+ `invSqrtSym` (truncated inverse square root)
20
+ - **Solvers**: `solve` (vector or multi-RHS), `choleskySolve` (vector or
21
+ multi-RHS), `lstsq` (QR-based), `pinvSolve` (minimum-norm, any rank)
22
+ - **SVD-derived**: `pinv`, `rank`, `cond`
23
+ - **Utilities**: `matmul`, `transpose`, `identity`, `diag`, `norm`
24
+ (fro/1/inf), `trace`, `det`, `inv`, `isPositiveDefinite`
25
+
26
+ ## Install
27
+
28
+ ```bash
29
+ npm install @tangent.to/lina # npm
30
+ deno add jsr:@tangent/lina # Deno / JSR
31
+ ```
32
+
33
+ The npm package includes TypeScript declarations, `llms.txt` and
34
+ `llms-full.txt`. In a notebook, `await help('solve')` shows the argument
35
+ and return types.
36
+
37
+ ## Usage
38
+
39
+ ```javascript
40
+ import { cholesky, eigSym, eigSymGeneralized, lstsq, solve, svd } from '@tangent.to/lina';
41
+
42
+ solve([[2, 1], [1, 3]], [3, 5]); // [0.8, 1.4]
43
+
44
+ const { values, vectors } = eigSym(covarianceMatrix); // PCA in two lines
45
+ const { U, s, V } = svd(dataMatrix);
46
+
47
+ const { x } = lstsq(designMatrix, y); // OLS coefficients
48
+ const L = cholesky(spdMatrix); // throws if not positive definite
49
+
50
+ // Discriminant axes: Sb x = λ Sw x, scipy's eigh(Sb, Sw) without the
51
+ // hard failure when Sw is rank-deficient
52
+ const { values: ratios, vectors: axes, definite } = eigSymGeneralized(Sb, Sw);
53
+ ```
54
+
55
+ ## Validation against numpy/scipy
56
+
57
+ `tests_compare-to-scipy/` checks every operation against
58
+ `numpy.linalg`/`scipy.linalg` on seeded random matrices — solve/det/inv,
59
+ Cholesky (entrywise vs numpy), QR and SVD invariants, singular values and
60
+ symmetric eigenvalues vs numpy, the generalized symmetric eigenproblem vs
61
+ `scipy.linalg.eigh(A, B)` (eigenvalues, residual and B-orthonormality),
62
+ `invSqrtSym` vs `fractional_matrix_power(A, -1/2)`, lstsq, pinv (including
63
+ rank-deficient), rank and cond. Agreement is at machine precision (~1e-15).
64
+ Requires
65
+ [uv](https://docs.astral.sh/uv/) and Node:
66
+
67
+ ```bash
68
+ npm run test:scipy
69
+ ```
70
+
71
+ ## Scope
72
+
73
+ Dense, double-precision, textbook-modern algorithms sized for the suite's
74
+ workloads (covariance algebra, regression, ordination — n up to a few
75
+ hundred). Deliberately out of scope: sparse matrices, complex numbers,
76
+ general nonsymmetric eigenproblems (until a consumer needs them), and
77
+ BLAS-style micro-optimization — wasm kernels belong in tangent/nd when it
78
+ lands.
79
+
80
+ ## Performance
81
+
82
+ lina favors simple, unconditionally-stable algorithms (one-sided Jacobi
83
+ SVD, cyclic Jacobi eigensolver) that hit machine precision on the suite's
84
+ target sizes. On `solve`/`inv` it is competitive with the mature
85
+ `ml-matrix`; on `matmul` and `svd` it is roughly 1.5–2× slower, and on
86
+ symmetric eigendecomposition about 5× slower, because those Jacobi methods
87
+ trade speed for simplicity. If a consumer ever profiles past this, the fix
88
+ is targeted, not a rewrite: swap the symmetric eigensolver for tridiagonal
89
+ QL and the SVD for Golub–Reinsch (the JAMA algorithms), and improve
90
+ `matmul` cache locality. Until then, correctness and a zero-dependency
91
+ footprint win. lina is not a general-purpose matrix library — for the rich
92
+ `Matrix` API (elementwise arithmetic, broadcasting, views, nonsymmetric
93
+ eigen), use `ml-matrix`; lina is the focused linear-algebra leaf the
94
+ tangent suite's own packages build on.
95
+
96
+ ## License
97
+
98
+ MIT.
99
+
100
+ ## Exports
101
+
102
+ - `help`: This package's documentation, for where the README is out of reach, such as a notebook, and for coding assistants.
103
+ - `version`: This package's version.
104
+ - `det`: Determinant via LU factorization (permutation sign times product of pivots).
105
+ - `inv`: Matrix inverse via solve(A, I).
106
+ - `lu`: LU factorization with partial pivoting: P A = L U.
107
+ - `luFactor`: LU factorization in packed flat storage, for callers that back-substitute many right-hand sides against one factorization on a hot path.
108
+ - `luFactorSolve`: Solve A x = b from a packed factorization returned by luFactor().
109
+ - `solve`: Solve A x = b via LU factorization with partial pivoting.
110
+ - `cholesky`: Cholesky factorization of a symmetric positive definite matrix.
111
+ - `choleskySolve`: Solve A x = b (or A X = B) given the Cholesky factor L of A (A = L L^T), by forward substitution (L y = b) then back substitution (L^T x = y).
112
+ - `isPositiveDefinite`: Test positive definiteness by attempting a Cholesky factorization.
113
+ - `lstsq`: Least-squares solution of A x ≈ b via reduced QR.
114
+ - `qr`: QR decomposition A = Q R via Householder reflections.
115
+ - `cond`: Condition number (2-norm): s_max / s_min.
116
+ - `pinv`: Moore-Penrose pseudoinverse via SVD, with numpy's default cutoff.
117
+ - `pinvSolve`: Minimum-norm least squares via the pseudoinverse (works for any rank).
118
+ - `rank`: Numerical rank via SVD.
119
+ - `svd`: Thin SVD: A = U diag(s) V^T with U m×k, s length k, V n×k, k = min(m, n).
120
+ - `eigSym`: Eigendecomposition of a symmetric matrix: A = V diag(values) V^T.
121
+ - `eigSymGeneralized`: Generalized symmetric eigenproblem A x = lambda B x, for symmetric A and symmetric positive (semi)definite B.
122
+ - `invSqrtSym`: Inverse square root of a symmetric positive semidefinite matrix: the symmetric W with W A W = I on A's range, and W = 0 on its null space.
123
+ - `diag`: Build a diagonal matrix from a vector, or extract the diagonal of a matrix.
124
+ - `identity`: Identity matrix of size n.
125
+ - `matmul`: Matrix product A B, or matrix-vector product A b.
126
+ - `norm`: Matrix or vector norm.
127
+ - `trace`: Sum of the diagonal of a square matrix.
128
+ - `transpose`: Matrix transpose.
129
+
130
+ Each export in full, with its types and options: https://cdn.jsdelivr.net/npm/@tangent.to/lina@0.1.5/llms-full.txt, or `await help('name')`
131
+ from the package itself.
132
+
133
+ ## Reference
134
+
135
+ ### help
136
+
137
+ ```ts
138
+ /**
139
+ * This package's documentation, for where the README is out of reach, such
140
+ * as a notebook, and for coding assistants.
141
+ *
142
+ * @param {string} [name] - an export, such as `'solve'`
143
+ * @returns {Promise<string>} its declaration, options and examples; without
144
+ * `name`, the overview and a line per export
145
+ * @example
146
+ * await help(); // overview and index
147
+ * await help('solve'); // one export in full
148
+ */
149
+ export function help(name?: string): Promise<string>;
150
+ ```
151
+
152
+ ### version
153
+
154
+ ```ts
155
+ /** This package's version. */
156
+ export const version: "0.1.5";
157
+ ```
158
+
159
+ ### det
160
+
161
+ ```ts
162
+ /**
163
+ * Determinant via LU factorization (permutation sign times product of pivots).
164
+ * Returns 0 for singular matrices instead of throwing.
165
+ *
166
+ * @param {Array<Array<number>>} A - Square nested matrix
167
+ * @returns {number}
168
+ */
169
+ export function det(A: Array<Array<number>>): number;
170
+ ```
171
+
172
+ ### inv
173
+
174
+ ```ts
175
+ /**
176
+ * Matrix inverse via solve(A, I).
177
+ *
178
+ * @param {Array<Array<number>>} A - Square nested matrix
179
+ * @returns {Array<Array<number>>}
180
+ */
181
+ export function inv(A: Array<Array<number>>): Array<Array<number>>;
182
+ ```
183
+
184
+ ### lu
185
+
186
+ ```ts
187
+ /**
188
+ * LU factorization with partial pivoting: P A = L U.
189
+ *
190
+ * @param {Array<Array<number>>} A - Square nested matrix
191
+ * @returns {{L: Array<Array<number>>, U: Array<Array<number>>, P: Array<Array<number>>}}
192
+ * L unit lower triangular, U upper triangular, P a permutation matrix.
193
+ */
194
+ export function lu(A: Array<Array<number>>): {
195
+ L: Array<Array<number>>;
196
+ U: Array<Array<number>>;
197
+ P: Array<Array<number>>;
198
+ };
199
+ ```
200
+
201
+ ### luFactor
202
+
203
+ ```ts
204
+ /**
205
+ * LU factorization in packed flat storage, for callers that back-substitute
206
+ * many right-hand sides against one factorization on a hot path.
207
+ *
208
+ * Unlike lu(), this skips building the nested L, U and dense permutation
209
+ * matrix P: it returns the combined LU array directly (unit-diagonal L
210
+ * strictly below the diagonal, U on and above, in row-major n*n storage)
211
+ * together with the permutation vector, so no nested round-trip or
212
+ * permutation-matrix scan is needed. Pair it with luFactorSolve().
213
+ *
214
+ * @param {Array<Array<number>>} A - Square nested matrix
215
+ * @returns {{lu: Float64Array, perm: Int32Array, n: number, sign: number, singular: boolean}}
216
+ * `lu` is the combined LU storage (row-major n*n); `perm` maps factored row k
217
+ * to input row perm[k]; `sign` is the permutation sign; `singular` flags a
218
+ * pivot at or below 1e-13 * maxAbs(A).
219
+ */
220
+ export function luFactor(A: Array<Array<number>>): {
221
+ lu: Float64Array;
222
+ perm: Int32Array;
223
+ n: number;
224
+ sign: number;
225
+ singular: boolean;
226
+ };
227
+ ```
228
+
229
+ ### luFactorSolve
230
+
231
+ ```ts
232
+ /**
233
+ * Solve A x = b from a packed factorization returned by luFactor().
234
+ *
235
+ * @param {{lu: Float64Array, perm: Int32Array, n: number}} fac - luFactor() result
236
+ * @param {Array<number>|Float64Array} b - Right-hand side (length n, not modified)
237
+ * @returns {Float64Array} Solution vector x
238
+ */
239
+ export function luFactorSolve(fac: {
240
+ lu: Float64Array;
241
+ perm: Int32Array;
242
+ n: number;
243
+ }, b: Array<number> | Float64Array): Float64Array;
244
+ ```
245
+
246
+ ### solve
247
+
248
+ ```ts
249
+ /**
250
+ * Solve A x = b via LU factorization with partial pivoting.
251
+ *
252
+ * @param {Array<Array<number>>} A - Square nested matrix
253
+ * @param {Array<number>|Array<Array<number>>} b - Right-hand side vector (length n)
254
+ * or nested matrix of right-hand sides (n x k, solved column by column)
255
+ * @returns {Array<number>|Array<Array<number>>} Solution vector, or nested n x k matrix
256
+ */
257
+ export function solve(A: Array<Array<number>>, b: Array<number> | Array<Array<number>>): Array<number> | Array<Array<number>>;
258
+ ```
259
+
260
+ ### cholesky
261
+
262
+ ```ts
263
+ /**
264
+ * Cholesky factorization of a symmetric positive definite matrix.
265
+ *
266
+ * @param {Array<Array<number>>} A - Symmetric positive definite nested matrix
267
+ * @returns {Array<Array<number>>} Lower triangular L with A = L L^T
268
+ * @throws {Error} When A is not symmetric, or a diagonal pivot is <= 0
269
+ * (not positive definite)
270
+ */
271
+ export function cholesky(A: Array<Array<number>>): Array<Array<number>>;
272
+ ```
273
+
274
+ ### choleskySolve
275
+
276
+ ```ts
277
+ /**
278
+ * Solve A x = b (or A X = B) given the Cholesky factor L of A (A = L L^T), by
279
+ * forward substitution (L y = b) then back substitution (L^T x = y).
280
+ *
281
+ * Accepts either a single right-hand side vector or a matrix of them. Passing
282
+ * the whole set at once matters: the alternative — calling this once per
283
+ * column — repeats the triangular walk's setup per column, which turns
284
+ * building an inverse into markedly more work than it needs. Measured on a
285
+ * 340x340 factor, one call with 340 right-hand sides against 340 single-vector
286
+ * calls: 76 ms against 371 ms.
287
+ *
288
+ * Reads the factor's nested rows directly rather than copying it to flat
289
+ * storage, and divides rather than multiplying by a reciprocal so the scaling
290
+ * step stays exact. The two paths accumulate in different orders — a scalar
291
+ * per element for one right-hand side, an axpy across the row for many — so
292
+ * they agree to roundoff (~1e-19 relative on the sizes measured) rather than
293
+ * bit for bit.
294
+ *
295
+ * @param {Array<Array<number>>} L - Lower triangular factor from cholesky()
296
+ * @param {Array<number>|Array<Array<number>>} b - Right-hand side vector, or
297
+ * an n x k matrix of right-hand sides
298
+ * @returns {Array<number>|Array<Array<number>>} Solution, matching the shape
299
+ * of `b`
300
+ */
301
+ export function choleskySolve(L: Array<Array<number>>, b: Array<number> | Array<Array<number>>): Array<number> | Array<Array<number>>;
302
+ ```
303
+
304
+ ### isPositiveDefinite
305
+
306
+ ```ts
307
+ /**
308
+ * Test positive definiteness by attempting a Cholesky factorization.
309
+ * Never throws; non-symmetric or malformed input returns false.
310
+ *
311
+ * @param {Array<Array<number>>} A - Nested matrix
312
+ * @returns {boolean}
313
+ */
314
+ export function isPositiveDefinite(A: Array<Array<number>>): boolean;
315
+ ```
316
+
317
+ ### lstsq
318
+
319
+ ```ts
320
+ /**
321
+ * Least-squares solution of A x ≈ b via reduced QR.
322
+ *
323
+ * Requires m >= n and full column rank: solves R x = Q^T b by back
324
+ * substitution. Throws for rank-deficient R.
325
+ *
326
+ * @param {Array<Array<number>>} A - m x n matrix with m >= n
327
+ * @param {Array<number>} b - Right-hand side of length m
328
+ * @returns {{x: Array<number>, residualNorm: number}} residualNorm = ||A x - b||_2
329
+ */
330
+ export function lstsq(A: Array<Array<number>>, b: Array<number>): {
331
+ x: Array<number>;
332
+ residualNorm: number;
333
+ };
334
+ ```
335
+
336
+ ### qr
337
+
338
+ ```ts
339
+ /**
340
+ * QR decomposition A = Q R via Householder reflections.
341
+ *
342
+ * Works for any shape: m >= n and m < n alike.
343
+ *
344
+ * @param {Array<Array<number>>} A - m x n matrix
345
+ * @param {Object} [options]
346
+ * @param {string} [options.mode='reduced'] - 'reduced' (Q is m x min(m,n),
347
+ * R is min(m,n) x n) or 'full' (Q is m x m, R is m x n)
348
+ * @returns {{Q: Array<Array<number>>, R: Array<Array<number>>}}
349
+ */
350
+ export function qr(A: Array<Array<number>>, options?: {
351
+ mode?: string | undefined;
352
+ }): {
353
+ Q: Array<Array<number>>;
354
+ R: Array<Array<number>>;
355
+ };
356
+ ```
357
+
358
+ ### cond
359
+
360
+ ```ts
361
+ /**
362
+ * Condition number (2-norm): s_max / s_min. Infinity when singular.
363
+ *
364
+ * @param {Array<Array<number>>} A - Matrix
365
+ * @returns {number}
366
+ */
367
+ export function cond(A: Array<Array<number>>): number;
368
+ ```
369
+
370
+ ### pinv
371
+
372
+ ```ts
373
+ /**
374
+ * Moore-Penrose pseudoinverse via SVD, with numpy's default cutoff.
375
+ * Solves rank-deficient least squares: x = pinv(A) b is the minimum-norm
376
+ * solution.
377
+ *
378
+ * @param {Array<Array<number>>} A - Matrix (any shape)
379
+ * @param {number} [rcond] - Relative cutoff; default max(m,n) * eps
380
+ * @returns {Array<Array<number>>} n×m pseudoinverse
381
+ */
382
+ export function pinv(A: Array<Array<number>>, rcond?: number): Array<Array<number>>;
383
+ ```
384
+
385
+ ### pinvSolve
386
+
387
+ ```ts
388
+ /**
389
+ * Minimum-norm least squares via the pseudoinverse (works for any rank).
390
+ *
391
+ * @param {Array<Array<number>>} A - m×n matrix
392
+ * @param {Array<number>} b - Vector of length m
393
+ * @returns {Array<number>} x of length n
394
+ */
395
+ export function pinvSolve(A: Array<Array<number>>, b: Array<number>): Array<number>;
396
+ ```
397
+
398
+ ### rank
399
+
400
+ ```ts
401
+ /**
402
+ * Numerical rank via SVD.
403
+ *
404
+ * @param {Array<Array<number>>} A - Matrix
405
+ * @param {number} [tol] - Threshold; default max(m,n) * eps * s[0] (numpy convention)
406
+ * @returns {number}
407
+ */
408
+ export function rank(A: Array<Array<number>>, tol?: number): number;
409
+ ```
410
+
411
+ ### svd
412
+
413
+ ```ts
414
+ /**
415
+ * Thin SVD: A = U diag(s) V^T with U m×k, s length k, V n×k, k = min(m, n).
416
+ * Singular values are non-negative and descending.
417
+ *
418
+ * @param {Array<Array<number>>} A - Matrix (any shape)
419
+ * @param {Object} [options]
420
+ * @param {number} [options.maxSweeps=60] - Maximum Jacobi sweeps
421
+ * @param {number} [options.tol=1e-15] - Column-pair orthogonality tolerance
422
+ * @returns {{U: Array<Array<number>>, s: Array<number>, V: Array<Array<number>>}}
423
+ */
424
+ export function svd(A: Array<Array<number>>, options?: {
425
+ maxSweeps?: number | undefined;
426
+ tol?: number | undefined;
427
+ }): {
428
+ U: Array<Array<number>>;
429
+ s: Array<number>;
430
+ V: Array<Array<number>>;
431
+ };
432
+ ```
433
+
434
+ ### eigSym
435
+
436
+ ```ts
437
+ /**
438
+ * Eigendecomposition of a symmetric matrix: A = V diag(values) V^T.
439
+ *
440
+ * @param {Array<Array<number>>} A - Symmetric matrix (validated to 1e-10)
441
+ * @param {Object} [options]
442
+ * @param {number} [options.maxSweeps=60] - Maximum Jacobi sweeps
443
+ * @param {number} [options.tol=1e-14] - Off-diagonal convergence tolerance,
444
+ * relative to the Frobenius norm of the diagonal
445
+ * @returns {{values: Array<number>, vectors: Array<Array<number>>}}
446
+ * values[i] descending; vectors' column i is the eigenvector for values[i]
447
+ */
448
+ export function eigSym(A: Array<Array<number>>, options?: {
449
+ maxSweeps?: number | undefined;
450
+ tol?: number | undefined;
451
+ }): {
452
+ values: Array<number>;
453
+ vectors: Array<Array<number>>;
454
+ };
455
+ ```
456
+
457
+ ### eigSymGeneralized
458
+
459
+ ```ts
460
+ /**
461
+ * Generalized symmetric eigenproblem A x = lambda B x, for symmetric A and
462
+ * symmetric positive (semi)definite B.
463
+ *
464
+ * When B is positive definite this is the textbook Cholesky reduction:
465
+ * B = L L^T, eigendecompose C = L^-1 A L^-T, then x = L^-T y. The returned
466
+ * eigenvectors are B-orthonormal (x^T B x = 1), matching LAPACK/scipy's
467
+ * `eigh(A, B)`.
468
+ *
469
+ * When B is only semidefinite the Cholesky factorization does not exist —
470
+ * scipy raises here — so the reduction falls back to B's truncated inverse
471
+ * square root (see invSqrtSym). Note what this solves: with P the orthogonal
472
+ * projector onto range(B), the returned pairs satisfy
473
+ *
474
+ * P A x = lambda B x
475
+ *
476
+ * the eigenproblem of A restricted to range(B), which is the most that is
477
+ * defined when B is singular — off that range A x = lambda B x generally has
478
+ * no solution at all. Null directions come back as zero eigenvectors with
479
+ * zero eigenvalues, and the remaining vectors are scaled to unit euclidean
480
+ * length, since B-orthonormality is undefined once B is singular. `definite`
481
+ * reports which route ran, so callers needing scipy's strictness can check it
482
+ * (or pass `strict`).
483
+ *
484
+ * @param {Array<Array<number>>} A - Symmetric matrix
485
+ * @param {Array<Array<number>>} B - Symmetric positive (semi)definite matrix
486
+ * @param {Object} [options]
487
+ * @param {boolean} [options.strict=false] - Throw instead of falling back when
488
+ * B is not positive definite
489
+ * @param {number} [options.rcond] - Relative eigenvalue cutoff for the
490
+ * semidefinite fallback; default n * eps
491
+ * @returns {{values: Array<number>, vectors: Array<Array<number>>, definite: boolean}}
492
+ * values[i] descending; vectors' column i is the eigenvector for values[i]
493
+ * @throws {Error} When A or B is not symmetric, sizes disagree, or `strict`
494
+ * is set and B is not positive definite
495
+ */
496
+ export function eigSymGeneralized(A: Array<Array<number>>, B: Array<Array<number>>, options?: {
497
+ strict?: boolean | undefined;
498
+ rcond?: number | undefined;
499
+ }): {
500
+ values: Array<number>;
501
+ vectors: Array<Array<number>>;
502
+ definite: boolean;
503
+ };
504
+ ```
505
+
506
+ ### invSqrtSym
507
+
508
+ ```ts
509
+ /**
510
+ * Inverse square root of a symmetric positive semidefinite matrix:
511
+ * the symmetric W with W A W = I on A's range, and W = 0 on its null space.
512
+ *
513
+ * @param {Array<Array<number>>} A - Symmetric positive semidefinite matrix
514
+ * @param {Object} [options]
515
+ * @param {number} [options.rcond] - Relative eigenvalue cutoff below which a
516
+ * direction is treated as null; default n * eps
517
+ * @returns {Array<Array<number>>} Symmetric n x n inverse square root
518
+ * @throws {Error} When A is not symmetric or has a clearly negative eigenvalue
519
+ */
520
+ export function invSqrtSym(A: Array<Array<number>>, options?: {
521
+ rcond?: number | undefined;
522
+ }): Array<Array<number>>;
523
+ ```
524
+
525
+ ### diag
526
+
527
+ ```ts
528
+ /**
529
+ * Build a diagonal matrix from a vector, or extract the diagonal of a matrix.
530
+ *
531
+ * @param {Array<number>|Array<Array<number>>} x - Vector (returns an n x n
532
+ * nested matrix) or nested matrix (returns its diagonal, length min(m, n))
533
+ * @returns {Array<Array<number>>|Array<number>}
534
+ */
535
+ export function diag(x: Array<number> | Array<Array<number>>): Array<Array<number>> | Array<number>;
536
+ ```
537
+
538
+ ### identity
539
+
540
+ ```ts
541
+ /**
542
+ * Identity matrix of size n.
543
+ *
544
+ * @param {number} n - Dimension (positive integer)
545
+ * @returns {Array<Array<number>>}
546
+ */
547
+ export function identity(n: number): Array<Array<number>>;
548
+ ```
549
+
550
+ ### matmul
551
+
552
+ ```ts
553
+ /**
554
+ * Matrix product A B, or matrix-vector product A b.
555
+ *
556
+ * @param {Array<Array<number>>} A - m x n nested matrix
557
+ * @param {Array<Array<number>>|Array<number>} B - n x p nested matrix, or
558
+ * vector of length n
559
+ * @returns {Array<Array<number>>|Array<number>} m x p nested matrix, or
560
+ * vector of length m
561
+ */
562
+ export function matmul(A: Array<Array<number>>, B: Array<Array<number>> | Array<number>): Array<Array<number>> | Array<number>;
563
+ ```
564
+
565
+ ### norm
566
+
567
+ ```ts
568
+ /**
569
+ * Matrix or vector norm.
570
+ *
571
+ * For a nested matrix: 'fro' (Frobenius), 1 (max column abs sum), or
572
+ * Infinity (max row abs sum). For a vector: 'fro' or 2 (euclidean),
573
+ * 1 (abs sum), or Infinity (max abs).
574
+ *
575
+ * @param {Array<Array<number>>|Array<number>} A - Nested matrix or vector
576
+ * @param {'fro'|1|2|Infinity} [kind='fro'] - Norm kind
577
+ * @returns {number}
578
+ */
579
+ export function norm(A: Array<Array<number>> | Array<number>, kind?: "fro" | 1 | 2 | number): number;
580
+ ```
581
+
582
+ ### trace
583
+
584
+ ```ts
585
+ /**
586
+ * Sum of the diagonal of a square matrix.
587
+ *
588
+ * @param {Array<Array<number>>} A - Square nested matrix
589
+ * @returns {number}
590
+ */
591
+ export function trace(A: Array<Array<number>>): number;
592
+ ```
593
+
594
+ ### transpose
595
+
596
+ ```ts
597
+ /**
598
+ * Matrix transpose.
599
+ *
600
+ * @param {Array<Array<number>>} A - m x n nested matrix
601
+ * @returns {Array<Array<number>>} n x m nested matrix
602
+ */
603
+ export function transpose(A: Array<Array<number>>): Array<Array<number>>;
604
+ ```