Changeset 257
- Timestamp:
- Mar 4, 2005, 1:53:34 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r225 r257 10 10 Alignment.cc Averager.cc AveragerPair.cc ConsensusInputRanker.cc \ 11 11 CrossValidation.cc FileIO.cc Fisher.cc GaussianKernelFunction.cc \ 12 gslapi_utility.cc \ 12 13 Histogram.cc InputRanker.cc Kernel.cc kNNI.cc matrix.cc Merge.cc \ 13 14 NNI.cc PCA.cc PolynomialKernelFunction.cc random_singleton.cc \ … … 22 23 Alignment.h Averager.h AveragerPair.h ConsensusInputRanker.h \ 23 24 CrossValidation.h FileIO.h Fisher.h GaussianKernelFunction.h \ 25 gslapi_utility.h \ 24 26 Histogram.h InputRanker.h Kernel.h KernelFunction.h kNNI.h matrix.h \ 25 27 Merge.h NNI.h PCA.h Pearson.h PolynomialKernelFunction.h \ -
trunk/src/vector.cc
r227 r257 39 39 { 40 40 v_ = other.TEMP_gsl_vector_copy(); 41 } 42 43 44 45 vector::vector(vector& v, size_t offset, size_t n, size_t stride) 46 { 47 view_ = new gsl_vector_view(gsl_vector_subvector_with_stride(v.v_,offset, 48 stride,n)); 49 v_ = &(view_->vector); 41 50 } 42 51 … … 125 134 vector::~vector(void) 126 135 { 127 if (v_) { 136 if (view_) 137 delete view_; 138 else if (v_) 128 139 gsl_vector_free(v_); 129 v_=NULL; 130 } 131 delete view_; 140 v_=NULL; 132 141 } 133 142 … … 160 169 161 170 162 163 /* Jari, remove this section164 std::pair<size_t,size_t> vector::minmax_index(const std::vector<size_t>& subset ) const165 {166 size_t min_index = subset[0];167 size_t max_index = subset[0];168 for (unsigned int i=1; i<subset.size(); i++) {169 if (gsl_vector_get( v_, subset[i]) < gsl_vector_get( v_, min_index))170 min_index = subset[i];171 else if (gsl_vector_get( v_, subset[i]) > gsl_vector_get( v_, max_index))172 max_index = subset[i];173 }174 return std::pair<size_t,size_t>(min_index, max_index);175 }176 */177 171 178 172 void vector::shuffle(void) const -
trunk/src/vector.h
r227 r257 68 68 69 69 /// 70 /// The vector view constructor. 71 /// 72 /// Create a view of vector \a v, with starting index \a offset, 73 /// size \a n, and an optional \a stride. 74 /// 75 /// A vector view can be used as any vector with the difference 76 /// that changes made to the view will also change the object that 77 /// is viewed. Also, using the copy constructor will create a new 78 /// vector object that is a copy of whatever is viewed. If a copy 79 /// of the view is needed the you should use this consturctor to 80 /// get one. 81 /// 82 /// @note If the object viewed by the view goes out of scope or is 83 /// deleted, the view becomes invalid. 84 /// 85 vector(vector& v, size_t offset, size_t n, size_t stride=1); 86 87 /// 70 88 /// Constructor that imports a GSL vector. The GSL object is owned 71 89 /// by the created object. … … 178 196 // Jari, doxygen group as Finding maximum and minimum elements 179 197 std::pair<size_t,size_t> vector::minmax_index(void) const; 180 181 ///This function returns the indices of the minimum and maximum182 ///values in the sub-vector (defined by \a subset), storing them183 ///in imin and imax. When there are several equal minimum or184 ///maximum elements then the lowest indices are returned. The185 ///returned index is the index from the complete vector (not the186 ///sub-vector)187 ///188 /// @return Index corresponding to the smallest and largest value.189 ///190 std::pair<size_t,size_t>191 vector::TEMP_minmax_index(const std::vector<size_t>& subset ) const;192 198 193 199 /// -
trunk/test/test_vector.cc
r127 r257 1 1 // $Id$ 2 2 3 // C++ tools include4 ////////////////////5 3 #include "vector.h" 6 4 7 using namespace std; 8 9 int main() 10 5 int main(const int argc,const char* argv[]) 11 6 { 12 7 bool ok = true; 13 theplu::gslapi::vector vec(10); 8 9 theplu::gslapi::vector vec(12); 14 10 for (unsigned int i=0; i<vec.size(); i++) 15 11 vec(i)=i; 12 13 // checking that shuffle works 16 14 double sum_before = vec.sum(); 17 15 vec.shuffle(); … … 19 17 if (sum_after != sum_before) 20 18 ok = false; 21 22 if (ok) 19 20 // checking that view works 21 sum_before=0; 22 for (unsigned int i=0; i<vec.size(); i+=2) 23 sum_before+=vec[i]; 24 theplu::gslapi::vector vec_view(vec,0,6,2); 25 sum_after=vec_view.sum(); 26 if (sum_after != sum_before) 27 ok = false; 28 vec[0]=0; 29 vec_view[0]=24; 30 if (vec[0]!=vec_view[0]) 31 ok=false; 32 33 // checking that copy contrutor creates an independent object 34 theplu::gslapi::vector vec2(vec); 35 if (vec.size()!=vec2.size()) 36 ok=false; 37 if (&vec2 == &vec) 38 ok=false; 39 if (vec2.isview()) 40 ok=false; 41 42 // checking that copy contrutor creates an independent object when 43 // copying a view 44 vec2=vec_view; 45 if (vec_view.size()!=vec2.size()) 46 ok=false; 47 if ((&vec2 == &vec_view) || (&vec2 == &vec)) 48 ok=false; 49 if (vec2.isview()) 50 ok=false; 51 vec2[0]=0; 52 vec_view[0]=24; 53 if (vec2[0]==vec_view[0]) 54 ok=false; 55 56 if (ok) { 57 std::cout << "test_vector: SUCCESS\n"; 23 58 return 0; 59 } 60 std::cerr << "test_vector: FAILED\n"; 24 61 return -1; 25 62 }
Note: See TracChangeset
for help on using the changeset viewer.