Show
Ignore:
Timestamp:
11/25/09 12:14:38 (15 years ago)
Author:
mido
Message:

ASTYLER RUN OVER THE WHOLE LIBRARY, JUPEE

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/itpp_ext.cpp

    r723 r737  
    1818// from  algebra/lapack.h 
    1919 
    20 extern "C"    /* QR factorization of a general matrix A  */ 
    21 { 
    22         void dgeqrf_ (int *m, int *n, double *a, int *lda, double *tau, double *work, 
    23                       int *lwork, int *info); 
    24 }; 
    25  
    26 namespace itpp 
    27 { 
    28         vec empty_vec = vec(0); 
    29          
    30 Array<int> to_Arr (const ivec &indices) 
    31 { 
    32         Array<int> a (indices.size()); 
    33         for (int i = 0; i < a.size(); i++) { 
    34                 a (i) = indices (i); 
     20extern "C" {  /* QR factorization of a general matrix A  */ 
     21        void dgeqrf_ ( int *m, int *n, double *a, int *lda, double *tau, double *work, 
     22        int *lwork, int *info ); 
     23}; 
     24 
     25namespace itpp { 
     26vec empty_vec = vec ( 0 ); 
     27 
     28Array<int> to_Arr ( const ivec &indices ) { 
     29        Array<int> a ( indices.size() ); 
     30        for ( int i = 0; i < a.size(); i++ ) { 
     31                a ( i ) = indices ( i ); 
    3532        } 
    3633        return a; 
    3734} 
    3835 
    39 ivec linspace (int from, int to) 
    40 { 
     36ivec linspace ( int from, int to ) { 
    4137        int n = to - from + 1; 
    4238        int i; 
    43         it_assert_debug (n > 0, "wrong linspace"); 
    44         ivec iv (n); 
    45         for (i = 0; i < n; i++) iv (i) = from + i; 
     39        it_assert_debug ( n > 0, "wrong linspace" ); 
     40        ivec iv ( n ); 
     41        for ( i = 0; i < n; i++ ) iv ( i ) = from + i; 
    4642        return iv; 
    4743}; 
    4844 
    49 void set_subvector (vec &ov, const ivec &iv, const vec &v) 
    50 { 
    51         it_assert_debug ( (iv.length() <= v.length()), 
     45void set_subvector ( vec &ov, const ivec &iv, const vec &v ) { 
     46        it_assert_debug ( ( iv.length() <= v.length() ), 
    5247                          "Vec<>::set_subvector(ivec, vec<Num_T>): Indexing out " 
    53                           "of range of v"); 
    54         for (int i = 0; i < iv.length(); i++) { 
    55                 it_assert_debug (iv (i) < ov.length(), 
    56                                  "Vec<>::set_subvector(ivec, vec<Num_T>): Indexing out " 
    57                                  "of range of v"); 
    58                 ov (iv (i)) = v (i); 
    59         } 
    60 } 
    61  
    62 vec get_vec (const vec &v, const ivec &indexlist) 
    63 { 
     48                          "of range of v" ); 
     49        for ( int i = 0; i < iv.length(); i++ ) { 
     50                it_assert_debug ( iv ( i ) < ov.length(), 
     51                                  "Vec<>::set_subvector(ivec, vec<Num_T>): Indexing out " 
     52                                  "of range of v" ); 
     53                ov ( iv ( i ) ) = v ( i ); 
     54        } 
     55} 
     56 
     57vec get_vec ( const vec &v, const ivec &indexlist ) { 
    6458        int size = indexlist.size(); 
    65         vec temp (size); 
    66         for (int i = 0; i < size; ++i) { 
    67                 temp (i) = v._data() [indexlist (i) ]; 
     59        vec temp ( size ); 
     60        for ( int i = 0; i < size; ++i ) { 
     61                temp ( i ) = v._data() [indexlist ( i ) ]; 
    6862        } 
    6963        return temp; 
     
    7670#define R_FINITE std::isfinite 
    7771 
    78 bvec operator> (const vec &t1, const vec &t2) 
    79 { 
    80         it_assert_debug (t1.length() == t2.length(), "Vec<>::operator>(): different size of vectors"); 
    81         bvec temp (t1.length()); 
    82         for (int i = 0; i < t1.length(); i++) 
    83                 temp (i) = (t1[i] > t2[i]); 
    84         return temp; 
    85 } 
    86  
    87 bvec operator< (const vec &t1, const vec &t2) 
    88 { 
    89         it_assert_debug (t1.length() == t2.length(), "Vec<>::operator>(): different size of vectors"); 
    90         bvec temp (t1.length()); 
    91         for (int i = 0; i < t1.length(); i++) 
    92                 temp (i) = (t1[i] < t2[i]); 
    93         return temp; 
    94 } 
    95  
    96  
    97 bvec operator& (const bvec &a, const bvec &b) 
    98 { 
    99         it_assert_debug (b.size() == a.size(), "operator&(): Vectors of different lengths"); 
    100  
    101         bvec temp (a.size()); 
    102         for (int i = 0; i < a.size(); i++) { 
    103                 temp (i) = a (i) & b (i); 
    104         } 
    105         return temp; 
    106 } 
    107  
    108 bvec operator| (const bvec &a, const bvec &b) 
    109 { 
    110         it_assert_debug (b.size() == a.size(), "operator|(): Vectors of different lengths"); 
    111  
    112         bvec temp (a.size()); 
    113         for (int i = 0; i < a.size(); i++) { 
    114                 temp (i) = a (i) | b (i); 
     72bvec operator> ( const vec &t1, const vec &t2 ) { 
     73        it_assert_debug ( t1.length() == t2.length(), "Vec<>::operator>(): different size of vectors" ); 
     74        bvec temp ( t1.length() ); 
     75        for ( int i = 0; i < t1.length(); i++ ) 
     76                temp ( i ) = ( t1[i] > t2[i] ); 
     77        return temp; 
     78} 
     79 
     80bvec operator< ( const vec &t1, const vec &t2 ) { 
     81        it_assert_debug ( t1.length() == t2.length(), "Vec<>::operator>(): different size of vectors" ); 
     82        bvec temp ( t1.length() ); 
     83        for ( int i = 0; i < t1.length(); i++ ) 
     84                temp ( i ) = ( t1[i] < t2[i] ); 
     85        return temp; 
     86} 
     87 
     88 
     89bvec operator& ( const bvec &a, const bvec &b ) { 
     90        it_assert_debug ( b.size() == a.size(), "operator&(): Vectors of different lengths" ); 
     91 
     92        bvec temp ( a.size() ); 
     93        for ( int i = 0; i < a.size(); i++ ) { 
     94                temp ( i ) = a ( i ) & b ( i ); 
     95        } 
     96        return temp; 
     97} 
     98 
     99bvec operator| ( const bvec &a, const bvec &b ) { 
     100        it_assert_debug ( b.size() == a.size(), "operator|(): Vectors of different lengths" ); 
     101 
     102        bvec temp ( a.size() ); 
     103        for ( int i = 0; i < a.size(); i++ ) { 
     104                temp ( i ) = a ( i ) | b ( i ); 
    115105        } 
    116106        return temp; 
     
    118108 
    119109//! poor man's operator vec(bvec) - copied for svn version of itpp 
    120 ivec get_from_bvec(const ivec &v, const bvec &binlist){ 
    121   int size = binlist.size(); 
    122   it_assert_debug(v.size() == size, "Vec<>::operator()(bvec &): " 
    123                   "Wrong size of binlist vector"); 
    124   ivec temp(size); 
    125   int j = 0; 
    126   for (int i = 0; i < size; ++i) 
    127     if (binlist(i) == bin(1)) 
    128       temp(j++) = v(i); 
    129   temp.set_size(j, true); 
    130   return temp; 
     110ivec get_from_bvec ( const ivec &v, const bvec &binlist ) { 
     111        int size = binlist.size(); 
     112        it_assert_debug ( v.size() == size, "Vec<>::operator()(bvec &): " 
     113                          "Wrong size of binlist vector" ); 
     114        ivec temp ( size ); 
     115        int j = 0; 
     116        for ( int i = 0; i < size; ++i ) 
     117                if ( binlist ( i ) == bin ( 1 ) ) 
     118                        temp ( j++ ) = v ( i ); 
     119        temp.set_size ( j, true ); 
     120        return temp; 
    131121} 
    132122 
    133123 
    134124//#if 0 
    135 Gamma_RNG::Gamma_RNG (double a, double b) 
    136 { 
    137         setup (a, b); 
    138 } 
    139 double  Gamma_RNG::sample() 
    140 { 
     125Gamma_RNG::Gamma_RNG ( double a, double b ) { 
     126        setup ( a, b ); 
     127} 
     128double  Gamma_RNG::sample() { 
    141129        //A copy of rgamma code from the R package!! 
    142130        // 
     
    176164        double scale = 1.0 / beta; 
    177165 
    178         if (!R_FINITE (a) || !R_FINITE (scale) || a < 0.0 || scale <= 0.0) { 
    179                 it_error ("Gamma_RNG wrong parameters"); 
    180         } 
    181  
    182         if (a < 1.) {  /* GS algorithm for parameters a < 1 */ 
    183                 if (a == 0) 
     166        if ( !R_FINITE ( a ) || !R_FINITE ( scale ) || a < 0.0 || scale <= 0.0 ) { 
     167                it_error ( "Gamma_RNG wrong parameters" ); 
     168        } 
     169 
     170        if ( a < 1. ) { /* GS algorithm for parameters a < 1 */ 
     171                if ( a == 0 ) 
    184172                        return 0.; 
    185173                e = 1.0 + exp_m1 * a; 
    186                 for (;;) {    //VS repeat 
     174                for ( ;; ) {  //VS repeat 
    187175                        p = e * unif_rand(); 
    188                         if (p >= 1.0) { 
    189                                 x = -log ( (e - p) / a); 
    190                                 if (exp_rand() >= (1.0 - a) * log (x)) 
     176                        if ( p >= 1.0 ) { 
     177                                x = -log ( ( e - p ) / a ); 
     178                                if ( exp_rand() >= ( 1.0 - a ) * log ( x ) ) 
    191179                                        break; 
    192180                        } else { 
    193                                 x = exp (log (p) / a); 
    194                                 if (exp_rand() >= x) 
     181                                x = exp ( log ( p ) / a ); 
     182                                if ( exp_rand() >= x ) 
    195183                                        break; 
    196184                        } 
     
    202190 
    203191        /* Step 1: Recalculations of s2, s, d if a has changed */ 
    204         if (a != aa) { 
     192        if ( a != aa ) { 
    205193                aa = a; 
    206194                s2 = a - 0.5; 
    207                 s = sqrt (s2); 
     195                s = sqrt ( s2 ); 
    208196                d = sqrt32 - s * 12.0; 
    209197        } 
     
    215203        x = s + 0.5 * t; 
    216204        ret_val = x * x; 
    217         if (t >= 0.0) 
     205        if ( t >= 0.0 ) 
    218206                return scale * ret_val; 
    219207 
    220208        /* Step 3: u = 0,1 - uniform sample. squeeze acceptance (s) */ 
    221209        u = unif_rand(); 
    222         if ( (d * u) <= (t * t * t)) 
     210        if ( ( d * u ) <= ( t * t * t ) ) 
    223211                return scale * ret_val; 
    224212 
    225213        /* Step 4: recalculations of q0, b, si, c if necessary */ 
    226214 
    227         if (a != aaa) { 
     215        if ( a != aaa ) { 
    228216                aaa = a; 
    229217                r = 1.0 / a; 
    230                 q0 = ( ( ( ( ( (q7 * r + q6) * r + q5) * r + q4) * r + q3) * r 
    231                          + q2) * r + q1) * r; 
     218                q0 = ( ( ( ( ( ( q7 * r + q6 ) * r + q5 ) * r + q4 ) * r + q3 ) * r 
     219                         + q2 ) * r + q1 ) * r; 
    232220 
    233221                /* Approximation depending on size of parameter a */ 
     
    235223                /* were established by numerical experiments */ 
    236224 
    237                 if (a <= 3.686) { 
     225                if ( a <= 3.686 ) { 
    238226                        b = 0.463 + s + 0.178 * s2; 
    239227                        si = 1.235; 
    240228                        c = 0.195 / s - 0.079 + 0.16 * s; 
    241                 } else if (a <= 13.022) { 
     229                } else if ( a <= 13.022 ) { 
    242230                        b = 1.654 + 0.0076 * s2; 
    243231                        si = 1.68 / s + 0.275; 
     
    251239        /* Step 5: no quotient test if x not positive */ 
    252240 
    253         if (x > 0.0) { 
     241        if ( x > 0.0 ) { 
    254242                /* Step 6: calculation of v and quotient q */ 
    255                 v = t / (s + s); 
    256                 if (fabs (v) <= 0.25) 
    257                         q = q0 + 0.5 * t * t * ( ( ( ( ( (a7 * v + a6) * v + a5) * v + a4) * v 
    258                                                      + a3) * v + a2) * v + a1) * v; 
     243                v = t / ( s + s ); 
     244                if ( fabs ( v ) <= 0.25 ) 
     245                        q = q0 + 0.5 * t * t * ( ( ( ( ( ( a7 * v + a6 ) * v + a5 ) * v + a4 ) * v 
     246                                                     + a3 ) * v + a2 ) * v + a1 ) * v; 
    259247                else 
    260                         q = q0 - s * t + 0.25 * t * t + (s2 + s2) * log (1.0 + v); 
     248                        q = q0 - s * t + 0.25 * t * t + ( s2 + s2 ) * log ( 1.0 + v ); 
    261249 
    262250 
    263251                /* Step 7: quotient acceptance (q) */ 
    264                 if (log (1.0 - u) <= q) 
     252                if ( log ( 1.0 - u ) <= q ) 
    265253                        return scale * ret_val; 
    266254        } 
    267255 
    268         for (;;) {  //VS repeat 
     256        for ( ;; ) { //VS repeat 
    269257                /* Step 8: e = standard exponential deviate 
    270258                 *      u =  0,1 -uniform deviate 
     
    273261                u = unif_rand(); 
    274262                u = u + u - 1.0; 
    275                 if (u < 0.0) 
     263                if ( u < 0.0 ) 
    276264                        t = b - si * e; 
    277265                else 
    278266                        t = b + si * e; 
    279267                /* Step  9:  rejection if t < tau(1) = -0.71874483771719 */ 
    280                 if (t >= -0.71874483771719) { 
     268                if ( t >= -0.71874483771719 ) { 
    281269                        /* Step 10:      calculation of v and quotient q */ 
    282                         v = t / (s + s); 
    283                         if (fabs (v) <= 0.25) 
     270                        v = t / ( s + s ); 
     271                        if ( fabs ( v ) <= 0.25 ) 
    284272                                q = q0 + 0.5 * t * t * 
    285                                     ( ( ( ( ( (a7 * v + a6) * v + a5) * v + a4) * v + a3) * v 
    286                                         + a2) * v + a1) * v; 
     273                                    ( ( ( ( ( ( a7 * v + a6 ) * v + a5 ) * v + a4 ) * v + a3 ) * v 
     274                                        + a2 ) * v + a1 ) * v; 
    287275                        else 
    288                                 q = q0 - s * t + 0.25 * t * t + (s2 + s2) * log (1.0 + v); 
     276                                q = q0 - s * t + 0.25 * t * t + ( s2 + s2 ) * log ( 1.0 + v ); 
    289277                        /* Step 11:      hat acceptance (h) */ 
    290278                        /* (if q not positive go to step 8) */ 
    291                         if (q > 0.0) { 
     279                        if ( q > 0.0 ) { 
    292280                                // TODO: w = expm1(q); 
    293                                 w = exp (q) - 1; 
     281                                w = exp ( q ) - 1; 
    294282                                /*  ^^^^^ original code had approximation with rel.err < 2e-7 */ 
    295283                                /* if t is rejected sample again at step 8 */ 
    296                                 if ( (c * fabs (u)) <= (w * exp (e - 0.5 * t * t))) 
     284                                if ( ( c * fabs ( u ) ) <= ( w * exp ( e - 0.5 * t * t ) ) ) 
    297285                                        break; 
    298286                        } 
     
    304292 
    305293 
    306 bool qr (const mat &A, mat &R) 
    307 { 
     294bool qr ( const mat &A, mat &R ) { 
    308295        int info; 
    309296        int m = A.rows(); 
    310297        int n = A.cols(); 
    311298        int lwork = n; 
    312         int k = std::min (m, n); 
    313         vec tau (k); 
    314         vec work (lwork); 
     299        int k = std::min ( m, n ); 
     300        vec tau ( k ); 
     301        vec work ( lwork ); 
    315302 
    316303        R = A; 
     
    318305        // perform workspace query for optimum lwork value 
    319306        int lwork_tmp = -1; 
    320         dgeqrf_ (&m, &n, R._data(), &m, tau._data(), work._data(), &lwork_tmp, 
    321                  &info); 
    322         if (info == 0) { 
    323                 lwork = static_cast<int> (work (0)); 
    324                 work.set_size (lwork, false); 
    325         } 
    326         dgeqrf_ (&m, &n, R._data(), &m, tau._data(), work._data(), &lwork, &info); 
     307        dgeqrf_ ( &m, &n, R._data(), &m, tau._data(), work._data(), &lwork_tmp, 
     308                  &info ); 
     309        if ( info == 0 ) { 
     310                lwork = static_cast<int> ( work ( 0 ) ); 
     311                work.set_size ( lwork, false ); 
     312        } 
     313        dgeqrf_ ( &m, &n, R._data(), &m, tau._data(), work._data(), &lwork, &info ); 
    327314 
    328315        // construct R 
    329         for (int i = 0; i < m; i++) 
    330                 for (int j = 0; j < std::min (i, n); j++) 
    331                         R (i, j) = 0; 
    332  
    333         return (info == 0); 
     316        for ( int i = 0; i < m; i++ ) 
     317                for ( int j = 0; j < std::min ( i, n ); j++ ) 
     318                        R ( i, j ) = 0; 
     319 
     320        return ( info == 0 ); 
    334321} 
    335322 
    336323//#endif 
    337 std::string num2str (double d) 
    338 { 
     324std::string num2str ( double d ) { 
    339325        char tmp[20];//that should do 
    340         sprintf (tmp, "%f", d); 
    341         return std::string (tmp); 
    342 }; 
    343 std::string num2str (int i) 
    344 { 
     326        sprintf ( tmp, "%f", d ); 
     327        return std::string ( tmp ); 
     328}; 
     329std::string num2str ( int i ) { 
    345330        char tmp[10];//that should do 
    346         sprintf (tmp, "%d", i); 
    347         return std::string (tmp); 
     331        sprintf ( tmp, "%d", i ); 
     332        return std::string ( tmp ); 
    348333}; 
    349334 
     
    353338#define el 0.5772156649015329 
    354339 
    355 double psi (double x) 
    356 { 
     340double psi ( double x ) { 
    357341        double s, ps, xa, x2; 
    358342        int n, k; 
     
    368352        }; 
    369353 
    370         xa = fabs (x); 
     354        xa = fabs ( x ); 
    371355        s = 0.0; 
    372         if ( (x == (int) x) && (x <= 0.0)) { 
     356        if ( ( x == ( int ) x ) && ( x <= 0.0 ) ) { 
    373357                ps = 1e308; 
    374358                return ps; 
    375359        } 
    376         if (xa == (int) xa) { 
     360        if ( xa == ( int ) xa ) { 
    377361                n = xa; 
    378                 for (k = 1; k < n; k++) { 
     362                for ( k = 1; k < n; k++ ) { 
    379363                        s += 1.0 / k; 
    380364                } 
    381365                ps =  s - el; 
    382         } else if ( (xa + 0.5) == ( (int) (xa + 0.5))) { 
     366        } else if ( ( xa + 0.5 ) == ( ( int ) ( xa + 0.5 ) ) ) { 
    383367                n = xa - 0.5; 
    384                 for (k = 1; k <= n; k++) { 
    385                         s += 1.0 / (2.0 * k - 1.0); 
     368                for ( k = 1; k <= n; k++ ) { 
     369                        s += 1.0 / ( 2.0 * k - 1.0 ); 
    386370                } 
    387371                ps = 2.0 * s - el - 1.386294361119891; 
    388372        } else { 
    389                 if (xa < 10.0) { 
    390                         n = 10 - (int) xa; 
    391                         for (k = 0; k < n; k++) { 
    392                                 s += 1.0 / (xa + k); 
     373                if ( xa < 10.0 ) { 
     374                        n = 10 - ( int ) xa; 
     375                        for ( k = 0; k < n; k++ ) { 
     376                                s += 1.0 / ( xa + k ); 
    393377                        } 
    394378                        xa += n; 
    395379                } 
    396                 x2 = 1.0 / (xa * xa); 
    397                 ps = log (xa) - 0.5 / xa + x2 * ( ( ( ( ( ( (a[7] * x2 + a[6]) * x2 + a[5]) * x2 + 
    398                                                         a[4]) * x2 + a[3]) * x2 + a[2]) * x2 + a[1]) * x2 + a[0]); 
     380                x2 = 1.0 / ( xa * xa ); 
     381                ps = log ( xa ) - 0.5 / xa + x2 * ( ( ( ( ( ( ( a[7] * x2 + a[6] ) * x2 + a[5] ) * x2 + 
     382                                                        a[4] ) * x2 + a[3] ) * x2 + a[2] ) * x2 + a[1] ) * x2 + a[0] ); 
    399383                ps -= s; 
    400384        } 
    401         if (x < 0.0) 
    402                 ps = ps - M_PI * std::cos (M_PI * x) / std::sin (M_PI * x) - 1.0 / x; 
     385        if ( x < 0.0 ) 
     386                ps = ps - M_PI * std::cos ( M_PI * x ) / std::sin ( M_PI * x ) - 1.0 / x; 
    403387        return ps; 
    404388} 
    405389 
    406 void triu (mat &A) 
    407 { 
    408         for (int i = 1;i < A.rows();i++) { // row cycle 
    409                 for (int j = 0; j < i; j++) {A (i, j) = 0;} 
     390void triu ( mat &A ) { 
     391        for ( int i = 1; i < A.rows(); i++ ) { // row cycle 
     392                for ( int j = 0; j < i; j++ ) { 
     393                        A ( i, j ) = 0; 
     394                } 
    410395        } 
    411396} 
    412397 
    413398//! Storage of randun() internals 
    414 class RandunStorage 
    415 { 
    416                 const int A; 
    417                 const int M; 
    418                 static double seed; 
    419                 static int counter; 
    420         public: 
    421                 RandunStorage() : A (16807), M (2147483647) {}; 
    422                 //!set seed of the randun() generator 
    423                 void set_seed (double seed0) {seed = seed0;} 
    424                 //! generate randun() sample 
    425                 double get() { 
    426                         long long tmp = A * seed; 
    427                         tmp = tmp % M; 
    428                         seed = tmp; 
    429                         counter++; 
    430                         return seed / M; 
    431                 } 
     399class RandunStorage { 
     400        const int A; 
     401        const int M; 
     402        static double seed; 
     403        static int counter; 
     404public: 
     405        RandunStorage() : A ( 16807 ), M ( 2147483647 ) {}; 
     406        //!set seed of the randun() generator 
     407        void set_seed ( double seed0 ) { 
     408                seed = seed0; 
     409        } 
     410        //! generate randun() sample 
     411        double get() { 
     412                long long tmp = A * seed; 
     413                tmp = tmp % M; 
     414                seed = tmp; 
     415                counter++; 
     416                return seed / M; 
     417        } 
    432418}; 
    433419static RandunStorage randun_global_storage; 
    434420double RandunStorage::seed = 1111111; 
    435421int RandunStorage::counter = 0; 
    436 double randun() {return randun_global_storage.get();}; 
    437 vec randun (int n) {vec res (n); for (int i = 0;i < n;i++) {res (i) = randun();}; return res;}; 
    438 mat randun (int n, int m) {mat res (n, m); for (int i = 0;i < n*m;i++) {res (i) = randun();}; return res;}; 
    439  
    440 ivec unique (const ivec &in) 
    441 { 
    442         ivec uniq (0); 
     422double randun() { 
     423        return randun_global_storage.get(); 
     424}; 
     425vec randun ( int n ) { 
     426        vec res ( n ); 
     427        for ( int i = 0; i < n; i++ ) { 
     428                res ( i ) = randun(); 
     429        }; 
     430        return res; 
     431}; 
     432mat randun ( int n, int m ) { 
     433        mat res ( n, m ); 
     434        for ( int i = 0; i < n*m; i++ ) { 
     435                res ( i ) = randun(); 
     436        }; 
     437        return res; 
     438}; 
     439 
     440ivec unique ( const ivec &in ) { 
     441        ivec uniq ( 0 ); 
    443442        int j = 0; 
    444443        bool found = false; 
    445         for (int i = 0;i < in.length(); i++) { 
     444        for ( int i = 0; i < in.length(); i++ ) { 
    446445                found = false; 
    447446                j = 0; 
    448                 while ( (!found) && (j < uniq.length())) { 
    449                         if (in (i) == uniq (j)) found = true; 
     447                while ( ( !found ) && ( j < uniq.length() ) ) { 
     448                        if ( in ( i ) == uniq ( j ) ) found = true; 
    450449                        j++; 
    451450                } 
    452                 if (!found) uniq = concat (uniq, in (i)); 
     451                if ( !found ) uniq = concat ( uniq, in ( i ) ); 
    453452        } 
    454453        return uniq; 
    455454} 
    456455 
    457 ivec unique_complement (const ivec &in, const ivec &base) 
    458 { 
     456ivec unique_complement ( const ivec &in, const ivec &base ) { 
    459457        // almost a copy of unique 
    460         ivec uniq (0); 
     458        ivec uniq ( 0 ); 
    461459        int j = 0; 
    462460        bool found = false; 
    463         for (int i = 0;i < in.length(); i++) { 
     461        for ( int i = 0; i < in.length(); i++ ) { 
    464462                found = false; 
    465463                j = 0; 
    466                 while ( (!found) && (j < uniq.length())) { 
    467                         if (in (i) == uniq (j)) found = true; 
     464                while ( ( !found ) && ( j < uniq.length() ) ) { 
     465                        if ( in ( i ) == uniq ( j ) ) found = true; 
    468466                        j++; 
    469467                } 
    470                 j=0; 
    471                 while ( (!found) && (j < base.length())) { 
    472                         if (in (i) == base (j)) found = true; 
     468                j = 0; 
     469                while ( ( !found ) && ( j < base.length() ) ) { 
     470                        if ( in ( i ) == base ( j ) ) found = true; 
    473471                        j++; 
    474472                } 
    475                 if (!found) uniq = concat (uniq, in (i)); 
     473                if ( !found ) uniq = concat ( uniq, in ( i ) ); 
    476474        } 
    477475        return uniq;