- Timestamp:
- Feb 17, 2007, 11:33:44 PM (16 years ago)
- Location:
- trunk/yat/utility
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/matrix.cc
r753 r754 64 64 size_t n_row, size_t n_column) 65 65 { 66 // Jari, exception handling needed here. Failure in setting up a67 // proper gsl_matrix_view is communicated by NULL pointer in the68 // view structure (cf. GSL manual). How about GSL error state?69 66 view_ = new gsl_matrix_view(gsl_matrix_submatrix(m.m_, 70 67 offset_row,offset_column, … … 142 139 if (!m_) 143 140 throw utility::GSL_error("matrix::matrix failed to allocate memory"); 141 142 // if gsl error handler disabled, out of bounds index will not 143 // abort the program. 144 144 for(u_int i=0;i<nof_rows;i++) 145 145 for(u_int j=0;j<nof_columns;j++) … … 158 158 159 159 160 int matrix::add(const matrix& b) 161 { 162 return gsl_matrix_add(m_, b.m_); 163 } 164 165 166 int matrix::add_constant(const double d) 167 { 168 return gsl_matrix_add_constant(m_, d); 160 void matrix::add(const matrix& b) 161 { 162 int status=gsl_matrix_add(m_, b.m_); 163 if (status) 164 throw utility::GSL_error(std::string("matrix::add",status)); 165 } 166 167 168 void matrix::add(double d) 169 { 170 gsl_matrix_add_constant(m_, d); 169 171 } 170 172 … … 183 185 if (!m) 184 186 throw utility::GSL_error("matrix::create_gsl_matrix_copy failed to allocate memory"); 185 gsl_matrix_memcpy(m,m_); // Jari, a GSL return value is ignored here 187 if (gsl_matrix_memcpy(m,m_)) 188 throw utility::GSL_error("matrix::create_gsl_matrix_copy dimension mis-match"); 186 189 return m; 187 190 } … … 280 283 281 284 282 int matrix::scale(const double d) 283 { 284 return gsl_matrix_scale(m_, d); 285 } 286 287 288 int matrix::set(const matrix& mat) 289 { 290 return gsl_matrix_memcpy(m_, mat.m_); 285 void matrix::scale(const double d) 286 { 287 gsl_matrix_scale(m_, d); 288 } 289 290 291 void matrix::set(const matrix& mat) 292 { 293 if (gsl_matrix_memcpy(m_, mat.m_)) 294 throw utility::GSL_error("matrix::create_gsl_matrix_copy dimension mis-match"); 291 295 } 292 296 … … 298 302 299 303 300 int matrix::set_column(const size_t column, const vector& vec) 301 { 302 return gsl_matrix_set_col(m_, column, vec.gsl_vector_p()); 303 } 304 305 306 int matrix::set_row(const size_t row, const vector& vec) 307 { 308 return gsl_matrix_set_row(m_, row, vec.gsl_vector_p()); 309 } 310 311 312 int matrix::sub(const matrix& b) 313 { 314 return gsl_matrix_sub(m_, b.m_); 304 void matrix::set_column(const size_t column, const vector& vec) 305 { 306 int status=gsl_matrix_set_col(m_, column, vec.gsl_vector_p()); 307 if (status) 308 throw utility::GSL_error(std::string("matrix::set_column",status)); 309 } 310 311 312 void matrix::set_row(const size_t row, const vector& vec) 313 { 314 int status=gsl_matrix_set_row(m_, row, vec.gsl_vector_p()); 315 if (status) 316 throw utility::GSL_error(std::string("matrix::set_row",status)); 317 } 318 319 320 void matrix::sub(const matrix& b) 321 { 322 int status=gsl_matrix_sub(m_, b.m_); 323 if (status) 324 throw utility::GSL_error(std::string("matrix::sub",status)); 315 325 } 316 326 … … 340 350 341 351 342 // Jari, checkout GSL transpose support in GSL manual 8.4.9343 352 void matrix::transpose(void) 344 353 { 345 354 if (columns()==rows()) 346 gsl_matrix_transpose(m_); 355 gsl_matrix_transpose(m_); // this never fails 347 356 else { 348 357 gsl_matrix* transposed = gsl_matrix_alloc(columns(),rows()); 349 358 if (!transposed) 350 359 throw utility::GSL_error("matrix::transpose failed to allocate memory"); 360 // next line never fails if allocation above succeeded. 351 361 gsl_matrix_transpose_memcpy(transposed,m_); 352 362 gsl_matrix_free(m_); … … 402 412 const matrix& matrix::operator+=(const double d) 403 413 { 404 add _constant(d);414 add(d); 405 415 return *this; 406 416 } -
trunk/yat/utility/matrix.h
r737 r754 9 9 Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér 10 10 Copyright (C) 2006 Jari Häkkinen, Peter Johansson 11 Copyright (C) 2007 Jari Häkkinen 11 12 12 13 This file is part of the yat library, http://lev.thep.lu.se/trac/yat … … 83 84 matrix(void); 84 85 85 /// 86 /// @brief Constructor allocating memory space for \a r times \a c 87 /// elements, and sets all elements to \a init_value. 88 /// 86 /** 87 \brief Constructor allocating memory space for \a r times \a c 88 elements, and sets all elements to \a init_value. 89 90 \throw GSL_error if memory allocation fails. 91 */ 89 92 matrix(const size_t& r, const size_t& c, double init_value=0); 90 93 91 /// 92 /// @brief The copy constructor. 93 /// 94 /// @note If the object to be copied is a matrix view, the values 95 /// of the view will be copied, i.e. the view is not copied. 96 /// 94 /** 95 \brief The copy constructor. 96 97 \note If the object to be copied is a matrix view, the values 98 of the view will be copied, i.e. the view is not copied. 99 100 \throw A GSL_error is indirectly thrown if memory allocation 101 fails. 102 */ 97 103 matrix(const matrix&); 98 104 99 /// 100 /// The matrix view constructor. 101 /// 102 /// Create a view of matrix \a m, with starting row \a offset_row, 103 /// starting column \a offset_column, row size \a n_row, and 104 /// column size \a n_column. 105 /// 106 /// A matrix view can be used as any matrix with the difference 107 /// that changes made to the view will also change the object that 108 /// is viewed. Also, using the copy constructor will create a new 109 /// matrix object that is a copy of whatever is viewed. If a copy 110 /// of the view is needed then you should use this constructor to 111 /// obtain a copy. 112 /// 113 /// @note If the object viewed by the view goes out of scope or is 114 /// deleted, the view becomes invalid and the result of further 115 /// use is undefined. 116 /// 105 /** 106 \brief The matrix view constructor. 107 108 Create a view of matrix \a m, with starting row \a offset_row, 109 starting column \a offset_column, row size \a n_row, and column 110 size \a n_column. 111 112 A matrix view can be used as any matrix with the difference 113 that changes made to the view will also change the object that 114 is viewed. Also, using the copy constructor will create a new 115 matrix object that is a copy of whatever is viewed. If a copy 116 of the view is needed then you should use this constructor to 117 obtain a copy. 118 119 \note If the object viewed by the view goes out of scope or is 120 deleted, the view becomes invalid and the result of further use 121 is undefined. 122 123 \throw GSL_error if a view cannot be set up. 124 */ 117 125 matrix(matrix& m, size_t offset_row, size_t offset_column, size_t n_row, 118 126 size_t n_column); 119 127 120 /// 121 /// The istream constructor. 122 /// 123 /// Matrix rows are sepearated with the new line character, and 124 /// column elements in a row must be separated either with white space 125 /// characters except the new line (\\n) character (default), or 126 /// by the delimiter \a sep. 127 ///. Rows, and 128 /// columns, are read consecutively and only rectangular matrices 129 /// are supported. Empty lines are ignored. End of input is at end 130 /// of file marker. 131 /// 128 /** 129 \brief The istream constructor. 130 131 Matrix rows are sepearated with the new line character, and 132 column elements in a row must be separated either with white 133 space characters except the new line (\\n) character (default), 134 or by the delimiter \a sep. Rows, and columns, are read 135 consecutively and only rectangular matrices are 136 supported. Empty lines are ignored. End of input is at end of 137 file marker. 138 139 \throw GSL_error if memory allocation fails. 140 */ 132 141 explicit matrix(std::istream &, char sep='\0') 133 142 throw(utility::IO_error, std::exception); 134 143 135 / //136 /// @brief The destructor.137 ///144 /** 145 \brief The destructor. 146 */ 138 147 ~matrix(void); 139 148 140 /// 141 /// Elementwise addition of the elements of matrix \a b to the 142 /// elements of the calling matrix ,\f$ a_{ij} = a_{ij} + b_{ij} \; 143 /// \forall i,j \f$. The result is stored into the calling matrix. 144 /// 145 /// @return Whatever GSL returns. 146 /// 147 int add(const matrix& b); 148 149 /// 150 /// Add the scalar value \a d to the elements of the calling 151 /// matrix, \f$ a_{ij} = a_{ij} + d \; \forall i,j \f$. The result 152 /// is stored into the calling matrix. 153 /// 154 /// @return Whatever GSL returns. 155 /// 156 int add_constant(const double d); 149 /** 150 Elementwise addition of the elements of matrix \a b to the 151 elements of the calling matrix ,\f$ a_{ij} = a_{ij} + b_{ij} \; 152 \forall i,j \f$. The result is stored into the calling matrix. 153 154 \throw GSL_error if dimensions mis-match. 155 */ 156 void add(const matrix& b); 157 158 /** 159 Add the scalar value \a d to the elements of the calling 160 matrix, \f$ a_{ij} = a_{ij} + d \; \forall i,j \f$. The result 161 is stored into the calling matrix. 162 */ 163 void add(double d); 157 164 158 165 /// … … 246 253 size_t rows(void) const; 247 254 248 /// 249 /// Multiply the elements of the calling matrix with a scalar \a 250 /// d, \f$ a_{ij} = d * a_{ij} \; \forall i,j \f$. The result is 251 /// stored into the calling matrix. 252 /// 253 /// @return Whatever GSL returns. 254 /// 255 int scale(const double d); 256 257 /// 258 /// Set element values to values in \a mat. This function is 259 /// needed for assignment of viewed elements. 260 /// 261 /// @return Whatever GSL returns. 262 /// 263 /// @note No check on size is done. 264 /// 265 /// @see const matrix& operator=(const matrix&) 266 /// 267 int set(const matrix& mat); 255 /** 256 Multiply the elements of the calling matrix with a scalar \a d, 257 \f$ a_{ij} = d * a_{ij} \; \forall i,j \f$. The result is 258 stored into the calling matrix. 259 */ 260 void scale(const double d); 261 262 /** 263 \brief Set element values to values in \a mat. 264 265 This function is needed for assignment of viewed elements. 266 267 \see const matrix& operator=(const matrix&) 268 269 \throw GSL_error if dimensions mis-match. 270 */ 271 void set(const matrix& mat); 268 272 269 273 /// … … 272 276 void set_all(const double value); 273 277 274 /// 275 /// Set \a column values to values in \a vec. 276 /// 277 /// @return Whatever GSL returns. 278 /// 279 /// @note No check on size is done. 280 /// 281 int set_column(const size_t column, const vector& vec); 282 283 /// 284 /// @brief Set \a row values to values in \a vec. 285 /// 286 /// @return Whatever GSL returns. 287 /// 288 /// @note No check on size is done. 289 /// 290 int set_row(const size_t row, const vector& vec); 291 292 /// 293 /// Subtract the elements of matrix \a b from the elements of the 294 /// calling matrix ,\f$ a_{ij} = a_{ij} - b_{ij} \; \forall 295 /// i,j \f$. The result is stored into the calling matrix. 296 /// 297 /// @return Whatever GSL returns. 298 /// 299 int sub(const matrix& b); 278 /** 279 \brief Set \a column values to values in \a vec. 280 281 \note No check on size is done. 282 283 \throw GSL_error if index is out of range or mis-match in 284 sizes. 285 */ 286 void set_column(const size_t column, const vector& vec); 287 288 /** 289 \brief Set \a row values to values in \a vec. 290 291 \note No check on size is done. 292 293 \throw GSL_error if index is out of range or mis-match in 294 sizes. 295 */ 296 void set_row(const size_t row, const vector& vec); 297 298 /** 299 Subtract the elements of matrix \a b from the elements of the 300 calling matrix ,\f$ a_{ij} = a_{ij} - b_{ij} \; \forall i,j 301 \f$. The result is stored into the calling matrix. 302 303 \throw GSL_error if dimensions mis-match. 304 */ 305 void sub(const matrix& b); 300 306 301 307 /// … … 322 328 int swap_rows(const size_t i, const size_t j); 323 329 324 /// 325 /// @brief Transpose the matrix. 326 /// 330 /** 331 \brief Transpose the matrix. 332 333 \throw GSL_error if memory allocation fails for the new 334 transposed matrix. 335 */ 327 336 void transpose(void); 328 337 … … 356 365 bool operator!=(const matrix& other) const; 357 366 358 /// 359 /// @brief The assignment operator. 360 /// 361 /// There is no requirements on dimensions, i.e. the matrix is 362 /// remapped in memory if necessary. This implies that in general 363 /// views cannot be assigned using this operator. Views will be 364 /// mutated into normal matrices. The only exception to this 365 /// behaviour on views is when self-assignemnt is done, since 366 /// self-assignment is ignored. 367 /// 368 /// @return A const reference to the resulting matrix. 369 /// 370 /// @see int set(const matrix&) 371 /// 367 /** 368 \brief The assignment operator. 369 370 There is no requirements on dimensions, i.e. the matrix is 371 remapped in memory if necessary. This implies that in general 372 views cannot be assigned using this operator. Views will be 373 mutated into normal matrices. The only exception to this 374 behaviour on views is when self-assignemnt is done, since 375 self-assignment is ignored. 376 377 \return A const reference to the resulting matrix. 378 379 \see void set(const matrix&). 380 381 \throw A GSL_error is indirectly thrown if memory allocation 382 fails, or if dimensions mis-match. 383 */ 372 384 const matrix& operator=(const matrix& other); 373 385 386 /** 387 \brief Add and assign operator. 388 389 \return A const reference to the resulting matrix. 390 391 \throw GSL_error if dimensions mis-match. 392 */ 393 const matrix& operator+=(const matrix&); 394 374 395 /// 375 396 /// @brief Add and assign operator. 376 397 /// 377 const matrix& operator+=(const matrix&);378 379 ///380 /// @brief Add and assign operator.381 ///382 398 const matrix& operator+=(const double); 383 399 384 /// 385 /// @brief Subtract and assign operator. 386 /// 400 /** 401 \brief Subtract and assign operator. 402 403 \return A const reference to the resulting matrix. 404 405 \throw GSL_error if dimensions mis-match. 406 */ 387 407 const matrix& operator-=(const matrix&); 388 408 389 /// 390 /// @brief Multiply and assigment operator. 391 /// 392 /// @return Const reference to the resulting matrix. 393 /// 409 /** 410 \brief Multiply and assigment operator. 411 412 \return Const reference to the resulting matrix. 413 414 \throw GSL_error if memory allocation fails. 415 */ 394 416 const matrix& operator*=(const matrix&); 395 417 396 /// 397 /// @brief Multiply and assignment operator 398 /// 418 /** 419 \brief Multiply and assignment operator 420 421 \throw GSL_error if memory allocation fails. 422 */ 399 423 const matrix& operator*=(const double); 400 424 401 425 private: 402 426 403 /// 404 /// Create a new copy of the internal GSL matrix. 405 /// 406 /// Necessary memory for the new GSL matrix is allocated and the 407 /// caller is responsible for freeing the allocated memory. 408 /// 409 /// @return A pointer to a copy of the internal GSL matrix. 410 /// 427 /** 428 \brief Create a new copy of the internal GSL matrix. 429 430 Necessary memory for the new GSL matrix is allocated and the 431 caller is responsible for freeing the allocated memory. 432 433 \return A pointer to a copy of the internal GSL matrix. 434 435 \throw GSL_error if memory cannot be allocated for the new 436 copy, or if dimensions mis-match. 437 */ 411 438 gsl_matrix* create_gsl_matrix_copy(void) const; 412 439 -
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 } -
trunk/yat/utility/vector.h
r714 r754 8 8 Copyright (C) 2004 Jari Häkkinen, Peter Johansson 9 9 Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér 10 Copyright (C) 2006 Jari Häkkinen10 Copyright (C) 2006, 2007 Jari Häkkinen 11 11 12 12 This file is part of the yat library, http://lev.thep.lu.se/trac/yat … … 88 88 public: 89 89 90 / //91 ///The default constructor.92 ///90 /** 91 \brief The default constructor. 92 */ 93 93 vector(void); 94 94 95 /// 96 /// Constructor. Allocates memory space for \a n elements, and 97 /// sets all elements to \a init_value. 98 /// 95 /** 96 \brief Allocates memory space for \a n elements, and sets all 97 elements to \a init_value. 98 99 \throw GSL_error if memory allocation fails. 100 */ 99 101 vector(size_t n, double init_value=0); 100 102 101 /// 102 /// The copy constructor. 103 /// 104 /// @note If the object to be copied is a vector view, the values 105 /// of the view will be copied, i.e. the view is not copied. 106 /// 103 /** 104 \brief The copy constructor. 105 106 \note If the object to be copied is a vector view, the values 107 of the view will be copied, i.e. the view is not copied. 108 109 \throw A GSL_error is indirectly thrown if memory allocation 110 fails. 111 */ 107 112 vector(const vector& other); 108 113 109 /// 110 /// Vector view constructor. 111 /// 112 /// Create a view of vector \a v, with starting index \a offset, 113 /// size \a n, and an optional \a stride. 114 /// 115 /// A vector view can be used as any vector with the difference 116 /// that changes made to the view will also change the object that 117 /// is viewed. Also, using the copy constructor will create a new 118 /// vector object that is a copy of whatever is viewed. If a copy 119 /// of the view is needed then you should use this constructor to 120 /// obtain a copy. 121 /// 122 /// @note If the object viewed by the view goes out of scope or is 123 /// deleted, the view becomes invalid and the result of further 124 /// use is undefined. 125 /// 114 /** 115 \brief Vector view constructor. 116 117 Create a view of vector \a v, with starting index \a offset, 118 size \a n, and an optional \a stride. 119 120 A vector view can be used as any vector with the difference 121 that changes made to the view will also change the object that 122 is viewed. Also, using the copy constructor will create a new 123 vector object that is a copy of whatever is viewed. If a copy 124 of the view is needed then you should use this constructor to 125 obtain a copy. 126 127 \note If the object viewed by the view goes out of scope or is 128 deleted, the view becomes invalid and the result of further use 129 is undefined. 130 131 \throw GSL_error if a view cannot be set up. 132 */ 126 133 vector(vector& v, size_t offset, size_t n, size_t stride=1); 127 134 128 /// 129 /// Vector const view constructor. 130 /// 131 /// Create a view of vector \a v, with starting index \a offset, 132 /// size \a n, and an optional \a stride. 133 /// 134 /// A vector view can be used as any const vector. Using the copy 135 /// constructor will create a new vector object that is a copy of 136 /// whatever is viewed. If a copy of the view is needed then you 137 /// should use this constructor to obtain a copy. 138 /// 139 /// @note If the object viewed by the view goes out of scope or is 140 /// deleted, the view becomes invalid and the result of further 141 /// use is undefined. 142 /// 135 /** 136 \brief Vector const view constructor. 137 138 Create a view of vector \a v, with starting index \a offset, 139 size \a n, and an optional \a stride. 140 141 A vector view can be used as any const vector. Using the copy 142 constructor will create a new vector object that is a copy of 143 whatever is viewed. If a copy of the view is needed then you 144 should use this constructor to obtain a copy. 145 146 \note If the object viewed by the view goes out of scope or is 147 deleted, the view becomes invalid and the result of further use 148 is undefined. 149 150 \throw GSL_error if a view cannot be set up. 151 */ 143 152 vector(const vector& v, size_t offset, size_t n, size_t stride=1); 144 153 … … 186 195 vector(const matrix& m, size_t i, bool row=true); 187 196 188 /// 189 /// The istream constructor. 190 /// 191 /// Either elements should be separated 192 /// with white space characters (default), or elements should be separated 193 /// by the delimiter \a sep. When delimiter \a sep is used empty elements 194 /// are stored as NaN's (except that empty lines are ignored). The 195 /// end of input to the vector is at end of file marker. 196 /// 197 /** 198 \brief The istream constructor. 199 200 Either elements should be separated with white space characters 201 (default), or elements should be separated by the delimiter \a 202 sep. When delimiter \a sep is used empty elements are stored as 203 NaN's (except that empty lines are ignored). The end of input 204 to the vector is at end of file marker. 205 206 \throw GSL_error if memory allocation fails. 207 */ 197 208 explicit vector(std::istream &, char sep='\0') 198 209 throw(utility::IO_error, std::exception); … … 203 214 ~vector(void); 204 215 205 /// 206 /// Vector addition, \f$ this_i = this_i + other_i \; \forall i \f$. 207 /// 208 /// @return GSL_SUCCESS on normal exit. 209 /// 210 // Jari, group as vector_operators 211 int add(const vector& other); 212 213 /// 214 /// Add a constant to a vector, \f$ this_i = this_i + term \; 215 /// \forall i \f$. 216 /// 217 /// @return GSL_SUCCESS on normal exit. 218 /// 219 // Jari, group as vector_operators 220 int add(double term); 216 /** 217 \brief Vector addition, \f$ this_i = this_i + other_i \; 218 \forall i \f$. 219 220 \throw GSL_error if dimensions mis-match. 221 */ 222 void add(const vector& other); 223 224 /** 225 \brief Add a constant to a vector, \f$ this_i = this_i + term \; 226 \forall i \f$. 227 */ 228 void add(double term); 221 229 222 230 /// … … 312 320 int reverse(void); 313 321 314 /// 315 /// Rescale vector, \f$ this_i = this_i * factor \; \forall i \f$. 316 /// 317 /// @return GSL_SUCCESS on normal exit. 318 /// 319 // Jari, doxygen group as Vector operators 320 int scale(double factor); 321 322 /// 323 /// Set element values to values in \a vec. This function is 324 /// needed for assignment of viewed elements. 325 /// 326 /// @return Whatever GSL returns. 327 /// 328 /// @note No check on size is done. 329 /// 330 /// @see const vector& operator=(const vector&) 331 /// 332 int set(const vector& vec); 322 /** 323 \brief Rescale vector, \f$ this_i = this_i * factor \; \forall i \f$. 324 */ 325 void scale(double factor); 326 327 /** 328 \brief Set element values to values in \a vec. 329 330 This function is needed for assignment of viewed elements. 331 332 \see const vector& operator=(const vector&) 333 334 \throw GSL_error if dimensions mis-match. 335 */ 336 void set(const vector& vec); 333 337 334 338 /// … … 365 369 void sort(void); 366 370 367 / //368 /// Vector subtraction, \f$ this_i = this_i - other_i \; \forall i \f$.369 ///370 /// @return GSL_SUCCESS on normal exit. 371 ///372 // Jari, doxygen group as Vector operators373 intsub(const vector& other);371 /** 372 \brief Vector subtraction, \f$ this_i = this_i - other_i \; 373 \forall i \f$. 374 375 \throw GSL_error if dimensions mis-match. 376 */ 377 void sub(const vector& other); 374 378 375 379 /// … … 441 445 double operator*(const vector&) const; 442 446 443 /// 444 /// The assignment operator. There is no requirements on 445 /// dimensions, i.e. the vector is remapped in memory if 446 /// necessary. This implies that in general views cannot be 447 /// assigned using this operator. Views will be mutated into 448 /// normal vectors. The only exception to this behaviour on views 449 /// is when self-assignemnt is done, since self-assignment is 450 /// ignored. 447 /** 448 \brief The assignment operator. 449 450 There is no requirements on dimensions, i.e. the vector is 451 remapped in memory if necessary. This implies that in general 452 views cannot be assigned using this operator. Views will be 453 mutated into normal vectors. The only exception to this 454 behaviour on views is when self-assignemnt is done, since 455 self-assignment is ignored. 456 457 \return A const reference to the resulting vector. 458 459 \see void set(const vector&). 460 461 \throw A GSL_error is indirectly thrown if memory allocation 462 fails, or if dimensions mis-match. 463 */ 464 const vector& operator=(const vector&); 465 466 /** 467 \brief Addition and assign operator. 468 469 \return A const reference to the resulting vector. 470 471 \throw GSL_error if dimensions mis-match. 472 */ 473 const vector& operator+=(const vector&); 474 475 /** 476 \brief Subtract and assign operator. 477 478 \return A const reference to the resulting vector. 479 480 \throw GSL_error if dimensions mis-match. 481 */ 482 const vector& operator-=(const vector&); 483 484 /// 485 /// Multiply with scalar and assign operator. 451 486 /// 452 487 /// @return A const reference to the resulting vector. 453 488 /// 454 /// @see int set(const vector&)455 ///456 const vector& operator=(const vector&);457 458 ///459 /// Addition and assign operator.460 ///461 /// @return A const reference to the resulting vector.462 ///463 const vector& operator+=(const vector&);464 465 ///466 /// Subtract and assign operator.467 ///468 /// @return A const reference to the resulting vector.469 ///470 const vector& operator-=(const vector&);471 472 ///473 /// Multiply with scalar and assign operator.474 ///475 /// @return A const reference to the resulting vector.476 ///477 489 const vector& operator*=(const double); 478 490 … … 480 492 private: 481 493 482 /// 483 /// Create a new copy of the internal GSL vector. 484 /// 485 /// Necessary memory for the new GSL vector is allocated and the 486 /// caller is responsible for freeing the allocated memory. 487 /// 488 /// @return A pointer to a copy of the internal GSL vector. 489 /// 494 /** 495 \brief Create a new copy of the internal GSL vector. 496 497 Necessary memory for the new GSL vector is allocated and the 498 caller is responsible for freeing the allocated memory. 499 500 \return A pointer to a copy of the internal GSL vector. 501 502 \throw GSL_error if memory cannot be allocated for the new 503 copy, or if dimensions mis-match. 504 */ 490 505 gsl_vector* create_gsl_vector_copy(void) const; 491 506
Note: See TracChangeset
for help on using the changeset viewer.