Changeset c126b51 in tol


Ignore:
Timestamp:
Jul 7, 2009, 1:38:30 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
2974cff
Parents:
6a081c4
Message:

ForMat is now a built-in faster function

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

File:
1 edited

Legend:

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

    r6a081c4 rc126b51  
    526526     "BINARY: "+
    527527     I2("Standard TOL binary format",
    528         "Formato estándar binario de TOL")+"\n"+
     528        "Formato estándar binario de TOL")+
    529529     "WGRIB2TXT: "+
    530530     I2("Result of command", "Resultado del comando")+
    … …  
    552552  {
    553553    FILE* file = fopen(fileName.String(),"r");
     554    if(!file)
     555    {
     556      Error(BText("[MatReadFile] Cannot open file ")+fileName); 
     557      return;
     558    }
    554559    int i, j, rows, cols;
    555560    fscanf(file, "%ld %ld", &cols, &rows);
    … …  
    560565      for(j=0; j<cols; j++, x++)
    561566      {
    562         fscanf(file, "%lf",x);
     567        if(!fscanf(file, "%lf", x))
     568        {
     569          Error(BText("[MatReadFile] Cannot read cell")+
     570            " of file "+fileName); 
     571          contens_.Alloc(0,0);
     572        }
    563573      }
    564574    }
    565575  }
    566576}
    567 
    568 
    569577//--------------------------------------------------------------------
    570578DeclareContensClass(BSet, BSetTemporary, BMatReadDimensions);
    … …  
    65806588}
    65816589
    6582 #ifdef __USE_DEPRECATED_LINALG_METHOD__
    6583 //--------------------------------------------------------------------
    6584 DeclareContensClass(BSet, BSetTemporary, BMatJordanIterative);
    6585 DefExtOpr(1, BMatJordanIterative, "JordanIterative", 1, 1, "Matrix",
    6586   "(Matrix M)",
    6587   I2("Makes the Jordan decomposition of a symmetric matrix by iterative "
    6588      "method.\n",
    6589      "Hace la descomposicion de Jordan de una matriz simetrica por el metodo "
    6590      "iterativo.\n"
    6591      "Devuelve un conjunto con dos matrices en el que la primera es la "
    6592      "matriz de vectores propios y la segunda es la matriz diagonal de "
    6593      "autovalores.\n"
    6594      "Para que el metodo sea valido es necesario que no hayan valores "
    6595      "propios multiples."),
    6596     BOperClassify::MatrixAlgebra_);
    6597 //--------------------------------------------------------------------
    6598 void BMatJordanIterative::CalcContens()
    6599 //--------------------------------------------------------------------
    6600 {
    6601     BMatrix<BDat>& M = Mat(Arg(1));
    6602     BMatrix<BDat>   S=M;
    6603     BMatrix<BDat> B;
    6604     BDiagMatrix<BDat> L;
    6605     JordanIterative(S,B,L);
    6606     BUserMat* UB = BContensMat::New("U",B,"Eigen vectors");
    6607     BUserMat* UL = BContensMat::New("D",L,"Eigen values");
    6608     contens_.RobElement(Cons(UB,NCons(UL)));
    6609 }
    6610 
    6611 
    6612 //--------------------------------------------------------------------
    6613 DeclareContensClass(BMat, BMatTemporary, BMatGaussSeidelSolve);
    6614 DefIntOpr(1, BMatGaussSeidelSolve, "GaussSeidelSolve", 2, 2,
    6615   "(Matrix M, Matrix B)",
    6616   I2("Applies the reduction method of Gauss-Seidel to solve the linear system M*X=B "
    6617      "where M is symmetric positive definite.",
    6618      "Aplica el metodo de relajacion de Gauss-Seidel para resolver el sistema "
    6619      "lineal M*X=B donde M es simetrica y definida positiva."),
    6620     BOperClassify::MatrixAlgebra_);
    6621 //--------------------------------------------------------------------
    6622 void BMatGaussSeidelSolve::CalcContens()
    6623 //--------------------------------------------------------------------
    6624 {
    6625     BMat& M = Mat(Arg(1));
    6626     BMat& B = Mat(Arg(2));
    6627     BDat err;
    6628     contens_ = GaussSeidelSolve(M, B, B);
    6629 }
    6630 
    6631 
    6632 
    6633 //--------------------------------------------------------------------
    6634 DeclareContensClass(BMat, BMatTemporary, BMatConjugateGradientSolve);
    6635 DefIntOpr(1, BMatConjugateGradientSolve, "ConjugateGradientSolve", 2, 2,
    6636   "(Matrix M, Matrix B)",
    6637   I2("Applies the Conjugate Gradient method to solve the linear system M*X=B "
    6638      "where M is symmetric positive definite.",
    6639      "Aplica el metodo del Gradiente Conjugado para resolver el sistema "
    6640      "lineal M*X=B donde M es simetrica y definida positiva."),
    6641     BOperClassify::MatrixAlgebra_);
    6642 //--------------------------------------------------------------------
    6643 void BMatConjugateGradientSolve::CalcContens()
    6644 //--------------------------------------------------------------------
    6645 {
    6646     BMat& M = Mat(Arg(1));
    6647     BMat& B = Mat(Arg(2));
    6648     BDat err;
    6649     contens_ = ConjugateGradientSolve(M, B, B);
    6650 }
    6651 
    6652 //--------------------------------------------------------------------
    6653 DeclareContensClass(BMat, BMatTemporary, BMatBiconjugateGradientSolve);
    6654 DefIntOpr(1, BMatBiconjugateGradientSolve, "BiconjugateGradientSolve", 2, 2,
    6655   "(Matrix M, Matrix B)",
    6656   I2("Applies the Biconjugate Gradient method to solve the linear system M*X=B "
    6657      "where M is square regular matrix.",
    6658      "Aplica el metodo del Gradiente Biconjugado para resolver el sistema "
    6659      "lineal M*X=B donde M es una matriz cuadrada regular."),
    6660     BOperClassify::MatrixAlgebra_);
    6661 //--------------------------------------------------------------------
    6662 void BMatBiconjugateGradientSolve::CalcContens()
    6663 //--------------------------------------------------------------------
    6664 {
    6665     BMat& M = Mat(Arg(1));
    6666     BMat& B = Mat(Arg(2));
    6667     BDat err;
    6668     contens_ = BiconjugateGradientSolve(M, B, B);
    6669 }
    6670 
    6671 #endif //__USE_DEPRECATED_LINALG_METHOD__       
     6590//--------------------------------------------------------------------
     6591DeclareContensClass(BMat, BMatTemporary, BMatForMat);
     6592DefExtOpr(1, BMatForMat, "ForMat", 3, 3, "Real Real Code",
     6593  "(Real rows, Real columns, Code fun)",
     6594  I2("Returns a matrix with the given dimensions and the values generated "
     6595  "by the indicator function, which takes two real arguments corresponding "
     6596  "to the coordinates (i, j) and returns the element (i, j) of the matrix.\n"
     6597  "Example : \n"
     6598  ,
     6599  "Devuelve una matriz con las dimensiones dadas y los valores generados "
     6600  "por la funcion indicada, la cual toma dos argumentos reales "
     6601  "correspondientes a las coordenadas (i,j) y devuelve el elemento (i,j) "
     6602  "de la matriz.\n"
     6603  "Ejemplo : \n")+
     6604  "Matrix ForMat(2, 3, Real (Real n, Real m){n*m});",
     6605  BOperClassify::MatrixAlgebra_);
     6606//--------------------------------------------------------------------
     6607void BMatForMat::CalcContens()
     6608//--------------------------------------------------------------------
     6609{
     6610  int i,j;
     6611  int rows = (int)Real(Arg(1));
     6612  int cols = (int)Real(Arg(2));
     6613  BCode&  code = Code(Arg(3));
     6614  BStandardOperator* opr = (BStandardOperator*)code.Operator();
     6615  if(!opr)
     6616  {
     6617    Error(I2("<fun> argument of function ForMat has no operator",
     6618             "El argumento <fun> de la función ForMat no tiene operador"));
     6619    return;
     6620  }
     6621  if((opr->Grammar()!= GraReal()) ||
     6622     (opr->NumArg()!=2)||
     6623     (opr->GrammarForArg(1)!=GraReal())||
     6624     (opr->GrammarForArg(2)!=GraReal()))
     6625  {
     6626    Error(I2("<fun> argument of function ForMat ",
     6627             "El argumento <fun> de la función ForMat ")+"\n"+
     6628          opr->Grammar()->Name()+" "+code.Name()+opr->Arguments()+"\n"+
     6629          I2("should be declared as ",
     6630             "debería estar declarada como ")+"\n"+
     6631          "Real "+code.Name()+"(Real i, Real j) \n");
     6632    return;
     6633  }
     6634
     6635  contens_.Alloc(rows, cols);
     6636  BSyntaxObject* ev;
     6637  for(i=0; i<rows; i++)
     6638  {
     6639    for(j=0; j<cols; j++)
     6640    {
     6641      BContensDat* r = new BContensDat("",i+1);
     6642      BContensDat* c = new BContensDat("",j+1);
     6643      BList* args = Cons(r, NCons(c));
     6644      ev = opr->Evaluator(args);
     6645      if(ev)
     6646      {
     6647        contens_(i,j) = Dat(ev);
     6648        DESTROY(ev);
     6649      }
     6650    }
     6651  }
     6652   
     6653}
     6654
Note: See TracChangeset for help on using the changeset viewer.