/[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 2881 by jfenwick, Thu Jan 28 02:03:15 2010 UTC revision 3035 by jfenwick, Thu Jun 10 01:48:41 2010 UTC
# Line 142  enum ES_opgroup Line 142  enum ES_opgroup
142     G_NP1OUT_P,      // non-pointwise op with one output requiring a parameter     G_NP1OUT_P,      // non-pointwise op with one output requiring a parameter
143     G_TENSORPROD,    // general tensor product     G_TENSORPROD,    // general tensor product
144     G_NP1OUT_2P,     // non-pointwise op with one output requiring two params     G_NP1OUT_2P,     // non-pointwise op with one output requiring two params
145     G_REDUCTION      // non-pointwise unary op with a scalar output     G_REDUCTION,     // non-pointwise unary op with a scalar output
146       G_CONDEVAL
147  };  };
148    
149    
# Line 158  string ES_opstrings[]={"UNKNOWN","IDENTI Line 159  string ES_opstrings[]={"UNKNOWN","IDENTI
159              "prod",              "prod",
160              "transpose", "trace",              "transpose", "trace",
161              "swapaxes",              "swapaxes",
162              "minval", "maxval"};              "minval", "maxval",
163  int ES_opcount=43;              "condEval"};
164    int ES_opcount=44;
165  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,
166              G_UNARY,G_UNARY,G_UNARY, //10              G_UNARY,G_UNARY,G_UNARY, //10
167              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 170  ES_opgroup opgroups[]={G_UNKNOWN,G_IDENT Line 172  ES_opgroup opgroups[]={G_UNKNOWN,G_IDENT
172              G_TENSORPROD,              G_TENSORPROD,
173              G_NP1OUT_P, G_NP1OUT_P,              G_NP1OUT_P, G_NP1OUT_P,
174              G_NP1OUT_2P,              G_NP1OUT_2P,
175              G_REDUCTION, G_REDUCTION};              G_REDUCTION, G_REDUCTION,
176                G_CONDEVAL};
177  inline  inline
178  ES_opgroup  ES_opgroup
179  getOpgroup(ES_optype op)  getOpgroup(ES_optype op)
# Line 740  DataLazy::DataLazy(DataAbstract_ptr left Line 743  DataLazy::DataLazy(DataAbstract_ptr left
743  LAZYDEBUG(cout << "(7)Lazy created with " << m_samplesize << endl;)  LAZYDEBUG(cout << "(7)Lazy created with " << m_samplesize << endl;)
744  }  }
745    
746    
747    namespace
748    {
749    
750        inline int max3(int a, int b, int c)
751        {
752        int t=(a>b?a:b);
753        return (t>c?t:c);
754    
755        }
756    }
757    
758    DataLazy::DataLazy(DataAbstract_ptr mask, DataAbstract_ptr left, DataAbstract_ptr right/*, double tol*/)
759        : parent(left->getFunctionSpace(), left->getShape()),
760        m_op(CONDEVAL),
761        m_axis_offset(0),
762        m_transpose(0),
763        m_tol(0)
764    {
765    
766       DataLazy_ptr lmask;
767       DataLazy_ptr lleft;
768       DataLazy_ptr lright;
769       if (!mask->isLazy())
770       {
771        lmask=DataLazy_ptr(new DataLazy(mask));
772       }
773       else
774       {
775        lmask=dynamic_pointer_cast<DataLazy>(mask);
776       }
777       if (!left->isLazy())
778       {
779        lleft=DataLazy_ptr(new DataLazy(left));
780       }
781       else
782       {
783        lleft=dynamic_pointer_cast<DataLazy>(left);
784       }
785       if (!right->isLazy())
786       {
787        lright=DataLazy_ptr(new DataLazy(right));
788       }
789       else
790       {
791        lright=dynamic_pointer_cast<DataLazy>(right);
792       }
793       m_readytype=lmask->m_readytype;
794       if ((lleft->m_readytype!=lright->m_readytype) || (lmask->m_readytype!=lleft->m_readytype))
795       {
796        throw DataException("Programmer Error - condEval arguments must have the same readytype");
797       }
798       m_left=lleft;
799       m_right=lright;
800       m_mask=lmask;
801       m_samplesize=getNumDPPSample()*getNoValues();
802       m_children=m_left->m_children+m_right->m_children+m_mask->m_children+1;
803       m_height=max3(m_left->m_height,m_right->m_height,m_mask->m_height)+1;
804       LazyNodeSetup();
805       SIZELIMIT
806    LAZYDEBUG(cout << "(8)Lazy created with " << m_samplesize << endl;)
807    }
808    
809    
810    
811  DataLazy::~DataLazy()  DataLazy::~DataLazy()
812  {  {
813     delete[] m_sampleids;     delete[] m_sampleids;
# Line 977  if (&x<stackend[omp_get_thread_num()]) Line 1045  if (&x<stackend[omp_get_thread_num()])
1045      return &(m_samples);        // sample is already resolved      return &(m_samples);        // sample is already resolved
1046    }    }
1047    m_sampleids[tid]=sampleNo;    m_sampleids[tid]=sampleNo;
1048    
1049    switch (getOpgroup(m_op))    switch (getOpgroup(m_op))
1050    {    {
1051    case G_UNARY:    case G_UNARY:
# Line 987  if (&x<stackend[omp_get_thread_num()]) Line 1056  if (&x<stackend[omp_get_thread_num()])
1056    case G_TENSORPROD: return resolveNodeTProd(tid, sampleNo, roffset);    case G_TENSORPROD: return resolveNodeTProd(tid, sampleNo, roffset);
1057    case G_NP1OUT_2P: return resolveNodeNP1OUT_2P(tid, sampleNo, roffset);    case G_NP1OUT_2P: return resolveNodeNP1OUT_2P(tid, sampleNo, roffset);
1058    case G_REDUCTION: return resolveNodeReduction(tid, sampleNo, roffset);    case G_REDUCTION: return resolveNodeReduction(tid, sampleNo, roffset);
1059      case G_CONDEVAL: return resolveNodeCondEval(tid, sampleNo, roffset);
1060    default:    default:
1061      throw DataException("Programmer Error - resolveSample does not know how to process "+opToString(m_op)+".");      throw DataException("Programmer Error - resolveSample does not know how to process "+opToString(m_op)+".");
1062    }    }
# Line 1305  DataLazy::resolveNodeNP1OUT_2P(int tid, Line 1375  DataLazy::resolveNodeNP1OUT_2P(int tid,
1375    return &m_samples;    return &m_samples;
1376  }  }
1377    
1378    const DataTypes::ValueType*
1379    DataLazy::resolveNodeCondEval(int tid, int sampleNo, size_t& roffset)
1380    {
1381      if (m_readytype!='E')
1382      {
1383        throw DataException("Programmer error - resolveNodeCondEval should only be called on expanded Data.");
1384      }
1385      if (m_op!=CONDEVAL)
1386      {
1387        throw DataException("Programmer error - resolveNodeCondEval should only be called on CONDEVAL nodes.");
1388      }
1389      size_t subroffset;
1390      size_t offset;
1391    
1392    
1393      const ValueType* maskres=m_mask->resolveNodeSample(tid, sampleNo, subroffset);
1394      const ValueType* srcres=0;
1395      if ((*maskres)[subroffset]>0)
1396      {
1397        srcres=m_left->resolveNodeSample(tid, sampleNo, subroffset);
1398      }
1399      else
1400      {
1401        srcres=m_right->resolveNodeSample(tid, sampleNo, subroffset);
1402      }
1403    
1404      // Now we need to copy the result
1405    
1406      roffset=m_samplesize*tid;
1407      offset=roffset;
1408      for (int i=0;i<m_samplesize;++i)
1409      {
1410        m_samples[roffset+i]=(*srcres)[subroffset+i];  
1411      }
1412    
1413      return &m_samples;
1414    }
1415    
1416  // This method assumes that any subexpressions which evaluate to Constant or Tagged Data  // This method assumes that any subexpressions which evaluate to Constant or Tagged Data
1417  // have already been collapsed to IDENTITY. So we must have at least one expanded child.  // have already been collapsed to IDENTITY. So we must have at least one expanded child.
1418  // If both children are expanded, then we can process them in a single operation (we treat  // If both children are expanded, then we can process them in a single operation (we treat
# Line 1808  DataLazy::intoString(ostringstream& oss) Line 1914  DataLazy::intoString(ostringstream& oss)
1914      oss << ", " << m_axis_offset << ", " << m_transpose;      oss << ", " << m_axis_offset << ", " << m_transpose;
1915      oss << ')';      oss << ')';
1916      break;      break;
1917      case G_CONDEVAL:
1918        oss << opToString(m_op)<< '(' ;
1919        m_mask->intoString(oss);
1920        oss << " ? ";
1921        m_left->intoString(oss);
1922        oss << " : ";
1923        m_right->intoString(oss);
1924        oss << ')';
1925        break;
1926    default:    default:
1927      oss << "UNKNOWN";      oss << "UNKNOWN";
1928    }    }

Legend:
Removed from v.2881  
changed lines
  Added in v.3035

  ViewVC Help
Powered by ViewVC 1.1.26