/[escript]/branches/schroedinger_upto1946/escript/src/DataLazy.cpp
ViewVC logotype

Diff of /branches/schroedinger_upto1946/escript/src/DataLazy.cpp

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

revision 1901 by jfenwick, Wed Oct 22 02:44:34 2008 UTC revision 1926 by jfenwick, Fri Oct 24 05:54:08 2008 UTC
# Line 95  enum ES_opgroup Line 95  enum ES_opgroup
95    
96    
97    
98  string ES_opstrings[]={"UNKNOWN","IDENTITY","+","-","*","/","sin","cos","tan",  string ES_opstrings[]={"UNKNOWN","IDENTITY","+","-","*","/","^",
99                "sin","cos","tan",
100              "asin","acos","atan","sinh","cosh","tanh","erf",              "asin","acos","atan","sinh","cosh","tanh","erf",
101              "asinh","acosh","atanh",              "asinh","acosh","atanh",
102              "log10","log","sign","abs","neg","pos","exp","sqrt",              "log10","log","sign","abs","neg","pos","exp","sqrt",
103              "1/","where>0","where<0","where>=0","where<=0"};              "1/","where>0","where<0","where>=0","where<=0"};
104  int ES_opcount=32;  int ES_opcount=33;
105  ES_opgroup opgroups[]={G_UNKNOWN,G_IDENTITY,G_BINARY,G_BINARY,G_BINARY,G_BINARY,G_UNARY,G_UNARY,G_UNARY, //9  ES_opgroup opgroups[]={G_UNKNOWN,G_IDENTITY,G_BINARY,G_BINARY,G_BINARY,G_BINARY, G_BINARY,
106              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,    // 16              G_UNARY,G_UNARY,G_UNARY, //10
107              G_UNARY,G_UNARY,G_UNARY,                    // 19              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,    // 17
108              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,        // 27              G_UNARY,G_UNARY,G_UNARY,                    // 20
109                G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,        // 28
110              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY};              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY};
111  inline  inline
112  ES_opgroup  ES_opgroup
# Line 136  resultShape(DataAbstract_ptr left, DataA Line 138  resultShape(DataAbstract_ptr left, DataA
138  {  {
139      if (left->getShape()!=right->getShape())      if (left->getShape()!=right->getShape())
140      {      {
141          throw DataException("Shapes not the same - shapes must match for lazy data.");        if (getOpgroup(op)!=G_BINARY)
142          {
143            throw DataException("Shapes not the name - shapes must match for (point)binary operations.");
144          }
145          if (left->getRank()==0)   // we need to allow scalar * anything
146          {
147            return right->getShape();
148          }
149          if (right->getRank()==0)
150          {
151            return left->getShape();
152          }
153          throw DataException("Shapes not the same - arguments must have matching shapes (or be scalars) for (point)binary operations on lazy data.");
154      }      }
155      return left->getShape();      return left->getShape();
156  }  }
# Line 576  DataLazy::resolveUnary(ValueType& v, siz Line 590  DataLazy::resolveUnary(ValueType& v, siz
590    
591    
592  #define PROC_OP(X) \  #define PROC_OP(X) \
593      for (int i=0;i<steps;++i,resultp+=getNoValues()) \      for (int i=0;i<steps;++i,resultp+=resultStep) \
594      { \      { \
595         tensor_binary_operation(chunksize, &((*left)[lroffset]), &((*right)[rroffset]), resultp, X); \         tensor_binary_operation(chunksize, &((*left)[lroffset]), &((*right)[rroffset]), resultp, X); \
596         lroffset+=leftStep; \         lroffset+=leftStep; \
# Line 601  DataLazy::resolveUnary(ValueType& v, siz Line 615  DataLazy::resolveUnary(ValueType& v, siz
615  // the whole sample as one big datapoint.  // the whole sample as one big datapoint.
616  // If one of the children is not expanded, then we need to treat each point in the sample  // If one of the children is not expanded, then we need to treat each point in the sample
617  // individually.  // individually.
618    // There is an additional complication when scalar operations are considered.
619    // For example, 2+Vector.
620    // In this case each double within the point is treated individually
621  DataTypes::ValueType*  DataTypes::ValueType*
622  DataLazy::resolveBinary(ValueType& v,  size_t offset, int sampleNo, size_t& roffset) const  DataLazy::resolveBinary(ValueType& v,  size_t offset, int sampleNo, size_t& roffset) const
623  {  {
# Line 611  cout << "Resolve binary: " << toString() Line 628  cout << "Resolve binary: " << toString()
628    bool leftExp=(m_left->m_readytype=='E');    bool leftExp=(m_left->m_readytype=='E');
629    bool rightExp=(m_right->m_readytype=='E');    bool rightExp=(m_right->m_readytype=='E');
630    bool bigloops=((leftExp && rightExp) || (!leftExp && !rightExp)); // is processing in single step?    bool bigloops=((leftExp && rightExp) || (!leftExp && !rightExp)); // is processing in single step?
631    int steps=(bigloops?1:getNumDPPSample());        int steps=(bigloops?1:getNumDPPSample());
632    size_t chunksize=(bigloops? m_samplesize : getNoValues());    // if bigloops, pretend the whole sample is a datapoint    size_t chunksize=(bigloops? m_samplesize : getNoValues());    // if bigloops, pretend the whole sample is a datapoint
633    int leftStep=((leftExp && !rightExp)? getNoValues() : 0);    if (m_left->getRank()!=m_right->getRank())    // need to deal with scalar * ? ops
634    int rightStep=((rightExp && !leftExp)? getNoValues() : 0);    {
635        EsysAssert((m_left->getRank()==0) || (m_right->getRank()==0), "Error - Ranks must match unless one is 0.");
636        steps=getNumDPPSample()*max(m_left->getNoValues(),m_right->getNoValues());
637        chunksize=1;    // for scalar
638      }    
639      int leftStep=((leftExp && !rightExp)? m_right->getNoValues() : 0);
640      int rightStep=((rightExp && !leftExp)? m_left->getNoValues() : 0);
641      int resultStep=max(leftStep,rightStep);   // only one (at most) should be !=0
642      // Get the values of sub-expressions      // Get the values of sub-expressions
643    const ValueType* left=m_left->resolveSample(v,offset,sampleNo,lroffset);    const ValueType* left=m_left->resolveSample(v,offset,sampleNo,lroffset);
644    const ValueType* right=m_right->resolveSample(v,offset+m_samplesize,sampleNo,rroffset); // Note    const ValueType* right=m_right->resolveSample(v,offset+m_samplesize,sampleNo,rroffset); // Note
# Line 634  cout << "Resolve binary: " << toString() Line 658  cout << "Resolve binary: " << toString()
658      case DIV:      case DIV:
659      PROC_OP(divides<double>());      PROC_OP(divides<double>());
660      break;      break;
661        case POW:
662        PROC_OP(::pow);
663        break;
664      default:      default:
665      throw DataException("Programmer error - resolveBinary can not resolve operator "+opToString(m_op)+".");      throw DataException("Programmer error - resolveBinary can not resolve operator "+opToString(m_op)+".");
666    }    }

Legend:
Removed from v.1901  
changed lines
  Added in v.1926

  ViewVC Help
Powered by ViewVC 1.1.26