Changeset d1ea29c in tol


Ignore:
Timestamp:
Aug 26, 2009, 9:59:24 AM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
dd43df6
Parents:
ce31518
Message:

New optional argument Text subType for built-in function Zeros
Non limited number of arguments for built-in functions And, Or, Eq, NE, LE, GE, LT, GT, Min, Max
New built-in function IfVMat

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/vmatrix_type/vmatgra.cpp

    rce31518 rd1ea29c  
    658658//--------------------------------------------------------------------
    659659DeclareContensClass(BVMat, BVMatTemporary, BVMatZero);
    660 DefExtOpr(1, BVMatZero, "Zeros", 1, 2,
    661   "Real Real",
    662   "(Real nrow [, Real ncol=nrow])",
     660DefExtOpr(1, BVMatZero, "Zeros", 1, 3,
     661  "Real Real Text",
     662  "(Real nrow [, Real ncol=nrow, Text subType=\"Cholmod.R.Sparse\"])",
    663663  I2("Creates a matrix with all elements equal to zero.\n"
    664664     "Allowed subtypes are :\n",
    … …  
    673673  int nrow = (int)Real(Arg(1));
    674674  int ncol = nrow;
    675   if(Arg(2)) { ncol=(int)Real(Arg(2)); }
    676   contens_.Zeros(nrow,ncol,BVMat::ESC_chlmRsparse);
     675  BVMat::ECode code = BVMat::ESC_chlmRsparse;
     676  if(Arg(2)) { ncol = (int)Real(Arg(2)); }
     677  if(Arg(3)) { code = BVMat::FindCodeName(Text(Arg(3))); }
     678  contens_.Zeros(nrow,ncol,code);
    677679  assert(contens_.Check());
    678680}
    … …  
    15931595//--------------------------------------------------------------------
    15941596DeclareContensClass(BVMat, BVMatTemporary, BVMatAnd);
    1595 DefIntOpr(1, BVMatAnd, "And", 2, 2,
    1596   "(VMatrix A, VMatrix B)",
     1597DefIntOpr(1, BVMatAnd, "And", 2, 0,
     1598  "(VMatrix A, VMatrix B [, VMatrix C, ...])",
    15971599  I2("Returns the logical AND of arguments.",
    15981600     "Devuelve el AND (Y) lógico de los argumentos"),                             
    … …  
    16031605{
    16041606  BVMat::And(VMat(Arg(1)),VMat(Arg(2)),contens_);
     1607  int n = 3;
     1608  while(Arg(n))
     1609  {
     1610    BVMat aux = contens_;
     1611    BVMat::And(aux,VMat(Arg(n)),contens_);
     1612    n++;
     1613  }
    16051614  assert(contens_.Check());
    16061615}
    … …  
    16081617//--------------------------------------------------------------------
    16091618DeclareContensClass(BVMat, BVMatTemporary, BVMatOr);
    1610 DefIntOpr(1, BVMatOr, "Or", 2, 2,
    1611   "(VMatrix A, VMatrix B)",
     1619DefIntOpr(1, BVMatOr, "Or", 2, 0,
     1620  "(VMatrix A, VMatrix B [, VMatrix C, ...])",
    16121621  I2("Returns the logical OR of arguments.",
    16131622     "Devuelve el OR (O) lógico de los argumentos"),                             
    … …  
    16181627{
    16191628  BVMat::Or(VMat(Arg(1)),VMat(Arg(2)),contens_);
     1629  int n = 3;
     1630  while(Arg(n))
     1631  {
     1632    BVMat aux = contens_;
     1633    BVMat::Or(aux,VMat(Arg(n)),contens_);
     1634    n++;
     1635  }
    16201636  assert(contens_.Check());
    16211637}
    … …  
    16231639//--------------------------------------------------------------------
    16241640DeclareContensClass(BVMat, BVMatTemporary, BVMatEq);
    1625 DefIntOpr(1, BVMatEq, "Eq", 2, 2,
    1626   "(VMatrix A, VMatrix B)",
     1641DefIntOpr(1, BVMatEq, "Eq", 2, 0,
     1642  "(VMatrix A, VMatrix B [, VMatrix C, ...])",
    16271643  I2("Returns TRUE just in each cell where ",
    16281644     "Devuelve CIERTO sólo para las celdas para las que ")+
    … …  
    16341650{
    16351651  BVMat::EQ(VMat(Arg(1)),VMat(Arg(2)),contens_);
     1652  int n = 3;
     1653  while(Arg(n))
     1654  {
     1655    BVMat aux1 = contens_;
     1656    BVMat::EQ(VMat(Arg(n-1)),VMat(Arg(n)),contens_);
     1657    BVMat aux2 = contens_;
     1658    BVMat::And(aux1,aux2,contens_);
     1659    n++;
     1660  }
    16361661  assert(contens_.Check());
    16371662}
    … …  
    16391664//--------------------------------------------------------------------
    16401665DeclareContensClass(BVMat, BVMatTemporary, BVMatNE);
    1641 DefIntOpr(1, BVMatNE, "NE", 2, 2,
    1642   "(VMatrix A, VMatrix B)",
     1666DefIntOpr(1, BVMatNE, "NE", 2, 0,
     1667  "(VMatrix A, VMatrix B [, VMatrix C, ...])",
    16431668  I2("Returns TRUE just in each cell where ",
    16441669     "Devuelve CIERTO sólo para las celdas para las que ")+
    … …  
    16501675{
    16511676  BVMat::NE(VMat(Arg(1)),VMat(Arg(2)),contens_);
     1677  int n = 3;
     1678  while(Arg(n))
     1679  {
     1680    BVMat aux1 = contens_;
     1681    BVMat::NE(VMat(Arg(n-1)),VMat(Arg(n)),contens_);
     1682    BVMat aux2 = contens_;
     1683    BVMat::And(aux1,aux2,contens_);
     1684    n++;
     1685  }
    16521686  assert(contens_.Check());
    16531687}
    … …  
    16551689//--------------------------------------------------------------------
    16561690DeclareContensClass(BVMat, BVMatTemporary, BVMatLE);
    1657 DefIntOpr(1, BVMatLE, "LE", 2, 2,
    1658   "(VMatrix A, VMatrix B)",
     1691DefIntOpr(1, BVMatLE, "LE", 2, 0,
     1692  "(VMatrix A, VMatrix B [, VMatrix C, ...])",
    16591693  I2("Returns TRUE just in each cell where ",
    16601694     "Devuelve CIERTO sólo para las celdas para las que ")+
    … …  
    16661700{
    16671701  BVMat::LE(VMat(Arg(1)),VMat(Arg(2)),contens_);
     1702  int n = 3;
     1703  while(Arg(n))
     1704  {
     1705    BVMat aux1 = contens_;
     1706    BVMat::LE(VMat(Arg(n-1)),VMat(Arg(n)),contens_);
     1707    BVMat aux2 = contens_;
     1708    BVMat::And(aux1,aux2,contens_);
     1709    n++;
     1710  }
    16681711  assert(contens_.Check());
    16691712}
    … …  
    16711714//--------------------------------------------------------------------
    16721715DeclareContensClass(BVMat, BVMatTemporary, BVMatLT);
    1673 DefIntOpr(1, BVMatLT, "LT", 2, 2,
    1674   "(VMatrix A, VMatrix B)",
     1716DefIntOpr(1, BVMatLT, "LT", 2, 0,
     1717  "(VMatrix A, VMatrix B [, VMatrix C, ...])",
    16751718  I2("Returns TRUE just in each cell where ",
    16761719     "Devuelve CIERTO sólo para las celdas para las que ")+
    … …  
    16821725{
    16831726  BVMat::LT(VMat(Arg(1)),VMat(Arg(2)),contens_);
     1727  int n = 3;
     1728  while(Arg(n))
     1729  {
     1730    BVMat aux1 = contens_;
     1731    BVMat::LT(VMat(Arg(n-1)),VMat(Arg(n)),contens_);
     1732    BVMat aux2 = contens_;
     1733    BVMat::And(aux1,aux2,contens_);
     1734    n++;
     1735  }
    16841736  assert(contens_.Check());
    16851737}
    … …  
    16871739//--------------------------------------------------------------------
    16881740DeclareContensClass(BVMat, BVMatTemporary, BVMatGE);
    1689 DefIntOpr(1, BVMatGE, "GE", 2, 2,
    1690   "(VMatrix A, VMatrix B)",
     1741DefIntOpr(1, BVMatGE, "GE", 2, 0,
     1742  "(VMatrix A, VMatrix B [, VMatrix C, ...])",
    16911743  I2("Returns TRUE just in each cell where ",
    16921744     "Devuelve CIERTO sólo para las celdas para las que ")+
    … …  
    16981750{
    16991751  BVMat::GE(VMat(Arg(1)),VMat(Arg(2)),contens_);
     1752  int n = 3;
     1753  while(Arg(n))
     1754  {
     1755    BVMat aux1 = contens_;
     1756    BVMat::GE(VMat(Arg(n-1)),VMat(Arg(n)),contens_);
     1757    BVMat aux2 = contens_;
     1758    BVMat::And(aux1,aux2,contens_);
     1759    n++;
     1760  }
    17001761  assert(contens_.Check());
    17011762}
    … …  
    17031764//--------------------------------------------------------------------
    17041765DeclareContensClass(BVMat, BVMatTemporary, BVMatGT);
    1705 DefIntOpr(1, BVMatGT, "GT", 2, 2,
    1706   "(VMatrix A, VMatrix B)",
     1766DefIntOpr(1, BVMatGT, "GT", 2, 0,
     1767  "(VMatrix A, VMatrix B [, VMatrix C, ...])",
    17071768  I2("Returns TRUE just in each cell where ",
    17081769     "Devuelve CIERTO sólo para las celdas para las que ")+
    … …  
    17141775{
    17151776  BVMat::GT(VMat(Arg(1)),VMat(Arg(2)),contens_);
     1777  int n = 3;
     1778  while(Arg(n))
     1779  {
     1780    BVMat aux1 = contens_;
     1781    BVMat::GT(VMat(Arg(n-1)),VMat(Arg(n)),contens_);
     1782    BVMat aux2 = contens_;
     1783    BVMat::And(aux1,aux2,contens_);
     1784    n++;
     1785  }
    17161786  assert(contens_.Check());
    17171787}
    … …  
    17191789//--------------------------------------------------------------------
    17201790DeclareContensClass(BVMat, BVMatTemporary, BVMatMin);
    1721 DefIntOpr(1, BVMatMin, "Min", 2, 2,
    1722   "(VMatrix A, VMatrix B)",
     1791DefIntOpr(1, BVMatMin, "Min", 2, 0,
     1792  "(VMatrix A, VMatrix B [, VMatrix C, ...])",
    17231793  I2("Returns in each cell the minimum value of arguments ",
    17241794     "Devuelve en cada celda el mínimo de los argumentos ")+
    … …  
    17301800{
    17311801  BVMat::Min(VMat(Arg(1)),VMat(Arg(2)),contens_);
     1802  int n = 3;
     1803  while(Arg(n))
     1804  {
     1805    BVMat aux = contens_;
     1806    BVMat::Min(aux,VMat(Arg(n)),contens_);
     1807    n++;
     1808  }
    17321809  assert(contens_.Check());
    17331810}
    … …  
    17351812//--------------------------------------------------------------------
    17361813DeclareContensClass(BVMat, BVMatTemporary, BVMatMax);
    1737 DefIntOpr(1, BVMatMax, "Max", 2, 2,
    1738   "(VMatrix A, VMatrix B)",
     1814DefIntOpr(1, BVMatMax, "Max", 2, 0,
     1815  "(VMatrix A, VMatrix B [, VMatrix C, ...])",
    17391816  I2("Returns in each cell the maximum value of arguments ",
    17401817     "Devuelve en cada celda el máximo de los argumentos ")+
    … …  
    17461823{
    17471824  BVMat::Max(VMat(Arg(1)),VMat(Arg(2)),contens_);
    1748   assert(contens_.Check());
     1825  int n = 3;
     1826  while(Arg(n))
     1827  {
     1828    BVMat aux = contens_;
     1829    BVMat::Max(aux,VMat(Arg(n)),contens_);
     1830    n++;
     1831  }
     1832  assert(contens_.Check());
     1833}
     1834
     1835//--------------------------------------------------------------------
     1836DeclareContensClass(BVMat, BVMatTemporary, BVMatIfVMatReal);
     1837DefExtOpr(1, BVMatIfVMatReal, "IfVMat", 3, 3, "VMatrix VMatrix VMatrix",
     1838  "(VMatrix condition, VMatrix A, VMatrix B)",
     1839  I2("For each cell (i,j) if condition(i,j) is true returns the value of A(i,j), else B(i,j).",
     1840     "Para cada celda (i,j) si condition(i,j) es cierto devuelve A(i,j) y si no B(i,j)."),
     1841    BOperClassify::MatrixAlgebra_);
     1842//--------------------------------------------------------------------
     1843void BVMatIfVMatReal::CalcContens()
     1844//--------------------------------------------------------------------
     1845{
     1846  BVMat& C = VMat(Arg(1));
     1847  BVMat& A = VMat(Arg(2));
     1848  BVMat& B = VMat(Arg(3));
     1849  BVMat::If(C,A,B,contens_);
    17491850}
    17501851
    … …  
    17961897  if(Arg(2)) { S=Text(Arg(2)); }
    17971898  if(Arg(3)) { force=Real(Arg(3))!=0.0; }
    1798 
    1799   BVMat::CholeskiFactor(VMat(Arg(1)),contens_,S,true,force);
     1899  if(Arg(1)->LocalName()=="X")
     1900    printf("");
     1901  BVMat& X = VMat(Arg(1));
     1902  BVMat::CholeskiFactor(X,contens_,S,true,force);
    18001903  assert(contens_.Check());
    18011904}
Note: See TracChangeset for help on using the changeset viewer.