From a71abe9e9d1a9c35cf84dabd3ebfd482a4d7214f Mon Sep 17 00:00:00 2001 From: dwarning Date: Thu, 15 Jun 2023 15:08:26 +0200 Subject: [PATCH] safe LoadGmin and code cleanup --- src/maths/sparse/spSMP.c | 49 ++++++++++++---------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/src/maths/sparse/spSMP.c b/src/maths/sparse/spSMP.c index ba044364f..26335a94a 100644 --- a/src/maths/sparse/spSMP.c +++ b/src/maths/sparse/spSMP.c @@ -480,16 +480,19 @@ register ArrayOfElementPtrs Diag; /* Begin `spLoadGmin'. */ ASSERT_IS_SPARSE( Matrix ); - Diag = Matrix->Diag; - for (I = Matrix->Size; I > 0; I--) - Diag[I]->Real += Gmin; + if (Gmin != 0.0) { + Diag = Matrix->Diag; + for (I = Matrix->Size; I > 0; I--) { + if ((diag = Diag[I]) != NULL) + diag->Real += Gmin; + } + } return; } - /* * FIND ELEMENT * @@ -499,27 +502,6 @@ register ArrayOfElementPtrs Diag; * pointer to the new element is returned. */ -//SMPelement * -//SMPfindElt( Matrix, Row, Col, CreateIfMissing ) -// -//SMPmatrix *Matrix; -//int Row, Col; -//int CreateIfMissing; -//{ -////MatrixPtr Matrix = (MatrixPtr)eMatrix; -//spREAL *Element = (spREAL *)Matrix->FirstInCol[Col]; -// -///* Begin `SMPfindElt'. */ -// ASSERT_IS_SPARSE( Matrix ); -// if (CreateIfMissing) -// { Element = spcCreateElement( Matrix, Row, Col, -// &Matrix->FirstInRow[Row], -// &Matrix->FirstInCol[Col], NO ); -// } -// else Element = spcFindElement( Matrix, Row, Col ); -// return (SMPelement *)Element; -//} - SMPelement * SMPfindElt(SMPmatrix *Matrix, int Row, int Col, int CreateIfMissing) { @@ -528,7 +510,6 @@ SMPfindElt(SMPmatrix *Matrix, int Row, int Col, int CreateIfMissing) /* Begin `SMPfindElt'. */ ASSERT_IS_SPARSE( Matrix ); Row = Matrix->ExtToIntRowMap[Row]; - Col = Matrix->ExtToIntColMap[Col]; if (Col == -1) @@ -597,6 +578,14 @@ SMPcAddCol(SMPmatrix *Matrix, int Accum_Col, int Addend_Col) return spErrorState( Matrix ); } +/* + * SMPconstMult() + */ +void +SMPconstMult(SMPmatrix *Matrix, double constant) +{ + spConstMult(Matrix, constant); +} /* * SMPmultiply() @@ -611,11 +600,3 @@ SMPmultiply(SMPmatrix *Matrix, double *RHS, double *Solution, double *iRHS, doub #endif } -/* - * SMPconstMult() - */ -void -SMPconstMult(SMPmatrix *Matrix, double constant) -{ - spConstMult(Matrix, constant); -}