/[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 126 by jgs, Fri Jul 22 03:53:08 2005 UTC revision 150 by jgs, Thu Sep 15 03:44:45 2005 UTC
# Line 481  void Line 481  void
481  Data::fillFromNumArray(const boost::python::numeric::array num_array)  Data::fillFromNumArray(const boost::python::numeric::array num_array)
482  {  {
483    //    //
484    // check rank:    // check rank
485    if (num_array.getrank()<getDataPointRank())    if (num_array.getrank()<getDataPointRank())
486        throw DataException("Rank of numarray does not match Data object rank");        throw DataException("Rank of numarray does not match Data object rank");
487    
488    //    //
489    // check rank of num_array    // check shape of num_array
490    for (int i=0; i<getDataPointRank(); i++) {    for (int i=0; i<getDataPointRank(); i++) {
491      if (extract<int>(num_array.getshape()[i+1])!=getDataPointShape()[i])      if (extract<int>(num_array.getshape()[i+1])!=getDataPointShape()[i])
492         throw DataException("Shape of numarray does not match Data object rank");         throw DataException("Shape of numarray does not match Data object rank");
493    }    }
   //  
   // 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]);  
   // }  
   
   //  
   // 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]);  
   // }  
494    
495    //    //
496    // loop through each data point in turn, loading the values for that data point    // make sure data is expanded:
497    // into the numeric array.    if (!isExpanded()) {
498    // int dataPoint = 0;      expand();
499    // 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++;  
   //   }  
   // }  
500    
501    //    //
502    // return the loaded array    // and copy over
503    // return numArray;    m_data->copyAll(num_array);
   
504  }  }
505    
506  const  const
# Line 969  Data::tan() const Line 892  Data::tan() const
892  }  }
893    
894  Data  Data
895    Data::asin() const
896    {
897      profData->unary++;
898      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asin);
899    }
900    
901    Data
902    Data::acos() const
903    {
904      profData->unary++;
905      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acos);
906    }
907    
908    Data
909    Data::atan() const
910    {
911      profData->unary++;
912      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atan);
913    }
914    
915    Data
916    Data::sinh() const
917    {
918      profData->unary++;
919      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::sinh);
920    }
921    
922    Data
923    Data::cosh() const
924    {
925      profData->unary++;
926      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::cosh);
927    }
928    
929    Data
930    Data::tanh() const
931    {
932      profData->unary++;
933      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::tanh);
934    }
935    
936    Data
937    Data::asinh() const
938    {
939      profData->unary++;
940      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::asinh);
941    }
942    
943    Data
944    Data::acosh() const
945    {
946      profData->unary++;
947      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::acosh);
948    }
949    
950    Data
951    Data::atanh() const
952    {
953      profData->unary++;
954      return escript::unaryOp(*this,(Data::UnaryDFunPtr)::atanh);
955    }
956    
957    Data
958  Data::log() const  Data::log() const
959  {  {
960    profData->unary++;    profData->unary++;
# Line 1007  Data Line 993  Data
993  Data::pos() const  Data::pos() const
994  {  {
995    profData->unary++;    profData->unary++;
996    return (*this);    Data result;
997      // perform a deep copy
998      result.copy(*this);
999      return result;
1000  }  }
1001    
1002  Data  Data
# Line 1030  Data::Lsup() const Line 1019  Data::Lsup() const
1019    profData->reduction1++;    profData->reduction1++;
1020    //    //
1021    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
1022    return algorithm(DataAlgorithmAdapter<AbsMax>(0));    AbsMax abs_max_func;
1023      return algorithm(abs_max_func,0);
1024  }  }
1025    
1026  double  double
# Line 1039  Data::Linf() const Line 1029  Data::Linf() const
1029    profData->reduction1++;    profData->reduction1++;
1030    //    //
1031    // set the initial absolute minimum value to max double    // set the initial absolute minimum value to max double
1032    return algorithm(DataAlgorithmAdapter<AbsMin>(numeric_limits<double>::max()));    AbsMin abs_min_func;
1033      return algorithm(abs_min_func,numeric_limits<double>::max());
1034  }  }
1035    
1036  double  double
# Line 1048  Data::sup() const Line 1039  Data::sup() const
1039    profData->reduction1++;    profData->reduction1++;
1040    //    //
1041    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1042    return algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    FMax fmax_func;
1043      return algorithm(fmax_func,numeric_limits<double>::max()*-1);
1044  }  }
1045    
1046  double  double
# Line 1057  Data::inf() const Line 1049  Data::inf() const
1049    profData->reduction1++;    profData->reduction1++;
1050    //    //
1051    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1052    return algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    FMin fmin_func;
1053      return algorithm(fmin_func,numeric_limits<double>::max());
1054  }  }
1055    
1056  Data  Data
# Line 1066  Data::maxval() const Line 1059  Data::maxval() const
1059    profData->reduction2++;    profData->reduction2++;
1060    //    //
1061    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1062    return dp_algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    FMax fmax_func;
1063      return dp_algorithm(fmax_func,numeric_limits<double>::max()*-1);
1064  }  }
1065    
1066  Data  Data
# Line 1075  Data::minval() const Line 1069  Data::minval() const
1069    profData->reduction2++;    profData->reduction2++;
1070    //    //
1071    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1072    return dp_algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    FMin fmin_func;
1073      return dp_algorithm(fmin_func,numeric_limits<double>::max());
1074  }  }
1075    
1076  Data  Data
1077  Data::length() const  Data::length() const
1078  {  {
1079    profData->reduction2++;    profData->reduction2++;
1080    return dp_algorithm(DataAlgorithmAdapter<Length>(0));    Length len_func;
1081      return dp_algorithm(len_func,0);
1082  }  }
1083    
1084  Data  Data
1085  Data::trace() const  Data::trace() const
1086  {  {
1087    profData->reduction2++;    profData->reduction2++;
1088    return dp_algorithm(DataAlgorithmAdapter<Trace>(0));    Trace trace_func;
1089      return dp_algorithm(trace_func,0);
1090  }  }
1091    
1092  Data  Data
# Line 1104  Data::transpose(int axis) const Line 1101  Data::transpose(int axis) const
1101  const boost::python::tuple  const boost::python::tuple
1102  Data::mindp() const  Data::mindp() const
1103  {  {
1104      // NB: calc_mindp had to be split off from mindp as boost::make_tuple causes an
1105      // abort (for unknown reasons) if there are openmp directives with it in the
1106      // surrounding function
1107    
1108      int SampleNo;
1109      int DataPointNo;
1110    
1111      calc_mindp(SampleNo,DataPointNo);
1112    
1113      return make_tuple(SampleNo,DataPointNo);
1114    }
1115    
1116    void
1117    Data::calc_mindp(int& SampleNo,
1118                     int& DataPointNo) const
1119    {
1120      int i,j;
1121      int lowi=0,lowj=0;
1122      double min=numeric_limits<double>::max();
1123    
1124    Data temp=minval();    Data temp=minval();
1125    
1126    int numSamples=temp.getNumSamples();    int numSamples=temp.getNumSamples();
1127    int numDPPSample=temp.getNumDataPointsPerSample();    int numDPPSample=temp.getNumDataPointsPerSample();
1128    
1129    int i,j,lowi=0,lowj=0;    double next,local_min;
1130    double min=numeric_limits<double>::max();    int local_lowi,local_lowj;
1131    
1132    for (i=0; i<numSamples; i++) {    #pragma omp parallel private(next,local_min,local_lowi,local_lowj)
1133      for (j=0; j<numDPPSample; j++) {    {
1134        double next=temp.getDataPoint(i,j)();      local_min=min;
1135        if (next<min) {      #pragma omp for private(i,j) schedule(static)
1136          min=next;      for (i=0; i<numSamples; i++) {
1137          lowi=i;        for (j=0; j<numDPPSample; j++) {
1138          lowj=j;          next=temp.getDataPoint(i,j)();
1139            if (next<local_min) {
1140              local_min=next;
1141              local_lowi=i;
1142              local_lowj=j;
1143            }
1144        }        }
1145      }      }
1146        #pragma omp critical
1147        if (local_min<min) {
1148          min=local_min;
1149          lowi=local_lowi;
1150          lowj=local_lowj;
1151        }
1152    }    }
1153    
1154    return make_tuple(lowi,lowj);    SampleNo = lowi;
1155      DataPointNo = lowj;
1156  }  }
1157    
1158  void  void
# Line 1560  Data::setTaggedValueFromCPP(int tagKey, Line 1589  Data::setTaggedValueFromCPP(int tagKey,
1589    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,value);
1590  }  }
1591    
1592    int
1593    Data::getTagNumber(int dpno)
1594    {
1595      return m_data->getTagNumber(dpno);
1596    }
1597    
1598  void  void
1599  Data::setRefValue(int ref,  Data::setRefValue(int ref,
1600                    const boost::python::numeric::array& value)                    const boost::python::numeric::array& value)

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

  ViewVC Help
Powered by ViewVC 1.1.26