@danielsimonjr/mathts-matrix 0.7.1 → 0.7.2

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 (99) hide show
  1. package/dist/backends/Backend.d.ts +146 -0
  2. package/dist/backends/Backend.d.ts.map +1 -0
  3. package/dist/backends/BackendManager.d.ts +189 -0
  4. package/dist/backends/BackendManager.d.ts.map +1 -0
  5. package/dist/backends/GPUBackend.d.ts +128 -0
  6. package/dist/backends/GPUBackend.d.ts.map +1 -0
  7. package/dist/backends/GPUMatrixBackend.d.ts +123 -0
  8. package/dist/backends/GPUMatrixBackend.d.ts.map +1 -0
  9. package/dist/backends/JSBackend.d.ts +93 -0
  10. package/dist/backends/JSBackend.d.ts.map +1 -0
  11. package/dist/backends/ParallelBackend.d.ts +131 -0
  12. package/dist/backends/ParallelBackend.d.ts.map +1 -0
  13. package/dist/backends/WASMBackend.d.ts +156 -0
  14. package/dist/backends/WASMBackend.d.ts.map +1 -0
  15. package/dist/backends/WasmLoader.d.ts +326 -0
  16. package/dist/backends/WasmLoader.d.ts.map +1 -0
  17. package/dist/backends/gpu/BatchExecutor.d.ts +190 -0
  18. package/dist/backends/gpu/BatchExecutor.d.ts.map +1 -0
  19. package/dist/backends/gpu/Sync.d.ts +167 -0
  20. package/dist/backends/gpu/Sync.d.ts.map +1 -0
  21. package/dist/backends/gpu/builtin-shaders.d.ts +178 -0
  22. package/dist/backends/gpu/builtin-shaders.d.ts.map +1 -0
  23. package/dist/backends/gpu/index.d.ts +13 -0
  24. package/dist/backends/gpu/index.d.ts.map +1 -0
  25. package/dist/backends/index.d.ts +18 -0
  26. package/dist/backends/index.d.ts.map +1 -0
  27. package/dist/backends/register-backends.d.ts +18 -0
  28. package/dist/backends/register-backends.d.ts.map +1 -0
  29. package/dist/backends/wasm/detect.d.ts +58 -0
  30. package/dist/backends/wasm/detect.d.ts.map +1 -0
  31. package/dist/backends/wasm/fft-wasm.d.ts +120 -0
  32. package/dist/backends/wasm/fft-wasm.d.ts.map +1 -0
  33. package/dist/backends/wasm/index.d.ts +9 -0
  34. package/dist/backends/wasm/index.d.ts.map +1 -0
  35. package/dist/backends/wasm/integrity.d.ts +18 -0
  36. package/dist/backends/wasm/integrity.d.ts.map +1 -0
  37. package/dist/backends/wasm/resolve.d.ts +12 -0
  38. package/dist/backends/wasm/resolve.d.ts.map +1 -0
  39. package/dist/{chunk-4VMDO6W2.js → chunk-PNKVD2UK.js} +2 -7
  40. package/dist/config.d.ts +145 -0
  41. package/dist/config.d.ts.map +1 -0
  42. package/dist/index.d.ts +14 -3037
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +9 -9
  45. package/dist/{integrity-LIWCCDIJ.js → integrity-IBNQNHXP.js} +1 -1
  46. package/dist/operations/cholesky.d.ts +24 -0
  47. package/dist/operations/cholesky.d.ts.map +1 -0
  48. package/dist/operations/common.d.ts +61 -0
  49. package/dist/operations/common.d.ts.map +1 -0
  50. package/dist/operations/condest.d.ts +27 -0
  51. package/dist/operations/condest.d.ts.map +1 -0
  52. package/dist/operations/eig-wasm.d.ts +35 -0
  53. package/dist/operations/eig-wasm.d.ts.map +1 -0
  54. package/dist/operations/eig.d.ts +75 -0
  55. package/dist/operations/eig.d.ts.map +1 -0
  56. package/dist/operations/expm.d.ts +46 -0
  57. package/dist/operations/expm.d.ts.map +1 -0
  58. package/dist/operations/index.d.ts +21 -0
  59. package/dist/operations/index.d.ts.map +1 -0
  60. package/dist/operations/logm.d.ts +59 -0
  61. package/dist/operations/logm.d.ts.map +1 -0
  62. package/dist/operations/lu.d.ts +51 -0
  63. package/dist/operations/lu.d.ts.map +1 -0
  64. package/dist/operations/pinv.d.ts +36 -0
  65. package/dist/operations/pinv.d.ts.map +1 -0
  66. package/dist/operations/qr-family.d.ts +52 -0
  67. package/dist/operations/qr-family.d.ts.map +1 -0
  68. package/dist/operations/qr-pivoted.d.ts +39 -0
  69. package/dist/operations/qr-pivoted.d.ts.map +1 -0
  70. package/dist/operations/qr.d.ts +35 -0
  71. package/dist/operations/qr.d.ts.map +1 -0
  72. package/dist/operations/schur.d.ts +58 -0
  73. package/dist/operations/schur.d.ts.map +1 -0
  74. package/dist/operations/sqrtm.d.ts +76 -0
  75. package/dist/operations/sqrtm.d.ts.map +1 -0
  76. package/dist/operations/svd-wasm.d.ts +23 -0
  77. package/dist/operations/svd-wasm.d.ts.map +1 -0
  78. package/dist/operations/svd.d.ts +70 -0
  79. package/dist/operations/svd.d.ts.map +1 -0
  80. package/dist/parallel-matrix.d.ts +222 -0
  81. package/dist/parallel-matrix.d.ts.map +1 -0
  82. package/dist/{resolve-DDCEWHWX.js → resolve-2SX6WJ6R.js} +1 -1
  83. package/dist/typed-operations.d.ts +161 -0
  84. package/dist/typed-operations.d.ts.map +1 -0
  85. package/dist/types/DenseMatrix.d.ts +213 -0
  86. package/dist/types/DenseMatrix.d.ts.map +1 -0
  87. package/dist/types/Matrix.d.ts +188 -0
  88. package/dist/types/Matrix.d.ts.map +1 -0
  89. package/dist/types/SparseMatrix.d.ts +214 -0
  90. package/dist/types/SparseMatrix.d.ts.map +1 -0
  91. package/dist/types/dense/arithmetic.d.ts +8 -0
  92. package/dist/types/dense/arithmetic.d.ts.map +1 -0
  93. package/dist/types/dense/reduction.d.ts +8 -0
  94. package/dist/types/dense/reduction.d.ts.map +1 -0
  95. package/dist/types/index.d.ts +9 -0
  96. package/dist/types/index.d.ts.map +1 -0
  97. package/dist/wasm/mathts-as.wasm +0 -0
  98. package/dist/wasm/wasm-manifest.json +1 -1
  99. package/package.json +70 -70
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Typed Matrix Operations
3
+ *
4
+ * Polymorphic matrix operations using typed-function for runtime dispatch.
5
+ * Supports operations on DenseMatrix with automatic type coercion.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ /**
10
+ * Create a matrix from various input types
11
+ */
12
+ export declare const matrix: import("typed-function").TypedFunction;
13
+ /**
14
+ * Create an identity matrix
15
+ */
16
+ export declare const identity: import("typed-function").TypedFunction;
17
+ /**
18
+ * Create a matrix of zeros
19
+ */
20
+ export declare const zeros: import("typed-function").TypedFunction;
21
+ /**
22
+ * Create a matrix of ones
23
+ */
24
+ export declare const ones: import("typed-function").TypedFunction;
25
+ /**
26
+ * Create a diagonal matrix
27
+ */
28
+ export declare const diag: import("typed-function").TypedFunction;
29
+ /**
30
+ * Create a random matrix
31
+ */
32
+ export declare const random: import("typed-function").TypedFunction;
33
+ /**
34
+ * Matrix addition - polymorphic add function
35
+ */
36
+ export declare const add: import("typed-function").TypedFunction;
37
+ /**
38
+ * Matrix subtraction
39
+ */
40
+ export declare const subtract: import("typed-function").TypedFunction;
41
+ /**
42
+ * Matrix multiplication (matmul)
43
+ */
44
+ export declare const multiply: import("typed-function").TypedFunction;
45
+ /**
46
+ * Element-wise multiplication (Hadamard product)
47
+ */
48
+ export declare const dotMultiply: import("typed-function").TypedFunction;
49
+ /**
50
+ * Matrix division (A / B where B is scalar or element-wise)
51
+ */
52
+ export declare const divide: import("typed-function").TypedFunction;
53
+ /**
54
+ * Matrix negation
55
+ */
56
+ export declare const unaryMinus: import("typed-function").TypedFunction;
57
+ /**
58
+ * Matrix transpose
59
+ */
60
+ export declare const transpose: import("typed-function").TypedFunction;
61
+ /**
62
+ * Sum of all elements
63
+ */
64
+ export declare const sum: import("typed-function").TypedFunction;
65
+ /**
66
+ * Mean of all elements
67
+ */
68
+ export declare const mean: import("typed-function").TypedFunction;
69
+ /**
70
+ * Minimum element
71
+ */
72
+ export declare const min: import("typed-function").TypedFunction;
73
+ /**
74
+ * Maximum element
75
+ */
76
+ export declare const max: import("typed-function").TypedFunction;
77
+ /**
78
+ * Frobenius norm
79
+ */
80
+ export declare const norm: import("typed-function").TypedFunction;
81
+ /**
82
+ * Matrix trace (sum of diagonal elements)
83
+ */
84
+ export declare const trace: import("typed-function").TypedFunction;
85
+ /**
86
+ * Element-wise absolute value
87
+ */
88
+ export declare const abs: import("typed-function").TypedFunction;
89
+ /**
90
+ * Element-wise square root
91
+ */
92
+ export declare const sqrt: import("typed-function").TypedFunction;
93
+ /**
94
+ * Element-wise square
95
+ */
96
+ export declare const square: import("typed-function").TypedFunction;
97
+ /**
98
+ * Element-wise exponential
99
+ */
100
+ export declare const exp: import("typed-function").TypedFunction;
101
+ /**
102
+ * Element-wise natural logarithm
103
+ */
104
+ export declare const log: import("typed-function").TypedFunction;
105
+ /**
106
+ * Element-wise power
107
+ */
108
+ export declare const pow: import("typed-function").TypedFunction;
109
+ /**
110
+ * Get matrix dimensions
111
+ */
112
+ export declare const size: import("typed-function").TypedFunction;
113
+ /**
114
+ * Get element at position
115
+ */
116
+ export declare const subset: import("typed-function").TypedFunction;
117
+ /**
118
+ * Get row from matrix
119
+ */
120
+ export declare const row: import("typed-function").TypedFunction;
121
+ /**
122
+ * Get column from matrix
123
+ */
124
+ export declare const column: import("typed-function").TypedFunction;
125
+ /**
126
+ * Get diagonal from matrix
127
+ */
128
+ export declare const diagonal: import("typed-function").TypedFunction;
129
+ export declare const typedMatrixOperations: {
130
+ matrix: import("typed-function").TypedFunction;
131
+ identity: import("typed-function").TypedFunction;
132
+ zeros: import("typed-function").TypedFunction;
133
+ ones: import("typed-function").TypedFunction;
134
+ diag: import("typed-function").TypedFunction;
135
+ random: import("typed-function").TypedFunction;
136
+ add: import("typed-function").TypedFunction;
137
+ subtract: import("typed-function").TypedFunction;
138
+ multiply: import("typed-function").TypedFunction;
139
+ dotMultiply: import("typed-function").TypedFunction;
140
+ divide: import("typed-function").TypedFunction;
141
+ unaryMinus: import("typed-function").TypedFunction;
142
+ transpose: import("typed-function").TypedFunction;
143
+ sum: import("typed-function").TypedFunction;
144
+ mean: import("typed-function").TypedFunction;
145
+ min: import("typed-function").TypedFunction;
146
+ max: import("typed-function").TypedFunction;
147
+ norm: import("typed-function").TypedFunction;
148
+ trace: import("typed-function").TypedFunction;
149
+ abs: import("typed-function").TypedFunction;
150
+ sqrt: import("typed-function").TypedFunction;
151
+ square: import("typed-function").TypedFunction;
152
+ exp: import("typed-function").TypedFunction;
153
+ log: import("typed-function").TypedFunction;
154
+ pow: import("typed-function").TypedFunction;
155
+ size: import("typed-function").TypedFunction;
156
+ subset: import("typed-function").TypedFunction;
157
+ row: import("typed-function").TypedFunction;
158
+ column: import("typed-function").TypedFunction;
159
+ diagonal: import("typed-function").TypedFunction;
160
+ };
161
+ //# sourceMappingURL=typed-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-operations.d.ts","sourceRoot":"","sources":["../src/typed-operations.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH;;GAEG;AACH,eAAO,MAAM,MAAM,wCAUH,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,QAAQ,wCAEL,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,KAAK,wCAEF,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,IAAI,wCAED,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,IAAI,wCAED,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,MAAM,wCAEH,CAAC;AAMjB;;GAEG;AACH,eAAO,MAAM,GAAG,wCAYA,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,QAAQ,wCAYL,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,QAAQ,wCAYL,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,WAAW,wCAIR,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,MAAM,wCASH,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,UAAU,wCAGP,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,SAAS,wCAEN,CAAC;AAMjB;;GAEG;AACH,eAAO,MAAM,GAAG,wCAGA,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,IAAI,wCAGD,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,GAAG,wCAIA,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,GAAG,wCAIA,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,IAAI,wCAGD,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,KAAK,wCAEF,CAAC;AAMjB;;GAEG;AACH,eAAO,MAAM,GAAG,wCAGA,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,IAAI,wCAGD,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,MAAM,wCAGH,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,GAAG,wCAGA,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,GAAG,wCAGA,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,GAAG,wCAGA,CAAC;AAMjB;;GAEG;AACH,eAAO,MAAM,IAAI,wCAQD,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,MAAM,wCAEH,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,GAAG,wCAEA,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,MAAM,wCAEH,CAAC;AAEjB;;GAEG;AACH,eAAO,MAAM,QAAQ,wCAGL,CAAC;AAMjB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCjC,CAAC"}
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Dense Matrix Implementation
3
+ *
4
+ * Row-major dense matrix backed by Float64Array for efficient storage
5
+ * and operations. Supports views (slices without copying) where possible.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import { Matrix, MatrixEntry, SliceSpec } from './Matrix.js';
10
+ /**
11
+ * Dense matrix implementation using Float64Array
12
+ *
13
+ * Data is stored in row-major order for cache-friendly row access.
14
+ * All operations return new matrices (immutable API).
15
+ */
16
+ export declare class DenseMatrix extends Matrix<number> {
17
+ readonly type: 'DenseMatrix';
18
+ readonly rows: number;
19
+ readonly cols: number;
20
+ /**
21
+ * Internal data storage (row-major Float64Array)
22
+ */
23
+ private readonly data;
24
+ /**
25
+ * Whether this matrix is a view into another matrix's data
26
+ */
27
+ private readonly isView;
28
+ /**
29
+ * Offset into data array (for views)
30
+ */
31
+ private readonly offset;
32
+ /**
33
+ * Stride between rows (for views)
34
+ */
35
+ private readonly rowStride;
36
+ /**
37
+ * Create a new DenseMatrix
38
+ *
39
+ * @param rows - Number of rows
40
+ * @param cols - Number of columns
41
+ * @param data - Optional initial data (row-major order)
42
+ */
43
+ constructor(rows: number, cols: number, data?: Float64Array | number[] | number[][], viewConfig?: {
44
+ isView: boolean;
45
+ offset: number;
46
+ rowStride: number;
47
+ });
48
+ /**
49
+ * Create a matrix from a nested array
50
+ */
51
+ static fromArray(arr: number[][]): DenseMatrix;
52
+ /**
53
+ * Create a matrix from a flat array with specified dimensions
54
+ */
55
+ static fromFlat(rows: number, cols: number, data: number[]): DenseMatrix;
56
+ /**
57
+ * Create a zero matrix
58
+ */
59
+ static zeros(rows: number, cols: number): DenseMatrix;
60
+ /**
61
+ * Create a matrix filled with ones
62
+ */
63
+ static ones(rows: number, cols: number): DenseMatrix;
64
+ /**
65
+ * Create an identity matrix
66
+ */
67
+ static identity(n: number): DenseMatrix;
68
+ /**
69
+ * Create a diagonal matrix from values
70
+ */
71
+ static diag(values: number[]): DenseMatrix;
72
+ /**
73
+ * Create a matrix filled with a constant value
74
+ */
75
+ static fill(rows: number, cols: number, value: number): DenseMatrix;
76
+ /**
77
+ * Create a matrix with random values in [0, 1)
78
+ */
79
+ static random(rows: number, cols: number): DenseMatrix;
80
+ /**
81
+ * Get element at (row, col)
82
+ * O(1) access time
83
+ */
84
+ get(row: number, col: number): number;
85
+ /**
86
+ * Set element at (row, col) - returns new matrix
87
+ */
88
+ set(row: number, col: number, value: number): DenseMatrix;
89
+ /**
90
+ * Get the raw Float64Array data (copy if view, reference otherwise)
91
+ */
92
+ private toFlatFloat64Array;
93
+ /**
94
+ * Get a row as a 1×n matrix (view, no copy)
95
+ */
96
+ row(index: number): DenseMatrix;
97
+ /**
98
+ * Get a column as an m×1 matrix (copy, since data is row-major)
99
+ */
100
+ column(index: number): DenseMatrix;
101
+ /**
102
+ * Get a submatrix
103
+ */
104
+ slice(spec: SliceSpec): DenseMatrix;
105
+ /**
106
+ * Get the diagonal elements
107
+ */
108
+ diagonal(k?: number): DenseMatrix;
109
+ /**
110
+ * Matrix addition
111
+ */
112
+ add(other: Matrix<number>): DenseMatrix;
113
+ /**
114
+ * Matrix subtraction
115
+ */
116
+ subtract(other: Matrix<number>): DenseMatrix;
117
+ /**
118
+ * Element-wise multiplication (Hadamard product)
119
+ */
120
+ multiplyElementwise(other: Matrix<number>): DenseMatrix;
121
+ /**
122
+ * Matrix multiplication
123
+ */
124
+ multiply(other: Matrix<number>): DenseMatrix;
125
+ /**
126
+ * Scalar multiplication
127
+ */
128
+ scale(scalar: number): DenseMatrix;
129
+ /**
130
+ * Matrix transpose
131
+ */
132
+ transpose(): DenseMatrix;
133
+ /**
134
+ * Negate all elements
135
+ */
136
+ negate(): DenseMatrix;
137
+ /**
138
+ * Sum of all elements
139
+ */
140
+ sum(): number;
141
+ /**
142
+ * Mean of all elements
143
+ */
144
+ mean(): number;
145
+ /**
146
+ * Minimum element
147
+ */
148
+ min(): number;
149
+ /**
150
+ * Maximum element
151
+ */
152
+ max(): number;
153
+ /**
154
+ * Frobenius norm (sqrt of sum of squared elements)
155
+ */
156
+ norm(): number;
157
+ /**
158
+ * Trace (sum of diagonal elements)
159
+ */
160
+ trace(): number;
161
+ /**
162
+ * Convert to nested array
163
+ */
164
+ toArray(): number[][];
165
+ /**
166
+ * Convert to flat array (row-major)
167
+ */
168
+ toFlatArray(): number[];
169
+ /**
170
+ * Get the underlying Float64Array (copy)
171
+ */
172
+ toFloat64Array(): Float64Array;
173
+ /**
174
+ * Clone the matrix
175
+ */
176
+ clone(): DenseMatrix;
177
+ /**
178
+ * Convert to sparse matrix (CSR format)
179
+ *
180
+ * This is a synchronous conversion that creates a SparseMatrix
181
+ * containing only the non-zero elements of this matrix.
182
+ *
183
+ * @param dropTolerance - Values below this threshold are treated as zero
184
+ * @returns SparseMatrix representation (typed as the `Matrix` base — the
185
+ * `SparseMatrix` subtype is loaded lazily to avoid an import cycle)
186
+ */
187
+ toSparse(dropTolerance?: number): Matrix;
188
+ /**
189
+ * Iterate over entries with indices
190
+ */
191
+ entries(): IterableIterator<MatrixEntry<number>>;
192
+ /**
193
+ * Iterate over values (row-major)
194
+ */
195
+ values(): IterableIterator<number>;
196
+ /**
197
+ * Support for...of iteration (iterates over values)
198
+ */
199
+ [Symbol.iterator](): IterableIterator<number>;
200
+ /**
201
+ * Apply a function to each element
202
+ */
203
+ map(fn: (value: number, row: number, col: number) => number): DenseMatrix;
204
+ /**
205
+ * Apply a function to each element (no return, for side effects)
206
+ */
207
+ forEach(fn: (value: number, row: number, col: number) => void): void;
208
+ }
209
+ /**
210
+ * Type guard for DenseMatrix
211
+ */
212
+ export declare function isDenseMatrix(value: unknown): value is DenseMatrix;
213
+ //# sourceMappingURL=DenseMatrix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DenseMatrix.d.ts","sourceRoot":"","sources":["../../src/types/DenseMatrix.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAI7D;;;;;GAKG;AACH,qBAAa,WAAY,SAAQ,MAAM,CAAC,MAAM,CAAC;IAC7C,QAAQ,CAAC,IAAI,EAAG,aAAa,CAAU;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;IAErC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC;;;;;;OAMG;IACH,YACE,IAAI,EAAE,M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EG;IACH,KAAK,IAAI,WAAW,CAEnB;IAED;;;;;;;;;OASG;IACH,QAAQ,CAAC,aAAa,GAAE,MAAU,GAAG,MAAM,CA+B1C;IAMD;;OAEG;IACF,OAAO,IAAI,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAMhD;IAED;;OAEG;IACF,MAAM,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAMlC;IAED;;OAEG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAE5C;IAMD;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,WAAW,CAQxE;IAED;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAMnE;CACF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE"}
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Matrix Base Class
3
+ *
4
+ * Abstract base class defining the common interface for all matrix types.
5
+ * Provides a unified API for DenseMatrix, SparseMatrix, and future implementations.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ /**
10
+ * Matrix dimension type, consolidated from `@danielsimonjr/mathts-core`'s
11
+ * byte-identical copy (see docs/Architecture/duplicate-symbols.json).
12
+ */
13
+ import type { MatrixDimensions } from '@danielsimonjr/mathts-core';
14
+ export type { MatrixDimensions };
15
+ /**
16
+ * Matrix index for element access
17
+ */
18
+ export interface MatrixIndex {
19
+ row: number;
20
+ col: number;
21
+ }
22
+ /**
23
+ * Slice specification for submatrix extraction
24
+ */
25
+ export interface SliceSpec {
26
+ rowStart?: number;
27
+ rowEnd?: number;
28
+ colStart?: number;
29
+ colEnd?: number;
30
+ }
31
+ /**
32
+ * Matrix iterator result
33
+ */
34
+ export interface MatrixEntry<T = number> {
35
+ row: number;
36
+ col: number;
37
+ value: T;
38
+ }
39
+ /**
40
+ * Matrix storage format identifier
41
+ */
42
+ export type MatrixType = 'DenseMatrix' | 'SparseMatrix' | 'DiagonalMatrix' | 'BandMatrix';
43
+ /**
44
+ * Abstract base class for all matrix types
45
+ *
46
+ * @typeParam T - The element type (default: number)
47
+ */
48
+ export declare abstract class Matrix<T = number> {
49
+ /**
50
+ * The matrix storage format type
51
+ */
52
+ abstract readonly type: MatrixType;
53
+ /**
54
+ * Number of rows
55
+ */
56
+ abstract readonly rows: number;
57
+ /**
58
+ * Number of columns
59
+ */
60
+ abstract readonly cols: number;
61
+ /**
62
+ * Get the dimensions of the matrix
63
+ */
64
+ get size(): MatrixDimensions;
65
+ /**
66
+ * Check if the matrix is square
67
+ */
68
+ get isSquare(): boolean;
69
+ /**
70
+ * Check if the matrix is a vector (single row or column)
71
+ */
72
+ get isVector(): boolean;
73
+ /**
74
+ * Check if the matrix is a row vector
75
+ */
76
+ get isRowVector(): boolean;
77
+ /**
78
+ * Check if the matrix is a column vector
79
+ */
80
+ get isColumnVector(): boolean;
81
+ /**
82
+ * Total number of elements
83
+ */
84
+ get length(): number;
85
+ /**
86
+ * Get element at position (row, col)
87
+ * @param row - Row index (0-based)
88
+ * @param col - Column index (0-based)
89
+ */
90
+ abstract get(row: number, col: number): T;
91
+ /**
92
+ * Set element at position (row, col)
93
+ * @param row - Row index (0-based)
94
+ * @param col - Column index (0-based)
95
+ * @param value - Value to set
96
+ * @returns A new matrix with the updated value (immutable)
97
+ */
98
+ abstract set(row: number, col: number, value: T): Matrix<T>;
99
+ /**
100
+ * Get a row as a new matrix (1×n)
101
+ * @param index - Row index
102
+ */
103
+ abstract row(index: number): Matrix<T>;
104
+ /**
105
+ * Get a column as a new matrix (m×1)
106
+ * @param index - Column index
107
+ */
108
+ abstract column(index: number): Matrix<T>;
109
+ /**
110
+ * Get a submatrix (view or copy depending on implementation)
111
+ * @param spec - Slice specification
112
+ */
113
+ abstract slice(spec: SliceSpec): Matrix<T>;
114
+ /**
115
+ * Get the diagonal elements as a vector
116
+ * @param k - Diagonal offset (0 = main diagonal, positive = above, negative = below)
117
+ */
118
+ abstract diagonal(k?: number): Matrix<T>;
119
+ /**
120
+ * Matrix addition
121
+ */
122
+ abstract add(other: Matrix<T>): Matrix<T>;
123
+ /**
124
+ * Matrix subtraction
125
+ */
126
+ abstract subtract(other: Matrix<T>): Matrix<T>;
127
+ /**
128
+ * Element-wise multiplication (Hadamard product)
129
+ */
130
+ abstract multiplyElementwise(other: Matrix<T>): Matrix<T>;
131
+ /**
132
+ * Matrix multiplication
133
+ */
134
+ abstract multiply(other: Matrix<T>): Matrix<T>;
135
+ /**
136
+ * Scalar multiplication
137
+ */
138
+ abstract scale(scalar: T): Matrix<T>;
139
+ /**
140
+ * Matrix transpose
141
+ */
142
+ abstract transpose(): Matrix<T>;
143
+ /**
144
+ * Convert to nested array representation
145
+ */
146
+ abstract toArray(): T[][];
147
+ /**
148
+ * Convert to flat array (row-major order)
149
+ */
150
+ abstract toFlatArray(): T[];
151
+ /**
152
+ * Create a deep copy of the matrix
153
+ */
154
+ abstract clone(): Matrix<T>;
155
+ /**
156
+ * Iterate over all elements with their indices
157
+ */
158
+ abstract entries(): IterableIterator<MatrixEntry<T>>;
159
+ /**
160
+ * Iterate over all values (row-major order)
161
+ */
162
+ abstract values(): IterableIterator<T>;
163
+ /**
164
+ * Check if indices are within bounds
165
+ */
166
+ protected checkBounds(row: number, col: number): void;
167
+ /**
168
+ * Check if dimensions match for element-wise operations
169
+ */
170
+ protected checkDimensionsMatch(other: Matrix<T>): void;
171
+ /**
172
+ * Check if matrices can be multiplied
173
+ */
174
+ protected checkMultiplyDimensions(other: Matrix<T>): void;
175
+ /**
176
+ * Format matrix for display
177
+ */
178
+ toString(): string;
179
+ /**
180
+ * Check equality with another matrix
181
+ */
182
+ equals(other: Matrix<T>, tolerance?: number): boolean;
183
+ }
184
+ /**
185
+ * Type guard to check if a value is a Matrix
186
+ */
187
+ export declare function isMatrix<T = number>(value: unknown): value is Matrix<T>;
188
+ //# sourceMappingURL=Matrix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Matrix.d.ts","sourceRoot":"","sources":["../../src/types/Matrix.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,MAAM;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC;CACV;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,cAAc,GAAG,gBAAgB,GAAG,YAAY,CAAC;AAE1F;;;;GAIG;AACH,8BAAsB,MAAM,CAAC,CAAC,GAAG,MAAM;IACrC;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAEnC;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,IAAI,IAAI,IAAI,gBAAgB,CAE3B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