ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/math/SquareMatrix.hpp
(Generate patch)

Comparing trunk/OOPSE-3.0/src/math/SquareMatrix.hpp (file contents):
Revision 1594 by tim, Mon Oct 18 23:13:23 2004 UTC vs.
Revision 1930 by gezelter, Wed Jan 12 22:41:40 2005 UTC

# Line 1 | Line 1
1 < /*
2 < * Copyright (C) 2000-2004  Object Oriented Parallel Simulation Engine (OOPSE) project
3 < *
4 < * Contact: oopse@oopse.org
5 < *
6 < * This program is free software; you can redistribute it and/or
7 < * modify it under the terms of the GNU Lesser General Public License
8 < * as published by the Free Software Foundation; either version 2.1
9 < * of the License, or (at your option) any later version.
10 < * All we ask is that proper credit is given for our work, which includes
11 < * - but is not limited to - adding the above copyright notice to the beginning
12 < * of your source code files, and to any copyright notice that you may distribute
13 < * with programs based on this work.
14 < *
15 < * This program is distributed in the hope that it will be useful,
16 < * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 < * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 < * GNU Lesser General Public License for more details.
19 < *
20 < * You should have received a copy of the GNU Lesser General Public License
21 < * along with this program; if not, write to the Free Software
22 < * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
1 > /*
2 > * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4 + * The University of Notre Dame grants you ("Licensee") a
5 + * non-exclusive, royalty free, license to use, modify and
6 + * redistribute this software in source and binary code form, provided
7 + * that the following conditions are met:
8 + *
9 + * 1. Acknowledgement of the program authors must be made in any
10 + *    publication of scientific results based in part on use of the
11 + *    program.  An acceptable form of acknowledgement is citation of
12 + *    the article in which the program was described (Matthew
13 + *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 + *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 + *    Parallel Simulation Engine for Molecular Dynamics,"
16 + *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 + *
18 + * 2. Redistributions of source code must retain the above copyright
19 + *    notice, this list of conditions and the following disclaimer.
20 + *
21 + * 3. Redistributions in binary form must reproduce the above copyright
22 + *    notice, this list of conditions and the following disclaimer in the
23 + *    documentation and/or other materials provided with the
24 + *    distribution.
25 + *
26 + * This software is provided "AS IS," without a warranty of any
27 + * kind. All express or implied conditions, representations and
28 + * warranties, including any implied warranty of merchantability,
29 + * fitness for a particular purpose or non-infringement, are hereby
30 + * excluded.  The University of Notre Dame and its licensors shall not
31 + * be liable for any damages suffered by licensee as a result of
32 + * using, modifying or distributing the software or its
33 + * derivatives. In no event will the University of Notre Dame or its
34 + * licensors be liable for any lost revenue, profit or data, or for
35 + * direct, indirect, special, consequential, incidental or punitive
36 + * damages, however caused and regardless of the theory of liability,
37 + * arising out of the use of or inability to use software, even if the
38 + * University of Notre Dame has been advised of the possibility of
39 + * such damages.
40   */
41 <
41 >
42   /**
43   * @file SquareMatrix.hpp
44   * @author Teng Lin
45   * @date 10/11/2004
46   * @version 1.0
47   */
48 < #ifndef MATH_SQUAREMATRIX_HPP
48 > #ifndef MATH_SQUAREMATRIX_HPP
49   #define MATH_SQUAREMATRIX_HPP
50  
51   #include "math/RectMatrix.hpp"
# Line 45 | Line 61 | namespace oopse {
61      template<typename Real, int Dim>
62      class SquareMatrix : public RectMatrix<Real, Dim, Dim> {
63          public:
64 +            typedef Real ElemType;
65 +            typedef Real* ElemPoinerType;
66  
67 <        /** default constructor */
68 <        SquareMatrix() {
69 <            for (unsigned int i = 0; i < Dim; i++)
70 <                for (unsigned int j = 0; j < Dim; j++)
71 <                    data_[i][j] = 0.0;
72 <         }
67 >            /** default constructor */
68 >            SquareMatrix() {
69 >                for (unsigned int i = 0; i < Dim; i++)
70 >                    for (unsigned int j = 0; j < Dim; j++)
71 >                        data_[i][j] = 0.0;
72 >             }
73  
74 <        /** copy constructor */
75 <        SquareMatrix(const RectMatrix<Real, Dim, Dim>& m)  : RectMatrix<Real, Dim, Dim>(m) {
76 <        }
59 <        
60 <        /** copy assignment operator */
61 <        SquareMatrix<Real, Dim>& operator =(const RectMatrix<Real, Dim, Dim>& m) {
62 <            RectMatrix<Real, Dim, Dim>::operator=(m);
63 <            return *this;
64 <        }
65 <                              
66 <        /** Retunrs  an identity matrix*/
74 >            /** Constructs and initializes every element of this matrix to a scalar */
75 >            SquareMatrix(Real s) : RectMatrix<Real, Dim, Dim>(s){
76 >            }
77  
78 <       static SquareMatrix<Real, Dim> identity() {
79 <            SquareMatrix<Real, Dim> m;
78 >            /** Constructs and initializes from an array */
79 >            SquareMatrix(Real* array) : RectMatrix<Real, Dim, Dim>(array){
80 >            }
81 >
82 >
83 >            /** copy constructor */
84 >            SquareMatrix(const RectMatrix<Real, Dim, Dim>& m) : RectMatrix<Real, Dim, Dim>(m) {
85 >            }
86              
87 <            for (unsigned int i = 0; i < Dim; i++)
88 <                for (unsigned int j = 0; j < Dim; j++)
89 <                    if (i == j)
90 <                        m(i, j) = 1.0;
91 <                    else
92 <                        m(i, j) = 0.0;
87 >            /** copy assignment operator */
88 >            SquareMatrix<Real, Dim>& operator =(const RectMatrix<Real, Dim, Dim>& m) {
89 >                RectMatrix<Real, Dim, Dim>::operator=(m);
90 >                return *this;
91 >            }
92 >                                  
93 >            /** Retunrs  an identity matrix*/
94  
95 <            return m;
96 <        }
95 >           static SquareMatrix<Real, Dim> identity() {
96 >                SquareMatrix<Real, Dim> m;
97 >                
98 >                for (unsigned int i = 0; i < Dim; i++)
99 >                    for (unsigned int j = 0; j < Dim; j++)
100 >                        if (i == j)
101 >                            m(i, j) = 1.0;
102 >                        else
103 >                            m(i, j) = 0.0;
104  
105 <        /**
106 <         * Retunrs  the inversion of this matrix.
83 <         * @todo
84 <         */
85 <         SquareMatrix<Real, Dim>  inverse() {
86 <             SquareMatrix<Real, Dim> result;
105 >                return m;
106 >            }
107  
108 <             return result;
109 <        }        
108 >            /**
109 >             * Retunrs  the inversion of this matrix.
110 >             * @todo need implementation
111 >             */
112 >             SquareMatrix<Real, Dim>  inverse() {
113 >                 SquareMatrix<Real, Dim> result;
114  
115 <        /**
116 <         * Returns the determinant of this matrix.
93 <         * @todo
94 <         */
95 <        double determinant() const {
96 <            double det;
97 <            return det;
98 <        }
115 >                 return result;
116 >            }        
117  
118 <        /** Returns the trace of this matrix. */
119 <        double trace() const {
120 <           double tmp = 0;
121 <          
122 <            for (unsigned int i = 0; i < Dim ; i++)
123 <                tmp += data_[i][i];
118 >            /**
119 >             * Returns the determinant of this matrix.
120 >             * @todo need implementation
121 >             */
122 >            Real determinant() const {
123 >                Real det;
124 >                return det;
125 >            }
126  
127 <            return tmp;
128 <        }
127 >            /** Returns the trace of this matrix. */
128 >            Real trace() const {
129 >               Real tmp = 0;
130 >              
131 >                for (unsigned int i = 0; i < Dim ; i++)
132 >                    tmp += data_[i][i];
133  
134 <        /** Tests if this matrix is symmetrix. */            
135 <        bool isSymmetric() const {
112 <            for (unsigned int i = 0; i < Dim - 1; i++)
113 <                for (unsigned int j = i; j < Dim; j++)
114 <                    if (fabs(data_[i][j] - data_[j][i]) > oopse::epsilon)
115 <                        return false;
116 <                    
117 <            return true;
118 <        }
134 >                return tmp;
135 >            }
136  
137 <        /** Tests if this matrix is orthogonal. */            
138 <        bool isOrthogonal() {
139 <            SquareMatrix<Real, Dim> tmp;
137 >            /** Tests if this matrix is symmetrix. */            
138 >            bool isSymmetric() const {
139 >                for (unsigned int i = 0; i < Dim - 1; i++)
140 >                    for (unsigned int j = i; j < Dim; j++)
141 >                        if (fabs(data_[i][j] - data_[j][i]) > oopse::epsilon)
142 >                            return false;
143 >                        
144 >                return true;
145 >            }
146  
147 <            tmp = *this * transpose();
147 >            /** Tests if this matrix is orthogonal. */            
148 >            bool isOrthogonal() {
149 >                SquareMatrix<Real, Dim> tmp;
150  
151 <            return tmp.isDiagonal();
127 <        }
151 >                tmp = *this * transpose();
152  
153 <        /** Tests if this matrix is diagonal. */
154 <        bool isDiagonal() const {
131 <            for (unsigned int i = 0; i < Dim ; i++)
132 <                for (unsigned int j = 0; j < Dim; j++)
133 <                    if (i !=j && fabs(data_[i][j]) > oopse::epsilon)
134 <                        return false;
135 <                    
136 <            return true;
137 <        }
153 >                return tmp.isDiagonal();
154 >            }
155  
156 <        /** Tests if this matrix is the unit matrix. */
157 <        bool isUnitMatrix() const {
158 <            if (!isDiagonal())
159 <                return false;
160 <            
161 <            for (unsigned int i = 0; i < Dim ; i++)
162 <                if (fabs(data_[i][i] - 1) > oopse::epsilon)
156 >            /** Tests if this matrix is diagonal. */
157 >            bool isDiagonal() const {
158 >                for (unsigned int i = 0; i < Dim ; i++)
159 >                    for (unsigned int j = 0; j < Dim; j++)
160 >                        if (i !=j && fabs(data_[i][j]) > oopse::epsilon)
161 >                            return false;
162 >                        
163 >                return true;
164 >            }
165 >
166 >            /** Tests if this matrix is the unit matrix. */
167 >            bool isUnitMatrix() const {
168 >                if (!isDiagonal())
169                      return false;
170                  
171 <            return true;
172 <        }        
171 >                for (unsigned int i = 0; i < Dim ; i++)
172 >                    if (fabs(data_[i][i] - 1) > oopse::epsilon)
173 >                        return false;
174 >                    
175 >                return true;
176 >            }        
177  
178 <        /** @todo need implement */
179 <        void diagonalize() {
180 <            //jacobi(m, eigenValues, ortMat);
154 <        }
155 <
156 <        /**
157 <         * Finds the eigenvalues and eigenvectors of a symmetric matrix
158 <         * @param eigenvals a reference to a vector3 where the
159 <         * eigenvalues will be stored. The eigenvalues are ordered so
160 <         * that eigenvals[0] <= eigenvals[1] <= eigenvals[2].
161 <         * @return an orthogonal matrix whose ith column is an
162 <         * eigenvector for the eigenvalue eigenvals[i]
163 <         */
164 <        SquareMatrix<Real, Dim>  findEigenvectors(Vector<Real, Dim>& eigenValues) {
165 <            SquareMatrix<Real, Dim> ortMat;
166 <            
167 <            if ( !isSymmetric()){
168 <                throw();
178 >            /** @todo need implementation */
179 >            void diagonalize() {
180 >                //jacobi(m, eigenValues, ortMat);
181              }
170            
171            SquareMatrix<Real, Dim> m(*this);
172            jacobi(m, eigenValues, ortMat);
182  
183 <            return ortMat;
184 <        }
185 <        /**
186 <         * Jacobi iteration routines for computing eigenvalues/eigenvectors of
187 <         * real symmetric matrix
188 <         *
189 <         * @return true if success, otherwise return false
190 <         * @param a source matrix
191 <         * @param w output eigenvalues
192 <         * @param v output eigenvectors
193 <         */
194 <        bool jacobi(const SquareMatrix<Real, Dim>& a, Vector<Real, Dim>& w,
195 <                              SquareMatrix<Real, Dim>& v);
183 >            /**
184 >             * Jacobi iteration routines for computing eigenvalues/eigenvectors of
185 >             * real symmetric matrix
186 >             *
187 >             * @return true if success, otherwise return false
188 >             * @param a symmetric matrix whose eigenvectors are to be computed. On return, the matrix is
189 >             *     overwritten
190 >             * @param w will contain the eigenvalues of the matrix On return of this function
191 >             * @param v the columns of this matrix will contain the eigenvectors. The eigenvectors are
192 >             *    normalized and mutually orthogonal.
193 >             */
194 >          
195 >            static int jacobi(SquareMatrix<Real, Dim>& a, Vector<Real, Dim>& d,
196 >                                  SquareMatrix<Real, Dim>& v);
197      };//end SquareMatrix
198  
199  
200 < #define ROT(a,i,j,k,l) g=a(i, j);h=a(k, l);a(i, j)=g-s*(h+g*tau);a(k, l)=h+s*(g-h*tau)
191 < #define MAX_ROTATIONS 60
200 > /*=========================================================================
201  
202 < template<typename Real, int Dim>
203 < bool SquareMatrix<Real, Dim>::jacobi(const SquareMatrix<Real, Dim>& a, Vector<Real, Dim>& w,
195 <                              SquareMatrix<Real, Dim>& v) {
196 <    const int N = Dim;                                                                      
197 <    int i, j, k, iq, ip;
198 <    double tresh, theta, tau, t, sm, s, h, g, c;
199 <    double tmp;
200 <    Vector<Real, Dim> b, z;
202 >  Program:   Visualization Toolkit
203 >  Module:    $RCSfile: SquareMatrix.hpp,v $
204  
205 <    // initialize
206 <    for (ip=0; ip<N; ip++) {
207 <        for (iq=0; iq<N; iq++)
205 <            v(ip, iq) = 0.0;
206 <        v(ip, ip) = 1.0;
207 <    }
208 <    
209 <    for (ip=0; ip<N; ip++) {
210 <        b(ip) = w(ip) = a(ip, ip);
211 <        z(ip) = 0.0;
212 <    }
205 >  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
206 >  All rights reserved.
207 >  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
208  
209 <    // begin rotation sequence
210 <    for (i=0; i<MAX_ROTATIONS; i++) {
211 <        sm = 0.0;
212 <        for (ip=0; ip<2; ip++) {
213 <            for (iq=ip+1; iq<N; iq++)
214 <                sm += fabs(a(ip, iq));
209 >     This software is distributed WITHOUT ANY WARRANTY; without even
210 >     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
211 >     PURPOSE.  See the above copyright notice for more information.
212 >
213 > =========================================================================*/
214 >
215 > #define VTK_ROTATE(a,i,j,k,l) g=a(i, j);h=a(k, l);a(i, j)=g-s*(h+g*tau);\
216 >        a(k, l)=h+s*(g-h*tau)
217 >
218 > #define VTK_MAX_ROTATIONS 20
219 >
220 >    // Jacobi iteration for the solution of eigenvectors/eigenvalues of a nxn
221 >    // real symmetric matrix. Square nxn matrix a; size of matrix in n;
222 >    // output eigenvalues in w; and output eigenvectors in v. Resulting
223 >    // eigenvalues/vectors are sorted in decreasing order; eigenvectors are
224 >    // normalized.
225 >    template<typename Real, int Dim>
226 >    int SquareMatrix<Real, Dim>::jacobi(SquareMatrix<Real, Dim>& a, Vector<Real, Dim>& w,
227 >                                        SquareMatrix<Real, Dim>& v) {
228 >        const int n = Dim;  
229 >        int i, j, k, iq, ip, numPos;
230 >        Real tresh, theta, tau, t, sm, s, h, g, c, tmp;
231 >        Real bspace[4], zspace[4];
232 >        Real *b = bspace;
233 >        Real *z = zspace;
234 >
235 >        // only allocate memory if the matrix is large
236 >        if (n > 4) {
237 >            b = new Real[n];
238 >            z = new Real[n];
239          }
221        
222        if (sm == 0.0)
223            break;
240  
241 <        if (i < 4)
242 <            tresh = 0.2*sm/(9);
243 <        else
244 <            tresh = 0.0;
241 >        // initialize
242 >        for (ip=0; ip<n; ip++) {
243 >            for (iq=0; iq<n; iq++) {
244 >                v(ip, iq) = 0.0;
245 >            }
246 >            v(ip, ip) = 1.0;
247 >        }
248 >        for (ip=0; ip<n; ip++) {
249 >            b[ip] = w[ip] = a(ip, ip);
250 >            z[ip] = 0.0;
251 >        }
252  
253 <        for (ip=0; ip<2; ip++) {
254 <            for (iq=ip+1; iq<N; iq++) {
255 <                g = 100.0*fabs(a(ip, iq));
256 <                if (i > 4 && (fabs(w(ip))+g) == fabs(w(ip))
257 <                    && (fabs(w(iq))+g) == fabs(w(iq))) {
258 <                    a(ip, iq) = 0.0;
259 <                } else if (fabs(a(ip, iq)) > tresh) {
260 <                    h = w(iq) - w(ip);
261 <                    if ( (fabs(h)+g) == fabs(h)) {
262 <                        t = (a(ip, iq)) / h;
263 <                    } else {
241 <                        theta = 0.5*h / (a(ip, iq));
242 <                        t = 1.0 / (fabs(theta)+sqrt(1.0+theta*theta));
253 >        // begin rotation sequence
254 >        for (i=0; i<VTK_MAX_ROTATIONS; i++) {
255 >            sm = 0.0;
256 >            for (ip=0; ip<n-1; ip++) {
257 >                for (iq=ip+1; iq<n; iq++) {
258 >                    sm += fabs(a(ip, iq));
259 >                }
260 >            }
261 >            if (sm == 0.0) {
262 >                break;
263 >            }
264  
265 <                        if (theta < 0.0)
266 <                            t = -t;
267 <                    }
265 >            if (i < 3) {                                // first 3 sweeps
266 >                tresh = 0.2*sm/(n*n);
267 >            } else {
268 >                tresh = 0.0;
269 >            }
270  
271 <                    c = 1.0 / sqrt(1+t*t);
272 <                    s = t*c;
273 <                    tau = s/(1.0+c);
251 <                    h = t*a(ip, iq);
252 <                    z(ip) -= h;
253 <                    z(iq) += h;
254 <                    w(ip) -= h;
255 <                    w(iq) += h;
256 <                    a(ip, iq)=0.0;
257 <                    
258 <                    for (j=0;j<ip-1;j++)
259 <                        ROT(a,j,ip,j,iq);
271 >            for (ip=0; ip<n-1; ip++) {
272 >                for (iq=ip+1; iq<n; iq++) {
273 >                    g = 100.0*fabs(a(ip, iq));
274  
275 <                    for (j=ip+1;j<iq-1;j++)
276 <                        ROT(a,ip,j,j,iq);
275 >                    // after 4 sweeps
276 >                    if (i > 3 && (fabs(w[ip])+g) == fabs(w[ip])
277 >                        && (fabs(w[iq])+g) == fabs(w[iq])) {
278 >                        a(ip, iq) = 0.0;
279 >                    } else if (fabs(a(ip, iq)) > tresh) {
280 >                        h = w[iq] - w[ip];
281 >                        if ( (fabs(h)+g) == fabs(h)) {
282 >                            t = (a(ip, iq)) / h;
283 >                        } else {
284 >                            theta = 0.5*h / (a(ip, iq));
285 >                            t = 1.0 / (fabs(theta)+sqrt(1.0+theta*theta));
286 >                            if (theta < 0.0) {
287 >                                t = -t;
288 >                            }
289 >                        }
290 >                        c = 1.0 / sqrt(1+t*t);
291 >                        s = t*c;
292 >                        tau = s/(1.0+c);
293 >                        h = t*a(ip, iq);
294 >                        z[ip] -= h;
295 >                        z[iq] += h;
296 >                        w[ip] -= h;
297 >                        w[iq] += h;
298 >                        a(ip, iq)=0.0;
299  
300 <                    for (j=iq+1; j<N; j++)
301 <                        ROT(a,ip,j,iq,j);
302 <                    
303 <                    for (j=0; j<N; j++)
304 <                        ROT(v,j,ip,j,iq);
300 >                        // ip already shifted left by 1 unit
301 >                        for (j = 0;j <= ip-1;j++) {
302 >                            VTK_ROTATE(a,j,ip,j,iq);
303 >                        }
304 >                        // ip and iq already shifted left by 1 unit
305 >                        for (j = ip+1;j <= iq-1;j++) {
306 >                            VTK_ROTATE(a,ip,j,j,iq);
307 >                        }
308 >                        // iq already shifted left by 1 unit
309 >                        for (j=iq+1; j<n; j++) {
310 >                            VTK_ROTATE(a,ip,j,iq,j);
311 >                        }
312 >                        for (j=0; j<n; j++) {
313 >                            VTK_ROTATE(v,j,ip,j,iq);
314 >                        }
315 >                    }
316                  }
317              }
271        }//for (ip=0; ip<2; ip++)
318  
319 <        for (ip=0; ip<N; ip++) {
320 <            b(ip) += z(ip);
321 <            w(ip) = b(ip);
322 <            z(ip) = 0.0;
319 >            for (ip=0; ip<n; ip++) {
320 >                b[ip] += z[ip];
321 >                w[ip] = b[ip];
322 >                z[ip] = 0.0;
323 >            }
324          }
278        
279    } // end for (i=0; i<MAX_ROTATIONS; i++)
325  
326 <    if ( i >= MAX_ROTATIONS )
327 <        return false;
326 >        //// this is NEVER called
327 >        if ( i >= VTK_MAX_ROTATIONS ) {
328 >            std::cout << "vtkMath::Jacobi: Error extracting eigenfunctions" << std::endl;
329 >            return 0;
330 >        }
331  
332 <    // sort eigenfunctions
333 <    for (j=0; j<N; j++) {
334 <        k = j;
335 <        tmp = w(k);
336 <        for (i=j; i<N; i++) {
337 <            if (w(i) >= tmp) {
338 <            k = i;
339 <            tmp = w(k);
332 >        // sort eigenfunctions                 these changes do not affect accuracy
333 >        for (j=0; j<n-1; j++) {                  // boundary incorrect
334 >            k = j;
335 >            tmp = w[k];
336 >            for (i=j+1; i<n; i++) {                // boundary incorrect, shifted already
337 >                if (w[i] >= tmp) {                   // why exchage if same?
338 >                    k = i;
339 >                    tmp = w[k];
340 >                }
341              }
342 +            if (k != j) {
343 +                w[k] = w[j];
344 +                w[j] = tmp;
345 +                for (i=0; i<n; i++) {
346 +                    tmp = v(i, j);
347 +                    v(i, j) = v(i, k);
348 +                    v(i, k) = tmp;
349 +                }
350 +            }
351          }
352 <    
353 <        if (k != j) {
354 <            w(k) = w(j);
355 <            w(j) = tmp;
356 <            for (i=0; i<N; i++)  {
357 <                tmp = v(i, j);
358 <                v(i, j) = v(i, k);
359 <                v(i, k) = tmp;
352 >        // insure eigenvector consistency (i.e., Jacobi can compute vectors that
353 >        // are negative of one another (.707,.707,0) and (-.707,-.707,0). This can
354 >        // reek havoc in hyperstreamline/other stuff. We will select the most
355 >        // positive eigenvector.
356 >        int ceil_half_n = (n >> 1) + (n & 1);
357 >        for (j=0; j<n; j++) {
358 >            for (numPos=0, i=0; i<n; i++) {
359 >                if ( v(i, j) >= 0.0 ) {
360 >                    numPos++;
361 >                }
362              }
363 +            //    if ( numPos < ceil(double(n)/double(2.0)) )
364 +            if ( numPos < ceil_half_n) {
365 +                for (i=0; i<n; i++) {
366 +                    v(i, j) *= -1.0;
367 +                }
368 +            }
369          }
304    }
370  
371 <    //    insure eigenvector consistency (i.e., Jacobi can compute
372 <    //    vectors that are negative of one another (.707,.707,0) and
373 <    //    (-.707,-.707,0). This can reek havoc in
374 <    //    hyperstreamline/other stuff. We will select the most
375 <    //    positive eigenvector.
311 <    int numPos;
312 <    for (j=0; j<N; j++) {
313 <        for (numPos=0, i=0; i<N; i++) if ( v(i, j) >= 0.0 ) numPos++;
314 <        if ( numPos < 2 ) for(i=0; i<N; i++) v(i, j) *= -1.0;
371 >        if (n > 4) {
372 >            delete [] b;
373 >            delete [] z;
374 >        }
375 >        return 1;
376      }
377  
317    return true;
318 }
378  
320 #undef ROT
321 #undef MAX_ROTATIONS
322
379   }
324
380   #endif //MATH_SQUAREMATRIX_HPP
381 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines