/[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 922 by gross, Fri Jan 5 04:23:05 2007 UTC revision 1092 by gross, Fri Apr 13 03:39:49 2007 UTC
# Line 38  using namespace boost::python; Line 38  using namespace boost::python;
38  using namespace boost;  using namespace boost;
39  using namespace escript;  using namespace escript;
40    
 #if defined DOPROF  
 //  
 // global table of profiling data for all Data objects  
 DataProf dataProfTable;  
 #endif  
   
41  Data::Data()  Data::Data()
42  {  {
43    //    //
# Line 52  Data::Data() Line 46  Data::Data()
46    shared_ptr<DataAbstract> temp_data(temp);    shared_ptr<DataAbstract> temp_data(temp);
47    m_data=temp_data;    m_data=temp_data;
48    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
49  }  }
50    
51  Data::Data(double value,  Data::Data(double value,
# Line 70  Data::Data(double value, Line 60  Data::Data(double value,
60    DataArray temp(dataPointShape,value);    DataArray temp(dataPointShape,value);
61    initialise(temp.getView(),what,expanded);    initialise(temp.getView(),what,expanded);
62    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
63  }  }
64    
65  Data::Data(double value,  Data::Data(double value,
# Line 85  Data::Data(double value, Line 71  Data::Data(double value,
71    pair<int,int> dataShape=what.getDataShape();    pair<int,int> dataShape=what.getDataShape();
72    initialise(temp.getView(),what,expanded);    initialise(temp.getView(),what,expanded);
73    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
74  }  }
75    
76  Data::Data(const Data& inData)  Data::Data(const Data& inData)
77  {  {
78    m_data=inData.m_data;    m_data=inData.m_data;
79    m_protected=inData.isProtected();    m_protected=inData.isProtected();
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
80  }  }
81    
82  Data::Data(const Data& inData,  Data::Data(const Data& inData,
# Line 110  Data::Data(const Data& inData, Line 88  Data::Data(const Data& inData,
88    shared_ptr<DataAbstract> temp_data(tmp);    shared_ptr<DataAbstract> temp_data(tmp);
89    m_data=temp_data;    m_data=temp_data;
90    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
91  }  }
92    
93  Data::Data(const Data& inData,  Data::Data(const Data& inData,
94             const FunctionSpace& functionspace)             const FunctionSpace& functionspace)
95  {  {
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
96    if (inData.getFunctionSpace()==functionspace) {    if (inData.getFunctionSpace()==functionspace) {
97      m_data=inData.m_data;      m_data=inData.m_data;
98    } else {    } else {
     #if defined DOPROF  
     profData->interpolate++;  
     #endif  
99      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);
100      // Note: Must use a reference or pointer to a derived object      // Note: Must use a reference or pointer to a derived object
101      // in order to get polymorphic behaviour. Shouldn't really      // in order to get polymorphic behaviour. Shouldn't really
# Line 158  Data::Data(const DataTagged::TagListType Line 125  Data::Data(const DataTagged::TagListType
125    if (expanded) {    if (expanded) {
126      expand();      expand();
127    }    }
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
128  }  }
129    
130  Data::Data(const numeric::array& value,  Data::Data(const numeric::array& value,
# Line 170  Data::Data(const numeric::array& value, Line 133  Data::Data(const numeric::array& value,
133  {  {
134    initialise(value,what,expanded);    initialise(value,what,expanded);
135    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
136  }  }
137    
138  Data::Data(const DataArrayView& value,  Data::Data(const DataArrayView& value,
# Line 182  Data::Data(const DataArrayView& value, Line 141  Data::Data(const DataArrayView& value,
141  {  {
142    initialise(value,what,expanded);    initialise(value,what,expanded);
143    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
144  }  }
145    
146  Data::Data(const object& value,  Data::Data(const object& value,
# Line 195  Data::Data(const object& value, Line 150  Data::Data(const object& value,
150    numeric::array asNumArray(value);    numeric::array asNumArray(value);
151    initialise(asNumArray,what,expanded);    initialise(asNumArray,what,expanded);
152    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
153  }  }
154    
155  Data::Data(const object& value,  Data::Data(const object& value,
# Line 220  Data::Data(const object& value, Line 171  Data::Data(const object& value,
171      initialise(temp.getView(),other.getFunctionSpace(),false);      initialise(temp.getView(),other.getFunctionSpace(),false);
172    }    }
173    m_protected=false;    m_protected=false;
 #if defined DOPROF  
   // create entry in global profiling table for this object  
   profData = dataProfTable.newData();  
 #endif  
174  }  }
175    
176  Data::~Data()  Data::~Data()
# Line 423  Data::tag() Line 370  Data::tag()
370  Data  Data
371  Data::oneOver() const  Data::oneOver() const
372  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
373    return escript::unaryOp(*this,bind1st(divides<double>(),1.));    return escript::unaryOp(*this,bind1st(divides<double>(),1.));
374  }  }
375    
376  Data  Data
377  Data::wherePositive() const  Data::wherePositive() const
378  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
379    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));
380  }  }
381    
382  Data  Data
383  Data::whereNegative() const  Data::whereNegative() const
384  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
385    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));
386  }  }
387    
388  Data  Data
389  Data::whereNonNegative() const  Data::whereNonNegative() const
390  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
391    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));
392  }  }
393    
394  Data  Data
395  Data::whereNonPositive() const  Data::whereNonPositive() const
396  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
397    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));
398  }  }
399    
400  Data  Data
401  Data::whereZero(double tol) const  Data::whereZero(double tol) const
402  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
403    Data dataAbs=abs();    Data dataAbs=abs();
404    return escript::unaryOp(dataAbs,bind2nd(less_equal<double>(),tol));    return escript::unaryOp(dataAbs,bind2nd(less_equal<double>(),tol));
405  }  }
# Line 478  Data::whereZero(double tol) const Line 407  Data::whereZero(double tol) const
407  Data  Data
408  Data::whereNonZero(double tol) const  Data::whereNonZero(double tol) const
409  {  {
 #if defined DOPROF  
   profData->where++;  
 #endif  
410    Data dataAbs=abs();    Data dataAbs=abs();
411    return escript::unaryOp(dataAbs,bind2nd(greater<double>(),tol));    return escript::unaryOp(dataAbs,bind2nd(greater<double>(),tol));
412  }  }
# Line 488  Data::whereNonZero(double tol) const Line 414  Data::whereNonZero(double tol) const
414  Data  Data
415  Data::interpolate(const FunctionSpace& functionspace) const  Data::interpolate(const FunctionSpace& functionspace) const
416  {  {
 #if defined DOPROF  
   profData->interpolate++;  
 #endif  
417    return Data(*this,functionspace);    return Data(*this,functionspace);
418  }  }
419    
# Line 512  Data::probeInterpolation(const FunctionS Line 435  Data::probeInterpolation(const FunctionS
435  Data  Data
436  Data::gradOn(const FunctionSpace& functionspace) const  Data::gradOn(const FunctionSpace& functionspace) const
437  {  {
 #if defined DOPROF  
   profData->grad++;  
 #endif  
438    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
439      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
440    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();
# Line 550  Data::getDataPointShape() const Line 470  Data::getDataPointShape() const
470    
471    
472    
 void  
 Data::fillFromNumArray(const boost::python::numeric::array num_array)  
 {  
   if (isProtected()) {  
         throw DataException("Error - attempt to update protected Data object.");  
   }  
   //  
   // check rank  
   if (num_array.getrank()<getDataPointRank())  
       throw DataException("Rank of numarray does not match Data object rank");  
   
   //  
   // check shape of num_array  
   for (int i=0; i<getDataPointRank(); i++) {  
     if (extract<int>(num_array.getshape()[i+1])!=getDataPointShape()[i])  
        throw DataException("Shape of numarray does not match Data object rank");  
   }  
   
   //  
   // make sure data is expanded:  
   if (!isExpanded()) {  
     expand();  
   }  
   
   //  
   // and copy over  
   m_data->copyAll(num_array);  
 }  
   
 const  
 boost::python::numeric::array  
 Data::convertToNumArray()  
 {  
   //  
   // determine the total number of data points  
   int numSamples = getNumSamples();  
   int numDataPointsPerSample = getNumDataPointsPerSample();  
   int numDataPoints = numSamples * numDataPointsPerSample;  
   
   //  
   // determine the rank and shape of each data point  
   int dataPointRank = getDataPointRank();  
   DataArrayView::ShapeType dataPointShape = getDataPointShape();  
   
   //  
   // create the numeric array to be returned  
   boost::python::numeric::array numArray(0.0);  
   
   //  
   // the rank of the returned numeric array will be the rank of  
   // the data points, plus one. Where the rank of the array is n,  
   // the last n-1 dimensions will be equal to the shape of the  
   // data points, whilst the first dimension will be equal to the  
   // total number of data points. Thus the array will consist of  
   // a serial vector of the data points.  
   int arrayRank = dataPointRank + 1;  
   DataArrayView::ShapeType arrayShape;  
   arrayShape.push_back(numDataPoints);  
   for (int d=0; d<dataPointRank; d++) {  
      arrayShape.push_back(dataPointShape[d]);  
   }  
   
   //  
   // resize the numeric array to the shape just calculated  
   if (arrayRank==1) {  
     numArray.resize(arrayShape[0]);  
   }  
   if (arrayRank==2) {  
     numArray.resize(arrayShape[0],arrayShape[1]);  
   }  
   if (arrayRank==3) {  
     numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2]);  
   }  
   if (arrayRank==4) {  
     numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3]);  
   }  
   if (arrayRank==5) {  
     numArray.resize(arrayShape[0],arrayShape[1],arrayShape[2],arrayShape[3],arrayShape[4]);  
   }  
   
   //  
   // loop through each data point in turn, loading the values for that data point  
   // into the numeric array.  
   int dataPoint = 0;  
   for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {  
     for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {  
       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);  
       if (dataPointRank==0) {  
         numArray[dataPoint]=dataPointView();  
       }  
       if (dataPointRank==1) {  
         for (int i=0; i<dataPointShape[0]; i++) {  
           numArray[make_tuple(dataPoint,i)]=dataPointView(i);  
         }  
       }  
       if (dataPointRank==2) {  
         for (int i=0; i<dataPointShape[0]; i++) {  
           for (int j=0; j<dataPointShape[1]; j++) {  
             numArray[make_tuple(dataPoint,i,j)] = dataPointView(i,j);  
           }  
         }  
       }  
       if (dataPointRank==3) {  
         for (int i=0; i<dataPointShape[0]; i++) {  
           for (int j=0; j<dataPointShape[1]; j++) {  
             for (int k=0; k<dataPointShape[2]; k++) {  
               numArray[make_tuple(dataPoint,i,j,k)]=dataPointView(i,j,k);  
             }  
           }  
         }  
       }  
       if (dataPointRank==4) {  
         for (int i=0; i<dataPointShape[0]; i++) {  
           for (int j=0; j<dataPointShape[1]; j++) {  
             for (int k=0; k<dataPointShape[2]; k++) {  
               for (int l=0; l<dataPointShape[3]; l++) {  
                 numArray[make_tuple(dataPoint,i,j,k,l)]=dataPointView(i,j,k,l);  
               }  
             }  
           }  
         }  
       }  
       dataPoint++;  
     }  
   }  
   
   //  
   // return the loaded array  
   return numArray;  
 }  
   
   
473  const  const
474  boost::python::numeric::array  boost::python::numeric::array
475  Data:: getValueOfDataPoint(int dataPointNo)  Data:: getValueOfDataPoint(int dataPointNo)
# Line 726  Data:: getValueOfDataPoint(int dataPoint Line 514  Data:: getValueOfDataPoint(int dataPoint
514         int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();         int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
515         //         //
516         // Check a valid sample number has been supplied         // Check a valid sample number has been supplied
517         if (sampleNo >= getNumSamples() or sampleNo < 0 ) {         if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
518             throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");             throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
519         }         }
520                                
521         //         //
522         // Check a valid data point number has been supplied         // Check a valid data point number has been supplied
523         if (dataPointNoInSample >= getNumDataPointsPerSample() or dataPointNoInSample < 0) {         if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
524             throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");             throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");
525         }         }
526         // TODO: global error handling         // TODO: global error handling
# Line 773  Data:: getValueOfDataPoint(int dataPoint Line 561  Data:: getValueOfDataPoint(int dataPoint
561    
562  }  }
563  void  void
564  Data::setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array num_array)  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)
565    {
566        // this will throw if the value cannot be represented
567        boost::python::numeric::array num_array(py_object);
568        setValueOfDataPointToArray(dataPointNo,num_array);
569    
570    
571    }
572    
573    void
574    Data::setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array& num_array)
575  {  {
576    if (isProtected()) {    if (isProtected()) {
577          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
# Line 877  Data::getValueOfGlobalDataPoint(int proc Line 675  Data::getValueOfGlobalDataPoint(int proc
675                  int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();                  int dataPointNoInSample = dataPointNo - sampleNo * getNumDataPointsPerSample();
676                  //                  //
677                  // Check a valid sample number has been supplied                  // Check a valid sample number has been supplied
678                  if (sampleNo >= getNumSamples() or sampleNo < 0 ) {                  if ((sampleNo >= getNumSamples()) || (sampleNo < 0 )) {
679                    throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");                    throw DataException("Error - Data::convertToNumArray: invalid sampleNo.");
680                  }                  }
681                                
682                  //                  //
683                  // Check a valid data point number has been supplied                  // Check a valid data point number has been supplied
684                  if (dataPointNoInSample >= getNumDataPointsPerSample() or dataPointNoInSample < 0) {                  if ((dataPointNoInSample >= getNumDataPointsPerSample()) || (dataPointNoInSample < 0)) {
685                    throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");                    throw DataException("Error - Data::convertToNumArray: invalid dataPointNoInSample.");
686                  }                  }
687                  // TODO: global error handling                  // TODO: global error handling
# Line 970  Data::integrate() const Line 768  Data::integrate() const
768    int rank = getDataPointRank();    int rank = getDataPointRank();
769    DataArrayView::ShapeType shape = getDataPointShape();    DataArrayView::ShapeType shape = getDataPointShape();
770    
 #if defined DOPROF  
   profData->integrate++;  
 #endif  
771    
772    //    //
773    // calculate the integral values    // calculate the integral values
# Line 1035  Data::integrate() const Line 830  Data::integrate() const
830  }  }
831    
832  Data  Data
 Data::erf() const  
 {  
 #if defined DOPROF  
   profData->unary++;  
 #endif  
   return escript::unaryOp(*this,(Data::UnaryDFunPtr)::erf);  
 }  
   
 Data  
833  Data::sin() const  Data::sin() const
834  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
835    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);
836  }  }
837    
838  Data  Data
839  Data::cos() const  Data::cos() const
840  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
841    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);
842  }  }
843    
844  Data  Data
845  Data::tan() const  Data::tan() const
846  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
847    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);
848  }  }
849    
850  Data  Data
851  Data::asin() const  Data::asin() const
852  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
853    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);
854  }  }
855    
856  Data  Data
857  Data::acos() const  Data::acos() const
858  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
859    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);
860  }  }
861    
862    
863  Data  Data
864  Data::atan() const  Data::atan() const
865  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
866    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);
867  }  }
868    
869  Data  Data
870  Data::sinh() const  Data::sinh() const
871  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
872    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);
873  }  }
874    
875  Data  Data
876  Data::cosh() const  Data::cosh() const
877  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
878    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);
879  }  }
880    
881  Data  Data
882  Data::tanh() const  Data::tanh() const
883  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
884    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);
885  }  }
886    
887    
888  Data  Data
889  Data::asinh() const  Data::erf() const
890  {  {
891  #if defined DOPROF  #ifdef _WIN32
892    profData->unary++;    throw DataException("Error - Data:: erf function is not supported on _WIN32 platforms.");
893    #else
894      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::erf);
895  #endif  #endif
896    }
897    
898    Data
899    Data::asinh() const
900    {
901    #ifdef _WIN32
902      return escript::unaryOp(*this,escript::asinh_substitute);
903    #else
904    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);
905    #endif
906  }  }
907    
908  Data  Data
909  Data::acosh() const  Data::acosh() const
910  {  {
911  #if defined DOPROF  #ifdef _WIN32
912    profData->unary++;    return escript::unaryOp(*this,escript::acosh_substitute);
913  #endif  #else
914    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);
915    #endif
916  }  }
917    
918  Data  Data
919  Data::atanh() const  Data::atanh() const
920  {  {
921  #if defined DOPROF  #ifdef _WIN32
922    profData->unary++;    return escript::unaryOp(*this,escript::atanh_substitute);
923  #endif  #else
924    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);
925    #endif
926  }  }
927    
928  Data  Data
929  Data::log10() const  Data::log10() const
930  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
931    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);
932  }  }
933    
934  Data  Data
935  Data::log() const  Data::log() const
936  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
937    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);
938  }  }
939    
940  Data  Data
941  Data::sign() const  Data::sign() const
942  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
943    return escript::unaryOp(*this,escript::fsign);    return escript::unaryOp(*this,escript::fsign);
944  }  }
945    
946  Data  Data
947  Data::abs() const  Data::abs() const
948  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
949    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);
950  }  }
951    
952  Data  Data
953  Data::neg() const  Data::neg() const
954  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
955    return escript::unaryOp(*this,negate<double>());    return escript::unaryOp(*this,negate<double>());
956  }  }
957    
958  Data  Data
959  Data::pos() const  Data::pos() const
960  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
961    Data result;    Data result;
962    // perform a deep copy    // perform a deep copy
963    result.copy(*this);    result.copy(*this);
# Line 1211  Data::pos() const Line 967  Data::pos() const
967  Data  Data
968  Data::exp() const  Data::exp() const
969  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
970    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);
971  }  }
972    
973  Data  Data
974  Data::sqrt() const  Data::sqrt() const
975  {  {
 #if defined DOPROF  
   profData->unary++;  
 #endif  
976    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);
977  }  }
978    
# Line 1230  double Line 980  double
980  Data::Lsup() const  Data::Lsup() const
981  {  {
982    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
983    //    //
984    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
985    
# Line 1250  double Line 997  double
997  Data::Linf() const  Data::Linf() const
998  {  {
999    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1000    //    //
1001    // set the initial absolute minimum value to max double    // set the initial absolute minimum value to max double
1002    AbsMin abs_min_func;    AbsMin abs_min_func;
# Line 1270  double Line 1014  double
1014  Data::sup() const  Data::sup() const
1015  {  {
1016    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1017    //    //
1018    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1019    FMax fmax_func;    FMax fmax_func;
# Line 1289  double Line 1030  double
1030  Data::inf() const  Data::inf() const
1031  {  {
1032    double localValue, globalValue;    double localValue, globalValue;
 #if defined DOPROF  
   profData->reduction1++;  
 #endif  
1033    //    //
1034    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1035    FMin fmin_func;    FMin fmin_func;
# Line 1309  Data::inf() const Line 1047  Data::inf() const
1047  Data  Data
1048  Data::maxval() const  Data::maxval() const
1049  {  {
 #if defined DOPROF  
   profData->reduction2++;  
 #endif  
1050    //    //
1051    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1052    FMax fmax_func;    FMax fmax_func;
# Line 1321  Data::maxval() const Line 1056  Data::maxval() const
1056  Data  Data
1057  Data::minval() const  Data::minval() const
1058  {  {
 #if defined DOPROF  
   profData->reduction2++;  
 #endif  
1059    //    //
1060    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1061    FMin fmin_func;    FMin fmin_func;
# Line 1334  Data Line 1066  Data
1066  Data::swapaxes(const int axis0, const int axis1) const  Data::swapaxes(const int axis0, const int axis1) const
1067  {  {
1068       int axis0_tmp,axis1_tmp;       int axis0_tmp,axis1_tmp;
      #if defined DOPROF  
      profData->unary++;  
      #endif  
1069       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1070       DataArrayView::ShapeType ev_shape;       DataArrayView::ShapeType ev_shape;
1071       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]
# Line 1380  Data::swapaxes(const int axis0, const in Line 1109  Data::swapaxes(const int axis0, const in
1109  Data  Data
1110  Data::symmetric() const  Data::symmetric() const
1111  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1112       // check input       // check input
1113       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1114       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
# Line 1405  Data::symmetric() const Line 1131  Data::symmetric() const
1131  Data  Data
1132  Data::nonsymmetric() const  Data::nonsymmetric() const
1133  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1134       // check input       // check input
1135       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1136       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
# Line 1442  Data::nonsymmetric() const Line 1165  Data::nonsymmetric() const
1165  Data  Data
1166  Data::trace(int axis_offset) const  Data::trace(int axis_offset) const
1167  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1168       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1169       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1170          DataArrayView::ShapeType ev_shape;          DataArrayView::ShapeType ev_shape;
# Line 1495  Data::trace(int axis_offset) const Line 1215  Data::trace(int axis_offset) const
1215  Data  Data
1216  Data::transpose(int axis_offset) const  Data::transpose(int axis_offset) const
1217  {  {
      #if defined DOPROF  
      profData->unary++;  
      #endif  
1218       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1219       DataArrayView::ShapeType ev_shape;       DataArrayView::ShapeType ev_shape;
1220       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]
# Line 1519  Data::transpose(int axis_offset) const Line 1236  Data::transpose(int axis_offset) const
1236  Data  Data
1237  Data::eigenvalues() const  Data::eigenvalues() const
1238  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1239       // check input       // check input
1240       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1241       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
# Line 1539  Data::eigenvalues() const Line 1253  Data::eigenvalues() const
1253  const boost::python::tuple  const boost::python::tuple
1254  Data::eigenvalues_and_eigenvectors(const double tol) const  Data::eigenvalues_and_eigenvectors(const double tol) const
1255  {  {
      #if defined DOPROF  
         profData->unary++;  
      #endif  
1256       DataArrayView::ShapeType s=getDataPointShape();       DataArrayView::ShapeType s=getDataPointShape();
1257       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1258          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for rank 2 object.");          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for rank 2 object.");
# Line 1955  Data::getItem(const boost::python::objec Line 1666  Data::getItem(const boost::python::objec
1666  Data  Data
1667  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataArrayView::RegionType& region) const
1668  {  {
 #if defined DOPROF  
   profData->slicing++;  
 #endif  
1669    return Data(*this,region);    return Data(*this,region);
1670  }  }
1671    
# Line 1999  Data::setSlice(const Data& value, Line 1707  Data::setSlice(const Data& value,
1707    if (isProtected()) {    if (isProtected()) {
1708          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
1709    }    }
 #if defined DOPROF  
   profData->slicing++;  
 #endif  
1710    Data tempValue(value);    Data tempValue(value);
1711    typeMatchLeft(tempValue);    typeMatchLeft(tempValue);
1712    typeMatchRight(tempValue);    typeMatchRight(tempValue);
# Line 2036  Data::typeMatchRight(const Data& right) Line 1741  Data::typeMatchRight(const Data& right)
1741    }    }
1742  }  }
1743    
1744  /* TODO */  void
1745  /* global reduction */  Data::setTaggedValueByName(std::string name,
1746                               const boost::python::object& value)
1747    {
1748         if (getFunctionSpace().getDomain().isValidTagName(name)) {
1749            int tagKey=getFunctionSpace().getDomain().getTag(name);
1750            setTaggedValue(tagKey,value);
1751         }
1752    }
1753  void  void
1754  Data::setTaggedValue(int tagKey,  Data::setTaggedValue(int tagKey,
1755                       const boost::python::object& value)                       const boost::python::object& value)
# Line 2062  Data::setTaggedValue(int tagKey, Line 1774  Data::setTaggedValue(int tagKey,
1774    m_data->setTaggedValue(tagKey,valueDataArray.getView());    m_data->setTaggedValue(tagKey,valueDataArray.getView());
1775  }  }
1776    
 /* TODO */  
 /* global reduction */  
1777  void  void
1778  Data::setTaggedValueFromCPP(int tagKey,  Data::setTaggedValueFromCPP(int tagKey,
1779                              const DataArrayView& value)                              const DataArrayView& value)
# Line 2084  Data::setTaggedValueFromCPP(int tagKey, Line 1794  Data::setTaggedValueFromCPP(int tagKey,
1794    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,value);
1795  }  }
1796    
 /* TODO */  
 /* global reduction */  
1797  int  int
1798  Data::getTagNumber(int dpno)  Data::getTagNumber(int dpno)
1799  {  {
1800    return m_data->getTagNumber(dpno);    return m_data->getTagNumber(dpno);
1801  }  }
1802    
 /* TODO */  
 /* global reduction */  
 void  
 Data::setRefValue(int ref,  
                   const boost::python::numeric::array& value)  
 {  
   if (isProtected()) {  
         throw DataException("Error - attempt to update protected Data object.");  
   }  
   //  
   // Construct DataArray from boost::python::object input value  
   DataArray valueDataArray(value);  
   
   //  
   // Call DataAbstract::setRefValue  
   m_data->setRefValue(ref,valueDataArray);  
 }  
   
 /* TODO */  
 /* global reduction */  
 void  
 Data::getRefValue(int ref,  
                   boost::python::numeric::array& value)  
 {  
   //  
   // Construct DataArray for boost::python::object return value  
   DataArray valueDataArray(value);  
   
   //  
   // Load DataArray with values from data-points specified by ref  
   m_data->getRefValue(ref,valueDataArray);  
   
   //  
   // Load values from valueDataArray into return numarray  
   
   // extract the shape of the numarray  
   int rank = value.getrank();  
   DataArrayView::ShapeType shape;  
   for (int i=0; i < rank; i++) {  
     shape.push_back(extract<int>(value.getshape()[i]));  
   }  
   
   // and load the numarray with the data from the DataArray  
   DataArrayView valueView = valueDataArray.getView();  
   
   if (rank==0) {  
       boost::python::numeric::array temp_numArray(valueView());  
       value = temp_numArray;  
   }  
   if (rank==1) {  
     for (int i=0; i < shape[0]; i++) {  
       value[i] = valueView(i);  
     }  
   }  
   if (rank==2) {  
     for (int i=0; i < shape[0]; i++) {  
       for (int j=0; j < shape[1]; j++) {  
         value[make_tuple(i,j)] = valueView(i,j);  
       }  
     }  
   }  
   if (rank==3) {  
     for (int i=0; i < shape[0]; i++) {  
       for (int j=0; j < shape[1]; j++) {  
         for (int k=0; k < shape[2]; k++) {  
           value[make_tuple(i,j,k)] = valueView(i,j,k);  
         }  
       }  
     }  
   }  
   if (rank==4) {  
     for (int i=0; i < shape[0]; i++) {  
       for (int j=0; j < shape[1]; j++) {  
         for (int k=0; k < shape[2]; k++) {  
           for (int l=0; l < shape[3]; l++) {  
             value[make_tuple(i,j,k,l)] = valueView(i,j,k,l);  
           }  
         }  
       }  
     }  
   }  
   
 }  
   
1803  void  void
1804  Data::archiveData(const std::string fileName)  Data::archiveData(const std::string fileName)
1805  {  {
# Line 2217  Data::archiveData(const std::string file Line 1841  Data::archiveData(const std::string file
1841    DataArrayView::ShapeType dataPointShape = getDataPointShape();    DataArrayView::ShapeType dataPointShape = getDataPointShape();
1842    vector<int> referenceNumbers(noSamples);    vector<int> referenceNumbers(noSamples);
1843    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {
1844      referenceNumbers[sampleNo] = getFunctionSpace().getReferenceNoFromSampleNo(sampleNo);      referenceNumbers[sampleNo] = getFunctionSpace().getReferenceIDOfSample(sampleNo);
1845    }    }
1846    vector<int> tagNumbers(noSamples);    vector<int> tagNumbers(noSamples);
1847    if (isTagged()) {    if (isTagged()) {
# Line 2426  Data::extractData(const std::string file Line 2050  Data::extractData(const std::string file
2050      throw DataException("extractData Error: incompatible FunctionSpace");      throw DataException("extractData Error: incompatible FunctionSpace");
2051    }    }
2052    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {    for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {
2053      if (referenceNumbers[sampleNo] != fspace.getReferenceNoFromSampleNo(sampleNo)) {      if (referenceNumbers[sampleNo] != fspace.getReferenceIDOfSample(sampleNo)) {
2054        throw DataException("extractData Error: incompatible FunctionSpace");        throw DataException("extractData Error: incompatible FunctionSpace");
2055      }      }
2056    }    }
# Line 2526  escript::C_GeneralTensorProduct(Data& ar Line 2150  escript::C_GeneralTensorProduct(Data& ar
2150    // General tensor product: res(SL x SR) = arg_0(SL x SM) * arg_1(SM x SR)    // General tensor product: res(SL x SR) = arg_0(SL x SM) * arg_1(SM x SR)
2151    // SM is the product of the last axis_offset entries in arg_0.getShape().    // SM is the product of the last axis_offset entries in arg_0.getShape().
2152    
   #if defined DOPROF  
     // profData->binary++;  
   #endif  
2153    
2154    // Interpolate if necessary and find an appropriate function space    // Interpolate if necessary and find an appropriate function space
2155    Data arg_0_Z, arg_1_Z;    Data arg_0_Z, arg_1_Z;

Legend:
Removed from v.922  
changed lines
  Added in v.1092

  ViewVC Help
Powered by ViewVC 1.1.26