Changeset 1120 for trunk/yat/utility


Ignore:
Timestamp:
Feb 22, 2008, 12:18:41 AM (14 years ago)
Author:
Peter
Message:

vector is now Vector

Location:
trunk/yat/utility
Files:
12 edited
2 moved

Legend:

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

    r1000 r1120  
    2626#include "Alignment.h"
    2727#include "matrix.h"
    28 #include "yat/utility/stl_utility.h"
     28#include "stl_utility.h"
    2929
    3030#include <algorithm>
  • trunk/yat/utility/Makefile.am

    r1110 r1120  
    2929  matrix.cc NNI.cc Option.cc OptionFile.cc OptionInFile.cc OptionOutFile.cc \
    3030  OptionHelp.cc OptionSwitch.cc \
    31   PCA.cc stl_utility.cc SVD.cc TypeInfo.cc utility.cc vector.cc \
     31  PCA.cc stl_utility.cc SVD.cc TypeInfo.cc utility.cc Vector.cc \
    3232  VectorBase.cc VectorConstView.cc VectorMutable.cc VectorView.cc WeNNI.cc
    3333
     
    4242  OptionHelp.h OptionSwitch.h \
    4343  PCA.h SmartPtr.h stl_utility.h StrideIterator.h \
    44   SVD.h TypeInfo.h utility.h vector.h \
     44  SVD.h TypeInfo.h utility.h Vector.h \
    4545  VectorBase.h VectorConstView.h VectorMutable.h VectorView.h \
    4646  WeNNI.h yat_assert.h
  • trunk/yat/utility/PCA.cc

    r1098 r1120  
    4747
    4848
    49   const utility::vector& PCA::eigenvalues(void) const
     49  const utility::Vector& PCA::eigenvalues(void) const
    5050  {
    5151    return eigenvalues_;
     
    147147    utility::matrix projs( Ncol, Ncol );
    148148
    149     utility::vector temp(samples.rows());
     149    utility::Vector temp(samples.rows());
    150150    for( size_t j = 0; j < Ncol; ++j ) {
    151151      for (size_t i=0; i<Ncol; ++i )
    152152        temp(i) = samples(i,j);
    153       utility::vector centered( Nrow );
     153      utility::Vector centered( Nrow );
    154154      for( size_t i = 0; i < Nrow; ++i )
    155155        centered(i) = temp(i) - meanvalues_(i);
    156       utility::vector proj( eigenvectors_ * centered );
     156      utility::Vector proj( eigenvectors_ * centered );
    157157      for( size_t i = 0; i < Ncol; ++i )
    158158        projs(i,j)=proj(i);
     
    191191  void PCA::row_center(utility::matrix& A_center)
    192192  {
    193     meanvalues_ = vector(A_.rows());
    194     utility::vector A_row_sum(A_.rows());
     193    meanvalues_ = Vector(A_.rows());
     194    utility::Vector A_row_sum(A_.rows());
    195195    for (size_t i=0; i<A_row_sum.size(); ++i){
    196196      A_row_sum(i) = sum(A_.row_const_view(i));
  • trunk/yat/utility/PCA.h

    r1000 r1120  
    3030
    3131#include "matrix.h"
    32 #include "vector.h"
     32#include "Vector.h"
    3333
    3434namespace theplu {
     
    7373       eigenvalues.
    7474    */
    75     const utility::vector& eigenvalues(void) const;
     75    const utility::Vector& eigenvalues(void) const;
    7676
    7777    /**
     
    119119
    120120    utility::matrix A_;
    121     utility::vector eigenvalues_;
     121    utility::Vector eigenvalues_;
    122122    utility::matrix eigenvectors_;
    123     utility::vector meanvalues_;
     123    utility::Vector meanvalues_;
    124124  };
    125125
  • trunk/yat/utility/SVD.cc

    r1016 r1120  
    2626
    2727#include "SVD.h"
    28 #include "vector.h"
     28#include "Vector.h"
    2929#include "VectorBase.h"
    3030
     
    7272  int SVD::golub_reinsch(void)
    7373  {
    74     utility::vector w(U_.columns());
     74    utility::Vector w(U_.columns());
    7575    return gsl_linalg_SV_decomp(U_.gsl_matrix_p(), V_.gsl_matrix_p(),
    7676                                s_.gsl_vector_p(), w.gsl_vector_p());
     
    8787  int SVD::modified_golub_reinsch(void)
    8888  {
    89     utility::vector w(U_.columns());
     89    utility::Vector w(U_.columns());
    9090    utility::matrix X(U_.columns(),U_.columns());
    9191    return gsl_linalg_SV_decomp_mod(U_.gsl_matrix_p(), X.gsl_matrix_p(),
     
    9595
    9696
    97   const utility::vector& SVD::s(void) const
     97  const utility::Vector& SVD::s(void) const
    9898  {
    9999    return s_;
     
    101101
    102102
    103   void SVD::solve(const utility::VectorBase& b, utility::vector& x)
     103  void SVD::solve(const utility::VectorBase& b, utility::Vector& x)
    104104  {
    105105    int status=gsl_linalg_SV_solve(U_.gsl_matrix_p(), V_.gsl_matrix_p(),
  • trunk/yat/utility/SVD.h

    r1016 r1120  
    3030
    3131#include "matrix.h"
    32 #include "vector.h"
     32#include "Vector.h"
    3333
    3434#include <gsl/gsl_linalg.h>
     
    103103       is undefined.
    104104    */
    105     const utility::vector& s(void) const;
     105    const utility::Vector& s(void) const;
    106106
    107107    /**
     
    114114       \throw GSL_error if the underlying GSL function fails.
    115115    */
    116     void solve(const utility::VectorBase& b, utility::vector& x);
     116    void solve(const utility::VectorBase& b, utility::Vector& x);
    117117
    118118    /**
     
    159159
    160160    utility::matrix U_, V_;
    161     utility::vector s_;
     161    utility::Vector s_;
    162162  }; 
    163163
  • trunk/yat/utility/Vector.cc

    r1118 r1120  
    2525*/
    2626
    27 #include "vector.h"
     27#include "Vector.h"
    2828#include "matrix.h"
    2929#include "utility.h"
     
    4343
    4444
    45   vector::vector(void)
     45  Vector::Vector(void)
    4646    : VectorMutable()
    4747  {
     
    4949
    5050
    51   vector::vector(size_t n, double init_value)
     51  Vector::Vector(size_t n, double init_value)
    5252    : VectorMutable(gsl_vector_alloc(n))
    5353  {
    5454    if (!vec_)
    55       throw utility::GSL_error("vector::vector failed to allocate memory");
     55      throw utility::GSL_error("Vector::Vector failed to allocate memory");
    5656    assert(const_vec_);
    5757    all(init_value);
     
    5959
    6060
    61   vector::vector(const vector& other)
     61  Vector::Vector(const Vector& other)
    6262    : VectorMutable(create_gsl_vector_copy(other))
    6363  {
     
    6565
    6666
    67   vector::vector(const VectorBase& other)
     67  Vector::Vector(const VectorBase& other)
    6868    : VectorMutable(create_gsl_vector_copy(other))
    6969  {
     
    7171
    7272
    73   vector::vector(std::istream& is, char sep)
     73  Vector::Vector(std::istream& is, char sep)
    7474    throw (utility::IO_error, std::exception)
    7575    : VectorMutable()
     
    117117      else if (nof_rows && (nof_columns>1)) {
    118118        std::ostringstream s;
    119         s << "vector::vector(std::istream&) data file error:\n"
     119        s << "Vector::Vector(std::istream&) data file error:\n"
    120120          << "    File has inconsistent number of rows (" << nof_rows
    121121          << ") and columns (" << nof_columns
    122           << ").\n    Expected a row or a column vector.";
     122          << ").\n    Expected a row or a column Vector.";
    123123        throw utility::IO_error(s.str());
    124124      }
    125125      else if (v.size()!=nof_columns) {
    126126        std::ostringstream s;
    127         s << "vector::vector(std::istream&) data file error:\n"
     127        s << "Vector::Vector(std::istream&) data file error:\n"
    128128          << "    Line " << nof_rows << " has " << v.size()
    129129          << " columns; expected " << nof_columns << " column.";
     
    138138    vec_ = gsl_vector_alloc(nof_rows*nof_columns);
    139139    if (!vec_)
    140       throw utility::GSL_error("vector::vector failed to allocate memory");
     140      throw utility::GSL_error("Vector::Vector failed to allocate memory");
    141141    size_t n=0;
    142142    // if gsl error handler disabled, out of bounds index will not
     
    149149
    150150
    151   vector::~vector(void)
     151  Vector::~Vector(void)
    152152  {
    153153    delete_allocated_memory();
     
    155155
    156156
    157   const vector& vector::assign(const VectorBase& other)
     157  const Vector& Vector::assign(const VectorBase& other)
    158158  {
    159159    delete_allocated_memory();
     
    162162        vec_ = gsl_vector_alloc(other.size());
    163163      if (!vec_)
    164         throw utility::GSL_error("vector failed to allocate memory");
     164        throw utility::GSL_error("Vector failed to allocate memory");
    165165      gsl_vector_memcpy(vec_,other.gsl_vector_p());
    166166      const_vec_ = vec_;
     
    170170
    171171
    172   gsl_vector* vector::create_gsl_vector_copy(const VectorBase& other) const
     172  gsl_vector* Vector::create_gsl_vector_copy(const VectorBase& other) const
    173173  {
    174174    gsl_vector* vec = gsl_vector_alloc(other.size());
    175175    if (!vec)
    176       throw utility::GSL_error("vector::create_gsl_vector_copy failed to allocate memory");
     176      throw utility::GSL_error("Vector::create_gsl_vector_copy failed to allocate memory");
    177177    if (gsl_vector_memcpy(vec, other.gsl_vector_p()))
    178       throw utility::GSL_error("vector::create_gsl_matrix_copy dimension mis-match");
     178      throw utility::GSL_error("Vector::create_gsl_matrix_copy dimension mis-match");
    179179    return vec;
    180180  }
    181181
    182182
    183   void vector::delete_allocated_memory(void)
     183  void Vector::delete_allocated_memory(void)
    184184  {
    185185    if (vec_)
     
    189189
    190190
    191   bool vector::isview(void) const
     191  bool Vector::isview(void) const
    192192  {
    193193    return false;
     
    195195
    196196
    197   void vector::resize(size_t n, double init_value)
     197  void Vector::resize(size_t n, double init_value)
    198198  {
    199199    delete_allocated_memory();
    200200    const_vec_ = vec_ = gsl_vector_alloc(n);
    201201    if (!vec_)
    202       throw utility::GSL_error("vector::vector failed to allocate memory");
     202      throw utility::GSL_error("Vector::Vector failed to allocate memory");
    203203    all(init_value);
    204204  }
    205205
    206206
    207   void set_basis(vector& v, size_t i)
     207  void set_basis(Vector& v, size_t i)
    208208  {
    209209    assert(v.gsl_vector_p());
     
    212212
    213213
    214   void sort(vector& v)
     214  void sort(Vector& v)
    215215  {
    216216    assert(v.gsl_vector_p());
     
    219219
    220220
    221   void swap(vector& v, vector& w)
     221  void swap(Vector& v, Vector& w)
    222222  {
    223223    assert(v.gsl_vector_p()); assert(w.gsl_vector_p());
    224224    int status=gsl_vector_swap(v.gsl_vector_p(),w.gsl_vector_p());
    225225    if (status)
    226       throw utility::GSL_error(std::string("swap(vector&,vector&)",status));
    227   }
    228 
    229 
    230   const vector& vector::operator=( const VectorBase& other )
     226      throw utility::GSL_error(std::string("swap(Vector&,Vector&)",status));
     227  }
     228
     229
     230  const Vector& Vector::operator=( const VectorBase& other )
    231231  {
    232232    return assign(other);
     
    234234
    235235
    236   const vector& vector::operator=( const vector& other )
     236  const Vector& Vector::operator=( const Vector& other )
    237237  {
    238238    return assign(other);
  • trunk/yat/utility/Vector.h

    r1118 r1120  
    5858  */
    5959
    60   class vector : public VectorMutable
     60  class Vector : public VectorMutable
    6161  {
    6262  public:
     
    6464       \brief The default constructor.
    6565    */
    66     vector(void);
     66    Vector(void);
    6767
    6868    /**
     
    7272       \throw GSL_error if memory allocation fails.
    7373    */
    74     vector(size_t n, double init_value=0);
     74    Vector(size_t n, double init_value=0);
    7575
    7676    /**
     
    8080       fails.
    8181    */
    82     vector(const vector& other);
     82    Vector(const Vector& other);
    8383
    8484    /**
     
    8888       fails.
    8989    */
    90     vector(const VectorBase& other);
     90    Vector(const VectorBase& other);
    9191
    9292    /**
     
    9797       sep. When delimiter \a sep is used empty elements are stored as
    9898       NaN's (except that empty lines are ignored). The end of input
    99        to the vector is at end of file marker.
     99       to the Vector is at end of file marker.
    100100
    101101       \throw GSL_error if memory allocation fails, IO_error if
    102102       unexpected input is found in the input stream.
    103103    */
    104     explicit vector(std::istream &, char sep='\0')
     104    explicit Vector(std::istream &, char sep='\0')
    105105      throw(utility::IO_error, std::exception);
    106106
     
    108108    /// The destructor.
    109109    ///
    110     ~vector(void);
     110    ~Vector(void);
    111111
    112112    /**
     
    116116
    117117    /**
    118       \brief Resize vector
     118      \brief Resize Vector
    119119
    120120      All elements are set to \a init_value.
    121121
    122122      \note Underlying GSL vector is destroyed and a view into this
    123       vector becomes invalid.
     123      Vector becomes invalid.
    124124    */
    125125    void resize(size_t, double init_value=0);
     
    128128       \brief The assignment operator.
    129129
    130        \note Invalidates views of vector.
     130       \note Invalidates views of Vector.
    131131
    132        \return A const reference to the resulting vector.
     132       \return A const reference to the resulting Vector.
    133133    */
    134     const vector& operator=(const vector&);
     134    const Vector& operator=(const Vector&);
    135135
    136136    /**
    137137       \brief The assignment operator.
    138138
    139        \note Invalidates views of vector.
     139       \note Invalidates views of Vector.
    140140
    141        \return A const reference to the resulting vector.
     141       \return A const reference to the resulting Vector.
    142142    */
    143     const vector& operator=(const VectorBase&);
     143    const Vector& operator=(const VectorBase&);
    144144
    145145  private:
    146     const vector& assign(const VectorBase& other);
     146    const Vector& assign(const VectorBase& other);
    147147
    148148    /**
     
    163163
    164164  /**
    165      \brief Swap vector elements by copying.
     165     \brief Swap Vector elements by copying.
    166166
    167      The two vectors must have the same length.
     167     The two Vectors must have the same length.
    168168
    169      \throw GSL_error if vector lengths differs.
     169     \throw GSL_error if Vector lengths differs.
    170170  */
    171   void swap(vector&, vector&);
     171  void swap(Vector&, Vector&);
    172172
    173173}}} // of namespace utility, yat, and theplu
  • trunk/yat/utility/VectorBase.cc

    r1038 r1120  
    167167
    168168
    169   bool nan(const VectorBase& templat, vector& flag)
     169  bool nan(const VectorBase& templat, Vector& flag)
    170170  {
    171171    size_t vsize(templat.size());
    172     flag = vector(vsize, 1.0);
     172    flag = Vector(vsize, 1.0);
    173173    bool nan=false;
    174174    for (size_t i=0; i<vsize; i++)
  • trunk/yat/utility/VectorBase.h

    r1046 r1120  
    4545 
    4646  class matrix;
    47   class vector;
     47  class Vector;
    4848
    4949  /**
     
    213213     \return True if the \a templat VectorBase contains at least one NaN.
    214214  */
    215   bool nan(const VectorBase& templat, vector& flag);
     215  bool nan(const VectorBase& templat, Vector& flag);
    216216
    217217  /**
  • trunk/yat/utility/VectorMutable.h

    r1118 r1120  
    4646
    4747  class matrix;
    48   class vector;
     48  class Vector;
    4949
    5050  /**
  • trunk/yat/utility/VectorView.h

    r1118 r1120  
    4444
    4545  class matrix;
    46   class vector;
     46  class Vector;
    4747
    4848  /**
  • trunk/yat/utility/matrix.cc

    r1103 r1120  
    2525*/
    2626
    27 #include "matrix.h"
    28 #include "vector.h"
     27#include "yat/utility/matrix.h"
     28#include "yat/utility/Vector.h"
    2929#include "VectorBase.h"
    3030#include "VectorConstView.h"
     
    576576
    577577
    578   vector operator*(const matrix& m, const VectorBase& v)
    579   {
    580     utility::vector res(m.rows());
     578  Vector operator*(const matrix& m, const VectorBase& v)
     579  {
     580    utility::Vector res(m.rows());
    581581    for (size_t i=0; i<res.size(); ++i)
    582582      res(i) = VectorConstView(m,i) * v;
     
    585585
    586586
    587   vector operator*(const VectorBase& v, const matrix& m)
    588   {
    589     utility::vector res(m.columns());
     587  Vector operator*(const VectorBase& v, const matrix& m)
     588  {
     589    utility::Vector res(m.columns());
    590590    for (size_t i=0; i<res.size(); ++i)
    591591      res(i) = v * VectorConstView(m,i,false);
  • trunk/yat/utility/matrix.h

    r1103 r1120  
    3131#include "Exception.h"
    3232#include "StrideIterator.h"
    33 #include "vector.h"
     33#include "Vector.h"
    3434#include "VectorConstView.h"
    3535#include "VectorView.h"
     
    538538     \brief vector matrix multiplication
    539539   */
    540   vector operator*(const matrix&, const VectorBase&);
     540  Vector operator*(const matrix&, const VectorBase&);
    541541
    542542  /**
    543543     \brief matrix vector multiplication
    544544   */
    545   vector operator*(const VectorBase&, const matrix&);
     545  Vector operator*(const VectorBase&, const matrix&);
    546546
    547547}}} // of namespace utility, yat, and theplu
Note: See TracChangeset for help on using the changeset viewer.