/[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 783 by gross, Tue Jul 18 01:32:50 2006 UTC revision 914 by gross, Thu Dec 14 04:38:18 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 271  class Data { Line 276  class Data {
276    */    */
277    ESCRIPT_DLL_API    ESCRIPT_DLL_API
278    const boost::python::numeric::array    const boost::python::numeric::array
279    convertToNumArrayFromDPNo(int sampleNo,    convertToNumArrayFromDPNo(int procNo,
280                              int dataPointNo);                  int sampleNo,
281                    int dataPointNo);
282    /**    /**
283       \brief       \brief
284       Fills the expanded Data object from values of a python numarray object.       Fills the expanded Data object from values of a python numarray object.
# Line 545  class Data { Line 550  class Data {
550    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
551                 int dataPointNo)                 int dataPointNo)
552    {    {
553      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
554    }    }
555    
556    /**    /**
# Line 657  class Data { Line 662  class Data {
662    
663    /**    /**
664       \brief       \brief
665         Returns 1./ Data object
666         *
667      */
668      ESCRIPT_DLL_API
669      Data
670      oneOver() const;
671      /**
672         \brief
673       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.
674       *       *
675    */    */
# Line 783  class Data { Line 796  class Data {
796    
797    ESCRIPT_DLL_API    ESCRIPT_DLL_API
798    void    void
 #ifndef PASO_MPI  
   calc_mindp(int& SampleNo,  
              int& DataPointNo) const;  
 #else  
799    calc_mindp(int& ProcNo,    calc_mindp(int& ProcNo,
800                          int& SampleNo,                            int& SampleNo,  
801               int& DataPointNo) const;               int& DataPointNo) const;
 #endif  
802    /**    /**
803       \brief       \brief
804       Return the sign of each data point of this Data object.       Return the sign of each data point of this Data object.
# Line 826  class Data { Line 834  class Data {
834    */    */
835    ESCRIPT_DLL_API    ESCRIPT_DLL_API
836    Data    Data
837    matrixtrace(int axis_offset) const;    trace(int axis_offset) const;
838    
839    /**    /**
840       \brief       \brief
# Line 862  class Data { Line 870  class Data {
870    
871    /**    /**
872       \brief       \brief
873       Calculate the trace of each data point of this Data object.       swaps the components axis0 and axis1
874         *
875      */
876      ESCRIPT_DLL_API
877      Data
878      swapaxes(const int axis0, const int axis1) const;
879    
880      /**
881         \brief
882         Return the error function erf of each data point of this Data object.
883       *       *
884    */    */
885    ESCRIPT_DLL_API    ESCRIPT_DLL_API
886    Data    Data
887    trace() const;    erf() const;
888    
889    /**    /**
890       \brief       \brief
# Line 1234  class Data { Line 1251  class Data {
1251                const FunctionSpace& fspace);                const FunctionSpace& fspace);
1252    
1253    
 #ifdef PASO_MPI  
1254    /**    /**
1255       \brief       \brief
1256       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
# Line 1271  class Data { Line 1287  class Data {
1287    ESCRIPT_DLL_API    ESCRIPT_DLL_API
1288      MPI_Comm      MPI_Comm
1289      get_MPIComm(void) const;      get_MPIComm(void) const;
1290  #endif  
1291          /**
1292         \brief
1293         return the object produced by the factory, which is a DataConstant or DataExpanded
1294      */
1295      ESCRIPT_DLL_API
1296        DataAbstract*
1297        borrowData(void) const;
1298    
1299   protected:   protected:
1300    
1301   private:   private:
# Line 1330  class Data { Line 1353  class Data {
1353    
1354    /**    /**
1355       \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  
1356       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1357       \param right - Input - data type to match.       \param right - Input - data type to match.
1358    */    */
# Line 1365  class Data { Line 1377  class Data {
1377               const FunctionSpace& what,               const FunctionSpace& what,
1378               bool expanded);               bool expanded);
1379    
   /**  
      \brief  
      Reshape the data point if the data point is currently rank 0.  
      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);  
   
1380    //    //
1381    // flag to protect the data object against any update    // flag to protect the data object against any update
1382    bool m_protected;    bool m_protected;
# Line 1414  Data::initialise(const IValueType& value Line 1416  Data::initialise(const IValueType& value
1416  /**  /**
1417     Binary Data object operators.     Binary Data object operators.
1418  */  */
1419    inline double rpow(double x,double y)
1420    {
1421        return pow(y,x);
1422    };
1423    
1424  /**  /**
1425    \brief    \brief
# Line 1515  ESCRIPT_DLL_API std::ostream& operator<< Line 1521  ESCRIPT_DLL_API std::ostream& operator<<
1521    
1522  /**  /**
1523    \brief    \brief
1524      Compute a tensor product of two Data objects
1525      \param arg0 - Input - Data object
1526      \param arg1 - Input - Data object
1527      \param axis_offset - Input - axis offset
1528      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1529    */
1530    ESCRIPT_DLL_API
1531    Data
1532    C_GeneralTensorProduct(Data& arg0,
1533                         Data& arg1,
1534                         int axis_offset=0,
1535                         int transpose=0);
1536    
1537    /**
1538      \brief
1539    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1540    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
1541    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1535  Data::binaryOp(const Data& right, Line 1556  Data::binaryOp(const Data& right,
1556     //     //
1557     // 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
1558     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1559       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1560     }     }
1561     //     //
1562     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1587  Data::binaryOp(const Data& right, Line 1608  Data::binaryOp(const Data& right,
1608       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
1609       escript::binaryOp(*leftC,*rightC,operation);       escript::binaryOp(*leftC,*rightC,operation);
1610     }     }
1611  }     #if defined DOPROF
1612       profData->binary++;
1613  /**     #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);  
    }  
1614  }  }
1615    
1616  /**  /**

Legend:
Removed from v.783  
changed lines
  Added in v.914

  ViewVC Help
Powered by ViewVC 1.1.26