Changeset 53456bc in tol


Ignore:
Timestamp:
May 17, 2015, 9:07:07 AM (11 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
1e43dec
Parents:
2789f1d
Message:

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

Location:
tol/btol
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/matrix_type/matgra.cpp

    r2789f1d r53456bc  
    46624662  {
    46634663    contens_(i,0)=i+1;
    4664     contens_(i,1)=acf(i);
     4664    contens_(i,1)=pacf(i);
    46654665    contens_(i,2)=sigma;
    46664666  }
  • tol/btol/real_type/datgrav.cpp

    r2789f1d r53456bc  
    809809  if(g->Grammar()==GraText())
    810810  {
     811    const BText& gt = Text(g);
    811812    graOpt.AllocBuffer(1);
    812     graOpt[0] = FindGrammar(Text(g));
     813    graOpt[0] = FindGrammar(gt);
    813814  }
    814815  else if(g->Grammar()==GraSet())
    … …  
    889890}
    890891
     892
     893//--------------------------------------------------------------------
     894  bool DestroyIdNeeded(BSyntaxObject*& result, int nObj0)
     895//--------------------------------------------------------------------
     896{
     897  if(result)
     898  {
     899    return(false);
     900  }
     901  {
     902    int nObj1 = AliveObjects();
     903    if(nObj1>nObj0)
     904    {
     905      DESTROY(result);
     906      result = NULL;
     907      return(true);
     908    }
     909    else
     910    {
     911      return(false);
     912    }
     913  }
     914};
     915
    891916//--------------------------------------------------------------------
    892917  DeclareContensClass(BDat, BDatTemporary, BDatObjectExist);
    … …  
    901926{
    902927  BSyntaxObject* g = Arg(1);
    903   const BText&  name = Text(Arg(2));
     928  const BText& name = Text(Arg(2));
    904929  BArray<BSyntaxObject*> graOpt;
    905930  int i;
    … …  
    909934  contens_ = false;
    910935  if(!GetGrammarOptions(g, graOpt)) { return; }
     936  int nObj0 = AliveObjects();
    911937  for(i=0; !result && (i<graOpt.Size()); i++)
    912938  {
    … …  
    930956      if(result && Set(result).Struct()!=found)
    931957      {
    932         result = NULL;
     958        DestroyIdNeeded(result, nObj0);
    933959      }
    934960    }
    … …  
    942968        if(!nb.IsInstanceOf((BClass*)found))
    943969        { 
    944           result = NULL;
     970          DestroyIdNeeded(result, nObj0);
    945971        } 
    946972      }
    … …  
    948974  }
    949975  contens_ = result!=NULL; 
     976  DestroyIdNeeded(result, nObj0);
    950977}
    951978
    … …  
    21552182{
    21562183  contens_ = Dat(Arg(1));
    2157   BSys::SleepMilliSeconds((BInt)contens_.Value()*1000);
     2184  BSys::SleepMilliSeconds((int)(contens_.Value()*1000.0));
    21582185}
    21592186
  • tol/btol/vmatrix_type/tol_bvmat.h

    r2789f1d r53456bc  
    742742  BVMat CholeskiSolve(const BVMat& B, const BText& sys)const;
    743743  BVMat CholeskiInv  ()const;
     744  int CholeskiUpdate (const BVMat& C_, bool upDown);
     745  int CholeskiAddRow (const BVMat& R_, int rowPos);
     746  int CholeskiDelRow (const BVMat& R_, int rowPos);
    744747
    745748  static int CholeskiFactor(const BVMat& X, BVMat& L,
    … …  
    755758  static int CholeskiInv   (const BVMat& X, BVMat& Xi);
    756759  static int CholeskiMinRes(const BVMat& X, const BVMat& b, BVMat& a);
     760  static int CholeskiUpdate (const BVMat& L, const BVMat& C_, bool upDown);
     761  static int CholeskiAddRow (const BVMat& L, const BVMat& R_, int rowPos);
     762  static int CholeskiDelRow (const BVMat& L, const BVMat& R_, int rowPos);
    757763 
    758764private:
  • tol/btol/vmatrix_type/vmat_chol.cpp

    r2789f1d r53456bc  
    7676  res = cholmod_factorize(X.s_.chlmRsparse_,L.s_.chlmRfactor_,common_);
    7777  TRACE_CHOLMOD_ALLOCATE("Cholmod.R.Factor",X.s_.chlmRsparse_)
    78   isNotPosDef = (L.s_.chlmRfactor_->minor<L.s_.chlmRfactor_->n);
     78 
     79  isNotPosDef = (common_->status == CHOLMOD_NOT_POSDEF)||
     80                (L.s_.chlmRfactor_->minor<L.s_.chlmRfactor_->n);
    7981  cholmod_change_factor
    8082  (
    … …  
    739741 
    740742
    741 
    742743////////////////////////////////////////////////////////////////////////////////
    743744  BVMat BVMat::CholeskiSolve(const BVMat& B, ECholSolSys sys) const
    … …  
    810811  return(0);
    811812};
     813
     814
     815////////////////////////////////////////////////////////////////////////////////
     816  int BVMat::CholeskiUpdate (const BVMat& L, const BVMat& C_, bool upDown)
     817////////////////////////////////////////////////////////////////////////////////
     818{
     819  if(!L .CheckDefined("CholeskiUpdate")) { return(-1); }
     820  if(!C_.CheckDefined("CholeskiUpdate")) { return(-1); }
     821  int result = 0;
     822  BVMat *C__=NULL;
     823  if(L.code_==ESC_chlmRfactor)
     824  {
     825    convertIfNeeded_all2cRs(C_,C__,"CholeskiUpdate");
     826  }
     827  else
     828  {
     829    err_invalid_subtype("CholeskiUpdate",L);
     830    result = -2;
     831    return(result);
     832  }
     833  BVMat &C = *C__;
     834  cholmod_factor* l = L.s_.chlmRfactor_;
     835  cholmod_sparse* c = cholmod_submatrix(
     836    C.s_.chlmRsparse_, (int*)l->Perm, l->n, NULL, -1, 1, 1, common_);
     837  result = cholmod_updown(upDown, c, l, common_);
     838  bool isNotPosDef = (common_->status == CHOLMOD_NOT_POSDEF)||
     839                (L.s_.chlmRfactor_->minor<L.s_.chlmRfactor_->n);
     840  if(isNotPosDef)
     841  {
     842    result == -1;
     843    err_cannot_apply("CholeskiUpdate","",L);
     844  }
     845  else
     846  {
     847    CholmodFree_sparse(&c,common_);
     848   
     849  }
     850  if(C__!=&C_) { delete C__; }
     851  return(result);
     852}
     853   
     854
     855////////////////////////////////////////////////////////////////////////////////
     856  int BVMat::CholeskiUpdate (const BVMat& C_, bool upDown)
     857//Matrix algebra operator
     858////////////////////////////////////////////////////////////////////////////////
     859{
     860  return(CholeskiUpdate(*this,C_,upDown));
     861};
     862
     863
     864////////////////////////////////////////////////////////////////////////////////
     865  int BVMat::CholeskiAddRow (const BVMat& L, const BVMat& R_, int rowPos)
     866////////////////////////////////////////////////////////////////////////////////
     867{
     868  if(!L .CheckDefined("CholeskiAddRow")) { return(-1); }
     869  if(!R_.CheckDefined("CholeskiAddRow")) { return(-1); }
     870  int result = 0;
     871  BVMat *R__=NULL;
     872  if(L.code_==ESC_chlmRfactor)
     873  {
     874    convertIfNeeded_all2cRs(R_,R__,"CholeskiAddRow");
     875  }
     876  else
     877  {
     878    err_invalid_subtype("CholeskiAddRow",L);
     879    result = -2;
     880    return(result);
     881  }
     882  BVMat &R = *R__;
     883  result = cholmod_rowadd(rowPos, R.s_.chlmRsparse_, L.s_.chlmRfactor_, common_);
     884  if(R__!=&R_) { delete R__; }
     885  return(result);
     886}
     887   
     888
     889////////////////////////////////////////////////////////////////////////////////
     890  int BVMat::CholeskiAddRow (const BVMat& R_, int rowPos)
     891//Matrix algebra operator
     892////////////////////////////////////////////////////////////////////////////////
     893{
     894  return(CholeskiAddRow(*this,R_,rowPos));
     895};
     896
     897////////////////////////////////////////////////////////////////////////////////
     898  int BVMat::CholeskiDelRow (const BVMat& L, const BVMat& R_, int rowPos)
     899////////////////////////////////////////////////////////////////////////////////
     900{
     901  if(!L .CheckDefined("CholeskiDelRow")) { return(-1); }
     902  if(!R_.CheckDefined("CholeskiDelRow")) { return(-1); }
     903  int result = 0;
     904  BVMat *R__=NULL;
     905  if(L.code_==ESC_chlmRfactor)
     906  {
     907    convertIfNeeded_all2cRs(R_,R__,"CholeskiDelRow");
     908  }
     909  else
     910  {
     911    err_invalid_subtype("CholeskiDelRow",L);
     912    result = -2;
     913    return(result);
     914  }
     915  BVMat &R = *R__;
     916  result = cholmod_rowdel(rowPos, R.s_.chlmRsparse_, L.s_.chlmRfactor_, common_);
     917  if(R__!=&R_) { delete R__; }
     918  return(result);
     919}
     920   
     921
     922////////////////////////////////////////////////////////////////////////////////
     923  int BVMat::CholeskiDelRow (const BVMat& R_, int rowPos)
     924//Matrix algebra operator
     925////////////////////////////////////////////////////////////////////////////////
     926{
     927  return(CholeskiDelRow(*this,R_,rowPos));
     928};
     929
     930
     931
  • tol/btol/vmatrix_type/vmatgra.cpp

    r2789f1d r53456bc  
    23332333
    23342334
     2335//--------------------------------------------------------------------
     2336DeclareContensClass(BDat, BDatTemporary, BDatCholeskiUpdate);
     2337DefExtOpr(1, BDatCholeskiUpdate, "CholeskiUpdate", 3, 3,
     2338  "VMatrix VMatrix Real",
     2339  "(VMatrix L, VMatrix C, Real upDown)",
     2340  "Updates a LL' Cholesky factorization computing LL'+CC' if upDown "
     2341  "is true or LL'-CC' in other case.",
     2342  BOperClassify::MatrixAlgebra_);
     2343//--------------------------------------------------------------------
     2344void BDatCholeskiUpdate::CalcContens()
     2345//--------------------------------------------------------------------
     2346{
     2347  contens_ = BVMat::CholeskiUpdate(VMat(Arg(1)), VMat(Arg(2)), (bool)Real(Arg(3)));
     2348}
     2349
     2350
     2351//--------------------------------------------------------------------
     2352DeclareContensClass(BDat, BDatTemporary, BDatCholeskiAddRow);
     2353DefExtOpr(1, BDatCholeskiAddRow, "CholeskiAddRow", 3, 3,
     2354  "VMatrix VMatrix Real",
     2355  "(VMatrix factor, VMatrix rowData, Real rowPos)",
     2356  "Adds a new row to a Cholesky factorization.",
     2357  BOperClassify::MatrixAlgebra_);
     2358//--------------------------------------------------------------------
     2359void BDatCholeskiAddRow::CalcContens()
     2360//--------------------------------------------------------------------
     2361{
     2362  contens_ = BVMat::CholeskiAddRow(VMat(Arg(1)), VMat(Arg(2)), (int)Real(Arg(3)));
     2363}
     2364
     2365//--------------------------------------------------------------------
     2366DeclareContensClass(BDat, BDatTemporary, BDatCholeskiDelRow);
     2367DefExtOpr(1, BDatCholeskiDelRow, "CholeskiDelRow", 3, 3,
     2368  "VMatrix VMatrix Real",
     2369  "(VMatrix factor, VMatrix rowData, Real rowPos)",
     2370  "Deletes a row to a Cholesky factorization.",
     2371  BOperClassify::MatrixAlgebra_);
     2372//--------------------------------------------------------------------
     2373void BDatCholeskiDelRow::CalcContens()
     2374//--------------------------------------------------------------------
     2375{
     2376  contens_ = BVMat::CholeskiDelRow(VMat(Arg(1)), VMat(Arg(2)), (int)Real(Arg(3)));
     2377}
     2378
    23352379/*------------------------------------------------------------------------------
    23362380  vmat_stats.cpp: Statistics methods
Note: See TracChangeset for help on using the changeset viewer.