TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcmodel
hholder.c
Go to the documentation of this file.
1
8
/*****************************************************************************/
9
#include "
libtpcmodel.h
"
10
/*****************************************************************************/
11
12
/*****************************************************************************/
23
double
householder_transform
(
25
double
*v,
27
int
N
28
) {
29
double
vnorm, alpha, beta, tau;
30
31
if
(N<1)
return
0.0;
// tau = 0
32
/* Euclidean norm of the vector starting from the second value */
33
vnorm=0.0;
for
(
int
n=1; n<N; n++) vnorm+=v[n]*v[n];
34
vnorm=sqrt(vnorm);
if
(isnan(vnorm) || vnorm==0.0)
return
0.0;
// tau = 0
35
36
/* Computing the coefficient tau */
37
alpha=v[0];
38
beta= - (alpha >= 0.0 ? +1.0 : -1.0) * hypot(alpha, vnorm);
39
tau=(beta-alpha)/beta ;
40
41
/* Scale the Householder vector so that the first element will be 1.
42
* (Scaling is also affecting the coefficient tau).
43
* Without scaling, the first element would have value (alpha - beta). */
44
{
45
double
s=alpha-beta;
46
if
(fabs(s)>DBL_MIN) {
47
v[0]=beta;
48
for
(
int
n=1; n<N; n++) v[n]*=(1.0/s);
49
}
else
{
50
v[0]=beta;
51
for
(
int
n=1; n<N; n++) v[n]*=(
doubleMachEps
()/s);
52
for
(
int
n=1; n<N; n++) v[n]*=(1.0/
doubleMachEps
());
53
}
54
}
55
56
return
tau;
57
}
58
/*****************************************************************************/
59
60
/*****************************************************************************/
68
int
householder_hm
(
70
double
tau,
72
double
*vector,
74
double
**matrix,
76
int
rowNr,
78
int
columnNr
79
) {
80
int
i, j;
81
double
wj;
82
83
if
(tau==0.0)
return
(0);
// success
84
if
(rowNr<1 || columnNr<1)
return
(1);
85
for
(j=0; j<columnNr; j++) {
86
/* Compute wj = vk Akj */
87
wj=matrix[0][j];
88
for
(i=1; i<rowNr; i++)
/* note, computed for v(0) = 1 above */
89
wj += vector[i]*matrix[i][j];
90
/* Aij = Aij - tau vi wj */
91
/* i = 0 */
92
matrix[0][j]-=tau*wj;
93
/* i = 1 .. M-1 */
94
for
(i=1; i<rowNr; i++) matrix[i][j]-=tau*vector[i]*wj;
95
}
96
return
(0);
97
}
98
/*****************************************************************************/
99
100
/*****************************************************************************/
107
int
householder_hv
(
109
double
tau,
111
int
size,
113
double
*v,
115
double
*w
116
) {
117
int
i;
118
double
d;
119
120
if
(tau==0)
return
(0);
// success
121
if
(size<1)
return
(1);
122
/* d = v'w */
123
d=w[0];
for
(i=1; i<size; i++) d+=v[i]*w[i];
124
/* w = w - tau (v) (v'w) */
125
w[0]-=tau*d;
126
for
(i=1; i<size; i++) w[i]-=tau*v[i]*d;
127
return
(0);
128
}
129
/*****************************************************************************/
130
131
/*****************************************************************************/
136
double
householder_norm
(
138
double
*v,
140
int
size
141
) {
142
double
help;
143
int
i;
144
145
for
(i=0, help=0; i<size; i++) help+=v[i]*v[i];
146
return
sqrt(help);
147
}
148
/*****************************************************************************/
149
150
/*****************************************************************************/
doubleMachEps
double doubleMachEps()
Definition
doubleutil.c:83
householder_norm
double householder_norm(double *v, int size)
Definition
hholder.c:136
householder_hv
int householder_hv(double tau, int size, double *v, double *w)
Definition
hholder.c:107
householder_hm
int householder_hm(double tau, double *vector, double **matrix, int rowNr, int columnNr)
Definition
hholder.c:68
householder_transform
double householder_transform(double *v, int N)
Definition
hholder.c:23
libtpcmodel.h
Header file for libtpcmodel.
Generated on
for TPCCLIB by
1.17.0