/[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 876 by ksteube, Thu Oct 19 03:50:23 2006 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 252  class Data { Line 274  class Data {
274       \brief       \brief
275       Return the value of the specified data-point as a single python numarray object.       Return the value of the specified data-point as a single python numarray object.
276    */    */
277    #ifndef PASO_MPI  
278    ESCRIPT_DLL_API    ESCRIPT_DLL_API
279    const boost::python::numeric::array    const boost::python::numeric::array
280    convertToNumArrayFromDPNo(int sampleNo,    convertToNumArrayFromDPNo(int ProcNo,
281                                                            int sampleNo,
282                              int dataPointNo);                              int dataPointNo);
283    #else
284      ESCRIPT_DLL_API
285      const boost::python::numeric::array
286      convertToNumArrayFromDPNo(int procNo,
287                    int sampleNo,
288                    int dataPointNo);
289    #endif
290    
291    
292    /**    /**
293       \brief       \brief
# Line 528  class Data { Line 560  class Data {
560    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
561                 int dataPointNo)                 int dataPointNo)
562    {    {
563      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
564    }    }
565    
566    /**    /**
# Line 640  class Data { Line 672  class Data {
672    
673    /**    /**
674       \brief       \brief
675         Returns 1./ Data object
676         *
677      */
678      ESCRIPT_DLL_API
679      Data
680      oneOver() const;
681      /**
682         \brief
683       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.
684       *       *
685    */    */
# Line 766  class Data { Line 806  class Data {
806    
807    ESCRIPT_DLL_API    ESCRIPT_DLL_API
808    void    void
 #ifndef PASO_MPI  
   calc_mindp(int& SampleNo,  
              int& DataPointNo) const;  
 #else  
809    calc_mindp(int& ProcNo,    calc_mindp(int& ProcNo,
810                          int& SampleNo,                            int& SampleNo,  
811               int& DataPointNo) const;               int& DataPointNo) const;
 #endif  
812    /**    /**
813       \brief       \brief
814       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 844  class Data {
844    */    */
845    ESCRIPT_DLL_API    ESCRIPT_DLL_API
846    Data    Data
847    matrixtrace(int axis_offset) const;    trace(int axis_offset) const;
848    
849    /**    /**
850       \brief       \brief
# Line 845  class Data { Line 880  class Data {
880    
881    /**    /**
882       \brief       \brief
883       Calculate the trace of each data point of this Data object.       swaps the components axis0 and axis1
884         *
885      */
886      ESCRIPT_DLL_API
887      Data
888      swapaxes(const int axis0, const int axis1) const;
889    
890      /**
891         \brief
892         Return the error function erf of each data point of this Data object.
893       *       *
894    */    */
895    ESCRIPT_DLL_API    ESCRIPT_DLL_API
896    Data    Data
897    trace() const;    erf() const;
898    
899    /**    /**
900       \brief       \brief
# Line 1217  class Data { Line 1261  class Data {
1261                const FunctionSpace& fspace);                const FunctionSpace& fspace);
1262    
1263    
 #ifdef PASO_MPI  
1264    /**    /**
1265       \brief       \brief
1266       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
# Line 1254  class Data { Line 1297  class Data {
1297    ESCRIPT_DLL_API    ESCRIPT_DLL_API
1298      MPI_Comm      MPI_Comm
1299      get_MPIComm(void) const;      get_MPIComm(void) const;
1300  #endif  
1301          /**
1302         \brief
1303         return the object produced by the factory, which is a DataConstant or DataExpanded
1304      */
1305      ESCRIPT_DLL_API
1306        DataAbstract*
1307        borrowData(void) const;
1308    
1309   protected:   protected:
1310    
1311   private:   private:
# Line 1313  class Data { Line 1363  class Data {
1363    
1364    /**    /**
1365       \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  
1366       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1367       \param right - Input - data type to match.       \param right - Input - data type to match.
1368    */    */
# Line 1348  class Data { Line 1387  class Data {
1387               const FunctionSpace& what,               const FunctionSpace& what,
1388               bool expanded);               bool expanded);
1389    
1390    /**    //
1391       \brief    // flag to protect the data object against any update
1392       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);  
1393    
1394    //    //
1395    // pointer to the actual data object    // pointer to the actual data object
# Line 1393  Data::initialise(const IValueType& value Line 1426  Data::initialise(const IValueType& value
1426  /**  /**
1427     Binary Data object operators.     Binary Data object operators.
1428  */  */
1429    inline double rpow(double x,double y)
1430    {
1431        return pow(y,x);
1432    };
1433    
1434  /**  /**
1435    \brief    \brief
# Line 1494  ESCRIPT_DLL_API std::ostream& operator<< Line 1531  ESCRIPT_DLL_API std::ostream& operator<<
1531    
1532  /**  /**
1533    \brief    \brief
1534      Compute a tensor product of two Data objects
1535      \param arg0 - Input - Data object
1536      \param arg1 - Input - Data object
1537      \param axis_offset - Input - axis offset
1538      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1539    */
1540    ESCRIPT_DLL_API
1541    Data
1542    C_GeneralTensorProduct(Data& arg0,
1543                         Data& arg1,
1544                         int axis_offset=0,
1545                         int transpose=0);
1546    
1547    /**
1548      \brief
1549    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1550    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
1551    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1514  Data::binaryOp(const Data& right, Line 1566  Data::binaryOp(const Data& right,
1566     //     //
1567     // 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
1568     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1569       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1570     }     }
1571     //     //
1572     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1566  Data::binaryOp(const Data& right, Line 1618  Data::binaryOp(const Data& right,
1618       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1619       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1620     }     }
1621  }     #if defined DOPROF
1622       profData->binary++;
1623  /**     #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);  
    }  
1624  }  }
1625    
1626  /**  /**

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

  ViewVC Help
Powered by ViewVC 1.1.26