Changeset a49be3d in tol


Ignore:
Timestamp:
Jan 9, 2012, 9:44:49 AM (15 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
6ff8ce3
Parents:
5fbda58
Message:

Refs #1387
New function EvalSetNth to speed up cycles calling C++ TOL functions with more than one argument

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/set_type/setgra.cpp

    r5fbda58 ra49be3d  
    18911891DeclareNoLazzyClass(BSet, BSetTemporary, BSetEvalSet);
    18921892DefExtOpr(1, BSetEvalSet, "EvalSet", 2, 2, "Set Code",
    1893           I2("(Set set, Code doit)", "(Set cto, Code hacer)"),
     1893          "(Set set, Code doit)",
    18941894          I2("Returns the set of the successive evaluations of a "
    18951895             "function, taking as argument each element of a set.",
    … …  
    19061906  BSet&              set    = Set (Arg(1));
    19071907  BCode&             code   = Code(Arg(2));
    1908   BGrammar*          gra    = code.Grammar();
     1908  BGrammar*        gra    = code.Grammar();
    19091909  BList*             aux    = NIL;
    19101910  BList*             result = NIL;
    … …  
    19351935          }
    19361936          while(n<=set.Card());
     1937  }
     1938  contens_.RobElement(result);
     1939}
     1940
     1941//--------------------------------------------------------------------
     1942DeclareNoLazzyClass(BSet, BSetTemporary, BSetEvalSetNth);
     1943DefExtOpr(1, BSetEvalSetNth, "EvalSetNth", 4, 4, "Real Set Set Code",
     1944    "(Real nth, Set args, Set set, Code doit)",
     1945    I2("Returns the set of the successive evaluations of a "
     1946       "function, taking as the k-th argument each element of a set."
     1947       "The rest of arguments are fixed.",
     1948       "Devuelve el conjunto de las evaluaciones sucesivas de "
     1949       "una función, tomando como k-ésimo argumento cada elemento de "
     1950       "un conjunto. El resto de argumentos permanecen fijos."),
     1951    BOperClassify::SetAlgebra_);
     1952
     1953//--------------------------------------------------------------------
     1954void BSetEvalSetNth::CalcContens()
     1955//--------------------------------------------------------------------
     1956{
     1957  BSyntaxObject* objCode, *arg;
     1958  int n = (int)Real (Arg(1));
     1959  BSet& args = Set (Arg(2));
     1960  BSet& set = Set (Arg(3));
     1961  BCode& code = Code(Arg(4));
     1962  BGrammar* gra = code.Grammar();
     1963  BList* aux1 = NIL;
     1964  BList* aux2 = NIL;
     1965  BList* aux3 = NIL;
     1966  BList* result = NIL;
     1967  int i;
     1968  int k = 1;
     1969  int m = args.Card();
     1970  int K = set.Card();
     1971  bool okArg = code.Operator()!=NULL;
     1972  int minArg = 0;
     1973  int maxArg = 0;
     1974  if(okArg)
     1975  {
     1976    minArg = code.Operator()->MinArg();
     1977    maxArg = code.Operator()->MaxArg();
     1978    okArg = (minArg<=m) && (m<=maxArg);
     1979  }
     1980  if(!okArg)
     1981  {
     1982    Error(I2("Wrong argument function in EvalSetNth function calling."
     1983             "It must admit "+m+" arguments.",
     1984             "Función argumento errónea en llamada a la función EvalSetNth."
     1985             "Ésta debe admitir "+m+" argumentos."));
     1986    return;
     1987  }
     1988  if(K)
     1989  {
     1990    do
     1991    {
     1992      aux1 = NIL;
     1993      aux2 = NIL;
     1994      for(i=1;i<=m;i++)
     1995      {
     1996        if(i==n) { arg = set[k]; }
     1997        else     { arg = args[i]; }
     1998        LstFastAppend(aux1, aux2, arg);
     1999      }
     2000      objCode = code.Evaluator(aux1);
     2001      if(!objCode)
     2002      {
     2003        Error(I2("EvalSetNth failed.","Fallo en EvalSetNth."));
     2004        DESTROY(result);
     2005        return;
     2006      }
     2007      LstFastAppend(result, aux3, objCode);
     2008      k++;
     2009    }
     2010    while(k<=K);
    19372011  }
    19382012  contens_.RobElement(result);
Note: See TracChangeset for help on using the changeset viewer.