/[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 2177 by jfenwick, Wed Dec 17 23:51:23 2008 UTC revision 2195 by jfenwick, Wed Jan 7 04:13:52 2009 UTC
# Line 331  DataLazy::DataLazy(DataAbstract_ptr p) Line 331  DataLazy::DataLazy(DataAbstract_ptr p)
331     {     {
332      DataReady_ptr dr=dynamic_pointer_cast<DataReady>(p);      DataReady_ptr dr=dynamic_pointer_cast<DataReady>(p);
333      makeIdentity(dr);      makeIdentity(dr);
334    cout << "Wrapping " << dr.get() << " id=" << m_id.get() << endl;
335     }     }
336  LAZYDEBUG(cout << "(1)Lazy created with " << m_samplesize << endl;)  LAZYDEBUG(cout << "(1)Lazy created with " << m_samplesize << endl;)
337  }  }
# Line 376  DataLazy::DataLazy(DataAbstract_ptr left Line 377  DataLazy::DataLazy(DataAbstract_ptr left
377      m_op(op),      m_op(op),
378      m_SL(0), m_SM(0), m_SR(0)      m_SL(0), m_SM(0), m_SR(0)
379  {  {
380    cout << "Forming operator with " << left.get() << " " << right.get() << endl;
381     if ((getOpgroup(op)!=G_BINARY))     if ((getOpgroup(op)!=G_BINARY))
382     {     {
383      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.");
# Line 392  DataLazy::DataLazy(DataAbstract_ptr left Line 394  DataLazy::DataLazy(DataAbstract_ptr left
394     {     {
395      Data tmp(Data(right),getFunctionSpace());      Data tmp(Data(right),getFunctionSpace());
396      right=tmp.borrowDataPtr();      right=tmp.borrowDataPtr();
397    cout << "Right interpolation required " << right.get() << endl;
398     }     }
399     left->operandCheck(*right);     left->operandCheck(*right);
400    
401     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
402     {     {
403      m_left=dynamic_pointer_cast<DataLazy>(left);      m_left=dynamic_pointer_cast<DataLazy>(left);
404    cout << "Left is " << m_left->toString() << endl;
405     }     }
406     else     else
407     {     {
408      m_left=DataLazy_ptr(new DataLazy(left));      m_left=DataLazy_ptr(new DataLazy(left));
409    cout << "Left " << left.get() << " wrapped " << m_left->m_id.get() << endl;
410     }     }
411     if (right->isLazy())     if (right->isLazy())
412     {     {
413      m_right=dynamic_pointer_cast<DataLazy>(right);      m_right=dynamic_pointer_cast<DataLazy>(right);
414    cout << "Right is " << m_right->toString() << endl;
415     }     }
416     else     else
417     {     {
418      m_right=DataLazy_ptr(new DataLazy(right));      m_right=DataLazy_ptr(new DataLazy(right));
419    cout << "Right " << right.get() << " wrapped " << m_right->m_id.get() << endl;
420     }     }
421     char lt=m_left->m_readytype;     char lt=m_left->m_readytype;
422     char rt=m_right->m_readytype;     char rt=m_right->m_readytype;
# Line 460  DataLazy::DataLazy(DataAbstract_ptr left Line 467  DataLazy::DataLazy(DataAbstract_ptr left
467      Data tmp(Data(right),getFunctionSpace());      Data tmp(Data(right),getFunctionSpace());
468      right=tmp.borrowDataPtr();      right=tmp.borrowDataPtr();
469     }     }
470     left->operandCheck(*right);  //    left->operandCheck(*right);
471    
472     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
473     {     {
# Line 1177  LAZYDEBUG(cout << " numsteps=" << numste Line 1184  LAZYDEBUG(cout << " numsteps=" << numste
1184  LAZYDEBUG(cout << "onumsteps=" << onumsteps << endl;)  LAZYDEBUG(cout << "onumsteps=" << onumsteps << endl;)
1185  LAZYDEBUG(cout << " DPPS=" << m_left->getNumDPPSample() << "," <<m_right->getNumDPPSample() << endl;)  LAZYDEBUG(cout << " DPPS=" << m_left->getNumDPPSample() << "," <<m_right->getNumDPPSample() << endl;)
1186  LAZYDEBUG(cout << "" << LS << RS << LN << RN << LES << RES <<LEN << REN <<   endl;)  LAZYDEBUG(cout << "" << LS << RS << LN << RN << LES << RES <<LEN << REN <<   endl;)
1187    // LAZYDEBUG(
1188    // cout << "Results of bin" << endl;
1189    // cout << "Left=";
1190    // for (int i=lroffset;i<lroffset+m_left->m_samplesize;++i)
1191    // {
1192    // cout << (*left)[i] << " ";
1193    // }
1194    // cout << endl << "Right=";
1195    // for (int i=rroffset;i<rroffset+(m_right->m_readytype=='E'?m_right->m_samplesize:m_right->getNoValues());++i)
1196    // {
1197    // cout << (*right)[i] << " ";
1198    // }
1199    // cout << endl;
1200    // )
1201    
1202    double* resultp=&(v[offset]);     // results are stored at the vector offset we recieved    double* resultp=&(v[offset]);     // results are stored at the vector offset we recieved
1203    switch(m_op)    switch(m_op)
1204    {    {
# Line 1198  LAZYDEBUG(cout << "" << LS << RS << LN < Line 1220  LAZYDEBUG(cout << "" << LS << RS << LN <
1220      default:      default:
1221      throw DataException("Programmer error - resolveBinary can not resolve operator "+opToString(m_op)+".");      throw DataException("Programmer error - resolveBinary can not resolve operator "+opToString(m_op)+".");
1222    }    }
1223    roffset=offset;      roffset=offset;
1224    return &v;    return &v;
1225  }  }
1226    
# Line 1222  LAZYDEBUG(cout << "" << LS << RS << LN < Line 1244  LAZYDEBUG(cout << "" << LS << RS << LN <
1244  DataTypes::ValueType*  DataTypes::ValueType*
1245  DataLazy::resolveTProd(ValueType& v,  size_t offset, int sampleNo, size_t& roffset) const  DataLazy::resolveTProd(ValueType& v,  size_t offset, int sampleNo, size_t& roffset) const
1246  {  {
1247  LAZYDEBUG(cout << "Resolve TensorProduct: " << toString() << endl;)  LAZYDEBUG(cout << "Resolve TensorProduct: " << toString()  << " to offset " << offset<< endl;)
1248    
1249    size_t lroffset=0, rroffset=0;    // offsets in the left and right result vectors    size_t lroffset=0, rroffset=0;    // offsets in the left and right result vectors
1250      // first work out which of the children are expanded      // first work out which of the children are expanded
1251    bool leftExp=(m_left->m_readytype=='E');    bool leftExp=(m_left->m_readytype=='E');
1252    bool rightExp=(m_right->m_readytype=='E');    bool rightExp=(m_right->m_readytype=='E');
1253    int steps=getNumDPPSample();    int steps=getNumDPPSample();
1254    int leftStep=((leftExp && !rightExp)? m_right->getNoValues() : 0);  /*  int leftStep=((leftExp && !rightExp)? m_right->getNoValues() : 0);
1255    int rightStep=((rightExp && !leftExp)? m_left->getNoValues() : 0);    int rightStep=((rightExp && !leftExp)? m_left->getNoValues() : 0);*/
1256    int resultStep=max(leftStep,rightStep);   // only one (at most) should be !=0    int leftStep=(leftExp? m_left->getNoValues() : 0);        // do not have scalars as input to this method
1257      int rightStep=(rightExp?m_right->getNoValues() : 0);
1258    
1259      int resultStep=getNoValues();
1260    //   int resultStep=max(leftStep,rightStep);    // only one (at most) should be !=0
1261      // Get the values of sub-expressions (leave a gap of one sample for the result).      // Get the values of sub-expressions (leave a gap of one sample for the result).
1262    int gap=offset+m_left->getMaxSampleSize();    // actually only needs to be m_left->m_samplesize    int gap=offset+m_left->getMaxSampleSize();    // actually only needs to be m_left->m_samplesize
1263    
1264    LAZYDEBUG(cout << "Query left with offset=" << gap << endl;)
1265    
1266    const ValueType* left=m_left->resolveSample(v,gap,sampleNo,lroffset);    const ValueType* left=m_left->resolveSample(v,gap,sampleNo,lroffset);
1267    gap+=m_right->getMaxSampleSize();    gap+=m_right->getMaxSampleSize();
1268    const ValueType* right=m_right->resolveSample(v,gap,sampleNo,rroffset);  
1269  LAZYDEBUG(cout << "Post sub calls: " << toString() << endl;)  
1270    LAZYDEBUG(cout << "Query right with offset=" << gap << endl;)
1271    
1272    
1273      const ValueType* right=m_right->resolveSample(v,gap,sampleNo,rroffset);
1274    
1275    LAZYDEBUG(cerr << "[Left shape]=" << DataTypes::shapeToString(m_left->getShape()) << "\n[Right shape]=" << DataTypes::shapeToString(m_right->getShape()) << " result=" <<DataTypes::shapeToString(getShape()) <<  endl;
1276    cout << getNoValues() << endl;)
1277    LAZYDEBUG(cerr << "Result of left=";)
1278    LAZYDEBUG(cerr << "[" << lroffset << " .. " << lroffset+m_left->getNoValues() << "]" << endl;
1279    for (int i=lroffset;i<lroffset+m_left->getNoValues();++i)
1280    {
1281    cout << (*left)[i] << " ";
1282    })
1283    LAZYDEBUG(cerr << "\nResult of right=" << endl;)
1284    LAZYDEBUG(cerr << "[" << rroffset << " .. " << rroffset+m_right->m_samplesize << "]" << endl;
1285    for (int i=rroffset;i<rroffset+m_right->m_samplesize;++i)
1286    {
1287    cerr << (*right)[i] << " ";
1288    }
1289    cerr << endl;
1290    )
1291    LAZYDEBUG(cerr << "Post sub calls: " << toString() << endl;)
1292  LAZYDEBUG(cout << "LeftExp=" << leftExp << " rightExp=" << rightExp << endl;)  LAZYDEBUG(cout << "LeftExp=" << leftExp << " rightExp=" << rightExp << endl;)
1293  LAZYDEBUG(cout << "LeftR=" << m_left->getRank() << " rightExp=" << m_right->getRank() << endl;)  LAZYDEBUG(cout << "LeftR=" << m_left->getRank() << " rightExp=" << m_right->getRank() << endl;)
1294  LAZYDEBUG(cout << "LeftSize=" << m_left->getNoValues() << " RightSize=" << m_right->getNoValues() << endl;)  LAZYDEBUG(cout << "LeftSize=" << m_left->getNoValues() << " RightSize=" << m_right->getNoValues() << endl;)
1295  LAZYDEBUG(cout << "m_samplesize=" << m_samplesize << endl;)  LAZYDEBUG(cout << "m_samplesize=" << m_samplesize << endl;)
1296  LAZYDEBUG(cout << "outputshape=" << DataTypes::shapeToString(getShape()) << endl;)  LAZYDEBUG(cout << "outputshape=" << DataTypes::shapeToString(getShape()) << endl;)
1297    LAZYDEBUG(cout << "DPPS=" << m_right->getNumDPPSample() <<"."<<endl;)
1298    
1299    double* resultp=&(v[offset]);     // results are stored at the vector offset we recieved    double* resultp=&(v[offset]);     // results are stored at the vector offset we recieved
1300    switch(m_op)    switch(m_op)
1301    {    {
# Line 1257  LAZYDEBUG(cout << "m_SL=" << m_SL << " m Line 1310  LAZYDEBUG(cout << "m_SL=" << m_SL << " m
1310  LAZYDEBUG(cout << DataTypes::pointToString(*left, m_left->getShape(),lroffset,"LEFT") << endl;)  LAZYDEBUG(cout << DataTypes::pointToString(*left, m_left->getShape(),lroffset,"LEFT") << endl;)
1311  LAZYDEBUG(cout << DataTypes::pointToString(*right,m_right->getShape(),rroffset, "RIGHT") << endl;)  LAZYDEBUG(cout << DataTypes::pointToString(*right,m_right->getShape(),rroffset, "RIGHT") << endl;)
1312            matrix_matrix_product(m_SL, m_SM, m_SR, ptr_0, ptr_1, resultp, m_transpose);            matrix_matrix_product(m_SL, m_SM, m_SR, ptr_0, ptr_1, resultp, m_transpose);
1313    LAZYDEBUG(cout << "Results--\n";
1314    for (int z=0;z<getNoValues();++z)
1315    {
1316    cout << resultp[z] << " ";
1317    }
1318    cout << "\nWritten to: " << resultp << " resultStep=" << resultStep << endl;
1319    )
1320        lroffset+=leftStep;        lroffset+=leftStep;
1321        rroffset+=rightStep;        rroffset+=rightStep;
1322      }      }
# Line 1431  DataLazy::toString() const Line 1491  DataLazy::toString() const
1491  void  void
1492  DataLazy::intoString(ostringstream& oss) const  DataLazy::intoString(ostringstream& oss) const
1493  {  {
1494    oss << "[" << m_children <<";"<<m_height <<"]";  //   oss << "[" << m_children <<";"<<m_height <<"]";
1495    switch (getOpgroup(m_op))    switch (getOpgroup(m_op))
1496    {    {
1497    case G_IDENTITY:    case G_IDENTITY:

Legend:
Removed from v.2177  
changed lines
  Added in v.2195

  ViewVC Help
Powered by ViewVC 1.1.26