/[escript]/trunk/escript/src/Data.h
ViewVC logotype

Diff of /trunk/escript/src/Data.h

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

revision 782 by bcumming, Tue Jul 18 00:47:47 2006 UTC revision 921 by gross, Fri Jan 5 00:54:37 2007 UTC
# Line 29  extern "C" { Line 29  extern "C" {
29  #include "paso/Paso.h"  #include "paso/Paso.h"
30  }  }
31    
32    #ifndef PASO_MPI
33    #define MPI_Comm long
34    #endif
35    
36  #include <string>  #include <string>
37  #include <algorithm>  #include <algorithm>
38    
# Line 66  class Data { Line 70  class Data {
70    typedef double (*UnaryDFunPtr)(double);    typedef double (*UnaryDFunPtr)(double);
71    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
72    
73    
74    /**    /**
75       Constructors.       Constructors.
76    */    */
# Line 234  class Data { Line 239  class Data {
239    
240    /**    /**
241       \brief       \brief
242         switches on update protection
243    
244      */
245      ESCRIPT_DLL_API
246      void
247      setProtection();
248    
249      /**
250         \brief
251         Returns trueif the data object is protected against update
252    
253      */
254      ESCRIPT_DLL_API
255      bool
256      isProtected() const;
257      /**
258         \brief
259       Return the values of all data-points as a single python numarray object.       Return the values of all data-points as a single python numarray object.
260    */    */
261    ESCRIPT_DLL_API    ESCRIPT_DLL_API
# Line 242  class Data { Line 264  class Data {
264    
265    /**    /**
266       \brief       \brief
267       Return the values of all data-points for the given sample as a single python numarray object.       Fills the expanded Data object from values of a python numarray object.
268    */    */
269    ESCRIPT_DLL_API    ESCRIPT_DLL_API
270    const boost::python::numeric::array    void
271    convertToNumArrayFromSampleNo(int sampleNo);    fillFromNumArray(const boost::python::numeric::array);
272    
273    /**    /**
274       \brief       \brief
275       Return the value of the specified data-point as a single python numarray object.       Return the values of a data point on this process
276    */    */
277    ESCRIPT_DLL_API    ESCRIPT_DLL_API
278    const boost::python::numeric::array    const boost::python::numeric::array
279    convertToNumArrayFromDPNo(int sampleNo,    getValueOfDataPoint(int dataPointNo);
                             int dataPointNo);  
280    
281    /**    /**
282       \brief       \brief
283       Fills the expanded Data object from values of a python numarray object.       sets the values of a data-point on this process
284    */    */
285    ESCRIPT_DLL_API    ESCRIPT_DLL_API
286    void    void
287    fillFromNumArray(const boost::python::numeric::array);    setValueOfDataPoint(int dataPointNo, const boost::python::numeric::array);
288    
289      /**
290         \brief
291         Return the value of the specified data-point across all processors
292      */
293      ESCRIPT_DLL_API
294      const boost::python::numeric::array
295      getValueOfGlobalDataPoint(int procNo, int dataPointNo);
296    
297    /**    /**
298       \brief       \brief
# Line 423  class Data { Line 452  class Data {
452    
453    /**    /**
454       \brief       \brief
455         Return the number of data points
456      */
457      ESCRIPT_DLL_API
458      inline
459      int
460      getNumDataPoints() const
461      {
462        return getNumSamples() * getNumDataPointsPerSample();
463      }
464      /**
465         \brief
466       Return the number of samples.       Return the number of samples.
467    */    */
468    ESCRIPT_DLL_API    ESCRIPT_DLL_API
# Line 528  class Data { Line 568  class Data {
568    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
569                 int dataPointNo)                 int dataPointNo)
570    {    {
571      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
572    }    }
573    
574    /**    /**
# Line 640  class Data { Line 680  class Data {
680    
681    /**    /**
682       \brief       \brief
683         Returns 1./ Data object
684         *
685      */
686      ESCRIPT_DLL_API
687      Data
688      oneOver() const;
689      /**
690         \brief
691       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.
692       *       *
693    */    */
# Line 762  class Data { Line 810  class Data {
810    */    */
811    ESCRIPT_DLL_API    ESCRIPT_DLL_API
812    const boost::python::tuple    const boost::python::tuple
813    mindp() const;    minGlobalDataPoint() const;
814    
815    ESCRIPT_DLL_API    ESCRIPT_DLL_API
816    void    void
817  #ifndef PASO_MPI    calc_minGlobalDataPoint(int& ProcNo,  int& DataPointNo) const;
   calc_mindp(int& SampleNo,  
              int& DataPointNo) const;  
 #else  
   calc_mindp(int& ProcNo,  
                         int& SampleNo,    
              int& DataPointNo) const;  
 #endif  
818    /**    /**
819       \brief       \brief
820       Return the sign of each data point of this Data object.       Return the sign of each data point of this Data object.
# Line 809  class Data { Line 850  class Data {
850    */    */
851    ESCRIPT_DLL_API    ESCRIPT_DLL_API
852    Data    Data
853    matrixtrace(int axis_offset) const;    trace(int axis_offset) const;
854    
855    /**    /**
856       \brief       \brief
# Line 845  class Data { Line 886  class Data {
886    
887    /**    /**
888       \brief       \brief
889       Calculate the trace of each data point of this Data object.       swaps the components axis0 and axis1
890         *
891      */
892      ESCRIPT_DLL_API
893      Data
894      swapaxes(const int axis0, const int axis1) const;
895    
896      /**
897         \brief
898         Return the error function erf of each data point of this Data object.
899       *       *
900    */    */
901    ESCRIPT_DLL_API    ESCRIPT_DLL_API
902    Data    Data
903    trace() const;    erf() const;
904    
905    /**    /**
906       \brief       \brief
# Line 1217  class Data { Line 1267  class Data {
1267                const FunctionSpace& fspace);                const FunctionSpace& fspace);
1268    
1269    
 #ifdef PASO_MPI  
1270    /**    /**
1271       \brief       \brief
1272       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
# Line 1254  class Data { Line 1303  class Data {
1303    ESCRIPT_DLL_API    ESCRIPT_DLL_API
1304      MPI_Comm      MPI_Comm
1305      get_MPIComm(void) const;      get_MPIComm(void) const;
1306  #endif  
1307          /**
1308         \brief
1309         return the object produced by the factory, which is a DataConstant or DataExpanded
1310      */
1311      ESCRIPT_DLL_API
1312        DataAbstract*
1313        borrowData(void) const;
1314    
1315   protected:   protected:
1316    
1317   private:   private:
# Line 1313  class Data { Line 1369  class Data {
1369    
1370    /**    /**
1371       \brief       \brief
      Perform the given binary operation on all of the data's elements.  
      RHS is a boost::python object.  
   */  
   template <class BinaryFunction>  
   inline  
   void  
   binaryOp(const boost::python::object& right,  
            BinaryFunction operation);  
   
   /**  
      \brief  
1372       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1373       \param right - Input - data type to match.       \param right - Input - data type to match.
1374    */    */
# Line 1348  class Data { Line 1393  class Data {
1393               const FunctionSpace& what,               const FunctionSpace& what,
1394               bool expanded);               bool expanded);
1395    
1396    /**    //
1397       \brief    // flag to protect the data object against any update
1398       Reshape the data point if the data point is currently rank 0.    bool m_protected;
      Will throw an exception if the data points are not rank 0.  
      The original data point value is used for all values of the new  
      data point.  
   */  
   void  
   reshapeDataPoint(const DataArrayView::ShapeType& shape);  
1399    
1400    //    //
1401    // pointer to the actual data object    // pointer to the actual data object
# Line 1393  Data::initialise(const IValueType& value Line 1432  Data::initialise(const IValueType& value
1432  /**  /**
1433     Binary Data object operators.     Binary Data object operators.
1434  */  */
1435    inline double rpow(double x,double y)
1436    {
1437        return pow(y,x);
1438    };
1439    
1440  /**  /**
1441    \brief    \brief
# Line 1494  ESCRIPT_DLL_API std::ostream& operator<< Line 1537  ESCRIPT_DLL_API std::ostream& operator<<
1537    
1538  /**  /**
1539    \brief    \brief
1540      Compute a tensor product of two Data objects
1541      \param arg0 - Input - Data object
1542      \param arg1 - Input - Data object
1543      \param axis_offset - Input - axis offset
1544      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1545    */
1546    ESCRIPT_DLL_API
1547    Data
1548    C_GeneralTensorProduct(Data& arg0,
1549                         Data& arg1,
1550                         int axis_offset=0,
1551                         int transpose=0);
1552    
1553    /**
1554      \brief
1555    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1556    NB: this operator does very little at this point, and isn't to    NB: this operator does very little at this point, and isn't to
1557    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1514  Data::binaryOp(const Data& right, Line 1572  Data::binaryOp(const Data& right,
1572     //     //
1573     // if this has a rank of zero promote it to the rank of the RHS     // if this has a rank of zero promote it to the rank of the RHS
1574     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1575       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1576     }     }
1577     //     //
1578     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1566  Data::binaryOp(const Data& right, Line 1624  Data::binaryOp(const Data& right,
1624       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1625       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1626     }     }
1627  }     #if defined DOPROF
1628       profData->binary++;
1629  /**     #endif
   \brief  
   Perform the given binary operation with this and right as operands.  
   Right is a boost::python object.  
 */  
 template <class BinaryFunction>  
 inline  
 void  
 Data::binaryOp(const boost::python::object& right,  
                BinaryFunction operation)  
 {  
    DataArray temp(right);  
    //  
    // if this has a rank of zero promote it to the rank of the RHS.  
    if (getPointDataView().getRank()==0 && temp.getView().getRank()!=0) {  
       reshapeDataPoint(temp.getView().getShape());  
    }  
    //  
    // Always allow scalar values for the RHS but check other shapes  
    if (temp.getView().getRank()!=0) {  
      if (!getPointDataView().checkShape(temp.getView().getShape())) {  
        throw DataException(getPointDataView().createShapeErrorMessage(  
                   "Error - RHS shape doesn't match LHS shape.",temp.getView().getShape()));  
      }  
    }  
    if (isExpanded()) {  
      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());  
      EsysAssert((leftC!=0),"Programming error - casting to DataExpanded.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    } else if (isTagged()) {  
      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());  
      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    } else if (isConstant()) {  
      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());  
      EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");  
      escript::binaryOp(*leftC,temp.getView(),operation);  
    }  
1630  }  }
1631    
1632  /**  /**

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

  ViewVC Help
Powered by ViewVC 1.1.26