/[escript]/trunk/escript/src/Data.cpp
ViewVC logotype

Diff of /trunk/escript/src/Data.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2460 by jfenwick, Thu Jun 4 06:17:54 2009 UTC revision 2461 by jfenwick, Fri Jun 5 05:06:31 2009 UTC
# Line 1077  const boost::python::object Line 1077  const boost::python::object
1077  Data::toListOfTuples(bool scalarastuple)  Data::toListOfTuples(bool scalarastuple)
1078  {  {
1079      using namespace boost::python;      using namespace boost::python;
1080        using boost::python::list;
1081      if (get_MPISize()>1)      if (get_MPISize()>1)
1082      {      {
1083          throw DataException("::toListOfTuples is not available for MPI with more than one process.");          throw DataException("::toListOfTuples is not available for MPI with more than one process.");
1084      }      }
1085      unsigned int rank=getDataPointRank();      unsigned int rank=getDataPointRank();
1086      unsigned int size=getDataPointSize();      unsigned int size=getDataPointSize();
1087      boost::python::list res;  
1088      int npoints=getNumDataPoints();      int npoints=getNumDataPoints();
1089      expand();           // This will also resolve if required      expand();           // This will also resolve if required
1090      const DataTypes::ValueType& vec=getReady()->getVectorRO();      const DataTypes::ValueType& vec=getReady()->getVectorRO();
1091        boost::python::list temp;
1092        temp.append(object());
1093        boost::python::list res(temp*npoints);// presize the list by the "[None] * npoints"  trick
1094      if (rank==0)      if (rank==0)
1095      {      {
1096          long count;          long count;
# Line 1094  Data::toListOfTuples(bool scalarastuple) Line 1098  Data::toListOfTuples(bool scalarastuple)
1098          {          {
1099              for (count=0;count<npoints;++count)              for (count=0;count<npoints;++count)
1100              {              {
1101                  res.append(make_tuple(vec[count]));          res[count]=make_tuple(vec[count]);
1102              }              }
1103          }          }
1104          else          else
1105          {          {
1106              for (count=0;count<npoints;++count)              for (count=0;count<npoints;++count)
1107              {              {
1108                  res.append(vec[count]);                  res[count]=vec[count];
1109              }              }
1110          }          }
1111      }      }
# Line 1111  Data::toListOfTuples(bool scalarastuple) Line 1115  Data::toListOfTuples(bool scalarastuple)
1115          size_t offset=0;          size_t offset=0;
1116          for (count=0;count<npoints;++count,offset+=size)          for (count=0;count<npoints;++count,offset+=size)
1117          {          {
1118          // need to pull a pointer to the start of the element (also need a way to skip to the next element)              res[count]=pointToTuple1(getDataPointShape(), vec, offset);
             res.append(pointToTuple1(getDataPointShape(), vec, offset));  
1119          }          }
1120      }      }
1121      else if (rank==2)      else if (rank==2)
# Line 1121  Data::toListOfTuples(bool scalarastuple) Line 1124  Data::toListOfTuples(bool scalarastuple)
1124          size_t offset=0;          size_t offset=0;
1125          for (count=0;count<npoints;++count,offset+=size)          for (count=0;count<npoints;++count,offset+=size)
1126          {          {
1127          // need to pull a pointer to the start of the element (also need a way to skip to the next element)          res[count]=pointToTuple2(getDataPointShape(), vec, offset);
             res.append(pointToTuple2(getDataPointShape(), vec, offset));  
1128          }          }
1129      }      }
1130      else if (rank==3)      else if (rank==3)
# Line 1131  Data::toListOfTuples(bool scalarastuple) Line 1133  Data::toListOfTuples(bool scalarastuple)
1133          size_t offset=0;          size_t offset=0;
1134          for (count=0;count<npoints;++count,offset+=size)          for (count=0;count<npoints;++count,offset+=size)
1135          {          {
1136          // need to pull a pointer to the start of the element (also need a way to skip to the next element)              res[count]=pointToTuple3(getDataPointShape(), vec, offset);
             res.append(pointToTuple3(getDataPointShape(), vec, offset));  
1137          }          }
1138      }      }
1139      else if (rank==4)      else if (rank==4)
# Line 1141  Data::toListOfTuples(bool scalarastuple) Line 1142  Data::toListOfTuples(bool scalarastuple)
1142          size_t offset=0;          size_t offset=0;
1143          for (count=0;count<npoints;++count,offset+=size)          for (count=0;count<npoints;++count,offset+=size)
1144          {          {
1145          // need to pull a pointer to the start of the element (also need a way to skip to the next element)              res[count]=pointToTuple4(getDataPointShape(), vec, offset);
             res.append(pointToTuple4(getDataPointShape(), vec, offset));  
1146          }          }
1147      }      }
1148      else      else

Legend:
Removed from v.2460  
changed lines
  Added in v.2461

  ViewVC Help
Powered by ViewVC 1.1.26