/[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 1899 by jfenwick, Mon Oct 20 05:13:24 2008 UTC revision 1910 by jfenwick, Thu Oct 23 03:05:28 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=32;
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 212  cout << "(1)Lazy created with " << m_sam Line 226  cout << "(1)Lazy created with " << m_sam
226    
227    
228    
229    
230  DataLazy::DataLazy(DataAbstract_ptr left, ES_optype op)  DataLazy::DataLazy(DataAbstract_ptr left, ES_optype op)
231      : parent(left->getFunctionSpace(),left->getShape()),      : parent(left->getFunctionSpace(),left->getShape()),
232      m_op(op)      m_op(op)
# Line 575  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 600  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 610  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 633  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    }    }
# Line 832  DataLazy::getPointOffset(int sampleNo, Line 860  DataLazy::getPointOffset(int sampleNo,
860    throw DataException("getPointOffset - not implemented for Lazy objects - yet.");    throw DataException("getPointOffset - not implemented for Lazy objects - yet.");
861  }  }
862    
863    // It would seem that DataTagged will need to be treated differently since even after setting all tags
864    // to zero, all the tags from all the DataTags would be in the result.
865    // However since they all have the same value (0) whether they are there or not should not matter.
866    // So I have decided that for all types this method will create a constant 0.
867    // It can be promoted up as required.
868    // A possible efficiency concern might be expanded->constant->expanded which has an extra memory management
869    // but we can deal with that if it arrises.
870    void
871    DataLazy::setToZero()
872    {
873      DataTypes::ValueType v(getNoValues(),0);
874      m_id=DataReady_ptr(new DataConstant(getFunctionSpace(),getShape(),v));
875      m_op=IDENTITY;
876      m_right.reset();  
877      m_left.reset();
878      m_readytype='C';
879      m_buffsRequired=1;
880    }
881    
882  }   // end namespace  }   // end namespace

Legend:
Removed from v.1899  
changed lines
  Added in v.1910

  ViewVC Help
Powered by ViewVC 1.1.26