File: umf_scale.c

package info (click to toggle)
python-scipy 0.5.2-0.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 33,888 kB
  • ctags: 44,231
  • sloc: ansic: 156,256; cpp: 90,347; python: 89,604; fortran: 73,083; sh: 1,318; objc: 424; makefile: 342
file content (118 lines) | stat: -rw-r--r-- 3,768 bytes parent folder | download | duplicates (6)
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
/* ========================================================================== */
/* === UMF_scale ============================================================ */
/* ========================================================================== */

/* -------------------------------------------------------------------------- */
/* UMFPACK Version 4.1 (Apr. 30, 2003), Copyright (c) 2003 by Timothy A.      */
/* Davis.  All Rights Reserved.  See ../README for License.                   */
/* email: davis@cise.ufl.edu    CISE Department, Univ. of Florida.            */
/* web: http://www.cise.ufl.edu/research/sparse/umfpack                       */
/* -------------------------------------------------------------------------- */

/* Divide a vector of stride 1 by the pivot value. */

#include "umf_internal.h"

GLOBAL void UMF_scale
(
    Int n,
    Entry pivot,
    Entry X [ ]
)
{
    Int i ;
    Entry x ;
    double s ;

    /* ---------------------------------------------------------------------- */
    /* compute the approximate absolute value of the pivot, and select method */
    /* ---------------------------------------------------------------------- */

    APPROX_ABS (s, pivot) ;

    if (s < RECIPROCAL_TOLERANCE || IS_NAN (pivot))
    {
	/* ------------------------------------------------------------------ */
	/* tiny, or zero, pivot case */
	/* ------------------------------------------------------------------ */

	/* The pivot is tiny, or NaN.  Do not divide zero by the pivot value,
	 * and do not multiply by 1/pivot, either. */

	for (i = 0 ; i < n ; i++)
	{
	    /* X [i] /= pivot ; */
	    x = X [i] ;
	    if (IS_NONZERO (x))
	    {
		DIV (X [i], x, pivot) ;
	    }
	}

    }
    else
    {

	/* ------------------------------------------------------------------ */
	/* normal case.  select the x/pivot or x * (1/pivot) method */
	/* ------------------------------------------------------------------ */

	/* The pivot is not tiny, and is not NaN.   Don't bother to check for
	 * zeros in the pivot column, X. */

#if !defined (NRECIPROCAL) && !(defined (__GNUC__) && defined (COMPLEX))

	    /* -------------------------------------------------------------- */
	    /* multiply x by (1/pivot) */
	    /* -------------------------------------------------------------- */

	    /* Slightly less accurate, but faster.  It allows the use of
	     * the level-1 BLAS dscal or zscal routine.  This not used when
	     * UMFPACK is used in MATLAB (either as a built-in routine, or as
	     * a mexFunction).
	     *
	     * Using gcc version 3.2 can cause the following code to fail for
	     * some complex matrices (not all), with or without the BLAS.  This
	     * was found in Red Hat Linux 7.3 on a Dell Latitude C840 with a
	     * Pentium 4M.  Thus, this code is not used when gcc is used, for
	     * the complex case.
	     *
	     * It works just fine with Intel's icc compiler, version 7.0.
	     */

	    /* pivot = 1 / pivot */
	    RECIPROCAL (pivot) ;

#if defined (USE_NO_BLAS)
	    for (i = 0 ; i < n ; i++)
	    {
		/* X [i] *= pivot ; */
		x = X [i] ;
		MULT (X [i], x, pivot) ;
	    }
#else
	    BLAS_SCAL (n, pivot, X) ;
#endif

#else

	    /* -------------------------------------------------------------- */
	    /* divide x by the pivot */
	    /* -------------------------------------------------------------- */

	    /* This is slightly more accurate, particularly if the pivot column
	     * consists of only IEEE subnormals.  Always do this if UMFPACK is
	     * being compiled as a built-in routine or mexFunction in MATLAB,
	     * or if gcc is being used with complex matrices. */

	    for (i = 0 ; i < n ; i++)
	    {
		/* X [i] /= pivot ; */
		x = X [i] ;
		DIV (X [i], x, pivot) ;
	    }

#endif

    }
}