/[escript]/branches/windows_from_1383_trunk/escript/src/Data.h
ViewVC logotype

Diff of /branches/windows_from_1383_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 854 by gross, Thu Sep 21 05:29:42 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    ESCRIPT_DLL_API
887    Data    Data
888    trace() const;    swapaxes(const int axis0, const int axis1) const;
889    
890    /**    /**
891       \brief       \brief
# Line 1217  class Data { Line 1252  class Data {
1252                const FunctionSpace& fspace);                const FunctionSpace& fspace);
1253    
1254    
 #ifdef PASO_MPI  
1255    /**    /**
1256       \brief       \brief
1257       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
# Line 1254  class Data { Line 1288  class Data {
1288    ESCRIPT_DLL_API    ESCRIPT_DLL_API
1289      MPI_Comm      MPI_Comm
1290      get_MPIComm(void) const;      get_MPIComm(void) const;
1291  #endif  
1292          /**
1293         \brief
1294         return the object produced by the factory, which is a DataConstant or DataExpanded
1295      */
1296      ESCRIPT_DLL_API
1297        DataAbstract*
1298        borrowData(void) const;
1299    
1300   protected:   protected:
1301    
1302   private:   private:
# Line 1313  class Data { Line 1354  class Data {
1354    
1355    /**    /**
1356       \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  
1357       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1358       \param right - Input - data type to match.       \param right - Input - data type to match.
1359    */    */
# Line 1348  class Data { Line 1378  class Data {
1378               const FunctionSpace& what,               const FunctionSpace& what,
1379               bool expanded);               bool expanded);
1380    
1381    /**    //
1382       \brief    // flag to protect the data object against any update
1383       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);  
1384    
1385    //    //
1386    // pointer to the actual data object    // pointer to the actual data object
# Line 1393  Data::initialise(const IValueType& value Line 1417  Data::initialise(const IValueType& value
1417  /**  /**
1418     Binary Data object operators.     Binary Data object operators.
1419  */  */
1420    inline double rpow(double x,double y)
1421    {
1422        return pow(y,x);
1423    };
1424    
1425  /**  /**
1426    \brief    \brief
# Line 1494  ESCRIPT_DLL_API std::ostream& operator<< Line 1522  ESCRIPT_DLL_API std::ostream& operator<<
1522    
1523  /**  /**
1524    \brief    \brief
1525      Compute a tensor product of two Data objects
1526      \param arg0 - Input - Data object
1527      \param arg1 - Input - Data object
1528      \param axis_offset - Input - axis offset
1529      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1530    */
1531    ESCRIPT_DLL_API
1532    Data
1533    C_GeneralTensorProduct(Data& arg0,
1534                         Data& arg1,
1535                         int axis_offset=0,
1536                         int transpose=0);
1537    
1538    /**
1539      \brief
1540    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1541    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
1542    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1514  Data::binaryOp(const Data& right, Line 1557  Data::binaryOp(const Data& right,
1557     //     //
1558     // 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
1559     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1560       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1561     }     }
1562     //     //
1563     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1566  Data::binaryOp(const Data& right, Line 1609  Data::binaryOp(const Data& right,
1609       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1610       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1611     }     }
1612  }     #if defined DOPROF
1613       profData->binary++;
1614  /**     #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);  
    }  
1615  }  }
1616    
1617  /**  /**

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

  ViewVC Help
Powered by ViewVC 1.1.26