From d8ea559c9215962e0370fd51832281a1f3877205 Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Sat, 2 Jul 2016 11:05:32 +0200 Subject: [PATCH] Ordered the COO format also along the columns to have a correct CSR format --- src/maths/KLU/klu_utils.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/maths/KLU/klu_utils.c b/src/maths/KLU/klu_utils.c index 80042f6b5..395bfa522 100644 --- a/src/maths/KLU/klu_utils.c +++ b/src/maths/KLU/klu_utils.c @@ -18,6 +18,18 @@ CompareRow (const void *a, const void *b) 0 ; } +static int +CompareColumn (const void *a, const void *b) +{ + Element *A = (Element *) a ; + Element *B = (Element *) b ; + + return + (A->col > B->col) ? 1 : + (A->col < B->col) ? -1 : + 0 ; +} + static void Compress (Int *Ai, Int *Bp, int num_rows, int n_COO) { @@ -117,6 +129,23 @@ KLU_convert_matrix_in_CSR /* return TRUE if successful, FALSE otherwise /* Order the MatrixCOO along the rows */ qsort (MatrixCOO, (size_t)nz, sizeof(Element), CompareRow) ; + /* Order the MatrixCOO along the columns */ + i = 0 ; + while (i < nz) + { + for (j = i + 1 ; j < nz ; j++) + { + if (MatrixCOO [j].row != MatrixCOO [i].row) + { + break ; + } + } + + qsort (MatrixCOO + i, (size_t)(j - i), sizeof(Element), CompareColumn) ; + + i = j ; + } + for (i = 0 ; i < nz ; i++) { Ap_COO [i] = MatrixCOO [i].row ;