TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpclinopt
hholder.c
Go to the documentation of this file.
1
10
/*****************************************************************************/
11
#include "tpcclibConfig.h"
12
/*****************************************************************************/
13
#include <stdio.h>
14
#include <stdlib.h>
15
#include <math.h>
16
/*****************************************************************************/
17
#include "
tpcextensions.h
"
18
/*****************************************************************************/
19
#include "
tpclinopt.h
"
20
/*****************************************************************************/
21
22
/*****************************************************************************/
33
double
householder_transform
(
35
double
*v,
37
int
N
38
) {
39
double
vnorm, alpha, beta, tau;
40
int
n;
41
42
if
(N<1)
return
0.0;
// tau = 0
43
/* Euclidean norm of the vector starting from the second value */
44
vnorm=0.0;
for
(n=1; n<N; n++) vnorm+=v[n]*v[n];
45
vnorm=sqrt(vnorm);
if
(isnan(vnorm) || vnorm==0.0)
return
0.0;
// tau = 0
46
47
/* Computing the coefficient tau */
48
alpha=v[0];
49
beta= - (alpha >= 0.0 ? +1.0 : -1.0) * hypot(alpha, vnorm);
50
tau=(beta-alpha)/beta ;
51
52
/* Scale the Householder vector so that the first element will be 1.
53
* (Scaling is also affecting the coefficient tau).
54
* Without scaling, the first element would have value (alpha - beta). */
55
#if(0)
// Kaisa's version
56
{
57
double
os=1.0/(alpha-beta);
58
for
(n=1; n<N; n++) v[n]*=os;
59
v[0]=beta;
60
}
61
#else
// Vesa's version
62
{
63
double
s=alpha-beta;
64
if
(fabs(s)>DBL_MIN) {
65
v[0]=beta;
66
for
(n=1; n<N; n++) v[n]*=(1.0/s);
67
}
else
{
68
v[0]=beta;
69
for
(n=1; n<N; n++) v[n]*=(
doubleMachEps
()/s);
70
for
(n=1; n<N; n++) v[n]*=(1.0/
doubleMachEps
());
71
}
72
}
73
#endif
74
75
return
tau;
76
}
77
/*****************************************************************************/
78
79
/*****************************************************************************/
87
int
householder_hm
(
89
double
tau,
91
double
*vector,
93
double
**matrix,
95
int
rowNr,
97
int
columnNr
98
) {
99
int
i, j;
100
double
wj;
101
102
if
(tau==0.0)
return
(0);
// success
103
if
(rowNr<1 || columnNr<1)
return
(1);
104
for
(j=0; j<columnNr; j++) {
105
/* Compute wj = vk Akj */
106
wj=matrix[0][j];
107
for
(i=1; i<rowNr; i++)
/* note, computed for v(0) = 1 above */
108
wj += vector[i]*matrix[i][j];
109
/* Aij = Aij - tau vi wj */
110
/* i = 0 */
111
matrix[0][j]-=tau*wj;
112
/* i = 1 .. M-1 */
113
for
(i=1; i<rowNr; i++) matrix[i][j]-=tau*vector[i]*wj;
114
}
115
return
(0);
116
}
117
/*****************************************************************************/
118
119
/*****************************************************************************/
126
int
householder_hv
(
128
double
tau,
130
int
size,
132
double
*v,
134
double
*w
135
) {
136
int
i;
137
double
d;
138
139
if
(tau==0)
return
(0);
// success
140
if
(size<1)
return
(1);
141
/* d = v'w */
142
d=w[0];
for
(i=1; i<size; i++) d+=v[i]*w[i];
143
/* w = w - tau (v) (v'w) */
144
w[0]-=tau*d;
145
for
(i=1; i<size; i++) w[i]-=tau*v[i]*d;
146
return
(0);
147
}
148
/*****************************************************************************/
149
150
/*****************************************************************************/
155
double
householder_norm
(
157
double
*v,
159
int
size
160
) {
161
double
ss=0.0;
162
int
i;
163
164
for
(i=0; i<size; i++) ss+=v[i]*v[i];
165
return
sqrt(ss);
166
}
167
/*****************************************************************************/
168
169
/*****************************************************************************/
doubleMachEps
double doubleMachEps()
Definition
doubleutil.c:105
householder_norm
double householder_norm(double *v, int size)
Definition
hholder.c:155
householder_hv
int householder_hv(double tau, int size, double *v, double *w)
Definition
hholder.c:126
householder_hm
int householder_hm(double tau, double *vector, double **matrix, int rowNr, int columnNr)
Definition
hholder.c:87
householder_transform
double householder_transform(double *v, int N)
Definition
hholder.c:33
tpcextensions.h
Header file for library libtpcextensions.
tpclinopt.h
Header file for libtpclinopt.
Generated on
for TPCCLIB by
1.17.0