@@ -1458,6 +1458,12 @@ SparseMatrix.prototype.klass = 'Matrix';
1458
1458
SparseMatrix . identity = SparseMatrix . eye ;
1459
1459
SparseMatrix . prototype . tensorProduct = SparseMatrix . prototype . kroneckerProduct ;
1460
1460
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
+ */
1461
1467
function csrToCsc ( csrMatrix , numCols ) {
1462
1468
const {
1463
1469
values : csrValues ,
@@ -1492,20 +1498,31 @@ function csrToCsc(csrMatrix, numCols) {
1492
1498
return { rows : cscRowIndices , columns : cscColPtr , values : cscValues } ;
1493
1499
}
1494
1500
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
+ */
1495
1507
function cooToCsr ( cooMatrix , nbRows = 9 ) {
1496
1508
const { values, columns, rows } = cooMatrix ;
1497
1509
const csrRowPtr = new Float64Array ( nbRows + 1 ) ;
1498
1510
const length = values . length ;
1499
1511
let currentRow = rows [ 0 ] ;
1500
1512
for ( let index = 0 ; index < length ; ) {
1501
- const prev = index ;
1502
1513
while ( currentRow === rows [ index ] && index < length ) ++ index ;
1503
1514
csrRowPtr [ currentRow + 1 ] = index ;
1504
1515
currentRow += 1 ;
1505
1516
}
1506
1517
return { rows : csrRowPtr , columns, values } ;
1507
1518
}
1508
1519
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
+ */
1509
1526
function matrixCreateEmpty ( nbRows , nbColumns ) {
1510
1527
const newMatrix = [ ] ;
1511
1528
for ( let row = 0 ; row < nbRows ; row ++ ) {
0 commit comments