Jspice3
spfactor.c File Reference
#include "spconfig.h"
#include "spmatrix.h"
#include "spdefs.h"
Include dependency graph for spfactor.c:

Go to the source code of this file.

Macros

#define spINSIDE_SPARSE
 
#define generic
 

Functions

static int FactorComplexMatrix ()
 
static void CountMarkowitz ()
 
static void MarkowitzProducts ()
 
static ElementPtr SearchForPivot ()
 
static ElementPtr SearchForSingleton ()
 
static ElementPtr QuicklySearchDiagonal ()
 
static ElementPtr SearchDiagonal ()
 
static ElementPtr SearchEntireMatrix ()
 
static RealNumber FindLargestInCol ()
 
static RealNumber FindBiggestInColExclude ()
 
static void ExchangeRowsAndCols ()
 
static void ExchangeColElements ()
 
static void ExchangeRowElements ()
 
static void RealRowColElimination ()
 
static void ComplexRowColElimination ()
 
static void UpdateMarkowitzNumbers ()
 
static ElementPtr CreateFillin ()
 
static int MatrixIsSingular ()
 
static int ZeroPivot ()
 
static void WriteStatus ()
 
int spOrderAndFactor (char *eMatrix, RHS, RelThreshold, AbsThreshold, BOOLEAN DiagPivoting)
 
int spFactor (char *eMatrix)
 
void spPartition (char *eMatrix, int Mode)
 
void spcCreateInternalVectors (MatrixPtr Matrix)
 
static void CountMarkowitz (MatrixPtr Matrix, RealVector RHS, int Step)
 
static void MarkowitzProducts (MatrixPtr Matrix, int Step)
 
static ElementPtr SearchForPivot (MatrixPtr Matrix, int Step, int DiagPivoting)
 
static ElementPtr SearchForSingleton (MatrixPtr Matrix, int Step)
 
static ElementPtr SearchEntireMatrix (MatrixPtr Matrix, int Step)
 
static RealNumber FindLargestInCol (MatrixPtr Matrix, ElementPtr pElement)
 
static RealNumber FindBiggestInColExclude (MatrixPtr Matrix, ElementPtr pElement, int Step)
 
static void ExchangeRowsAndCols (MatrixPtr Matrix, ElementPtr pPivot, int Step)
 
void spcRowExchange (MatrixPtr Matrix, int Row1, int Row2)
 
void spcColExchange (MatrixPtr Matrix, int Col1, int Col2)
 
static void ExchangeColElements (MatrixPtr Matrix, int Row1, ElementPtr Element1, int Row2, ElementPtr Element2, int Column)
 
static void ExchangeRowElements (MatrixPtr Matrix, int Col1, ElementPtr Element1, int Col2, ElementPtr Element2, int Row)
 
static void RealRowColElimination (MatrixPtr Matrix, ElementPtr pPivot)
 
static void ComplexRowColElimination (MatrixPtr Matrix, ElementPtr pPivot)
 
static void UpdateMarkowitzNumbers (MatrixPtr Matrix, ElementPtr pPivot)
 
static ElementPtr CreateFillin (MatrixPtr Matrix, int Row, int Col)
 
static int MatrixIsSingular (MatrixPtr Matrix, int Step)
 
static int ZeroPivot (MatrixPtr Matrix, int Step)
 
static void WriteStatus (MatrixPtr Matrix, int Step)
 

Macro Definition Documentation

#define generic
#define spINSIDE_SPARSE

Definition at line 68 of file spfactor.c.

Function Documentation

static void ComplexRowColElimination ( )
static
static void ComplexRowColElimination ( MatrixPtr  Matrix,
ElementPtr  pPivot 
)
static

Definition at line 2846 of file spfactor.c.

2850 {
2851 #if spCOMPLEX
2852 register ElementPtr pSub;
2853 register int Row;
2854 register ElementPtr pLower, pUpper;
2856 
2857 /* Begin `ComplexRowColElimination'. */
2858 
2859 /* Test for zero pivot. */
2860  if (ELEMENT_MAG(pPivot) == 0.0)
2861  { (void)MatrixIsSingular( Matrix, pPivot->Row );
2862  return;
2863  }
2864  CMPLX_RECIPROCAL(*pPivot, *pPivot);
2865 
2866  pUpper = pPivot->NextInRow;
2867  while (pUpper != NULL)
2868  {
2869 /* Calculate upper triangular element. */
2870 /* Cmplx expr: *pUpper = *pUpper * (1.0 / *pPivot). */
2871  CMPLX_MULT_ASSIGN(*pUpper, *pPivot);
2872 
2873  pSub = pUpper->NextInCol;
2874  pLower = pPivot->NextInCol;
2875  while (pLower != NULL)
2876  { Row = pLower->Row;
2877 
2878 /* Find element in row that lines up with current lower triangular element. */
2879  while (pSub != NULL AND pSub->Row < Row)
2880  pSub = pSub->NextInCol;
2881 
2882 /* Test to see if desired element was not found, if not, create fill-in. */
2883  if (pSub == NULL OR pSub->Row > Row)
2884  { pSub = CreateFillin( Matrix, Row, pUpper->Col );
2885  if (pSub == NULL)
2886  { Matrix->Error = spNO_MEMORY;
2887  return;
2888  }
2889  }
2890 
2891 /* Cmplx expr: pElement -= *pUpper * pLower. */
2892  CMPLX_MULT_SUBT_ASSIGN(*pSub, *pUpper, *pLower);
2893  pSub = pSub->NextInCol;
2894  pLower = pLower->NextInCol;
2895  }
2896  pUpper = pUpper->NextInRow;
2897  }
2898  return;
2899 #endif /* spCOMPLEX */
2900 }
#define CMPLX_MULT_ASSIGN(to, from)
Definition: spdefs.h:241
static int MatrixIsSingular()
#define ELEMENT_MAG(ptr)
Definition: spdefs.h:161
#define CMPLX_MULT_SUBT_ASSIGN(to, from_a, from_b)
Definition: spdefs.h:297
struct MatrixElement * NextInCol
Definition: spdefs.h:547
#define NULL
Definition: spdefs.h:121
#define OR
Definition: fteparse.h:93
int Error
Definition: spdefs.h:829
struct MatrixElement * NextInRow
Definition: spdefs.h:546
static ElementPtr CreateFillin()
#define spNO_MEMORY
Definition: spmatrix.h:105
#define CMPLX_RECIPROCAL(to, den)
Definition: spdefs.h:367
#define AND
Definition: fteparse.h:92
static void CountMarkowitz ( )
static
static void CountMarkowitz ( MatrixPtr  Matrix,
RealVector  RHS,
int  Step 
)
static

Definition at line 861 of file spfactor.c.

866 {
867 register int Count, I, Size = Matrix->Size;
868 register ElementPtr pElement;
869 int ExtRow;
870 
871 /* Begin `CountMarkowitz'. */
872 
873 /* Correct array pointer for ARRAY_OFFSET. */
874 #if NOT ARRAY_OFFSET
875 #if spSEPARATED_COMPLEX_VECTORS OR NOT spCOMPLEX
876  if (RHS != NULL) --RHS;
877 #else
878  if (RHS != NULL)
879  { if (Matrix->Complex) RHS -= 2;
880  else --RHS;
881  }
882 #endif
883 #endif
884 
885 /* Generate MarkowitzRow Count for each row. */
886  for (I = Step; I <= Size; I++)
887  {
888 /* Set Count to -1 initially to remove count due to pivot element. */
889  Count = -1;
890  pElement = Matrix->FirstInRow[I];
891  while (pElement != NULL AND pElement->Col < Step)
892  pElement = pElement->NextInRow;
893  while (pElement != NULL)
894  { Count++;
895  pElement = pElement->NextInRow;
896  }
897 
898 /* Include nonzero elements in the RHS vector. */
899  ExtRow = Matrix->IntToExtRowMap[I];
900 
901 #if spSEPARATED_COMPLEX_VECTORS OR NOT spCOMPLEX
902  if (RHS != NULL)
903  if (RHS[ExtRow] != 0.0) Count++;
904 #else
905  if (RHS != NULL)
906  { if (Matrix->Complex)
907  { if ((RHS[2*ExtRow] != 0.0) OR (RHS[2*ExtRow+1] != 0.0))
908  Count++;
909  }
910  else if (RHS[I] != 0.0) Count++;
911  }
912 #endif
913  Matrix->MarkowitzRow[I] = Count;
914  }
915 
916 /* Generate the MarkowitzCol count for each column. */
917  for (I = Step; I <= Size; I++)
918  {
919 /* Set Count to -1 initially to remove count due to pivot element. */
920  Count = -1;
921  pElement = Matrix->FirstInCol[I];
922  while (pElement != NULL AND pElement->Row < Step)
923  pElement = pElement->NextInCol;
924  while (pElement != NULL)
925  { Count++;
926  pElement = pElement->NextInCol;
927  }
928  Matrix->MarkowitzCol[I] = Count;
929  }
930  return;
931 }
int * MarkowitzRow
Definition: spdefs.h:842
int * MarkowitzCol
Definition: spdefs.h:843
ArrayOfElementPtrs FirstInRow
Definition: spdefs.h:836
int Size
Definition: spdefs.h:859
struct MatrixElement * NextInCol
Definition: spdefs.h:547
#define NULL
Definition: spdefs.h:121
#define OR
Definition: fteparse.h:93
register ElementPtr pElement
Definition: spsolve.c:158
register int Size
Definition: spsolve.c:163
int * IntToExtRowMap
Definition: spdefs.h:841
BOOLEAN Complex
Definition: spdefs.h:823
RealVector RHS
Definition: spsolve.c:157
struct MatrixElement * NextInRow
Definition: spdefs.h:546
register int I
Definition: spsolve.c:163
ArrayOfElementPtrs FirstInCol
Definition: spdefs.h:835
#define AND
Definition: fteparse.h:92
static ElementPtr CreateFillin ( )
static
static ElementPtr CreateFillin ( MatrixPtr  Matrix,
int  Row,
int  Col 
)
static

Definition at line 3018 of file spfactor.c.

3023 {
3024 register ElementPtr pElement, *ppElementAbove;
3026 
3027 /* Begin `CreateFillin'. */
3028 
3029 /* Find Element above fill-in. */
3030  ppElementAbove = &Matrix->FirstInCol[Col];
3031  pElement = *ppElementAbove;
3032  while (pElement != NULL)
3033  { if (pElement->Row < Row)
3034  { ppElementAbove = &pElement->NextInCol;
3035  pElement = *ppElementAbove;
3036  }
3037  else break; /* while loop */
3038  }
3039 
3040 /* End of search, create the element. */
3041  pElement = spcCreateElement( Matrix, Row, Col, ppElementAbove, YES );
3042 
3043 /* Update Markowitz counts and products. */
3044  Matrix->MarkowitzProd[Row] = ++Matrix->MarkowitzRow[Row] *
3045  Matrix->MarkowitzCol[Row];
3046  if ((Matrix->MarkowitzRow[Row] == 1) AND (Matrix->MarkowitzCol[Row] != 0))
3047  Matrix->Singletons--;
3048  Matrix->MarkowitzProd[Col] = ++Matrix->MarkowitzCol[Col] *
3049  Matrix->MarkowitzRow[Col];
3050  if ((Matrix->MarkowitzRow[Col] != 0) AND (Matrix->MarkowitzCol[Col] == 1))
3051  Matrix->Singletons--;
3052 
3053  return pElement;
3054 }
int * MarkowitzRow
Definition: spdefs.h:842
int * MarkowitzCol
Definition: spdefs.h:843
long * MarkowitzProd
Definition: spdefs.h:844
int Singletons
Definition: spdefs.h:858
struct MatrixElement * NextInCol
Definition: spdefs.h:547
ElementPtr spcCreateElement()
#define NULL
Definition: spdefs.h:121
register ElementPtr pElement
Definition: spsolve.c:158
#define YES
Definition: spdefs.h:114
ArrayOfElementPtrs FirstInCol
Definition: spdefs.h:835
#define AND
Definition: fteparse.h:92
static void ExchangeColElements ( )
static
static void ExchangeColElements ( MatrixPtr  Matrix,
int  Row1,
ElementPtr  Element1,
int  Row2,
ElementPtr  Element2,
int  Column 
)
static

Definition at line 2480 of file spfactor.c.

2485 {
2486 ElementPtr *ElementAboveRow1, *ElementAboveRow2;
2487 ElementPtr ElementBelowRow1, ElementBelowRow2;
2488 register ElementPtr pElement;
2489 
2490 /* Begin `ExchangeColElements'. */
2491 /* Search to find the ElementAboveRow1. */
2492  ElementAboveRow1 = &(Matrix->FirstInCol[Column]);
2493  pElement = *ElementAboveRow1;
2494  while (pElement->Row < Row1)
2495  { ElementAboveRow1 = &(pElement->NextInCol);
2496  pElement = *ElementAboveRow1;
2497  }
2498  if (Element1 != NULL)
2499  { ElementBelowRow1 = Element1->NextInCol;
2500  if (Element2 == NULL)
2501  {
2502 /* Element2 does not exist, move Element1 down to Row2. */
2503  if ( ElementBelowRow1 != NULL AND ElementBelowRow1->Row < Row2 )
2504  {
2505 /* Element1 must be removed from linked list and moved. */
2506  *ElementAboveRow1 = ElementBelowRow1;
2507 
2508 /* Search column for Row2. */
2509  pElement = ElementBelowRow1;
2510  do
2511  { ElementAboveRow2 = &(pElement->NextInCol);
2512  pElement = *ElementAboveRow2;
2513  } while (pElement != NULL AND pElement->Row < Row2);
2514 
2515 /* Place Element1 in Row2. */
2516  *ElementAboveRow2 = Element1;
2517  Element1->NextInCol = pElement;
2518  *ElementAboveRow1 =ElementBelowRow1;
2519  }
2520  Element1->Row = Row2;
2521  }
2522  else
2523  {
2524 /* Element2 does exist, and the two elements must be exchanged. */
2525  if ( ElementBelowRow1->Row == Row2)
2526  {
2527 /* Element2 is just below Element1, exchange them. */
2528  Element1->NextInCol = Element2->NextInCol;
2529  Element2->NextInCol = Element1;
2530  *ElementAboveRow1 = Element2;
2531  }
2532  else
2533  {
2534 /* Element2 is not just below Element1 and must be searched for. */
2535  pElement = ElementBelowRow1;
2536  do
2537  { ElementAboveRow2 = &(pElement->NextInCol);
2538  pElement = *ElementAboveRow2;
2539  } while (pElement->Row < Row2);
2540 
2541  ElementBelowRow2 = Element2->NextInCol;
2542 
2543 /* Switch Element1 and Element2. */
2544  *ElementAboveRow1 = Element2;
2545  Element2->NextInCol = ElementBelowRow1;
2546  *ElementAboveRow2 = Element1;
2547  Element1->NextInCol = ElementBelowRow2;
2548  }
2549  Element1->Row = Row2;
2550  Element2->Row = Row1;
2551  }
2552  }
2553  else
2554  {
2555 /* Element1 does not exist. */
2556  ElementBelowRow1 = pElement;
2557 
2558 /* Find Element2. */
2559  if (ElementBelowRow1->Row != Row2)
2560  { do
2561  { ElementAboveRow2 = &(pElement->NextInCol);
2562  pElement = *ElementAboveRow2;
2563  } while (pElement->Row < Row2);
2564 
2565  ElementBelowRow2 = Element2->NextInCol;
2566 
2567 /* Move Element2 to Row1. */
2568  *ElementAboveRow2 = Element2->NextInCol;
2569  *ElementAboveRow1 = Element2;
2570  Element2->NextInCol = ElementBelowRow1;
2571  }
2572  Element2->Row = Row1;
2573  }
2574  return;
2575 }
struct MatrixElement * NextInCol
Definition: spdefs.h:547
#define NULL
Definition: spdefs.h:121
register ElementPtr pElement
Definition: spsolve.c:158
ArrayOfElementPtrs FirstInCol
Definition: spdefs.h:835
#define AND
Definition: fteparse.h:92
static void ExchangeRowElements ( )
static
static void ExchangeRowElements ( MatrixPtr  Matrix,
int  Col1,
ElementPtr  Element1,
int  Col2,
ElementPtr  Element2,
int  Row 
)
static

Definition at line 2622 of file spfactor.c.

2627 {
2628 ElementPtr *ElementLeftOfCol1, *ElementLeftOfCol2;
2629 ElementPtr ElementRightOfCol1, ElementRightOfCol2;
2630 register ElementPtr pElement;
2631 
2632 /* Begin `ExchangeRowElements'. */
2633 /* Search to find the ElementLeftOfCol1. */
2634  ElementLeftOfCol1 = &(Matrix->FirstInRow[Row]);
2635  pElement = *ElementLeftOfCol1;
2636  while (pElement->Col < Col1)
2637  { ElementLeftOfCol1 = &(pElement->NextInRow);
2638  pElement = *ElementLeftOfCol1;
2639  }
2640  if (Element1 != NULL)
2641  { ElementRightOfCol1 = Element1->NextInRow;
2642  if (Element2 == NULL)
2643  {
2644 /* Element2 does not exist, move Element1 to right to Col2. */
2645  if ( ElementRightOfCol1 != NULL AND ElementRightOfCol1->Col < Col2 )
2646  {
2647 /* Element1 must be removed from linked list and moved. */
2648  *ElementLeftOfCol1 = ElementRightOfCol1;
2649 
2650 /* Search Row for Col2. */
2651  pElement = ElementRightOfCol1;
2652  do
2653  { ElementLeftOfCol2 = &(pElement->NextInRow);
2654  pElement = *ElementLeftOfCol2;
2655  } while (pElement != NULL AND pElement->Col < Col2);
2656 
2657 /* Place Element1 in Col2. */
2658  *ElementLeftOfCol2 = Element1;
2659  Element1->NextInRow = pElement;
2660  *ElementLeftOfCol1 =ElementRightOfCol1;
2661  }
2662  Element1->Col = Col2;
2663  }
2664  else
2665  {
2666 /* Element2 does exist, and the two elements must be exchanged. */
2667  if ( ElementRightOfCol1->Col == Col2)
2668  {
2669 /* Element2 is just right of Element1, exchange them. */
2670  Element1->NextInRow = Element2->NextInRow;
2671  Element2->NextInRow = Element1;
2672  *ElementLeftOfCol1 = Element2;
2673  }
2674  else
2675  {
2676 /* Element2 is not just right of Element1 and must be searched for. */
2677  pElement = ElementRightOfCol1;
2678  do
2679  { ElementLeftOfCol2 = &(pElement->NextInRow);
2680  pElement = *ElementLeftOfCol2;
2681  } while (pElement->Col < Col2);
2682 
2683  ElementRightOfCol2 = Element2->NextInRow;
2684 
2685 /* Switch Element1 and Element2. */
2686  *ElementLeftOfCol1 = Element2;
2687  Element2->NextInRow = ElementRightOfCol1;
2688  *ElementLeftOfCol2 = Element1;
2689  Element1->NextInRow = ElementRightOfCol2;
2690  }
2691  Element1->Col = Col2;
2692  Element2->Col = Col1;
2693  }
2694  }
2695  else
2696  {
2697 /* Element1 does not exist. */
2698  ElementRightOfCol1 = pElement;
2699 
2700 /* Find Element2. */
2701  if (ElementRightOfCol1->Col != Col2)
2702  { do
2703  { ElementLeftOfCol2 = &(pElement->NextInRow);
2704  pElement = *ElementLeftOfCol2;
2705  } while (pElement->Col < Col2);
2706 
2707  ElementRightOfCol2 = Element2->NextInRow;
2708 
2709 /* Move Element2 to Col1. */
2710  *ElementLeftOfCol2 = Element2->NextInRow;
2711  *ElementLeftOfCol1 = Element2;
2712  Element2->NextInRow = ElementRightOfCol1;
2713  }
2714  Element2->Col = Col1;
2715  }
2716  return;
2717 }
ArrayOfElementPtrs FirstInRow
Definition: spdefs.h:836
#define NULL
Definition: spdefs.h:121
register ElementPtr pElement
Definition: spsolve.c:158
struct MatrixElement * NextInRow
Definition: spdefs.h:546
#define AND
Definition: fteparse.h:92
static void ExchangeRowsAndCols ( )
static
static void ExchangeRowsAndCols ( MatrixPtr  Matrix,
ElementPtr  pPivot,
int  Step 
)
static

Definition at line 2141 of file spfactor.c.

2146 {
2147 register int Row, Col;
2148 long OldMarkowitzProd_Step, OldMarkowitzProd_Row, OldMarkowitzProd_Col;
2150 
2151 /* Begin `ExchangeRowsAndCols'. */
2152  Row = pPivot->Row;
2153  Col = pPivot->Col;
2154  Matrix->PivotsOriginalRow = Row;
2155  Matrix->PivotsOriginalCol = Col;
2156 
2157  if ((Row == Step) AND (Col == Step)) return;
2158 
2159 /* Exchange rows and columns. */
2160  if (Row == Col)
2161  { spcRowExchange( Matrix, Step, Row );
2162  spcColExchange( Matrix, Step, Col );
2163  SWAP( long, Matrix->MarkowitzProd[Step], Matrix->MarkowitzProd[Row] );
2164  SWAP( ElementPtr, Matrix->Diag[Row], Matrix->Diag[Step] );
2165  }
2166  else
2167  {
2168 
2169 /* Initialize variables that hold old Markowitz products. */
2170  OldMarkowitzProd_Step = Matrix->MarkowitzProd[Step];
2171  OldMarkowitzProd_Row = Matrix->MarkowitzProd[Row];
2172  OldMarkowitzProd_Col = Matrix->MarkowitzProd[Col];
2173 
2174 /* Exchange rows. */
2175  if (Row != Step)
2176  { spcRowExchange( Matrix, Step, Row );
2177  Matrix->NumberOfInterchangesIsOdd =
2179  Matrix->MarkowitzProd[Row] = Matrix->MarkowitzRow[Row] *
2180  Matrix->MarkowitzCol[Row];
2181 
2182 /* Update singleton count. */
2183  if ((Matrix->MarkowitzProd[Row]==0) != (OldMarkowitzProd_Row==0))
2184  { if (OldMarkowitzProd_Row == 0)
2185  Matrix->Singletons--;
2186  else
2187  Matrix->Singletons++;
2188  }
2189  }
2190 
2191 /* Exchange columns. */
2192  if (Col != Step)
2193  { spcColExchange( Matrix, Step, Col );
2194  Matrix->NumberOfInterchangesIsOdd =
2196  Matrix->MarkowitzProd[Col] = Matrix->MarkowitzCol[Col] *
2197  Matrix->MarkowitzRow[Col];
2198 
2199 /* Update singleton count. */
2200  if ((Matrix->MarkowitzProd[Col]==0) != (OldMarkowitzProd_Col==0))
2201  { if (OldMarkowitzProd_Col == 0)
2202  Matrix->Singletons--;
2203  else
2204  Matrix->Singletons++;
2205  }
2206 
2207  Matrix->Diag[Col] = spcFindElementInCol( Matrix,
2208  Matrix->FirstInCol+Col,
2209  Col, Col, NO );
2210  }
2211  if (Row != Step)
2212  { Matrix->Diag[Row] = spcFindElementInCol( Matrix,
2213  Matrix->FirstInCol+Row,
2214  Row, Row, NO );
2215  }
2216  Matrix->Diag[Step] = spcFindElementInCol( Matrix,
2217  Matrix->FirstInCol+Step,
2218  Step, Step, NO );
2219 
2220 /* Update singleton count. */
2221  Matrix->MarkowitzProd[Step] = Matrix->MarkowitzCol[Step] *
2222  Matrix->MarkowitzRow[Step];
2223  if ((Matrix->MarkowitzProd[Step]==0) != (OldMarkowitzProd_Step==0))
2224  { if (OldMarkowitzProd_Step == 0)
2225  Matrix->Singletons--;
2226  else
2227  Matrix->Singletons++;
2228  }
2229  }
2230  return;
2231 }
void spcRowExchange(MatrixPtr Matrix, int Row1, int Row2)
Definition: spfactor.c:2271
int * MarkowitzRow
Definition: spdefs.h:842
int * MarkowitzCol
Definition: spdefs.h:843
#define NO
Definition: spdefs.h:113
int PivotsOriginalRow
Definition: spdefs.h:850
void spcColExchange(MatrixPtr Matrix, int Col1, int Col2)
Definition: spfactor.c:2373
long * MarkowitzProd
Definition: spdefs.h:844
BOOLEAN NumberOfInterchangesIsOdd
Definition: spdefs.h:847
int Singletons
Definition: spdefs.h:858
int PivotsOriginalCol
Definition: spdefs.h:849
ElementPtr spcFindElementInCol()
#define SWAP(type, a, b)
Definition: spdefs.h:145
ArrayOfElementPtrs Diag
Definition: spdefs.h:825
#define NOT
Definition: fteparse.h:94
ArrayOfElementPtrs FirstInCol
Definition: spdefs.h:835
#define AND
Definition: fteparse.h:92
static int FactorComplexMatrix ( )
static
static RealNumber FindBiggestInColExclude ( )
static
static RealNumber FindBiggestInColExclude ( MatrixPtr  Matrix,
ElementPtr  pElement,
int  Step 
)
static

Definition at line 2064 of file spfactor.c.

2069 {
2070 register int Row;
2071 int Col;
2072 RealNumber Largest, Magnitude;
2073 
2074 /* Begin `FindBiggestInColExclude'. */
2075  Row = pElement->Row;
2076  Col = pElement->Col;
2077  pElement = Matrix->FirstInCol[Col];
2078 
2079 /* Travel down column until reduced submatrix is entered. */
2080  while ((pElement != NULL) AND (pElement->Row < Step))
2081  pElement = pElement->NextInCol;
2082 
2083 /* Initialize the variable Largest. */
2084  if (pElement->Row != Row)
2085  Largest = ELEMENT_MAG(pElement);
2086  else
2087  Largest = 0.0;
2088 
2089 /* Search rest of column for largest element, avoiding excluded element. */
2090  while ((pElement = pElement->NextInCol) != NULL)
2091  { if ((Magnitude = ELEMENT_MAG(pElement)) > Largest)
2092  { if (pElement->Row != Row)
2093  Largest = Magnitude;
2094  }
2095  }
2096 
2097  return Largest;
2098 }
#define ELEMENT_MAG(ptr)
Definition: spdefs.h:161
struct MatrixElement * NextInCol
Definition: spdefs.h:547
#define NULL
Definition: spdefs.h:121
spREAL RealNumber
Definition: spdefs.h:458
ArrayOfElementPtrs FirstInCol
Definition: spdefs.h:835
#define AND
Definition: fteparse.h:92
static RealNumber FindLargestInCol ( )
static
static RealNumber FindLargestInCol ( MatrixPtr  Matrix,
ElementPtr  pElement 
)
static

Definition at line 1997 of file spfactor.c.

2001 {
2002 RealNumber Magnitude, Largest = 0.0;
2003 
2004 /* Begin `FindLargestInCol'. */
2005 /* Search column for largest element beginning at Element. */
2006  while (pElement != NULL)
2007  { if ((Magnitude = ELEMENT_MAG(pElement)) > Largest)
2008  Largest = Magnitude;
2009  pElement = pElement->NextInCol;
2010  }
2011 
2012  return Largest;
2013 }
#define ELEMENT_MAG(ptr)
Definition: spdefs.h:161
struct MatrixElement * NextInCol
Definition: spdefs.h:547
#define NULL
Definition: spdefs.h:121
spREAL RealNumber
Definition: spdefs.h:458
static void MarkowitzProducts ( )
static
static void MarkowitzProducts ( MatrixPtr  Matrix,
int  Step 
)
static

Definition at line 971 of file spfactor.c.

975 {
976 register int I, *pMarkowitzRow, *pMarkowitzCol;
977 register long Product, *pMarkowitzProduct;
978 register int Size = Matrix->Size;
979 double fProduct;
980 
981 /* Begin `MarkowitzProducts'. */
982  Matrix->Singletons = 0;
983 
984  pMarkowitzProduct = &(Matrix->MarkowitzProd[Step]);
985  pMarkowitzRow = &(Matrix->MarkowitzRow[Step]);
986  pMarkowitzCol = &(Matrix->MarkowitzCol[Step]);
987 
988  for (I = Step; I <= Size; I++)
989  {
990 /* If chance of overflow, use real numbers. */
991  if ((*pMarkowitzRow > LARGEST_SHORT_INTEGER AND *pMarkowitzCol != 0) OR
992  (*pMarkowitzCol > LARGEST_SHORT_INTEGER AND *pMarkowitzRow != 0))
993  { fProduct = (double)(*pMarkowitzRow++) * (double)(*pMarkowitzCol++);
994  if (fProduct >= LARGEST_LONG_INTEGER)
995  *pMarkowitzProduct++ = LARGEST_LONG_INTEGER;
996  else
997  *pMarkowitzProduct++ = fProduct;
998  }
999  else
1000  { Product = *pMarkowitzRow++ * *pMarkowitzCol++;
1001  if ((*pMarkowitzProduct++ = Product) == 0)
1002  Matrix->Singletons++;
1003  }
1004  }
1005  return;
1006 }
int * MarkowitzRow
Definition: spdefs.h:842
int * MarkowitzCol
Definition: spdefs.h:843
int Size
Definition: spdefs.h:859
long * MarkowitzProd
Definition: spdefs.h:844
int Singletons
Definition: spdefs.h:858
#define OR
Definition: fteparse.h:93
register int Size
Definition: spsolve.c:163
register int I
Definition: spsolve.c:163
#define AND
Definition: fteparse.h:92
static int MatrixIsSingular ( )
static
static int MatrixIsSingular ( MatrixPtr  Matrix,
int  Step 
)
static

Definition at line 3080 of file spfactor.c.

3084 {
3085 /* Begin `MatrixIsSingular'. */
3086 
3087  Matrix->SingularRow = Matrix->IntToExtRowMap[ Step ];
3088  Matrix->SingularCol = Matrix->IntToExtColMap[ Step ];
3089  return (Matrix->Error = spSINGULAR);
3090 }
int SingularCol
Definition: spdefs.h:856
int SingularRow
Definition: spdefs.h:857
#define spSINGULAR
Definition: spmatrix.h:104
int * IntToExtColMap
Definition: spdefs.h:840
int * IntToExtRowMap
Definition: spdefs.h:841
int Error
Definition: spdefs.h:829
static ElementPtr QuicklySearchDiagonal ( )
static
static void RealRowColElimination ( )
static
static void RealRowColElimination ( MatrixPtr  Matrix,
ElementPtr  pPivot 
)
static

Definition at line 2757 of file spfactor.c.

2761 {
2762 #if REAL
2763 register ElementPtr pSub;
2764 register int Row;
2765 register ElementPtr pLower, pUpper;
2766 extern ElementPtr CreateFillin();
2767 
2768 /* Begin `RealRowColElimination'. */
2769 
2770 /* Test for zero pivot. */
2771  if (ABS(pPivot->Real) == 0.0)
2772  { (void)MatrixIsSingular( Matrix, pPivot->Row );
2773  return;
2774  }
2775  pPivot->Real = 1.0 / pPivot->Real;
2776 
2777  pUpper = pPivot->NextInRow;
2778  while (pUpper != NULL)
2779  {
2780 /* Calculate upper triangular element. */
2781  pUpper->Real *= pPivot->Real;
2782 
2783  pSub = pUpper->NextInCol;
2784  pLower = pPivot->NextInCol;
2785  while (pLower != NULL)
2786  { Row = pLower->Row;
2787 
2788 /* Find element in row that lines up with current lower triangular element. */
2789  while (pSub != NULL AND pSub->Row < Row)
2790  pSub = pSub->NextInCol;
2791 
2792 /* Test to see if desired element was not found, if not, create fill-in. */
2793  if (pSub == NULL OR pSub->Row > Row)
2794  { pSub = CreateFillin( Matrix, Row, pUpper->Col );
2795  if (pSub == NULL)
2796  { Matrix->Error = spNO_MEMORY;
2797  return;
2798  }
2799  }
2800  pSub->Real -= pUpper->Real * pLower->Real;
2801  pSub = pSub->NextInCol;
2802  pLower = pLower->NextInCol;
2803  }
2804  pUpper = pUpper->NextInRow;
2805  }
2806  return;
2807 #endif /* REAL */
2808 }
RealNumber Real
Definition: spdefs.h:539
static int MatrixIsSingular()
struct MatrixElement * NextInCol
Definition: spdefs.h:547
#define NULL
Definition: spdefs.h:121
#define OR
Definition: fteparse.h:93
#define ABS(a)
Definition: spdefs.h:139
int Error
Definition: spdefs.h:829
struct MatrixElement * NextInRow
Definition: spdefs.h:546
static ElementPtr CreateFillin()
#define spNO_MEMORY
Definition: spmatrix.h:105
#define AND
Definition: fteparse.h:92
static ElementPtr SearchDiagonal ( )
static
static ElementPtr SearchEntireMatrix ( )
static
static ElementPtr SearchEntireMatrix ( MatrixPtr  Matrix,
int  Step 
)
static

Definition at line 1874 of file spfactor.c.

1878 {
1879 register int I, Size = Matrix->Size;
1880 register ElementPtr pElement;
1881 int NumberOfTies;
1882 long Product, MinMarkowitzProduct;
1883 ElementPtr ChosenPivot, pLargestElement;
1884 RealNumber Magnitude, LargestElementMag, Ratio, RatioOfAccepted, LargestInCol;
1886 
1887 /* Begin `SearchEntireMatrix'. */
1888  ChosenPivot = NULL;
1889  LargestElementMag = 0.0;
1890  MinMarkowitzProduct = LARGEST_LONG_INTEGER;
1891 
1892 /* Start search of matrix on column by column basis. */
1893  for (I = Step; I <= Size; I++)
1894  { pElement = Matrix->FirstInCol[I];
1895 
1896  while (pElement != NULL AND pElement->Row < Step)
1897  pElement = pElement->NextInCol;
1898 
1899  if((LargestInCol = FindLargestInCol(Matrix,pElement)) == 0.0)
1900  continue; /* for loop */
1901 
1902  while (pElement != NULL)
1903  {
1904 /* Check to see if element is the largest encountered so far. If so, record
1905  its magnitude and address. */
1906  if ((Magnitude = ELEMENT_MAG(pElement)) > LargestElementMag)
1907  { LargestElementMag = Magnitude;
1908  pLargestElement = pElement;
1909  }
1910 /* Calculate element's MarkowitzProduct. */
1911  Product = Matrix->MarkowitzRow[pElement->Row] *
1912  Matrix->MarkowitzCol[pElement->Col];
1913 
1914 /* Test to see if element is acceptable as a pivot candidate. */
1915  if ((Product <= MinMarkowitzProduct) AND
1916  (Magnitude > Matrix->RelThreshold * LargestInCol) AND
1917  (Magnitude > Matrix->AbsThreshold))
1918  {
1919 /* Test to see if element has lowest MarkowitzProduct yet found, or whether it
1920  is tied with an element found earlier. */
1921  if (Product < MinMarkowitzProduct)
1922  {
1923 /* Notice strict inequality in test. This is a new smallest MarkowitzProduct. */
1924  ChosenPivot = pElement;
1925  MinMarkowitzProduct = Product;
1926  RatioOfAccepted = LargestInCol / Magnitude;
1927  NumberOfTies = 0;
1928  }
1929  else
1930  {
1931 /* This case handles Markowitz ties. */
1932  NumberOfTies++;
1933  Ratio = LargestInCol / Magnitude;
1934  if (Ratio < RatioOfAccepted)
1935  { ChosenPivot = pElement;
1936  RatioOfAccepted = Ratio;
1937  }
1938  if (NumberOfTies >= MinMarkowitzProduct * TIES_MULTIPLIER)
1939  return ChosenPivot;
1940  }
1941  }
1942  pElement = pElement->NextInCol;
1943  } /* End of while(pElement != NULL) */
1944  } /* End of for(Step) */
1945 
1946  if (ChosenPivot != NULL) return ChosenPivot;
1947 
1948  if (LargestElementMag == 0.0)
1949  { Matrix->Error = spSINGULAR;
1950  return NULL;
1951  }
1952 
1953  Matrix->Error = spSMALL_PIVOT;
1954  return pLargestElement;
1955 }
RealNumber RelThreshold
Definition: spdefs.h:853
int * MarkowitzRow
Definition: spdefs.h:842
int * MarkowitzCol
Definition: spdefs.h:843
int Size
Definition: spdefs.h:859
static RealNumber FindLargestInCol()
#define spSINGULAR
Definition: spmatrix.h:104
#define ELEMENT_MAG(ptr)
Definition: spdefs.h:161
struct MatrixElement * NextInCol
Definition: spdefs.h:547
#define spSMALL_PIVOT
Definition: spmatrix.h:102
RealNumber AbsThreshold
Definition: spdefs.h:820
#define NULL
Definition: spdefs.h:121
register ElementPtr pElement
Definition: spsolve.c:158
register int Size
Definition: spsolve.c:163
int Error
Definition: spdefs.h:829
spREAL RealNumber
Definition: spdefs.h:458
register int I
Definition: spsolve.c:163
ArrayOfElementPtrs FirstInCol
Definition: spdefs.h:835
#define AND
Definition: fteparse.h:92
static ElementPtr SearchForPivot ( )
static
static ElementPtr SearchForPivot ( MatrixPtr  Matrix,
int  Step,
int  DiagPivoting 
)
static

Definition at line 1058 of file spfactor.c.

1062 {
1063 register ElementPtr ChosenPivot;
1068 
1069 /* Begin `SearchForPivot'. */
1070 
1071 /* If singletons exist, look for an acceptable one to use as pivot. */
1072  if (Matrix->Singletons)
1073  { ChosenPivot = SearchForSingleton( Matrix, Step );
1074  if (ChosenPivot != NULL)
1075  { Matrix->PivotSelectionMethod = 's';
1076  return ChosenPivot;
1077  }
1078  }
1079 
1080 #if DIAGONAL_PIVOTING
1081  if (DiagPivoting)
1082  {
1083 /*
1084  * Either no singletons exist or they weren't acceptable. Take quick first
1085  * pass at searching diagonal. First search for element on diagonal of
1086  * remaining submatrix with smallest Markowitz product, then check to see
1087  * if it okay numerically. If not, QuicklySearchDiagonal fails.
1088  */
1089  ChosenPivot = QuicklySearchDiagonal( Matrix, Step );
1090  if (ChosenPivot != NULL)
1091  { Matrix->PivotSelectionMethod = 'q';
1092  return ChosenPivot;
1093  }
1094 
1095 /*
1096  * Quick search of diagonal failed, carefully search diagonal and check each
1097  * pivot candidate numerically before even tentatively accepting it.
1098  */
1099  ChosenPivot = SearchDiagonal( Matrix, Step );
1100  if (ChosenPivot != NULL)
1101  { Matrix->PivotSelectionMethod = 'd';
1102  return ChosenPivot;
1103  }
1104  }
1105 #endif /* DIAGONAL_PIVOTING */
1106 
1107 /* No acceptable pivot found yet, search entire matrix. */
1108  ChosenPivot = SearchEntireMatrix( Matrix, Step );
1109  Matrix->PivotSelectionMethod = 'e';
1110 
1111  return ChosenPivot;
1112 }
char PivotSelectionMethod
Definition: spdefs.h:851
int Singletons
Definition: spdefs.h:858
static ElementPtr SearchEntireMatrix()
static ElementPtr SearchDiagonal()
#define NULL
Definition: spdefs.h:121
static ElementPtr SearchForSingleton()
static ElementPtr QuicklySearchDiagonal()
static ElementPtr SearchForSingleton ( )
static
static ElementPtr SearchForSingleton ( MatrixPtr  Matrix,
int  Step 
)
static

Definition at line 1159 of file spfactor.c.

1163 {
1164 register ElementPtr ChosenPivot;
1165 register int I;
1166 register long *pMarkowitzProduct;
1167 int Singletons;
1169 
1170 /* Begin `SearchForSingleton'. */
1171 /* Initialize pointer that is to scan through MarkowitzProduct vector. */
1172  pMarkowitzProduct = &(Matrix->MarkowitzProd[Matrix->Size+1]);
1173  Matrix->MarkowitzProd[Matrix->Size+1] = Matrix->MarkowitzProd[Step];
1174 
1175 /* Decrement the count of available singletons, on the assumption that an
1176  * acceptable one will be found. */
1177  Singletons = Matrix->Singletons--;
1178 
1179 /*
1180  * Assure that following while loop will always terminate, this is just
1181  * preventive medicine, if things are working right this should never
1182  * be needed.
1183  */
1184  Matrix->MarkowitzProd[Step-1] = 0;
1185 
1186  while (Singletons-- > 0)
1187  {
1188 /* Singletons exist, find them. */
1189 
1190 /*
1191  * This is tricky. Am using a pointer to sequentially step through the
1192  * MarkowitzProduct array. Search terminates when singleton (Product = 0)
1193  * is found. Note that the conditional in the while statement
1194  * ( *pMarkowitzProduct ) is true as long as the MarkowitzProduct is not
1195  * equal to zero. The row (and column) index on the diagonal is then
1196  * calculated by subtracting the pointer to the Markowitz product of
1197  * the first diagonal from the pointer to the Markowitz product of the
1198  * desired element, the singleton.
1199  *
1200  * Search proceeds from the end (high row and column numbers) to the
1201  * beginning (low row and column numbers) so that rows and columns with
1202  * large Markowitz products will tend to be move to the bottom of the
1203  * matrix. However, choosing Diag[Step] is desirable because it would
1204  * require no row and column interchanges, so inspect it first by
1205  * putting its Markowitz product at the end of the MarkowitzProd
1206  * vector.
1207  */
1208 
1209  while ( *pMarkowitzProduct-- )
1210  { /*
1211  * N bottles of beer on the wall;
1212  * N bottles of beer.
1213  * you take one down and pass it around;
1214  * N-1 bottles of beer on the wall.
1215  */
1216  }
1217  I = pMarkowitzProduct - Matrix->MarkowitzProd + 1;
1218 
1219 /* Assure that I is valid. */
1220  if (I < Step) break; /* while (Singletons-- > 0) */
1221  if (I > Matrix->Size) I = Step;
1222 
1223 /* Singleton has been found in either/both row or/and column I. */
1224  if ((ChosenPivot = Matrix->Diag[I]) != NULL)
1225  {
1226 /* Singleton lies on the diagonal. */
1227  PivotMag = ELEMENT_MAG(ChosenPivot);
1228  if
1229  ( PivotMag > Matrix->AbsThreshold AND
1230  PivotMag > Matrix->RelThreshold *
1231  FindBiggestInColExclude( Matrix, ChosenPivot, Step )
1232  ) return ChosenPivot;
1233  }
1234  else
1235  {
1236 /* Singleton does not lie on diagonal, find it. */
1237  if (Matrix->MarkowitzCol[I] == 0)
1238  { ChosenPivot = Matrix->FirstInCol[I];
1239  while ((ChosenPivot != NULL) AND (ChosenPivot->Row < Step))
1240  ChosenPivot = ChosenPivot->NextInCol;
1241  if (ChosenPivot != NULL)
1242  { /* Reduced column has no elements, matrix is singular. */
1243  break;
1244  }
1245  PivotMag = ELEMENT_MAG(ChosenPivot);
1246  if
1247  ( PivotMag > Matrix->AbsThreshold AND
1248  PivotMag > Matrix->RelThreshold *
1249  FindBiggestInColExclude( Matrix, ChosenPivot,
1250  Step )
1251  ) return ChosenPivot;
1252  else
1253  { if (Matrix->MarkowitzRow[I] == 0)
1254  { ChosenPivot = Matrix->FirstInRow[I];
1255  while((ChosenPivot != NULL) AND (ChosenPivot->Col<Step))
1256  ChosenPivot = ChosenPivot->NextInRow;
1257  if (ChosenPivot != NULL)
1258  { /* Reduced row has no elements, matrix is singular. */
1259  break;
1260  }
1261  PivotMag = ELEMENT_MAG(ChosenPivot);
1262  if
1263  ( PivotMag > Matrix->AbsThreshold AND
1264  PivotMag > Matrix->RelThreshold *
1265  FindBiggestInColExclude( Matrix,
1266  ChosenPivot,
1267  Step )
1268  ) return ChosenPivot;
1269  }
1270  }
1271  }
1272  else
1273  { ChosenPivot = Matrix->FirstInRow[I];
1274  while ((ChosenPivot != NULL) AND (ChosenPivot->Col < Step))
1275  ChosenPivot = ChosenPivot->NextInRow;
1276  if (ChosenPivot != NULL)
1277  { /* Reduced row has no elements, matrix is singular. */
1278  break;
1279  }
1280  PivotMag = ELEMENT_MAG(ChosenPivot);
1281  if
1282  ( PivotMag > Matrix->AbsThreshold AND
1283  PivotMag > Matrix->RelThreshold *
1284  FindBiggestInColExclude( Matrix, ChosenPivot,
1285  Step )
1286  ) return ChosenPivot;
1287  }
1288  }
1289 /* Singleton not acceptable (too small), try another. */
1290  } /* end of while(lSingletons>0) */
1291 
1292 /*
1293  * All singletons were unacceptable. Restore Matrix->Singletons count.
1294  * Initial assumption that an acceptable singleton would be found was wrong.
1295  */
1296  Matrix->Singletons++;
1297  return NULL;
1298 }
static RealNumber FindBiggestInColExclude()
RealNumber RelThreshold
Definition: spdefs.h:853
int * MarkowitzRow
Definition: spdefs.h:842
int * MarkowitzCol
Definition: spdefs.h:843
ArrayOfElementPtrs FirstInRow
Definition: spdefs.h:836
int Size
Definition: spdefs.h:859
long * MarkowitzProd
Definition: spdefs.h:844
int Singletons
Definition: spdefs.h:858
#define ELEMENT_MAG(ptr)
Definition: spdefs.h:161
struct MatrixElement * NextInCol
Definition: spdefs.h:547
RealNumber AbsThreshold
Definition: spdefs.h:820
#define NULL
Definition: spdefs.h:121
spREAL RealNumber
Definition: spdefs.h:458
struct MatrixElement * NextInRow
Definition: spdefs.h:546
ArrayOfElementPtrs Diag
Definition: spdefs.h:825
register int I
Definition: spsolve.c:163
ArrayOfElementPtrs FirstInCol
Definition: spdefs.h:835
#define AND
Definition: fteparse.h:92
void spcColExchange ( MatrixPtr  Matrix,
int  Col1,
int  Col2 
)

Definition at line 2373 of file spfactor.c.

2377 {
2378 register ElementPtr Col1Ptr, Col2Ptr;
2379 int Row;
2380 ElementPtr Element1, Element2;
2381 
2382 /* Begin `spcColExchange'. */
2383  if (Col1 > Col2) SWAP(int, Col1, Col2);
2384 
2385  Col1Ptr = Matrix->FirstInCol[Col1];
2386  Col2Ptr = Matrix->FirstInCol[Col2];
2387  while (Col1Ptr != NULL OR Col2Ptr != NULL)
2388  {
2389 /* Exchange elements in rows while traveling from top to bottom. */
2390  if (Col1Ptr == NULL)
2391  { Row = Col2Ptr->Row;
2392  Element1 = NULL;
2393  Element2 = Col2Ptr;
2394  Col2Ptr = Col2Ptr->NextInCol;
2395  }
2396  else if (Col2Ptr == NULL)
2397  { Row = Col1Ptr->Row;
2398  Element1 = Col1Ptr;
2399  Element2 = NULL;
2400  Col1Ptr = Col1Ptr->NextInCol;
2401  }
2402  else if (Col1Ptr->Row < Col2Ptr->Row)
2403  { Row = Col1Ptr->Row;
2404  Element1 = Col1Ptr;
2405  Element2 = NULL;
2406  Col1Ptr = Col1Ptr->NextInCol;
2407  }
2408  else if (Col1Ptr->Row > Col2Ptr->Row)
2409  { Row = Col2Ptr->Row;
2410  Element1 = NULL;
2411  Element2 = Col2Ptr;
2412  Col2Ptr = Col2Ptr->NextInCol;
2413  }
2414  else /* Col1Ptr->Row == Col2Ptr->Row */
2415  { Row = Col1Ptr->Row;
2416  Element1 = Col1Ptr;
2417  Element2 = Col2Ptr;
2418  Col1Ptr = Col1Ptr->NextInCol;
2419  Col2Ptr = Col2Ptr->NextInCol;
2420  }
2421 
2422  ExchangeRowElements( Matrix, Col1, Element1, Col2, Element2, Row);
2423  } /* end of while(Col1Ptr != NULL OR Col2Ptr != NULL) */
2424 
2425  if (Matrix->InternalVectorsAllocated)
2426  SWAP( int, Matrix->MarkowitzCol[Col1], Matrix->MarkowitzCol[Col2]);
2427  SWAP( ElementPtr, Matrix->FirstInCol[Col1], Matrix->FirstInCol[Col2]);
2428  SWAP( int, Matrix->IntToExtColMap[Col1], Matrix->IntToExtColMap[Col2]);
2429 #if TRANSLATE
2430  Matrix->ExtToIntColMap[ Matrix->IntToExtColMap[Col1] ] = Col1;
2431  Matrix->ExtToIntColMap[ Matrix->IntToExtColMap[Col2] ] = Col2;
2432 #endif
2433 
2434  return;
2435 }
int * MarkowitzCol
Definition: spdefs.h:843
static void ExchangeRowElements()
struct MatrixElement * NextInCol
Definition: spdefs.h:547
#define NULL
Definition: spdefs.h:121
#define OR
Definition: fteparse.h:93
int * IntToExtColMap
Definition: spdefs.h:840
#define SWAP(type, a, b)
Definition: spdefs.h:145
BOOLEAN InternalVectorsAllocated
Definition: spdefs.h:839
int * ExtToIntColMap
Definition: spdefs.h:831
ArrayOfElementPtrs FirstInCol
Definition: spdefs.h:835
void spcCreateInternalVectors ( MatrixPtr  Matrix)

Definition at line 772 of file spfactor.c.

775 {
776 int Size;
777 
778 /* Begin `spcCreateInternalVectors'. */
779 /* Create Markowitz arrays. */
780  Size= Matrix->Size;
781 
782  if (Matrix->MarkowitzRow == NULL)
783  { if (( Matrix->MarkowitzRow = ALLOC(int, Size+1)) == NULL)
784  Matrix->Error = spNO_MEMORY;
785  }
786  if (Matrix->MarkowitzCol == NULL)
787  { if (( Matrix->MarkowitzCol = ALLOC(int, Size+1)) == NULL)
788  Matrix->Error = spNO_MEMORY;
789  }
790  if (Matrix->MarkowitzProd == NULL)
791  { if (( Matrix->MarkowitzProd = ALLOC(long, Size+2)) == NULL)
792  Matrix->Error = spNO_MEMORY;
793  }
794 
795 /* Create DoDirect vectors for use in spFactor(). */
796 #if REAL
797  if (Matrix->DoRealDirect == NULL)
798  { if (( Matrix->DoRealDirect = ALLOC(BOOLEAN, Size+1)) == NULL)
799  Matrix->Error = spNO_MEMORY;
800  }
801 #endif
802 #if spCOMPLEX
803  if (Matrix->DoCmplxDirect == NULL)
804  { if (( Matrix->DoCmplxDirect = ALLOC(BOOLEAN, Size+1)) == NULL)
805  Matrix->Error = spNO_MEMORY;
806  }
807 #endif
808 
809 /* Create Intermediate vectors for use in MatrixSolve. */
810 #if spCOMPLEX
811  if (Matrix->Intermediate == NULL)
812  { if ((Matrix->Intermediate = ALLOC(RealNumber,2*(Size+1))) == NULL)
813  Matrix->Error = spNO_MEMORY;
814  }
815 #else
816  if (Matrix->Intermediate == NULL)
817  { if ((Matrix->Intermediate = ALLOC(RealNumber, Size+1)) == NULL)
818  Matrix->Error = spNO_MEMORY;
819  }
820 #endif
821 
822  if (Matrix->Error != spNO_MEMORY)
823  Matrix->InternalVectorsAllocated = YES;
824  return;
825 }
#define ALLOC(type, number)
Definition: spdefs.h:433
int * MarkowitzRow
Definition: spdefs.h:842
int * MarkowitzCol
Definition: spdefs.h:843
int Size
Definition: spdefs.h:859
#define BOOLEAN
Definition: spdefs.h:112
BOOLEAN * DoRealDirect
Definition: spdefs.h:827
long * MarkowitzProd
Definition: spdefs.h:844
#define NULL
Definition: spdefs.h:121
register int Size
Definition: spsolve.c:163
int Error
Definition: spdefs.h:829
RealVector Intermediate
Definition: spdefs.h:838
spREAL RealNumber
Definition: spdefs.h:458
#define YES
Definition: spdefs.h:114
BOOLEAN InternalVectorsAllocated
Definition: spdefs.h:839
#define spNO_MEMORY
Definition: spmatrix.h:105
BOOLEAN * DoCmplxDirect
Definition: spdefs.h:826
void spcRowExchange ( MatrixPtr  Matrix,
int  Row1,
int  Row2 
)

Definition at line 2271 of file spfactor.c.

2275 {
2276 register ElementPtr Row1Ptr, Row2Ptr;
2277 int Column;
2278 ElementPtr Element1, Element2;
2279 
2280 /* Begin `spcRowExchange'. */
2281  if (Row1 > Row2) SWAP(int, Row1, Row2);
2282 
2283  Row1Ptr = Matrix->FirstInRow[Row1];
2284  Row2Ptr = Matrix->FirstInRow[Row2];
2285  while (Row1Ptr != NULL OR Row2Ptr != NULL)
2286  {
2287 /* Exchange elements in rows while traveling from left to right. */
2288  if (Row1Ptr == NULL)
2289  { Column = Row2Ptr->Col;
2290  Element1 = NULL;
2291  Element2 = Row2Ptr;
2292  Row2Ptr = Row2Ptr->NextInRow;
2293  }
2294  else if (Row2Ptr == NULL)
2295  { Column = Row1Ptr->Col;
2296  Element1 = Row1Ptr;
2297  Element2 = NULL;
2298  Row1Ptr = Row1Ptr->NextInRow;
2299  }
2300  else if (Row1Ptr->Col < Row2Ptr->Col)
2301  { Column = Row1Ptr->Col;
2302  Element1 = Row1Ptr;
2303  Element2 = NULL;
2304  Row1Ptr = Row1Ptr->NextInRow;
2305  }
2306  else if (Row1Ptr->Col > Row2Ptr->Col)
2307  { Column = Row2Ptr->Col;
2308  Element1 = NULL;
2309  Element2 = Row2Ptr;
2310  Row2Ptr = Row2Ptr->NextInRow;
2311  }
2312  else /* Row1Ptr->Col == Row2Ptr->Col */
2313  { Column = Row1Ptr->Col;
2314  Element1 = Row1Ptr;
2315  Element2 = Row2Ptr;
2316  Row1Ptr = Row1Ptr->NextInRow;
2317  Row2Ptr = Row2Ptr->NextInRow;
2318  }
2319 
2320  ExchangeColElements( Matrix, Row1, Element1, Row2, Element2, Column);
2321  } /* end of while(Row1Ptr != NULL OR Row2Ptr != NULL) */
2322 
2323  if (Matrix->InternalVectorsAllocated)
2324  SWAP( int, Matrix->MarkowitzRow[Row1], Matrix->MarkowitzRow[Row2]);
2325  SWAP( ElementPtr, Matrix->FirstInRow[Row1], Matrix->FirstInRow[Row2]);
2326  SWAP( int, Matrix->IntToExtRowMap[Row1], Matrix->IntToExtRowMap[Row2]);
2327 #if TRANSLATE
2328  Matrix->ExtToIntRowMap[ Matrix->IntToExtRowMap[Row1] ] = Row1;
2329  Matrix->ExtToIntRowMap[ Matrix->IntToExtRowMap[Row2] ] = Row2;
2330 #endif
2331 
2332  return;
2333 }
int * MarkowitzRow
Definition: spdefs.h:842
ArrayOfElementPtrs FirstInRow
Definition: spdefs.h:836
int * ExtToIntRowMap
Definition: spdefs.h:832
#define NULL
Definition: spdefs.h:121
#define OR
Definition: fteparse.h:93
int * IntToExtRowMap
Definition: spdefs.h:841
static void ExchangeColElements()
#define SWAP(type, a, b)
Definition: spdefs.h:145
BOOLEAN InternalVectorsAllocated
Definition: spdefs.h:839
struct MatrixElement * NextInRow
Definition: spdefs.h:546
int spFactor ( char *  eMatrix)

Definition at line 364 of file spfactor.c.

367 {
368 MatrixPtr Matrix = (MatrixPtr)eMatrix;
369 register ElementPtr pElement;
370 register ElementPtr pColumn;
371 register int Step, Size;
372 RealNumber Mult;
373 
374 /* Begin `spFactor'. */
375  ASSERT( IS_VALID(Matrix) AND NOT Matrix->Factored);
376 
377  if (Matrix->NeedsOrdering)
378  { return spOrderAndFactor( eMatrix, (RealVector)NULL,
379  0.0, 0.0, DIAG_PIVOTING_AS_DEFAULT );
380  }
381  if (NOT Matrix->Partitioned) spPartition( eMatrix, spDEFAULT_PARTITION );
382 #if spCOMPLEX
383  if (Matrix->Complex) return FactorComplexMatrix( Matrix );
384 #endif
385 
386 #if REAL
387  Size = Matrix->Size;
388 
389  if (Matrix->Diag[1]->Real == 0.0) return ZeroPivot( Matrix, 1 );
390  Matrix->Diag[1]->Real = 1.0 / Matrix->Diag[1]->Real;
391 
392 /* Start factorization. */
393  for (Step = 2; Step <= Size; Step++)
394  { if (Matrix->DoRealDirect[Step])
395  { /* Update column using direct addressing scatter-gather. */
396  register RealNumber *Dest = (RealNumber *)Matrix->Intermediate;
397 
398 /* Scatter. */
399  pElement = Matrix->FirstInCol[Step];
400  while (pElement != NULL)
401  { Dest[pElement->Row] = pElement->Real;
402  pElement = pElement->NextInCol;
403  }
404 
405 /* Update column. */
406  pColumn = Matrix->FirstInCol[Step];
407  while (pColumn->Row < Step)
408  { pElement = Matrix->Diag[pColumn->Row];
409  pColumn->Real = Dest[pColumn->Row] * pElement->Real;
410  while ((pElement = pElement->NextInCol) != NULL)
411  Dest[pElement->Row] -= pColumn->Real * pElement->Real;
412  pColumn = pColumn->NextInCol;
413  }
414 
415 /* Gather. */
416  pElement = Matrix->Diag[Step]->NextInCol;
417  while (pElement != NULL)
418  { pElement->Real = Dest[pElement->Row];
419  pElement = pElement->NextInCol;
420  }
421 
422 /* Check for singular matrix. */
423  if (Dest[Step] == 0.0) return ZeroPivot( Matrix, Step );
424  Matrix->Diag[Step]->Real = 1.0 / Dest[Step];
425  }
426  else
427  { /* Update column using indirect addressing scatter-gather. */
428  register RealNumber **pDest = (RealNumber **)Matrix->Intermediate;
429 
430 /* Scatter. */
431  pElement = Matrix->FirstInCol[Step];
432  while (pElement != NULL)
433  { pDest[pElement->Row] = &pElement->Real;
434  pElement = pElement->NextInCol;
435  }
436 
437 /* Update column. */
438  pColumn = Matrix->FirstInCol[Step];
439  while (pColumn->Row < Step)
440  { pElement = Matrix->Diag[pColumn->Row];
441  Mult = (*pDest[pColumn->Row] *= pElement->Real);
442  while ((pElement = pElement->NextInCol) != NULL)
443  *pDest[pElement->Row] -= Mult * pElement->Real;
444  pColumn = pColumn->NextInCol;
445  }
446 
447 /* Check for singular matrix. */
448  if (Matrix->Diag[Step]->Real == 0.0)
449  return ZeroPivot( Matrix, Step );
450  Matrix->Diag[Step]->Real = 1.0 / Matrix->Diag[Step]->Real;
451  }
452  }
453 
454  Matrix->Factored = YES;
455  return (Matrix->Error = spOKAY);
456 #endif /* REAL */
457 }
BOOLEAN Partitioned
Definition: spdefs.h:848
#define spDEFAULT_PARTITION
Definition: spmatrix.h:177
int Size
Definition: spdefs.h:859
BOOLEAN * DoRealDirect
Definition: spdefs.h:827
#define spOKAY
Definition: spmatrix.h:101
RealNumber Real
Definition: spdefs.h:539
static int ZeroPivot()
spREAL * RealVector
Definition: spdefs.h:458
static int FactorComplexMatrix()
struct MatrixElement * NextInCol
Definition: spdefs.h:547
BOOLEAN Factored
Definition: spdefs.h:833
BOOLEAN NeedsOrdering
Definition: spdefs.h:846
#define IS_VALID(matrix)
Definition: spdefs.h:127
ASSERT(IS_VALID(Matrix) AND IS_FACTORED(Matrix))
#define NULL
Definition: spdefs.h:121
register ElementPtr pElement
Definition: spsolve.c:158
register int Size
Definition: spsolve.c:163
int Error
Definition: spdefs.h:829
BOOLEAN Complex
Definition: spdefs.h:823
RealVector Intermediate
Definition: spdefs.h:838
while(TDesc->tSucc!=NULL)
Definition: cd.c:1335
spREAL RealNumber
Definition: spdefs.h:458
#define YES
Definition: spdefs.h:114
int spOrderAndFactor(char *eMatrix, RHS, RelThreshold, AbsThreshold, BOOLEAN DiagPivoting)
Definition: spfactor.c:222
ArrayOfElementPtrs Diag
Definition: spdefs.h:825
#define NOT
Definition: fteparse.h:94
struct MatrixFrame * MatrixPtr
Definition: spdefs.h:871
ArrayOfElementPtrs FirstInCol
Definition: spdefs.h:835
void spPartition(char *eMatrix, int Mode)
Definition: spfactor.c:623
#define AND
Definition: fteparse.h:92
int spOrderAndFactor ( char *  eMatrix,
RHS  ,
  RelThreshold,
  AbsThreshold,
BOOLEAN  DiagPivoting 
)

Definition at line 222 of file spfactor.c.

227 {
228 MatrixPtr Matrix = (MatrixPtr)eMatrix;
230 int Step, Size, ReorderingRequired;
232 RealNumber LargestInCol, FindLargestInCol();
233 
234 /* Begin `spOrderAndFactor'. */
235  ASSERT( IS_VALID(Matrix) AND NOT Matrix->Factored);
236 
237  Matrix->Error = spOKAY;
238  Size = Matrix->Size;
239  if (RelThreshold <= 0.0) RelThreshold = Matrix->RelThreshold;
240  if (RelThreshold > 1.0) RelThreshold = Matrix->RelThreshold;
241  Matrix->RelThreshold = RelThreshold;
242  if (AbsThreshold < 0.0) AbsThreshold = Matrix->AbsThreshold;
243  Matrix->AbsThreshold = AbsThreshold;
244  ReorderingRequired = NO;
245 
246  if (NOT Matrix->NeedsOrdering)
247  {
248 /* Matrix has been factored before and reordering is not required. */
249  for (Step = 1; Step <= Size; Step++)
250  { pPivot = Matrix->Diag[Step];
251  LargestInCol = FindLargestInCol(Matrix,pPivot->NextInCol);
252  if ((LargestInCol * RelThreshold < ELEMENT_MAG(pPivot)))
253  { if (Matrix->Complex)
254  ComplexRowColElimination( Matrix, pPivot );
255  else
256  RealRowColElimination( Matrix, pPivot );
257  }
258  else
259  { ReorderingRequired = YES;
260  break; /* for loop */
261  }
262  }
263  if (NOT ReorderingRequired)
264  goto Done;
265  else
266  {
267 /*
268  * A pivot was not large enough to maintain accuracy,
269  * so a partial reordering is required.
270  */
271 
272 #if (ANNOTATE >= ON_STRANGE_BEHAVIOR)
273  printf("Reordering, Step = %1d\n", Step);
274 #endif
275  }
276  } /* End of if(NOT Matrix->NeedsOrdering) */
277  else
278  {
279 /*
280  * This is the first time the matrix has been factored. These few statements
281  * indicate to the rest of the code that a full reodering is required rather
282  * than a partial reordering, which occurs during a failure of a fast
283  * factorization.
284  */
285  Step = 1;
286  if (NOT Matrix->RowsLinked)
287  spcLinkRows( Matrix );
288  if (NOT Matrix->InternalVectorsAllocated)
289  spcCreateInternalVectors( Matrix );
290  if (Matrix->Error >= spFATAL)
291  return Matrix->Error;
292  }
293 
294 /* Form initial Markowitz products. */
295  CountMarkowitz( Matrix, RHS, Step );
296  MarkowitzProducts( Matrix, Step );
297  Matrix->MaxRowCountInLowerTri = -1;
298 
299 /* Perform reordering and factorization. */
300  for (; Step <= Size; Step++)
301  { pPivot = SearchForPivot( Matrix, Step, DiagPivoting );
302  if (pPivot == NULL) return MatrixIsSingular( Matrix, Step );
303  ExchangeRowsAndCols( Matrix, pPivot, Step );
304 
305  if (Matrix->Complex)
306  ComplexRowColElimination( Matrix, pPivot );
307  else
308  RealRowColElimination( Matrix, pPivot );
309 
310  if (Matrix->Error >= spFATAL) return Matrix->Error;
311  UpdateMarkowitzNumbers( Matrix, pPivot );
312 
313 #if (ANNOTATE == FULL)
314  WriteStatus( Matrix, Step );
315 #endif
316  }
317 
318 Done:
319  Matrix->NeedsOrdering = NO;
320  Matrix->Reordered = YES;
321  Matrix->Factored = YES;
322 
323  return Matrix->Error;
324 }
RealNumber RelThreshold
Definition: spdefs.h:853
static void CountMarkowitz()
#define NO
Definition: spdefs.h:113
int Size
Definition: spdefs.h:859
static RealNumber FindLargestInCol()
#define spOKAY
Definition: spmatrix.h:101
#define spFATAL
Definition: spmatrix.h:108
static int MatrixIsSingular()
static void ExchangeRowsAndCols()
#define ELEMENT_MAG(ptr)
Definition: spdefs.h:161
struct MatrixElement * NextInCol
Definition: spdefs.h:547
BOOLEAN Factored
Definition: spdefs.h:833
BOOLEAN NeedsOrdering
Definition: spdefs.h:846
RealNumber AbsThreshold
Definition: spdefs.h:820
static void RealRowColElimination()
#define IS_VALID(matrix)
Definition: spdefs.h:127
ASSERT(IS_VALID(Matrix) AND IS_FACTORED(Matrix))
#define NULL
Definition: spdefs.h:121
register int Size
Definition: spsolve.c:163
static void ComplexRowColElimination()
static void UpdateMarkowitzNumbers()
static ElementPtr SearchForPivot()
void spcCreateInternalVectors(MatrixPtr Matrix)
Definition: spfactor.c:772
void spcLinkRows()
int Error
Definition: spdefs.h:829
BOOLEAN Complex
Definition: spdefs.h:823
BOOLEAN RowsLinked
Definition: spdefs.h:855
static void WriteStatus()
spREAL RealNumber
Definition: spdefs.h:458
#define YES
Definition: spdefs.h:114
BOOLEAN InternalVectorsAllocated
Definition: spdefs.h:839
RealVector RHS
Definition: spsolve.c:157
ArrayOfElementPtrs Diag
Definition: spdefs.h:825
#define NOT
Definition: fteparse.h:94
BOOLEAN Reordered
Definition: spdefs.h:854
struct MatrixFrame * MatrixPtr
Definition: spdefs.h:871
int MaxRowCountInLowerTri
Definition: spdefs.h:845
ElementPtr pPivot
Definition: spsolve.c:164
#define AND
Definition: fteparse.h:92
static void MarkowitzProducts()
void spPartition ( char *  eMatrix,
int  Mode 
)

Definition at line 623 of file spfactor.c.

627 {
628 MatrixPtr Matrix = (MatrixPtr)eMatrix;
629 register ElementPtr pElement, pColumn;
630 register int Step, Size;
631 register int *Nc, *No, *Nm;
632 BOOLEAN *DoRealDirect, *DoCmplxDirect;
633 
634 /* Begin `spPartition'. */
635  ASSERT( IS_SPARSE( Matrix ) );
636  if (Matrix->Partitioned) return;
637  Size = Matrix->Size;
638  DoRealDirect = Matrix->DoRealDirect;
639  DoCmplxDirect = Matrix->DoCmplxDirect;
640  Matrix->Partitioned = YES;
641 
642 /* If partition is specified by the user, this is easy. */
643  if (Mode == spDEFAULT_PARTITION) Mode = DEFAULT_PARTITION;
644  if (Mode == spDIRECT_PARTITION)
645  { for (Step = 1; Step <= Size; Step++)
646 #if REAL
647  DoRealDirect[Step] = YES;
648 #endif
649 #if spCOMPLEX
650  DoCmplxDirect[Step] = YES;
651 #endif
652  return;
653  }
654  else if (Mode == spINDIRECT_PARTITION)
655  { for (Step = 1; Step <= Size; Step++)
656 #if REAL
657  DoRealDirect[Step] = NO;
658 #endif
659 #if spCOMPLEX
660  DoCmplxDirect[Step] = NO;
661 #endif
662  return;
663  }
664  else ASSERT( Mode == spAUTO_PARTITION );
665 
666 /* Otherwise, count all operations needed in when factoring matrix. */
667  Nc = (int *)Matrix->MarkowitzRow;
668  No = (int *)Matrix->MarkowitzCol;
669  Nm = (int *)Matrix->MarkowitzProd;
670 
671 /* Start mock-factorization. */
672  for (Step = 1; Step <= Size; Step++)
673  { Nc[Step] = No[Step] = Nm[Step] = 0;
674 
675  pElement = Matrix->FirstInCol[Step];
676  while (pElement != NULL)
677  { Nc[Step]++;
678  pElement = pElement->NextInCol;
679  }
680 
681  pColumn = Matrix->FirstInCol[Step];
682  while (pColumn->Row < Step)
683  { pElement = Matrix->Diag[pColumn->Row];
684  Nm[Step]++;
685  while ((pElement = pElement->NextInCol) != NULL)
686  No[Step]++;
687  pColumn = pColumn->NextInCol;
688  }
689  }
690 
691  for (Step = 1; Step <= Size; Step++)
692  {
693 /*
694  * The following are just estimates based on a count on the number of
695  * machine instructions used on each machine to perform the various
696  * tasks. It was assumed that each machine instruction required the
697  * same amount of time (I don't believe this is true for the VAX, and
698  * have no idea if this is true for the 68000 family). For optimum
699  * performance, these numbers should be tuned to the machine.
700  * Nc is the number of nonzero elements in the column.
701  * Nm is the number of multipliers in the column.
702  * No is the number of operations in the inner loop.
703  */
704 
705 #define generic
706 #ifdef hp9000s300
707 #if REAL
708  DoRealDirect[Step] = (Nm[Step] + No[Step] > 3*Nc[Step] - 2*Nm[Step]);
709 #endif
710 #if spCOMPLEX
711  /* On the hp350, it is never profitable to use direct for complex. */
712  DoCmplxDirect[Step] = NO;
713 #endif
714 #undef generic
715 #endif
716 
717 #ifdef vax
718 #if REAL
719  DoRealDirect[Step] = (Nm[Step] + No[Step] > 3*Nc[Step] - 2*Nm[Step]);
720 #endif
721 #if spCOMPLEX
722  DoCmplxDirect[Step] = (Nm[Step] + No[Step] > 7*Nc[Step] - 4*Nm[Step]);
723 #endif
724 #undef generic
725 #endif
726 
727 #ifdef generic
728 #if REAL
729  DoRealDirect[Step] = (Nm[Step] + No[Step] > 3*Nc[Step] - 2*Nm[Step]);
730 #endif
731 #if spCOMPLEX
732  DoCmplxDirect[Step] = (Nm[Step] + No[Step] > 7*Nc[Step] - 4*Nm[Step]);
733 #endif
734 #undef generic
735 #endif
736  }
737 
738 #if (ANNOTATE == FULL)
739  { int Ops = 0;
740  for (Step = 1; Step <= Size; Step++)
741  Ops += No[Step];
742  printf("Operation count for inner loop of factorization = %d.\n", Ops);
743  }
744 #endif
745  return;
746 }
BOOLEAN Partitioned
Definition: spdefs.h:848
#define spDEFAULT_PARTITION
Definition: spmatrix.h:177
int * MarkowitzRow
Definition: spdefs.h:842
int * MarkowitzCol
Definition: spdefs.h:843
#define spINDIRECT_PARTITION
Definition: spmatrix.h:179
#define NO
Definition: spdefs.h:113
int Size
Definition: spdefs.h:859
#define BOOLEAN
Definition: spdefs.h:112
#define spDIRECT_PARTITION
Definition: spmatrix.h:178
BOOLEAN * DoRealDirect
Definition: spdefs.h:827
#define spAUTO_PARTITION
Definition: spmatrix.h:180
long * MarkowitzProd
Definition: spdefs.h:844
#define IS_SPARSE(matrix)
Definition: spdefs.h:125
struct MatrixElement * NextInCol
Definition: spdefs.h:547
ASSERT(IS_VALID(Matrix) AND IS_FACTORED(Matrix))
#define NULL
Definition: spdefs.h:121
register ElementPtr pElement
Definition: spsolve.c:158
register int Size
Definition: spsolve.c:163
#define YES
Definition: spdefs.h:114
ArrayOfElementPtrs Diag
Definition: spdefs.h:825
struct MatrixFrame * MatrixPtr
Definition: spdefs.h:871
BOOLEAN * DoCmplxDirect
Definition: spdefs.h:826
ArrayOfElementPtrs FirstInCol
Definition: spdefs.h:835
static void UpdateMarkowitzNumbers ( )
static
static void UpdateMarkowitzNumbers ( MatrixPtr  Matrix,
ElementPtr  pPivot 
)
static

Definition at line 2930 of file spfactor.c.

2934 {
2935 register int Row, Col;
2936 register ElementPtr ColPtr, RowPtr;
2937 register int *MarkoRow = Matrix->MarkowitzRow, *MarkoCol = Matrix->MarkowitzCol;
2938 double Product;
2939 
2940 /* Begin `UpdateMarkowitzNumbers'. */
2941 
2942 /* Update Markowitz numbers. */
2943  for (ColPtr = pPivot->NextInCol; ColPtr != NULL; ColPtr = ColPtr->NextInCol)
2944  { Row = ColPtr->Row;
2945  --MarkoRow[Row];
2946 
2947 /* Form Markowitz product while being cautious of overflows. */
2948  if ((MarkoRow[Row] > LARGEST_SHORT_INTEGER AND MarkoCol[Row] != 0) OR
2949  (MarkoCol[Row] > LARGEST_SHORT_INTEGER AND MarkoRow[Row] != 0))
2950  { Product = MarkoCol[Row] * MarkoRow[Row];
2951  if (Product >= LARGEST_LONG_INTEGER)
2952  Matrix->MarkowitzProd[Row] = LARGEST_LONG_INTEGER;
2953  else
2954  Matrix->MarkowitzProd[Row] = Product;
2955  }
2956  else Matrix->MarkowitzProd[Row] = MarkoRow[Row] * MarkoCol[Row];
2957  if (MarkoRow[Row] == 0)
2958  Matrix->Singletons++;
2959  }
2960 
2961  for (RowPtr = pPivot->NextInRow; RowPtr != NULL; RowPtr = RowPtr->NextInRow)
2962  { Col = RowPtr->Col;
2963  --MarkoCol[Col];
2964 
2965 /* Form Markowitz product while being cautious of overflows. */
2966  if ((MarkoRow[Col] > LARGEST_SHORT_INTEGER AND MarkoCol[Col] != 0) OR
2967  (MarkoCol[Col] > LARGEST_SHORT_INTEGER AND MarkoRow[Col] != 0))
2968  { Product = MarkoCol[Col] * MarkoRow[Col];
2969  if (Product >= LARGEST_LONG_INTEGER)
2970  Matrix->MarkowitzProd[Col] = LARGEST_LONG_INTEGER;
2971  else
2972  Matrix->MarkowitzProd[Col] = Product;
2973  }
2974  else Matrix->MarkowitzProd[Col] = MarkoRow[Col] * MarkoCol[Col];
2975  if ((MarkoCol[Col] == 0) AND (MarkoRow[Col] != 0))
2976  Matrix->Singletons++;
2977  }
2978  return;
2979 }
int * MarkowitzRow
Definition: spdefs.h:842
int * MarkowitzCol
Definition: spdefs.h:843
long * MarkowitzProd
Definition: spdefs.h:844
int Singletons
Definition: spdefs.h:858
struct MatrixElement * NextInCol
Definition: spdefs.h:547
#define NULL
Definition: spdefs.h:121
#define OR
Definition: fteparse.h:93
struct MatrixElement * NextInRow
Definition: spdefs.h:546
#define AND
Definition: fteparse.h:92
static void WriteStatus ( )
static
static void WriteStatus ( MatrixPtr  Matrix,
int  Step 
)
static

Definition at line 3121 of file spfactor.c.

3125 {
3126 int I;
3127 
3128 /* Begin `WriteStatus'. */
3129 
3130  printf("Step = %1d ", Step);
3131  printf("Pivot found at %1d,%1d using ", Matrix->PivotsOriginalRow,
3132  Matrix->PivotsOriginalCol);
3133  switch(Matrix->PivotSelectionMethod)
3134  { case 's': printf("SearchForSingleton\n"); break;
3135  case 'q': printf("QuicklySearchDiagonal\n"); break;
3136  case 'd': printf("SearchDiagonal\n"); break;
3137  case 'e': printf("SearchEntireMatrix\n"); break;
3138  }
3139 
3140  printf("MarkowitzRow = ");
3141  for (I = 1; I <= Matrix->Size; I++)
3142  printf("%2d ", Matrix->MarkowitzRow[I]);
3143  printf("\n");
3144 
3145  printf("MarkowitzCol = ");
3146  for (I = 1; I <= Matrix->Size; I++)
3147  printf("%2d ", Matrix->MarkowitzCol[I]);
3148  printf("\n");
3149 
3150  printf("MarkowitzProduct = ");
3151  for (I = 1; I <= Matrix->Size; I++)
3152  printf("%2d ", Matrix->MarkowitzProd[I]);
3153  printf("\n");
3154 
3155  printf("Singletons = %2d\n", Matrix->Singletons);
3156 
3157  printf("IntToExtRowMap = ");
3158  for (I = 1; I <= Matrix->Size; I++)
3159  printf("%2d ", Matrix->IntToExtRowMap[I]);
3160  printf("\n");
3161 
3162  printf("IntToExtColMap = ");
3163  for (I = 1; I <= Matrix->Size; I++)
3164  printf("%2d ", Matrix->IntToExtColMap[I]);
3165  printf("\n");
3166 
3167  printf("ExtToIntRowMap = ");
3168  for (I = 1; I <= Matrix->ExtSize; I++)
3169  printf("%2d ", Matrix->ExtToIntRowMap[I]);
3170  printf("\n");
3171 
3172  printf("ExtToIntColMap = ");
3173  for (I = 1; I <= Matrix->ExtSize; I++)
3174  printf("%2d ", Matrix->ExtToIntColMap[I]);
3175  printf("\n\n");
3176 
3177 /* spPrint((char *)Matrix, NO, YES); */
3178 
3179  return;
3180 
3181 }
int * MarkowitzRow
Definition: spdefs.h:842
int * MarkowitzCol
Definition: spdefs.h:843
char PivotSelectionMethod
Definition: spdefs.h:851
int Size
Definition: spdefs.h:859
int PivotsOriginalRow
Definition: spdefs.h:850
long * MarkowitzProd
Definition: spdefs.h:844
int * ExtToIntRowMap
Definition: spdefs.h:832
int Singletons
Definition: spdefs.h:858
int PivotsOriginalCol
Definition: spdefs.h:849
int * IntToExtColMap
Definition: spdefs.h:840
int ExtSize
Definition: spdefs.h:830
int * IntToExtRowMap
Definition: spdefs.h:841
int * ExtToIntColMap
Definition: spdefs.h:831
register int I
Definition: spsolve.c:163
static int ZeroPivot ( )
static
static int ZeroPivot ( MatrixPtr  Matrix,
int  Step 
)
static

Definition at line 3094 of file spfactor.c.

3098 {
3099 /* Begin `ZeroPivot'. */
3100 
3101  Matrix->SingularRow = Matrix->IntToExtRowMap[ Step ];
3102  Matrix->SingularCol = Matrix->IntToExtColMap[ Step ];
3103  return (Matrix->Error = spZERO_DIAG);
3104 }
int SingularCol
Definition: spdefs.h:856
int SingularRow
Definition: spdefs.h:857
int * IntToExtColMap
Definition: spdefs.h:840
int * IntToExtRowMap
Definition: spdefs.h:841
int Error
Definition: spdefs.h:829
#define spZERO_DIAG
Definition: spmatrix.h:103