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

Addresses #2. Continued adding GSL_error exceptions.

File:
1 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_);
Note: See TracChangeset for help on using the changeset viewer.