@pawells/math-extended 1.1.1 → 2.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/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 +5 -3
- package/build/clamp.d.ts.map +1 -1
- package/build/clamp.js +5 -3
- package/build/clamp.js.map +1 -1
- package/build/interpolation.d.ts +158 -96
- package/build/interpolation.d.ts.map +1 -1
- package/build/interpolation.js +158 -96
- package/build/interpolation.js.map +1 -1
- package/build/matrices/_exports.d.ts +13 -0
- package/build/matrices/_exports.d.ts.map +1 -0
- package/build/matrices/_exports.js +13 -0
- package/build/matrices/_exports.js.map +1 -0
- package/build/matrices/arithmetic.d.ts +170 -181
- package/build/matrices/arithmetic.d.ts.map +1 -1
- package/build/matrices/arithmetic.js +192 -202
- package/build/matrices/arithmetic.js.map +1 -1
- package/build/matrices/asserts.d.ts +240 -109
- package/build/matrices/asserts.d.ts.map +1 -1
- package/build/matrices/asserts.js +287 -87
- package/build/matrices/asserts.js.map +1 -1
- package/build/matrices/core.d.ts +29 -29
- package/build/matrices/core.js +1 -1
- package/build/matrices/decompositions.d.ts +102 -104
- package/build/matrices/decompositions.d.ts.map +1 -1
- package/build/matrices/decompositions.js +87 -89
- package/build/matrices/decompositions.js.map +1 -1
- package/build/matrices/index.d.ts +3 -2
- package/build/matrices/index.d.ts.map +1 -1
- package/build/matrices/index.js +5 -2
- package/build/matrices/index.js.map +1 -1
- package/build/matrices/linear-algebra.d.ts +12 -12
- package/build/matrices/linear-algebra.js +4 -4
- package/build/matrices/normalization.d.ts +8 -8
- package/build/matrices/transformations.d.ts +184 -165
- package/build/matrices/transformations.d.ts.map +1 -1
- package/build/matrices/transformations.js +99 -80
- package/build/matrices/transformations.js.map +1 -1
- package/build/matrices/types.d.ts +12 -12
- package/build/matrices/types.d.ts.map +1 -1
- package/build/quaternions/_exports.d.ts +11 -0
- package/build/quaternions/_exports.d.ts.map +1 -0
- package/build/quaternions/_exports.js +11 -0
- package/build/quaternions/_exports.js.map +1 -0
- package/build/quaternions/asserts.d.ts +115 -7
- package/build/quaternions/asserts.d.ts.map +1 -1
- package/build/quaternions/asserts.js +162 -8
- package/build/quaternions/asserts.js.map +1 -1
- package/build/quaternions/conversions.d.ts +31 -21
- package/build/quaternions/conversions.d.ts.map +1 -1
- package/build/quaternions/conversions.js +28 -18
- package/build/quaternions/conversions.js.map +1 -1
- package/build/quaternions/core.d.ts +67 -39
- package/build/quaternions/core.d.ts.map +1 -1
- package/build/quaternions/core.js +67 -39
- package/build/quaternions/core.js.map +1 -1
- package/build/quaternions/index.d.ts +3 -2
- package/build/quaternions/index.d.ts.map +1 -1
- package/build/quaternions/index.js +5 -2
- package/build/quaternions/index.js.map +1 -1
- package/build/quaternions/interpolation.d.ts +15 -9
- package/build/quaternions/interpolation.d.ts.map +1 -1
- package/build/quaternions/interpolation.js +15 -9
- package/build/quaternions/interpolation.js.map +1 -1
- package/build/quaternions/predefined.d.ts +9 -3
- package/build/quaternions/predefined.d.ts.map +1 -1
- package/build/quaternions/predefined.js +9 -3
- package/build/quaternions/predefined.js.map +1 -1
- package/build/quaternions/types.d.ts +3 -3
- package/build/vectors/_exports.d.ts +10 -0
- package/build/vectors/_exports.d.ts.map +1 -0
- package/build/vectors/_exports.js +10 -0
- package/build/vectors/_exports.js.map +1 -0
- package/build/vectors/asserts.d.ts +153 -49
- package/build/vectors/asserts.d.ts.map +1 -1
- package/build/vectors/asserts.js +202 -52
- package/build/vectors/asserts.js.map +1 -1
- package/build/vectors/core.d.ts +216 -137
- package/build/vectors/core.d.ts.map +1 -1
- package/build/vectors/core.js +212 -149
- package/build/vectors/core.js.map +1 -1
- package/build/vectors/index.d.ts +1 -0
- package/build/vectors/index.d.ts.map +1 -1
- package/build/vectors/index.js +3 -0
- package/build/vectors/index.js.map +1 -1
- package/build/vectors/interpolation.d.ts +39 -27
- package/build/vectors/interpolation.d.ts.map +1 -1
- package/build/vectors/interpolation.js +39 -27
- package/build/vectors/interpolation.js.map +1 -1
- package/build/vectors/predefined.d.ts +48 -24
- package/build/vectors/predefined.d.ts.map +1 -1
- package/build/vectors/predefined.js +38 -18
- package/build/vectors/predefined.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TMatrix, TMatrix1, TMatrix2, TMatrix3, TMatrix4, TMatrixResult } from './types.js';
|
|
2
2
|
import { TVector, TVector2, TVector3, TVector4 } from '../vectors/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Performs element-wise addition of two matrices.
|
|
@@ -19,27 +19,27 @@ 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
|
|
26
26
|
* @throws {Error} If matrices have different dimensions or contain invalid values
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
* ```typescript
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Adding 2×2 matrices
|
|
32
|
+
* MatrixAdd([[1, 2], [3, 4]], [[5, 6], [7, 8]]) // Returns [[6, 8], [10, 12]]
|
|
33
|
+
* // Adding 1×3 row vectors
|
|
34
|
+
* MatrixAdd([[1, 2, 3]], [[4, 5, 6]]) // Returns [[5, 7, 9]]
|
|
35
|
+
* // Type-safe matrix addition with specific matrix types
|
|
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
|
+
* ```
|
|
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,26 +59,26 @@ 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
|
|
66
66
|
* @throws {Error} If matrices have different dimensions or contain invalid values
|
|
67
67
|
*
|
|
68
68
|
* @example
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
* ```typescript
|
|
70
|
+
* ```typescript
|
|
71
|
+
* // Subtracting 2×2 matrices
|
|
72
|
+
* MatrixSubtract([[10, 8], [6, 4]], [[3, 2], [1, 1]]) // Returns [[7, 6], [5, 3]]
|
|
73
|
+
* // Order matters: A - B ≠ B - A
|
|
74
|
+
* MatrixSubtract([[1, 2]], [[3, 4]]) // Returns [[-2, -2]]
|
|
75
|
+
* MatrixSubtract([[3, 4]], [[1, 2]]) // Returns [[2, 2]]
|
|
76
|
+
* // Self-subtraction produces zero matrix
|
|
77
|
+
* MatrixSubtract([[5, 6]], [[5, 6]]) // Returns [[0, 0]]
|
|
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,59 +126,55 @@ 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
|
|
133
133
|
* @throws {Error} If matrix dimensions are incompatible for multiplication
|
|
134
134
|
*
|
|
135
135
|
* @example
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
* const scalarResult = MatrixMultiply(matrixA, 5); // Scalar multiplication
|
|
164
|
-
* const vectorResult2 = MatrixMultiply(matrixA, vector2); // Vector multiplication
|
|
165
|
-
* const matrixResult2 = MatrixMultiply(matrixA, matrixB); // Matrix multiplication
|
|
166
|
-
* ```
|
|
136
|
+
* ```typescript
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Type-safe scalar multiplication with specific matrix types
|
|
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
|
|
143
|
+
* // Type-safe vector multiplication with specific matrix/vector types
|
|
144
|
+
* const matrix2x2: TMatrix2 = [[1, 2], [3, 4]];
|
|
145
|
+
* const vector2: TVector2 = [5, 6];
|
|
146
|
+
* const vectorResult: TVector2 = MatrixMultiply(matrix2x2, vector2); // [17, 39]
|
|
147
|
+
* const matrix4x4: TMatrix4 = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]];
|
|
148
|
+
* const vector4: TVector4 = [1, 2, 3, 4];
|
|
149
|
+
* const vector4Result: TVector4 = MatrixMultiply(matrix4x4, vector4); // [1, 2, 3, 4]
|
|
150
|
+
* // Type-safe matrix multiplication with specific matrix types
|
|
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]]
|
|
154
|
+
* // General matrix operations (fallback to generic types)
|
|
155
|
+
* MatrixMultiply([[1, 2]], [[3], [4]]) // Returns [[11]]
|
|
156
|
+
* MatrixMultiply([[1], [2]], [[3, 4]]) // Returns [[3, 4], [6, 8]]
|
|
157
|
+
* // Type detection is automatic - no need to specify operation type
|
|
158
|
+
* const scalarResult = MatrixMultiply(matrixA, 5); // Scalar multiplication
|
|
159
|
+
* const vectorResult2 = MatrixMultiply(matrixA, vector2); // Vector multiplication
|
|
160
|
+
* const matrixResult2 = MatrixMultiply(matrixA, matrixB); // Matrix multiplication
|
|
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,37 +215,34 @@ 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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
* const bottomLeft = MatrixSubmatrix(large, 0, 4, 4, 4); // Bottom-left 4×4 block
|
|
249
|
-
* const bottomRight = MatrixSubmatrix(large, 4, 4, 4, 4); // Bottom-right 4×4 block
|
|
250
|
-
* ```
|
|
221
|
+
* ```typescript
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const matrix = [
|
|
224
|
+
* [1, 2, 3, 4],
|
|
225
|
+
* [5, 6, 7, 8],
|
|
226
|
+
* [9, 10, 11, 12]
|
|
227
|
+
* ]; // 3×4 matrix
|
|
228
|
+
* // Extract 2×2 submatrix from top-left corner
|
|
229
|
+
* MatrixSubmatrix(matrix, 0, 0, 2, 2) // Returns [[1, 2], [5, 6]]
|
|
230
|
+
* // Extract 2×2 submatrix from center-right region
|
|
231
|
+
* MatrixSubmatrix(matrix, 2, 1, 2, 2) // Returns [[7, 8], [11, 12]]
|
|
232
|
+
* // Extract single column (column vector)
|
|
233
|
+
* MatrixSubmatrix(matrix, 1, 0, 1, 3) // Returns [[2], [6], [10]]
|
|
234
|
+
* // Extract single row (row vector)
|
|
235
|
+
* MatrixSubmatrix(matrix, 0, 1, 4, 1) // Returns [[5, 6, 7, 8]]
|
|
236
|
+
* // Block matrix partitioning for algorithms
|
|
237
|
+
* const large = MatrixCreate(8, 8); // 8×8 matrix
|
|
238
|
+
* const topLeft = MatrixSubmatrix(large, 0, 0, 4, 4); // Top-left 4×4 block
|
|
239
|
+
* const topRight = MatrixSubmatrix(large, 4, 0, 4, 4); // Top-right 4×4 block
|
|
240
|
+
* const bottomLeft = MatrixSubmatrix(large, 0, 4, 4, 4); // Bottom-left 4×4 block
|
|
241
|
+
* const bottomRight = MatrixSubmatrix(large, 4, 4, 4, 4); // Bottom-right 4×4 block
|
|
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,41 +281,38 @@ 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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
* const image = MatrixCreate(28, 28); // 28×28 image
|
|
322
|
-
* const padded = MatrixPad(image, 32, 32); // Add border for valid convolution
|
|
323
|
-
* ```
|
|
287
|
+
* ```typescript
|
|
288
|
+
* ```typescript
|
|
289
|
+
* const matrix = [[1, 2], [3, 4]]; // 2×2 matrix
|
|
290
|
+
* // Pad to 4×4 matrix (symmetric padding)
|
|
291
|
+
* MatrixPad(matrix, 4, 4)
|
|
292
|
+
* // Returns:
|
|
293
|
+
* // [[1, 2, 0, 0],
|
|
294
|
+
* // [3, 4, 0, 0],
|
|
295
|
+
* // [0, 0, 0, 0],
|
|
296
|
+
* // [0, 0, 0, 0]]
|
|
297
|
+
* // Pad to 3×4 matrix (asymmetric padding)
|
|
298
|
+
* MatrixPad(matrix, 3, 4)
|
|
299
|
+
* // Returns:
|
|
300
|
+
* // [[1, 2, 0, 0],
|
|
301
|
+
* // [3, 4, 0, 0],
|
|
302
|
+
* // [0, 0, 0, 0]]
|
|
303
|
+
* // Prepare for power-of-2 algorithm (e.g., FFT-based convolution)
|
|
304
|
+
* const data = [[1, 2, 3], [4, 5, 6]]; // 2×3 matrix
|
|
305
|
+
* const powerOf2 = MatrixPad(data, 4, 4); // Pad to 4×4 for FFT
|
|
306
|
+
* // Batch size alignment in machine learning
|
|
307
|
+
* const features = MatrixCreate(7, 10); // 7 samples, 10 features
|
|
308
|
+
* const aligned = MatrixPad(features, 8, 10); // Align to batch size 8
|
|
309
|
+
* // Image border padding for convolution
|
|
310
|
+
* const image = MatrixCreate(28, 28); // 28×28 image
|
|
311
|
+
* const padded = MatrixPad(image, 32, 32); // Add border for valid convolution
|
|
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,41 +361,40 @@ 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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
* ```
|
|
368
|
+
* ```typescript
|
|
369
|
+
* ```typescript
|
|
370
|
+
* // Basic 2×2 quadrant combination
|
|
371
|
+
* const topLeft = [[1, 2], [3, 4]];
|
|
372
|
+
* const topRight = [[5, 6], [7, 8]];
|
|
373
|
+
* const bottomLeft = [[9, 10], [11, 12]];
|
|
374
|
+
* const bottomRight = [[13, 14], [15, 16]];
|
|
375
|
+
* MatrixCombine(topLeft, topRight, bottomLeft, bottomRight)
|
|
376
|
+
* // Returns:
|
|
377
|
+
* // [[1, 2, 5, 6],
|
|
378
|
+
* // [3, 4, 7, 8],
|
|
379
|
+
* // [9, 10, 13, 14],
|
|
380
|
+
* // [11,12, 15, 16]]
|
|
381
|
+
* // Strassen algorithm result reconstruction
|
|
382
|
+
* const m1 = computeStrassenProduct1(); // Computed Strassen intermediate results
|
|
383
|
+
* const m2 = computeStrassenProduct2();
|
|
384
|
+
* const m3 = computeStrassenProduct3();
|
|
385
|
+
* const m4 = computeStrassenProduct4();
|
|
386
|
+
* const finalResult = MatrixCombine(m1, m2, m3, m4); // Assemble final result
|
|
387
|
+
* // Image processing: combining processed quadrants
|
|
388
|
+
* const processedTopLeft = processImageQuadrant(imageTopLeft);
|
|
389
|
+
* const processedTopRight = processImageQuadrant(imageTopRight);
|
|
390
|
+
* const processedBottomLeft = processImageQuadrant(imageBottomLeft);
|
|
391
|
+
* const processedBottomRight = processImageQuadrant(imageBottomRight);
|
|
392
|
+
* const reconstructedImage = MatrixCombine(
|
|
393
|
+
* processedTopLeft, processedTopRight,
|
|
394
|
+
* processedBottomLeft, processedBottomRight
|
|
395
|
+
* );
|
|
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,OAA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