Changeset 754 for trunk/yat/utility/vector.cc
- Timestamp:
- Feb 17, 2007, 11:33:44 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/vector.cc
r753 r754 67 67 : v_const_(NULL), view_const_(NULL) 68 68 { 69 // Jari, exception handling needed here. Failure in setting up a70 // proper gsl_vector_view is communicated by NULL pointer in the71 // view structure (cf. GSL manual). How about GSL error state?72 69 view_ = new gsl_vector_view(gsl_vector_subvector_with_stride(v.v_,offset, 73 70 stride,n)); … … 81 78 : v_(NULL), view_(NULL) 82 79 { 83 // Jari, exception handling needed here. Failure in setting up a84 // proper gsl_vector_view is communicated by NULL pointer in the85 // view structure (cf. GSL manual). How about GSL error state?86 80 view_const_ = new gsl_vector_const_view( 87 81 gsl_vector_const_subvector_with_stride(v.v_,offset,stride,n)); … … 181 175 throw utility::GSL_error("vector::vector failed to allocate memory"); 182 176 size_t n=0; 177 // if gsl error handler disabled, out of bounds index will not 178 // abort the program. 183 179 for (size_t i=0; i<nof_rows; i++) 184 180 for (size_t j=0; j<nof_columns; j++) … … 198 194 199 195 200 int vector::add(const vector& other) 201 { 202 return gsl_vector_add(v_,other.v_); 203 } 204 205 206 int vector::add(double term) 207 { 208 return gsl_vector_add_constant(v_,term); 196 void vector::add(const vector& other) 197 { 198 int status=gsl_vector_add(v_,other.v_); 199 if (status) 200 throw utility::GSL_error(std::string("vector::add",status)); 201 } 202 203 204 void vector::add(double term) 205 { 206 gsl_vector_add_constant(v_,term); 209 207 } 210 208 … … 215 213 if (!vec) 216 214 throw utility::GSL_error("vector::create_gsl_vector_copy failed to allocate memory"); 217 gsl_vector_memcpy(vec, proxy_v_); 215 if (gsl_vector_memcpy(vec, proxy_v_)) 216 throw utility::GSL_error("vector::create_gsl_matrix_copy dimension mis-match"); 218 217 return vec; 219 218 } … … 302 301 303 302 304 int vector::scale(double factor) 305 { 306 return gsl_vector_scale(v_,factor); 307 } 308 309 310 int vector::set(const vector& vec) 311 { 312 return gsl_vector_memcpy(v_,vec.v_); 303 void vector::scale(double factor) 304 { 305 gsl_vector_scale(v_,factor); 306 } 307 308 309 void vector::set(const vector& vec) 310 { 311 if (gsl_vector_memcpy(v_,vec.v_)) 312 throw utility::GSL_error("vector::set dimension mis-match"); 313 313 } 314 314 … … 346 346 347 347 348 int vector::sub(const vector& other) 349 { 350 return gsl_vector_sub(v_,other.v_); 348 void vector::sub(const vector& other) 349 { 350 int status=gsl_vector_sub(v_,other.v_); 351 if (status) 352 throw utility::GSL_error(std::string("vector::sub",status)); 351 353 } 352 354 … … 435 437 const vector& vector::operator+=(const vector& other) 436 438 { 437 gsl_vector_add(v_,other.v_);439 add(other); 438 440 return *this; 439 441 } … … 442 444 const vector& vector::operator-=(const vector& other) 443 445 { 444 gsl_vector_sub(v_,other.v_);446 sub(other); 445 447 return *this; 446 448 } … … 449 451 const vector& vector::operator*=(const double d) 450 452 { 451 gsl_vector_scale(v_,d);453 scale(d); 452 454 return *this; 453 455 }
Note: See TracChangeset
for help on using the changeset viewer.