/[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

trunk/esys2/escript/src/Data/Data.cpp revision 126 by jgs, Fri Jul 22 03:53:08 2005 UTC trunk/escript/src/Data/Data.cpp revision 436 by gross, Thu Jan 19 22:36:36 2006 UTC
# Line 25  Line 25 
25  #include <functional>  #include <functional>
26  #include <math.h>  #include <math.h>
27    
28    #include <boost/python/dict.hpp>
29  #include <boost/python/str.hpp>  #include <boost/python/str.hpp>
30  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
31  #include <boost/python/long.hpp>  #include <boost/python/long.hpp>
32    #include <boost/python/tuple.hpp>
33    
34  #include "escript/Data/DataException.h"  #include "escript/Data/DataException.h"
35  #include "escript/Data/DataExpanded.h"  #include "escript/Data/DataExpanded.h"
# Line 45  using namespace boost::python; Line 47  using namespace boost::python;
47  using namespace boost;  using namespace boost;
48  using namespace escript;  using namespace escript;
49    
50    #if defined DOPROF
51  //  //
52  // global table of profiling data for all Data objects  // global table of profiling data for all Data objects
53  DataProf dataProfTable;  DataProf dataProfTable;
54    #endif
55    
56  Data::Data()  Data::Data()
57  {  {
# Line 56  Data::Data() Line 60  Data::Data()
60    DataAbstract* temp=new DataEmpty();    DataAbstract* temp=new DataEmpty();
61    shared_ptr<DataAbstract> temp_data(temp);    shared_ptr<DataAbstract> temp_data(temp);
62    m_data=temp_data;    m_data=temp_data;
63    #if defined DOPROF
64    // create entry in global profiling table for this object    // create entry in global profiling table for this object
65    profData = dataProfTable.newData();    profData = dataProfTable.newData();
66    #endif
67  }  }
68    
69  Data::Data(double value,  Data::Data(double value,
# Line 71  Data::Data(double value, Line 77  Data::Data(double value,
77    }    }
78    DataArray temp(dataPointShape,value);    DataArray temp(dataPointShape,value);
79    initialise(temp.getView(),what,expanded);    initialise(temp.getView(),what,expanded);
80    #if defined DOPROF
81    // create entry in global profiling table for this object    // create entry in global profiling table for this object
82    profData = dataProfTable.newData();    profData = dataProfTable.newData();
83    #endif
84  }  }
85    
86  Data::Data(double value,  Data::Data(double value,
# Line 83  Data::Data(double value, Line 91  Data::Data(double value,
91    DataArray temp(dataPointShape,value);    DataArray temp(dataPointShape,value);
92    pair<int,int> dataShape=what.getDataShape();    pair<int,int> dataShape=what.getDataShape();
93    initialise(temp.getView(),what,expanded);    initialise(temp.getView(),what,expanded);
94    #if defined DOPROF
95    // create entry in global profiling table for this object    // create entry in global profiling table for this object
96    profData = dataProfTable.newData();    profData = dataProfTable.newData();
97    #endif
98  }  }
99    
100  Data::Data(const Data& inData)  Data::Data(const Data& inData)
101  {  {
102    m_data=inData.m_data;    m_data=inData.m_data;
103    #if defined DOPROF
104    // create entry in global profiling table for this object    // create entry in global profiling table for this object
105    profData = dataProfTable.newData();    profData = dataProfTable.newData();
106    #endif
107  }  }
108    
109  Data::Data(const Data& inData,  Data::Data(const Data& inData,
# Line 102  Data::Data(const Data& inData, Line 114  Data::Data(const Data& inData,
114    DataAbstract* tmp = inData.m_data->getSlice(region);    DataAbstract* tmp = inData.m_data->getSlice(region);
115    shared_ptr<DataAbstract> temp_data(tmp);    shared_ptr<DataAbstract> temp_data(tmp);
116    m_data=temp_data;    m_data=temp_data;
117    #if defined DOPROF
118    // create entry in global profiling table for this object    // create entry in global profiling table for this object
119    profData = dataProfTable.newData();    profData = dataProfTable.newData();
120    #endif
121  }  }
122    
123  Data::Data(const Data& inData,  Data::Data(const Data& inData,
# Line 125  Data::Data(const Data& inData, Line 139  Data::Data(const Data& inData,
139      }      }
140      m_data=tmp.m_data;      m_data=tmp.m_data;
141    }    }
142    #if defined DOPROF
143    // create entry in global profiling table for this object    // create entry in global profiling table for this object
144    profData = dataProfTable.newData();    profData = dataProfTable.newData();
145    #endif
146  }  }
147    
148  Data::Data(const DataTagged::TagListType& tagKeys,  Data::Data(const DataTagged::TagListType& tagKeys,
# Line 141  Data::Data(const DataTagged::TagListType Line 157  Data::Data(const DataTagged::TagListType
157    if (expanded) {    if (expanded) {
158      expand();      expand();
159    }    }
160    #if defined DOPROF
161    // create entry in global profiling table for this object    // create entry in global profiling table for this object
162    profData = dataProfTable.newData();    profData = dataProfTable.newData();
163    #endif
164  }  }
165    
166  Data::Data(const numeric::array& value,  Data::Data(const numeric::array& value,
# Line 150  Data::Data(const numeric::array& value, Line 168  Data::Data(const numeric::array& value,
168             bool expanded)             bool expanded)
169  {  {
170    initialise(value,what,expanded);    initialise(value,what,expanded);
171    #if defined DOPROF
172    // create entry in global profiling table for this object    // create entry in global profiling table for this object
173    profData = dataProfTable.newData();    profData = dataProfTable.newData();
174    #endif
175  }  }
176    
177  Data::Data(const DataArrayView& value,  Data::Data(const DataArrayView& value,
# Line 159  Data::Data(const DataArrayView& value, Line 179  Data::Data(const DataArrayView& value,
179             bool expanded)             bool expanded)
180  {  {
181    initialise(value,what,expanded);    initialise(value,what,expanded);
182    #if defined DOPROF
183    // create entry in global profiling table for this object    // create entry in global profiling table for this object
184    profData = dataProfTable.newData();    profData = dataProfTable.newData();
185    #endif
186  }  }
187    
188  Data::Data(const object& value,  Data::Data(const object& value,
# Line 169  Data::Data(const object& value, Line 191  Data::Data(const object& value,
191  {  {
192    numeric::array asNumArray(value);    numeric::array asNumArray(value);
193    initialise(asNumArray,what,expanded);    initialise(asNumArray,what,expanded);
194    #if defined DOPROF
195    // create entry in global profiling table for this object    // create entry in global profiling table for this object
196    profData = dataProfTable.newData();    profData = dataProfTable.newData();
197    #endif
198  }  }
199    
200  Data::Data(const object& value,  Data::Data(const object& value,
# Line 191  Data::Data(const object& value, Line 215  Data::Data(const object& value,
215      // Create a DataConstant with the same sample shape as other      // Create a DataConstant with the same sample shape as other
216      initialise(temp.getView(),other.getFunctionSpace(),false);      initialise(temp.getView(),other.getFunctionSpace(),false);
217    }    }
218    #if defined DOPROF
219    // create entry in global profiling table for this object    // create entry in global profiling table for this object
220    profData = dataProfTable.newData();    profData = dataProfTable.newData();
221    #endif
222    }
223    
224    Data::~Data()
225    {
226    
227  }  }
228    
229  escriptDataC  escriptDataC
# Line 379  Data::reshapeDataPoint(const DataArrayVi Line 410  Data::reshapeDataPoint(const DataArrayVi
410  Data  Data
411  Data::wherePositive() const  Data::wherePositive() const
412  {  {
413    #if defined DOPROF
414    profData->where++;    profData->where++;
415    #endif
416    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater<double>(),0.0));
417  }  }
418    
419  Data  Data
420  Data::whereNegative() const  Data::whereNegative() const
421  {  {
422    #if defined DOPROF
423    profData->where++;    profData->where++;
424    #endif
425    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less<double>(),0.0));
426  }  }
427    
428  Data  Data
429  Data::whereNonNegative() const  Data::whereNonNegative() const
430  {  {
431    #if defined DOPROF
432    profData->where++;    profData->where++;
433    #endif
434    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(greater_equal<double>(),0.0));
435  }  }
436    
437  Data  Data
438  Data::whereNonPositive() const  Data::whereNonPositive() const
439  {  {
440    #if defined DOPROF
441    profData->where++;    profData->where++;
442    #endif
443    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));    return escript::unaryOp(*this,bind2nd(less_equal<double>(),0.0));
444  }  }
445    
446  Data  Data
447  Data::whereZero() const  Data::whereZero() const
448  {  {
449    #if defined DOPROF
450    profData->where++;    profData->where++;
451    #endif
452    return escript::unaryOp(*this,bind2nd(equal_to<double>(),0.0));    return escript::unaryOp(*this,bind2nd(equal_to<double>(),0.0));
453  }  }
454    
455  Data  Data
456  Data::whereNonZero() const  Data::whereNonZero() const
457  {  {
458    #if defined DOPROF
459    profData->where++;    profData->where++;
460    #endif
461    return escript::unaryOp(*this,bind2nd(not_equal_to<double>(),0.0));    return escript::unaryOp(*this,bind2nd(not_equal_to<double>(),0.0));
462  }  }
463    
464  Data  Data
465  Data::interpolate(const FunctionSpace& functionspace) const  Data::interpolate(const FunctionSpace& functionspace) const
466  {  {
467    #if defined DOPROF
468    profData->interpolate++;    profData->interpolate++;
469    #endif
470    return Data(*this,functionspace);    return Data(*this,functionspace);
471  }  }
472    
# Line 443  Data::probeInterpolation(const FunctionS Line 488  Data::probeInterpolation(const FunctionS
488  Data  Data
489  Data::gradOn(const FunctionSpace& functionspace) const  Data::gradOn(const FunctionSpace& functionspace) const
490  {  {
491    #if defined DOPROF
492    profData->grad++;    profData->grad++;
493    #endif
494    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
495      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
496    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();
# Line 481  void Line 528  void
528  Data::fillFromNumArray(const boost::python::numeric::array num_array)  Data::fillFromNumArray(const boost::python::numeric::array num_array)
529  {  {
530    //    //
531    // check rank:    // check rank
532    if (num_array.getrank()<getDataPointRank())    if (num_array.getrank()<getDataPointRank())
533        throw DataException("Rank of numarray does not match Data object rank");        throw DataException("Rank of numarray does not match Data object rank");
534    
535    //    //
536    // check rank of num_array    // check shape of num_array
537    for (int i=0; i<getDataPointRank(); i++) {    for (int i=0; i<getDataPointRank(); i++) {
538      if (extract<int>(num_array.getshape()[i+1])!=getDataPointShape()[i])      if (extract<int>(num_array.getshape()[i+1])!=getDataPointShape()[i])
539         throw DataException("Shape of numarray does not match Data object rank");         throw DataException("Shape of numarray does not match Data object rank");
540    }    }
   //  
   // make sure data is expanded:  
   if (! isExpanded()) expand();  
   //  
   // and copy over:  
   m_data->copyAll(num_array);  
   //  
   // 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]);  
   // }  
541    
542    //    //
543    // resize the numeric array to the shape just calculated    // make sure data is expanded:
544    // if (arrayRank==1) {    if (!isExpanded()) {
545    //   numArray.resize(arrayShape[0]);      expand();
546    // }    }
   // 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) {  
   //       dataPointView()=numArray[dataPoint];  
   //     }  
   //     if (dataPointRank==1) {  
   //       for (int i=0; i<dataPointShape[0]; i++) {  
   //         dataPointView(i)=numArray[dataPoint][i];  
   //       }  
   //     }  
   //     if (dataPointRank==2) {  
   //       for (int i=0; i<dataPointShape[0]; i++) {  
   //         for (int j=0; j<dataPointShape[1]; j++) {  
   //           numArray[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[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[dataPoint][i][j][k][l]=dataPointView(i,j,k,l);  
   //             }  
   //           }  
   //         }  
   //       }  
   //     }  
   //     dataPoint++;  
   //   }  
   // }  
547    
548    //    //
549    // return the loaded array    // and copy over
550    // return numArray;    m_data->copyAll(num_array);
   
551  }  }
552    
553  const  const
# Line 885  Data::integrate() const Line 855  Data::integrate() const
855    int rank = getDataPointRank();    int rank = getDataPointRank();
856    DataArrayView::ShapeType shape = getDataPointShape();    DataArrayView::ShapeType shape = getDataPointShape();
857    
858    #if defined DOPROF
859    profData->integrate++;    profData->integrate++;
860    #endif
861    
862    //    //
863    // calculate the integral values    // calculate the integral values
# Line 909  Data::integrate() const Line 881  Data::integrate() const
881      }      }
882    }    }
883    if (rank==2) {    if (rank==2) {
884      bp_array.resize(shape[0],shape[1]);         bp_array.resize(shape[0],shape[1]);
885      for (int i=0; i<shape[0]; i++) {         for (int i=0; i<shape[0]; i++) {
886        for (int j=0; j<shape[1]; j++) {           for (int j=0; j<shape[1]; j++) {
887          index = i + shape[0] * j;             index = i + shape[0] * j;
888          bp_array[i,j] = integrals[index];             bp_array[make_tuple(i,j)] = integrals[index];
889        }           }
890      }         }
891    }    }
892    if (rank==3) {    if (rank==3) {
893      bp_array.resize(shape[0],shape[1],shape[2]);      bp_array.resize(shape[0],shape[1],shape[2]);
# Line 923  Data::integrate() const Line 895  Data::integrate() const
895        for (int j=0; j<shape[1]; j++) {        for (int j=0; j<shape[1]; j++) {
896          for (int k=0; k<shape[2]; k++) {          for (int k=0; k<shape[2]; k++) {
897            index = i + shape[0] * ( j + shape[1] * k );            index = i + shape[0] * ( j + shape[1] * k );
898            bp_array[i,j,k] = integrals[index];            bp_array[make_tuple(i,j,k)] = integrals[index];
899          }          }
900        }        }
901      }      }
# Line 935  Data::integrate() const Line 907  Data::integrate() const
907          for (int k=0; k<shape[2]; k++) {          for (int k=0; k<shape[2]; k++) {
908            for (int l=0; l<shape[3]; l++) {            for (int l=0; l<shape[3]; l++) {
909              index = i + shape[0] * ( j + shape[1] * ( k + shape[2] * l ) );              index = i + shape[0] * ( j + shape[1] * ( k + shape[2] * l ) );
910              bp_array[i,j,k,l] = integrals[index];              bp_array[make_tuple(i,j,k,l)] = integrals[index];
911            }            }
912          }          }
913        }        }
# Line 950  Data::integrate() const Line 922  Data::integrate() const
922  Data  Data
923  Data::sin() const  Data::sin() const
924  {  {
925    #if defined DOPROF
926    profData->unary++;    profData->unary++;
927    #endif
928    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sin);
929  }  }
930    
931  Data  Data
932  Data::cos() const  Data::cos() const
933  {  {
934    #if defined DOPROF
935    profData->unary++;    profData->unary++;
936    #endif
937    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cos);
938  }  }
939    
940  Data  Data
941  Data::tan() const  Data::tan() const
942  {  {
943    #if defined DOPROF
944    profData->unary++;    profData->unary++;
945    #endif
946    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tan);
947  }  }
948    
949  Data  Data
950  Data::log() const  Data::asin() const
951    {
952    #if defined DOPROF
953      profData->unary++;
954    #endif
955      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);
956    }
957    
958    Data
959    Data::acos() const
960    {
961    #if defined DOPROF
962      profData->unary++;
963    #endif
964      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);
965    }
966    
967    Data
968    Data::atan() const
969    {
970    #if defined DOPROF
971      profData->unary++;
972    #endif
973      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);
974    }
975    
976    Data
977    Data::sinh() const
978  {  {
979    #if defined DOPROF
980    profData->unary++;    profData->unary++;
981    #endif
982      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);
983    }
984    
985    Data
986    Data::cosh() const
987    {
988    #if defined DOPROF
989      profData->unary++;
990    #endif
991      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);
992    }
993    
994    Data
995    Data::tanh() const
996    {
997    #if defined DOPROF
998      profData->unary++;
999    #endif
1000      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);
1001    }
1002    
1003    Data
1004    Data::asinh() const
1005    {
1006    #if defined DOPROF
1007      profData->unary++;
1008    #endif
1009      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);
1010    }
1011    
1012    Data
1013    Data::acosh() const
1014    {
1015    #if defined DOPROF
1016      profData->unary++;
1017    #endif
1018      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);
1019    }
1020    
1021    Data
1022    Data::atanh() const
1023    {
1024    #if defined DOPROF
1025      profData->unary++;
1026    #endif
1027      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);
1028    }
1029    
1030    Data
1031    Data::log10() const
1032    {
1033    #if defined DOPROF
1034      profData->unary++;
1035    #endif
1036    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log10);
1037  }  }
1038    
1039  Data  Data
1040  Data::ln() const  Data::log() const
1041  {  {
1042    #if defined DOPROF
1043    profData->unary++;    profData->unary++;
1044    #endif
1045    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::log);
1046  }  }
1047    
1048  Data  Data
1049  Data::sign() const  Data::sign() const
1050  {  {
1051    #if defined DOPROF
1052    profData->unary++;    profData->unary++;
1053    #endif
1054    return escript::unaryOp(*this,escript::fsign);    return escript::unaryOp(*this,escript::fsign);
1055  }  }
1056    
1057  Data  Data
1058  Data::abs() const  Data::abs() const
1059  {  {
1060    #if defined DOPROF
1061    profData->unary++;    profData->unary++;
1062    #endif
1063    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::fabs);
1064  }  }
1065    
1066  Data  Data
1067  Data::neg() const  Data::neg() const
1068  {  {
1069    #if defined DOPROF
1070    profData->unary++;    profData->unary++;
1071    #endif
1072    return escript::unaryOp(*this,negate<double>());    return escript::unaryOp(*this,negate<double>());
1073  }  }
1074    
1075  Data  Data
1076  Data::pos() const  Data::pos() const
1077  {  {
1078    #if defined DOPROF
1079    profData->unary++;    profData->unary++;
1080    return (*this);  #endif
1081      Data result;
1082      // perform a deep copy
1083      result.copy(*this);
1084      return result;
1085  }  }
1086    
1087  Data  Data
1088  Data::exp() const  Data::exp() const
1089  {  {
1090    #if defined DOPROF
1091    profData->unary++;    profData->unary++;
1092    #endif
1093    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::exp);
1094  }  }
1095    
1096  Data  Data
1097  Data::sqrt() const  Data::sqrt() const
1098  {  {
1099    #if defined DOPROF
1100    profData->unary++;    profData->unary++;
1101    #endif
1102    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);    return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sqrt);
1103  }  }
1104    
1105  double  double
1106  Data::Lsup() const  Data::Lsup() const
1107  {  {
1108    #if defined DOPROF
1109    profData->reduction1++;    profData->reduction1++;
1110    #endif
1111    //    //
1112    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
1113    return algorithm(DataAlgorithmAdapter<AbsMax>(0));    AbsMax abs_max_func;
1114      return algorithm(abs_max_func,0);
1115  }  }
1116    
1117  double  double
1118  Data::Linf() const  Data::Linf() const
1119  {  {
1120    #if defined DOPROF
1121    profData->reduction1++;    profData->reduction1++;
1122    #endif
1123    //    //
1124    // set the initial absolute minimum value to max double    // set the initial absolute minimum value to max double
1125    return algorithm(DataAlgorithmAdapter<AbsMin>(numeric_limits<double>::max()));    AbsMin abs_min_func;
1126      return algorithm(abs_min_func,numeric_limits<double>::max());
1127  }  }
1128    
1129  double  double
1130  Data::sup() const  Data::sup() const
1131  {  {
1132    #if defined DOPROF
1133    profData->reduction1++;    profData->reduction1++;
1134    #endif
1135    //    //
1136    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1137    return algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    FMax fmax_func;
1138      return algorithm(fmax_func,numeric_limits<double>::max()*-1);
1139  }  }
1140    
1141  double  double
1142  Data::inf() const  Data::inf() const
1143  {  {
1144    #if defined DOPROF
1145    profData->reduction1++;    profData->reduction1++;
1146    #endif
1147    //    //
1148    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1149    return algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    FMin fmin_func;
1150      return algorithm(fmin_func,numeric_limits<double>::max());
1151  }  }
1152    
1153  Data  Data
1154  Data::maxval() const  Data::maxval() const
1155  {  {
1156    #if defined DOPROF
1157    profData->reduction2++;    profData->reduction2++;
1158    #endif
1159    //    //
1160    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1161    return dp_algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    FMax fmax_func;
1162      return dp_algorithm(fmax_func,numeric_limits<double>::max()*-1);
1163  }  }
1164    
1165  Data  Data
1166  Data::minval() const  Data::minval() const
1167  {  {
1168    #if defined DOPROF
1169    profData->reduction2++;    profData->reduction2++;
1170    #endif
1171    //    //
1172    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1173    return dp_algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    FMin fmin_func;
1174  }    return dp_algorithm(fmin_func,numeric_limits<double>::max());
   
 Data  
 Data::length() const  
 {  
   profData->reduction2++;  
   return dp_algorithm(DataAlgorithmAdapter<Length>(0));  
1175  }  }
1176    
1177  Data  Data
1178  Data::trace() const  Data::trace() const
1179  {  {
1180    #if defined DOPROF
1181    profData->reduction2++;    profData->reduction2++;
1182    return dp_algorithm(DataAlgorithmAdapter<Trace>(0));  #endif
1183      Trace trace_func;
1184      return dp_algorithm(trace_func,0);
1185  }  }
1186    
1187  Data  Data
1188  Data::transpose(int axis) const  Data::transpose(int axis) const
1189  {  {
1190    #if defined DOPROF
1191    profData->reduction2++;    profData->reduction2++;
1192    #endif
1193    // not implemented    // not implemented
1194    throw DataException("Error - Data::transpose not implemented yet.");    throw DataException("Error - Data::transpose not implemented yet.");
1195    return Data();    return Data();
# Line 1104  Data::transpose(int axis) const Line 1198  Data::transpose(int axis) const
1198  const boost::python::tuple  const boost::python::tuple
1199  Data::mindp() const  Data::mindp() const
1200  {  {
1201      // NB: calc_mindp had to be split off from mindp as boost::make_tuple causes an
1202      // abort (for unknown reasons) if there are openmp directives with it in the
1203      // surrounding function
1204    
1205      int SampleNo;
1206      int DataPointNo;
1207    
1208      calc_mindp(SampleNo,DataPointNo);
1209    
1210      return make_tuple(SampleNo,DataPointNo);
1211    }
1212    
1213    void
1214    Data::calc_mindp(int& SampleNo,
1215                     int& DataPointNo) const
1216    {
1217      int i,j;
1218      int lowi=0,lowj=0;
1219      double min=numeric_limits<double>::max();
1220    
1221    Data temp=minval();    Data temp=minval();
1222    
1223    int numSamples=temp.getNumSamples();    int numSamples=temp.getNumSamples();
1224    int numDPPSample=temp.getNumDataPointsPerSample();    int numDPPSample=temp.getNumDataPointsPerSample();
1225    
1226    int i,j,lowi=0,lowj=0;    double next,local_min;
1227    double min=numeric_limits<double>::max();    int local_lowi,local_lowj;
1228    
1229    for (i=0; i<numSamples; i++) {    #pragma omp parallel private(next,local_min,local_lowi,local_lowj)
1230      for (j=0; j<numDPPSample; j++) {    {
1231        double next=temp.getDataPoint(i,j)();      local_min=min;
1232        if (next<min) {      #pragma omp for private(i,j) schedule(static)
1233          min=next;      for (i=0; i<numSamples; i++) {
1234          lowi=i;        for (j=0; j<numDPPSample; j++) {
1235          lowj=j;          next=temp.getDataPoint(i,j)();
1236            if (next<local_min) {
1237              local_min=next;
1238              local_lowi=i;
1239              local_lowj=j;
1240            }
1241        }        }
1242      }      }
1243        #pragma omp critical
1244        if (local_min<min) {
1245          min=local_min;
1246          lowi=local_lowi;
1247          lowj=local_lowj;
1248        }
1249    }    }
1250    
1251    return make_tuple(lowi,lowj);    SampleNo = lowi;
1252      DataPointNo = lowj;
1253  }  }
1254    
1255  void  void
1256  Data::saveDX(std::string fileName) const  Data::saveDX(std::string fileName) const
1257  {  {
1258    getDomain().saveDX(fileName,*this);    boost::python::dict args;
1259      args["data"]=boost::python::object(this);
1260      getDomain().saveDX(fileName,args);
1261    return;    return;
1262  }  }
1263    
1264  void  void
1265  Data::saveVTK(std::string fileName) const  Data::saveVTK(std::string fileName) const
1266  {  {
1267    getDomain().saveVTK(fileName,*this);    boost::python::dict args;
1268      args["data"]=boost::python::object(this);
1269      getDomain().saveVTK(fileName,args);
1270    return;    return;
1271  }  }
1272    
1273  Data&  Data&
1274  Data::operator+=(const Data& right)  Data::operator+=(const Data& right)
1275  {  {
1276    #if defined DOPROF
1277    profData->binary++;    profData->binary++;
1278    #endif
1279    binaryOp(right,plus<double>());    binaryOp(right,plus<double>());
1280    return (*this);    return (*this);
1281  }  }
# Line 1151  Data::operator+=(const Data& right) Line 1283  Data::operator+=(const Data& right)
1283  Data&  Data&
1284  Data::operator+=(const boost::python::object& right)  Data::operator+=(const boost::python::object& right)
1285  {  {
1286    #if defined DOPROF
1287    profData->binary++;    profData->binary++;
1288    #endif
1289    binaryOp(right,plus<double>());    binaryOp(right,plus<double>());
1290    return (*this);    return (*this);
1291  }  }
# Line 1159  Data::operator+=(const boost::python::ob Line 1293  Data::operator+=(const boost::python::ob
1293  Data&  Data&
1294  Data::operator-=(const Data& right)  Data::operator-=(const Data& right)
1295  {  {
1296    #if defined DOPROF
1297    profData->binary++;    profData->binary++;
1298    #endif
1299    binaryOp(right,minus<double>());    binaryOp(right,minus<double>());
1300    return (*this);    return (*this);
1301  }  }
# Line 1167  Data::operator-=(const Data& right) Line 1303  Data::operator-=(const Data& right)
1303  Data&  Data&
1304  Data::operator-=(const boost::python::object& right)  Data::operator-=(const boost::python::object& right)
1305  {  {
1306    #if defined DOPROF
1307    profData->binary++;    profData->binary++;
1308    #endif
1309    binaryOp(right,minus<double>());    binaryOp(right,minus<double>());
1310    return (*this);    return (*this);
1311  }  }
# Line 1175  Data::operator-=(const boost::python::ob Line 1313  Data::operator-=(const boost::python::ob
1313  Data&  Data&
1314  Data::operator*=(const Data& right)  Data::operator*=(const Data& right)
1315  {  {
1316    #if defined DOPROF
1317    profData->binary++;    profData->binary++;
1318    #endif
1319    binaryOp(right,multiplies<double>());    binaryOp(right,multiplies<double>());
1320    return (*this);    return (*this);
1321  }  }
# Line 1183  Data::operator*=(const Data& right) Line 1323  Data::operator*=(const Data& right)
1323  Data&  Data&
1324  Data::operator*=(const boost::python::object& right)  Data::operator*=(const boost::python::object& right)
1325  {  {
1326    #if defined DOPROF
1327    profData->binary++;    profData->binary++;
1328    #endif
1329    binaryOp(right,multiplies<double>());    binaryOp(right,multiplies<double>());
1330    return (*this);    return (*this);
1331  }  }
# Line 1191  Data::operator*=(const boost::python::ob Line 1333  Data::operator*=(const boost::python::ob
1333  Data&  Data&
1334  Data::operator/=(const Data& right)  Data::operator/=(const Data& right)
1335  {  {
1336    #if defined DOPROF
1337    profData->binary++;    profData->binary++;
1338    #endif
1339    binaryOp(right,divides<double>());    binaryOp(right,divides<double>());
1340    return (*this);    return (*this);
1341  }  }
# Line 1199  Data::operator/=(const Data& right) Line 1343  Data::operator/=(const Data& right)
1343  Data&  Data&
1344  Data::operator/=(const boost::python::object& right)  Data::operator/=(const boost::python::object& right)
1345  {  {
1346    #if defined DOPROF
1347    profData->binary++;    profData->binary++;
1348    #endif
1349    binaryOp(right,divides<double>());    binaryOp(right,divides<double>());
1350    return (*this);    return (*this);
1351  }  }
# Line 1207  Data::operator/=(const boost::python::ob Line 1353  Data::operator/=(const boost::python::ob
1353  Data  Data
1354  Data::powO(const boost::python::object& right) const  Data::powO(const boost::python::object& right) const
1355  {  {
1356    #if defined DOPROF
1357    profData->binary++;    profData->binary++;
1358    #endif
1359    Data result;    Data result;
1360    result.copy(*this);    result.copy(*this);
1361    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);
# Line 1217  Data::powO(const boost::python::object& Line 1365  Data::powO(const boost::python::object&
1365  Data  Data
1366  Data::powD(const Data& right) const  Data::powD(const Data& right) const
1367  {  {
1368    #if defined DOPROF
1369    profData->binary++;    profData->binary++;
1370    #endif
1371    Data result;    Data result;
1372    result.copy(*this);    result.copy(*this);
1373    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);    result.binaryOp(right,(Data::BinaryDFunPtr)::pow);
# Line 1454  Data::getItem(const boost::python::objec Line 1604  Data::getItem(const boost::python::objec
1604  Data  Data
1605  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataArrayView::RegionType& region) const
1606  {  {
1607    #if defined DOPROF
1608    profData->slicing++;    profData->slicing++;
1609    #endif
1610    return Data(*this,region);    return Data(*this,region);
1611  }  }
1612    
# Line 1487  void Line 1639  void
1639  Data::setSlice(const Data& value,  Data::setSlice(const Data& value,
1640                 const DataArrayView::RegionType& region)                 const DataArrayView::RegionType& region)
1641  {  {
1642    #if defined DOPROF
1643    profData->slicing++;    profData->slicing++;
1644    #endif
1645    Data tempValue(value);    Data tempValue(value);
1646    typeMatchLeft(tempValue);    typeMatchLeft(tempValue);
1647    typeMatchRight(tempValue);    typeMatchRight(tempValue);
# Line 1560  Data::setTaggedValueFromCPP(int tagKey, Line 1714  Data::setTaggedValueFromCPP(int tagKey,
1714    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,value);
1715  }  }
1716    
1717    int
1718    Data::getTagNumber(int dpno)
1719    {
1720      return m_data->getTagNumber(dpno);
1721    }
1722    
1723  void  void
1724  Data::setRefValue(int ref,  Data::setRefValue(int ref,
1725                    const boost::python::numeric::array& value)                    const boost::python::numeric::array& value)

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

  ViewVC Help
Powered by ViewVC 1.1.26