Changeset 810 for trunk/yat/utility/matrix.cc
 Timestamp:
 Mar 16, 2007, 12:31:22 AM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/utility/matrix.cc
r808 r810 151 151 matrix::~matrix(void) 152 152 { 153 delete_allocated_memory(); 154 if (blas_result_) 155 gsl_matrix_free(blas_result_); 156 } 157 158 159 const matrix& matrix::clone(const matrix& other) 160 { 161 if (this!=&other) { 162 163 delete_allocated_memory(); 164 165 if (other.view_) { 166 view_ = new gsl_matrix_view(*other.view_); 167 proxy_m_ = m_ = &(view_>matrix); 168 } 169 else if (other.view_const_) { 170 view_const_ = new gsl_matrix_const_view(*other.view_const_); 171 proxy_m_ = &(view_const_>matrix); 172 } 173 else if (other.m_) 174 proxy_m_ = m_ = other.create_gsl_matrix_copy(); 175 176 // no need to delete blas_result_ if the number of rows fit, it 177 // may be useful later. 178 if (blas_result_ && (blas_result_>size1!=rows())) { 179 gsl_matrix_free(blas_result_); 180 blas_result_=NULL; 181 } 182 } 183 return *this; 184 } 185 186 187 size_t matrix::columns(void) const 188 { 189 if (!proxy_m_) 190 return 0; 191 return proxy_m_>size2; 192 } 193 194 195 gsl_matrix* matrix::create_gsl_matrix_copy(void) const 196 { 197 gsl_matrix* m = gsl_matrix_alloc(rows(),columns()); 198 if (!m) 199 throw utility::GSL_error("matrix::create_gsl_matrix_copy failed to allocate memory"); 200 if (gsl_matrix_memcpy(m,proxy_m_)) 201 throw utility::GSL_error("matrix::create_gsl_matrix_copy dimension mismatch"); 202 return m; 203 } 204 205 206 void matrix::delete_allocated_memory(void) 207 { 153 208 if (view_) 154 209 delete view_; … … 157 212 else if (m_) 158 213 gsl_matrix_free(m_); 159 if (blas_result_)160 gsl_matrix_free(blas_result_);161 214 blas_result_=NULL; 162 m_=NULL; 163 } 164 165 166 const matrix& matrix::clone(const matrix& other) 167 { 168 if (this!=&other) { 169 170 if (view_) 171 delete view_; 172 else if (view_const_) 173 delete view_const_; 174 else if (m_) 175 gsl_matrix_free(m_); 176 proxy_m_=m_=NULL; 177 178 if (other.view_) { 179 view_ = new gsl_matrix_view(*other.view_); 180 proxy_m_ = m_ = &(view_>matrix); 181 } 182 else if (other.view_const_) { 183 view_const_ = new gsl_matrix_const_view(*other.view_const_); 184 proxy_m_ = &(view_const_>matrix); 185 } 186 else if (other.m_) 187 proxy_m_ = m_ = other.create_gsl_matrix_copy(); 188 189 // no need to delete blas_result_ if the number of rows fit, it 190 // may be useful later. 191 if (blas_result_ && (blas_result_>size1!=rows())) { 192 gsl_matrix_free(blas_result_); 193 blas_result_=NULL; 194 } 195 } 196 return *this; 197 } 198 199 200 size_t matrix::columns(void) const 201 { 202 if (!proxy_m_) 203 return 0; 204 return proxy_m_>size2; 205 } 206 207 208 gsl_matrix* matrix::create_gsl_matrix_copy(void) const 209 { 210 gsl_matrix* m = gsl_matrix_alloc(rows(),columns()); 211 if (!m) 212 throw utility::GSL_error("matrix::create_gsl_matrix_copy failed to allocate memory"); 213 if (gsl_matrix_memcpy(m,proxy_m_)) 214 throw utility::GSL_error("matrix::create_gsl_matrix_copy dimension mismatch"); 215 return m; 215 proxy_m_=m_=NULL; 216 216 } 217 217 … … 271 271 void matrix::resize(size_t r, size_t c, double init_value) 272 272 { 273 if (view_) 274 delete view_; 275 else if (view_const_) 276 delete view_const_; 277 else if (m_) 278 gsl_matrix_free(m_); 279 proxy_m_ = m_ = gsl_matrix_alloc(r,c); 280 if (!m_) 281 throw utility::GSL_error("matrix::matrix failed to allocate memory"); 282 set_all(init_value); 283 284 // no need to delete blas_result_ if the number of rows fit, it 285 // may be useful later. 286 if (blas_result_ && (blas_result_>size1!=rows())) { 287 gsl_matrix_free(blas_result_); 288 blas_result_=NULL; 289 } 290 } 273 delete_allocated_memory(); 274 275 proxy_m_ = m_ = gsl_matrix_alloc(r,c); 276 if (!m_) 277 throw utility::GSL_error("matrix::matrix failed to allocate memory"); 278 set_all(init_value); 279 280 // no need to delete blas_result_ if the number of rows fit, it 281 // may be useful later. 282 if (blas_result_ && (blas_result_>size1!=rows())) { 283 gsl_matrix_free(blas_result_); 284 blas_result_=NULL; 285 } 286 } 291 287 292 288
Note: See TracChangeset
for help on using the changeset viewer.