1 /* ========================================================================== */
2 /* === UMF_scale ============================================================ */
3 /* ========================================================================== */
4 
5 /* -------------------------------------------------------------------------- */
6 /* Copyright (c) 2005-2012 by Timothy A. Davis, http://www.suitesparse.com.   */
7 /* All Rights Reserved.  See ../Doc/License.txt for License.                  */
8 /* -------------------------------------------------------------------------- */
9 
10 /* Divide a vector of stride 1 by the pivot value. */
11 
12 #include "umf_internal.h"
13 #include "umf_scale.h"
14 
UMF_scale(Int n,Entry pivot,Entry X[])15 GLOBAL void UMF_scale
16 (
17     Int n,
18     Entry pivot,
19     Entry X [ ]
20 )
21 {
22     Entry x ;
23     double s ;
24     Int i ;
25 
26     /* ---------------------------------------------------------------------- */
27     /* compute the approximate absolute value of the pivot, and select method */
28     /* ---------------------------------------------------------------------- */
29 
30     APPROX_ABS (s, pivot) ;
31 
32     if (s < RECIPROCAL_TOLERANCE || IS_NAN (pivot))
33     {
34 	/* ------------------------------------------------------------------ */
35 	/* tiny, or zero, pivot case */
36 	/* ------------------------------------------------------------------ */
37 
38 	/* The pivot is tiny, or NaN.  Do not divide zero by the pivot value,
39 	 * and do not multiply by 1/pivot, either. */
40 
41 	for (i = 0 ; i < n ; i++)
42 	{
43 	    /* X [i] /= pivot ; */
44 	    x = X [i] ;
45 
46 #ifndef NO_DIVIDE_BY_ZERO
47 	    if (IS_NONZERO (x))
48 	    {
49 		DIV (X [i], x, pivot) ;
50 	    }
51 #else
52 	    /* Do not divide by zero */
53 	    if (IS_NONZERO (x) && IS_NONZERO (pivot))
54 	    {
55 		DIV (X [i], x, pivot) ;
56 	    }
57 #endif
58 
59 	}
60 
61     }
62     else
63     {
64 
65 	/* ------------------------------------------------------------------ */
66 	/* normal case */
67 	/* ------------------------------------------------------------------ */
68 
69 	/* The pivot is not tiny, and is not NaN.   Don't bother to check for
70 	 * zeros in the pivot column, X.  This is slightly more accurate than
71 	 * multiplying by 1/pivot (but slightly slower), particularly if the
72 	 * pivot column consists of only IEEE subnormals. */
73 
74 	for (i = 0 ; i < n ; i++)
75 	{
76 	    /* X [i] /= pivot ; */
77 	    x = X [i] ;
78 	    DIV (X [i], x, pivot) ;
79 	}
80     }
81 }
82