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

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

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

revision 123 by jgs, Fri Jul 8 04:08:13 2005 UTC revision 126 by jgs, Fri Jul 22 03:53:08 2005 UTC
# Line 477  Data::getDataPointShape() const Line 477  Data::getDataPointShape() const
477    return getPointDataView().getShape();    return getPointDataView().getShape();
478  }  }
479    
480    void
481    Data::fillFromNumArray(const boost::python::numeric::array num_array)
482    {
483      //
484      // check rank:
485      if (num_array.getrank()<getDataPointRank())
486          throw DataException("Rank of numarray does not match Data object rank");
487      //
488      // check rank of num_array
489      for (int i=0; i<getDataPointRank(); i++) {
490        if (extract<int>(num_array.getshape()[i+1])!=getDataPointShape()[i])
491           throw DataException("Shape of numarray does not match Data object rank");
492      }
493      //
494      // make sure data is expanded:
495      if (! isExpanded()) expand();
496      //
497      // and copy over:
498      m_data->copyAll(num_array);
499      //
500      // the rank of the returned numeric array will be the rank of
501      // the data points, plus one. Where the rank of the array is n,
502      // the last n-1 dimensions will be equal to the shape of the
503      // data points, whilst the first dimension will be equal to the
504      // total number of data points. Thus the array will consist of
505      // a serial vector of the data points.
506      // int arrayRank = dataPointRank + 1;
507      // DataArrayView::ShapeType arrayShape;
508      // arrayShape.push_back(numDataPoints);
509      // for (int d=0; d<dataPointRank; d++) {
510      //    arrayShape.push_back(dataPointShape[d]);
511      // }
512    
513      //
514      // resize the numeric array to the shape just calculated
515      // if (arrayRank==1) {
516      //   numArray.resize(arrayShape[0]);
517      // }
518      // if (arrayRank==2) {
519      //   numArray.resize(arrayShape[0],arrayShape[1]);
520      // }
521      // if (arrayRank==3) {
522      //   numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2]);
523      // }
524      // if (arrayRank==4) {
525      //   numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);
526      // }
527      // if (arrayRank==5) {
528      //   numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3],arrayShape[4]);
529      // }
530    
531      //
532      // loop through each data point in turn, loading the values for that data point
533      // into the numeric array.
534      // int dataPoint = 0;
535      // for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {
536      //   for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
537      //     DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
538      //     if (dataPointRank==0) {
539      //       dataPointView()=numArray[dataPoint];
540      //     }
541      //     if (dataPointRank==1) {
542      //       for (int i=0; i<dataPointShape[0]; i++) {
543      //         dataPointView(i)=numArray[dataPoint][i];
544      //       }
545      //     }
546      //     if (dataPointRank==2) {
547      //       for (int i=0; i<dataPointShape[0]; i++) {
548      //         for (int j=0; j<dataPointShape[1]; j++) {
549      //           numArray[dataPoint][i][j] = dataPointView(i,j);
550      //         }
551      //       }
552      //     }
553      //     if (dataPointRank==3) {
554      //       for (int i=0; i<dataPointShape[0]; i++) {
555      //         for (int j=0; j<dataPointShape[1]; j++) {
556      //           for (int k=0; k<dataPointShape[2]; k++) {
557      //             numArray[dataPoint][i][j][k]=dataPointView(i,j,k);
558      //           }
559      //         }
560      //       }
561      //     }
562      //     if (dataPointRank==4) {
563      //       for (int i=0; i<dataPointShape[0]; i++) {
564      //         for (int j=0; j<dataPointShape[1]; j++) {
565      //           for (int k=0; k<dataPointShape[2]; k++) {
566      //             for (int l=0; l<dataPointShape[3]; l++) {
567      //               numArray[dataPoint][i][j][k][l]=dataPointView(i,j,k,l);
568      //             }
569      //           }
570      //         }
571      //       }
572      //     }
573      //     dataPoint++;
574      //   }
575      // }
576    
577      //
578      // return the loaded array
579      // return numArray;
580    
581    }
582    
583  const  const
584  boost::python::numeric::array  boost::python::numeric::array
585  Data::convertToNumArray()  Data::convertToNumArray()
# Line 1496  Data::getRefValue(int ref, Line 1599  Data::getRefValue(int ref,
1599    DataArrayView valueView = valueDataArray.getView();    DataArrayView valueView = valueDataArray.getView();
1600    
1601    if (rank==0) {    if (rank==0) {
1602      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");        boost::python::numeric::array temp_numArray(valueView());
1603          value = temp_numArray;
1604    }    }
1605    if (rank==1) {    if (rank==1) {
1606      for (int i=0; i < shape[0]; i++) {      for (int i=0; i < shape[0]; i++) {
# Line 1504  Data::getRefValue(int ref, Line 1608  Data::getRefValue(int ref,
1608      }      }
1609    }    }
1610    if (rank==2) {    if (rank==2) {
1611      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");      for (int i=0; i < shape[0]; i++) {
1612          for (int j=0; j < shape[1]; j++) {
1613            value[i][j] = valueView(i,j);
1614          }
1615        }
1616    }    }
1617    if (rank==3) {    if (rank==3) {
1618      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");      for (int i=0; i < shape[0]; i++) {
1619          for (int j=0; j < shape[1]; j++) {
1620            for (int k=0; k < shape[2]; k++) {
1621              value[i][j][k] = valueView(i,j,k);
1622            }
1623          }
1624        }
1625    }    }
1626    if (rank==4) {    if (rank==4) {
1627      throw DataException("Data::getRefValue error: only rank 1 data handled for now.");      for (int i=0; i < shape[0]; i++) {
1628          for (int j=0; j < shape[1]; j++) {
1629            for (int k=0; k < shape[2]; k++) {
1630              for (int l=0; l < shape[3]; l++) {
1631                value[i][j][k][l] = valueView(i,j,k,l);
1632              }
1633            }
1634          }
1635        }
1636    }    }
1637    
1638  }  }
# Line 1848  Data::extractData(const std::string file Line 1970  Data::extractData(const std::string file
1970    }    }
1971    shared_ptr<DataAbstract> temp_data(tempData);    shared_ptr<DataAbstract> temp_data(tempData);
1972    m_data=temp_data;    m_data=temp_data;
   
1973  }  }
1974    
1975  ostream& escript::operator<<(ostream& o, const Data& data)  ostream& escript::operator<<(ostream& o, const Data& data)

Legend:
Removed from v.123  
changed lines
  Added in v.126

  ViewVC Help
Powered by ViewVC 1.1.26