Changeset 1015 for trunk/yat/utility/VectorBase.cc
 Timestamp:
 Feb 1, 2008, 5:35:32 PM (15 years ago)
 File:

 1 moved
Legend:
 Unmodified
 Added
 Removed

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);
Note: See TracChangeset
for help on using the changeset viewer.