Skip to content

Commit c32bc1b

Browse files
committed
chore: add jsdoc to functions
1 parent dd0b69c commit c32bc1b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,12 @@ SparseMatrix.prototype.klass = 'Matrix';
14581458
SparseMatrix.identity = SparseMatrix.eye;
14591459
SparseMatrix.prototype.tensorProduct = SparseMatrix.prototype.kroneckerProduct;
14601460

1461+
/**
1462+
* Converts a matrix from Compressed Sparse Row (CSR) format to Compressed Sparse Column (CSC) format.
1463+
* @param {Object} csrMatrix - The matrix in CSR format with properties: values, columns, rows.
1464+
* @param {number} numCols - The number of columns in the matrix.
1465+
* @returns {{rows: Float64Array, columns: Float64Array, values: Float64Array}} The matrix in CSC format.
1466+
*/
14611467
function csrToCsc(csrMatrix, numCols) {
14621468
const {
14631469
values: csrValues,
@@ -1492,20 +1498,31 @@ function csrToCsc(csrMatrix, numCols) {
14921498
return { rows: cscRowIndices, columns: cscColPtr, values: cscValues };
14931499
}
14941500

1501+
/**
1502+
* Converts a matrix from Coordinate (COO) format to Compressed Sparse Row (CSR) format.
1503+
* @param {Object} cooMatrix - The matrix in COO format with properties: values, columns, rows.
1504+
* @param {number} [nbRows=9] - The number of rows in the matrix.
1505+
* @returns {{rows: Float64Array, columns: Float64Array, values: Float64Array}} The matrix in CSR format.
1506+
*/
14951507
function cooToCsr(cooMatrix, nbRows = 9) {
14961508
const { values, columns, rows } = cooMatrix;
14971509
const csrRowPtr = new Float64Array(nbRows + 1);
14981510
const length = values.length;
14991511
let currentRow = rows[0];
15001512
for (let index = 0; index < length; ) {
1501-
const prev = index;
15021513
while (currentRow === rows[index] && index < length) ++index;
15031514
csrRowPtr[currentRow + 1] = index;
15041515
currentRow += 1;
15051516
}
15061517
return { rows: csrRowPtr, columns, values };
15071518
}
15081519

1520+
/**
1521+
* Creates an empty 2D matrix (array of Float64Array) with the given dimensions.
1522+
* @param {number} nbRows - Number of rows.
1523+
* @param {number} nbColumns - Number of columns.
1524+
* @returns {Float64Array[]} A 2D array representing the matrix.
1525+
*/
15091526
function matrixCreateEmpty(nbRows, nbColumns) {
15101527
const newMatrix = [];
15111528
for (let row = 0; row < nbRows; row++) {

0 commit comments

Comments
 (0)