Changeset 1028


Ignore:
Timestamp:
Feb 3, 2008, 2:53:29 AM (14 years ago)
Author:
Peter
Message:

documentation for VectorConstView? and changing name of view functions in matrix

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/iterator_test.cc

    r1027 r1028  
    5555  ///////////////////////////////////////////////////////
    5656  /* const conversion doesn't work for new vector structure
     57     see ticket 303
    5758  utility::vector::const_iterator ci = vec.begin();
    5859  ci = begin;
  • trunk/test/matrix_test.cc

    r1015 r1028  
    3737
    3838  inline theplu::yat::utility::VectorView
    39   row(const size_t& i) { return m_.row_vec(i); }
     39  row(const size_t& i) { return m_.row_view(i); }
    4040
    4141  inline const theplu::yat::utility::matrix& matrix(void) const { return m_; }
     
    280280    for (size_t j=0; j<m5.columns(); ++j)
    281281      m5_sum3+=m5(i,j);
    282   utility::VectorView v5subcolumn = m5.column_vec(0);
     282  utility::VectorView v5subcolumn = m5.column_view(0);
    283283  double v5subcolumn_sum=0;
    284284  for (size_t i=0; i<v5subcolumn.size(); ++i) {
  • trunk/test/score_test.cc

    r1015 r1028  
    109109  utility::vector weight(target2.size(),1);
    110110  for (size_t i=0; i<data.rows(); i++){
    111     utility::VectorView vec = data.row_vec(i);
     111    utility::VectorView vec = data.row_view(i);
    112112    area = auc.score(target2, vec, weight);
    113113    if (area<correct_area(i)-tol || area>correct_area(i)+tol){
  • trunk/yat/classifier/KNN.h

    r1027 r1028  
    262262      std::vector<size_t> k_index;
    263263      utility::sort_smallest_index(k_index,k_,
    264                                    distances->column_const_vec(sample));
     264                                   distances->column_const_view(sample));
    265265      for(size_t j=0;j<k_index.size();j++) {
    266266        prediction(target_(k_index[j]),sample)++;
  • trunk/yat/classifier/NBC.cc

    r1027 r1028  
    206206    // normalize each row (label) to sum up to unity (probability)
    207207    for (size_t i=0; i<prediction.rows(); ++i){
    208       prediction.row_vec(i) *=
    209         1.0/sum(prediction.row_const_vec(i));
     208      prediction.row_view(i) *= 1.0/sum(prediction.row_const_view(i));
    210209    }
    211210  }
  • trunk/yat/utility/PCA.cc

    r1027 r1028  
    193193    utility::vector A_row_sum(A_.rows());
    194194    for (size_t i=0; i<A_row_sum.size(); ++i){
    195       const VectorConstView tmp(A_.row_const_vec(i));
    196       A_row_sum(i) = sum(tmp);
     195      A_row_sum(i) = sum(A_.row_const_view(i));
    197196    }
    198197    for( size_t i = 0; i < A_center.rows(); ++i ) {
  • trunk/yat/utility/VectorConstView.h

    r1027 r1028  
    1010  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
    1111  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
     12  Copyright (C) 2008 Peter Johansson
    1213
    1314  This file is part of the yat library, http://trac.thep.lu.se/trac/yat
     
    4748
    4849  /**
    49      @brief This is the yat interface to GSL vector.
     50     @brief Read-only view.
    5051
    51      For time being 'double' is the only type supported.
     52     Wrapper to gsl_vector_const_view
    5253
    53      \par File streams:
    54      Reading and writing vectors to file streams are of course
    55      supported. These are implemented without using GSL functionality,
    56      and thus binary read and write to streams are not supported.
     54     With this class you can create a view into const
     55     objects - either a vector or matrix. By design all functionality
     56     in this class is const to guarantee that the viewed object is not
     57     modified.
    5758
    58      \par Vector views:
    59      GSL vector views are supported and these are disguised as
    60      ordinary utility::vectors. A support function is added,
    61      utility::vector::isview(), that can be used to check if a vector
    62      object is a view. Note that view vectors do not own the
    63      underlying data, and a view is not valid if the vector/matrix
    64      owing the data is deallocated.
    65 
    66      \par
    67      Currently there is no restriction on how a vector is used when
    68      the vector is a const view into another vector or matrix. To
    69      avoid unexpected runtime errors, the programmer must declare
    70      const view vectors as 'const' in order to get compile time
    71      diagnostics about improper use of a const view vector object. If
    72      'const' is not used and the const view vector is used erroneously
    73      (such as on the left hand side in assignments), the compiler will
    74      not catch the error and runtime error will occur. assert(3) is
    75      used to catch the runtime error during development. Example on
    76      bad and proper use of const view vectors:
    77      @code
    78   const vector vm(13,1.0);
    79   vector v1(vm,2,4);       // bad code! not const!
    80   v1(0)=-123;              // accepted by compiler, runtime abort will occur
    81                            // or catched by assert depending on compiler flags
    82   const vector v2(vm,2,4); // proper code
    83   v2(0)=-123;              // not acceptable for the compiler
    84      @endcode
     59     \Note that view vectors do not own the underlying data,
     60     and a view is not valid if the vector/matrix owing the data is
     61     deallocated.
    8562  */
    86 
    8763  class VectorConstView : public VectorBase
    8864  {
     
    9066    /**
    9167       \brief The copy constructor.
    92     */ 
    93     VectorConstView(const VectorBase& other);
     68    */
     69    // needed to override compiler generated copy constructor
    9470    VectorConstView(const VectorConstView& other);
    9571
    9672    /**
    97        \brief VectorConstView constructor.
     73       \brief Copy a VectorBase
     74    */
     75    VectorConstView(const VectorBase& other);
    9876
    99        Create a view of VectorConstView \a v, with starting index \a offset,
     77    /**
     78       \brief const view into a vector
     79
     80       Create a const view of VectorBase \a v, with starting index \a offset,
    10081       size \a n, and an optional \a stride.
    101 
    102        A VectorConstView view can be used as any VectorConstView with the difference
    103        that changes made to the view will also change the object that
    104        is viewed. Also, using the copy constructor will create a new
    105        VectorConstView object that is a copy of whatever is viewed. If a copy
    106        of the view is needed then you should use this constructor to
    107        obtain a copy.
    10882
    10983       \note If the object viewed by the view goes out of scope or is
     
    11589    VectorConstView(const VectorBase& v,size_t offset,size_t n,size_t stride=1);
    11690
    117     ///
    118     /// Matrix row/column view constructor.
    119     ///
    120     /// Create a row/column VectorConstView view of matrix \a m, pointing at
    121     /// row/column \a i. The parameter \a row is used to set whether
    122     /// the view should be a row or column view. If \a row is set to
    123     /// true, the view will be a row view (default behaviour), and,
    124     /// naturally, a column view otherwise.
    125     ///
    126     /// A VectorConstView view can be used as any VectorConstView with the difference
    127     /// that changes made to the view will also change the object that
    128     /// is viewed. Also, using the copy constructor will create a new
    129     /// VectorConstView object that is a copy of whatever is viewed. If a copy
    130     /// of the view is needed then you should use the VectorConstView view
    131     /// constructor to obtain a copy.
    132     ///
    133     /// @note If the object viewed by the view goes out of scope or is
    134     /// deleted, the view becomes invalid and the result of further
    135     /// use is undefined.
    136     ///
     91    /**
     92       \brief Matrix row/column view constructor.
     93       
     94       Create a view into a row/column of a matrix.
     95
     96       \param m matrix to view into.
     97       \param i index telling which row/column to view into
     98       \param row if true (defult) created view is a row vector, i.e.,
     99       viewing into row \a i, and, naturally, a column vector
     100       otherwise.
     101
     102       \see matrix::column_const_view(size_t) and
     103       matrix::row_const_view(size_t)
     104
     105       @note If the object viewed by the view goes out of scope or is
     106       deleted, the view becomes invalid and the result of further
     107       use is undefined.
     108    */
    137109    VectorConstView(const matrix& m, size_t i, bool row=true);
    138110
    139     ///
    140     /// The destructor.
    141     ///
     111    /**
     112      The destructor.
     113    */
    142114    ~VectorConstView(void);
    143115
     
    147119    bool isview(void) const;
    148120
    149     /**
    150        \brief The assignment operator.
    151 
    152        \return A const reference to the resulting vector.
    153 
    154        \throw GSL_error if dimensions mis-match.
    155     */
    156     const VectorConstView& operator=(const VectorBase&);
    157     const VectorConstView& operator=(const VectorConstView&);
    158 
    159121  private:
    160     const VectorConstView& assign(const VectorBase& other);
    161122    void delete_allocated_memory(void);
    162123
     124    // Perhaps not needed - only used to create a gsl_vector (that is
     125    // stored in base class). For data access use data in base class
     126    // because this pointer may be NULL.
    163127    gsl_vector_const_view* const_view_;
    164128   
  • trunk/yat/utility/matrix.cc

    r1027 r1028  
    305305
    306306
    307   VectorView matrix::column_vec(size_t col)
     307  VectorView matrix::column_view(size_t col)
    308308  {
    309309    VectorView res(*this, col, false);
     
    312312
    313313
    314   const VectorConstView matrix::column_const_vec(size_t col) const
     314  const VectorConstView matrix::column_const_view(size_t col) const
    315315  {
    316316    return VectorConstView(*this, col, false);
     
    318318
    319319
    320   const VectorConstView matrix::row_const_vec(size_t col) const
     320  const VectorConstView matrix::row_const_view(size_t col) const
    321321  {
    322322    return VectorConstView(*this, col, true);
     
    324324
    325325
    326   VectorView matrix::row_vec(size_t row)
     326  VectorView matrix::row_view(size_t row)
    327327  {
    328328    VectorView res(*this, row, true);
  • trunk/yat/utility/matrix.h

    r1027 r1028  
    158158    /**
    159159     */
    160     VectorView column_vec(size_t);
     160    VectorView column_view(size_t);
    161161
    162162    /**
    163163     */
    164     const VectorConstView column_const_vec(size_t) const;
     164    const VectorConstView column_const_view(size_t) const;
    165165
    166166    ///
     
    233233    /**
    234234     */
    235     VectorView row_vec(size_t);
     235    VectorView row_view(size_t);
    236236
    237237    /**
    238238     */
    239     const VectorConstView row_const_vec(size_t) const;
     239    const VectorConstView row_const_view(size_t) const;
    240240
    241241    /**
Note: See TracChangeset for help on using the changeset viewer.