From fdd815183af371e9dc65eaa93a0e34da052bf3e9 Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Sun, 5 Apr 2020 19:56:28 +0200 Subject: [PATCH] Fix SMPfindElement for KLU --- src/maths/KLU/klusmp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/maths/KLU/klusmp.c b/src/maths/KLU/klusmp.c index ff375393e..b1b3a7971 100644 --- a/src/maths/KLU/klusmp.c +++ b/src/maths/KLU/klusmp.c @@ -1462,8 +1462,14 @@ SMPfindElt (SMPmatrix *eMatrix, int Row, int Col, int CreateIfMissing) Row = Matrix->ExtToIntRowMap [Row] ; Col = Matrix->ExtToIntColMap [Col] ; - for (i = eMatrix->CKTkluAp [Col - 1] ; i < eMatrix->CKTkluAp [Col] ; i++) { - if (eMatrix->CKTkluAi [i] == Row - 1) { + Row = Row - 1 ; + Col = Col - 1 ; + if ((Row < 0) || (Col < 0)) { + printf ("Error: Cannot find an element with row '%d' and column '%d' in the KLU matrix\n", Row, Col) ; + return NULL ; + } + for (i = eMatrix->CKTkluAp [Col] ; i < eMatrix->CKTkluAp [Col + 1] ; i++) { + if (eMatrix->CKTkluAi [i] == Row) { if (eMatrix->CKTkluMatrixIsComplex == CKTkluMatrixReal) { return (SMPelement *) &(eMatrix->CKTkluAx [i]) ; } else if (eMatrix->CKTkluMatrixIsComplex == CKTkluMatrixComplex) {