33
44#include " tnt.h"
55#include < algorithm>
6- #include " v_detail.h"
76using namespace TNT ;
87using namespace std ;
98
@@ -82,16 +81,16 @@ class LU
8281 // Outer loop.
8382
8483 for (int j = 0 ; j < n; j++) {
85- int i;
84+
8685 // Make a copy of the j-th column to localize references.
8786
88- for ( i = 0 ; i < m; i++) {
87+ for (int i = 0 ; i < m; i++) {
8988 LUcolj[i] = LU_[i][j];
9089 }
9190
9291 // Apply previous transformations.
9392
94- for ( i = 0 ; i < m; i++) {
93+ for (int i = 0 ; i < m; i++) {
9594 LUrowi = LU_[i];
9695
9796 // Most of the time is spent in the following dot product.
@@ -108,8 +107,8 @@ class LU
108107 // Find pivot and exchange if necessary.
109108
110109 int p = j;
111- for ( i = j+1 ; i < m; i++) {
112- if (fabs (LUcolj[i]) > fabs (LUcolj[p])) {
110+ for (int i = j+1 ; i < m; i++) {
111+ if (abs (LUcolj[i]) > abs (LUcolj[p])) {
113112 p = i;
114113 }
115114 }
@@ -128,7 +127,7 @@ class LU
128127
129128 // Compute multipliers.
130129
131- if ( (j < m) && noZero (LU_[j][j]) ) {
130+ if ( (j < m) && (LU_[j][j] != 0.0 ) ) {
132131 for (int ii = j+1 ; ii < m; ii++) {
133132 LU_[ii][j] /= LU_[j][j];
134133 }
@@ -144,7 +143,7 @@ class LU
144143
145144 int isNonsingular () {
146145 for (int j = 0 ; j < n; j++) {
147- if ( approximatelyZero ( LU_[j][j] ) )
146+ if (LU_[j][j] == 0 )
148147 return 0 ;
149148 }
150149 return 1 ;
@@ -270,7 +269,7 @@ class LU
270269
271270 Array1D<Real> solve (const Array1D<Real> &b)
272271 {
273- int k;
272+
274273 /* Dimensions: A is mxn, X is nxk, B is mxk */
275274
276275 if (b.dim1 () != m) {
@@ -284,14 +283,14 @@ class LU
284283 Array1D<Real> x = permute_copy (b, piv1);
285284
286285 // Solve L*Y = B(piv)
287- for ( k = 0 ; k < n; k++) {
286+ for (int k = 0 ; k < n; k++) {
288287 for (int i = k+1 ; i < n; i++) {
289288 x[i] -= x[k]*LU_[i][k];
290289 }
291290 }
292291
293292 // Solve U*X = Y;
294- for ( k = n-1 ; k >= 0 ; k--) {
293+ for (int k = n-1 ; k >= 0 ; k--) {
295294 x[k] /= LU_[k][k];
296295 for (int i = 0 ; i < k; i++)
297296 x[i] -= x[k]*LU_[i][k];
0 commit comments