Changeset 774 for trunk/yat/utility/matrix.cc
 Timestamp:
 Mar 1, 2007, 10:52:48 PM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/utility/matrix.cc
r773 r774 213 213 214 214 215 bool matrix::isnull(void) const216 {217 return gsl_matrix_isnull(m_);218 }219 220 221 215 bool matrix::isview(void) const 222 216 { 223 217 return view_; 224 }225 226 227 double matrix::max(void) const228 {229 return gsl_matrix_max(m_);230 }231 232 233 double matrix::min(void) const234 {235 return gsl_matrix_min(m_);236 }237 238 239 void matrix::minmax_index(std::pair<size_t,size_t>& min,240 std::pair<size_t,size_t>& max) const241 {242 gsl_matrix_minmax_index(m_, &min.first, &min.second, &max.first,243 &max.second);244 }245 246 247 bool matrix::nan(matrix &m) const248 {249 m=matrix(rows(),columns(),1.0);250 bool nan=false;251 for (size_t i=0; i<rows(); i++)252 for (size_t j=0; j<columns(); j++)253 if (std::isnan(operator()(i,j))) {254 m(i,j)=0;255 nan=true;256 }257 return nan;258 218 } 259 219 … … 302 262 if (status) 303 263 throw utility::GSL_error(std::string("matrix::set_row",status)); 304 }305 306 307 void matrix::swap(matrix& other)308 {309 int status=gsl_matrix_swap(m_, other.m_);310 if (status)311 throw utility::GSL_error(std::string("matrix::swap",status));312 264 } 313 265 … … 455 407 456 408 409 bool isnull(const matrix& m) 410 { 411 return gsl_matrix_isnull(m.gsl_matrix_p()); 412 } 413 414 415 double max(const matrix& m) 416 { 417 return gsl_matrix_max(m.gsl_matrix_p()); 418 } 419 420 421 double min(const matrix& m) 422 { 423 return gsl_matrix_min(m.gsl_matrix_p()); 424 } 425 426 427 void minmax_index(const matrix& m, 428 std::pair<size_t,size_t>& min, std::pair<size_t,size_t>& max) 429 { 430 gsl_matrix_minmax_index(m.gsl_matrix_p(), &min.first, &min.second, 431 &max.first, &max.second); 432 } 433 434 435 bool nan(const matrix& templat, matrix& flag) 436 { 437 size_t rows=templat.rows(); 438 size_t columns=templat.columns(); 439 if (rows!=flag.rows() && columns!=flag.columns()) 440 flag=matrix(rows,columns,1.0); 441 else 442 flag.set_all(1.0); 443 bool nan=false; 444 for (size_t i=0; i<rows; i++) 445 for (size_t j=0; j<columns; j++) 446 if (std::isnan(templat(i,j))) { 447 flag(i,j)=0; 448 nan=true; 449 } 450 return nan; 451 } 452 453 454 void swap(matrix& a, matrix& b) 455 { 456 int status=gsl_matrix_swap(a.gsl_matrix_p(), b.gsl_matrix_p()); 457 if (status) 458 throw utility::GSL_error(std::string("matrix::swap",status)); 459 } 460 461 457 462 std::ostream& operator<<(std::ostream& s, const matrix& m) 458 463 {
Note: See TracChangeset
for help on using the changeset viewer.