Changeset ab4c03e in tol


Ignore:
Timestamp:
Nov 25, 2009, 8:02:47 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
c7623c38
Parents:
752eb20
Message:

Fixes #787

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1730 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tol/btol/vmatrix_type
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/vmatrix_type/tol_bvmat.h

    r752eb20 rab4c03e  
    266266//Copy operator
    267267  const BVMat& operator = (const BVMat& v); 
     268  ECode Code() const { return(code_); }
    268269  int  Check       () const;
    269270  void Pack        ();
     271  void Pack        (double sparsity);
    270272  void Copy        (const BVMat& v);
    271273  void BlasRDense  (int nrow, int ncol);
    … …  
    335337                               const BVMat& a);
    336338private:
     339  static size_t bytes_blasRdense(int nzmax);
     340  static size_t bytes_chlmRsparse(int nzmax, int ncol, bool packed);
    337341  size_t bytes_blasRdense  () const;
    338342  size_t bytes_chlmRsparse () const;
  • tol/btol/vmatrix_type/vmat.cpp

    r752eb20 rab4c03e  
    288288////////////////////////////////////////////////////////////////////////////////
    289289{
     290  int nz,ncol,nrow,dense_size,sparse_size;
     291  BVMat aux;
    290292  switch(code_) {
    291293  case(ESC_blasRdense  ) :
    292294  {
     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    }
    293305    break;
    294306  }
    295307  case(ESC_chlmRsparse ) :
    296308  {
    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;
    304344  }
    305345  case(ESC_chlmRfactor ) :
    … …  
    307347    cholmod_pack_factor(s_.chlmRfactor_,common_);
    308348    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;
    318349  }
    319350  default:
    320351    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()");
    322423    assert(1); }
    323424};
    … …  
    10751176  int c = Columns();
    10761177  double cells = StoredCells();
     1178  double nz = NonNullCells();
    10771179  double denseCells = (double)r*(double)c;
    1078   double cellPercent = round(10000.0*cells/denseCells)/100.0;
    10791180  double bytes = Bytes();
    10801181  double denseBytes = sizeof(BVMat)+sizeof(cholmod_dense)+
    10811182                     (denseCells)*sizeof(double);
     1183  double nzPercent = round(10000.0*nz/denseCells)/100.0;
     1184  double cellPercent = round(10000.0*cells/denseCells)/100.0;
    10821185  double bytesPercent = round(10000.0*bytes/denseBytes)/100.0;
    10831186  aux +=BText("\n")+
     1187        " Non zero cells "+nz+"/("+r+"x"+c+")="+nzPercent+"%\n"+
    10841188        " Stored cells "+cells+"/("+r+"x"+c+")="+cellPercent+"%\n"+
    10851189        " Stored bytes "+bytes+"/"+denseBytes+"="+bytesPercent+"%\n";
  • tol/btol/vmatrix_type/vmat_convert.cpp

    r752eb20 rab4c03e  
    198198  B_ = (BVMat*)&B;
    199199  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))
    201205  {
    202206    warn_convert2cRs(fName,B);
    … …  
    254258  B_ = (BVMat*)&B;
    255259  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))
    257265  {
    258266    warn_convert2bRd(fName,B);
  • tol/btol/vmatrix_type/vmat_io.cpp

    r752eb20 rab4c03e  
    381381
    382382////////////////////////////////////////////////////////////////////////////////
     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////////////////////////////////////////////////////////////////////////////////
    383401  size_t BVMat::bytes_blasRdense() const
    384402//Exporting method
    … …  
    386404{
    387405  cholmod_dense& a = *s_.blasRdense_;
    388   return(sizeof(cholmod_dense)+ a.nzmax*sizeof(double));
     406  return(bytes_blasRdense(a.nzmax));
    389407};
    390408
    … …  
    395413{
    396414  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));
    400416};
    401417
  • tol/btol/vmatrix_type/vmatgra.cpp

    r752eb20 rab4c03e  
    468468//--------------------------------------------------------------------
    469469DeclareContensClass(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."),
     470DefExtOpr(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."),
    477494BOperClassify::MatrixAlgebra_);
    478495//--------------------------------------------------------------------
    … …  
    480497//--------------------------------------------------------------------
    481498{
    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  }
    484509  assert(contens_.Check());
    485510}
Note: See TracChangeset for help on using the changeset viewer.