Code cleanup: "0.0" -> "0", "1.0" -> "1".
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1157288 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
64787dc2ec
commit
58faa3eeb7
|
@ -96,20 +96,20 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
for (int i = k; i < m; i++) {
|
for (int i = k; i < m; i++) {
|
||||||
singularValues[k] = FastMath.hypot(singularValues[k], A[i][k]);
|
singularValues[k] = FastMath.hypot(singularValues[k], A[i][k]);
|
||||||
}
|
}
|
||||||
if (singularValues[k] != 0.0) {
|
if (singularValues[k] != 0) {
|
||||||
if (A[k][k] < 0.0) {
|
if (A[k][k] < 0) {
|
||||||
singularValues[k] = -singularValues[k];
|
singularValues[k] = -singularValues[k];
|
||||||
}
|
}
|
||||||
for (int i = k; i < m; i++) {
|
for (int i = k; i < m; i++) {
|
||||||
A[i][k] /= singularValues[k];
|
A[i][k] /= singularValues[k];
|
||||||
}
|
}
|
||||||
A[k][k] += 1.0;
|
A[k][k] += 1;
|
||||||
}
|
}
|
||||||
singularValues[k] = -singularValues[k];
|
singularValues[k] = -singularValues[k];
|
||||||
}
|
}
|
||||||
for (int j = k + 1; j < n; j++) {
|
for (int j = k + 1; j < n; j++) {
|
||||||
if (k < nct &&
|
if (k < nct &&
|
||||||
singularValues[k] != 0.0) {
|
singularValues[k] != 0) {
|
||||||
// Apply the transformation.
|
// Apply the transformation.
|
||||||
double t = 0;
|
double t = 0;
|
||||||
for (int i = k; i < m; i++) {
|
for (int i = k; i < m; i++) {
|
||||||
|
@ -139,21 +139,21 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
for (int i = k + 1; i < n; i++) {
|
for (int i = k + 1; i < n; i++) {
|
||||||
e[k] = FastMath.hypot(e[k], e[i]);
|
e[k] = FastMath.hypot(e[k], e[i]);
|
||||||
}
|
}
|
||||||
if (e[k] != 0.0) {
|
if (e[k] != 0) {
|
||||||
if (e[k + 1] < 0.0) {
|
if (e[k + 1] < 0) {
|
||||||
e[k] = -e[k];
|
e[k] = -e[k];
|
||||||
}
|
}
|
||||||
for (int i = k + 1; i < n; i++) {
|
for (int i = k + 1; i < n; i++) {
|
||||||
e[i] /= e[k];
|
e[i] /= e[k];
|
||||||
}
|
}
|
||||||
e[k + 1] += 1.0;
|
e[k + 1] += 1;
|
||||||
}
|
}
|
||||||
e[k] = -e[k];
|
e[k] = -e[k];
|
||||||
if (k + 1 < m &&
|
if (k + 1 < m &&
|
||||||
e[k] != 0) {
|
e[k] != 0) {
|
||||||
// Apply the transformation.
|
// Apply the transformation.
|
||||||
for (int i = k + 1; i < m; i++) {
|
for (int i = k + 1; i < m; i++) {
|
||||||
work[i] = 0.0;
|
work[i] = 0;
|
||||||
}
|
}
|
||||||
for (int j = k + 1; j < n; j++) {
|
for (int j = k + 1; j < n; j++) {
|
||||||
for (int i = k + 1; i < m; i++) {
|
for (int i = k + 1; i < m; i++) {
|
||||||
|
@ -181,22 +181,22 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
singularValues[nct] = A[nct][nct];
|
singularValues[nct] = A[nct][nct];
|
||||||
}
|
}
|
||||||
if (m < p) {
|
if (m < p) {
|
||||||
singularValues[p - 1] = 0.0;
|
singularValues[p - 1] = 0;
|
||||||
}
|
}
|
||||||
if (nrt + 1 < p) {
|
if (nrt + 1 < p) {
|
||||||
e[nrt] = A[nrt][p - 1];
|
e[nrt] = A[nrt][p - 1];
|
||||||
}
|
}
|
||||||
e[p - 1] = 0.0;
|
e[p - 1] = 0;
|
||||||
|
|
||||||
// Generate U.
|
// Generate U.
|
||||||
for (int j = nct; j < n; j++) {
|
for (int j = nct; j < n; j++) {
|
||||||
for (int i = 0; i < m; i++) {
|
for (int i = 0; i < m; i++) {
|
||||||
U[i][j] = 0.0;
|
U[i][j] = 0;
|
||||||
}
|
}
|
||||||
U[j][j] = 1.0;
|
U[j][j] = 1;
|
||||||
}
|
}
|
||||||
for (int k = nct - 1; k >= 0; k--) {
|
for (int k = nct - 1; k >= 0; k--) {
|
||||||
if (singularValues[k] != 0.0) {
|
if (singularValues[k] != 0) {
|
||||||
for (int j = k + 1; j < n; j++) {
|
for (int j = k + 1; j < n; j++) {
|
||||||
double t = 0;
|
double t = 0;
|
||||||
for (int i = k; i < m; i++) {
|
for (int i = k; i < m; i++) {
|
||||||
|
@ -210,15 +210,15 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
for (int i = k; i < m; i++) {
|
for (int i = k; i < m; i++) {
|
||||||
U[i][k] = -U[i][k];
|
U[i][k] = -U[i][k];
|
||||||
}
|
}
|
||||||
U[k][k] = 1.0 + U[k][k];
|
U[k][k] = 1 + U[k][k];
|
||||||
for (int i = 0; i < k - 1; i++) {
|
for (int i = 0; i < k - 1; i++) {
|
||||||
U[i][k] = 0.0;
|
U[i][k] = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < m; i++) {
|
for (int i = 0; i < m; i++) {
|
||||||
U[i][k] = 0.0;
|
U[i][k] = 0;
|
||||||
}
|
}
|
||||||
U[k][k] = 1.0;
|
U[k][k] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,9 +238,9 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
V[i][k] = 0.0;
|
V[i][k] = 0;
|
||||||
}
|
}
|
||||||
V[k][k] = 1.0;
|
V[k][k] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main iteration loop for the singular values.
|
// Main iteration loop for the singular values.
|
||||||
|
@ -266,7 +266,7 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
= TINY + EPS * (FastMath.abs(singularValues[k]) +
|
= TINY + EPS * (FastMath.abs(singularValues[k]) +
|
||||||
FastMath.abs(singularValues[k + 1]));
|
FastMath.abs(singularValues[k + 1]));
|
||||||
if (FastMath.abs(e[k]) <= threshold) {
|
if (FastMath.abs(e[k]) <= threshold) {
|
||||||
e[k] = 0.0;
|
e[k] = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,10 +278,10 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
if (ks == k) {
|
if (ks == k) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
final double t = (ks != p ? FastMath.abs(e[ks]) : 0.0) +
|
final double t = (ks != p ? FastMath.abs(e[ks]) : 0) +
|
||||||
(ks != k + 1 ? FastMath.abs(e[ks - 1]) : 0.0);
|
(ks != k + 1 ? FastMath.abs(e[ks - 1]) : 0);
|
||||||
if (FastMath.abs(singularValues[ks]) <= TINY + EPS * t) {
|
if (FastMath.abs(singularValues[ks]) <= TINY + EPS * t) {
|
||||||
singularValues[ks] = 0.0;
|
singularValues[ks] = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
// Deflate negligible s(p).
|
// Deflate negligible s(p).
|
||||||
case 1: {
|
case 1: {
|
||||||
double f = e[p - 2];
|
double f = e[p - 2];
|
||||||
e[p - 2] = 0.0;
|
e[p - 2] = 0;
|
||||||
for (int j = p - 2; j >= k; j--) {
|
for (int j = p - 2; j >= k; j--) {
|
||||||
double t = FastMath.hypot(singularValues[j], f);
|
double t = FastMath.hypot(singularValues[j], f);
|
||||||
final double cs = singularValues[j] / t;
|
final double cs = singularValues[j] / t;
|
||||||
|
@ -322,7 +322,7 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
// Split at negligible s(k).
|
// Split at negligible s(k).
|
||||||
case 2: {
|
case 2: {
|
||||||
double f = e[k - 1];
|
double f = e[k - 1];
|
||||||
e[k - 1] = 0.0;
|
e[k - 1] = 0;
|
||||||
for (int j = k; j < p; j++) {
|
for (int j = k; j < p; j++) {
|
||||||
double t = FastMath.hypot(singularValues[j], f);
|
double t = FastMath.hypot(singularValues[j], f);
|
||||||
final double cs = singularValues[j] / t;
|
final double cs = singularValues[j] / t;
|
||||||
|
@ -352,11 +352,11 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
final double ek = e[k] / scale;
|
final double ek = e[k] / scale;
|
||||||
final double b = ((spm1 + sp) * (spm1 - sp) + epm1 * epm1) / 2.0;
|
final double b = ((spm1 + sp) * (spm1 - sp) + epm1 * epm1) / 2.0;
|
||||||
final double c = (sp * epm1) * (sp * epm1);
|
final double c = (sp * epm1) * (sp * epm1);
|
||||||
double shift = 0.0;
|
double shift = 0;
|
||||||
if (b != 0 ||
|
if (b != 0 ||
|
||||||
c != 0) {
|
c != 0) {
|
||||||
shift = FastMath.sqrt(b * b + c);
|
shift = FastMath.sqrt(b * b + c);
|
||||||
if (b < 0.0) {
|
if (b < 0) {
|
||||||
shift = -shift;
|
shift = -shift;
|
||||||
}
|
}
|
||||||
shift = c / (b + shift);
|
shift = c / (b + shift);
|
||||||
|
@ -404,8 +404,8 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
|
||||||
// Convergence.
|
// Convergence.
|
||||||
default: {
|
default: {
|
||||||
// Make the singular values positive.
|
// Make the singular values positive.
|
||||||
if (singularValues[k] <= 0.0) {
|
if (singularValues[k] <= 0) {
|
||||||
singularValues[k] = singularValues[k] < 0.0 ? -singularValues[k] : 0.0;
|
singularValues[k] = singularValues[k] < 0 ? -singularValues[k] : 0;
|
||||||
|
|
||||||
for (int i = 0; i <= pp; i++) {
|
for (int i = 0; i <= pp; i++) {
|
||||||
V[i][k] = -V[i][k];
|
V[i][k] = -V[i][k];
|
||||||
|
|
Loading…
Reference in New Issue