/[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 1908 by jfenwick, Thu Oct 23 01:35:31 2008 UTC branches/schroedinger_upto1946/escript/src/DataLazy.cpp revision 1950 by jfenwick, Thu Oct 30 00:59:34 2008 UTC
# Line 26  Line 26 
26  #include "DataTypes.h"  #include "DataTypes.h"
27  #include "Data.h"  #include "Data.h"
28  #include "UnaryFuncs.h"     // for escript::fsign  #include "UnaryFuncs.h"     // for escript::fsign
29    #include "Utils.h"
30    
31  /*  /*
32  How does DataLazy work?  How does DataLazy work?
# Line 95  enum ES_opgroup Line 96  enum ES_opgroup
96    
97    
98    
99  string ES_opstrings[]={"UNKNOWN","IDENTITY","+","-","*","/","sin","cos","tan",  string ES_opstrings[]={"UNKNOWN","IDENTITY","+","-","*","/","^",
100                "sin","cos","tan",
101              "asin","acos","atan","sinh","cosh","tanh","erf",              "asin","acos","atan","sinh","cosh","tanh","erf",
102              "asinh","acosh","atanh",              "asinh","acosh","atanh",
103              "log10","log","sign","abs","neg","pos","exp","sqrt",              "log10","log","sign","abs","neg","pos","exp","sqrt",
104              "1/","where>0","where<0","where>=0","where<=0"};              "1/","where>0","where<0","where>=0","where<=0"};
105  int ES_opcount=32;  int ES_opcount=33;
106  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,
107              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,    // 16              G_UNARY,G_UNARY,G_UNARY, //10
108              G_UNARY,G_UNARY,G_UNARY,                    // 19              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,    // 17
109              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,        // 27              G_UNARY,G_UNARY,G_UNARY,                    // 20
110                G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,        // 28
111              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY};              G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY};
112  inline  inline
113  ES_opgroup  ES_opgroup
# Line 122  resultFS(DataAbstract_ptr left, DataAbst Line 125  resultFS(DataAbstract_ptr left, DataAbst
125      // 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
126      // programming error exception.      // programming error exception.
127    
128      FunctionSpace l=left->getFunctionSpace();
129      if (left->getFunctionSpace()!=right->getFunctionSpace())    FunctionSpace r=right->getFunctionSpace();
130      {    if (l!=r)
131          throw DataException("FunctionSpaces not equal - interpolation not supported on lazy data.");    {
132      }      if (r.probeInterpolation(l))
133      return left->getFunctionSpace();      {
134        return l;
135        }
136        if (l.probeInterpolation(r))
137        {
138        return r;
139        }
140        throw DataException("Cannot interpolate between the FunctionSpaces given for operation "+opToString(op)+".");
141      }
142      return l;
143  }  }
144    
145  // return the shape of the result of "left op right"  // return the shape of the result of "left op right"
# Line 250  DataLazy::DataLazy(DataAbstract_ptr left Line 262  DataLazy::DataLazy(DataAbstract_ptr left
262  }  }
263    
264    
265    // In this constructor we need to consider interpolation
266  DataLazy::DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op)  DataLazy::DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op)
267      : parent(resultFS(left,right,op), resultShape(left,right,op)),      : parent(resultFS(left,right,op), resultShape(left,right,op)),
268      m_op(op)      m_op(op)
# Line 258  DataLazy::DataLazy(DataAbstract_ptr left Line 271  DataLazy::DataLazy(DataAbstract_ptr left
271     {     {
272      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.");
273     }     }
274    
275       if (getFunctionSpace()!=left->getFunctionSpace())    // left needs to be interpolated
276       {
277        FunctionSpace fs=getFunctionSpace();
278        Data ltemp(left);
279        Data tmp(ltemp,fs);
280        left=tmp.borrowDataPtr();
281       }
282       if (getFunctionSpace()!=right->getFunctionSpace())   // left needs to be interpolated
283       {
284        Data tmp(Data(right),getFunctionSpace());
285        right=tmp.borrowDataPtr();
286       }
287       left->operandCheck(*right);
288    
289     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
290     {     {
291      m_left=dynamic_pointer_cast<DataLazy>(left);      m_left=dynamic_pointer_cast<DataLazy>(left);
# Line 656  cout << "Resolve binary: " << toString() Line 684  cout << "Resolve binary: " << toString()
684      case DIV:      case DIV:
685      PROC_OP(divides<double>());      PROC_OP(divides<double>());
686      break;      break;
687        case POW:
688        PROC_OP(::pow);
689        break;
690      default:      default:
691      throw DataException("Programmer error - resolveBinary can not resolve operator "+opToString(m_op)+".");      throw DataException("Programmer error - resolveBinary can not resolve operator "+opToString(m_op)+".");
692    }    }
# Line 822  DataLazy::intoString(ostringstream& oss) Line 853  DataLazy::intoString(ostringstream& oss)
853    }    }
854  }  }
855    
 // 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.  
856  DataAbstract*  DataAbstract*
857  DataLazy::deepCopy()  DataLazy::deepCopy()
858  {  {
859    if (m_op==IDENTITY)    switch (getOpgroup(m_op))
860    {    {
861      return new DataLazy(m_left);    // we don't need to copy the child here    case G_IDENTITY:  return new DataLazy(m_id->deepCopy()->getPtr());
862      case G_UNARY: return new DataLazy(m_left->deepCopy()->getPtr(),m_op);
863      case G_BINARY:    return new DataLazy(m_left->deepCopy()->getPtr(),m_right->deepCopy()->getPtr(),m_op);
864      default:
865        throw DataException("Programmer error - do not know how to deepcopy operator "+opToString(m_op)+".");
866    }    }
   return new DataLazy(m_left->deepCopy()->getPtr(),m_right->deepCopy()->getPtr(),m_op);  
867  }  }
868    
869    
# Line 848  DataLazy::getSlice(const DataTypes::Regi Line 880  DataLazy::getSlice(const DataTypes::Regi
880    throw DataException("getSlice - not implemented for Lazy objects.");    throw DataException("getSlice - not implemented for Lazy objects.");
881  }  }
882    
883    
884    // To do this we need to rely on our child nodes
885    DataTypes::ValueType::size_type
886    DataLazy::getPointOffset(int sampleNo,
887                     int dataPointNo)
888    {
889      if (m_op==IDENTITY)
890      {
891        return m_id->getPointOffset(sampleNo,dataPointNo);
892      }
893      if (m_readytype!='E')
894      {
895        collapse();
896        return m_id->getPointOffset(sampleNo,dataPointNo);
897      }
898      // at this point we do not have an identity node and the expression will be Expanded
899      // so we only need to know which child to ask
900      if (m_left->m_readytype=='E')
901      {
902        return m_left->getPointOffset(sampleNo,dataPointNo);
903      }
904      else
905      {
906        return m_right->getPointOffset(sampleNo,dataPointNo);
907      }
908    }
909    
910    // To do this we need to rely on our child nodes
911  DataTypes::ValueType::size_type  DataTypes::ValueType::size_type
912  DataLazy::getPointOffset(int sampleNo,  DataLazy::getPointOffset(int sampleNo,
913                   int dataPointNo) const                   int dataPointNo) const
914  {  {
915    throw DataException("getPointOffset - not implemented for Lazy objects - yet.");    if (m_op==IDENTITY)
916      {
917        return m_id->getPointOffset(sampleNo,dataPointNo);
918      }
919      if (m_readytype=='E')
920      {
921        // at this point we do not have an identity node and the expression will be Expanded
922        // so we only need to know which child to ask
923        if (m_left->m_readytype=='E')
924        {
925        return m_left->getPointOffset(sampleNo,dataPointNo);
926        }
927        else
928        {
929        return m_right->getPointOffset(sampleNo,dataPointNo);
930        }
931      }
932      if (m_readytype=='C')
933      {
934        return m_left->getPointOffset(sampleNo,dataPointNo); // which child doesn't matter
935      }
936      throw DataException("Programmer error - getPointOffset on lazy data may require collapsing (but this object is marked const).");
937  }  }
938    
939  // 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.1908  
changed lines
  Added in v.1950

  ViewVC Help
Powered by ViewVC 1.1.26