@danielsimonjr/mathts-tensor 0.2.19 → 0.2.20
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/dist/Tensor.d.ts +176 -0
- package/dist/Tensor.d.ts.map +1 -0
- package/dist/contraction-sequence.d.ts +93 -0
- package/dist/contraction-sequence.d.ts.map +1 -0
- package/dist/index.d.ts +37 -1129
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/named-index.d.ts +76 -0
- package/dist/named-index.d.ts.map +1 -0
- package/dist/operations/cholesky.d.ts +47 -0
- package/dist/operations/cholesky.d.ts.map +1 -0
- package/dist/operations/concatenate.d.ts +35 -0
- package/dist/operations/concatenate.d.ts.map +1 -0
- package/dist/operations/eig.d.ts +50 -0
- package/dist/operations/eig.d.ts.map +1 -0
- package/dist/operations/flip.d.ts +35 -0
- package/dist/operations/flip.d.ts.map +1 -0
- package/dist/operations/gather.d.ts +33 -0
- package/dist/operations/gather.d.ts.map +1 -0
- package/dist/operations/kron.d.ts +38 -0
- package/dist/operations/kron.d.ts.map +1 -0
- package/dist/operations/lu.d.ts +48 -0
- package/dist/operations/lu.d.ts.map +1 -0
- package/dist/operations/pad.d.ts +50 -0
- package/dist/operations/pad.d.ts.map +1 -0
- package/dist/operations/pinv.d.ts +39 -0
- package/dist/operations/pinv.d.ts.map +1 -0
- package/dist/operations/qr.d.ts +49 -0
- package/dist/operations/qr.d.ts.map +1 -0
- package/dist/operations/random.d.ts +61 -0
- package/dist/operations/random.d.ts.map +1 -0
- package/dist/operations/roll.d.ts +44 -0
- package/dist/operations/roll.d.ts.map +1 -0
- package/dist/operations/scatter.d.ts +54 -0
- package/dist/operations/scatter.d.ts.map +1 -0
- package/dist/operations/slice.d.ts +43 -0
- package/dist/operations/slice.d.ts.map +1 -0
- package/dist/operations/solve.d.ts +54 -0
- package/dist/operations/solve.d.ts.map +1 -0
- package/dist/operations/stack.d.ts +50 -0
- package/dist/operations/stack.d.ts.map +1 -0
- package/dist/operations/svd.d.ts +56 -0
- package/dist/operations/svd.d.ts.map +1 -0
- package/package.json +57 -57
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAMxD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5D,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAGzF,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5D,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGvE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1629,7 +1629,7 @@ function tensorCholesky(t, rowAxes, opts) {
|
|
|
1629
1629
|
lData = matL.toFloat64Array();
|
|
1630
1630
|
} catch (err) {
|
|
1631
1631
|
const msg = err instanceof Error ? err.message : String(err);
|
|
1632
|
-
throw new Error(msg.replace(/^cholesky:/, "tensorCholesky:"));
|
|
1632
|
+
throw new Error(msg.replace(/^cholesky:/, "tensorCholesky:"), { cause: err });
|
|
1633
1633
|
}
|
|
1634
1634
|
const factorData = lower ? lData : transposeSquare(lData, n);
|
|
1635
1635
|
let factorLabels;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index — an immutable value type carrying a unique identity, a dimension,
|
|
3
|
+
* optional tags, and a prime level. Two indices *match* (and will be
|
|
4
|
+
* contracted by `Tensor.contract`) iff their `id` and `primeLevel` agree.
|
|
5
|
+
* Dimension agreement is validated at contraction time, not at matching time.
|
|
6
|
+
*
|
|
7
|
+
* Inspired by ITensors.jl's `Index` primitive.
|
|
8
|
+
*/
|
|
9
|
+
export interface IndexOpts {
|
|
10
|
+
/** Human-readable name; not used for matching but useful in errors / debug. */
|
|
11
|
+
name?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Free-form tag list. Two indices with the SAME id but DIFFERENT tags still
|
|
14
|
+
* match by id.
|
|
15
|
+
*/
|
|
16
|
+
tags?: ReadonlyArray<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Prime level (ITensor's "prime"). Two indices with the same id but different
|
|
19
|
+
* prime levels do NOT match.
|
|
20
|
+
*/
|
|
21
|
+
primeLevel?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A first-class index value. Each `new Index(...)` call mints a fresh `id`
|
|
25
|
+
* (Symbol) that can never collide with another. Methods that would mutate
|
|
26
|
+
* state instead return a new `Index` sharing the same `id`.
|
|
27
|
+
*/
|
|
28
|
+
export declare class Index {
|
|
29
|
+
readonly id: symbol;
|
|
30
|
+
readonly dim: number;
|
|
31
|
+
readonly name?: string;
|
|
32
|
+
readonly tags: ReadonlyArray<string>;
|
|
33
|
+
readonly primeLevel: number;
|
|
34
|
+
constructor(dim: number, opts?: IndexOpts);
|
|
35
|
+
/**
|
|
36
|
+
* Internal constructor used by mutating-style methods that need to share the
|
|
37
|
+
* same `id` with a different primeLevel / tags. Not exposed publicly.
|
|
38
|
+
*/
|
|
39
|
+
private static _from;
|
|
40
|
+
/**
|
|
41
|
+
* Return a new Index with `primeLevel` incremented by `by` (default 1).
|
|
42
|
+
*/
|
|
43
|
+
prime(by?: number): Index;
|
|
44
|
+
/**
|
|
45
|
+
* Return a new Index with `primeLevel` reset to 0.
|
|
46
|
+
*/
|
|
47
|
+
noprime(): Index;
|
|
48
|
+
/**
|
|
49
|
+
* Return a new Index with `tag` added to its tag list (no-op if already present).
|
|
50
|
+
*/
|
|
51
|
+
addTag(tag: string): Index;
|
|
52
|
+
/**
|
|
53
|
+
* Return a new Index with `tag` removed from its tag list (no-op if absent).
|
|
54
|
+
*/
|
|
55
|
+
removeTag(tag: string): Index;
|
|
56
|
+
/**
|
|
57
|
+
* True if `tag` is in this index's tag list.
|
|
58
|
+
*/
|
|
59
|
+
hasTag(tag: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Two indices match iff they share the same `id` AND the same `primeLevel`.
|
|
62
|
+
* Dimension is NOT used for matching — it is validated at contraction time.
|
|
63
|
+
*/
|
|
64
|
+
matches(other: Index): boolean;
|
|
65
|
+
toString(): string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Convenience factory: `const i = idx(3, 'i')`.
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* const i = idx(3, 'i'); // dim=3, name='i', primeLevel=0
|
|
72
|
+
* const j = idx(4, 'j', { tags: ['site'] });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function idx(dim: number, name?: string, opts?: Omit<IndexOpts, 'name'>): Index;
|
|
76
|
+
//# sourceMappingURL=named-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"named-index.d.ts","sourceRoot":"","sources":["../src/named-index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,SAAS;IACxB,+EAA+E;IAC/E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,IAAI,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,qBAAa,KAAK;IAChB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,YAAY,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,EASxC;IAED;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,KAAK;IAgBpB;;OAEG;IACH,KAAK,CAAC,EAAE,SAAI,GAAG,KAAK,CAKnB;IAED;;OAEG;IACH,OAAO,IAAI,KAAK,CAEf;IAED;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAGzB;IAED;;OAEG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAI5B;IAED;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3B;IAED;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAE7B;IAED,QAAQ,IAAI,MAAM,CAKjB;CACF;AAED;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG,KAAK,CAErF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tensorCholesky — Cholesky decomposition for symmetric positive-definite
|
|
3
|
+
* rank-N tensors.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the `tensorSvd` pattern: partitions the axes of `t` into "row"
|
|
6
|
+
* axes and "col" axes, reshapes `t` into a 2-D matrix, performs the
|
|
7
|
+
* Cholesky decomposition via the matrix primitive (right-looking algorithm),
|
|
8
|
+
* and returns the factor as a Tensor.
|
|
9
|
+
*
|
|
10
|
+
* The 2-D reshaped input must be square and symmetric positive-definite;
|
|
11
|
+
* otherwise an error is thrown.
|
|
12
|
+
*
|
|
13
|
+
* Decomposition modes:
|
|
14
|
+
* - default (`lower: true`): returns L such that A = L · Lᵀ.
|
|
15
|
+
* - `lower: false`: returns U such that A = Uᵀ · U.
|
|
16
|
+
*
|
|
17
|
+
* `axisLabels` propagation: the returned factor receives the rowAxes labels
|
|
18
|
+
* on its leading dims and a fresh joining Index on its trailing axis
|
|
19
|
+
* (for L), or the joining Index on the leading axis and colAxes labels on
|
|
20
|
+
* the trailing dims (for U).
|
|
21
|
+
*/
|
|
22
|
+
import { Tensor } from '../Tensor.js';
|
|
23
|
+
export interface TensorCholeskyOpts {
|
|
24
|
+
/** When true (default), return L such that A = L·Lᵀ. When false, return U such that A = Uᵀ·U. */
|
|
25
|
+
lower?: boolean;
|
|
26
|
+
/** Optional name for the joining index on the returned factor. Defaults to "cholesky". */
|
|
27
|
+
joiningIndexName?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface TensorCholeskyResult {
|
|
30
|
+
/** Cholesky factor (lower or upper depending on `opts.lower`). */
|
|
31
|
+
L: Tensor;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Compute the Cholesky decomposition of tensor `t` by partitioning its
|
|
35
|
+
* axes into "row" and "col" groups. The reshaped 2-D matrix must be
|
|
36
|
+
* square and symmetric positive-definite.
|
|
37
|
+
*
|
|
38
|
+
* Delegates the core right-looking Cholesky algorithm to
|
|
39
|
+
* `@danielsimonjr/mathts-matrix`'s `cholesky` primitive.
|
|
40
|
+
*
|
|
41
|
+
* @param t - Input tensor of any rank ≥ 1.
|
|
42
|
+
* @param rowAxes - Axis indices forming the row dimension of the effective
|
|
43
|
+
* 2-D matrix. The remaining axes form the column dimension.
|
|
44
|
+
* @param opts - Optional triangle selector + naming.
|
|
45
|
+
*/
|
|
46
|
+
export declare function tensorCholesky(t: Tensor, rowAxes: ReadonlyArray<number>, opts?: TensorCholeskyOpts): TensorCholeskyResult;
|
|
47
|
+
//# sourceMappingURL=cholesky.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cholesky.d.ts","sourceRoot":"","sources":["../../src/operations/cholesky.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKtC,MAAM,WAAW,kBAAkB;IACjC,iGAAiG;IACjG,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,0FAA0F;IAC1F,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,oBAAoB;IACnC,kEAAkE;IAClE,CAAC,EAAE,MAAM,CAAC;CACX;AAeD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,EAC9B,IAAI,CAAC,EAAE,kBAAkB,GACxB,oBAAoB,CAgFtB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* concatenate — join tensors along an existing axis (NumPy `concatenate`).
|
|
3
|
+
*
|
|
4
|
+
* All tensors must agree on every axis except the join axis. The output rank
|
|
5
|
+
* equals the input rank; only `shape[axis]` grows (sum of all input shapes
|
|
6
|
+
* along that axis).
|
|
7
|
+
*
|
|
8
|
+
* Axis-label semantics:
|
|
9
|
+
* - All axis labels are taken from `tensors[0]`.
|
|
10
|
+
* - If any `tensors[i].axisLabels[axis]` disagrees with `tensors[0]`'s label
|
|
11
|
+
* on the join axis, `tensors[0]`'s label is used silently (matching the
|
|
12
|
+
* principle that the first tensor is authoritative for label semantics).
|
|
13
|
+
* - If `tensors[0]` carries no `axisLabels`, the output also carries none.
|
|
14
|
+
*/
|
|
15
|
+
import { Tensor } from '../Tensor.js';
|
|
16
|
+
/**
|
|
17
|
+
* Concatenate tensors along an existing `axis`.
|
|
18
|
+
*
|
|
19
|
+
* @param tensors - Array of tensors. Must be non-empty. All must agree on every
|
|
20
|
+
* axis except `axis`.
|
|
21
|
+
* @param axis - The axis along which to concatenate. Supports negative indexing.
|
|
22
|
+
* @returns A tensor with the same rank and with `shape[axis]` equal to the sum
|
|
23
|
+
* of `tensors[i].shape[axis]`.
|
|
24
|
+
*
|
|
25
|
+
* @throws {Error} If `tensors` is empty, if any tensor has a different rank, or
|
|
26
|
+
* if shapes disagree on any non-join axis.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Vertically stack two 2×3 matrices → 4×3 matrix:
|
|
30
|
+
* const tall = concatenate([a, b], 0);
|
|
31
|
+
* // Horizontally stack two 2×3 matrices → 2×6 matrix:
|
|
32
|
+
* const wide = concatenate([a, b], 1);
|
|
33
|
+
*/
|
|
34
|
+
export declare function concatenate(tensors: Tensor[], axis: number): Tensor;
|
|
35
|
+
//# sourceMappingURL=concatenate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concatenate.d.ts","sourceRoot":"","sources":["../../src/operations/concatenate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAsFnE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tensorEig — eigenvalue / eigenvector decomposition for rank-N tensors.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the `tensorSvd` pattern: partitions the axes of `t` into "row"
|
|
5
|
+
* axes and "col" axes, reshapes `t` into a 2-D matrix, and delegates to
|
|
6
|
+
* the DenseMatrix `eig` primitive.
|
|
7
|
+
*
|
|
8
|
+
* The 2-D reshaped input must be square.
|
|
9
|
+
*
|
|
10
|
+
* Routing:
|
|
11
|
+
* - `symmetric: true` — eigenvalues are real and eigenvectors are
|
|
12
|
+
* orthogonal (matrix routes the symmetric path
|
|
13
|
+
* internally).
|
|
14
|
+
* - `symmetric: false` (default) — general eigensolver. If any eigenvalue
|
|
15
|
+
* has a non-zero imaginary part, the result
|
|
16
|
+
* includes an `eigenvaluesImaginary` Tensor;
|
|
17
|
+
* otherwise the field is undefined.
|
|
18
|
+
* - `computeVectors: false` — only eigenvalues are returned (faster).
|
|
19
|
+
*/
|
|
20
|
+
import { Tensor } from '../Tensor.js';
|
|
21
|
+
export interface TensorEigOpts {
|
|
22
|
+
/** Hint that the input is symmetric; routes through a stable real-eigenvalue path. */
|
|
23
|
+
symmetric?: boolean;
|
|
24
|
+
/** When false, only eigenvalues are computed. Default true. */
|
|
25
|
+
computeVectors?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface TensorEigResult {
|
|
28
|
+
/** Real parts of the eigenvalues. 1-D Tensor of length n. */
|
|
29
|
+
eigenvalues: Tensor;
|
|
30
|
+
/** Eigenvectors as columns; shape [n, n]. Present only when computeVectors !== false. */
|
|
31
|
+
eigenvectors?: Tensor;
|
|
32
|
+
/**
|
|
33
|
+
* Imaginary parts of the eigenvalues. 1-D Tensor of length n.
|
|
34
|
+
* Only present when any eigenvalue has nonzero imaginary part (general
|
|
35
|
+
* non-symmetric case). Undefined when all eigenvalues are real.
|
|
36
|
+
*/
|
|
37
|
+
eigenvaluesImaginary?: Tensor;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Tensor eigendecomposition using the pure-JS matrix eig primitive (synchronous).
|
|
41
|
+
*/
|
|
42
|
+
export declare function tensorEig(t: Tensor, rowAxes: ReadonlyArray<number>, opts?: TensorEigOpts): TensorEigResult;
|
|
43
|
+
/**
|
|
44
|
+
* Tensor eigendecomposition routed through the AssemblyScript WASM eig kernel
|
|
45
|
+
* (`eigWasm`) — same result as {@link tensorEig}, accelerated for large
|
|
46
|
+
* matricisations. Async (WASM instantiation); `eigWasm` falls back to JS when no
|
|
47
|
+
* binary is available.
|
|
48
|
+
*/
|
|
49
|
+
export declare function tensorEigWasm(t: Tensor, rowAxes: ReadonlyArray<number>, opts?: TensorEigOpts): Promise<TensorEigResult>;
|
|
50
|
+
//# sourceMappingURL=eig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eig.d.ts","sourceRoot":"","sources":["../../src/operations/eig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,MAAM,WAAW,aAAa;IAC5B,sFAAsF;IACtF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,+DAA+D;IAC/D,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,6DAA6D;IAC7D,WAAW,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAuHD;;GAEG;AACH,wBAAgB,SAAS,CACvB,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,EAC9B,IAAI,CAAC,EAAE,aAAa,GACnB,eAAe,CAKjB;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,EAC9B,IAAI,CAAC,EAAE,aAAa,GACnB,OAAO,CAAC,eAAe,CAAC,CAK1B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* flip — reverse element order along given axes.
|
|
3
|
+
*
|
|
4
|
+
* For each axis in `axes`, the index along that axis is reversed:
|
|
5
|
+
*
|
|
6
|
+
* out[..., i, ...] = in[..., dim - 1 - i, ...]
|
|
7
|
+
*
|
|
8
|
+
* Multiple axes can be flipped in a single pass. An empty `axes` array is
|
|
9
|
+
* a no-op (returns a copy of the input).
|
|
10
|
+
*
|
|
11
|
+
* Axis-label semantics: reversing the iteration order of an axis does not
|
|
12
|
+
* change its semantic identity — it is still the same logical axis. All axis
|
|
13
|
+
* labels from the input are therefore preserved unchanged in the output.
|
|
14
|
+
*/
|
|
15
|
+
import { Tensor } from '../Tensor.js';
|
|
16
|
+
/**
|
|
17
|
+
* Reverse element order along the specified axes.
|
|
18
|
+
*
|
|
19
|
+
* @param t - Input tensor of any rank.
|
|
20
|
+
* @param axes - The axes to flip. Supports negative indexing. Duplicates are
|
|
21
|
+
* ignored. An empty array returns a copy of `t`.
|
|
22
|
+
* @returns A new `Tensor` with the same shape as `t`, with axis labels
|
|
23
|
+
* preserved from `t`.
|
|
24
|
+
*
|
|
25
|
+
* @throws {Error} If any axis value is out of range.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Flip rows (axis 0) of a 3×4 matrix:
|
|
29
|
+
* const flipped = flip(matrix, [0]);
|
|
30
|
+
*
|
|
31
|
+
* // Flip both axes simultaneously:
|
|
32
|
+
* const rotated180 = flip(matrix, [0, 1]);
|
|
33
|
+
*/
|
|
34
|
+
export declare function flip(t: Tensor, axes: readonly number[]): Tensor;
|
|
35
|
+
//# sourceMappingURL=flip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flip.d.ts","sourceRoot":"","sources":["../../src/operations/flip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CA6C/D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gather — pull elements along one axis (NumPy `take` / JAX `gather`).
|
|
3
|
+
*
|
|
4
|
+
* For each index in `indices`, the output contains the corresponding "slice"
|
|
5
|
+
* of the input tensor along `axis`. The output has the same rank as the input;
|
|
6
|
+
* only `shape[axis]` changes to `indices.length`.
|
|
7
|
+
*
|
|
8
|
+
* Axis-label semantics: the gathered axis's label is **primed** (primeLevel
|
|
9
|
+
* incremented by 1 via `Index.prime()`) so it does not auto-match the original
|
|
10
|
+
* axis in `contract`. All other axis labels are preserved unchanged.
|
|
11
|
+
*
|
|
12
|
+
* The priming approach mirrors ITensors.jl's convention: after gathering, the
|
|
13
|
+
* index is the "selected" variant of the original, not the original itself.
|
|
14
|
+
*/
|
|
15
|
+
import { Tensor } from '../Tensor.js';
|
|
16
|
+
/**
|
|
17
|
+
* Gather elements along `axis` using `indices`.
|
|
18
|
+
*
|
|
19
|
+
* @param t - Input tensor of any rank.
|
|
20
|
+
* @param axis - The axis along which to gather. Supports negative indexing.
|
|
21
|
+
* @param indices - The indices to gather. Duplicates are allowed.
|
|
22
|
+
* @returns A new `Tensor` with `shape[axis] === indices.length` and all other
|
|
23
|
+
* dimensions unchanged. The gathered-axis label is primed.
|
|
24
|
+
*
|
|
25
|
+
* @throws {RangeError} If any index in `indices` is outside [0, shape[axis]).
|
|
26
|
+
* @throws {Error} If `axis` is out of range.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Select rows 0 and 2 from a 3×4 matrix:
|
|
30
|
+
* const rows = gather(matrix, 0, [0, 2]); // shape [2, 4]
|
|
31
|
+
*/
|
|
32
|
+
export declare function gather(t: Tensor, axis: number, indices: readonly number[]): Tensor;
|
|
33
|
+
//# sourceMappingURL=gather.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gather.d.ts","sourceRoot":"","sources":["../../src/operations/gather.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAsElF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tensorKron — Kronecker product for rank-N tensors.
|
|
3
|
+
*
|
|
4
|
+
* Computes the Kronecker product of tensors `a` and `b`. For rank-2 matrices
|
|
5
|
+
* this is the classical Kronecker product:
|
|
6
|
+
*
|
|
7
|
+
* kron(A, B)[i0, j0] = A[i0 / B.rows, j0 / B.cols] * B[i0 % B.rows, j0 % B.cols]
|
|
8
|
+
*
|
|
9
|
+
* For higher-rank tensors, the same rule is applied axis-by-axis:
|
|
10
|
+
*
|
|
11
|
+
* result.shape[k] = a.shape[k] * b.shape[k]
|
|
12
|
+
* result[...i] = a[i[0]/b.shape[0], ..., i[r-1]/b.shape[r-1]]
|
|
13
|
+
* * b[i[0]%b.shape[0], ..., i[r-1]%b.shape[r-1]]
|
|
14
|
+
*
|
|
15
|
+
* Rank alignment: if the tensors have different ranks, the smaller one is
|
|
16
|
+
* broadcast-aligned to the right by prepending size-1 dimensions (numpy-style).
|
|
17
|
+
*
|
|
18
|
+
* Axis labels: when both tensors carry `axisLabels`, the output axis labels
|
|
19
|
+
* are formed by concatenating each pair as `"<aName>_X_<bName>"` to avoid
|
|
20
|
+
* collisions. When only one tensor has labels, the output carries no labels.
|
|
21
|
+
*/
|
|
22
|
+
import { Tensor } from '../Tensor.js';
|
|
23
|
+
export interface TensorKronOpts {
|
|
24
|
+
/**
|
|
25
|
+
* Separator string inserted between a's and b's axis-label names when
|
|
26
|
+
* building the output axisLabels. Default: "_X_".
|
|
27
|
+
*/
|
|
28
|
+
separator?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Compute the Kronecker product of tensors `a` and `b`.
|
|
32
|
+
*
|
|
33
|
+
* @param a - Left operand tensor.
|
|
34
|
+
* @param b - Right operand tensor.
|
|
35
|
+
* @param opts - Optional separator for axis-label naming.
|
|
36
|
+
*/
|
|
37
|
+
export declare function tensorKron(a: Tensor, b: Tensor, opts?: TensorKronOpts): Tensor;
|
|
38
|
+
//# sourceMappingURL=kron.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kron.d.ts","sourceRoot":"","sources":["../../src/operations/kron.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,MAAM,CA4G9E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tensorLU — LU decomposition with partial pivoting for rank-N tensors.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the `tensorSvd` pattern: partitions the axes of `t` into "row"
|
|
5
|
+
* axes and "col" axes, reshapes `t` into a 2-D matrix, performs LU with
|
|
6
|
+
* partial pivoting (Doolittle's algorithm via the matrix primitive), and
|
|
7
|
+
* returns the factors as Tensors.
|
|
8
|
+
*
|
|
9
|
+
* The 2-D-reshaped input must be square; otherwise an error is thrown.
|
|
10
|
+
*
|
|
11
|
+
* Decomposition: P · A = L · U, where L is unit lower-triangular and U is
|
|
12
|
+
* upper-triangular. P is returned as the row-permutation array (P[i] is
|
|
13
|
+
* the row index of the original A that was moved to position i).
|
|
14
|
+
*
|
|
15
|
+
* `axisLabels` propagation: L receives the rowAxes labels on its leading
|
|
16
|
+
* dims and a fresh joining Index on its trailing axis; U receives the
|
|
17
|
+
* joining Index on its leading axis and the colAxes labels on its trailing
|
|
18
|
+
* dims.
|
|
19
|
+
*/
|
|
20
|
+
import { Tensor } from '../Tensor.js';
|
|
21
|
+
export interface TensorLUResult {
|
|
22
|
+
/** Unit lower-triangular L. Shape [...rowDims, n]. */
|
|
23
|
+
L: Tensor;
|
|
24
|
+
/** Upper-triangular U. Shape [n, ...colDims]. */
|
|
25
|
+
U: Tensor;
|
|
26
|
+
/** Row permutation array of length n. P[i] is the original-row index now at position i. */
|
|
27
|
+
P: Int32Array;
|
|
28
|
+
/** Sign of the permutation (+1 for even, -1 for odd) — useful for det(). */
|
|
29
|
+
parity: 1 | -1;
|
|
30
|
+
}
|
|
31
|
+
export interface TensorLUOpts {
|
|
32
|
+
/** Optional name for the joining index between L and U. Defaults to "lu". */
|
|
33
|
+
joiningIndexName?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Compute the LU decomposition of tensor `t` by partitioning its axes into
|
|
37
|
+
* "row" and "col" groups. The reshaped 2-D matrix must be square.
|
|
38
|
+
*
|
|
39
|
+
* Delegates the core Doolittle algorithm to `@danielsimonjr/mathts-matrix`'s
|
|
40
|
+
* `lu` primitive.
|
|
41
|
+
*
|
|
42
|
+
* @param t - Input tensor of any rank ≥ 1.
|
|
43
|
+
* @param rowAxes - Axis indices forming the row dimension of the effective
|
|
44
|
+
* 2-D matrix. The remaining axes form the column dimension.
|
|
45
|
+
* @param opts - Optional joining-index name.
|
|
46
|
+
*/
|
|
47
|
+
export declare function tensorLU(t: Tensor, rowAxes: ReadonlyArray<number>, opts?: TensorLUOpts): TensorLUResult;
|
|
48
|
+
//# sourceMappingURL=lu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lu.d.ts","sourceRoot":"","sources":["../../src/operations/lu.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKtC,MAAM,WAAW,cAAc;IAC7B,sDAAsD;IACtD,CAAC,EAAE,MAAM,CAAC;IACV,iDAAiD;IACjD,CAAC,EAAE,MAAM,CAAC;IACV,2FAA2F;IAC3F,CAAC,EAAE,UAAU,CAAC;IACd,4EAA4E;IAC5E,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CACtB,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,EAC9B,IAAI,CAAC,EAAE,YAAY,GAClB,cAAc,CA6FhB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pad — pad each axis by [before, after] amounts.
|
|
3
|
+
*
|
|
4
|
+
* Three modes are supported, mirroring NumPy's `np.pad`:
|
|
5
|
+
*
|
|
6
|
+
* - `'constant'` (default): Fill padded cells with `constantValue` (default 0).
|
|
7
|
+
* - `'edge'`: Repeat the boundary element along each padded slice.
|
|
8
|
+
* - `'reflect'`: Mirror the data across the boundary, excluding the boundary
|
|
9
|
+
* element itself. Requires that each padding amount is strictly
|
|
10
|
+
* less than the corresponding axis size.
|
|
11
|
+
*
|
|
12
|
+
* Axis-label semantics: output rank equals input rank and axis identities do
|
|
13
|
+
* not change (padding is just extension, not transformation). All axis labels
|
|
14
|
+
* from the input are preserved unchanged in the output.
|
|
15
|
+
*/
|
|
16
|
+
import { Tensor } from '../Tensor.js';
|
|
17
|
+
export interface PadOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Padding mode.
|
|
20
|
+
* - `'constant'` (default): fill with `constantValue`.
|
|
21
|
+
* - `'edge'`: repeat boundary element.
|
|
22
|
+
* - `'reflect'`: mirror across boundary, excluding boundary itself.
|
|
23
|
+
*/
|
|
24
|
+
mode?: 'constant' | 'edge' | 'reflect';
|
|
25
|
+
/** Value used when `mode === 'constant'`. Default `0`. */
|
|
26
|
+
constantValue?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Pad a tensor along each axis by specified widths.
|
|
30
|
+
*
|
|
31
|
+
* @param t - Input tensor of any rank.
|
|
32
|
+
* @param padWidths - Array of `[before, after]` pairs, one per axis. Length
|
|
33
|
+
* must equal `t.shape.length`. Each value must be >= 0.
|
|
34
|
+
* @param opts - Optional padding options (mode and constantValue).
|
|
35
|
+
* @returns A new `Tensor` with `shape[k] = t.shape[k] + before_k + after_k`
|
|
36
|
+
* and axis labels preserved from `t`.
|
|
37
|
+
*
|
|
38
|
+
* @throws {Error} If `padWidths.length !== t.shape.length`, any pad
|
|
39
|
+
* value is negative, or `mode === 'reflect'` is used
|
|
40
|
+
* with a pad amount >= the corresponding axis size.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Constant-pad a 3×4 tensor with 1 cell of zeros on each side:
|
|
44
|
+
* const padded = pad(t, [[1, 1], [1, 1]]); // shape [5, 6]
|
|
45
|
+
*
|
|
46
|
+
* // Edge-pad with asymmetric widths:
|
|
47
|
+
* const ep = pad(t, [[2, 0], [0, 1]], { mode: 'edge' });
|
|
48
|
+
*/
|
|
49
|
+
export declare function pad(t: Tensor, padWidths: readonly (readonly [number, number])[], opts?: PadOptions): Tensor;
|
|
50
|
+
//# sourceMappingURL=pad.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pad.d.ts","sourceRoot":"","sources":["../../src/operations/pad.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;IACvC,0DAA0D;IAC1D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,GAAG,CACjB,CAAC,EAAE,MAAM,EACT,SAAS,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,EACjD,IAAI,CAAC,EAAE,UAAU,GAChB,MAAM,CA6GR"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tensorPinv — Moore-Penrose pseudoinverse for rank-N tensors.
|
|
3
|
+
*
|
|
4
|
+
* Partitions the axes of `t` into "row" axes (the axes that form the
|
|
5
|
+
* numerically "tall" side of the matrix) and the remaining "col" axes.
|
|
6
|
+
* Then:
|
|
7
|
+
* 1. Permutes + reshapes `t` to a 2-D matrix M (numRows × numCols).
|
|
8
|
+
* 2. Computes the full SVD: M = U · diag(S) · V^T.
|
|
9
|
+
* 3. Thresholds small singular values using `rcond`: keep s_i if
|
|
10
|
+
* s_i > rcond · max(S), else treat as zero.
|
|
11
|
+
* 4. Computes pinv(M) = V · diag(S^+) · U^T (shape: numCols × numRows).
|
|
12
|
+
* 5. Reshapes the result back into a Tensor with swapped row/col dims.
|
|
13
|
+
*
|
|
14
|
+
* Axis labels: if the input carries `axisLabels`, the output tensor's
|
|
15
|
+
* leading axes get the original col-axis labels and the trailing axes get
|
|
16
|
+
* the original row-axis labels (because the pseudoinverse swaps rows ↔ cols).
|
|
17
|
+
*/
|
|
18
|
+
import { Tensor } from '../Tensor.js';
|
|
19
|
+
import { Index } from '../named-index.js';
|
|
20
|
+
export interface TensorPinvOpts {
|
|
21
|
+
/**
|
|
22
|
+
* Relative condition threshold for singular-value truncation.
|
|
23
|
+
* A singular value s_i is treated as zero when s_i ≤ rcond · max(S).
|
|
24
|
+
* Default: 1e-10.
|
|
25
|
+
*/
|
|
26
|
+
rcond?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compute the Moore-Penrose pseudoinverse of tensor `t` by partitioning its
|
|
30
|
+
* axes into "row" and "col" groups.
|
|
31
|
+
*
|
|
32
|
+
* @param t - Input tensor of any rank ≥ 1.
|
|
33
|
+
* @param rowAxes - Axis indices (integers) or Index objects whose dimensions
|
|
34
|
+
* form the row dimension of the effective 2-D matrix. The
|
|
35
|
+
* remaining axes form the column dimension.
|
|
36
|
+
* @param opts - Optional rcond threshold.
|
|
37
|
+
*/
|
|
38
|
+
export declare function tensorPinv(t: Tensor, rowAxes: ReadonlyArray<number | Index>, opts?: TensorPinvOpts): Tensor;
|
|
39
|
+
//# sourceMappingURL=pinv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pinv.d.ts","sourceRoot":"","sources":["../../src/operations/pinv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG1C,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,aAAa,CAAC,MAAM,GAAG,KAAK,CAAC,EACtC,IAAI,CAAC,EAAE,cAAc,GACpB,MAAM,CAiGR"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tensorQr — QR decomposition for rank-N tensors.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the `tensorSvd` pattern: partitions the axes of `t` into "row" axes
|
|
5
|
+
* (joining with Q) and "col" axes (joining with R), permutes + reshapes `t`
|
|
6
|
+
* into a 2-D matrix, calls the DenseMatrix `qr` primitive, then reshapes Q
|
|
7
|
+
* and R back into Tensors.
|
|
8
|
+
*
|
|
9
|
+
* In 'reduced' mode (default, thin QR):
|
|
10
|
+
* Q has shape [...rowDims, k] where k = min(numRows, numCols)
|
|
11
|
+
* R has shape [k, ...colDims]
|
|
12
|
+
*
|
|
13
|
+
* In 'full' mode:
|
|
14
|
+
* Q has shape [...rowDims, numRows] (square in the row direction)
|
|
15
|
+
* R has shape [numRows, ...colDims]
|
|
16
|
+
*
|
|
17
|
+
* `axisLabels` propagation: when the input carries labels, the row-axis
|
|
18
|
+
* labels are forwarded to Q's leading dims and the col-axis labels to R's
|
|
19
|
+
* trailing dims. A fresh "joining" Index of dimension `k` (or `numRows` in
|
|
20
|
+
* full mode) is inserted between them.
|
|
21
|
+
*/
|
|
22
|
+
import { Tensor } from '../Tensor.js';
|
|
23
|
+
export interface TensorQrOpts {
|
|
24
|
+
/** 'reduced' (default, thin QR) or 'full'. */
|
|
25
|
+
mode?: 'reduced' | 'full';
|
|
26
|
+
/**
|
|
27
|
+
* Optional name for the joining index between Q and R. Used only when
|
|
28
|
+
* input axisLabels are present to label the new joining axis. Defaults
|
|
29
|
+
* to "qr".
|
|
30
|
+
*/
|
|
31
|
+
joiningIndexName?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface TensorQrResult {
|
|
34
|
+
/** Q factor with orthonormal columns reshaped to [...rowDims, k]. */
|
|
35
|
+
Q: Tensor;
|
|
36
|
+
/** R factor (upper-triangular) reshaped to [k, ...colDims]. */
|
|
37
|
+
R: Tensor;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Compute the QR decomposition of tensor `t` by partitioning its axes into
|
|
41
|
+
* "row" and "col" groups.
|
|
42
|
+
*
|
|
43
|
+
* @param t - Input tensor of any rank ≥ 1.
|
|
44
|
+
* @param rowAxes - Axis indices forming the row dimension of the effective
|
|
45
|
+
* 2-D matrix. The remaining axes form the column dimension.
|
|
46
|
+
* @param opts - Optional mode + naming settings.
|
|
47
|
+
*/
|
|
48
|
+
export declare function tensorQr(t: Tensor, rowAxes: ReadonlyArray<number>, opts?: TensorQrOpts): TensorQrResult;
|
|
49
|
+
//# sourceMappingURL=qr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qr.d.ts","sourceRoot":"","sources":["../../src/operations/qr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,MAAM,WAAW,YAAY;IAC3B,8CAA8C;IAC9C,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAC1B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,qEAAqE;IACrE,CAAC,EAAE,MAAM,CAAC;IACV,+DAA+D;IAC/D,CAAC,EAAE,MAAM,CAAC;CACX;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CACtB,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,EAC9B,IAAI,CAAC,EAAE,YAAY,GAClB,cAAc,CAwEhB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* randomTensor — construct a Tensor filled with pseudo-random values.
|
|
3
|
+
*
|
|
4
|
+
* Supported distributions:
|
|
5
|
+
* 'uniform' — U(0, 1) via the seeded PRNG or Math.random().
|
|
6
|
+
* 'normal' — N(0, 1) via Box–Muller transform on the underlying PRNG.
|
|
7
|
+
* 'orthogonal' — Uniform on the orthogonal group O(n) via QR decomposition
|
|
8
|
+
* of a normal random matrix. Rank-2 shapes only.
|
|
9
|
+
*
|
|
10
|
+
* Seeded RNG: Mulberry32 — a small, fast, high-quality 32-bit PRNG.
|
|
11
|
+
* Reference: Tommy Ettinger, https://gist.github.com/tommyettinger/46a874533244883189143505d203312c
|
|
12
|
+
*
|
|
13
|
+
* WARNING: The seeded path is NOT cryptographically secure. Do not use for
|
|
14
|
+
* security-sensitive purposes (key generation, nonces, etc.).
|
|
15
|
+
*/
|
|
16
|
+
import { Tensor } from '../Tensor.js';
|
|
17
|
+
import { Index } from '../named-index.js';
|
|
18
|
+
export interface RandomTensorOpts {
|
|
19
|
+
/**
|
|
20
|
+
* Distribution to sample from.
|
|
21
|
+
*
|
|
22
|
+
* - `'uniform'` — U(0, 1).
|
|
23
|
+
* - `'normal'` — N(0, 1) via Box–Muller transform.
|
|
24
|
+
* - `'orthogonal'` — uniform on the orthogonal group; rank-2 shape only.
|
|
25
|
+
*
|
|
26
|
+
* @default 'uniform'
|
|
27
|
+
*/
|
|
28
|
+
distribution?: 'uniform' | 'normal' | 'orthogonal';
|
|
29
|
+
/**
|
|
30
|
+
* Integer seed for the Mulberry32 PRNG. When omitted, Math.random() is
|
|
31
|
+
* used (non-reproducible). NOT cryptographically secure.
|
|
32
|
+
*/
|
|
33
|
+
seed?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Optional axis labels forwarded into the new Tensor's constructor.
|
|
36
|
+
* Requires Phase-1 `axisLabels` support in the Tensor constructor
|
|
37
|
+
* (constructor signature: `Tensor(shape, data, axisLabels?)`).
|
|
38
|
+
*/
|
|
39
|
+
axisLabels?: ReadonlyArray<Index>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Construct a Tensor of the given `shape` filled with pseudo-random values.
|
|
43
|
+
*
|
|
44
|
+
* @param shape - Array of positive integers defining the tensor dimensions.
|
|
45
|
+
* @param opts - Optional configuration (distribution, seed, axisLabels).
|
|
46
|
+
* @returns A new Tensor.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* // 3x4 uniform random tensor
|
|
51
|
+
* const t = randomTensor([3, 4]);
|
|
52
|
+
*
|
|
53
|
+
* // Seeded normal random vector (reproducible)
|
|
54
|
+
* const v = randomTensor([100], { distribution: 'normal', seed: 42 });
|
|
55
|
+
*
|
|
56
|
+
* // 8x8 random orthogonal matrix
|
|
57
|
+
* const O = randomTensor([8, 8], { distribution: 'orthogonal', seed: 7 });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function randomTensor(shape: ReadonlyArray<number>, opts?: RandomTensorOpts): Tensor;
|
|
61
|
+
//# sourceMappingURL=random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/operations/random.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAO1C,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,YAAY,CAAC;IAEnD;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;CACnC;AAqED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAuE1F"}
|