Changeset 762 for trunk/yat/utility/matrix.cc
- Timestamp:
- Feb 20, 2007, 8:18:48 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/matrix.cc
r759 r762 41 41 42 42 matrix::matrix(void) 43 : m_(NULL), view_(NULL)43 : blas_result_(NULL), m_(NULL), view_(NULL) 44 44 { 45 45 } … … 47 47 48 48 matrix::matrix(const size_t& r, const size_t& c, double init_value) 49 : m_(gsl_matrix_alloc(r,c)), view_(NULL)49 : blas_result_(NULL), m_(gsl_matrix_alloc(r,c)), view_(NULL) 50 50 { 51 51 if (!m_) … … 56 56 57 57 matrix::matrix(const matrix& o) 58 : m_(o.create_gsl_matrix_copy()), view_(NULL)58 : blas_result_(NULL), m_(o.create_gsl_matrix_copy()), view_(NULL) 59 59 { 60 60 } … … 63 63 matrix::matrix(matrix& m, size_t offset_row, size_t offset_column, 64 64 size_t n_row, size_t n_column) 65 : blas_result_(NULL) 65 66 { 66 67 view_ = new gsl_matrix_view(gsl_matrix_submatrix(m.m_, … … 76 77 matrix::matrix(std::istream& is, char sep) 77 78 throw (utility::IO_error,std::exception) 78 : view_(NULL)79 : blas_result_(NULL), view_(NULL) 79 80 { 80 81 // read the data file and store in stl vectors (dynamically … … 148 149 if (view_) 149 150 delete view_; 150 else if (m_) 151 gsl_matrix_free(m_); 151 else { 152 if (blas_result_) 153 gsl_matrix_free(blas_result_); 154 if (m_) 155 gsl_matrix_free(m_); 156 } 157 blas_result_=NULL; 152 158 m_=NULL; 153 159 } … … 371 377 gsl_matrix_free(m_); 372 378 m_=transposed; 379 if (blas_result_) { 380 gsl_matrix_free(blas_result_); 381 blas_result_=NULL; 382 } 373 383 } 374 384 } … … 441 451 const matrix& matrix::operator*=(const matrix& other) 442 452 { 443 gsl_matrix* result = gsl_matrix_alloc(rows(),other.columns()); 444 if (!result) 445 throw utility::GSL_error("matrix::operator*= failed to allocate memory"); 446 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, m_, other.m_, 0.0, result); 447 gsl_matrix_free(m_); 448 m_=result; 453 if (!blas_result_) { 454 blas_result_ = gsl_matrix_alloc(rows(),other.columns()); 455 if (!blas_result_) 456 throw utility::GSL_error("matrix::operator*= failed to allocate memory"); 457 } 458 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, m_, other.m_, 0.0, 459 blas_result_); 460 gsl_matrix* tmp=m_; 461 m_=blas_result_; 462 blas_result_=tmp; 449 463 return *this; 450 464 }
Note: See TracChangeset
for help on using the changeset viewer.