@@ -85,7 +85,7 @@ Matrix.addable = function (x: Matrix, y: Matrix): boolean {
85
85
*/
86
86
function Add ( x : Matrix1D , y : Matrix1D ) : Matrix1D ;
87
87
function Add ( x : Matrix2D , y : Matrix2D ) : Matrix2D ;
88
- function Add < T extends Matrix1D & Matrix2D > ( x : T , y : T ) : Matrix1D | Matrix2D {
88
+ function Add < T extends Matrix1D | Matrix2D > ( x : T , y : T ) : Matrix1D | Matrix2D {
89
89
if ( ! Matrix . addable ( x , y ) ) throw new TypeError ( "Matrices are not addable" ) ;
90
90
return x . map ( ( row : number [ ] , i : number ) : number [ ] =>
91
91
row . map ( ( column : number , j : number ) : number => {
@@ -134,7 +134,12 @@ function innerproduct(x: Matrix1D, y: Matrix, i: number): number {
134
134
* @param {Matrix } y - Matrix to multiply
135
135
* @return {Matrix } New matrix with the dot product
136
136
*/
137
- Matrix . multiply = function ( x : Matrix , y : Matrix ) : Matrix {
137
+ function Multiply ( x : Matrix1D , y : Matrix ) : Matrix1D ;
138
+ function Multiply ( x : Matrix2D , y : Matrix ) : Matrix2D ;
139
+ function Multiply < T extends Matrix1D | Matrix2D > (
140
+ x : T ,
141
+ y : Matrix
142
+ ) : Matrix1D | Matrix2D {
138
143
if ( ! Matrix . multipliable ( x , y ) ) {
139
144
throw new TypeError ( "Matrices are not multipliable" ) ;
140
145
}
@@ -154,7 +159,8 @@ Matrix.multiply = function (x: Matrix, y: Matrix): Matrix {
154
159
}
155
160
} ) ;
156
161
}
157
- } ;
162
+ }
163
+ Matrix . multiply = Multiply ;
158
164
159
165
/**
160
166
* Inverts a matrix. Matrix must be a square (e.g. 1x1 or 2x2)
@@ -164,7 +170,7 @@ Matrix.multiply = function (x: Matrix, y: Matrix): Matrix {
164
170
*/
165
171
function Invert ( x : Matrix1D ) : Matrix1D ;
166
172
function Invert ( x : Matrix2D ) : Matrix2D ;
167
- function Invert < T extends Matrix1D & Matrix2D > ( x : T ) : Matrix1D | Matrix2D {
173
+ function Invert < T extends Matrix1D | Matrix2D > ( x : T ) : Matrix1D | Matrix2D {
168
174
return Matrix ( inv < any > ( x . __value ) ) ;
169
175
}
170
176
Matrix . invert = Invert ;
@@ -231,9 +237,15 @@ Matrix.prototype.multipliable = function (this: Matrix, y: Matrix): boolean {
231
237
* @param {Matrix } y - Matrix to multiply
232
238
* @return {Matrix } New matrix with the dot product
233
239
*/
234
- Matrix . prototype . multiply = function ( this : Matrix , y : Matrix ) : Matrix {
240
+ function multiply ( this : Matrix1D , y : Matrix ) : Matrix1D ;
241
+ function multiply ( this : Matrix2D , y : Matrix ) : Matrix2D ;
242
+ function multiply < T extends Matrix1D & Matrix2D > (
243
+ this : T ,
244
+ y : Matrix
245
+ ) : Matrix1D | Matrix2D {
235
246
return Matrix . multiply ( this , y ) ;
236
- } ;
247
+ }
248
+ Matrix . prototype . multiply = multiply ;
237
249
238
250
/**
239
251
* Calculates the transpose of this matrix
0 commit comments