Skip to content

Commit bf23561

Browse files
committed
svd.c rename W param to U which it now is
1 parent 58e3e25 commit bf23561

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

lib/PDL/MatrixOps.pd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ pp_def(
658658
Pars => 'a(n,m); [o]u(minmn=CALC(PDLMIN($SIZE(m),$SIZE(n))),m); [o]s(minmn); [o]v(minmn,n);
659659
[t]w(wsize=CALC(($SIZE(m) >= $SIZE(n)) ? 0 : $SIZE(n) * $SIZE(m)));',
660660
GenericTypes => ['D'],
661-
CHeader => 'void SVD( double *W, double *V, double *Z, int nRow, int nCol );',
661+
CHeader => 'void SVD( double *U, double *V, double *Z, int nRow, int nCol );',
662662
Code => <<'EOF',
663663
char is_transpose = $SIZE(m) < $SIZE(n);
664664
broadcastloop %{

lib/PDL/MatrixOps/svd.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ Bryant
4949

5050
/*
5151
Form a singular value decomposition of matrix A which is stored in
52-
the nRow*nCol elements of working array W. Upon return, the
53-
nRow*nCol elements of W will become the product U x S of a
52+
the nRow*nCol elements of working array U. Upon return, the
53+
nRow*nCol elements of U will become the product U x S of a
5454
thin svd, where S is the diagonal vector of singular
5555
values. The passed-in V will become the square matrix
5656
V of a thin svd. On return, Z will contain the squares of the
@@ -73,7 +73,7 @@ Bryant
7373
colval1 = d1*cos0 + d2*sin0; colval2 = -d1*sin0 + d2*cos0; \
7474
}
7575

76-
void SVD(double *W, double *V, double *Z, int nRow, int nCol)
76+
void SVD(double *U, double *V, double *Z, int nRow, int nCol)
7777
{
7878
int i, j, k, EstColRank, RotCount, SweepCount, slimit;
7979
double eps, e2, tol, vt, p, x0, y0, q, r, c0, s0;
@@ -86,8 +86,7 @@ void SVD(double *W, double *V, double *Z, int nRow, int nCol)
8686
e2 = 10.0*nRow*eps*eps;
8787
tol = eps*.1; /*set convergence tolerances */
8888
EstColRank = nCol; /* current estimate of rank */
89-
/* Set V matrix to the unit matrix of order nCol.
90-
V is stored in elements nCol*nRow to nCol*(nRow+nCol)-1 of array W. */
89+
/* Set V matrix to the unit matrix of order nCol. */
9190
for (i=0; i<nCol; i++)
9291
for (j=0; j<nCol; j++)
9392
V[ nCol*i + j ] = i == j ? 1.0 : 0.0;
@@ -118,7 +117,7 @@ void SVD(double *W, double *V, double *Z, int nRow, int nCol)
118117
the matrix approaches orthogonality.
119118
*/
120119
for (i=0; i<nRow; i++) {
121-
x0 = W[nCol*i+j]; y0 = W[nCol*i+k];
120+
x0 = U[nCol*i+j]; y0 = U[nCol*i+k];
122121
p += x0*y0; q += x0*x0; r += y0*y0;
123122
}
124123
Z[j] = q; Z[k] = r;
@@ -145,7 +144,7 @@ void SVD(double *W, double *V, double *Z, int nRow, int nCol)
145144
should be positive even without the fabs. abs
146145
isn't in Nash's book. c0 and s0 are cos(phi) and sin(phi) as above for q>=0*/
147146
c0 = sqrt(fabs(.5*(1+r/vt))); s0 = p/(vt*c0);
148-
SVD_ROTATE_COL(W, j, k, i, nCol, nRow, c0, s0)
147+
SVD_ROTATE_COL(U, j, k, i, nCol, nRow, c0, s0)
149148
SVD_ROTATE_COL(V, j, k, i, nCol, nCol, c0, s0)
150149
}
151150
} else {
@@ -162,7 +161,7 @@ void SVD(double *W, double *V, double *Z, int nRow, int nCol)
162161
already */
163162
if (p<0) s0 = -s0; /*s0 and c0 are sin(phi) and cos(phi) as above for q<0 */
164163
c0 = p/(vt*s0);
165-
SVD_ROTATE_COL(W, j, k, i, nCol, nRow, c0, s0)
164+
SVD_ROTATE_COL(U, j, k, i, nCol, nRow, c0, s0)
166165
SVD_ROTATE_COL(V, j, k, i, nCol, nCol, c0, s0)
167166
}
168167
/* Both angle calculations have been set up so that

0 commit comments

Comments
 (0)