~logan/ubuntu/trusty/suitesparse/4.2.1-3ubuntu1

« back to all changes in this revision

Viewing changes to CXSparse_newfiles/Source/cs_house.c

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2007-05-29 09:36:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529093629-zowquo0b7slkk6nc
Tags: 3.0.0-2
* suitesparse builds properly twice in a row
* Bug fix: "suitesparse - FTBFS: Broken build depens: libgfortran1-dev",
  thanks to Bastian Blank (Closes: #426349).
* Bug fix: "suitesparse_3.0.0-1: FTBFS: build-depends on
  libgfortran1-dev", thanks to Steve Langasek (Closes: #426354).

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/* create a Householder reflection [v,beta,s]=house(x), overwrite x with v,
3
3
 * where (I-beta*v*v')*x = s*e1 and e1 = [1 0 ... 0]'.
4
4
 * Note that this CXSparse version is different than CSparse. */
5
 
CS_ENTRY cs_house (CS_ENTRY *x, CS_ENTRY *beta, CS_INT n)
 
5
CS_ENTRY cs_house (CS_ENTRY *x, double *beta, CS_INT n)
6
6
{
7
7
    CS_ENTRY s = 0 ;
8
8
    CS_INT i ;
9
9
    if (!x || !beta) return (-1) ;          /* check inputs */
 
10
    /* s = norm(x) */
10
11
    for (i = 0 ; i < n ; i++) s += x [i] * CS_CONJ (x [i]) ;
11
12
    s = sqrt (s) ;
12
13
    if (s == 0)
16
17
    }
17
18
    else
18
19
    {
 
20
        /* s = sign(x[0]) * norm (x) ; */
19
21
        if (x [0] != 0)
20
22
        {
21
23
            s *= x [0] / CS_ABS (x [0]) ;
22
24
        }
23
 
        s = -s ;
24
 
        x [0] -= s ;
25
 
        (*beta) = -1. / (CS_CONJ (s) * x [0]) ;
 
25
        x [0] += s ;
 
26
        (*beta) = 1. / CS_REAL (CS_CONJ (s) * x [0]) ;
26
27
    }
27
 
    return (s) ;
 
28
    return (-s) ;
28
29
}