Skip to content

Commit 0132991

Browse files
authored
Enhance type definitions in Matrix and Tensor classes (#976)
1 parent 90f4cd2 commit 0132991

File tree

2 files changed

+98
-59
lines changed

2 files changed

+98
-59
lines changed

lib/util/matrix.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,33 +1316,43 @@ export default class Matrix {
13161316
return r
13171317
}
13181318

1319+
/**
1320+
* Returns a matrix reduced along all element with the callback function.
1321+
* @overload
1322+
* @param {function (T, T, number[], Matrix<T>): T} cb Reducing function
1323+
* @param {undefined | null} [init] Initial value
1324+
* @returns {T} Reduced value
1325+
*/
13191326
/**
13201327
* Returns a matrix reduced along all element with the callback function.
13211328
* @template U
13221329
* @overload
13231330
* @param {function (U, T, number[], Matrix<T>): U} cb Reducing function
1324-
* @param {U} [init] Initial value
1331+
* @param {U} init Initial value
13251332
* @returns {U} Reduced value
13261333
*/
13271334
/**
13281335
* Returns a matrix reduced along the axis with the callback function.
1329-
* @template U
1336+
* @template {number | number[]} A
1337+
* @template {boolean} F
13301338
* @overload
1331-
* @param {function (U, T, number[], Matrix<T>): U} cb Reducing function
1332-
* @param {U} init Initial value
1333-
* @param {0 | 1} axis Axis to be reduced
1334-
* @param {boolean} [keepdims] Keep dimensions or not. If null, negative axis retuns number and other axis returns Matrix.
1335-
* @returns {Matrix<U>} Reduced matrix
1339+
* @param {function (T, T, number[], Matrix<T>): T} cb Reducing function
1340+
* @param {undefined | null} init Initial value
1341+
* @param {A} axis Axis to be reduced
1342+
* @param {F} [keepdims] Keep dimensions or not. If null, negative axis retuns number and other axis returns Matrix.
1343+
* @returns {Matrix<T> | (A extends 0 | 1 ? never : F extends true ? never : T)} Reduced matrix
13361344
*/
13371345
/**
13381346
* Returns a matrix reduced along the axis with the callback function.
13391347
* @template U
1348+
* @template {number | number[]} A
1349+
* @template {boolean} F
13401350
* @overload
13411351
* @param {function (U, T, number[], Matrix<T>): U} cb Reducing function
13421352
* @param {U} init Initial value
1343-
* @param {number | number[]} axis Axis to be reduced. If negative, reduce along all elements.
1344-
* @param {boolean} [keepdims] Keep dimensions or not. If null, negative axis retuns number and other axis returns Matrix.
1345-
* @returns {Matrix<U> | U} Reduced matrix or value
1353+
* @param {A} axis Axis to be reduced
1354+
* @param {F} [keepdims] Keep dimensions or not. If null, negative axis retuns number and other axis returns Matrix.
1355+
* @returns {Matrix<U> | (A extends 0 | 1 ? never : F extends true ? never : U)} Reduced matrix
13461356
*/
13471357
/**
13481358
* @template U

0 commit comments

Comments
 (0)