/[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 2092 by jfenwick, Tue Nov 25 04:18:17 2008 UTC revision 2147 by jfenwick, Wed Dec 10 04:41:26 2008 UTC
# Line 73  The convention that I use, is that the r Line 73  The convention that I use, is that the r
73  For expressions which evaluate to Constant or Tagged, there is a different evaluation method.  For expressions which evaluate to Constant or Tagged, there is a different evaluation method.
74  The collapse method invokes the (non-lazy) operations on the Data class to evaluate the expression.  The collapse method invokes the (non-lazy) operations on the Data class to evaluate the expression.
75    
76  To add a new operator you need to do the following (plus anything I might have forgotten):  To add a new operator you need to do the following (plus anything I might have forgotten - adding a new group for example):
77  1) Add to the ES_optype.  1) Add to the ES_optype.
78  2) determine what opgroup your operation belongs to (X)  2) determine what opgroup your operation belongs to (X)
79  3) add a string for the op to the end of ES_opstrings  3) add a string for the op to the end of ES_opstrings
# Line 99  enum ES_opgroup Line 99  enum ES_opgroup
99     G_IDENTITY,     G_IDENTITY,
100     G_BINARY,        // pointwise operations with two arguments     G_BINARY,        // pointwise operations with two arguments
101     G_UNARY,     // pointwise operations with one argument     G_UNARY,     // pointwise operations with one argument
102       G_UNARY_P,       // pointwise operations with one argument, requiring a parameter
103     G_NP1OUT,        // non-pointwise op with one output     G_NP1OUT,        // non-pointwise op with one output
104     G_NP1OUT_P,      // non-pointwise op with one output requiring a parameter     G_NP1OUT_P,      // non-pointwise op with one output requiring a parameter
105     G_TENSORPROD     // general tensor product     G_TENSORPROD     // general tensor product
# Line 112  string ES_opstrings[]={"UNKNOWN","IDENTI Line 113  string ES_opstrings[]={"UNKNOWN","IDENTI
113              "asin","acos","atan","sinh","cosh","tanh","erf",              "asin","acos","atan","sinh","cosh","tanh","erf",
114              "asinh","acosh","atanh",              "asinh","acosh","atanh",
115              "log10","log","sign","abs","neg","pos","exp","sqrt",              "log10","log","sign","abs","neg","pos","exp","sqrt",
116              "1/","where>0","where<0","where>=0","where<=0",              "1/","where>0","where<0","where>=0","where<=0", "where<>0","where=0",
117              "symmetric","nonsymmetric",              "symmetric","nonsymmetric",
118              "prod",              "prod",
119              "transpose",              "transpose", "trace"};
120              "trace"};  int ES_opcount=40;
 int ES_opcount=38;  
121  ES_opgroup opgroups[]={G_UNKNOWN,G_IDENTITY,G_BINARY,G_BINARY,G_BINARY,G_BINARY, G_BINARY,  ES_opgroup opgroups[]={G_UNKNOWN,G_IDENTITY,G_BINARY,G_BINARY,G_BINARY,G_BINARY, G_BINARY,
122              G_UNARY,G_UNARY,G_UNARY, //10              G_UNARY,G_UNARY,G_UNARY, //10
123              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,    // 17              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,    // 17
124              G_UNARY,G_UNARY,G_UNARY,                    // 20              G_UNARY,G_UNARY,G_UNARY,                    // 20
125              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,        // 28              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,    // 28
126              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,            // 33              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY, G_UNARY_P, G_UNARY_P,      // 35
127              G_NP1OUT,G_NP1OUT,              G_NP1OUT,G_NP1OUT,
128              G_TENSORPROD,              G_TENSORPROD,
129              G_NP1OUT_P, G_NP1OUT_P};              G_NP1OUT_P, G_NP1OUT_P};
# Line 292  calcBuffs(const DataLazy_ptr& left, cons Line 292  calcBuffs(const DataLazy_ptr& left, cons
292     {     {
293     case G_IDENTITY: return 1;     case G_IDENTITY: return 1;
294     case G_BINARY: return max(left->getBuffsRequired(),right->getBuffsRequired()+1);     case G_BINARY: return max(left->getBuffsRequired(),right->getBuffsRequired()+1);
295     case G_UNARY: return max(left->getBuffsRequired(),1);     case G_UNARY:
296       case G_UNARY_P: return max(left->getBuffsRequired(),1);
297     case G_NP1OUT: return 1+max(left->getBuffsRequired(),1);     case G_NP1OUT: return 1+max(left->getBuffsRequired(),1);
298     case G_NP1OUT_P: return 1+max(left->getBuffsRequired(),1);     case G_NP1OUT_P: return 1+max(left->getBuffsRequired(),1);
299     case G_TENSORPROD: return 1+max(left->getBuffsRequired(),right->getBuffsRequired()+1);     case G_TENSORPROD: return 1+max(left->getBuffsRequired(),right->getBuffsRequired()+1);
# Line 508  DataLazy::DataLazy(DataAbstract_ptr left Line 509  DataLazy::DataLazy(DataAbstract_ptr left
509      : parent(left->getFunctionSpace(), resultShape(left,op)),      : parent(left->getFunctionSpace(), resultShape(left,op)),
510      m_op(op),      m_op(op),
511      m_axis_offset(axis_offset),      m_axis_offset(axis_offset),
512      m_transpose(0)      m_transpose(0),
513        m_tol(0)
514  {  {
515     if ((getOpgroup(op)!=G_NP1OUT_P))     if ((getOpgroup(op)!=G_NP1OUT_P))
516     {     {
# Line 531  DataLazy::DataLazy(DataAbstract_ptr left Line 533  DataLazy::DataLazy(DataAbstract_ptr left
533  LAZYDEBUG(cout << "(5)Lazy created with " << m_samplesize << endl;)  LAZYDEBUG(cout << "(5)Lazy created with " << m_samplesize << endl;)
534  }  }
535    
536    DataLazy::DataLazy(DataAbstract_ptr left, ES_optype op, double tol)
537        : parent(left->getFunctionSpace(), left->getShape()),
538        m_op(op),
539        m_axis_offset(0),
540        m_transpose(0),
541        m_tol(tol)
542    {
543       if ((getOpgroup(op)!=G_UNARY_P))
544       {
545        throw DataException("Programmer error - constructor DataLazy(left, op, tol) will only process UNARY operations which require parameters.");
546       }
547       DataLazy_ptr lleft;
548       if (!left->isLazy())
549       {
550        lleft=DataLazy_ptr(new DataLazy(left));
551       }
552       else
553       {
554        lleft=dynamic_pointer_cast<DataLazy>(left);
555       }
556       m_readytype=lleft->m_readytype;
557       m_left=lleft;
558       m_buffsRequired=calcBuffs(m_left, m_right,m_op); // yeah m_right will be null at this point
559       m_samplesize=getNumDPPSample()*getNoValues();
560       m_maxsamplesize=max(m_samplesize,m_left->getMaxSampleSize());
561    LAZYDEBUG(cout << "(6)Lazy created with " << m_samplesize << endl;)
562    }
563    
564  DataLazy::~DataLazy()  DataLazy::~DataLazy()
565  {  {
# Line 668  DataLazy::collapseToReady() Line 697  DataLazy::collapseToReady()
697      case LEZ:      case LEZ:
698      result=left.whereNonPositive();      result=left.whereNonPositive();
699      break;      break;
700        case NEZ:
701        result=left.whereNonZero(m_tol);
702        break;
703        case EZ:
704        result=left.whereZero(m_tol);
705        break;
706      case SYM:      case SYM:
707      result=left.symmetric();      result=left.symmetric();
708      break;      break;
# Line 834  DataLazy::resolveUnary(ValueType& v, siz Line 869  DataLazy::resolveUnary(ValueType& v, siz
869      case LEZ:      case LEZ:
870      tensor_unary_operation(m_samplesize, left, result, bind2nd(less_equal<double>(),0.0));      tensor_unary_operation(m_samplesize, left, result, bind2nd(less_equal<double>(),0.0));
871      break;      break;
872    // There are actually G_UNARY_P but I don't see a compelling reason to treat them differently
873        case NEZ:
874        tensor_unary_operation(m_samplesize, left, result, bind2nd(AbsGT(),m_tol));
875        break;
876        case EZ:
877        tensor_unary_operation(m_samplesize, left, result, bind2nd(AbsLTE(),m_tol));
878        break;
879    
880      default:      default:
881      throw DataException("Programmer error - resolveUnary can not resolve operator "+opToString(m_op)+".");      throw DataException("Programmer error - resolveUnary can not resolve operator "+opToString(m_op)+".");
# Line 842  DataLazy::resolveUnary(ValueType& v, siz Line 884  DataLazy::resolveUnary(ValueType& v, siz
884  }  }
885    
886    
887    
888    
889    
890    
891  /*  /*
892    \brief Compute the value of the expression (unary operation) for the given sample.    \brief Compute the value of the expression (unary operation) for the given sample.
893    \return Vector which stores the value of the subexpression for the given sample.    \return Vector which stores the value of the subexpression for the given sample.
# Line 1107  LAZYDEBUG(cout << "Resolve sample " << t Line 1153  LAZYDEBUG(cout << "Resolve sample " << t
1153    }    }
1154    switch (getOpgroup(m_op))    switch (getOpgroup(m_op))
1155    {    {
1156    case G_UNARY: return resolveUnary(v, offset,sampleNo,roffset);    case G_UNARY:
1157      case G_UNARY_P: return resolveUnary(v, offset,sampleNo,roffset);
1158    case G_BINARY: return resolveBinary(v, offset,sampleNo,roffset);    case G_BINARY: return resolveBinary(v, offset,sampleNo,roffset);
1159    case G_NP1OUT: return resolveNP1OUT(v, offset, sampleNo,roffset);    case G_NP1OUT: return resolveNP1OUT(v, offset, sampleNo,roffset);
1160    case G_NP1OUT_P: return resolveNP1OUT_P(v, offset, sampleNo,roffset);    case G_NP1OUT_P: return resolveNP1OUT_P(v, offset, sampleNo,roffset);
# Line 1215  DataLazy::intoString(ostringstream& oss) Line 1262  DataLazy::intoString(ostringstream& oss)
1262      oss << ')';      oss << ')';
1263      break;      break;
1264    case G_UNARY:    case G_UNARY:
1265      case G_UNARY_P:
1266    case G_NP1OUT:    case G_NP1OUT:
1267    case G_NP1OUT_P:    case G_NP1OUT_P:
1268      oss << opToString(m_op) << '(';      oss << opToString(m_op) << '(';

Legend:
Removed from v.2092  
changed lines
  Added in v.2147

  ViewVC Help
Powered by ViewVC 1.1.26