Changeset 753 for trunk/yat/utility


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

Addresses #2. Continued adding GSL_error exceptions.

Location:
trunk/yat/utility
Files:
2 edited

Legend:

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

    r737 r753  
    55  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
    66  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
     7  Copyright (C) 2007 Jari Häkkinen
    78
    89  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
     
    4647
    4748  matrix::matrix(const size_t& r, const size_t& c, double init_value)
    48     : view_(NULL)
    49   {
    50     m_ = gsl_matrix_alloc(r,c);
     49    : m_(gsl_matrix_alloc(r,c)), view_(NULL)
     50  {
     51    if (!m_)
     52      throw utility::GSL_error("matrix::matrix failed to allocate memory");
    5153    set_all(init_value);
    5254  }
     
    5456
    5557  matrix::matrix(const matrix& o)
    56     : view_(NULL)
    57   {
    58     m_ = o.create_gsl_matrix_copy();
     58    : m_(o.create_gsl_matrix_copy()), view_(NULL)
     59  {
    5960  }
    6061
     
    6970                                                     offset_row,offset_column,
    7071                                                     n_row,n_column));
     72    if (!view_)
     73      throw utility::GSL_error("matrix::matrix failed to setup view");
    7174    m_ = &(view_->matrix);
    7275  }
     
    137140    // convert the data to a gsl matrix
    138141    m_ = gsl_matrix_alloc ( nof_rows, nof_columns );
     142    if (!m_)
     143      throw utility::GSL_error("matrix::matrix failed to allocate memory");
    139144    for(u_int i=0;i<nof_rows;i++)
    140145      for(u_int j=0;j<nof_columns;j++)
     
    176181  {
    177182    gsl_matrix* m = gsl_matrix_alloc(rows(),columns());
     183    if (!m)
     184      throw utility::GSL_error("matrix::create_gsl_matrix_copy failed to allocate memory");
    178185    gsl_matrix_memcpy(m,m_);  // Jari, a GSL return value is ignored here
    179186    return m;
     
    340347    else {
    341348      gsl_matrix* transposed = gsl_matrix_alloc(columns(),rows());
     349      if (!transposed)
     350        throw utility::GSL_error("matrix::transpose failed to allocate memory");
    342351      gsl_matrix_transpose_memcpy(transposed,m_);
    343352      gsl_matrix_free(m_);
     
    408417  {
    409418    gsl_matrix* result = gsl_matrix_alloc(rows(),other.columns());
     419    if (!result)
     420      throw utility::GSL_error("matrix::operator*= failed to allocate memory");
    410421    gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, m_, other.m_, 0.0, result);
    411422    gsl_matrix_free(m_);
  • trunk/yat/utility/vector.cc

    r733 r753  
    66  Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér
    77  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2007 Jari Häkkinen
    89
    910  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
     
    4950      proxy_v_(v_)
    5051  {
     52    if (!v_)
     53      throw utility::GSL_error("vector::vector failed to allocate memory");
     54
    5155    set_all(init_value);
    5256  }
     
    6872    view_ = new gsl_vector_view(gsl_vector_subvector_with_stride(v.v_,offset,
    6973                                                                 stride,n));
     74    if (!view_)
     75      throw utility::GSL_error("vector::vector failed to setup view");
    7076    proxy_v_ = v_ = &(view_->vector);
    7177  }
     
    8086    view_const_ = new gsl_vector_const_view(
    8187                   gsl_vector_const_subvector_with_stride(v.v_,offset,stride,n));
     88    if (!view_const_)
     89      throw utility::GSL_error("vector::vector failed to setup view");
    8290    proxy_v_ = v_const_ = &(view_const_->vector);
    8391  }
     
    170178    // convert the data to a gsl vector
    171179    proxy_v_ = v_ = gsl_vector_alloc(nof_rows*nof_columns);
     180    if (!v_)
     181      throw utility::GSL_error("vector::vector failed to allocate memory");
    172182    size_t n=0;
    173183    for (size_t i=0; i<nof_rows; i++)
     
    203213  {
    204214    gsl_vector* vec = gsl_vector_alloc(size());
     215    if (!vec)
     216      throw utility::GSL_error("vector::create_gsl_vector_copy failed to allocate memory");
    205217    gsl_vector_memcpy(vec, proxy_v_);
    206218    return vec;
Note: See TracChangeset for help on using the changeset viewer.