Changeset 227 for trunk/src/vector.h


Ignore:
Timestamp:
Feb 1, 2005, 1:52:27 AM (17 years ago)
Author:
Jari Häkkinen
Message:

Started reimplementation of the vector class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/vector.h

    r142 r227  
    2828
    2929  ///
    30   /// This is the C++ tools interface to GSL vector.
    31   ///
    32 
     30  /// This is the C++ tools interface to GSL vector. 'double' is the
     31  /// only type supported, maybe we should add a 'complex' type as
     32  /// well in the future.
     33  ///
     34  /// \par[File streams] Reading and writing vectors to file streams
     35  /// are of course supported. These are implemented without using GSL
     36  /// functionality, and thus binary read and write to streams are not
     37  /// supported.
     38  ///
     39  /// \par[Vector views] GSL vector views are supported and these are
     40  /// disguised as ordinary gslapi::vectors. A support function is
     41  /// added, gslapi::vector::is_view(), that can be used to check if
     42  /// the vector object is a view. Note that view vectors do not own
     43  /// the undelying data, and is not valid if the original vector is
     44  /// deallocated.
     45  ///
    3346  class vector
    3447  {
     
    4760
    4861    ///
    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>());
     62    /// The copy constructor.
     63    ///
     64    /// @note If the object to be copied is a vector view, the values
     65    /// of the view will be copied, i.e. the view is not copied.
     66    ///
     67    vector(const vector&);
    5468
    5569    ///
     
    7387
    7488    ///
    75     /// Create a new copy of the internal GSL vector.
    76     ///
    77     /// Necessary memory for the new GSL vector is allocated and the
    78     /// caller is responsible for freeing the allocated memory.
    79     ///
    80     /// @return A pointer to a copy of the internal GSL vector.
    81     ///
    82     gsl_vector* gsl_vector_copy(void) const;
     89    /// Vector addition, \f$this_i = this_i + other_i \; \forall i\f$.
     90    ///
     91    /// @return .GSL_SUCCESS on normal exit.
     92    ///
     93    // Jari, doxygen group as Vector operators
     94    inline int add(const vector& other) { return gsl_vector_add(v_,other.v_); }
     95
     96    ///
     97    /// Add a constant to a vector, \f$this_i = this_i + term \;
     98    /// \forall i\f$.
     99    ///
     100    /// @return .GSL_SUCCESS on normal exit.
     101    ///
     102    // Jari, doxygen group as Vector operators
     103    inline int
     104    add_constant(double term) { return gsl_vector_add_constant(v_,term); }
     105
     106    ///
     107    /// This function performs element-wise division, \f$this_i =
     108    /// this_i/other_i \; \forall i\f$.
     109    ///
     110    /// @return .GSL_SUCCESS on normal exit.
     111    ///
     112    // Jari, doxygen group as Vector operators
     113    inline int div(const vector& other) { return gsl_vector_div(v_,other.v_); }
     114
     115    ///
     116    /// @return True if all elements in the vector is zero, false
     117    /// othwerwise;
     118    ///
     119    inline bool isnull(void) const { return gsl_vector_isnull(v_); }
     120
     121    ///
     122    /// Check if the vector object is a view (sub vector) to another
     123    /// vector.
     124    ///
     125    /// @return True if the object is a view, false othwerwise;
     126    ///
     127    inline bool isview(void) const { return view_; }
    83128
    84129    ///
     
    90135    /// @return A pointer to the internal GSL vector,
    91136    ///
    92     inline gsl_vector* gsl_vector_pointer(void) { return v_; }
    93 
    94     ///This function returns the indices of the minimum and maximum values in
    95     ///the vector, storing them in imin and imax. When
    96     ///there are several equal minimum or maximum elements then the lowest
    97     ///indices are returned. @return Index corresponding to the smallest
    98     /// and largest value.
    99     ///
     137    inline gsl_vector* TEMP_gsl_vector_pointer(void) { return v_; }
     138
     139    ///
     140    /// @return The maximum value of the vector.
     141    ///
     142    // Jari, doxygen group as Finding maximum and minimum elements
     143    inline double max(void) const { return gsl_vector_max(v_); }
     144
     145    ///
     146    /// @return The element index to the maximum value of the
     147    /// vector. The lowest index has precedence.
     148    ///
     149    // Jari, doxygen group as Finding maximum and minimum elements
     150    inline size_t max_index(void) const { return gsl_vector_max_index(v_); }
     151
     152    ///
     153    /// @return The minimum value of the vector.
     154    ///
     155    // Jari, doxygen group as Finding maximum and minimum elements
     156    inline double min(void) const { return gsl_vector_min(v_); }
     157
     158    ///
     159    /// @return The element index to the minimum value of the
     160    /// vector. The lowest index has precedence.
     161    ///
     162    // Jari, doxygen group as Finding maximum and minimum elements
     163    inline size_t min_index(void) const { return gsl_vector_min_index(v_); }
     164
     165    ///
     166    /// @return The minimum and maximum values of the vector, as the
     167    /// \a first and \a second member of the returned \a pair,
     168    /// respectively.
     169    ///
     170    // Jari, doxygen group as Finding maximum and minimum elements
     171    std::pair<double,double> vector::minmax(void) const;
     172
     173    ///
     174    /// @return The indecies to the minimum and maximum values of the
     175    /// vector, as the \a first and \a second member of the returned
     176    /// \a pair, respectively. The lowest index has precedence.
     177    ///
     178    // Jari, doxygen group as Finding maximum and minimum elements
    100179    std::pair<size_t,size_t> vector::minmax_index(void) const;
    101180
     
    110189    ///
    111190    std::pair<size_t,size_t>
    112     vector::minmax_index(const std::vector<size_t>& subset ) const;
    113 
    114     ///
    115     /// This function multiplies all elements between two vectors and
    116     /// returns a third vector containing the result, \f$a_i = b_i *
    117     /// c_i \; \forall i\f$.
    118     ///
    119     /// @return The result vector.
    120     ///
    121     vector vector::mul_elements( const vector& other ) const;
     191    vector::TEMP_minmax_index(const std::vector<size_t>& subset ) const;
     192
     193    ///
     194    /// This function performs element-wise multiplication, \f$this_i =
     195    /// this_i * other_i \; \forall i\f$.
     196    ///
     197    /// @return .GSL_SUCCESS on normal exit.
     198    ///
     199    // Jari, doxygen group as Vector operators
     200    inline int mul(const vector& other) { return gsl_vector_mul(v_,other.v_); }
     201
     202    ///
     203    /// Reverse the order of elements in the vector.
     204    ///
     205    /// @return .GSL_SUCCESS on normal exit.
     206    ///
     207    // Jari, doxygen group as Exchanging elements
     208    inline int reverse(void) { return gsl_vector_reverse(v_);}
     209
     210    ///
     211    /// Rescale vector, \f$this_i = this_i * factor \; \forall i\f$.
     212    ///
     213    /// @return .GSL_SUCCESS on normal exit.
     214    ///
     215    // Jari, doxygen group as Vector operators
     216    inline int scale(double factor) { return gsl_vector_scale(v_,factor); }
    122217
    123218    ///
    124219    /// Set all elements to \a value.
    125220    ///
     221    // Jari, doxygen group as Initializing vector elements
    126222    inline void set_all(const double& value) { gsl_vector_set_all(v_,value); }
    127223
     
    131227    /// one.
    132228    ///
     229    // Jari, doxygen group as Initializing vector elements
    133230    inline void set_basis(const size_t i) { gsl_vector_set_basis(v_,i); }
    134231   
     
    136233    /// Set all elements to zero.
    137234    ///
     235    // Jari, doxygen group as Initializing vector elements
    138236    inline void set_zero(void) { gsl_vector_set_zero(v_); }
    139237
     
    150248
    151249    ///
     250    /// Vector subtraction, \f$this_i = this_i - other_i \; \forall i\f$.
     251    ///
     252    /// @return .GSL_SUCCESS on normal exit.
     253    ///
     254    // Jari, doxygen group as Vector operators
     255    inline int sub(const vector& other) { return gsl_vector_sub(v_,other.v_); }
     256
     257    ///
    152258    /// Calculate the sum of all vector elements.
    153259    ///
    154260    /// @return The sum.
    155261    ///
     262    // Jari, doxygen group as "Extends GSL".
    156263    double vector::sum(void) const;
    157264
    158265    ///
     266    /// Swap vector elements by copying. The two vectors must have the
     267    /// same length.
     268    ///
     269    /// @return .GSL_SUCCESS on normal exit.
     270    ///
     271    inline int swap(vector& other) { return gsl_vector_swap(v_,other.v_); }
     272
     273    ///
     274    /// Exchange elements \a i and \a j.
     275    ///
     276    /// @return .GSL_SUCCESS on normal exit.
     277    ///
     278    // Jari, doxygen group as Exchanging elements
     279    inline int
     280    swap_elements(size_t i,size_t j) { return gsl_vector_swap_elements(v_,i,j);}
     281
     282    ///
    159283    /// Element access operator.
    160284    ///
    161285    /// @return Reference to element \a i.
    162286    ///
     287    // Jari, doxygen group as Accessing vector elements
    163288    inline double& operator()(size_t i) { return *gsl_vector_ptr(v_,i); }
    164289
     
    168293    /// @return The value of element \a i.
    169294    ///
     295    // Jari, doxygen group as Accessing vector elements
    170296    inline const double& operator()(size_t i) const
    171297      { return *gsl_vector_const_ptr(v_,i); }
     
    176302    /// @return Reference to element \a i.
    177303    ///
     304    // Jari, doxygen group as Accessing vector elements
    178305    inline double& operator[](size_t i) { return *gsl_vector_ptr(v_,i); }
    179306
     
    183310    /// @return The value of element \a i.
    184311    ///
     312    // Jari, doxygen group as Accessing vector elements
    185313    inline const double& operator[](size_t i) const
    186314      { return *gsl_vector_const_ptr(v_,i); }
     
    217345
    218346    ///
    219     /// Multiply and assign operator.
     347    /// Multiply with scalar and assign operator.
    220348    ///
    221349    vector& operator*=(const double d) { gsl_vector_scale(v_,d); return *this; }
    222350
    223351    ///
    224     /// Multiply operator.
    225     ///
    226     vector& operator*(const double d) { gsl_vector_scale(v_,d); return *this; }
     352    /// Vector with scalar multiplication.
     353    ///
     354    /// \note This operator is not implemented!
     355    ///
     356    vector operator*(const double d) const;
    227357
    228358
    229359  private:
    230360
     361    ///
     362    /// Create a new copy of the internal GSL vector.
     363    ///
     364    /// Necessary memory for the new GSL vector is allocated and the
     365    /// caller is responsible for freeing the allocated memory.
     366    ///
     367    /// @return A pointer to a copy of the internal GSL vector.
     368    ///
     369    gsl_vector* TEMP_gsl_vector_copy(void) const;
     370
    231371    gsl_vector* v_;
    232 
     372    gsl_vector_view* view_;
    233373  };
    234374
Note: See TracChangeset for help on using the changeset viewer.