Changeset 1506


Ignore:
Timestamp:
Sep 17, 2008, 12:53:55 AM (15 years ago)
Author:
Peter
Message:

fixes #434

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/vector_test.cc

    r1487 r1506  
    341341  }
    342342
     343  // test for zero size constructor
     344  {
     345    theplu::yat::utility::Vector vec(0, 1.2);
     346    theplu::yat::utility::Vector vec2(vec);
     347  }
    343348  return suite.return_value();
    344349}
  • trunk/yat/utility/Vector.cc

    r1487 r1506  
    4646
    4747  Vector::Vector(size_t n, double init_value)
    48     : VectorMutable(gsl_vector_alloc(n))
    49   {
    50     if (!vec_)
    51       throw utility::GSL_error("Vector::Vector failed to allocate memory");
    52     assert(const_vec_);
    53     all(init_value);
     48    : VectorMutable(create_gsl_vector(n))
     49  {
     50    if (n)
     51      all(init_value);
     52    assert(n==0 || vec_);
     53    assert(n==0 || const_vec_);
    5454  }
    5555
     
    204204
    205205
     206  gsl_vector* Vector::create_gsl_vector(size_t n) const
     207  {
     208    if (!n)
     209      return NULL;
     210    gsl_vector* vec = gsl_vector_alloc(n);
     211    if (!vec)
     212      throw utility::GSL_error("Vector::create_gsl_vector failed to allocate memory");
     213    return vec;
     214  }
     215
     216
    206217  void Vector::delete_allocated_memory(void)
    207218  {
  • trunk/yat/utility/Vector.h

    r1487 r1506  
    164164    gsl_vector* create_gsl_vector_copy(const VectorBase&) const;
    165165
     166    /**
     167       \brief Create a new gsl vector
     168
     169       Necessary memory for the new GSL vector is allocated and the
     170       caller is responsible for freeing the allocated memory.
     171
     172       \return A pointer to created GSL vector.
     173
     174       \throw GSL_error if memory cannot be allocated for the new
     175       GSL vector.
     176    */
     177    gsl_vector* create_gsl_vector(size_t n) const;
     178
    166179    void delete_allocated_memory(void);
    167180  };
Note: See TracChangeset for help on using the changeset viewer.