Ignore:
Timestamp:
Feb 17, 2007, 11:33:44 PM (15 years ago)
Author:
Jari Häkkinen
Message:

Addresses #2 and #65. Continued adding GSL_error exceptions, and added doxygen briefs.

File:
1 edited

Legend:

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

    r753 r754  
    6767    : v_const_(NULL), view_const_(NULL)
    6868  {
    69     // Jari, exception handling needed here. Failure in setting up a
    70     // proper gsl_vector_view is communicated by NULL pointer in the
    71     // view structure (cf. GSL manual). How about GSL error state?
    7269    view_ = new gsl_vector_view(gsl_vector_subvector_with_stride(v.v_,offset,
    7370                                                                 stride,n));
     
    8178    : v_(NULL), view_(NULL)
    8279  {
    83     // Jari, exception handling needed here. Failure in setting up a
    84     // proper gsl_vector_view is communicated by NULL pointer in the
    85     // view structure (cf. GSL manual). How about GSL error state?
    8680    view_const_ = new gsl_vector_const_view(
    8781                   gsl_vector_const_subvector_with_stride(v.v_,offset,stride,n));
     
    181175      throw utility::GSL_error("vector::vector failed to allocate memory");
    182176    size_t n=0;
     177    // if gsl error handler disabled, out of bounds index will not
     178    // abort the program.
    183179    for (size_t i=0; i<nof_rows; i++)
    184180      for (size_t j=0; j<nof_columns; j++)
     
    198194
    199195
    200   int vector::add(const vector& other)
    201   {
    202     return gsl_vector_add(v_,other.v_);
    203   }
    204 
    205 
    206   int vector::add(double term)
    207   {
    208     return gsl_vector_add_constant(v_,term);
     196  void vector::add(const vector& other)
     197  {
     198    int status=gsl_vector_add(v_,other.v_);
     199    if (status)
     200      throw utility::GSL_error(std::string("vector::add",status));
     201  }
     202
     203
     204  void vector::add(double term)
     205  {
     206    gsl_vector_add_constant(v_,term);
    209207  }
    210208
     
    215213    if (!vec)
    216214      throw utility::GSL_error("vector::create_gsl_vector_copy failed to allocate memory");
    217     gsl_vector_memcpy(vec, proxy_v_);
     215    if (gsl_vector_memcpy(vec, proxy_v_))
     216      throw utility::GSL_error("vector::create_gsl_matrix_copy dimension mis-match");
    218217    return vec;
    219218  }
     
    302301
    303302
    304   int vector::scale(double factor)
    305   {
    306     return gsl_vector_scale(v_,factor);
    307   }
    308 
    309 
    310   int vector::set(const vector& vec)
    311   {
    312     return gsl_vector_memcpy(v_,vec.v_);
     303  void vector::scale(double factor)
     304  {
     305    gsl_vector_scale(v_,factor);
     306  }
     307
     308
     309  void vector::set(const vector& vec)
     310  {
     311    if (gsl_vector_memcpy(v_,vec.v_))
     312      throw utility::GSL_error("vector::set dimension mis-match");
    313313  }
    314314
     
    346346
    347347
    348   int vector::sub(const vector& other)
    349   {
    350     return gsl_vector_sub(v_,other.v_);
     348  void vector::sub(const vector& other)
     349  {
     350    int status=gsl_vector_sub(v_,other.v_);
     351    if (status)
     352      throw utility::GSL_error(std::string("vector::sub",status));
    351353  }
    352354
     
    435437  const vector& vector::operator+=(const vector& other)
    436438  {
    437     gsl_vector_add(v_,other.v_);
     439    add(other);
    438440    return *this;
    439441  }
     
    442444  const vector& vector::operator-=(const vector& other)
    443445  {
    444     gsl_vector_sub(v_,other.v_);
     446    sub(other);
    445447    return *this;
    446448  }
     
    449451  const vector& vector::operator*=(const double d)
    450452  {
    451     gsl_vector_scale(v_,d);
     453    scale(d);
    452454    return *this;
    453455  }
Note: See TracChangeset for help on using the changeset viewer.