Changeset 1598 for trunk/yat


Ignore:
Timestamp:
Oct 24, 2008, 11:12:37 PM (13 years ago)
Author:
Peter
Message:

Fixed some issues related to empty (zero sized) Matrix.

  • Matrix(size_t, size_t) now accepts 0 as argument
  • Matrix(const& Matrix) now works when passed Matrix is empty
  • assignment now works when rhs is empty

related to ticket:343

File:
1 edited

Legend:

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

    r1487 r1598  
    4949
    5050  Matrix::Matrix(const size_t& r, const size_t& c, double init_value)
    51     : blas_result_(NULL), m_(gsl_matrix_alloc(r,c))
    52   {
    53     if (!m_)
    54       throw utility::GSL_error("Matrix::Matrix failed to allocate memory");
    55     all(init_value);
     51    : blas_result_(NULL), m_(NULL)
     52  {
     53    resize(r,c,init_value);
    5654  }
    5755
     
    217215  gsl_matrix* Matrix::create_gsl_matrix_copy(void) const
    218216  {
     217    if (!m_)
     218      return NULL;
    219219    gsl_matrix* m = gsl_matrix_alloc(rows(),columns());
    220220    if (!m)
     
    441441  const Matrix& Matrix::operator=( const Matrix& other )
    442442  {
    443     assert(other.m_);
    444443    if (this!=&other) {
    445       if ( !m_ || (other.m_->size1!=m_->size1) || (other.m_->size2!=m_->size2) )
    446         resize(other.m_->size1,other.m_->size2);
    447       if (gsl_matrix_memcpy(m_, other.gsl_matrix_p()))
    448         throw utility::GSL_error("Matrix::create_gsl_matrix_copy dimension mis-match");
     444      if (rows()!=other.rows() || columns()!=other.columns())
     445        resize(other.rows(), other.columns());
     446       
     447      if (m_)
     448        if (gsl_matrix_memcpy(m_, other.gsl_matrix_p())) {
     449          std::string s="Matrix::create_gsl_matrix_copy dimension mis-match";
     450          throw utility::GSL_error(s);
     451        }
    449452    }
    450453    return *this;
Note: See TracChangeset for help on using the changeset viewer.