Changeset 754 for trunk/yat


Ignore:
Timestamp:
Feb 17, 2007, 11:33:44 PM (16 years ago)
Author:
Jari Häkkinen
Message:

Addresses #2 and #65. Continued adding GSL_error exceptions, and added doxygen briefs.

Location:
trunk/yat/utility
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/matrix.cc

    r753 r754  
    6464                 size_t n_row, size_t n_column)
    6565  {
    66     // Jari, exception handling needed here. Failure in setting up a
    67     // proper gsl_matrix_view is communicated by NULL pointer in the
    68     // view structure (cf. GSL manual). How about GSL error state?
    6966    view_ = new gsl_matrix_view(gsl_matrix_submatrix(m.m_,
    7067                                                     offset_row,offset_column,
     
    142139    if (!m_)
    143140      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.
    144144    for(u_int i=0;i<nof_rows;i++)
    145145      for(u_int j=0;j<nof_columns;j++)
     
    158158
    159159
    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);
    169171  }
    170172
     
    183185    if (!m)
    184186      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");
    186189    return m;
    187190  }
     
    280283
    281284
    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");
    291295  }
    292296
     
    298302
    299303
    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));
    315325  }
    316326
     
    340350
    341351
    342   // Jari, checkout GSL transpose support in GSL manual 8.4.9
    343352  void matrix::transpose(void)
    344353  {
    345354    if (columns()==rows())
    346       gsl_matrix_transpose(m_);
     355      gsl_matrix_transpose(m_); // this never fails
    347356    else {
    348357      gsl_matrix* transposed = gsl_matrix_alloc(columns(),rows());
    349358      if (!transposed)
    350359        throw utility::GSL_error("matrix::transpose failed to allocate memory");
     360      // next line never fails if allocation above succeeded.
    351361      gsl_matrix_transpose_memcpy(transposed,m_);
    352362      gsl_matrix_free(m_);
     
    402412  const matrix& matrix::operator+=(const double d)
    403413  {
    404     add_constant(d);
     414    add(d);
    405415    return *this;
    406416  }
  • trunk/yat/utility/matrix.h

    r737 r754  
    99  Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér
    1010  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
     11  Copyright (C) 2007 Jari Häkkinen
    1112
    1213  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
     
    8384    matrix(void);
    8485
    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    */
    8992    matrix(const size_t& r, const size_t& c, double init_value=0);
    9093
    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    */
    97103    matrix(const matrix&);
    98104
    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    */
    117125    matrix(matrix& m, size_t offset_row, size_t offset_column, size_t n_row,
    118126           size_t n_column);
    119127
    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    */
    132141    explicit matrix(std::istream &, char sep='\0')
    133142      throw(utility::IO_error, std::exception);
    134143
    135     ///
    136     /// @brief The destructor.
    137     ///
     144    /**
     145       \brief The destructor.
     146    */
    138147    ~matrix(void);
    139148
    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);
    157164
    158165    ///
     
    246253    size_t rows(void) const;
    247254
    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);
    268272
    269273    ///
     
    272276    void set_all(const double value);
    273277
    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);
    300306
    301307    ///
     
    322328    int swap_rows(const size_t i, const size_t j);
    323329
    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    */
    327336    void transpose(void);
    328337
     
    356365    bool operator!=(const matrix& other) const;
    357366
    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    */
    372384    const matrix& operator=(const matrix& other);
    373385
     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
    374395    ///
    375396    /// @brief Add and assign operator.
    376397    ///
    377     const matrix& operator+=(const matrix&);
    378 
    379     ///
    380     /// @brief Add and assign operator.
    381     ///
    382398    const matrix& operator+=(const double);
    383399
    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    */
    387407    const matrix& operator-=(const matrix&);
    388408
    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    */
    394416    const matrix& operator*=(const matrix&);
    395417
    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    */
    399423    const matrix& operator*=(const double);
    400424
    401425  private:
    402426
    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    */
    411438    gsl_matrix* create_gsl_matrix_copy(void) const;
    412439
  • trunk/yat/utility/vector.cc

    r753 r754  
    6767    : v_const_(NULL), view_const_(NULL)
    6868  {
    69     // Jari, exception handling needed here. Failure in setting up a
    70     // proper gsl_vector_view is communicated by NULL pointer in the
    71     // view structure (cf. GSL manual). How about GSL error state?
    7269    view_ = new gsl_vector_view(gsl_vector_subvector_with_stride(v.v_,offset,
    7370                                                                 stride,n));
     
    8178    : v_(NULL), view_(NULL)
    8279  {
    83     // Jari, exception handling needed here. Failure in setting up a
    84     // proper gsl_vector_view is communicated by NULL pointer in the
    85     // view structure (cf. GSL manual). How about GSL error state?
    8680    view_const_ = new gsl_vector_const_view(
    8781                   gsl_vector_const_subvector_with_stride(v.v_,offset,stride,n));
     
    181175      throw utility::GSL_error("vector::vector failed to allocate memory");
    182176    size_t n=0;
     177    // if gsl error handler disabled, out of bounds index will not
     178    // abort the program.
    183179    for (size_t i=0; i<nof_rows; i++)
    184180      for (size_t j=0; j<nof_columns; j++)
     
    198194
    199195
    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);
    209207  }
    210208
     
    215213    if (!vec)
    216214      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");
    218217    return vec;
    219218  }
     
    302301
    303302
    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");
    313313  }
    314314
     
    346346
    347347
    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));
    351353  }
    352354
     
    435437  const vector& vector::operator+=(const vector& other)
    436438  {
    437     gsl_vector_add(v_,other.v_);
     439    add(other);
    438440    return *this;
    439441  }
     
    442444  const vector& vector::operator-=(const vector& other)
    443445  {
    444     gsl_vector_sub(v_,other.v_);
     446    sub(other);
    445447    return *this;
    446448  }
     
    449451  const vector& vector::operator*=(const double d)
    450452  {
    451     gsl_vector_scale(v_,d);
     453    scale(d);
    452454    return *this;
    453455  }
  • trunk/yat/utility/vector.h

    r714 r754  
    88  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
    99  Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér
    10   Copyright (C) 2006 Jari Häkkinen
     10  Copyright (C) 2006, 2007 Jari Häkkinen
    1111
    1212  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
     
    8888  public:
    8989
    90     ///
    91     /// The default constructor.
    92     ///
     90    /**
     91       \brief The default constructor.
     92    */
    9393    vector(void);
    9494
    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    */
    99101    vector(size_t n, double init_value=0);
    100102
    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    */
    107112    vector(const vector& other);
    108113
    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    */
    126133    vector(vector& v, size_t offset, size_t n, size_t stride=1);
    127134
    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    */
    143152    vector(const vector& v, size_t offset, size_t n, size_t stride=1);
    144153
     
    186195    vector(const matrix& m, size_t i, bool row=true);
    187196
    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    */
    197208    explicit vector(std::istream &, char sep='\0')
    198209      throw(utility::IO_error, std::exception);
     
    203214    ~vector(void);
    204215
    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);
    221229
    222230    ///
     
    312320    int reverse(void);
    313321
    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);
    333337
    334338    ///
     
    365369    void sort(void);
    366370
    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 operators
    373     int sub(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);
    374378
    375379    ///
     
    441445    double operator*(const vector&) const;
    442446
    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.
    451486    ///
    452487    /// @return A const reference to the resulting vector.
    453488    ///
    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     ///
    477489    const vector& operator*=(const double);
    478490
     
    480492  private:
    481493
    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    */
    490505    gsl_vector* create_gsl_vector_copy(void) const;
    491506
Note: See TracChangeset for help on using the changeset viewer.