Ignore:
Timestamp:
Feb 2, 2008, 10:29:29 PM (13 years ago)
Author:
Peter
Message:

going back to previous design in which view and const_view are in different classes. Having them in same didnt work as expected. There is a problem converting vector::iterator to vector::const_iterator. I'll open a separate ticket for this issue.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/VectorMutable.h

    r1026 r1027  
    1 #ifndef _theplu_yat_utility_vector_base_
    2 #define _theplu_yat_utility_vector_base_
     1#ifndef _theplu_yat_utility_vector_mutable_
     2#define _theplu_yat_utility_vector_mutable_
    33
    44// $Id$
     
    3030*/
    3131
     32#include "VectorBase.h"
    3233#include "Exception.h"
    3334#include "Iterator.h"
     
    8687  */
    8788
    88   class VectorBase
     89  class VectorMutable : public VectorBase
    8990  {
    9091  public:
    91 
    92     /// \brief VectorBase::iterator
    93     typedef Iterator<double&, VectorBase> iterator;
    94 
    95     /// \brief VectorBase::const_iterator
    96     typedef Iterator<const double, const VectorBase> const_iterator;
     92    /**
     93       \brief mutable iterator
     94    */
     95    typedef Iterator<double&, VectorMutable> iterator;
    9796
    9897    /**
    9998       \brief default constructor
    10099    */
    101     VectorBase(void);
     100    VectorMutable(void);
    102101
    103102    /**
    104103       \brief Constructor.
    105104    */
    106     VectorBase(gsl_vector*);
     105    VectorMutable(gsl_vector*);
    107106
    108107    /**
    109108       \brief Constructor.
    110109    */
    111     VectorBase(const gsl_vector*);
     110    VectorMutable(const gsl_vector*);
    112111
    113112    ///
    114113    /// The destructor.
    115114    ///
    116     virtual ~VectorBase(void);
     115    virtual ~VectorMutable(void);
    117116
    118117    ///
     
    126125    iterator begin(void);
    127126
    128     /**
    129        \return read-only iterator to start of VectorBase
    130      */
    131     const_iterator begin(void) const;
    132 
    133     /**
    134        \brief This function performs element-wise division, \f$ this_i =
    135        this_i/other_i \; \forall i \f$.
     127    // to allow overload from base class
     128    using VectorBase::begin;
     129
     130    /**
     131       \brief This function performs element-wise division, \f$
     132       this_i = this_i / other_i \; \forall i \f$.
    136133
    137134       \throw GSL_error if dimensions mis-match.
     
    140137
    141138    /**
    142        \return mutable iterator to end of VectorBase
     139       \return mutable iterator to end of VectorMutable
    143140     */
    144141    iterator end(void);
    145142
    146     /**
    147        \return read-only iterator to end of VectorBase
    148      */
    149     const_iterator end(void) const;
    150 
    151     /**
    152        \brief Check whether VectorBases are equal within a user defined
    153        precision, set by \a precision.
    154 
    155        \return True if each element deviates less or equal than \a
    156        d. If any VectorBase contain a NaN, false is always returned.
    157 
    158        \see operator== and operator!=
    159     */
    160     bool equal(const VectorBase&, const double precision=0) const;
    161 
    162     ///
    163     /// @return A pointer to the internal GSL vector,
    164     ///
     143    // to allow overload from base class
     144    using VectorBase::end;
     145
     146    /**
     147       @return A pointer to the internal GSL vector,
     148    */
    165149    gsl_vector* gsl_vector_p(void);
    166150
    167     ///
    168     /// @return A const pointer to the internal GSL vector,
    169     ///
    170     const gsl_vector* gsl_vector_p(void) const;
    171 
    172     /**
    173    
     151    using VectorBase::gsl_vector_p;
     152
     153    /**
    174154       Check if the vector object is a view (sub-vector) to another
    175155       vector.
     
    189169
    190170    /**
    191        \brief Reverse the order of elements in the VectorBase.
     171       \brief Reverse the order of elements in the VectorMutable.
    192172    */
    193173    void reverse(void);
    194174
    195     ///
    196     /// @return the number of elements in the VectorBase.
    197     ///
    198     size_t size(void) const;
    199 
    200175    /**
    201176       \brief Exchange elements \a i and \a j.
    202 
    203        \throw GSL_error if VectorBase lengths differs.
    204177    */
    205178    void swap(size_t i, size_t j);
     
    217190    // Peter, remove this one
    218191    double& operator[](size_t i);
    219 
    220     /**
    221        \brief Element access operator.
    222 
    223        \return Const reference to element \a i.
    224 
    225        \throw If GSL range checks are enabled in the underlying GSL
    226        library a GSL_error exception is thrown if either index is out
    227        of range.
    228     */
    229     const double& operator()(size_t i) const;
    230     // Peter, remove this one
    231     const double& operator[](size_t i) const;
    232 
    233     /**
    234        \brief Comparison operator. Takes linear time.
    235 
    236        Checks are performed with exact matching, i.e., rounding off
    237        effects may destroy comparison. Use the equal function for
    238        comparing elements within a user defined precision.
    239 
    240        \return True if all elements are equal otherwise false.
    241 
    242        \see equal(const VectorBase&, const double precision=0)
    243     */
    244     bool operator==(const VectorBase&) const;
    245 
    246     /**
    247        \brief Comparison operator. Takes linear time.
    248 
    249        Checks are performed with exact matching, i.e., rounding off
    250        effects may destroy comparison. Use the equal function for
    251        comparing elements within a user defined precision.
    252 
    253        \return False if all elements are equal otherwise true.
    254 
    255        \see equal(const VectorBase&, const double precision=0)
    256     */
    257     bool operator!=(const VectorBase&) const;
    258 
    259     ///
    260     /// @return The dot product.
    261     ///
    262     double operator*(const VectorBase&) const;
    263 
    264     /**
    265        \brief The assignment operator.
    266 
    267        Dimensions of the VectorBases must match. If the LHS VectorBase is a
    268        view, the underlying data will be changed.
    269 
    270        \return A const reference to the resulting VectorBase.
    271 
    272        \see void set(const VectorBase&).
    273 
    274        \throw GSL_error if dimensions mis-match.
    275     */
    276     //const VectorBase& operator=(VectorBase&);
     192    // to allow overload from base class
     193    using VectorBase::operator();
     194    using VectorBase::operator[];
    277195
    278196    /**
     
    284202       \throw GSL_error if dimensions mis-match.
    285203    */
    286     const VectorBase& operator+=(const VectorBase&);
     204    const VectorMutable& operator+=(const VectorBase&);
    287205
    288206    /**
     
    292210       \return A const reference to the resulting VectorBase.
    293211    */
    294     const VectorBase& operator+=(double d);
     212    const VectorMutable& operator+=(double d);
    295213
    296214    /**
     
    302220       \throw GSL_error if dimensions mis-match.
    303221    */
    304     const VectorBase& operator-=(const VectorBase&);
     222    const VectorMutable& operator-=(const VectorBase&);
    305223
    306224    /**
     
    310228       \return A const reference to the resulting VectorBase.
    311229    */
    312     const VectorBase& operator-=(double d);
     230    const VectorMutable& operator-=(double d);
    313231
    314232    /**
     
    318236       \return A const reference to the resulting VectorBase.
    319237    */
    320     const VectorBase& operator*=(double d);
    321 
    322 
     238    const VectorMutable& operator*=(double d);
    323239
    324240  protected:
    325241    gsl_vector* vec_;
    326     const gsl_vector* const_vec_;
    327 
    328     /*
     242
     243    // Peter document
    329244    struct proxy
    330245    {
    331246      gsl_vector* vec_;
    332247    };
    333     */
    334248
    335249  private:
    336250    // copy assignment no allowed
    337     const VectorBase& operator=(const VectorBase&);
     251    const VectorMutable& operator=(const VectorMutable&);
    338252  public:
    339253    /**
    340254     */
    341     //operator proxy();
     255    operator proxy();
    342256
    343257  };
    344 
    345   /**
    346      \brief Check if all elements of the VectorBase are zero.
    347 
    348      \return True if all elements in the VectorBase is zero, false
    349      othwerwise.
    350   */
    351   bool isnull(const VectorBase&);
    352 
    353   /**
    354      \brief Get the maximum value of the VectorBase.
    355 
    356      \return The maximum value of the VectorBase.
    357   */
    358   double max(const VectorBase&);
    359 
    360   /**
    361      \brief Locate the maximum value in the VectorBase.
    362 
    363      \return The index to the maximum value of the VectorBase.
    364 
    365      \note Lower index has precedence.
    366   */
    367   size_t max_index(const VectorBase&);
    368 
    369   /**
    370      \brief Get the minimum value of the VectorBase.
    371 
    372      \return The minimum value of the VectorBase.
    373   */
    374   double min(const VectorBase&);
    375 
    376   /**
    377      \brief Locate the minimum value in the VectorBase.
    378 
    379      \return The index to the minimum value of the VectorBase.
    380 
    381      \note Lower index has precedence.
    382   */
    383   size_t min_index(const VectorBase&);
    384 
    385   /**
    386      \brief Create a VectorBase \a flag indicating NaN's in another VectorBase
    387      \a templat.
    388 
    389      The \a flag VectorBase is changed to contain 1's and 0's only. A 1
    390      means that the corresponding element in the \a templat VectorBase is
    391      valid and a zero means that the corresponding element is a NaN.
    392 
    393      \note Space for VectorBase \a flag is reallocated to fit the size of
    394      VectorBase \a templat if sizes mismatch.
    395 
    396      \return True if the \a templat VectorBase contains at least one NaN.
    397   */
    398   bool nan(const VectorBase& templat, vector& flag);
    399258
    400259  /**
    401260     Randomly shuffles the elements in VectorBase \a invec
    402261  */
    403   void shuffle(VectorBase& invec);
     262  void shuffle(VectorMutable& invec);
    404263
    405264  /**
    406265     Sort the elements in the VectorBase.
    407266  */
    408   void sort(VectorBase&);
    409 
    410   /**
    411      Create a vector \a sort_index containing the indeces of
    412      elements in a another VectorBase \a invec.  The elements of \a
    413      sort_index give the index of the VectorBase element which would
    414      have been stored in that position if the VectorBase had been sorted
    415      in place. The first element of \a sort_index gives the index of the least
    416      element in \a invec, and the last element of \a sort_index gives the
    417      index of the greatest element in \a invec . The VectorBase \a invec
    418      is not changed.
    419   */
    420   void sort_index(std::vector<size_t>& sort_index, const VectorBase& invec);
    421 
    422   /**
    423       Similar to sort_index but creates a VectorBase with indices to the \a k
    424   smallest elements in \a invec. 
    425   */
    426   void sort_smallest_index(std::vector<size_t>& sort_index, size_t k,
    427                            const VectorBase& invec);
    428 
    429   /**
    430       Similar to sort_index but creates a VectorBase with indices to the \a k
    431   largest elements in \a invec. 
    432   */
    433   void sort_largest_index(std::vector<size_t>& sort_index, size_t k,
    434                           const VectorBase& invec);
    435 
    436   /**
    437      \brief Calculate the sum of all VectorBase elements.
    438 
    439      \return The sum.
    440   */
    441   double sum(const VectorBase&);
    442 
    443   /**
    444      \brief Swap vector elements by copying.
    445 
    446      The two vectorMutables must have the same length.
    447 
    448      \throw GSL_error if vectorMutable lengths differs.
    449   */
    450   //void swap(vectorMutable&, vectorMutable&);
    451 
    452   /**
    453      \brief The output operator for the VectorBase class.
    454   */
    455   std::ostream& operator<<(std::ostream&, const VectorBase&);
     267  void sort(VectorMutable&);
    456268
    457269}}} // of namespace utility, yat, and theplu
Note: See TracChangeset for help on using the changeset viewer.