53 #define PYTHAG(a,b) ((at=fabs(a)) > (bt=fabs(b)) ? \ 54 (ct=bt/at,at*sqrt(SVD_FLOAT(1.0f)+ct*ct)) : (bt ? (ct=at/bt,bt*sqrt(SVD_FLOAT(1.0f)+ct*ct)): SVD_FLOAT(0.0))) 56 #define MAX(a,b) (maxarg1=(a),maxarg2=(b),(maxarg1) > (maxarg2) ? (maxarg1) : (maxarg2)) 58 #define SIGN(a,b) ((b) >= SVD_FLOAT(0.0f) ? fabs(a) : -fabs(a)) 61 int svdcmp(
double **a,
int m,
int n,
double *w,
double **v)
63 int flag,i,its,j,jj,k,ii=0,nm=0;
64 SVD_FLOAT c,
f,h,
s,
x,
y,
z;
65 SVD_FLOAT anorm=0.0,g=0.0,scale=0.0;
80 for (k=i;k<=m;k++) scale += (SVD_FLOAT)fabs(a[k][i]);
92 for (s=0.0,k=i;k<=m;k++) s += a[k][i]*a[k][j];
94 for (k=i;k<=m;k++) a[k][j] += (SVD_FLOAT)(f)*a[k][i];
97 for (k=i;k<=m;k++) a[k][i] *= (SVD_FLOAT)(scale);
102 if (i <= m && i != n) {
103 for (k=ii;k<=n;k++) scale += fabs(a[i][k]);
105 for (k=ii;k<=n;k++) {
107 s += a[i][k]*a[i][k];
110 g = -
SIGN(sqrt(s),f);
113 for (k=ii;k<=n;k++) rv1[k]=a[i][k]/h;
115 for (j=ii;j<=m;j++) {
116 for (s=0.0,k=ii;k<=n;k++) s += a[j][k]*a[i][k];
117 for (k=ii;k<=n;k++) a[j][k] += s*rv1[k];
120 for (k=ii;k<=n;k++) a[i][k] *= scale;
123 anorm=
MAX(anorm,(fabs(w[i])+fabs(rv1[i])));
129 v[j][i]=(a[i][j]/a[i][ii])/g;
130 for (j=ii;j<=n;j++) {
131 for (s=0.0,k=ii;k<=n;k++) s += a[i][k]*v[k][j];
132 for (k=ii;k<=n;k++) v[k][j] += s*v[k][i];
135 for (j=ii;j<=n;j++) v[i][j]=v[j][i]=0.0;
145 for (j=ii;j<=n;j++) a[i][j]=0.0;
149 for (j=ii;j<=n;j++) {
150 for (s=0.0,k=ii;k<=m;k++) s += a[k][i]*a[k][j];
152 for (k=i;k<=m;k++) a[k][j] += f*a[k][i];
155 for (j=i;j<=m;j++) a[j][i] *= g;
157 for (j=i;j<=m;j++) a[j][i]=0.0;
162 for (its=1;its<=30;its++) {
164 for (ii=k;ii>=0;ii--) {
166 if (fabs(rv1[ii])+anorm == anorm) {
170 if (fabs(w[nm])+anorm == anorm)
break;
175 for (i=ii;i<=k;i++) {
177 if (fabs(f)+anorm != anorm) {
197 for (j=0;j<=n;j++) v[j][k]=(-v[j][k]);
201 if (its == 30)
return -2;
207 f=((y-z)*(y+z)+(g-h)*(g+h))/(
SVD_FLOAT(2.0)*h*y);
209 f=((x-z)*(x+z)+h*((y/(f+
SIGN(g,f)))-h))/x;
211 for (j=ii;j<=nm;j++) {
225 for (jj=0;jj<=n;jj++) {
240 for (jj=0;jj<=m;jj++) {
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & z() const
int svdcmp(double **a, int m, int n, double *w, double **v)