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

Diff of /branches/more_shared_ptrs_from_1812/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 1092 by gross, Fri Apr 13 03:39:49 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       Return the values of all data-points as a single python numarray object.       switches on update protection
243    
244    */    */
245    ESCRIPT_DLL_API    ESCRIPT_DLL_API
246    const boost::python::numeric::array    void
247    convertToNumArray();    setProtection();
248    
249    /**    /**
250       \brief       \brief
251       Return the values of all data-points for the given sample as a single python numarray object.       Returns trueif the data object is protected against update
252    
253    */    */
254    ESCRIPT_DLL_API    ESCRIPT_DLL_API
255    const boost::python::numeric::array    bool
256    convertToNumArrayFromSampleNo(int sampleNo);    isProtected() const;
257    
258    /**    /**
259       \brief       \brief
260       Return the value of the specified data-point as a single python numarray object.       Return the values of a data point on this process
261    */    */
262    ESCRIPT_DLL_API    ESCRIPT_DLL_API
263    const boost::python::numeric::array    const boost::python::numeric::array
264    convertToNumArrayFromDPNo(int sampleNo,    getValueOfDataPoint(int dataPointNo);
265                              int dataPointNo);  
266      /**
267         \brief
268         sets the values of a data-point from a python object on this process
269      */
270      ESCRIPT_DLL_API
271      void
272      setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object);
273    
274      /**
275         \brief
276         sets the values of a data-point from a numarray object on this process
277      */
278      ESCRIPT_DLL_API
279      void
280      setValueOfDataPointToArray(int dataPointNo, const boost::python::numeric::array&);
281    
282    /**    /**
283       \brief       \brief
284       Fills the expanded Data object from values of a python numarray object.       sets the values of a data-point on this process
285    */    */
286    ESCRIPT_DLL_API    ESCRIPT_DLL_API
287    void    void
288    fillFromNumArray(const boost::python::numeric::array);    setValueOfDataPoint(int dataPointNo, const double);
289    
290      /**
291         \brief
292         Return the value of the specified data-point across all processors
293      */
294      ESCRIPT_DLL_API
295      const boost::python::numeric::array
296      getValueOfGlobalDataPoint(int procNo, int dataPointNo);
297    
298    /**    /**
299       \brief       \brief
# Line 423  class Data { Line 453  class Data {
453    
454    /**    /**
455       \brief       \brief
456         Return the number of data points
457      */
458      ESCRIPT_DLL_API
459      inline
460      int
461      getNumDataPoints() const
462      {
463        return getNumSamples() * getNumDataPointsPerSample();
464      }
465      /**
466         \brief
467       Return the number of samples.       Return the number of samples.
468    */    */
469    ESCRIPT_DLL_API    ESCRIPT_DLL_API
# Line 444  class Data { Line 485  class Data {
485    {    {
486      return m_data->getNumDPPSample();      return m_data->getNumDPPSample();
487    }    }
488      /**
489         \brief
490         dumps the object into a netCDF file
491      */
492      ESCRIPT_DLL_API
493      inline
494      void
495      dump(const std::string fileName) const
496      {
497        return m_data->dump(fileName);
498      }
499    
500    /**    /**
501       \brief       \brief
# Line 475  class Data { Line 527  class Data {
527    
528    /**    /**
529       \brief       \brief
      Assign the given value to the data-points referenced by the given  
      reference number.  
   
      The value supplied is a python numarray object.  The data from this numarray  
      is unpacked into a DataArray, and this is used to set the corresponding  
      data-points in the underlying Data object.  
   
      If the underlying Data object cannot be accessed via reference numbers, an  
      exception will be thrown.  
   
      \param ref - Input - reference number.  
      \param value - Input - value to assign to data-points associated with  
                             the given reference number.  
   */  
   ESCRIPT_DLL_API  
   void  
   setRefValue(int ref,  
               const boost::python::numeric::array& value);  
   
   /**  
      \brief  
      Return the values associated with the data-points referenced by the given  
      reference number.  
   
      The value supplied is a python numarray object. The data from the corresponding  
      data-points in this Data object are packed into the given numarray object.  
   
      If the underlying Data object cannot be accessed via reference numbers, an  
      exception will be thrown.  
   
      \param ref - Input - reference number.  
      \param value - Output - object to receive values from data-points  
                              associated with the given reference number.  
   */  
   ESCRIPT_DLL_API  
   void  
   getRefValue(int ref,  
               boost::python::numeric::array& value);  
   
   /**  
      \brief  
530       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
531       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
532       operation.       operation.
# Line 528  class Data { Line 539  class Data {
539    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
540                 int dataPointNo)                 int dataPointNo)
541    {    {
542      return m_data->getDataPoint(sampleNo,dataPointNo);          return m_data->getDataPoint(sampleNo,dataPointNo);
543    }    }
544    
545    /**    /**
# Line 564  class Data { Line 575  class Data {
575    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
576    getLength() const;    getLength() const;
577    
578    
579    
580      /**
581         \brief
582         Assign the given value to the tag assocciated with name. Implicitly converts this
583         object to type DataTagged. Throws an exception if this object
584         cannot be converted to a DataTagged object or name cannot be mapped onto a tag key.
585         \param tagKey - Input - Integer key.
586         \param value - Input - Value to associate with given key.
587        ==>*
588      */
589      ESCRIPT_DLL_API
590      void
591      setTaggedValueByName(std::string name,
592                           const boost::python::object& value);
593    
594    /**    /**
595       \brief       \brief
596       Assign the given value to the tag. Implicitly converts this       Assign the given value to the tag. Implicitly converts this
# Line 640  class Data { Line 667  class Data {
667    
668    /**    /**
669       \brief       \brief
670         Returns 1./ Data object
671         *
672      */
673      ESCRIPT_DLL_API
674      Data
675      oneOver() const;
676      /**
677         \brief
678       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.
679       *       *
680    */    */
# Line 762  class Data { Line 797  class Data {
797    */    */
798    ESCRIPT_DLL_API    ESCRIPT_DLL_API
799    const boost::python::tuple    const boost::python::tuple
800    mindp() const;    minGlobalDataPoint() const;
801    
802    ESCRIPT_DLL_API    ESCRIPT_DLL_API
803    void    void
804  #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  
805    /**    /**
806       \brief       \brief
807       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 837  class Data {
837    */    */
838    ESCRIPT_DLL_API    ESCRIPT_DLL_API
839    Data    Data
840    matrixtrace(int axis_offset) const;    trace(int axis_offset) const;
841    
842    /**    /**
843       \brief       \brief
# Line 845  class Data { Line 873  class Data {
873    
874    /**    /**
875       \brief       \brief
876       Calculate the trace of each data point of this Data object.       swaps the components axis0 and axis1
877         *
878      */
879      ESCRIPT_DLL_API
880      Data
881      swapaxes(const int axis0, const int axis1) const;
882    
883      /**
884         \brief
885         Return the error function erf of each data point of this Data object.
886       *       *
887    */    */
888    ESCRIPT_DLL_API    ESCRIPT_DLL_API
889    Data    Data
890    trace() const;    erf() const;
891    
892    /**    /**
893       \brief       \brief
# Line 1217  class Data { Line 1254  class Data {
1254                const FunctionSpace& fspace);                const FunctionSpace& fspace);
1255    
1256    
 #ifdef PASO_MPI  
1257    /**    /**
1258       \brief       \brief
1259       print the data values to stdout. Used for debugging       print the data values to stdout. Used for debugging
# Line 1254  class Data { Line 1290  class Data {
1290    ESCRIPT_DLL_API    ESCRIPT_DLL_API
1291      MPI_Comm      MPI_Comm
1292      get_MPIComm(void) const;      get_MPIComm(void) const;
1293  #endif  
1294          /**
1295         \brief
1296         return the object produced by the factory, which is a DataConstant or DataExpanded
1297      */
1298      ESCRIPT_DLL_API
1299        DataAbstract*
1300        borrowData(void) const;
1301    
1302   protected:   protected:
1303    
1304   private:   private:
# Line 1313  class Data { Line 1356  class Data {
1356    
1357    /**    /**
1358       \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  
1359       Convert the data type of the RHS to match this.       Convert the data type of the RHS to match this.
1360       \param right - Input - data type to match.       \param right - Input - data type to match.
1361    */    */
# Line 1348  class Data { Line 1380  class Data {
1380               const FunctionSpace& what,               const FunctionSpace& what,
1381               bool expanded);               bool expanded);
1382    
1383    /**    //
1384       \brief    // flag to protect the data object against any update
1385       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);  
1386    
1387    //    //
1388    // pointer to the actual data object    // pointer to the actual data object
1389    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1390    
   //  
   // pointer to the internal profiling data  
   struct profDataEntry *profData;  
   
1391  };  };
1392    
1393  template <class IValueType>  template <class IValueType>
# Line 1393  Data::initialise(const IValueType& value Line 1415  Data::initialise(const IValueType& value
1415  /**  /**
1416     Binary Data object operators.     Binary Data object operators.
1417  */  */
1418    inline double rpow(double x,double y)
1419    {
1420        return pow(y,x);
1421    }
1422    
1423  /**  /**
1424    \brief    \brief
# Line 1494  ESCRIPT_DLL_API std::ostream& operator<< Line 1520  ESCRIPT_DLL_API std::ostream& operator<<
1520    
1521  /**  /**
1522    \brief    \brief
1523      Compute a tensor product of two Data objects
1524      \param arg0 - Input - Data object
1525      \param arg1 - Input - Data object
1526      \param axis_offset - Input - axis offset
1527      \param transpose - Input - 0: transpose neither, 1: transpose arg0, 2: transpose arg1
1528    */
1529    ESCRIPT_DLL_API
1530    Data
1531    C_GeneralTensorProduct(Data& arg0,
1532                         Data& arg1,
1533                         int axis_offset=0,
1534                         int transpose=0);
1535    
1536    /**
1537      \brief
1538    Return true if operands are equivalent, else return false.    Return true if operands are equivalent, else return false.
1539    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
1540    be relied on. Requires further implementation.    be relied on. Requires further implementation.
# Line 1514  Data::binaryOp(const Data& right, Line 1555  Data::binaryOp(const Data& right,
1555     //     //
1556     // 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
1557     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {     if (getPointDataView().getRank()==0 && right.getPointDataView().getRank()!=0) {
1558       reshapeDataPoint(right.getPointDataView().getShape());       throw DataException("Error - attempt to update rank zero object with object with rank bigger than zero.");
1559     }     }
1560     //     //
1561     // initially make the temporary a shallow copy     // initially make the temporary a shallow copy
# Line 1568  Data::binaryOp(const Data& right, Line 1609  Data::binaryOp(const Data& right,
1609     }     }
1610  }  }
1611    
 /**  
   \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);  
    }  
 }  
   
1612  /**  /**
1613    \brief    \brief
1614    Perform the given unary operation on other and return the result.    Perform the given unary operation on other and return the result.

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

  ViewVC Help
Powered by ViewVC 1.1.26