- Timestamp:
- Feb 1, 2008, 5:35:32 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/matrix_test.cc
r1009 r1015 36 36 : m_(i,j,value) {} 37 37 38 inline theplu::yat::utility:: vectorView38 inline theplu::yat::utility::VectorView 39 39 row(const size_t& i) { return m_.row_vec(i); } 40 40 … … 258 258 for (size_t j=0; j<m5.columns(); ++j) 259 259 m5_sum2+=m5(i,j); 260 utility:: vectorView v5subrow(m5,3);260 utility::VectorView v5subrow(m5,3); 261 261 double v5subrow_sum=0; 262 262 for (size_t i=0; i<v5subrow.size(); ++i) { … … 280 280 for (size_t j=0; j<m5.columns(); ++j) 281 281 m5_sum3+=m5(i,j); 282 utility:: vectorView v5subcolumn = m5.column_vec(0);282 utility::VectorView v5subcolumn = m5.column_vec(0); 283 283 double v5subcolumn_sum=0; 284 284 for (size_t i=0; i<v5subcolumn.size(); ++i) { … … 332 332 *error << "\tthat class member returns a view" << std::endl; 333 333 matrixwrapper mw(5,2); 334 utility:: vectorView mwrow=mw.row(2);334 utility::VectorView mwrow=mw.row(2); 335 335 if (mwrow.gsl_vector_p()->data != &(mw.matrix()(2,0))) { 336 336 ok=false; -
trunk/test/score_test.cc
r1009 r1015 32 32 #include "yat/utility/matrix.h" 33 33 #include "yat/utility/vector.h" 34 #include "yat/utility/ vectorView.h"34 #include "yat/utility/VectorView.h" 35 35 36 36 #include <cmath> … … 93 93 const double tol = 0.001; 94 94 for (size_t i=0; i<data.rows(); i++){ 95 utility:: vectorView vec(data,i);95 utility::VectorView vec(data,i); 96 96 if (vec.size()!=target2.size()){ 97 97 *error << "vec.size() is " << vec.size() << " and target2.size() is " … … 109 109 utility::vector weight(target2.size(),1); 110 110 for (size_t i=0; i<data.rows(); i++){ 111 utility:: vectorView vec = data.row_vec(i);111 utility::VectorView vec = data.row_vec(i); 112 112 area = auc.score(target2, vec, weight); 113 113 if (area<correct_area(i)-tol || area>correct_area(i)+tol){ -
trunk/test/vector_test.cc
r1009 r1015 29 29 #include "yat/utility/utility.h" 30 30 #include "yat/utility/vector.h" 31 #include "yat/utility/ vectorView.h"31 #include "yat/utility/VectorView.h" 32 32 33 33 #include <fstream> … … 74 74 for (size_t i=0; i<vec.size(); i+=2) 75 75 sum_before+=vec[i]; 76 utility:: vectorView vec_view(vec,0,6,2);76 utility::VectorView vec_view(vec,0,6,2); 77 77 sum_after=utility::sum(vec_view); 78 78 ok &= (sum_after==sum_before); … … 88 88 *message << "const view implementation" << std::endl; 89 89 const utility::vector vv(10,3.0); 90 utility:: vectorView vview(vv,0,5,1);90 utility::VectorView vview(vv,0,5,1); 91 91 // const utility::vector vview(vv,0,5,1); // this is the proper line 92 92 utility::vector vv2(5,2.0); … … 148 148 *message << "assignment operator on view" << std::endl; 149 149 vec[3]=vec[4]=vec[5]=13; 150 utility:: vectorView vec_view(vec,3,3,1);150 utility::VectorView vec_view(vec,3,3,1); 151 151 utility::vector vec2(3,123.0); 152 152 vec_view=vec2; … … 173 173 this_ok=false; 174 174 *message << "\tcloning vector view" << std::endl; 175 utility:: vectorView* vec_view=new utility::vectorView(vec,3,3,1);176 utility:: vectorView vec_view2(*vec_view);175 utility::VectorView* vec_view=new utility::VectorView(vec,3,3,1); 176 utility::VectorView vec_view2(*vec_view); 177 177 if (!vec_view2.isview()) 178 178 this_ok=false; -
trunk/yat/regression/Local.cc
r1009 r1015 27 27 #include "OneDimensionalWeighted.h" 28 28 #include "yat/utility/vector.h" 29 #include "yat/utility/ vectorView.h"29 #include "yat/utility/VectorView.h" 30 30 31 31 #include <algorithm> … … 103 103 assert(max_index<data_.size()); 104 104 105 utility:: vectorView x_local(x, min_index, max_index-min_index+1);106 utility:: vectorView y_local(y, min_index, max_index-min_index+1);105 utility::VectorView x_local(x, min_index, max_index-min_index+1); 106 utility::VectorView y_local(y, min_index, max_index-min_index+1); 107 107 108 108 // calculating weights -
trunk/yat/utility/Makefile.am
r1014 r1015 30 30 OptionHelp.cc OptionSwitch.cc \ 31 31 PCA.cc stl_utility.cc SVD.cc TypeInfo.cc utility.cc vector.cc \ 32 vectorBase.cc vectorView.cc WeNNI.cc32 VectorBase.cc VectorView.cc WeNNI.cc 33 33 34 34 include_utilitydir = $(includedir)/yat/utility … … 41 41 OptionHelp.h OptionSwitch.h \ 42 42 PCA.h stl_utility.h SVD.h TypeInfo.h utility.h vector.h \ 43 vectorBase.h vectorView.h \43 VectorBase.h VectorView.h \ 44 44 WeNNI.h yat_assert.h 45 45 -
trunk/yat/utility/PCA.cc
r1009 r1015 29 29 #include "SVD.h" 30 30 #include "utility.h" 31 #include " vectorView.h"31 #include "VectorView.h" 32 32 33 33 #include <iostream> … … 193 193 utility::vector A_row_sum(A_.rows()); 194 194 for (size_t i=0; i<A_row_sum.size(); ++i){ 195 const vectorView tmp(A_.row_vec(i));195 const VectorView tmp(A_.row_vec(i)); 196 196 A_row_sum(i) = sum(tmp); 197 197 } -
trunk/yat/utility/VectorBase.cc
r1013 r1015 25 25 */ 26 26 27 #include " vectorBase.h"27 #include "VectorBase.h" 28 28 #include "matrix.h" 29 29 #include "utility.h" … … 43 43 44 44 45 vectorBase::vectorBase(void)45 VectorBase::VectorBase(void) 46 46 : vec_(NULL), const_vec_(NULL) 47 47 { … … 49 49 50 50 51 vectorBase::vectorBase(gsl_vector* v)51 VectorBase::VectorBase(gsl_vector* v) 52 52 : vec_(v), const_vec_(v) 53 53 { … … 55 55 56 56 57 vectorBase::vectorBase(const gsl_vector* v)57 VectorBase::VectorBase(const gsl_vector* v) 58 58 : vec_(NULL), const_vec_(v) 59 59 { … … 61 61 62 62 63 vectorBase::~vectorBase(void)64 { 65 } 66 67 68 void vectorBase::all(double value)63 VectorBase::~VectorBase(void) 64 { 65 } 66 67 68 void VectorBase::all(double value) 69 69 { 70 70 assert(vec_); … … 73 73 74 74 75 vectorBase::const_iterator vectorBase::begin(void) const75 VectorBase::const_iterator VectorBase::begin(void) const 76 76 { 77 77 return const_iterator(*this, 0); … … 79 79 80 80 81 vectorBase::iterator vectorBase::begin(void)81 VectorBase::iterator VectorBase::begin(void) 82 82 { 83 83 return iterator(*this, 0); … … 85 85 86 86 87 void vectorBase::div(const vectorBase& other)87 void VectorBase::div(const VectorBase& other) 88 88 { 89 89 assert(vec_); 90 90 int status=gsl_vector_div(vec_,other.gsl_vector_p()); 91 91 if (status) 92 throw utility::GSL_error(std::string(" vectorBase::div",status));93 } 94 95 96 vectorBase::const_iterator vectorBase::end(void) const92 throw utility::GSL_error(std::string("VectorBase::div",status)); 93 } 94 95 96 VectorBase::const_iterator VectorBase::end(void) const 97 97 { 98 98 return const_iterator(*this, size()); … … 100 100 101 101 102 vectorBase::iterator vectorBase::end(void)102 VectorBase::iterator VectorBase::end(void) 103 103 { 104 104 return iterator(*this, size()); … … 106 106 107 107 108 bool vectorBase::equal(const vectorBase& other, const double d) const108 bool VectorBase::equal(const VectorBase& other, const double d) const 109 109 { 110 110 if (this==&other) … … 122 122 123 123 124 const gsl_vector* vectorBase::gsl_vector_p(void) const124 const gsl_vector* VectorBase::gsl_vector_p(void) const 125 125 { 126 126 return const_vec_; … … 128 128 129 129 130 gsl_vector* vectorBase::gsl_vector_p(void)130 gsl_vector* VectorBase::gsl_vector_p(void) 131 131 { 132 132 return vec_; … … 134 134 135 135 136 void vectorBase::mul(const vectorBase& other)136 void VectorBase::mul(const VectorBase& other) 137 137 { 138 138 assert(vec_); 139 139 int status=gsl_vector_mul(vec_,other.gsl_vector_p()); 140 140 if (status) 141 throw utility::GSL_error(std::string(" vectorBase::div",status));142 } 143 144 145 size_t vectorBase::size(void) const141 throw utility::GSL_error(std::string("VectorBase::div",status)); 142 } 143 144 145 size_t VectorBase::size(void) const 146 146 { 147 147 if (!const_vec_) … … 151 151 152 152 153 const double& vectorBase::operator()(size_t i) const153 const double& VectorBase::operator()(size_t i) const 154 154 { 155 155 const double* d=gsl_vector_const_ptr(const_vec_, i); 156 156 if (!d) 157 throw utility::GSL_error(" vectorBase::operator()",GSL_EINVAL);157 throw utility::GSL_error("VectorBase::operator()",GSL_EINVAL); 158 158 return *d; 159 159 } 160 160 161 161 162 double& vectorBase::operator()(size_t i)162 double& VectorBase::operator()(size_t i) 163 163 { 164 164 double* d=gsl_vector_ptr(vec_, i); 165 165 if (!d) 166 throw utility::GSL_error(" vectorBase::operator()",GSL_EINVAL);166 throw utility::GSL_error("VectorBase::operator()",GSL_EINVAL); 167 167 return *d; 168 168 } 169 169 170 170 171 double& vectorBase::operator[](size_t i)171 double& VectorBase::operator[](size_t i) 172 172 { 173 173 return this->operator()(i); … … 175 175 176 176 177 const double& vectorBase::operator[](size_t i) const177 const double& VectorBase::operator[](size_t i) const 178 178 { 179 179 return this->operator()(i); … … 181 181 182 182 183 bool vectorBase::operator==(const vectorBase& other) const183 bool VectorBase::operator==(const VectorBase& other) const 184 184 { 185 185 return equal(other); … … 187 187 188 188 189 bool vectorBase::operator!=(const vectorBase& other) const189 bool VectorBase::operator!=(const VectorBase& other) const 190 190 { 191 191 return !equal(other); … … 193 193 194 194 195 double vectorBase::operator*( const vectorBase &other ) const195 double VectorBase::operator*( const VectorBase &other ) const 196 196 { 197 197 double res = 0.0;; … … 202 202 203 203 204 const vectorBase& vectorBase::operator+=(double d)204 const VectorBase& VectorBase::operator+=(double d) 205 205 { 206 206 assert(vec_); … … 210 210 211 211 212 const vectorBase& vectorBase::operator-=(const vectorBase& other)212 const VectorBase& VectorBase::operator-=(const VectorBase& other) 213 213 { 214 214 assert(vec_); 215 215 int status=gsl_vector_sub(vec_, other.gsl_vector_p()); 216 216 if (status) 217 throw utility::GSL_error(std::string(" vectorBase::sub", status));217 throw utility::GSL_error(std::string("VectorBase::sub", status)); 218 218 return *this; 219 219 } 220 220 221 221 222 const vectorBase& vectorBase::operator-=(const double d)222 const VectorBase& VectorBase::operator-=(const double d) 223 223 { 224 224 assert(vec_); … … 228 228 229 229 230 const vectorBase& vectorBase::operator*=(double d)230 const VectorBase& VectorBase::operator*=(double d) 231 231 { 232 232 assert(vec_); … … 236 236 237 237 238 bool isnull(const vectorBase& v)238 bool isnull(const VectorBase& v) 239 239 { 240 240 return gsl_vector_isnull(v.gsl_vector_p()); … … 242 242 243 243 244 double max(const vectorBase& v)244 double max(const VectorBase& v) 245 245 { 246 246 return gsl_vector_max(v.gsl_vector_p()); … … 248 248 249 249 250 size_t max_index(const vectorBase& v)250 size_t max_index(const VectorBase& v) 251 251 { 252 252 return gsl_vector_max_index(v.gsl_vector_p()); … … 254 254 255 255 256 double min(const vectorBase& v)256 double min(const VectorBase& v) 257 257 { 258 258 return gsl_vector_min(v.gsl_vector_p()); … … 260 260 261 261 262 size_t min_index(const vectorBase& v)262 size_t min_index(const VectorBase& v) 263 263 { 264 264 return gsl_vector_min_index(v.gsl_vector_p()); … … 266 266 267 267 268 bool nan(const vectorBase& templat, vector& flag)268 bool nan(const VectorBase& templat, vector& flag) 269 269 { 270 270 size_t vsize(templat.size()); … … 280 280 281 281 282 void shuffle( vectorBase& invec)282 void shuffle(VectorBase& invec) 283 283 { 284 284 random::DiscreteUniform rnd; … … 287 287 288 288 289 void sort_index(std::vector<size_t>& sort_index, const vectorBase& invec)289 void sort_index(std::vector<size_t>& sort_index, const VectorBase& invec) 290 290 { 291 291 assert(invec.gsl_vector_p()); … … 294 294 if (status) { 295 295 gsl_permutation_free(p); 296 throw utility::GSL_error(std::string("sort_index(vector&,const vectorBase&)",status));296 throw utility::GSL_error(std::string("sort_index(vector&,const VectorBase&)",status)); 297 297 } 298 298 sort_index=std::vector<size_t>(p->data,p->data+p->size); … … 302 302 303 303 void sort_smallest_index(std::vector<size_t>& sort_index, size_t k, 304 const vectorBase& invec)304 const VectorBase& invec) 305 305 { 306 306 assert(invec.gsl_vector_p()); … … 311 311 312 312 void sort_largest_index(std::vector<size_t>& sort_index, size_t k, 313 const vectorBase& invec)313 const VectorBase& invec) 314 314 { 315 315 assert(invec.gsl_vector_p()); … … 320 320 321 321 322 double sum(const vectorBase& v)322 double sum(const VectorBase& v) 323 323 { 324 324 double sum = 0; … … 330 330 331 331 332 std::ostream& operator<<(std::ostream& s, const vectorBase& a)332 std::ostream& operator<<(std::ostream& s, const VectorBase& a) 333 333 { 334 334 s.setf(std::ios::dec); -
trunk/yat/utility/VectorBase.h
r1013 r1015 86 86 */ 87 87 88 class vectorBase88 class VectorBase 89 89 { 90 90 public: 91 91 92 /// \brief vectorBase::iterator93 typedef Iterator<double&, vectorBase> iterator;94 95 /// \brief vectorBase::const_iterator96 typedef Iterator<const double, const vectorBase> const_iterator;92 /// \brief VectorBase::iterator 93 typedef Iterator<double&, VectorBase> iterator; 94 95 /// \brief VectorBase::const_iterator 96 typedef Iterator<const double, const VectorBase> const_iterator; 97 97 98 98 /** 99 99 \brief default constructor 100 100 */ 101 vectorBase(void);101 VectorBase(void); 102 102 103 103 /** 104 104 \brief Constructor. 105 105 */ 106 vectorBase(gsl_vector*);106 VectorBase(gsl_vector*); 107 107 108 108 /** 109 109 \brief Constructor. 110 110 */ 111 vectorBase(const gsl_vector*);111 VectorBase(const gsl_vector*); 112 112 113 113 /// 114 114 /// The destructor. 115 115 /// 116 virtual ~ vectorBase(void);116 virtual ~VectorBase(void); 117 117 118 118 /// … … 122 122 123 123 /** 124 \return mutable iterator to start of vectorBase124 \return mutable iterator to start of VectorBase 125 125 */ 126 126 iterator begin(void); 127 127 128 128 /** 129 \return read-only iterator to start of vectorBase129 \return read-only iterator to start of VectorBase 130 130 */ 131 131 const_iterator begin(void) const; … … 137 137 \throw GSL_error if dimensions mis-match. 138 138 */ 139 void div(const vectorBase& other);140 141 /** 142 \return mutable iterator to end of vectorBase139 void div(const VectorBase& other); 140 141 /** 142 \return mutable iterator to end of VectorBase 143 143 */ 144 144 iterator end(void); 145 145 146 146 /** 147 \return read-only iterator to end of vectorBase147 \return read-only iterator to end of VectorBase 148 148 */ 149 149 const_iterator end(void) const; 150 150 151 151 /** 152 \brief Check whether vectorBases are equal within a user defined152 \brief Check whether VectorBases are equal within a user defined 153 153 precision, set by \a precision. 154 154 155 155 \return True if each element deviates less or equal than \a 156 d. If any vectorBase contain a NaN, false is always returned.156 d. If any VectorBase contain a NaN, false is always returned. 157 157 158 158 \see operator== and operator!= 159 159 */ 160 bool equal(const vectorBase&, const double precision=0) const;160 bool equal(const VectorBase&, const double precision=0) const; 161 161 162 162 /// … … 186 186 \throw GSL_error if dimensions mis-match. 187 187 */ 188 void mul(const vectorBase& other);189 190 /** 191 \brief Reverse the order of elements in the vectorBase.188 void mul(const VectorBase& other); 189 190 /** 191 \brief Reverse the order of elements in the VectorBase. 192 192 */ 193 193 void reverse(void); 194 194 195 195 /// 196 /// @return the number of elements in the vectorBase.196 /// @return the number of elements in the VectorBase. 197 197 /// 198 198 size_t size(void) const; … … 201 201 \brief Exchange elements \a i and \a j. 202 202 203 \throw GSL_error if vectorBase lengths differs.203 \throw GSL_error if VectorBase lengths differs. 204 204 */ 205 205 void swap(size_t i, size_t j); … … 240 240 \return True if all elements are equal otherwise false. 241 241 242 \see equal(const vectorBase&, const double precision=0)243 */ 244 bool operator==(const vectorBase&) const;242 \see equal(const VectorBase&, const double precision=0) 243 */ 244 bool operator==(const VectorBase&) const; 245 245 246 246 /** … … 253 253 \return False if all elements are equal otherwise true. 254 254 255 \see equal(const vectorBase&, const double precision=0)256 */ 257 bool operator!=(const vectorBase&) const;255 \see equal(const VectorBase&, const double precision=0) 256 */ 257 bool operator!=(const VectorBase&) const; 258 258 259 259 /// 260 260 /// @return The dot product. 261 261 /// 262 double operator*(const vectorBase&) const;262 double operator*(const VectorBase&) const; 263 263 264 264 /** 265 265 \brief The assignment operator. 266 266 267 Dimensions of the vectorBases must match. If the LHS vectorBase is a267 Dimensions of the VectorBases must match. If the LHS VectorBase is a 268 268 view, the underlying data will be changed. 269 269 270 \return A const reference to the resulting vectorBase.271 272 \see void set(const vectorBase&).270 \return A const reference to the resulting VectorBase. 271 272 \see void set(const VectorBase&). 273 273 274 274 \throw GSL_error if dimensions mis-match. 275 275 */ 276 //const vectorBase& operator=(vectorBase&);276 //const VectorBase& operator=(VectorBase&); 277 277 278 278 /** … … 280 280 this_i = this_i + other_i \; \forall i \f$. 281 281 282 \return A const reference to the resulting vectorBase.282 \return A const reference to the resulting VectorBase. 283 283 284 284 \throw GSL_error if dimensions mis-match. 285 285 */ 286 const vectorBase& operator+=(const vectorBase&);287 288 /** 289 \brief Add a constant to a vectorBase, \f$ this_i = this_i + d \;286 const VectorBase& operator+=(const VectorBase&); 287 288 /** 289 \brief Add a constant to a VectorBase, \f$ this_i = this_i + d \; 290 290 \forall i \f$. 291 291 292 \return A const reference to the resulting vectorBase.293 */ 294 const vectorBase& operator+=(double d);292 \return A const reference to the resulting VectorBase. 293 */ 294 const VectorBase& operator+=(double d); 295 295 296 296 /** … … 298 298 this_i = this_i - other_i \; \forall i \f$. 299 299 300 \return A const reference to the resulting vectorBase.300 \return A const reference to the resulting VectorBase. 301 301 302 302 \throw GSL_error if dimensions mis-match. 303 303 */ 304 const vectorBase& operator-=(const vectorBase&);305 306 /** 307 \brief Subtract a constant to a vectorBase, \f$ this_i = this_i - d304 const VectorBase& operator-=(const VectorBase&); 305 306 /** 307 \brief Subtract a constant to a VectorBase, \f$ this_i = this_i - d 308 308 \; \forall i \f$. 309 309 310 \return A const reference to the resulting vectorBase.311 */ 312 const vectorBase& operator-=(double d);310 \return A const reference to the resulting VectorBase. 311 */ 312 const VectorBase& operator-=(double d); 313 313 314 314 /** … … 316 316 this_i * d \; \forall i \f$. 317 317 318 \return A const reference to the resulting vectorBase.319 */ 320 const vectorBase& operator*=(double d);318 \return A const reference to the resulting VectorBase. 319 */ 320 const VectorBase& operator*=(double d); 321 321 322 322 … … 335 335 private: 336 336 // copy assignment no allowed 337 const vectorBase& operator=(const vectorBase&);337 const VectorBase& operator=(const VectorBase&); 338 338 public: 339 339 /** … … 344 344 345 345 /** 346 \brief Check if all elements of the vectorBase are zero.347 348 \return True if all elements in the vectorBase is zero, false346 \brief Check if all elements of the VectorBase are zero. 347 348 \return True if all elements in the VectorBase is zero, false 349 349 othwerwise. 350 350 */ 351 bool isnull(const vectorBase&);352 353 /** 354 \brief Get the maximum value of the vectorBase.355 356 \return The maximum value of the vectorBase.357 */ 358 double max(const vectorBase&);359 360 /** 361 \brief Locate the maximum value in the vectorBase.362 363 \return The index to the maximum value of the vectorBase.351 bool isnull(const VectorBase&); 352 353 /** 354 \brief Get the maximum value of the VectorBase. 355 356 \return The maximum value of the VectorBase. 357 */ 358 double max(const VectorBase&); 359 360 /** 361 \brief Locate the maximum value in the VectorBase. 362 363 \return The index to the maximum value of the VectorBase. 364 364 365 365 \note Lower index has precedence. 366 366 */ 367 size_t max_index(const vectorBase&);368 369 /** 370 \brief Get the minimum value of the vectorBase.371 372 \return The minimum value of the vectorBase.373 */ 374 double min(const vectorBase&);375 376 /** 377 \brief Locate the minimum value in the vectorBase.378 379 \return The index to the minimum value of the vectorBase.367 size_t max_index(const VectorBase&); 368 369 /** 370 \brief Get the minimum value of the VectorBase. 371 372 \return The minimum value of the VectorBase. 373 */ 374 double min(const VectorBase&); 375 376 /** 377 \brief Locate the minimum value in the VectorBase. 378 379 \return The index to the minimum value of the VectorBase. 380 380 381 381 \note Lower index has precedence. 382 382 */ 383 size_t min_index(const vectorBase&);384 385 /** 386 \brief Create a vectorBase \a flag indicating NaN's in another vectorBase383 size_t min_index(const VectorBase&); 384 385 /** 386 \brief Create a VectorBase \a flag indicating NaN's in another VectorBase 387 387 \a templat. 388 388 389 The \a flag vectorBase is changed to contain 1's and 0's only. A 1390 means that the corresponding element in the \a templat vectorBase is389 The \a flag VectorBase is changed to contain 1's and 0's only. A 1 390 means that the corresponding element in the \a templat VectorBase is 391 391 valid and a zero means that the corresponding element is a NaN. 392 392 393 \note Space for vectorBase \a flag is reallocated to fit the size of394 vectorBase \a templat if sizes mismatch.395 396 \return True if the \a templat vectorBase contains at least one NaN.397 */ 398 bool nan(const vectorBase& templat, vector& flag);399 400 /** 401 Randomly shuffles the elements in vectorBase \a invec402 */ 403 void shuffle( vectorBase& invec);404 405 /** 406 Sort the elements in the vectorBase.407 */ 408 void sort( vectorBase&);393 \note Space for VectorBase \a flag is reallocated to fit the size of 394 VectorBase \a templat if sizes mismatch. 395 396 \return True if the \a templat VectorBase contains at least one NaN. 397 */ 398 bool nan(const VectorBase& templat, vector& flag); 399 400 /** 401 Randomly shuffles the elements in VectorBase \a invec 402 */ 403 void shuffle(VectorBase& invec); 404 405 /** 406 Sort the elements in the VectorBase. 407 */ 408 void sort(VectorBase&); 409 409 410 410 /** 411 411 Create a vector \a sort_index containing the indeces of 412 elements in a another vectorBase \a invec. The elements of \a413 sort_index give the index of the vectorBase element which would414 have been stored in that position if the vectorBase had been sorted412 elements in a another VectorBase \a invec. The elements of \a 413 sort_index give the index of the VectorBase element which would 414 have been stored in that position if the VectorBase had been sorted 415 415 in place. The first element of \a sort_index gives the index of the least 416 416 element in \a invec, and the last element of \a sort_index gives the 417 index of the greatest element in \a invec . The vectorBase \a invec417 index of the greatest element in \a invec . The VectorBase \a invec 418 418 is not changed. 419 419 */ 420 void sort_index(std::vector<size_t>& sort_index, const vectorBase& invec);420 void sort_index(std::vector<size_t>& sort_index, const VectorBase& invec); 421 421 422 422 /** 423 Similar to sort_index but creates a vectorBase with indices to the \a k423 Similar to sort_index but creates a VectorBase with indices to the \a k 424 424 smallest elements in \a invec. 425 425 */ 426 426 void sort_smallest_index(std::vector<size_t>& sort_index, size_t k, 427 const vectorBase& invec);427 const VectorBase& invec); 428 428 429 429 /** 430 Similar to sort_index but creates a vectorBase with indices to the \a k430 Similar to sort_index but creates a VectorBase with indices to the \a k 431 431 largest elements in \a invec. 432 432 */ 433 433 void sort_largest_index(std::vector<size_t>& sort_index, size_t k, 434 const vectorBase& invec);435 436 /** 437 \brief Calculate the sum of all vectorBase elements.434 const VectorBase& invec); 435 436 /** 437 \brief Calculate the sum of all VectorBase elements. 438 438 439 439 \return The sum. 440 440 */ 441 double sum(const vectorBase&);441 double sum(const VectorBase&); 442 442 443 443 /** … … 451 451 452 452 /** 453 \brief The output operator for the vectorBase class.454 */ 455 std::ostream& operator<<(std::ostream&, const vectorBase&);453 \brief The output operator for the VectorBase class. 454 */ 455 std::ostream& operator<<(std::ostream&, const VectorBase&); 456 456 457 457 }}} // of namespace utility, yat, and theplu -
trunk/yat/utility/VectorView.cc
r1013 r1015 25 25 */ 26 26 27 #include " vectorView.h"27 #include "VectorView.h" 28 28 #include "matrix.h" 29 29 #include "utility.h" … … 43 43 44 44 45 vectorView::vectorView(void)46 : vectorBase(), view_(NULL), const_view_(NULL)47 { 48 } 49 50 51 vectorView::vectorView(vectorView& other)52 : vectorBase(), const_view_(NULL)45 VectorView::VectorView(void) 46 : VectorBase(), view_(NULL), const_view_(NULL) 47 { 48 } 49 50 51 VectorView::VectorView(VectorView& other) 52 : VectorBase(), const_view_(NULL) 53 53 { 54 54 view_ = new gsl_vector_view(gsl_vector_subvector(other.gsl_vector_p(), … … 59 59 60 60 61 vectorView::vectorView(const vectorView& other)62 : vectorBase(), view_(NULL)61 VectorView::VectorView(const VectorView& other) 62 : VectorBase(), view_(NULL) 63 63 { 64 64 const_view_ = new gsl_vector_const_view( … … 68 68 69 69 70 vectorView::vectorView(vectorBase& other)71 : vectorBase(other.gsl_vector_p()), const_view_(NULL)70 VectorView::VectorView(VectorBase& other) 71 : VectorBase(other.gsl_vector_p()), const_view_(NULL) 72 72 { 73 73 view_ = … … 79 79 80 80 /* 81 vectorView::vectorView(const vectorBase& other)82 : vectorBase(other.const_vec_), view_(NULL)81 VectorView::VectorView(const VectorBase& other) 82 : VectorBase(other.const_vec_), view_(NULL) 83 83 { 84 84 } 85 85 */ 86 86 87 vectorView::vectorView(vectorBase& v, size_t offset,size_t n,size_t stride)88 : vectorBase(), const_view_(NULL)87 VectorView::VectorView(VectorBase& v, size_t offset,size_t n,size_t stride) 88 : VectorBase(), const_view_(NULL) 89 89 { 90 90 view_ = … … 95 95 96 96 97 vectorView::vectorView(const vectorBase& v, size_t offset,size_t n,97 VectorView::VectorView(const VectorBase& v, size_t offset,size_t n, 98 98 size_t stride) 99 : vectorBase(), view_(NULL)99 : VectorBase(), view_(NULL) 100 100 { 101 101 const_view_ = new gsl_vector_const_view( … … 106 106 107 107 108 vectorView::vectorView(matrix& m, size_t i, bool row)109 : vectorBase(), const_view_(NULL)108 VectorView::VectorView(matrix& m, size_t i, bool row) 109 : VectorBase(), const_view_(NULL) 110 110 { 111 111 view_=new gsl_vector_view(row ? … … 116 116 117 117 118 vectorView::vectorView(const matrix& m, size_t i, bool row)119 : vectorBase(), view_(NULL)118 VectorView::VectorView(const matrix& m, size_t i, bool row) 119 : VectorBase(), view_(NULL) 120 120 { 121 121 const_view_ = … … 128 128 129 129 /* 130 vectorView::vectorView(proxy p)131 : vectorBase()130 VectorView::VectorView(proxy p) 131 : VectorBase() 132 132 { 133 133 view_ = new gsl_vector_view(gsl_vector_subvector(p.vec_, 0, p.vec_->size)); … … 136 136 */ 137 137 138 vectorView::~vectorView(void)138 VectorView::~VectorView(void) 139 139 { 140 140 delete_allocated_memory(); … … 142 142 143 143 144 const vectorBase& vectorView::assign(const vectorBase& other )144 const VectorBase& VectorView::assign(const VectorBase& other ) 145 145 { 146 146 if (size()!=other.size()) 147 throw utility::GSL_error(" vectorView::dimension mis-match");147 throw utility::GSL_error("VectorView::dimension mis-match"); 148 148 if (!other.size()) 149 149 return *this; … … 154 154 155 155 156 bool vectorView::isview(void) const156 bool VectorView::isview(void) const 157 157 { 158 158 return true; … … 161 161 162 162 163 const vectorBase& vectorView::operator=(const vectorView& other )163 const VectorBase& VectorView::operator=(const VectorView& other ) 164 164 { 165 165 return assign(other); … … 167 167 168 168 169 const vectorBase& vectorView::operator=(const vectorBase& other )169 const VectorBase& VectorView::operator=(const VectorBase& other ) 170 170 { 171 171 return assign(other); … … 174 174 175 175 /* 176 const vectorBase& vectorView::operator=(proxy p)176 const VectorBase& VectorView::operator=(proxy p) 177 177 { 178 178 if (size()!=p.vec_->size) 179 throw utility::GSL_error(" vectorView::dimension mis-match");179 throw utility::GSL_error("VectorView::dimension mis-match"); 180 180 if (!size()) 181 181 return *this; … … 187 187 */ 188 188 189 void vectorView::delete_allocated_memory(void)189 void VectorView::delete_allocated_memory(void) 190 190 { 191 191 if (view_){ -
trunk/yat/utility/VectorView.h
r1013 r1015 29 29 */ 30 30 31 #include " vectorBase.h"31 #include "VectorBase.h" 32 32 #include "Exception.h" 33 33 … … 85 85 */ 86 86 87 class vectorView : public vectorBase87 class VectorView : public VectorBase 88 88 { 89 89 public: … … 91 91 \brief Default constructor. 92 92 */ 93 vectorView(void);93 VectorView(void); 94 94 95 95 /** 96 96 \brief The copy constructor. 97 */ 98 vectorView(vectorBase& other);99 vectorView(vectorView& other);97 */ 98 VectorView(VectorBase& other); 99 VectorView(VectorView& other); 100 100 // Peter, privatize 101 vectorView(const vectorView& other);101 VectorView(const VectorView& other); 102 102 103 103 /** 104 104 \brief VectorView constructor. 105 105 106 Create a view of vectorView \a v, with starting index \a offset,106 Create a view of VectorView \a v, with starting index \a offset, 107 107 size \a n, and an optional \a stride. 108 108 109 A vectorView view can be used as any vectorView with the difference109 A VectorView view can be used as any VectorView with the difference 110 110 that changes made to the view will also change the object that 111 111 is viewed. Also, using the copy constructor will create a new 112 vectorView object that is a copy of whatever is viewed. If a copy112 VectorView object that is a copy of whatever is viewed. If a copy 113 113 of the view is needed then you should use this constructor to 114 114 obtain a copy. … … 120 120 \throw GSL_error if a view cannot be set up. 121 121 */ 122 vectorView(vectorBase& v, size_t offset, size_t n, size_t stride=1);122 VectorView(VectorBase& v, size_t offset, size_t n, size_t stride=1); 123 123 // Peter, privatize 124 vectorView(const vectorBase& v, size_t offset, size_t n, size_t stride=1);124 VectorView(const VectorBase& v, size_t offset, size_t n, size_t stride=1); 125 125 126 126 /// 127 127 /// Matrix row/column view constructor. 128 128 /// 129 /// Create a row/column vectorView view of matrix \a m, pointing at129 /// Create a row/column VectorView view of matrix \a m, pointing at 130 130 /// row/column \a i. The parameter \a row is used to set whether 131 131 /// the view should be a row or column view. If \a row is set to … … 133 133 /// naturally, a column view otherwise. 134 134 /// 135 /// A vectorView view can be used as any vectorView with the difference135 /// A VectorView view can be used as any VectorView with the difference 136 136 /// that changes made to the view will also change the object that 137 137 /// is viewed. Also, using the copy constructor will create a new 138 /// vectorView object that is a copy of whatever is viewed. If a copy139 /// of the view is needed then you should use the vectorView view138 /// VectorView object that is a copy of whatever is viewed. If a copy 139 /// of the view is needed then you should use the VectorView view 140 140 /// constructor to obtain a copy. 141 141 /// … … 144 144 /// use is undefined. 145 145 /// 146 vectorView(matrix& m, size_t i, bool row=true);146 VectorView(matrix& m, size_t i, bool row=true); 147 147 148 148 // Peter should be private 149 vectorView(const matrix& m, size_t i, bool row=true);149 VectorView(const matrix& m, size_t i, bool row=true); 150 150 151 151 /** 152 152 */ 153 // vectorView(proxy p);153 //VectorView(proxy p); 154 154 155 155 /// 156 156 /// The destructor. 157 157 /// 158 ~ vectorView(void);158 ~VectorView(void); 159 159 160 160 /** … … 170 170 \throw GSL_error if dimensions mis-match. 171 171 */ 172 const vectorBase& operator=(const vectorBase&);173 const vectorBase& operator=(const vectorView&);172 const VectorBase& operator=(const VectorBase&); 173 const VectorBase& operator=(const VectorView&); 174 174 175 //const vectorBase& operator=(proxy);175 //const VectorBase& operator=(proxy); 176 176 177 177 private: 178 const vectorBase& assign(const vectorBase& other);178 const VectorBase& assign(const VectorBase& other); 179 179 void delete_allocated_memory(void); 180 180 -
trunk/yat/utility/matrix.cc
r1009 r1015 27 27 #include "matrix.h" 28 28 #include "vector.h" 29 #include " vectorView.h"29 #include "VectorView.h" 30 30 #include "utility.h" 31 31 … … 303 303 304 304 305 vectorView matrix::column_vec(size_t col)306 { 307 vectorView res(*this, col, false);305 VectorView matrix::column_vec(size_t col) 306 { 307 VectorView res(*this, col, false); 308 308 return res; 309 309 } 310 310 311 311 312 const vectorView matrix::column_vec(size_t col) const313 { 314 return vectorView(*this, col, false);315 } 316 317 318 const vectorView matrix::row_vec(size_t col) const319 { 320 return vectorView(*this, col, true);321 } 322 323 324 vectorView matrix::row_vec(size_t row)325 { 326 vectorView res(*this, row, true);312 const VectorView matrix::column_vec(size_t col) const 313 { 314 return VectorView(*this, col, false); 315 } 316 317 318 const VectorView matrix::row_vec(size_t col) const 319 { 320 return VectorView(*this, col, true); 321 } 322 323 324 VectorView matrix::row_vec(size_t row) 325 { 326 VectorView res(*this, row, true); 327 327 return res; 328 328 } … … 558 558 559 559 560 vector operator*(const matrix& m, const vectorBase& v)560 vector operator*(const matrix& m, const VectorBase& v) 561 561 { 562 562 utility::vector res(m.rows()); 563 563 for (size_t i=0; i<res.size(); ++i) 564 res(i) = vectorView(m,i) * v;564 res(i) = VectorView(m,i) * v; 565 565 return res; 566 566 } … … 571 571 utility::vector res(m.columns()); 572 572 for (size_t i=0; i<res.size(); ++i) 573 res(i) = v * vectorView(m,i,false);573 res(i) = v * VectorView(m,i,false); 574 574 return res; 575 575 } -
trunk/yat/utility/matrix.h
r1014 r1015 28 28 */ 29 29 30 #include "vectorBase.h"31 30 #include "vector.h" 32 #include "vectorView.h" 31 #include "VectorBase.h" 32 #include "VectorView.h" 33 33 #include "Exception.h" 34 34 … … 158 158 /** 159 159 */ 160 vectorView column_vec(size_t);160 VectorView column_vec(size_t); 161 161 162 162 /** 163 163 */ 164 const vectorView column_vec(size_t) const;164 const VectorView column_vec(size_t) const; 165 165 166 166 /// … … 233 233 /** 234 234 */ 235 vectorView row_vec(size_t);235 VectorView row_vec(size_t); 236 236 237 237 /** 238 238 */ 239 const vectorView row_vec(size_t) const;239 const VectorView row_vec(size_t) const; 240 240 241 241 /** … … 500 500 \brief vector matrix multiplication 501 501 */ 502 vector operator*(const matrix&, const vectorBase&);502 vector operator*(const matrix&, const VectorBase&); 503 503 504 504 /** -
trunk/yat/utility/vector.cc
r1010 r1015 44 44 45 45 vector::vector(void) 46 : vectorBase()46 : VectorBase() 47 47 { 48 48 } … … 50 50 51 51 vector::vector(size_t n, double init_value) 52 : vectorBase(gsl_vector_alloc(n))52 : VectorBase(gsl_vector_alloc(n)) 53 53 { 54 54 if (!vec_) … … 60 60 61 61 vector::vector(const vector& other) 62 : vectorBase(create_gsl_vector_copy(other))63 { 64 } 65 66 67 vector::vector(const vectorBase& other)68 : vectorBase(create_gsl_vector_copy(other))62 : VectorBase(create_gsl_vector_copy(other)) 63 { 64 } 65 66 67 vector::vector(const VectorBase& other) 68 : VectorBase(create_gsl_vector_copy(other)) 69 69 { 70 70 } … … 73 73 vector::vector(std::istream& is, char sep) 74 74 throw (utility::IO_error, std::exception) 75 : vectorBase()75 : VectorBase() 76 76 { 77 77 // read the data file and store in stl vectors (dynamically … … 155 155 156 156 157 gsl_vector* vector::create_gsl_vector_copy(const vectorBase& other) const157 gsl_vector* vector::create_gsl_vector_copy(const VectorBase& other) const 158 158 { 159 159 gsl_vector* vec = gsl_vector_alloc(other.size()); … … 193 193 /* 194 194 //Peter use swap idiom 195 const vectorBase& vector::operator=( const vectorBase& other )195 const VectorBase& vector::operator=( const VectorBase& other ) 196 196 { 197 197 if (!other.size()) … … 206 206 */ 207 207 208 const vectorBase& vector::operator=( const vector& other )208 const VectorBase& vector::operator=( const vector& other ) 209 209 { 210 210 return assign(other); … … 212 212 213 213 /* 214 const vectorBase& vector::assign(vectorBase& other)214 const VectorBase& vector::assign(VectorBase& other) 215 215 { 216 216 assign(other); … … 218 218 */ 219 219 220 const vectorBase& vector::assign(const vectorBase& other)220 const VectorBase& vector::assign(const VectorBase& other) 221 221 { 222 222 if (!other.size()) -
trunk/yat/utility/vector.h
r1009 r1015 29 29 */ 30 30 31 #include " vectorBase.h"31 #include "VectorBase.h" 32 32 #include "Exception.h" 33 33 #include "Iterator.h" … … 85 85 */ 86 86 87 class vector : public vectorBase87 class vector : public VectorBase 88 88 { 89 89 public: … … 122 122 fails. 123 123 */ 124 vector(const vectorBase& other);124 vector(const VectorBase& other); 125 125 126 126 /** … … 159 159 void resize(size_t n, double init_value); 160 160 161 // using vectorBase::operator=;161 // using VectorBase::operator=; 162 162 163 163 /** … … 166 166 \return A const reference to the resulting vector. 167 167 */ 168 //const vectorBase& operator=(const vectorBase&);169 const vectorBase& operator=(const vector&);168 //const VectorBase& operator=(const VectorBase&); 169 const VectorBase& operator=(const vector&); 170 170 171 171 private: 172 const vectorBase& assign(const vectorBase& other);173 //const vectorBase& assign(vectorBase& other);172 const VectorBase& assign(const VectorBase& other); 173 //const VectorBase& assign(VectorBase& other); 174 174 175 175 /** … … 184 184 copy, or if dimensions mis-match. 185 185 */ 186 gsl_vector* create_gsl_vector_copy(const vectorBase&) const;186 gsl_vector* create_gsl_vector_copy(const VectorBase&) const; 187 187 188 188 void delete_allocated_memory(void);
Note: See TracChangeset
for help on using the changeset viewer.