Changeset 1027 for trunk/yat/utility/VectorBase.cc
- Timestamp:
- Feb 2, 2008, 10:29:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/VectorBase.cc
r1015 r1027 43 43 44 44 45 VectorBase::VectorBase(void)46 : vec_(NULL), const_vec_(NULL)47 {48 }49 50 51 VectorBase::VectorBase(gsl_vector* v)52 : vec_(v), const_vec_(v)53 {54 }55 56 57 45 VectorBase::VectorBase(const gsl_vector* v) 58 : vec_(NULL),const_vec_(v)46 : const_vec_(v) 59 47 { 60 48 } … … 66 54 67 55 68 void VectorBase::all(double value)69 {70 assert(vec_);71 gsl_vector_set_all(vec_,value);72 }73 74 75 56 VectorBase::const_iterator VectorBase::begin(void) const 76 57 { … … 79 60 80 61 81 VectorBase::iterator VectorBase::begin(void)82 {83 return iterator(*this, 0);84 }85 86 87 void VectorBase::div(const VectorBase& other)88 {89 assert(vec_);90 int status=gsl_vector_div(vec_,other.gsl_vector_p());91 if (status)92 throw utility::GSL_error(std::string("VectorBase::div",status));93 }94 95 96 62 VectorBase::const_iterator VectorBase::end(void) const 97 63 { 98 64 return const_iterator(*this, size()); 99 }100 101 102 VectorBase::iterator VectorBase::end(void)103 {104 return iterator(*this, size());105 65 } 106 66 … … 128 88 129 89 130 gsl_vector* VectorBase::gsl_vector_p(void)131 {132 return vec_;133 }134 135 136 void VectorBase::mul(const VectorBase& other)137 {138 assert(vec_);139 int status=gsl_vector_mul(vec_,other.gsl_vector_p());140 if (status)141 throw utility::GSL_error(std::string("VectorBase::div",status));142 }143 144 145 90 size_t VectorBase::size(void) const 146 91 { … … 160 105 161 106 162 double& VectorBase::operator()(size_t i)163 {164 double* d=gsl_vector_ptr(vec_, i);165 if (!d)166 throw utility::GSL_error("VectorBase::operator()",GSL_EINVAL);167 return *d;168 }169 170 171 double& VectorBase::operator[](size_t i)172 {173 return this->operator()(i);174 }175 176 177 107 const double& VectorBase::operator[](size_t i) const 178 108 { … … 199 129 res += other(i) * (*this)(i); 200 130 return res; 201 }202 203 204 const VectorBase& VectorBase::operator+=(double d)205 {206 assert(vec_);207 gsl_vector_add_constant(vec_, d);208 return *this;209 }210 211 212 const VectorBase& VectorBase::operator-=(const VectorBase& other)213 {214 assert(vec_);215 int status=gsl_vector_sub(vec_, other.gsl_vector_p());216 if (status)217 throw utility::GSL_error(std::string("VectorBase::sub", status));218 return *this;219 }220 221 222 const VectorBase& VectorBase::operator-=(const double d)223 {224 assert(vec_);225 gsl_vector_add_constant(vec_, -d);226 return *this;227 }228 229 230 const VectorBase& VectorBase::operator*=(double d)231 {232 assert(vec_);233 gsl_vector_scale(vec_, d);234 return *this;235 131 } 236 132 … … 280 176 281 177 282 void shuffle(VectorBase& invec)283 {284 random::DiscreteUniform rnd;285 std::random_shuffle(invec.begin(), invec.end(), rnd);286 }287 288 289 178 void sort_index(std::vector<size_t>& sort_index, const VectorBase& invec) 290 179 {
Note: See TracChangeset
for help on using the changeset viewer.