/[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

branches/schroedinger/escript/src/DataLazy.cpp revision 1910 by jfenwick, Thu Oct 23 03:05:28 2008 UTC branches/schroedinger_upto1946/escript/src/DataLazy.cpp revision 1947 by jfenwick, Wed Oct 29 23:19:45 2008 UTC
# Line 101  string ES_opstrings[]={"UNKNOWN","IDENTI Line 101  string ES_opstrings[]={"UNKNOWN","IDENTI
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_BINARY,  ES_opgroup opgroups[]={G_UNKNOWN,G_IDENTITY,G_BINARY,G_BINARY,G_BINARY,G_BINARY, G_BINARY,
106              G_UNARY,G_UNARY,G_UNARY, //10              G_UNARY,G_UNARY,G_UNARY, //10
107              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
# Line 124  resultFS(DataAbstract_ptr left, DataAbst Line 124  resultFS(DataAbstract_ptr left, DataAbst
124      // that way, if interpolate is required in any other op we can just throw a      // that way, if interpolate is required in any other op we can just throw a
125      // programming error exception.      // programming error exception.
126    
127      FunctionSpace l=left->getFunctionSpace();
128      if (left->getFunctionSpace()!=right->getFunctionSpace())    FunctionSpace r=right->getFunctionSpace();
129      {    if (l!=r)
130          throw DataException("FunctionSpaces not equal - interpolation not supported on lazy data.");    {
131      }      if (r.probeInterpolation(l))
132      return left->getFunctionSpace();      {
133        return l;
134        }
135        if (l.probeInterpolation(r))
136        {
137        return r;
138        }
139        throw DataException("Cannot interpolate between the FunctionSpaces given for operation "+opToString(op)+".");
140      }
141      return l;
142  }  }
143    
144  // return the shape of the result of "left op right"  // return the shape of the result of "left op right"
# Line 252  DataLazy::DataLazy(DataAbstract_ptr left Line 261  DataLazy::DataLazy(DataAbstract_ptr left
261  }  }
262    
263    
264    // In this constructor we need to consider interpolation
265  DataLazy::DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op)  DataLazy::DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op)
266      : parent(resultFS(left,right,op), resultShape(left,right,op)),      : parent(resultFS(left,right,op), resultShape(left,right,op)),
267      m_op(op)      m_op(op)
# Line 260  DataLazy::DataLazy(DataAbstract_ptr left Line 270  DataLazy::DataLazy(DataAbstract_ptr left
270     {     {
271      throw DataException("Programmer error - constructor DataLazy(left, right, op) will only process BINARY operations.");      throw DataException("Programmer error - constructor DataLazy(left, right, op) will only process BINARY operations.");
272     }     }
273    
274       if (getFunctionSpace()!=left->getFunctionSpace())    // left needs to be interpolated
275       {
276        FunctionSpace fs=getFunctionSpace();
277        Data ltemp(left);
278        Data tmp(ltemp,fs);
279        left=tmp.borrowDataPtr();
280       }
281       if (getFunctionSpace()!=right->getFunctionSpace())   // left needs to be interpolated
282       {
283        Data tmp(Data(right),getFunctionSpace());
284        right=tmp.borrowDataPtr();
285       }
286       left->operandCheck(*right);
287    
288     if (left->isLazy())          // the children need to be DataLazy. Wrap them in IDENTITY if required     if (left->isLazy())          // the children need to be DataLazy. Wrap them in IDENTITY if required
289     {     {
290      m_left=dynamic_pointer_cast<DataLazy>(left);      m_left=dynamic_pointer_cast<DataLazy>(left);
# Line 827  DataLazy::intoString(ostringstream& oss) Line 852  DataLazy::intoString(ostringstream& oss)
852    }    }
853  }  }
854    
 // Note that in this case, deepCopy does not make copies of the leaves.  
 // Hopefully copy on write (or whatever we end up using) will take care of this.  
855  DataAbstract*  DataAbstract*
856  DataLazy::deepCopy()  DataLazy::deepCopy()
857  {  {
858    if (m_op==IDENTITY)    switch (getOpgroup(m_op))
859    {    {
860      return new DataLazy(m_left);    // we don't need to copy the child here    case G_IDENTITY:  return new DataLazy(m_id->deepCopy()->getPtr());
861      case G_UNARY: return new DataLazy(m_left->deepCopy()->getPtr(),m_op);
862      case G_BINARY:    return new DataLazy(m_left->deepCopy()->getPtr(),m_right->deepCopy()->getPtr(),m_op);
863      default:
864        throw DataException("Programmer error - do not know how to deepcopy operator "+opToString(m_op)+".");
865    }    }
   return new DataLazy(m_left->deepCopy()->getPtr(),m_right->deepCopy()->getPtr(),m_op);  
866  }  }
867    
868    
# Line 853  DataLazy::getSlice(const DataTypes::Regi Line 879  DataLazy::getSlice(const DataTypes::Regi
879    throw DataException("getSlice - not implemented for Lazy objects.");    throw DataException("getSlice - not implemented for Lazy objects.");
880  }  }
881    
882    
883    // To do this we need to rely on our child nodes
884    DataTypes::ValueType::size_type
885    DataLazy::getPointOffset(int sampleNo,
886                     int dataPointNo)
887    {
888      if (m_op==IDENTITY)
889      {
890        return m_id->getPointOffset(sampleNo,dataPointNo);
891      }
892      if (m_readytype!='E')
893      {
894        collapse();
895        return m_id->getPointOffset(sampleNo,dataPointNo);
896      }
897      // at this point we do not have an identity node and the expression will be Expanded
898      // so we only need to know which child to ask
899      if (m_left->m_readytype=='E')
900      {
901        return m_left->getPointOffset(sampleNo,dataPointNo);
902      }
903      else
904      {
905        return m_right->getPointOffset(sampleNo,dataPointNo);
906      }
907    }
908    
909    // To do this we need to rely on our child nodes
910  DataTypes::ValueType::size_type  DataTypes::ValueType::size_type
911  DataLazy::getPointOffset(int sampleNo,  DataLazy::getPointOffset(int sampleNo,
912                   int dataPointNo) const                   int dataPointNo) const
913  {  {
914    throw DataException("getPointOffset - not implemented for Lazy objects - yet.");    if (m_op==IDENTITY)
915      {
916        return m_id->getPointOffset(sampleNo,dataPointNo);
917      }
918      if (m_readytype=='E')
919      {
920        // at this point we do not have an identity node and the expression will be Expanded
921        // so we only need to know which child to ask
922        if (m_left->m_readytype=='E')
923        {
924        return m_left->getPointOffset(sampleNo,dataPointNo);
925        }
926        else
927        {
928        return m_right->getPointOffset(sampleNo,dataPointNo);
929        }
930      }
931      if (m_readytype=='C')
932      {
933        return m_left->getPointOffset(sampleNo,dataPointNo); // which child doesn't matter
934      }
935      throw DataException("Programmer error - getPointOffset on lazy data may require collapsing (but this object is marked const).");
936  }  }
937    
938  // It would seem that DataTagged will need to be treated differently since even after setting all tags  // It would seem that DataTagged will need to be treated differently since even after setting all tags

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

  ViewVC Help
Powered by ViewVC 1.1.26