Ignore:
Timestamp:
Feb 2, 2008, 10:29:29 PM (14 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 edited

Legend:

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

    r1015 r1027  
    4343
    4444
    45   VectorBase::VectorBase(void)
    46     : vec_(NULL), const_vec_(NULL)
    47   {
    48   }
    49 
    50 
    51   VectorBase::VectorBase(gsl_vector* v)
    52     : vec_(v), const_vec_(v)
    53   {
    54   }
    55 
    56 
    5745  VectorBase::VectorBase(const gsl_vector* v)
    58     : vec_(NULL), const_vec_(v)
     46    : const_vec_(v)
    5947  {
    6048  }
     
    6654
    6755
    68   void VectorBase::all(double value)
    69   {
    70     assert(vec_);
    71     gsl_vector_set_all(vec_,value);
    72   }
    73 
    74 
    7556  VectorBase::const_iterator VectorBase::begin(void) const
    7657  {
     
    7960
    8061
    81   VectorBase::iterator VectorBase::begin(void)
    82   {
    83     return iterator(*this, 0);
    84   }
    85 
    86 
    87   void VectorBase::div(const VectorBase& other)
    88   {
    89     assert(vec_);
    90     int status=gsl_vector_div(vec_,other.gsl_vector_p());
    91     if (status)
    92       throw utility::GSL_error(std::string("VectorBase::div",status));
    93   }
    94 
    95 
    9662  VectorBase::const_iterator VectorBase::end(void) const
    9763  {
    9864    return const_iterator(*this, size());
    99   }
    100 
    101 
    102   VectorBase::iterator VectorBase::end(void)
    103   {
    104     return iterator(*this, size());
    10565  }
    10666
     
    12888
    12989
    130   gsl_vector* VectorBase::gsl_vector_p(void)
    131   {
    132     return vec_;
    133   }
    134 
    135 
    136   void VectorBase::mul(const VectorBase& other)
    137   {
    138     assert(vec_);
    139     int status=gsl_vector_mul(vec_,other.gsl_vector_p());
    140     if (status)
    141       throw utility::GSL_error(std::string("VectorBase::div",status));
    142   }
    143 
    144 
    14590  size_t VectorBase::size(void) const
    14691  {
     
    160105
    161106
    162   double& VectorBase::operator()(size_t i)
    163   {
    164     double* d=gsl_vector_ptr(vec_, i);
    165     if (!d)
    166       throw utility::GSL_error("VectorBase::operator()",GSL_EINVAL);
    167     return *d;
    168   }
    169 
    170 
    171   double& VectorBase::operator[](size_t i)
    172   {
    173     return this->operator()(i);
    174   }
    175 
    176 
    177107  const double& VectorBase::operator[](size_t i) const
    178108  {
     
    199129      res += other(i) * (*this)(i);
    200130    return res;
    201   }
    202 
    203 
    204   const VectorBase& VectorBase::operator+=(double d)
    205   {
    206     assert(vec_);
    207     gsl_vector_add_constant(vec_, d);
    208     return *this;
    209   }
    210 
    211 
    212   const VectorBase& VectorBase::operator-=(const VectorBase& other)
    213   {
    214     assert(vec_);
    215     int status=gsl_vector_sub(vec_, other.gsl_vector_p());
    216     if (status)
    217       throw utility::GSL_error(std::string("VectorBase::sub", status));
    218     return *this;
    219   }
    220 
    221 
    222   const VectorBase& VectorBase::operator-=(const double d)
    223   {
    224     assert(vec_);
    225     gsl_vector_add_constant(vec_, -d);
    226     return *this;
    227   }
    228 
    229 
    230   const VectorBase& VectorBase::operator*=(double d)
    231   {
    232     assert(vec_);
    233     gsl_vector_scale(vec_, d);
    234     return *this;
    235131  }
    236132
     
    280176
    281177
    282   void shuffle(VectorBase& invec)
    283   {
    284     random::DiscreteUniform rnd;
    285     std::random_shuffle(invec.begin(), invec.end(), rnd);
    286   }
    287 
    288 
    289178  void sort_index(std::vector<size_t>& sort_index, const VectorBase& invec)
    290179  {
Note: See TracChangeset for help on using the changeset viewer.