/[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 149 by jgs, Thu Sep 1 03:31:39 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]);  
   // }  
494    
495    //    //
496    // resize the numeric array to the shape just calculated    // make sure data is expanded:
497    // if (arrayRank==1) {    if (!isExpanded()) {
498    //   numArray.resize(arrayShape[0]);      expand();
499    // }    }
   // 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++;  
   //   }  
   // }  
500    
501    //    //
502    // return the loaded array    // and copy over
503    // return numArray;    m_data->copyAll(num_array);
   
504  }  }
505    
506  const  const
# Line 1007  Data Line 930  Data
930  Data::pos() const  Data::pos() const
931  {  {
932    profData->unary++;    profData->unary++;
933    return (*this);    Data result;
934      // perform a deep copy
935      result.copy(*this);
936      return result;
937  }  }
938    
939  Data  Data
# Line 1030  Data::Lsup() const Line 956  Data::Lsup() const
956    profData->reduction1++;    profData->reduction1++;
957    //    //
958    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
959    return algorithm(DataAlgorithmAdapter<AbsMax>(0));    AbsMax abs_max_func;
960      return algorithm(abs_max_func,0);
961  }  }
962    
963  double  double
# Line 1039  Data::Linf() const Line 966  Data::Linf() const
966    profData->reduction1++;    profData->reduction1++;
967    //    //
968    // set the initial absolute minimum value to max double    // set the initial absolute minimum value to max double
969    return algorithm(DataAlgorithmAdapter<AbsMin>(numeric_limits<double>::max()));    AbsMin abs_min_func;
970      return algorithm(abs_min_func,numeric_limits<double>::max());
971  }  }
972    
973  double  double
# Line 1048  Data::sup() const Line 976  Data::sup() const
976    profData->reduction1++;    profData->reduction1++;
977    //    //
978    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
979    return algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    FMax fmax_func;
980      return algorithm(fmax_func,numeric_limits<double>::max()*-1);
981  }  }
982    
983  double  double
# Line 1057  Data::inf() const Line 986  Data::inf() const
986    profData->reduction1++;    profData->reduction1++;
987    //    //
988    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
989    return algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    FMin fmin_func;
990      return algorithm(fmin_func,numeric_limits<double>::max());
991  }  }
992    
993  Data  Data
# Line 1066  Data::maxval() const Line 996  Data::maxval() const
996    profData->reduction2++;    profData->reduction2++;
997    //    //
998    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
999    return dp_algorithm(DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));    FMax fmax_func;
1000      return dp_algorithm(fmax_func,numeric_limits<double>::max()*-1);
1001  }  }
1002    
1003  Data  Data
# Line 1075  Data::minval() const Line 1006  Data::minval() const
1006    profData->reduction2++;    profData->reduction2++;
1007    //    //
1008    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1009    return dp_algorithm(DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));    FMin fmin_func;
1010      return dp_algorithm(fmin_func,numeric_limits<double>::max());
1011  }  }
1012    
1013  Data  Data
1014  Data::length() const  Data::length() const
1015  {  {
1016    profData->reduction2++;    profData->reduction2++;
1017    return dp_algorithm(DataAlgorithmAdapter<Length>(0));    Length len_func;
1018      return dp_algorithm(len_func,0);
1019  }  }
1020    
1021  Data  Data
1022  Data::trace() const  Data::trace() const
1023  {  {
1024    profData->reduction2++;    profData->reduction2++;
1025    return dp_algorithm(DataAlgorithmAdapter<Trace>(0));    Trace trace_func;
1026      return dp_algorithm(trace_func,0);
1027  }  }
1028    
1029  Data  Data
# Line 1104  Data::transpose(int axis) const Line 1038  Data::transpose(int axis) const
1038  const boost::python::tuple  const boost::python::tuple
1039  Data::mindp() const  Data::mindp() const
1040  {  {
1041      // NB: calc_mindp had to be split off from mindp as boost::make_tuple causes an
1042      // abort (for unknown reasons) if there are openmp directives with it in the
1043      // surrounding function
1044    
1045      int SampleNo;
1046      int DataPointNo;
1047    
1048      calc_mindp(SampleNo,DataPointNo);
1049    
1050      return make_tuple(SampleNo,DataPointNo);
1051    }
1052    
1053    void
1054    Data::calc_mindp(int& SampleNo,
1055                     int& DataPointNo) const
1056    {
1057      int i,j;
1058      int lowi=0,lowj=0;
1059      double min=numeric_limits<double>::max();
1060    
1061    Data temp=minval();    Data temp=minval();
1062    
1063    int numSamples=temp.getNumSamples();    int numSamples=temp.getNumSamples();
1064    int numDPPSample=temp.getNumDataPointsPerSample();    int numDPPSample=temp.getNumDataPointsPerSample();
1065    
1066    int i,j,lowi=0,lowj=0;    double next,local_min;
1067    double min=numeric_limits<double>::max();    int local_lowi,local_lowj;
1068    
1069    for (i=0; i<numSamples; i++) {    #pragma omp parallel private(next,local_min,local_lowi,local_lowj)
1070      for (j=0; j<numDPPSample; j++) {    {
1071        double next=temp.getDataPoint(i,j)();      local_min=min;
1072        if (next<min) {      #pragma omp for private(i,j) schedule(static)
1073          min=next;      for (i=0; i<numSamples; i++) {
1074          lowi=i;        for (j=0; j<numDPPSample; j++) {
1075          lowj=j;          next=temp.getDataPoint(i,j)();
1076            if (next<local_min) {
1077              local_min=next;
1078              local_lowi=i;
1079              local_lowj=j;
1080            }
1081        }        }
1082      }      }
1083        #pragma omp critical
1084        if (local_min<min) {
1085          min=local_min;
1086          lowi=local_lowi;
1087          lowj=local_lowj;
1088        }
1089    }    }
1090    
1091    return make_tuple(lowi,lowj);    SampleNo = lowi;
1092      DataPointNo = lowj;
1093  }  }
1094    
1095  void  void
# Line 1560  Data::setTaggedValueFromCPP(int tagKey, Line 1526  Data::setTaggedValueFromCPP(int tagKey,
1526    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,value);
1527  }  }
1528    
1529    int
1530    Data::getTagNumber(int dpno)
1531    {
1532      return m_data->getTagNumber(dpno);
1533    }
1534    
1535  void  void
1536  Data::setRefValue(int ref,  Data::setRefValue(int ref,
1537                    const boost::python::numeric::array& value)                    const boost::python::numeric::array& value)

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

  ViewVC Help
Powered by ViewVC 1.1.26