@pawells/math-extended 1.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -21
- package/build/angles.d.ts +28 -18
- package/build/angles.d.ts.map +1 -1
- package/build/angles.js +28 -18
- package/build/angles.js.map +1 -1
- package/build/clamp.d.ts +2 -0
- package/build/clamp.d.ts.map +1 -1
- package/build/clamp.js +2 -0
- package/build/clamp.js.map +1 -1
- package/build/core.d.ts +23 -0
- package/build/core.d.ts.map +1 -0
- package/build/core.js +25 -0
- package/build/core.js.map +1 -0
- package/build/index.d.ts +1 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -6
- package/build/index.js.map +1 -1
- package/build/interpolation.d.ts +62 -13
- package/build/interpolation.d.ts.map +1 -1
- package/build/interpolation.js +66 -23
- package/build/interpolation.js.map +1 -1
- package/build/matrices/arithmetic.d.ts +65 -76
- package/build/matrices/arithmetic.d.ts.map +1 -1
- package/build/matrices/arithmetic.js +65 -107
- package/build/matrices/arithmetic.js.map +1 -1
- package/build/matrices/asserts.d.ts +26 -273
- package/build/matrices/asserts.d.ts.map +1 -1
- package/build/matrices/asserts.js +106 -350
- package/build/matrices/asserts.js.map +1 -1
- package/build/matrices/core.d.ts +150 -79
- package/build/matrices/core.d.ts.map +1 -1
- package/build/matrices/core.js +128 -104
- package/build/matrices/core.js.map +1 -1
- package/build/matrices/decompositions.d.ts +41 -44
- package/build/matrices/decompositions.d.ts.map +1 -1
- package/build/matrices/decompositions.js +51 -94
- package/build/matrices/decompositions.js.map +1 -1
- package/build/matrices/index.d.ts +2 -2
- package/build/matrices/index.d.ts.map +1 -1
- package/build/matrices/index.js +2 -2
- package/build/matrices/index.js.map +1 -1
- package/build/matrices/linear-algebra.d.ts +56 -19
- package/build/matrices/linear-algebra.d.ts.map +1 -1
- package/build/matrices/linear-algebra.js +80 -36
- package/build/matrices/linear-algebra.js.map +1 -1
- package/build/matrices/normalization.d.ts +36 -15
- package/build/matrices/normalization.d.ts.map +1 -1
- package/build/matrices/normalization.js +32 -23
- package/build/matrices/normalization.js.map +1 -1
- package/build/matrices/transformations.d.ts +39 -52
- package/build/matrices/transformations.d.ts.map +1 -1
- package/build/matrices/transformations.js +8 -11
- package/build/matrices/transformations.js.map +1 -1
- package/build/matrices/types.d.ts +39 -67
- package/build/matrices/types.d.ts.map +1 -1
- package/build/matrices/types.js +63 -1
- package/build/matrices/types.js.map +1 -1
- package/build/quaternions/asserts.d.ts +114 -15
- package/build/quaternions/asserts.d.ts.map +1 -1
- package/build/quaternions/asserts.js +189 -51
- package/build/quaternions/asserts.js.map +1 -1
- package/build/quaternions/conversions.d.ts +18 -8
- package/build/quaternions/conversions.d.ts.map +1 -1
- package/build/quaternions/conversions.js +14 -4
- package/build/quaternions/conversions.js.map +1 -1
- package/build/quaternions/core.d.ts +31 -2
- package/build/quaternions/core.d.ts.map +1 -1
- package/build/quaternions/core.js +32 -4
- package/build/quaternions/core.js.map +1 -1
- package/build/quaternions/index.d.ts +2 -2
- package/build/quaternions/index.d.ts.map +1 -1
- package/build/quaternions/index.js +3 -2
- package/build/quaternions/index.js.map +1 -1
- package/build/quaternions/interpolation.d.ts +7 -1
- package/build/quaternions/interpolation.d.ts.map +1 -1
- package/build/quaternions/interpolation.js +12 -6
- package/build/quaternions/interpolation.js.map +1 -1
- package/build/quaternions/predefined.d.ts +7 -1
- package/build/quaternions/predefined.d.ts.map +1 -1
- package/build/quaternions/predefined.js +6 -0
- package/build/quaternions/predefined.js.map +1 -1
- package/build/quaternions/types.d.ts +24 -13
- package/build/quaternions/types.d.ts.map +1 -1
- package/build/quaternions/types.js +51 -1
- package/build/quaternions/types.js.map +1 -1
- package/build/random.d.ts +66 -20
- package/build/random.d.ts.map +1 -1
- package/build/random.js +73 -20
- package/build/random.js.map +1 -1
- package/build/vectors/asserts.d.ts +33 -99
- package/build/vectors/asserts.d.ts.map +1 -1
- package/build/vectors/asserts.js +145 -181
- package/build/vectors/asserts.js.map +1 -1
- package/build/vectors/core.d.ts +76 -44
- package/build/vectors/core.d.ts.map +1 -1
- package/build/vectors/core.js +128 -119
- package/build/vectors/core.js.map +1 -1
- package/build/vectors/index.d.ts.map +1 -1
- package/build/vectors/index.js +1 -0
- package/build/vectors/index.js.map +1 -1
- package/build/vectors/interpolation.d.ts +13 -1
- package/build/vectors/interpolation.d.ts.map +1 -1
- package/build/vectors/interpolation.js +48 -47
- package/build/vectors/interpolation.js.map +1 -1
- package/build/vectors/predefined.d.ts +73 -25
- package/build/vectors/predefined.d.ts.map +1 -1
- package/build/vectors/predefined.js +62 -18
- package/build/vectors/predefined.js.map +1 -1
- package/build/vectors/types.d.ts +26 -4
- package/build/vectors/types.d.ts.map +1 -1
- package/build/vectors/types.js +50 -1
- package/build/vectors/types.js.map +1 -1
- package/package.json +4 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TVector, TVector2, TVector3, TVector4 } from '../vectors/types.js';
|
|
1
|
+
import type { TMatrix, TMatrix1, TMatrix2, TMatrix3, TMatrix4, TMatrixResult } from './types.js';
|
|
2
|
+
import type { TVector, TVector2, TVector3, TVector4 } from '../vectors/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Performs element-wise addition of two matrices.
|
|
5
5
|
*
|
|
@@ -19,7 +19,7 @@ import { TVector, TVector2, TVector3, TVector4 } from '../vectors/types.js';
|
|
|
19
19
|
* **Time Complexity:** O(m×n) where m and n are the matrix dimensions
|
|
20
20
|
* **Space Complexity:** O(m×n) for the result matrix
|
|
21
21
|
*
|
|
22
|
-
* @template T - The matrix type extending
|
|
22
|
+
* @template T - The matrix type extending TMatrix interface
|
|
23
23
|
* @param a - First matrix (addend) - must have same dimensions as b
|
|
24
24
|
* @param b - Second matrix (addend) - must have same dimensions as a
|
|
25
25
|
* @returns {TMatrixResult<T>} A new matrix where each element is the sum of corresponding elements
|
|
@@ -27,19 +27,19 @@ import { TVector, TVector2, TVector3, TVector4 } from '../vectors/types.js';
|
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* ```typescript
|
|
30
|
+
* ```typescript
|
|
30
31
|
* // Adding 2×2 matrices
|
|
31
32
|
* MatrixAdd([[1, 2], [3, 4]], [[5, 6], [7, 8]]) // Returns [[6, 8], [10, 12]]
|
|
32
|
-
*
|
|
33
33
|
* // Adding 1×3 row vectors
|
|
34
34
|
* MatrixAdd([[1, 2, 3]], [[4, 5, 6]]) // Returns [[5, 7, 9]]
|
|
35
|
-
*
|
|
36
35
|
* // Type-safe matrix addition with specific matrix types
|
|
37
|
-
* const matrixA:
|
|
38
|
-
* const matrixB:
|
|
39
|
-
* const result:
|
|
36
|
+
* const matrixA: TMatrix2 = [[1, 2], [3, 4]];
|
|
37
|
+
* const matrixB: TMatrix2 = [[5, 6], [7, 8]];
|
|
38
|
+
* const result: TMatrix2 = MatrixAdd(matrixA, matrixB);
|
|
39
|
+
* ```
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
export declare function MatrixAdd<T extends
|
|
42
|
+
export declare function MatrixAdd<T extends TMatrix>(a: T, b: T): TMatrixResult<T>;
|
|
43
43
|
/**
|
|
44
44
|
* Performs element-wise subtraction of two matrices (a - b).
|
|
45
45
|
*
|
|
@@ -59,7 +59,7 @@ export declare function MatrixAdd<T extends IMatrix>(a: T, b: T): TMatrixResult<
|
|
|
59
59
|
* **Time Complexity:** O(m×n) where m and n are the matrix dimensions
|
|
60
60
|
* **Space Complexity:** O(m×n) for the result matrix
|
|
61
61
|
*
|
|
62
|
-
* @template T - The matrix type extending
|
|
62
|
+
* @template T - The matrix type extending TMatrix interface
|
|
63
63
|
* @param a - First matrix (minuend) - the matrix being subtracted from
|
|
64
64
|
* @param b - Second matrix (subtrahend) - the matrix being subtracted
|
|
65
65
|
* @returns {TMatrixResult<T>} A new matrix where each element is the difference of corresponding elements
|
|
@@ -67,18 +67,18 @@ export declare function MatrixAdd<T extends IMatrix>(a: T, b: T): TMatrixResult<
|
|
|
67
67
|
*
|
|
68
68
|
* @example
|
|
69
69
|
* ```typescript
|
|
70
|
+
* ```typescript
|
|
70
71
|
* // Subtracting 2×2 matrices
|
|
71
72
|
* MatrixSubtract([[10, 8], [6, 4]], [[3, 2], [1, 1]]) // Returns [[7, 6], [5, 3]]
|
|
72
|
-
*
|
|
73
73
|
* // Order matters: A - B ≠ B - A
|
|
74
74
|
* MatrixSubtract([[1, 2]], [[3, 4]]) // Returns [[-2, -2]]
|
|
75
75
|
* MatrixSubtract([[3, 4]], [[1, 2]]) // Returns [[2, 2]]
|
|
76
|
-
*
|
|
77
76
|
* // Self-subtraction produces zero matrix
|
|
78
77
|
* MatrixSubtract([[5, 6]], [[5, 6]]) // Returns [[0, 0]]
|
|
79
78
|
* ```
|
|
79
|
+
* ```
|
|
80
80
|
*/
|
|
81
|
-
export declare function MatrixSubtract<T extends
|
|
81
|
+
export declare function MatrixSubtract<T extends TMatrix>(a: T, b: T): TMatrixResult<T>;
|
|
82
82
|
/**
|
|
83
83
|
* Performs matrix multiplication with comprehensive type-safe overloads for matrices, vectors, and scalars.
|
|
84
84
|
*
|
|
@@ -89,24 +89,24 @@ export declare function MatrixSubtract<T extends IMatrix>(a: T, b: T): TMatrixRe
|
|
|
89
89
|
*
|
|
90
90
|
* **Type-Safe Overloads:**
|
|
91
91
|
* - **Scalar Multiplication:**
|
|
92
|
-
* - `
|
|
93
|
-
* - `
|
|
94
|
-
* - `
|
|
95
|
-
* - `
|
|
96
|
-
* - `
|
|
92
|
+
* - `TMatrix1 × number → TMatrix1` (1×1 matrix scalar multiplication)
|
|
93
|
+
* - `TMatrix2 × number → TMatrix2` (2×2 matrix scalar multiplication)
|
|
94
|
+
* - `TMatrix3 × number → TMatrix3` (3×3 matrix scalar multiplication)
|
|
95
|
+
* - `TMatrix4 × number → TMatrix4` (4×4 matrix scalar multiplication)
|
|
96
|
+
* - `TMatrix × number → TMatrix` (general matrix scalar multiplication)
|
|
97
97
|
*
|
|
98
98
|
* - **Vector Multiplication:**
|
|
99
|
-
* - `
|
|
100
|
-
* - `
|
|
101
|
-
* - `
|
|
102
|
-
* - `
|
|
99
|
+
* - `TMatrix2 × TVector2 → TVector2` (2×2 matrix × 2D vector)
|
|
100
|
+
* - `TMatrix3 × TVector3 → TVector3` (3×3 matrix × 3D vector)
|
|
101
|
+
* - `TMatrix4 × TVector4 → TVector4` (4×4 matrix × 4D vector)
|
|
102
|
+
* - `TMatrix × TVector → TVector` (general matrix × vector)
|
|
103
103
|
*
|
|
104
104
|
* - **Matrix Multiplication:**
|
|
105
|
-
* - `
|
|
106
|
-
* - `
|
|
107
|
-
* - `
|
|
108
|
-
* - `
|
|
109
|
-
* - `
|
|
105
|
+
* - `TMatrix1 × TMatrix1 → TMatrix1` (1×1 matrix multiplication)
|
|
106
|
+
* - `TMatrix2 × TMatrix2 → TMatrix2` (2×2 matrix multiplication)
|
|
107
|
+
* - `TMatrix3 × TMatrix3 → TMatrix3` (3×3 matrix multiplication)
|
|
108
|
+
* - `TMatrix4 × TMatrix4 → TMatrix4` (4×4 matrix multiplication)
|
|
109
|
+
* - `TMatrix × TMatrix → TMatrix` (general matrix multiplication)
|
|
110
110
|
*
|
|
111
111
|
* **Operation Types:**
|
|
112
112
|
* - **Matrix × Scalar:** Element-wise multiplication by scalar value
|
|
@@ -126,7 +126,7 @@ export declare function MatrixSubtract<T extends IMatrix>(a: T, b: T): TMatrixRe
|
|
|
126
126
|
*
|
|
127
127
|
* @param a - First matrix (left operand) with dimensions m×n
|
|
128
128
|
* @param b - Second operand: matrix (n×p), vector (n elements), or scalar number
|
|
129
|
-
* @returns {
|
|
129
|
+
* @returns {TMatrix | TVector} The product result:
|
|
130
130
|
* - For scalar: m×n matrix with each element multiplied by scalar
|
|
131
131
|
* - For vector: m×1 column vector matrix
|
|
132
132
|
* - For matrix: m×p product matrix
|
|
@@ -134,51 +134,47 @@ export declare function MatrixSubtract<T extends IMatrix>(a: T, b: T): TMatrixRe
|
|
|
134
134
|
*
|
|
135
135
|
* @example
|
|
136
136
|
* ```typescript
|
|
137
|
+
* ```typescript
|
|
137
138
|
* // Type-safe scalar multiplication with specific matrix types
|
|
138
|
-
* const matrix2:
|
|
139
|
-
* const scalar2Result:
|
|
140
|
-
*
|
|
141
|
-
* const
|
|
142
|
-
* const scalar3Result: IMatrix3 = MatrixMultiply(matrix3, 5); // Identity × 5
|
|
143
|
-
*
|
|
139
|
+
* const matrix2: TMatrix2 = [[1, 2], [3, 4]];
|
|
140
|
+
* const scalar2Result: TMatrix2 = MatrixMultiply(matrix2, 2); // [[2, 4], [6, 8]]
|
|
141
|
+
* const matrix3: TMatrix3 = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
|
|
142
|
+
* const scalar3Result: TMatrix3 = MatrixMultiply(matrix3, 5); // Identity × 5
|
|
144
143
|
* // Type-safe vector multiplication with specific matrix/vector types
|
|
145
|
-
* const matrix2x2:
|
|
144
|
+
* const matrix2x2: TMatrix2 = [[1, 2], [3, 4]];
|
|
146
145
|
* const vector2: TVector2 = [5, 6];
|
|
147
146
|
* const vectorResult: TVector2 = MatrixMultiply(matrix2x2, vector2); // [17, 39]
|
|
148
|
-
*
|
|
149
|
-
* const matrix4x4: IMatrix4 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]];
|
|
147
|
+
* const matrix4x4: TMatrix4 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]];
|
|
150
148
|
* const vector4: TVector4 = [1, 2, 3, 4];
|
|
151
149
|
* const vector4Result: TVector4 = MatrixMultiply(matrix4x4, vector4); // [1, 2, 3, 4]
|
|
152
|
-
*
|
|
153
150
|
* // Type-safe matrix multiplication with specific matrix types
|
|
154
|
-
* const matrixA:
|
|
155
|
-
* const matrixB:
|
|
156
|
-
* const matrixResult:
|
|
157
|
-
*
|
|
151
|
+
* const matrixA: TMatrix2 = [[1, 2], [3, 4]];
|
|
152
|
+
* const matrixB: TMatrix2 = [[5, 6], [7, 8]];
|
|
153
|
+
* const matrixResult: TMatrix2 = MatrixMultiply(matrixA, matrixB); // [[19, 22], [43, 50]]
|
|
158
154
|
* // General matrix operations (fallback to generic types)
|
|
159
155
|
* MatrixMultiply([[1, 2]], [[3], [4]]) // Returns [[11]]
|
|
160
156
|
* MatrixMultiply([[1], [2]], [[3, 4]]) // Returns [[3, 4], [6, 8]]
|
|
161
|
-
*
|
|
162
157
|
* // Type detection is automatic - no need to specify operation type
|
|
163
158
|
* const scalarResult = MatrixMultiply(matrixA, 5); // Scalar multiplication
|
|
164
159
|
* const vectorResult2 = MatrixMultiply(matrixA, vector2); // Vector multiplication
|
|
165
160
|
* const matrixResult2 = MatrixMultiply(matrixA, matrixB); // Matrix multiplication
|
|
166
161
|
* ```
|
|
162
|
+
* ```
|
|
167
163
|
*/
|
|
168
|
-
export declare function MatrixMultiply(a:
|
|
169
|
-
export declare function MatrixMultiply(a:
|
|
170
|
-
export declare function MatrixMultiply(a:
|
|
171
|
-
export declare function MatrixMultiply(a:
|
|
172
|
-
export declare function MatrixMultiply(a:
|
|
173
|
-
export declare function MatrixMultiply(a:
|
|
174
|
-
export declare function MatrixMultiply(a:
|
|
175
|
-
export declare function MatrixMultiply(a:
|
|
176
|
-
export declare function MatrixMultiply(a:
|
|
177
|
-
export declare function MatrixMultiply(a:
|
|
178
|
-
export declare function MatrixMultiply(a:
|
|
179
|
-
export declare function MatrixMultiply(a:
|
|
180
|
-
export declare function MatrixMultiply(a:
|
|
181
|
-
export declare function MatrixMultiply(a:
|
|
164
|
+
export declare function MatrixMultiply(a: TMatrix1, b: number): TMatrix1;
|
|
165
|
+
export declare function MatrixMultiply(a: TMatrix2, b: number): TMatrix2;
|
|
166
|
+
export declare function MatrixMultiply(a: TMatrix3, b: number): TMatrix3;
|
|
167
|
+
export declare function MatrixMultiply(a: TMatrix4, b: number): TMatrix4;
|
|
168
|
+
export declare function MatrixMultiply(a: TMatrix2, b: TVector2): TVector2;
|
|
169
|
+
export declare function MatrixMultiply(a: TMatrix3, b: TVector3): TVector3;
|
|
170
|
+
export declare function MatrixMultiply(a: TMatrix4, b: TVector4): TVector4;
|
|
171
|
+
export declare function MatrixMultiply(a: TMatrix1, b: TMatrix1): TMatrix1;
|
|
172
|
+
export declare function MatrixMultiply(a: TMatrix2, b: TMatrix2): TMatrix2;
|
|
173
|
+
export declare function MatrixMultiply(a: TMatrix3, b: TMatrix3): TMatrix3;
|
|
174
|
+
export declare function MatrixMultiply(a: TMatrix4, b: TMatrix4): TMatrix4;
|
|
175
|
+
export declare function MatrixMultiply(a: TMatrix, b: TVector): TVector;
|
|
176
|
+
export declare function MatrixMultiply(a: TMatrix, b: TMatrix): TMatrix;
|
|
177
|
+
export declare function MatrixMultiply(a: TMatrix, b: number): TMatrix;
|
|
182
178
|
/**
|
|
183
179
|
* Extracts a rectangular submatrix from a larger matrix.
|
|
184
180
|
*
|
|
@@ -219,28 +215,24 @@ export declare function MatrixMultiply(a: IMatrix, b: number): IMatrix;
|
|
|
219
215
|
* @param startRow - Starting row index (0-based, inclusive) — note reversed order
|
|
220
216
|
* @param width - Number of columns to extract (must be positive)
|
|
221
217
|
* @param height - Number of rows to extract (must be positive)
|
|
222
|
-
* @returns {
|
|
218
|
+
* @returns {TMatrix} The extracted submatrix with dimensions height×width
|
|
223
219
|
* @throws {Error} If extraction bounds exceed matrix dimensions or contain invalid values
|
|
224
220
|
* @example
|
|
225
221
|
* ```typescript
|
|
222
|
+
* ```typescript
|
|
226
223
|
* const matrix = [
|
|
227
224
|
* [1, 2, 3, 4],
|
|
228
225
|
* [5, 6, 7, 8],
|
|
229
226
|
* [9, 10, 11, 12]
|
|
230
227
|
* ]; // 3×4 matrix
|
|
231
|
-
*
|
|
232
228
|
* // Extract 2×2 submatrix from top-left corner
|
|
233
229
|
* MatrixSubmatrix(matrix, 0, 0, 2, 2) // Returns [[1, 2], [5, 6]]
|
|
234
|
-
*
|
|
235
230
|
* // Extract 2×2 submatrix from center-right region
|
|
236
231
|
* MatrixSubmatrix(matrix, 2, 1, 2, 2) // Returns [[7, 8], [11, 12]]
|
|
237
|
-
*
|
|
238
232
|
* // Extract single column (column vector)
|
|
239
233
|
* MatrixSubmatrix(matrix, 1, 0, 1, 3) // Returns [[2], [6], [10]]
|
|
240
|
-
*
|
|
241
234
|
* // Extract single row (row vector)
|
|
242
235
|
* MatrixSubmatrix(matrix, 0, 1, 4, 1) // Returns [[5, 6, 7, 8]]
|
|
243
|
-
*
|
|
244
236
|
* // Block matrix partitioning for algorithms
|
|
245
237
|
* const large = MatrixCreate(8, 8); // 8×8 matrix
|
|
246
238
|
* const topLeft = MatrixSubmatrix(large, 0, 0, 4, 4); // Top-left 4×4 block
|
|
@@ -248,8 +240,9 @@ export declare function MatrixMultiply(a: IMatrix, b: number): IMatrix;
|
|
|
248
240
|
* const bottomLeft = MatrixSubmatrix(large, 0, 4, 4, 4); // Bottom-left 4×4 block
|
|
249
241
|
* const bottomRight = MatrixSubmatrix(large, 4, 4, 4, 4); // Bottom-right 4×4 block
|
|
250
242
|
* ```
|
|
243
|
+
* ```
|
|
251
244
|
*/
|
|
252
|
-
export declare function MatrixSubmatrix(matrix:
|
|
245
|
+
export declare function MatrixSubmatrix(matrix: TMatrix, startCol: number, startRow: number, width: number, height: number): TMatrix;
|
|
253
246
|
/**
|
|
254
247
|
* Pads a matrix with zeros to reach the specified dimensions.
|
|
255
248
|
*
|
|
@@ -288,12 +281,12 @@ export declare function MatrixSubmatrix(matrix: IMatrix, startCol: number, start
|
|
|
288
281
|
* @param matrix - Source matrix to pad
|
|
289
282
|
* @param newRows - Target number of rows (must be ≥ current rows)
|
|
290
283
|
* @param newCols - Target number of columns (must be ≥ current columns)
|
|
291
|
-
* @returns {
|
|
284
|
+
* @returns {TMatrix} The padded matrix with dimensions newRows×newCols
|
|
292
285
|
* @throws {Error} If new dimensions are smaller than current dimensions
|
|
293
286
|
* @example
|
|
294
287
|
* ```typescript
|
|
288
|
+
* ```typescript
|
|
295
289
|
* const matrix = [[1, 2], [3, 4]]; // 2×2 matrix
|
|
296
|
-
*
|
|
297
290
|
* // Pad to 4×4 matrix (symmetric padding)
|
|
298
291
|
* MatrixPad(matrix, 4, 4)
|
|
299
292
|
* // Returns:
|
|
@@ -301,28 +294,25 @@ export declare function MatrixSubmatrix(matrix: IMatrix, startCol: number, start
|
|
|
301
294
|
* // [3, 4, 0, 0],
|
|
302
295
|
* // [0, 0, 0, 0],
|
|
303
296
|
* // [0, 0, 0, 0]]
|
|
304
|
-
*
|
|
305
297
|
* // Pad to 3×4 matrix (asymmetric padding)
|
|
306
298
|
* MatrixPad(matrix, 3, 4)
|
|
307
299
|
* // Returns:
|
|
308
300
|
* // [[1, 2, 0, 0],
|
|
309
301
|
* // [3, 4, 0, 0],
|
|
310
302
|
* // [0, 0, 0, 0]]
|
|
311
|
-
*
|
|
312
303
|
* // Prepare for power-of-2 algorithm (e.g., FFT-based convolution)
|
|
313
304
|
* const data = [[1, 2, 3], [4, 5, 6]]; // 2×3 matrix
|
|
314
305
|
* const powerOf2 = MatrixPad(data, 4, 4); // Pad to 4×4 for FFT
|
|
315
|
-
*
|
|
316
306
|
* // Batch size alignment in machine learning
|
|
317
307
|
* const features = MatrixCreate(7, 10); // 7 samples, 10 features
|
|
318
308
|
* const aligned = MatrixPad(features, 8, 10); // Align to batch size 8
|
|
319
|
-
*
|
|
320
309
|
* // Image border padding for convolution
|
|
321
310
|
* const image = MatrixCreate(28, 28); // 28×28 image
|
|
322
311
|
* const padded = MatrixPad(image, 32, 32); // Add border for valid convolution
|
|
323
312
|
* ```
|
|
313
|
+
* ```
|
|
324
314
|
*/
|
|
325
|
-
export declare function MatrixPad(matrix:
|
|
315
|
+
export declare function MatrixPad(matrix: TMatrix, newRows: number, newCols: number): TMatrix;
|
|
326
316
|
/**
|
|
327
317
|
* Combines four square submatrices into a single matrix (2×2 block structure).
|
|
328
318
|
*
|
|
@@ -371,31 +361,29 @@ export declare function MatrixPad(matrix: IMatrix, newRows: number, newCols: num
|
|
|
371
361
|
* @param c12 - Top-right quadrant (upper-right block)
|
|
372
362
|
* @param c21 - Bottom-left quadrant (lower-left block)
|
|
373
363
|
* @param c22 - Bottom-right quadrant (lower-right block)
|
|
374
|
-
* @returns {
|
|
364
|
+
* @returns {TMatrix} The combined matrix with dimensions 2n×2n (where each input is n×n)
|
|
375
365
|
* @throws {Error} If quadrants have mismatched dimensions or invalid values
|
|
376
366
|
*
|
|
377
367
|
* @example
|
|
378
368
|
* ```typescript
|
|
369
|
+
* ```typescript
|
|
379
370
|
* // Basic 2×2 quadrant combination
|
|
380
371
|
* const topLeft = [[1, 2], [3, 4]];
|
|
381
372
|
* const topRight = [[5, 6], [7, 8]];
|
|
382
373
|
* const bottomLeft = [[9, 10], [11, 12]];
|
|
383
374
|
* const bottomRight = [[13, 14], [15, 16]];
|
|
384
|
-
*
|
|
385
375
|
* MatrixCombine(topLeft, topRight, bottomLeft, bottomRight)
|
|
386
376
|
* // Returns:
|
|
387
377
|
* // [[1, 2, 5, 6],
|
|
388
378
|
* // [3, 4, 7, 8],
|
|
389
379
|
* // [9, 10, 13, 14],
|
|
390
380
|
* // [11,12, 15, 16]]
|
|
391
|
-
*
|
|
392
381
|
* // Strassen algorithm result reconstruction
|
|
393
382
|
* const m1 = computeStrassenProduct1(); // Computed Strassen intermediate results
|
|
394
383
|
* const m2 = computeStrassenProduct2();
|
|
395
384
|
* const m3 = computeStrassenProduct3();
|
|
396
385
|
* const m4 = computeStrassenProduct4();
|
|
397
386
|
* const finalResult = MatrixCombine(m1, m2, m3, m4); // Assemble final result
|
|
398
|
-
*
|
|
399
387
|
* // Image processing: combining processed quadrants
|
|
400
388
|
* const processedTopLeft = processImageQuadrant(imageTopLeft);
|
|
401
389
|
* const processedTopRight = processImageQuadrant(imageTopRight);
|
|
@@ -406,6 +394,7 @@ export declare function MatrixPad(matrix: IMatrix, newRows: number, newCols: num
|
|
|
406
394
|
* processedBottomLeft, processedBottomRight
|
|
407
395
|
* );
|
|
408
396
|
* ```
|
|
397
|
+
* ```
|
|
409
398
|
*/
|
|
410
|
-
export declare function MatrixCombine(c11:
|
|
399
|
+
export declare function MatrixCombine(c11: TMatrix, c12: TMatrix, c21: TMatrix, c22: TMatrix): TMatrix;
|
|
411
400
|
//# sourceMappingURL=arithmetic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arithmetic.d.ts","sourceRoot":"","sources":["../../src/matrices/arithmetic.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"arithmetic.d.ts","sourceRoot":"","sources":["../../src/matrices/arithmetic.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACjG,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAiCzE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CA8B9E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiFG;AAEH,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC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