/[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 113 by jgs, Mon Feb 28 07:06:33 2005 UTC revision 117 by jgs, Fri Apr 1 05:48:57 2005 UTC
# Line 444  Data::getDataPointShape() const Line 444  Data::getDataPointShape() const
444  }  }
445    
446  boost::python::numeric::array  boost::python::numeric::array
447    Data::convertToNumArray()
448    {
449      //
450      // determine the current number of data points
451      int numSamples = getNumSamples();
452      int numDataPointsPerSample = getNumDataPointsPerSample();
453      int numDataPoints = numSamples * numDataPointsPerSample;
454    
455      //
456      // determine the rank and shape of each data point
457      int dataPointRank = getDataPointRank();
458      DataArrayView::ShapeType dataPointShape = getDataPointShape();
459    
460      //
461      // create the numeric array to be returned
462      boost::python::numeric::array numArray(0.0);
463    
464      //
465      // the rank of the returned numeric array will be the rank of
466      // the data points, plus one. Where the rank of the array is n,
467      // the last n-1 dimensions will be equal to the shape of the
468      // data points, whilst the first dimension will be equal to the
469      // total number of data points. Thus the array will consist of
470      // a serial vector of the data points.
471      int arrayRank = dataPointRank + 1;
472      DataArrayView::ShapeType arrayShape;
473      arrayShape.push_back(numDataPoints);
474      for (int d=0; d<dataPointRank; d++) {
475         arrayShape.push_back(dataPointShape[d]);
476      }
477    
478      //
479      // resize the numeric array to the shape just calculated
480      if (arrayRank==1) {
481        numArray.resize(arrayShape[0]);
482      }
483      if (arrayRank==2) {
484        numArray.resize(arrayShape[0],arrayShape[1]);
485      }
486      if (arrayRank==3) {
487        numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2]);
488      }
489      if (arrayRank==4) {
490        numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);
491      }
492      if (arrayRank==5) {
493        numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3],arrayShape[4]);
494      }
495    
496      //
497      // loop through each data point in turn, loading the values for that data point
498      // into the numeric array.
499      int dataPoint = 0;
500      for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {
501        for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
502    
503          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
504    
505          if (dataPointRank==0) {
506            numArray[dataPoint]=dataPointView();
507          }
508    
509          if (dataPointRank==1) {
510            for (int i=0; i<dataPointShape[0]; i++) {
511              numArray[dataPoint][i]=dataPointView(i);
512            }
513          }
514    
515          if (dataPointRank==2) {
516            for (int i=0; i<dataPointShape[0]; i++) {
517              for (int j=0; j<dataPointShape[1]; j++) {
518                numArray[dataPoint][i][j] = dataPointView(i,j);
519              }
520            }
521          }
522    
523          if (dataPointRank==3) {
524            for (int i=0; i<dataPointShape[0]; i++) {
525              for (int j=0; j<dataPointShape[1]; j++) {
526                for (int k=0; k<dataPointShape[2]; k++) {
527                  numArray[dataPoint][i][j][k]=dataPointView(i,j,k);
528                }
529              }
530            }
531          }
532    
533          if (dataPointRank==4) {
534            for (int i=0; i<dataPointShape[0]; i++) {
535              for (int j=0; j<dataPointShape[1]; j++) {
536                for (int k=0; k<dataPointShape[2]; k++) {
537                  for (int l=0; l<dataPointShape[3]; l++) {
538                    numArray[dataPoint][i][j][k][l]=dataPointView(i,j,k,l);
539                  }
540                }
541              }
542            }
543          }
544    
545          dataPoint++;
546    
547        }
548      }
549    
550      //
551      // return the loaded array
552      return numArray;
553    }
554    
555    boost::python::numeric::array
556  Data::integrate() const  Data::integrate() const
557  {  {
558    int index;    int index;
# Line 585  Data::Lsup() const Line 694  Data::Lsup() const
694  }  }
695    
696  double  double
697    Data::Linf() const
698    {
699      //
700      // set the initial absolute minimum value to max double
701      return algorithm(DataAlgorithmAdapter<AbsMin>(numeric_limits<double>::max()));
702    }
703    
704    double
705  Data::sup() const  Data::sup() const
706  {  {
707    //    //

Legend:
Removed from v.113  
changed lines
  Added in v.117

  ViewVC Help
Powered by ViewVC 1.1.26