Changeset 773


Ignore:
Timestamp:
Mar 1, 2007, 1:51:25 AM (17 years ago)
Author:
Jari Häkkinen
Message:

Fixes #138. Removed add, sub, scale and added appropriate operators.

Location:
trunk/yat/utility
Files:
2 edited

Legend:

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

    r762 r773  
    160160
    161161
    162   void matrix::add(const matrix& b)
    163   {
    164     int status=gsl_matrix_add(m_, b.m_);
    165     if (status)
    166       throw utility::GSL_error(std::string("matrix::add",status));
    167   }
    168 
    169 
    170   void matrix::add(double d)
    171   {
    172     gsl_matrix_add_constant(m_, d);
    173   }
    174 
    175 
    176162  size_t matrix::columns(void) const
    177163  {
     
    290276
    291277
    292   void matrix::scale(const double d)
    293   {
    294     gsl_matrix_scale(m_, d);
    295   }
    296 
    297 
    298278  void matrix::set(const matrix& mat)
    299279  {
     
    322302    if (status)
    323303      throw utility::GSL_error(std::string("matrix::set_row",status));
    324   }
    325 
    326 
    327   void matrix::sub(const matrix& b)
    328   {
    329     int status=gsl_matrix_sub(m_, b.m_);
    330     if (status)
    331       throw utility::GSL_error(std::string("matrix::sub",status));
    332304  }
    333305
     
    430402  const matrix& matrix::operator+=(const matrix& m)
    431403  {
    432     add(m);
     404    int status=gsl_matrix_add(m_, m.m_);
     405    if (status)
     406      throw utility::GSL_error(std::string("matrix::operator+=", status));
    433407    return *this;
    434408  }
     
    437411  const matrix& matrix::operator+=(const double d)
    438412  {
    439     add(d);
     413    gsl_matrix_add_constant(m_, d);
    440414    return *this;
    441415  }
     
    444418  const matrix& matrix::operator-=(const matrix& m)
    445419  {
    446     sub(m);
     420    int status=gsl_matrix_sub(m_, m.m_);
     421    if (status)
     422      throw utility::GSL_error(std::string("matrix::operator-=", status));
     423    return *this;
     424  }
     425
     426
     427  const matrix& matrix::operator-=(const double d)
     428  {
     429    gsl_matrix_add_constant(m_, -d);
    447430    return *this;
    448431  }
     
    467450  const matrix& matrix::operator*=(const double d)
    468451  {
    469     scale(d);
     452    gsl_matrix_scale(m_, d);
    470453    return *this;
    471454  }
  • trunk/yat/utility/matrix.h

    r767 r773  
    143143    ~matrix(void);
    144144
    145     /**
    146        Elementwise addition of the elements of matrix \a b to the
    147        elements of the calling matrix ,\f$ a_{ij} = a_{ij} + b_{ij} \;
    148        \forall i,j \f$. The result is stored into the calling matrix.
    149 
    150        \throw GSL_error if dimensions mis-match.
    151     */
    152     void add(const matrix& b);
    153 
    154     /**
    155        Add the scalar value \a d to the elements of the calling
    156        matrix, \f$ a_{ij} = a_{ij} + d \; \forall i,j \f$. The result
    157        is stored into the calling matrix.
    158     */
    159     void add(double d);
    160 
    161145    ///
    162146    /// @return The number of columns in the matrix.
     
    248232
    249233    /**
    250        Multiply the elements of the calling matrix with a scalar \a d,
    251        \f$ a_{ij} = d * a_{ij} \; \forall i,j \f$. The result is
    252        stored into the calling matrix.
    253     */
    254     void scale(const double d);
    255 
    256     /**
    257234       \brief Set element values to values in \a mat.
    258235
     
    289266    */
    290267    void 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 i,j
    295        \f$. The result is stored into the calling matrix.
    296 
    297        \throw GSL_error if dimensions mis-match.
    298     */
    299     void sub(const matrix& b);
    300268
    301269    /**
     
    403371       \brief Add and assign operator.
    404372
     373       Elementwise addition of the elements of matrix \a b to the left
     374       hand side matrix ,\f$ a_{ij} = a_{ij} + b_{ij} \; \forall i,j
     375       \f$.
     376
    405377       \return A const reference to the resulting matrix.
    406378
    407379       \throw GSL_error if dimensions mis-match.
    408380    */
    409     const matrix& operator+=(const matrix&);
    410 
    411     ///
    412     /// @brief Add and assign operator.
    413     ///
    414     const matrix& operator+=(const double);
     381    const matrix& operator+=(const matrix& b);
     382
     383    /**
     384       \brief Add and assign operator
     385
     386       Add the scalar value \a d to the left hand side matrix, \f$
     387       a_{ij} = a_{ij} + d \; \forall i,j \f$.
     388    */
     389    const matrix& operator+=(const double d);
    415390
    416391    /**
    417392       \brief Subtract and assign operator.
    418393
     394       Elementwise subtraction of the elements of matrix \a b to the
     395       left hand side matrix ,\f$ a_{ij} = a_{ij} + b_{ij} \; \forall
     396       i,j \f$.
     397
    419398       \return A const reference to the resulting matrix.
    420399
     
    424403
    425404    /**
     405       \brief Subtract and assign operator
     406
     407       Subtract the scalar value \a d to the left hand side matrix,
     408       \f$ a_{ij} = a_{ij} + d \; \forall i,j \f$.
     409    */
     410    const matrix& operator-=(const double d);
     411
     412    /**
    426413       \brief Multiply and assigment operator.
    427414
     
    435422       \brief Multiply and assignment operator
    436423
     424       Multiply the elements of the left hand side matrix with a
     425       scalar \a d, \f$ a_{ij} = d * a_{ij} \; \forall i,j \f$.
     426
    437427       \throw GSL_error if memory allocation fails.
    438428    */
    439     const matrix& operator*=(const double);
     429    const matrix& operator*=(double d);
    440430
    441431  private:
Note: See TracChangeset for help on using the changeset viewer.