Changeset ab4c03e in tol
- Timestamp:
- Nov 25, 2009, 8:02:47 PM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- c7623c38
- Parents:
- 752eb20
- Location:
- tol/btol/vmatrix_type
- Files:
-
- 5 edited
-
tol_bvmat.h (modified) (2 diffs)
-
vmat.cpp (modified) (3 diffs)
-
vmat_convert.cpp (modified) (2 diffs)
-
vmat_io.cpp (modified) (3 diffs)
-
vmatgra.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol/btol/vmatrix_type/tol_bvmat.h
r752eb20 rab4c03e 266 266 //Copy operator 267 267 const BVMat& operator = (const BVMat& v); 268 ECode Code() const { return(code_); } 268 269 int Check () const; 269 270 void Pack (); 271 void Pack (double sparsity); 270 272 void Copy (const BVMat& v); 271 273 void BlasRDense (int nrow, int ncol); … … 335 337 const BVMat& a); 336 338 private: 339 static size_t bytes_blasRdense(int nzmax); 340 static size_t bytes_chlmRsparse(int nzmax, int ncol, bool packed); 337 341 size_t bytes_blasRdense () const; 338 342 size_t bytes_chlmRsparse () const; -
tol/btol/vmatrix_type/vmat.cpp
r752eb20 rab4c03e 288 288 //////////////////////////////////////////////////////////////////////////////// 289 289 { 290 int nz,ncol,nrow,dense_size,sparse_size; 291 BVMat aux; 290 292 switch(code_) { 291 293 case(ESC_blasRdense ) : 292 294 { 295 nz = NonNullCells(0); 296 ncol=Columns(); 297 nrow=Rows(); 298 dense_size = bytes_blasRdense(nrow*ncol); 299 sparse_size = bytes_chlmRsparse(nz, ncol, true); 300 if(sparse_size<dense_size) 301 { 302 aux.Convert(*this,ESC_chlmRsparse); 303 *this = aux; 304 } 293 305 break; 294 306 } 295 307 case(ESC_chlmRsparse ) : 296 308 { 297 int nnz = NonNullCells(0); 298 if(s_.chlmRsparse_->nzmax > nnz) 299 { 300 cholmod_drop(0,s_.chlmRsparse_, common_); 301 } 302 cholmod_sort(s_.chlmRsparse_, common_); 303 break; 309 cholmod_drop(0,s_.chlmRsparse_, common_); 310 nz = NonNullCells(0); 311 ncol=Columns(); 312 nrow=Rows(); 313 dense_size = bytes_blasRdense(nrow*ncol); 314 sparse_size = bytes_chlmRsparse(nz, ncol, true); 315 if(sparse_size>dense_size) 316 { 317 aux.Convert(*this,ESC_blasRdense); 318 *this = aux; 319 } 320 else 321 { 322 cholmod_sort(s_.chlmRsparse_, common_); 323 } 324 break; 325 } 326 case(ESC_chlmRtriplet) : 327 { 328 Drop(0); 329 nz = NonNullCells(0); 330 ncol=Columns(); 331 nrow=Rows(); 332 dense_size = bytes_blasRdense(nrow*ncol); 333 sparse_size = bytes_chlmRsparse(nz, ncol, true); 334 if(sparse_size<dense_size) 335 { 336 aux.Convert(*this,ESC_chlmRsparse); 337 } 338 else 339 { 340 aux.Convert(*this,ESC_blasRdense); 341 } 342 *this = aux; 343 break; 304 344 } 305 345 case(ESC_chlmRfactor ) : … … 307 347 cholmod_pack_factor(s_.chlmRfactor_,common_); 308 348 break; 309 }310 case(ESC_chlmRtriplet) :311 {312 int nnz = NonNullCells(0);313 if(s_.chlmRtriplet_->nzmax > nnz)314 {315 Drop(0);316 }317 break;318 349 } 319 350 default: 320 351 Error(I2("FATAL ERROR in", 321 "ERROR FATAL en")+" BVMat::Pack(const BVMat& v)"); 352 "ERROR FATAL en")+" BVMat::Pack()"); 353 assert(1); } 354 }; 355 356 //////////////////////////////////////////////////////////////////////////////// 357 void BVMat::Pack(double sparsity) 358 //Importing method 359 //////////////////////////////////////////////////////////////////////////////// 360 { 361 if(sparsity==BDat::Nan()) { Pack(); return; } 362 int nz,ncol,nrow; 363 double sparseRatio; 364 BVMat aux; 365 switch(code_) { 366 case(ESC_blasRdense ) : 367 { 368 nz = NonNullCells(0); 369 ncol=Columns(); 370 nrow=Rows(); 371 sparseRatio = 1.0 - double(nz)/double(nrow*ncol); 372 if(sparseRatio>sparsity) 373 { 374 aux.Convert(*this,ESC_chlmRsparse); 375 *this = aux; 376 } 377 break; 378 } 379 case(ESC_chlmRsparse ) : 380 { 381 cholmod_drop(0,s_.chlmRsparse_, common_); 382 nz = NonNullCells(0); 383 ncol=Columns(); 384 nrow=Rows(); 385 sparseRatio = 1.0 - double(nz)/double(nrow*ncol); 386 if(sparseRatio<sparsity) 387 { 388 aux.Convert(*this,ESC_blasRdense); 389 *this = aux; 390 } 391 else 392 { 393 cholmod_sort(s_.chlmRsparse_, common_); 394 } 395 break; 396 } 397 case(ESC_chlmRtriplet) : 398 { 399 Drop(0); 400 nz = NonNullCells(0); 401 ncol=Columns(); 402 nrow=Rows(); 403 sparseRatio = 1.0 - double(nz)/double(nrow*ncol); 404 if(sparseRatio>=sparsity) 405 { 406 aux.Convert(*this,ESC_chlmRsparse); 407 } 408 else 409 { 410 aux.Convert(*this,ESC_blasRdense); 411 } 412 *this = aux; 413 break; 414 } 415 case(ESC_chlmRfactor ) : 416 { 417 cholmod_pack_factor(s_.chlmRfactor_,common_); 418 break; 419 } 420 default: 421 Error(I2("FATAL ERROR in", 422 "ERROR FATAL en")+" BVMat::Pack()"); 322 423 assert(1); } 323 424 }; … … 1075 1176 int c = Columns(); 1076 1177 double cells = StoredCells(); 1178 double nz = NonNullCells(); 1077 1179 double denseCells = (double)r*(double)c; 1078 double cellPercent = round(10000.0*cells/denseCells)/100.0;1079 1180 double bytes = Bytes(); 1080 1181 double denseBytes = sizeof(BVMat)+sizeof(cholmod_dense)+ 1081 1182 (denseCells)*sizeof(double); 1183 double nzPercent = round(10000.0*nz/denseCells)/100.0; 1184 double cellPercent = round(10000.0*cells/denseCells)/100.0; 1082 1185 double bytesPercent = round(10000.0*bytes/denseBytes)/100.0; 1083 1186 aux +=BText("\n")+ 1187 " Non zero cells "+nz+"/("+r+"x"+c+")="+nzPercent+"%\n"+ 1084 1188 " Stored cells "+cells+"/("+r+"x"+c+")="+cellPercent+"%\n"+ 1085 1189 " Stored bytes "+bytes+"/"+denseBytes+"="+bytesPercent+"%\n"; -
tol/btol/vmatrix_type/vmat_convert.cpp
r752eb20 rab4c03e 198 198 B_ = (BVMat*)&B; 199 199 int result = 0; 200 if((A.code_==ESC_chlmRsparse) && (B.code_!=ESC_chlmRsparse)) 200 if((A.code_==ESC_chlmRsparse) && (B.code_==ESC_chlmRsparse)) 201 { 202 result = -1; 203 } 204 else if((A.code_==ESC_chlmRsparse) && (B.code_!=ESC_chlmRsparse)) 201 205 { 202 206 warn_convert2cRs(fName,B); … … 254 258 B_ = (BVMat*)&B; 255 259 int result = 0; 256 if((A.code_==ESC_blasRdense) && (B.code_!=ESC_blasRdense)) 260 if((A.code_==ESC_blasRdense) && (B.code_==ESC_blasRdense)) 261 { 262 result = -1; 263 } 264 else if((A.code_==ESC_blasRdense) && (B.code_!=ESC_blasRdense)) 257 265 { 258 266 warn_convert2bRd(fName,B); -
tol/btol/vmatrix_type/vmat_io.cpp
r752eb20 rab4c03e 381 381 382 382 //////////////////////////////////////////////////////////////////////////////// 383 size_t BVMat::bytes_blasRdense(int nzmax) 384 //Exporting method 385 //////////////////////////////////////////////////////////////////////////////// 386 { 387 return(sizeof(cholmod_dense)+ nzmax*sizeof(double)); 388 }; 389 390 //////////////////////////////////////////////////////////////////////////////// 391 size_t BVMat::bytes_chlmRsparse(int nzmax, int ncol, bool packed) 392 //Exporting method 393 //////////////////////////////////////////////////////////////////////////////// 394 { 395 return(sizeof(cholmod_sparse)+ 396 (ncol+1+((packed)?0:ncol))*sizeof(int)+ 397 nzmax*(sizeof(int) + sizeof(double)) ); 398 }; 399 400 //////////////////////////////////////////////////////////////////////////////// 383 401 size_t BVMat::bytes_blasRdense() const 384 402 //Exporting method … … 386 404 { 387 405 cholmod_dense& a = *s_.blasRdense_; 388 return( sizeof(cholmod_dense)+ a.nzmax*sizeof(double));406 return(bytes_blasRdense(a.nzmax)); 389 407 }; 390 408 … … 395 413 { 396 414 cholmod_sparse& a = *s_.chlmRsparse_; 397 return(sizeof(cholmod_sparse)+ 398 (a.ncol+1+((a.packed)?0:a.ncol))*sizeof(int)+ 399 a.nzmax*(sizeof(int) + sizeof(double)) ); 415 return(bytes_chlmRsparse(a.nzmax,a.ncol,a.packed!=0)); 400 416 }; 401 417 -
tol/btol/vmatrix_type/vmatgra.cpp
r752eb20 rab4c03e 468 468 //-------------------------------------------------------------------- 469 469 DeclareContensClass(BVMat, BVMatTemporary, BVMatPack); 470 DefExtOpr(1, BVMatPack, "Pack", 1, 1, 471 "VMatrix", 472 "(VMatrix data)", 473 I2("Packs an sparse matrix to be stored in the minimum posible size." 474 "It has no effect over non sparse matrices.", 475 "Empaqueta una matriz sparse para que ocupe el mínimo espacio posible." 476 "No tiene ningún efecto sobre matrices no sparse."), 470 DefExtOpr(1, BVMatPack, "Pack", 1, 2, 471 "VMatrix Real", 472 "(VMatrix data [, Real sparsity=?])", 473 I2("Converts a virtual matrix to be stored in the optimal way:" 474 " * Converts a dense matrix to sparse if it has enough zero cells, ie if \n" 475 " 1-VNonNullCells(M)/(VRows(M)*VColumns(M)) >= sparsity\n" 476 " * Converts an sparse matrix to dense if it hasn't enough zero cells, ie if \n" 477 " 1-VNonNullCells(M)/(VRows(M)*VColumns(M)) <= sparsity\n" 478 " Sparse matrices will be packed internally in other case.\n" 479 " * Converts triplet matrices to dense or sparse, following the same explained " 480 "rules\n" 481 "If argument 'sparsity' is unknown then it will be calculated to ensure the " 482 "minimum size of returned matrix." 483 , 484 "Convierte una matriz virtual para ser almacenados en la forma óptima:\n" 485 " * Convierte una matriz densa a escasa si tiene bastantes celdas cero, es decir, si\n" 486 "1-VNonNullCells (M) / (VRows (M) * VColumns (M))> = sparsity\n" 487 "* Convierte una matriz dispersa a densa si no hay bastantes celdas cero, es decir, si\n" 488 "1-VNonNullCells (M) / (VRows (M) * VColumns (M)) <= sparsity\n" 489 "Si no es así, las matrices sparse serán empaquetadas al máximo internamente.\n" 490 "* Convierte las matrices triplet a denso o sparse según estas mismas reglas\n" 491 "* Las matrices factor serán empaquetadas al máximo internamente\n" 492 "Si el argumento 'sparsity' es desconocido entonces será calculado " 493 "para garantizar el mínimo tamaño posible de la matriz devuelta."), 477 494 BOperClassify::MatrixAlgebra_); 478 495 //-------------------------------------------------------------------- … … 480 497 //-------------------------------------------------------------------- 481 498 { 482 contens_.Copy(VMat(Arg(1))); 483 contens_.Pack(); 499 contens_ = VMat(Arg(1)); 500 if(Arg(2)) 501 { 502 double sparsity = Real(Arg(2)); 503 contens_.Pack(sparsity); 504 } 505 else 506 { 507 contens_.Pack(); 508 } 484 509 assert(contens_.Check()); 485 510 }
Note: See TracChangeset
for help on using the changeset viewer.
