Blame view

fvn_sparse/UMFPACK/Source/umfpack_scale.c 3.46 KB
422234dc3   daniau   git-svn-id: https...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  /* ========================================================================== */
  /* === UMFPACK_scale ======================================================== */
  /* ========================================================================== */
  
  /* -------------------------------------------------------------------------- */
  /* UMFPACK Copyright (c) Timothy A. Davis, CISE,                              */
  /* Univ. of Florida.  All Rights Reserved.  See ../Doc/License for License.   */
  /* web: http://www.cise.ufl.edu/research/sparse/umfpack                       */
  /* -------------------------------------------------------------------------- */
  
  /*
      User-callable.  Applies the scale factors computed during numerical
      factorization to a vector. See umfpack_scale.h for more details.
  
      The LU factorization is L*U = P*R*A*Q, where P and Q are permutation
      matrices, and R is diagonal.  This routine computes X = R * B using the
      matrix R stored in the Numeric object.
  
      Returns FALSE if any argument is invalid, TRUE otherwise.
  
      If R not present in the Numeric object, then R = I and no floating-point
      work is done.  B is simply copied into X.
  */
  
  #include "umf_internal.h"
  #include "umf_valid_numeric.h"
  
  GLOBAL Int UMFPACK_scale
  (
      double Xx [ ],
  #ifdef COMPLEX
      double Xz [ ],
  #endif
      const double Bx [ ],
  #ifdef COMPLEX
      const double Bz [ ],
  #endif
      void *NumericHandle
  )
  {
      /* ---------------------------------------------------------------------- */
      /* local variables */
      /* ---------------------------------------------------------------------- */
  
      NumericType *Numeric ;
      Int n, i ;
      double *Rs ;
  #ifdef COMPLEX
      Int split = SPLIT (Xz) && SPLIT (Bz) ;
  #endif
  
      Numeric = (NumericType *) NumericHandle ;
      if (!UMF_valid_numeric (Numeric))
      {
  	return (UMFPACK_ERROR_invalid_Numeric_object) ;
      }
  
      n = Numeric->n_row ;
      Rs = Numeric->Rs ;
  
      if (!Xx || !Bx)
      {
  	return (UMFPACK_ERROR_argument_missing) ;
      }
  
      /* ---------------------------------------------------------------------- */
      /* X = R*B or R\B */
      /* ---------------------------------------------------------------------- */
  
      if (Rs != (double *) NULL)
      {
  #ifndef NRECIPROCAL
  	if (Numeric->do_recip)
  	{
  	    /* multiply by the scale factors */
  #ifdef COMPLEX
  	    if (split)
  	    {
  		for (i = 0 ; i < n ; i++)
  		{
  		    Xx [i] = Bx [i] * Rs [i] ;
  		    Xz [i] = Bz [i] * Rs [i] ;
  		}
  	    }
  	    else
  	    {
  		for (i = 0 ; i < n ; i++)
  		{
  		    Xx [2*i  ] = Bx [2*i  ] * Rs [i] ;
  		    Xx [2*i+1] = Bx [2*i+1] * Rs [i] ;
  		}
  	    }
  #else
  	    for (i = 0 ; i < n ; i++)
  	    {
  		Xx [i] = Bx [i] * Rs [i] ;
  	    }
  #endif
  	}
  	else
  #endif
  	{
  	    /* divide by the scale factors */
  #ifdef COMPLEX
  	    if (split)
  	    {
  		for (i = 0 ; i < n ; i++)
  		{
  		    Xx [i] = Bx [i] / Rs [i] ;
  		    Xz [i] = Bz [i] / Rs [i] ;
  		}
  	    }
  	    else
  	    {
  		for (i = 0 ; i < n ; i++)
  		{
  		    Xx [2*i  ] = Bx [2*i  ] / Rs [i] ;
  		    Xx [2*i+1] = Bx [2*i+1] / Rs [i] ;
  		}
  	    }
  #else
  	    for (i = 0 ; i < n ; i++)
  	    {
  		Xx [i] = Bx [i] / Rs [i] ;
  	    }
  #endif
  	}
      }
      else
      {
  	/* no scale factors, just copy B into X */
  #ifdef COMPLEX
          if (split)
  	{
  	    for (i = 0 ; i < n ; i++)
  	    {
  		Xx [i] = Bx [i] ;
  		Xz [i] = Bz [i] ;
  	    }
  	}
  	else
  	{
  	    for (i = 0 ; i < n ; i++)
  	    {
  		Xx [2*i  ] = Bx [2*i  ] ;
  		Xx [2*i+1] = Bx [2*i+1] ;
  	    }
  	}
  #else
  	for (i = 0 ; i < n ; i++)
  	{
  	    Xx [i] = Bx [i] ;
  	}
  #endif
      }
  
      return (UMFPACK_OK) ;
  }