Changeset 109


Ignore:
Timestamp:
Jun 16, 2004, 4:41:17 PM (18 years ago)
Author:
Peter
Message:

Modified copy constructor to be able to copy a sub-vector

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/vector.cc

    r68 r109  
    3030
    3131
    32   vector::vector(const vector& other)
    33   {
    34     v_ = other.gsl_vector_copy();
     32  vector::vector(const vector& other, const std::vector<size_t>& index)
     33  {
     34    if (index.size()){
     35      v_ = gsl_vector_alloc(index.size());
     36      for (size_t i=0; i<index.size(); i++)
     37        gsl_vector_set(v_, i, other(index[i]));
     38    }
     39    else
     40      v_ = other.gsl_vector_copy();
    3541  }
    3642
  • trunk/src/vector.h

    r65 r109  
    4747
    4848    ///
    49     /// The copy constructor.
    50     ///
    51     vector(const vector&);
     49    /// The copy constructor, creating a new sub-vector defined by \a
     50    /// index (default is to copy the whole vector).
     51    ///
     52    vector(const vector&,
     53           const std::vector<size_t>& index = std::vector<size_t>());
    5254
    5355    ///
     
    98100    std::pair<size_t,size_t> vector::minmax_index(void) const;
    99101
    100     ///This function returns the indices of the minimum and maximum values in
    101     ///the sub-vector (defined by subset), storing them in imin and imax. When
    102     ///there are several equal minimum or maximum elements then the lowest
    103     ///indices are returned. The returned index is the index from the complete vector (not the sub-vector)  @return Index corresponding to the smallest
    104     ///and largest value.
    105     ///
    106     std::pair<size_t,size_t> vector::minmax_index(const std::vector<size_t>& subset ) const;
     102    ///This function returns the indices of the minimum and maximum
     103    ///values in the sub-vector (defined by subset), storing them in
     104    ///imin and imax. When there are several equal minimum or maximum
     105    ///elements then the lowest indices are returned. The returned
     106    ///index is the index from the complete vector (not the
     107    ///sub-vector)
     108    ///@return Index corresponding to the smallest and largest value.
     109    ///
     110    std::pair<size_t,size_t>
     111    vector::minmax_index(const std::vector<size_t>& subset ) const;
    107112
    108113    ///
     
    121126
    122127    ///
    123     /// Makes a basis vector byy settin all elements to
     128    /// Makes a basis vector by setting all elements to
    124129    /// zero except the \a i-th element which is set to
    125     /// one..
     130    /// one.
    126131    ///
    127132    inline void set_basis(const size_t i) { gsl_vector_set_basis(v_,i); }
     133   
    128134    ///
    129135    /// Set all elements to zero.
Note: See TracChangeset for help on using the changeset viewer.