Changeset 584

Show
Ignore:
Timestamp:
08/27/09 15:39:33 (15 years ago)
Author:
smidl
Message:

new function unique(ivec) and its test in RV_test

Location:
library
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/base/bdmbase.h

    r573 r584  
    139139                        return dsize; 
    140140                } 
     141                 
     142                //! access function 
     143                const ivec& _ids() const { return ids;} 
    141144 
    142145                //! Recount size of the corresponding data vector 
  • library/bdm/itpp_ext.cpp

    r581 r584  
    398398vec randun(int n){vec res(n); for(int i=0;i<n;i++){res(i)=randun();}; return res;}; 
    399399mat randun(int n, int m){mat res(n,m); for(int i=0;i<n*m;i++){res(i)=randun();}; return res;}; 
    400  
    401 } 
     400ivec unique (const ivec &in) 
     401{ 
     402        ivec uniq (0); 
     403        int j = 0; 
     404        bool found = false; 
     405        for (int i = 0;i < in.length(); i++) { 
     406                found = false; 
     407                j = 0; 
     408                while ( (!found) && (j < uniq.length())) { 
     409                        if (in (i) == uniq (j)) found = true; 
     410                        j++; 
     411                } 
     412                if (!found) uniq = concat (uniq, in (i)); 
     413        } 
     414        return uniq; 
     415} 
     416 
     417} 
  • library/bdm/itpp_ext.h

    r579 r584  
    113113mat randun(int n, int m); 
    114114 
     115//! function returns unique entries in input vector \c in 
     116ivec unique(const ivec &in); 
    115117} 
    116118 
  • library/tests/rv_test.cpp

    r531 r584  
    133133                CHECK_EQUAL ( exp_bi[i], bi ( i ) ); 
    134134        } 
     135         
     136        // check uniqueness 
     137        RV join=a; 
     138        join.add(b); 
     139        RV tmp=a; tmp.t(1); 
     140        join.add(tmp); 
     141        tmp=b; tmp.t(-1); 
     142        join.add(tmp); 
     143         
     144        CHECK_EQUAL(unique(join._ids()), vec_2(a.id(0), b.id(0))); 
    135145}