Changeset 716 for trunk/yat


Ignore:
Timestamp:
Dec 25, 2006, 1:53:13 AM (16 years ago)
Author:
Jari Häkkinen
Message:

Addresses #170.

Location:
trunk/yat/utility
Files:
2 edited

Legend:

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

    r703 r716  
    154154
    155155
     156  int matrix::add(const matrix& b)
     157  {
     158    return gsl_matrix_add(m_, b.m_);
     159  }
     160
     161
     162  int matrix::add_constant(const double d)
     163  {
     164    return gsl_matrix_add_constant(m_, d);
     165  }
     166
     167
     168  size_t matrix::columns(void) const
     169  {
     170    return m_->size2;
     171  }
     172
     173
     174  gsl_matrix* matrix::create_gsl_matrix_copy(void) const
     175  {
     176    gsl_matrix* m = gsl_matrix_alloc(rows(),columns());
     177    gsl_matrix_memcpy(m,m_);  // Jari, a GSL return value is ignored here
     178    return m;
     179  }
     180
     181
     182  int matrix::div_elements(const matrix& b)
     183  {
     184    return gsl_matrix_div_elements(m_, b.m_);
     185  }
     186
    156187
    157188  bool matrix::equal(const matrix& other, const double d) const
     
    169200
    170201
    171 
    172   gsl_matrix* matrix::create_gsl_matrix_copy(void) const
    173   {
    174     gsl_matrix* m = gsl_matrix_alloc(rows(),columns());
    175     gsl_matrix_memcpy(m,m_);  // Jari, a GSL return value is ignored here
    176     return m;
    177   }
    178 
     202  const gsl_matrix* matrix::gsl_matrix_p(void) const
     203  {
     204    return m_;
     205  }
     206
     207
     208  gsl_matrix* matrix::gsl_matrix_p(void)
     209  {
     210    return m_;
     211  }
     212
     213
     214  bool matrix::isnull(void) const
     215  {
     216    return gsl_matrix_isnull(m_);
     217  }
     218
     219
     220  bool matrix::isview(void) const
     221  {
     222    return view_;
     223  }
     224
     225
     226  double matrix::max(void) const
     227  {
     228    return gsl_matrix_max(m_);
     229  }
     230
     231
     232  double matrix::min(void) const
     233  {
     234    return gsl_matrix_min(m_);
     235  }
     236
     237
     238  void matrix::minmax_index(std::pair<size_t,size_t>& min,
     239                            std::pair<size_t,size_t>& max) const
     240  {
     241    gsl_matrix_minmax_index(m_, &min.first, &min.second, &max.first,
     242                            &max.second);
     243  }
    179244
    180245
     
    193258
    194259
     260  int matrix::mul_elements(const matrix& b)
     261  {
     262    return gsl_matrix_mul_elements(m_, b.m_);
     263  }
     264
     265
     266  size_t matrix::rows(void) const
     267  {
     268    return m_->size1;
     269  }
     270
     271
     272  int matrix::scale(const double d)
     273  {
     274    return gsl_matrix_scale(m_, d);
     275  }
     276
     277
     278  int matrix::set(const matrix& mat)
     279  {
     280    return gsl_matrix_memcpy(m_, mat.m_);
     281  }
     282
     283
     284  void matrix::set_all(const double value)
     285  {
     286    gsl_matrix_set_all(m_, value);
     287  }
     288
     289
     290  int matrix::set_column(const size_t column, const vector& vec)
     291  {
     292    return gsl_matrix_set_col(m_, column, vec.gsl_vector_p());
     293  }
     294
     295
     296  int matrix::set_row(const size_t row, const vector& vec)
     297  {
     298    return gsl_matrix_set_row(m_, row, vec.gsl_vector_p());
     299  }
     300
     301
     302  int matrix::sub(const matrix& b)
     303  {
     304    return gsl_matrix_sub(m_, b.m_);
     305  }
     306
     307
     308  int matrix::swap(matrix& other)
     309  {
     310    return gsl_matrix_swap(m_, other.m_);
     311  }
     312
     313
     314  int matrix::swap_columns(const size_t i, const size_t j)
     315  {
     316    return gsl_matrix_swap_columns(m_, i, j);
     317  }
     318
     319
     320  int matrix::swap_rowcol(const size_t i, const size_t j)
     321  {
     322    return gsl_matrix_swap_rowcol(m_, i, j);
     323  }
     324
     325
     326  int matrix::swap_rows(const size_t i, const size_t j)
     327  {
     328    return gsl_matrix_swap_rows(m_, i, j);
     329  }
     330
    195331
    196332  // Jari, checkout GSL transpose support in GSL manual 8.4.9
     
    208344
    209345
     346  double& matrix::operator()(size_t row, size_t column)
     347  {
     348    return (*gsl_matrix_ptr(m_, row, column));
     349  }
     350
     351
     352  const double& matrix::operator()(size_t row, size_t column) const
     353  {
     354    return (*gsl_matrix_const_ptr(m_, row, column));
     355  }
     356
    210357
    211358  const vector matrix::operator*(const vector&) const
     
    217364  }
    218365
     366
     367  bool matrix::operator==(const matrix& other) const
     368  {
     369    return equal(other);
     370  }
     371
     372
     373  bool matrix::operator!=(const matrix& other) const
     374  {
     375    return !equal(other);
     376  }
    219377
    220378
     
    285443  }
    286444
    287 
    288445}}} // of namespace utility, yat and thep
  • trunk/yat/utility/matrix.h

    r703 r716  
    3333#include <gsl/gsl_matrix.h>
    3434#include <iostream>
     35#include <utility>
    3536
    3637namespace theplu {
     
    144145    /// @return Whatever GSL returns.
    145146    ///
    146     inline int add(const matrix& b) { return gsl_matrix_add(m_,b.m_); }
     147    int add(const matrix& b);
    147148
    148149    ///
     
    153154    /// @return Whatever GSL returns.
    154155    ///
    155     inline int
    156     add_constant(const double d) { return gsl_matrix_add_constant(m_,d); }
     156    int add_constant(const double d);
    157157
    158158    ///
    159159    /// @return The number of columns in the matrix.
    160160    ///
    161     inline size_t columns(void) const { return m_->size2; }
     161    size_t columns(void) const;
    162162
    163163    ///
     
    168168    /// @return Whatever GSL returns.
    169169    ///
    170     inline int
    171     div_elements(const matrix& b) { return gsl_matrix_div_elements(m_,b.m_); }
     170    int div_elements(const matrix& b);
    172171
    173172    ///
     
    183182    /// @return A const pointer to the internal GSL matrix.
    184183    ///
    185     inline const gsl_matrix* gsl_matrix_p(void) const { return m_; }
     184    const gsl_matrix* gsl_matrix_p(void) const;
    186185
    187186    ///
     
    189188    ///
    190189    // Jari, is this needed?
    191     inline gsl_matrix* gsl_matrix_p(void) { return m_; };
     190    gsl_matrix* gsl_matrix_p(void);
    192191
    193192    ///
     
    195194    /// othwerwise;
    196195    ///
    197     inline bool isnull(void) const { return gsl_matrix_isnull(m_); }
     196    bool isnull(void) const;
    198197
    199198    ///
     
    203202    /// @return True if the object is a view, false othwerwise.
    204203    ///
    205     inline bool isview(void) const { return view_; }
     204    bool isview(void) const;
    206205
    207206    ///
    208207    /// @return The maximum value of the matrix.
    209208    ///
    210     inline double max(void) const { return gsl_matrix_max(m_); }
     209    double max(void) const;
    211210
    212211    ///
     
    220219    /// @return The minimum value of the matrix.
    221220    ///
    222     inline double min(void) const { return gsl_matrix_min(m_); }
     221    double min(void) const;
    223222
    224223    ///
     
    234233    /// has precedence (searching in row-major order).
    235234    ///
    236     inline void minmax_index(std::pair<size_t,size_t>& min,
    237                              std::pair<size_t,size_t>& max) const
    238       { gsl_matrix_minmax_index(m_,&min.first,&min.second,
    239                                 &max.first,&max.second); }
     235    void minmax_index(std::pair<size_t,size_t>& min,
     236                      std::pair<size_t,size_t>& max) const;
    240237
    241238    ///
     
    262259    /// @return Whatever GSL returns.
    263260    ///
    264     inline int
    265     mul_elements(const matrix& b) { return gsl_matrix_mul_elements(m_,b.m_); }
     261    int
     262    mul_elements(const matrix& b);
    266263
    267264    ///
    268265    /// @return The number of rows in the matrix.
    269266    ///
    270     inline size_t rows(void) const { return m_->size1; }
     267    size_t rows(void) const;
    271268
    272269    ///
     
    277274    /// @return Whatever GSL returns.
    278275    ///
    279     inline int scale(const double d) { return gsl_matrix_scale(m_,d); }
     276    int scale(const double d);
    280277
    281278    ///
     
    289286    /// @see const matrix& operator=(const matrix&)
    290287    ///
    291     inline int set(const matrix& mat) { return gsl_matrix_memcpy(m_,mat.m_); }
     288    int set(const matrix& mat);
    292289
    293290    ///
    294291    /// Set all elements to \a value.
    295292    ///
    296     inline void set_all(const double value) { gsl_matrix_set_all(m_,value); }
     293    void set_all(const double value);
    297294
    298295    ///
     
    303300    /// @note No check on size is done.
    304301    ///
    305     inline int set_column(const size_t column, const vector& vec)
    306       { return gsl_matrix_set_col(m_, column, vec.gsl_vector_p()); }
     302    int set_column(const size_t column, const vector& vec);
    307303
    308304    ///
     
    313309    /// @note No check on size is done.
    314310    ///
    315     inline int set_row(const size_t row, const vector& vec)
    316       { return gsl_matrix_set_row(m_, row, vec.gsl_vector_p()); }
     311    int set_row(const size_t row, const vector& vec);
    317312
    318313    ///
     
    323318    /// @return Whatever GSL returns.
    324319    ///
    325     inline int sub(const matrix& b) { return gsl_matrix_sub(m_,b.m_); }
     320    int sub(const matrix& b);
    326321
    327322    ///
     
    331326    /// @return Whatever GSL returns.
    332327    ///
    333     inline int swap(matrix& other) { return gsl_matrix_swap(m_,other.m_); }
     328    int swap(matrix& other);
    334329
    335330    ///
    336331    /// @brief Swap columns \a i and \a j.
    337332    ///
    338     inline int swap_columns(const size_t i,const size_t j)
    339       { return gsl_matrix_swap_columns(m_,i,j); }
     333    int swap_columns(const size_t i,const size_t j);
    340334
    341335    ///
    342336    /// @brief Swap row \a i and column \a j.
    343337    ///
    344     inline int swap_rowcol(const size_t i,const size_t j)
    345       { return gsl_matrix_swap_rowcol(m_,i,j); }
     338    int swap_rowcol(const size_t i,const size_t j);
    346339
    347340    ///
    348341    /// @brief Swap rows \a i and \a j.
    349342    ///
    350     inline int swap_rows(const size_t i, const size_t j)
    351       { return gsl_matrix_swap_rows(m_,i,j); }
     343    int swap_rows(const size_t i, const size_t j);
    352344
    353345    ///
     
    359351    /// @return Reference to the element position (\a row, \a column).
    360352    ///
    361     inline double& operator()(size_t row,size_t column)
    362     { return (*gsl_matrix_ptr(m_,row,column)); }
     353    double& operator()(size_t row,size_t column);
    363354
    364355    ///
     
    366357    /// column).
    367358    ///
    368     inline const double& operator()(size_t row,size_t column) const
    369     { return (*gsl_matrix_const_ptr(m_,row,column)); }
     359    const double& operator()(size_t row,size_t column) const;
    370360
    371361    ///
     
    384374    /// @see equal
    385375    ///
    386     inline bool operator==(const matrix& other) const { return equal(other); }
     376    bool operator==(const matrix& other) const;
    387377
    388378    ///
     
    393383    /// @see equal
    394384    ///
    395     inline bool operator!=(const matrix& other) const { return !equal(other); }
     385    bool operator!=(const matrix& other) const;
    396386
    397387    ///
Note: See TracChangeset for help on using the changeset viewer.