Compare commits

...

3 Commits

Author SHA1 Message Date
ImperiumTakp
f85ea02d51
Merge 76ce702f9d into fb54d8b549 2023-05-22 17:39:47 -05:00
denon1
76ce702f9d fix remove nested tuple 2023-04-01 11:48:24 +02:00
denon1
dbb0a4b263 Change uses fold over foreach now 2023-04-01 11:43:44 +02:00

View File

@ -44,22 +44,17 @@ object EigenVectorsForSparseSymmetric {
* @return the constructed matrix * @return the constructed matrix
*/ */
def getMatrix(nonzeros: Iterable[(Int, Int, Double)], nRows: Int, nCols: Int): Matrix = { def getMatrix(nonzeros: Iterable[(Int, Int, Double)], nRows: Int, nCols: Int): Matrix = {
val matrix = new LinkedSparseMatrix(nRows, nCols) val baseCase = (new LinkedSparseMatrix(nRows, nCols), 0, 0, 0)
var numEntries = 0 val partialNonzeros = nonzeros.foldRight(baseCase)
var maxRow = 0 val (matrix, numEntries, maxRow, maxCol) = partialNonzeros{
var maxCol = 0 case ((i, j, v), (matrix, numEntries, maxRow, maxCol) ) => (i, j) match {
case (_, _) if (i > maxRow) && (j > maxCol) => (matrix.set(i, j, v), numEntries += 1, i, j)
nonzeros.foreach { case (_, _) if (i > maxRow) => (matrix.set(i, j, v), numEntries += 1, i, maxCol)
case (i, j, v) => case (_, _) if (j > maxCol) => (matrix.set(i, j, v), numEntries += 1, maxRow, j)
if (i > maxRow) { case (_, _) => (matrix.set(i, j, v), numEntries += 1, maxRow, maxCol)
maxRow = i }
}
if (j > maxCol) {
maxCol = j
}
numEntries += 1
matrix.set(i, j, v)
} }
log.info( log.info(
"Finished building matrix with %d entries and maxRow %d and maxCol %d" "Finished building matrix with %d entries and maxRow %d and maxCol %d"
.format(numEntries, maxRow, maxCol)) .format(numEntries, maxRow, maxCol))