/[escript]/branches/clazy/escriptcore/src/DataLazy.cpp
ViewVC logotype

Diff of /branches/clazy/escriptcore/src/DataLazy.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6056 by jfenwick, Thu Mar 10 04:29:53 2016 UTC revision 6083 by jfenwick, Tue Mar 22 03:30:18 2016 UTC
# Line 19  Line 19 
19  #include "DataTypes.h"  #include "DataTypes.h"
20  #include "EscriptParams.h"  #include "EscriptParams.h"
21  #include "FunctionSpace.h"  #include "FunctionSpace.h"
 #include "UnaryFuncs.h"    // for escript::fsign  
22  #include "Utils.h"  #include "Utils.h"
23  #include "DataMaths.h"  #include "DataMaths.h"
24    
# Line 991  DataLazy::collapse() const Line 990  DataLazy::collapse() const
990    m_op=IDENTITY;    m_op=IDENTITY;
991  }  }
992    
   
   
   
   
   
 #define PROC_OP(TYPE,X)                               \  
         for (int j=0;j<onumsteps;++j)\  
         {\  
           for (int i=0;i<numsteps;++i,resultp+=resultStep) \  
           { \  
 LAZYDEBUG(cout << "[left,right]=[" << lroffset << "," << rroffset << "]" << endl;)\  
 LAZYDEBUG(cout << "{left,right}={" << (*left)[lroffset] << "," << (*right)[rroffset] << "}\n";)\  
              tensor_binary_operation< TYPE >(chunksize, &((*left)[lroffset]), &((*right)[rroffset]), resultp, X); \  
 LAZYDEBUG(cout << " result=      " << resultp[0] << endl;) \  
              lroffset+=leftstep; \  
              rroffset+=rightstep; \  
           }\  
           lroffset+=oleftstep;\  
           rroffset+=orightstep;\  
         }  
   
   
993  // The result will be stored in m_samples  // The result will be stored in m_samples
994  // The return value is a pointer to the DataVector, offset is the offset within the return value  // The return value is a pointer to the DataVector, offset is the offset within the return value
995  const DataTypes::RealVectorType*  const DataTypes::RealVectorType*
# Line 1083  DataLazy::resolveNodeUnary(int tid, int Line 1060  DataLazy::resolveNodeUnary(int tid, int
1060    const double* left=&((*leftres)[roffset]);    const double* left=&((*leftres)[roffset]);
1061    roffset=m_samplesize*tid;    roffset=m_samplesize*tid;
1062    double* result=&(m_samples[roffset]);    double* result=&(m_samples[roffset]);
1063      escript::ESFunction operation=SINF;
1064    switch (m_op)    switch (m_op)
1065    {    {
1066      case SIN:        case SIN:
1067          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::sin);      operation=SINF;
1068          break;      break;
1069      case COS:      case COS:
1070          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::cos);          operation=COSF;
1071          break;      break;
1072      case TAN:      case TAN:
1073          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::tan);          operation=TANF;
1074          break;      break;
1075      case ASIN:      case ASIN:
1076          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::asin);          operation=ASINF;
1077          break;      break;
1078      case ACOS:      case ACOS:
1079          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::acos);          operation=ACOSF;
1080          break;      break;
1081      case ATAN:      case ATAN:
1082          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::atan);          operation=ATANF;
1083          break;      break;
1084      case SINH:      case SINH:
1085          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::sinh);          operation=SINHF;
1086          break;      break;
1087      case COSH:      case COSH:
1088          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::cosh);          operation=COSHF;
1089          break;      break;
1090      case TANH:      case TANH:
1091          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::tanh);          operation=TANHF;
1092          break;      break;
1093      case ERF:      case ERF:
1094  #if defined (_WIN32) && !defined(__INTEL_COMPILER)          operation=ERFF;
1095          throw DataException("Error - Data:: erf function is not supported on _WIN32 platforms.");      break;
 #else  
         tensor_unary_operation(m_samplesize, left, result, ::erf);  
         break;  
 #endif  
1096     case ASINH:     case ASINH:
1097  #if defined (_WIN32) && !defined(__INTEL_COMPILER)          operation=ASINHF;
1098          tensor_unary_operation(m_samplesize, left, result, escript::asinh_substitute);      break;
 #else  
         tensor_unary_operation(m_samplesize, left, result, ::asinh);  
 #endif    
         break;  
1099     case ACOSH:     case ACOSH:
1100  #if defined (_WIN32) && !defined(__INTEL_COMPILER)          operation=ACOSHF;
1101          tensor_unary_operation(m_samplesize, left, result, escript::acosh_substitute);      break;
 #else  
         tensor_unary_operation(m_samplesize, left, result, ::acosh);  
 #endif    
         break;  
1102     case ATANH:     case ATANH:
1103  #if defined (_WIN32) && !defined(__INTEL_COMPILER)          operation=ATANHF;
1104          tensor_unary_operation(m_samplesize, left, result, escript::atanh_substitute);      break;
 #else  
         tensor_unary_operation(m_samplesize, left, result, ::atanh);  
 #endif    
         break;  
1105      case LOG10:      case LOG10:
1106          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::log10);          operation=LOG10F;
1107          break;      break;
1108      case LOG:      case LOG:
1109          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::log);          operation=LOGF;
1110          break;      break;
1111      case SIGN:      case SIGN:
1112          tensor_unary_operation(m_samplesize, left, result, escript::fsign);          operation=SIGNF;
1113          break;      break;
1114      case ABS:      case ABS:
1115          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::fabs);          operation=ABSF;
1116          break;      break;
1117      case NEG:      case NEG:
1118          tensor_unary_operation(m_samplesize, left, result, negate<double>());          operation=NEGF;
1119          break;      break;
1120      case POS:      case POS:
1121          // it doesn't mean anything for delayed.          // it doesn't mean anything for delayed.
1122          // it will just trigger a deep copy of the lazy object          // it will just trigger a deep copy of the lazy object
1123          throw DataException("Programmer error - POS not supported for lazy data.");          throw DataException("Programmer error - POS not supported for lazy data.");
1124          break;          break;
1125      case EXP:      case EXP:
1126          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::exp);          operation=EXPF;
1127          break;      break;
1128      case SQRT:      case SQRT:
1129          tensor_unary_operation<double (*)(double)>(m_samplesize, left, result, ::sqrt);          operation=SQRTF;
1130          break;      break;
1131      case RECIP:      case RECIP:
1132          tensor_unary_operation(m_samplesize, left, result, bind1st(divides<double>(),1.));          operation=INVF;
1133          break;      break;
1134      case GZ:      case GZ:
1135          tensor_unary_operation(m_samplesize, left, result, bind2nd(greater<double>(),0.0));          operation=GTZEROF;
1136          break;      break;
1137      case LZ:      case LZ:
1138          tensor_unary_operation(m_samplesize, left, result, bind2nd(less<double>(),0.0));          operation=LTZEROF;
1139          break;      break;
1140      case GEZ:      case GEZ:
1141          tensor_unary_operation(m_samplesize, left, result, bind2nd(greater_equal<double>(),0.0));          operation=GEZEROF;
1142          break;      break;
1143      case LEZ:      case LEZ:
1144          tensor_unary_operation(m_samplesize, left, result, bind2nd(less_equal<double>(),0.0));          operation=LEZEROF;
1145          break;      break;
1146  // There are actually G_UNARY_P but I don't see a compelling reason to treat them differently  // There are actually G_UNARY_P but I don't see a compelling reason to treat them differently
1147      case NEZ:      case NEZ:
1148          tensor_unary_operation(m_samplesize, left, result, bind2nd(AbsGT(),m_tol));          operation=NEQZEROF;
1149          break;      break;
1150      case EZ:      case EZ:
1151          tensor_unary_operation(m_samplesize, left, result, bind2nd(AbsLTE(),m_tol));          operation=EQZEROF;
1152          break;      break;
   
1153      default:      default:
1154          throw DataException("Programmer error - resolveUnary can not resolve operator "+opToString(m_op)+".");          throw DataException("Programmer error - resolveUnary can not resolve operator "+opToString(m_op)+".");
1155    }    }
1156      tensor_unary_array_operation(m_samplesize,
1157                                 left,
1158                                 result,
1159                                 operation,
1160                                 m_tol);  
1161    return &(m_samples);    return &(m_samples);
1162  }  }
1163    
# Line 1225  DataLazy::resolveNodeReduction(int tid, Line 1191  DataLazy::resolveNodeReduction(int tid,
1191            for (unsigned int z=0;z<ndpps;++z)            for (unsigned int z=0;z<ndpps;++z)
1192            {            {
1193              FMin op;              FMin op;
1194              *result=DataMaths::reductionOp(*leftres, m_left->getShape(), loffset, op, numeric_limits<double>::max());              *result=escript::reductionOpVector(*leftres, m_left->getShape(), loffset, op, numeric_limits<double>::max());
1195              loffset+=psize;              loffset+=psize;
1196              result++;              result++;
1197            }            }
# Line 1236  DataLazy::resolveNodeReduction(int tid, Line 1202  DataLazy::resolveNodeReduction(int tid,
1202            for (unsigned int z=0;z<ndpps;++z)            for (unsigned int z=0;z<ndpps;++z)
1203            {            {
1204            FMax op;            FMax op;
1205            *result=DataMaths::reductionOp(*leftres, m_left->getShape(), loffset, op, numeric_limits<double>::max()*-1);            *result=escript::reductionOpVector(*leftres, m_left->getShape(), loffset, op, numeric_limits<double>::max()*-1);
1206            loffset+=psize;            loffset+=psize;
1207            result++;            result++;
1208            }            }
# Line 1274  DataLazy::resolveNodeNP1OUT(int tid, int Line 1240  DataLazy::resolveNodeNP1OUT(int tid, int
1240      case SYM:      case SYM:
1241          for (loop=0;loop<numsteps;++loop)          for (loop=0;loop<numsteps;++loop)
1242          {          {
1243              DataMaths::symmetric(*leftres,m_left->getShape(),subroffset, m_samples, getShape(), offset);              escript::symmetric(*leftres,m_left->getShape(),subroffset, m_samples, getShape(), offset);
1244              subroffset+=step;              subroffset+=step;
1245              offset+=step;              offset+=step;
1246          }          }
# Line 1282  DataLazy::resolveNodeNP1OUT(int tid, int Line 1248  DataLazy::resolveNodeNP1OUT(int tid, int
1248      case NSYM:      case NSYM:
1249          for (loop=0;loop<numsteps;++loop)          for (loop=0;loop<numsteps;++loop)
1250          {          {
1251              DataMaths::nonsymmetric(*leftres,m_left->getShape(),subroffset, m_samples, getShape(), offset);              escript::nonsymmetric(*leftres,m_left->getShape(),subroffset, m_samples, getShape(), offset);
1252              subroffset+=step;              subroffset+=step;
1253              offset+=step;              offset+=step;
1254          }          }
# Line 1321  DataLazy::resolveNodeNP1OUT_P(int tid, i Line 1287  DataLazy::resolveNodeNP1OUT_P(int tid, i
1287      case TRACE:      case TRACE:
1288          for (loop=0;loop<numsteps;++loop)          for (loop=0;loop<numsteps;++loop)
1289          {          {
1290              DataMaths::trace(*leftres,m_left->getShape(),subroffset, m_samples ,getShape(),offset,m_axis_offset);              escript::trace(*leftres,m_left->getShape(),subroffset, m_samples ,getShape(),offset,m_axis_offset);
1291              subroffset+=instep;              subroffset+=instep;
1292              offset+=outstep;              offset+=outstep;
1293          }          }
# Line 1329  DataLazy::resolveNodeNP1OUT_P(int tid, i Line 1295  DataLazy::resolveNodeNP1OUT_P(int tid, i
1295      case TRANS:      case TRANS:
1296          for (loop=0;loop<numsteps;++loop)          for (loop=0;loop<numsteps;++loop)
1297          {          {
1298              DataMaths::transpose(*leftres,m_left->getShape(),subroffset, m_samples, getShape(),offset,m_axis_offset);              escript::transpose(*leftres,m_left->getShape(),subroffset, m_samples, getShape(),offset,m_axis_offset);
1299              subroffset+=instep;              subroffset+=instep;
1300              offset+=outstep;              offset+=outstep;
1301          }          }
# Line 1366  DataLazy::resolveNodeNP1OUT_2P(int tid, Line 1332  DataLazy::resolveNodeNP1OUT_2P(int tid,
1332      case SWAP:      case SWAP:
1333          for (loop=0;loop<numsteps;++loop)          for (loop=0;loop<numsteps;++loop)
1334          {          {
1335              DataMaths::swapaxes(*leftres,m_left->getShape(),subroffset, m_samples, getShape(),offset, m_axis_offset, m_transpose);              escript::swapaxes(*leftres,m_left->getShape(),subroffset, m_samples, getShape(),offset, m_axis_offset, m_transpose);
1336              subroffset+=instep;              subroffset+=instep;
1337              offset+=outstep;              offset+=outstep;
1338          }          }
# Line 1554  LAZYDEBUG(cout << "Right res["<< rroffse Line 1520  LAZYDEBUG(cout << "Right res["<< rroffse
1520    {    {
1521      case ADD:      case ADD:
1522          //PROC_OP(NO_ARG,plus<double>());          //PROC_OP(NO_ARG,plus<double>());
1523        DataMaths::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,        escript::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,
1524               &(*left)[0],               &(*left)[0],
1525               &(*right)[0],               &(*right)[0],
1526               chunksize,               chunksize,
# Line 1570  LAZYDEBUG(cout << "Right res["<< rroffse Line 1536  LAZYDEBUG(cout << "Right res["<< rroffse
1536               escript::ESFunction::PLUSF);                 escript::ESFunction::PLUSF);  
1537          break;          break;
1538      case SUB:      case SUB:
1539          PROC_OP(NO_ARG,minus<double>());        escript::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,
1540                 &(*left)[0],
1541                 &(*right)[0],
1542                 chunksize,
1543                 onumsteps,
1544                 numsteps,
1545                 resultStep,
1546                 leftstep,
1547                 rightstep,
1548                 oleftstep,
1549                 orightstep,
1550                 lroffset,
1551                 rroffset,
1552                 escript::ESFunction::MINUSF);        
1553            //PROC_OP(NO_ARG,minus<double>());
1554          break;          break;
1555      case MUL:      case MUL:
1556          PROC_OP(NO_ARG,multiplies<double>());          //PROC_OP(NO_ARG,multiplies<double>());
1557          escript::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,
1558                 &(*left)[0],
1559                 &(*right)[0],
1560                 chunksize,
1561                 onumsteps,
1562                 numsteps,
1563                 resultStep,
1564                 leftstep,
1565                 rightstep,
1566                 oleftstep,
1567                 orightstep,
1568                 lroffset,
1569                 rroffset,
1570                 escript::ESFunction::MULTIPLIESF);      
1571          break;          break;
1572      case DIV:      case DIV:
1573          PROC_OP(NO_ARG,divides<double>());          //PROC_OP(NO_ARG,divides<double>());
1574          escript::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,
1575                 &(*left)[0],
1576                 &(*right)[0],
1577                 chunksize,
1578                 onumsteps,
1579                 numsteps,
1580                 resultStep,
1581                 leftstep,
1582                 rightstep,
1583                 oleftstep,
1584                 orightstep,
1585                 lroffset,
1586                 rroffset,
1587                 escript::ESFunction::DIVIDESF);          
1588          break;          break;
1589      case POW:      case POW:
1590         PROC_OP(double (double,double),::pow);         //PROC_OP(double (double,double),::pow);
1591          escript::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,
1592                 &(*left)[0],
1593                 &(*right)[0],
1594                 chunksize,
1595                 onumsteps,
1596                 numsteps,
1597                 resultStep,
1598                 leftstep,
1599                 rightstep,
1600                 oleftstep,
1601                 orightstep,
1602                 lroffset,
1603                 rroffset,
1604                 escript::ESFunction::POWF);          
1605          break;          break;
1606      default:      default:
1607          throw DataException("Programmer error - resolveBinary can not resolve operator "+opToString(m_op)+".");          throw DataException("Programmer error - resolveBinary can not resolve operator "+opToString(m_op)+".");

Legend:
Removed from v.6056  
changed lines
  Added in v.6083

  ViewVC Help
Powered by ViewVC 1.1.26