Changeset 753
 Timestamp:
 Feb 17, 2007, 2:33:24 PM (16 years ago)
 Location:
 trunk/yat/utility
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/utility/matrix.cc
r737 r753 5 5 Copyright (C) 2004 Jari HÃ¤kkinen, Peter Johansson 6 6 Copyright (C) 2005, 2006 Jari HÃ¤kkinen, Peter Johansson, Markus Ringnér 7 Copyright (C) 2007 Jari HÃ¤kkinen 7 8 8 9 This file is part of the yat library, http://lev.thep.lu.se/trac/yat … … 46 47 47 48 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"); 51 53 set_all(init_value); 52 54 } … … 54 56 55 57 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 { 59 60 } 60 61 … … 69 70 offset_row,offset_column, 70 71 n_row,n_column)); 72 if (!view_) 73 throw utility::GSL_error("matrix::matrix failed to setup view"); 71 74 m_ = &(view_>matrix); 72 75 } … … 137 140 // convert the data to a gsl matrix 138 141 m_ = gsl_matrix_alloc ( nof_rows, nof_columns ); 142 if (!m_) 143 throw utility::GSL_error("matrix::matrix failed to allocate memory"); 139 144 for(u_int i=0;i<nof_rows;i++) 140 145 for(u_int j=0;j<nof_columns;j++) … … 176 181 { 177 182 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"); 178 185 gsl_matrix_memcpy(m,m_); // Jari, a GSL return value is ignored here 179 186 return m; … … 340 347 else { 341 348 gsl_matrix* transposed = gsl_matrix_alloc(columns(),rows()); 349 if (!transposed) 350 throw utility::GSL_error("matrix::transpose failed to allocate memory"); 342 351 gsl_matrix_transpose_memcpy(transposed,m_); 343 352 gsl_matrix_free(m_); … … 408 417 { 409 418 gsl_matrix* result = gsl_matrix_alloc(rows(),other.columns()); 419 if (!result) 420 throw utility::GSL_error("matrix::operator*= failed to allocate memory"); 410 421 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, m_, other.m_, 0.0, result); 411 422 gsl_matrix_free(m_); 
trunk/yat/utility/vector.cc
r733 r753 6 6 Copyright (C) 2005 Jari HÃ¤kkinen, Peter Johansson, Markus Ringnér 7 7 Copyright (C) 2006 Jari HÃ¤kkinen, Peter Johansson 8 Copyright (C) 2007 Jari HÃ¤kkinen 8 9 9 10 This file is part of the yat library, http://lev.thep.lu.se/trac/yat … … 49 50 proxy_v_(v_) 50 51 { 52 if (!v_) 53 throw utility::GSL_error("vector::vector failed to allocate memory"); 54 51 55 set_all(init_value); 52 56 } … … 68 72 view_ = new gsl_vector_view(gsl_vector_subvector_with_stride(v.v_,offset, 69 73 stride,n)); 74 if (!view_) 75 throw utility::GSL_error("vector::vector failed to setup view"); 70 76 proxy_v_ = v_ = &(view_>vector); 71 77 } … … 80 86 view_const_ = new gsl_vector_const_view( 81 87 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"); 82 90 proxy_v_ = v_const_ = &(view_const_>vector); 83 91 } … … 170 178 // convert the data to a gsl vector 171 179 proxy_v_ = v_ = gsl_vector_alloc(nof_rows*nof_columns); 180 if (!v_) 181 throw utility::GSL_error("vector::vector failed to allocate memory"); 172 182 size_t n=0; 173 183 for (size_t i=0; i<nof_rows; i++) … … 203 213 { 204 214 gsl_vector* vec = gsl_vector_alloc(size()); 215 if (!vec) 216 throw utility::GSL_error("vector::create_gsl_vector_copy failed to allocate memory"); 205 217 gsl_vector_memcpy(vec, proxy_v_); 206 218 return vec;
Note: See TracChangeset
for help on using the changeset viewer.