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

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

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

revision 615 by elspeth, Wed Mar 22 02:12:00 2006 UTC revision 921 by gross, Fri Jan 5 00:54:37 2007 UTC
# Line 154  DataExpanded::~DataExpanded() Line 154  DataExpanded::~DataExpanded()
154  {  {
155  }  }
156    
 void  
 DataExpanded::reshapeDataPoint(const DataArrayView::ShapeType& shape)  
 {  
   if (getPointDataView().getRank()!=0) {  
     stringstream temp;  
     temp << "Error - Can only reshape Data with data points of rank 0. "  
          << "This Data has data points with rank: "  
          << getPointDataView().getRank();  
     throw DataException(temp.str());  
   }  
   //  
   // create the new DataBlocks2D data array, and a corresponding DataArrayView  
   DataBlocks2D newData(getNumSamples(),getNumDPPSample(),DataArrayView::noValues(shape));  
   DataArrayView newView(newData.getData(),shape);  
   //  
   // Copy the original data to every value for the new shape  
   int i,j;  
   int nRows=m_data.getNumRows();  
   int nCols=m_data.getNumCols();  
   #pragma omp parallel for private(i,j) schedule(static)  
   for (i=0;i<nRows;i++) {  
     for (j=0;j<nCols;j++) {  
       // NOTE: An exception may be thown from this call if  
       // DOASSERT is on which of course will play  
       // havoc with the omp threads. Run single threaded  
       // if using DOASSERT.  
       newView.copy(newData.index(i,j),m_data(i,j));  
     }  
   }  
   // swap the new data array for the original  
   m_data.Swap(newData);  
   // set the corresponding DataArrayView  
   DataArrayView temp(m_data.getData(),shape);  
   setPointDataView(temp);  
 }  
   
157  DataAbstract*  DataAbstract*
158  DataExpanded::getSlice(const DataArrayView::RegionType& region) const  DataExpanded::getSlice(const DataArrayView::RegionType& region) const
159  {  {
# Line 213  DataExpanded::setSlice(const DataAbstrac Line 177  DataExpanded::setSlice(const DataAbstrac
177    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
178      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
179    }    }
180    if (tempDataExp->getPointDataView().getRank()>0 and !value->getPointDataView().checkShape(shape)) {    if (tempDataExp->getPointDataView().getRank()>0 && !value->getPointDataView().checkShape(shape)) {
181      throw DataException (value->getPointDataView().createShapeErrorMessage(      throw DataException (value->getPointDataView().createShapeErrorMessage(
182          "Error - Couldn't copy slice due to shape mismatch.",shape));          "Error - Couldn't copy slice due to shape mismatch.",shape));
183    }    }
# Line 289  string Line 253  string
253  DataExpanded::toString() const  DataExpanded::toString() const
254  {  {
255    stringstream temp;    stringstream temp;
256      FunctionSpace fs=getFunctionSpace();
257    //    //
258    // create a temporary view as the offset will be changed    // create a temporary view as the offset will be changed
259    DataArrayView tempView(getPointDataView().getData(),getPointDataView().getShape(),getPointDataView().getOffset());    DataArrayView tempView(getPointDataView().getData(),getPointDataView().getShape(),getPointDataView().getOffset());
# Line 296  DataExpanded::toString() const Line 261  DataExpanded::toString() const
261      for (int j=0;j<m_data.getNumCols();j++) {      for (int j=0;j<m_data.getNumCols();j++) {
262        tempView.setOffset(m_data.index(i,j));        tempView.setOffset(m_data.index(i,j));
263        stringstream suffix;        stringstream suffix;
264        suffix << "(" << i << "," << j << ")";        suffix << "( id: " << i << ", ref: " << fs.getReferenceNoFromSampleNo(i) << ", pnt: " << j << ")";
265        temp << tempView.toString(suffix.str());        temp << tempView.toString(suffix.str());
266        if (!(i==(m_data.getNumRows()-1) && j==(m_data.getNumCols()-1))) {        if (!(i==(m_data.getNumRows()-1) && j==(m_data.getNumCols()-1))) {
267          temp << endl;          temp << endl;
# Line 408  DataExpanded::extractData(ifstream& arch Line 373  DataExpanded::extractData(ifstream& arch
373    return(m_data.extractData(archiveFile, noValues));    return(m_data.extractData(archiveFile, noValues));
374  }  }
375    
376    void
377    DataExpanded::copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value) {
378      //
379      // Get the number of samples and data-points per sample.
380      int numSamples = getNumSamples();
381      int numDataPointsPerSample = getNumDPPSample();
382      int dataPointRank = getPointDataView().getRank();
383      ShapeType dataPointShape = getPointDataView().getShape();
384      //
385      // check rank:
386      if (value.getrank()!=dataPointRank)
387           throw DataException("Rank of numarray does not match Data object rank");
388      if (numSamples*numDataPointsPerSample > 0) {
389         //TODO: global error handling
390         if (sampleNo >= numSamples or sampleNo < 0 ) {
391              throw DataException("Error - DataExpanded::copyDataPoint invalid sampleNo.");
392         }
393         if (dataPointNo >= numDataPointsPerSample or dataPointNo < 0) {
394               throw DataException("Error - DataExpanded::copyDataPoint invalid dataPointNoInSample.");
395         }
396         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
397         if (dataPointRank==0) {
398             dataPointView()=extract<double>(value[0]);
399         } else if (dataPointRank==1) {
400            for (int i=0; i<dataPointShape[0]; i++) {
401                dataPointView(i)=extract<double>(value[i]);
402            }
403         } else if (dataPointRank==2) {
404            for (int i=0; i<dataPointShape[0]; i++) {
405               for (int j=0; j<dataPointShape[1]; j++) {
406                  dataPointView(i,j)=extract<double>(value[i][j]);
407               }
408            }
409         } else if (dataPointRank==3) {
410            for (int i=0; i<dataPointShape[0]; i++) {
411               for (int j=0; j<dataPointShape[1]; j++) {
412                  for (int k=0; k<dataPointShape[2]; k++) {
413                     dataPointView(i,j,k)=extract<double>(value[i][j][k]);
414                  }
415               }
416            }
417         } else if (dataPointRank==4) {
418             for (int i=0; i<dataPointShape[0]; i++) {
419               for (int j=0; j<dataPointShape[1]; j++) {
420                 for (int k=0; k<dataPointShape[2]; k++) {
421                   for (int l=0; l<dataPointShape[3]; l++) {
422                      dataPointView(i,j,k,l)=extract<double>(value[i][j][k][l]);
423                   }
424                 }
425               }
426             }
427         }
428      }
429    }
430  void  void
431  DataExpanded::copyAll(const boost::python::numeric::array& value) {  DataExpanded::copyAll(const boost::python::numeric::array& value) {
432    //    //
# Line 462  DataExpanded::copyAll(const boost::pytho Line 481  DataExpanded::copyAll(const boost::pytho
481      }      }
482    }    }
483  }  }
484    void
485    DataExpanded::symmetric(DataAbstract* ev)
486    {
487      int sampleNo,dataPointNo;
488      int numSamples = getNumSamples();
489      int numDataPointsPerSample = getNumDPPSample();
490      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
491      if (temp_ev==0) {
492        throw DataException("Error - DataExpanded::symmetric: casting to DataExpanded failed (propably a programming error).");
493      }
494      DataArrayView& thisView=getPointDataView();
495      DataArrayView& evView=ev->getPointDataView();
496      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
497      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
498        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
499             DataArrayView::symmetric(thisView,getPointOffset(sampleNo,dataPointNo),
500                                        evView,ev->getPointOffset(sampleNo,dataPointNo));
501        }
502      }
503    }
504    void
505    DataExpanded::nonsymmetric(DataAbstract* ev)
506    {
507      int sampleNo,dataPointNo;
508      int numSamples = getNumSamples();
509      int numDataPointsPerSample = getNumDPPSample();
510      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
511      if (temp_ev==0) {
512        throw DataException("Error - DataExpanded::nonsymmetric: casting to DataExpanded failed (propably a programming error).");
513      }
514      DataArrayView& thisView=getPointDataView();
515      DataArrayView& evView=ev->getPointDataView();
516      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
517      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
518        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
519             DataArrayView::nonsymmetric(thisView,getPointOffset(sampleNo,dataPointNo),
520                                        evView,ev->getPointOffset(sampleNo,dataPointNo));
521        }
522      }
523    }
524    void
525    DataExpanded::trace(DataAbstract* ev, int axis_offset)
526    {
527      int sampleNo,dataPointNo;
528      int numSamples = getNumSamples();
529      int numDataPointsPerSample = getNumDPPSample();
530      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
531      if (temp_ev==0) {
532        throw DataException("Error - DataExpanded::trace: casting to DataExpanded failed (propably a programming error).");
533      }
534      DataArrayView& thisView=getPointDataView();
535      DataArrayView& evView=ev->getPointDataView();
536      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
537      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
538        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
539             DataArrayView::trace(thisView,getPointOffset(sampleNo,dataPointNo),
540                                        evView,ev->getPointOffset(sampleNo,dataPointNo),axis_offset);
541        }
542      }
543    }
544    
545    void
546    DataExpanded::transpose(DataAbstract* ev, int axis_offset)
547    {
548      int sampleNo,dataPointNo;
549      int numSamples = getNumSamples();
550      int numDataPointsPerSample = getNumDPPSample();
551      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
552      if (temp_ev==0) {
553        throw DataException("Error - DataExpanded::transpose: casting to DataExpanded failed (propably a programming error).");
554      }
555      DataArrayView& thisView=getPointDataView();
556      DataArrayView& evView=ev->getPointDataView();
557      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
558      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
559        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
560             DataArrayView::transpose(thisView,getPointOffset(sampleNo,dataPointNo),
561                                        evView,ev->getPointOffset(sampleNo,dataPointNo),axis_offset);
562        }
563      }
564    }
565    
566    void
567    DataExpanded::swapaxes(DataAbstract* ev, int axis0, int axis1)
568    {
569      int sampleNo,dataPointNo;
570      int numSamples = getNumSamples();
571      int numDataPointsPerSample = getNumDPPSample();
572      DataExpanded* temp_ev=dynamic_cast<DataExpanded*>(ev);
573      if (temp_ev==0) {
574        throw DataException("Error - DataExpanded::swapaxes: casting to DataExpanded failed (propably a programming error).");
575      }
576      DataArrayView& thisView=getPointDataView();
577      DataArrayView& evView=ev->getPointDataView();
578      #pragma omp parallel for private(sampleNo,dataPointNo) schedule(static)
579      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
580        for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
581             DataArrayView::swapaxes(thisView,getPointOffset(sampleNo,dataPointNo),
582                                        evView,ev->getPointOffset(sampleNo,dataPointNo),axis0,axis1);
583        }
584      }
585    }
586  void  void
587  DataExpanded::eigenvalues(DataAbstract* ev)  DataExpanded::eigenvalues(DataAbstract* ev)
588  {  {

Legend:
Removed from v.615  
changed lines
  Added in v.921

  ViewVC Help
Powered by ViewVC 1.1.26